We won't use D
[apps/pfixtools.git] / job.h
diff --git a/job.h b/job.h
index ad7d649..7246ef9 100644 (file)
--- a/job.h
+++ b/job.h
 #ifndef POSTLICYD_JOB_H
 #define POSTLICYD_JOB_H
 
-#include "buffer.h"
+#include "mem.h"
 
-enum job_state {
-    JOB_FREE   = 0x00,
+enum job_mode {
+    JOB_IDLE   = 0x00,
     JOB_READ   = 0x01,
     JOB_WRITE  = 0x02,
-    JOB_RDWR   = 0x03,
-    JOB_CONN   = 0x04,
-    JOB_LISTEN = 0x08,
-    JOB_IDLE   = 0x10,
+    JOB_RDWR   = JOB_READ | JOB_WRITE,
+    JOB_LISTEN = 0x04,
+    JOB_CONN   = 0x08,
 };
 
-enum smtp_state {
-    STATE_CONNECT,
-    STATE_HELO, /* or EHLO */
-    STATE_MAIL,
-    STATE_RCPT,
-    STATE_DATE,
-    STATE_EOM,
-    STATE_VRFY,
-    STATE_ETRN,
-};
-
-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;
+typedef struct job_t {
+    unsigned mode  :  6; /* 4 are enough, 2 used as padding */
+    unsigned done  :  1;
+    unsigned error :  1;
+    unsigned state : 24;
 
     int fd;
 
-    task_t *task;
-    jpriv_t *jdata;
-};
-
-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;
+    void (*process)(struct job_t *);
+    void (*stop)(struct job_t *);
 
-    /* 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;
+    jpriv_t *jdata;
+} job_t;
 
-    buffer_t data;
+static inline job_t *job_new(void) {
+    job_t *job = p_new(job_t, 1);
+    job->fd = -1;
+    return job;
+}
+void job_delete(job_t **job);
 
-    job_t *postfix;
-    job_t *current;
-};
+void job_update_mode(job_t *job, int mode);
+job_t *job_accept(job_t *listener, int mode);
 
-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);
+void job_initialize(void);
+void job_loop(void);
+void job_shutdown(void);
 
 #endif