35#include <sys/socket.h>
39int main(
int argc,
char* argv[]) {
44 for (
int i = 1; i < argc; i++) {
45 if (strcmp(argv[i],
"-V") == 0 && i + 1 < argc) {
46 if (strcmp(argv[i + 1],
"LOG_DEBUG") == 0)
48 else if (strcmp(argv[i + 1],
"LOG_ERR") == 0)
50 else if (strcmp(argv[i + 1],
"LOG_NOTICE") == 0)
66 if (strcmp(cfg->
scheme,
"http") != 0) errors++;
67 if (strcmp(cfg->
host,
"proxy.corp") != 0) errors++;
68 if (cfg->
port != 3128) errors++;
85 if (strcmp(cfg->
scheme,
"socks5") != 0) errors++;
86 if (strcmp(cfg->
host,
"proxy.corp") != 0) errors++;
87 if (cfg->
port != 1080) errors++;
100 n_log(
LOG_INFO,
" scheme=%s host=%s port=%d user=%s pass=%s",
104 if (strcmp(cfg->
scheme,
"https") != 0) errors++;
105 if (strcmp(cfg->
host,
"secure-proxy.corp") != 0) errors++;
106 if (cfg->
port != 8443) errors++;
122 if (strcmp(cfg->
scheme,
"https") != 0) errors++;
123 if (cfg->
port != 3128) errors++;
150 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) != 0) {
158 if (send(sv[1],
"PING", 4, 0) != 4) errors++;
159 memset(rbuf, 0,
sizeof(rbuf));
166 memset(rbuf, 0,
sizeof(rbuf));
167 if (recv(sv[1], rbuf, 4, 0) != 4 || memcmp(rbuf,
"PONG", 4) != 0) {
175 n_log(
LOG_ERR,
" FAIL: netw_adopt_client_fd returned FALSE");
188 n_log(
LOG_ERR,
" FAIL: expected FALSE for INVALID_SOCKET");
196 errors == 0 ?
"PASS" :
"FAIL", errors, errors == 1 ?
"" :
"s");
197 return errors > 0 ? 1 : 0;
NETWORK * netw
Network for server mode, accepting incomming.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
#define LOG_INFO
informational
char * host
proxy hostname
char * password
NULL if no auth.
char * scheme
"http", "https", or "socks5"
netw_func send_data
send func ptr
char * username
NULL if no auth.
netw_func recv_data
receive func ptr
N_PROXY_CFG * n_proxy_cfg_parse(const char *url)
Parse a proxy URL string into an N_PROXY_CFG struct.
int netw_adopt_client_fd(NETWORK **netw, SOCKET fd, const char *host, const char *port)
Adopt an already-connected socket fd into a fresh client NETWORK.
int SOCKET
default socket declaration
void n_proxy_cfg_free(N_PROXY_CFG **cfg)
Free an N_PROXY_CFG created by n_proxy_cfg_parse().
int netw_close(NETWORK **netw)
Closing a specified Network, destroy queues, free the structure.
Parsed proxy URL components.
Common headers and low-level functions & define.