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