changeset 112:5403f0d2d692

Use common exit codepath.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 21 Jun 2014 22:58:31 +0300
parents cddfc43a4e45
children 059f48a04024
files th_network.c
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/th_network.c	Sat Jun 21 22:44:56 2014 +0300
+++ b/th_network.c	Sat Jun 21 22:58:31 2014 +0300
@@ -334,7 +334,7 @@
                 err = THERR_INVALID_DATA;
                 th_conn_err(conn, err,
                     "SOCKS 5 user authentication chosen, but no user/pass set.\n");
-                return err;
+                goto out;
             }
 
             userid_len = strlen(conn->proxy.userid);
@@ -344,7 +344,7 @@
                 err = THERR_INVALID_DATA;
                 th_conn_err(conn, err,
                     "SOCKS 5 proxy userid or password is too long.\n");
-                return err;
+                goto out;
             }
             break;
 
@@ -353,7 +353,7 @@
             th_conn_err(conn, err,
                 "Unsupported proxy authentication method %d.\n",
                 conn->proxy.auth_type);
-            return err;
+            goto out;
     }
 
     bufsiz = 2 + avail;
@@ -375,7 +375,7 @@
 
     // Send request
     if ((err = th_conn_proxy_send(conn, buf, bufsiz)) != THERR_OK)
-        return err;
+        goto out;
 
     // Wait for SOCKS server to reply
     if (th_conn_proxy_wait(conn) != TH_CONN_DATA_AVAIL)
@@ -387,7 +387,7 @@
         err = THERR_INVALID_DATA;
         th_conn_err(conn, err,
             "Invalid SOCKS 5 server reply, does not begin with protocol version byte (%d).\n", *ptr);
-        return err;
+        goto out;
     }
     ptr++;
     auth = *ptr;
@@ -397,7 +397,7 @@
         err = THERR_NOT_SUPPORTED;
         th_conn_err(conn, err,
             "No authentication method could be negotiated with the server.\n");
-        return err;
+        goto out;
     }
 
     if (auth == TH_SOCKS5_AUTH_USER)
@@ -419,7 +419,7 @@
 
         // Send request
         if ((err = th_conn_proxy_send(conn, buf, bufsiz)) != THERR_OK)
-            return err;
+            goto out;
 
         // Wait for SOCKS server to reply
         if (th_conn_proxy_wait(conn) != TH_CONN_DATA_AVAIL)
@@ -431,7 +431,7 @@
             err = THERR_INVALID_DATA;
             th_conn_err(conn, err,
                 "Invalid SOCKS 5 server reply, does not begin with protocol version byte (%d).\n", *ptr);
-            return err;
+            goto out;
         }
         ptr++;
         if (*ptr != 0)
@@ -439,7 +439,7 @@
             err = THERR_AUTH_FAILED;
             th_conn_err(conn, err,
                 "SOCKS 5 proxy user/pass authentication failed! Code %d.\n", *ptr);
-            return err;
+            goto out;
         }
     }
     else
@@ -449,7 +449,7 @@
         th_conn_err(conn, THERR_NOT_SUPPORTED,
             "Proxy server chose an unsupported SOCKS 5 authentication method %d.\n",
             auth);
-        return err;
+        goto out;
     }
 
 
@@ -477,7 +477,7 @@
 
     // Send request
     if ((err = th_conn_proxy_send(conn, buf, bufsiz)) != THERR_OK)
-        return err;
+        goto out;
 
     // Wait for SOCKS server to reply
     if (th_conn_proxy_wait(conn) != TH_CONN_DATA_AVAIL)
@@ -498,18 +498,20 @@
         else
             th_conn_err(conn, err ".Unknown\n");
 
-        return err;
+        goto out;
     }
     ptr++;
     if (*ptr != 0)
     {
         int err = asdf;
         th_conn_err(conn, err, ".\n");
-        return err;
+        goto out;
     }
 
 #endif
 
+out:
+
     return THERR_OK;
 }