From 015189b5df17d3572d27e850336e9d1c9dc83c6d Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 19 Jun 2009 12:40:23 -0400 Subject: Move SOCKS reason-decoding switches into reasons.c --- src/or/buffers.c | 49 ++----------------------------------------------- src/or/or.h | 2 ++ src/or/reasons.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/or/buffers.c b/src/or/buffers.c index 31725c5f2..ada8bddcb 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 930599267..f901121d5 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 a252f8319..5efb08bb4 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"; + } +} -- cgit v1.2.3