diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-06-19 12:40:23 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-06-19 12:40:23 -0400 |
commit | 015189b5df17d3572d27e850336e9d1c9dc83c6d (patch) | |
tree | cd09a5933e8b78da2657a2973ca6cab5dbc4acdf /src/or | |
parent | 75472c19c3fdcda913eb8117c917ddfd445b2b77 (diff) | |
download | tor-015189b5df17d3572d27e850336e9d1c9dc83c6d.tar.gz tor-015189b5df17d3572d27e850336e9d1c9dc83c6d.zip |
Move SOCKS reason-decoding switches into reasons.c
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/buffers.c | 49 | ||||
-rw-r--r-- | src/or/or.h | 2 | ||||
-rw-r--r-- | src/or/reasons.c | 43 |
3 files changed, 47 insertions, 47 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 31725c5f27..ada8bddcb9 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -1641,22 +1641,7 @@ fetch_from_buf_socks_client(buf_t *buf, int state, char **reason) return 0; if (data[1] != 0x5a) { - switch (data[1]) { - case 0x5b: - *reason = tor_strdup("server rejected connection"); - break; - case 0x5c: - *reason = tor_strdup("server cannot connect to identd " - "on this client"); - break; - case 0x5d: - *reason = tor_strdup("user id does not match identd"); - break; - default: - *reason = tor_strdup("invalid SOCKS 4 response code"); - break; - } - + *reason = tor_strdup(socks4_response_code_to_string(data[1])); return -1; } @@ -1738,37 +1723,7 @@ fetch_from_buf_socks_client(buf_t *buf, int state, char **reason) return 0; if (data[1] != 0x00) { - - switch (data[1]) { - case 0x01: - *reason = tor_strdup("general SOCKS server failure"); - break; - case 0x02: - *reason = tor_strdup("connection not allowed by ruleset"); - break; - case 0x03: - *reason = tor_strdup("Network unreachable"); - break; - case 0x04: - *reason = tor_strdup("Host unreachable"); - break; - case 0x05: - *reason = tor_strdup("Connection refused"); - break; - case 0x06: - *reason = tor_strdup("TTL expired"); - break; - case 0x07: - *reason = tor_strdup("Command not supported"); - break; - case 0x08: - *reason = tor_strdup("Address type not supported"); - break; - default: - *reason = tor_strdup("unknown reason"); - break; - } - + *reason = tor_strdup(socks5_response_code_to_string(data[1])); return -1; } diff --git a/src/or/or.h b/src/or/or.h index 930599267f..f901121d53 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -3930,6 +3930,8 @@ int tls_error_to_orconn_end_reason(int e); int errno_to_orconn_end_reason(int e); const char *circuit_end_reason_to_control_string(int reason); +const char *socks4_response_code_to_string(uint8_t code); +const char *socks5_response_code_to_string(uint8_t code); /********************************* relay.c ***************************/ diff --git a/src/or/reasons.c b/src/or/reasons.c index a252f83198..5efb08bb41 100644 --- a/src/or/reasons.c +++ b/src/or/reasons.c @@ -326,3 +326,46 @@ circuit_end_reason_to_control_string(int reason) } } +const char * +socks4_response_code_to_string(uint8_t code) +{ + switch (code) { + case 0x5a: + return "connection accepted"; + case 0x5b: + return "server rejected connection"; + case 0x5c: + return "server cannot connect to identd on this client"; + case 0x5d: + return "user id does not match identd"; + default: + return "invalid SOCKS 4 response code"; + } +} + +const char * +socks5_response_code_to_string(uint8_t code) +{ + switch (code) { + case 0x00: + return "connection accepted"; + case 0x01: + return "general SOCKS server failure"; + case 0x02: + return "connection not allowed by ruleset"; + case 0x03: + return "Network unreachable"; + case 0x04: + return "Host unreachable"; + case 0x05: + return "Connection refused"; + case 0x06: + return "TTL expired"; + case 0x07: + return "Command not supported"; + case 0x08: + return "Address type not supported"; + default: + return "unknown reason"; + } +} |