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
, const char* host
, unsigned short port
, const char* username
, const char* password
) {
20 return rocksock_seterror(sock
, RS_ET_OWN
, RS_E_NULL
, ROCKSOCK_FILENAME
, __LINE__
);
21 if(proxytype
== RS_PT_SOCKS4
&& (username
|| password
))
22 return rocksock_seterror(sock
, RS_ET_OWN
, RS_E_SOCKS4_NOAUTH
, ROCKSOCK_FILENAME
, __LINE__
);
23 if(proxytype
== RS_PT_SOCKS5
&& ((username
&& strlen(username
) > 255) || (password
&& strlen(password
) > 255)))
24 return rocksock_seterror(sock
, RS_ET_OWN
, RS_E_SOCKS5_AUTH_EXCEEDSIZE
, ROCKSOCK_FILENAME
, __LINE__
);
26 return rocksock_seterror(sock
, RS_ET_OWN
, RS_E_NO_PROXYSTORAGE
, ROCKSOCK_FILENAME
, __LINE__
);
27 size_t l
= strlen(host
);
29 return rocksock_seterror(sock
, RS_ET_OWN
, RS_E_HOSTNAME_TOO_LONG
, ROCKSOCK_FILENAME
, __LINE__
);
31 prx
= &sock
->proxies
[sock
->lastproxy
];
32 prx
->hostinfo
.port
= port
;
33 prx
->proxytype
= proxytype
;
34 memcpy(prx
->hostinfo
.host
, host
, l
+1);
35 memcpy(prx
->username
, username
?username
:"", username
?strlen(username
)+1:1);
36 memcpy(prx
->password
, password
?password
:"", password
?strlen(password
)+1:1);
37 return rocksock_seterror(sock
, RS_ET_OWN
, 0, NULL
, 0);