Refactor to do CONF_CHANGED event formatting inside control.c

This commit is contained in:
Kamran Riaz Khan 2011-08-08 19:19:06 +05:00
parent 5a801a8c8b
commit 02c62b2966
3 changed files with 32 additions and 17 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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);