From 509c85f69fa3469a4212af0274e8866036a79f65 Mon Sep 17 00:00:00 2001 From: iratqq Date: Wed, 6 Feb 2008 16:33:36 +0000 Subject: [PATCH] add trace option '-t' to sj3proxy. it makes debugging easy. --- trunk/configure.in | 2 +- trunk/include/sj3compat/Makefile.am | 2 +- trunk/include/sj3compat/sj3compat.h | 6 +++--- trunk/include/sj3compat/{vis.h => sj3vis.h} | 0 trunk/lib/sj3compat/vis.c | 2 +- trunk/src/sj3proxy/sj3proxy.c | 22 ++++++++++++++++++++- 6 files changed, 27 insertions(+), 7 deletions(-) rename trunk/include/sj3compat/{vis.h => sj3vis.h} (100%) diff --git a/trunk/configure.in b/trunk/configure.in index 5b79884..d967f3e 100644 --- a/trunk/configure.in +++ b/trunk/configure.in @@ -361,7 +361,7 @@ AC_CHECK_FUNCS([ \ strerror \ strlcat \ strlcpy \ - strnvis \ + strvisx \ strrchr \ strstr \ strtol \ diff --git a/trunk/include/sj3compat/Makefile.am b/trunk/include/sj3compat/Makefile.am index 58c6f47..1d55977 100644 --- a/trunk/include/sj3compat/Makefile.am +++ b/trunk/include/sj3compat/Makefile.am @@ -1,2 +1,2 @@ -EXTRA_DIST = sj3compat.h sys-queue.h +EXTRA_DIST = sj3compat.h sj3vis.h sys-queue.h diff --git a/trunk/include/sj3compat/sj3compat.h b/trunk/include/sj3compat/sj3compat.h index ef5b018..5958dc6 100644 --- a/trunk/include/sj3compat/sj3compat.h +++ b/trunk/include/sj3compat/sj3compat.h @@ -126,9 +126,9 @@ size_t sj3_strlcpy(char *, const char *, size_t); #endif /* vis.c */ -#ifndef HAVE_STRNVIS -#define strnvis sj3strnvis -int strnvis(char *, const char *, size_t, int); +#ifndef HAVE_STRVISX +#define strvisx sj3strvisx +int strvisx(char *, const char *, size_t, int); #endif #endif /* SJ3COMPAT_H */ diff --git a/trunk/include/sj3compat/vis.h b/trunk/include/sj3compat/sj3vis.h similarity index 100% rename from trunk/include/sj3compat/vis.h rename to trunk/include/sj3compat/sj3vis.h diff --git a/trunk/lib/sj3compat/vis.c b/trunk/lib/sj3compat/vis.c index c8d9e35..14d94d2 100644 --- a/trunk/lib/sj3compat/vis.c +++ b/trunk/lib/sj3compat/vis.c @@ -36,7 +36,7 @@ #include #include -#include "vis.h" +#include "sj3vis.h" #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') #define isvisible(c) \ diff --git a/trunk/src/sj3proxy/sj3proxy.c b/trunk/src/sj3proxy/sj3proxy.c index 3abf2d4..9592d0b 100644 --- a/trunk/src/sj3proxy/sj3proxy.c +++ b/trunk/src/sj3proxy/sj3proxy.c @@ -30,6 +30,9 @@ #include #include #include +#if defined(HAVE_STRVISX) && defined(HAVE_VIS_H) +# include +#endif #include "sys-queue.h" #include @@ -50,6 +53,8 @@ char socket_file[MAXPATHLEN]; char host_name[NI_MAXHOST]; char service_name[NI_MAXSERV]; +static int trace_enable = 0; + struct listen_addr { TAILQ_ENTRY(listen_addr) entry; struct sockaddr_storage sa; @@ -143,6 +148,12 @@ readwrite(int inet_fd) shutdown(inet_fd, SHUT_RD); return; } else { + if (trace_enable) { + char fmtbuf[BUFSIZ * 4 + 1]; + strvisx(fmtbuf, buf, readlen, VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL); + fmtbuf[BUFSIZ * 4] = 0; + printf("i< %s\n", fmtbuf); + } if (atomicio(vwrite, sj3_fd, buf, readlen) != readlen) return; } @@ -156,6 +167,12 @@ readwrite(int inet_fd) shutdown(inet_fd, SHUT_WR); return; } else { + if (trace_enable) { + char fmtbuf[BUFSIZ * 4 + 1]; + strvisx(fmtbuf, buf, readlen, VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL); + fmtbuf[BUFSIZ * 4] = 0; + printf("o> %s\n", fmtbuf); + } if (atomicio(vwrite, inet_fd, buf, readlen) != readlen) return; } @@ -217,7 +234,7 @@ main(int argc, char *argv[]) int opt_inet4 = 0, opt_inet6 = 0; char *config_file = SJ3PROXYCFG; - while ((c = getopt(argc, argv, "46c:d")) != EOF) { + while ((c = getopt(argc, argv, "46c:dt")) != EOF) { switch (c) { case '4': opt_inet4 = 1; @@ -231,6 +248,9 @@ main(int argc, char *argv[]) case 'd': daemon_disable = 1; break; + case 't': + trace_enable = 1; + break; case '?': default: errflg++;