2 #define _POSIX_C_SOURCE 200809L
9 #include "rocksock_internal.h"
11 #ifndef ROCKSOCK_FILENAME
12 #define ROCKSOCK_FILENAME __FILE__
15 int rocksock_add_proxy(rocksock
* sock
, rs_proxyType proxytype
, char* host
, unsigned short port
, char* username
, char* password
) {
19 if(sock
->lastproxy
+1 >= MAX_PROXIES
)
20 return rocksock_seterror(sock
, RS_ET_OWN
, RS_E_EXCEED_PROXY_LIMIT
, ROCKSOCK_FILENAME
, __LINE__
);
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__
);
28 prx
= &sock
->proxies
[sock
->lastproxy
];
29 prx
->hostinfo
.port
= port
;
30 prx
->proxytype
= proxytype
;
32 prx
->hostinfo
.host
= strdup(host
);
33 prx
->username
= username
? strdup(username
) : NULL
;
34 prx
->password
= password
? strdup(password
) : NULL
;
36 prx
->hostinfo
.host
= host
;
37 prx
->username
= username
;
38 prx
->password
= password
;
40 return rocksock_seterror(sock
, RS_ET_NO_ERROR
, 0, NULL
, 0);