attribute.c attribute.h auth.h event.h header.c header.h io.c
io.h io0.h locker.c mbx_unix.c message.c message.h message0.h registrar.c registrar.h url_pop.c Typos and after a long debate merge istream_t/ostream_t to stream_t better fit to the net_t object comming.
Showing
17 changed files
with
423 additions
and
351 deletions
... | @@ -19,6 +19,7 @@ | ... | @@ -19,6 +19,7 @@ |
19 | 19 | ||
20 | #include <sys/types.h> | 20 | #include <sys/types.h> |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <string.h> | ||
22 | #include <errno.h> | 23 | #include <errno.h> |
23 | 24 | ||
24 | #define MU_ATTRIBUTE_SEEN ((int)1) | 25 | #define MU_ATTRIBUTE_SEEN ((int)1) |
... | @@ -33,14 +34,13 @@ struct _attribute | ... | @@ -33,14 +34,13 @@ struct _attribute |
33 | { | 34 | { |
34 | size_t flag; | 35 | size_t flag; |
35 | void *owner; | 36 | void *owner; |
36 | int ref_count; | ||
37 | }; | 37 | }; |
38 | 38 | ||
39 | int | 39 | int |
40 | attribute_init (attribute_t *pattr, void *owner) | 40 | attribute_init (attribute_t *pattr, void *owner) |
41 | { | 41 | { |
42 | attribute_t attr; | 42 | attribute_t attr; |
43 | if (pattr == NULL) | 43 | if (pattr == NULL || owner == NULL) |
44 | return EINVAL; | 44 | return EINVAL; |
45 | attr = calloc (1, sizeof(*attr)); | 45 | attr = calloc (1, sizeof(*attr)); |
46 | if (attr == NULL) | 46 | if (attr == NULL) |
... | @@ -57,12 +57,8 @@ attribute_destroy (attribute_t *pattr, void *owner) | ... | @@ -57,12 +57,8 @@ attribute_destroy (attribute_t *pattr, void *owner) |
57 | { | 57 | { |
58 | attribute_t attr = *pattr; | 58 | attribute_t attr = *pattr; |
59 | 59 | ||
60 | attr->ref_count--; | 60 | if (attr->owner == owner) |
61 | if ((attr->owner && attr->owner == owner) || | 61 | free (attr); |
62 | (attr->owner == NULL && attr->ref_count <= 0)) | ||
63 | { | ||
64 | free (attr); | ||
65 | } | ||
66 | /* loose the link */ | 62 | /* loose the link */ |
67 | *pattr = NULL; | 63 | *pattr = NULL; |
68 | } | 64 | } |
... | @@ -70,66 +66,94 @@ attribute_destroy (attribute_t *pattr, void *owner) | ... | @@ -70,66 +66,94 @@ attribute_destroy (attribute_t *pattr, void *owner) |
70 | } | 66 | } |
71 | 67 | ||
72 | int | 68 | int |
73 | attribute_set_seen (attribute_t attr) | 69 | attribute_set_seen (attribute_t attr, void *owner) |
74 | { | 70 | { |
75 | if (attr == NULL) | 71 | if (attr == NULL) |
76 | return EINVAL; | 72 | return EINVAL; |
77 | attr->flag |= MU_ATTRIBUTE_SEEN; | 73 | if (owner == attr->owner) |
78 | return 0; | 74 | { |
75 | attr->flag |= MU_ATTRIBUTE_SEEN; | ||
76 | return 0; | ||
77 | } | ||
78 | return EACCES; | ||
79 | } | 79 | } |
80 | 80 | ||
81 | int | 81 | int |
82 | attribute_set_answered (attribute_t attr) | 82 | attribute_set_answered (attribute_t attr, void *owner) |
83 | { | 83 | { |
84 | if (attr == NULL) | 84 | if (attr == NULL) |
85 | return EINVAL; | 85 | return EINVAL; |
86 | attr->flag |= MU_ATTRIBUTE_ANSWERED; | 86 | if (owner == attr->owner) |
87 | return 0; | 87 | { |
88 | attr->flag |= MU_ATTRIBUTE_ANSWERED; | ||
89 | return 0; | ||
90 | } | ||
91 | return EACCES; | ||
88 | } | 92 | } |
89 | 93 | ||
90 | int | 94 | int |
91 | attribute_set_flagged (attribute_t attr) | 95 | attribute_set_flagged (attribute_t attr, void *owner) |
92 | { | 96 | { |
93 | if (attr == NULL) | 97 | if (attr == NULL) |
94 | return EINVAL; | 98 | return EINVAL; |
95 | attr->flag |= MU_ATTRIBUTE_FLAGGED; | 99 | if (owner == attr->owner) |
96 | return 0; | 100 | { |
101 | attr->flag |= MU_ATTRIBUTE_FLAGGED; | ||
102 | return 0; | ||
103 | } | ||
104 | return EACCES; | ||
97 | } | 105 | } |
98 | 106 | ||
99 | int | 107 | int |
100 | attribute_set_read (attribute_t attr) | 108 | attribute_set_read (attribute_t attr, void *owner) |
101 | { | 109 | { |
102 | if (attr == NULL) | 110 | if (attr == NULL) |
103 | return EINVAL; | 111 | return EINVAL; |
104 | attr->flag |= MU_ATTRIBUTE_READ; | 112 | if (owner == attr->owner) |
105 | return 0; | 113 | { |
114 | attr->flag |= MU_ATTRIBUTE_READ; | ||
115 | return 0; | ||
116 | } | ||
117 | return EACCES; | ||
106 | } | 118 | } |
107 | 119 | ||
108 | int | 120 | int |
109 | attribute_set_deleted (attribute_t attr) | 121 | attribute_set_deleted (attribute_t attr, void *owner) |
110 | { | 122 | { |
111 | if (attr == NULL) | 123 | if (attr == NULL) |
112 | return EINVAL; | 124 | return EINVAL; |
113 | attr->flag |= MU_ATTRIBUTE_DELETED; | 125 | if (owner == attr->owner) |
114 | return 0; | 126 | { |
127 | attr->flag |= MU_ATTRIBUTE_DELETED; | ||
128 | return 0; | ||
129 | } | ||
130 | return EACCES; | ||
115 | } | 131 | } |
116 | 132 | ||
117 | int | 133 | int |
118 | attribute_set_draft (attribute_t attr) | 134 | attribute_set_draft (attribute_t attr, void *owner) |
119 | { | 135 | { |
120 | if (attr == NULL) | 136 | if (attr == NULL) |
121 | return EINVAL; | 137 | return EINVAL; |
122 | attr->flag |= MU_ATTRIBUTE_DRAFT; | 138 | if (owner == attr->owner) |
123 | return 0; | 139 | { |
140 | attr->flag |= MU_ATTRIBUTE_DRAFT; | ||
141 | return 0; | ||
142 | } | ||
143 | return EACCES; | ||
124 | } | 144 | } |
125 | 145 | ||
126 | int | 146 | int |
127 | attribute_set_recent (attribute_t attr) | 147 | attribute_set_recent (attribute_t attr, void *owner) |
128 | { | 148 | { |
129 | if (attr == NULL) | 149 | if (attr == NULL) |
130 | return EINVAL; | 150 | return EINVAL; |
131 | attr->flag |= MU_ATTRIBUTE_RECENT; | 151 | if (attr == NULL) |
132 | return 0; | 152 | { |
153 | attr->flag |= MU_ATTRIBUTE_RECENT; | ||
154 | return 0; | ||
155 | } | ||
156 | return EACCES; | ||
133 | } | 157 | } |
134 | 158 | ||
135 | int | 159 | int |
... | @@ -189,66 +213,94 @@ attribute_is_recent (attribute_t attr) | ... | @@ -189,66 +213,94 @@ attribute_is_recent (attribute_t attr) |
189 | } | 213 | } |
190 | 214 | ||
191 | int | 215 | int |
192 | attribute_unset_seen (attribute_t attr) | 216 | attribute_unset_seen (attribute_t attr, void *owner) |
193 | { | 217 | { |
194 | if (attr == NULL) | 218 | if (attr == NULL) |
195 | return 0; | 219 | return 0; |
196 | attr->flag &= ~MU_ATTRIBUTE_SEEN; | 220 | if (owner == attr->owner) |
197 | return 0; | 221 | { |
222 | attr->flag &= ~MU_ATTRIBUTE_SEEN; | ||
223 | return 0; | ||
224 | } | ||
225 | return EACCES; | ||
198 | } | 226 | } |
199 | 227 | ||
200 | int | 228 | int |
201 | attribute_unset_answered (attribute_t attr) | 229 | attribute_unset_answered (attribute_t attr, void *owner) |
202 | { | 230 | { |
203 | if (attr == NULL) | 231 | if (attr == NULL) |
204 | return 0; | 232 | return 0; |
205 | attr->flag &= ~MU_ATTRIBUTE_ANSWERED; | 233 | if (owner == attr->owner) |
206 | return 0; | 234 | { |
235 | attr->flag &= ~MU_ATTRIBUTE_ANSWERED; | ||
236 | return 0; | ||
237 | } | ||
238 | return EACCES; | ||
207 | } | 239 | } |
208 | 240 | ||
209 | int | 241 | int |
210 | attribute_unset_flagged (attribute_t attr) | 242 | attribute_unset_flagged (attribute_t attr, void *owner) |
211 | { | 243 | { |
212 | if (attr == NULL) | 244 | if (attr == NULL) |
213 | return 0; | 245 | return 0; |
214 | attr->flag &= ~MU_ATTRIBUTE_FLAGGED; | 246 | if (owner == attr->owner) |
215 | return 0; | 247 | { |
248 | attr->flag &= ~MU_ATTRIBUTE_FLAGGED; | ||
249 | return 0; | ||
250 | } | ||
251 | return EACCES; | ||
216 | } | 252 | } |
217 | 253 | ||
218 | int | 254 | int |
219 | attribute_unset_read (attribute_t attr) | 255 | attribute_unset_read (attribute_t attr, void *owner) |
220 | { | 256 | { |
221 | if (attr == NULL) | 257 | if (attr == NULL) |
222 | return 0; | 258 | return 0; |
223 | attr->flag &= ~MU_ATTRIBUTE_READ; | 259 | if (owner == attr->owner) |
224 | return 0; | 260 | { |
261 | attr->flag &= ~MU_ATTRIBUTE_READ; | ||
262 | return 0; | ||
263 | } | ||
264 | return EACCES; | ||
225 | } | 265 | } |
226 | 266 | ||
227 | int | 267 | int |
228 | attribute_unset_deleted (attribute_t attr) | 268 | attribute_unset_deleted (attribute_t attr, void *owner) |
229 | { | 269 | { |
230 | if (attr == NULL) | 270 | if (attr == NULL) |
231 | return 0; | 271 | return 0; |
232 | attr->flag &= ~MU_ATTRIBUTE_DELETED; | 272 | if (owner == attr->owner) |
233 | return 0; | 273 | { |
274 | attr->flag &= ~MU_ATTRIBUTE_DELETED; | ||
275 | return 0; | ||
276 | } | ||
277 | return EACCES; | ||
234 | } | 278 | } |
235 | 279 | ||
236 | int | 280 | int |
237 | attribute_unset_draft (attribute_t attr) | 281 | attribute_unset_draft (attribute_t attr, void *owner) |
238 | { | 282 | { |
239 | if (attr == NULL) | 283 | if (attr == NULL) |
240 | return 0; | 284 | return 0; |
241 | attr->flag &= ~MU_ATTRIBUTE_DRAFT; | 285 | if (owner == attr->owner) |
242 | return 0; | 286 | { |
287 | attr->flag &= ~MU_ATTRIBUTE_DRAFT; | ||
288 | return 0; | ||
289 | } | ||
290 | return EACCES; | ||
243 | } | 291 | } |
244 | 292 | ||
245 | int | 293 | int |
246 | attribute_unset_recent (attribute_t attr) | 294 | attribute_unset_recent (attribute_t attr, void *owner) |
247 | { | 295 | { |
248 | if (attr == NULL) | 296 | if (attr == NULL) |
249 | return 0; | 297 | return 0; |
250 | attr->flag &= ~MU_ATTRIBUTE_RECENT; | 298 | if (owner == attr->owner) |
251 | return 0; | 299 | { |
300 | attr->flag &= ~MU_ATTRIBUTE_RECENT; | ||
301 | return 0; | ||
302 | } | ||
303 | return EACCES; | ||
252 | } | 304 | } |
253 | 305 | ||
254 | int | 306 | int |
... | @@ -260,20 +312,42 @@ attribute_is_equal (attribute_t attr, attribute_t attr2) | ... | @@ -260,20 +312,42 @@ attribute_is_equal (attribute_t attr, attribute_t attr2) |
260 | } | 312 | } |
261 | 313 | ||
262 | int | 314 | int |
263 | attribute_copy (attribute_t dest, attribute_t src) | 315 | attribute_copy (attribute_t dest, attribute_t src, void *dest_owner) |
264 | { | 316 | { |
265 | if (dest == NULL || src == NULL) | 317 | if (dest == NULL || src == NULL) |
266 | return EINVAL; | 318 | return EINVAL; |
267 | memcpy (dest, src, sizeof (*dest)); | 319 | if (dest->owner == dest_owner) |
268 | return 0; | 320 | { |
321 | memcpy (dest, src, sizeof (*dest)); | ||
322 | return 0; | ||
323 | } | ||
324 | return EACCES; | ||
269 | } | 325 | } |
270 | 326 | ||
271 | int | 327 | int |
272 | attribute_get_owner (attribute_t attr, void **powner) | 328 | string_to_attribute (const char *buffer, size_t len, |
329 | attribute_t *pattr, void *owner) | ||
273 | { | 330 | { |
274 | if (attr == NULL) | 331 | char *sep; |
275 | return EINVAL; | 332 | int status; |
276 | if (powner) | 333 | |
277 | *powner = attr->owner; | 334 | status = attribute_init (pattr, owner); |
335 | if (status != 0) | ||
336 | return status; | ||
337 | |||
338 | /* Set the attribute */ | ||
339 | if (len > 7 && strncasecmp (buffer, "Status:", 7) == 0) | ||
340 | { | ||
341 | sep = strchr(buffer, ':'); /* pass the ':' */ | ||
342 | if (strchr (sep, 'R') != NULL || strchr (sep, 'r') != NULL) | ||
343 | attribute_set_read (*pattr, owner); | ||
344 | if (strchr (sep, 'O') != NULL || strchr (sep, 'o') != NULL) | ||
345 | attribute_set_seen (*pattr, owner); | ||
346 | if (strchr (sep, 'A') != NULL || strchr (sep, 'a') != NULL) | ||
347 | attribute_set_answered (*pattr, owner); | ||
348 | if (strchr (sep, 'F') != NULL || strchr (sep, 'f') != NULL) | ||
349 | attribute_set_flagged (*pattr, owner); | ||
350 | } | ||
278 | return 0; | 351 | return 0; |
279 | } | 352 | } |
353 | ... | ... |
... | @@ -18,6 +18,8 @@ | ... | @@ -18,6 +18,8 @@ |
18 | #ifndef _ATTRIBUTE_H | 18 | #ifndef _ATTRIBUTE_H |
19 | #define _ATTRIBUTE_H | 19 | #define _ATTRIBUTE_H |
20 | 20 | ||
21 | #include <sys/types.h> | ||
22 | |||
21 | #ifdef __cplusplus | 23 | #ifdef __cplusplus |
22 | extern "C" { | 24 | extern "C" { |
23 | #endif | 25 | #endif |
... | @@ -44,25 +46,29 @@ extern int attribute_is_draft __P ((attribute_t)); | ... | @@ -44,25 +46,29 @@ extern int attribute_is_draft __P ((attribute_t)); |
44 | extern int attribute_is_recent __P ((attribute_t)); | 46 | extern int attribute_is_recent __P ((attribute_t)); |
45 | extern int attribute_is_read __P ((attribute_t)); | 47 | extern int attribute_is_read __P ((attribute_t)); |
46 | 48 | ||
47 | extern int attribute_set_seen __P ((attribute_t)); | 49 | extern int attribute_set_seen __P ((attribute_t, void *owner)); |
48 | extern int attribute_set_answered __P ((attribute_t)); | 50 | extern int attribute_set_answered __P ((attribute_t, void *owner)); |
49 | extern int attribute_set_flagged __P ((attribute_t)); | 51 | extern int attribute_set_flagged __P ((attribute_t, void *owner)); |
50 | extern int attribute_set_deleted __P ((attribute_t)); | 52 | extern int attribute_set_deleted __P ((attribute_t, void *owner)); |
51 | extern int attribute_set_draft __P ((attribute_t)); | 53 | extern int attribute_set_draft __P ((attribute_t, void *owner)); |
52 | extern int attribute_set_recent __P ((attribute_t)); | 54 | extern int attribute_set_recent __P ((attribute_t, void *owner)); |
53 | extern int attribute_set_read __P ((attribute_t)); | 55 | extern int attribute_set_read __P ((attribute_t, void *owner)); |
54 | 56 | ||
55 | extern int attribute_unset_seen __P ((attribute_t)); | 57 | extern int attribute_unset_seen __P ((attribute_t, void *owner)); |
56 | extern int attribute_unset_answered __P ((attribute_t)); | 58 | extern int attribute_unset_answered __P ((attribute_t, void *owner)); |
57 | extern int attribute_unset_flagged __P ((attribute_t)); | 59 | extern int attribute_unset_flagged __P ((attribute_t, void *owner)); |
58 | extern int attribute_unset_deleted __P ((attribute_t)); | 60 | extern int attribute_unset_deleted __P ((attribute_t, void *owner)); |
59 | extern int attribute_unset_draft __P ((attribute_t)); | 61 | extern int attribute_unset_draft __P ((attribute_t, void *owner)); |
60 | extern int attribute_unset_recent __P ((attribute_t)); | 62 | extern int attribute_unset_recent __P ((attribute_t, void *owner)); |
61 | extern int attribute_unset_read __P ((attribute_t)); | 63 | extern int attribute_unset_read __P ((attribute_t, void *owner)); |
62 | 64 | ||
63 | extern int attribute_is_equal __P ((attribute_t att1, attribute_t att2)); | 65 | extern int attribute_is_equal __P ((attribute_t att1, attribute_t att2)); |
64 | 66 | ||
65 | extern int attribute_copy __P ((attribute_t dst, attribute_t src)); | 67 | extern int attribute_copy __P ((attribute_t dst, |
68 | attribute_t src, void *dest_owner)); | ||
69 | |||
70 | extern int string_to_attribute __P ((const char *buf, size_t len, | ||
71 | attribute_t *pattr, void *owner)); | ||
66 | extern int attribute_get_owner __P ((attribute_t attr, void **owner)); | 72 | extern int attribute_get_owner __P ((attribute_t attr, void **owner)); |
67 | #ifdef __cplusplus | 73 | #ifdef __cplusplus |
68 | } | 74 | } | ... | ... |
... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
28 | #endif | 28 | #endif |
29 | #endif /*__P */ | 29 | #endif /*__P */ |
30 | 30 | ||
31 | #ifdef _cpluscplus | 31 | #ifdef _cplusplus |
32 | extern "C" { | 32 | extern "C" { |
33 | #endif | 33 | #endif |
34 | 34 | ||
... | @@ -54,7 +54,7 @@ extern int auth_set_epilogue __P ((auth_t auth, | ... | @@ -54,7 +54,7 @@ extern int auth_set_epilogue __P ((auth_t auth, |
54 | int (*_epilogue) __P ((auth_t)), | 54 | int (*_epilogue) __P ((auth_t)), |
55 | void *owner)); | 55 | void *owner)); |
56 | 56 | ||
57 | #ifdef _cpluscplus | 57 | #ifdef _cplusplus |
58 | } | 58 | } |
59 | #endif | 59 | #endif |
60 | 60 | ... | ... |
... | @@ -26,7 +26,7 @@ | ... | @@ -26,7 +26,7 @@ |
26 | # endif | 26 | # endif |
27 | #endif /* __P */ | 27 | #endif /* __P */ |
28 | 28 | ||
29 | #ifdef _cpluscplus | 29 | #ifdef _cplusplus |
30 | extern "C" { | 30 | extern "C" { |
31 | #endif | 31 | #endif |
32 | 32 | ||
... | @@ -38,7 +38,7 @@ struct _event | ... | @@ -38,7 +38,7 @@ struct _event |
38 | }; | 38 | }; |
39 | typedef struct _event *event_t; | 39 | typedef struct _event *event_t; |
40 | 40 | ||
41 | #ifdef _cpluscplus | 41 | #ifdef _cplusplus |
42 | } | 42 | } |
43 | #endif | 43 | #endif |
44 | 44 | ... | ... |
... | @@ -27,9 +27,9 @@ | ... | @@ -27,9 +27,9 @@ |
27 | #include <errno.h> | 27 | #include <errno.h> |
28 | 28 | ||
29 | static int header_parse (header_t h, char *blurb, int len); | 29 | static int header_parse (header_t h, char *blurb, int len); |
30 | static int header_read (istream_t is, char *buf, size_t buflen, | 30 | static int header_read (stream_t is, char *buf, size_t buflen, |
31 | off_t off, size_t *pnread); | 31 | off_t off, size_t *pnread); |
32 | static int header_write (ostream_t os, const char *buf, size_t buflen, | 32 | static int header_write (stream_t os, const char *buf, size_t buflen, |
33 | off_t off, size_t *pnwrite); | 33 | off_t off, size_t *pnwrite); |
34 | 34 | ||
35 | struct _hdr | 35 | struct _hdr |
... | @@ -49,8 +49,7 @@ struct _header | ... | @@ -49,8 +49,7 @@ struct _header |
49 | struct _hdr *hdr; | 49 | struct _hdr *hdr; |
50 | 50 | ||
51 | /* streams */ | 51 | /* streams */ |
52 | istream_t is; | 52 | stream_t stream; |
53 | ostream_t os; | ||
54 | 53 | ||
55 | /* owner ? */ | 54 | /* owner ? */ |
56 | void *owner; | 55 | void *owner; |
... | @@ -74,13 +73,12 @@ header_init (header_t *ph, const char *blurb, size_t len, void *owner) | ... | @@ -74,13 +73,12 @@ header_init (header_t *ph, const char *blurb, size_t len, void *owner) |
74 | return status; | 73 | return status; |
75 | } | 74 | } |
76 | 75 | ||
77 | status = istream_init (&(h->is), header_read, h); | 76 | status = stream_init (&(h->stream), h); |
78 | if (status != 0) | 77 | if (status != 0) |
79 | return status; | 78 | return status; |
80 | 79 | ||
81 | status = ostream_init (&(h->os), header_write, h); | 80 | stream_set_read (h->stream, header_read, h); |
82 | if (status != 0) | 81 | stream_set_write (h->stream, header_write, h); |
83 | return status; | ||
84 | 82 | ||
85 | *ph = h; | 83 | *ph = h; |
86 | return status; | 84 | return status; |
... | @@ -101,8 +99,7 @@ header_destroy (header_t *ph, void *owner) | ... | @@ -101,8 +99,7 @@ header_destroy (header_t *ph, void *owner) |
101 | (h->owner == NULL && h->ref_count <= 0)) | 99 | (h->owner == NULL && h->ref_count <= 0)) |
102 | { | 100 | { |
103 | /* io */ | 101 | /* io */ |
104 | istream_destroy (&(h->is), h); | 102 | stream_destroy (&(h->stream), h); |
105 | ostream_destroy (&(h->os), h); | ||
106 | 103 | ||
107 | free (h->hdr); | 104 | free (h->hdr); |
108 | free (h->blurb); | 105 | free (h->blurb); |
... | @@ -308,7 +305,7 @@ header_entry_count (header_t header, size_t *pnum) | ... | @@ -308,7 +305,7 @@ header_entry_count (header_t header, size_t *pnum) |
308 | } | 305 | } |
309 | 306 | ||
310 | int | 307 | int |
311 | header_size (header_t header, size_t *pnum) | 308 | header_get_size (header_t header, size_t *pnum) |
312 | { | 309 | { |
313 | if (header == NULL) | 310 | if (header == NULL) |
314 | return EINVAL; | 311 | return EINVAL; |
... | @@ -364,7 +361,7 @@ header_entry_value (header_t header, size_t num, char *buf, | ... | @@ -364,7 +361,7 @@ header_entry_value (header_t header, size_t num, char *buf, |
364 | } | 361 | } |
365 | 362 | ||
366 | static int | 363 | static int |
367 | header_write (ostream_t os, const char *buf, size_t buflen, | 364 | header_write (stream_t os, const char *buf, size_t buflen, |
368 | off_t off, size_t *pnwrite) | 365 | off_t off, size_t *pnwrite) |
369 | { | 366 | { |
370 | header_t header; | 367 | header_t header; |
... | @@ -382,7 +379,7 @@ header_write (ostream_t os, const char *buf, size_t buflen, | ... | @@ -382,7 +379,7 @@ header_write (ostream_t os, const char *buf, size_t buflen, |
382 | } | 379 | } |
383 | 380 | ||
384 | static int | 381 | static int |
385 | header_read (istream_t is, char *buf, size_t buflen, | 382 | header_read (stream_t is, char *buf, size_t buflen, |
386 | off_t off, size_t *pnread) | 383 | off_t off, size_t *pnread) |
387 | { | 384 | { |
388 | header_t header; | 385 | header_t header; |
... | @@ -409,19 +406,10 @@ header_read (istream_t is, char *buf, size_t buflen, | ... | @@ -409,19 +406,10 @@ header_read (istream_t is, char *buf, size_t buflen, |
409 | } | 406 | } |
410 | 407 | ||
411 | int | 408 | int |
412 | header_get_istream (header_t header, istream_t *pis) | 409 | header_get_stream (header_t header, stream_t *pstream) |
413 | { | 410 | { |
414 | if (header == NULL || pis == NULL) | 411 | if (header == NULL || pstream == NULL) |
415 | return EINVAL; | 412 | return EINVAL; |
416 | *pis = header->is; | 413 | *pstream = header->stream; |
417 | return 0; | 414 | return 0; |
418 | } | 415 | } |
419 | |||
420 | int | ||
421 | rfc822_get_ostream (header_t header, ostream_t *pos) | ||
422 | { | ||
423 | if (header == NULL || pos == NULL) | ||
424 | return EINVAL; | ||
425 | *pos = header->os; | ||
426 | return ENOSYS; | ||
427 | } | ... | ... |
... | @@ -29,7 +29,7 @@ | ... | @@ -29,7 +29,7 @@ |
29 | #endif | 29 | #endif |
30 | #endif /*__P */ | 30 | #endif /*__P */ |
31 | 31 | ||
32 | #ifdef _cpluscplus | 32 | #ifdef _cplusplus |
33 | extern "C" { | 33 | extern "C" { |
34 | #endif | 34 | #endif |
35 | 35 | ||
... | @@ -79,10 +79,10 @@ extern int header_entry_name __P ((header_t, size_t num, char *buf, | ... | @@ -79,10 +79,10 @@ extern int header_entry_name __P ((header_t, size_t num, char *buf, |
79 | size_t buflen, size_t *total)); | 79 | size_t buflen, size_t *total)); |
80 | extern int header_entry_value __P ((header_t, size_t num, char *buf, | 80 | extern int header_entry_value __P ((header_t, size_t num, char *buf, |
81 | size_t buflen, size_t *total)); | 81 | size_t buflen, size_t *total)); |
82 | extern int header_get_istream __P ((header_t, istream_t *pis)); | 82 | extern int header_get_stream __P ((header_t, stream_t *stream)); |
83 | extern int header_get_ostream __P ((header_t, ostream_t *pos)); | ||
84 | extern int header_get_size __P ((header_t, size_t *size)); | 83 | extern int header_get_size __P ((header_t, size_t *size)); |
85 | #ifdef _cpluscplus | 84 | |
85 | #ifdef _cplusplus | ||
86 | } | 86 | } |
87 | #endif | 87 | #endif |
88 | 88 | ... | ... |
... | @@ -22,70 +22,77 @@ | ... | @@ -22,70 +22,77 @@ |
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | 23 | ||
24 | int | 24 | int |
25 | istream_init (istream_t *pis, int (*_read) | 25 | stream_init (stream_t *pstream, void *owner) |
26 | __P ((istream_t, char *, size_t, off_t, size_t *)), | ||
27 | void *owner) | ||
28 | { | 26 | { |
29 | istream_t is; | 27 | stream_t stream; |
30 | if (pis == NULL) | 28 | if (pstream == NULL || owner == NULL) |
31 | return EINVAL; | 29 | return EINVAL; |
32 | is = calloc (1, sizeof (*is)); | 30 | stream = calloc (1, sizeof (*stream)); |
33 | if (is == NULL) | 31 | if (stream == NULL) |
34 | return ENOMEM; | 32 | return ENOMEM; |
35 | is->owner = owner; | 33 | stream->owner = owner; |
36 | is->_read = _read; | 34 | *pstream = stream; |
37 | *pis = is; | ||
38 | return 0; | 35 | return 0; |
39 | } | 36 | } |
40 | 37 | ||
38 | void | ||
39 | stream_destroy (stream_t *pstream, void *owner) | ||
40 | { | ||
41 | if (pstream && *pstream) | ||
42 | { | ||
43 | stream_t stream = *pstream; | ||
44 | if (stream->owner == owner) | ||
45 | free (stream); | ||
46 | *pstream = NULL; | ||
47 | } | ||
48 | } | ||
49 | |||
41 | int | 50 | int |
42 | ostream_init (ostream_t *pos, int (*_write) | 51 | stream_set_fd (stream_t stream, int (*_get_fd) (stream_t, int *), void *owner) |
43 | __P ((ostream_t, const char *, size_t, off_t, size_t *)), | ||
44 | void *owner) | ||
45 | { | 52 | { |
46 | ostream_t os; | 53 | if (stream == NULL) |
47 | if (pos == NULL) | ||
48 | return EINVAL; | 54 | return EINVAL; |
49 | os = calloc (1, sizeof (*os)); | 55 | if (owner == stream->owner) |
50 | if (os == NULL) | 56 | { |
51 | return ENOMEM; | 57 | stream->_get_fd = _get_fd; |
52 | os->owner = owner; | 58 | return 0; |
53 | os->_write = _write; | 59 | } |
54 | *pos = os; | 60 | return EACCES; |
55 | return 0; | ||
56 | } | 61 | } |
57 | 62 | ||
58 | void | 63 | int |
59 | istream_destroy (istream_t *pis, void *owner) | 64 | stream_set_read (stream_t stream, int (*_read) |
65 | (stream_t, char *, size_t, off_t, size_t *), | ||
66 | void *owner) | ||
60 | { | 67 | { |
61 | if (pis && *pis) | 68 | if (stream == NULL) |
69 | return EINVAL; | ||
70 | if (owner == stream->owner) | ||
62 | { | 71 | { |
63 | istream_t is = *pis; | 72 | stream->_read = _read; |
64 | is->ref_count--; | 73 | return 0; |
65 | if ((is->owner && is->owner == owner) || | ||
66 | (is->owner == NULL && is->ref_count <= 0)) | ||
67 | free (is); | ||
68 | *pis = NULL; | ||
69 | } | 74 | } |
75 | return EACCES; | ||
70 | } | 76 | } |
71 | 77 | ||
72 | void | 78 | int |
73 | ostream_destroy (ostream_t *pos, void *owner) | 79 | stream_set_write (stream_t stream, int (*_write) |
80 | __P ((stream_t, const char *, size_t, off_t, size_t *)), | ||
81 | void *owner) | ||
74 | { | 82 | { |
75 | if (pos && (*pos)) | 83 | if (stream == NULL) |
84 | return EINVAL; | ||
85 | if (stream->owner == owner) | ||
76 | { | 86 | { |
77 | ostream_t os = *pos; | 87 | stream->_write = _write; |
78 | os->ref_count--; | 88 | return 0; |
79 | if ((os->owner && os->owner == owner) || | ||
80 | (os->owner == NULL && os->ref_count <= 0)) | ||
81 | free (os); | ||
82 | *pos = NULL; | ||
83 | } | 89 | } |
90 | return EACCES; | ||
84 | } | 91 | } |
85 | 92 | ||
86 | int | 93 | int |
87 | istream_read (istream_t is, char *buf, size_t count, | 94 | stream_read (stream_t is, char *buf, size_t count, |
88 | off_t offset, size_t *pnread) | 95 | off_t offset, size_t *pnread) |
89 | { | 96 | { |
90 | if (is == NULL || is->_read == NULL) | 97 | if (is == NULL || is->_read == NULL) |
91 | return EINVAL; | 98 | return EINVAL; |
... | @@ -93,10 +100,18 @@ istream_read (istream_t is, char *buf, size_t count, | ... | @@ -93,10 +100,18 @@ istream_read (istream_t is, char *buf, size_t count, |
93 | } | 100 | } |
94 | 101 | ||
95 | int | 102 | int |
96 | ostream_write (ostream_t os, const char *buf, size_t count, | 103 | stream_write (stream_t os, const char *buf, size_t count, |
97 | off_t offset, size_t *pnwrite) | 104 | off_t offset, size_t *pnwrite) |
98 | { | 105 | { |
99 | if (os == NULL || os->_write == NULL) | 106 | if (os == NULL || os->_write == NULL) |
100 | return EINVAL; | 107 | return EINVAL; |
101 | return os->_write (os, buf, count, offset, pnwrite); | 108 | return os->_write (os, buf, count, offset, pnwrite); |
102 | } | 109 | } |
110 | |||
111 | int | ||
112 | stream_get_fd (stream_t stream, int *pfd) | ||
113 | { | ||
114 | if (stream == NULL || stream->_get_fd == NULL) | ||
115 | return EINVAL; | ||
116 | return stream->_get_fd (stream, pfd); | ||
117 | } | ... | ... |
... | @@ -21,7 +21,7 @@ | ... | @@ -21,7 +21,7 @@ |
21 | #include <sys/types.h> | 21 | #include <sys/types.h> |
22 | 22 | ||
23 | #ifdef __cplusplus | 23 | #ifdef __cplusplus |
24 | extern "C" { | 24 | extern "C" { /*}*/ |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | #ifndef __P | 27 | #ifndef __P |
... | @@ -32,16 +32,30 @@ extern "C" { | ... | @@ -32,16 +32,30 @@ extern "C" { |
32 | # endif | 32 | # endif |
33 | #endif /*__P */ | 33 | #endif /*__P */ |
34 | 34 | ||
35 | struct _istream; | 35 | struct _stream; |
36 | typedef struct _istream *istream_t; | 36 | typedef struct _stream *stream_t; |
37 | struct _ostream; | 37 | |
38 | typedef struct _ostream *ostream_t; | 38 | extern int stream_init __P ((stream_t *, void *owner)); |
39 | 39 | extern void stream_destroy __P ((stream_t *, void *owner)); | |
40 | extern int istream_read __P ((istream_t, char *, size_t, off_t, size_t *)); | 40 | |
41 | 41 | extern int stream_set_fd __P ((stream_t, | |
42 | extern int ostream_write __P ((ostream_t, const char *, size_t, | 42 | int (*_get_fd)(stream_t, int *), |
43 | void *owner)); | ||
44 | extern int stream_set_read __P ((stream_t, | ||
45 | int (*_read) __P ((stream_t, char *, | ||
46 | size_t, off_t, size_t *)), | ||
47 | void *owner)); | ||
48 | extern int stream_set_write __P ((stream_t, | ||
49 | int (*_write) __P ((stream_t, const char *, | ||
50 | size_t, off_t, | ||
51 | size_t *)), | ||
52 | void *owner)); | ||
53 | extern int stream_get_fd __P ((stream_t , int *)); | ||
54 | extern int stream_read __P ((stream_t, char *, size_t, off_t, size_t *)); | ||
55 | extern int stream_write __P ((stream_t, const char *, size_t, | ||
43 | off_t, size_t *)); | 56 | off_t, size_t *)); |
44 | 57 | ||
58 | |||
45 | #ifdef __cplusplus | 59 | #ifdef __cplusplus |
46 | } | 60 | } |
47 | #endif | 61 | #endif | ... | ... |
... | @@ -32,33 +32,14 @@ extern "C" { | ... | @@ -32,33 +32,14 @@ extern "C" { |
32 | # endif | 32 | # endif |
33 | #endif /*__P */ | 33 | #endif /*__P */ |
34 | 34 | ||
35 | struct _istream | 35 | struct _stream |
36 | { | 36 | { |
37 | /* owner of the stream can not be a specific type */ | ||
38 | void *owner; | 37 | void *owner; |
39 | int ref_count; | 38 | int (*_get_fd) __P ((stream_t, int *)); |
40 | int (*_read) __P ((istream_t, char *, size_t, off_t, size_t *)); | 39 | int (*_read) __P ((stream_t, char *, size_t, off_t, size_t *)); |
40 | int (*_write) __P ((stream_t, const char *, size_t, off_t, size_t *)); | ||
41 | }; | 41 | }; |
42 | 42 | ||
43 | struct _ostream | ||
44 | { | ||
45 | /* owner of the stream can not be a specific type */ | ||
46 | void *owner; | ||
47 | int ref_count; | ||
48 | int (*_write) __P ((ostream_t, const char *, size_t, off_t, size_t *)); | ||
49 | }; | ||
50 | |||
51 | extern int istream_init __P ((istream_t *, | ||
52 | int (*_read) __P ((istream_t, char *, | ||
53 | size_t, off_t, size_t *)), | ||
54 | void *owner)); | ||
55 | extern void istream_destroy __P ((istream_t *, void *owner)); | ||
56 | extern int ostream_init __P ((ostream_t *, | ||
57 | int (*_write) __P ((ostream_t, const char *, | ||
58 | size_t, off_t, size_t *)), | ||
59 | void *owner)); | ||
60 | extern void ostream_destroy __P ((ostream_t *, void *owner)); | ||
61 | |||
62 | #ifdef __cplusplus | 43 | #ifdef __cplusplus |
63 | } | 44 | } |
64 | #endif | 45 | #endif | ... | ... |
... | @@ -95,7 +95,7 @@ locker_lock (locker_t lock, int flags) | ... | @@ -95,7 +95,7 @@ locker_lock (locker_t lock, int flags) |
95 | int fd = -1; | 95 | int fd = -1; |
96 | char buf[16]; | 96 | char buf[16]; |
97 | pid_t pid; | 97 | pid_t pid; |
98 | int remove = 0; | 98 | int removed = 0; |
99 | 99 | ||
100 | (void)flags; | 100 | (void)flags; |
101 | if (lock == NULL) | 101 | if (lock == NULL) |
... | @@ -115,22 +115,22 @@ locker_lock (locker_t lock, int flags) | ... | @@ -115,22 +115,22 @@ locker_lock (locker_t lock, int flags) |
115 | { | 115 | { |
116 | /* process is gone so we try to remove the lock */ | 116 | /* process is gone so we try to remove the lock */ |
117 | if (kill(pid, 0) == -1) | 117 | if (kill(pid, 0) == -1) |
118 | remove = 1; | 118 | removed = 1; |
119 | } | 119 | } |
120 | } | 120 | } |
121 | } | 121 | } |
122 | if (lock->flags & MU_LOCKER_TIME) | 122 | if (lock->flags & MU_LOCKER_TIME) |
123 | { | 123 | { |
124 | struct stat buf; | 124 | struct stat stbuf; |
125 | 125 | ||
126 | fstat(fd, &buf); | 126 | fstat(fd, &stbuf); |
127 | /* the lock has expired */ | 127 | /* the lock has expired */ |
128 | if ((time(NULL) - buf.st_mtime) > LOCK_EXPIRE_TIME) | 128 | if ((time(NULL) - stbuf.st_mtime) > LOCK_EXPIRE_TIME) |
129 | remove = 1; | 129 | removed = 1; |
130 | } | 130 | } |
131 | 131 | ||
132 | close(fd); | 132 | close(fd); |
133 | if (remove) | 133 | if (removed) |
134 | unlink(lock->fname); | 134 | unlink(lock->fname); |
135 | } | 135 | } |
136 | 136 | ... | ... |
... | @@ -137,7 +137,8 @@ static ssize_t mailbox_unix_get_header (mailbox_t, size_t msgno, char *h, | ... | @@ -137,7 +137,8 @@ static ssize_t mailbox_unix_get_header (mailbox_t, size_t msgno, char *h, |
137 | /* private stuff */ | 137 | /* private stuff */ |
138 | static int mailbox_unix_is_deleted (mailbox_t mbox, size_t msgno); | 138 | static int mailbox_unix_is_deleted (mailbox_t mbox, size_t msgno); |
139 | static int mailbox_unix_validity (mailbox_t mbox, size_t msgno); | 139 | static int mailbox_unix_validity (mailbox_t mbox, size_t msgno); |
140 | static int mailbox_unix_readstream (istream_t is, char *buffer, size_t buflen, | 140 | static int mailbox_unix_getfd (stream_t is, int *pfd); |
141 | static int mailbox_unix_readstream (stream_t is, char *buffer, size_t buflen, | ||
141 | off_t off, size_t *pnread); | 142 | off_t off, size_t *pnread); |
142 | static int mailbox_unix_is_from (const char *); | 143 | static int mailbox_unix_is_from (const char *); |
143 | static int mailbox_unix_readhdr (mailbox_t mbox, char *buf, size_t len, | 144 | static int mailbox_unix_readhdr (mailbox_t mbox, char *buf, size_t len, |
... | @@ -338,7 +339,7 @@ mailbox_unix_open (mailbox_t mbox, int flags) | ... | @@ -338,7 +339,7 @@ mailbox_unix_open (mailbox_t mbox, int flags) |
338 | mailbox_unix_data_t mud; | 339 | mailbox_unix_data_t mud; |
339 | int fd = -1; | 340 | int fd = -1; |
340 | int flg = 0; | 341 | int flg = 0; |
341 | char *mode; | 342 | const char *mode; |
342 | 343 | ||
343 | if (mbox == NULL || | 344 | if (mbox == NULL || |
344 | (mud = (mailbox_unix_data_t)mbox->data) == NULL) | 345 | (mud = (mailbox_unix_data_t)mbox->data) == NULL) |
... | @@ -601,20 +602,20 @@ mailbox_unix_readhdr (mailbox_t mbox, char *buf, size_t len, | ... | @@ -601,20 +602,20 @@ mailbox_unix_readhdr (mailbox_t mbox, char *buf, size_t len, |
601 | } | 602 | } |
602 | } | 603 | } |
603 | /* Set the attribute */ | 604 | /* Set the attribute */ |
604 | else if (strncmp (buf, "Status:", 7) == 0) | 605 | else if (strncasecmp (buf, "Status:", 7) == 0) |
605 | { | 606 | { |
606 | mum->hdr_status_end = ftell (mud->file); | 607 | mum->hdr_status_end = ftell (mud->file); |
607 | mum->hdr_status = mum->hdr_status_end - strlen (buf); | 608 | mum->hdr_status = mum->hdr_status_end - strlen (buf); |
608 | sep = strchr(buf, ':'); /* pass the ':' */ | 609 | sep = strchr(buf, ':'); /* pass the ':' */ |
609 | if (strchr (sep, 'R') != NULL) | 610 | if (strchr (sep, 'R') != NULL || strchr (sep, 'r') != NULL) |
610 | attribute_set_read (mum->old_attr); | 611 | attribute_set_read (mum->old_attr, mbox); |
611 | if (strchr (sep, 'O') != NULL) | 612 | if (strchr (sep, 'O') != NULL || strchr (sep, 'o') != NULL) |
612 | attribute_set_seen (mum->old_attr); | 613 | attribute_set_seen (mum->old_attr, mbox); |
613 | if (strchr (sep, 'A') != NULL) | 614 | if (strchr (sep, 'A') != NULL || strchr (sep, 'a') != NULL) |
614 | attribute_set_answered (mum->old_attr); | 615 | attribute_set_answered (mum->old_attr, mbox); |
615 | if (strchr (sep, 'F') != NULL) | 616 | if (strchr (sep, 'F') != NULL || strchr (sep, 'f') != NULL) |
616 | attribute_set_flagged (mum->old_attr); | 617 | attribute_set_flagged (mum->old_attr, mbox); |
617 | attribute_copy (mum->new_attr, mum->old_attr); | 618 | attribute_copy (mum->new_attr, mum->old_attr, mbox); |
618 | } | 619 | } |
619 | } | 620 | } |
620 | /* check for any dubious conditions */ | 621 | /* check for any dubious conditions */ |
... | @@ -1018,7 +1019,7 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1018,7 +1019,7 @@ mailbox_unix_expunge (mailbox_t mbox) |
1018 | int status = 0; | 1019 | int status = 0; |
1019 | int oflags; | 1020 | int oflags; |
1020 | sigset_t sigset; | 1021 | sigset_t sigset; |
1021 | FILE *tmpfile; | 1022 | FILE *tempfile; |
1022 | size_t nread; | 1023 | size_t nread; |
1023 | size_t i, j, first; | 1024 | size_t i, j, first; |
1024 | off_t marker = 0; | 1025 | off_t marker = 0; |
... | @@ -1034,14 +1035,14 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1034,14 +1035,14 @@ mailbox_unix_expunge (mailbox_t mbox) |
1034 | if (mud->messages_count == 0) | 1035 | if (mud->messages_count == 0) |
1035 | return 0; | 1036 | return 0; |
1036 | 1037 | ||
1037 | tmpfile = mailbox_unix_tmpfile (mbox, tmpmbox); | 1038 | tempfile = mailbox_unix_tmpfile (mbox, tmpmbox); |
1038 | if (tmpfile == NULL) | 1039 | if (tempfile == NULL) |
1039 | return errno; | 1040 | return errno; |
1040 | 1041 | ||
1041 | /* Get the lock */ | 1042 | /* Get the lock */ |
1042 | if (mailbox_unix_lock (mbox, MU_LOCKER_WRLOCK) < 0) | 1043 | if (mailbox_unix_lock (mbox, MU_LOCKER_WRLOCK) < 0) |
1043 | { | 1044 | { |
1044 | fclose (tmpfile); | 1045 | fclose (tempfile); |
1045 | remove (tmpmbox); | 1046 | remove (tmpmbox); |
1046 | free (tmpmbox); | 1047 | free (tmpmbox); |
1047 | return ENOLCK; | 1048 | return ENOLCK; |
... | @@ -1125,7 +1126,7 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1125,7 +1126,7 @@ mailbox_unix_expunge (mailbox_t mbox) |
1125 | first = 0; | 1126 | first = 0; |
1126 | else | 1127 | else |
1127 | { | 1128 | { |
1128 | fputc ('\n', tmpfile); | 1129 | fputc ('\n', tempfile); |
1129 | total++; | 1130 | total++; |
1130 | } | 1131 | } |
1131 | /* copy the header */ | 1132 | /* copy the header */ |
... | @@ -1144,7 +1145,7 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1144,7 +1145,7 @@ mailbox_unix_expunge (mailbox_t mbox) |
1144 | { | 1145 | { |
1145 | nread = (len < sizeof (buffer)) ? len : sizeof (buffer); | 1146 | nread = (len < sizeof (buffer)) ? len : sizeof (buffer); |
1146 | if (fread (buffer, sizeof (*buffer), nread, mud->file) != nread | 1147 | if (fread (buffer, sizeof (*buffer), nread, mud->file) != nread |
1147 | || fwrite(buffer, sizeof(*buffer), nread, tmpfile) != nread) | 1148 | || fwrite(buffer, sizeof(*buffer), nread, tempfile) != nread) |
1148 | { | 1149 | { |
1149 | status = errno; | 1150 | status = errno; |
1150 | goto bailout; | 1151 | goto bailout; |
... | @@ -1155,29 +1156,29 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1155,29 +1156,29 @@ mailbox_unix_expunge (mailbox_t mbox) |
1155 | /* put the new attributes */ | 1156 | /* put the new attributes */ |
1156 | { | 1157 | { |
1157 | attribute_t attr = mum->new_attr; | 1158 | attribute_t attr = mum->new_attr; |
1158 | fputs ("Status: ", tmpfile); | 1159 | fputs ("Status: ", tempfile); |
1159 | total += 8; | 1160 | total += 8; |
1160 | if (attribute_is_seen (attr)) | 1161 | if (attribute_is_seen (attr)) |
1161 | { | 1162 | { |
1162 | fputc ('R', tmpfile); | 1163 | fputc ('R', tempfile); |
1163 | total++; | 1164 | total++; |
1164 | } | 1165 | } |
1165 | if (attribute_is_answered (attr)) | 1166 | if (attribute_is_answered (attr)) |
1166 | { | 1167 | { |
1167 | fputc ('A', tmpfile); | 1168 | fputc ('A', tempfile); |
1168 | total++; | 1169 | total++; |
1169 | } | 1170 | } |
1170 | if (attribute_is_flagged (attr)) | 1171 | if (attribute_is_flagged (attr)) |
1171 | { | 1172 | { |
1172 | fputc ('F', tmpfile); | 1173 | fputc ('F', tempfile); |
1173 | total++; | 1174 | total++; |
1174 | } | 1175 | } |
1175 | if (attribute_is_read (attr)) | 1176 | if (attribute_is_read (attr)) |
1176 | { | 1177 | { |
1177 | fputc ('O', tmpfile); | 1178 | fputc ('O', tempfile); |
1178 | total++; | 1179 | total++; |
1179 | } | 1180 | } |
1180 | fputc ('\n', tmpfile); | 1181 | fputc ('\n', tempfile); |
1181 | total++; | 1182 | total++; |
1182 | } | 1183 | } |
1183 | /* skip the status field */ | 1184 | /* skip the status field */ |
... | @@ -1196,7 +1197,7 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1196,7 +1197,7 @@ mailbox_unix_expunge (mailbox_t mbox) |
1196 | { | 1197 | { |
1197 | nread = (len < sizeof (buffer)) ? len : sizeof (buffer); | 1198 | nread = (len < sizeof (buffer)) ? len : sizeof (buffer); |
1198 | if (fread (buffer, sizeof (*buffer), nread, mud->file) != nread | 1199 | if (fread (buffer, sizeof (*buffer), nread, mud->file) != nread |
1199 | || fwrite(buffer, sizeof(*buffer), nread, tmpfile) != nread) | 1200 | || fwrite(buffer, sizeof(*buffer), nread, tempfile) != nread) |
1200 | { | 1201 | { |
1201 | status = errno; | 1202 | status = errno; |
1202 | goto bailout; | 1203 | goto bailout; |
... | @@ -1206,7 +1207,7 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1206,7 +1207,7 @@ mailbox_unix_expunge (mailbox_t mbox) |
1206 | } | 1207 | } |
1207 | 1208 | ||
1208 | /* Separate the header from body */ | 1209 | /* Separate the header from body */ |
1209 | fputc ('\n', tmpfile); | 1210 | fputc ('\n', tempfile); |
1210 | total++; | 1211 | total++; |
1211 | 1212 | ||
1212 | /* copy the body */ | 1213 | /* copy the body */ |
... | @@ -1220,7 +1221,7 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1220,7 +1221,7 @@ mailbox_unix_expunge (mailbox_t mbox) |
1220 | { | 1221 | { |
1221 | nread = (len < sizeof (buffer)) ? len : sizeof (buffer); | 1222 | nread = (len < sizeof (buffer)) ? len : sizeof (buffer); |
1222 | if (fread (buffer, sizeof (*buffer), nread, mud->file) != nread | 1223 | if (fread (buffer, sizeof (*buffer), nread, mud->file) != nread |
1223 | || fwrite(buffer, sizeof(*buffer), nread, tmpfile) != nread) | 1224 | || fwrite(buffer, sizeof(*buffer), nread, tempfile) != nread) |
1224 | { | 1225 | { |
1225 | status = errno; | 1226 | status = errno; |
1226 | goto bailout; | 1227 | goto bailout; |
... | @@ -1254,7 +1255,7 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1254,7 +1255,7 @@ mailbox_unix_expunge (mailbox_t mbox) |
1254 | { | 1255 | { |
1255 | nread = (len < sizeof (buffer)) ? len : sizeof (buffer); | 1256 | nread = (len < sizeof (buffer)) ? len : sizeof (buffer); |
1256 | if (fread (buffer, sizeof (*buffer), nread, mud->file) != nread | 1257 | if (fread (buffer, sizeof (*buffer), nread, mud->file) != nread |
1257 | || fwrite(buffer, sizeof(*buffer), nread, tmpfile) != nread) | 1258 | || fwrite(buffer, sizeof(*buffer), nread, tempfile) != nread) |
1258 | { | 1259 | { |
1259 | status = errno; | 1260 | status = errno; |
1260 | goto bailout; | 1261 | goto bailout; |
... | @@ -1270,11 +1271,11 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1270,11 +1271,11 @@ mailbox_unix_expunge (mailbox_t mbox) |
1270 | status = errno; | 1271 | status = errno; |
1271 | goto bailout; | 1272 | goto bailout; |
1272 | } | 1273 | } |
1273 | rewind (tmpfile); | 1274 | rewind (tempfile); |
1274 | 1275 | ||
1275 | errno = 0; | 1276 | errno = 0; |
1276 | while ((nread = fread (buffer, sizeof (*buffer), | 1277 | while ((nread = fread (buffer, sizeof (*buffer), |
1277 | sizeof (buffer), tmpfile)) != 0) | 1278 | sizeof (buffer), tempfile)) != 0) |
1278 | { | 1279 | { |
1279 | if (fwrite (buffer, sizeof (*buffer), nread, mud->file) != nread) | 1280 | if (fwrite (buffer, sizeof (*buffer), nread, mud->file) != nread) |
1280 | { | 1281 | { |
... | @@ -1289,7 +1290,7 @@ mailbox_unix_expunge (mailbox_t mbox) | ... | @@ -1289,7 +1290,7 @@ mailbox_unix_expunge (mailbox_t mbox) |
1289 | } | 1290 | } |
1290 | 1291 | ||
1291 | /* how can I handle error here ?? */ | 1292 | /* how can I handle error here ?? */ |
1292 | clearerr (tmpfile); | 1293 | clearerr (tempfile); |
1293 | clearerr (mud->file); | 1294 | clearerr (mud->file); |
1294 | fflush (mud->file); | 1295 | fflush (mud->file); |
1295 | 1296 | ||
... | @@ -1310,13 +1311,25 @@ bailout: | ... | @@ -1310,13 +1311,25 @@ bailout: |
1310 | mailbox_unix_unlock (mbox); | 1311 | mailbox_unix_unlock (mbox); |
1311 | funlockfile (mud->file); | 1312 | funlockfile (mud->file); |
1312 | mailbox_unix_iunlock (mbox); | 1313 | mailbox_unix_iunlock (mbox); |
1313 | fclose (tmpfile); | 1314 | fclose (tempfile); |
1314 | sigprocmask (SIG_UNBLOCK, &sigset, 0); | 1315 | sigprocmask (SIG_UNBLOCK, &sigset, 0); |
1315 | return status; | 1316 | return status; |
1316 | } | 1317 | } |
1317 | 1318 | ||
1318 | static int | 1319 | static int |
1319 | mailbox_unix_readstream (istream_t is, char *buffer, size_t buflen, | 1320 | mailbox_unix_getfd (stream_t is, int *pfd) |
1321 | { | ||
1322 | mailbox_unix_message_t mum; | ||
1323 | |||
1324 | if (is == NULL || (mum = (mailbox_unix_message_t)is->owner) == NULL) | ||
1325 | return EINVAL; | ||
1326 | if (pfd) | ||
1327 | *pfd = fileno (mum->file); | ||
1328 | return 0; | ||
1329 | } | ||
1330 | |||
1331 | static int | ||
1332 | mailbox_unix_readstream (stream_t is, char *buffer, size_t buflen, | ||
1320 | off_t off, size_t *pnread) | 1333 | off_t off, size_t *pnread) |
1321 | { | 1334 | { |
1322 | mailbox_unix_message_t mum; | 1335 | mailbox_unix_message_t mum; |
... | @@ -1426,7 +1439,7 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) | ... | @@ -1426,7 +1439,7 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) |
1426 | mailbox_unix_data_t mud; | 1439 | mailbox_unix_data_t mud; |
1427 | mailbox_unix_message_t mum; | 1440 | mailbox_unix_message_t mum; |
1428 | message_t msg = NULL; | 1441 | message_t msg = NULL; |
1429 | istream_t is = NULL; | 1442 | stream_t stream = NULL; |
1430 | header_t header = NULL; | 1443 | header_t header = NULL; |
1431 | 1444 | ||
1432 | if (mbox == NULL || pmsg == NULL || | 1445 | if (mbox == NULL || pmsg == NULL || |
... | @@ -1488,13 +1501,16 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) | ... | @@ -1488,13 +1501,16 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) |
1488 | free (pbuf); | 1501 | free (pbuf); |
1489 | message_set_header (msg, header, mum); | 1502 | message_set_header (msg, header, mum); |
1490 | 1503 | ||
1491 | /* prepare the istream */ | 1504 | /* prepare the stream */ |
1492 | if ((status = istream_init (&is, mailbox_unix_readstream, mum)) != 0 || | 1505 | status = stream_init (&stream, mum); |
1493 | (status = message_set_istream (msg, is, mum)) != 0) | 1506 | if (status != 0) |
1494 | { | 1507 | { |
1495 | message_destroy (&msg, mum); | 1508 | message_destroy (&msg, mum); |
1496 | return status; | 1509 | return status; |
1497 | } | 1510 | } |
1511 | stream_set_read (stream, mailbox_unix_readstream, mum); | ||
1512 | stream_set_fd (stream, mailbox_unix_getfd, mum); | ||
1513 | message_set_stream (msg, stream, mum); | ||
1498 | 1514 | ||
1499 | /* set the attribute */ | 1515 | /* set the attribute */ |
1500 | status = message_set_attribute (msg, mum->new_attr, mum); | 1516 | status = message_set_attribute (msg, mum->new_attr, mum); |
... | @@ -1505,7 +1521,7 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) | ... | @@ -1505,7 +1521,7 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) |
1505 | } | 1521 | } |
1506 | 1522 | ||
1507 | /* set the size */ | 1523 | /* set the size */ |
1508 | status = message_set_size (msg, mum->body_end - mum->body, mum); | 1524 | status = message_set_size (msg, mum->body_end - mum->header, mum); |
1509 | if (status != 0) | 1525 | if (status != 0) |
1510 | { | 1526 | { |
1511 | message_destroy (&msg, mum); | 1527 | message_destroy (&msg, mum); |
... | @@ -1542,7 +1558,7 @@ mailbox_unix_append_message (mailbox_t mbox, message_t msg) | ... | @@ -1542,7 +1558,7 @@ mailbox_unix_append_message (mailbox_t mbox, message_t msg) |
1542 | char buffer[BUFSIZ]; | 1558 | char buffer[BUFSIZ]; |
1543 | size_t nread; | 1559 | size_t nread; |
1544 | off_t off = 0; | 1560 | off_t off = 0; |
1545 | istream_t is; | 1561 | stream_t is; |
1546 | header_t hdr; | 1562 | header_t hdr; |
1547 | int status; | 1563 | int status; |
1548 | 1564 | ||
... | @@ -1562,11 +1578,11 @@ mailbox_unix_append_message (mailbox_t mbox, message_t msg) | ... | @@ -1562,11 +1578,11 @@ mailbox_unix_append_message (mailbox_t mbox, message_t msg) |
1562 | 1578 | ||
1563 | /* header */ | 1579 | /* header */ |
1564 | message_get_header (msg, &hdr); | 1580 | message_get_header (msg, &hdr); |
1565 | header_get_istream (hdr, &is); | 1581 | header_get_stream (hdr, &is); |
1566 | if (st.st_size != 0) | 1582 | if (st.st_size != 0) |
1567 | fputc ('\n', mud->file); | 1583 | fputc ('\n', mud->file); |
1568 | do { | 1584 | do { |
1569 | status = istream_read (is, buffer, sizeof (buffer), off, &nread); | 1585 | status = stream_read (is, buffer, sizeof (buffer), off, &nread); |
1570 | if (status != 0) | 1586 | if (status != 0) |
1571 | return status; | 1587 | return status; |
1572 | fwrite (buffer, sizeof (*buffer), nread, mud->file); | 1588 | fwrite (buffer, sizeof (*buffer), nread, mud->file); |
... | @@ -1579,9 +1595,9 @@ mailbox_unix_append_message (mailbox_t mbox, message_t msg) | ... | @@ -1579,9 +1595,9 @@ mailbox_unix_append_message (mailbox_t mbox, message_t msg) |
1579 | 1595 | ||
1580 | /* body */ | 1596 | /* body */ |
1581 | off = 0; | 1597 | off = 0; |
1582 | message_get_istream (msg, &is); | 1598 | message_get_stream (msg, &is); |
1583 | do { | 1599 | do { |
1584 | istream_read (is, buffer, sizeof (buffer), off, &nread); | 1600 | stream_read (is, buffer, sizeof (buffer), off, &nread); |
1585 | fwrite (buffer, sizeof (*buffer), nread, mud->file); | 1601 | fwrite (buffer, sizeof (*buffer), nread, mud->file); |
1586 | off += nread; | 1602 | off += nread; |
1587 | } while (nread > 0); | 1603 | } while (nread > 0); | ... | ... |
... | @@ -30,17 +30,17 @@ | ... | @@ -30,17 +30,17 @@ |
30 | 30 | ||
31 | static int body_init (body_t *pbody, void *owner); | 31 | static int body_init (body_t *pbody, void *owner); |
32 | static void body_destroy (body_t *pbody, void *owner); | 32 | static void body_destroy (body_t *pbody, void *owner); |
33 | static int message_read (istream_t is, char *buf, size_t buflen, | 33 | static int message_read (stream_t is, char *buf, size_t buflen, |
34 | off_t off, size_t *pnread ); | 34 | off_t off, size_t *pnread ); |
35 | static int message_write (ostream_t os, const char *buf, size_t buflen, | 35 | static int message_write (stream_t os, const char *buf, size_t buflen, |
36 | off_t off, size_t *pnwrite); | 36 | off_t off, size_t *pnwrite); |
37 | static int message_get_fd (stream_t stream, int *pfd); | ||
37 | 38 | ||
38 | int | 39 | int |
39 | message_clone (message_t msg) | 40 | message_clone (message_t msg) |
40 | { | 41 | { |
41 | int status; | 42 | int status; |
42 | istream_t is; | 43 | stream_t stream; |
43 | ostream_t os; | ||
44 | header_t header; | 44 | header_t header; |
45 | attribute_t attribute; | 45 | attribute_t attribute; |
46 | body_t body; | 46 | body_t body; |
... | @@ -68,12 +68,12 @@ message_clone (message_t msg) | ... | @@ -68,12 +68,12 @@ message_clone (message_t msg) |
68 | /* retreive the header */ | 68 | /* retreive the header */ |
69 | { | 69 | { |
70 | header = msg->header; | 70 | header = msg->header; |
71 | status = header_get_istream (header, &is); | 71 | status = header_get_stream (header, &stream); |
72 | if (status != 0) | 72 | if (status != 0) |
73 | return status; | 73 | return status; |
74 | 74 | ||
75 | do { | 75 | do { |
76 | status = istream_read (is, buffer, sizeof (buffer), offset, &nread); | 76 | status = stream_read (stream, buffer, sizeof (buffer), offset, &nread); |
77 | if (status != 0) | 77 | if (status != 0) |
78 | { | 78 | { |
79 | free (pbuf); | 79 | free (pbuf); |
... | @@ -112,12 +112,12 @@ message_clone (message_t msg) | ... | @@ -112,12 +112,12 @@ message_clone (message_t msg) |
112 | return status; | 112 | return status; |
113 | } | 113 | } |
114 | 114 | ||
115 | is = msg->is; | 115 | stream = msg->stream; |
116 | offset = 0; | 116 | offset = 0; |
117 | do { | 117 | do { |
118 | do | 118 | do |
119 | { | 119 | { |
120 | status = istream_read (is, buffer, sizeof (buffer), offset, &nread); | 120 | status = stream_read (stream, buffer, sizeof (buffer), offset, &nread); |
121 | } while (status == EAGAIN); | 121 | } while (status == EAGAIN); |
122 | if (status != 0) | 122 | if (status != 0) |
123 | { | 123 | { |
... | @@ -132,21 +132,15 @@ message_clone (message_t msg) | ... | @@ -132,21 +132,15 @@ message_clone (message_t msg) |
132 | } | 132 | } |
133 | 133 | ||
134 | /* set the body with the streams */ | 134 | /* set the body with the streams */ |
135 | status = istream_init (&is, message_read, msg); | 135 | status = stream_init (&stream, msg); |
136 | if (status != 0) | 136 | if (status != 0 ) |
137 | { | ||
138 | header_destroy (&header, msg); | ||
139 | body_destroy (&body, msg); | ||
140 | return status; | ||
141 | } | ||
142 | status = ostream_init (&os, message_write, msg); | ||
143 | if (status != 0) | ||
144 | { | 137 | { |
145 | header_destroy (&header, msg); | 138 | header_destroy (&header, msg); |
146 | body_destroy (&body, msg); | 139 | body_destroy (&body, msg); |
147 | istream_destroy (&is, msg); | ||
148 | return status; | 140 | return status; |
149 | } | 141 | } |
142 | stream_set_read (stream, message_read, msg); | ||
143 | stream_set_write (stream, message_write, msg); | ||
150 | 144 | ||
151 | /* attribute */ | 145 | /* attribute */ |
152 | status = attribute_init (&attribute, msg); | 146 | status = attribute_init (&attribute, msg); |
... | @@ -154,16 +148,14 @@ message_clone (message_t msg) | ... | @@ -154,16 +148,14 @@ message_clone (message_t msg) |
154 | { | 148 | { |
155 | header_destroy (&header, msg); | 149 | header_destroy (&header, msg); |
156 | body_destroy (&body, msg); | 150 | body_destroy (&body, msg); |
157 | istream_destroy (&is, msg); | 151 | stream_destroy (&stream, msg); |
158 | ostream_destroy (&os, msg); | ||
159 | } | 152 | } |
160 | attribute_copy (attribute, msg->attribute); | 153 | attribute_copy (attribute, msg->attribute, msg); |
161 | 154 | ||
162 | /* every thing went ok */ | 155 | /* every thing went ok */ |
163 | msg->header = header; | 156 | msg->header = header; |
164 | msg->attribute = attribute; | 157 | msg->attribute = attribute; |
165 | msg->is = is; | 158 | msg->stream = stream; |
166 | msg->os = os; | ||
167 | msg->body = body; | 159 | msg->body = body; |
168 | msg->size = offset; | 160 | msg->size = offset; |
169 | msg->ref_count++; | 161 | msg->ref_count++; |
... | @@ -210,8 +202,7 @@ message_destroy (message_t *pmsg, void *owner) | ... | @@ -210,8 +202,7 @@ message_destroy (message_t *pmsg, void *owner) |
210 | { | 202 | { |
211 | header_t header = msg->header; | 203 | header_t header = msg->header; |
212 | attribute_t attribute = msg->attribute; | 204 | attribute_t attribute = msg->attribute; |
213 | istream_t is = msg->is; | 205 | stream_t stream = msg->stream; |
214 | ostream_t os = msg->os; | ||
215 | body_t body = msg->body; | 206 | body_t body = msg->body; |
216 | 207 | ||
217 | /* notify the listeners */ | 208 | /* notify the listeners */ |
... | @@ -220,10 +211,8 @@ message_destroy (message_t *pmsg, void *owner) | ... | @@ -220,10 +211,8 @@ message_destroy (message_t *pmsg, void *owner) |
220 | header_destroy (&header, owner); | 211 | header_destroy (&header, owner); |
221 | /* attribute */ | 212 | /* attribute */ |
222 | attribute_destroy (&attribute, owner); | 213 | attribute_destroy (&attribute, owner); |
223 | /* istream */ | 214 | /* stream */ |
224 | istream_destroy (&is, owner); | 215 | stream_destroy (&stream, owner); |
225 | /* ostream */ | ||
226 | ostream_destroy (&os, owner); | ||
227 | 216 | ||
228 | /* if sometype of floating/temporary message */ | 217 | /* if sometype of floating/temporary message */ |
229 | if (body) | 218 | if (body) |
... | @@ -281,75 +270,43 @@ message_set_header (message_t msg, header_t hdr, void *owner) | ... | @@ -281,75 +270,43 @@ message_set_header (message_t msg, header_t hdr, void *owner) |
281 | } | 270 | } |
282 | 271 | ||
283 | int | 272 | int |
284 | message_get_istream (message_t msg, istream_t *pis) | 273 | message_get_stream (message_t msg, stream_t *pstream) |
285 | { | 274 | { |
286 | if (msg == NULL || pis == NULL) | 275 | if (msg == NULL || pstream == NULL) |
287 | return EINVAL; | 276 | return EINVAL; |
288 | 277 | ||
289 | if (msg->is == NULL && msg->owner == NULL) | 278 | if (msg->stream == NULL && msg->owner == NULL) |
290 | { | 279 | { |
291 | istream_t is; | 280 | stream_t stream; |
292 | int status; | 281 | int status; |
293 | status = istream_init (&is, message_read, msg); | 282 | /* lazy floating message the body is created when |
294 | if (status != 0) | 283 | * doing the first message_write creation |
295 | return status; | 284 | */ |
296 | /* make sure we've clean */ | 285 | status = stream_init (&stream, msg); |
297 | istream_destroy (&(msg->is), msg); | ||
298 | msg->is = is; | ||
299 | } | ||
300 | |||
301 | *pis = msg->is; | ||
302 | return 0; | ||
303 | } | ||
304 | |||
305 | int | ||
306 | message_set_istream (message_t msg, istream_t is, void *owner) | ||
307 | { | ||
308 | if (msg == NULL) | ||
309 | return EINVAL; | ||
310 | if (msg->owner != owner) | ||
311 | return EACCES; | ||
312 | /* make sure we destroy the old one if it is own by the message */ | ||
313 | istream_destroy (&(msg->is), msg); | ||
314 | msg->is = is; | ||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | int | ||
319 | message_get_ostream (message_t msg, ostream_t *pos) | ||
320 | { | ||
321 | if (msg == NULL || pos == NULL) | ||
322 | return EINVAL; | ||
323 | |||
324 | /* lazy floating message the body is created when | ||
325 | * doing the first message_write creation | ||
326 | */ | ||
327 | if (msg->os == NULL && msg->owner == NULL) | ||
328 | { | ||
329 | ostream_t os; | ||
330 | int status; | ||
331 | status = ostream_init (&os, message_write, msg); | ||
332 | if (status != 0) | 286 | if (status != 0) |
333 | return status; | 287 | return status; |
288 | stream_set_read (stream, message_read, msg); | ||
289 | stream_set_write (stream, message_write, msg); | ||
290 | stream_set_fd (stream, message_get_fd, msg); | ||
334 | /* make sure we've clean */ | 291 | /* make sure we've clean */ |
335 | ostream_destroy (&(msg->os), msg); | 292 | stream_destroy (&(msg->stream), msg); |
336 | msg->os = os; | 293 | msg->stream = stream; |
337 | } | 294 | } |
338 | 295 | ||
339 | *pos = msg->os; | 296 | *pstream = msg->stream; |
340 | return 0; | 297 | return 0; |
341 | } | 298 | } |
342 | 299 | ||
343 | int | 300 | int |
344 | message_set_ostream (message_t msg, ostream_t os, void *owner) | 301 | message_set_stream (message_t msg, stream_t stream, void *owner) |
345 | { | 302 | { |
346 | if (msg == NULL) | 303 | if (msg == NULL) |
347 | return EINVAL; | 304 | return EINVAL; |
348 | if (msg->owner != owner) | 305 | if (msg->owner != owner) |
349 | return EACCES; | 306 | return EACCES; |
350 | /* make sure we destroy the old one if it is own by the message */ | 307 | /* make sure we destroy the old one if it is own by the message */ |
351 | ostream_destroy (&(msg->os), msg); | 308 | stream_destroy (&(msg->stream), msg); |
352 | msg->os = os; | 309 | msg->stream = stream; |
353 | return 0; | 310 | return 0; |
354 | } | 311 | } |
355 | 312 | ||
... | @@ -528,7 +485,7 @@ body_destroy (body_t *pbody, void *owner) | ... | @@ -528,7 +485,7 @@ body_destroy (body_t *pbody, void *owner) |
528 | } | 485 | } |
529 | 486 | ||
530 | static int | 487 | static int |
531 | message_read (istream_t is, char *buf, size_t buflen, | 488 | message_read (stream_t is, char *buf, size_t buflen, |
532 | off_t off, size_t *pnread ) | 489 | off_t off, size_t *pnread ) |
533 | { | 490 | { |
534 | message_t msg; | 491 | message_t msg; |
... | @@ -568,7 +525,7 @@ message_read (istream_t is, char *buf, size_t buflen, | ... | @@ -568,7 +525,7 @@ message_read (istream_t is, char *buf, size_t buflen, |
568 | } | 525 | } |
569 | 526 | ||
570 | static int | 527 | static int |
571 | message_write (ostream_t os, const char *buf, size_t buflen, | 528 | message_write (stream_t os, const char *buf, size_t buflen, |
572 | off_t off, size_t *pnwrite) | 529 | off_t off, size_t *pnwrite) |
573 | { | 530 | { |
574 | message_t msg; | 531 | message_t msg; |
... | @@ -614,3 +571,29 @@ message_write (ostream_t os, const char *buf, size_t buflen, | ... | @@ -614,3 +571,29 @@ message_write (ostream_t os, const char *buf, size_t buflen, |
614 | *pnwrite = nwrite; | 571 | *pnwrite = nwrite; |
615 | return 0; | 572 | return 0; |
616 | } | 573 | } |
574 | |||
575 | static int | ||
576 | message_get_fd (stream_t stream, int *pfd) | ||
577 | { | ||
578 | message_t msg; | ||
579 | body_t body; | ||
580 | |||
581 | if (stream == NULL || (msg = stream->owner) == NULL) | ||
582 | return EINVAL; | ||
583 | |||
584 | /* Probably being lazy, then create a body for the stream */ | ||
585 | if (msg->body == NULL) | ||
586 | { | ||
587 | int status = body_init (&body, msg); | ||
588 | if (status != 0 ) | ||
589 | return status; | ||
590 | msg->body = body; | ||
591 | } | ||
592 | else | ||
593 | body = msg->body; | ||
594 | |||
595 | if (pfd) | ||
596 | *pfd = fileno (body->file); | ||
597 | |||
598 | return 0; | ||
599 | } | ... | ... |
... | @@ -32,7 +32,7 @@ | ... | @@ -32,7 +32,7 @@ |
32 | # endif | 32 | # endif |
33 | #endif /* __P */ | 33 | #endif /* __P */ |
34 | 34 | ||
35 | #ifdef _cpluscplus | 35 | #ifdef _cplusplus |
36 | extern "C" { | 36 | extern "C" { |
37 | #endif | 37 | #endif |
38 | 38 | ||
... | @@ -54,10 +54,8 @@ extern void message_destroy __P ((message_t *, void *owner)); | ... | @@ -54,10 +54,8 @@ extern void message_destroy __P ((message_t *, void *owner)); |
54 | extern int message_get_header __P ((message_t, header_t *)); | 54 | extern int message_get_header __P ((message_t, header_t *)); |
55 | extern int message_set_header __P ((message_t, header_t, void *owner)); | 55 | extern int message_set_header __P ((message_t, header_t, void *owner)); |
56 | 56 | ||
57 | extern int message_get_istream __P ((message_t, istream_t *)); | 57 | extern int message_get_stream __P ((message_t, stream_t *)); |
58 | extern int message_set_istream __P ((message_t, istream_t, void *owner)); | 58 | extern int message_set_stream __P ((message_t, stream_t, void *owner)); |
59 | extern int message_get_ostream __P ((message_t, ostream_t *)); | ||
60 | extern int message_set_ostream __P ((message_t, ostream_t, void *owner)); | ||
61 | 59 | ||
62 | extern int message_is_multipart __P ((message_t)); | 60 | extern int message_is_multipart __P ((message_t)); |
63 | 61 | ||
... | @@ -75,7 +73,7 @@ extern int message_register __P ((message_t msg, size_t type, | ... | @@ -75,7 +73,7 @@ extern int message_register __P ((message_t msg, size_t type, |
75 | int (*action) (size_t typ, void *arg), | 73 | int (*action) (size_t typ, void *arg), |
76 | void *arg)); | 74 | void *arg)); |
77 | extern int message_deregister __P ((message_t msg, void *action)); | 75 | extern int message_deregister __P ((message_t msg, void *action)); |
78 | #ifdef _cpluscplus | 76 | #ifdef _cplusplus |
79 | } | 77 | } |
80 | #endif | 78 | #endif |
81 | 79 | ... | ... |
... | @@ -27,7 +27,7 @@ | ... | @@ -27,7 +27,7 @@ |
27 | #include <sys/types.h> | 27 | #include <sys/types.h> |
28 | #include <stdio.h> | 28 | #include <stdio.h> |
29 | 29 | ||
30 | #ifdef _cpluscplus | 30 | #ifdef _cplusplus |
31 | extern "C" { | 31 | extern "C" { |
32 | #endif | 32 | #endif |
33 | 33 | ||
... | @@ -57,8 +57,7 @@ typedef struct _body * body_t; | ... | @@ -57,8 +57,7 @@ typedef struct _body * body_t; |
57 | struct _message | 57 | struct _message |
58 | { | 58 | { |
59 | header_t header; | 59 | header_t header; |
60 | istream_t is; | 60 | stream_t stream; |
61 | ostream_t os; | ||
62 | body_t body; | 61 | body_t body; |
63 | attribute_t attribute; | 62 | attribute_t attribute; |
64 | size_t num; | 63 | size_t num; |
... | @@ -77,17 +76,15 @@ struct _message | ... | @@ -77,17 +76,15 @@ struct _message |
77 | int (*_get_attribute) __P ((message_t msg, attribute_t *attr)); | 76 | int (*_get_attribute) __P ((message_t msg, attribute_t *attr)); |
78 | int (*_set_attribute) __P ((message_t msg, attribute_t attr, void *owner)); | 77 | int (*_set_attribute) __P ((message_t msg, attribute_t attr, void *owner)); |
79 | 78 | ||
80 | int (*_get_istream) __P ((message_t msg, istream_t *)); | 79 | int (*_get_stream) __P ((message_t msg, stream_t *)); |
81 | int (*_set_istream) __P ((message_t msg, istream_t, void *owner)); | 80 | int (*_set_stream) __P ((message_t msg, stream_t, void *owner)); |
82 | int (*_get_ostream) __P ((message_t msg, ostream_t *)); | ||
83 | int (*_set_ostream) __P ((message_t msg, ostream_t, void *owner)); | ||
84 | 81 | ||
85 | int (*_size) __P ((message_t msg, size_t *size)); | 82 | int (*_size) __P ((message_t msg, size_t *size)); |
86 | 83 | ||
87 | int (*_clone) __P ((message_t msg, message_t *cmsg)); | 84 | int (*_clone) __P ((message_t msg, message_t *cmsg)); |
88 | }; | 85 | }; |
89 | 86 | ||
90 | #ifdef _cpluscplus | 87 | #ifdef _cplusplus |
91 | } | 88 | } |
92 | #endif | 89 | #endif |
93 | 90 | ... | ... |
... | @@ -47,7 +47,7 @@ free_ureg (struct url_registrar *ureg) | ... | @@ -47,7 +47,7 @@ free_ureg (struct url_registrar *ureg) |
47 | { | 47 | { |
48 | if (ureg) | 48 | if (ureg) |
49 | { | 49 | { |
50 | free (ureg->scheme); | 50 | free ((char *)ureg->scheme); |
51 | free (ureg); | 51 | free (ureg); |
52 | } | 52 | } |
53 | } | 53 | } |
... | @@ -57,7 +57,7 @@ free_mreg (struct mailbox_registrar *mreg) | ... | @@ -57,7 +57,7 @@ free_mreg (struct mailbox_registrar *mreg) |
57 | { | 57 | { |
58 | if (mreg) | 58 | if (mreg) |
59 | { | 59 | { |
60 | free (mreg->name); | 60 | free ((char *)mreg->name); |
61 | free (mreg); | 61 | free (mreg); |
62 | } | 62 | } |
63 | } | 63 | } | ... | ... |
... | @@ -31,20 +31,20 @@ | ... | @@ -31,20 +31,20 @@ |
31 | # endif | 31 | # endif |
32 | #endif /*__P */ | 32 | #endif /*__P */ |
33 | 33 | ||
34 | #ifdef _cpluscplus | 34 | #ifdef _cplusplus |
35 | extern "C" { | 35 | extern "C" { |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | struct url_registrar | 38 | struct url_registrar |
39 | { | 39 | { |
40 | char *scheme; | 40 | const char *scheme; |
41 | int (*_init) __P ((url_t *, const char * name)); | 41 | int (*_init) __P ((url_t *, const char * name)); |
42 | void (*_destroy) __P ((url_t *)); | 42 | void (*_destroy) __P ((url_t *)); |
43 | }; | 43 | }; |
44 | 44 | ||
45 | struct mailbox_registrar | 45 | struct mailbox_registrar |
46 | { | 46 | { |
47 | char *name; | 47 | const char *name; |
48 | int (*_init) __P ((mailbox_t *, const char *name)); | 48 | int (*_init) __P ((mailbox_t *, const char *name)); |
49 | void (*_destroy) __P ((mailbox_t *)); | 49 | void (*_destroy) __P ((mailbox_t *)); |
50 | }; | 50 | }; |
... | @@ -66,7 +66,7 @@ extern int registrar_get_entry __P ((size_t num, struct url_registrar **ureg, | ... | @@ -66,7 +66,7 @@ extern int registrar_get_entry __P ((size_t num, struct url_registrar **ureg, |
66 | extern int registrar_list __P ((struct url_registrar **ureg, | 66 | extern int registrar_list __P ((struct url_registrar **ureg, |
67 | struct mailbox_registrar **mreg, | 67 | struct mailbox_registrar **mreg, |
68 | int *id, registrar_t *reg)); | 68 | int *id, registrar_t *reg)); |
69 | #ifdef _cpluscplus | 69 | #ifdef _cplusplus |
70 | } | 70 | } |
71 | #endif | 71 | #endif |
72 | 72 | ... | ... |
... | @@ -82,7 +82,7 @@ url_pop_destroy (url_t *purl) | ... | @@ -82,7 +82,7 @@ url_pop_destroy (url_t *purl) |
82 | static int | 82 | static int |
83 | url_pop_init (url_t *purl, const char *name) | 83 | url_pop_init (url_t *purl, const char *name) |
84 | { | 84 | { |
85 | const char *host_port, *index; | 85 | const char *host_port, *indexe; |
86 | struct url_registrar *ureg = &_url_pop_registrar; | 86 | struct url_registrar *ureg = &_url_pop_registrar; |
87 | size_t len, scheme_len = strlen (ureg->scheme); | 87 | size_t len, scheme_len = strlen (ureg->scheme); |
88 | url_t url; | 88 | url_t url; |
... | @@ -115,34 +115,34 @@ url_pop_init (url_t *purl, const char *name) | ... | @@ -115,34 +115,34 @@ url_pop_init (url_t *purl, const char *name) |
115 | name += scheme_len; /* pass the scheme */ | 115 | name += scheme_len; /* pass the scheme */ |
116 | 116 | ||
117 | /* looking for "user;auth=auth-enc" */ | 117 | /* looking for "user;auth=auth-enc" */ |
118 | for (index = name; index != host_port; index++) | 118 | for (indexe = name; indexe != host_port; indexe++) |
119 | { | 119 | { |
120 | /* Auth ? */ | 120 | /* Auth ? */ |
121 | if (*index == ';') | 121 | if (*indexe == ';') |
122 | { | 122 | { |
123 | /* make sure it the token */ | 123 | /* make sure it the token */ |
124 | if (strncasecmp(index + 1, "auth=", 5) == 0) | 124 | if (strncasecmp(indexe + 1, "auth=", 5) == 0) |
125 | break; | 125 | break; |
126 | } | 126 | } |
127 | } | 127 | } |
128 | 128 | ||
129 | if (index == name) | 129 | if (indexe == name) |
130 | { | 130 | { |
131 | url_pop_destroy (&url); | 131 | url_pop_destroy (&url); |
132 | return -1; | 132 | return -1; |
133 | } | 133 | } |
134 | 134 | ||
135 | /* USER */ | 135 | /* USER */ |
136 | url->user = malloc(index - name + 1); | 136 | url->user = malloc(indexe - name + 1); |
137 | if (url->user == NULL) | 137 | if (url->user == NULL) |
138 | { | 138 | { |
139 | url_pop_destroy (&url); | 139 | url_pop_destroy (&url); |
140 | return -1; | 140 | return -1; |
141 | } | 141 | } |
142 | ((char *)memcpy(url->user, name, index - name))[index - name] = '\0'; | 142 | ((char *)memcpy(url->user, name, indexe - name))[indexe - name] = '\0'; |
143 | 143 | ||
144 | /* AUTH */ | 144 | /* AUTH */ |
145 | if ((host_port - index) <= 6 /*strlen(";AUTH=")*/) | 145 | if ((host_port - indexe) <= 6 /*strlen(";AUTH=")*/) |
146 | { | 146 | { |
147 | /* Use default AUTH '*' */ | 147 | /* Use default AUTH '*' */ |
148 | up->auth = malloc (1 + 1); | 148 | up->auth = malloc (1 + 1); |
... | @@ -155,12 +155,12 @@ url_pop_init (url_t *purl, const char *name) | ... | @@ -155,12 +155,12 @@ url_pop_init (url_t *purl, const char *name) |
155 | else | 155 | else |
156 | { | 156 | { |
157 | /* move pass AUTH= */ | 157 | /* move pass AUTH= */ |
158 | index += 6; | 158 | indexe += 6; |
159 | up->auth = malloc (host_port - index + 1); | 159 | up->auth = malloc (host_port - indexe + 1); |
160 | if (up->auth) | 160 | if (up->auth) |
161 | { | 161 | { |
162 | ((char *)memcpy (up->auth, index, host_port - index)) | 162 | ((char *)memcpy (up->auth, indexe, host_port - indexe)) |
163 | [host_port - index] = '\0'; | 163 | [host_port - indexe] = '\0'; |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
... | @@ -171,20 +171,20 @@ url_pop_init (url_t *purl, const char *name) | ... | @@ -171,20 +171,20 @@ url_pop_init (url_t *purl, const char *name) |
171 | } | 171 | } |
172 | 172 | ||
173 | /* HOST:PORT */ | 173 | /* HOST:PORT */ |
174 | index = strchr (++host_port, ':'); | 174 | indexe = strchr (++host_port, ':'); |
175 | if (index == NULL) | 175 | if (indexe == NULL) |
176 | { | 176 | { |
177 | url->host = strdup (host_port); | 177 | url->host = strdup (host_port); |
178 | url->port = MU_POP_PORT; | 178 | url->port = MU_POP_PORT; |
179 | } | 179 | } |
180 | else | 180 | else |
181 | { | 181 | { |
182 | long p = strtol(index + 1, NULL, 10); | 182 | long p = strtol(indexe + 1, NULL, 10); |
183 | url->host = malloc (index - host_port + 1); | 183 | url->host = malloc (indexe - host_port + 1); |
184 | if (url->host) | 184 | if (url->host) |
185 | { | 185 | { |
186 | ((char *)memcpy (url->host, host_port, index - host_port)) | 186 | ((char *)memcpy (url->host, host_port, indexe - host_port)) |
187 | [index - host_port]='\0'; | 187 | [indexe - host_port]='\0'; |
188 | url->port = (p == 0) ? MU_POP_PORT : p; | 188 | url->port = (p == 0) ? MU_POP_PORT : p; |
189 | } | 189 | } |
190 | } | 190 | } | ... | ... |
-
Please register or sign in to post a comment