summaryrefslogtreecommitdiffstats
path: root/server-msg.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-06-02 18:08:17 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-06-02 18:08:17 +0000
commitc7243b73cb3baaf6993d8a9dfb16c054c3978040 (patch)
tree1d67ee4c5cf764dc83245c79d27da52857b4a89d /server-msg.c
parent11ee55e755af67dc9155e956b4569c8fdeb11848 (diff)
Move -s and -c down a level so handling them is the responsibility of the command (with some helper functions), rather than the top-level. This changes the action command syntax so that -s and -c must be after the command rather than before.
Diffstat (limited to 'server-msg.c')
-rw-r--r--server-msg.c63
1 files changed, 8 insertions, 55 deletions
diff --git a/server-msg.c b/server-msg.c
index d92aa3c1..ed8b86b6 100644
--- a/server-msg.c
+++ b/server-msg.c
@@ -1,4 +1,4 @@
-/* $Id: server-msg.c,v 1.43 2007-12-13 18:59:42 nicm Exp $ */
+/* $Id: server-msg.c,v 1.44 2008-06-02 18:08:17 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -111,16 +111,10 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
struct msg_command_data data;
struct cmd_ctx ctx;
struct cmd *cmd;
- char *name, *client, *cause;
- u_int i;
-
- /* XXX I hate this function. Split it? */
if (hdr->size < sizeof data)
fatalx("bad MSG_COMMAND size");
buffer_read(c->in, &data, sizeof data);
- name = cmd_recv_string(c->in);
- client = cmd_recv_string(c->in);
cmd = cmd_recv(c->in);
log_debug("got command %s from client %d", cmd->entry->name, c->fd);
@@ -128,64 +122,23 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
ctx.error = server_msg_fn_command_error;
ctx.print = server_msg_fn_command_print;
+ ctx.curclient = NULL;
+ ctx.cursession = NULL;
+ ctx.msgdata = &data;
+
ctx.cmdclient = c;
ctx.flags = 0;
+ /* XXX */
if (data.pid != -1 && (cmd->entry->flags & CMD_CANTNEST)) {
server_msg_fn_command_error(&ctx, "sessions "
"should be nested with care. unset $TMUX to force");
- goto out;
- }
-
- ctx.client = NULL;
- if (cmd->entry->flags & CMD_NOCLIENT) {
- if (client != NULL) {
- server_msg_fn_command_error(&ctx,
- "%s: cannot specify a client", cmd->entry->name);
- goto out;
- }
- } else {
- if (client == NULL) {
- server_msg_fn_command_error(&ctx,
- "%s: must specify a client", cmd->entry->name);
- goto out;
- }
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- /* XXX fnmatch, multi clients etc */
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL && strcmp(client, c->tty.path) == 0)
- ctx.client = c;
- }
- if (ctx.client == NULL) {
- server_msg_fn_command_error(&ctx, "%s: "
- "client not found: %s", cmd->entry->name, client);
- goto out;
- }
- }
-
- ctx.session = NULL;
- if (cmd->entry->flags & CMD_NOSESSION) {
- if (name != NULL) {
- server_msg_fn_command_error(&ctx,
- "%s: cannot specify a session", cmd->entry->name);
- goto out;
- }
- } else {
- ctx.session = server_extract_session(&data, name, &cause);
- if (ctx.session == NULL) {
- server_msg_fn_command_error(
- &ctx, "%s: %s", cmd->entry->name, cause);
- xfree(cause);
- goto out;
- }
+ cmd_free(cmd);
+ return (0);
}
cmd_exec(cmd, &ctx);
cmd_free(cmd);
-
-out:
- if (name != NULL)
- xfree(name);
return (0);
}