2 * Copyright (c) 1990 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
20 #if !defined( NEEDPROTOS ) && defined(__STDC__)
24 /* BER classes and mask */
25 #define LBER_CLASS_UNIVERSAL 0x00
26 #define LBER_CLASS_APPLICATION 0x40
27 #define LBER_CLASS_CONTEXT 0x80
28 #define LBER_CLASS_PRIVATE 0xc0
29 #define LBER_CLASS_MASK 0xc0
31 /* BER encoding type and mask */
32 #define LBER_PRIMITIVE 0x00
33 #define LBER_CONSTRUCTED 0x20
34 #define LBER_ENCODING_MASK 0x20
36 #define LBER_BIG_TAG_MASK 0x1f
37 #define LBER_MORE_TAG_MASK 0x80
40 * Note that LBER_ERROR and LBER_DEFAULT are values that can never appear
41 * as valid BER tags, and so it is safe to use them to report errors. In
42 * fact, any tag for which the following is true is invalid:
43 * (( tag & 0x00000080 ) != 0 ) && (( tag & 0xFFFFFF00 ) != 0 )
45 #define LBER_ERROR 0xffffffffL
46 #define LBER_DEFAULT 0xffffffffL
48 /* general BER types we know about */
49 #define LBER_BOOLEAN 0x01L
50 #define LBER_INTEGER 0x02L
51 #define LBER_BITSTRING 0x03L
52 #define LBER_OCTETSTRING 0x04L
53 #define LBER_NULL 0x05L
54 #define LBER_ENUMERATED 0x0aL
55 #define LBER_SEQUENCE 0x30L /* constructed */
56 #define LBER_SET 0x31L /* constructed */
58 #define OLD_LBER_SEQUENCE 0x10L /* w/o constructed bit - broken */
59 #define OLD_LBER_SET 0x11L /* w/o constructed bit - broken */
62 typedef int (*BERTranslateProc)( char **bufp, unsigned long *buflenp,
64 #else /* NEEDPROTOS */
65 typedef int (*BERTranslateProc)();
66 #endif /* NEEDPROTOS */
68 typedef struct berelement {
72 struct seqorset *ber_sos;
73 unsigned long ber_tag;
74 unsigned long ber_len;
77 #define LBER_USE_DER 0x01
78 #define LBER_USE_INDEFINITE_LEN 0x02
79 #define LBER_TRANSLATE_STRINGS 0x04
81 BERTranslateProc ber_encode_translate_proc;
82 BERTranslateProc ber_decode_translate_proc;
84 #define NULLBER ((BerElement *) 0)
86 typedef struct sockbuf {
94 int sb_naddr; /* > 0 implies using CLDAP (UDP) */
95 void *sb_useaddr; /* pointer to sockaddr to use next */
96 void *sb_fromaddr; /* pointer to message source sockaddr */
97 void **sb_addrs; /* actually an array of pointers to
100 int sb_options; /* to support copying ber elements */
101 #define LBER_TO_FILE 0x01 /* to a file referenced by sb_fd */
102 #define LBER_TO_FILE_ONLY 0x02 /* only write to file, not network */
103 #define LBER_MAX_INCOMING_SIZE 0x04 /* impose limit on incoming stuff */
104 #define LBER_NO_READ_AHEAD 0x08 /* read only as much as requested */
106 long sb_max_incoming;
108 #define READBUFSIZ 8192
110 typedef struct seqorset {
112 unsigned long sos_clen;
113 unsigned long sos_tag;
116 struct seqorset *sos_next;
118 #define NULLSEQORSET ((Seqorset *) 0)
120 /* structure for returning a sequence of octet strings + length */
122 unsigned long bv_len;
127 extern BerElement *ber_alloc();
128 extern BerElement *der_alloc();
129 extern BerElement *ber_alloc_t();
130 extern BerElement *ber_dup();
131 extern int lber_debug;
132 extern void ber_bvfree();
133 extern void ber_bvecfree();
134 extern struct berval *ber_bvdup();
135 extern void ber_dump();
136 extern void ber_sos_dump();
137 extern void lber_bprint();
138 extern void ber_reset();
139 extern void ber_init();
140 #else /* NEEDPROTOS */
142 #include "proto-lb.h"
144 #include "proto-lber.h"
146 #endif /* NEEDPROTOS */
148 #if !defined(__alpha) || defined(VMS)
150 #define LBER_HTONL( l ) htonl( l )
151 #define LBER_NTOHL( l ) ntohl( l )
155 * htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the
156 * lower-order 32-bits of a (64-bit) long, so we define correct versions
159 #define LBER_HTONL( l ) (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \
160 | htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
162 #define LBER_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \
163 | ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
168 * SAFEMEMCPY is an overlap-safe copy from s to d of n bytes
171 #define SAFEMEMCPY( d, s, n ) BlockMoveData( (Ptr)s, (Ptr)d, n )
174 #define SAFEMEMCPY( d, s, n ) bcopy( s, d, n )
176 #define SAFEMEMCPY( d, s, n ) memmove( d, s, n )