/src/pigeonhole/src/lib-sieve/sieve-comparators.h
Line | Count | Source |
1 | | #ifndef SIEVE_COMPARATORS_H |
2 | | #define SIEVE_COMPARATORS_H |
3 | | |
4 | | #include "sieve-common.h" |
5 | | #include "sieve-extensions.h" |
6 | | #include "sieve-commands.h" |
7 | | #include "sieve-objects.h" |
8 | | #include "sieve-code.h" |
9 | | |
10 | | /* |
11 | | * Core comparators |
12 | | */ |
13 | | |
14 | | enum sieve_comparator_code { |
15 | | SIEVE_COMPARATOR_I_OCTET, |
16 | | SIEVE_COMPARATOR_I_ASCII_CASEMAP, |
17 | | SIEVE_COMPARATOR_I_UNICODE_CASEMAP, |
18 | | SIEVE_COMPARATOR_CUSTOM |
19 | | }; |
20 | | |
21 | | extern const struct sieve_comparator_def i_octet_comparator; |
22 | | extern const struct sieve_comparator_def i_ascii_casemap_comparator; |
23 | | extern const struct sieve_comparator_def i_unicode_casemap_comparator; |
24 | | |
25 | | /* |
26 | | * Comparator flags |
27 | | */ |
28 | | |
29 | | enum sieve_comparator_flags { |
30 | | SIEVE_COMPARATOR_FLAG_ORDERING = (1 << 0), |
31 | | SIEVE_COMPARATOR_FLAG_EQUALITY = (1 << 1), |
32 | | SIEVE_COMPARATOR_FLAG_PREFIX_MATCH = (1 << 2), |
33 | | SIEVE_COMPARATOR_FLAG_SUBSTRING_MATCH = (1 << 3), |
34 | | }; |
35 | | |
36 | | /* |
37 | | * Comparator definition |
38 | | */ |
39 | | |
40 | | struct sieve_comparator_def { |
41 | | struct sieve_object_def obj_def; |
42 | | |
43 | | unsigned int flags; |
44 | | |
45 | | /* Equality and ordering */ |
46 | | |
47 | | int (*compare)(const struct sieve_comparator *cmp, |
48 | | const char *val1, size_t val1_size, |
49 | | const char *val2, size_t val2_size); |
50 | | |
51 | | /* Prefix and substring match */ |
52 | | |
53 | | bool (*char_match)(const struct sieve_comparator *cmp, |
54 | | const char **val, const char *val_end, |
55 | | const char **key, const char *key_end); |
56 | | bool (*char_skip)(const struct sieve_comparator *cmp, |
57 | | const char **val, const char *val_end); |
58 | | }; |
59 | | |
60 | | /* |
61 | | * Comparator instance |
62 | | */ |
63 | | |
64 | | struct sieve_comparator { |
65 | | struct sieve_object object; |
66 | | |
67 | | const struct sieve_comparator_def *def; |
68 | | }; |
69 | | |
70 | | #define SIEVE_COMPARATOR_DEFAULT(definition) \ |
71 | 0 | { SIEVE_OBJECT_DEFAULT(definition), &(definition) } |
72 | | |
73 | | #define sieve_comparator_name(cmp) \ |
74 | | ((cmp)->object.def->identifier) |
75 | | #define sieve_comparator_is(cmp, definition) \ |
76 | | ((cmp)->def == &(definition)) |
77 | | |
78 | | static inline const struct sieve_comparator * |
79 | | sieve_comparator_copy(pool_t pool, const struct sieve_comparator *cmp_orig) |
80 | 0 | { |
81 | 0 | struct sieve_comparator *cmp = p_new(pool, struct sieve_comparator, 1); |
82 | 0 |
|
83 | 0 | *cmp = *cmp_orig; |
84 | 0 | return cmp; |
85 | 0 | } Unexecuted instantiation: tst-test-error.c:sieve_comparator_copy Unexecuted instantiation: tst-test-result-action.c:sieve_comparator_copy |
86 | | |
87 | | /* |
88 | | * Comparator tagged argument |
89 | | */ |
90 | | |
91 | | extern const struct sieve_argument_def comparator_tag; |
92 | | |
93 | | static inline bool |
94 | | sieve_argument_is_comparator(struct sieve_ast_argument *arg) |
95 | 0 | { |
96 | 0 | return (arg->argument != NULL && |
97 | 0 | (arg->argument->def == &comparator_tag)); |
98 | 0 | } Unexecuted instantiation: tst-test-error.c:sieve_argument_is_comparator Unexecuted instantiation: tst-test-result-action.c:sieve_argument_is_comparator |
99 | | |
100 | | void sieve_comparators_link_tag(struct sieve_validator *validator, |
101 | | struct sieve_command_registration *cmd_reg, |
102 | | int id_code); |
103 | | bool sieve_comparator_tag_is(struct sieve_ast_argument *tag, |
104 | | const struct sieve_comparator_def *cmp); |
105 | | const struct sieve_comparator * |
106 | | sieve_comparator_tag_get(struct sieve_ast_argument *tag); |
107 | | |
108 | | void sieve_comparator_register(struct sieve_validator *validator, |
109 | | const struct sieve_extension *ext, |
110 | | const struct sieve_comparator_def *cmp); |
111 | | |
112 | | /* |
113 | | * Comparator operand |
114 | | */ |
115 | | |
116 | | #define SIEVE_EXT_DEFINE_COMPARATOR(OP) SIEVE_EXT_DEFINE_OBJECT(OP) |
117 | | #define SIEVE_EXT_DEFINE_COMPARATORS(OPS) SIEVE_EXT_DEFINE_OBJECTS(OPS) |
118 | | |
119 | | extern const struct sieve_operand_class sieve_comparator_operand_class; |
120 | | extern const struct sieve_operand_def comparator_operand; |
121 | | |
122 | | static inline void |
123 | | sieve_opr_comparator_emit(struct sieve_binary_block *sblock, |
124 | | const struct sieve_comparator *cmp) |
125 | 0 | { |
126 | 0 | sieve_opr_object_emit(sblock, cmp->object.ext, cmp->object.def); |
127 | 0 | } Unexecuted instantiation: tst-test-error.c:sieve_opr_comparator_emit Unexecuted instantiation: tst-test-result-action.c:sieve_opr_comparator_emit |
128 | | static inline bool |
129 | | sieve_opr_comparator_dump(const struct sieve_dumptime_env *denv, |
130 | | sieve_size_t *address) |
131 | 0 | { |
132 | 0 | return sieve_opr_object_dump(denv, &sieve_comparator_operand_class, |
133 | 0 | address, NULL); |
134 | 0 | } Unexecuted instantiation: tst-test-error.c:sieve_opr_comparator_dump Unexecuted instantiation: tst-test-result-action.c:sieve_opr_comparator_dump |
135 | | |
136 | | static inline int |
137 | | sieve_opr_comparator_read(const struct sieve_runtime_env *renv, |
138 | | sieve_size_t *address, struct sieve_comparator *cmp) |
139 | 0 | { |
140 | 0 | if (!sieve_opr_object_read(renv, &sieve_comparator_operand_class, |
141 | 0 | address, &cmp->object)) |
142 | 0 | return SIEVE_EXEC_BIN_CORRUPT; |
143 | 0 |
|
144 | 0 | cmp->def = (const struct sieve_comparator_def *)cmp->object.def; |
145 | 0 | return SIEVE_EXEC_OK; |
146 | 0 | } Unexecuted instantiation: tst-test-error.c:sieve_opr_comparator_read Unexecuted instantiation: tst-test-result-action.c:sieve_opr_comparator_read |
147 | | |
148 | | /* |
149 | | * Trivial/Common comparator method implementations |
150 | | */ |
151 | | |
152 | | bool sieve_comparator_octet_skip(const struct sieve_comparator *cmp ATTR_UNUSED, |
153 | | const char **val, const char *val_end); |
154 | | |
155 | | #endif |