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
];
47 /* end-of-line character(s) */
48 char r_eol
[VIRUSFILTER_IO_EOL_SIZE
];
52 char r_buffer
[VIRUSFILTER_IO_BUFFER_SIZE
];
56 struct virusfilter_cache_entry
{
58 virusfilter_result result
;
62 struct virusfilter_cache
{
63 struct memcache
*cache
;
68 /* ====================================================================== */
70 char *virusfilter_string_sub(
72 connection_struct
*conn
,
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(
84 int virusfilter_io_set_connect_timeout(
85 struct virusfilter_io_handle
*io_h
,
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
,
93 void virusfilter_io_set_readl_eol(
94 struct virusfilter_io_handle
*io_h
,
97 bool virusfilter_io_connect_path(
98 struct virusfilter_io_handle
*io_h
,
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
,
107 bool virusfilter_io_write(
108 struct virusfilter_io_handle
*io_h
,
111 bool virusfilter_io_writel(
112 struct virusfilter_io_handle
*io_h
,
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
,
128 bool virusfilter_io_writefl_readl(
129 struct virusfilter_io_handle
*io_h
,
131 const char *fmt
, ...);
133 /* Scan result cache */
134 struct virusfilter_cache
*virusfilter_cache_new(
138 bool virusfilter_cache_entry_add(
139 struct virusfilter_cache
*cache
,
140 const char *directory
,
142 virusfilter_result result
,
144 bool virusfilter_cache_entry_rename(
145 struct virusfilter_cache
*cache
,
146 const char *directory
,
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
,
154 void virusfilter_cache_remove(
155 struct virusfilter_cache
*cache
,
156 const char *directory
,
158 void virusfilter_cache_purge(struct virusfilter_cache
*cache
);
160 /* Shell scripting */
161 int virusfilter_env_set(
166 int virusfilter_shell_set_conn_env(
169 connection_struct
*conn
);
170 int virusfilter_shell_run(
174 connection_struct
*conn
,
177 #endif /* _VIRUSFILTER_UTILS_H */