diff options
author | Kamran Riaz Khan <krkhan@inspirated.com> | 2011-08-08 19:19:06 +0500 |
---|---|---|
committer | Kamran Riaz Khan <krkhan@inspirated.com> | 2011-08-08 19:19:06 +0500 |
commit | 02c62b2966083ce549fc6ba6c743d5c37f357fe6 (patch) | |
tree | 44682b820c830dac91db04cbb9200df866553034 /src/or | |
parent | 5a801a8c8b71c9551a80913398135809cb10cecd (diff) | |
download | tor-02c62b2966083ce549fc6ba6c743d5c37f357fe6.tar.gz tor-02c62b2966083ce549fc6ba6c743d5c37f357fe6.zip |
Refactor to do CONF_CHANGED event formatting inside control.c
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/config.c | 17 | ||||
-rw-r--r-- | src/or/control.c | 30 | ||||
-rw-r--r-- | src/or/control.h | 2 |
3 files changed, 32 insertions, 17 deletions
diff --git a/src/or/config.c b/src/or/config.c index 653e23dca7..02dc7eba5a 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -10,7 +10,6 @@ **/ #define CONFIG_PRIVATE -#define CONTROL_PRIVATE #include "or.h" #include "circuitbuild.h" @@ -695,7 +694,6 @@ int set_options(or_options_t *new_val, char **msg) { int i; - char *result; smartlist_t *elements; config_line_t *line; or_options_t *old_options = global_options; @@ -724,21 +722,16 @@ set_options(or_options_t *new_val, char **msg) if (line) { for (; line; line = line->next) { - char *tmp; - tor_asprintf(&tmp, "650-%s=%s", line->key, line->value); - smartlist_add(elements, tmp); + smartlist_add(elements, line->key); + smartlist_add(elements, line->value); } } else { - char *tmp; - tor_asprintf(&tmp, "650-%s", options_format.vars[i].name); - smartlist_add(elements, tmp); + smartlist_add(elements, options_format.vars[i].name); + smartlist_add(elements, NULL); } } } - result = smartlist_join_strings(elements, "\r\n", 0, NULL); - control_event_conf_changed(result); - tor_free(result); - SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp)); + control_event_conf_changed(elements); smartlist_free(elements); } config_free(&options_format, old_options); diff --git a/src/or/control.c b/src/or/control.c index 0b19a25d99..05797038de 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -4002,12 +4002,34 @@ control_event_guard(const char *nickname, const char *digest, * by SETCONF requests and RELOAD/SIGHUP signals. The <b>values</b> are the * keyword/value pairs for the configuration changes tor is using. */ int -control_event_conf_changed(const char *values) +control_event_conf_changed(smartlist_t *elements) { - if(strlen(values) > 0) { - send_control_event(EVENT_CONF_CHANGED, 0, - "650-CONF_CHANGED\r\n%s\r\n650 OK\r\n", values); + int i; + char *result; + smartlist_t *lines; + if (smartlist_len(elements) == 0) { + return 0; } + lines = smartlist_create(); + for (i = 0; i < smartlist_len(elements); i += 2) { + char *k = smartlist_get(elements, i); + char *v = smartlist_get(elements, i+1); + if (v == NULL) { + char *tmp; + tor_asprintf(&tmp, "650-%s", k); + smartlist_add(lines, tmp); + } else { + char *tmp; + tor_asprintf(&tmp, "650-%s=%s", k, v); + smartlist_add(lines, tmp); + } + } + result = smartlist_join_strings(lines, "\r\n", 0, NULL); + send_control_event(EVENT_CONF_CHANGED, 0, + "650-CONF_CHANGED\r\n%s\r\n650 OK\r\n", result); + tor_free(result); + SMARTLIST_FOREACH(lines, char *, cp, tor_free(cp)); + smartlist_free(lines); return 0; } diff --git a/src/or/control.h b/src/or/control.h index ed83f53ac4..544a9fcc9e 100644 --- a/src/or/control.h +++ b/src/or/control.h @@ -66,7 +66,7 @@ int control_event_server_status(int severity, const char *format, ...) CHECK_PRINTF(2,3); int control_event_guard(const char *nickname, const char *digest, const char *status); -int control_event_conf_changed(const char *values); +int control_event_conf_changed(smartlist_t *elements); int control_event_buildtimeout_set(const circuit_build_times_t *cbt, buildtimeout_set_event_t type); int control_event_signal(uintptr_t signal); |