3 * Copyright 1998-2000 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 /* LBER BerElement options */
84 #define LBER_USE_DER 0x01
85 #define LBER_USE_INDEFINITE_LEN 0x02
87 /* get/set options for BerElement */
88 #define LBER_OPT_BER_OPTIONS 0x01
89 #define LBER_OPT_BER_DEBUG 0x02
90 #define LBER_OPT_BER_REMAINING_BYTES 0x03
91 #define LBER_OPT_BER_TOTAL_BYTES 0x04
92 #define LBER_OPT_BER_BYTES_TO_WRITE 0x05
94 #define LBER_OPT_DEBUG_LEVEL LBER_OPT_BER_DEBUG
95 #define LBER_OPT_REMAINING_BYTES LBER_OPT_BER_REMAINING_BYTES
96 #define LBER_OPT_TOTAL_BYTES LBER_OPT_BER_TOTAL_BYTES
97 #define LBER_OPT_BYTES_TO_WRITE LBER_OPT_BER_BYTES_TO_WRITE
99 #define LBER_OPT_LOG_PRINT_FN 0x8001
100 #define LBER_OPT_MEMORY_FNS 0x8002
101 #define LBER_OPT_ERROR_FN 0x8003
102 #define LBER_OPT_LOG_PRINT_FILE 0x8004
104 typedef int* (*BER_ERRNO_FN) LDAP_P(( void ));
106 typedef void (*BER_LOG_PRINT_FN) LDAP_P(( LDAP_CONST char *buf ));
108 typedef void* (*BER_MEMALLOC_FN) LDAP_P(( ber_len_t size ));
109 typedef void* (*BER_MEMCALLOC_FN) LDAP_P(( ber_len_t n, ber_len_t size ));
110 typedef void* (*BER_MEMREALLOC_FN) LDAP_P(( void *p, ber_len_t size ));
111 typedef void (*BER_MEMFREE_FN) LDAP_P(( void *p ));
113 typedef struct lber_memory_fns {
114 BER_MEMALLOC_FN bmf_malloc;
115 BER_MEMCALLOC_FN bmf_calloc;
116 BER_MEMREALLOC_FN bmf_realloc;
117 BER_MEMFREE_FN bmf_free;
118 } BerMemoryFunctions;
120 /* LBER Sockbuf_IO options */
121 #define LBER_SB_OPT_GET_FD 1
122 #define LBER_SB_OPT_SET_FD 2
123 #define LBER_SB_OPT_HAS_IO 3
124 #define LBER_SB_OPT_SET_NONBLOCK 4
125 #define LBER_SB_OPT_UDP_GET_SRC 5
126 #define LBER_SB_OPT_UDP_SET_DST 6
127 #define LBER_SB_OPT_GET_SSL 7
128 #define LBER_SB_OPT_DATA_READY 8
129 #define LBER_SB_OPT_SET_READAHEAD 9
130 #define LBER_SB_OPT_DRAIN 10
131 #define LBER_SB_OPT_NEEDS_READ 11
132 #define LBER_SB_OPT_NEEDS_WRITE 12
133 /* Largest option used by the library */
134 #define LBER_SB_OPT_OPT_MAX 12
136 /* LBER IO operations stacking levels */
137 #define LBER_SBIOD_LEVEL_PROVIDER 10
138 #define LBER_SBIOD_LEVEL_TRANSPORT 20
139 #define LBER_SBIOD_LEVEL_APPLICATION 30
141 /* get/set options for Sockbuf */
142 #define LBER_OPT_SOCKBUF_DESC 0x1000
143 #define LBER_OPT_SOCKBUF_OPTIONS 0x1001
144 #define LBER_OPT_SOCKBUF_DEBUG 0x1002
147 #define LBER_OPT_ON ((void *) 1)
148 #define LBER_OPT_OFF ((void *) 0)
150 #define LBER_OPT_SUCCESS (0)
151 #define LBER_OPT_ERROR (-1)
153 typedef struct berelement BerElement;
154 typedef struct sockbuf Sockbuf;
155 typedef struct seqorset Seqorset;
157 typedef struct sockbuf_io Sockbuf_IO;
159 /* Structure for LBER IO operarion descriptor */
160 typedef struct sockbuf_io_desc {
163 Sockbuf_IO *sbiod_io;
165 struct sockbuf_io_desc *sbiod_next;
168 /* Structure for LBER IO operation functions */
170 int (*sbi_setup)( Sockbuf_IO_Desc *sbiod, void *arg );
171 int (*sbi_remove)( Sockbuf_IO_Desc *sbiod );
172 int (*sbi_ctrl)( Sockbuf_IO_Desc *sbiod, int opt, void *arg);
174 ber_slen_t (*sbi_read)( Sockbuf_IO_Desc *sbiod, void *buf,
176 ber_slen_t (*sbi_write)( Sockbuf_IO_Desc *sbiod, void *buf,
179 int (*sbi_close)( Sockbuf_IO_Desc *sbiod );
182 /* Helper macros for LBER IO functions */
183 #define LBER_SBIOD_READ_NEXT( sbiod, buf, len ) \
184 ( (sbiod)->sbiod_next->sbiod_io->sbi_read( (sbiod)->sbiod_next, \
186 #define LBER_SBIOD_WRITE_NEXT( sbiod, buf, len ) \
187 ( (sbiod)->sbiod_next->sbiod_io->sbi_write( (sbiod)->sbiod_next, \
189 #define LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg ) \
190 ( (sbiod)->sbiod_next ? \
191 ( (sbiod)->sbiod_next->sbiod_io->sbi_ctrl( \
192 (sbiod)->sbiod_next, opt, arg ) ) : 0 )
194 /* structure for returning a sequence of octet strings + length */
195 typedef struct berval {
200 /* this should be moved to lber-int.h */
206 ber_error_print LDAP_P((
207 LDAP_CONST char *data ));
211 LDAP_CONST char *data, ber_len_t len ));
215 BerElement *ber, int inout ));
218 ber_sos_dump LDAP_P((
225 typedef int (*BERDecodeCallback) LDAP_P((
230 LIBLBER_F( ber_tag_t )
234 LIBLBER_F( ber_tag_t )
235 ber_skip_tag LDAP_P((
239 LIBLBER_F( ber_tag_t )
240 ber_peek_tag LDAP_P((
244 LIBLBER_F( ber_tag_t )
249 LIBLBER_F( ber_tag_t )
250 ber_get_enum LDAP_P((
254 LIBLBER_F( ber_tag_t )
255 ber_get_stringb LDAP_P((
260 LIBLBER_F( ber_tag_t )
261 ber_get_stringa LDAP_P((
265 LIBLBER_F( ber_tag_t )
266 ber_get_stringal LDAP_P((
268 struct berval **bv ));
270 LIBLBER_F( ber_tag_t )
271 ber_get_bitstringa LDAP_P((
276 LIBLBER_F( ber_tag_t )
277 ber_get_null LDAP_P((
280 LIBLBER_F( ber_tag_t )
281 ber_get_boolean LDAP_P((
283 ber_int_t *boolval ));
285 LIBLBER_F( ber_tag_t )
286 ber_first_element LDAP_P((
291 LIBLBER_F( ber_tag_t )
292 ber_next_element LDAP_P((
295 LDAP_CONST char *last ));
297 LIBLBER_F( ber_tag_t )
300 LDAP_CONST char *fmt,
306 typedef int (*BEREncodeCallback) LDAP_P((
311 ber_put_enum LDAP_P((
323 ber_put_ostring LDAP_P((
325 LDAP_CONST char *str,
330 ber_put_berval LDAP_P((
332 LDAP_CONST struct berval *bv,
336 ber_put_string LDAP_P((
338 LDAP_CONST char *str,
342 ber_put_bitstring LDAP_P((
344 LDAP_CONST char *str,
349 ber_put_null LDAP_P((
354 ber_put_boolean LDAP_P((
360 ber_start_seq LDAP_P((
365 ber_start_set LDAP_P((
380 LDAP_CONST char *fmt,
388 LIBLBER_F( ber_slen_t )
394 LIBLBER_F( ber_slen_t )
397 LDAP_CONST char *buf,
412 LIBLBER_F( BerElement * )
413 ber_alloc LDAP_P(( void )); /* DEPRECATED */
415 LIBLBER_F( BerElement * )
416 der_alloc LDAP_P(( void )); /* DEPRECATED */
418 LIBLBER_F( BerElement * )
422 LIBLBER_F( BerElement * )
426 LIBLBER_F( ber_tag_t )
427 ber_get_next LDAP_P((
433 ber_init_w_nullc LDAP_P((
442 LIBLBER_F( BerElement * )
444 struct berval *bv ));
449 struct berval **bvPtr ));
452 * LBER ber accessor functions
456 ber_get_option LDAP_P((
462 ber_set_option LDAP_P((
465 LDAP_CONST void *invalue));
471 LIBLBER_F( Sockbuf * )
472 ber_sockbuf_alloc LDAP_P((
476 ber_sockbuf_free LDAP_P((
480 ber_sockbuf_add_io LDAP_P((
487 ber_sockbuf_remove_io LDAP_P((
493 ber_sockbuf_ctrl LDAP_P((
498 LIBLBER_F( Sockbuf_IO ) ber_sockbuf_io_tcp;
499 LIBLBER_F( Sockbuf_IO ) ber_sockbuf_io_udp;
500 LIBLBER_F( Sockbuf_IO ) ber_sockbuf_io_readahead;
501 LIBLBER_F( Sockbuf_IO ) ber_sockbuf_io_fd;
502 LIBLBER_F( Sockbuf_IO ) ber_sockbuf_io_debug;
508 ber_memalloc LDAP_P((
512 ber_memrealloc LDAP_P((
517 ber_memcalloc LDAP_P((
526 ber_memvfree LDAP_P((
531 struct berval *bv ));
534 ber_bvecfree LDAP_P((
535 struct berval **bv ));
539 struct berval ***bvec,
540 struct berval *bv ));
542 LIBLBER_F( struct berval * )
544 LDAP_CONST struct berval *bv ));
546 LIBLBER_F( struct berval * )
548 LDAP_CONST char * ));
550 LIBLBER_F( struct berval * )
551 ber_bvstrdup LDAP_P((
552 LDAP_CONST char * ));
556 LDAP_CONST char * ));
561 LIBLBER_F( int * ) ber_errno_addr LDAP_P((void));
562 #define ber_errno (*(ber_errno_addr)())
564 #define LBER_ERROR_NONE 0
565 #define LBER_ERROR_PARAM 0x1
566 #define LBER_ERROR_MEMORY 0x2