1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains source for the ZParseNotice function.
4 * Created by: Robert French
6 * $Id: ZParseNot.c,v 1.30 2002/09/10 16:04:29 ghudson Exp $
8 * Copyright (c) 1987,1991 by the Massachusetts Institute of Technology.
9 * For copying and distribution information, see the file
14 static char rcsid_ZParseNotice_c[] =
15 "$Zephyr: /mit/zephyr/src/lib/RCS/ZParseNotice.c,v 1.22 91/03/29 03:34:46 raeburn Exp $";
20 /* Skip to the next NUL-terminated field in the packet. */
21 static char *next_field(ptr, end)
24 while (ptr < end && *ptr != '\0')
31 Code_t ZParseNotice(buffer, len, notice)
38 int maj, numfields, i;
42 /* Note: This definition of BAD eliminates lint and compiler
43 * complains about the "while (0)", but require that the macro not
44 * be used as the "then" part of an "if" statement that also has
47 #define BAD_PACKET {lineno=__LINE__;goto badpkt;}
48 /* This one gets lint/compiler complaints. */
49 /*#define BAD do{lineno=__LINE__;goto badpkt;}while(0)*/
51 #define BAD_PACKET goto badpkt
54 (void) memset((char *)notice, 0, sizeof(ZNotice_t));
59 notice->z_packet = buffer;
61 notice->z_version = ptr;
62 if (strncmp(ptr, ZVERSIONHDR, sizeof(ZVERSIONHDR) - 1))
64 ptr += sizeof(ZVERSIONHDR) - 1;
67 Z_debug ("ZParseNotice: null version string");
72 if (maj != ZVERSIONMAJOR)
74 ptr = next_field(ptr, end);
76 if (ZReadAscii32(ptr, end-ptr, &temp) == ZERR_BADFIELD)
79 ptr = next_field(ptr, end);
82 numfields -= 2; /* numfields, version, and checksum */
88 Z_debug ("ZParseNotice: bad packet from %s/%d (line %d)",
89 inet_ntoa (notice->z_uid.zuid_addr.s_addr),
90 notice->z_port, lineno);
95 Z_debug ("ZParseNotice: bad packet from %s/%d",
96 inet_ntoa (notice->z_uid.zuid_addr.s_addr),
103 if (numfields && ptr < end) {
104 if (ZReadAscii32(ptr, end-ptr, &temp) == ZERR_BADFIELD)
106 notice->z_kind = (ZNotice_Kind_t)temp;
108 ptr = next_field(ptr, end);
113 if (numfields && ptr < end) {
114 if (ZReadAscii(ptr, end-ptr, (unsigned char *)¬ice->z_uid,
115 sizeof(ZUnique_Id_t)) == ZERR_BADFIELD)
117 notice->z_time.tv_sec = ntohl((u_long) notice->z_uid.tv.tv_sec);
118 notice->z_time.tv_usec = ntohl((u_long) notice->z_uid.tv.tv_usec);
120 ptr = next_field(ptr, end);
125 if (numfields && ptr < end) {
126 if (ZReadAscii16(ptr, end-ptr, ¬ice->z_port) == ZERR_BADFIELD)
128 notice->z_port = htons(notice->z_port);
130 ptr = next_field(ptr, end);
135 if (numfields && ptr < end) {
136 if (ZReadAscii32(ptr, end-ptr, &temp) == ZERR_BADFIELD)
138 notice->z_auth = temp;
140 ptr = next_field(ptr, end);
144 notice->z_checked_auth = ZAUTH_UNSET;
146 if (numfields && ptr < end) {
147 if (ZReadAscii32(ptr, end-ptr, &temp) == ZERR_BADFIELD)
149 notice->z_authent_len = temp;
151 ptr = next_field(ptr, end);
156 if (numfields && ptr < end) {
157 notice->z_ascii_authent = ptr;
159 ptr = next_field(ptr, end);
164 if (numfields && ptr < end) {
165 notice->z_class = ptr;
167 ptr = next_field(ptr, end);
170 notice->z_class = "";
172 if (numfields && ptr < end) {
173 notice->z_class_inst = ptr;
175 ptr = next_field(ptr, end);
178 notice->z_class_inst = "";
180 if (numfields && ptr < end) {
181 notice->z_opcode = ptr;
183 ptr = next_field(ptr, end);
186 notice->z_opcode = "";
188 if (numfields && ptr < end) {
189 notice->z_sender = ptr;
191 ptr = next_field(ptr, end);
194 notice->z_sender = "";
196 if (numfields && ptr < end) {
197 notice->z_recipient = ptr;
199 ptr = next_field(ptr, end);
202 notice->z_recipient = "";
204 if (numfields && ptr < end) {
205 notice->z_default_format = ptr;
207 ptr = next_field(ptr, end);
210 notice->z_default_format = "";
212 if (numfields && ptr < end) {
213 notice->z_ascii_checksum = ptr;
215 if (ZReadAscii32(ptr, end-ptr, &temp) == ZERR_BADFIELD)
216 notice->z_checksum = 0;
218 notice->z_checksum = temp;
221 ptr = next_field (ptr, end);
225 notice->z_ascii_checksum = "";
226 notice->z_checksum = 0;
229 if (numfields && ptr < end) {
230 notice->z_multinotice = ptr;
232 ptr = next_field(ptr, end);
235 notice->z_multinotice = "";
237 if (numfields && ptr < end) {
238 if (ZReadAscii(ptr, end-ptr, (unsigned char *)¬ice->z_multiuid,
239 sizeof(ZUnique_Id_t)) == ZERR_BADFIELD)
241 notice->z_time.tv_sec = ntohl((u_long) notice->z_multiuid.tv.tv_sec);
242 notice->z_time.tv_usec = ntohl((u_long) notice->z_multiuid.tv.tv_usec);
244 ptr = next_field(ptr, end);
247 notice->z_multiuid = notice->z_uid;
249 for (i=0;ptr < end && i<Z_MAXOTHERFIELDS && numfields;i++,numfields--) {
250 notice->z_other_fields[i] = ptr;
251 ptr = next_field(ptr, end);
253 notice->z_num_other_fields = i;
255 for (i=0;ptr < end && numfields;numfields--)
256 ptr = next_field(ptr, end);
258 if (numfields || *(ptr - 1) != '\0')
261 notice->z_message = (caddr_t) ptr;
262 notice->z_message_len = len-(ptr-buffer);