rocksock.h: expose all functions unconditionally
[rofl0r-rocksock.git] / rocksock_add_proxy.c
blobdf8fb53358f19f5bde95098ffac5879402f34ea3
1 #undef _POSIX_C_SOURCE
2 #define _POSIX_C_SOURCE 200809L
3 #undef _GNU_SOURCE
4 #define _GNU_SOURCE
6 #include <string.h>
8 #include "rocksock.h"
9 #include "rocksock_internal.h"
11 #ifndef ROCKSOCK_FILENAME
12 #define ROCKSOCK_FILENAME __FILE__
13 #endif
15 int rocksock_add_proxy(rocksock* sock, rs_proxyType proxytype, char* host, unsigned short port, char* username, char* password) {
16 rs_proxy* prx;
17 if (!sock)
18 return RS_E_NULL;
19 if(sock->lastproxy+1 >= MAX_PROXIES)
20 return rocksock_seterror(sock, RS_ET_OWN, RS_E_EXCEED_PROXY_LIMIT, ROCKSOCK_FILENAME, __LINE__);
21 if(!host)
22 return rocksock_seterror(sock, RS_ET_OWN, RS_E_NULL, ROCKSOCK_FILENAME, __LINE__);
23 if(proxytype == RS_PT_SOCKS4 && (username || password))
24 return rocksock_seterror(sock, RS_ET_OWN, RS_E_SOCKS4_NOAUTH, ROCKSOCK_FILENAME, __LINE__);
25 if(proxytype == RS_PT_SOCKS5 && ((username && strlen(username) > 255) || (password && strlen(password) > 255)))
26 return rocksock_seterror(sock, RS_ET_OWN, RS_E_SOCKS5_AUTH_EXCEEDSIZE, ROCKSOCK_FILENAME, __LINE__);
27 sock->lastproxy++;
28 prx = &sock->proxies[sock->lastproxy];
29 prx->hostinfo.port = port;
30 prx->proxytype = proxytype;
31 #ifndef NO_STRDUP
32 prx->hostinfo.host = strdup(host);
33 prx->username = username ? strdup(username) : NULL;
34 prx->password = password ? strdup(password) : NULL;
35 #else
36 prx->hostinfo.host = host;
37 prx->username = username;
38 prx->password = password;
39 #endif
40 return rocksock_seterror(sock, RS_ET_OWN, 0, NULL, 0);