prepare hooking of policy.c module.
[apps/pfixtools.git] / policy.h
index 1ebaba1..077b045 100644 (file)
--- a/policy.h
+++ b/policy.h
@@ -1,5 +1,5 @@
 /******************************************************************************/
-/*          postlicyd: a postfix policy daemon with a lot of features         */
+/*          pfixtools: a collection of postfix related tools                  */
 /*          ~~~~~~~~~                                                         */
 /*  ________________________________________________________________________  */
 /*                                                                            */
 /******************************************************************************/
 
 /*
- * Copyright © 2006 Pierre Habouzit
+ * Copyright © 2006-2007 Pierre Habouzit
  */
 
-#ifndef POSTLICYD_POLICY_H
-#define POSTLICYD_POLICY_H
+#ifndef PFIXTOOLS_POLICY_H
+#define PFIXTOOLS_POLICY_H
+
+#include <stddef.h>
 
 #include "buffer.h"
 
-enum protocol_state {
-    STATE_CONNECT,
-    STATE_HELO, /* or EHLO */
-    STATE_MAIL,
-    STATE_RCPT,
-    STATE_DATE,
-    STATE_EOM,
-    STATE_VRFY,
-    STATE_ETRN,
+enum smtp_state {
+    SMTP_UNKNOWN,
+    SMTP_CONNECT,
+    SMTP_EHLO,
+    SMTP_HELO = SMTP_EHLO,
+    SMTP_MAIL,
+    SMTP_RCPT,
+    SMTP_DATA,
+    SMTP_END_OF_MESSAGE,
+    SMTP_VRFY,
+    SMTP_ETRN,
 };
 
-typedef struct policy_request {
+/* \see http://www.postfix.org/SMTPD_POLICY_README.html */
+typedef struct query_t {
     unsigned state : 4;
     unsigned esmtp : 1;
 
@@ -78,13 +83,26 @@ typedef struct policy_request {
     const char *encryption_keysize;
     const char *etrn_domain;
 
-    buffer_t buf;
-} policy_request;
+    buffer_t data;
+} query_t;
+
+static inline query_t *query_init(query_t *rq) {
+    memset(rq, 0, offsetof(query_t, data));
+    buffer_init(&rq->data);
+    return rq;
+}
+static inline query_t *query_reset(query_t *rq) {
+    memset(rq, 0, offsetof(query_t, data));
+    buffer_reset(&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);
 
-policy_request *pcyrq_init(policy_request *rq);
-void pcyrq_wipe(policy_request *rq);
 
-DO_NEW(policy_request, pcyrq);
-DO_DELETE(policy_request, pcyrq);
+void *policy_run(int fd, void *);
 
 #endif