Snow storm, good took the opportunity to rewrite one time to many
the registrar/record code, still fuzzy. Implemented the folder for Mbox. and various cleaning.
Showing
23 changed files
with
473 additions
and
304 deletions
... | @@ -55,7 +55,8 @@ folder_create (folder_t *pfolder, const char *name) | ... | @@ -55,7 +55,8 @@ folder_create (folder_t *pfolder, const char *name) |
55 | { | 55 | { |
56 | int status = EINVAL; | 56 | int status = EINVAL; |
57 | record_t record = NULL; | 57 | record_t record = NULL; |
58 | folder_entry_t entry = NULL; | 58 | int (*f_init) __P ((folder_t)) = NULL; |
59 | int (*u_init) __P ((url_t)) = NULL; | ||
59 | iterator_t iterator; | 60 | iterator_t iterator; |
60 | list_t list; | 61 | list_t list; |
61 | int found = 0; | 62 | int found = 0; |
... | @@ -74,8 +75,9 @@ folder_create (folder_t *pfolder, const char *name) | ... | @@ -74,8 +75,9 @@ folder_create (folder_t *pfolder, const char *name) |
74 | iterator_current (iterator, (void **)&record); | 75 | iterator_current (iterator, (void **)&record); |
75 | if (record_is_scheme (record, name)) | 76 | if (record_is_scheme (record, name)) |
76 | { | 77 | { |
77 | record_get_folder (record, &entry); | 78 | record_get_folder (record, &f_init); |
78 | if (entry) | 79 | record_get_url (record, &u_init); |
80 | if (f_init && u_init) | ||
79 | { | 81 | { |
80 | found = 1; | 82 | found = 1; |
81 | break; | 83 | break; |
... | @@ -92,7 +94,7 @@ folder_create (folder_t *pfolder, const char *name) | ... | @@ -92,7 +94,7 @@ folder_create (folder_t *pfolder, const char *name) |
92 | /* Parse the url, it may be a bad one and we should bailout if this | 94 | /* Parse the url, it may be a bad one and we should bailout if this |
93 | failed. */ | 95 | failed. */ |
94 | if ((status = url_create (&url, name) != 0) | 96 | if ((status = url_create (&url, name) != 0) |
95 | || (status = entry->_url_init (url)) != 0) | 97 | || (status = u_init (url)) != 0) |
96 | return status; | 98 | return status; |
97 | 99 | ||
98 | monitor_wrlock (&folder_lock); | 100 | monitor_wrlock (&folder_lock); |
... | @@ -122,7 +124,7 @@ folder_create (folder_t *pfolder, const char *name) | ... | @@ -122,7 +124,7 @@ folder_create (folder_t *pfolder, const char *name) |
122 | if (status == 0) | 124 | if (status == 0) |
123 | { | 125 | { |
124 | /* Create the concrete folder type. */ | 126 | /* Create the concrete folder type. */ |
125 | status = entry->_folder_init (folder); | 127 | status = f_init (folder); |
126 | if (status == 0) | 128 | if (status == 0) |
127 | { | 129 | { |
128 | *pfolder = folder; | 130 | *pfolder = folder; |
... | @@ -350,11 +352,19 @@ folder_list_destroy (struct folder_list ***pflist, size_t count) | ... | @@ -350,11 +352,19 @@ folder_list_destroy (struct folder_list ***pflist, size_t count) |
350 | } | 352 | } |
351 | 353 | ||
352 | int | 354 | int |
353 | folder_delete_mailbox (folder_t folder, const char *name) | 355 | folder_delete (folder_t folder, const char *name) |
354 | { | 356 | { |
355 | if (folder == NULL || folder->_delete_mailbox == NULL) | 357 | if (folder == NULL || folder->_delete == NULL) |
356 | return ENOSYS; | 358 | return ENOSYS; |
357 | return folder->_delete_mailbox (folder, name); | 359 | return folder->_delete (folder, name); |
360 | } | ||
361 | |||
362 | int | ||
363 | folder_rename (folder_t folder, const char *oldname, const char *newname) | ||
364 | { | ||
365 | if (folder == NULL || folder->_rename == NULL) | ||
366 | return ENOSYS; | ||
367 | return folder->_rename (folder, oldname, newname); | ||
358 | } | 368 | } |
359 | 369 | ||
360 | int | 370 | int | ... | ... |
... | @@ -24,30 +24,73 @@ | ... | @@ -24,30 +24,73 @@ |
24 | #include <sys/stat.h> | 24 | #include <sys/stat.h> |
25 | #include <unistd.h> | 25 | #include <unistd.h> |
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <glob.h> | ||
28 | #include <stdio.h> | ||
27 | 29 | ||
28 | #include <folder0.h> | 30 | #include <folder0.h> |
29 | #include <registrar0.h> | 31 | #include <registrar0.h> |
30 | 32 | ||
33 | /* We export url parsing and the initialisation of | ||
34 | the mailbox, via the register entry/record. */ | ||
31 | 35 | ||
32 | static int fmbox_init (folder_t); | 36 | static struct _record _mbox_record = |
37 | { | ||
38 | MU_MBOX_SCHEME, | ||
39 | _url_mbox_init, /* Mailbox init. */ | ||
40 | _mailbox_mbox_init, /* Mailbox init. */ | ||
41 | NULL, /* Mailer init. */ | ||
42 | _folder_mbox_init, /* Folder init. */ | ||
43 | NULL, /* No need for an back pointer. */ | ||
44 | NULL, /* _is_scheme method. */ | ||
45 | NULL, /* _get_url method. */ | ||
46 | NULL, /* _get_mailbox method. */ | ||
47 | NULL, /* _get_mailer method. */ | ||
48 | NULL /* _get_folder method. */ | ||
49 | }; | ||
50 | record_t mbox_record = &_mbox_record; | ||
33 | 51 | ||
34 | struct folder_entry _fmbox_entry = | 52 | static struct _record _file_record = |
35 | { | 53 | { |
36 | url_path_init, fmbox_init | 54 | MU_FILE_SCHEME, |
55 | _url_file_init, /* Mailbox init. */ | ||
56 | _mailbox_file_init, /* Mailbox init. */ | ||
57 | NULL, /* Mailer init. */ | ||
58 | _folder_mbox_init, /* Folder init. */ | ||
59 | NULL, /* No need for an owner. */ | ||
60 | NULL, /* _is_scheme method. */ | ||
61 | NULL, /* _get_url method. */ | ||
62 | NULL, /* _get_mailbox method. */ | ||
63 | NULL, /* _get_mailer method. */ | ||
64 | NULL /* _get_folder method. */ | ||
37 | }; | 65 | }; |
66 | record_t file_record = &_file_record; | ||
38 | 67 | ||
39 | /* We export two functions: url parsing and the initialisation of | 68 | static struct _record _path_record = |
40 | the mailbox, via the register entry/record. */ | 69 | { |
41 | folder_entry_t fmbox_entry = &_fmbox_entry; | 70 | MU_PATH_SCHEME, |
71 | _url_path_init, /* Mailbox init. */ | ||
72 | _mailbox_file_init, /* Mailbox init. */ | ||
73 | NULL, /* Mailer init. */ | ||
74 | _folder_mbox_init, /* Folder init. */ | ||
75 | NULL, /* No need for an owner. */ | ||
76 | NULL, /* is_scheme method. */ | ||
77 | NULL, /* get_url method. */ | ||
78 | NULL, /* get_mailbox method. */ | ||
79 | NULL, /* get_mailer method. */ | ||
80 | NULL /* get_folder method. */ | ||
81 | }; | ||
82 | record_t path_record = &_path_record; | ||
42 | 83 | ||
43 | static void fmbox_destroy (folder_t); | 84 | /* lsub/subscribe/unsubscribe are not needed. */ |
44 | static int fmbox_open (folder_t, int); | 85 | static void folder_mbox_destroy (folder_t); |
45 | static int fmbox_close (folder_t); | 86 | static int folder_mbox_open (folder_t, int); |
46 | static int fmbox_delete (folder_t, const char *); | 87 | static int folder_mbox_close (folder_t); |
47 | static int fmbox_list (folder_t, const char *, | 88 | static int folder_mbox_delete (folder_t, const char *); |
89 | static int folder_mbox_rename (folder_t , const char *, const char *); | ||
90 | static int folder_mbox_list (folder_t, const char *, | ||
48 | struct folder_list ***, size_t *); | 91 | struct folder_list ***, size_t *); |
49 | 92 | ||
50 | static int fmbox_list0 (const char *, struct folder_list ***, size_t *, int); | 93 | static char *get_pathname (const char *, const char *); |
51 | 94 | ||
52 | struct _fmbox | 95 | struct _fmbox |
53 | { | 96 | { |
... | @@ -56,11 +99,10 @@ struct _fmbox | ... | @@ -56,11 +99,10 @@ struct _fmbox |
56 | typedef struct _fmbox *fmbox_t; | 99 | typedef struct _fmbox *fmbox_t; |
57 | 100 | ||
58 | 101 | ||
59 | static int | 102 | int |
60 | fmbox_init (folder_t folder) | 103 | _folder_mbox_init (folder_t folder) |
61 | { | 104 | { |
62 | fmbox_t dfolder; | 105 | fmbox_t dfolder; |
63 | //char *dirname; | ||
64 | size_t name_len = 0; | 106 | size_t name_len = 0; |
65 | 107 | ||
66 | dfolder = folder->data = calloc (1, sizeof (dfolder)); | 108 | dfolder = folder->data = calloc (1, sizeof (dfolder)); |
... | @@ -77,20 +119,20 @@ fmbox_init (folder_t folder) | ... | @@ -77,20 +119,20 @@ fmbox_init (folder_t folder) |
77 | } | 119 | } |
78 | url_get_path (folder->url, dfolder->dirname, name_len + 1, NULL); | 120 | url_get_path (folder->url, dfolder->dirname, name_len + 1, NULL); |
79 | 121 | ||
80 | folder->_init = fmbox_init; | 122 | folder->_destroy = folder_mbox_destroy; |
81 | folder->_destroy = fmbox_destroy; | ||
82 | 123 | ||
83 | folder->_open = fmbox_open; | 124 | folder->_open = folder_mbox_open; |
84 | folder->_close = fmbox_close; | 125 | folder->_close = folder_mbox_close; |
85 | 126 | ||
86 | folder->_list = fmbox_list; | 127 | folder->_list = folder_mbox_list; |
87 | folder->_delete_mailbox = fmbox_delete; | 128 | folder->_delete = folder_mbox_delete; |
129 | folder->_rename = folder_mbox_rename; | ||
88 | 130 | ||
89 | return 0; | 131 | return 0; |
90 | } | 132 | } |
91 | 133 | ||
92 | void | 134 | void |
93 | fmbox_destroy (folder_t folder) | 135 | folder_mbox_destroy (folder_t folder) |
94 | { | 136 | { |
95 | if (folder->data) | 137 | if (folder->data) |
96 | { | 138 | { |
... | @@ -102,104 +144,160 @@ fmbox_destroy (folder_t folder) | ... | @@ -102,104 +144,160 @@ fmbox_destroy (folder_t folder) |
102 | } | 144 | } |
103 | } | 145 | } |
104 | 146 | ||
147 | /* Noop. */ | ||
105 | static int | 148 | static int |
106 | fmbox_open (folder_t folder, int flags) | 149 | folder_mbox_open (folder_t folder, int flags) |
107 | { | 150 | { |
108 | (void)(folder); | 151 | (void)(folder); |
152 | |||
109 | (void)(flags); | 153 | (void)(flags); |
110 | return 0; | 154 | return 0; |
111 | } | 155 | } |
112 | 156 | ||
157 | /* Noop. */ | ||
113 | static int | 158 | static int |
114 | fmbox_close (folder_t folder) | 159 | folder_mbox_close (folder_t folder) |
115 | { | 160 | { |
116 | (void)(folder); | 161 | (void)(folder); |
117 | return 0; | 162 | return 0; |
118 | } | 163 | } |
119 | 164 | ||
120 | static int | 165 | static int |
121 | fmbox_delete (folder_t folder, const char *dirname) | 166 | folder_mbox_delete (folder_t folder, const char *filename) |
122 | { | 167 | { |
123 | (void)(folder); | 168 | fmbox_t fmbox = folder->data; |
124 | (void)dirname; | 169 | if (filename) |
125 | return 0; | 170 | { |
171 | int status = 0; | ||
172 | char *pathname = get_pathname (fmbox->dirname, filename); | ||
173 | if (pathname) | ||
174 | { | ||
175 | if (remove (pathname) != 0) | ||
176 | status = errno; | ||
177 | free (pathname); | ||
178 | } | ||
179 | else | ||
180 | status = ENOMEM; | ||
181 | return status; | ||
182 | } | ||
183 | return EINVAL; | ||
126 | } | 184 | } |
127 | 185 | ||
128 | static int | 186 | static int |
129 | fmbox_list (folder_t folder, const char *pattern, | 187 | folder_mbox_rename (folder_t folder, const char *oldpath, const char *newpath) |
130 | struct folder_list ***pflist, size_t *pnum) | ||
131 | { | 188 | { |
132 | fmbox_t fmbox = folder->data; | 189 | fmbox_t fmbox = folder->data; |
133 | struct folder_list **list = NULL; | 190 | if (oldpath && newpath) |
134 | char *dirname = NULL; | ||
135 | int status; | ||
136 | size_t num = 0; | ||
137 | |||
138 | if (pattern == NULL) | ||
139 | { | 191 | { |
140 | dirname = strdup (fmbox->dirname); | 192 | int status = 0; |
141 | } | 193 | char *pathold = get_pathname (fmbox->dirname, oldpath); |
142 | else if (pattern[0] != '/') | 194 | if (pathold) |
143 | { | 195 | { |
144 | size_t len = strlen (pattern); | 196 | char *pathnew = get_pathname (fmbox->dirname, newpath); |
145 | dirname = calloc (strlen (fmbox->dirname) + len + 2, sizeof (char)); | 197 | if (pathnew) |
146 | if (dirname) | 198 | { |
147 | sprintf (dirname, "%s/%s", fmbox->dirname, pattern); | 199 | if (rename (pathold, pathnew) != 0) |
200 | status = errno; | ||
201 | free (pathnew); | ||
148 | } | 202 | } |
149 | else | 203 | else |
150 | dirname = strdup (pattern); | 204 | status = ENOMEM; |
151 | 205 | free (pathold); | |
152 | if (dirname == NULL) | ||
153 | return errno; | ||
154 | |||
155 | status = fmbox_list0 (dirname, &list, &num, (strchr (dirname, '*') != NULL)); | ||
156 | if (status == 0) | ||
157 | { | ||
158 | if (pflist) | ||
159 | *pflist = list; | ||
160 | if (pnum) | ||
161 | *pnum = num; | ||
162 | } | 206 | } |
207 | else | ||
208 | status = ENOMEM; | ||
163 | return status; | 209 | return status; |
210 | } | ||
211 | return EINVAL; | ||
164 | } | 212 | } |
165 | 213 | ||
214 | /* The listing is not recursif and we use glob() some expansion for us. | ||
215 | Unfortunately glov() does not expand the '~'. We also return | ||
216 | The full pathname so it can be use to create other folders. */ | ||
166 | static int | 217 | static int |
167 | fmbox_list0 (const char *dirname, struct folder_list ***pflist, | 218 | folder_mbox_list (folder_t folder, const char *pattern, |
168 | size_t *pnum, int recurse) | 219 | struct folder_list ***pflist, size_t *pnum) |
169 | { | 220 | { |
170 | DIR *dp; | 221 | fmbox_t fmbox = folder->data; |
171 | struct dirent *rp; | 222 | char *pathname = NULL; |
172 | struct stat stbuf; | 223 | int status; |
173 | struct folder_list **flist = *pflist; | 224 | size_t num = 0; |
174 | char buf[512]; | 225 | glob_t gl; |
175 | dp = opendir (dirname); | 226 | |
176 | if (dp == NULL) | 227 | pathname = get_pathname (fmbox->dirname, pattern); |
228 | if (pathname) | ||
177 | { | 229 | { |
178 | return errno; | 230 | memset(&gl, 0, sizeof(gl)); |
231 | status = glob (pathname, 0, NULL, &gl); | ||
232 | free (pathname); | ||
233 | num = gl.gl_pathc; | ||
179 | } | 234 | } |
180 | while ((rp = readdir (dp)) != NULL) | 235 | else |
236 | status = ENOMEM; | ||
237 | |||
238 | /* Build the folder list from glob. */ | ||
239 | if (status == 0) | ||
240 | { | ||
241 | if (pflist) | ||
242 | { | ||
243 | struct folder_list **flist; | ||
244 | flist = calloc (num, sizeof (*flist)); | ||
245 | if (flist) | ||
181 | { | 246 | { |
182 | if (rp->d_name[0] == '.') | 247 | size_t i; |
183 | continue; | 248 | struct stat stbuf; |
184 | flist = realloc (flist, (*pnum + 1) * sizeof (*flist)); | 249 | for (i = 0; i < num; i++) |
185 | flist[*pnum] = calloc (1, sizeof (**flist)); | 250 | { |
186 | sprintf (buf, "%s/%s", dirname, rp->d_name); | 251 | flist[i] = calloc (1, sizeof (**flist)); |
187 | if (stat (buf, &stbuf) == 0) | 252 | if (flist[i] == NULL |
253 | || (flist[i]->name = strdup (gl.gl_pathv[i])) == NULL) | ||
188 | { | 254 | { |
189 | int isdir = S_ISDIR(stbuf.st_mode); | 255 | num = i; |
190 | if (isdir) | 256 | break; |
191 | flist[*pnum]->attribute |= MU_FOLDER_ATTRIBUTE_NOSELECT; | 257 | } |
192 | flist[*pnum]->name = strdup (buf); | 258 | if (stat (gl.gl_pathv[i], &stbuf) == 0) |
193 | (*pnum)++; | ||
194 | if (isdir && recurse) | ||
195 | { | 259 | { |
196 | fmbox_list0 (buf, &flist, pnum, recurse); | 260 | if (S_ISDIR(stbuf.st_mode)) |
261 | flist[i]->type = MU_FOLDER_ATTRIBUTE_DIRECTORY; | ||
262 | if (S_ISREG(stbuf.st_mode)) | ||
263 | flist[i]->type = MU_FOLDER_ATTRIBUTE_FILE; | ||
197 | } | 264 | } |
265 | flist[i]->separator = '/'; | ||
198 | } | 266 | } |
199 | else | ||
200 | (*pnum)++; | ||
201 | } | 267 | } |
202 | closedir (dp); | 268 | else |
269 | status = ENOMEM; | ||
203 | *pflist = flist; | 270 | *pflist = flist; |
204 | return 0; | 271 | } |
272 | globfree (&gl); | ||
273 | } | ||
274 | else | ||
275 | { | ||
276 | status = (status == GLOB_NOSPACE) ? ENOMEM : | ||
277 | ((status == GLOB_NOMATCH) ? ENOENT : EINVAL); | ||
278 | } | ||
279 | if (pnum) | ||
280 | *pnum = num; | ||
281 | return status; | ||
282 | } | ||
283 | |||
284 | static char * | ||
285 | get_pathname (const char *dirname, const char *basename) | ||
286 | { | ||
287 | char *pathname = NULL; | ||
288 | /* null basename gives dirname. */ | ||
289 | if (basename == NULL) | ||
290 | pathname = (dirname) ? strdup (dirname) : strdup ("."); | ||
291 | /* Absolute. */ | ||
292 | else if (basename[0] == '/') | ||
293 | pathname = strdup (basename); | ||
294 | /* Relative. */ | ||
295 | else | ||
296 | { | ||
297 | size_t len = strlen (basename); | ||
298 | pathname = calloc (strlen (dirname) + len + 2, sizeof (char)); | ||
299 | if (pathname) | ||
300 | sprintf (pathname, "%s/%s", dirname, basename); | ||
301 | } | ||
302 | return pathname; | ||
205 | } | 303 | } | ... | ... |
mailbox/folder_pop.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | |||
22 | #include <errno.h> | ||
23 | |||
24 | #include <folder0.h> | ||
25 | #include <registrar0.h> | ||
26 | |||
27 | /* We export url parsing and the initialisation of | ||
28 | the mailbox, via the register entry/record. */ | ||
29 | |||
30 | static struct _record _pop_record = | ||
31 | { | ||
32 | MU_POP_SCHEME, | ||
33 | _url_pop_init, /* Mailbox init. */ | ||
34 | _mailbox_pop_init, /* Mailbox init. */ | ||
35 | NULL, /* Mailer init. */ | ||
36 | _folder_pop_init, /* Folder init. */ | ||
37 | NULL, /* No need for an back pointer. */ | ||
38 | NULL, /* _is_scheme method. */ | ||
39 | NULL, /* _get_url method. */ | ||
40 | NULL, /* _get_mailbox method. */ | ||
41 | NULL, /* _get_mailer method. */ | ||
42 | NULL /* _get_folder method. */ | ||
43 | }; | ||
44 | record_t pop_record = &_pop_record; | ||
45 | |||
46 | int | ||
47 | _folder_pop_init (folder_t folder) | ||
48 | { | ||
49 | (void)folder; | ||
50 | return 0; | ||
51 | } |
... | @@ -59,14 +59,18 @@ struct _folder | ... | @@ -59,14 +59,18 @@ struct _folder |
59 | 59 | ||
60 | /* Public methods */ | 60 | /* Public methods */ |
61 | 61 | ||
62 | int (*_init) __P ((folder_t)); | ||
63 | void (*_destroy) __P ((folder_t)); | 62 | void (*_destroy) __P ((folder_t)); |
64 | 63 | ||
65 | int (*_open) __P ((folder_t, int flag)); | 64 | int (*_open) __P ((folder_t, int flag)); |
66 | int (*_close) __P ((folder_t)); | 65 | int (*_close) __P ((folder_t)); |
67 | int (*_list) __P ((folder_t, const char *, | 66 | int (*_list) __P ((folder_t, const char *, |
68 | struct folder_list ***, size_t *)); | 67 | struct folder_list ***, size_t *)); |
69 | int (*_delete_mailbox) __P ((folder_t, const char *)); | 68 | int (*_lsub) __P ((folder_t, const char *, |
69 | struct folder_list ***, size_t *)); | ||
70 | int (*_delete) __P ((folder_t, const char *)); | ||
71 | int (*_rename) __P ((folder_t, const char *, const char *)); | ||
72 | int (*_subscribe) __P ((folder_t, const char *)); | ||
73 | int (*_unsubscribe) __P ((folder_t, const char *)); | ||
70 | }; | 74 | }; |
71 | 75 | ||
72 | 76 | ... | ... |
... | @@ -65,7 +65,6 @@ struct _mailbox | ... | @@ -65,7 +65,6 @@ struct _mailbox |
65 | 65 | ||
66 | /* Public methods */ | 66 | /* Public methods */ |
67 | 67 | ||
68 | int (*_init) __P ((mailbox_t)); | ||
69 | void (*_destroy) __P ((mailbox_t)); | 68 | void (*_destroy) __P ((mailbox_t)); |
70 | 69 | ||
71 | int (*_open) __P ((mailbox_t, int flag)); | 70 | int (*_open) __P ((mailbox_t, int flag)); | ... | ... |
... | @@ -65,7 +65,6 @@ struct _mailer | ... | @@ -65,7 +65,6 @@ struct _mailer |
65 | void *data; | 65 | void *data; |
66 | 66 | ||
67 | /* Public methods. */ | 67 | /* Public methods. */ |
68 | int (*_init) __P ((mailer_t)); | ||
69 | void (*_destroy) __P ((mailer_t)); | 68 | void (*_destroy) __P ((mailer_t)); |
70 | int (*_open) __P ((mailer_t, int flags)); | 69 | int (*_open) __P ((mailer_t, int flags)); |
71 | int (*_close) __P ((mailer_t)); | 70 | int (*_close) __P ((mailer_t)); | ... | ... |
... | @@ -36,19 +36,48 @@ extern "C" { | ... | @@ -36,19 +36,48 @@ extern "C" { |
36 | # endif | 36 | # endif |
37 | #endif /*__P */ | 37 | #endif /*__P */ |
38 | 38 | ||
39 | struct _record | 39 | #define MU_POP_PORT 110 |
40 | { | 40 | #define MU_POP_SCHEME "pop://" |
41 | const char *scheme; | 41 | #define MU_POP_SCHEME_LEN 6 |
42 | mailbox_entry_t mailbox; | 42 | extern int _url_pop_init __P ((url_t)); |
43 | mailer_entry_t mailer; | 43 | extern int _mailbox_pop_init __P ((mailbox_t)); |
44 | folder_entry_t folder; | 44 | extern int _folder_pop_init __P ((folder_t)); |
45 | int is_allocated; | 45 | |
46 | void *onwer; | 46 | #define MU_IMAP_PORT 143 |
47 | int (*_is_scheme) __P ((record_t, const char *)); | 47 | #define MU_IMAP_SCHEME "imap://" |
48 | int (*_get_mailbox) __P ((record_t, mailbox_entry_t *_mailbox)); | 48 | #define MU_IMAP_SCHEME_LEN 7 |
49 | int (*_get_mailer) __P ((record_t, mailer_entry_t *_mailer)); | 49 | extern int _url_imap_init __P ((url_t)); |
50 | int (*_get_folder) __P ((record_t, folder_entry_t *_mailer)); | 50 | extern int _mailbox_imap_init __P ((mailbox_t)); |
51 | }; | 51 | extern int _folder_imap_init __P ((folder_t)); |
52 | |||
53 | #define MU_MBOX_SCHEME "mbox:" | ||
54 | #define MU_MBOX_SCHEME_LEN 5 | ||
55 | extern int _url_mbox_init __P ((url_t)); | ||
56 | extern int _mailbox_mbox_init __P ((mailbox_t)); | ||
57 | extern int _folder_mbox_init __P ((folder_t)); | ||
58 | |||
59 | #define MU_FILE_SCHEME "file:" | ||
60 | #define MU_FILE_SCHEME_LEN 5 | ||
61 | extern int _url_file_init __P ((url_t)); | ||
62 | extern int _mailbox_file_init __P ((mailbox_t)); | ||
63 | extern int _folder_file_init __P ((folder_t)); | ||
64 | |||
65 | #define MU_PATH_SCHEME "/" | ||
66 | #define MU_PATH_SCHEME_LEN 1 | ||
67 | extern int _url_path_init __P ((url_t)); | ||
68 | extern int _mailbox_path_init __P ((mailbox_t)); | ||
69 | extern int _folder_path_init __P ((folder_t)); | ||
70 | |||
71 | #define MU_SMTP_SCHEME "smtp://" | ||
72 | #define MU_SMTP_SCHEME_LEN 7 | ||
73 | #define MU_SMTP_PORT 25 | ||
74 | extern int _url_smtp_init __P ((url_t)); | ||
75 | extern int _mailer_smtp_init __P ((mailer_t)); | ||
76 | |||
77 | #define MU_SENDMAIL_SCHEME "sendmail:" | ||
78 | #define MU_SENDMAIL_SCHEME_LEN 9 | ||
79 | extern int _url_sendmail_init __P ((url_t)); | ||
80 | extern int _mailer_sendmail_init __P ((mailer_t)); | ||
52 | 81 | ||
53 | #ifdef __cplusplus | 82 | #ifdef __cplusplus |
54 | } | 83 | } | ... | ... |
... | @@ -36,7 +36,8 @@ mailbox_create (mailbox_t *pmbox, const char *name) | ... | @@ -36,7 +36,8 @@ mailbox_create (mailbox_t *pmbox, const char *name) |
36 | { | 36 | { |
37 | int status = EINVAL; | 37 | int status = EINVAL; |
38 | record_t record = NULL; | 38 | record_t record = NULL; |
39 | mailbox_entry_t entry = NULL; | 39 | int (*m_init) __P ((mailbox_t)) = NULL; |
40 | int (*u_init) __P ((url_t)) = NULL; | ||
40 | iterator_t iterator; | 41 | iterator_t iterator; |
41 | list_t list; | 42 | list_t list; |
42 | int found = 0; | 43 | int found = 0; |
... | @@ -55,8 +56,9 @@ mailbox_create (mailbox_t *pmbox, const char *name) | ... | @@ -55,8 +56,9 @@ mailbox_create (mailbox_t *pmbox, const char *name) |
55 | iterator_current (iterator, (void **)&record); | 56 | iterator_current (iterator, (void **)&record); |
56 | if (record_is_scheme (record, name)) | 57 | if (record_is_scheme (record, name)) |
57 | { | 58 | { |
58 | record_get_mailbox (record, &entry); | 59 | record_get_mailbox (record, &m_init); |
59 | if (entry) | 60 | record_get_url (record, &u_init); |
61 | if (m_init && u_init) | ||
60 | { | 62 | { |
61 | found = 1; | 63 | found = 1; |
62 | break; | 64 | break; |
... | @@ -87,7 +89,7 @@ mailbox_create (mailbox_t *pmbox, const char *name) | ... | @@ -87,7 +89,7 @@ mailbox_create (mailbox_t *pmbox, const char *name) |
87 | /* Parse the url, it may be a bad one and we should bailout if this | 89 | /* Parse the url, it may be a bad one and we should bailout if this |
88 | failed. */ | 90 | failed. */ |
89 | if ((status = url_create (&url, name)) != 0 | 91 | if ((status = url_create (&url, name)) != 0 |
90 | || (status = entry->_url_init (url)) != 0) | 92 | || (status = u_init (url)) != 0) |
91 | { | 93 | { |
92 | mailbox_destroy (&mbox); | 94 | mailbox_destroy (&mbox); |
93 | return status; | 95 | return status; |
... | @@ -95,7 +97,7 @@ mailbox_create (mailbox_t *pmbox, const char *name) | ... | @@ -95,7 +97,7 @@ mailbox_create (mailbox_t *pmbox, const char *name) |
95 | mbox->url = url; | 97 | mbox->url = url; |
96 | 98 | ||
97 | /* Create the concrete mailbox type. */ | 99 | /* Create the concrete mailbox type. */ |
98 | status = entry->_mailbox_init (mbox); | 100 | status = m_init (mbox); |
99 | if (status != 0) | 101 | if (status != 0) |
100 | { | 102 | { |
101 | mailbox_destroy (&mbox); | 103 | mailbox_destroy (&mbox); | ... | ... |
... | @@ -36,7 +36,8 @@ mailer_create (mailer_t *pmailer, const char *name, int id) | ... | @@ -36,7 +36,8 @@ mailer_create (mailer_t *pmailer, const char *name, int id) |
36 | { | 36 | { |
37 | int status = EINVAL; | 37 | int status = EINVAL; |
38 | record_t record = NULL; | 38 | record_t record = NULL; |
39 | mailer_entry_t entry = NULL; | 39 | int (*m_init) __P ((mailer_t)) = NULL; |
40 | int (*u_init) __P ((url_t)) = NULL; | ||
40 | list_t list = NULL; | 41 | list_t list = NULL; |
41 | iterator_t iterator; | 42 | iterator_t iterator; |
42 | int found = 0; | 43 | int found = 0; |
... | @@ -55,12 +56,15 @@ mailer_create (mailer_t *pmailer, const char *name, int id) | ... | @@ -55,12 +56,15 @@ mailer_create (mailer_t *pmailer, const char *name, int id) |
55 | iterator_current (iterator, (void **)&record); | 56 | iterator_current (iterator, (void **)&record); |
56 | if (record_is_scheme (record, name)) | 57 | if (record_is_scheme (record, name)) |
57 | { | 58 | { |
58 | status = record_get_mailer (record, &entry); | 59 | record_get_mailer (record, &m_init); |
59 | if (status == 0) | 60 | record_get_url (record, &u_init); |
61 | if (m_init && u_init) | ||
62 | { | ||
60 | found = 1; | 63 | found = 1; |
61 | break; | 64 | break; |
62 | } | 65 | } |
63 | } | 66 | } |
67 | } | ||
64 | iterator_destroy (&iterator); | 68 | iterator_destroy (&iterator); |
65 | 69 | ||
66 | if (found) | 70 | if (found) |
... | @@ -83,14 +87,14 @@ mailer_create (mailer_t *pmailer, const char *name, int id) | ... | @@ -83,14 +87,14 @@ mailer_create (mailer_t *pmailer, const char *name, int id) |
83 | /* Parse the url, it may be a bad one and we should bailout if this | 87 | /* Parse the url, it may be a bad one and we should bailout if this |
84 | failed. */ | 88 | failed. */ |
85 | if ((status = url_create (&url, name)) != 0 | 89 | if ((status = url_create (&url, name)) != 0 |
86 | || (status = entry->_url_init (url)) != 0) | 90 | || (status = u_init (url)) != 0) |
87 | { | 91 | { |
88 | mailer_destroy (&mailer); | 92 | mailer_destroy (&mailer); |
89 | return status; | 93 | return status; |
90 | } | 94 | } |
91 | mailer->url = url; | 95 | mailer->url = url; |
92 | 96 | ||
93 | status = entry->_mailer_init (mailer); | 97 | status = m_init (mailer); |
94 | if (status != 0) | 98 | if (status != 0) |
95 | { | 99 | { |
96 | mailer_destroy (&mailer); | 100 | mailer_destroy (&mailer); | ... | ... |
... | @@ -27,53 +27,6 @@ | ... | @@ -27,53 +27,6 @@ |
27 | #include <mailbox0.h> | 27 | #include <mailbox0.h> |
28 | #include <registrar0.h> | 28 | #include <registrar0.h> |
29 | 29 | ||
30 | static int mailbox_file_init (mailbox_t mbox); | ||
31 | |||
32 | /* Register variables. */ | ||
33 | static struct mailbox_entry _file_entry = | ||
34 | { | ||
35 | url_file_init, mailbox_file_init | ||
36 | }; | ||
37 | mailbox_entry_t file_entry = &_file_entry; | ||
38 | extern struct folder_entry _fmbox_entry; | ||
39 | |||
40 | static struct _record _file_record = | ||
41 | { | ||
42 | MU_FILE_SCHEME, | ||
43 | &_file_entry, /* Mailbox entry. */ | ||
44 | NULL, /* Mailer entry. */ | ||
45 | &_fmbox_entry, /* Folder entry. */ | ||
46 | 0, /* Not malloc()ed. */ | ||
47 | NULL, /* No need for an owner. */ | ||
48 | NULL, /* is_scheme method. */ | ||
49 | NULL, /* get_mailbox method. */ | ||
50 | NULL, /* get_mailer method. */ | ||
51 | NULL /* get_folder method. */ | ||
52 | }; | ||
53 | record_t file_record = &_file_record; | ||
54 | |||
55 | /* Register variables. */ | ||
56 | static struct mailbox_entry _path_entry = | ||
57 | { | ||
58 | url_path_init, mailbox_file_init | ||
59 | }; | ||
60 | mailbox_entry_t path_entry = &_path_entry; | ||
61 | |||
62 | static struct _record _path_record = | ||
63 | { | ||
64 | MU_PATH_SCHEME, | ||
65 | &_path_entry, /* Mailbox entry. */ | ||
66 | NULL, /* Mailer entry. */ | ||
67 | &_fmbox_entry, /* Folder entry. */ | ||
68 | 0, /* Not malloc()ed. */ | ||
69 | NULL, /* No need for an owner. */ | ||
70 | NULL, /* is_scheme method. */ | ||
71 | NULL, /* get_mailbox method. */ | ||
72 | NULL, /* get_mailer method. */ | ||
73 | NULL /* get_folder method. */ | ||
74 | }; | ||
75 | record_t path_record = &_path_record; | ||
76 | |||
77 | /* | 30 | /* |
78 | Caveat there is no specific URL for file mailbox or simple path name, | 31 | Caveat there is no specific URL for file mailbox or simple path name, |
79 | <path_name> | 32 | <path_name> |
... | @@ -87,8 +40,8 @@ record_t path_record = &_path_record; | ... | @@ -87,8 +40,8 @@ record_t path_record = &_path_record; |
87 | out to be wrong. | 40 | out to be wrong. |
88 | */ | 41 | */ |
89 | 42 | ||
90 | static int | 43 | int |
91 | mailbox_file_init (mailbox_t mbox) | 44 | _mailbox_file_init (mailbox_t mbox) |
92 | { | 45 | { |
93 | struct stat st; | 46 | struct stat st; |
94 | size_t len = 0; | 47 | size_t len = 0; |
... | @@ -113,7 +66,7 @@ mailbox_file_init (mailbox_t mbox) | ... | @@ -113,7 +66,7 @@ mailbox_file_init (mailbox_t mbox) |
113 | file does not exist. */ | 66 | file does not exist. */ |
114 | if (stat (path, &st) < 0) | 67 | if (stat (path, &st) < 0) |
115 | { | 68 | { |
116 | status = mbox_entry->_mailbox_init (mbox); | 69 | status = _mailbox_mbox_init (mbox); |
117 | } | 70 | } |
118 | else if (S_ISREG (st.st_mode)) | 71 | else if (S_ISREG (st.st_mode)) |
119 | { | 72 | { |
... | @@ -121,12 +74,12 @@ mailbox_file_init (mailbox_t mbox) | ... | @@ -121,12 +74,12 @@ mailbox_file_init (mailbox_t mbox) |
121 | FIXME: We should do an open() and try | 74 | FIXME: We should do an open() and try |
122 | to do a better reconnaissance of the type, | 75 | to do a better reconnaissance of the type, |
123 | maybe MMDF. For now assume Unix MBox */ | 76 | maybe MMDF. For now assume Unix MBox */ |
124 | status = mbox_entry->_mailbox_init (mbox); | 77 | status = _mailbox_mbox_init (mbox); |
125 | } | 78 | } |
126 | /* Is that true ? Are all directories Maildir ?? */ | 79 | /* Is that true ? Are all directories Maildir ?? */ |
127 | else if (S_ISDIR (st.st_mode)) | 80 | else if (S_ISDIR (st.st_mode)) |
128 | { | 81 | { |
129 | /*status = maildir_entry._mailbox_init (mbox);*/ | 82 | /*status = _mailbox_maildir_init (mbox);*/ |
130 | status = EINVAL; | 83 | status = EINVAL; |
131 | } | 84 | } |
132 | 85 | ... | ... |
... | @@ -49,31 +49,6 @@ | ... | @@ -49,31 +49,6 @@ |
49 | #define ATTRIBUTE_IS_DELETED(flag) (flag & MU_ATTRIBUTE_DELETED) | 49 | #define ATTRIBUTE_IS_DELETED(flag) (flag & MU_ATTRIBUTE_DELETED) |
50 | #define ATTRIBUTE_IS_EQUAL(flag1, flag2) (flag1 == flag2) | 50 | #define ATTRIBUTE_IS_EQUAL(flag1, flag2) (flag1 == flag2) |
51 | 51 | ||
52 | static int mbox_init (mailbox_t mailbox); | ||
53 | |||
54 | /* Registrar variables. */ | ||
55 | static struct mailbox_entry _mbox_entry = | ||
56 | { | ||
57 | url_mbox_init, mbox_init | ||
58 | }; | ||
59 | mailbox_entry_t mbox_entry = &_mbox_entry; | ||
60 | extern struct folder_entry _fmbox_entry; | ||
61 | |||
62 | static struct _record _mbox_record = | ||
63 | { | ||
64 | MU_MBOX_SCHEME, | ||
65 | &_mbox_entry, /* Mailbox entry. */ | ||
66 | NULL, /* Mailer entry. */ | ||
67 | &_fmbox_entry, /* Folder entry. */ | ||
68 | 0, /* Not malloc()ed. */ | ||
69 | NULL, /* No need for an owner. */ | ||
70 | NULL, /* is_scheme method. */ | ||
71 | NULL, /* get_mailbox method. */ | ||
72 | NULL, /* get_mailer method. */ | ||
73 | NULL /* get_folder method. */ | ||
74 | }; | ||
75 | record_t mbox_record = &_mbox_record; | ||
76 | |||
77 | static void mbox_destroy (mailbox_t); | 52 | static void mbox_destroy (mailbox_t); |
78 | 53 | ||
79 | struct _mbox_message; | 54 | struct _mbox_message; |
... | @@ -170,8 +145,8 @@ static void mbox_cleanup (void *); | ... | @@ -170,8 +145,8 @@ static void mbox_cleanup (void *); |
170 | /* We allocate the mbox_data_t struct, but don't do any parsing on the name or | 145 | /* We allocate the mbox_data_t struct, but don't do any parsing on the name or |
171 | even test for existence. However we do strip any leading "mbox:" part of | 146 | even test for existence. However we do strip any leading "mbox:" part of |
172 | the name, this is suppose to be the protocol/scheme name. */ | 147 | the name, this is suppose to be the protocol/scheme name. */ |
173 | static int | 148 | int |
174 | mbox_init (mailbox_t mailbox) | 149 | _mailbox_mbox_init (mailbox_t mailbox) |
175 | { | 150 | { |
176 | mbox_data_t mud; | 151 | mbox_data_t mud; |
177 | size_t name_len; | 152 | size_t name_len; |
... | @@ -208,7 +183,6 @@ mbox_init (mailbox_t mailbox) | ... | @@ -208,7 +183,6 @@ mbox_init (mailbox_t mailbox) |
208 | mud->state = MBOX_NO_STATE; | 183 | mud->state = MBOX_NO_STATE; |
209 | 184 | ||
210 | /* Overloading the default. */ | 185 | /* Overloading the default. */ |
211 | mailbox->_init = mbox_init; | ||
212 | mailbox->_destroy = mbox_destroy; | 186 | mailbox->_destroy = mbox_destroy; |
213 | 187 | ||
214 | mailbox->_open = mbox_open; | 188 | mailbox->_open = mbox_open; |
... | @@ -1189,6 +1163,7 @@ mbox_get_message (mailbox_t mailbox, size_t msgno, message_t *pmsg) | ... | @@ -1189,6 +1163,7 @@ mbox_get_message (mailbox_t mailbox, size_t msgno, message_t *pmsg) |
1189 | return 0; | 1163 | return 0; |
1190 | } | 1164 | } |
1191 | 1165 | ||
1166 | /* FIXME: We have to generate a Message-ID: if the message have none. */ | ||
1192 | static int | 1167 | static int |
1193 | mbox_append_message (mailbox_t mailbox, message_t msg) | 1168 | mbox_append_message (mailbox_t mailbox, message_t msg) |
1194 | { | 1169 | { | ... | ... |
... | @@ -39,31 +39,6 @@ | ... | @@ -39,31 +39,6 @@ |
39 | #include <registrar0.h> | 39 | #include <registrar0.h> |
40 | #include <bio.h> | 40 | #include <bio.h> |
41 | 41 | ||
42 | static int pop_init (mailbox_t); | ||
43 | |||
44 | static struct mailbox_entry _pop_entry = | ||
45 | { | ||
46 | url_pop_init, pop_init | ||
47 | }; | ||
48 | static struct _record _pop_record = | ||
49 | { | ||
50 | MU_POP_SCHEME, | ||
51 | &_pop_entry, /* Mailbox entry. */ | ||
52 | NULL, /* Mailer entry. */ | ||
53 | NULL, /* folder entry. */ | ||
54 | 0, /* Not malloc()ed. */ | ||
55 | NULL, /* No need for an owner. */ | ||
56 | NULL, /* is_scheme method. */ | ||
57 | NULL, /* get_mailbox method. */ | ||
58 | NULL, /* get_mailer method. */ | ||
59 | NULL /* get_folder method. */ | ||
60 | }; | ||
61 | |||
62 | /* We export two functions: url parsing and the initialisation of | ||
63 | the mailbox, via the register entry/record. */ | ||
64 | record_t pop_record = &_pop_record; | ||
65 | mailbox_entry_t pop_entry = &_pop_entry; | ||
66 | |||
67 | /* Advance declarations. */ | 42 | /* Advance declarations. */ |
68 | struct _pop_data; | 43 | struct _pop_data; |
69 | struct _pop_message; | 44 | struct _pop_message; |
... | @@ -259,8 +234,8 @@ while (0) | ... | @@ -259,8 +234,8 @@ while (0) |
259 | 234 | ||
260 | 235 | ||
261 | /* Parse the url, allocate mailbox_t, allocate pop internal structures. */ | 236 | /* Parse the url, allocate mailbox_t, allocate pop internal structures. */ |
262 | static int | 237 | int |
263 | pop_init (mailbox_t mbox) | 238 | _mailbox_pop_init (mailbox_t mbox) |
264 | { | 239 | { |
265 | pop_data_t mpd; | 240 | pop_data_t mpd; |
266 | 241 | ||
... | @@ -274,7 +249,6 @@ pop_init (mailbox_t mbox) | ... | @@ -274,7 +249,6 @@ pop_init (mailbox_t mbox) |
274 | mpd->state = POP_NO_STATE; /* Init with no state. */ | 249 | mpd->state = POP_NO_STATE; /* Init with no state. */ |
275 | 250 | ||
276 | /* Initialize the structure. */ | 251 | /* Initialize the structure. */ |
277 | mbox->_init = pop_init; | ||
278 | mbox->_destroy = pop_destroy; | 252 | mbox->_destroy = pop_destroy; |
279 | 253 | ||
280 | mbox->_open = pop_open; | 254 | mbox->_open = pop_open; | ... | ... |
... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
28 | #include <registrar0.h> | 28 | #include <registrar0.h> |
29 | 29 | ||
30 | /* NOTE: We will leak here since the monitor and the registrar will never | 30 | /* NOTE: We will leak here since the monitor and the registrar will never |
31 | be release. */ | 31 | be release. That's ok we can leave with this, it's only done once. */ |
32 | static list_t registrar_list; | 32 | static list_t registrar_list; |
33 | struct _monitor registrar_monitor = MU_MONITOR_INITIALIZER; | 33 | struct _monitor registrar_monitor = MU_MONITOR_INITIALIZER; |
34 | 34 | ||
... | @@ -82,43 +82,144 @@ record_is_scheme (record_t record, const char *scheme) | ... | @@ -82,43 +82,144 @@ record_is_scheme (record_t record, const char *scheme) |
82 | } | 82 | } |
83 | 83 | ||
84 | int | 84 | int |
85 | record_get_mailbox (record_t record, mailbox_entry_t *pmbox) | 85 | record_set_scheme (record_t record, const char *scheme) |
86 | { | 86 | { |
87 | if (record == NULL || pmbox == NULL) | 87 | if (record == NULL) |
88 | return EINVAL; | ||
89 | record->scheme = scheme; | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | int | ||
94 | record_set_is_scheme (record_t record, int (*_is_scheme) | ||
95 | __P ((record_t, const char *))) | ||
96 | { | ||
97 | if (record == NULL) | ||
98 | return EINVAL; | ||
99 | record->_is_scheme = _is_scheme; | ||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | int | ||
104 | record_get_url (record_t record, int (*(*_purl)) __P ((url_t))) | ||
105 | { | ||
106 | if (record == NULL || _purl == NULL) | ||
107 | return EINVAL; | ||
108 | /* Overload. */ | ||
109 | if (record->_get_url) | ||
110 | return record->_get_url (record, _purl); | ||
111 | *_purl = record->_url; | ||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | int | ||
116 | record_set_url (record_t record, int (*_url) __P ((url_t))) | ||
117 | { | ||
118 | if (record == NULL) | ||
88 | return EINVAL; | 119 | return EINVAL; |
120 | record->_url = _url; | ||
121 | return 0; | ||
122 | } | ||
89 | 123 | ||
124 | int | ||
125 | record_set_get_url (record_t record, int (*_get_url) | ||
126 | __P ((record_t, int (*(*)) __P ((url_t))))) | ||
127 | { | ||
128 | if (record == NULL) | ||
129 | return EINVAL; | ||
130 | record->_get_url = _get_url; | ||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | int | ||
135 | record_get_mailbox (record_t record, int (*(*_pmailbox)) __P ((mailbox_t))) | ||
136 | { | ||
137 | if (record == NULL || _pmailbox == NULL) | ||
138 | return EINVAL; | ||
90 | /* Overload. */ | 139 | /* Overload. */ |
91 | if (record->_get_mailbox) | 140 | if (record->_get_mailbox) |
92 | return record->_get_mailbox (record, pmbox); | 141 | return record->_get_mailbox (record, _pmailbox); |
142 | *_pmailbox = record->_mailbox; | ||
143 | return 0; | ||
144 | } | ||
93 | 145 | ||
94 | *pmbox = record->mailbox; | 146 | int |
147 | record_set_mailbox (record_t record, int (*_mailbox) __P ((mailbox_t))) | ||
148 | { | ||
149 | if (record) | ||
150 | return EINVAL; | ||
151 | record->_mailbox = _mailbox; | ||
95 | return 0; | 152 | return 0; |
96 | } | 153 | } |
97 | 154 | ||
98 | int | 155 | int |
99 | record_get_mailer (record_t record, mailer_entry_t *pml) | 156 | record_set_get_mailbox (record_t record, int (*_get_mailbox) |
157 | __P ((record_t, int (*(*)) __P((mailbox_t))))) | ||
100 | { | 158 | { |
101 | if (record == NULL || pml == NULL) | 159 | if (record) |
102 | return EINVAL; | 160 | return EINVAL; |
161 | record->_get_mailbox = _get_mailbox; | ||
162 | return 0; | ||
163 | } | ||
103 | 164 | ||
165 | int | ||
166 | record_get_mailer (record_t record, int (*(*_pmailer)) __P ((mailer_t))) | ||
167 | { | ||
168 | if (record == NULL || _pmailer == NULL) | ||
169 | return EINVAL; | ||
104 | /* Overload. */ | 170 | /* Overload. */ |
105 | if (record->_get_mailer) | 171 | if (record->_get_mailer) |
106 | return record->_get_mailer (record, pml); | 172 | return record->_get_mailer (record, _pmailer); |
173 | *_pmailer = record->_mailer; | ||
174 | return 0; | ||
175 | } | ||
107 | 176 | ||
108 | *pml = record->mailer; | 177 | int |
178 | record_set_mailer (record_t record, int (*_mailer) __P ((mailer_t))) | ||
179 | { | ||
180 | if (record) | ||
181 | return EINVAL; | ||
182 | record->_mailer = _mailer; | ||
109 | return 0; | 183 | return 0; |
110 | } | 184 | } |
111 | 185 | ||
112 | int | 186 | int |
113 | record_get_folder (record_t record, folder_entry_t *pfolder) | 187 | record_set_get_mailer (record_t record, int (*_get_mailer) |
188 | __P ((record_t, int (*(*)) __P ((mailer_t))))) | ||
114 | { | 189 | { |
115 | if (record == NULL || pfolder == NULL) | 190 | if (record == NULL) |
116 | return EINVAL; | 191 | return EINVAL; |
192 | record->_get_mailer = _get_mailer; | ||
193 | return 0; | ||
194 | } | ||
117 | 195 | ||
196 | int | ||
197 | record_get_folder (record_t record, int (*(*_pfolder)) __P ((folder_t))) | ||
198 | { | ||
199 | if (record == NULL || _pfolder == NULL) | ||
200 | return EINVAL; | ||
118 | /* Overload. */ | 201 | /* Overload. */ |
119 | if (record->_get_folder) | 202 | if (record->_get_folder) |
120 | return record->_get_folder (record, pfolder); | 203 | return record->_get_folder (record, _pfolder); |
204 | *_pfolder = record->_folder; | ||
205 | return 0; | ||
206 | } | ||
121 | 207 | ||
122 | *pfolder = record->folder; | 208 | int |
209 | record_set_folder (record_t record, int (*_folder) __P ((folder_t))) | ||
210 | { | ||
211 | if (record == NULL) | ||
212 | return EINVAL; | ||
213 | record->_folder = _folder; | ||
214 | return 0; | ||
215 | } | ||
216 | |||
217 | int | ||
218 | record_set_get_folder (record_t record, int (*_get_folder) | ||
219 | __P ((record_t, int (*(*)) __P ((folder_t))))) | ||
220 | { | ||
221 | if (record == NULL) | ||
222 | return EINVAL; | ||
223 | record->_get_folder = _get_folder; | ||
123 | return 0; | 224 | return 0; |
124 | } | 225 | } | ... | ... |
... | @@ -31,30 +31,23 @@ | ... | @@ -31,30 +31,23 @@ |
31 | #include <mailer0.h> | 31 | #include <mailer0.h> |
32 | #include <registrar0.h> | 32 | #include <registrar0.h> |
33 | 33 | ||
34 | static int sendmail_init (mailer_t); | ||
35 | |||
36 | static struct mailer_entry _sendmail_entry = | ||
37 | { | ||
38 | url_sendmail_init, sendmail_init | ||
39 | }; | ||
40 | static struct _record _sendmail_record = | 34 | static struct _record _sendmail_record = |
41 | { | 35 | { |
42 | MU_SENDMAIL_SCHEME, | 36 | MU_SENDMAIL_SCHEME, |
37 | _url_sendmail_init, /* url init. */ | ||
43 | NULL, /* Mailbox entry. */ | 38 | NULL, /* Mailbox entry. */ |
44 | &_sendmail_entry, /* Mailer entry. */ | 39 | _mailer_sendmail_init, /* Mailer entry. */ |
45 | NULL, /* Folder entry. */ | 40 | NULL, /* Folder entry. */ |
46 | 0, /* Not malloc()ed. */ | 41 | NULL, /* No need for a back pointer. */ |
47 | NULL, /* No need for an owner. */ | 42 | NULL, /* _is_scheme method. */ |
48 | NULL, /* is_scheme method. */ | 43 | NULL, /* _get_url method. */ |
49 | NULL, /* get_mailbox method. */ | 44 | NULL, /* _get_mailbox method. */ |
50 | NULL, /* get_mailer method. */ | 45 | NULL, /* _get_mailer method. */ |
51 | NULL /* get_folder method. */ | 46 | NULL /* _get_folder method. */ |
52 | }; | 47 | }; |
53 | 48 | /* We export, url parsing and the initialisation of | |
54 | /* We export two functions: url parsing and the initialisation of | ||
55 | the mailbox, via the register entry/record. */ | 49 | the mailbox, via the register entry/record. */ |
56 | record_t sendmail_record = &_sendmail_record; | 50 | record_t sendmail_record = &_sendmail_record; |
57 | mailer_entry_t sendmail_entry = &_sendmail_entry; | ||
58 | 51 | ||
59 | struct _sendmail | 52 | struct _sendmail |
60 | { | 53 | { |
... | @@ -74,7 +67,7 @@ static int sendmail_close (mailer_t); | ... | @@ -74,7 +67,7 @@ static int sendmail_close (mailer_t); |
74 | static int sendmail_send_message (mailer_t, message_t); | 67 | static int sendmail_send_message (mailer_t, message_t); |
75 | 68 | ||
76 | int | 69 | int |
77 | sendmail_init (mailer_t mailer) | 70 | _mailer_sendmail_init (mailer_t mailer) |
78 | { | 71 | { |
79 | sendmail_t sendmail; | 72 | sendmail_t sendmail; |
80 | 73 | ||
... | @@ -83,9 +76,7 @@ sendmail_init (mailer_t mailer) | ... | @@ -83,9 +76,7 @@ sendmail_init (mailer_t mailer) |
83 | if (mailer->data == NULL) | 76 | if (mailer->data == NULL) |
84 | return ENOMEM; | 77 | return ENOMEM; |
85 | sendmail->state = SENDMAIL_NO_STATE; | 78 | sendmail->state = SENDMAIL_NO_STATE; |
86 | mailer->_init = sendmail_init; | ||
87 | mailer->_destroy = sendmail_destroy; | 79 | mailer->_destroy = sendmail_destroy; |
88 | |||
89 | mailer->_open = sendmail_open; | 80 | mailer->_open = sendmail_open; |
90 | mailer->_close = sendmail_close; | 81 | mailer->_close = sendmail_close; |
91 | mailer->_send_message = sendmail_send_message; | 82 | mailer->_send_message = sendmail_send_message; | ... | ... |
... | @@ -34,30 +34,23 @@ | ... | @@ -34,30 +34,23 @@ |
34 | #include <registrar0.h> | 34 | #include <registrar0.h> |
35 | #include <bio.h> | 35 | #include <bio.h> |
36 | 36 | ||
37 | static int smtp_init (mailer_t); | ||
38 | |||
39 | static struct mailer_entry _smtp_entry = | ||
40 | { | ||
41 | url_smtp_init, smtp_init | ||
42 | }; | ||
43 | static struct _record _smtp_record = | 37 | static struct _record _smtp_record = |
44 | { | 38 | { |
45 | MU_SMTP_SCHEME, | 39 | MU_SMTP_SCHEME, |
46 | NULL, /* Mailbox entry. */ | 40 | _url_smtp_init, /* url init. */ |
47 | &_smtp_entry, /* Mailer entry. */ | 41 | NULL, /* Mailbox init. */ |
48 | NULL, /* Mailer entry. */ | 42 | &_mailer_smtp_init, /* Mailer init. */ |
49 | 0, /* Not malloc()ed. */ | 43 | NULL, /* Folder init. */ |
50 | NULL, /* No need for an owner. */ | 44 | NULL, /* No need for a back pointer. */ |
51 | NULL, /* is_scheme method. */ | 45 | NULL, /* _is_scheme method. */ |
52 | NULL, /* get_mailbox method. */ | 46 | NULL, /* _get_url method. */ |
53 | NULL, /* get_mailer method. */ | 47 | NULL, /* _get_mailbox method. */ |
54 | NULL /* get_folder method. */ | 48 | NULL, /* _get_mailer method. */ |
49 | NULL /* _get_folder method. */ | ||
55 | }; | 50 | }; |
56 | 51 | /* We export : url parsing and the initialisation of | |
57 | /* We export two functions: url parsing and the initialisation of | ||
58 | the mailbox, via the register entry/record. */ | 52 | the mailbox, via the register entry/record. */ |
59 | record_t smtp_record = &_smtp_record; | 53 | record_t smtp_record = &_smtp_record; |
60 | mailer_entry_t smtp_entry = &_smtp_entry; | ||
61 | 54 | ||
62 | struct _smtp | 55 | struct _smtp |
63 | { | 56 | { |
... | @@ -144,7 +137,7 @@ static int get_rcpt (message_t , address_t *); | ... | @@ -144,7 +137,7 @@ static int get_rcpt (message_t , address_t *); |
144 | static int get_from (message_t , char *, address_t *); | 137 | static int get_from (message_t , char *, address_t *); |
145 | 138 | ||
146 | int | 139 | int |
147 | smtp_init (mailer_t mailer) | 140 | _mailer_smtp_init (mailer_t mailer) |
148 | { | 141 | { |
149 | smtp_t smtp; | 142 | smtp_t smtp; |
150 | 143 | ||
... | @@ -152,10 +145,7 @@ smtp_init (mailer_t mailer) | ... | @@ -152,10 +145,7 @@ smtp_init (mailer_t mailer) |
152 | smtp = mailer->data = calloc (1, sizeof (*smtp)); | 145 | smtp = mailer->data = calloc (1, sizeof (*smtp)); |
153 | if (mailer->data == NULL) | 146 | if (mailer->data == NULL) |
154 | return ENOMEM; | 147 | return ENOMEM; |
155 | |||
156 | mailer->_init = smtp_init; | ||
157 | mailer->_destroy = smtp_destroy; | 148 | mailer->_destroy = smtp_destroy; |
158 | |||
159 | mailer->_open = smtp_open; | 149 | mailer->_open = smtp_open; |
160 | mailer->_close = smtp_close; | 150 | mailer->_close = smtp_close; |
161 | mailer->_send_message = smtp_send_message; | 151 | mailer->_send_message = smtp_send_message; | ... | ... |
... | @@ -23,10 +23,9 @@ | ... | @@ -23,10 +23,9 @@ |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | 25 | ||
26 | #include <mailutils/registrar.h> | ||
27 | #include <url0.h> | 26 | #include <url0.h> |
27 | #include <registrar0.h> | ||
28 | 28 | ||
29 | int url_file_init (url_t purl); | ||
30 | static void url_file_destroy (url_t purl); | 29 | static void url_file_destroy (url_t purl); |
31 | 30 | ||
32 | static void | 31 | static void |
... | @@ -40,7 +39,7 @@ url_file_destroy (url_t url) | ... | @@ -40,7 +39,7 @@ url_file_destroy (url_t url) |
40 | file:path | 39 | file:path |
41 | */ | 40 | */ |
42 | int | 41 | int |
43 | url_file_init (url_t url) | 42 | _url_file_init (url_t url) |
44 | { | 43 | { |
45 | const char *name = url_to_string (url); | 44 | const char *name = url_to_string (url); |
46 | size_t len = strlen (name); | 45 | size_t len = strlen (name); |
... | @@ -53,7 +52,6 @@ url_file_init (url_t url) | ... | @@ -53,7 +52,6 @@ url_file_init (url_t url) |
53 | /* do I need to decode url encoding '% hex hex' ? */ | 52 | /* do I need to decode url encoding '% hex hex' ? */ |
54 | 53 | ||
55 | /* TYPE */ | 54 | /* TYPE */ |
56 | url->_init = url_file_init; | ||
57 | url->_destroy = url_file_destroy; | 55 | url->_destroy = url_file_destroy; |
58 | 56 | ||
59 | /* SCHEME */ | 57 | /* SCHEME */ | ... | ... |
... | @@ -23,10 +23,9 @@ | ... | @@ -23,10 +23,9 @@ |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | 25 | ||
26 | #include <mailutils/registrar.h> | 26 | #include <registrar0.h> |
27 | #include <url0.h> | 27 | #include <url0.h> |
28 | 28 | ||
29 | int url_mbox_init (url_t purl); | ||
30 | static void url_mbox_destroy (url_t purl); | 29 | static void url_mbox_destroy (url_t purl); |
31 | 30 | ||
32 | static void | 31 | static void |
... | @@ -40,7 +39,7 @@ url_mbox_destroy (url_t url) | ... | @@ -40,7 +39,7 @@ url_mbox_destroy (url_t url) |
40 | mbox:path | 39 | mbox:path |
41 | */ | 40 | */ |
42 | int | 41 | int |
43 | url_mbox_init (url_t url) | 42 | _url_mbox_init (url_t url) |
44 | { | 43 | { |
45 | const char *name = url_to_string (url); | 44 | const char *name = url_to_string (url); |
46 | size_t len = strlen (name); | 45 | size_t len = strlen (name); |
... | @@ -53,7 +52,6 @@ url_mbox_init (url_t url) | ... | @@ -53,7 +52,6 @@ url_mbox_init (url_t url) |
53 | /* do I need to decode url encoding '% hex hex' ? */ | 52 | /* do I need to decode url encoding '% hex hex' ? */ |
54 | 53 | ||
55 | /* TYPE */ | 54 | /* TYPE */ |
56 | url->_init = url_mbox_init; | ||
57 | url->_destroy = url_mbox_destroy; | 55 | url->_destroy = url_mbox_destroy; |
58 | 56 | ||
59 | /* SCHEME */ | 57 | /* SCHEME */ | ... | ... |
... | @@ -23,11 +23,10 @@ | ... | @@ -23,11 +23,10 @@ |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | 25 | ||
26 | #include <mailutils/registrar.h> | 26 | #include <registrar0.h> |
27 | #include <url0.h> | 27 | #include <url0.h> |
28 | 28 | ||
29 | static void url_path_destroy (url_t); | 29 | static void url_path_destroy (url_t); |
30 | int url_path_init (url_t); | ||
31 | 30 | ||
32 | static void | 31 | static void |
33 | url_path_destroy (url_t url) | 32 | url_path_destroy (url_t url) |
... | @@ -36,7 +35,7 @@ url_path_destroy (url_t url) | ... | @@ -36,7 +35,7 @@ url_path_destroy (url_t url) |
36 | } | 35 | } |
37 | 36 | ||
38 | int | 37 | int |
39 | url_path_init (url_t url) | 38 | _url_path_init (url_t url) |
40 | { | 39 | { |
41 | const char *name = url_to_string (url); | 40 | const char *name = url_to_string (url); |
42 | /* reject the obvious */ | 41 | /* reject the obvious */ |
... | @@ -46,7 +45,6 @@ url_path_init (url_t url) | ... | @@ -46,7 +45,6 @@ url_path_init (url_t url) |
46 | /* FIXME: do I need to decode url encoding '% hex hex' ? */ | 45 | /* FIXME: do I need to decode url encoding '% hex hex' ? */ |
47 | 46 | ||
48 | /* TYPE */ | 47 | /* TYPE */ |
49 | url->_init = url_path_init; | ||
50 | url->_destroy = url_path_destroy; | 48 | url->_destroy = url_path_destroy; |
51 | 49 | ||
52 | /* SCHEME */ | 50 | /* SCHEME */ | ... | ... |
... | @@ -24,8 +24,8 @@ | ... | @@ -24,8 +24,8 @@ |
24 | #include <string.h> | 24 | #include <string.h> |
25 | #include <errno.h> | 25 | #include <errno.h> |
26 | 26 | ||
27 | #include <mailutils/registrar.h> | ||
28 | #include <url0.h> | 27 | #include <url0.h> |
28 | #include <registrar0.h> | ||
29 | 29 | ||
30 | static void url_pop_destroy (url_t url); | 30 | static void url_pop_destroy (url_t url); |
31 | 31 | ||
... | @@ -40,7 +40,7 @@ url_pop_destroy (url_t url) | ... | @@ -40,7 +40,7 @@ url_pop_destroy (url_t url) |
40 | pop://[<user>;AUTH=<auth>@]<host>[:<port>] | 40 | pop://[<user>;AUTH=<auth>@]<host>[:<port>] |
41 | */ | 41 | */ |
42 | int | 42 | int |
43 | url_pop_init (url_t url) | 43 | _url_pop_init (url_t url) |
44 | { | 44 | { |
45 | const char *host_port, *indexe; | 45 | const char *host_port, *indexe; |
46 | char *name = url->name; | 46 | char *name = url->name; |
... | @@ -52,7 +52,6 @@ url_pop_init (url_t url) | ... | @@ -52,7 +52,6 @@ url_pop_init (url_t url) |
52 | /* do I need to decode url encoding '% hex hex' ? */ | 52 | /* do I need to decode url encoding '% hex hex' ? */ |
53 | 53 | ||
54 | /* TYPE */ | 54 | /* TYPE */ |
55 | url->_init = url_pop_init; | ||
56 | url->_destroy = url_pop_destroy; | 55 | url->_destroy = url_pop_destroy; |
57 | 56 | ||
58 | /* SCHEME */ | 57 | /* SCHEME */ | ... | ... |
... | @@ -23,10 +23,9 @@ | ... | @@ -23,10 +23,9 @@ |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | 25 | ||
26 | #include <mailutils/registrar.h> | 26 | #include <registrar0.h> |
27 | #include <url0.h> | 27 | #include <url0.h> |
28 | 28 | ||
29 | int url_sendmail_init (url_t purl); | ||
30 | static void url_sendmail_destroy (url_t purl); | 29 | static void url_sendmail_destroy (url_t purl); |
31 | 30 | ||
32 | static void | 31 | static void |
... | @@ -40,7 +39,7 @@ url_sendmail_destroy (url_t url) | ... | @@ -40,7 +39,7 @@ url_sendmail_destroy (url_t url) |
40 | sendmail:path | 39 | sendmail:path |
41 | */ | 40 | */ |
42 | int | 41 | int |
43 | url_sendmail_init (url_t url) | 42 | _url_sendmail_init (url_t url) |
44 | { | 43 | { |
45 | const char *name = url_to_string (url); | 44 | const char *name = url_to_string (url); |
46 | size_t len = strlen (name); | 45 | size_t len = strlen (name); |
... | @@ -53,7 +52,6 @@ url_sendmail_init (url_t url) | ... | @@ -53,7 +52,6 @@ url_sendmail_init (url_t url) |
53 | /* do I need to decode url encoding '% hex hex' ? */ | 52 | /* do I need to decode url encoding '% hex hex' ? */ |
54 | 53 | ||
55 | /* TYPE */ | 54 | /* TYPE */ |
56 | url->_init = url_sendmail_init; | ||
57 | url->_destroy = url_sendmail_destroy; | 55 | url->_destroy = url_sendmail_destroy; |
58 | 56 | ||
59 | /* SCHEME */ | 57 | /* SCHEME */ | ... | ... |
... | @@ -23,10 +23,9 @@ | ... | @@ -23,10 +23,9 @@ |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | 25 | ||
26 | #include <mailutils/registrar.h> | 26 | #include <registrar0.h> |
27 | #include <url0.h> | 27 | #include <url0.h> |
28 | 28 | ||
29 | int url_smtp_init (url_t purl); | ||
30 | static void url_smtp_destroy (url_t purl); | 29 | static void url_smtp_destroy (url_t purl); |
31 | 30 | ||
32 | static void | 31 | static void |
... | @@ -40,7 +39,7 @@ url_smtp_destroy (url_t url) | ... | @@ -40,7 +39,7 @@ url_smtp_destroy (url_t url) |
40 | file:path | 39 | file:path |
41 | */ | 40 | */ |
42 | int | 41 | int |
43 | url_smtp_init (url_t url) | 42 | _url_smtp_init (url_t url) |
44 | { | 43 | { |
45 | const char *name = url_to_string (url); | 44 | const char *name = url_to_string (url); |
46 | size_t len = strlen (name); | 45 | size_t len = strlen (name); |
... | @@ -53,7 +52,6 @@ url_smtp_init (url_t url) | ... | @@ -53,7 +52,6 @@ url_smtp_init (url_t url) |
53 | /* do I need to decode url encoding '% hex hex' ? */ | 52 | /* do I need to decode url encoding '% hex hex' ? */ |
54 | 53 | ||
55 | /* TYPE */ | 54 | /* TYPE */ |
56 | url->_init = url_smtp_init; | ||
57 | url->_destroy = url_smtp_destroy; | 55 | url->_destroy = url_smtp_destroy; |
58 | 56 | ||
59 | /* SCHEME */ | 57 | /* SCHEME */ | ... | ... |
-
Please register or sign in to post a comment