/src/pigeonhole/src/testsuite/testsuite-binary.c
Line | Count | Source |
1 | | /* Copyright (c) Pigeonhole authors, see top-level COPYING file */ |
2 | | |
3 | | #include "lib.h" |
4 | | #include "mempool.h" |
5 | | #include "imem.h" |
6 | | #include "array.h" |
7 | | #include "strfuncs.h" |
8 | | #include "unlink-directory.h" |
9 | | |
10 | | #include "sieve.h" |
11 | | #include "sieve-common.h" |
12 | | #include "sieve-script.h" |
13 | | #include "sieve-binary.h" |
14 | | #include "sieve-error.h" |
15 | | |
16 | | #include "testsuite-common.h" |
17 | | #include "testsuite-binary.h" |
18 | | |
19 | | #include <sys/stat.h> |
20 | | #include <sys/types.h> |
21 | | |
22 | | /* |
23 | | * State |
24 | | */ |
25 | | |
26 | | static char *testsuite_binary_tmp = NULL; |
27 | | |
28 | | /* |
29 | | * Initialization |
30 | | */ |
31 | | |
32 | | void testsuite_binary_init(void) |
33 | 0 | { |
34 | 0 | testsuite_binary_tmp = i_strconcat(testsuite_tmp_dir_get(), |
35 | 0 | "/binaries", NULL); |
36 | |
|
37 | 0 | if (mkdir(testsuite_binary_tmp, 0700) < 0) { |
38 | 0 | i_fatal("failed to create temporary directory '%s': %m", |
39 | 0 | testsuite_binary_tmp); |
40 | 0 | } |
41 | 0 | } |
42 | | |
43 | | void testsuite_binary_deinit(void) |
44 | 0 | { |
45 | 0 | const char *error; |
46 | |
|
47 | 0 | if (unlink_directory(testsuite_binary_tmp, UNLINK_DIRECTORY_FLAG_RMDIR, |
48 | 0 | &error) < 0) { |
49 | 0 | i_warning("failed to remove temporary directory '%s': %s", |
50 | 0 | testsuite_binary_tmp, error); |
51 | 0 | } |
52 | |
|
53 | 0 | i_free(testsuite_binary_tmp); |
54 | 0 | } |
55 | | |
56 | | void testsuite_binary_reset(void) |
57 | 0 | { |
58 | 0 | testsuite_binary_init(); |
59 | 0 | testsuite_binary_deinit(); |
60 | 0 | } |
61 | | |
62 | | /* |
63 | | * Binary Access |
64 | | */ |
65 | | |
66 | | bool testsuite_binary_save(struct sieve_binary *sbin, const char *name) |
67 | 0 | { |
68 | 0 | return (sieve_save_as(sbin, |
69 | 0 | t_strdup_printf("%s/%s", testsuite_binary_tmp, |
70 | 0 | sieve_binfile_from_name(name)), |
71 | 0 | TRUE, 0600, NULL) > 0); |
72 | 0 | } |
73 | | |
74 | | struct sieve_binary *testsuite_binary_load(const char *name) |
75 | 0 | { |
76 | 0 | struct sieve_instance *svinst = testsuite_sieve_instance; |
77 | 0 | struct sieve_binary *sbin; |
78 | |
|
79 | 0 | if (sieve_load(svinst, t_strdup_printf("%s/%s", testsuite_binary_tmp, |
80 | 0 | sieve_binfile_from_name(name)), |
81 | 0 | &sbin, NULL) < 0) |
82 | 0 | return NULL; |
83 | 0 | return sbin; |
84 | 0 | } |