3 * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
12 * Copyright (c) 1990 Regents of the University of Michigan.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms are permitted
16 * provided that this notice is preserved and that due credit is given
17 * to the University of Michigan at Ann Arbor. The name of the University
18 * may not be used to endorse or promote products derived from this
19 * software without specific prior written permission. This software
20 * is provided ``as is'' without express or implied warranty.
26 #include <lber_types.h>
30 /* Overview of LBER tag construction
37 * 1 0 = CONTEXT-SPECIFIC
44 * | 5 ... 1 | TAG-NUMBER
47 /* BER classes and mask */
48 #define LBER_CLASS_UNIVERSAL ((ber_tag_t) 0x00U)
49 #define LBER_CLASS_APPLICATION ((ber_tag_t) 0x40U)
50 #define LBER_CLASS_CONTEXT ((ber_tag_t) 0x80U)
51 #define LBER_CLASS_PRIVATE ((ber_tag_t) 0xc0U)
52 #define LBER_CLASS_MASK ((ber_tag_t) 0xc0U)
54 /* BER encoding type and mask */
55 #define LBER_PRIMITIVE ((ber_tag_t) 0x00U)
56 #define LBER_CONSTRUCTED ((ber_tag_t) 0x20U)
57 #define LBER_ENCODING_MASK ((ber_tag_t) 0x20U)
59 #define LBER_BIG_TAG_MASK ((ber_tag_t) 0x1fU)
60 #define LBER_MORE_TAG_MASK ((ber_tag_t) 0x80U)
63 * Note that LBER_ERROR and LBER_DEFAULT are values that can never appear
64 * as valid BER tags, and so it is safe to use them to report errors. In
65 * fact, any tag for which the following is true is invalid:
67 #define LBER_INVALID(t) (((t) & (ber_tag_t) 0x080UL) \
68 && (((t) & (ber_tag_t) ~ 0x0FF))
70 #define LBER_ERROR ((ber_tag_t) -1)
71 #define LBER_DEFAULT ((ber_tag_t) -1)
73 /* general BER types we know about */
74 #define LBER_BOOLEAN ((ber_tag_t) 0x01UL)
75 #define LBER_INTEGER ((ber_tag_t) 0x02UL)
76 #define LBER_BITSTRING ((ber_tag_t) 0x03UL)
77 #define LBER_OCTETSTRING ((ber_tag_t) 0x04UL)
78 #define LBER_NULL ((ber_tag_t) 0x05UL)
79 #define LBER_ENUMERATED ((ber_tag_t) 0x0aUL)
80 #define LBER_SEQUENCE ((ber_tag_t) 0x30UL) /* constructed */
81 #define LBER_SET ((ber_tag_t) 0x31UL) /* constructed */
83 typedef int (*BERTranslateProc) LDAP_P((
88 /* LBER BerElement options */
89 #define LBER_USE_DER 0x01
90 #define LBER_USE_INDEFINITE_LEN 0x02
91 #define LBER_TRANSLATE_STRINGS 0x04 /* deprecated */
93 /* get/set options for BerElement */
94 #define LBER_OPT_BER_OPTIONS 0x01
95 #define LBER_OPT_BER_DEBUG 0x02
96 #define LBER_OPT_BER_REMAINING_BYTES 0x03
97 #define LBER_OPT_BER_TOTAL_BYTES 0x04
98 #define LBER_OPT_BER_BYTES_TO_WRITE 0x05
100 #define LBER_OPT_DEBUG_LEVEL LBER_OPT_BER_DEBUG
101 #define LBER_OPT_REMAINING_BYTES LBER_OPT_BER_REMAINING_BYTES
102 #define LBER_OPT_TOTAL_BYTES LBER_OPT_BER_TOTAL_BYTES
103 #define LBER_OPT_BYTES_TO_WRITE LBER_OPT_BER_BYTES_TO_WRITE
105 #define LBER_OPT_LOG_PRINT_FN 0x8001
106 #define LBER_OPT_MEMORY_FNS 0x8002
107 #define LBER_OPT_ERROR_FN 0x8003
109 typedef int* (*BER_ERRNO_FN) LDAP_P(( void ));
111 typedef void (*BER_LOG_PRINT_FN) LDAP_P(( char *buf ));
113 typedef void* (*BER_MEMALLOC_FN) LDAP_P(( ber_len_t size ));
114 typedef void* (*BER_MEMCALLOC_FN) LDAP_P(( ber_len_t n, ber_len_t size ));
115 typedef void* (*BER_MEMREALLOC_FN) LDAP_P(( void *p, ber_len_t size ));
116 typedef void (*BER_MEMFREE_FN) LDAP_P(( void *p ));
118 typedef struct lber_memory_fns {
119 BER_MEMALLOC_FN bmf_malloc;
120 BER_MEMCALLOC_FN bmf_calloc;
121 BER_MEMREALLOC_FN bmf_realloc;
122 BER_MEMFREE_FN bmf_free;
123 } BerMemoryFunctions;
125 /* LBER Sockbuf options */
126 #define LBER_TO_FILE 0x01 /* to a file referenced by sb_fd */
127 #define LBER_TO_FILE_ONLY 0x02 /* only write to file, not network */
128 #define LBER_MAX_INCOMING_SIZE 0x04 /* impose limit on incoming stuff */
129 #define LBER_NO_READ_AHEAD 0x08 /* read only as much as requested */
131 /* get/set options for Sockbuf */
132 #define LBER_OPT_SOCKBUF_DESC 0x1000
133 #define LBER_OPT_SOCKBUF_OPTIONS 0x1001
134 #define LBER_OPT_SOCKBUF_DEBUG 0x1002
137 #define LBER_OPT_ON ((void *) 1)
138 #define LBER_OPT_OFF ((void *) 0)
140 #define LBER_OPT_SUCCESS (0)
141 #define LBER_OPT_ERROR (-1)
143 typedef struct berelement BerElement;
144 typedef struct sockbuf Sockbuf;
145 typedef struct seqorset Seqorset;
147 /* structure for returning a sequence of octet strings + length */
148 typedef struct berval {
153 /* this should be moved to lber-int.h */
159 ber_print_error LDAP_P((
160 LDAP_CONST char *data ));
164 LDAP_CONST char *data, ber_len_t len ));
168 BerElement *ber, int inout ));
171 ber_sos_dump LDAP_P((
178 typedef int (*BERDecodeCallback) LDAP_P((
183 LIBLBER_F( ber_tag_t )
187 LIBLBER_F( ber_tag_t )
188 ber_skip_tag LDAP_P((
192 LIBLBER_F( ber_tag_t )
193 ber_peek_tag LDAP_P((
197 LIBLBER_F( ber_tag_t )
202 LIBLBER_F( ber_tag_t )
203 ber_get_stringb LDAP_P((
208 LIBLBER_F( ber_tag_t )
209 ber_get_stringa LDAP_P((
213 LIBLBER_F( ber_tag_t )
214 ber_get_stringal LDAP_P((
216 struct berval **bv ));
218 LIBLBER_F( ber_tag_t )
219 ber_get_bitstringa LDAP_P((
224 LIBLBER_F( ber_tag_t )
225 ber_get_null LDAP_P((
228 LIBLBER_F( ber_tag_t )
229 ber_get_boolean LDAP_P((
231 ber_int_t *boolval ));
233 LIBLBER_F( ber_tag_t )
234 ber_first_element LDAP_P((
239 LIBLBER_F( ber_tag_t )
240 ber_next_element LDAP_P((
243 LDAP_CONST char *last ));
245 LIBLBER_F( ber_tag_t )
248 LDAP_CONST char *fmt,
252 ber_set_string_translators LDAP_P((
254 BERTranslateProc encode_proc,
255 BERTranslateProc decode_proc ));
260 typedef int (*BEREncodeCallback) LDAP_P((
265 ber_put_enum LDAP_P((
277 ber_put_ostring LDAP_P((
279 LDAP_CONST char *str,
284 ber_put_berval LDAP_P((
286 LDAP_CONST struct berval *bv,
290 ber_put_string LDAP_P((
292 LDAP_CONST char *str,
296 ber_put_bitstring LDAP_P((
298 LDAP_CONST char *str,
303 ber_put_null LDAP_P((
308 ber_put_boolean LDAP_P((
314 ber_start_seq LDAP_P((
319 ber_start_set LDAP_P((
334 LDAP_CONST char *fmt,
342 LIBLBER_F( ber_slen_t )
348 LIBLBER_F( ber_slen_t )
351 LDAP_CONST char *buf,
366 LIBLBER_F( BerElement * )
367 ber_alloc LDAP_P(( void )); /* DEPRECATED */
369 LIBLBER_F( BerElement * )
370 der_alloc LDAP_P(( void )); /* DEPRECATED */
372 LIBLBER_F( BerElement * )
376 LIBLBER_F( BerElement * )
380 LIBLBER_F( ber_tag_t )
381 ber_get_next LDAP_P((
387 ber_init_w_nullc LDAP_P((
396 LIBLBER_F( BerElement * )
398 struct berval *bv ));
403 struct berval **bvPtr ));
406 * LBER ber accessor functions
410 ber_get_option LDAP_P((
416 ber_set_option LDAP_P((
419 LDAP_CONST void *invalue));
425 LIBLBER_F( Sockbuf * )
426 ber_sockbuf_alloc( void );
428 LIBLBER_F( Sockbuf * )
429 ber_sockbuf_alloc_fd(
440 ber_memalloc LDAP_P((
444 ber_memrealloc LDAP_P((
449 ber_memcalloc LDAP_P((
458 ber_memvfree LDAP_P((
463 struct berval *bv ));
466 ber_bvecfree LDAP_P((
467 struct berval **bv ));
471 struct berval ***bvec,
472 struct berval *bv ));
474 LIBLBER_F( struct berval * )
476 LDAP_CONST struct berval *bv ));
478 LIBLBER_F( struct berval * )
480 LDAP_CONST char * ));
482 LIBLBER_F( struct berval * )
483 ber_bvstrdup LDAP_P((
484 LDAP_CONST char * ));
488 LDAP_CONST char * ));
493 LIBLBER_F( int * ) ber_errno_addr LDAP_P((void));
494 #define ber_errno (*(ber_errno_addr)())
496 #define LBER_ERROR_NONE 0
497 #define LBER_ERROR_PARAM 0x1
498 #define LBER_ERROR_MEMORY 0x2