Move some code.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 12 Oct 2008 13:03:24 +0000 (15:03 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 12 Oct 2008 13:17:26 +0000 (15:17 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
postlicyd/match.c
postlicyd/query.c
postlicyd/query.h

index ebee763..558bc88 100644 (file)
@@ -182,36 +182,7 @@ static void match_filter_destructor(filter_t *filter)
 
 static inline bool match_condition(const match_condition_t *cond, const query_t *query)
 {
-    const char *field = NULL;
-    switch (cond->field) {
-#define CASE(Up, Low)                                                          \
-      case PTK_ ## Up: field = query->Low; break;
-      CASE(HELO_NAME, helo_name)
-      CASE(QUEUE_ID, queue_id)
-      CASE(SENDER, sender)
-      CASE(SENDER_DOMAIN, sender_domain)
-      CASE(RECIPIENT, recipient)
-      CASE(RECIPIENT_DOMAIN, recipient_domain)
-      CASE(RECIPIENT_COUNT, recipient_count)
-      CASE(CLIENT_ADDRESS, client_address)
-      CASE(CLIENT_NAME, client_name)
-      CASE(REVERSE_CLIENT_NAME, reverse_client_name)
-      CASE(INSTANCE, instance)
-      CASE(SASL_METHOD, sasl_method)
-      CASE(SASL_USERNAME, sasl_username)
-      CASE(SASL_SENDER, sasl_sender)
-      CASE(SIZE, size)
-      CASE(CCERT_SUBJECT, ccert_subject)
-      CASE(CCERT_ISSUER, ccert_issuer)
-      CASE(CCERT_FINGERPRINT, ccert_fingerprint)
-      CASE(ENCRYPTION_PROTOCOL, encryption_protocol)
-      CASE(ENCRYPTION_CIPHER, encryption_cipher)
-      CASE(ENCRYPTION_KEYSIZE, encryption_keysize)
-      CASE(ETRN_DOMAIN, etrn_domain)
-      CASE(STRESS, stress)
-#undef CASE
-      default: return false;
-    }
+    const char *field = query_field_for_id(query, cond->field);
     debug("running condition: \"%s\" %s %s\"%s\"",
           field, condition_names[cond->condition],
           cond->case_sensitive ? "" : "(alternative) ",
index 327c2b7..01b7ca4 100644 (file)
@@ -149,3 +149,42 @@ bool query_parse(query_t *query, char *p)
 #undef PARSE_CHECK
 }
 
+const char *query_field_for_id(const query_t *query, postlicyd_token id)
+{
+    switch (id) {
+#define CASE(Up, Low)                                                          \
+      case PTK_ ## Up: return query->Low;
+      CASE(HELO_NAME, helo_name)
+      CASE(QUEUE_ID, queue_id)
+      CASE(SENDER, sender)
+      CASE(SENDER_DOMAIN, sender_domain)
+      CASE(RECIPIENT, recipient)
+      CASE(RECIPIENT_DOMAIN, recipient_domain)
+      CASE(RECIPIENT_COUNT, recipient_count)
+      CASE(CLIENT_ADDRESS, client_address)
+      CASE(CLIENT_NAME, client_name)
+      CASE(REVERSE_CLIENT_NAME, reverse_client_name)
+      CASE(INSTANCE, instance)
+      CASE(SASL_METHOD, sasl_method)
+      CASE(SASL_USERNAME, sasl_username)
+      CASE(SASL_SENDER, sasl_sender)
+      CASE(SIZE, size)
+      CASE(CCERT_SUBJECT, ccert_subject)
+      CASE(CCERT_ISSUER, ccert_issuer)
+      CASE(CCERT_FINGERPRINT, ccert_fingerprint)
+      CASE(ENCRYPTION_PROTOCOL, encryption_protocol)
+      CASE(ENCRYPTION_CIPHER, encryption_cipher)
+      CASE(ENCRYPTION_KEYSIZE, encryption_keysize)
+      CASE(ETRN_DOMAIN, etrn_domain)
+      CASE(STRESS, stress)
+#undef CASE
+      default: return NULL;
+    }
+}
+
+const char *query_field_for_name(const query_t *query, const char *name)
+{
+    postlicyd_token id = policy_tokenize(name, strlen(name));
+    return query_field_for_id(query, id);
+}
+
index 86e41ba..1443d65 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "mem.h"
 #include "common.h"
+#include "policy_tokens.h"
 
 enum smtp_state {
     SMTP_CONNECT,
@@ -102,4 +103,14 @@ typedef struct query_t {
 __attribute__((nonnull(1,2)))
 bool query_parse(query_t *query, char *p);
 
+/** Return the value of the field with the given name.
+ */
+__attribute__((nonnull(1,2)))
+const char *query_field_for_name(const query_t *query, const char *name);
+
+/** Returns the value of the field with the given id.
+ */
+__attribute__((nonnull))
+const char *query_field_for_id(const query_t *query, postlicyd_token id);
+
 #endif