]> git.sur5r.net Git - openldap/blob - include/lber_pvt.h
fff5e85ffe99df2b7da9364f356af2a8b85c023d
[openldap] / include / lber_pvt.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2018 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 file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15
16 /*
17  * lber_pvt.h - Header for ber_pvt_ functions. 
18  * These are meant to be internal to OpenLDAP Software.
19  */
20
21 #ifndef _LBER_PVT_H
22 #define _LBER_PVT_H 1
23
24 #include <lber.h>
25
26 LDAP_BEGIN_DECL
27
28 /* for allocating aligned buffers (on the stack) */
29 #define LBER_ALIGNED_BUFFER(uname,size) \
30         union uname { \
31                 char buffer[size]; \
32                 /* force alignment */ \
33                 int ialign; \
34                 long lalign; \
35                 float falign; \
36                 double dalign; \
37                 char* palign; \
38         }
39
40 #define LBER_ELEMENT_SIZEOF (256) /* must be >= sizeof(BerElement) */
41 typedef LBER_ALIGNED_BUFFER(lber_berelement_u,LBER_ELEMENT_SIZEOF)
42         BerElementBuffer;
43
44 typedef struct sockbuf_buf {
45         ber_len_t               buf_size;
46         ber_len_t               buf_ptr;
47         ber_len_t               buf_end;
48         char                    *buf_base;
49 } Sockbuf_Buf;
50
51 /*
52  * bprint.c
53  */
54 LBER_V( BER_LOG_PRINT_FN ) ber_pvt_log_print;
55
56 LBER_F( int )
57 ber_pvt_log_printf LDAP_P((
58         int errlvl,
59         int loglvl,
60         const char *fmt,
61         ... )) LDAP_GCCATTR((format(printf, 3, 4)));
62
63 /*
64  * sockbuf.c
65  */
66 LBER_F( ber_slen_t )
67 ber_pvt_sb_do_write LDAP_P(( Sockbuf_IO_Desc *sbiod, Sockbuf_Buf *buf_out ));
68
69 LBER_F( void )
70 ber_pvt_sb_buf_init LDAP_P(( Sockbuf_Buf *buf ));
71
72 LBER_F( void )
73 ber_pvt_sb_buf_destroy LDAP_P(( Sockbuf_Buf *buf ));
74
75 LBER_F( int )
76 ber_pvt_sb_grow_buffer LDAP_P(( Sockbuf_Buf *buf, ber_len_t minsize ));
77
78 LBER_F( ber_len_t )
79 ber_pvt_sb_copy_out LDAP_P(( Sockbuf_Buf *sbb, char *buf, ber_len_t len ));
80
81 LBER_F( int )
82 ber_pvt_socket_set_nonblock LDAP_P(( ber_socket_t sd, int nb ));
83
84 /*
85  * memory.c
86  */
87 LBER_F( void * )
88 ber_memalloc_x LDAP_P((
89         ber_len_t s, void *ctx));
90
91 LBER_F( void * )
92 ber_memrealloc_x LDAP_P((
93         void* p,
94         ber_len_t s, void *ctx ));
95
96 LBER_F( void * )
97 ber_memcalloc_x LDAP_P((
98         ber_len_t n,
99         ber_len_t s, void *ctx ));
100
101 LBER_F( void )
102 ber_memfree_x LDAP_P((
103         void* p, void *ctx ));
104
105 LBER_F( void )
106 ber_memvfree_x LDAP_P((
107         void** vector, void *ctx ));
108
109 LBER_F( void )
110 ber_bvfree_x LDAP_P((
111         struct berval *bv, void *ctx ));
112
113 LBER_F( void )
114 ber_bvecfree_x LDAP_P((
115         struct berval **bv, void *ctx ));
116
117 LBER_F( int )
118 ber_bvecadd_x LDAP_P((
119         struct berval ***bvec,
120         struct berval *bv, void *ctx ));
121
122 LBER_F( struct berval * )
123 ber_dupbv_x LDAP_P((
124         struct berval *dst, struct berval *src, void *ctx ));
125
126 LBER_F( struct berval * )
127 ber_str2bv_x LDAP_P((
128         LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
129
130 LBER_F( struct berval * )
131 ber_mem2bv_x LDAP_P((
132         LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
133
134 LBER_F( char * )
135 ber_strdup_x LDAP_P((
136         LDAP_CONST char *, void *ctx ));
137
138 LBER_F( struct berval * )
139 ber_bvreplace_x LDAP_P((
140         struct berval *dst, LDAP_CONST struct berval *src, void *ctx ));
141
142 LBER_F( void )
143 ber_bvarray_free_x LDAP_P(( BerVarray p, void *ctx ));
144
145 LBER_F( int )
146 ber_bvarray_add_x LDAP_P(( BerVarray *p, BerValue *bv, void *ctx ));
147
148 LBER_F( int )
149 ber_bvarray_dup_x LDAP_P(( BerVarray *dst, BerVarray src, void *ctx ));
150
151 #if 0
152 #define ber_bvstrcmp(v1,v2) \
153         ((v1)->bv_len < (v2)->bv_len \
154                 ? -1 : ((v1)->bv_len > (v2)->bv_len \
155                         ? 1 : strncmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
156 #else
157         /* avoid strncmp() */
158 #define ber_bvstrcmp(v1,v2)     ber_bvcmp((v1),(v2))
159 #endif
160
161 #define ber_bvstrcasecmp(v1,v2) \
162         ((v1)->bv_len < (v2)->bv_len \
163                 ? -1 : ((v1)->bv_len > (v2)->bv_len \
164                         ? 1 : strncasecmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
165
166 #define ber_bvccmp(v1,c) \
167         ( (v1)->bv_len == 1 && (v1)->bv_val[0] == (c) )
168
169 #define ber_strccmp(s,c) \
170         ( (s)[0] == (c) && (s)[1] == '\0' )
171
172 #define ber_bvchr(bv,c) \
173         ((char *) memchr( (bv)->bv_val, (c), (bv)->bv_len ))
174
175 #define ber_bvrchr(bv,c) \
176         ((char *) lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ))
177
178 #define ber_bvchr_post(dst,bv,c) \
179         do { \
180                 (dst)->bv_val = memchr( (bv)->bv_val, (c), (bv)->bv_len ); \
181                 (dst)->bv_len = (dst)->bv_val ? (bv)->bv_len - ((dst)->bv_val - (bv)->bv_val) : 0; \
182         } while (0)
183
184 #define ber_bvchr_pre(dst,bv,c) \
185         do { \
186                 (dst)->bv_val = memchr( (bv)->bv_val, (c), (bv)->bv_len ); \
187                 (dst)->bv_len = (dst)->bv_val ? ((dst)->bv_val - (bv)->bv_val) : (bv)->bv_len; \
188                 (dst)->bv_val = (bv)->bv_val; \
189         } while (0)
190
191 #define ber_bvrchr_post(dst,bv,c) \
192         do { \
193                 (dst)->bv_val = lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ); \
194                 (dst)->bv_len = (dst)->bv_val ? (bv)->bv_len - ((dst)->bv_val - (bv)->bv_val) : 0; \
195         } while (0)
196
197 #define ber_bvrchr_pre(dst,bv,c) \
198         do { \
199                 (dst)->bv_val = lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ); \
200                 (dst)->bv_len = (dst)->bv_val ? ((dst)->bv_val - (bv)->bv_val) : (bv)->bv_len; \
201                 (dst)->bv_val = (bv)->bv_val; \
202         } while (0)
203
204 #define BER_BVC(s)              { STRLENOF(s), (char *)(s) }
205 #define BER_BVNULL              { 0L, NULL }
206 #define BER_BVZERO(bv) \
207         do { \
208                 (bv)->bv_len = 0; \
209                 (bv)->bv_val = NULL; \
210         } while (0)
211 #define BER_BVSTR(bv,s) \
212         do { \
213                 (bv)->bv_len = STRLENOF(s); \
214                 (bv)->bv_val = (s); \
215         } while (0)
216 #define BER_BVISNULL(bv)        ((bv)->bv_val == NULL)
217 #define BER_BVISEMPTY(bv)       ((bv)->bv_len == 0)
218
219 LDAP_END_DECL
220
221 #endif
222