Implemented true, false, exists and size.
Showing
1 changed file
with
58 additions
and
11 deletions
... | @@ -37,45 +37,92 @@ | ... | @@ -37,45 +37,92 @@ |
37 | #define TAG_OVER 9 | 37 | #define TAG_OVER 9 |
38 | 38 | ||
39 | int | 39 | int |
40 | sieve_test_address (sieve_machine_t *mach, list_t args, list_t tags) | 40 | sieve_test_address (sieve_machine_t mach, list_t args, list_t tags) |
41 | { | 41 | { |
42 | return 0; | 42 | return 0; |
43 | } | 43 | } |
44 | 44 | ||
45 | int | 45 | int |
46 | sieve_test_header (sieve_machine_t *mach, list_t args, list_t tags) | 46 | sieve_test_header (sieve_machine_t mach, list_t args, list_t tags) |
47 | { | 47 | { |
48 | return 0; | 48 | return 0; |
49 | } | 49 | } |
50 | 50 | ||
51 | int | 51 | int |
52 | sieve_test_envelope (sieve_machine_t *mach, list_t args, list_t tags) | 52 | sieve_test_envelope (sieve_machine_t mach, list_t args, list_t tags) |
53 | { | 53 | { |
54 | return 0; | 54 | return 0; |
55 | } | 55 | } |
56 | 56 | ||
57 | int | 57 | int |
58 | sieve_test_size (sieve_machine_t *mach, list_t args, list_t tags) | 58 | sieve_test_size (sieve_machine_t mach, list_t args, list_t tags) |
59 | { | 59 | { |
60 | return 0; | 60 | int rc; |
61 | sieve_runtime_tag_t *tag = NULL; | ||
62 | size_t size; | ||
63 | |||
64 | sieve_value_t *val = sieve_value_get (args, 0); | ||
65 | if (!val) | ||
66 | { | ||
67 | sieve_error (mach, "size: can't get argument!"); | ||
68 | sieve_abort (mach); | ||
69 | } | ||
70 | |||
71 | message_size (sieve_get_message (mach), &size); | ||
72 | list_get (tags, 0, (void **)&tag); | ||
73 | if (!tag) | ||
74 | rc = size == val->v.number; | ||
75 | else if (tag->tag == TAG_OVER) | ||
76 | rc = size > val->v.number; | ||
77 | else if (tag->tag == TAG_UNDER) | ||
78 | rc = size < val->v.number; | ||
79 | |||
80 | return rc; | ||
61 | } | 81 | } |
62 | 82 | ||
63 | int | 83 | int |
64 | sieve_test_true (sieve_machine_t *mach, list_t args, list_t tags) | 84 | sieve_test_true (sieve_machine_t mach, list_t args, list_t tags) |
65 | { | 85 | { |
66 | return 0; | 86 | if (mach->debug_level & MU_SIEVE_DEBUG_TRACE) |
87 | sieve_debug (mach, "TRUE\n"); | ||
88 | return 1; | ||
67 | } | 89 | } |
68 | 90 | ||
69 | int | 91 | int |
70 | sieve_test_false (sieve_machine_t *mach, list_t args, list_t tags) | 92 | sieve_test_false (sieve_machine_t mach, list_t args, list_t tags) |
71 | { | 93 | { |
94 | if (mach->debug_level & MU_SIEVE_DEBUG_TRACE) | ||
95 | sieve_debug (mach, "FALSE\n"); | ||
72 | return 0; | 96 | return 0; |
73 | } | 97 | } |
74 | 98 | ||
75 | int | 99 | int |
76 | sieve_test_exists (sieve_machine_t *mach, list_t args, list_t tags) | 100 | _test_exists (void *item, void *data) |
77 | { | 101 | { |
78 | return 0; | 102 | header_t hdr = data; |
103 | size_t n; | ||
104 | |||
105 | return header_get_value (hdr, (char*)item, NULL, 0, &n); | ||
106 | } | ||
107 | |||
108 | int | ||
109 | sieve_test_exists (sieve_machine_t mach, list_t args, list_t tags) | ||
110 | { | ||
111 | header_t header = NULL; | ||
112 | sieve_value_t *val; | ||
113 | |||
114 | if (mach->debug_level & MU_SIEVE_DEBUG_TRACE) | ||
115 | sieve_debug (mach, "EXISTS\n"); | ||
116 | |||
117 | message_get_header (sieve_get_message (mach), &header); | ||
118 | val = sieve_value_get (args, 0); | ||
119 | if (!val) | ||
120 | { | ||
121 | sieve_error (mach, "exists: can't get argument!"); | ||
122 | sieve_abort (mach); | ||
123 | } | ||
124 | |||
125 | return list_do (val->v.list, _test_exists, header) == 0; | ||
79 | } | 126 | } |
80 | 127 | ||
81 | #define ADDRESS_PART \ | 128 | #define ADDRESS_PART \ |
... | @@ -142,7 +189,7 @@ void | ... | @@ -142,7 +189,7 @@ void |
142 | sieve_register_standard_tests () | 189 | sieve_register_standard_tests () |
143 | { | 190 | { |
144 | sieve_register_test ("false", sieve_test_false, NULL, NULL, 1); | 191 | sieve_register_test ("false", sieve_test_false, NULL, NULL, 1); |
145 | sieve_register_test ("true", sieve_test_false, NULL, NULL, 1); | 192 | sieve_register_test ("true", sieve_test_true, NULL, NULL, 1); |
146 | sieve_register_test ("address", sieve_test_address, | 193 | sieve_register_test ("address", sieve_test_address, |
147 | address_req_args, address_tags, 1); | 194 | address_req_args, address_tags, 1); |
148 | sieve_register_test ("size", sieve_test_size, | 195 | sieve_register_test ("size", sieve_test_size, | ... | ... |
-
Please register or sign in to post a comment