prepare useful things for policy request parsing.
authorPierre Habouzit <madcoder@debian.org>
Mon, 8 Jan 2007 00:10:43 +0000 (01:10 +0100)
committerPierre Habouzit <madcoder@debian.org>
Mon, 8 Jan 2007 00:10:43 +0000 (01:10 +0100)
use our usual functions.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
buffer.c
buffer.h
policy.c
policy.h

index f6091fb..366b7d0 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -46,4 +46,15 @@ void buffer_resize(buffer_t *buf, ssize_t newsize)
     }
 }
 
     }
 }
 
+void buffer_consume(buffer_t *buf, ssize_t len) {
+    if (len <= 0)
+        return;
 
 
+    if (len >= buf->len) {
+        buffer_reset(buf);
+        return;
+    }
+
+    memmove(buf->data, buf->data + len, buf->len + 1 - len);
+    buf->len -= len;
+}
index e3075ba..87c0ad2 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -52,6 +52,10 @@ static inline void buffer_wipe(buffer_t *buf) {
 DO_NEW(buffer_t, buffer);
 DO_DELETE(buffer_t, buffer);
 
 DO_NEW(buffer_t, buffer);
 DO_DELETE(buffer_t, buffer);
 
+static inline void buffer_reset(buffer_t *buf) {
+    buf->data[buf->len = 0] = '\0';
+}
+
 static inline char *buffer_unwrap(buffer_t **buf) {
     char *res = (*buf)->data;
     (*buf)->data = NULL;
 static inline char *buffer_unwrap(buffer_t **buf) {
     char *res = (*buf)->data;
     (*buf)->data = NULL;
@@ -96,4 +100,6 @@ static inline void buffer_addch(buffer_t *buf, int c) {
     buffer_extendch(buf, 1, c);
 }
 
     buffer_extendch(buf, 1, c);
 }
 
+void buffer_consume(buffer_t *buf, ssize_t len);
+
 #endif /* MUTT_LIB_LIB_BUFFER_H */
 #endif /* MUTT_LIB_LIB_BUFFER_H */
index 4370e22..b814888 100644 (file)
--- a/policy.c
+++ b/policy.c
 
 #include "policy.h"
 
 
 #include "policy.h"
 
+policy_request *pcyrq_init(policy_request *rq)
+{
+    p_clear(rq, 1);
+    buffer_init(&rq->buf);
+    return rq;
+}
+
+void policy_wipe(policy_request *rq)
+{
+    buffer_wipe(&rq->buf);
+}
index c4bd145..1ebaba1 100644 (file)
--- a/policy.h
+++ b/policy.h
@@ -36,6 +36,8 @@
 #ifndef POSTLICYD_POLICY_H
 #define POSTLICYD_POLICY_H
 
 #ifndef POSTLICYD_POLICY_H
 #define POSTLICYD_POLICY_H
 
+#include "buffer.h"
+
 enum protocol_state {
     STATE_CONNECT,
     STATE_HELO, /* or EHLO */
 enum protocol_state {
     STATE_CONNECT,
     STATE_HELO, /* or EHLO */
@@ -48,7 +50,6 @@ enum protocol_state {
 };
 
 typedef struct policy_request {
 };
 
 typedef struct policy_request {
-    unsigned ready : 1;
     unsigned state : 4;
     unsigned esmtp : 1;
 
     unsigned state : 4;
     unsigned esmtp : 1;
 
@@ -76,7 +77,14 @@ typedef struct policy_request {
     const char *encryption_cipher;
     const char *encryption_keysize;
     const char *etrn_domain;
     const char *encryption_cipher;
     const char *encryption_keysize;
     const char *etrn_domain;
+
+    buffer_t buf;
 } policy_request;
 
 } policy_request;
 
+policy_request *pcyrq_init(policy_request *rq);
+void pcyrq_wipe(policy_request *rq);
+
+DO_NEW(policy_request, pcyrq);
+DO_DELETE(policy_request, pcyrq);
 
 #endif
 
 #endif