changeset 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 e661d7654e23
children 0a30bf8db004
files main.c network.c network.h
diffstat 3 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Tue May 20 00:09:45 2014 +0300
+++ b/main.c	Tue May 20 01:04:30 2014 +0300
@@ -63,6 +63,8 @@
 int     optUserColor = 0x000000;
 char    *optServer = "chat.newbienudes.com",
         *optProxyServer = NULL,
+        *optProxyUserID = NULL,
+        *optProxyPassword = NULL,
         *optUserName = NULL,
         *optUserNameCmd = NULL,
         *optUserNameEnc = NULL,
@@ -1869,6 +1871,10 @@
     th_cfg_add_string(&tmpcfg, "host", &optProxyServer, optProxyServer);
     th_cfg_add_comment(&tmpcfg, "Proxy port, 1080 is the standard SOCKS port");
     th_cfg_add_int(&tmpcfg, "port", &optProxyPort, optProxyPort);
+    th_cfg_add_comment(&tmpcfg, "Proxy user ID");
+    th_cfg_add_string(&tmpcfg, "userid", &optProxyUserID, optProxyUserID);
+//    th_cfg_add_comment(&tmpcfg, "Proxy password (only available for SOCKS 5)");
+//    th_cfg_add_string(&tmpcfg, "password", &optProxyPassword, optProxyPassword);
     th_cfg_add_section(&cfg, "proxy", tmpcfg);
 
 
@@ -2063,7 +2069,11 @@
     // Are we using a proxy?
     if (optProxyType != NN_PROXY_NONE && optProxyServer != NULL)
     {
-        if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer, NULL) != 0)
+        if (optProxyUserID == NULL)
+            optProxyUserID = "James Bond";
+
+        if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer,
+            optProxyUserID, optProxyPassword) != 0)
         {
             errorMsg("Error setting proxy information.\n");
             goto err_exit;
--- 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);
--- a/network.h	Tue May 20 00:09:45 2014 +0300
+++ b/network.h	Tue May 20 01:04:30 2014 +0300
@@ -81,7 +81,7 @@
         int type;
         int port;
         struct in_addr addr;
-        char *userid;
+        char *userid, *passwd;
     } proxy;
 
     char *host;
@@ -113,7 +113,7 @@
     void (*errfunc)(nn_conn_t *conn, const char *msg),
     void (*msgfunc)(nn_conn_t *conn, const char *msg));
 
-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);
 int         nn_conn_open(nn_conn_t *conn, const int port, const char *host);
 void        nn_conn_close(nn_conn_t *);
 void        nn_conn_reset(nn_conn_t *);