diff network.c @ 602:4bae14092b78

Add parameters (unused for now) for proxy password etc. in case SOCKS 5 support is ever added.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 20 May 2014 01:04:30 +0300
parents eeea75b8b6f3
children 37ab4725e4f9
line wrap: on
line diff
--- a/network.c	Tue May 20 00:09:45 2014 +0300
+++ b/network.c	Tue May 20 01:04:30 2014 +0300
@@ -142,7 +142,7 @@
 }
 
 
-int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, const char *userid)
+int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, const char *userid, const char *passwd)
 {
     if (conn == NULL)
         return -1;
@@ -151,8 +151,7 @@
     conn->proxy.port = port;
     conn->proxy.host = th_strdup(host);
     conn->proxy.userid = th_strdup(userid);
-    if (conn->proxy.userid == NULL)
-        conn->proxy.userid = th_strdup("James Bond");
+    conn->proxy.passwd = th_strdup(passwd);
 
     if (host != NULL)
     {
@@ -224,12 +223,13 @@
     if (conn->proxy.type == NN_PROXY_SOCKS4 || conn->proxy.type == NN_PROXY_SOCKS4A)
     {
         struct nn_socks_t *socksh;
-        size_t bufsiz = sizeof(struct nn_socks_t) + strlen(conn->proxy.userid) + 1;
+        size_t bufsiz;
         char *ptr, *buf;
         int tries, status = -1;
 
         nn_conn_msg(conn, "Initializing proxy negotiation.\n");
 
+        bufsiz = sizeof(struct nn_socks_t) + strlen(conn->proxy.userid) + 1;
         if (conn->proxy.type == NN_PROXY_SOCKS4A)
             bufsiz += strlen(conn->host) + 1;
 
@@ -245,11 +245,8 @@
         socksh = (struct nn_socks_t *) buf;
         socksh->version = 4;
         socksh->command = SOCKS_CMD_CONNECT;
-        socksh->port = htons(port);
-        if (conn->proxy.type == NN_PROXY_SOCKS4A)
-            socksh->addr = htonl(0x00000032);
-        else
-            socksh->addr = conn->addr.s_addr;
+        socksh->port    = htons(port);
+        socksh->addr    = (conn->proxy.type == NN_PROXY_SOCKS4A) ?  htonl(0x00000032) : conn->addr.s_addr;
         ptr += sizeof(struct nn_socks_t);
 
         strcpy(ptr, conn->proxy.userid);