/[imapfilter]/imapfilter/imapfilter.h
ViewVC logotype

Contents of /imapfilter/imapfilter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.63 - (show annotations)
Sun Jul 27 15:54:49 2003 UTC (20 years, 8 months ago) by lefcha
Branch: MAIN
Changes since 1.62: +14 -10 lines
File MIME type: text/plain
Use new *_buffer() routines for input/output buffers.

1 #ifndef IMAPFILTER_H
2 #define IMAPFILTER_H
3
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <sys/stat.h>
7 #include <sys/types.h>
8 #include <dirent.h>
9
10 #include "config.h"
11
12 #ifdef SSL_TLS
13 #include <openssl/ssl.h>
14 #include <openssl/x509.h>
15 #endif
16
17 #ifndef DATA_H
18 #include "data.h"
19 #endif
20
21 /* Program's version number. */
22 #define IMAPFILTER_VERSION "0.8.9"
23
24 /* Error codes returned by functions. */
25 #define ERROR_SIGNAL 1
26 #define ERROR_TRIVIAL 2
27 #define ERROR_FILE_OPEN 3
28 #define ERROR_LOCKFILE 4
29 #define ERROR_CONFIG_PARSE 5
30 #define ERROR_MEMORY_ALLOCATION 6
31 #define ERROR_SETUID 7
32 #define ERROR_TERMIO 8
33 #define ERROR_NETWORK 9
34 #define ERROR_SSL 10
35 #define ERROR_PASSPHRASE 11
36 #define ERROR_ENCRYPT 12
37 #define ERROR_DECRYPT 13
38 #define ERROR_FORK 14
39 #define ERROR_UNDEFINED 15
40
41 /* SSL/TLS certificate status for the server. */
42 #define SSL_CERT_OK 0
43 #define SSL_CERT_NONEXISTENT 1
44 #define SSL_CERT_MISMATCH 2
45
46 /* Action to be applied, concerning the SSL/TLS certificate. */
47 #define SSL_CERT_ACTION_ACCEPT 0
48 #define SSL_CERT_ACTION_REJECT 1
49 #define SSL_CERT_ACTION_CONTINUE 0
50 #define SSL_CERT_ACTION_ABORT 1
51
52 /* Flags that control the program's execution options. */
53 #define OPTION_DETAILS_QUIET 0x0001
54 #define OPTION_DETAILS_NORMAL 0x0002
55 #define OPTION_DETAILS_VERBOSE 0x0004
56 #define OPTION_DETAILS_CLEAR 0xfff8
57 #define OPTION_ERRORS 0x0008
58 #define OPTION_EXPUNGE 0x0010
59 #define OPTION_HEADERS 0x0020
60 #define OPTION_NAMESPACE 0x0040
61 #define OPTION_SUBSCRIBE 0x0080
62 #define OPTION_PASSWORD_EDITOR 0x0100
63 #define OPTION_DAEMON_MODE 0x0200
64
65 /* Other flags. */
66 #define FLAG_DAEMON_MODE 0x01
67 #define FLAG_TTY 0x02
68 #define FLAG_TTY_MODIFIED 0x04
69 #define FLAG_BLANK_PASSWORD 0x08
70 #define FLAG_SIGHUP_RECEIVED 0x10
71
72 /* Capabilities of mail server. */
73 #define CAPABILITY_NONE 0x00
74 #define CAPABILITY_NAMESPACE 0x01
75 #define CAPABILITY_AUTH_CRAM_MD5 0x02
76 #define CAPABILITY_STARTTLS 0x04
77
78 /* Flags for logger. */
79 #define LOG_PREAMBLE 0
80 #define LOG_ACCOUNT 1
81 #define LOG_MAILBOX 2
82 #define LOG_FILTER 3
83 #define LOG_ACTION 4
84 #define LOG_DESTINATION_ACCOUNT 5
85 #define LOG_DESTINATION_MAILBOX 6
86 #define LOG_HEADER 7
87
88 /* Store IMAP command type may replace,add or remove flags. */
89 #define STORE_FLAG_REPLACE 1
90 #define STORE_FLAG_ADD 2
91 #define STORE_FLAG_REMOVE 3
92
93 /* Buffer size of server's response. */
94 #define RESPONSE_BUF 4096
95 #define RESULT_BUF 512
96
97 /* Response codes. */
98 #define RESPONSE_NULLBODY -2
99 #define RESPONSE_NONE -1
100 #define RESPONSE_OK 0
101 #define RESPONSE_NO 1
102 #define RESPONSE_BAD 2
103 #define RESPONSE_BYE 3
104 #define RESPONSE_PREAUTH 4
105 #define RESPONSE_READONLY 5
106 #define RESPONSE_TRYCREATE 6
107
108 /* Size of temporary buffer. */
109 #define BUFFER_SIZE 4096
110
111 /* Length of mailbox namespace prefix. */
112 #define NAMESPACE_PREFIX_LEN 64
113
114 /* Encryption and decryption buffers. */
115 #define ENCRYPTION_BUF 1024
116 #define DECRYPTION_BUF 4096
117
118 /* Buffer to save flags of the store IMAP command. */
119 #define STORE_FLAGS_BUF 64
120
121 /* Maximum passwords the password editor can handle. */
122 #define EDITOR_PASSWORDS_MAX 64
123
124 /* Lenght of charset for IMAP SEARCH requests. */
125 #define CHARSET_LEN 64
126
127
128 #define min(A, B) ((A) < (B) ? (A) : (B))
129 #define plural(A) ((A) == 1 ? "" : "s")
130
131
132 /* Secure memory information. */
133 typedef struct secmem {
134 void *buf; /* Allocated memory buffer. */
135 size_t size; /* Size of the buffer. */
136 struct secmem *prev, *next; /* Previous/next node of doubly linked
137 * list. */
138 } secmem_t;
139
140
141 /* Temporary buffer. */
142 typedef struct buffer {
143 char *data;
144 size_t size;
145 } buffer_t;
146
147
148 /* Namespace of IMAP mailboxes. */
149 typedef struct namesp {
150 char prefix[NAMESPACE_PREFIX_LEN];
151 char delim;
152 } namesp_t;
153
154
155 /* auth.c */
156 #ifdef CRAM_MD5
157 int imf_cram_md5(int *sock, char *user, char *pass);
158
159 #endif
160
161 /* buffer.c */
162 void init_buffer(buffer_t * buf);
163 void reset_buffer(buffer_t * buf);
164 void check_buffer(buffer_t * buf, size_t n);
165
166 /* file.c */
167 int read_config(char *cfg);
168 int parse_config(FILE * fd);
169 void reread_config(char *cfg);
170 void set_options(char *line, regmatch_t * match);
171
172 int read_passwords(void);
173 int parse_passwords(FILE * fd);
174 int store_passwords(account_t ** accts);
175
176 int create_homedir(void);
177 int exists_file(char *fname);
178 int exists_dir(char *fname);
179 int create_file(char *fname, mode_t mode);
180
181 #ifdef CHECK_PERMISSIONS
182 int check_file_perms(char *fname, mode_t mode);
183 int check_dir_perms(char *dname, mode_t mode);
184
185 #endif
186
187 #ifdef SSL_TLS
188 int imf_ssl_cert(SSL * ssl);
189 int imf_ssl_check_cert(X509 * pcert, unsigned char *pmd, unsigned int *pmdlen);
190 void imf_ssl_print_cert(X509 * cert, unsigned char *md, unsigned int *mdlen);
191 int imf_ssl_new_cert(X509 * cert);
192 int imf_ssl_cert_mismatch(void);
193
194 #endif
195
196 /* imapfilter.c */
197 void usage(void);
198 void version(void);
199
200 /* imap.c */
201 unsigned int send_command(int *sock, char *cmd);
202 void send_command_cont(int *sock, char *cmd);
203
204 #ifdef DEBUG
205 int imap_noop(int *sock);
206
207 #endif
208 int imap_capability(int *sock);
209 int imap_namespace(int *sock);
210 int imap_logout(int *sock);
211
212 #ifdef SSL_TLS
213 int imap_starttls(int *sock);
214
215 #endif
216 int imap_authenticate(int *sock, char *auth, int cont);
217 int imap_login(int *sock, char *user, char *pass);
218
219 /* int imap_list(int *sock, char *refer, char *mbox); */
220 int imap_subscribe(int *sock, char *mbox);
221
222 /* int imap_examine(int *sock, char *mbox); */
223 int imap_select(int *sock, char *mbox);
224 int imap_status(int *sock, char *mbox, char *items);
225 int imap_create(int *sock, char *mbox);
226 int imap_search(int *sock, char *charset, char *search);
227 int imap_fetch(int *sock, char *mesg, char *items);
228 int imap_store(int *sock, char *mesg, unsigned int mode, char *flags);
229 int imap_copy(int *sock, char *mesg, char *mbox);
230 int imap_append(int *sock, char *mbox, unsigned int size);
231 int imap_close(int *sock);
232 int imap_expunge(int *sock);
233
234 /* lock.c */
235 void lockfile_create(void);
236 void lockfile_check(void);
237 pid_t lockfile_pid(void);
238 int lockfile_remove(void);
239 void kill_imapfilter(void);
240
241 /* log.c */
242 void info(const char *info,...);
243 void verbose(const char *info,...);
244 void error(const char *errmsg,...);
245 void fatal(unsigned int errnum, const char *fatal,...);
246 void catch_signals(void);
247 void signal_handler(int sig);
248 int open_logfile(void);
249 int create_logfile(void);
250 int close_logfile(void);
251 void log_info(int flag, void *ptr);
252 char *get_time(void);
253
254 /* memory.c */
255 void *xmalloc(size_t size);
256 void *xrealloc(void *ptr, size_t size);
257 void xfree(void *ptr);
258 char *xstrdup(const char *s);
259
260 void *smalloc(size_t size);
261 void *srealloc(void *ptr, size_t size);
262 void sfree(void *ptr);
263 char *sstrdup(const char *s);
264 void secmem_append(secmem_t * node);
265 secmem_t *secmem_find(void *ptr);
266 void secmem_remove(secmem_t * node);
267 void secmem_clear(void);
268
269 void corefile_disable(void);
270
271 /* misc.c */
272 char *strcasestr(const char *haystack, const char *needle);
273 char *ultostr(unsigned long int num, int base);
274 char *xstrncpy(char *dest, const char *src, size_t size);
275
276 /* passwd.c */
277 void get_password(char *passwd, size_t pwlen);
278
279 #ifdef ENCRYPTED_PASSWORDS
280 int encrypt_passwords(FILE * fd, account_t ** accts);
281 int decrypt_passwords(unsigned char **buf, FILE * fd);
282 void password_editor(void);
283
284 #endif
285
286 /* request.c */
287 int test(int *sock);
288 int check_capabilities(int *sock);
289 int check_namespace(int *sock, namesp_t * nsp);
290
291 #ifdef SSL_TLS
292 int imf_starttls(int *sock);
293
294 #endif
295 int login(int *sock, char *user, char *pass);
296 int check_mailbox(int *sock, char *mbox);
297 int select_mailbox(int *sock, char *mbox, namesp_t * nsp);
298 int mailbox_status(int *sock, char *mbox, namesp_t * nsp);
299 int close_mailbox(int *sock);
300 int logout(int *sock);
301
302 int apply_filters(char *mbox, filter_t ** filters);
303 int match_filter(filter_t * filter, char **mesgs);
304
305 void empty_fifo(mask_t ** mfifo);
306 void queue_fifo(mask_t ** mfifo, mask_t * mask);
307 mask_t *dequeue_fifo(mask_t ** mfifo);
308
309 char *generate_filter_and(mask_t * mask, unsigned int masknum, unsigned int masklen);
310 char *generate_filter_or(mask_t * mask, unsigned int masknum, unsigned int masklen);
311
312 int apply_action(char *mbox, char *mesgs, unsigned int *type, account_t * raccount, char *destmbox, unsigned int *msgflags, char *args);
313 int action_delete(char *mesgs, char *args);
314 int action_copy(char *mbox, char *mesgs, char *destmbox, char *args);
315 int action_move(char *mbox, char *mesgs, char *destmbox, char *args);
316 int action_rcopy(char *mbox, char *mesgs, account_t * destacc, char *destmbox, char *args);
317 int action_rmove(char *mbox, char *mesgs, account_t * destacc, char *destmbox, char *args);
318 int action_flag(char *mesgs, unsigned int *type, unsigned int *msgflags, char *args);
319 int action_list(char *mesgs, char *args);
320
321 unsigned int count_messages(char *mesgs);
322 char *convert_messages(char *mesgs);
323 int substitute_date(char *str);
324 void current_date(char *destmbox);
325 void message_date(char *mesg, char *destmbox);
326 void default_variables(char *mbox, char *destmbox);
327
328 /* response.c */
329 void receive_response(int *sock, char *buf);
330 int server_response(int *sock, unsigned int tag);
331 void bye_response(char *buf);
332 int greeting_response(int *sock);
333 int logout_response(int *sock, unsigned int tag);
334 int capability_response(int *sock, unsigned int tag);
335 int authenticate_response(int *sock, unsigned int tag, unsigned char **cont);
336 int namespace_response(int *sock, unsigned int tag, namesp_t * nsp);
337 int status_response(int *sock, unsigned int tag, char *mbox);
338 int select_response(int *sock, unsigned int tag);
339 int search_response(int *sock, unsigned int tag, char **mesgs);
340 int fetch_response(int *sock, unsigned int tag, int reset, char *fetch);
341 int fetchsize_response(int *sock, unsigned int *size, unsigned int tag);
342 int append_response(int *sock, unsigned int tag);
343 int copy_response(int *sock, unsigned int tag);
344 int analyze_response(int *sock, char *buf);
345
346 /* socket.c */
347 int init_connection(int *sock, char *serv, unsigned short int port, unsigned int protocol);
348
349 #ifdef SSL_TLS
350 int imf_ssl_init(int *sock, unsigned int protocol);
351
352 #endif
353 int close_connection(int *sock);
354 int socket_read(int *sock, char *buf);
355 int socket_write(int *sock, char *data);
356
357 /* tty.c */
358 int tty_store(void);
359 int tty_disable_echo(void);
360 int tty_restore(void);
361
362 #endif /* IMAPFILTER_H */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26