Describe implication of upstream ICU-22610
[samba.git] / source3 / modules / vfs_virusfilter_utils.h
blob69754aa6546e40cbd86639db9c8fed782bb50b82
1 /*
2 Samba-VirusFilter VFS modules
3 Copyright (C) 2010-2016 SATOH Fumiyasu @ OSS Technology Corp., Japan
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _VIRUSFILTER_UTILS_H
20 #define _VIRUSFILTER_UTILS_H
22 #include "modules/vfs_virusfilter_common.h"
23 #include "../lib/util/memcache.h"
24 #include "../lib/util/strv.h"
26 /*#define str_eq(s1, s2) \
27 ((strcmp((s1), (s2)) == 0) ? true : false)
28 #define strn_eq(s1, s2, n) \
29 ((strncmp((s1), (s2), (n)) == 0) ? true : false) */
31 /* "* 3" is for %-encoding */
32 #define VIRUSFILTER_IO_URL_MAX (PATH_MAX * 3)
33 #define VIRUSFILTER_IO_BUFFER_SIZE (VIRUSFILTER_IO_URL_MAX + 128)
34 #define VIRUSFILTER_IO_EOL_SIZE 1
35 #define VIRUSFILTER_IO_IOV_MAX 16
36 #define VIRUSFILTER_CACHE_BUFFER_SIZE (PATH_MAX + 128)
38 struct virusfilter_io_handle {
39 struct tstream_context *stream;
40 int connect_timeout; /* msec */
41 int io_timeout; /* msec */
43 /* end-of-line character(s) */
44 char w_eol[VIRUSFILTER_IO_EOL_SIZE];
45 int w_eol_size;
47 /* end-of-line character(s) */
48 char r_eol[VIRUSFILTER_IO_EOL_SIZE];
49 int r_eol_size;
51 /* buffer */
52 char r_buffer[VIRUSFILTER_IO_BUFFER_SIZE];
53 size_t r_len;
56 struct virusfilter_cache_entry {
57 time_t time;
58 virusfilter_result result;
59 char *report;
62 struct virusfilter_cache {
63 struct memcache *cache;
64 TALLOC_CTX *ctx;
65 time_t time_limit;
68 /* ====================================================================== */
70 char *virusfilter_string_sub(
71 TALLOC_CTX *mem_ctx,
72 connection_struct *conn,
73 const char *str);
74 int virusfilter_vfs_next_move(
75 vfs_handle_struct *handle,
76 const struct smb_filename *smb_fname_src,
77 const struct smb_filename *smb_fname_dst);
79 /* Line-based socket I/O */
80 struct virusfilter_io_handle *virusfilter_io_new(
81 TALLOC_CTX *mem_ctx,
82 int connect_timeout,
83 int timeout);
84 int virusfilter_io_set_connect_timeout(
85 struct virusfilter_io_handle *io_h,
86 int timeout);
87 int virusfilter_io_set_io_timeout(
88 struct virusfilter_io_handle *io_h, int timeout);
89 void virusfilter_io_set_writel_eol(
90 struct virusfilter_io_handle *io_h,
91 const char *eol,
92 int eol_size);
93 void virusfilter_io_set_readl_eol(
94 struct virusfilter_io_handle *io_h,
95 const char *eol,
96 int eol_size);
97 bool virusfilter_io_connect_path(
98 struct virusfilter_io_handle *io_h,
99 const char *path);
100 bool virusfilter_io_disconnect(
101 struct virusfilter_io_handle *io_h);
102 bool write_data_iov_timeout(
103 struct tstream_context *stream,
104 const struct iovec *iov,
105 size_t iovcnt,
106 int ms_timeout);
107 bool virusfilter_io_write(
108 struct virusfilter_io_handle *io_h,
109 const char *data,
110 size_t data_size);
111 bool virusfilter_io_writel(
112 struct virusfilter_io_handle *io_h,
113 const char *data,
114 size_t data_size);
115 bool virusfilter_io_writefl(
116 struct virusfilter_io_handle *io_h,
117 const char *data_fmt, ...);
118 bool virusfilter_io_vwritefl(
119 struct virusfilter_io_handle *io_h,
120 const char *data_fmt, va_list ap);
121 bool virusfilter_io_writev(
122 struct virusfilter_io_handle *io_h, ...);
123 bool virusfilter_io_writevl(
124 struct virusfilter_io_handle *io_h, ...);
125 bool virusfilter_io_readl(TALLOC_CTX *ctx,
126 struct virusfilter_io_handle *io_h,
127 char **read_line);
128 bool virusfilter_io_writefl_readl(
129 struct virusfilter_io_handle *io_h,
130 char **read_line,
131 const char *fmt, ...);
133 /* Scan result cache */
134 struct virusfilter_cache *virusfilter_cache_new(
135 TALLOC_CTX *ctx,
136 int entry_limit,
137 time_t time_limit);
138 bool virusfilter_cache_entry_add(
139 struct virusfilter_cache *cache,
140 const char *directory,
141 const char *fname,
142 virusfilter_result result,
143 char *report);
144 bool virusfilter_cache_entry_rename(
145 struct virusfilter_cache *cache,
146 const char *directory,
147 char *old_fname,
148 char *new_fname);
149 void virusfilter_cache_entry_free(struct virusfilter_cache_entry *cache_e);
150 struct virusfilter_cache_entry *virusfilter_cache_get(
151 struct virusfilter_cache *cache,
152 const char *directory,
153 const char *fname);
154 void virusfilter_cache_remove(
155 struct virusfilter_cache *cache,
156 const char *directory,
157 const char *fname);
158 void virusfilter_cache_purge(struct virusfilter_cache *cache);
160 /* Shell scripting */
161 int virusfilter_env_set(
162 TALLOC_CTX *mem_ctx,
163 char **env_list,
164 const char *name,
165 const char *value);
166 int virusfilter_shell_set_conn_env(
167 TALLOC_CTX *mem_ctx,
168 char **env_list,
169 connection_struct *conn);
170 int virusfilter_shell_run(
171 TALLOC_CTX *mem_ctx,
172 const char *cmd,
173 char **env_list,
174 connection_struct *conn,
175 bool sanitize);
177 #endif /* _VIRUSFILTER_UTILS_H */