]> git.sur5r.net Git - openldap/blob - include/lber.h
d85ec9f38b0758a512216faf16c7a96f1cb50140
[openldap] / include / lber.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998,1999 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
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
109 typedef int* (*BER_ERRNO_FN) LDAP_P(( void ));
110
111 typedef void (*BER_LOG_PRINT_FN) LDAP_P(( char *buf ));
112
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 ));
117
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;
124
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  */
130
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
135
136 /* on/off values */
137 #define LBER_OPT_ON             ((void *) 1)
138 #define LBER_OPT_OFF    ((void *) 0)
139
140 #define LBER_OPT_SUCCESS        (0)
141 #define LBER_OPT_ERROR          (-1)
142
143 typedef struct berelement BerElement;
144 typedef struct sockbuf Sockbuf;
145 typedef struct seqorset Seqorset;
146
147 /* structure for returning a sequence of octet strings + length */
148 typedef struct berval {
149         ber_len_t       bv_len;
150         char            *bv_val;
151 } BerValue;
152
153 /* this should be moved to lber-int.h */
154
155 /*
156  * in bprint.c:
157  */
158 LIBLBER_F( void )
159 ber_print_error LDAP_P((
160         LDAP_CONST char *data ));
161
162 LIBLBER_F( void )
163 ber_bprint LDAP_P((
164         LDAP_CONST char *data, ber_len_t len ));
165
166 LIBLBER_F( void )
167 ber_dump LDAP_P((
168         BerElement *ber, int inout ));
169
170 LIBLBER_F( void )
171 ber_sos_dump LDAP_P((
172         Seqorset *sos ));
173
174
175 /*
176  * in decode.c:
177  */
178 typedef int (*BERDecodeCallback) LDAP_P((
179         BerElement *ber,
180         void *data,
181         int mode ));
182
183 LIBLBER_F( ber_tag_t )
184 ber_get_tag LDAP_P((
185         BerElement *ber ));
186
187 LIBLBER_F( ber_tag_t )
188 ber_skip_tag LDAP_P((
189         BerElement *ber,
190         ber_len_t *len ));
191
192 LIBLBER_F( ber_tag_t )
193 ber_peek_tag LDAP_P((
194         BerElement *ber,
195         ber_len_t *len ));
196
197 LIBLBER_F( ber_tag_t )
198 ber_get_int LDAP_P((
199         BerElement *ber,
200         ber_int_t *num ));
201
202 LIBLBER_F( ber_tag_t )
203 ber_get_stringb LDAP_P((
204         BerElement *ber,
205         char *buf,
206         ber_len_t *len ));
207
208 LIBLBER_F( ber_tag_t )
209 ber_get_stringa LDAP_P((
210         BerElement *ber,
211         char **buf ));
212
213 LIBLBER_F( ber_tag_t )
214 ber_get_stringal LDAP_P((
215         BerElement *ber,
216         struct berval **bv ));
217
218 LIBLBER_F( ber_tag_t )
219 ber_get_bitstringa LDAP_P((
220         BerElement *ber,
221         char **buf,
222         ber_len_t *len ));
223
224 LIBLBER_F( ber_tag_t )
225 ber_get_null LDAP_P((
226         BerElement *ber ));
227
228 LIBLBER_F( ber_tag_t )
229 ber_get_boolean LDAP_P((
230         BerElement *ber,
231         ber_int_t *boolval ));
232
233 LIBLBER_F( ber_tag_t )
234 ber_first_element LDAP_P((
235         BerElement *ber,
236         ber_len_t *len,
237         char **last ));
238
239 LIBLBER_F( ber_tag_t )
240 ber_next_element LDAP_P((
241         BerElement *ber,
242         ber_len_t *len,
243         LDAP_CONST char *last ));
244
245 LIBLBER_F( ber_tag_t )
246 ber_scanf LDAP_P((                                                                
247         BerElement *ber,
248         LDAP_CONST char *fmt,
249         ... ));
250
251 LIBLBER_F( void )
252 ber_set_string_translators LDAP_P((
253         BerElement *ber,
254         BERTranslateProc encode_proc,
255         BERTranslateProc decode_proc ));
256
257 /*
258  * in encode.c
259  */
260 typedef int (*BEREncodeCallback) LDAP_P((
261         BerElement *ber,
262         void *data ));
263
264 LIBLBER_F( int )
265 ber_put_enum LDAP_P((
266         BerElement *ber,
267         ber_int_t num,
268         ber_tag_t tag ));
269
270 LIBLBER_F( int )
271 ber_put_int LDAP_P((
272         BerElement *ber,
273         ber_int_t num,
274         ber_tag_t tag ));
275
276 LIBLBER_F( int )
277 ber_put_ostring LDAP_P((
278         BerElement *ber,
279         LDAP_CONST char *str,
280         ber_len_t len,
281         ber_tag_t tag ));
282
283 LIBLBER_F( int )
284 ber_put_berval LDAP_P((
285         BerElement *ber,
286         LDAP_CONST struct berval *bv,
287         ber_tag_t tag ));
288
289 LIBLBER_F( int )
290 ber_put_string LDAP_P((
291         BerElement *ber,
292         LDAP_CONST char *str,
293         ber_tag_t tag ));
294
295 LIBLBER_F( int )
296 ber_put_bitstring LDAP_P((
297         BerElement *ber,
298         LDAP_CONST char *str,
299         ber_len_t bitlen,
300         ber_tag_t tag ));
301
302 LIBLBER_F( int )
303 ber_put_null LDAP_P((
304         BerElement *ber,
305         ber_tag_t tag ));
306
307 LIBLBER_F( int )
308 ber_put_boolean LDAP_P((
309         BerElement *ber,
310         ber_int_t boolval,
311         ber_tag_t tag ));
312
313 LIBLBER_F( int )
314 ber_start_seq LDAP_P((
315         BerElement *ber,
316         ber_tag_t tag ));
317
318 LIBLBER_F( int )
319 ber_start_set LDAP_P((
320         BerElement *ber,
321         ber_tag_t tag ));
322
323 LIBLBER_F( int )
324 ber_put_seq LDAP_P((
325         BerElement *ber ));
326
327 LIBLBER_F( int )
328 ber_put_set LDAP_P((
329         BerElement *ber ));
330
331 LIBLBER_F( int )
332 ber_printf LDAP_P((
333         BerElement *ber,
334         LDAP_CONST char *fmt,
335         ... ));
336
337
338 /*
339  * in io.c:
340  */
341
342 LIBLBER_F( ber_slen_t )
343 ber_read LDAP_P((
344         BerElement *ber,
345         char *buf,
346         ber_len_t len ));
347
348 LIBLBER_F( ber_slen_t )
349 ber_write LDAP_P((
350         BerElement *ber,
351         LDAP_CONST char *buf,
352         ber_len_t len,
353         int nosos ));
354
355 LIBLBER_F( void )
356 ber_free LDAP_P((
357         BerElement *ber,
358         int freebuf ));
359
360 LIBLBER_F( int )
361 ber_flush LDAP_P((
362         Sockbuf *sb,
363         BerElement *ber,
364         int freeit ));
365
366 LIBLBER_F( BerElement * )
367 ber_alloc LDAP_P(( void )); /* DEPRECATED */
368
369 LIBLBER_F( BerElement * )
370 der_alloc LDAP_P(( void )); /* DEPRECATED */
371
372 LIBLBER_F( BerElement * )
373 ber_alloc_t LDAP_P((
374         int beroptions ));
375
376 LIBLBER_F( BerElement * )
377 ber_dup LDAP_P((
378         BerElement *ber ));
379
380 LIBLBER_F( ber_tag_t )
381 ber_get_next LDAP_P((
382         Sockbuf *sb,
383         ber_len_t *len,
384         BerElement *ber ));
385
386 LIBLBER_F( void )
387 ber_init_w_nullc LDAP_P((
388         BerElement *ber,
389         int options ));
390
391 LIBLBER_F( void )
392 ber_reset LDAP_P((
393         BerElement *ber,
394         int was_writing ));
395
396 LIBLBER_F( BerElement * )
397 ber_init LDAP_P((
398         struct berval *bv ));
399
400 LIBLBER_F( int )
401 ber_flatten LDAP_P((
402         BerElement *ber,
403         struct berval **bvPtr ));
404
405 /*
406  * LBER ber accessor functions
407  */
408
409 LIBLBER_F( int )
410 ber_get_option LDAP_P((
411         void *item,
412         int option,
413         void *outvalue));
414
415 LIBLBER_F( int )
416 ber_set_option LDAP_P((
417         void *item,
418         int option,
419         LDAP_CONST void *invalue));
420
421 /*
422  * LBER sockbuf.c
423  */
424
425 LIBLBER_F( Sockbuf * )
426 ber_sockbuf_alloc( void );
427
428 LIBLBER_F( Sockbuf *  )
429 ber_sockbuf_alloc_fd(
430         ber_socket_t fd );
431
432 LIBLBER_F( void )
433 ber_sockbuf_free(
434         Sockbuf *sb );
435
436 /*
437  * LBER memory.c
438  */
439 LIBLBER_F( void * )
440 ber_memalloc LDAP_P((
441         ber_len_t s ));
442
443 LIBLBER_F( void * )
444 ber_memrealloc LDAP_P((
445         void* p,
446         ber_len_t s ));
447
448 LIBLBER_F( void * )
449 ber_memcalloc LDAP_P((
450         ber_len_t n,
451         ber_len_t s ));
452
453 LIBLBER_F( void )
454 ber_memfree LDAP_P((
455         void* p ));
456
457 LIBLBER_F( void )
458 ber_memvfree LDAP_P((
459         void** vector ));
460
461 LIBLBER_F( void )
462 ber_bvfree LDAP_P((
463         struct berval *bv ));
464
465 LIBLBER_F( void )
466 ber_bvecfree LDAP_P((
467         struct berval **bv ));
468
469 LIBLBER_F( struct berval * )
470 ber_bvdup LDAP_P((
471         LDAP_CONST struct berval *bv ));
472
473 LIBLBER_F( char * )
474 ber_strdup LDAP_P((
475         LDAP_CONST char * ));
476
477 /*
478  * error.c
479  */
480 LIBLBER_F( int * ) ber_errno_addr LDAP_P((void));
481 #define ber_errno (*(ber_errno_addr)())
482
483 #define LBER_ERROR_NONE         0
484 #define LBER_ERROR_PARAM        0x1
485 #define LBER_ERROR_MEMORY       0x2
486
487 LDAP_END_DECL
488
489 #endif /* _LBER_H */