summaryrefslogtreecommitdiff
path: root/lib/ZParseNot.c
blob: 96cb4e03e8e5f86b02c56d45f338f954ff97d20c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* This file is part of the Project Athena Zephyr Notification System.
 * It contains source for the ZParseNotice function.
 *
 *	Created by:	Robert French
 *
 *	$Source$
 *	$Author$
 *
 *	Copyright (c) 1987 by the Massachusetts Institute of Technology.
 *	For copying and distribution information, see the file
 *	"mit-copyright.h". 
 */
/* $Header$ */

#ifndef lint
static char rcsid_ZParseNotice_c[] = "$Header$";
#endif lint

#include <zephyr/mit-copyright.h>

#include <zephyr/zephyr_internal.h>

Code_t ZParseNotice(buffer, len, notice)
    char *buffer;
    int len;
    ZNotice_t *notice;
{
    char *ptr, *end;
    int maj, numfields, i;
    unsigned int temp[3];

    bzero(notice, sizeof(ZNotice_t));
	
    ptr = buffer;
    end = buffer+len;

    notice->z_packet = buffer;
    
    notice->z_version = ptr;
    if (strncmp(ptr, ZVERSIONHDR, strlen(ZVERSIONHDR)))
	return (ZERR_VERS);
    ptr += strlen(ZVERSIONHDR);
    maj = atoi(ptr);
    if (maj != ZVERSIONMAJOR)
	return (ZERR_VERS);
    ptr += strlen(ptr)+1;

    if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp,
		   sizeof(int)) == ZERR_BADFIELD)
	return (ZERR_BADPKT);
    numfields = ntohl(*temp);
    ptr += strlen(ptr)+1;

    numfields -= 2;
    if (numfields < 0)
	numfields = 0;

    if (numfields) {
	if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp, 
		       sizeof(int)) == ZERR_BADFIELD)
	    return (ZERR_BADPKT);
	notice->z_kind = (ZNotice_Kind_t)ntohl((ZNotice_Kind_t)*temp);
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	return (ZERR_BADPKT);
	
    if (numfields) {
	if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp, 
		       sizeof(ZUnique_Id_t)) == ZERR_BADFIELD)
	    return (ZERR_BADPKT);
	bcopy((char *)temp, (char *)&notice->z_uid, sizeof(ZUnique_Id_t));
	notice->z_time.tv_sec = ntohl(notice->z_uid.tv.tv_sec);
	notice->z_time.tv_usec = ntohl(notice->z_uid.tv.tv_usec);
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	return (ZERR_BADPKT);
	
    if (numfields) {
	if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp, 
		       sizeof(u_short)) ==
	    ZERR_BADFIELD)
	    return (ZERR_BADPKT);
	notice->z_port = *((u_short *)temp);
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	return (ZERR_BADPKT);

    if (numfields) {
	if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp, 
		       sizeof(int)) == ZERR_BADFIELD)
	    return (ZERR_BADPKT);
	notice->z_auth = *temp;
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	return (ZERR_BADPKT);
	
    if (numfields) {
	if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp, 
		       sizeof(int)) == ZERR_BADFIELD)
	    return (ZERR_BADPKT);
	notice->z_authent_len = ntohl(*temp);
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	return (ZERR_BADPKT);

    if (numfields) {
	notice->z_ascii_authent = ptr;
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	return (ZERR_BADPKT);

    if (numfields) {
	notice->z_class = ptr;
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	notice->z_class = "";
	
    if (numfields) {
	notice->z_class_inst = ptr;
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	notice->z_class_inst = "";

    if (numfields) {
	notice->z_opcode = ptr;
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	notice->z_opcode = "";

    if (numfields) {
	notice->z_sender = ptr;
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	notice->z_sender = "";

    if (numfields) {
	notice->z_recipient = ptr;
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	notice->z_recipient = "";

    if (numfields) {
	notice->z_default_format = ptr;
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	notice->z_default_format = "";
	
    if (numfields) {
	if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp, 
		       sizeof(ZChecksum_t))
	    == ZERR_BADFIELD)
	    return (ZERR_BADPKT);
	notice->z_checksum = ntohl(*temp);
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	notice->z_checksum = 0;

    if (numfields) {
	notice->z_multinotice = ptr;
	numfields--;
	ptr += strlen(ptr)+1;
    }
    else
	notice->z_multinotice = "";

    for (i=0;i<Z_MAXOTHERFIELDS && numfields;i++,numfields--) {
	notice->z_other_fields[i] = ptr;
	ptr += strlen(ptr)+1;
    }
    notice->z_num_other_fields = i;
    
    for (i=0;i<numfields;i++)
	ptr += strlen(ptr)+1;
	
    notice->z_message = (caddr_t) ptr;
    notice->z_message_len = len-(ptr-buffer);

    return (ZERR_NONE);
}