Coverage Report

Created: 2026-04-12 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/testsuite/cmd-test-set.c
Line
Count
Source
1
/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
2
 */
3
4
#include "lib.h"
5
#include "ioloop.h"
6
#include "str-sanitize.h"
7
#include "istream.h"
8
#include "istream-header-filter.h"
9
10
#include "sieve-common.h"
11
#include "sieve-commands.h"
12
#include "sieve-code.h"
13
#include "sieve-actions.h"
14
#include "sieve-validator.h"
15
#include "sieve-generator.h"
16
#include "sieve-interpreter.h"
17
#include "sieve-code-dumper.h"
18
#include "sieve-result.h"
19
20
#include "testsuite-common.h"
21
#include "testsuite-objects.h"
22
23
#include <stdio.h>
24
25
/*
26
 * Test_set command
27
 *
28
 * Syntax
29
 *   test_set <testsuite object (member): string> <value: string>
30
 */
31
32
static bool cmd_test_set_validate
33
  (struct sieve_validator *valdtr, struct sieve_command *cmd);
34
static bool cmd_test_set_generate
35
  (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd);
36
37
const struct sieve_command_def cmd_test_set = {
38
  .identifier = "test_set",
39
  .type = SCT_COMMAND,
40
  .positional_args = 2,
41
  .subtests = 0,
42
  .block_allowed = FALSE,
43
  .block_required = FALSE,
44
  .validate = cmd_test_set_validate,
45
  .generate = cmd_test_set_generate
46
};
47
48
/*
49
 * Test_set operation
50
 */
51
52
static bool cmd_test_set_operation_dump
53
  (const struct sieve_dumptime_env *denv, sieve_size_t *address);
54
static int cmd_test_set_operation_execute
55
  (const struct sieve_runtime_env *renv, sieve_size_t *address);
56
57
const struct sieve_operation_def test_set_operation = {
58
  .mnemonic = "TEST_SET",
59
  .ext_def = &testsuite_extension,
60
  .code = TESTSUITE_OPERATION_TEST_SET,
61
  .dump = cmd_test_set_operation_dump,
62
  .execute = cmd_test_set_operation_execute
63
};
64
65
/*
66
 * Validation
67
 */
68
69
static bool cmd_test_set_validate
70
(struct sieve_validator *valdtr, struct sieve_command *cmd)
71
0
{
72
0
  struct sieve_ast_argument *arg = cmd->first_positional;
73
74
  /* Check arguments */
75
76
0
  if ( !sieve_validate_positional_argument
77
0
    (valdtr, cmd, arg, "object", 1, SAAT_STRING) ) {
78
0
    return FALSE;
79
0
  }
80
81
0
  if ( !testsuite_object_argument_activate(valdtr, arg, cmd) )
82
0
    return FALSE;
83
84
0
  arg = sieve_ast_argument_next(arg);
85
86
0
  if ( !sieve_validate_positional_argument
87
0
    (valdtr, cmd, arg, "value", 2, SAAT_STRING) ) {
88
0
    return FALSE;
89
0
  }
90
91
0
  return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE);
92
0
}
93
94
/*
95
 * Code generation
96
 */
97
98
static bool cmd_test_set_generate
99
(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd)
100
0
{
101
0
  sieve_operation_emit(cgenv->sblock, cmd->ext, &test_set_operation);
102
103
  /* Generate arguments */
104
0
  return sieve_generate_arguments(cgenv, cmd, NULL);
105
0
}
106
107
/*
108
 * Code dump
109
 */
110
111
static bool cmd_test_set_operation_dump
112
(const struct sieve_dumptime_env *denv, sieve_size_t *address)
113
0
{
114
0
  sieve_code_dumpf(denv, "TEST SET:");
115
0
  sieve_code_descend(denv);
116
117
0
  return
118
0
    testsuite_object_dump(denv, address) &&
119
0
    sieve_opr_string_dump(denv, address, "value");
120
0
}
121
122
/*
123
 * Intepretation
124
 */
125
126
static int cmd_test_set_operation_execute
127
(const struct sieve_runtime_env *renv, sieve_size_t *address)
128
0
{
129
0
  struct testsuite_object tobj;
130
0
  string_t *value;
131
0
  int member_id;
132
0
  int ret;
133
134
0
  if ( !testsuite_object_read_member
135
0
    (renv->sblock, address, &tobj, &member_id) ) {
136
0
    sieve_runtime_trace_error(renv, "invalid testsuite object member");
137
0
    return SIEVE_EXEC_BIN_CORRUPT;
138
0
  }
139
140
0
  if ( (ret=sieve_opr_string_read(renv, address, "string", &value)) <= 0 )
141
0
    return ret;
142
143
0
  if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
144
0
    sieve_runtime_trace(renv, 0, "testsuite: test_set command");
145
0
    sieve_runtime_trace_descend(renv);
146
0
    sieve_runtime_trace(renv, 0,
147
0
      "set test parameter '%s' = \"%s\"",
148
0
        testsuite_object_member_name(&tobj, member_id), str_c(value));
149
0
  }
150
151
0
  if ( tobj.def == NULL || tobj.def->set_member == NULL ) {
152
0
    sieve_runtime_trace_error(renv, "unimplemented testsuite object");
153
0
    return SIEVE_EXEC_FAILURE;
154
0
  }
155
156
0
  tobj.def->set_member(renv, member_id, value);
157
0
  return SIEVE_EXEC_OK;
158
0
}
159
160
161