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

Contents of /imapfilter/imapfilter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.27 - (show annotations)
Tue Jan 29 21:23:42 2002 UTC (22 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.26: +40 -14 lines
File MIME type: text/plain
Added secure memory allocation subsystem.

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
9 #ifndef DATA_H
10 #include "data.h"
11 #endif
12
13 /* Error codes returned by functions. */
14 #define ERROR_SIGNAL 1
15 #define ERROR_TRIVIAL 2
16 #define ERROR_FILE_OPEN 3
17 #define ERROR_CONFIG_PARSE 4
18 #define ERROR_MEMORY_ALLOCATION 5
19 #define ERROR_SETUID 6
20 #define ERROR_TERMIO 7
21 #define ERROR_NETWORK 8
22 #define ERROR_SSL 9
23 #define ERROR_PASSPHRASE 10
24 #define ERROR_ENCRYPT 11
25 #define ERROR_DECRYPT 12
26 #define ERROR_UNDEFINED 13
27
28 /* Flags that control the program's options. */
29 #define OPTION_DETAILS_QUIET 0x01
30 #define OPTION_DETAILS_NORMAL 0x02
31 #define OPTION_DETAILS_VERBOSE 0x04
32 #define OPTION_DETAILS_CLEAR 0xf8
33 #define OPTION_HEADERS 0x08
34 #define OPTION_NAMESPACE 0x10
35 #define OPTION_PASSWORD_EDITOR 0x20
36
37 /* Capabilities of mail server. */
38 #define CAPABILITY_NONE 0x00
39 #define CAPABILITY_NAMESPACE 0x01
40
41 /* Flags for logger. */
42 #define LOG_WRITE 0
43 #define LOG_SERVER 1
44 #define LOG_USERNAME 2
45 #define LOG_MAILBOX 3
46 #define LOG_FILTER 4
47 #define LOG_ACTION 5
48 #define LOG_DESTINATION_MAILBOX 6
49
50 /* Buffer size of the IMAP command. */
51 #define SMALL_CMD 64
52 #define MEDIUM_CMD 256
53 #define BIG_CMD 8192
54
55 /* Buffer size of server's response. */
56 #define RESPONSE_BUF (4096 + 1)
57 #define RESULT_BUF 512
58
59 /* Response codes. */
60 #define RESPONSE_BAD -1
61 #define RESPONSE_OK 0
62 #define RESPONSE_NO 1
63 #define RESPONSE_BYE 2
64 #define RESPONSE_PREAUTH 3
65 #define RESPONSE_READONLY 4
66 #define RESPONSE_TRYCREATE 5
67
68 /* Buffer size of message's headers. */
69 #define HEADERS_BUF 16384
70
71 /* Length of mailbox namespace prefix. */
72 #define NAMESPACE_PREFIX_LEN 64
73
74 /* Encryption and decryption buffers. */
75 #define ENCRYPTION_BUF 1024
76 #define DECRYPTION_BUF 4096
77
78 /* Maximum passwords the password editor can handle. */
79 #define EDITOR_PASSWORDS_MAX 64
80
81
82 #define min(A, B) ((A) < (B) ? (A) : (B))
83 #define plural(A) ((A) == 1 ? "" : "s")
84
85
86 /* Secure memory information. */
87 typedef struct secmem {
88 void *buf; /* Allocated memory buffer. */
89 size_t size; /* Size of the buffer. */
90 struct secmem *prev, *next; /* Previous/next node of doubly linked list. */
91 } secmem_t;
92
93
94 /* file.c */
95 int read_config(char *cfg);
96 int parse_config(FILE * fd);
97 void set_options(char *line, regmatch_t * match);
98
99 int read_passwords(void);
100 int parse_passwords(FILE * fd);
101 int store_passwords(account_t * accts[]);
102
103 int create_homedir(void);
104 int exists_file(char *fname);
105 int exists_dir(char *fname);
106 int create_file(char *fname, mode_t mode);
107 int create_dir(char *dname, mode_t mode);
108 #ifdef CHECK_PERMISSIONS
109 int check_file_perms(char *fname, mode_t mode);
110 int check_dir_perms(char *dname, mode_t mode);
111 #endif
112
113 /* imapfilter.c */
114 void usage(void);
115
116 /* imap.c */
117 unsigned int send_command(char *cmd);
118 #ifdef DEBUG
119 int imap_noop(void);
120 #endif
121 int imap_capability(void);
122 int imap_namespace(void);
123 int imap_logout(void);
124 int imap_login(char *user, char *pass);
125 /* int imap_examine(char *mbox); */
126 int imap_select(char *mbox);
127 int imap_status(char *mbox, char *items);
128 int imap_create(char *mbox);
129 int imap_search(char *search);
130 int imap_fetch(char *mesg, char *headers, int peek);
131 int imap_store(char *mesg, char *flags);
132 int imap_copy(char *mesg, char *mbox);
133 int imap_close(void);
134 /* int imap_expunge(void); */
135
136 /* log.c */
137 void info(const char *info,...);
138 void verbose(const char *info,...);
139 void error(const char *errmsg,...);
140 void fatal(unsigned int errnum, const char *fatal,...);
141 void catch_signals(void);
142 void signal_handler(int sig);
143 int open_logfile(void);
144 int create_logfile(void);
145 int close_logfile(void);
146 void log_info(int flag, void *ptr);
147 char *get_time(void);
148
149 /* memory.c */
150 void *xmalloc(size_t size);
151 void *xrealloc(void *ptr, size_t size);
152 void xfree(void *ptr);
153 char *xstrdup(const char *s);
154
155 void *smalloc(size_t size);
156 void *srealloc(void *ptr, size_t size);
157 void sfree(void *ptr);
158 char *sstrdup(const char *s);
159 void secmem_append(secmem_t *node);
160 secmem_t *secmem_find(void *ptr);
161 void secmem_remove(secmem_t *node);
162 void secmem_clear(void);
163
164 void corefile_disable(void);
165 void corefile_restore(void);
166
167 /* misc.c */
168 char *strcasestr(const char *haystack, const char *needle);
169 char *ultostr(unsigned long int num, int base);
170 char *xstrncpy(char *dest, const char *src, size_t size);
171
172 /* passwd.c */
173 void get_password(char *passwd, size_t pwlen);
174 #ifdef ENCRYPTED_PASSWORDS
175 int encrypt_passwords(FILE *fd, account_t *accts[]);
176 int decrypt_passwords(unsigned char **buf, FILE *fd);
177 void password_editor(void);
178 #endif
179
180 /* request.c */
181 int test(void);
182 int check_capabilities(void);
183 int check_namespace(void);
184 int login(char *user, char *pass);
185 int select_mailbox(char *mbox);
186 int mailbox_status(char *mbox);
187 int close_mailbox(void);
188 int logout(void);
189
190 int apply_filters(filter_t ** filters);
191 int match_filter(filter_t * filter, char **mesgs);
192
193 void empty_fifo(mask_t ** mfifo);
194 void queue_fifo(mask_t ** mfifo, mask_t * mask);
195 mask_t *dequeue_fifo(mask_t ** mfifo);
196
197 char *generate_filter_and(mask_t * mask, unsigned int masknum, unsigned int masklen);
198 char *generate_filter_or(mask_t * mask, unsigned int masknum, unsigned int masklen);
199
200 int apply_action(char *mesgs, unsigned int *type, char *destmbox, char *args);
201 int action_delete(char *mesgs, char *args);
202 int action_copy(char *mesgs, char *destmbox, char *args);
203 int action_move(char *mesgs, char *destmbox, char *args);
204 int action_list(char *mesgs, char *args);
205
206 unsigned int convert_messages(char *mesgs);
207
208 /* response.c */
209 void receive_response(char *buf);
210 int server_response(unsigned int tag);
211 int greeting_response(void);
212 int capability_response(unsigned int tag);
213 int namespace_response(unsigned int tag, char *prefix, char delim);
214 int status_response(unsigned int tag, char *mbox);
215 int select_response(unsigned int tag);
216 int search_response(unsigned int tag, char **mesgs);
217 int fetch_response(unsigned int tag);
218 int copy_response(unsigned int tag);
219 int analyze_response(char *buf);
220
221 /* socket.c */
222 #ifndef SSL_TLS
223 int init_connection(char *serv, unsigned short int port);
224 #else
225 int init_connection(char *serv, unsigned short int port, unsigned int protocol);
226 #endif
227 int ssl_init(unsigned int protocol);
228 int close_connection(void);
229 int socket_read(char *buf);
230 int socket_write(char *data);
231
232 /* tty.c */
233 int tty_store(void);
234 int tty_disable_echo(void);
235 int tty_restore(void);
236
237 #endif /* IMAPFILTER_H */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26