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

Annotation of /imapfilter/data.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (hide annotations)
Tue Jan 29 21:23:41 2002 UTC (22 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.15: +1 -5 lines
File MIME type: text/plain
Added secure memory allocation subsystem.

1 lefcha 1.1 #ifndef DATA_H
2     #define DATA_H
3    
4 lefcha 1.8 #include <sys/types.h>
5 lefcha 1.1 #include <regex.h>
6    
7     /* String lengths of account settings. */
8 lefcha 1.7 #define SERVER_LEN (635 + 1) /* Section 2.5 RFC 1123. */
9 lefcha 1.12 #define USERNAME_LEN 128
10     #define PASSWORD_LEN 128
11 lefcha 1.1
12 lefcha 1.15 /* String lengths of master password and encrypted passwords. */
13     #define PASSPHRASE_LEN 256
14     #define ENCRYPTED_PASSWORD_LEN 128
15    
16     /* Attributes of a password. */
17     #define PASSWORD_NONE 0
18     #define PASSWORD_PLAIN 1
19     #define PASSWORD_ENCRYPTED 2
20    
21 lefcha 1.9 /* Secure Socket Layer protocols. */
22     #define SSL_DISABLED 0
23     #define SSL_SSL_V2 1
24     #define SSL_SSL_V3 2
25     #define SSL_TLS_V1 3
26    
27 lefcha 1.1 /* String length of keys (aliases). */
28 lefcha 1.7 #define KEY_LEN 32
29 lefcha 1.1
30     /* String length of action's arguments. */
31 lefcha 1.7 #define ARGS_LEN 256
32 lefcha 1.1
33     /* String length of mailbox's name. */
34 lefcha 1.7 #define MBOX_NAME_LEN 128
35 lefcha 1.1
36     /* String length of mask's body. */
37 lefcha 1.7 #define MASK_BODY_LEN 256
38 lefcha 1.1
39     /* Maximum filters assigned to a mailbox. */
40 lefcha 1.12 #define MBOX_FILTERS_MAX 64
41 lefcha 1.1
42     /* Maximum mailboxes contained in a mailbox-group. */
43 lefcha 1.7 #define MBOXGRP_MBOXES_MAX 64
44 lefcha 1.1
45 lefcha 1.5 /*
46 lefcha 1.1 * Mode for masks that comprise a filter. So if a filter is of AND type then
47     * as default masks are ANDed.
48     */
49 lefcha 1.7 #define FILTER_MODE_OR 1
50     #define FILTER_MODE_AND 2
51 lefcha 1.1
52     /* Action to do in case of filter matching. */
53 lefcha 1.7 #define FILTER_ACTION_DELETE 1
54     #define FILTER_ACTION_COPY 2
55     #define FILTER_ACTION_MOVE 3
56     #define FILTER_ACTION_LIST 4
57 lefcha 1.1
58 lefcha 1.9 /* Type of mask. This overrides the default filter mode (AND/OR). */
59 lefcha 1.7 #define MASK_TYPE_OR 1
60     #define MASK_TYPE_AND 2
61 lefcha 1.1
62    
63     /*
64     * Find last node of linked list and append at the end of the list the
65     * supplied node.
66     */
67     #define APPEND_LINKED_LIST(f, n, p, a) \
68     a = &f; \
69     p = f; \
70     while (p) { \
71     a = &(p->next); \
72     p = p->next; \
73     } \
74     *a = n;
75    
76     /*
77 lefcha 1.5 * Find, based on the key of the supplied node, the apropriate position for it
78 lefcha 1.9 * in the tree, and then insert it there.
79 lefcha 1.1 */
80     #define INSERT_TREE(r, n, p, i, c) \
81     i = &r; \
82     p = r; \
83     while (p) { \
84     c = strncmp(n->key, p->key, KEY_LEN); \
85     if (c < 0) { \
86     i = &(p->left); \
87     p = p->left; \
88     } else if (c > 0) { \
89     i = &(p->right); \
90     p = p->right; \
91     } else \
92     return; \
93     } \
94     *i = n;
95    
96     /*
97     * Find, based on the supplied key, the position of a node, and return a
98     * pointer directing to that node.
99     */
100     #define FIND_TREE(r, k, p, c) \
101     p = r; \
102     while (p) { \
103     c = strncmp(k, p->key, KEY_LEN); \
104     if (c < 0) \
105     p = p->left; \
106     else if (c > 0) \
107     p = p->right; \
108     else \
109     return p; \
110     } \
111     return NULL;
112    
113 lefcha 1.7 #define create_node(A) xmalloc(A)
114 lefcha 1.5
115 lefcha 1.1
116     /* Account. */
117 lefcha 1.14 typedef struct account {
118 lefcha 1.5 char server[SERVER_LEN]; /* Hostname of mail server. */
119     unsigned short int port; /* Port to connect. */
120    
121     char username[USERNAME_LEN];/* Username. */
122 lefcha 1.16 char *password; /* Password. */
123 lefcha 1.15 int passwdattr; /* Password attributes. */
124 lefcha 1.10 #ifdef SSL_TLS
125 lefcha 1.9 unsigned int ssl; /* Secure Socket Layer support. */
126     #endif
127 lefcha 1.14 struct mbox *mboxes; /* Mailboxes. */
128     struct account *next; /* Next node of linked list. */
129 lefcha 1.1 } account_t;
130    
131     /* Mailbox. */
132 lefcha 1.14 typedef struct mbox {
133 lefcha 1.5 char name[MBOX_NAME_LEN]; /* Name of mailbox. */
134 lefcha 1.14 struct filter *filters[MBOX_FILTERS_MAX]; /* Filters to be applied. */
135     struct mbox *next; /* Next node of linked list. */
136 lefcha 1.1 } mbox_t;
137    
138     /* Group of mailboxes. */
139 lefcha 1.14 typedef struct mboxgrp {
140 lefcha 1.5 char key[KEY_LEN]; /* Alias of mailbox group. */
141 lefcha 1.14 struct mbox *mboxes[MBOXGRP_MBOXES_MAX]; /* Mailboxes of group. */
142     struct mboxgrp *left, *right; /* Left/right nodes of tree. */
143 lefcha 1.1 } mboxgrp_t;
144    
145     /* Filter. */
146 lefcha 1.14 typedef struct filter {
147 lefcha 1.1 char key[KEY_LEN]; /* Alias of filter. */
148     unsigned int mode; /* AND/OR mode. */
149    
150 lefcha 1.5 struct { /* What to do on filter match. */
151     unsigned int type; /* Action. */
152     char destmbox[MBOX_NAME_LEN]; /* Destination mailbox. */
153     char args[ARGS_LEN]; /* Action's arguments. */
154 lefcha 1.1 } action;
155    
156 lefcha 1.14 struct mask *masks; /* Masks comprising the filter. */
157 lefcha 1.5 unsigned int masknum; /* Total number of masks. */
158     unsigned int masklen; /* Total length of body of masks. */
159    
160 lefcha 1.14 struct filter *left, *right;/* Left/right node of tree. */
161 lefcha 1.1 } filter_t;
162    
163     /* Mask. */
164 lefcha 1.14 typedef struct mask {
165 lefcha 1.1 char body[MASK_BODY_LEN]; /* Body of mask. */
166     unsigned int type; /* AND/OR type. */
167 lefcha 1.14 struct mask *next; /* Next node of linked list. */
168 lefcha 1.1 } mask_t;
169    
170    
171     /* data.c */
172     void init_account(account_t * node);
173     void append_account(account_t * node);
174     int set_account(char *line, regmatch_t * match);
175 lefcha 1.15 #ifdef ENCRYPTED_PASSWORDS
176     char *find_password(char *user, char *serv);
177     #endif
178 lefcha 1.1
179     void init_mboxgrp(mboxgrp_t * node);
180     void ins_mboxgrp(mboxgrp_t * node);
181     int set_mboxgrp(char *line, regmatch_t * match);
182     void process_mboxgrp(mboxgrp_t * node, char *mboxs);
183     mboxgrp_t *find_mboxgrp(char *key);
184    
185     void init_mbox(mbox_t * node);
186     void append_mbox(mbox_t * node);
187     mbox_t *set_mbox(char *name);
188    
189     void init_filter(filter_t * node);
190     void ins_filter(filter_t * node);
191     int set_filter(char *line, regmatch_t * match);
192     filter_t *find_filter(char *key);
193 lefcha 1.4 int set_action(char *line, regmatch_t * match);
194 lefcha 1.1
195     void init_mask(mask_t * node);
196     void append_mask(mask_t * node);
197     int set_mask(char *line, regmatch_t * match);
198 lefcha 1.10 void convert_date(mask_t * node);
199 lefcha 1.1
200     int set_job(char *line, regmatch_t * match);
201 lefcha 1.4 void link_mbox_filter(filter_t * cf, mboxgrp_t * cg);
202 lefcha 1.1
203 lefcha 1.3 void destroy_data(void);
204 lefcha 1.1 void destroy_mboxgrp(mboxgrp_t * node);
205    
206 lefcha 1.4 void string_upper(char *str, size_t size);
207 lefcha 1.6 int string_decode(char *str);
208 lefcha 1.14
209     char *apply_namespace(char *mbox, char *prefix, char delim);
210 lefcha 1.3
211 lefcha 1.5 #endif /* DATA_H */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26