diff options
Diffstat (limited to 'cmd-rename-session.c')
-rw-r--r-- | cmd-rename-session.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/cmd-rename-session.c b/cmd-rename-session.c index 498bacd2..8a057543 100644 --- a/cmd-rename-session.c +++ b/cmd-rename-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-rename-session.c,v 1.4 2007-12-06 09:46:22 nicm Exp $ */ +/* $Id: cmd-rename-session.c,v 1.5 2008-06-02 18:08:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -27,19 +27,21 @@ * Change session name. */ -int cmd_rename_session_parse(void **, int, char **, char **); +int cmd_rename_session_parse(struct cmd *, void **, int, char **, char **); void cmd_rename_session_exec(void *, struct cmd_ctx *); void cmd_rename_session_send(void *, struct buffer *); void cmd_rename_session_recv(void **, struct buffer *); void cmd_rename_session_free(void *); struct cmd_rename_session_data { + char *sname; char *newname; }; const struct cmd_entry cmd_rename_session_entry = { - "rename-session", "rename", "new-name", - CMD_NOCLIENT, + "rename-session", "rename", + "[-s session-name] new-name", + 0, cmd_rename_session_parse, cmd_rename_session_exec, cmd_rename_session_send, @@ -48,16 +50,21 @@ const struct cmd_entry cmd_rename_session_entry = { }; int -cmd_rename_session_parse(void **ptr, int argc, char **argv, char **cause) +cmd_rename_session_parse( + struct cmd *self, void **ptr, int argc, char **argv, char **cause) { struct cmd_rename_session_data *data; int opt; *ptr = data = xmalloc(sizeof *data); + data->sname = NULL; data->newname = NULL; - while ((opt = getopt(argc, argv, "")) != EOF) { + while ((opt = getopt(argc, argv, "s:")) != EOF) { switch (opt) { + case 's': + data->sname = xstrdup(optarg); + break; default: goto usage; } @@ -72,8 +79,7 @@ cmd_rename_session_parse(void **ptr, int argc, char **argv, char **cause) return (0); usage: - usage(cause, "%s %s", - cmd_rename_session_entry.name, cmd_rename_session_entry.usage); + usage(cause, "%s %s", self->entry->name, self->entry->usage); cmd_rename_session_free(data); return (-1); @@ -83,12 +89,16 @@ void cmd_rename_session_exec(void *ptr, struct cmd_ctx *ctx) { struct cmd_rename_session_data *data = ptr; + struct session *s; if (data == NULL) return; - xfree(ctx->session->name); - ctx->session->name = xstrdup(data->newname); + if ((s = cmd_find_session(ctx, data->sname)) == NULL) + return; + + xfree(s->name); + s->name = xstrdup(data->newname); if (ctx->cmdclient != NULL) server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); @@ -100,6 +110,7 @@ cmd_rename_session_send(void *ptr, struct buffer *b) struct cmd_rename_session_data *data = ptr; buffer_write(b, data, sizeof *data); + cmd_send_string(b, data->sname); cmd_send_string(b, data->newname); } @@ -110,6 +121,7 @@ cmd_rename_session_recv(void **ptr, struct buffer *b) *ptr = data = xmalloc(sizeof *data); buffer_read(b, data, sizeof *data); + data->sname = cmd_recv_string(b); data->newname = cmd_recv_string(b); } @@ -118,6 +130,8 @@ cmd_rename_session_free(void *ptr) { struct cmd_rename_session_data *data = ptr; + if (data->sname != NULL) + xfree(data->sname); if (data->newname != NULL) xfree(data->newname); xfree(data); |