+static int handle_request_quit (HANDLER_PROTO) /* {{{ */
+{
+ return -1;
+} /* }}} static int handle_request_quit */
+
+struct command COMMANDS[] = {
+ {
+ "UPDATE",
+ handle_request_update,
+ PRIV_HIGH,
+ CMD_CONTEXT_ANY,
+ "UPDATE <filename> <values> [<values> ...]\n"
+ ,
+ "Adds the given file to the internal cache if it is not yet known and\n"
+ "appends the given value(s) to the entry. See the rrdcached(1) manpage\n"
+ "for details.\n"
+ "\n"
+ "Each <values> has the following form:\n"
+ " <values> = <time>:<value>[:<value>[...]]\n"
+ "See the rrdupdate(1) manpage for details.\n"
+ },
+ {
+ "WROTE",
+ handle_request_wrote,
+ PRIV_HIGH,
+ CMD_CONTEXT_JOURNAL,
+ NULL,
+ NULL
+ },
+ {
+ "FLUSH",
+ handle_request_flush,
+ PRIV_LOW,
+ CMD_CONTEXT_CLIENT | CMD_CONTEXT_BATCH,
+ "FLUSH <filename>\n"
+ ,
+ "Adds the given filename to the head of the update queue and returns\n"
+ "after it has been dequeued.\n"
+ },
+ {
+ "FLUSHALL",
+ handle_request_flushall,
+ PRIV_HIGH,
+ CMD_CONTEXT_CLIENT,
+ "FLUSHALL\n"
+ ,
+ "Triggers writing of all pending updates. Returns immediately.\n"
+ },
+ {
+ "PENDING",
+ handle_request_pending,
+ PRIV_HIGH,
+ CMD_CONTEXT_CLIENT,
+ "PENDING <filename>\n"
+ ,
+ "Shows any 'pending' updates for a file, in order.\n"
+ "The updates shown have not yet been written to the underlying RRD file.\n"
+ },
+ {
+ "FORGET",
+ handle_request_forget,
+ PRIV_HIGH,
+ CMD_CONTEXT_ANY,
+ "FORGET <filename>\n"
+ ,
+ "Removes the file completely from the cache.\n"
+ "Any pending updates for the file will be lost.\n"
+ },
+ {
+ "QUEUE",
+ handle_request_queue,
+ PRIV_LOW,
+ CMD_CONTEXT_CLIENT,
+ "QUEUE\n"
+ ,
+ "Shows all files in the output queue.\n"
+ "The output is zero or more lines in the following format:\n"
+ "(where <num_vals> is the number of values to be written)\n"
+ "\n"
+ "<num_vals> <filename>\n"
+ },
+ {
+ "STATS",
+ handle_request_stats,
+ PRIV_LOW,
+ CMD_CONTEXT_CLIENT,
+ "STATS\n"
+ ,
+ "Returns some performance counters, see the rrdcached(1) manpage for\n"
+ "a description of the values.\n"
+ },
+ {
+ "HELP",
+ handle_request_help,
+ PRIV_LOW,
+ CMD_CONTEXT_CLIENT,
+ "HELP [<command>]\n",
+ NULL, /* special! */
+ },
+ {
+ "BATCH",
+ batch_start,
+ PRIV_LOW,
+ CMD_CONTEXT_CLIENT,
+ "BATCH\n"
+ ,
+ "The 'BATCH' command permits the client to initiate a bulk load\n"
+ " of commands to rrdcached.\n"
+ "\n"
+ "Usage:\n"
+ "\n"
+ " client: BATCH\n"
+ " server: 0 Go ahead. End with dot '.' on its own line.\n"
+ " client: command #1\n"
+ " client: command #2\n"
+ " client: ... and so on\n"
+ " client: .\n"
+ " server: 2 errors\n"
+ " server: 7 message for command #7\n"
+ " server: 9 message for command #9\n"
+ "\n"
+ "For more information, consult the rrdcached(1) documentation.\n"
+ },
+ {
+ ".", /* BATCH terminator */
+ batch_done,
+ PRIV_LOW,
+ CMD_CONTEXT_BATCH,
+ NULL,
+ NULL
+ },
+ {
+ "QUIT",
+ handle_request_quit,
+ PRIV_LOW,
+ CMD_CONTEXT_CLIENT | CMD_CONTEXT_BATCH,
+ "QUIT\n"
+ ,
+ "Disconnect from rrdcached.\n"
+ },
+ {NULL,NULL,0,0,NULL,NULL} /* LAST ENTRY */
+};
+
+static struct command *find_command(char *cmd)
+{
+ struct command *c = COMMANDS;
+
+ while (c->cmd != NULL)
+ {
+ if (strcasecmp(cmd, c->cmd) == 0)
+ break;
+ c++;
+ }
+
+ if (c->cmd == NULL)
+ return NULL;
+ else
+ return c;
+}
+
+/* check whether commands are received in the expected context */
+static int command_check_context(listen_socket_t *sock, struct command *cmd)
+{
+ if (sock == NULL)
+ return (cmd->context & CMD_CONTEXT_JOURNAL);
+ else if (sock->batch_start)
+ return (cmd->context & CMD_CONTEXT_BATCH);
+ else
+ return (cmd->context & CMD_CONTEXT_CLIENT);
+
+ /* NOTREACHED */
+ assert(1==0);
+}
+
+static int handle_request_help (HANDLER_PROTO) /* {{{ */
+{
+ int status;
+ char *cmd_str;
+ char *resp_txt;
+ struct command *help = NULL;
+
+ status = buffer_get_field (&buffer, &buffer_size, &cmd_str);
+ if (status == 0)
+ help = find_command(cmd_str);
+
+ if (help && (help->syntax || help->help))
+ {
+ char tmp[CMD_MAX];
+
+ snprintf(tmp, sizeof(tmp)-1, "Help for %s\n", help->cmd);
+ resp_txt = tmp;
+
+ if (help->syntax)
+ add_response_info(sock, "Usage: %s\n", help->syntax);
+
+ if (help->help)
+ add_response_info(sock, "%s\n", help->help);
+ }
+ else
+ {
+ help = COMMANDS;
+ resp_txt = "Command overview\n";
+
+ while (help->cmd)
+ {
+ if (help->syntax)
+ add_response_info(sock, "%s", help->syntax);
+ help++;
+ }
+ }
+
+ return send_response(sock, RESP_OK, resp_txt);
+} /* }}} int handle_request_help */
+