]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZReadZcode.c
more from the krb5-interrealm patches
[1ts-debian.git] / zephyr / lib / ZReadZcode.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZReadZcode function.
3  *
4  *      Created by:     Jeffrey Hutzelman
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987, 1990, 2002 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_ZReadZcode_c[] = "$Id$";
15 #endif /* lint */
16
17 #include <internal.h>
18 #include <assert.h>
19
20
21 Code_t
22 ZReadAsciiOrZcode(char *buf, int buflen, unsigned char *data, int datalen)
23 {
24     if (buf[0] == 'Z')
25         return ZReadZcode(buf, buflen, data, datalen);
26     else
27         return ZReadAscii(buf, buflen, data, datalen);
28 }
29
30 Code_t ZReadZcode32(ptr, value_ptr)
31     unsigned char *ptr;
32     unsigned long *value_ptr;
33 {
34     abort();
35 }
36
37 Code_t ZReadZcode(ptr, field, max, len)
38     unsigned char *ptr;
39     unsigned char *field;
40     int max;
41     int *len;
42 {
43     int n = 0;
44
45     if (*ptr++ != 'Z')
46         return ZERR_BADFIELD;
47
48     while (*ptr && n < max) {
49         if (*ptr == 0xff) {
50             ptr++;
51             switch (*ptr++) {
52                 case 0xf0: field[n++] = 0x00; continue;
53                 case 0xf1: field[n++] = 0xff; continue;
54                 default:   return ZERR_BADFIELD;
55             }
56         } else {
57             field[n++] = *ptr++;
58         }
59     }
60     if (*ptr)
61         return (ZERR_BADFIELD);
62     *len = n;
63     return (ZERR_NONE);
64 }