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