2 * Copyright (c) 2001 by Sun Microsystems, Inc.
7 * Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4
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/
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
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
28 #pragma ident "%Z%%M% %I% %E% SMI"
38 #include <stdlib.h> /* to pick up size_t typedef */
42 #define SAFEMEMCPY(d, s, n) bcopy(s, d, n)
44 #define SAFEMEMCPY(d, s, n) memmove(d, s, n)
46 #endif /* _SOLARIS_SDK */
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 )
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
63 /* BER encoding type and mask */
64 #define LBER_PRIMITIVE 0x00
65 #define LBER_CONSTRUCTED 0x20
66 #define LBER_ENCODING_MASK 0x20
68 #define LBER_BIG_TAG_MASK 0x1f
69 #define LBER_MORE_TAG_MASK 0x80
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
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 */
88 typedef struct berval
{
93 typedef struct berelement BerElement
;
96 #define NULLBER ((BerElement *)NULL)
99 typedef int (*BERTranslateProc
)(char **bufp
, ber_uint_t
*buflenp
,
102 #if defined(_WINDOWS) || defined(_WIN32) || defined(_CONSOLE)
103 #include <winsock.h> /* for SOCKET */
104 typedef SOCKET LBER_SOCKET
;
106 typedef int LBER_SOCKET
;
107 #endif /* _WINDOWS */
108 #else /* macintosh */
109 typedef void *LBER_SOCKET
;
110 #endif /* macintosh */
112 /* calling conventions used by library */
114 #if defined(_WINDOWS) || defined(_WIN32)
115 #define LDAP_C __cdecl
117 #define __stdcall _far _pascal
118 #define LDAP_CALLBACK _loadds
120 #define LDAP_CALLBACK
122 #define LDAP_PASCAL __stdcall
123 #define LDAP_CALL LDAP_PASCAL
126 #define LDAP_CALLBACK
129 #endif /* _WINDOWS */
130 #endif /* LDAP_CALL */
133 * function prototypes for lber library
136 #if defined(_WINDOWS) || defined(_WIN32)
137 #define LDAP_API(rt) rt
139 #define LDAP_API(rt) rt
140 #endif /* _WINDOWS */
141 #endif /* LDAP_API */
146 ber_tag_t LDAP_CALL
ber_get_tag(BerElement
*ber
);
147 ber_tag_t LDAP_CALL
ber_skip_tag(BerElement
*ber
,
149 ber_tag_t LDAP_CALL
ber_peek_tag(BerElement
*ber
,
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
,
154 ber_tag_t LDAP_CALL
ber_get_stringa(BerElement
*ber
,
156 ber_tag_t LDAP_CALL
ber_get_stringal(BerElement
*ber
,
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
,
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
,
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
);
179 int LDAP_CALL
ber_put_enum(BerElement
*ber
, ber_int_t num
,
181 int LDAP_CALL
ber_put_int(BerElement
*ber
, ber_int_t num
,
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
,
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
,
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
);
201 * miscellaneous routines
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
,
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
);