r12229@catbus: nickm | 2007-03-17 17:20:28 -0400

Add a warning when using obsolete "GUARDS" event.  Also, remove obsolete "if (1) {}"s from control.c: big patch, mostly just dedenting block contents.


svn:r9865
This commit is contained in:
Nick Mathewson 2007-03-17 21:34:37 +00:00
parent c50cf094b1
commit d787ef906a

View File

@ -631,9 +631,9 @@ control_setconf_helper(control_connection_t *conn, uint32_t len, char *body,
char *errstring = NULL;
const int clear_first = 1;
if (1) {
char *config;
smartlist_t *entries = smartlist_create();
/* We have a string, "body", of the format '(key(=val|="val")?)' entries
* separated by space. break it into a list of configuration entries. */
while (*body) {
@ -690,7 +690,6 @@ control_setconf_helper(control_connection_t *conn, uint32_t len, char *body,
return 0;
}
tor_free(config);
}
if ((r=options_trial_assign(lines, use_defaults,
clear_first, &errstring)) < 0) {
@ -753,6 +752,7 @@ handle_control_getconf(control_connection_t *conn, uint32_t body_len,
char *msg = NULL;
size_t msg_len;
or_options_t *options = get_options();
int i, len;
questions = smartlist_create();
(void) body_len; /* body is nul-terminated; so we can ignore len. */
@ -791,8 +791,6 @@ handle_control_getconf(control_connection_t *conn, uint32_t body_len,
}
});
if (1) {
int i,len;
if ((len = smartlist_len(unrecognized))) {
for (i=0; i < len-1; ++i)
connection_printf_to_buf(conn,
@ -810,7 +808,6 @@ handle_control_getconf(control_connection_t *conn, uint32_t body_len,
} else {
connection_write_str_to_buf("250 OK\r\n", conn);
}
}
if (answers) {
SMARTLIST_FOREACH(answers, char *, cp, tor_free(cp));
@ -835,10 +832,10 @@ handle_control_setevents(control_connection_t *conn, uint32_t len,
uint16_t event_code;
uint32_t event_mask = 0;
unsigned int extended = 0;
smartlist_t *events = smartlist_create();
(void) len;
if (1) {
smartlist_t *events = smartlist_create();
smartlist_split_string(events, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
SMARTLIST_FOREACH(events, const char *, ev,
@ -884,6 +881,8 @@ handle_control_setevents(control_connection_t *conn, uint32_t len,
event_code = EVENT_GUARD;
else if (!strcasecmp(ev, "GUARDS")) {
/* XXX tolerate buggy spec in 0.1.2.5-alpha through 0.1.2.10-rc */
log_warn(LD_CONTROL, "Controller used obsolete 'GUARDS' event name; "
"use GUARD instead.");
event_code = EVENT_GUARD;
} else if (!strcasecmp(ev, "STREAM_BW"))
event_code = EVENT_STREAM_BANDWIDTH_USED;
@ -898,7 +897,7 @@ handle_control_setevents(control_connection_t *conn, uint32_t len,
});
SMARTLIST_FOREACH(events, char *, e, tor_free(e));
smartlist_free(events);
}
conn->event_mask = event_mask;
if (extended)
conn->use_extended_events = 1;
@ -946,7 +945,7 @@ handle_control_authenticate(control_connection_t *conn, uint32_t len,
const char *errstr = NULL;
char *password;
size_t password_len;
if (1) {
if (TOR_ISXDIGIT(body[0])) {
int i = 0;
while (TOR_ISXDIGIT(body[i]))
@ -972,7 +971,7 @@ handle_control_authenticate(control_connection_t *conn, uint32_t len,
}
used_quoted_string = 1;
}
}
if (options->CookieAuthentication && authentication_cookie_is_set) {
if (password_len != AUTHENTICATION_COOKIE_LEN) {
log_warn(LD_CONTROL, "Got authentication cookie with wrong length (%d)",
@ -1053,11 +1052,11 @@ handle_control_signal(control_connection_t *conn, uint32_t len,
const char *body)
{
int sig;
(void) len;
if (1) {
int n = 0;
char *s;
(void) len;
while (body[n] && ! TOR_ISSPACE(body[n]))
++n;
s = tor_strndup(body, n);
@ -1083,7 +1082,6 @@ handle_control_signal(control_connection_t *conn, uint32_t len,
tor_free(s);
if (sig<0)
return 0;
}
/* Send DONE first, in case the signal makes us shut down. */
send_control_done(conn);
@ -1160,7 +1158,6 @@ handle_control_mapaddress(control_connection_t *conn, uint32_t len,
smartlist_free(lines);
smartlist_free(elts);
if (1) {
if (smartlist_len(reply)) {
((char*)smartlist_get(reply,smartlist_len(reply)-1))[3] = ' ';
r = smartlist_join_strings(reply, "\r\n", 1, &sz);
@ -1171,7 +1168,6 @@ handle_control_mapaddress(control_connection_t *conn, uint32_t len,
"512 syntax error: not enough arguments to mapaddress.\r\n";
connection_write_to_buf(response, strlen(response), TO_CONN(conn));
}
}
SMARTLIST_FOREACH(reply, char *, cp, tor_free(cp));
smartlist_free(reply);
@ -1618,6 +1614,7 @@ handle_control_getinfo(control_connection_t *conn, uint32_t len,
smartlist_t *answers = NULL;
smartlist_t *unrecognized = NULL;
char *msg = NULL, *ans = NULL;
int i;
(void) len; /* body is nul-terminated, so it's safe to ignore the length. */
questions = smartlist_create();
@ -1650,8 +1647,6 @@ handle_control_getinfo(control_connection_t *conn, uint32_t len,
goto done;
}
if (1) {
int i;
for (i = 0; i < smartlist_len(answers); i += 2) {
char *k = smartlist_get(answers, i);
char *v = smartlist_get(answers, i+1);
@ -1669,7 +1664,6 @@ handle_control_getinfo(control_connection_t *conn, uint32_t len,
}
}
connection_write_str_to_buf("250 OK\r\n", conn);
}
done:
if (answers) {
@ -1721,12 +1715,11 @@ handle_control_extendcircuit(control_connection_t *conn, uint32_t len,
origin_circuit_t *circ = NULL;
int zero_circ;
uint8_t intended_purpose = CIRCUIT_PURPOSE_C_GENERAL;
smartlist_t *args;
(void) len;
router_nicknames = smartlist_create();
if (1) {
smartlist_t *args;
args = smartlist_create();
smartlist_split_string(args, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@ -1759,7 +1752,6 @@ handle_control_extendcircuit(control_connection_t *conn, uint32_t len,
if (!zero_circ && !circ) {
goto done;
}
}
routers = smartlist_create();
SMARTLIST_FOREACH(router_nicknames, const char *, n,
@ -1887,10 +1879,9 @@ handle_control_attachstream(control_connection_t *conn, uint32_t len,
edge_connection_t *ap_conn = NULL;
origin_circuit_t *circ = NULL;
int zero_circ;
smartlist_t *args;
(void) len;
if (1) {
smartlist_t *args;
args = smartlist_create();
smartlist_split_string(args, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@ -1915,7 +1906,6 @@ handle_control_attachstream(control_connection_t *conn, uint32_t len,
smartlist_free(args);
if (!ap_conn || (!zero_circ && !circ))
return 0;
}
if (ap_conn->_base.state != AP_CONN_STATE_CONTROLLER_WAIT &&
ap_conn->_base.state != AP_CONN_STATE_CONNECT_WAIT &&
@ -1968,7 +1958,6 @@ handle_control_postdescriptor(control_connection_t *conn, uint32_t len,
const char *msg=NULL;
uint8_t purpose = ROUTER_PURPOSE_GENERAL;
if (1) {
char *cp = memchr(body, '\n', len);
smartlist_t *args = smartlist_create();
tor_assert(cp);
@ -1988,7 +1977,6 @@ handle_control_postdescriptor(control_connection_t *conn, uint32_t len,
SMARTLIST_FOREACH(args, char *, cp, tor_free(cp));
smartlist_free(args);
read_escaped_data(cp, len-(cp-body), 1, &desc);
}
switch (router_load_single_router(desc, purpose, &msg)) {
case -1:
@ -2017,10 +2005,9 @@ handle_control_redirectstream(control_connection_t *conn, uint32_t len,
edge_connection_t *ap_conn = NULL;
char *new_addr = NULL;
uint16_t new_port = 0;
smartlist_t *args;
(void) len;
if (1) {
smartlist_t *args;
args = smartlist_create();
smartlist_split_string(args, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@ -2049,7 +2036,6 @@ handle_control_redirectstream(control_connection_t *conn, uint32_t len,
smartlist_free(args);
if (!new_addr)
return 0;
}
strlcpy(ap_conn->socks_request->address, new_addr,
sizeof(ap_conn->socks_request->address));
@ -2068,11 +2054,10 @@ handle_control_closestream(control_connection_t *conn, uint32_t len,
{
edge_connection_t *ap_conn=NULL;
uint8_t reason=0;
(void) len;
if (1) {
smartlist_t *args;
int ok;
(void) len;
args = smartlist_create();
smartlist_split_string(args, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@ -2095,7 +2080,6 @@ handle_control_closestream(control_connection_t *conn, uint32_t len,
smartlist_free(args);
if (!ap_conn)
return 0;
}
connection_mark_unattached_ap(ap_conn, reason);
send_control_done(conn);
@ -2110,10 +2094,9 @@ handle_control_closecircuit(control_connection_t *conn, uint32_t len,
{
origin_circuit_t *circ = NULL;
int safe = 0;
smartlist_t *args;
(void) len;
if (1) {
smartlist_t *args;
args = smartlist_create();
smartlist_split_string(args, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@ -2137,7 +2120,6 @@ handle_control_closecircuit(control_connection_t *conn, uint32_t len,
smartlist_free(args);
if (!circ)
return 0;
}
if (!safe || !circ->p_streams) {
circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_REQUESTED);
@ -2437,6 +2419,9 @@ int
control_event_circuit_status(origin_circuit_t *circ, circuit_status_event_t tp,
int reason_code)
{
const char *status;
char reason_buf[64];
int providing_reason=0;
char *path=NULL;
if (!EVENT_IS_INTERESTING(EVENT_CIRCUIT_STATUS))
return 0;
@ -2445,10 +2430,6 @@ control_event_circuit_status(origin_circuit_t *circ, circuit_status_event_t tp,
if (EVENT_IS_INTERESTING1S(EVENT_CIRCUIT_STATUS))
path = circuit_list_path(circ,0);
if (1) {
const char *status;
char reason_buf[64];
int providing_reason=0;
switch (tp)
{
case CIRC_EVENT_LAUNCHED: status = "LAUNCHED"; break;
@ -2508,7 +2489,7 @@ control_event_circuit_status(origin_circuit_t *circ, circuit_status_event_t tp,
status, sp, vpath);
tor_free(vpath);
}
}
tor_free(path);
return 0;
@ -2570,6 +2551,10 @@ int
control_event_stream_status(edge_connection_t *conn, stream_status_event_t tp,
int reason_code)
{
char reason_buf[64];
const char *status;
circuit_t *circ;
origin_circuit_t *origin_circ = NULL;
char buf[256];
tor_assert(conn->socks_request);
@ -2582,11 +2567,6 @@ control_event_stream_status(edge_connection_t *conn, stream_status_event_t tp,
write_stream_target_to_buf(conn, buf, sizeof(buf));
if (1) {
char reason_buf[64];
const char *status;
circuit_t *circ;
origin_circuit_t *origin_circ = NULL;
reason_buf[0] = '\0';
switch (tp)
{
@ -2644,7 +2624,7 @@ control_event_stream_status(edge_connection_t *conn, stream_status_event_t tp,
(unsigned long)origin_circ->global_identifier : 0ul,
buf, reason_buf);
/* XXX need to specify its intended exit, etc? */
}
return 0;
}
@ -2742,14 +2722,13 @@ control_event_or_conn_status(or_connection_t *conn, or_conn_status_event_t tp,
int reason)
{
int ncircs = 0;
const char *status;
char name[128];
char ncircs_buf[32] = {0}; /* > 8 + log10(2^32)=10 + 2 */
if (!EVENT_IS_INTERESTING(EVENT_OR_CONN_STATUS))
return 0;
if (1) {
const char *status;
char name[128];
char ncircs_buf[32] = {0}; /* > 8 + log10(2^32)=10 + 2 */
switch (tp)
{
case OR_CONN_EVENT_LAUNCHED: status = "LAUNCHED"; break;
@ -2782,7 +2761,7 @@ control_event_or_conn_status(or_connection_t *conn, or_conn_status_event_t tp,
name, status,
or_conn_end_reason_to_string(reason), ncircs_buf);
}
}
return 0;
}