From 5c4c166802b5fdaf5072518feb19a3c0a5c216c8 Mon Sep 17 00:00:00 2001 From: crass Date: Sun, 23 Jun 2013 12:12:25 +0700 Subject: [PATCH] Add DUMP_PROXY_CHAIN for debug builds and debug.c. --- Makefile | 2 +- src/common.c | 20 ++++++++++++++++++++ src/common.h | 4 ++++ src/debug.c | 21 +++++++++++++++++++++ src/debug.h | 8 +++++++- 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/debug.c diff --git a/Makefile b/Makefile index 7a3080f..b85d808 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ OBJS = $(SRCS:.c=.o) LOBJS = src/nameinfo.o \ src/core.o src/common.o src/libproxychains.o src/shm.o \ src/allocator_thread.o src/ip_type.o src/stringdump.o \ - src/hostentdb.o src/hash.o + src/hostentdb.o src/hash.o src/debug.o CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe NO_AS_NEEDED = -Wl,--no-as-needed diff --git a/src/common.c b/src/common.c index 525310a..9cab4ff 100644 --- a/src/common.c +++ b/src/common.c @@ -3,6 +3,26 @@ #include #include +const char *proxy_type_strmap[] = { + "http", + "socks4", + "socks5", +}; + +const char *chain_type_strmap[] = { + "dynamic_chain", + "strict_chain", + "random_chain", + "round_robin_chain", +}; + +const char *proxy_state_strmap[] = { + "play", + "down", + "blocked", + "busy", +}; + // stolen from libulz (C) rofl0r void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes) { unsigned char *p; diff --git a/src/common.h b/src/common.h index 2a3f017..5335bd1 100644 --- a/src/common.h +++ b/src/common.h @@ -11,6 +11,10 @@ #include +extern const char *proxy_type_strmap[]; +extern const char *chain_type_strmap[]; +extern const char *proxy_state_strmap[]; + char *get_config_path(char* default_path, char* pbuf, size_t bufsize); void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes); diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 000000000..d867569 --- /dev/null +++ b/src/debug.c @@ -0,0 +1,21 @@ + +#ifdef DEBUG +# include "core.h" +# include "common.h" +# include "debug.h" + +void DUMP_PROXY_CHAIN(proxy_data *pchain, unsigned int count) { + char ip_buf[16]; + for (; count; pchain++, count--) { + pc_stringfromipv4(&pchain->ip.octet[0], ip_buf); + PDEBUG("[%s] %s %s:%d", proxy_state_strmap[pchain->ps], + proxy_type_strmap[pchain->pt], + ip_buf, htons(pchain->port)); + if (*pchain->user || *pchain->pass) { + PSTDERR(" [u=%s,p=%s]", pchain->user, pchain->pass); + } + PSTDERR("\n"); + } +} + +#endif diff --git a/src/debug.h b/src/debug.h index 2c04cc5..8bcf2e9 100644 --- a/src/debug.h +++ b/src/debug.h @@ -3,9 +3,15 @@ #ifdef DEBUG # include -# define PDEBUG(fmt, args...) do { dprintf(2,"DEBUG:"fmt, ## args); } while(0) +# define PSTDERR(fmt, args...) do { dprintf(2,fmt, ## args); } while(0) +# define PDEBUG(fmt, args...) PSTDERR("DEBUG:"fmt, ## args) + +# include "core.h" +void DUMP_PROXY_CHAIN(proxy_data *pchain, unsigned int count); + #else # define PDEBUG(fmt, args...) do {} while (0) +# define DUMP_PROXY_CHAIN(args...) do {} while (0) #endif # define PFUNC() do { PDEBUG("pid[%d]:%s\n", getpid(), __FUNCTION__); } while(0)