comparison 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
comparison
equal deleted inserted replaced
598:1e10031cf2d5 599:eeea75b8b6f3
140 return FALSE; 140 return FALSE;
141 } 141 }
142 } 142 }
143 143
144 144
145 int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host) 145 int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, const char *userid)
146 { 146 {
147 if (conn == NULL) 147 if (conn == NULL)
148 return -1; 148 return -1;
149 149
150 conn->proxy.type = type; 150 conn->proxy.type = type;
151 conn->proxy.port = port; 151 conn->proxy.port = port;
152 conn->proxy.host = th_strdup(host); 152 conn->proxy.host = th_strdup(host);
153 conn->proxy.userid = th_strdup(userid);
154 if (conn->proxy.userid == NULL)
155 conn->proxy.userid = th_strdup("James Bond");
153 156
154 if (host != NULL) 157 if (host != NULL)
155 { 158 {
156 conn->proxy.hst = nn_resolve_host(conn, host); 159 conn->proxy.hst = nn_resolve_host(conn, host);
157 nn_get_addr(&(conn->proxy.addr), conn->proxy.hst); 160 nn_get_addr(&(conn->proxy.addr), conn->proxy.hst);
164 167
165 168
166 int nn_conn_open(nn_conn_t *conn, const int port, const char *host) 169 int nn_conn_open(nn_conn_t *conn, const int port, const char *host)
167 { 170 {
168 struct sockaddr_in dest; 171 struct sockaddr_in dest;
169 static const char *userid = "James Bond";
170 172
171 if (conn == NULL) 173 if (conn == NULL)
172 return -1; 174 return -1;
173 175
174 conn->port = port; 176 conn->port = port;
220 222
221 // Proxy-specific setup 223 // Proxy-specific setup
222 if (conn->proxy.type == NN_PROXY_SOCKS4 || conn->proxy.type == NN_PROXY_SOCKS4A) 224 if (conn->proxy.type == NN_PROXY_SOCKS4 || conn->proxy.type == NN_PROXY_SOCKS4A)
223 { 225 {
224 struct nn_socks_t *socksh; 226 struct nn_socks_t *socksh;
225 size_t bufsiz = sizeof(struct nn_socks_t) + strlen(userid) + 1; 227 size_t bufsiz = sizeof(struct nn_socks_t) + strlen(conn->proxy.userid) + 1;
226 char *ptr, *buf; 228 char *ptr, *buf;
227 int tries, status = -1; 229 int tries, status = -1;
228 230
229 nn_conn_msg(conn, "Initializing proxy negotiation.\n"); 231 nn_conn_msg(conn, "Initializing proxy negotiation.\n");
230 232
248 socksh->addr = htonl(0x00000032); 250 socksh->addr = htonl(0x00000032);
249 else 251 else
250 socksh->addr = conn->addr.s_addr; 252 socksh->addr = conn->addr.s_addr;
251 ptr += sizeof(struct nn_socks_t); 253 ptr += sizeof(struct nn_socks_t);
252 254
253 strcpy(ptr, userid); 255 strcpy(ptr, conn->proxy.userid);
254 256
255 if (conn->proxy.type == NN_PROXY_SOCKS4A) 257 if (conn->proxy.type == NN_PROXY_SOCKS4A)
256 { 258 {
257 ptr += strlen(userid) + 1; 259 ptr += strlen(conn->proxy.userid) + 1;
258 strcpy(ptr, conn->host); 260 strcpy(ptr, conn->host);
259 } 261 }
260 262
261 // Send request 263 // Send request
262 nn_conn_reset(conn); 264 nn_conn_reset(conn);