Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / include / lber.h
blob3851fb52181eb7a1c553472641491ed02b5d6b76
1 /* $OpenLDAP: pkg/ldap/include/lber.h,v 1.99.2.4 2008/02/11 23:26:40 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
11 * A copy of this license is available in file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
16 * All rights reserved.
18 * Redistribution and use in source and binary forms are permitted
19 * provided that this notice is preserved and that due credit is given
20 * to the University of Michigan at Ann Arbor. The name of the University
21 * may not be used to endorse or promote products derived from this
22 * software without specific prior written permission. This software
23 * is provided ``as is'' without express or implied warranty.
26 #ifndef _LBER_H
27 #define _LBER_H
29 #include <lber_types.h>
30 #include <string.h>
32 LDAP_BEGIN_DECL
34 /* Overview of LBER tag construction
36 * Bits
37 * ______
38 * 8 7 | CLASS
39 * 0 0 = UNIVERSAL
40 * 0 1 = APPLICATION
41 * 1 0 = CONTEXT-SPECIFIC
42 * 1 1 = PRIVATE
43 * _____
44 * | 6 | DATA-TYPE
45 * 0 = PRIMITIVE
46 * 1 = CONSTRUCTED
47 * ___________
48 * | 5 ... 1 | TAG-NUMBER
51 /* BER classes and mask */
52 #define LBER_CLASS_UNIVERSAL ((ber_tag_t) 0x00U)
53 #define LBER_CLASS_APPLICATION ((ber_tag_t) 0x40U)
54 #define LBER_CLASS_CONTEXT ((ber_tag_t) 0x80U)
55 #define LBER_CLASS_PRIVATE ((ber_tag_t) 0xc0U)
56 #define LBER_CLASS_MASK ((ber_tag_t) 0xc0U)
58 /* BER encoding type and mask */
59 #define LBER_PRIMITIVE ((ber_tag_t) 0x00U)
60 #define LBER_CONSTRUCTED ((ber_tag_t) 0x20U)
61 #define LBER_ENCODING_MASK ((ber_tag_t) 0x20U)
63 #define LBER_BIG_TAG_MASK ((ber_tag_t) 0x1fU)
64 #define LBER_MORE_TAG_MASK ((ber_tag_t) 0x80U)
67 * Note that LBER_ERROR and LBER_DEFAULT are values that can never appear
68 * as valid BER tags, and so it is safe to use them to report errors. In
69 * fact, any tag for which the following is true is invalid:
71 #define LBER_INVALID(t) (((t) & (ber_tag_t) 0x080UL) \
72 && (((t) & (ber_tag_t) ~ 0x0FF))
74 #define LBER_ERROR ((ber_tag_t) -1)
75 #define LBER_DEFAULT ((ber_tag_t) -1)
77 /* general BER types we know about */
78 #define LBER_BOOLEAN ((ber_tag_t) 0x01UL)
79 #define LBER_INTEGER ((ber_tag_t) 0x02UL)
80 #define LBER_BITSTRING ((ber_tag_t) 0x03UL)
81 #define LBER_OCTETSTRING ((ber_tag_t) 0x04UL)
82 #define LBER_NULL ((ber_tag_t) 0x05UL)
83 #define LBER_ENUMERATED ((ber_tag_t) 0x0aUL)
84 #define LBER_SEQUENCE ((ber_tag_t) 0x30UL) /* constructed */
85 #define LBER_SET ((ber_tag_t) 0x31UL) /* constructed */
87 /* LBER BerElement options */
88 #define LBER_USE_DER 0x01
90 /* get/set options for BerElement */
91 #define LBER_OPT_BER_OPTIONS 0x01
92 #define LBER_OPT_BER_DEBUG 0x02
93 #define LBER_OPT_BER_REMAINING_BYTES 0x03
94 #define LBER_OPT_BER_TOTAL_BYTES 0x04
95 #define LBER_OPT_BER_BYTES_TO_WRITE 0x05
96 #define LBER_OPT_BER_MEMCTX 0x06
98 #define LBER_OPT_DEBUG_LEVEL LBER_OPT_BER_DEBUG
99 #define LBER_OPT_REMAINING_BYTES LBER_OPT_BER_REMAINING_BYTES
100 #define LBER_OPT_TOTAL_BYTES LBER_OPT_BER_TOTAL_BYTES
101 #define LBER_OPT_BYTES_TO_WRITE LBER_OPT_BER_BYTES_TO_WRITE
103 #define LBER_OPT_LOG_PRINT_FN 0x8001
104 #define LBER_OPT_MEMORY_FNS 0x8002
105 #define LBER_OPT_ERROR_FN 0x8003
106 #define LBER_OPT_LOG_PRINT_FILE 0x8004
108 /* get/set Memory Debug options */
109 #define LBER_OPT_MEMORY_INUSE 0x8005 /* for memory debugging */
110 #define LBER_OPT_LOG_PROC 0x8006 /* for external logging function */
112 typedef int* (*BER_ERRNO_FN) LDAP_P(( void ));
114 typedef void (*BER_LOG_PRINT_FN) LDAP_P(( LDAP_CONST char *buf ));
116 typedef void* (BER_MEMALLOC_FN) LDAP_P(( ber_len_t size, void *ctx ));
117 typedef void* (BER_MEMCALLOC_FN) LDAP_P(( ber_len_t n, ber_len_t size, void *ctx ));
118 typedef void* (BER_MEMREALLOC_FN) LDAP_P(( void *p, ber_len_t size, void *ctx ));
119 typedef void (BER_MEMFREE_FN) LDAP_P(( void *p, void *ctx ));
121 typedef struct lber_memory_fns {
122 BER_MEMALLOC_FN *bmf_malloc;
123 BER_MEMCALLOC_FN *bmf_calloc;
124 BER_MEMREALLOC_FN *bmf_realloc;
125 BER_MEMFREE_FN *bmf_free;
126 } BerMemoryFunctions;
128 /* LBER Sockbuf_IO options */
129 #define LBER_SB_OPT_GET_FD 1
130 #define LBER_SB_OPT_SET_FD 2
131 #define LBER_SB_OPT_HAS_IO 3
132 #define LBER_SB_OPT_SET_NONBLOCK 4
133 #define LBER_SB_OPT_GET_SSL 7
134 #define LBER_SB_OPT_DATA_READY 8
135 #define LBER_SB_OPT_SET_READAHEAD 9
136 #define LBER_SB_OPT_DRAIN 10
137 #define LBER_SB_OPT_NEEDS_READ 11
138 #define LBER_SB_OPT_NEEDS_WRITE 12
139 #define LBER_SB_OPT_GET_MAX_INCOMING 13
140 #define LBER_SB_OPT_SET_MAX_INCOMING 14
142 /* Only meaningful ifdef LDAP_PF_LOCAL_SENDMSG */
143 #define LBER_SB_OPT_UNGET_BUF 15
145 /* Largest option used by the library */
146 #define LBER_SB_OPT_OPT_MAX 15
148 /* LBER IO operations stacking levels */
149 #define LBER_SBIOD_LEVEL_PROVIDER 10
150 #define LBER_SBIOD_LEVEL_TRANSPORT 20
151 #define LBER_SBIOD_LEVEL_APPLICATION 30
153 /* get/set options for Sockbuf */
154 #define LBER_OPT_SOCKBUF_DESC 0x1000
155 #define LBER_OPT_SOCKBUF_OPTIONS 0x1001
156 #define LBER_OPT_SOCKBUF_DEBUG 0x1002
158 /* on/off values */
159 LBER_V( char ) ber_pvt_opt_on;
160 #define LBER_OPT_ON ((void *) &ber_pvt_opt_on)
161 #define LBER_OPT_OFF ((void *) 0)
163 #define LBER_OPT_SUCCESS (0)
164 #define LBER_OPT_ERROR (-1)
166 typedef struct berelement BerElement;
167 typedef struct sockbuf Sockbuf;
168 typedef struct seqorset Seqorset;
170 typedef struct sockbuf_io Sockbuf_IO;
172 /* Structure for LBER IO operarion descriptor */
173 typedef struct sockbuf_io_desc {
174 int sbiod_level;
175 Sockbuf *sbiod_sb;
176 Sockbuf_IO *sbiod_io;
177 void *sbiod_pvt;
178 struct sockbuf_io_desc *sbiod_next;
179 } Sockbuf_IO_Desc;
181 /* Structure for LBER IO operation functions */
182 struct sockbuf_io {
183 int (*sbi_setup)( Sockbuf_IO_Desc *sbiod, void *arg );
184 int (*sbi_remove)( Sockbuf_IO_Desc *sbiod );
185 int (*sbi_ctrl)( Sockbuf_IO_Desc *sbiod, int opt, void *arg);
187 ber_slen_t (*sbi_read)( Sockbuf_IO_Desc *sbiod, void *buf,
188 ber_len_t len );
189 ber_slen_t (*sbi_write)( Sockbuf_IO_Desc *sbiod, void *buf,
190 ber_len_t len );
192 int (*sbi_close)( Sockbuf_IO_Desc *sbiod );
195 /* Helper macros for LBER IO functions */
196 #define LBER_SBIOD_READ_NEXT( sbiod, buf, len ) \
197 ( (sbiod)->sbiod_next->sbiod_io->sbi_read( (sbiod)->sbiod_next, \
198 buf, len ) )
199 #define LBER_SBIOD_WRITE_NEXT( sbiod, buf, len ) \
200 ( (sbiod)->sbiod_next->sbiod_io->sbi_write( (sbiod)->sbiod_next, \
201 buf, len ) )
202 #define LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg ) \
203 ( (sbiod)->sbiod_next ? \
204 ( (sbiod)->sbiod_next->sbiod_io->sbi_ctrl( \
205 (sbiod)->sbiod_next, opt, arg ) ) : 0 )
207 /* structure for returning a sequence of octet strings + length */
208 typedef struct berval {
209 ber_len_t bv_len;
210 char *bv_val;
211 } BerValue;
213 typedef BerValue *BerVarray; /* To distinguish from a single bv */
215 /* this should be moved to lber-int.h */
218 * in bprint.c:
220 LBER_F( void )
221 ber_error_print LDAP_P((
222 LDAP_CONST char *data ));
224 LBER_F( void )
225 ber_bprint LDAP_P((
226 LDAP_CONST char *data, ber_len_t len ));
228 LBER_F( void )
229 ber_dump LDAP_P((
230 BerElement *ber, int inout ));
232 LBER_F( void )
233 ber_sos_dump LDAP_P((
234 Seqorset *sos ));
237 * in decode.c:
239 typedef int (*BERDecodeCallback) LDAP_P((
240 BerElement *ber,
241 void *data,
242 int mode ));
244 LBER_F( ber_tag_t )
245 ber_get_tag LDAP_P((
246 BerElement *ber ));
248 LBER_F( ber_tag_t )
249 ber_skip_tag LDAP_P((
250 BerElement *ber,
251 ber_len_t *len ));
253 LBER_F( ber_tag_t )
254 ber_peek_tag LDAP_P((
255 BerElement *ber,
256 ber_len_t *len ));
258 LBER_F( ber_tag_t )
259 ber_get_int LDAP_P((
260 BerElement *ber,
261 ber_int_t *num ));
263 LBER_F( ber_tag_t )
264 ber_get_enum LDAP_P((
265 BerElement *ber,
266 ber_int_t *num ));
268 LBER_F( ber_tag_t )
269 ber_get_stringb LDAP_P((
270 BerElement *ber,
271 char *buf,
272 ber_len_t *len ));
274 #define LBER_BV_ALLOC 0x01 /* allocate/copy result, otherwise in-place */
275 #define LBER_BV_NOTERM 0x02 /* omit NUL-terminator if parsing in-place */
277 LBER_F( ber_tag_t )
278 ber_get_stringbv LDAP_P((
279 BerElement *ber,
280 struct berval *bv,
281 int options ));
283 LBER_F( ber_tag_t )
284 ber_get_stringa LDAP_P((
285 BerElement *ber,
286 char **buf ));
288 LBER_F( ber_tag_t )
289 ber_get_stringal LDAP_P((
290 BerElement *ber,
291 struct berval **bv ));
293 LBER_F( ber_tag_t )
294 ber_get_bitstringa LDAP_P((
295 BerElement *ber,
296 char **buf,
297 ber_len_t *len ));
299 LBER_F( ber_tag_t )
300 ber_get_null LDAP_P((
301 BerElement *ber ));
303 LBER_F( ber_tag_t )
304 ber_get_boolean LDAP_P((
305 BerElement *ber,
306 ber_int_t *boolval ));
308 LBER_F( ber_tag_t )
309 ber_first_element LDAP_P((
310 BerElement *ber,
311 ber_len_t *len,
312 char **last ));
314 LBER_F( ber_tag_t )
315 ber_next_element LDAP_P((
316 BerElement *ber,
317 ber_len_t *len,
318 LDAP_CONST char *last ));
320 LBER_F( ber_tag_t )
321 ber_scanf LDAP_P((
322 BerElement *ber,
323 LDAP_CONST char *fmt,
324 ... ));
326 LBER_F( int )
327 ber_decode_oid LDAP_P((
328 struct berval *in,
329 struct berval *out ));
332 * in encode.c
334 LBER_F( int )
335 ber_encode_oid LDAP_P((
336 struct berval *in,
337 struct berval *out ));
339 typedef int (*BEREncodeCallback) LDAP_P((
340 BerElement *ber,
341 void *data ));
343 LBER_F( int )
344 ber_put_enum LDAP_P((
345 BerElement *ber,
346 ber_int_t num,
347 ber_tag_t tag ));
349 LBER_F( int )
350 ber_put_int LDAP_P((
351 BerElement *ber,
352 ber_int_t num,
353 ber_tag_t tag ));
355 LBER_F( int )
356 ber_put_ostring LDAP_P((
357 BerElement *ber,
358 LDAP_CONST char *str,
359 ber_len_t len,
360 ber_tag_t tag ));
362 LBER_F( int )
363 ber_put_berval LDAP_P((
364 BerElement *ber,
365 struct berval *bv,
366 ber_tag_t tag ));
368 LBER_F( int )
369 ber_put_string LDAP_P((
370 BerElement *ber,
371 LDAP_CONST char *str,
372 ber_tag_t tag ));
374 LBER_F( int )
375 ber_put_bitstring LDAP_P((
376 BerElement *ber,
377 LDAP_CONST char *str,
378 ber_len_t bitlen,
379 ber_tag_t tag ));
381 LBER_F( int )
382 ber_put_null LDAP_P((
383 BerElement *ber,
384 ber_tag_t tag ));
386 LBER_F( int )
387 ber_put_boolean LDAP_P((
388 BerElement *ber,
389 ber_int_t boolval,
390 ber_tag_t tag ));
392 LBER_F( int )
393 ber_start_seq LDAP_P((
394 BerElement *ber,
395 ber_tag_t tag ));
397 LBER_F( int )
398 ber_start_set LDAP_P((
399 BerElement *ber,
400 ber_tag_t tag ));
402 LBER_F( int )
403 ber_put_seq LDAP_P((
404 BerElement *ber ));
406 LBER_F( int )
407 ber_put_set LDAP_P((
408 BerElement *ber ));
410 LBER_F( int )
411 ber_printf LDAP_P((
412 BerElement *ber,
413 LDAP_CONST char *fmt,
414 ... ));
418 * in io.c:
421 LBER_F( ber_slen_t )
422 ber_skip_data LDAP_P((
423 BerElement *ber,
424 ber_len_t len ));
426 LBER_F( ber_slen_t )
427 ber_read LDAP_P((
428 BerElement *ber,
429 char *buf,
430 ber_len_t len ));
432 LBER_F( ber_slen_t )
433 ber_write LDAP_P((
434 BerElement *ber,
435 LDAP_CONST char *buf,
436 ber_len_t len,
437 int nosos ));
439 LBER_F( void )
440 ber_free LDAP_P((
441 BerElement *ber,
442 int freebuf ));
444 LBER_F( void )
445 ber_free_buf LDAP_P(( BerElement *ber ));
447 LBER_F( int )
448 ber_flush2 LDAP_P((
449 Sockbuf *sb,
450 BerElement *ber,
451 int freeit ));
452 #define LBER_FLUSH_FREE_NEVER (0x0) /* traditional behavior */
453 #define LBER_FLUSH_FREE_ON_SUCCESS (0x1) /* traditional behavior */
454 #define LBER_FLUSH_FREE_ON_ERROR (0x2)
455 #define LBER_FLUSH_FREE_ALWAYS (LBER_FLUSH_FREE_ON_SUCCESS|LBER_FLUSH_FREE_ON_ERROR)
457 LBER_F( int )
458 ber_flush LDAP_P((
459 Sockbuf *sb,
460 BerElement *ber,
461 int freeit )); /* DEPRECATED */
463 LBER_F( BerElement * )
464 ber_alloc LDAP_P(( void )); /* DEPRECATED */
466 LBER_F( BerElement * )
467 der_alloc LDAP_P(( void )); /* DEPRECATED */
469 LBER_F( BerElement * )
470 ber_alloc_t LDAP_P((
471 int beroptions ));
473 LBER_F( BerElement * )
474 ber_dup LDAP_P((
475 BerElement *ber ));
477 LBER_F( ber_tag_t )
478 ber_get_next LDAP_P((
479 Sockbuf *sb,
480 ber_len_t *len,
481 BerElement *ber ));
483 LBER_F( void )
484 ber_init2 LDAP_P((
485 BerElement *ber,
486 struct berval *bv,
487 int options ));
489 LBER_F( void )
490 ber_init_w_nullc LDAP_P(( /* DEPRECATED */
491 BerElement *ber,
492 int options ));
494 LBER_F( void )
495 ber_reset LDAP_P((
496 BerElement *ber,
497 int was_writing ));
499 LBER_F( BerElement * )
500 ber_init LDAP_P((
501 struct berval *bv ));
503 LBER_F( int )
504 ber_flatten LDAP_P((
505 BerElement *ber,
506 struct berval **bvPtr ));
508 LBER_F( int )
509 ber_flatten2 LDAP_P((
510 BerElement *ber,
511 struct berval *bv,
512 int alloc ));
514 LBER_F( int )
515 ber_remaining LDAP_P((
516 BerElement *ber ));
519 * LBER ber accessor functions
522 LBER_F( int )
523 ber_get_option LDAP_P((
524 void *item,
525 int option,
526 void *outvalue));
528 LBER_F( int )
529 ber_set_option LDAP_P((
530 void *item,
531 int option,
532 LDAP_CONST void *invalue));
535 * LBER sockbuf.c
538 LBER_F( Sockbuf * )
539 ber_sockbuf_alloc LDAP_P((
540 void ));
542 LBER_F( void )
543 ber_sockbuf_free LDAP_P((
544 Sockbuf *sb ));
546 LBER_F( int )
547 ber_sockbuf_add_io LDAP_P((
548 Sockbuf *sb,
549 Sockbuf_IO *sbio,
550 int layer,
551 void *arg ));
553 LBER_F( int )
554 ber_sockbuf_remove_io LDAP_P((
555 Sockbuf *sb,
556 Sockbuf_IO *sbio,
557 int layer ));
559 LBER_F( int )
560 ber_sockbuf_ctrl LDAP_P((
561 Sockbuf *sb,
562 int opt,
563 void *arg ));
565 LBER_V( Sockbuf_IO ) ber_sockbuf_io_tcp;
566 LBER_V( Sockbuf_IO ) ber_sockbuf_io_readahead;
567 LBER_V( Sockbuf_IO ) ber_sockbuf_io_fd;
568 LBER_V( Sockbuf_IO ) ber_sockbuf_io_debug;
569 LBER_V( Sockbuf_IO ) ber_sockbuf_io_udp;
572 * LBER memory.c
574 LBER_F( void * )
575 ber_memalloc LDAP_P((
576 ber_len_t s ));
578 LBER_F( void * )
579 ber_memrealloc LDAP_P((
580 void* p,
581 ber_len_t s ));
583 LBER_F( void * )
584 ber_memcalloc LDAP_P((
585 ber_len_t n,
586 ber_len_t s ));
588 LBER_F( void )
589 ber_memfree LDAP_P((
590 void* p ));
592 LBER_F( void )
593 ber_memvfree LDAP_P((
594 void** vector ));
596 LBER_F( void )
597 ber_bvfree LDAP_P((
598 struct berval *bv ));
600 LBER_F( void )
601 ber_bvecfree LDAP_P((
602 struct berval **bv ));
604 LBER_F( int )
605 ber_bvecadd LDAP_P((
606 struct berval ***bvec,
607 struct berval *bv ));
609 LBER_F( struct berval * )
610 ber_dupbv LDAP_P((
611 struct berval *dst, struct berval *src ));
613 LBER_F( struct berval * )
614 ber_bvdup LDAP_P((
615 struct berval *src ));
617 LBER_F( struct berval * )
618 ber_mem2bv LDAP_P((
619 LDAP_CONST char *, ber_len_t len, int duplicate, struct berval *bv));
621 LBER_F( struct berval * )
622 ber_str2bv LDAP_P((
623 LDAP_CONST char *, ber_len_t len, int duplicate, struct berval *bv));
625 #define ber_bvstr(a) ((ber_str2bv)((a), 0, 0, NULL))
626 #define ber_bvstrdup(a) ((ber_str2bv)((a), 0, 1, NULL))
628 LBER_F( char * )
629 ber_strdup LDAP_P((
630 LDAP_CONST char * ));
632 LBER_F( struct berval * )
633 ber_bvreplace LDAP_P((
634 struct berval *dst, LDAP_CONST struct berval *src ));
636 LBER_F( void )
637 ber_bvarray_free LDAP_P(( BerVarray p ));
639 LBER_F( int )
640 ber_bvarray_add LDAP_P(( BerVarray *p, BerValue *bv ));
642 #define ber_bvcmp(v1,v2) \
643 ((v1)->bv_len < (v2)->bv_len \
644 ? -1 : ((v1)->bv_len > (v2)->bv_len \
645 ? 1 : memcmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
648 * error.c
650 LBER_F( int * ) ber_errno_addr LDAP_P((void));
651 #define ber_errno (*(ber_errno_addr)())
653 #define LBER_ERROR_NONE 0
654 #define LBER_ERROR_PARAM 0x1
655 #define LBER_ERROR_MEMORY 0x2
657 LDAP_END_DECL
659 #endif /* _LBER_H */