* Update to packages/alpine.spec to account for the new location of man
[alpine.git] / ldap / inckit / lber.h
blob9c5289f11893ef30c5f080819443ca2f6dd874e0
1 /*
2 * Copyright (c) 1990 Regents of the University of Michigan.
3 * All rights reserved.
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.
13 #ifndef _LBER_H
14 #define _LBER_H
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
20 #if !defined( NEEDPROTOS ) && defined(__STDC__)
21 #define NEEDPROTOS 1
22 #endif
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 */
61 #ifdef NEEDPROTOS
62 typedef int (*BERTranslateProc)( char **bufp, unsigned long *buflenp,
63 int free_input );
64 #else /* NEEDPROTOS */
65 typedef int (*BERTranslateProc)();
66 #endif /* NEEDPROTOS */
68 typedef struct berelement {
69 char *ber_buf;
70 char *ber_ptr;
71 char *ber_end;
72 struct seqorset *ber_sos;
73 unsigned long ber_tag;
74 unsigned long ber_len;
75 int ber_usertag;
76 char ber_options;
77 #define LBER_USE_DER 0x01
78 #define LBER_USE_INDEFINITE_LEN 0x02
79 #define LBER_TRANSLATE_STRINGS 0x04
80 char *ber_rwptr;
81 BERTranslateProc ber_encode_translate_proc;
82 BERTranslateProc ber_decode_translate_proc;
83 } BerElement;
84 #define NULLBER ((BerElement *) 0)
86 typedef struct sockbuf {
87 #ifndef MACOS
88 int sb_sd;
89 #else /* MACOS */
90 void *sb_sd;
91 #endif /* MACOS */
92 BerElement sb_ber;
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
98 sockaddrs */
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 */
105 int sb_fd;
106 long sb_max_incoming;
107 } Sockbuf;
108 #define READBUFSIZ 8192
110 typedef struct seqorset {
111 BerElement *sos_ber;
112 unsigned long sos_clen;
113 unsigned long sos_tag;
114 char *sos_first;
115 char *sos_ptr;
116 struct seqorset *sos_next;
117 } Seqorset;
118 #define NULLSEQORSET ((Seqorset *) 0)
120 /* structure for returning a sequence of octet strings + length */
121 struct berval {
122 unsigned long bv_len;
123 char *bv_val;
126 #ifndef NEEDPROTOS
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 */
141 #if defined(WINSOCK)
142 #include "proto-lb.h"
143 #else
144 #include "proto-lber.h"
145 #endif
146 #endif /* NEEDPROTOS */
148 #if !defined(__alpha) || defined(VMS)
150 #define LBER_HTONL( l ) htonl( l )
151 #define LBER_NTOHL( l ) ntohl( l )
153 #else /* __alpha */
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
157 * here.
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 ))
164 #endif /* __alpha */
168 * SAFEMEMCPY is an overlap-safe copy from s to d of n bytes
170 #ifdef MACOS
171 #define SAFEMEMCPY( d, s, n ) BlockMoveData( (Ptr)s, (Ptr)d, n )
172 #else /* MACOS */
173 #ifdef sunos4
174 #define SAFEMEMCPY( d, s, n ) bcopy( s, d, n )
175 #else /* sunos4 */
176 #define SAFEMEMCPY( d, s, n ) memmove( d, s, n )
177 #endif /* sunos4 */
178 #endif /* MACOS */
181 #ifdef __cplusplus
183 #endif
184 #endif /* _LBER_H */