typedef enum {
CMD_UNKNOWN = 0,
- CMD_PUTVAL = 1,
+ CMD_FLUSH = 1,
+ CMD_LISTVAL = 2,
+ CMD_PUTVAL = 3,
} cmd_type_t;
#define CMD_TO_STRING(type) \
- ((type) == CMD_PUTVAL) ? "PUTVAL" \
+ ((type) == CMD_FLUSH) ? "FLUSH" \
+ : ((type) == CMD_LISTVAL) ? "LISTVAL" \
+ : ((type) == CMD_PUTVAL) ? "PUTVAL" \
: "UNKNOWN"
typedef struct {
+ double timeout;
+
+ char **plugins;
+ size_t plugins_num;
+ identifier_t *identifiers;
+ size_t identifiers_num;
+} cmd_flush_t;
+
+typedef struct {
+} cmd_listval_t;
+
+typedef struct {
/* The raw identifier as provided by the user. */
char *identifier;
typedef struct {
cmd_type_t type;
union {
+ cmd_flush_t flush;
+ cmd_listval_t listval;
cmd_putval_t putval;
} cmd;
} cmd_t;
CMD_ERROR = -1,
CMD_PARSE_ERROR = -2,
CMD_UNKNOWN_COMMAND = -3,
+
+ /* Not necessarily fatal errors. */
+ CMD_NO_OPTION = 1,
} cmd_status_t;
/*
cmd_status_t cmd_parse (char *buffer,
cmd_t *ret_cmd, cmd_error_handler_t *err);
+cmd_status_t cmd_parsev (size_t argc, char **argv,
+ cmd_t *ret_cmd, cmd_error_handler_t *err);
+
void cmd_destroy (cmd_t *cmd);
/*
* NAME
+ * cmd_parse_option
+ *
+ * DESCRIPTION
+ * Parses a command option which must be of the form:
+ * name=value with \ and spaces
+ *
+ * PARAMETERS
+ * `field' The parsed input field with any quotes removed and special
+ * characters unescaped.
+ * `ret_key' The parsed key will be stored at this location.
+ * `ret_value' The parsed value will be stored at this location.
+ *
+ * RETURN VALUE
+ * CMD_OK on success or an error code otherwise.
+ * CMD_NO_OPTION if `field' does not represent an option at all (missing
+ * equal sign).
+ */
+cmd_status_t cmd_parse_option (char *field,
+ char **ret_key, char **ret_value, cmd_error_handler_t *err);
+
+/*
+ * NAME
* cmd_error_fh
*
* DESCRIPTION