mbx_unix.c message.c message.h message0.h rfc822.c
message_get_size.
Showing
4 changed files
with
42 additions
and
12 deletions
... | @@ -1265,9 +1265,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) | ... | @@ -1265,9 +1265,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) |
1265 | off_t offset = 0; | 1265 | off_t offset = 0; |
1266 | mailbox_unix_data_t mud; | 1266 | mailbox_unix_data_t mud; |
1267 | mailbox_unix_message_t mum; | 1267 | mailbox_unix_message_t mum; |
1268 | message_t msg; | 1268 | message_t msg = NULL; |
1269 | istream_t is; | 1269 | istream_t is = NULL; |
1270 | header_t header; | 1270 | header_t header = NULL; |
1271 | 1271 | ||
1272 | if (mbox == NULL || pmsg == NULL || | 1272 | if (mbox == NULL || pmsg == NULL || |
1273 | (mud = (mailbox_unix_data_t)mbox->data) == NULL || | 1273 | (mud = (mailbox_unix_data_t)mbox->data) == NULL || |
... | @@ -1294,6 +1294,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) | ... | @@ -1294,6 +1294,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) |
1294 | return status; | 1294 | return status; |
1295 | } | 1295 | } |
1296 | 1296 | ||
1297 | if (nread == 0) | ||
1298 | break; | ||
1299 | |||
1297 | tbuf = realloc (pbuf, offset + nread); | 1300 | tbuf = realloc (pbuf, offset + nread); |
1298 | if (tbuf == NULL) | 1301 | if (tbuf == NULL) |
1299 | { | 1302 | { |
... | @@ -1315,8 +1318,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) | ... | @@ -1315,8 +1318,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) |
1315 | } | 1318 | } |
1316 | 1319 | ||
1317 | /* set the header */ | 1320 | /* set the header */ |
1318 | status = header_init (&header, pbuf, offset, MU_HEADER_RFC822, mum); | 1321 | if ((status = header_init (&header, pbuf, |
1319 | if (status != 0) | 1322 | offset, MU_HEADER_RFC822, mum)) != 0 || |
1323 | (status = message_set_header (msg, header, mum)) != 0) | ||
1320 | { | 1324 | { |
1321 | free (pbuf); | 1325 | free (pbuf); |
1322 | message_destroy (&msg, mum); | 1326 | message_destroy (&msg, mum); |
... | @@ -1327,9 +1331,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) | ... | @@ -1327,9 +1331,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) |
1327 | 1331 | ||
1328 | /* prepare the istream */ | 1332 | /* prepare the istream */ |
1329 | status = istream_init (&is, mailbox_unix_readstream, mum); | 1333 | status = istream_init (&is, mailbox_unix_readstream, mum); |
1330 | if (status != 0) | 1334 | if ((status = istream_init (&is, mailbox_unix_readstream, mum)) != 0 || |
1335 | (status = message_set_istream (msg, is, mum)) != 0) | ||
1331 | { | 1336 | { |
1332 | free (pbuf); | ||
1333 | message_destroy (&msg, mum); | 1337 | message_destroy (&msg, mum); |
1334 | return status; | 1338 | return status; |
1335 | } | 1339 | } |
... | @@ -1337,6 +1341,19 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) | ... | @@ -1337,6 +1341,19 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) |
1337 | 1341 | ||
1338 | /* set the attribute */ | 1342 | /* set the attribute */ |
1339 | status = message_set_attribute (msg, mum->new_attr, mum); | 1343 | status = message_set_attribute (msg, mum->new_attr, mum); |
1344 | if (status != 0) | ||
1345 | { | ||
1346 | message_destroy (&msg, mum); | ||
1347 | return status; | ||
1348 | } | ||
1349 | |||
1350 | /* set the size */ | ||
1351 | status = message_set_size (msg, mum->body_end - mum->body, mum); | ||
1352 | if (status != 0) | ||
1353 | { | ||
1354 | message_destroy (&msg, mum); | ||
1355 | return status; | ||
1356 | } | ||
1340 | 1357 | ||
1341 | if (pmsg) | 1358 | if (pmsg) |
1342 | *pmsg = msg; | 1359 | *pmsg = msg; | ... | ... |
... | @@ -157,7 +157,7 @@ message_destroy (message_t *pmsg, void *owner) | ... | @@ -157,7 +157,7 @@ message_destroy (message_t *pmsg, void *owner) |
157 | message_t msg = *pmsg; | 157 | message_t msg = *pmsg; |
158 | 158 | ||
159 | msg->ref_count--; | 159 | msg->ref_count--; |
160 | if ((msg->owner && msg->owner != owner) || | 160 | if ((msg->owner && msg->owner == owner) || |
161 | (msg->owner == NULL && msg->ref_count <= 0)) | 161 | (msg->owner == NULL && msg->ref_count <= 0)) |
162 | { | 162 | { |
163 | /* header */ | 163 | /* header */ |
... | @@ -247,13 +247,24 @@ message_set_ostream (message_t msg, ostream_t os, void *owner) | ... | @@ -247,13 +247,24 @@ message_set_ostream (message_t msg, ostream_t os, void *owner) |
247 | } | 247 | } |
248 | 248 | ||
249 | int | 249 | int |
250 | message_size (message_t msg, size_t *size) | 250 | message_get_size (message_t msg, size_t *psize) |
251 | { | 251 | { |
252 | if (msg == NULL) | 252 | if (msg == NULL) |
253 | return EINVAL; | 253 | return EINVAL; |
254 | if (msg->_size) | 254 | if (psize) |
255 | return msg->_size (msg, size); | 255 | *psize = msg->size; |
256 | return ENOSYS; | 256 | return 0; |
257 | } | ||
258 | |||
259 | int | ||
260 | message_set_size (message_t msg, size_t size, void *owner) | ||
261 | { | ||
262 | if (msg == NULL) | ||
263 | return EINVAL; | ||
264 | if (msg->owner != owner) | ||
265 | return EACCES; | ||
266 | msg->size = size; | ||
267 | return 0; | ||
257 | } | 268 | } |
258 | 269 | ||
259 | int | 270 | int | ... | ... |
... | @@ -54,6 +54,7 @@ extern int message_set_ostream __P ((message_t, ostream_t, void *owner)); | ... | @@ -54,6 +54,7 @@ extern int message_set_ostream __P ((message_t, ostream_t, void *owner)); |
54 | extern int message_is_multipart __P ((message_t)); | 54 | extern int message_is_multipart __P ((message_t)); |
55 | 55 | ||
56 | extern int message_get_size __P ((message_t, size_t *)); | 56 | extern int message_get_size __P ((message_t, size_t *)); |
57 | extern int message_set_size __P ((message_t, size_t, void *owner)); | ||
57 | 58 | ||
58 | extern int message_get_attribute __P ((message_t, attribute_t *)); | 59 | extern int message_get_attribute __P ((message_t, attribute_t *)); |
59 | extern int message_set_attribute __P ((message_t, attribute_t, void *owner)); | 60 | extern int message_set_attribute __P ((message_t, attribute_t, void *owner)); | ... | ... |
... | @@ -48,6 +48,7 @@ struct _message | ... | @@ -48,6 +48,7 @@ struct _message |
48 | body_t body; | 48 | body_t body; |
49 | attribute_t attribute; | 49 | attribute_t attribute; |
50 | size_t num; | 50 | size_t num; |
51 | size_t size; | ||
51 | 52 | ||
52 | /* who is the owner */ | 53 | /* who is the owner */ |
53 | void *owner; | 54 | void *owner; | ... | ... |
-
Please register or sign in to post a comment