Coverage Report

Created: 2026-09-03 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/lib-sieve/cmd-require.c
Line
Count
Source
1
/* Copyright (c) Pigeonhole authors, see top-level COPYING file */
2
3
#include "lib.h"
4
5
#include "sieve-common.h"
6
#include "sieve-commands.h"
7
#include "sieve-extensions.h"
8
#include "sieve-validator.h"
9
#include "sieve-generator.h"
10
11
/*
12
 * Require command
13
 *
14
 * Syntax
15
 *   Syntax: require <capabilities: string-list>
16
 */
17
18
static bool
19
cmd_require_validate(struct sieve_validator *valdtr, struct sieve_command *cmd);
20
21
const struct sieve_command_def cmd_require = {
22
  .identifier = "require",
23
  .type = SCT_COMMAND,
24
  .positional_args = 1,
25
  .subtests = 0,
26
  .block_allowed = FALSE,
27
  .block_required = FALSE,
28
  .validate = cmd_require_validate
29
};
30
31
/*
32
 * Validation
33
 */
34
35
static bool
36
cmd_require_validate(struct sieve_validator *valdtr, struct sieve_command *cmd)
37
0
{
38
0
  bool result = TRUE;
39
0
  struct sieve_ast_argument *arg;
40
0
  struct sieve_command *prev = sieve_command_prev(cmd);
41
42
  /* Check valid command placement */
43
0
  if (!sieve_command_is_toplevel(cmd) ||
44
0
      (!sieve_command_is_first(cmd) && prev != NULL &&
45
0
       !sieve_command_is(prev, cmd_require)))
46
0
  {
47
0
    sieve_command_validate_error(
48
0
      valdtr, cmd,
49
0
      "require commands can only be placed at top level "
50
0
      "at the beginning of the file");
51
0
    return FALSE;
52
0
  }
53
54
  /* Check argument and load specified extension(s) */
55
56
0
  arg = cmd->first_positional;
57
0
  if (sieve_ast_argument_type(arg) == SAAT_STRING) {
58
    /* Single string */
59
0
    const struct sieve_extension *ext =
60
0
      sieve_validator_extension_load_by_name(
61
0
        valdtr, cmd, arg, sieve_ast_argument_strc(arg));
62
63
0
    if (ext == NULL)
64
0
      result = FALSE;
65
0
  } else if (sieve_ast_argument_type(arg) == SAAT_STRING_LIST) {
66
    /* String list */
67
0
    struct sieve_ast_argument *stritem =
68
0
      sieve_ast_strlist_first(arg);
69
70
0
    while (stritem != NULL) {
71
0
      const struct sieve_extension *ext =
72
0
        sieve_validator_extension_load_by_name(
73
0
          valdtr, cmd, stritem,
74
0
          sieve_ast_strlist_strc(stritem));
75
76
0
      if (ext == NULL)
77
0
        result = FALSE;
78
0
      stritem = sieve_ast_strlist_next(stritem);
79
0
    }
80
0
  } else {
81
    /* Something else */
82
0
    sieve_argument_validate_error(
83
0
      valdtr, arg,
84
0
      "the require command accepts a single string or string list argument, "
85
0
      "but %s was found",
86
0
      sieve_ast_argument_name(arg));
87
0
    return FALSE;
88
0
  }
89
90
0
  return result;
91
0
}