Permalink
Browse files

Moved adhoc commands to their own file.

  • Loading branch information...
1 parent e097ba2 commit efeb47c057afa1447f867daec18995dbbd77ca89 @dustin dustin committed Jun 18, 2009
Showing with 155 additions and 142 deletions.
  1. +1 −1 Makefile.am
  2. +150 −0 adhoc_commands.c
  3. +3 −0 conflate_internal.h
  4. +1 −141 xmpp.c
View
@@ -12,7 +12,7 @@ examples_bot_LDADD = -L. -lconflate @PROFILER_LDFLAGS@
libconflate_a_CFLAGS = @PROFILER_FLAGS@
libconflate_a_SOURCES = conflate.h conflate_internal.h conflate_convenience.h \
- kvpair.c util.c persist.c xmpp.c logging.c
+ kvpair.c util.c persist.c xmpp.c logging.c adhoc_commands.c
.PHONY: docs
docs:
View
@@ -0,0 +1,150 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <assert.h>
+
+#include "conflate.h"
+#include "conflate_internal.h"
+#include "conflate_convenience.h"
+
+bool commands_initialized = false;
+
+static enum conflate_mgmt_cb_result process_serverlist(void *opaque,
+ conflate_handle_t *handle,
+ const char *cmd,
+ bool direct,
+ kvpair_t *conf,
+ conflate_form_result *r)
+{
+ /* If we have "config_is_private" set to "yes" we should only
+ process this if it's direct (i.e. ignore pubsub) */
+ if (!direct) {
+ char *priv = conflate_get_private(handle, "config_is_private",
+ handle->conf->save_path);
+
+ if (priv && strcmp(priv, "yes") == 0) {
+ CONFLATE_LOG(handle, INFO,
+ "Currently using a private config, ignoring update.");
+ return RV_OK;
+ }
+ free(priv);
+ }
+
+ CONFLATE_LOG(handle, INFO, "Processing a serverlist");
+
+ /* Persist the config lists */
+ if (!save_kvpairs(handle, conf, handle->conf->save_path)) {
+ CONFLATE_LOG(handle, ERROR, "Can not save config to %s",
+ handle->conf->save_path);
+ }
+
+ /* Send the config to the callback */
+ handle->conf->new_config(handle->conf->userdata, conf);
+
+ return RV_OK;
+}
+
+static enum conflate_mgmt_cb_result process_set_private(void *opaque,
+ conflate_handle_t *handle,
+ const char *cmd,
+ bool direct,
+ kvpair_t *form,
+ conflate_form_result *r)
+{
+ /* Only direct stat requests are handled. */
+ assert(direct);
+ enum conflate_mgmt_cb_result rv = RV_ERROR;
+
+ char *key = get_simple_kvpair_val(form, "key");
+ char *value = get_simple_kvpair_val(form, "value");
+
+ if (key && value) {
+ if (conflate_save_private(handle, key, value,
+ handle->conf->save_path)) {
+ rv = RV_OK;
+ }
+ } else {
+ rv = RV_BADARG;
+ }
+
+ return rv;
+}
+
+static enum conflate_mgmt_cb_result process_get_private(void *opaque,
+ conflate_handle_t *handle,
+ const char *cmd,
+ bool direct,
+ kvpair_t *form,
+ conflate_form_result *r)
+{
+ /* Only direct stat requests are handled. */
+ assert(direct);
+ enum conflate_mgmt_cb_result rv = RV_ERROR;
+
+ char *key = get_simple_kvpair_val(form, "key");
+
+ if (key) {
+ /* Initialize the form so there's always one there */
+ conflate_init_form(r);
+ char *value = conflate_get_private(handle, key,
+ handle->conf->save_path);
+ if (value) {
+ conflate_add_field(r, key, value);
+ free(value);
+ }
+
+ rv = RV_OK;
+ } else {
+ rv = RV_BADARG;
+ }
+
+ return rv;
+}
+
+static enum conflate_mgmt_cb_result process_delete_private(void *opaque,
+ conflate_handle_t *handle,
+ const char *cmd,
+ bool direct,
+ kvpair_t *form,
+ conflate_form_result *r)
+{
+ /* Only direct stat requests are handled. */
+ assert(direct);
+ enum conflate_mgmt_cb_result rv = RV_ERROR;
+
+ char *key = get_simple_kvpair_val(form, "key");
+
+ if (key) {
+ if (conflate_delete_private(handle, key,
+ handle->conf->save_path)) {
+ rv = RV_OK;
+ }
+ } else {
+ rv = RV_BADARG;
+ }
+
+ return rv;
+}
+
+void conflate_init_commands(void)
+{
+ if (commands_initialized) {
+ return;
+ }
+
+ conflate_register_mgmt_cb("set_private",
+ "Set a private value on the agent.",
+ process_set_private);
+ conflate_register_mgmt_cb("get_private",
+ "Get a private value from the agent.",
+ process_get_private);
+ conflate_register_mgmt_cb("rm_private",
+ "Delete a private value from the agent.",
+ process_delete_private);
+
+ conflate_register_mgmt_cb("serverlist", "Configure a server list.",
+ process_serverlist);
+
+ commands_initialized = true;
+}
View
@@ -9,3 +9,6 @@ struct _conflate_handle {
pthread_t thread;
};
+
+void conflate_init_commands(void);
+
View
142 xmpp.c
@@ -30,7 +30,6 @@ struct command_def {
struct command_def *next;
};
-bool commands_initialized = false;
struct command_def *commands = NULL;
void conflate_register_mgmt_cb(const char *cmd, const char *desc,
@@ -219,41 +218,6 @@ static kvpair_t *grok_form(xmpp_stanza_t *fields)
return rv;
}
-static enum conflate_mgmt_cb_result process_serverlist(void *opaque,
- conflate_handle_t *handle,
- const char *cmd,
- bool direct,
- kvpair_t *conf,
- conflate_form_result *r)
-{
- /* If we have "config_is_private" set to "yes" we should only
- process this if it's direct (i.e. ignore pubsub) */
- if (!direct) {
- char *priv = conflate_get_private(handle, "config_is_private",
- handle->conf->save_path);
-
- if (priv && strcmp(priv, "yes") == 0) {
- CONFLATE_LOG(handle, INFO,
- "Currently using a private config, ignoring update.");
- return RV_OK;
- }
- free(priv);
- }
-
- CONFLATE_LOG(handle, INFO, "Processing a serverlist");
-
- /* Persist the config lists */
- if (!save_kvpairs(handle, conf, handle->conf->save_path)) {
- CONFLATE_LOG(handle, ERROR, "Can not save config to %s",
- handle->conf->save_path);
- }
-
- /* Send the config to the callback */
- handle->conf->new_config(handle->conf->userdata, conf);
-
- return RV_OK;
-}
-
static void add_form_values(xmpp_ctx_t* ctx, xmpp_stanza_t *parent,
const char *key, const char **values)
{
@@ -374,88 +338,6 @@ void conflate_next_fieldset(conflate_form_result *r)
add_and_release(r->container, r->current);
}
-static enum conflate_mgmt_cb_result process_set_private(void *opaque,
- conflate_handle_t *handle,
- const char *cmd,
- bool direct,
- kvpair_t *form,
- conflate_form_result *r)
-{
- /* Only direct stat requests are handled. */
- assert(direct);
- enum conflate_mgmt_cb_result rv = RV_ERROR;
-
- char *key = get_simple_kvpair_val(form, "key");
- char *value = get_simple_kvpair_val(form, "value");
-
- if (key && value) {
- if (conflate_save_private(handle, key, value,
- handle->conf->save_path)) {
- rv = RV_OK;
- }
- } else {
- rv = RV_BADARG;
- }
-
- return rv;
-}
-
-static enum conflate_mgmt_cb_result process_get_private(void *opaque,
- conflate_handle_t *handle,
- const char *cmd,
- bool direct,
- kvpair_t *form,
- conflate_form_result *r)
-{
- /* Only direct stat requests are handled. */
- assert(direct);
- enum conflate_mgmt_cb_result rv = RV_ERROR;
-
- char *key = get_simple_kvpair_val(form, "key");
-
- if (key) {
- /* Initialize the form so there's always one there */
- conflate_init_form(r);
- char *value = conflate_get_private(handle, key,
- handle->conf->save_path);
- if (value) {
- conflate_add_field(r, key, value);
- free(value);
- }
-
- rv = RV_OK;
- } else {
- rv = RV_BADARG;
- }
-
- return rv;
-}
-
-static enum conflate_mgmt_cb_result process_delete_private(void *opaque,
- conflate_handle_t *handle,
- const char *cmd,
- bool direct,
- kvpair_t *form,
- conflate_form_result *r)
-{
- /* Only direct stat requests are handled. */
- assert(direct);
- enum conflate_mgmt_cb_result rv = RV_ERROR;
-
- char *key = get_simple_kvpair_val(form, "key");
-
- if (key) {
- if (conflate_delete_private(handle, key,
- handle->conf->save_path)) {
- rv = RV_OK;
- }
- } else {
- rv = RV_BADARG;
- }
-
- return rv;
-}
-
static char* cb_name(enum conflate_mgmt_cb_result r)
{
char *rv = "UNKNOWN";
@@ -813,36 +695,14 @@ conflate_config_t* dup_conf(conflate_config_t c) {
return rv;
}
-static void init_commands(void)
-{
- if (commands_initialized) {
- return;
- }
-
- conflate_register_mgmt_cb("set_private",
- "Set a private value on the agent.",
- process_set_private);
- conflate_register_mgmt_cb("get_private",
- "Get a private value from the agent.",
- process_get_private);
- conflate_register_mgmt_cb("rm_private",
- "Delete a private value from the agent.",
- process_delete_private);
-
- conflate_register_mgmt_cb("serverlist", "Configure a server list.",
- process_serverlist);
-
- commands_initialized = true;
-}
-
void init_conflate(conflate_config_t *conf)
{
assert(conf);
memset(conf, 0x00, sizeof(conflate_config_t));
conf->log = conflate_syslog_logger;
conf->initialization_marker = (void*)INITIALIZATION_MAGIC;
- init_commands();
+ conflate_init_commands();
}
bool start_conflate(conflate_config_t conf) {

0 comments on commit efeb47c

Please sign in to comment.