Mon, 22 Aug 2011 02:07:41 +0000
Don't use strlen() when all you're trying to do is check if the string
is empty
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for the ZIfNotice function. | |
| 3 | * | |
| 4 | * Created by: Robert French | |
| 5 | * | |
| 6 | * Copyright (c) 1987,1988 by the Massachusetts Institute of Technology. | |
| 7 | * For copying and distribution information, see the file | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
8 | * "mit-copyright.h". |
| 2086 | 9 | */ |
| 10 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
2086
diff
changeset
|
11 | #include "internal.h" |
| 2086 | 12 | |
| 13 | Code_t ZIfNotice(notice, from, predicate, args) | |
| 14 | ZNotice_t *notice; | |
| 15 | struct sockaddr_in *from; | |
| 16 | int (*predicate) __P((ZNotice_t *, void *)); | |
| 17 | void *args; | |
| 18 | { | |
| 19 | ZNotice_t tmpnotice; | |
| 20 | Code_t retval; | |
| 21 | char *buffer; | |
| 22 | struct _Z_InputQ *qptr; | |
| 23 | ||
| 24 | if ((retval = Z_WaitForComplete()) != ZERR_NONE) | |
| 25 | return (retval); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
26 | |
| 2086 | 27 | qptr = Z_GetFirstComplete(); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
28 | |
| 2086 | 29 | for (;;) { |
| 30 | while (qptr) { | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
31 | if ((retval = ZParseNotice(qptr->packet, qptr->packet_len, |
| 2086 | 32 | &tmpnotice)) != ZERR_NONE) |
| 33 | return (retval); | |
| 34 | if ((*predicate)(&tmpnotice, args)) { | |
| 35 | if (!(buffer = (char *) malloc((unsigned) qptr->packet_len))) | |
| 36 | return (ENOMEM); | |
| 37 | (void) memcpy(buffer, qptr->packet, qptr->packet_len); | |
| 38 | if (from) | |
| 39 | *from = qptr->from; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
40 | if ((retval = ZParseNotice(buffer, qptr->packet_len, |
| 2086 | 41 | notice)) != ZERR_NONE) { |
| 42 | free(buffer); | |
| 43 | return (retval); | |
| 44 | } | |
| 45 | Z_RemQueue(qptr); | |
| 46 | return (ZERR_NONE); | |
| 47 | } | |
| 48 | qptr = Z_GetNextComplete(qptr); | |
| 49 | } | |
| 50 | if ((retval = Z_ReadWait()) != ZERR_NONE) | |
| 51 | return (retval); | |
| 52 | qptr = Z_GetFirstComplete(); /* need to look over all of | |
| 53 | the queued messages, in case | |
| 54 | a fragment has been reassembled */ | |
| 55 | } | |
| 56 | } |