diff --git a/src/cfg.c b/src/cfg.c index 92ca197..4502b55 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -64,6 +64,7 @@ { "clamd_addr", "string", (void*) string_parser, offsetof(struct __config, clamd_addr), "", MAXVAL-1}, { "clamd_port", "integer", (void*) int_parser, offsetof(struct __config, clamd_port), "0", sizeof(int)}, { "clamd_socket", "string", (void*) string_parser, offsetof(struct __config, clamd_socket), CLAMD_SOCKET, MAXVAL-1}, + { "debug", "integer", (void*) int_parser, offsetof(struct __config, debug), "0", sizeof(int)}, { "default_retention_days", "integer", (void*) int_parser, offsetof(struct __config, default_retention_days), "2557", sizeof(int)}, { "hostid", "string", (void*) string_parser, offsetof(struct __config, hostid), HOSTID, MAXVAL-1}, { "iv", "string", (void*) string_parser, offsetof(struct __config, iv), "", MAXVAL-1}, diff --git a/src/cfg.h b/src/cfg.h index 93fc501..24940e6 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -63,6 +63,8 @@ int memcached_to_db_interval; int archive_emails_not_having_message_id; + + int debug; }; diff --git a/src/parser.c b/src/parser.c index 0f56e3c..a01dd21 100644 --- a/src/parser.c +++ b/src/parser.c @@ -142,6 +142,8 @@ char *p, *q, puf[SMALLBUFSIZE]; int x, n, len, b64_len, boundary_line=0; + if(cfg->debug == 1) printf("line: %s", buf); + state->line_num++; len = strlen(buf); diff --git a/test/Makefile.in b/test/Makefile.in index ba09faf..d0f7f0f 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -24,12 +24,12 @@ INSTALL = @INSTALL@ -all: parser view +all: parser debug parser: parser.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $^ -lpiler $(LIBS) $(LIBDIR) -view: view.c ../src/libpiler.a +debug: debug.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $^ -lpiler $(LIBS) $(LIBDIR) install: @@ -38,7 +38,7 @@ ./parser clean: - rm -f parser view + rm -f parser debug distclean: clean rm -f Makefile diff --git a/test/debug.c b/test/debug.c new file mode 100644 index 0000000..df4e624 --- /dev/null +++ b/test/debug.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv){ + struct stat st; + struct session_data sdata; + struct _state state; + struct __config cfg; + + + if(argc < 2){ + fprintf(stderr, "usage: %s \n", argv[0]); + exit(1); + } + + if(stat(argv[1], &st) != 0){ + fprintf(stderr, "%s is not found\n", argv[1]); + return 0; + } + + + cfg = read_config(CONFIG_FILE); + + + init_session_data(&sdata); + + sdata.sent = 0; + sdata.tot_len = st.st_size; + + snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", argv[1]); + snprintf(sdata.filename, SMALLBUFSIZE-1, "%s", argv[1]); + snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", argv[1]); + + cfg.debug = 1; + + state = parse_message(&sdata, 0, &cfg); + post_parse(&sdata, &state, &cfg); + + printf("message-id: %s\n", state.message_id); + printf("from: *%s (%s)*\n", state.b_from, state.b_from_domain); + printf("to: *%s (%s)*\n", state.b_to, state.b_to_domain); + printf("reference: *%s*\n", state.reference); + printf("subject: *%s*\n", state.b_subject); + printf("body: *%s*\n", state.b_body); + + printf("sent: %ld\n", sdata.sent); + + make_digests(&sdata, &cfg); + + return 0; +} diff --git a/test/view.c b/test/view.c deleted file mode 100644 index e40c011..0000000 --- a/test/view.c +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -int main(int argc, char **argv){ - struct stat st; - struct session_data sdata; - struct _state state; - struct __config cfg; - - - if(argc < 2){ - fprintf(stderr, "usage: %s \n", argv[0]); - exit(1); - } - - if(stat(argv[1], &st) != 0){ - fprintf(stderr, "%s is not found\n", argv[1]); - return 0; - } - - - cfg = read_config(CONFIG_FILE); - - - init_session_data(&sdata); - - sdata.sent = 0; - sdata.tot_len = st.st_size; - - snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", argv[1]); - snprintf(sdata.filename, SMALLBUFSIZE-1, "%s", argv[1]); - snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", argv[1]); - - state = parse_message(&sdata, 0, &cfg); - post_parse(&sdata, &state, &cfg); - - printf("message-id: %s\n", state.message_id); - printf("from: *%s (%s)*\n", state.b_from, state.b_from_domain); - printf("to: *%s (%s)*\n", state.b_to, state.b_to_domain); - printf("reference: *%s*\n", state.reference); - printf("subject: *%s*\n", state.b_subject); - printf("body: *%s*\n", state.b_body); - - printf("sent: %ld\n", sdata.sent); - - make_digests(&sdata, &cfg); - - return 0; -}