diff network.c @ 599:eeea75b8b6f3

Implement proxy user id setting.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 08 May 2014 16:14:09 +0300
parents 97a49a6cc959
children 4bae14092b78
line wrap: on
line diff
--- a/network.c	Mon Feb 10 22:59:13 2014 +0200
+++ b/network.c	Thu May 08 16:14:09 2014 +0300
@@ -142,7 +142,7 @@
 }
 
 
-int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host)
+int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, const char *userid)
 {
     if (conn == NULL)
         return -1;
@@ -150,6 +150,9 @@
     conn->proxy.type = type;
     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");
 
     if (host != NULL)
     {
@@ -166,7 +169,6 @@
 int nn_conn_open(nn_conn_t *conn, const int port, const char *host)
 {
     struct sockaddr_in dest;
-    static const char *userid = "James Bond";
 
     if (conn == NULL)
         return -1;
@@ -222,7 +224,7 @@
     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(userid) + 1;
+        size_t bufsiz = sizeof(struct nn_socks_t) + strlen(conn->proxy.userid) + 1;
         char *ptr, *buf;
         int tries, status = -1;
 
@@ -250,11 +252,11 @@
             socksh->addr = conn->addr.s_addr;
         ptr += sizeof(struct nn_socks_t);
 
-        strcpy(ptr, userid);
+        strcpy(ptr, conn->proxy.userid);
 
         if (conn->proxy.type == NN_PROXY_SOCKS4A)
         {
-            ptr += strlen(userid) + 1;
+            ptr += strlen(conn->proxy.userid) + 1;
             strcpy(ptr, conn->host);
         }