Coverage Report

Created: 2026-05-16 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/lib-sieve/plugins/relational/mcht-value.c
Line
Count
Source
1
/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
2
 */
3
4
#include "lib.h"
5
#include "str.h"
6
7
#include "sieve-common.h"
8
9
#include "sieve-ast.h"
10
#include "sieve-code.h"
11
#include "sieve-extensions.h"
12
#include "sieve-commands.h"
13
#include "sieve-comparators.h"
14
#include "sieve-match-types.h"
15
#include "sieve-validator.h"
16
#include "sieve-generator.h"
17
#include "sieve-interpreter.h"
18
#include "sieve-match.h"
19
20
#include "ext-relational-common.h"
21
22
/*
23
 * Match-type objects
24
 */
25
26
const struct sieve_match_type_def value_match_type = {
27
  SIEVE_OBJECT("value",
28
    &rel_match_type_operand, RELATIONAL_VALUE),
29
  .validate = mcht_relational_validate
30
};
31
32
#define VALUE_MATCH_TYPE(name, rel_match)                       \
33
const struct sieve_match_type_def rel_match_value_ ## name = {  \
34
  SIEVE_OBJECT("value-" #name,                                  \
35
    &rel_match_type_operand,                                    \
36
    REL_MATCH_INDEX(RELATIONAL_VALUE, rel_match)),              \
37
  .match_key = mcht_value_match_key,                            \
38
}
39
40
VALUE_MATCH_TYPE(gt, REL_MATCH_GREATER);
41
VALUE_MATCH_TYPE(ge, REL_MATCH_GREATER_EQUAL);
42
VALUE_MATCH_TYPE(lt, REL_MATCH_LESS);
43
VALUE_MATCH_TYPE(le, REL_MATCH_LESS_EQUAL);
44
VALUE_MATCH_TYPE(eq, REL_MATCH_EQUAL);
45
VALUE_MATCH_TYPE(ne, REL_MATCH_NOT_EQUAL);
46
47
/*
48
 * Match-type implementation
49
 */
50
51
int mcht_value_match_key
52
(struct sieve_match_context *mctx, const char *val, size_t val_size,
53
  const char *key, size_t key_size)
54
0
{
55
0
  const struct sieve_match_type *mtch = mctx->match_type;
56
0
  unsigned int rel_match = REL_MATCH(mtch->object.def->code);
57
0
  int cmp_result;
58
59
0
  cmp_result = mctx->comparator->def->
60
0
    compare(mctx->comparator, val, val_size, key, key_size);
61
62
0
  switch ( rel_match ) {
63
0
  case REL_MATCH_GREATER:
64
0
    return ( cmp_result > 0 ? 1 : 0 );
65
0
  case REL_MATCH_GREATER_EQUAL:
66
0
    return ( cmp_result >= 0 ? 1 : 0 );
67
0
  case REL_MATCH_LESS:
68
0
    return ( cmp_result < 0 ? 1 : 0 );
69
0
  case REL_MATCH_LESS_EQUAL:
70
0
    return ( cmp_result <= 0 ? 1 : 0 );
71
0
  case REL_MATCH_EQUAL:
72
0
    return ( cmp_result == 0 ? 1 : 0);
73
0
  case REL_MATCH_NOT_EQUAL:
74
0
    return ( cmp_result != 0 ? 1 : 0);
75
0
  }
76
77
0
  i_unreached();
78
0
}
79
80