Demonstrates n_proxy_cfg_parse / n_proxy_cfg_free and netw_adopt_client_fd.
Demonstrates n_proxy_cfg_parse / n_proxy_cfg_free and netw_adopt_client_fd.
#include <stdio.h>
#include <string.h>
#ifndef __windows__
#include <sys/socket.h>
#include <unistd.h>
#endif
int main(
int argc,
char* argv[]) {
int errors = 0;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-V") == 0 && i + 1 < argc) {
if (strcmp(argv[i + 1], "LOG_DEBUG") == 0)
else if (strcmp(argv[i + 1], "LOG_ERR") == 0)
else if (strcmp(argv[i + 1], "LOG_NOTICE") == 0)
}
}
{
if (cfg) {
if (strcmp(cfg->
scheme,
"http") != 0) errors++;
if (strcmp(cfg->
host,
"proxy.corp") != 0) errors++;
if (cfg->
port != 3128) errors++;
} else {
errors++;
}
}
{
if (cfg) {
if (strcmp(cfg->
scheme,
"socks5") != 0) errors++;
if (strcmp(cfg->
host,
"proxy.corp") != 0) errors++;
if (cfg->
port != 1080) errors++;
} else {
errors++;
}
}
{
if (cfg) {
if (strcmp(cfg->
scheme,
"https") != 0) errors++;
if (strcmp(cfg->
host,
"secure-proxy.corp") != 0) errors++;
if (cfg->
port != 8443) errors++;
} else {
errors++;
}
}
{
if (cfg) {
if (strcmp(cfg->
scheme,
"https") != 0) errors++;
if (cfg->
port != 3128) errors++;
} else {
errors++;
}
}
{
if (cfg) {
errors++;
} else {
}
}
#ifndef __windows__
{
int sv[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) != 0) {
errors++;
} else {
char rbuf[8];
if (send(sv[1], "PING", 4, 0) != 4) errors++;
memset(rbuf, 0, sizeof(rbuf));
errors++;
}
memset(rbuf, 0, sizeof(rbuf));
if (recv(sv[1], rbuf, 4, 0) != 4 || memcmp(rbuf, "PONG", 4) != 0) {
errors++;
}
if (errors == 0)
} else {
n_log(
LOG_ERR,
" FAIL: netw_adopt_client_fd returned FALSE");
errors++;
closesocket(sv[0]);
}
closesocket(sv[1]);
}
}
#endif
{
errors++;
} else {
}
}
errors == 0 ? "PASS" : "FAIL", errors, errors == 1 ? "" : "s");
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.