X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command.h;h=0265f056d999ff1322b639493ad5503bc847dd6e;hp=6d2202071c6b849fe37a9a69c30c21d09ff80ef0;hb=fe3d9cd155b5eac8706015854c343440823e12da;hpb=0879c9de4eaf8c78131c243d8e9fec013df0d14a;ds=sidebyside diff --git a/command.h b/command.h index 6d220207..0265f056 100644 --- a/command.h +++ b/command.h @@ -2,43 +2,57 @@ /** Per connection data available to command handlers. */ struct command_context { - /** Network address of the peer. */ - const char *peer; /** The paraslash user that executes this command. */ struct user *u; - /** Argument count. */ - int argc; - /** Argument vector. */ - char **argv; - /** The command being executed. */ - struct server_command *cmd; /** File descriptor and crypto keys. */ struct stream_cipher_context scc; }; +/** Prototype of a server command handler. */ +typedef int (*server_cmd_handler_t)(struct command_context *, + struct lls_parse_result *); + /** - * Defines one command of para_server. + * The lopsub user data structure for server commands. + * + * One such structure exists for each server command. Lopsub maintains + * references to the user data structures and provides lls_user_data() for + * applications to fetch the user data pointer of a given command. This + * mechanism is used by the dispatcher of command.c to run the command handler. */ -struct server_command { - /** The name of the command. */ - const char *name; - /** Pointer to the function that handles the command. */ - int (*handler)(struct command_context *); - /** The privileges a user must have to execute this command. */ - unsigned int perms; - /** One-line description of the command. */ - const char *description; - /** Summary of the command line options. */ - const char *usage; - /** The long help text. */ - const char *help; +struct server_cmd_user_data { + /** Pointer to the command handler. */ + server_cmd_handler_t handler; }; +/** Define the user data structure for one command. */ +#define EXPORT_SERVER_CMD_HANDLER(_cmd) \ + const struct server_cmd_user_data lsg_server_cmd_com_ ## _cmd ## _user_data = { \ + .handler = com_ ## _cmd \ + }; + +/** Get the lopsub command pointer by command name. */ +#define SERVER_CMD_CMD_PTR(_cmd) \ + (lls_cmd(LSG_SERVER_CMD_CMD_ ## _cmd, server_cmd_suite)) + +/** Get the lopsub parse result of an option. */ +#define SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr) \ + (lls_opt_result(LSG_SERVER_CMD_ ## _cmd ## _OPT_ ## _opt, _lpr)) + +/** How many times an option was given. */ +#define SERVER_CMD_OPT_GIVEN(_cmd, _opt, _lpr) \ + (lls_opt_given(SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr))) + +/** Fetch the (first) argument given to an option of type uint32. */ +#define SERVER_CMD_UINT32_VAL(_cmd, _opt, _lpr) \ + (lls_uint32_val(0, SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr))) + int send_sb(struct stream_cipher_context *scc, void *buf, size_t numbytes, int band, bool dont_free); __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band, const char *fmt, ...); int send_strerror(struct command_context *cc, int err); +int send_errctx(struct command_context *cc, char *errctx); int recv_sb(struct stream_cipher_context *scc, enum sb_designator expected_band, size_t max_size, struct iovec *result);