# HG changeset patch # User Matti Hamalainen # Date 1399554849 -10800 # Node ID eeea75b8b6f3dfcbdc659d5e9d488994800df75e # Parent 1e10031cf2d526beb4c7db1a9ab1d46ba3de18de Implement proxy user id setting. diff -r 1e10031cf2d5 -r eeea75b8b6f3 main.c --- a/main.c Mon Feb 10 22:59:13 2014 +0200 +++ b/main.c Thu May 08 16:14:09 2014 +0300 @@ -2062,7 +2062,7 @@ // Are we using a proxy? if (optProxyType != NN_PROXY_NONE && optProxyServer != NULL) { - if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer) != 0) + if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer, NULL) != 0) { errorMsg("Error setting proxy information.\n"); goto err_exit; diff -r 1e10031cf2d5 -r eeea75b8b6f3 network.c --- 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); } diff -r 1e10031cf2d5 -r eeea75b8b6f3 network.h --- a/network.h Mon Feb 10 22:59:13 2014 +0200 +++ b/network.h Thu May 08 16:14:09 2014 +0300 @@ -81,6 +81,7 @@ int type; int port; struct in_addr addr; + char *userid; } proxy; char *host; @@ -112,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); +int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, const char *userid); 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 *);