server: Convert com_mvatt() to lopsub.
[paraslash.git] / command.h
1 /** \file command.h The structure of server and afs commands. */
2
3 /** Per connection data available to command handlers. */
4 struct command_context {
5 /** Network address of the peer. */
6 const char *peer;
7 /** The paraslash user that executes this command. */
8 struct user *u;
9 /** Argument count. */
10 int argc;
11 /** Argument vector. */
12 char **argv;
13 /** File descriptor and crypto keys. */
14 struct stream_cipher_context scc;
15 };
16
17 /** Prototype of a server command handler. */
18 typedef int (*server_cmd_handler_t)(struct command_context *,
19 struct lls_parse_result *);
20
21 /**
22 * The lopsub user data structure for server commands.
23 *
24 * One such structure exists for each server command. Lopsub maintains
25 * references to the user data structures and provides lls_user_data() for
26 * applications to fetch the user data pointer of a given command. This
27 * mechanism is used by the dispatcher of command.c to run the command handler.
28 */
29 struct server_cmd_user_data {
30 /** Pointer to the command handler. */
31 server_cmd_handler_t handler;
32 };
33
34 /** Define the user data structure for one command. */
35 #define EXPORT_SERVER_CMD_HANDLER(_cmd) \
36 const struct server_cmd_user_data lsg_server_cmd_com_ ## _cmd ## _user_data = { \
37 .handler = com_ ## _cmd \
38 };
39
40 /** Get the lopsub command pointer by command name. */
41 #define SERVER_CMD_CMD_PTR(_cmd) \
42 (lls_cmd(LSG_SERVER_CMD_CMD_ ## _cmd, server_cmd_suite))
43
44 /** Get the lopsub parse result of an option. */
45 #define SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr) \
46 (lls_opt_result(LSG_SERVER_CMD_ ## _cmd ## _OPT_ ## _opt, _lpr))
47
48 /** How many times an option was given. */
49 #define SERVER_CMD_OPT_GIVEN(_cmd, _opt, _lpr) \
50 (lls_opt_given(SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr)))
51
52 /** Fetch the (first) argument given to an option of type uint32. */
53 #define SERVER_CMD_UINT32_VAL(_cmd, _opt, _lpr) \
54 (lls_uint32_val(0, SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr)))
55
56 int send_sb(struct stream_cipher_context *scc, void *buf, size_t numbytes,
57 int band, bool dont_free);
58 __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band,
59 const char *fmt, ...);
60 int send_strerror(struct command_context *cc, int err);
61 int send_errctx(struct command_context *cc, char *errctx);
62 int recv_sb(struct stream_cipher_context *scc,
63 enum sb_designator expected_band,
64 size_t max_size, struct iovec *result);