PROGRAMS = postlicyd
postlicyd_SOURCES = \
- str.h buffer.h policy.h \
- str.c buffer.c policy.c \
+ str.h buffer.h job.h postfix.h \
+ str.c buffer.c job.c postfix.c \
postlicyd.c
postlicyd_LIBADD = -ludns
/******************************************************************************/
/*
- * Copyright © 2006 Pierre Habouzit
+ * Copyright © 2006-2007 Pierre Habouzit
*/
#include <stdio.h>
/******************************************************************************/
/*
- * Copyright © 2006 Pierre Habouzit
+ * Copyright © 2006-2007 Pierre Habouzit
*/
#ifndef POSTLICYD_BUFFER_H
--- /dev/null
+/******************************************************************************/
+/* postlicyd: a postfix policy daemon with a lot of features */
+/* ~~~~~~~~~ */
+/* ________________________________________________________________________ */
+/* */
+/* Redistribution and use in source and binary forms, with or without */
+/* modification, are permitted provided that the following conditions */
+/* are met: */
+/* */
+/* 1. Redistributions of source code must retain the above copyright */
+/* notice, this list of conditions and the following disclaimer. */
+/* 2. Redistributions in binary form must reproduce the above copyright */
+/* notice, this list of conditions and the following disclaimer in the */
+/* documentation and/or other materials provided with the distribution. */
+/* 3. The names of its contributors may not be used to endorse or promote */
+/* products derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND */
+/* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE */
+/* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
+/* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR */
+/* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF */
+/* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS */
+/* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */
+/* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF */
+/* THE POSSIBILITY OF SUCH DAMAGE. */
+/******************************************************************************/
+
+/*
+ * Copyright © 2007 Pierre Habouzit
+ */
+
+#include "job.h"
+
/******************************************************************************/
/*
- * Copyright © 2006 Pierre Habouzit
+ * Copyright © 2007 Pierre Habouzit
*/
-#ifndef POSTLICYD_POLICY_H
-#define POSTLICYD_POLICY_H
+#ifndef POSTLICYD_JOB_H
+#define POSTLICYD_JOB_H
#include "buffer.h"
-enum protocol_state {
+enum job_state {
+ JOB_FREE = 0x00,
+ JOB_READ = 0x01,
+ JOB_WRITE = 0x02,
+ JOB_RDWR = 0x03,
+ JOB_CONN = 0x04,
+ JOB_LISTEN = 0x08,
+ JOB_IDLE = 0x10,
+};
+
+enum smtp_state {
STATE_CONNECT,
STATE_HELO, /* or EHLO */
STATE_MAIL,
STATE_ETRN,
};
-typedef struct policy_request {
+typedef struct job_t job_t;
+typedef struct jpriv_t jpriv_t;
+typedef struct task_t task_t;
+typedef struct query_t query_t;
+
+struct task_t {
+ task_t *(*create)(void);
+ void (*release)(task_t **);
+
+ void (*run)(job_t *, query_t *);
+ void (*done)(job_t *);
+ void (*cancel)(job_t *);
+ void (*process)(job_t *);
+};
+
+struct job_t {
+ unsigned state : 6;
+ unsigned done : 1;
+ unsigned error : 1;
+
+ int fd;
+
+ task_t *task;
+ jpriv_t *jdata;
+};
+
+struct query_t {
unsigned state : 4;
unsigned esmtp : 1;
const char *encryption_keysize;
const char *etrn_domain;
- ssize_t rqsize;
- buffer_t ibuf;
- buffer_t obuf;
-} policy_request;
+ buffer_t data;
+
+ job_t *postfix;
+ job_t *current;
+};
-policy_request *pcyrq_init(policy_request *rq);
-void pcyrq_wipe(policy_request *rq);
-DO_NEW(policy_request, pcyrq);
-DO_DELETE(policy_request, pcyrq);
+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
--- /dev/null
+/******************************************************************************/
+/* postlicyd: a postfix policy daemon with a lot of features */
+/* ~~~~~~~~~ */
+/* ________________________________________________________________________ */
+/* */
+/* Redistribution and use in source and binary forms, with or without */
+/* modification, are permitted provided that the following conditions */
+/* are met: */
+/* */
+/* 1. Redistributions of source code must retain the above copyright */
+/* notice, this list of conditions and the following disclaimer. */
+/* 2. Redistributions in binary form must reproduce the above copyright */
+/* notice, this list of conditions and the following disclaimer in the */
+/* documentation and/or other materials provided with the distribution. */
+/* 3. The names of its contributors may not be used to endorse or promote */
+/* products derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND */
+/* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE */
+/* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
+/* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR */
+/* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF */
+/* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS */
+/* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */
+/* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF */
+/* THE POSSIBILITY OF SUCH DAMAGE. */
+/******************************************************************************/
+
+/*
+ * Copyright © 2006-2007 Pierre Habouzit
+ */
+
+#include <errno.h>
+#include <stdbool.h>
+#include <unistd.h>
+
+#include "postfix.h"
+
+struct jpriv_t {
+ buffer_t ibuf;
+ buffer_t obuf;
+};
+
+task_t *postfix_create(void)
+{
+ return NULL;
+}
+
+void postfix_release(task_t **task)
+{
+ if (task) {
+ *task = NULL;
+ }
+}
+
+void postfix_run(job_t *job, query_t *query)
+{
+}
+
+void postfix_done(job_t *job)
+{
+}
+
+void postfix_process(job_t *job)
+{
+ if (job->state & JOB_LISTEN) {
+ // TODO
+ }
+
+ if (job->state & JOB_WRITE) {
+ int nbwritten;
+
+ nbwritten = write(job->fd, job->jdata->obuf.data, job->jdata->obuf.len);
+ if (nbwritten < 0) {
+ job->error = errno != EINTR && errno != EAGAIN;
+ return;
+ }
+
+ buffer_consume(&job->jdata->obuf, nbwritten);
+ }
+
+ if (job->state & JOB_READ) {
+ int nbread;
+
+ nbread = buffer_read(&job->jdata->ibuf, job->fd, -1);
+ if (nbread < 0) {
+ job->error = errno != EINTR && errno != EAGAIN;
+ return;
+ }
+ if (nbread == 0) {
+ job->error = true;
+ return;
+ }
+
+ if (!strstr(job->jdata->ibuf.data, "\r\n\r\n"))
+ return;
+
+ /* TODO: do the parse */
+ }
+}
+
+task_t task_postfix = {
+ postfix_create,
+ postfix_release,
+ postfix_run,
+ postfix_done,
+ NULL,
+ postfix_process
+};
/******************************************************************************/
/*
- * Copyright © 2006 Pierre Habouzit
+ * Copyright © 2006-2007 Pierre Habouzit
*/
-#include "policy.h"
+#ifndef POSTLICYD_POSTFIX_H
+#define POSTLICYD_POSTFIX_H
-policy_request *pcyrq_init(policy_request *rq)
-{
- p_clear(rq, 1);
- buffer_init(&rq->ibuf);
- buffer_init(&rq->obuf);
- return rq;
-}
+#include "job.h"
-void policy_wipe(policy_request *rq)
-{
- buffer_wipe(&rq->ibuf);
- buffer_wipe(&rq->obuf);
-}
+extern task_t task_postfix;
+
+#endif