Commit a6483b11 a6483b1164098d209d8d7a69533b9fe187591120 by Alain Magloire

New batch of files.

1 parent eaaa3d36
...@@ -11,10 +11,17 @@ SUBDIRS = include pop3 mbox ...@@ -11,10 +11,17 @@ SUBDIRS = include pop3 mbox
11 lib_LTLIBRARIES = libmailbox.la 11 lib_LTLIBRARIES = libmailbox.la
12 12
13 libmailbox_la_SOURCES = \ 13 libmailbox_la_SOURCES = \
14 address.c \
15 attribute.c \
14 bstream.c \ 16 bstream.c \
17 envelope.c \
15 fstream.c \ 18 fstream.c \
16 iterator.c \ 19 iterator.c \
20 list.c \
17 md5-rsa.c \ 21 md5-rsa.c \
18 mstream.c \ 22 mstream.c \
23 observable.c \
24 observer.c \
25 parse822.c \
19 stream.c \ 26 stream.c \
20 tcp.c 27 tcpstream.c
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 <string.h>
23 #include <stdio.h>
24 #include <sys/types.h>
25 #include <string.h>
26 #include <ctype.h>
27 #include <stdlib.h>
28 #include <errno.h>
29
30 #include <mailutils/parse822.h>
31 #include <mailutils/mutil.h>
32 #include <mailutils/sys/address.h>
33
34 /* Get email address from rfc822 address. */
35 int
36 address_create (address_t *a, const char *s)
37 {
38 /* 'paddress' must exist, and can't already have been initialized
39 */
40 int status;
41
42 if (!a)
43 return EINVAL;
44
45 *a = NULL;
46 status = parse822_address_list (a, (char*) s);
47 if (status == 0)
48 {
49 /* And address-list may contain 0 addresses but parse correctly.
50 */
51 if (!*a)
52 return ENOENT;
53
54 (*a)->addr = strdup (s);
55 if (!(*a)->addr)
56 {
57 address_destroy (*a);
58 return ENOMEM;
59 }
60 }
61 return status;
62 }
63
64 int
65 address_destroy (address_t address)
66 {
67 if (address)
68 {
69 address_t current;
70 for (; address; address = current)
71 {
72 if (address->addr)
73 free (address->addr);
74 if (address->comments)
75 free (address->comments);
76 if (address->personal)
77 free (address->personal);
78 if (address->email)
79 free (address->email);
80 if (address->local_part)
81 free (address->local_part);
82 if (address->domain)
83 free (address->domain);
84 if (address->route)
85 free (address->route);
86 current = address->next;
87 free (address);
88 }
89 }
90 return 0;
91 }
92
93 int
94 address_get_personal (address_t addr, size_t no, char *buf, size_t len,
95 size_t *n)
96 {
97 size_t i, j;
98 int status = ENOENT;
99 if (addr == NULL)
100 return EINVAL;
101 for (i = 0, j = 1; addr; addr = addr->next, j++)
102 {
103 if (j == no)
104 {
105 i = util_cpystr (buf, addr->personal, len);
106 status = 0;
107 break;
108 }
109 }
110 if (n)
111 *n = i;
112 return status;
113 }
114
115 int
116 address_get_comments (address_t addr, size_t no, char *buf, size_t len,
117 size_t *n)
118 {
119 size_t i, j;
120 int status = ENOENT;
121 if (addr == NULL)
122 return EINVAL;
123 for (j = 1; addr; addr = addr->next, j++)
124 {
125 if (j == no)
126 {
127 i = util_cpystr (buf, addr->comments, len);
128 if (n)
129 *n = i;
130 status = 0;
131 break;
132 }
133 }
134 return status;
135 }
136
137 int
138 address_get_email (address_t addr, size_t no, char *buf, size_t len, size_t *n)
139 {
140 size_t i, j;
141 int status = ENOENT;
142 if (addr == NULL)
143 return EINVAL;
144 for (j = 1; addr; addr = addr->next, j++)
145 {
146 if (j == no)
147 {
148 i = util_cpystr (buf, addr->email, len);
149 if (n)
150 *n = i;
151 status = 0;
152 break;
153 }
154 }
155 return status;
156 }
157
158 int
159 address_get_local_part (address_t addr, size_t no, char *buf, size_t len, size_t *n)
160 {
161 size_t i, j;
162 int status = ENOENT;
163 if (addr == NULL)
164 return EINVAL;
165 for (j = 1; addr; addr = addr->next, j++)
166 {
167 if (j == no)
168 {
169 i = util_cpystr (buf, addr->local_part, len);
170 if (n)
171 *n = i;
172 status = 0;
173 break;
174 }
175 }
176 return status;
177 }
178
179 int
180 address_get_domain (address_t addr, size_t no, char *buf, size_t len, size_t *n)
181 {
182 size_t i, j;
183 int status = ENOENT;
184 if (addr == NULL)
185 return EINVAL;
186 for (j = 1; addr; addr = addr->next, j++)
187 {
188 if (j == no)
189 {
190 i = util_cpystr (buf, addr->domain, len);
191 if (n)
192 *n = i;
193 status = 0;
194 break;
195 }
196 }
197 return status;
198 }
199
200 int
201 address_get_route (address_t addr, size_t no, char *buf, size_t len, size_t *n)
202 {
203 size_t i, j;
204 int status = ENOENT;
205 if (addr == NULL)
206 return EINVAL;
207 for (j = 1; addr; addr = addr->next, j++)
208 {
209 if (j == no)
210 {
211 i = util_cpystr (buf, addr->route, len);
212 if (n)
213 *n = i;
214 status = 0;
215 break;
216 }
217 }
218 return status;
219 }
220
221 int
222 address_is_group (address_t addr, size_t no, int* yes)
223 {
224 size_t j;
225 int status = ENOENT;
226 if(addr == NULL)
227 return EINVAL;
228 for (j = 1; addr; addr = addr->next, j++)
229 {
230 if (j == no)
231 {
232 status = 0;
233 if(yes)
234 {
235 *yes = 0;
236 if(addr->personal && !addr->local_part && !addr->domain)
237 *yes = 1;
238 }
239 break;
240 }
241 }
242 return status;
243 }
244
245 int
246 address_to_string (address_t addr, char *buf, size_t len, size_t *n)
247 {
248 size_t i;
249 if (addr == NULL)
250 return EINVAL;
251 if (buf)
252 *buf = '\0';
253 i = util_cpystr (buf, addr->addr, len);
254 if (n)
255 *n = i;
256 return 0;
257 }
258
259 int
260 address_get_count (address_t addr, size_t *pcount)
261 {
262 size_t j;
263 for (j = 0; addr; addr = addr->next, j++)
264 ;
265 if (pcount)
266 *pcount = j;
267 return 0;
268 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
20
21 #include <sys/types.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <errno.h>
25
26 #ifdef HAVE_STRINGS_H
27 # include <strings.h>
28 #endif
29
30 #include <mailutils/error.h>
31 #include <mailutils/sys/attribute.h>
32
33 int
34 (attribute_add_ref) (attribute_t attribute)
35 {
36 if (attribute == NULL || attribute->vtable == NULL
37 || attribute->vtable->add_ref == NULL)
38 return MU_ERROR_NOT_SUPPORTED;
39 return attribute->vtable->add_ref (attribute);
40 }
41
42 int
43 (attribute_release) (attribute_t attribute)
44 {
45 if (attribute == NULL || attribute->vtable == NULL
46 || attribute->vtable->release == NULL)
47 return MU_ERROR_NOT_SUPPORTED;
48 return attribute->vtable->release (attribute);
49 }
50
51 int
52 (attribute_destroy) (attribute_t attribute)
53 {
54 if (attribute == NULL || attribute->vtable == NULL
55 || attribute->vtable->destroy == NULL)
56 return MU_ERROR_NOT_SUPPORTED;
57 return attribute->vtable->destroy (attribute);
58 }
59
60 int
61 (attribute_get_flags) (attribute_t attribute, int *pflags)
62 {
63 if (attribute == NULL || attribute->vtable == NULL
64 || attribute->vtable->get_flags == NULL)
65 return MU_ERROR_NOT_SUPPORTED;
66 return attribute->vtable->get_flags (attribute, pflags);
67 }
68
69 int
70 (attribute_set_flags) (attribute_t attribute, int flags)
71 {
72 if (attribute == NULL || attribute->vtable == NULL
73 || attribute->vtable->set_flags == NULL)
74 return MU_ERROR_NOT_SUPPORTED;
75 return attribute->vtable->set_flags (attribute, flags);
76 }
77
78 int
79 (attribute_unset_flags) (attribute_t attribute, int flags)
80 {
81 if (attribute == NULL || attribute->vtable == NULL
82 || attribute->vtable->unset_flags == NULL)
83 return MU_ERROR_NOT_SUPPORTED;
84 return attribute->vtable->unset_flags (attribute, flags);
85 }
86
87 int
88 (attribute_clear_flags) (attribute_t attribute)
89 {
90 if (attribute == NULL || attribute->vtable == NULL
91 || attribute->vtable->clear_flags == NULL)
92 return MU_ERROR_NOT_SUPPORTED;
93 return attribute->vtable->clear_flags (attribute);
94 }
95
96
97 /* Stub helpers for the wellknown flags. */
98 int
99 attribute_set_seen (attribute_t attribute)
100 {
101 if (attribute == NULL)
102 return MU_ERROR_INVALID_PARAMETER;
103 return attribute_set_flags (attribute, MU_ATTRIBUTE_SEEN);
104 }
105
106 int
107 attribute_set_answered (attribute_t attribute)
108 {
109 if (attribute == NULL)
110 return MU_ERROR_INVALID_PARAMETER;
111 return attribute_set_flags (attribute, MU_ATTRIBUTE_ANSWERED);
112 }
113
114 int
115 attribute_set_flagged (attribute_t attribute)
116 {
117 if (attribute == NULL)
118 return MU_ERROR_INVALID_PARAMETER;
119 return attribute_set_flags (attribute, MU_ATTRIBUTE_FLAGGED);
120 }
121
122 int
123 attribute_set_read (attribute_t attribute)
124 {
125 if (attribute == NULL)
126 return MU_ERROR_INVALID_PARAMETER;
127 return attribute_set_flags (attribute, MU_ATTRIBUTE_READ);
128 }
129
130 int
131 attribute_set_deleted (attribute_t attribute)
132 {
133 if (attribute == NULL)
134 return MU_ERROR_INVALID_PARAMETER;
135 return attribute_set_flags (attribute, MU_ATTRIBUTE_DELETED);
136 }
137
138 int
139 attribute_set_draft (attribute_t attribute)
140 {
141 if (attribute == NULL)
142 return MU_ERROR_INVALID_PARAMETER;
143 return attribute_set_flags (attribute, MU_ATTRIBUTE_DRAFT);
144 }
145
146 int
147 attribute_set_recent (attribute_t attribute)
148 {
149 if (attribute == NULL)
150 return MU_ERROR_INVALID_PARAMETER;
151 attribute_unset_flags (attribute, MU_ATTRIBUTE_READ);
152 return attribute_unset_flags (attribute, MU_ATTRIBUTE_SEEN);
153 }
154
155 int
156 attribute_set_modified (attribute_t attribute)
157 {
158 if (attribute == NULL)
159 return MU_ERROR_INVALID_PARAMETER;
160 return attribute_set_flags (attribute, MU_ATTRIBUTE_MODIFIED);
161 }
162
163 int
164 attribute_is_seen (attribute_t attribute)
165 {
166 int flags = 0;
167 if (attribute == NULL)
168 return 0;
169 attribute_get_flags (attribute, &flags);
170 return flags & MU_ATTRIBUTE_SEEN;
171 }
172
173 int
174 attribute_is_answered (attribute_t attribute)
175 {
176 int flags = 0;
177 if (attribute == NULL)
178 return 0;
179 attribute_get_flags (attribute, &flags);
180 return flags & MU_ATTRIBUTE_ANSWERED;
181 }
182
183 int
184 attribute_is_flagged (attribute_t attribute)
185 {
186 int flags = 0;
187 if (attribute == NULL)
188 return 0;
189 attribute_get_flags (attribute, &flags);
190 return flags & MU_ATTRIBUTE_FLAGGED;
191 }
192
193 int
194 attribute_is_read (attribute_t attribute)
195 {
196 int flags = 0;
197 if (attribute == NULL)
198 return 0;
199 attribute_get_flags (attribute, &flags);
200 return flags & MU_ATTRIBUTE_READ;
201 }
202
203 int
204 attribute_is_deleted (attribute_t attribute)
205 {
206 int flags = 0;
207 if (attribute == NULL)
208 return 0;
209 attribute_get_flags (attribute, &flags);
210 return flags & MU_ATTRIBUTE_DELETED;
211 }
212
213 int
214 attribute_is_draft (attribute_t attribute)
215 {
216 int flags = 0;
217 if (attribute == NULL)
218 return 0;
219 attribute_get_flags (attribute, &flags);
220 return flags & MU_ATTRIBUTE_DRAFT;
221 }
222
223 int
224 attribute_is_recent (attribute_t attribute)
225 {
226 int flags = 0;
227 if (attribute == NULL)
228 return 0;
229 attribute_get_flags (attribute, &flags);
230 /* Something is recent when it is not read and not seen. */
231 return (flags == 0
232 || ! ((flags & MU_ATTRIBUTE_SEEN) || (flags & MU_ATTRIBUTE_READ)));
233 }
234
235 int
236 attribute_is_modified (attribute_t attribute)
237 {
238 int flags = 0;
239 if (attribute == NULL)
240 return 0;
241 attribute_get_flags (attribute, &flags);
242 return flags & MU_ATTRIBUTE_MODIFIED;
243 }
244
245 int
246 attribute_unset_seen (attribute_t attribute)
247 {
248 if (attribute == NULL)
249 return 0;
250 return attribute_unset_flags (attribute, MU_ATTRIBUTE_SEEN);
251 }
252
253 int
254 attribute_unset_answered (attribute_t attribute)
255 {
256 if (attribute == NULL)
257 return 0;
258 return attribute_unset_flags (attribute, MU_ATTRIBUTE_ANSWERED);
259 }
260
261 int
262 attribute_unset_flagged (attribute_t attribute)
263 {
264 if (attribute == NULL)
265 return 0;
266 return attribute_unset_flags (attribute, MU_ATTRIBUTE_FLAGGED);
267 }
268
269 int
270 attribute_unset_read (attribute_t attribute)
271 {
272 if (attribute == NULL)
273 return 0;
274 return attribute_unset_flags (attribute, MU_ATTRIBUTE_READ);
275 }
276
277 int
278 attribute_unset_deleted (attribute_t attribute)
279 {
280 if (attribute == NULL)
281 return 0;
282 return attribute_unset_flags (attribute, MU_ATTRIBUTE_DELETED);
283 }
284
285 int
286 attribute_unset_draft (attribute_t attribute)
287 {
288 if (attribute == NULL)
289 return 0;
290 return attribute_unset_flags (attribute, MU_ATTRIBUTE_DRAFT);
291 }
292
293 int
294 attribute_unset_recent (attribute_t attribute)
295 {
296 if (attribute == NULL)
297 return 0;
298 return attribute_unset_flags (attribute, MU_ATTRIBUTE_SEEN);
299 }
300
301 int
302 attribute_unset_modified (attribute_t attribute)
303 {
304 if (attribute == NULL)
305 return 0;
306 return attribute_unset_flags (attribute, MU_ATTRIBUTE_MODIFIED);
307 }
308
309 /* Miscellaneous. */
310 int
311 attribute_is_equal (attribute_t attribute1, attribute_t attribute2)
312 {
313 int flags1 = 0;
314 int flags2 = 0;
315 if (attribute1)
316 attribute_get_flags (attribute1, &flags1);
317 if (attribute2)
318 attribute_get_flags (attribute2, &flags2);
319 return flags1 == flags2;
320 }
321
322 int
323 attribute_copy (attribute_t dest, attribute_t src)
324 {
325 int sflags = 0;
326 if (dest == NULL || src == NULL)
327 return MU_ERROR_INVALID_PARAMETER;
328 attribute_get_flags (src, &sflags);
329 attribute_clear_flags (dest);
330 attribute_set_flags (dest, sflags);
331 return 0;
332 }
333
334 static int
335 _da_add_ref (attribute_t attribute)
336 {
337 struct _da *da = (struct _da *)attribute;
338 int status;
339 monitor_lock (da->lock);
340 status = ++da->ref;
341 monitor_unlock (da->lock);
342 return status;
343 }
344
345 static int
346 _da_destroy (attribute_t attribute)
347 {
348 struct _da *da = (struct _da *)attribute;
349 monitor_destroy (da->lock);
350 free (da);
351 return 0;
352 }
353
354 static int
355 _da_release (attribute_t attribute)
356 {
357 struct _da *da = (struct _da *)attribute;
358 int status;
359 monitor_lock (da->lock);
360 status = --da->ref;
361 if (status <= 0)
362 {
363 monitor_unlock (da->lock);
364 _da_destroy (attribute);
365 return 0;
366 }
367 monitor_unlock (da->lock);
368 return status;
369 }
370
371 static int
372 _da_get_flags (attribute_t attribute, int *pflags)
373 {
374 struct _da *da = (struct _da *)attribute;
375 monitor_lock (da->lock);
376 if (pflags)
377 *pflags = da->flags;
378 monitor_unlock (da->lock);
379 return 0;
380 }
381
382 static int
383 _da_set_flags (attribute_t attribute, int flags)
384 {
385 struct _da *da = (struct _da *)attribute;
386 monitor_lock (da->lock);
387 da->flags |= (flags | MU_ATTRIBUTE_MODIFIED);
388 monitor_unlock (da->lock);
389 return 0;
390 }
391
392 static int
393 _da_unset_flags (attribute_t attribute, int flags)
394 {
395 struct _da *da = (struct _da *)attribute;
396 monitor_lock (da->lock);
397 da->flags &= ~flags;
398 /* If Modified was being unset do not reset it. */
399 if (!(flags & MU_ATTRIBUTE_MODIFIED))
400 da->flags |= MU_ATTRIBUTE_MODIFIED;
401 monitor_unlock (da->lock);
402 return 0;
403 }
404
405 static int
406 _da_clear_flags (attribute_t attribute)
407 {
408 struct _da *da = (struct _da *)attribute;
409 monitor_lock (da->lock);
410 da->flags = 0;
411 monitor_unlock (da->lock);
412 return 0;
413 }
414
415 static struct _attribute_vtable _da_vtable =
416 {
417 _da_add_ref,
418 _da_release,
419 _da_destroy,
420
421 _da_get_flags,
422 _da_set_flags,
423 _da_unset_flags,
424 _da_clear_flags
425 };
426
427 int
428 attribute_create (attribute_t *pattribute)
429 {
430 struct _da *da;
431 if (pattribute == NULL)
432 return MU_ERROR_INVALID_PARAMETER;
433 da = calloc (1, sizeof *da);
434 if (da == NULL)
435 return MU_ERROR_NO_MEMORY;
436
437 da->base.vtable = &_da_vtable;
438 da->ref = 1;
439 da->flags = 0;
440 monitor_create (&(da->lock));
441 *pattribute = &da->base;
442 return 0;
443 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 <mailutils/error.h>
23 #include <mailutils/sys/envelope.h>
24
25 int
26 (envelope_add_ref) (envelope_t envelope)
27 {
28 if (envelope == NULL || envelope->vtable == NULL
29 || envelope->vtable->add_ref == NULL)
30 return MU_ERROR_NOT_SUPPORTED;
31 return envelope->vtable->add_ref (envelope);
32 }
33
34 int
35 (envelope_release) (envelope_t envelope)
36 {
37 if (envelope == NULL || envelope->vtable == NULL
38 || envelope->vtable->release == NULL)
39 return MU_ERROR_NOT_SUPPORTED;
40 return envelope->vtable->release (envelope);
41 }
42
43 int
44 (envelope_destroy) (envelope_t envelope)
45 {
46 if (envelope == NULL || envelope->vtable == NULL
47 || envelope->vtable->destroy == NULL)
48 return MU_ERROR_NOT_SUPPORTED;
49 return envelope->vtable->destroy (envelope);
50 }
51
52 int
53 (envelope_sender) (envelope_t envelope, address_t *paddr)
54 {
55 if (envelope == NULL || envelope->vtable == NULL
56 || envelope->vtable->sender == NULL)
57 return MU_ERROR_NOT_SUPPORTED;
58 return envelope->vtable->sender (envelope, paddr);
59 }
60
61 int
62 (envelope_recipient) (envelope_t envelope, address_t *paddr)
63 {
64 if (envelope == NULL || envelope->vtable == NULL
65 || envelope->vtable->recipient == NULL)
66 return MU_ERROR_NOT_SUPPORTED;
67 return envelope->vtable->recipient (envelope, paddr);
68 }
69
70 int
71 (envelope_date) (envelope_t envelope, struct tm *tm, struct mu_timezone *tz)
72 {
73 if (envelope == NULL || envelope->vtable == NULL
74 || envelope->vtable->date == NULL)
75 return MU_ERROR_NOT_SUPPORTED;
76 return envelope->vtable->date (envelope, tm, tz);
77 }
...@@ -26,8 +26,9 @@ ...@@ -26,8 +26,9 @@
26 26
27 #include <sys/types.h> 27 #include <sys/types.h>
28 #include <sys/stat.h> 28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <unistd.h> 29 #include <unistd.h>
30 #include <fcntl.h>
31 #include <stdio.h>
31 32
32 #include <mailutils/sys/fstream.h> 33 #include <mailutils/sys/fstream.h>
33 #include <mailutils/error.h> 34 #include <mailutils/error.h>
...@@ -76,7 +77,7 @@ static int ...@@ -76,7 +77,7 @@ static int
76 _fs_read (stream_t stream, void *optr, size_t osize, size_t *nbytes) 77 _fs_read (stream_t stream, void *optr, size_t osize, size_t *nbytes)
77 { 78 {
78 struct _fs *fs = (struct _fs *)stream; 79 struct _fs *fs = (struct _fs *)stream;
79 size_t n; 80 size_t n = 0;
80 int err = 0; 81 int err = 0;
81 82
82 if (fs->file) 83 if (fs->file)
...@@ -123,7 +124,7 @@ static int ...@@ -123,7 +124,7 @@ static int
123 _fs_write (stream_t stream, const void *iptr, size_t isize, size_t *nbytes) 124 _fs_write (stream_t stream, const void *iptr, size_t isize, size_t *nbytes)
124 { 125 {
125 struct _fs *fs = (struct _fs *)stream; 126 struct _fs *fs = (struct _fs *)stream;
126 size_t n; 127 size_t n = 0;
127 int err = 0; 128 int err = 0;
128 129
129 if (fs->file) 130 if (fs->file)
...@@ -334,7 +335,7 @@ _fs_open (stream_t stream, const char *filename, int port, int flags) ...@@ -334,7 +335,7 @@ _fs_open (stream_t stream, const char *filename, int port, int flags)
334 || fdbuf.st_ino != filebuf.st_ino 335 || fdbuf.st_ino != filebuf.st_ino
335 || fdbuf.st_nlink != 1 336 || fdbuf.st_nlink != 1
336 || filebuf.st_nlink != 1 337 || filebuf.st_nlink != 1
337 || (fdbuf.st_mode & S_IFMT) != S_IFREG) 338 || !S_ISREG(fdbuf.st_mode))
338 { 339 {
339 mu_error ("%s must be a plain file with one link\n", filename); 340 mu_error ("%s must be a plain file with one link\n", filename);
340 close (fd); 341 close (fd);
......
1 # Use automake to process this file -*-Makefile-*-
2
3
4 SUBDIRS = sys
5
6 pkginclude_HEADERS = \
7 address.h \
8 attribute.h \
9 base.h \
10 envelope.h \
11 error.h \
12 iterator.h \
13 list.h \
14 mbox.h \
15 md5-rsa.h \
16 monitor.h \
17 mutil.h \
18 observer.h \
19 parse822.h \
20 pop3.h \
21 stream.h
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifndef _MAILUTILS_ADDRESS_H
19 #define _MAILUTILS_ADDRESS_H
20
21 #include <sys/types.h>
22
23 #ifndef __P
24 # ifdef __STDC__
25 # define __P(args) args
26 # else
27 # define __P(args) ()
28 # endif
29 #endif /*__P */
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 struct _address;
36 typedef struct _address *address_t;
37
38 extern int address_create __P ((address_t *, const char *));
39
40 extern int address_add_ref __P ((address_t));
41 extern int address_release __P ((address_t));
42 extern int address_destroy __P ((address_t));
43
44 extern int address_get_email
45 __P ((address_t, size_t, char *, size_t, size_t *));
46 extern int address_get_local_part
47 __P ((address_t, size_t, char *, size_t, size_t *));
48 extern int address_get_domain
49 __P ((address_t, size_t, char *, size_t, size_t *));
50 extern int address_get_personal
51 __P ((address_t, size_t, char *, size_t, size_t *));
52 extern int address_get_comments
53 __P ((address_t, size_t, char *, size_t, size_t *));
54 extern int address_get_route
55 __P ((address_t, size_t, char *, size_t, size_t *));
56
57 extern int address_is_group
58 __P ((address_t, size_t, int*));
59
60 extern int address_to_string __P ((address_t, char *, size_t, size_t *));
61 extern int address_get_count __P ((address_t, size_t *));
62
63 #ifdef __cplusplus
64 }
65 #endif
66
67 #endif /* _MAILUTILS_ADDRESS_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifndef _MAILUTILS_ATTRIBUTE_H
19 #define _MAILUTILS_ATTRIBUTE_H
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #ifndef __P
26 # ifdef __STDC__
27 # define __P(args) args
28 # else
29 # define __P(args) ()
30 # endif
31 #endif /*__P */
32
33 struct _attribute;
34 typedef struct _attribute * attribute_t;
35
36 #define MU_ATTRIBUTE_ANSWERED 0x0001
37 #define MU_ATTRIBUTE_FLAGGED 0x0002
38 #define MU_ATTRIBUTE_DELETED 0x0004
39 #define MU_ATTRIBUTE_DRAFT 0x0008
40 #define MU_ATTRIBUTE_SEEN 0x0010
41 #define MU_ATTRIBUTE_READ 0x0020
42 #define MU_ATTRIBUTE_MODIFIED 0x1000
43 #define MU_ATTRIBUTE_RECENT 0x0000
44
45 extern int attribute_create __P ((attribute_t *));
46
47 extern int attribute_add_ref __P ((attribute_t));
48 extern int attribute_release __P ((attribute_t));
49 extern int attribute_destroy __P ((attribute_t));
50
51 extern int attribute_is_seen __P ((attribute_t));
52 extern int attribute_is_answered __P ((attribute_t));
53 extern int attribute_is_flagged __P ((attribute_t));
54 extern int attribute_is_deleted __P ((attribute_t));
55 extern int attribute_is_draft __P ((attribute_t));
56 extern int attribute_is_recent __P ((attribute_t));
57 extern int attribute_is_read __P ((attribute_t));
58 extern int attribute_is_modified __P ((attribute_t));
59
60 extern int attribute_set_seen __P ((attribute_t));
61 extern int attribute_set_answered __P ((attribute_t));
62 extern int attribute_set_flagged __P ((attribute_t));
63 extern int attribute_set_deleted __P ((attribute_t));
64 extern int attribute_set_draft __P ((attribute_t));
65 extern int attribute_set_recent __P ((attribute_t));
66 extern int attribute_set_read __P ((attribute_t));
67 extern int attribute_set_modified __P ((attribute_t));
68
69 extern int attribute_unset_seen __P ((attribute_t));
70 extern int attribute_unset_answered __P ((attribute_t));
71 extern int attribute_unset_flagged __P ((attribute_t));
72 extern int attribute_unset_deleted __P ((attribute_t));
73 extern int attribute_unset_draft __P ((attribute_t));
74 extern int attribute_unset_recent __P ((attribute_t));
75 extern int attribute_unset_read __P ((attribute_t));
76 extern int attribute_unset_modified __P ((attribute_t));
77
78
79 extern int attribute_get_flags __P ((attribute_t, int *));
80 extern int attribute_set_flags __P ((attribute_t, int));
81 extern int attribute_unset_flags __P ((attribute_t, int));
82 extern int attribute_clear_flags __P ((attribute_t));
83
84 extern int attribute_is_equal __P ((attribute_t, attribute_t));
85 extern int attribute_copy __P ((attribute_t dst, attribute_t src));
86
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif /* _MAILUTILS_ATTRIBUTE_H */
...@@ -57,12 +57,6 @@ struct _mime *mime_t; ...@@ -57,12 +57,6 @@ struct _mime *mime_t;
57 struct _message; 57 struct _message;
58 typedef struct _message *message_t; 58 typedef struct _message *message_t;
59 59
60 struct _attribute;
61 typedef struct _attribute *attribute_t;
62
63 struct _envelope;
64 typedef struct _envelope *envelope_t;
65
66 struct _header; 60 struct _header;
67 typedef struct _header *header_t; 61 typedef struct _header *header_t;
68 62
...@@ -75,36 +69,18 @@ typedef struct _ticket *ticket_t; ...@@ -75,36 +69,18 @@ typedef struct _ticket *ticket_t;
75 struct _authority; 69 struct _authority;
76 typedef struct _authority *authority_t; 70 typedef struct _authority *authority_t;
77 71
78 struct _observable;
79 typedef struct _observable *observable_t;
80
81 struct _locker; 72 struct _locker;
82 typedef struct _locker *locker_t; 73 typedef struct _locker *locker_t;
83 74
84 struct _address;
85 typedef struct _address *address_t;
86
87 struct _debug; 75 struct _debug;
88 typedef struct _debug *mu_debug_t; 76 typedef struct _debug *mu_debug_t;
89 77
90 struct _stream;
91 typedef struct _stream *stream_t;
92
93 struct _filter; 78 struct _filter;
94 typedef struct _filter *filter_t; 79 typedef struct _filter *filter_t;
95 80
96 struct _iterator;
97 typedef struct _iterator *iterator_t;
98
99 struct _property; 81 struct _property;
100 typedef struct _property *property_t; 82 typedef struct _property *property_t;
101 83
102 struct _monitor;
103 typedef struct _monitor *monitory_t;
104
105 struct _list;
106 typedef struct _list *list_t;
107
108 __MAILUTILS_END_DECLS 84 __MAILUTILS_END_DECLS
109 85
110 #endif /*_MAILUTILS_BASE_H */ 86 #endif /*_MAILUTILS_BASE_H */
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifndef _MAILUTILS_ENVELOPE_H
19 # define _MAILUTILS_ENVELOPE_H
20
21 #include <mailutils/address.h>
22 #include <mailutils/mutil.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #ifndef __P
29 # ifdef __STDC__
30 # define __P(args) args
31 # else
32 # define __P(args) ()
33 # endif
34 #endif /*__P */
35
36 struct _envelope;
37 typedef struct _envelope *envelope_t;
38
39 extern int envelope_add_ref __P ((envelope_t));
40 extern int envelope_release __P ((envelope_t));
41 extern int envelope_destroy __P ((envelope_t));
42
43 extern int envelope_sender __P ((envelope_t, address_t *));
44 extern int envelope_recipient __P ((envelope_t, address_t *));
45 extern int envelope_date __P ((envelope_t, struct tm *, struct mu_timezone *));
46
47 #ifdef __cplusplus
48 }
49 #endif
50
51 #endif /* _MAILUTILS_ENVELOPE_H */
...@@ -18,9 +18,20 @@ ...@@ -18,9 +18,20 @@
18 #ifndef _MAILUTILS_ITERATOR_H 18 #ifndef _MAILUTILS_ITERATOR_H
19 #define _MAILUTILS_ITERATOR_H 19 #define _MAILUTILS_ITERATOR_H
20 20
21 #include <mailutils/base.h> 21 #ifdef __cplusplus
22 extern "C" {
23 #endif
22 24
23 __MAILUTILS_BEGIN_DECLS 25 #ifndef __P
26 # ifdef __STDC__
27 # define __P(args) args
28 # else
29 # define __P(args) ()
30 # endif /* __STDC__ */
31 #endif /* __P */
32
33 struct _iterator;
34 typedef struct _iterator *iterator_t;
24 35
25 extern int iterator_add_ref __P ((iterator_t)); 36 extern int iterator_add_ref __P ((iterator_t));
26 extern int iterator_destroy __P ((iterator_t)); 37 extern int iterator_destroy __P ((iterator_t));
...@@ -31,6 +42,8 @@ extern int iterator_next __P ((iterator_t)); ...@@ -31,6 +42,8 @@ extern int iterator_next __P ((iterator_t));
31 extern int iterator_current __P ((iterator_t, void *)); 42 extern int iterator_current __P ((iterator_t, void *));
32 extern int iterator_is_done __P ((iterator_t)); 43 extern int iterator_is_done __P ((iterator_t));
33 44
34 __MAILUTILS_END_DECLS 45 #ifdef __cplusplus
46 }
47 #endif
35 48
36 #endif /* _MAILUTILS_ITERATOR_H */ 49 #endif /* _MAILUTILS_ITERATOR_H */
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifndef _MAILUTILS_LIST_H
19 #define _MAILUTILS_LIST_H
20
21 #include <sys/types.h>
22 #include <mailutils/iterator.h>
23
24 #ifndef __P
25 # ifdef __STDC__
26 # define __P(args) args
27 # else
28 # define __P(args) ()
29 # endif
30 #endif /*__P */
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 struct _list;
37 typedef struct _list *list_t;
38
39 extern int list_create __P ((list_t *));
40 extern int list_destroy __P ((list_t));
41 extern int list_append __P ((list_t, void *));
42 extern int list_prepend __P ((list_t, void *));
43 extern int list_is_empty __P ((list_t));
44 extern int list_count __P ((list_t, size_t *));
45 extern int list_remove __P ((list_t, void *));
46 extern int list_get __P ((list_t, size_t, void **));
47 extern int list_get_iterator __P ((list_t, iterator_t *));
48
49 #ifdef __cplusplus
50 }
51 #endif
52
53 #endif /* _MAILUTILS_LIST_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifndef _MAILUTILS_OBSERVER_H
19 #define _MAILUTILS_OBSERVER_H
20
21 #include <sys/types.h>
22 #include <mailutils/base.h>
23
24 #ifndef __P
25 #ifdef __STDC__
26 #define __P(args) args
27 #else
28 #define __P(args) ()
29 #endif
30 #endif /*__P */
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 struct _observer;
37 struct _observable;
38 typedef struct _observer * observer_t;
39 typedef struct _observable * observable_t;
40
41 struct event
42 {
43 int type;
44 union
45 {
46 mailbox_t mailbox; /* For corrupted mailbox. */
47 int msgno; /* For new message. */
48 int percentage; /* Scan progress. */
49 message_t message; /* message sent. */
50 } data ;
51 };
52
53 #define MU_EVT_MESSAGE_ADD 0x010
54 #define MU_EVT_MAILBOX_PROGRESS 0x020
55 #define MU_EVT_AUTHORITY_FAILED 0x030
56 #define MU_EVT_MAILBOX_CORRUPT 0x040
57 #define MU_EVT_MAILER_MESSAGE_SENT 0x080
58
59 extern int observer_create __P ((observer_t *, int (*action)
60 __P ((void *, struct event)), void *));
61
62 extern int observer_add_ref __P ((observer_t));
63 extern int observer_release __P ((observer_t));
64 extern int observer_destroy __P ((observer_t));
65
66 extern int observer_action __P ((observer_t, struct event));
67
68
69 extern int observable_create __P ((observable_t *));
70 extern int observable_release __P ((observable_t));
71 extern int observable_destroy __P ((observable_t));
72
73 extern int observable_attach __P ((observable_t, int, observer_t));
74 extern int observable_detach __P ((observable_t, observer_t));
75 extern int observable_notify_all __P ((observable_t, struct event));
76
77 #ifdef __cplusplus
78 }
79 #endif
80
81 #endif /* _MAILUTILS_OBSERVER_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 /**
19 * Parses syntatic elements defined in RFC 822.
20 */
21
22 #ifndef _MAILUTILS_PARSE822_H
23 #define _MAILUTILS_PARSE822_H
24
25 #include <mailutils/address.h>
26 #include <mailutils/mutil.h>
27
28 #ifndef __P
29 # ifdef __STDC__
30 # define __P(args) args
31 # else
32 # define __P(args) ()
33 # endif
34 #endif /*__P */
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /**
41 * Reads an RFC822 defined lexical token from an input. All names are
42 * as close as possible to those used in the extended BNF of the RFC.
43 */
44
45 /* From RFC 822, 3.3 Lexical Tokens */
46
47 extern int parse822_is_char __P ((char c));
48 extern int parse822_is_digit __P ((char c));
49 extern int parse822_is_ctl __P ((char c));
50 extern int parse822_is_space __P ((char c));
51 extern int parse822_is_htab __P ((char c));
52 extern int parse822_is_lwsp_char __P ((char c));
53 extern int parse822_is_special __P ((char c));
54 extern int parse822_is_atom_char __P ((char c));
55 extern int parse822_is_q_text __P ((char c));
56 extern int parse822_is_d_text __P ((char c));
57 extern int parse822_is_smtp_q __P ((char c));
58
59 extern int parse822_skip_crlf __P ((const char** p, const char* e));
60 extern int parse822_skip_lwsp_char __P ((const char** p, const char* e));
61 extern int parse822_skip_lwsp __P ((const char** p, const char* e));
62 extern int parse822_skip_comments __P ((const char** p, const char* e));
63 extern int parse822_skip_nl __P ((const char** p, const char* e));
64
65 extern int parse822_digits __P ((const char** p, const char* e, int min, int max, int* digits));
66 extern int parse822_special __P ((const char** p, const char* e, char c));
67 extern int parse822_comment __P ((const char** p, const char* e, char** comment));
68 extern int parse822_atom __P ((const char** p, const char* e, char** atom));
69 extern int parse822_quoted_pair __P ((const char** p, const char* e, char** qpair));
70 extern int parse822_quoted_string __P ((const char** p, const char* e, char** qstr));
71 extern int parse822_word __P ((const char** p, const char* e, char** word));
72 extern int parse822_phrase __P ((const char** p, const char* e, char** phrase));
73 extern int parse822_d_text __P ((const char** p, const char* e, char** dtext));
74
75 /* From RFC 822, 6.1 Address Specification Syntax */
76
77 extern int parse822_address_list __P ((address_t* a, const char* s));
78 extern int parse822_mail_box __P ((const char** p, const char* e, address_t* a));
79 extern int parse822_group __P ((const char** p, const char* e, address_t* a));
80 extern int parse822_address __P ((const char** p, const char* e, address_t* a));
81 extern int parse822_route_addr __P ((const char** p, const char* e, address_t* a));
82 extern int parse822_route __P ((const char** p, const char* e, char** route));
83 extern int parse822_addr_spec __P ((const char** p, const char* e, address_t* a));
84 extern int parse822_unix_mbox __P ((const char** p, const char* e, address_t* a));
85 extern int parse822_local_part __P ((const char** p, const char* e, char** local_part));
86 extern int parse822_domain __P ((const char** p, const char* e, char** domain));
87 extern int parse822_sub_domain __P ((const char** p, const char* e, char** sub_domain));
88 extern int parse822_domain_ref __P ((const char** p, const char* e, char** domain_ref));
89 extern int parse822_domain_literal __P ((const char** p, const char* e, char** domain_literal));
90
91 /* RFC 822 Quoting Functions
92 * Various elements must be quoted if then contain non-safe characters. What
93 * characters are allowed depend on the element. The following functions will
94 * allocate a quoted version of the raw element, it may not actually be
95 * quoted if no unsafe characters were in the raw string.
96 */
97
98 extern int parse822_quote_string __P ((char** quoted, const char* raw));
99 extern int parse822_quote_local_part __P ((char** quoted, const char* raw));
100
101 extern int parse822_field_body __P ((const char** p, const char *e, char** fieldbody));
102 extern int parse822_field_name __P ((const char** p, const char *e, char** fieldname));
103
104 /***** From RFC 822, 5.1 Date and Time Specification Syntax *****/
105
106 extern int parse822_day __P ((const char** p, const char* e, int* day));
107 extern int parse822_date __P ((const char** p, const char* e, int* day, int* mon, int* year));
108 extern int parse822_time __P ((const char** p, const char* e, int* h, int* m, int* s, int* tz, const char** tz_name));
109 extern int parse822_date_time __P ((const char** p, const char* e, struct tm* tm, mu_timezone* tz));
110
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif /* _MAILUTILS_PARSE822_H */
117
...@@ -21,7 +21,17 @@ ...@@ -21,7 +21,17 @@
21 #include <mailutils/iterator.h> 21 #include <mailutils/iterator.h>
22 #include <mailutils/stream.h> 22 #include <mailutils/stream.h>
23 23
24 __MAILUTILS_BEGIN_DECLS 24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #ifndef __P
29 # ifdef __STDC__
30 # define __P(args) args
31 # else
32 # define __P(args) ()
33 # endif
34 #endif /*__P */
25 35
26 struct _pop3; 36 struct _pop3;
27 typedef struct _pop3* pop3_t; 37 typedef struct _pop3* pop3_t;
...@@ -72,6 +82,8 @@ extern int pop3_writeline __P ((pop3_t, const char *, ...)); ...@@ -72,6 +82,8 @@ extern int pop3_writeline __P ((pop3_t, const char *, ...));
72 extern int pop3_sendline __P ((pop3_t, const char *)); 82 extern int pop3_sendline __P ((pop3_t, const char *));
73 extern int pop3_send __P ((pop3_t)); 83 extern int pop3_send __P ((pop3_t));
74 84
75 __MAILUTILS_END_DECLS 85 #ifdef __cplusplus
86 }
87 #endif
76 88
77 #endif /* _MAILUTILS_POP3_H */ 89 #endif /* _MAILUTILS_POP3_H */
......
...@@ -16,12 +16,13 @@ ...@@ -16,12 +16,13 @@
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17 17
18 #ifndef _MAILUTILS_STREAM_H 18 #ifndef _MAILUTILS_STREAM_H
19 # define _MAILUTILS_STREAM_H 19 #define _MAILUTILS_STREAM_H
20 20
21 #include <mailutils/base.h>
22 #include <sys/types.h> 21 #include <sys/types.h>
23 22
24 __MAILUTILS_BEGIN_DECLS 23 #ifdef __cplusplus
24 extern "C" {
25 #endif
25 26
26 #define MU_STREAM_READ 0x00000001 27 #define MU_STREAM_READ 0x00000001
27 #define MU_STREAM_WRITE 0x00000002 28 #define MU_STREAM_WRITE 0x00000002
...@@ -46,6 +47,9 @@ enum stream_state ...@@ -46,6 +47,9 @@ enum stream_state
46 MU_STREAM_STATE_CLOSE 47 MU_STREAM_STATE_CLOSE
47 }; 48 };
48 49
50 struct _stream;
51 typedef struct _stream *stream_t;
52
49 extern int stream_add_ref __P ((stream_t)); 53 extern int stream_add_ref __P ((stream_t));
50 extern int stream_release __P ((stream_t)); 54 extern int stream_release __P ((stream_t));
51 extern int stream_destroy __P ((stream_t)); 55 extern int stream_destroy __P ((stream_t));
...@@ -75,6 +79,8 @@ extern int stream_memory_create __P ((stream_t *)); ...@@ -75,6 +79,8 @@ extern int stream_memory_create __P ((stream_t *));
75 extern int stream_tcp_create __P ((stream_t *)); 79 extern int stream_tcp_create __P ((stream_t *));
76 extern int stream_buffer_create __P ((stream_t *, stream_t, size_t)); 80 extern int stream_buffer_create __P ((stream_t *, stream_t, size_t));
77 81
78 __MAILUTILS_END_DECLS 82 #ifdef __cplusplus
83 }
84 #endif
79 85
80 #endif /* _MAILUTILS_STREAM_H */ 86 #endif /* _MAILUTILS_STREAM_H */
......
1 # Use automake to process this file -*-Makefile-*-
2
3 pkginclude_HEADERS = \
4 address.h \
5 attribute.h \
6 bstream.h \
7 envelope.h \
8 fstream.h \
9 iterator.h \
10 list.h \
11 mbox.h \
12 mstream.h \
13 observer.h \
14 pop3.h \
15 stream.h \
16 tcpstream.h
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifndef _ADDRESS0_H
19 #define _ADDRESS0_H
20
21 #ifdef DMALLOC
22 # include <dmalloc.h>
23 #endif
24
25 #include <mailutils/address.h>
26
27 #ifndef __P
28 # ifdef __STDC__
29 # define __P(args) args
30 # else
31 # define __P(args) ()
32 # endif
33 #endif /*__P */
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /*
40 * The data-structure representing an RFC822 MAILBOX. It may be
41 * one MAILBOX or a list of them, as found in an ADDRESS or
42 * a MAILBOX list (as found in a GROUP).
43 *
44 * Capitalized names are from RFC 822, section 6.1 (Address Syntax).
45 */
46 struct _address
47 {
48 char *addr;
49 /* the original string that this list of addresses was created
50 * from, only present at the head of the list */
51
52 char *comments;
53 /* the collection of comments stripped during parsing this MAILBOX */
54 char *personal;
55 /* the PHRASE portion of a MAILBOX, called the DISPLAY-NAME in drums */
56 char *email;
57 /* the ADDR-SPEC, the LOCAL-PART@DOMAIN */
58 char *local_part;
59 /* the LOCAL-PART of a MAILBOX */
60 char *domain;
61 /* the DOMAIN of a MAILBOX */
62 char *route;
63 /* the optional ROUTE in the ROUTE-ADDR form of MAILBOX */
64
65 /* size_t num; this didn't appear to be used anywhere... so I commented
66 it out, is that ok? -sam */
67
68 struct _address *next;
69 };
70
71 #ifdef __cplusplus
72 }
73 #endif
74
75 #endif /* _ADDRESS0_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifndef _MAILUTILS_SYS_ATTRIBUTE_H
19 # define _MAILUTILS_SYS_ATTRIBUTE_H
20
21 #ifdef DMALLOC
22 # include <dmalloc.h>
23 #endif
24
25 #include <mailutils/attribute.h>
26 #include <mailutils/monitor.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #ifndef __P
33 # ifdef __STDC__
34 # define __P(args) args
35 # else
36 # define __P(args) ()
37 # endif
38 #endif /*__P */
39
40 struct _attribute_vtable
41 {
42 int (*add_ref) __P ((attribute_t));
43 int (*release) __P ((attribute_t));
44 int (*destroy) __P ((attribute_t));
45
46 int (*get_flags) __P ((attribute_t, int *));
47 int (*set_flags) __P ((attribute_t, int));
48 int (*unset_flags) __P ((attribute_t, int));
49 int (*clear_flags) __P ((attribute_t));
50 };
51
52 struct _attribute
53 {
54 struct _attribute_vtable *vtable;
55 };
56
57 /* A simple default attribute implementation. */
58 struct _da
59 {
60 struct _attribute base;
61 int ref;
62 int flags;
63 monitor_t lock;
64 };
65
66 #define attribute_add_ref(a) ((a)->vtable->add_ref)(s)
67 #define attribute_release(a) ((a)->vtable->release)(s)
68 #define attribute_destroy(a) ((a)->vtable->destroy)(s)
69
70 #define attribute_get_flags(a,pf) ((a)->vtable->get_flags)(a,pf)
71 #define attribute_set_flags(a,f) ((a)->vtable->set_flags)(a,f)
72 #define attribute_unset_flags(a,f) ((a)->vtable->unset_flags)(a,f)
73 #define attribute_clear_flags(a) ((a)->vtable->clear_flags)(a)
74
75
76 #ifdef __cplusplus
77 }
78 #endif
79
80 #endif /* _MAILUTILS_SYS_ATTRIBUTE_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifndef _MAILUTILS_SYS_ENVELOPE_H
19 #define _MAILUTILS_SYS_ENVELOPE_H
20
21 #ifdef DMALLOC
22 #include <dmalloc.h>
23 #endif
24
25 #include <mailutils/envelope.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #ifndef __P
32 # ifdef __STDC__
33 # define __P(args) args
34 # else
35 # define __P(args) ()
36 # endif
37 #endif /*__P */
38
39 struct _envelope_vtable
40 {
41 int (*add_ref) __P ((envelope_t));
42 int (*release) __P ((envelope_t));
43 int (*destroy) __P ((envelope_t));
44 int (*sender) __P ((envelope_t, address_t *));
45 int (*recipient) __P ((envelope_t, address_t *));
46 int (*date) __P ((envelope_t, struct tm *, struct mu_timezone *));
47 };
48
49 struct _envelope
50 {
51 struct _envelope_vtable *vtable;
52 };
53
54 #ifdef __cplusplus
55 }
56 #endif
57
58 #endif /* _MAILUTILS_SYS_ENVELOPE_H */
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
20 20
21 #include <mailutils/iterator.h> 21 #include <mailutils/iterator.h>
22 22
23 __MAILUTILS_BEGIN_DECLS 23 #ifdef __cplusplus
24 extern "C" {
25 #endif
24 26
25 struct _iterator_vtable 27 struct _iterator_vtable
26 { 28 {
...@@ -50,6 +52,8 @@ struct _iterator ...@@ -50,6 +52,8 @@ struct _iterator
50 #define iterator_current(i,a) ((i)->vtable->current)(i,a) 52 #define iterator_current(i,a) ((i)->vtable->current)(i,a)
51 #define iterator_is_done(i) ((i)->vtable->is_done)(i) 53 #define iterator_is_done(i) ((i)->vtable->is_done)(i)
52 54
53 __MAILUTILS_END_DECLS 55 #ifdef __cplusplus
56 }
57 #endif
54 58
55 #endif /* _MAILUTILS_SYS_ITERATOR_H */ 59 #endif /* _MAILUTILS_SYS_ITERATOR_H */
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifndef _MAILUTILS_SYS_LIST_H
19 #define _MAILUTILS_SYS_LIST_H
20
21 #ifdef DMALLOC
22 # include <dmalloc.h>
23 #endif
24
25 #include <sys/types.h>
26
27 #include <mailutils/list.h>
28 #include <mailutils/monitor.h>
29 #include <mailutils/sys/iterator.h>
30
31 #ifndef __P
32 #ifdef __STDC__
33 #define __P(args) args
34 #else
35 #define __P(args) ()
36 #endif
37 #endif /*__P */
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 struct list_data
44 {
45 void *item;
46 struct list_data *next;
47 struct list_data *prev;
48 };
49
50 struct _list
51 {
52 struct list_data head;
53 size_t count;
54 size_t index;
55 monitor_t lock;
56 };
57
58 struct l_iterator
59 {
60 struct _iterator base;
61 unsigned int ref;
62 list_t list;
63 struct list_data *current;
64 monitor_t lock;
65 };
66
67
68 #ifdef __cplusplus
69 }
70 #endif
71
72 #endif /* _MAILUTILS_SYS_LIST_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #ifndef _MAILUTILS_SYS_OBSERVER_H
19 #define _MAILUTILS_SYS_OBSERVER_H
20
21 #ifdef DMALLOC
22 # include <dmalloc.h>
23 #endif
24
25 #include <mailutils/monitor.h>
26 #include <mailutils/observer.h>
27 #include <mailutils/list.h>
28
29 #ifndef __P
30 #ifdef __STDC__
31 #define __P(args) args
32 #else
33 #define __P(args) ()
34 #endif
35 #endif /*__P */
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 struct _observer_vtable
42 {
43 int (*add_ref) __P ((observer_t));
44 int (*release) __P ((observer_t));
45 int (*destroy) __P ((observer_t));
46
47 int (*action) __P ((observer_t, struct event));
48 };
49
50 struct _observer
51 {
52 struct _observer_vtable *vtable;
53 };
54
55 struct _observable
56 {
57 list_t list;
58 };
59
60 struct _dobserver
61 {
62 struct _observer base;
63 int ref;
64 void *arg;
65 int (*action) __P ((void *, struct event));
66 monitor_t lock;
67 };
68
69 #ifdef __cplusplus
70 }
71 #endif
72
73 #endif /* _MAILUTILS_SYS_OBSERVER_H */
...@@ -30,7 +30,9 @@ ...@@ -30,7 +30,9 @@
30 # include <dmalloc.h> 30 # include <dmalloc.h>
31 #endif 31 #endif
32 32
33 __MAILUTILS_BEGIN_DECLS 33 #ifdef __cplusplus
34 extern "C" {
35 #endif
34 36
35 enum pop3_state 37 enum pop3_state
36 { 38 {
...@@ -150,6 +152,8 @@ do \ ...@@ -150,6 +152,8 @@ do \
150 } \ 152 } \
151 while (0) 153 while (0)
152 154
153 __MAILUTILS_END_DECLS 155 #ifdef __cplusplus
156 }
157 #endif
154 158
155 #endif /* _MAILUTILS_SYS_POP3_H */ 159 #endif /* _MAILUTILS_SYS_POP3_H */
......
...@@ -18,10 +18,11 @@ ...@@ -18,10 +18,11 @@
18 #ifndef _MAILUTILS_SYS_STREAM_H 18 #ifndef _MAILUTILS_SYS_STREAM_H
19 #define _MAILUTILS_SYS_STREAM_H 19 #define _MAILUTILS_SYS_STREAM_H
20 20
21 #include <mailutils/base.h>
22 #include <mailutils/stream.h> 21 #include <mailutils/stream.h>
23 22
24 __MAILUTILS_BEGIN_DECLS 23 #ifdef __cplusplus
24 extern "C" {
25 #endif
25 26
26 struct _stream_vtable 27 struct _stream_vtable
27 { 28 {
...@@ -75,6 +76,8 @@ struct _stream ...@@ -75,6 +76,8 @@ struct _stream
75 #define stream_get_flags(s,f) ((s)->vtable->get_flags)(s,f) 76 #define stream_get_flags(s,f) ((s)->vtable->get_flags)(s,f)
76 #define stream_get_state(s,f) ((s)->vtable->get_state)(s,f) 77 #define stream_get_state(s,f) ((s)->vtable->get_state)(s,f)
77 78
78 __MAILUTILS_END_DECLS 79 #ifdef __cplusplus
80 }
81 #endif
79 82
80 #endif /* _MAILUTILS_SYS_STREAM_H */ 83 #endif /* _MAILUTILS_SYS_STREAM_H */
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #include <stdlib.h>
24
25 #include <mailutils/error.h>
26 #include <mailutils/sys/list.h>
27
28 /* Simple double (circular)link list. We rollup our own because we
29 need to be thread-safe. */
30
31 int
32 list_create (list_t *plist)
33 {
34 list_t list;
35 int status;
36 if (plist == NULL)
37 return EINVAL;
38 list = calloc (sizeof (*list), 1);
39 if (list == NULL)
40 return ENOMEM;
41 status = monitor_create (&(list->lock));
42 if (status != 0)
43 {
44 free (list);
45 return status;
46 }
47 list->head.next = &(list->head);
48 list->head.prev = &(list->head);
49 list->count = 0;
50 *plist = list;
51 return 0;
52 }
53
54 int
55 list_destroy (list_t list)
56 {
57 if (list)
58 {
59 struct list_data *current;
60 struct list_data *previous;
61 monitor_lock (list->lock);
62 for (current = list->head.next; current != &(list->head);)
63 {
64 previous = current;
65 current = current->next;
66 free (previous);
67 }
68 monitor_unlock (list->lock);
69 monitor_destroy (list->lock);
70 free (list);
71 }
72 return 0;
73 }
74
75 int
76 list_append (list_t list, void *item)
77 {
78 struct list_data *ldata;
79 struct list_data *last;
80 if (list == NULL)
81 return EINVAL;
82 last = list->head.prev;
83 ldata = calloc (sizeof (*ldata), 1);
84 if (ldata == NULL)
85 return ENOMEM;
86 ldata->item = item;
87 monitor_lock (list->lock);
88 ldata->next = &(list->head);
89 ldata->prev = list->head.prev;
90 last->next = ldata;
91 list->head.prev = ldata;
92 list->count++;
93 monitor_unlock (list->lock);
94 return 0;
95 }
96
97 int
98 list_prepend (list_t list, void *item)
99 {
100 struct list_data *ldata;
101 struct list_data *first;
102 if (list == NULL)
103 return EINVAL;
104 first = list->head.next;
105 ldata = calloc (sizeof (*ldata), 1);
106 if (ldata == NULL)
107 return ENOMEM;
108 ldata->item = item;
109 monitor_lock (list->lock);
110 ldata->prev = &(list->head);
111 ldata->next = list->head.next;
112 first->prev = ldata;
113 list->head.next = ldata;
114 list->count++;
115 monitor_unlock (list->lock);
116 return 0;
117 }
118
119 int
120 list_is_empty (list_t list)
121 {
122 size_t n = 0;
123 list_count (list, &n);
124 return (n == 0);
125 }
126
127 int
128 list_count (list_t list, size_t *pcount)
129 {
130 if (list == NULL || pcount == NULL)
131 return EINVAL;
132 *pcount = list->count;
133 return 0;
134 }
135
136 int
137 list_remove (list_t list, void *item)
138 {
139 struct list_data *current, *previous;
140 int status = ENOENT;
141 if (list == NULL)
142 return EINVAL;
143 monitor_lock (list->lock);
144 for (previous = &(list->head), current = list->head.next;
145 current != &(list->head); previous = current, current = current->next)
146 {
147 if ((int)current->item == (int)item)
148 {
149 previous->next = current->next;
150 current->next->prev = previous;
151 free (current);
152 list->count--;
153 status = 0;
154 break;
155 }
156 }
157 monitor_unlock (list->lock);
158 return ENOENT;
159 }
160
161 int
162 list_get (list_t list, size_t index, void **pitem)
163 {
164 struct list_data *current;
165 size_t count;
166 int status = ENOENT;
167 if (list == NULL || pitem == NULL)
168 return EINVAL;
169 monitor_lock (list->lock);
170 for (current = list->head.next, count = 0; current != &(list->head);
171 current = current->next, count++)
172 {
173 if (count == index)
174 {
175 *pitem = current->item;
176 status = 0;
177 break;
178 }
179 }
180 monitor_unlock (list->lock);
181 return status;
182 }
183
184 static int l_add_ref __P ((iterator_t));
185 static int l_release __P ((iterator_t));
186 static int l_destroy __P ((iterator_t));
187 static int l_first __P ((iterator_t));
188 static int l_next __P ((iterator_t));
189 static int l_current __P ((iterator_t, void *));
190 static int l_is_done __P ((iterator_t));
191
192 static struct _iterator_vtable l_i_vtable =
193 {
194 /* Base. */
195 l_add_ref,
196 l_release,
197 l_destroy,
198
199 l_first,
200 l_next,
201 l_current,
202 l_is_done
203 };
204
205 int
206 list_get_iterator (list_t list, iterator_t *piterator)
207 {
208 struct l_iterator *l_iterator;
209
210 if (list == NULL || piterator == NULL)
211 return MU_ERROR_INVALID_PARAMETER;
212
213 l_iterator = malloc (sizeof *l_iterator);
214 if (l_iterator == NULL)
215 return MU_ERROR_NO_MEMORY;
216
217 l_iterator->base.vtable = &l_i_vtable;
218 l_iterator->ref = 1;
219 l_iterator->list = list;
220 l_iterator->current = NULL;
221 monitor_create (&(l_iterator->lock));
222 *piterator = &l_iterator->base;
223 return 0;
224 }
225
226 static int
227 l_add_ref (iterator_t iterator)
228 {
229 int status = 0;
230 struct l_iterator *l_iterator = (struct l_iterator *)iterator;
231 if (l_iterator)
232 {
233 monitor_lock (l_iterator->lock);
234 status = ++l_iterator->ref;
235 monitor_unlock (l_iterator->lock);
236 }
237 return status;
238 }
239
240 static int
241 l_release (iterator_t iterator)
242 {
243 int status = 0;
244 struct l_iterator *l_iterator = (struct l_iterator *)iterator;
245 if (l_iterator)
246 {
247 monitor_lock (l_iterator->lock);
248 status = --l_iterator->ref;
249 if (status <= 0)
250 {
251 monitor_unlock (l_iterator->lock);
252 l_destroy (iterator);
253 return 0;
254 }
255 monitor_unlock (l_iterator->lock);
256 }
257 return status;
258 }
259
260 static int
261 l_destroy (iterator_t iterator)
262 {
263 struct l_iterator *l_iterator = (struct l_iterator *)iterator;
264 monitor_destroy (l_iterator->lock);
265 free (l_iterator);
266 return 0;
267 }
268
269 static int
270 l_first (iterator_t iterator)
271 {
272 struct l_iterator *l_iterator = (struct l_iterator *)iterator;
273 list_t list = l_iterator->list;
274 if (list)
275 {
276 monitor_lock (list->lock);
277 l_iterator->current = l_iterator->list->head.next;
278 monitor_unlock (list->lock);
279 }
280 return 0;
281 }
282
283 static int
284 l_next (iterator_t iterator)
285 {
286 struct l_iterator *l_iterator = (struct l_iterator *)iterator;
287 list_t list = l_iterator->list;
288 if (list)
289 {
290 if (l_iterator->current)
291 {
292 monitor_lock (list->lock);
293 l_iterator->current = l_iterator->current->next;
294 monitor_unlock (list->lock);
295 }
296 else
297 l_first (iterator);
298 }
299 return 0;
300 }
301
302 static int
303 l_is_done (iterator_t iterator)
304 {
305 struct l_iterator *l_iterator = (struct l_iterator *)iterator;
306 int done = 0;
307 list_t list = l_iterator->list;
308 if (list)
309 {
310 monitor_lock (list->lock);
311 done = (l_iterator->current == &(list->head));
312 monitor_unlock (list->lock);
313 }
314 return done;
315 }
316
317 static int
318 l_current (iterator_t iterator, void *item)
319 {
320 struct l_iterator *l_iterator = (struct l_iterator *)iterator;
321 list_t list = l_iterator->list;
322 if (list)
323 {
324 monitor_lock (list->lock);
325 if (l_iterator->current)
326 *((void **)item) = l_iterator->current->item;
327 else
328 *((void **)item) = NULL;
329 monitor_unlock (list->lock);
330 }
331 return 0;
332 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #include <stdlib.h>
24 #include <mailutils/iterator.h>
25 #include <mailutils/error.h>
26 #include <mailutils/sys/observer.h>
27
28 struct observer_info
29 {
30 int type;
31 observer_t observer;
32 };
33
34 int
35 observable_create (observable_t *pobservable)
36 {
37 observable_t observable;
38 int status;
39 if (pobservable == NULL)
40 return MU_ERROR_INVALID_PARAMETER;
41 observable = calloc (sizeof (*observable), 1);
42 if (observable == NULL)
43 return MU_ERROR_NO_MEMORY;
44 status = list_create (&(observable->list));
45 if (status != 0 )
46 {
47 free (observable);
48 return status;
49 }
50 *pobservable = observable;
51 return 0;
52 }
53
54 int
55 observable_release (observable_t observable)
56 {
57 (void)observable;
58 return 1;
59 }
60
61 int
62 observable_destroy (observable_t observable)
63 {
64 if (observable)
65 {
66 iterator_t iterator = NULL;
67 int status = list_get_iterator (observable->list, &iterator);
68 if (status == 0)
69 {
70 struct observer_info *info;
71 for (iterator_first (iterator); !iterator_is_done (iterator);
72 iterator_next (iterator))
73 {
74 info = NULL;
75 iterator_current (iterator, (void **)&info);
76 if (info)
77 {
78 observer_release (info->observer);
79 free (info);
80 }
81 }
82 iterator_release (iterator);
83 }
84 list_destroy (observable->list);
85 free (observable);
86 }
87 return 0;
88 }
89
90 int
91 observable_attach (observable_t observable, int type, observer_t observer)
92 {
93 struct observer_info *info;
94 if (observable == NULL || observer == NULL)
95 return MU_ERROR_INVALID_PARAMETER;
96 info = calloc (1, sizeof *info);
97 if (info == NULL)
98 return MU_ERROR_NO_MEMORY;
99 info->type = type;
100 info->observer = observer;
101 return list_append (observable->list, info);
102 }
103
104 int
105 observable_detach (observable_t observable, observer_t observer)
106 {
107 iterator_t iterator = NULL;
108 int status;
109 int found = 0;
110 struct observer_info *info;
111 if (observable == NULL ||observer == NULL)
112 return EINVAL;
113 status = list_get_iterator (observable->list, &iterator);
114 if (status != 0)
115 return status;
116 for (iterator_first (iterator); !iterator_is_done (iterator);
117 iterator_next (iterator))
118 {
119 info = NULL;
120 iterator_current (iterator, (void **)&info);
121 if (info && (int)(info->observer) == (int)observer)
122 {
123 found = 1;
124 break;
125 }
126 }
127 iterator_release (iterator);
128 if (found)
129 {
130 status = list_remove (observable->list, info);
131 free (info);
132 }
133 return status;
134 }
135
136 int
137 observable_notify_all (observable_t observable, struct event evt)
138 {
139 iterator_t iterator;
140 struct observer_info *info;
141 int status = 0;
142
143 if (observable == NULL)
144 return MU_ERROR_INVALID_PARAMETER;
145 status = list_get_iterator (observable->list, &iterator);
146 if (status != 0)
147 return status;
148 for (iterator_first (iterator); !iterator_is_done (iterator);
149 iterator_next (iterator))
150 {
151 info = NULL;
152 iterator_current (iterator, (void **)&info);
153 if (info && info->type & evt.type)
154 {
155 status |= observer_action (info->observer, evt);
156 }
157 }
158 iterator_release (iterator);
159 return status;
160 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 General Library 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 #include <stdlib.h>
24 #include <mailutils/error.h>
25 #include <mailutils/sys/observer.h>
26
27 int
28 (observer_add_ref) (observer_t observer)
29 {
30 if (observer == NULL || observer->vtable == NULL
31 || observer->vtable->add_ref == NULL)
32 return MU_ERROR_NOT_SUPPORTED;
33 return observer->vtable->add_ref (observer);
34 }
35
36 int
37 (observer_release) (observer_t observer)
38 {
39 if (observer == NULL || observer->vtable == NULL
40 || observer->vtable->release == NULL)
41 return MU_ERROR_NOT_SUPPORTED;
42 return observer->vtable->release (observer);
43 }
44
45 int
46 (observer_destroy) (observer_t observer)
47 {
48 if (observer == NULL || observer->vtable == NULL
49 || observer->vtable->destroy == NULL)
50 return MU_ERROR_NOT_SUPPORTED;
51 return observer->vtable->destroy (observer);
52 }
53
54 int
55 (observer_action) (observer_t observer, struct event evt)
56 {
57 if (observer == NULL || observer->vtable == NULL
58 || observer->vtable->action == NULL)
59 return MU_ERROR_NOT_SUPPORTED;
60 return observer->vtable->action (observer, evt);
61 }
62
63
64
65 static int
66 _dobserver_add_ref (observer_t observer)
67 {
68 struct _dobserver *dobserver = (struct _dobserver *)observer;
69 int status;
70 monitor_lock (dobserver->lock);
71 status = ++dobserver->ref;
72 monitor_unlock (dobserver->lock);
73 return status;
74 }
75
76 static int
77 _dobserver_destroy (observer_t observer)
78 {
79 struct _dobserver *dobserver = (struct _dobserver *)observer;
80 monitor_destroy (dobserver->lock);
81 free (dobserver);
82 return 0;
83 }
84
85 static int
86 _dobserver_release (observer_t observer)
87 {
88 int status;
89 struct _dobserver *dobserver = (struct _dobserver *)observer;
90 monitor_lock (dobserver->lock);
91 status = --dobserver->ref;
92 if (status <= 0)
93 {
94 monitor_unlock (dobserver->lock);
95 return _dobserver_destroy (observer);
96 }
97 monitor_unlock (dobserver->lock);
98 return status;
99 }
100
101 static int
102 _dobserver_action (observer_t observer, struct event evt)
103 {
104 struct _dobserver *dobserver = (struct _dobserver *)observer;
105 if (dobserver->action)
106 return dobserver->action (dobserver->arg, evt);
107 return 0;
108 }
109
110 static struct _observer_vtable _dobserver_vtable =
111 {
112 _dobserver_add_ref,
113 _dobserver_release,
114 _dobserver_destroy,
115
116 _dobserver_action
117 };
118
119 /* Implement a default observer. */
120 int
121 observer_create (observer_t *pobserver,
122 int (*action) (void *arg, struct event), void *arg)
123 {
124 struct _dobserver * dobserver;
125
126 if (pobserver)
127 return MU_ERROR_INVALID_PARAMETER;
128
129 dobserver = calloc (1, sizeof *dobserver);
130 if (dobserver)
131 return MU_ERROR_NO_MEMORY;
132
133 dobserver->base.vtable = &_dobserver_vtable;
134 dobserver->ref = 1;
135 dobserver->arg = arg;
136 dobserver->action = action;
137 monitor_create (&(dobserver->lock));
138 *pobserver = &dobserver->base;
139 return 0;
140 }