]> git.sur5r.net Git - openldap/blob - libraries/liblber/lber-int.h
5bd643f04ff150233643b54f7fd4dde54e9c4ef5
[openldap] / libraries / liblber / lber-int.h
1 /*
2  * Copyright 1998 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5 /* Portions
6  * Copyright (c) 1990 Regents of the University of Michigan.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms are permitted
10  * provided that this notice is preserved and that due credit is given
11  * to the University of Michigan at Ann Arbor. The name of the University
12  * may not be used to endorse or promote products derived from this
13  * software without specific prior written permission. This software
14  * is provided ``as is'' without express or implied warranty.
15  */
16
17 #ifndef _LBER_INT_H
18 #define _LBER_INT_H
19
20 #include "lber.h"
21 #include "ldap_log.h"
22 #include "lber_pvt.h"
23
24 LDAP_BEGIN_DECL
25
26 extern BER_MEMORY_FN    ber_int_realloc;
27
28 struct lber_options {
29         short lbo_valid;
30 #define LBER_UNINITIALIZED              0x0
31 #define LBER_INITIALIZED                0x1
32 #define LBER_VALID_BERELEMENT   0x2
33 #define LBER_VALID_SOCKBUF              0x3
34
35         unsigned short lbo_options;
36         int lbo_debug;
37 };
38
39 extern struct lber_options ber_int_options;
40 #define ber_int_debug ber_int_options.lbo_debug
41
42 struct berelement {
43         struct          lber_options ber_opts;
44 #define ber_valid               ber_opts.lbo_valid
45 #define ber_options             ber_opts.lbo_options
46 #define ber_debug               ber_opts.lbo_debug
47
48         int                     ber_usertag;
49
50         unsigned long   ber_tag;
51         unsigned long   ber_len;
52
53         char            *ber_buf;
54         char            *ber_ptr;
55         char            *ber_end;
56
57         struct seqorset *ber_sos;
58         char            *ber_rwptr;
59         BERTranslateProc ber_encode_translate_proc;
60         BERTranslateProc ber_decode_translate_proc;
61 };
62 #define BER_VALID(ber)  ((ber)->ber_valid==LBER_VALID_BERELEMENT)
63 #define NULLBER ((BerElement *) 0)
64
65 #define ber_pvt_ber_bytes(ber)          ((ber)->ber_ptr - (ber)->ber_buf)
66 #define ber_pvt_ber_remaining(ber)      ((ber)->ber_end - (ber)->ber_ptr)
67
68 struct sockbuf;
69
70 struct sockbuf_io {
71         int     (*sbi_setup)( struct sockbuf * sb, void *arg );
72         int     (*sbi_remove)( struct sockbuf *sb );
73         
74         long    (*sbi_read)( struct sockbuf *sb, void *buf, long len );
75         long    (*sbi_write)( struct sockbuf *sb, void *buf, long len );
76         int     (*sbi_close)( struct sockbuf *sb );
77 };
78
79 struct sockbuf_sec {
80         int     (*sbs_setup)( struct sockbuf * sb, void *arg );
81         int     (*sbs_remove)( struct sockbuf *sb );
82    
83         long    (*sbs_protect)( struct sockbuf *sb, char *in, long *ilen,
84                                 char *out, long olen );
85         long    (*sbs_release)( struct sockbuf *sb, char *in, long ilen,
86                                char *out0, long olen0, char *out1, long olen1 );
87 };
88
89 struct sockbuf_buf {
90         long    buf_size;
91         long    buf_ptr;
92         long    buf_end;
93         char    *buf_base;
94 };
95
96 typedef struct sockbuf_io Sockbuf_IO;
97 typedef struct sockbuf_sec Sockbuf_Sec;
98 typedef struct sockbuf_buf Sockbuf_Buf;
99
100 extern Sockbuf_IO ber_pvt_sb_io_tcp;
101 extern Sockbuf_IO ber_pvt_sb_io_udp;
102
103
104 struct sockbuf {
105         struct lber_options sb_opts;
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
110         int             sb_non_block:1; 
111         int             sb_read_ahead:1;
112    
113         int             sb_buf_ready:1;
114         int             sb_trans_ready:1;
115         int             sb_sec_ready:1;
116       
117         int             sb_fd;
118    
119         void            *sb_iodata;     /* transport-layer data pointer */
120         Sockbuf_IO      *sb_io;         /* I/O functions */
121    
122 #ifdef LDAP_SASL
123         void            *sb_sdata;      /* security-layer data pointer */
124         Sockbuf_Sec     *sb_sec;
125 #endif  
126         
127 #ifndef MACOS
128         int             sb_sd;
129 #else /* MACOS */
130         void            *sb_sd;
131 #endif /* MACOS */
132 #ifdef DEADWOOD
133         long            sb_max_incoming;
134 #endif
135         Sockbuf_Buf     sb_buf;
136 #ifdef LDAP_SASL   
137         Sockbuf_Buf     sb_sec_buf_in;
138         Sockbuf_Buf     sb_sec_buf_out;
139         long            sb_sec_prev_len;
140 #endif   
141 };
142 #define SOCKBUF_VALID(ber)      ((sb)->sb_valid==LBER_VALID_SOCKBUF)
143
144 /* these should be internal ie: ber_int_* */
145 #define ber_pvt_sb_get_desc( sb ) ((sb)->sb_sd)
146 #define ber_pvt_sb_set_desc( sb, val ) ((sb)->sb_sd =(val))
147
148 #define ber_pvt_sb_in_use( sb ) ((sb)->sb_sd!=-1)
149
150 #ifdef USE_SASL
151 #define ber_pvt_sb_data_ready( sb ) \
152 (((sb)->sb_buf_ready) || ((sb)->sb_trans_ready) || ((sb)->sb_sec_ready))
153 #else
154 #define ber_pvt_sb_data_ready( sb ) \
155 (((sb)->sb_buf_ready) || ((sb)->sb_trans_ready))
156 #endif
157
158 #define READBUFSIZ      8192
159
160 struct seqorset {
161         BerElement      *sos_ber;
162         unsigned long   sos_clen;
163         unsigned long   sos_tag;
164         char            *sos_first;
165         char            *sos_ptr;
166         struct seqorset *sos_next;
167 };
168 #define NULLSEQORSET    ((Seqorset *) 0)
169
170 /*
171  * bprint.c
172  */
173 #define ber_log_printf ber_pvt_log_printf
174
175 LDAP_F( int )
176 ber_log_bprint LDAP_P((
177         int errlvl,
178         int loglvl,
179         const char *data,
180         int len ));
181
182 LDAP_F( int )
183 ber_log_dump LDAP_P((
184         int errlvl,
185         int loglvl,
186         const BerElement *ber,
187         int inout ));
188
189 LDAP_F( int )
190 ber_log_sos_dump LDAP_P((
191         int errlvl,
192         int loglvl,
193         const Seqorset *sos ));
194
195
196 /* memory.c */
197         /* simple macros to realloc for now */
198 #define LBER_MALLOC(s)  \
199         (ber_int_realloc \
200                 ? (*ber_int_realloc)(NULL,(s)) \
201                 : realloc(NULL,(s)))
202
203 #define LBER_CALLOC(n,s) \
204         (ber_int_realloc \
205                 ? ber_int_calloc((n),(s)) \
206                 : calloc((n),(s)))
207
208 #define LBER_REALLOC(p,s) \
209         (ber_int_realloc \
210                 ? (*ber_int_realloc)((p),(s)) \
211                 : realloc((p),(s)))
212
213 #define LBER_FREE(p) \
214         (ber_int_realloc \
215                 ? (*ber_int_realloc)((p),(size_t)0) \
216                 : realloc((p),(size_t)0))
217
218 LDAP_F( void * )
219 ber_int_calloc LDAP_P((
220         size_t n,
221         size_t size ));
222
223
224 /* sockbuf.c */
225
226 /* these should be ber_int*() functions */
227
228 LDAP_F( int )
229 ber_pvt_sb_init LDAP_P(( Sockbuf *sb ));
230
231 LDAP_F( int )
232 ber_pvt_sb_destroy LDAP_P(( Sockbuf *sb ));
233 #ifdef USE_SASL
234
235 LDAP_F( int )
236 ber_pvt_sb_set_sec LDAP_P(( Sockbuf *sb, Sockbuf_Sec *sec, void *arg ));
237
238 LDAP_F( int )
239 ber_pvt_sb_clear_sec LDAP_P(( Sockbuf *sb ));
240 #endif
241
242 LDAP_F( int )
243 ber_pvt_sb_set_io LDAP_P(( Sockbuf *sb, Sockbuf_IO *layer, void *arg ));
244
245 LDAP_F( int )
246 ber_pvt_sb_clear_io LDAP_P(( Sockbuf *sb ));
247
248 LDAP_F( int )
249 ber_pvt_sb_close LDAP_P((Sockbuf *sb ));
250
251 LDAP_F( int )
252 ber_pvt_sb_set_nonblock LDAP_P(( Sockbuf *sb, int nb ));
253
254 LDAP_F( int )
255 ber_pvt_sb_set_readahead LDAP_P(( Sockbuf *sb, int rh ));
256
257 LDAP_F( long )
258 ber_pvt_sb_read LDAP_P(( Sockbuf *sb, void *buf, long len ));
259
260 LDAP_F( long )
261 ber_pvt_sb_write LDAP_P(( Sockbuf *sb, void *buf, long len ));
262
263 LDAP_F( int )
264 ber_pvt_sb_udp_set_dst LDAP_P((Sockbuf *sb, void *addr ));
265
266 LDAP_F( void * )
267 ber_pvt_sb_udp_get_src LDAP_P((Sockbuf *sb ));
268
269
270 #endif /* _LBER_INT_H */