Coverage Report

Created: 2026-06-15 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/lib-sieve/storage/data/sieve-data-script.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
#include "strfuncs.h"
7
#include "istream.h"
8
9
#include "sieve-common.h"
10
#include "sieve-error.h"
11
#include "sieve-dump.h"
12
#include "sieve-binary.h"
13
14
#include "sieve-data-storage.h"
15
16
/*
17
 * Script data implementation
18
 */
19
20
static struct sieve_data_script *sieve_data_script_alloc(void)
21
0
{
22
0
  struct sieve_data_script *dscript;
23
0
  pool_t pool;
24
25
0
  pool = pool_alloconly_create("sieve_data_script", 1024);
26
0
  dscript = p_new(pool, struct sieve_data_script, 1);
27
0
  dscript->script = sieve_data_script;
28
0
  dscript->script.pool = pool;
29
30
0
  return dscript;
31
0
}
32
33
struct sieve_script *
34
sieve_data_script_create_from_input(struct sieve_instance *svinst,
35
            const char *cause, const char *name,
36
            struct istream *input)
37
0
{
38
0
  struct sieve_storage *storage;
39
0
  struct sieve_data_script *dscript = NULL;
40
0
  int ret;
41
42
0
  ret = sieve_storage_alloc(svinst, svinst->event, &sieve_data_storage,
43
0
          cause, "data", "data", "data", 0, &storage,
44
0
          NULL, NULL);
45
0
  i_assert(ret >= 0);
46
47
0
  dscript = sieve_data_script_alloc();
48
0
  sieve_script_init(&dscript->script, storage, &sieve_data_script, name);
49
50
0
  dscript->data = input;
51
0
  i_stream_ref(dscript->data);
52
53
0
  sieve_storage_unref(&storage);
54
55
0
  dscript->script.open = TRUE;
56
57
0
  return &dscript->script;
58
0
}
59
60
static void sieve_data_script_destroy(struct sieve_script *script)
61
0
{
62
0
  struct sieve_data_script *dscript =
63
0
    container_of(script, struct sieve_data_script, script);
64
65
0
  i_stream_unref(&dscript->data);
66
0
}
67
68
static int
69
sieve_data_script_get_stream(struct sieve_script *script,
70
           struct istream **stream_r)
71
0
{
72
0
  struct sieve_data_script *dscript =
73
0
    container_of(script, struct sieve_data_script, script);
74
75
0
  i_stream_ref(dscript->data);
76
0
  i_stream_seek(dscript->data, 0);
77
78
0
  *stream_r = dscript->data;
79
0
  return 0;
80
0
}
81
82
const struct sieve_script sieve_data_script = {
83
  .driver_name = SIEVE_DATA_STORAGE_DRIVER_NAME,
84
  .v = {
85
    .destroy = sieve_data_script_destroy,
86
87
    .get_stream = sieve_data_script_get_stream,
88
  },
89
};