]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZCkIfNot.c
finalize -3
[1ts-debian.git] / zephyr / lib / ZCkIfNot.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZCheckIfNotice function.
3  *
4  *      Created by:     Robert French
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987,1988 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h". 
11  */
12
13 #include <internal.h>
14
15 #ifndef lint
16 static const char rcsid_ZCheckIfNotice_c[] = "$Id$";
17 #endif
18
19 Code_t ZCheckIfNotice(notice, from, predicate, args)
20     ZNotice_t *notice;
21     struct sockaddr_in *from;
22     register int (*predicate) __P((ZNotice_t *, void *));
23     void *args;
24 {
25     ZNotice_t tmpnotice;
26     Code_t retval;
27     register char *buffer;
28     register struct _Z_InputQ *qptr;
29
30     if ((retval = Z_ReadEnqueue()) != ZERR_NONE)
31         return (retval);
32         
33     qptr = Z_GetFirstComplete();
34     
35     while (qptr) {
36         if ((retval = ZParseNotice(qptr->packet, qptr->packet_len, 
37                                    &tmpnotice)) != ZERR_NONE)
38             return (retval);
39         if ((*predicate)(&tmpnotice, args)) {
40             if (!(buffer = (char *) malloc((unsigned) qptr->packet_len)))
41                 return (ENOMEM);
42             (void) memcpy(buffer, qptr->packet, qptr->packet_len);
43             if (from)
44                 *from = qptr->from;
45             if ((retval = ZParseNotice(buffer, qptr->packet_len, 
46                                        notice)) != ZERR_NONE) {
47                 free(buffer);
48                 return (retval);
49             }
50             Z_RemQueue(qptr);
51             return (ZERR_NONE);
52         } 
53         qptr = Z_GetNextComplete(qptr);
54     }
55
56     return (ZERR_NONOTICE);
57 }