summaryrefslogtreecommitdiffstats
path: root/pigeonhole/src/lib-sieve/plugins/relational/ext-relational-common.h
blob: c0f7d3bc5fd5331e1a726f9887f3eb8319468fed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef EXT_RELATIONAL_COMMON_H
#define EXT_RELATIONAL_COMMON_H

#include "lib.h"
#include "str.h"

#include "sieve-common.h"

/*
 * Types
 */

enum ext_relational_match_type {
	RELATIONAL_VALUE,
	RELATIONAL_COUNT
};

enum relational_match {
	REL_MATCH_GREATER,
	REL_MATCH_GREATER_EQUAL,
	REL_MATCH_LESS,
	REL_MATCH_LESS_EQUAL,
	REL_MATCH_EQUAL,
	REL_MATCH_NOT_EQUAL,
	REL_MATCH_INVALID
};

#define REL_MATCH_INDEX(type, match) (type * REL_MATCH_INVALID + match)
#define REL_MATCH_TYPE(index) (index / REL_MATCH_INVALID)
#define REL_MATCH(index) (index % REL_MATCH_INVALID)

/*
 * Extension definitions
 */

extern const struct sieve_extension_def relational_extension;

/*
 * Match types
 */

/* Registered for validation */

extern const struct sieve_match_type_def value_match_type;
extern const struct sieve_match_type_def count_match_type;

/* Used in byte code */

extern const struct sieve_match_type_def rel_match_count_gt;
extern const struct sieve_match_type_def rel_match_count_ge;
extern const struct sieve_match_type_def rel_match_count_lt;
extern const struct sieve_match_type_def rel_match_count_le;
extern const struct sieve_match_type_def rel_match_count_eq;
extern const struct sieve_match_type_def rel_match_count_ne;

extern const struct sieve_match_type_def rel_match_value_gt;
extern const struct sieve_match_type_def rel_match_value_ge;
extern const struct sieve_match_type_def rel_match_value_lt;
extern const struct sieve_match_type_def rel_match_value_le;
extern const struct sieve_match_type_def rel_match_value_eq;
extern const struct sieve_match_type_def rel_match_value_ne;

/*
 * Operand
 */

extern const struct sieve_operand_def rel_match_type_operand;


/*
 * Match type validation
 */

bool mcht_relational_validate(struct sieve_validator *validator,
			      struct sieve_ast_argument **arg,
			      struct sieve_match_type_context *ctx);

/*
 * Value match function (also used by :count)
 */

int mcht_value_match_key(struct sieve_match_context *mctx,
			 const char *val, size_t val_size,
			 const char *key, size_t key_size);

#endif