]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZPeekIfNot.c
finalize -3
[1ts-debian.git] / zephyr / lib / ZPeekIfNot.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZPeekIfNotice 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 #ifndef lint
14 static char rcsid_ZPeekIfNotice_c[] = "$Id$";
15 #endif
16
17 #include <internal.h>
18
19 Code_t ZPeekIfNotice(notice, from, predicate, args)
20     ZNotice_t *notice;
21     struct sockaddr_in *from;
22     int (*predicate)();
23     char *args;
24 {
25     ZNotice_t tmpnotice;
26     Code_t retval;
27     char *buffer;
28     struct _Z_InputQ *qptr;
29
30     if ((retval = Z_WaitForComplete()) != ZERR_NONE)
31         return (retval);
32     
33     for (;;) {
34         qptr = Z_GetFirstComplete();
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                 return (ZERR_NONE);
51             }
52             qptr = Z_GetNextComplete(qptr);
53         }
54         if ((retval = Z_ReadWait()) != ZERR_NONE)
55             return (retval);
56     }
57 }