]> git.sur5r.net Git - openldap/blob - include/lber.h
Update lber-encode/decode man pages
[openldap] / include / lber.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, Redwood City, California, USA
4  * All rights reserved.
5  *
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.
10  */
11 /* Portions
12  * Copyright (c) 1990 Regents of the University of Michigan.
13  * All rights reserved.
14  *
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.
21  */
22
23 #ifndef _LBER_H
24 #define _LBER_H
25
26 #include <lber_types.h>
27
28 LDAP_BEGIN_DECL
29
30 /* Overview of LBER tag construction
31  *
32  *      Bits
33  *      ______
34  *      8 7 | CLASS
35  *      0 0 = UNIVERSAL
36  *      0 1 = APPLICATION
37  *      1 0 = CONTEXT-SPECIFIC
38  *      1 1 = PRIVATE
39  *              _____
40  *              | 6 | DATA-TYPE
41  *                0 = PRIMITIVE
42  *                1 = CONSTRUCTED
43  *                      ___________
44  *                      | 5 ... 1 | TAG-NUMBER
45  */
46
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)
53
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)
58
59 #define LBER_BIG_TAG_MASK               ((ber_tag_t) 0x1fU)
60 #define LBER_MORE_TAG_MASK              ((ber_tag_t) 0x80U)
61
62 /*
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:
66  */
67 #define LBER_INVALID(t)     (((t) & (ber_tag_t) 0x080UL) \
68         && (((t) & (ber_tag_t) ~ 0x0FF))
69
70 #define LBER_ERROR                      ((ber_tag_t) -1)
71 #define LBER_DEFAULT            ((ber_tag_t) -1)
72
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 */
82
83 typedef int (*BERTranslateProc) LDAP_P((
84         char **bufp,
85         ber_len_t *buflenp,
86         int free_input ));
87
88 /* LBER BerElement options */
89 #define LBER_USE_DER            0x01
90 #define LBER_USE_INDEFINITE_LEN 0x02
91 #define LBER_TRANSLATE_STRINGS  0x04    /* deprecated */
92
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
99
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
104
105 #define LBER_OPT_LOG_PRINT_FN   0x8001
106 #define LBER_OPT_MEMORY_FNS             0x8002
107 #define LBER_OPT_ERROR_FN               0x8003
108 #define LBER_OPT_LOG_PRINT_FILE         0x8004
109
110 typedef int* (*BER_ERRNO_FN) LDAP_P(( void ));
111
112 typedef void (*BER_LOG_PRINT_FN) LDAP_P(( char *buf ));
113
114 typedef void* (*BER_MEMALLOC_FN)        LDAP_P(( ber_len_t size ));
115 typedef void* (*BER_MEMCALLOC_FN)       LDAP_P(( ber_len_t n, ber_len_t size ));
116 typedef void* (*BER_MEMREALLOC_FN)      LDAP_P(( void *p, ber_len_t size ));
117 typedef void  (*BER_MEMFREE_FN)         LDAP_P(( void *p ));
118
119 typedef struct lber_memory_fns {
120         BER_MEMALLOC_FN bmf_malloc;
121         BER_MEMCALLOC_FN bmf_calloc;
122         BER_MEMREALLOC_FN bmf_realloc;
123         BER_MEMFREE_FN bmf_free;
124 } BerMemoryFunctions;
125
126 /* LBER Sockbuf options */ 
127 #define LBER_TO_FILE           0x01     /* to a file referenced by sb_fd   */
128 #define LBER_TO_FILE_ONLY      0x02     /* only write to file, not network */
129 #define LBER_MAX_INCOMING_SIZE 0x04     /* impose limit on incoming stuff  */
130 #define LBER_NO_READ_AHEAD     0x08     /* read only as much as requested  */
131
132 /* get/set options for Sockbuf */
133 #define LBER_OPT_SOCKBUF_DESC           0x1000
134 #define LBER_OPT_SOCKBUF_OPTIONS        0x1001
135 #define LBER_OPT_SOCKBUF_DEBUG          0x1002
136
137 /* on/off values */
138 #define LBER_OPT_ON             ((void *) 1)
139 #define LBER_OPT_OFF    ((void *) 0)
140
141 #define LBER_OPT_SUCCESS        (0)
142 #define LBER_OPT_ERROR          (-1)
143
144 typedef struct berelement BerElement;
145 typedef struct sockbuf Sockbuf;
146 typedef struct seqorset Seqorset;
147
148 /* structure for returning a sequence of octet strings + length */
149 typedef struct berval {
150         ber_len_t       bv_len;
151         char            *bv_val;
152 } BerValue;
153
154 /* this should be moved to lber-int.h */
155
156 /*
157  * in bprint.c:
158  */
159 LIBLBER_F( void )
160 ber_print_error LDAP_P((
161         LDAP_CONST char *data ));
162
163 LIBLBER_F( void )
164 ber_bprint LDAP_P((
165         LDAP_CONST char *data, ber_len_t len ));
166
167 LIBLBER_F( void )
168 ber_dump LDAP_P((
169         BerElement *ber, int inout ));
170
171 LIBLBER_F( void )
172 ber_sos_dump LDAP_P((
173         Seqorset *sos ));
174
175
176 /*
177  * in decode.c:
178  */
179 typedef int (*BERDecodeCallback) LDAP_P((
180         BerElement *ber,
181         void *data,
182         int mode ));
183
184 LIBLBER_F( ber_tag_t )
185 ber_get_tag LDAP_P((
186         BerElement *ber ));
187
188 LIBLBER_F( ber_tag_t )
189 ber_skip_tag LDAP_P((
190         BerElement *ber,
191         ber_len_t *len ));
192
193 LIBLBER_F( ber_tag_t )
194 ber_peek_tag LDAP_P((
195         BerElement *ber,
196         ber_len_t *len ));
197
198 LIBLBER_F( ber_tag_t )
199 ber_get_int LDAP_P((
200         BerElement *ber,
201         ber_int_t *num ));
202
203 LIBLBER_F( ber_tag_t )
204 ber_get_enum LDAP_P((
205         BerElement *ber,
206         ber_int_t *num ));
207
208 LIBLBER_F( ber_tag_t )
209 ber_get_stringb LDAP_P((
210         BerElement *ber,
211         char *buf,
212         ber_len_t *len ));
213
214 LIBLBER_F( ber_tag_t )
215 ber_get_stringa LDAP_P((
216         BerElement *ber,
217         char **buf ));
218
219 LIBLBER_F( ber_tag_t )
220 ber_get_stringal LDAP_P((
221         BerElement *ber,
222         struct berval **bv ));
223
224 LIBLBER_F( ber_tag_t )
225 ber_get_bitstringa LDAP_P((
226         BerElement *ber,
227         char **buf,
228         ber_len_t *len ));
229
230 LIBLBER_F( ber_tag_t )
231 ber_get_null LDAP_P((
232         BerElement *ber ));
233
234 LIBLBER_F( ber_tag_t )
235 ber_get_boolean LDAP_P((
236         BerElement *ber,
237         ber_int_t *boolval ));
238
239 LIBLBER_F( ber_tag_t )
240 ber_first_element LDAP_P((
241         BerElement *ber,
242         ber_len_t *len,
243         char **last ));
244
245 LIBLBER_F( ber_tag_t )
246 ber_next_element LDAP_P((
247         BerElement *ber,
248         ber_len_t *len,
249         LDAP_CONST char *last ));
250
251 LIBLBER_F( ber_tag_t )
252 ber_scanf LDAP_P((                                                                
253         BerElement *ber,
254         LDAP_CONST char *fmt,
255         ... ));
256
257 LIBLBER_F( void )
258 ber_set_string_translators LDAP_P((
259         BerElement *ber,
260         BERTranslateProc encode_proc,
261         BERTranslateProc decode_proc ));
262
263 /*
264  * in encode.c
265  */
266 typedef int (*BEREncodeCallback) LDAP_P((
267         BerElement *ber,
268         void *data ));
269
270 LIBLBER_F( int )
271 ber_put_enum LDAP_P((
272         BerElement *ber,
273         ber_int_t num,
274         ber_tag_t tag ));
275
276 LIBLBER_F( int )
277 ber_put_int LDAP_P((
278         BerElement *ber,
279         ber_int_t num,
280         ber_tag_t tag ));
281
282 LIBLBER_F( int )
283 ber_put_ostring LDAP_P((
284         BerElement *ber,
285         LDAP_CONST char *str,
286         ber_len_t len,
287         ber_tag_t tag ));
288
289 LIBLBER_F( int )
290 ber_put_berval LDAP_P((
291         BerElement *ber,
292         LDAP_CONST struct berval *bv,
293         ber_tag_t tag ));
294
295 LIBLBER_F( int )
296 ber_put_string LDAP_P((
297         BerElement *ber,
298         LDAP_CONST char *str,
299         ber_tag_t tag ));
300
301 LIBLBER_F( int )
302 ber_put_bitstring LDAP_P((
303         BerElement *ber,
304         LDAP_CONST char *str,
305         ber_len_t bitlen,
306         ber_tag_t tag ));
307
308 LIBLBER_F( int )
309 ber_put_null LDAP_P((
310         BerElement *ber,
311         ber_tag_t tag ));
312
313 LIBLBER_F( int )
314 ber_put_boolean LDAP_P((
315         BerElement *ber,
316         ber_int_t boolval,
317         ber_tag_t tag ));
318
319 LIBLBER_F( int )
320 ber_start_seq LDAP_P((
321         BerElement *ber,
322         ber_tag_t tag ));
323
324 LIBLBER_F( int )
325 ber_start_set LDAP_P((
326         BerElement *ber,
327         ber_tag_t tag ));
328
329 LIBLBER_F( int )
330 ber_put_seq LDAP_P((
331         BerElement *ber ));
332
333 LIBLBER_F( int )
334 ber_put_set LDAP_P((
335         BerElement *ber ));
336
337 LIBLBER_F( int )
338 ber_printf LDAP_P((
339         BerElement *ber,
340         LDAP_CONST char *fmt,
341         ... ));
342
343
344 /*
345  * in io.c:
346  */
347
348 LIBLBER_F( ber_slen_t )
349 ber_read LDAP_P((
350         BerElement *ber,
351         char *buf,
352         ber_len_t len ));
353
354 LIBLBER_F( ber_slen_t )
355 ber_write LDAP_P((
356         BerElement *ber,
357         LDAP_CONST char *buf,
358         ber_len_t len,
359         int nosos ));
360
361 LIBLBER_F( void )
362 ber_free LDAP_P((
363         BerElement *ber,
364         int freebuf ));
365
366 LIBLBER_F( int )
367 ber_flush LDAP_P((
368         Sockbuf *sb,
369         BerElement *ber,
370         int freeit ));
371
372 LIBLBER_F( BerElement * )
373 ber_alloc LDAP_P(( void )); /* DEPRECATED */
374
375 LIBLBER_F( BerElement * )
376 der_alloc LDAP_P(( void )); /* DEPRECATED */
377
378 LIBLBER_F( BerElement * )
379 ber_alloc_t LDAP_P((
380         int beroptions ));
381
382 LIBLBER_F( BerElement * )
383 ber_dup LDAP_P((
384         BerElement *ber ));
385
386 LIBLBER_F( ber_tag_t )
387 ber_get_next LDAP_P((
388         Sockbuf *sb,
389         ber_len_t *len,
390         BerElement *ber ));
391
392 LIBLBER_F( void )
393 ber_init_w_nullc LDAP_P((
394         BerElement *ber,
395         int options ));
396
397 LIBLBER_F( void )
398 ber_reset LDAP_P((
399         BerElement *ber,
400         int was_writing ));
401
402 LIBLBER_F( BerElement * )
403 ber_init LDAP_P((
404         struct berval *bv ));
405
406 LIBLBER_F( int )
407 ber_flatten LDAP_P((
408         BerElement *ber,
409         struct berval **bvPtr ));
410
411 /*
412  * LBER ber accessor functions
413  */
414
415 LIBLBER_F( int )
416 ber_get_option LDAP_P((
417         void *item,
418         int option,
419         void *outvalue));
420
421 LIBLBER_F( int )
422 ber_set_option LDAP_P((
423         void *item,
424         int option,
425         LDAP_CONST void *invalue));
426
427 /*
428  * LBER sockbuf.c
429  */
430
431 LIBLBER_F( Sockbuf * )
432 ber_sockbuf_alloc( void );
433
434 LIBLBER_F( Sockbuf *  )
435 ber_sockbuf_alloc_fd(
436         ber_socket_t fd );
437
438 LIBLBER_F( void )
439 ber_sockbuf_free(
440         Sockbuf *sb );
441
442 /*
443  * LBER memory.c
444  */
445 LIBLBER_F( void * )
446 ber_memalloc LDAP_P((
447         ber_len_t s ));
448
449 LIBLBER_F( void * )
450 ber_memrealloc LDAP_P((
451         void* p,
452         ber_len_t s ));
453
454 LIBLBER_F( void * )
455 ber_memcalloc LDAP_P((
456         ber_len_t n,
457         ber_len_t s ));
458
459 LIBLBER_F( void )
460 ber_memfree LDAP_P((
461         void* p ));
462
463 LIBLBER_F( void )
464 ber_memvfree LDAP_P((
465         void** vector ));
466
467 LIBLBER_F( void )
468 ber_bvfree LDAP_P((
469         struct berval *bv ));
470
471 LIBLBER_F( void )
472 ber_bvecfree LDAP_P((
473         struct berval **bv ));
474
475 LIBLBER_F( int )
476 ber_bvecadd LDAP_P((
477         struct berval ***bvec,
478         struct berval *bv ));
479
480 LIBLBER_F( struct berval * )
481 ber_bvdup LDAP_P((
482         LDAP_CONST struct berval *bv ));
483
484 LIBLBER_F( struct berval * )
485 ber_bvstr LDAP_P((
486         LDAP_CONST char * ));
487
488 LIBLBER_F( struct berval * )
489 ber_bvstrdup LDAP_P((
490         LDAP_CONST char * ));
491
492 LIBLBER_F( char * )
493 ber_strdup LDAP_P((
494         LDAP_CONST char * ));
495
496 /*
497  * error.c
498  */
499 LIBLBER_F( int * ) ber_errno_addr LDAP_P((void));
500 #define ber_errno (*(ber_errno_addr)())
501
502 #define LBER_ERROR_NONE         0
503 #define LBER_ERROR_PARAM        0x1
504 #define LBER_ERROR_MEMORY       0x2
505
506 LDAP_END_DECL
507
508 #endif /* _LBER_H */