]> git.sur5r.net Git - openldap/blob - libraries/liblber/lber-int.h
fix ITS#3499 (may need further testing)
[openldap] / libraries / liblber / lber-int.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2005 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 LBER_F( int ) ber_pvt_log_output(
49         const char *subsystem,
50         int level,
51         const char *fmt, ... );
52
53 #define LBER_UNINITIALIZED              0x0
54 #define LBER_INITIALIZED                0x1
55 #define LBER_VALID_BERELEMENT   0x2
56 #define LBER_VALID_SOCKBUF              0x3
57
58 LBER_V (struct lber_options) ber_int_options;
59 #define ber_int_debug ber_int_options.lbo_debug
60
61 struct berelement {
62         struct          lber_options ber_opts;
63 #define ber_valid               ber_opts.lbo_valid
64 #define ber_options             ber_opts.lbo_options
65 #define ber_debug               ber_opts.lbo_debug
66
67         /* Do not change the order of these 3 fields! see ber_get_next */
68         ber_tag_t       ber_tag;
69         ber_len_t       ber_len;
70         ber_tag_t       ber_usertag;
71
72         char            *ber_buf;
73         char            *ber_ptr;
74         char            *ber_end;
75
76         struct seqorset *ber_sos;
77         char            *ber_rwptr;
78         void            *ber_memctx;
79 };
80 #define LBER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
81
82 #define ber_pvt_ber_remaining(ber)      ((ber)->ber_end - (ber)->ber_ptr)
83 #define ber_pvt_ber_total(ber)          ((ber)->ber_end - (ber)->ber_buf)
84 #define ber_pvt_ber_write(ber)          ((ber)->ber_ptr - (ber)->ber_buf)
85
86 struct sockbuf {
87         struct lber_options sb_opts;
88         Sockbuf_IO_Desc         *sb_iod;                /* I/O functions */
89 #define sb_valid                sb_opts.lbo_valid
90 #define sb_options              sb_opts.lbo_options
91 #define sb_debug                sb_opts.lbo_debug
92         ber_socket_t            sb_fd;
93         unsigned int            sb_trans_needs_read:1;
94         unsigned int            sb_trans_needs_write:1;
95         ber_len_t                       sb_max_incoming;
96 };
97
98 #define SOCKBUF_VALID( sb )     ( (sb)->sb_valid == LBER_VALID_SOCKBUF )
99
100 struct seqorset {
101         BerElement      *sos_ber;
102         ber_len_t       sos_clen;
103         ber_tag_t       sos_tag;
104         char            *sos_first;
105         char            *sos_ptr;
106         struct seqorset *sos_next;
107 };
108
109
110 /*
111  * io.c
112  */
113 LBER_F( int )
114 ber_realloc LDAP_P((
115         BerElement *ber,
116         ber_len_t len ));
117
118 LBER_F (char *) ber_start LDAP_P(( BerElement * ));
119 LBER_F (int) ber_len LDAP_P(( BerElement * ));
120 LBER_F (int) ber_ptrlen LDAP_P(( BerElement * ));
121 LBER_F (void) ber_rewind LDAP_P(( BerElement * ));
122
123 /*
124  * bprint.c
125  */
126 #define ber_log_printf ber_pvt_log_printf
127
128 LBER_F( int )
129 ber_log_bprint LDAP_P((
130         int errlvl,
131         int loglvl,
132         const char *data,
133         ber_len_t len ));
134
135 LBER_F( int )
136 ber_log_dump LDAP_P((
137         int errlvl,
138         int loglvl,
139         BerElement *ber,
140         int inout ));
141
142 LBER_F( int )
143 ber_log_sos_dump LDAP_P((
144         int errlvl,
145         int loglvl,
146         Seqorset *sos ));
147
148 LBER_V (BER_LOG_FN) ber_int_log_proc;
149 LBER_V (FILE *) ber_pvt_err_file;
150
151 /* memory.c */
152         /* simple macros to realloc for now */
153 LBER_V (BerMemoryFunctions *)   ber_int_memory_fns;
154 LBER_F (char *) ber_strndup( LDAP_CONST char *, ber_len_t );
155 LBER_F (char *) ber_strndup_x( LDAP_CONST char *, ber_len_t, void *ctx );
156
157 #define LBER_MALLOC(s)          ber_memalloc((s))
158 #define LBER_CALLOC(n,s)        ber_memcalloc((n),(s))
159 #define LBER_REALLOC(p,s)       ber_memrealloc((p),(s))
160 #define LBER_FREE(p)            ber_memfree((p))        
161 #define LBER_VFREE(v)           ber_memvfree((void**)(v))
162 #define LBER_STRDUP(s)          ber_strdup((s))
163 #define LBER_STRNDUP(s,l)       ber_strndup((s),(l))
164
165 /* sockbuf.c */
166
167 LBER_F( int )
168 ber_int_sb_init LDAP_P(( Sockbuf *sb ));
169
170 LBER_F( int )
171 ber_int_sb_close LDAP_P(( Sockbuf *sb ));
172
173 LBER_F( int )
174 ber_int_sb_destroy LDAP_P(( Sockbuf *sb ));
175
176 LBER_F( ber_slen_t )
177 ber_int_sb_read LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
178
179 LBER_F( ber_slen_t )
180 ber_int_sb_write LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
181
182 LDAP_END_DECL
183
184 #endif /* _LBER_INT_H */