]> git.sur5r.net Git - openldap/blob - include/lber.h
Remove DEFS variables from Makefiles, remove bridge.h.
[openldap] / include / lber.h
1 /*
2  * Copyright (c) 1990 Regents of the University of Michigan.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of Michigan at Ann Arbor. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12
13 #ifndef _LBER_H
14 #define _LBER_H
15
16 #include <ldap_cdefs.h>
17
18 LDAP_BEGIN_DECL
19
20 /* BER classes and mask */
21 #define LBER_CLASS_UNIVERSAL    0x00
22 #define LBER_CLASS_APPLICATION  0x40
23 #define LBER_CLASS_CONTEXT      0x80
24 #define LBER_CLASS_PRIVATE      0xc0
25 #define LBER_CLASS_MASK         0xc0
26
27 /* BER encoding type and mask */
28 #define LBER_PRIMITIVE          0x00
29 #define LBER_CONSTRUCTED        0x20
30 #define LBER_ENCODING_MASK      0x20
31
32 #define LBER_BIG_TAG_MASK       0x1f
33 #define LBER_MORE_TAG_MASK      0x80
34
35 /*
36  * Note that LBER_ERROR and LBER_DEFAULT are values that can never appear
37  * as valid BER tags, and so it is safe to use them to report errors.  In
38  * fact, any tag for which the following is true is invalid:
39  *     (( tag & 0x00000080 ) != 0 ) && (( tag & 0xFFFFFF00 ) != 0 )
40  */
41 #define LBER_ERROR              0xffffffffL
42 #define LBER_DEFAULT            0xffffffffL
43
44 /* general BER types we know about */
45 #define LBER_BOOLEAN            0x01L
46 #define LBER_INTEGER            0x02L
47 #define LBER_BITSTRING          0x03L
48 #define LBER_OCTETSTRING        0x04L
49 #define LBER_NULL               0x05L
50 #define LBER_ENUMERATED         0x0aL
51 #define LBER_SEQUENCE           0x30L   /* constructed */
52 #define LBER_SET                0x31L   /* constructed */
53
54 #define OLD_LBER_SEQUENCE       0x10L   /* w/o constructed bit - broken */
55 #define OLD_LBER_SET            0x11L   /* w/o constructed bit - broken */
56
57 typedef int (*BERTranslateProc) LDAP_P(( char **bufp,
58         unsigned long *buflenp,
59         int free_input ));
60
61 typedef struct berelement {
62         char            *ber_buf;
63         char            *ber_ptr;
64         char            *ber_end;
65         struct seqorset *ber_sos;
66         unsigned long   ber_tag;
67         unsigned long   ber_len;
68         int             ber_usertag;
69         char            ber_options;
70 #define LBER_USE_DER            0x01
71 #define LBER_USE_INDEFINITE_LEN 0x02
72 #define LBER_TRANSLATE_STRINGS  0x04
73         char            *ber_rwptr;
74         BERTranslateProc ber_encode_translate_proc;
75         BERTranslateProc ber_decode_translate_proc;
76 } BerElement;
77 #define NULLBER ((BerElement *) 0)
78
79 typedef struct sockbuf {
80 #ifndef MACOS
81         int             sb_sd;
82 #else /* MACOS */
83         void            *sb_sd;
84 #endif /* MACOS */
85         BerElement      sb_ber;
86
87         int             sb_naddr;       /* > 0 implies using CLDAP (UDP) */
88         void            *sb_useaddr;    /* pointer to sockaddr to use next */
89         void            *sb_fromaddr;   /* pointer to message source sockaddr */
90         void            **sb_addrs;     /* actually an array of pointers to
91                                                 sockaddrs */
92
93         int             sb_options;     /* to support copying ber elements */
94 #define LBER_TO_FILE            0x01    /* to a file referenced by sb_fd   */
95 #define LBER_TO_FILE_ONLY       0x02    /* only write to file, not network */
96 #define LBER_MAX_INCOMING_SIZE  0x04    /* impose limit on incoming stuff  */
97 #define LBER_NO_READ_AHEAD      0x08    /* read only as much as requested  */
98         int             sb_fd;
99         long            sb_max_incoming;
100 } Sockbuf;
101 #define READBUFSIZ      8192
102
103 typedef struct seqorset {
104         BerElement      *sos_ber;
105         unsigned long   sos_clen;
106         unsigned long   sos_tag;
107         char            *sos_first;
108         char            *sos_ptr;
109         struct seqorset *sos_next;
110 } Seqorset;
111 #define NULLSEQORSET    ((Seqorset *) 0)
112
113 /* structure for returning a sequence of octet strings + length */
114 struct berval {
115         unsigned long   bv_len;
116         char            *bv_val;
117 };
118
119 extern int lber_debug;
120
121 /*
122  * in bprint.c:
123  */
124 LDAP_F void lber_bprint LDAP_P(( char *data, int len ));
125
126 /*
127  * in decode.c:
128  */
129 LDAP_F unsigned long ber_get_tag LDAP_P(( BerElement *ber ));
130 LDAP_F unsigned long ber_skip_tag LDAP_P(( BerElement *ber, unsigned long *len ));
131 LDAP_F unsigned long ber_peek_tag LDAP_P(( BerElement *ber, unsigned long *len ));
132 LDAP_F unsigned long ber_get_int LDAP_P(( BerElement *ber, long *num ));
133 LDAP_F unsigned long ber_get_stringb LDAP_P(( BerElement *ber, char *buf,
134         unsigned long *len ));
135 LDAP_F unsigned long ber_get_stringa LDAP_P(( BerElement *ber, char **buf ));
136 LDAP_F unsigned long ber_get_stringal LDAP_P(( BerElement *ber, struct berval **bv ));
137 LDAP_F unsigned long ber_get_bitstringa LDAP_P(( BerElement *ber, char **buf,
138         unsigned long *len ));
139 LDAP_F unsigned long ber_get_null LDAP_P(( BerElement *ber ));
140 LDAP_F unsigned long ber_get_boolean LDAP_P(( BerElement *ber, int *boolval ));
141 LDAP_F unsigned long ber_first_element LDAP_P(( BerElement *ber, unsigned long *len,
142         char **last ));
143 LDAP_F unsigned long ber_next_element LDAP_P(( BerElement *ber, unsigned long *len,
144         char *last ));
145 LDAP_F unsigned long ber_scanf LDAP_P(( BerElement *ber, char *fmt, ... ));
146 LDAP_F void ber_bvfree LDAP_P(( struct berval *bv ));
147 LDAP_F void ber_bvecfree LDAP_P(( struct berval **bv ));
148 LDAP_F struct berval *ber_bvdup LDAP_P(( struct berval *bv ));
149 LDAP_F void ber_set_string_translators LDAP_P(( BerElement *ber,
150         BERTranslateProc encode_proc, BERTranslateProc decode_proc ));
151
152 /*
153  * in encode.c
154  */
155 LDAP_F int ber_put_enum LDAP_P(( BerElement *ber, long num, unsigned long tag ));
156 LDAP_F int ber_put_int LDAP_P(( BerElement *ber, long num, unsigned long tag ));
157 LDAP_F int ber_put_ostring LDAP_P(( BerElement *ber, char *str, unsigned long len,
158         unsigned long tag ));
159 LDAP_F int ber_put_string LDAP_P(( BerElement *ber, char *str, unsigned long tag ));
160 LDAP_F int ber_put_bitstring LDAP_P(( BerElement *ber, char *str,
161         unsigned long bitlen, unsigned long tag ));
162 LDAP_F int ber_put_null LDAP_P(( BerElement *ber, unsigned long tag ));
163 LDAP_F int ber_put_boolean LDAP_P(( BerElement *ber, int boolval,
164         unsigned long tag ));
165 LDAP_F int ber_start_seq LDAP_P(( BerElement *ber, unsigned long tag ));
166 LDAP_F int ber_start_set LDAP_P(( BerElement *ber, unsigned long tag ));
167 LDAP_F int ber_put_seq LDAP_P(( BerElement *ber ));
168 LDAP_F int ber_put_set LDAP_P(( BerElement *ber ));
169 LDAP_F int ber_printf LDAP_P(( BerElement *ber, char *fmt, ... ));
170
171 /*
172  * in io.c:
173  */
174 LDAP_F long ber_read LDAP_P(( BerElement *ber, char *buf, unsigned long len ));
175 LDAP_F long ber_write LDAP_P(( BerElement *ber, char *buf, unsigned long len,
176         int nosos ));
177 LDAP_F void ber_free LDAP_P(( BerElement *ber, int freebuf ));
178 LDAP_F int ber_flush LDAP_P(( Sockbuf *sb, BerElement *ber, int freeit ));
179 LDAP_F BerElement *ber_alloc LDAP_P(( void ));
180 LDAP_F BerElement *der_alloc LDAP_P(( void ));
181 LDAP_F BerElement *ber_alloc_t LDAP_P(( int options ));
182 LDAP_F BerElement *ber_dup LDAP_P(( BerElement *ber ));
183 LDAP_F void ber_dump LDAP_P(( BerElement *ber, int inout ));
184 LDAP_F void ber_sos_dump LDAP_P(( Seqorset *sos ));
185 LDAP_F unsigned long ber_get_next LDAP_P(( Sockbuf *sb, unsigned long *len,
186         BerElement *ber ));
187 LDAP_F void ber_init LDAP_P(( BerElement *ber, int options ));
188 LDAP_F void ber_reset LDAP_P(( BerElement *ber, int was_writing ));
189
190 LDAP_END_DECL
191
192 #endif /* _LBER_H */