]> git.sur5r.net Git - openldap/blob - include/lber.h
Fix up makefiles after removal of getdxname.c
[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_IO options */ 
127 #define LBER_SB_OPT_GET_FD              1
128 #define LBER_SB_OPT_SET_FD              2
129 #define LBER_SB_OPT_HAS_IO              3
130 #define LBER_SB_OPT_SET_NONBLOCK        4
131 #define LBER_SB_OPT_UDP_GET_SRC         5
132 #define LBER_SB_OPT_UDP_SET_DST         6
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 /* Largest option used by the library */
140 #define LBER_SB_OPT_OPT_MAX             12
141
142 /* LBER IO operations stacking levels */
143 #define LBER_SBIOD_LEVEL_PROVIDER       10
144 #define LBER_SBIOD_LEVEL_TRANSPORT      20
145 #define LBER_SBIOD_LEVEL_APPLICATION    30
146
147 /* get/set options for Sockbuf */
148 #define LBER_OPT_SOCKBUF_DESC           0x1000
149 #define LBER_OPT_SOCKBUF_OPTIONS        0x1001
150 #define LBER_OPT_SOCKBUF_DEBUG          0x1002
151
152 /* on/off values */
153 #define LBER_OPT_ON             ((void *) 1)
154 #define LBER_OPT_OFF    ((void *) 0)
155
156 #define LBER_OPT_SUCCESS        (0)
157 #define LBER_OPT_ERROR          (-1)
158
159 typedef struct berelement BerElement;
160 typedef struct sockbuf Sockbuf;
161 typedef struct seqorset Seqorset;
162
163 typedef struct sockbuf_io Sockbuf_IO;
164
165 /* Structure for LBER IO operarion descriptor */
166 typedef struct sockbuf_io_desc {
167         int                     sbiod_level;
168         Sockbuf                 *sbiod_sb;
169         Sockbuf_IO              *sbiod_io;
170         void                    *sbiod_pvt;
171         struct sockbuf_io_desc  *sbiod_next;
172 } Sockbuf_IO_Desc;
173
174 /* Structure for LBER IO operation functions */
175 struct sockbuf_io {
176         int (*sbi_setup)( Sockbuf_IO_Desc *sbiod, void *arg );
177         int (*sbi_remove)( Sockbuf_IO_Desc *sbiod );
178         int (*sbi_ctrl)( Sockbuf_IO_Desc *sbiod, int opt, void *arg);
179         
180         ber_slen_t (*sbi_read)( Sockbuf_IO_Desc *sbiod, void *buf,
181                 ber_len_t len );
182         ber_slen_t (*sbi_write)( Sockbuf_IO_Desc *sbiod, void *buf,
183                 ber_len_t len );
184         
185         int (*sbi_close)( Sockbuf_IO_Desc *sbiod );
186 };
187
188 /* Helper macros for LBER IO functions */
189 #define LBER_SBIOD_READ_NEXT( sbiod, buf, len ) \
190         ( (sbiod)->sbiod_next->sbiod_io->sbi_read( (sbiod)->sbiod_next, \
191                 buf, len ) )
192 #define LBER_SBIOD_WRITE_NEXT( sbiod, buf, len ) \
193         ( (sbiod)->sbiod_next->sbiod_io->sbi_write( (sbiod)->sbiod_next, \
194                 buf, len ) )
195 #define LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg ) \
196         ( (sbiod)->sbiod_next ? \
197                 ( (sbiod)->sbiod_next->sbiod_io->sbi_ctrl( \
198                 (sbiod)->sbiod_next, opt, arg ) ) : 0 )
199
200 /* structure for returning a sequence of octet strings + length */
201 typedef struct berval {
202         ber_len_t       bv_len;
203         char            *bv_val;
204 } BerValue;
205
206 /* this should be moved to lber-int.h */
207
208 /*
209  * in bprint.c:
210  */
211 LIBLBER_F( void )
212 ber_print_error LDAP_P((
213         LDAP_CONST char *data ));
214
215 LIBLBER_F( void )
216 ber_bprint LDAP_P((
217         LDAP_CONST char *data, ber_len_t len ));
218
219 LIBLBER_F( void )
220 ber_dump LDAP_P((
221         BerElement *ber, int inout ));
222
223 LIBLBER_F( void )
224 ber_sos_dump LDAP_P((
225         Seqorset *sos ));
226
227
228 /*
229  * in decode.c:
230  */
231 typedef int (*BERDecodeCallback) LDAP_P((
232         BerElement *ber,
233         void *data,
234         int mode ));
235
236 LIBLBER_F( ber_tag_t )
237 ber_get_tag LDAP_P((
238         BerElement *ber ));
239
240 LIBLBER_F( ber_tag_t )
241 ber_skip_tag LDAP_P((
242         BerElement *ber,
243         ber_len_t *len ));
244
245 LIBLBER_F( ber_tag_t )
246 ber_peek_tag LDAP_P((
247         BerElement *ber,
248         ber_len_t *len ));
249
250 LIBLBER_F( ber_tag_t )
251 ber_get_int LDAP_P((
252         BerElement *ber,
253         ber_int_t *num ));
254
255 LIBLBER_F( ber_tag_t )
256 ber_get_enum LDAP_P((
257         BerElement *ber,
258         ber_int_t *num ));
259
260 LIBLBER_F( ber_tag_t )
261 ber_get_stringb LDAP_P((
262         BerElement *ber,
263         char *buf,
264         ber_len_t *len ));
265
266 LIBLBER_F( ber_tag_t )
267 ber_get_stringa LDAP_P((
268         BerElement *ber,
269         char **buf ));
270
271 LIBLBER_F( ber_tag_t )
272 ber_get_stringal LDAP_P((
273         BerElement *ber,
274         struct berval **bv ));
275
276 LIBLBER_F( ber_tag_t )
277 ber_get_bitstringa LDAP_P((
278         BerElement *ber,
279         char **buf,
280         ber_len_t *len ));
281
282 LIBLBER_F( ber_tag_t )
283 ber_get_null LDAP_P((
284         BerElement *ber ));
285
286 LIBLBER_F( ber_tag_t )
287 ber_get_boolean LDAP_P((
288         BerElement *ber,
289         ber_int_t *boolval ));
290
291 LIBLBER_F( ber_tag_t )
292 ber_first_element LDAP_P((
293         BerElement *ber,
294         ber_len_t *len,
295         char **last ));
296
297 LIBLBER_F( ber_tag_t )
298 ber_next_element LDAP_P((
299         BerElement *ber,
300         ber_len_t *len,
301         LDAP_CONST char *last ));
302
303 LIBLBER_F( ber_tag_t )
304 ber_scanf LDAP_P((                                                                
305         BerElement *ber,
306         LDAP_CONST char *fmt,
307         ... ));
308
309 LIBLBER_F( void )
310 ber_set_string_translators LDAP_P((
311         BerElement *ber,
312         BERTranslateProc encode_proc,
313         BERTranslateProc decode_proc ));
314
315 /*
316  * in encode.c
317  */
318 typedef int (*BEREncodeCallback) LDAP_P((
319         BerElement *ber,
320         void *data ));
321
322 LIBLBER_F( int )
323 ber_put_enum LDAP_P((
324         BerElement *ber,
325         ber_int_t num,
326         ber_tag_t tag ));
327
328 LIBLBER_F( int )
329 ber_put_int LDAP_P((
330         BerElement *ber,
331         ber_int_t num,
332         ber_tag_t tag ));
333
334 LIBLBER_F( int )
335 ber_put_ostring LDAP_P((
336         BerElement *ber,
337         LDAP_CONST char *str,
338         ber_len_t len,
339         ber_tag_t tag ));
340
341 LIBLBER_F( int )
342 ber_put_berval LDAP_P((
343         BerElement *ber,
344         LDAP_CONST struct berval *bv,
345         ber_tag_t tag ));
346
347 LIBLBER_F( int )
348 ber_put_string LDAP_P((
349         BerElement *ber,
350         LDAP_CONST char *str,
351         ber_tag_t tag ));
352
353 LIBLBER_F( int )
354 ber_put_bitstring LDAP_P((
355         BerElement *ber,
356         LDAP_CONST char *str,
357         ber_len_t bitlen,
358         ber_tag_t tag ));
359
360 LIBLBER_F( int )
361 ber_put_null LDAP_P((
362         BerElement *ber,
363         ber_tag_t tag ));
364
365 LIBLBER_F( int )
366 ber_put_boolean LDAP_P((
367         BerElement *ber,
368         ber_int_t boolval,
369         ber_tag_t tag ));
370
371 LIBLBER_F( int )
372 ber_start_seq LDAP_P((
373         BerElement *ber,
374         ber_tag_t tag ));
375
376 LIBLBER_F( int )
377 ber_start_set LDAP_P((
378         BerElement *ber,
379         ber_tag_t tag ));
380
381 LIBLBER_F( int )
382 ber_put_seq LDAP_P((
383         BerElement *ber ));
384
385 LIBLBER_F( int )
386 ber_put_set LDAP_P((
387         BerElement *ber ));
388
389 LIBLBER_F( int )
390 ber_printf LDAP_P((
391         BerElement *ber,
392         LDAP_CONST char *fmt,
393         ... ));
394
395
396 /*
397  * in io.c:
398  */
399
400 LIBLBER_F( ber_slen_t )
401 ber_read LDAP_P((
402         BerElement *ber,
403         char *buf,
404         ber_len_t len ));
405
406 LIBLBER_F( ber_slen_t )
407 ber_write LDAP_P((
408         BerElement *ber,
409         LDAP_CONST char *buf,
410         ber_len_t len,
411         int nosos ));
412
413 LIBLBER_F( void )
414 ber_free LDAP_P((
415         BerElement *ber,
416         int freebuf ));
417
418 LIBLBER_F( int )
419 ber_flush LDAP_P((
420         Sockbuf *sb,
421         BerElement *ber,
422         int freeit ));
423
424 LIBLBER_F( BerElement * )
425 ber_alloc LDAP_P(( void )); /* DEPRECATED */
426
427 LIBLBER_F( BerElement * )
428 der_alloc LDAP_P(( void )); /* DEPRECATED */
429
430 LIBLBER_F( BerElement * )
431 ber_alloc_t LDAP_P((
432         int beroptions ));
433
434 LIBLBER_F( BerElement * )
435 ber_dup LDAP_P((
436         BerElement *ber ));
437
438 LIBLBER_F( ber_tag_t )
439 ber_get_next LDAP_P((
440         Sockbuf *sb,
441         ber_len_t *len,
442         BerElement *ber ));
443
444 LIBLBER_F( void )
445 ber_init_w_nullc LDAP_P((
446         BerElement *ber,
447         int options ));
448
449 LIBLBER_F( void )
450 ber_reset LDAP_P((
451         BerElement *ber,
452         int was_writing ));
453
454 LIBLBER_F( BerElement * )
455 ber_init LDAP_P((
456         struct berval *bv ));
457
458 LIBLBER_F( int )
459 ber_flatten LDAP_P((
460         BerElement *ber,
461         struct berval **bvPtr ));
462
463 /*
464  * LBER ber accessor functions
465  */
466
467 LIBLBER_F( int )
468 ber_get_option LDAP_P((
469         void *item,
470         int option,
471         void *outvalue));
472
473 LIBLBER_F( int )
474 ber_set_option LDAP_P((
475         void *item,
476         int option,
477         LDAP_CONST void *invalue));
478
479 /*
480  * LBER sockbuf.c
481  */
482
483 LIBLBER_F( Sockbuf *  )
484 ber_sockbuf_alloc LDAP_P((
485         void ));
486
487 LIBLBER_F( void )
488 ber_sockbuf_free LDAP_P((
489         Sockbuf *sb ));
490
491 LIBLBER_F( int )
492 ber_sockbuf_add_io LDAP_P((
493         Sockbuf *sb,
494         Sockbuf_IO *sbio,
495         int layer,
496         void *arg ));
497
498 LIBLBER_F( int )
499 ber_sockbuf_remove_io LDAP_P((
500         Sockbuf *sb,
501         Sockbuf_IO *sbio,
502         int layer ));
503
504 LIBLBER_F( int )
505 ber_sockbuf_ctrl LDAP_P((
506         Sockbuf *sb,
507         int opt,
508         void *arg ));
509
510 LIBLBER_F( Sockbuf_IO ) ber_sockbuf_io_tcp;
511 LIBLBER_F( Sockbuf_IO ) ber_sockbuf_io_udp;
512 LIBLBER_F( Sockbuf_IO ) ber_sockbuf_io_readahead;
513 LIBLBER_F( Sockbuf_IO ) ber_sockbuf_io_fd;
514 LIBLBER_F( Sockbuf_IO ) ber_sockbuf_io_debug;
515
516 /*
517  * LBER memory.c
518  */
519 LIBLBER_F( void * )
520 ber_memalloc LDAP_P((
521         ber_len_t s ));
522
523 LIBLBER_F( void * )
524 ber_memrealloc LDAP_P((
525         void* p,
526         ber_len_t s ));
527
528 LIBLBER_F( void * )
529 ber_memcalloc LDAP_P((
530         ber_len_t n,
531         ber_len_t s ));
532
533 LIBLBER_F( void )
534 ber_memfree LDAP_P((
535         void* p ));
536
537 LIBLBER_F( void )
538 ber_memvfree LDAP_P((
539         void** vector ));
540
541 LIBLBER_F( void )
542 ber_bvfree LDAP_P((
543         struct berval *bv ));
544
545 LIBLBER_F( void )
546 ber_bvecfree LDAP_P((
547         struct berval **bv ));
548
549 LIBLBER_F( int )
550 ber_bvecadd LDAP_P((
551         struct berval ***bvec,
552         struct berval *bv ));
553
554 LIBLBER_F( struct berval * )
555 ber_bvdup LDAP_P((
556         LDAP_CONST struct berval *bv ));
557
558 LIBLBER_F( struct berval * )
559 ber_bvstr LDAP_P((
560         LDAP_CONST char * ));
561
562 LIBLBER_F( struct berval * )
563 ber_bvstrdup LDAP_P((
564         LDAP_CONST char * ));
565
566 LIBLBER_F( char * )
567 ber_strdup LDAP_P((
568         LDAP_CONST char * ));
569
570 /*
571  * error.c
572  */
573 LIBLBER_F( int * ) ber_errno_addr LDAP_P((void));
574 #define ber_errno (*(ber_errno_addr)())
575
576 #define LBER_ERROR_NONE         0
577 #define LBER_ERROR_PARAM        0x1
578 #define LBER_ERROR_MEMORY       0x2
579
580 LDAP_END_DECL
581
582 #endif /* _LBER_H */