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