Merged pidgin/main into default
[pidgin-git.git] / libpurple / protocols / zephyr / ZCkIfNot.c
blob06aff8029de77629bc5971adfd12b1f09bac8075
1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains source for the ZCheckIfNotice function.
4 * Created by: Robert French
6 * Copyright (c) 1987,1988 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, see the file
8 * "mit-copyright.h".
9 */
11 #include "internal.h"
13 Code_t ZCheckIfNotice(notice, from, predicate, args)
14 ZNotice_t *notice;
15 struct sockaddr_in *from;
16 register int (*predicate) __P((ZNotice_t *, void *));
17 void *args;
19 ZNotice_t tmpnotice;
20 Code_t retval;
21 register char *buffer;
22 register struct _Z_InputQ *qptr;
24 if ((retval = Z_ReadEnqueue()) != ZERR_NONE)
25 return (retval);
27 qptr = Z_GetFirstComplete();
29 while (qptr) {
30 if ((retval = ZParseNotice(qptr->packet, qptr->packet_len,
31 &tmpnotice)) != ZERR_NONE)
32 return (retval);
33 if ((*predicate)(&tmpnotice, args)) {
34 if (!(buffer = (char *) malloc((unsigned) qptr->packet_len)))
35 return (ENOMEM);
36 (void) memcpy(buffer, qptr->packet, qptr->packet_len);
37 if (from)
38 *from = qptr->from;
39 if ((retval = ZParseNotice(buffer, qptr->packet_len,
40 notice)) != ZERR_NONE) {
41 free(buffer);
42 return (retval);
44 Z_RemQueue(qptr);
45 return (ZERR_NONE);
47 qptr = Z_GetNextComplete(qptr);
50 return (ZERR_NONOTICE);