Fixes.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 24 Sep 2008 19:31:50 +0000 (21:31 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 24 Sep 2008 19:31:50 +0000 (21:31 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
common/array.h
common/buffer.c
common/buffer.h
postlicyd/match.c

index 55883d2..86cf360 100644 (file)
 #define array_ensure_capacity_delta(array, delta)                              \
     array_ensure_capacity(array, (array).len + (delta))
 #define array_ensure_exact_capacity(array, goal)                               \
-    if (array_size(array) < (goal)) {                                          \
+    if ((array).size < (goal)) {                                               \
         array_ensure_can_edit(array);                                          \
         p_allocgrow(&(array).data, (goal), &(array).size);                     \
     }
index 81855fd..bfd8ba0 100644 (file)
 #include "mem.h"
 #include "buffer.h"
 
-#define BUFSIZ_INCREMENT  256
-
-void buffer_resize(buffer_t *buf, ssize_t newsize)
-{
-    p_allocgrow(&buf->data, newsize + 1, &buf->size);
-}
-
 ssize_t buffer_addvf(buffer_t *buf, const char *fmt, va_list ap)
 {
     ssize_t len, avail = buf->size - buf->len;
@@ -71,7 +64,7 @@ void buffer_consume(buffer_t *buf, ssize_t len)
     if (len <= 0)
         return;
 
-    if (len >= buf->len) {
+    if (len >= (ssize_t)buf->len) {
         buffer_reset(buf);
         return;
     }
index a1a96ec..c6c11c6 100644 (file)
@@ -63,8 +63,9 @@ static inline char *buffer_unwrap(buffer_t **buf) {
     return res;
 }
 
+#define buffer_resize(buffer, newsize)                                         \
+  array_ensure_exact_capacity(*(buffer), (newsize) + 1)
 
-void buffer_resize(buffer_t *, ssize_t newsize);
 static inline void buffer_ensure(buffer_t *buf, ssize_t extra) {
     assert (extra >= 0);
     if (buf->len + extra >= buf->size) {
index 5dbf3d4..ae4dbe4 100644 (file)
@@ -115,18 +115,17 @@ static bool match_filter_constructor(filter_t *filter)
 #define     IS_OP_END(N)                                                          \
               ((N) == '=' || (N) == 'i')
             match_condition_t condition = CONDITION_INIT;
-            const char *p = m_strnextsp(param->value);
+            const char *p = skipspaces(param->value);
             const char *n = p + 1;
             PARSE_CHECK(isalnum(*p), "invalid field name");
             for (n = p + 1 ; *n && (isalnum(*n) || *n == '_') ; ++n);
-            PARSE_CHECK(*n &&
-                        (isspace(*n) || IS_OP_START(*n)),
+            PARSE_CHECK(*n && (isspace(*n) || IS_OP_START(*n)),
                         "invalid condition, expected operator after field name");
             condition.field = policy_tokenize(p, n - p);
             PARSE_CHECK(condition.field >= PTK_HELO_NAME
                         && condition.field < PTK_SMTPD_ACCESS_POLICY,
                         "invalid field name %.*s", n - p, p);
-            p = m_strnextsp(n);
+            p = skipspaces(n);
             n = p + 1;
             PARSE_CHECK(IS_OP_START(*p) && IS_OP_END(*n),
                         "invalid operator %2s", p);
@@ -254,15 +253,15 @@ static filter_result_t match_filter(const filter_t *filter, const query_t *query
     foreach (const match_condition_t *condition, config->conditions) {
         bool r = match_condition(condition, query);
         if (!r && config->match_all) {
-            return HTK_FALSE;
+            return HTK_FAIL;
         } else if (r && !(config->match_all)) {
-            return HTK_TRUE;
+            return HTK_MATCH;
         }
     }}
     if (config->match_all) {
-        return HTK_TRUE;
+        return HTK_MATCH;
     } else {
-        return HTK_FALSE;
+        return HTK_FAIL;
     }
 }
 
@@ -274,8 +273,8 @@ static int match_init(void)
      */
     (void)filter_hook_register(type, "abort");
     (void)filter_hook_register(type, "error");
-    (void)filter_hook_register(type, "true");
-    (void)filter_hook_register(type, "false");
+    (void)filter_hook_register(type, "match");
+    (void)filter_hook_register(type, "fail");
 
     /* Parameters.
      */