From 42ea2884f2b8a1b7cb940f4e07d22444c6f61cc6 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Mon, 8 Jan 2007 01:10:43 +0100 Subject: [PATCH] prepare useful things for policy request parsing. use our usual functions. Signed-off-by: Pierre Habouzit --- buffer.c | 11 +++++++++++ buffer.h | 6 ++++++ policy.c | 11 +++++++++++ policy.h | 10 +++++++++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/buffer.c b/buffer.c index f6091fb..366b7d0 100644 --- 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; +} diff --git a/buffer.h b/buffer.h index e3075ba..87c0ad2 100644 --- 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); +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; @@ -96,4 +100,6 @@ static inline void buffer_addch(buffer_t *buf, int c) { buffer_extendch(buf, 1, c); } +void buffer_consume(buffer_t *buf, ssize_t len); + #endif /* MUTT_LIB_LIB_BUFFER_H */ diff --git a/policy.c b/policy.c index 4370e22..b814888 100644 --- a/policy.c +++ b/policy.c @@ -35,3 +35,14 @@ #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); +} diff --git a/policy.h b/policy.h index c4bd145..1ebaba1 100644 --- a/policy.h +++ b/policy.h @@ -36,6 +36,8 @@ #ifndef POSTLICYD_POLICY_H #define POSTLICYD_POLICY_H +#include "buffer.h" + enum protocol_state { STATE_CONNECT, STATE_HELO, /* or EHLO */ @@ -48,7 +50,6 @@ enum protocol_state { }; typedef struct policy_request { - unsigned ready : 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; + + buffer_t buf; } 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 -- 2.20.1