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