summaryrefslogtreecommitdiff
path: root/src/feature/control/control_cmd.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-04-02 08:17:22 -0400
committerNick Mathewson <nickm@torproject.org>2019-04-25 14:13:03 -0400
commitde70eebc65d40d50f877b0f82df4d05ce670faa5 (patch)
treeb84bb2f4fb0a0b73a76eac71083e2a34b44df155 /src/feature/control/control_cmd.h
parente9ca904dbfc99ebef567d7bb2c6d87819d0d832c (diff)
downloadtor-de70eebc65d40d50f877b0f82df4d05ce670faa5.tar.gz
tor-de70eebc65d40d50f877b0f82df4d05ce670faa5.zip
Start on a command-parsing tool for controller commands.
There _is_ an underlying logic to these commands, but it isn't wholly uniform, given years of tweaks and changes. Fortunately I think there is a superset that will work. This commit adds a parser for some of the most basic cases -- the ones currently handled by getargs_helper() and some of the object-taking ones. Soon will come initial tests; then I'll start using the parser. After that, I'll expand the parser to handle the other cases that come up in the controller protocol.
Diffstat (limited to 'src/feature/control/control_cmd.h')
-rw-r--r--src/feature/control/control_cmd.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/feature/control/control_cmd.h b/src/feature/control/control_cmd.h
index a417e10da3..1070a9edb7 100644
--- a/src/feature/control/control_cmd.h
+++ b/src/feature/control/control_cmd.h
@@ -12,11 +12,19 @@
#ifndef TOR_CONTROL_CMD_H
#define TOR_CONTROL_CMD_H
+#include "lib/malloc/malloc.h"
+
int handle_control_command(control_connection_t *conn,
uint32_t cmd_data_len,
char *args);
void control_cmd_free_all(void);
+typedef struct control_cmd_args_t control_cmd_args_t;
+void control_cmd_args_free_(control_cmd_args_t *args);
+
+#define control_cmd_args_free(v) \
+ FREE_AND_NULL(control_cmd_args_t, control_cmd_args_free_, (v))
+
#ifdef CONTROL_CMD_PRIVATE
#include "lib/crypt_ops/crypto_ed25519.h"
@@ -39,6 +47,37 @@ STATIC int add_onion_helper_keyarg(const char *arg, int discard_pk,
STATIC rend_authorized_client_t *add_onion_helper_clientauth(const char *arg,
int *created, char **err_msg_out);
+/**
+ * Definition for the syntax of a controller command, as parsed by
+ * control_cmd_parse_args.
+ *
+ * WORK IN PROGRESS: This structure is going to get more complex as this
+ * branch goes on.
+ **/
+typedef struct control_cmd_syntax_t {
+ /**
+ * Lowest number of positional arguments that this command accepts.
+ * 0 for "it's okay not to have positional arguments."
+ **/
+ unsigned int min_args;
+ /**
+ * Highest number of positional arguments that this command accepts.
+ * UINT_MAX for no limit.
+ **/
+ unsigned int max_args;
+ /**
+ * True iff this command wants to be followed by a multiline object.
+ **/
+ bool want_object;
+} control_cmd_syntax_t;
+
+STATIC control_cmd_args_t *control_cmd_parse_args(
+ const char *command,
+ const control_cmd_syntax_t *syntax,
+ size_t body_len,
+ const char *body,
+ char **error_out);
+
#endif /* defined(CONTROL_CMD_PRIVATE) */
#ifdef CONTROL_MODULE_PRIVATE