Coverage Report

Created: 2026-04-12 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) 2002-2018 Pigeonhole authors, see the included COPYING file
2
 */
3
4
#include "lib.h"
5
6
#include "sieve-common.h"
7
#include "sieve-commands.h"
8
#include "sieve-extensions.h"
9
#include "sieve-validator.h"
10
#include "sieve-generator.h"
11
12
/*
13
 * Require command
14
 *
15
 * Syntax
16
 *   Syntax: require <capabilities: string-list>
17
 */
18
19
static bool cmd_require_validate
20
  (struct sieve_validator *valdtr, struct sieve_command *cmd);
21
22
const struct sieve_command_def cmd_require = {
23
  .identifier = "require",
24
  .type = SCT_COMMAND,
25
  .positional_args = 1,
26
  .subtests = 0,
27
  .block_allowed = FALSE,
28
  .block_required = FALSE,
29
  .validate = cmd_require_validate
30
};
31
32
/*
33
 * Validation
34
 */
35
36
static bool cmd_require_validate
37
(struct sieve_validator *valdtr, struct sieve_command *cmd)
38
0
{
39
0
  bool result = TRUE;
40
0
  struct sieve_ast_argument *arg;
41
0
  struct sieve_command *prev = sieve_command_prev(cmd);
42
43
  /* Check valid command placement */
44
0
  if ( !sieve_command_is_toplevel(cmd) ||
45
0
    ( !sieve_command_is_first(cmd) && prev != NULL &&
46
0
      !sieve_command_is(prev, cmd_require) ) )
47
0
  {
48
0
    sieve_command_validate_error(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 = sieve_validator_extension_load_by_name
60
0
      (valdtr, cmd, arg, sieve_ast_argument_strc(arg));
61
62
0
    if ( ext == NULL ) result = FALSE;
63
64
0
  } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) {
65
    /* String list */
66
0
    struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg);
67
68
0
    while ( stritem != NULL ) {
69
0
      const struct sieve_extension *ext = sieve_validator_extension_load_by_name
70
0
        (valdtr, cmd, stritem, sieve_ast_strlist_strc(stritem));
71
72
0
      if ( ext == NULL ) result = FALSE;
73
74
0
      stritem = sieve_ast_strlist_next(stritem);
75
0
    }
76
0
  } else {
77
    /* Something else */
78
0
    sieve_argument_validate_error(valdtr, arg,
79
0
      "the require command accepts a single string or string list argument, "
80
0
      "but %s was found",
81
0
      sieve_ast_argument_name(arg));
82
0
    return FALSE;
83
0
  }
84
85
0
  return result;
86
0
}