summaryrefslogtreecommitdiff
path: root/lib/ZParseNot.c
blob: ea4ef67e73a0692307ff60d583aef260248a1366 (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
/* 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$ */

#include <zephyr/mit-copyright.h>

#include <zephyr/zephyr_internal.h>

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

	ptr = buffer;
	
	if (Z_ReadField(&ptr,temp,1))
		return (ZERR_BADPKT);
	
	if (*temp != ZVERSION)
		return (ZERR_VERS);

	if (Z_ReadField(&ptr,temp,1))
		return (ZERR_BADPKT);
	notice->z_kind = (ZNotice_Kind_t)*temp;

	if (Z_ReadField(&ptr,temp,1))
		return (ZERR_BADPKT);
	notice->z_port = (short)*temp;
	
	if (Z_ReadField(&ptr,temp,2))
		return (ZERR_BADPKT);
	bcopy(temp,notice->z_checksum,sizeof(ZChecksum_t));

	if (Z_ReadField(&ptr,temp,3))
		return (ZERR_BADPKT);
	bcopy(temp,&notice->z_uid,sizeof(ZUnique_Id_t));

	notice->z_class = ptr;
	ptr += strlen(ptr)+1;
	notice->z_class_inst = ptr;
	ptr += strlen(ptr)+1;
	notice->z_opcode = ptr;
	ptr += strlen(ptr)+1;
	notice->z_sender = ptr;
	ptr += strlen(ptr)+1;
	notice->z_recipient = ptr;
	ptr += strlen(ptr)+1;

	notice->z_message = (caddr_t) ptr;
	notice->z_message_len = len-(ptr-buffer);

	*auth = 0;

	return (ZERR_NONE);
}

int Z_ReadField(ptr,temp,num)
	char **ptr;
	int *temp;
	int num;
{
	int i;
	char *space;

	for (i=0;i<num;i++) {
		space = (char *)index(*ptr,' ');
		if ((*ptr)[0] != '0' || (*ptr)[1] != 'x')
			return (1);
		sscanf(*ptr+2,"%x",temp+i);
		if (space)
			*ptr = space+1;
		else
			*ptr += strlen(*ptr);
		if (!*ptr && i != num-1)
			return (1);
	}

	if (**ptr)
		return (1);
	(*ptr)++;
	return (0);
}