From: Pierre Habouzit Date: Wed, 2 May 2007 10:24:57 +0000 (+0200) Subject: further work on data parsing. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=14330fbdf398c3786803a001f0130b0d9ab70b46;p=apps%2Fpfixtools.git further work on data parsing. Signed-off-by: Pierre Habouzit --- diff --git a/Makefile b/Makefile index 0cd6149..2f96388 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ ############################################################################## include mk/cflags.mk -CFLAGS += --std=gnu99 -D_GNU_SOURCE -D_FORTIFY_SOURCE=1 +CFLAGS += --std=gnu99 -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 PROGRAMS = postlicyd diff --git a/postfix.c b/postfix.c index f88feba..46d2708 100644 --- a/postfix.c +++ b/postfix.c @@ -34,6 +34,7 @@ */ #include +#include #include #include #include @@ -41,6 +42,7 @@ #include "job.h" #include "postfix.h" #include "buffer.h" +#include "tokens.h" struct jpriv_t { buffer_t ibuf; @@ -66,6 +68,40 @@ static void postfix_stop(job_t *job) postfix_jpriv_delete(&job->jdata); } +static int postfix_parsejob(job_t *job) +{ + const char *p = skipspaces(job->jdata->ibuf.data); + + for (;;) { + const char *k, *v; + int klen, vlen; + + while (*p == ' ' || *p == '\t') + p++; + p = strchrnul(k = p, '='); + if (!*p) + return -1; + for (klen = p - k; k[klen] == ' ' || k[klen] == '\t'; klen--); + p += 1; /* skip = */ + + while (*p == ' ' || *p == '\t') + p++; + p = strstr(v = p, "\r\n"); + if (!p) + return -1; + for (vlen = p - v; v[vlen] == ' ' || v[vlen] == '\t'; vlen--); + p += 2; /* skip \r\n */ + + /* do sth with (k,v) */ + + assert (p[0] && p[1]); + if (p[0] == '\r' && p[1] == '\n') + break; + } + + return -1; +} + static void postfix_process(job_t *job) { int nb; @@ -110,11 +146,23 @@ static void postfix_process(job_t *job) return; } - if (!strstr(job->jdata->ibuf.data, "\r\n\r\n")) + if (!strstr(skipspaces(job->jdata->ibuf.data), "\r\n\r\n")) { + if (job->jdata->ibuf.len > SHRT_MAX) { + syslog(LOG_ERR, "too much data without CRLFCRLF"); + job->error = true; + } + return; + } + + if (postfix_parsejob(job) < 0) { + syslog(LOG_ERR, "could not parse postfix request"); + job->error = true; return; + } - /* TODO: do the parse */ job_update_mode(job, JOB_IDLE); + + /* TODO: run the scenario */ return; default: