From: Pierre Habouzit Date: Tue, 1 May 2007 21:39:48 +0000 (+0200) Subject: Refactor, prepare gperf things needed for the parse. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=e826fd379421938f920e7e51d2a34bf4eb3483a0;p=apps%2Fpfixtools.git Refactor, prepare gperf things needed for the parse. Signed-off-by: Pierre Habouzit --- diff --git a/.gitignore b/.gitignore index 6fd3da2..484968f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +tokens.[hc] + postlicyd *.o diff --git a/Makefile b/Makefile index 179fed8..0cd6149 100644 --- a/Makefile +++ b/Makefile @@ -34,10 +34,12 @@ CFLAGS += --std=gnu99 -D_GNU_SOURCE -D_FORTIFY_SOURCE=1 PROGRAMS = postlicyd +GENERATED = tokens.h tokens.c + postlicyd_SOURCES = \ - str.h buffer.h job.h postfix.h gai.h query.h \ - str.c buffer.c job.c postfix.c gai.c \ - postlicyd.c + str.h buffer.h job.h postfix.h gai.h \ + str.c buffer.c job.c postfix.c gai.c \ + postlicyd.c $(GENERATED) postlicyd_LIBADD = -lanl @@ -50,6 +52,7 @@ clean: $(RM) .*.o distclean: clean + $(RM) $(GENERATED) tags: .tags .tags: $(shell git ls-files | egrep '\.[hc]$$') @@ -61,6 +64,12 @@ headers: ( echo "package headache not installed" ; exit 1 ) @git ls-files | egrep '(\.h|\.c|Makefile|*\.mk)$$' | xargs -t headache $(HEADACHEOPTS) +%.c: %.sh + ./$< $@ || ($(RM) $@; exit 1) + +%.h: %.sh + ./$< $@ || ($(RM) $@; exit 1) + .%.o: %.c Makefile $(CC) $(CFLAGS) -MMD -MT ".$*.d $@" -MF .$*.d -g -c -o $@ $< diff --git a/postfix.h b/postfix.h index ea8fffb..d24dcbb 100644 --- a/postfix.h +++ b/postfix.h @@ -36,4 +36,50 @@ #ifndef POSTLICYD_POSTFIX_H #define POSTLICYD_POSTFIX_H +#include "buffer.h" + +/* \see http://www.postfix.org/SMTPD_POLICY_README.html */ +typedef struct query_t { + unsigned state : 4; + unsigned esmtp : 1; + + const char *helo_name; + const char *queue_id; + const char *sender; + const char *recipient; + const char *recipient_count; + const char *client_address; + const char *client_name; + const char *rclient_name; + const char *instance; + + /* postfix 2.2+ */ + const char *sasl_method; + const char *sasl_username; + const char *sasl_sender; + const char *size; + const char *ccert_subject; + const char *ccert_issuer; + const char *ccsert_fingerprint; + + /* postfix 2.3+ */ + const char *encryption_protocol; + const char *encryption_cipher; + const char *encryption_keysize; + const char *etrn_domain; + + buffer_t data; +} query_t; + +static inline query_t *query_init(query_t *rq) { + p_clear(rq, 1); + buffer_init(&rq->data); + return rq; +} +static inline void query_wipe(query_t *rq) { + buffer_wipe(&rq->data); +} +DO_NEW(query_t, query); +DO_DELETE(query_t, query); + #endif diff --git a/query.h b/tokens.sh old mode 100644 new mode 100755 similarity index 55% rename from query.h rename to tokens.sh index f8df50a..9a1faaf --- a/query.h +++ b/tokens.sh @@ -1,3 +1,12 @@ +#! /bin/sh -e + +die() { + echo "$@" 1>&2 + exit 2 +} + +do_hdr() { + cat <data); - return rq; +/***** THIS FILE IS AUTOGENERATED DO NOT MODIFY DIRECTLY ! *****/ + +EOF +} + +do_h() { + do_hdr + cat <data); + +do_tokens() { + while read tok; do + echo "$tok, PTK_`echo $tok | tr 'a-z-' 'A-Z_'`" + done } -DO_NEW(query_t, query); -DO_DELETE(query_t, query); -#endif +do_c() { + cat <val : PTK_UNKNOWN; + } else { + return PTK_UNKNOWN; + } +} +EOF +} + +grep_self() { + grep '^## ' "$1" | cut -d' ' -f2 +} + +trap "rm -f $1" 1 2 3 15 +rm -f $1 +case "$1" in + *.h) do_h > $1;; + *.c) do_c > $1;; + *) die "you must ask for the 'h' or 'c' generation";; +esac +chmod -w $1 + +exit 0 + +############ Put tokens here ############ +# postfix 2.1+ +## request +## protocol_state +## protocol_esmtp +## helo_name +## queue_id +## sender +## recipient +## recipient_count +## client_address +## client_name +## rclient_name +## instance +# +# postfix 2.2+ +## sasl_method +## sasl_username +## sasl_sender +## size +## ccert_subject +## ccert_issuer +## ccsert_fingerprint +# +# postfix 2.3+ +## encryption_protocol +## encryption_cipher +## encryption_keysize +## etrn_domain