[or-cvs] [tor/master] Move SOCKS reason-decoding switches into reasons.c

Nick Mathewson nickm at seul.org
Wed Aug 26 15:34:35 UTC 2009


Author: Nick Mathewson <nickm at torproject.org>
Date: Fri, 19 Jun 2009 12:40:23 -0400
Subject: Move SOCKS reason-decoding switches into reasons.c
Commit: 015189b5df17d3572d27e850336e9d1c9dc83c6d

---
 src/or/buffers.c |   49 ++-----------------------------------------------
 src/or/or.h      |    2 ++
 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 31725c5..ada8bdd 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 9305992..f901121 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 a252f83..5efb08b 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";
+  }
+}
-- 
1.5.6.5




More information about the tor-commits mailing list