Coverage Report

Created: 2026-09-14 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/lib-sieve/plugins/enotify/tst-valid-notify-method.c
Line
Count
Source
1
/* Copyright (c) Pigeonhole authors, see top-level COPYING file */
2
3
#include "sieve-common.h"
4
#include "sieve-commands.h"
5
#include "sieve-stringlist.h"
6
#include "sieve-code.h"
7
#include "sieve-comparators.h"
8
#include "sieve-match-types.h"
9
#include "sieve-validator.h"
10
#include "sieve-generator.h"
11
#include "sieve-interpreter.h"
12
#include "sieve-dump.h"
13
#include "sieve-match.h"
14
15
#include "ext-enotify-common.h"
16
17
/*
18
 * Valid_notify_method test
19
 *
20
 * Syntax:
21
 *   valid_notify_method <notification-uris: string-list>
22
 */
23
24
static bool
25
tst_vnotifym_validate(struct sieve_validator *valdtr,
26
          struct sieve_command *tst);
27
static bool
28
tst_vnotifym_generate(const struct sieve_codegen_env *cgenv,
29
          struct sieve_command *ctx);
30
31
const struct sieve_command_def valid_notify_method_test = {
32
  .identifier = "valid_notify_method",
33
  .type = SCT_TEST,
34
  .positional_args = 1,
35
  .subtests = 0,
36
  .block_allowed = FALSE,
37
  .block_required = FALSE,
38
  .validate = tst_vnotifym_validate,
39
  .generate = tst_vnotifym_generate,
40
};
41
42
/*
43
 * Valid_notify_method operation
44
 */
45
46
static bool
47
tst_vnotifym_operation_dump(const struct sieve_dumptime_env *denv,
48
          sieve_size_t *address);
49
static int
50
tst_vnotifym_operation_execute(const struct sieve_runtime_env *renv,
51
             sieve_size_t *address);
52
53
const struct sieve_operation_def valid_notify_method_operation = {
54
  .mnemonic = "VALID_NOTIFY_METHOD",
55
  .ext_def = &enotify_extension,
56
  .code = EXT_ENOTIFY_OPERATION_VALID_NOTIFY_METHOD,
57
  .dump = tst_vnotifym_operation_dump,
58
  .execute = tst_vnotifym_operation_execute,
59
};
60
61
/*
62
 * Test validation
63
 */
64
65
static bool
66
tst_vnotifym_validate(struct sieve_validator *valdtr, struct sieve_command *tst)
67
0
{
68
0
  struct sieve_ast_argument *arg = tst->first_positional;
69
70
0
  if (!sieve_validate_positional_argument(
71
0
    valdtr, tst, arg, "notification-uris", 1, SAAT_STRING_LIST))
72
0
    return FALSE;
73
0
  return sieve_validator_argument_activate(valdtr, tst, arg, FALSE);
74
0
}
75
76
/*
77
 * Test generation
78
 */
79
80
static bool
81
tst_vnotifym_generate(const struct sieve_codegen_env *cgenv,
82
          struct sieve_command *cmd)
83
0
{
84
0
  sieve_operation_emit(cgenv->sblock, cmd->ext,
85
0
           &valid_notify_method_operation);
86
87
  /* Generate arguments */
88
0
  return sieve_generate_arguments(cgenv, cmd, NULL);
89
0
}
90
91
/*
92
 * Code dump
93
 */
94
95
static bool
96
tst_vnotifym_operation_dump(const struct sieve_dumptime_env *denv,
97
          sieve_size_t *address)
98
0
{
99
0
  sieve_code_dumpf(denv, "VALID_NOTIFY_METHOD");
100
0
  sieve_code_descend(denv);
101
102
0
  return sieve_opr_stringlist_dump(denv, address, "notify-uris");
103
0
}
104
105
/*
106
 * Code execution
107
 */
108
109
static int
110
tst_vnotifym_operation_execute(const struct sieve_runtime_env *renv,
111
             sieve_size_t *address)
112
0
{
113
0
  struct sieve_stringlist *notify_uris;
114
0
  string_t *uri_item;
115
0
  bool all_valid = TRUE;
116
0
  int ret;
117
118
  /*
119
   * Read operands
120
   */
121
122
  /* Read notify uris */
123
0
  ret = sieve_opr_stringlist_read(renv, address, "notify-uris",
124
0
          &notify_uris);
125
0
  if (ret <= 0)
126
0
    return ret;
127
128
  /*
129
   * Perform operation
130
   */
131
132
0
  sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS,
133
0
          "valid_notify_method test");
134
135
0
  uri_item = NULL;
136
0
  while ((ret = sieve_stringlist_next_item(notify_uris, &uri_item)) > 0) {
137
0
    if (!ext_enotify_runtime_method_validate(renv, uri_item)) {
138
0
      all_valid = FALSE;
139
0
      break;
140
0
    }
141
0
  }
142
143
0
  if (ret < 0) {
144
0
    sieve_runtime_trace_error(renv, "invalid method uri item");
145
0
    return SIEVE_EXEC_BIN_CORRUPT;
146
0
  }
147
148
0
  sieve_interpreter_set_test_result(renv->interp, all_valid);
149
0
  return SIEVE_EXEC_OK;
150
0
}