]> git.sur5r.net Git - openldap/blob - libraries/liblber/lber-int.h
Happy new year
[openldap] / libraries / liblber / lber-int.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2004 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
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.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
16  * All rights reserved.
17  *
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.
24  */
25
26 #ifndef _LBER_INT_H
27 #define _LBER_INT_H
28
29 #include "lber.h"
30 #include "ldap_log.h"
31 #include "lber_pvt.h"
32 #include "ldap_queue.h"
33
34 LDAP_BEGIN_DECL
35
36 typedef void (*BER_LOG_FN)(FILE *file,
37         const char *subsys, int level, const char *fmt, ... );
38
39 LBER_V (BER_ERRNO_FN) ber_int_errno_fn;
40
41 struct lber_options {
42         short lbo_valid;
43         unsigned short          lbo_options;
44         int                     lbo_debug;
45         long            lbo_meminuse;
46 };
47
48 #ifdef NEW_LOGGING
49 /*
50 #    ifdef LDAP_DEBUG
51 #        ifdef LDAP_LOG
52 #            undef LDAP_LOG
53 #        endif
54 #        define LDAP_LOG(a) ber_pvt_log_output a
55  */
56 #        define BER_DUMP(a) ber_output_dump a
57 /*
58 #    else
59 #        define LDAP_LOG(a)
60 #        define BER_DUMP(a)
61 #    endif
62  */
63 #endif
64
65 LBER_F( int ) ber_pvt_log_output(
66         const char *subsystem,
67         int level,
68         const char *fmt, ... );
69
70 #define LBER_UNINITIALIZED              0x0
71 #define LBER_INITIALIZED                0x1
72 #define LBER_VALID_BERELEMENT   0x2
73 #define LBER_VALID_SOCKBUF              0x3
74
75 LBER_V (struct lber_options) ber_int_options;
76 #define ber_int_debug ber_int_options.lbo_debug
77
78 struct berelement {
79         struct          lber_options ber_opts;
80 #define ber_valid               ber_opts.lbo_valid
81 #define ber_options             ber_opts.lbo_options
82 #define ber_debug               ber_opts.lbo_debug
83
84         /* Do not change the order of these 3 fields! see ber_get_next */
85         ber_tag_t       ber_tag;
86         ber_len_t       ber_len;
87         ber_tag_t       ber_usertag;
88
89         char            *ber_buf;
90         char            *ber_ptr;
91         char            *ber_end;
92
93         struct seqorset *ber_sos;
94         char            *ber_rwptr;
95         void            *ber_memctx;
96 };
97 #define LBER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
98
99 #define ber_pvt_ber_remaining(ber)      ((ber)->ber_end - (ber)->ber_ptr)
100 #define ber_pvt_ber_total(ber)          ((ber)->ber_end - (ber)->ber_buf)
101 #define ber_pvt_ber_write(ber)          ((ber)->ber_ptr - (ber)->ber_buf)
102
103 struct sockbuf {
104         struct lber_options sb_opts;
105         Sockbuf_IO_Desc         *sb_iod;                /* I/O functions */
106 #define sb_valid                sb_opts.lbo_valid
107 #define sb_options              sb_opts.lbo_options
108 #define sb_debug                sb_opts.lbo_debug
109         ber_socket_t            sb_fd;
110         unsigned int            sb_trans_needs_read:1;
111         unsigned int            sb_trans_needs_write:1;
112         ber_len_t                       sb_max_incoming;
113 };
114
115 #define SOCKBUF_VALID( sb )     ( (sb)->sb_valid == LBER_VALID_SOCKBUF )
116
117 struct seqorset {
118         BerElement      *sos_ber;
119         ber_len_t       sos_clen;
120         ber_tag_t       sos_tag;
121         char            *sos_first;
122         char            *sos_ptr;
123         struct seqorset *sos_next;
124 };
125
126
127 /*
128  * io.c
129  */
130 LBER_F( int )
131 ber_realloc LDAP_P((
132         BerElement *ber,
133         ber_len_t len ));
134
135 LBER_F (char *) ber_start LDAP_P(( BerElement * ));
136 LBER_F (int) ber_len LDAP_P(( BerElement * ));
137 LBER_F (int) ber_ptrlen LDAP_P(( BerElement * ));
138 LBER_F (void) ber_rewind LDAP_P(( BerElement * ));
139
140 /*
141  * bprint.c
142  */
143 #define ber_log_printf ber_pvt_log_printf
144
145 #ifdef NEW_LOGGING
146 LBER_F( int )
147 ber_output_dump LDAP_P((
148         const char *subsys,
149         int level,
150         BerElement *ber,
151         int inout ));
152 #endif
153
154 LBER_F( int )
155 ber_log_bprint LDAP_P((
156         int errlvl,
157         int loglvl,
158         const char *data,
159         ber_len_t len ));
160
161 LBER_F( int )
162 ber_log_dump LDAP_P((
163         int errlvl,
164         int loglvl,
165         BerElement *ber,
166         int inout ));
167
168 LBER_F( int )
169 ber_log_sos_dump LDAP_P((
170         int errlvl,
171         int loglvl,
172         Seqorset *sos ));
173
174 LBER_V (BER_LOG_FN) ber_int_log_proc;
175 LBER_V (FILE *) ber_pvt_err_file;
176
177 /* memory.c */
178         /* simple macros to realloc for now */
179 LBER_V (BerMemoryFunctions *)   ber_int_memory_fns;
180 LBER_F (char *) ber_strndup( LDAP_CONST char *, ber_len_t );
181 LBER_F (char *) ber_strndup_x( LDAP_CONST char *, ber_len_t, void *ctx );
182
183 #define LBER_MALLOC(s)          ber_memalloc((s))
184 #define LBER_CALLOC(n,s)        ber_memcalloc((n),(s))
185 #define LBER_REALLOC(p,s)       ber_memrealloc((p),(s))
186 #define LBER_FREE(p)            ber_memfree((p))        
187 #define LBER_VFREE(v)           ber_memvfree((void**)(v))
188 #define LBER_STRDUP(s)          ber_strdup((s))
189 #define LBER_STRNDUP(s,l)       ber_strndup((s),(l))
190
191 /* sockbuf.c */
192
193 LBER_F( int )
194 ber_int_sb_init LDAP_P(( Sockbuf *sb ));
195
196 LBER_F( int )
197 ber_int_sb_close LDAP_P(( Sockbuf *sb ));
198
199 LBER_F( int )
200 ber_int_sb_destroy LDAP_P(( Sockbuf *sb ));
201
202 LBER_F( ber_slen_t )
203 ber_int_sb_read LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
204
205 LBER_F( ber_slen_t )
206 ber_int_sb_write LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
207
208 LDAP_END_DECL
209
210 #endif /* _LBER_INT_H */