Commit 9a23cb9f 9a23cb9fed48f2a7964ddcbe9c6401746ca0f5bd by Alain Magloire

header.c mailbox.c mailbox.h mailbox0.h mbx_unix.c message.c

Possibility to restart the scan.
1 parent 0b61ff71
...@@ -244,7 +244,8 @@ header_get_value (header_t header, const char *name, char *buffer, ...@@ -244,7 +244,8 @@ header_get_value (header_t header, const char *name, char *buffer,
244 for (name_len = strlen (name), i = 0; i < header->hdr_count; i++) 244 for (name_len = strlen (name), i = 0; i < header->hdr_count; i++)
245 { 245 {
246 fn_len = header->hdr[i].fn_end - header->hdr[i].fn; 246 fn_len = header->hdr[i].fn_end - header->hdr[i].fn;
247 if (fn_len == name_len && memcmp (header->hdr[i].fn, name, fn_len) == 0) 247 if (fn_len == name_len &&
248 strncasecmp (header->hdr[i].fn, name, fn_len) == 0)
248 { 249 {
249 fv_len = (header->hdr[i].fv_end - header->hdr[i].fv); 250 fv_len = (header->hdr[i].fv_end - header->hdr[i].fv);
250 total += fv_len; 251 total += fv_len;
...@@ -252,7 +253,7 @@ header_get_value (header_t header, const char *name, char *buffer, ...@@ -252,7 +253,7 @@ header_get_value (header_t header, const char *name, char *buffer,
252 if (buffer && threshold > 0) 253 if (buffer && threshold > 0)
253 { 254 {
254 threshold -= fv_len; 255 threshold -= fv_len;
255 if (threshold > 0) 256 if (threshold >= 0)
256 { 257 {
257 memcpy (buffer, header->hdr[i].fv, fv_len); 258 memcpy (buffer, header->hdr[i].fv, fv_len);
258 buffer += fv_len; 259 buffer += fv_len;
......
...@@ -165,6 +165,14 @@ mailbox_is_updated (mailbox_t mbox) ...@@ -165,6 +165,14 @@ mailbox_is_updated (mailbox_t mbox)
165 return mbox->_is_updated (mbox); 165 return mbox->_is_updated (mbox);
166 } 166 }
167 167
168 int
169 mailbox_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
170 {
171 if (mbox == NULL || mbox->_scan == NULL)
172 return 0;
173 return mbox->_scan (mbox, msgno, pcount);
174 }
175
168 /* locking */ 176 /* locking */
169 int 177 int
170 mailbox_set_locker (mailbox_t mbox, locker_t locker) 178 mailbox_set_locker (mailbox_t mbox, locker_t locker)
...@@ -262,15 +270,17 @@ mailbox_deregister (mailbox_t mbox, void *action) ...@@ -262,15 +270,17 @@ mailbox_deregister (mailbox_t mbox, void *action)
262 return ENOENT; 270 return ENOENT;
263 } 271 }
264 272
265 void 273 int
266 mailbox_notification (mailbox_t mbox, size_t type) 274 mailbox_notification (mailbox_t mbox, size_t type)
267 { 275 {
268 size_t i; 276 size_t i;
269 event_t event; 277 event_t event;
278 int status = 0;
270 for (i = 0; i < mbox->event_num; i++) 279 for (i = 0; i < mbox->event_num; i++)
271 { 280 {
272 event = &(mbox->event[i]); 281 event = &(mbox->event[i]);
273 if ((event->_action) && (event->type & type)) 282 if ((event->_action) && (event->type & type))
274 event->_action (type, event->arg); 283 status |= event->_action (type, event->arg);
275 } 284 }
285 return status;
276 } 286 }
......
...@@ -72,9 +72,8 @@ extern int mailbox_get_auth __P ((mailbox_t, auth_t *auth)); ...@@ -72,9 +72,8 @@ extern int mailbox_get_auth __P ((mailbox_t, auth_t *auth));
72 extern int mailbox_set_auth __P ((mailbox_t, auth_t auth)); 72 extern int mailbox_set_auth __P ((mailbox_t, auth_t auth));
73 73
74 /* update and scanning*/ 74 /* update and scanning*/
75 extern int mailbox_progress __P ((mailbox_t, int (*progress)
76 __P ((int, void *)), void *arg));
77 extern int mailbox_is_updated __P ((mailbox_t)); 75 extern int mailbox_is_updated __P ((mailbox_t));
76 extern int mailbox_scan __P ((mailbox_t, size_t msgno, size_t *count));
78 77
79 /* mailbox size ? */ 78 /* mailbox size ? */
80 extern int mailbox_size __P ((mailbox_t, off_t size)); 79 extern int mailbox_size __P ((mailbox_t, off_t size));
......
...@@ -65,6 +65,7 @@ struct _mailbox ...@@ -65,6 +65,7 @@ struct _mailbox
65 int (*_messages_count) __P ((mailbox_t, size_t *num)); 65 int (*_messages_count) __P ((mailbox_t, size_t *num));
66 int (*_expunge) __P ((mailbox_t)); 66 int (*_expunge) __P ((mailbox_t));
67 67
68 int (*_scan) __P ((mailbox_t, size_t msgno, size_t *count));
68 int (*_is_updated) __P ((mailbox_t)); 69 int (*_is_updated) __P ((mailbox_t));
69 70
70 int (*_size) __P ((mailbox_t, off_t *size)); 71 int (*_size) __P ((mailbox_t, off_t *size));
...@@ -90,7 +91,7 @@ extern int mailbox_get_attribute __P ((mailbox_t mbox, size_t msgno, ...@@ -90,7 +91,7 @@ extern int mailbox_get_attribute __P ((mailbox_t mbox, size_t msgno,
90 attribute_t *attr)); 91 attribute_t *attr));
91 extern int mailbox_set_attribute __P ((mailbox_t mbox, size_t msgno, 92 extern int mailbox_set_attribute __P ((mailbox_t mbox, size_t msgno,
92 attribute_t attr)); 93 attribute_t attr));
93 extern void mailbox_notification __P ((mailbox_t mbox, size_t type)); 94 extern int mailbox_notification __P ((mailbox_t mbox, size_t type));
94 95
95 96
96 #ifdef __cplusplus 97 #ifdef __cplusplus
......
...@@ -96,14 +96,15 @@ message_clone (message_t msg) ...@@ -96,14 +96,15 @@ message_clone (message_t msg)
96 offset += nread; 96 offset += nread;
97 } while (nread > 0); 97 } while (nread > 0);
98 98
99 status = header_init (&header, pbuf, offset, NULL);
100 if (status != 0)
101 {
102 free (pbuf);
103 return status;
104 }
105 free (pbuf);
106 } 99 }
100 /* set the new header */
101 status = header_init (&header, pbuf, offset, msg);
102 if (status != 0)
103 {
104 free (pbuf);
105 return status;
106 }
107 free (pbuf);
107 108
108 /* retrieve the body */ 109 /* retrieve the body */
109 { 110 {
...@@ -111,7 +112,7 @@ message_clone (message_t msg) ...@@ -111,7 +112,7 @@ message_clone (message_t msg)
111 file = tmpfile (); 112 file = tmpfile ();
112 if (file == NULL) 113 if (file == NULL)
113 { 114 {
114 header_destroy (&header, NULL); 115 header_destroy (&header, msg);
115 return errno; 116 return errno;
116 } 117 }
117 offset = 0; 118 offset = 0;
...@@ -122,7 +123,7 @@ message_clone (message_t msg) ...@@ -122,7 +123,7 @@ message_clone (message_t msg)
122 } while (status == EAGAIN); 123 } while (status == EAGAIN);
123 if (status != 0) 124 if (status != 0)
124 { 125 {
125 header_destroy (&header, NULL); 126 header_destroy (&header, msg);
126 return status; 127 return status;
127 } 128 }
128 fwrite (buffer, sizeof (*buffer), nread, file); 129 fwrite (buffer, sizeof (*buffer), nread, file);
...@@ -136,33 +137,33 @@ message_clone (message_t msg) ...@@ -136,33 +137,33 @@ message_clone (message_t msg)
136 if (body == NULL) 137 if (body == NULL)
137 { 138 {
138 fclose (file); 139 fclose (file);
139 header_destroy (&header, NULL); 140 header_destroy (&header, msg);
140 return ENOMEM; 141 return ENOMEM;
141 } 142 }
142 status = istream_init (&is, message_read, NULL); 143 status = istream_init (&is, message_read, msg);
143 if (status != 0) 144 if (status != 0)
144 { 145 {
145 fclose (file); 146 fclose (file);
146 header_destroy (&header, NULL); 147 header_destroy (&header, msg);
147 return status; 148 return status;
148 } 149 }
149 status = ostream_init (&os, message_write, NULL); 150 status = ostream_init (&os, message_write, msg);
150 if (status != 0) 151 if (status != 0)
151 { 152 {
152 fclose (file); 153 fclose (file);
153 header_destroy (&header, NULL); 154 header_destroy (&header, msg);
154 istream_destroy (&is, NULL); 155 istream_destroy (&is, msg);
155 return status; 156 return status;
156 } 157 }
157 158
158 /* attribute */ 159 /* attribute */
159 status = attribute_init (&attribute, NULL); 160 status = attribute_init (&attribute, msg);
160 if (status != 0) 161 if (status != 0)
161 { 162 {
162 fclose (file); 163 fclose (file);
163 header_destroy (&header, NULL); 164 header_destroy (&header, msg);
164 istream_destroy (&is, NULL); 165 istream_destroy (&is, msg);
165 ostream_destroy (&os, NULL); 166 ostream_destroy (&os, msg);
166 } 167 }
167 attribute_copy (attribute, msg->attribute); 168 attribute_copy (attribute, msg->attribute);
168 169
...@@ -229,6 +230,8 @@ message_destroy (message_t *pmsg, void *owner) ...@@ -229,6 +230,8 @@ message_destroy (message_t *pmsg, void *owner)
229 free (body->content); 230 free (body->content);
230 free (body); 231 free (body);
231 } 232 }
233 /* notifications are done */
234 free (msg->event);
232 /* check again for resurrection before free()ing 235 /* check again for resurrection before free()ing
233 * the memory maybe it was clone, if yes we can not 236 * the memory maybe it was clone, if yes we can not
234 * free the pointer. 237 * free the pointer.
...@@ -415,10 +418,10 @@ static int ...@@ -415,10 +418,10 @@ static int
415 message_read (istream_t is, char *buf, size_t buflen, 418 message_read (istream_t is, char *buf, size_t buflen,
416 off_t off, ssize_t *pnread ) 419 off_t off, ssize_t *pnread )
417 { 420 {
418 message_t msg = NULL; 421 message_t msg;
419 ssize_t nread = 0; 422 ssize_t nread = 0;
420 423
421 if (is == NULL) 424 if (is == NULL || (msg = is->owner) == NULL)
422 return EINVAL; 425 return EINVAL;
423 426
424 if (msg->body) 427 if (msg->body)
...@@ -469,10 +472,10 @@ static int ...@@ -469,10 +472,10 @@ static int
469 message_write (ostream_t os, const char *buf, size_t buflen, 472 message_write (ostream_t os, const char *buf, size_t buflen,
470 off_t off, ssize_t *pnwrite) 473 off_t off, ssize_t *pnwrite)
471 { 474 {
472 message_t msg = NULL; 475 message_t msg;
473 ssize_t nwrite = 0; 476 ssize_t nwrite = 0;
474 477
475 if (os == NULL) 478 if (os == NULL || (msg = os->owner) == NULL)
476 return EINVAL; 479 return EINVAL;
477 480
478 if (msg->body) 481 if (msg->body)
......