]> git.sur5r.net Git - openldap/blob - libraries/liblber/lber-int.h
bf03644868749dddef9c9d28bdd364adfc753fe3
[openldap] / libraries / liblber / lber-int.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /* Portions
7  * Copyright (c) 1990 Regents of the University of Michigan.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms are permitted
11  * provided that this notice is preserved and that due credit is given
12  * to the University of Michigan at Ann Arbor. The name of the University
13  * may not be used to endorse or promote products derived from this
14  * software without specific prior written permission. This software
15  * is provided ``as is'' without express or implied warranty.
16  */
17
18 #ifndef _LBER_INT_H
19 #define _LBER_INT_H
20
21 #include "lber.h"
22 #include "ldap_log.h"
23 #include "lber_pvt.h"
24
25 LDAP_BEGIN_DECL
26
27 LBER_F (BER_ERRNO_FN) ber_int_errno_fn;
28
29 struct lber_options {
30         short lbo_valid;
31         unsigned short          lbo_options;
32         int                     lbo_debug;
33         long            lbo_meminuse;
34 };
35
36 #ifdef NEW_LOGGING
37 #    ifdef LDAP_DEBUG
38 #        ifdef LDAP_LOG
39 #            undef LDAP_LOG
40 #        endif
41 #        define LDAP_LOG(a) ber_pvt_log_output a
42 #        define BER_DUMP(a) ber_output_dump a
43 #    else
44 #        define LDAP_LOG(a)
45 #        define BER_DUMP(a)
46 #    endif
47 #endif
48
49 #define LBER_UNINITIALIZED              0x0
50 #define LBER_INITIALIZED                0x1
51 #define LBER_VALID_BERELEMENT   0x2
52 #define LBER_VALID_SOCKBUF              0x3
53
54 LBER_F (struct lber_options) ber_int_options;
55 #define ber_int_debug ber_int_options.lbo_debug
56
57 struct berelement {
58         struct          lber_options ber_opts;
59 #define ber_valid               ber_opts.lbo_valid
60 #define ber_options             ber_opts.lbo_options
61 #define ber_debug               ber_opts.lbo_debug
62
63         ber_tag_t       ber_usertag;
64
65         ber_tag_t       ber_tag;
66         ber_len_t       ber_len;
67
68         char            *ber_buf;
69         char            *ber_ptr;
70         char            *ber_end;
71
72         struct seqorset *ber_sos;
73         char            *ber_rwptr;
74 };
75 #define LBER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
76
77 #define ber_pvt_ber_remaining(ber)      ((ber)->ber_end - (ber)->ber_ptr)
78 #define ber_pvt_ber_total(ber)          ((ber)->ber_end - (ber)->ber_buf)
79 #define ber_pvt_ber_write(ber)          ((ber)->ber_ptr - (ber)->ber_buf)
80
81 struct sockbuf {
82         struct lber_options sb_opts;
83         Sockbuf_IO_Desc         *sb_iod;                /* I/O functions */
84 #define sb_valid                sb_opts.lbo_valid
85 #define sb_options              sb_opts.lbo_options
86 #define sb_debug                sb_opts.lbo_debug
87         ber_socket_t            sb_fd;
88         unsigned int            sb_trans_needs_read:1;
89         unsigned int            sb_trans_needs_write:1;
90         ber_len_t                       sb_max_incoming;
91 };
92
93 #define SOCKBUF_VALID( sb )     ( (sb)->sb_valid == LBER_VALID_SOCKBUF )
94
95 struct seqorset {
96         BerElement      *sos_ber;
97         ber_len_t       sos_clen;
98         ber_tag_t       sos_tag;
99         char            *sos_first;
100         char            *sos_ptr;
101         struct seqorset *sos_next;
102 };
103
104
105 /*
106  * io.c
107  */
108 int ber_realloc LDAP_P((
109         BerElement *ber,
110         ber_len_t len ));
111
112 /*
113  * bprint.c
114  */
115 #define ber_log_printf ber_pvt_log_printf
116
117 #ifdef NEW_LOGGING
118 LBER_F( int )
119 ber_output_dump LDAP_P((
120         const char *subsys,
121         int level,
122         BerElement *ber,
123         int inout ));
124 #endif
125
126 LBER_F( int )
127 ber_log_bprint LDAP_P((
128         int errlvl,
129         int loglvl,
130         const char *data,
131         ber_len_t len ));
132
133 LBER_F( int )
134 ber_log_dump LDAP_P((
135         int errlvl,
136         int loglvl,
137         BerElement *ber,
138         int inout ));
139
140 LBER_F( int )
141 ber_log_sos_dump LDAP_P((
142         int errlvl,
143         int loglvl,
144         Seqorset *sos ));
145
146
147 /* memory.c */
148         /* simple macros to realloc for now */
149 LBER_F (BerMemoryFunctions *)   ber_int_memory_fns;
150
151 #ifdef CSRIMALLOC
152 #define LBER_INT_MALLOC         malloc
153 #define LBER_INT_CALLOC         calloc
154 #define LBER_INT_REALLOC        realloc
155 #define LBER_INT_FREE           free
156 #define LBER_INT_VFREE          ber_memvfree
157 #define LBER_INT_STRDUP         strdup
158
159 #define LBER_MALLOC                     malloc
160 #define LBER_CALLOC                     calloc
161 #define LBER_REALLOC            realloc
162 #define LBER_FREE                       free
163 #define LBER_VFREE                      ber_memvfree
164 #define LBER_STRDUP                     strdup
165
166 #else
167 #define LBER_INT_MALLOC(s)              ber_memalloc((s))
168 #define LBER_INT_CALLOC(n,s)    ber_memcalloc((n),(s))
169 #define LBER_INT_REALLOC(p,s)   ber_memrealloc((p),(s))
170 #define LBER_INT_FREE(p)                ber_memfree((p))
171 #define LBER_INT_VFREE(v)               ber_memvfree((void**)(v))
172 #define LBER_INT_STRDUP(s)              ber_strdup((s))
173
174 #define LBER_MALLOC(s)          ber_memalloc((s))
175 #define LBER_CALLOC(n,s)        ber_memcalloc((n),(s))
176 #define LBER_REALLOC(p,s)       ber_memrealloc((p),(s))
177 #define LBER_FREE(p)            ber_memfree((p))        
178 #define LBER_VFREE(v)           ber_memvfree((void**)(v))
179 #define LBER_STRDUP(s)          ber_strdup((s))
180 #endif
181
182 /* sockbuf.c */
183
184 LBER_F( int )
185 ber_int_sb_init LDAP_P(( Sockbuf *sb ));
186
187 LBER_F( int )
188 ber_int_sb_close LDAP_P(( Sockbuf *sb ));
189
190 LBER_F( int )
191 ber_int_sb_destroy LDAP_P(( Sockbuf *sb ));
192
193 LBER_F( ber_slen_t )
194 ber_int_sb_read LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
195
196 LBER_F( ber_slen_t )
197 ber_int_sb_write LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
198
199 LDAP_END_DECL
200
201 #endif /* _LBER_INT_H */