xref: /titanic_41/usr/src/head/lber.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * Copyright (c) 2001 by Sun Microsystems, Inc.
3  * All rights reserved.
4  */
5 
6 /*
7  * Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4
8  *
9  * The contents of this file are subject to the Netscape Public License
10  * Version 1.0(the "NPL"); you may not use this file except in
11  * compliance with the NPL.  You may obtain a copy of the NPL at
12  * http:/ /www.mozilla.org/NPL/
13  *
14  * Software distributed under the NPL is distributed on an "AS IS" basis,
15  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
16  * for the specific language governing rights and limitations under the
17  * NPL.
18  *
19  * The Initial Developer of this code under the NPL is Netscape
20  * Communications Corporation.  Portions created by Netscape are
21  * Copyright(C) 1998 Netscape Communications Corporation.  All Rights
22  * Reserved.
23  */
24 
25 #ifndef	_LBER_H
26 #define	_LBER_H
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #ifndef	_SOLARIS_SDK
35 #define	_SOLARIS_SDK
36 #endif
37 
38 #include <stdlib.h>	/* to pick up size_t typedef */
39 
40 #ifdef	_SOLARIS_SDK
41 #ifdef	sunos4
42 #define	SAFEMEMCPY(d, s, n)   bcopy(s, d, n)
43 #else /* sunos4 */
44 #define	SAFEMEMCPY(d, s, n)   memmove(d, s, n)
45 #endif /* sunos4 */
46 #endif /* _SOLARIS_SDK */
47 /*
48  * Note that LBER_ERROR and LBER_DEFAULT are values that can never appear
49  * as valid BER tags, and so it is safe to use them to report errors.  In
50  * fact, any tag for which the following is true is invalid:
51  *     (( tag & 0x00000080 ) != 0 ) && (( tag & 0xFFFFFF00 ) != 0 )
52  */
53 #define	LBER_ERROR		0xffffffffU
54 #define	LBER_DEFAULT		0xffffffffU
55 #define	LBER_END_OF_SEQORSET	0xfffffffeU
56 /* BER classes and mask */
57 #define	LBER_CLASS_UNIVERSAL    0x00
58 #define	LBER_CLASS_APPLICATION  0x40
59 #define	LBER_CLASS_CONTEXT	0x80
60 #define	LBER_CLASS_PRIVATE	0xc0
61 #define	LBER_CLASS_MASK		0xc0
62 
63 /* BER encoding type and mask */
64 #define	LBER_PRIMITIVE		0x00
65 #define	LBER_CONSTRUCTED	0x20
66 #define	LBER_ENCODING_MASK	0x20
67 
68 #define	LBER_BIG_TAG_MASK	0x1f
69 #define	LBER_MORE_TAG_MASK	0x80
70 
71 /* general BER types we know about */
72 #define	LBER_BOOLEAN		0x01
73 #define	LBER_INTEGER		0x02
74 #define	LBER_BITSTRING		0x03
75 #define	LBER_OCTETSTRING	0x04
76 #define	LBER_NULL		0x05
77 #define	LBER_ENUMERATED		0x0a
78 #define	LBER_SEQUENCE		0x30
79 #define	LBER_SET		0x31
80 
81 
82 typedef unsigned int	ber_len_t;   /* for BER len */
83 typedef unsigned int	ber_tag_t;   /* for BER tags */
84 typedef int		ber_int_t;   /* for BER ints, enums, and Booleans */
85 typedef unsigned int	ber_uint_t; /* unsigned equivalent of ber_int_t */
86 typedef int		ber_slen_t; /* signed equivalent of ber_len_t */
87 
88 typedef struct berval {
89 	ber_len_t	bv_len;
90 	char		*bv_val;
91 } BerValue;
92 
93 typedef struct berelement BerElement;
94 
95 #ifdef	_SOLARIS_SDK
96 #define	NULLBER ((BerElement *)NULL)
97 #endif
98 
99 typedef int (*BERTranslateProc)(char **bufp, ber_uint_t *buflenp,
100 	int free_input);
101 #ifndef	macintosh
102 #if defined(_WINDOWS) || defined(_WIN32) || defined(_CONSOLE)
103 #include <winsock.h> /* for SOCKET */
104 typedef SOCKET LBER_SOCKET;
105 #else
106 typedef int LBER_SOCKET;
107 #endif /* _WINDOWS */
108 #else /* macintosh */
109 typedef void *LBER_SOCKET;
110 #endif /* macintosh */
111 
112 /* calling conventions used by library */
113 #ifndef	LDAP_CALL
114 #if defined(_WINDOWS) || defined(_WIN32)
115 #define	LDAP_C __cdecl
116 #ifndef	_WIN32
117 #define	__stdcall _far _pascal
118 #define	LDAP_CALLBACK _loadds
119 #else
120 #define	LDAP_CALLBACK
121 #endif /* _WIN32 */
122 #define	LDAP_PASCAL __stdcall
123 #define	LDAP_CALL LDAP_PASCAL
124 #else /* _WINDOWS */
125 #define	LDAP_C
126 #define	LDAP_CALLBACK
127 #define	LDAP_PASCAL
128 #define	LDAP_CALL
129 #endif /* _WINDOWS */
130 #endif /* LDAP_CALL */
131 
132 /*
133  * function prototypes for lber library
134  */
135 #ifndef	LDAP_API
136 #if defined(_WINDOWS) || defined(_WIN32)
137 #define	LDAP_API(rt) rt
138 #else /* _WINDOWS */
139 #define	LDAP_API(rt) rt
140 #endif /* _WINDOWS */
141 #endif /* LDAP_API */
142 
143 /*
144  * decode routines
145  */
146 ber_tag_t LDAP_CALL ber_get_tag(BerElement *ber);
147 ber_tag_t LDAP_CALL ber_skip_tag(BerElement *ber,
148 	ber_len_t *len);
149 ber_tag_t LDAP_CALL ber_peek_tag(BerElement *ber,
150 	ber_len_t *len);
151 ber_tag_t LDAP_CALL ber_get_int(BerElement *ber, ber_int_t *num);
152 ber_tag_t LDAP_CALL ber_get_stringb(BerElement *ber, char *buf,
153 	ber_len_t *len);
154 ber_tag_t LDAP_CALL ber_get_stringa(BerElement *ber,
155 	char **buf);
156 ber_tag_t LDAP_CALL ber_get_stringal(BerElement *ber,
157 	struct berval **bv);
158 ber_tag_t ber_get_bitstringa(BerElement *ber,
159 	char **buf, ber_len_t *len);
160 ber_tag_t LDAP_CALL ber_get_null(BerElement *ber);
161 ber_tag_t LDAP_CALL ber_get_boolean(BerElement *ber,
162 	int *boolval);
163 ber_tag_t LDAP_CALL ber_first_element(BerElement *ber,
164 	ber_len_t *len, char **last);
165 ber_tag_t LDAP_CALL ber_next_element(BerElement *ber,
166 	ber_len_t *len, char *last);
167 ber_tag_t LDAP_C ber_scanf(BerElement *ber, const char *fmt,
168 	...);
169 LDAP_API(void) LDAP_CALL ber_bvfree(struct berval *bv);
170 LDAP_API(void) LDAP_CALL ber_bvecfree(struct berval **bv);
171 struct berval *LDAP_CALL ber_bvdup(const struct berval *bv);
172 LDAP_API(void) LDAP_CALL ber_set_string_translators(BerElement *ber,
173 	BERTranslateProc encode_proc, BERTranslateProc decode_proc);
174 LDAP_API(BerElement *) LDAP_CALL ber_init(const struct berval *bv);
175 
176 /*
177  * encoding routines
178  */
179 int LDAP_CALL ber_put_enum(BerElement *ber, ber_int_t num,
180 	ber_tag_t tag);
181 int LDAP_CALL ber_put_int(BerElement *ber, ber_int_t num,
182 	ber_tag_t tag);
183 int LDAP_CALL ber_put_ostring(BerElement *ber, char *str,
184 	ber_len_t len, ber_tag_t tag);
185 int LDAP_CALL ber_put_string(BerElement *ber, char *str,
186 	ber_tag_t tag);
187 int LDAP_CALL ber_put_bitstring(BerElement *ber, char *str,
188 	ber_len_t bitlen, ber_tag_t tag);
189 int LDAP_CALL ber_put_null(BerElement *ber, ber_tag_t tag);
190 int LDAP_CALL ber_put_boolean(BerElement *ber, int boolval,
191 	ber_tag_t tag);
192 int LDAP_CALL ber_start_seq(BerElement *ber, ber_tag_t tag);
193 int LDAP_CALL ber_start_set(BerElement *ber, ber_tag_t tag);
194 int LDAP_CALL ber_put_seq(BerElement *ber);
195 int LDAP_CALL ber_put_set(BerElement *ber);
196 int LDAP_C ber_printf(BerElement *ber, const char *fmt, ...);
197 int LDAP_CALL ber_flatten(BerElement *ber,
198 	struct berval **bvPtr);
199 
200 /*
201  * miscellaneous routines
202  */
203 LDAP_API(void) LDAP_CALL ber_free(BerElement *ber, int freebuf);
204 LDAP_API(BerElement*) LDAP_CALL ber_alloc(void);
205 LDAP_API(BerElement*) LDAP_CALL der_alloc(void);
206 LDAP_API(BerElement*) LDAP_CALL ber_alloc_t(int options);
207 LDAP_API(BerElement*) LDAP_CALL ber_dup(BerElement *ber);
208 ber_int_t LDAP_CALL ber_read(BerElement *ber, char *buf,
209 	ber_len_t len);
210 ber_int_t LDAP_CALL ber_write(BerElement *ber, char *buf,
211 	ber_len_t len, int nosos);
212 LDAP_API(void) LDAP_CALL ber_reset(BerElement *ber, int was_writing);
213 
214 #ifdef	__cplusplus
215 }
216 #endif
217 
218 #endif /* _LBER_H */
219