1 /* $OpenLDAP: pkg/ldap/include/lber_pvt.h,v 1.35.2.5 2008/03/21 00:43:00 hyc Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
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>.
17 * lber_pvt.h - Header for ber_pvt_ functions.
18 * These are meant to be internal to OpenLDAP Software.
28 /* for allocating aligned buffers (on the stack) */
29 #define LBER_ALIGNED_BUFFER(uname,size) \
32 /* force alignment */ \
40 #define LBER_ELEMENT_SIZEOF (256) /* must be >= sizeof(BerElement) */
41 typedef LBER_ALIGNED_BUFFER(lber_berelement_u
,LBER_ELEMENT_SIZEOF
)
44 typedef struct sockbuf_buf
{
54 LBER_V( BER_LOG_PRINT_FN
) ber_pvt_log_print
;
57 ber_pvt_log_printf
LDAP_P((
61 ... )) LDAP_GCCATTR((format(printf
, 3, 4)));
67 ber_pvt_sb_do_write
LDAP_P(( Sockbuf_IO_Desc
*sbiod
, Sockbuf_Buf
*buf_out
));
70 ber_pvt_sb_buf_init
LDAP_P(( Sockbuf_Buf
*buf
));
73 ber_pvt_sb_buf_destroy
LDAP_P(( Sockbuf_Buf
*buf
));
76 ber_pvt_sb_grow_buffer
LDAP_P(( Sockbuf_Buf
*buf
, ber_len_t minsize
));
79 ber_pvt_sb_copy_out
LDAP_P(( Sockbuf_Buf
*sbb
, char *buf
, ber_len_t len
));
82 ber_pvt_socket_set_nonblock
LDAP_P(( ber_socket_t sd
, int nb
));
88 ber_memalloc_x
LDAP_P((
89 ber_len_t s
, void *ctx
));
92 ber_memrealloc_x
LDAP_P((
94 ber_len_t s
, void *ctx
));
97 ber_memcalloc_x
LDAP_P((
99 ber_len_t s
, void *ctx
));
102 ber_memfree_x
LDAP_P((
103 void* p
, void *ctx
));
106 ber_memvfree_x
LDAP_P((
107 void** vector
, void *ctx
));
110 ber_bvfree_x
LDAP_P((
111 struct berval
*bv
, void *ctx
));
114 ber_bvecfree_x
LDAP_P((
115 struct berval
**bv
, void *ctx
));
118 ber_bvecadd_x
LDAP_P((
119 struct berval
***bvec
,
120 struct berval
*bv
, void *ctx
));
122 LBER_F( struct berval
* )
124 struct berval
*dst
, struct berval
*src
, void *ctx
));
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
));
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
));
135 ber_strdup_x
LDAP_P((
136 LDAP_CONST
char *, void *ctx
));
138 LBER_F( struct berval
* )
139 ber_bvreplace_x
LDAP_P((
140 struct berval
*dst
, LDAP_CONST
struct berval
*src
, void *ctx
));
143 ber_bvarray_free_x
LDAP_P(( BerVarray p
, void *ctx
));
146 ber_bvarray_add_x
LDAP_P(( BerVarray
*p
, BerValue
*bv
, void *ctx
));
149 ber_bvarray_dup_x
LDAP_P(( BerVarray
*dst
, BerVarray src
, void *ctx
));
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) ))
157 /* avoid strncmp() */
158 #define ber_bvstrcmp(v1,v2) ber_bvcmp((v1),(v2))
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) ))
166 #define ber_bvccmp(v1,c) \
167 ( (v1)->bv_len == 1 && (v1)->bv_val[0] == (c) )
169 #define ber_strccmp(s,c) \
170 ( (s)[0] == (c) && (s)[1] == '\0' )
172 #define ber_bvchr(bv,c) \
173 ((char *) memchr( (bv)->bv_val, (c), (bv)->bv_len ))
175 #define ber_bvrchr(bv,c) \
176 ((char *) memrchr( (bv)->bv_val, (c), (bv)->bv_len ))
178 #define ber_bvchr_post(dst,bv,c) \
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; \
184 #define ber_bvchr_pre(dst,bv,c) \
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; \
191 #define ber_bvrchr_post(dst,bv,c) \
193 (dst)->bv_val = 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; \
197 #define ber_bvrchr_pre(dst,bv,c) \
199 (dst)->bv_val = 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; \
204 #define BER_BVC(s) { STRLENOF(s), (char *)(s) }
205 #define BER_BVNULL { 0L, NULL }
206 #define BER_BVZERO(bv) \
209 (bv)->bv_val = NULL; \
211 #define BER_BVSTR(bv,s) \
213 (bv)->bv_len = STRLENOF(s); \
214 (bv)->bv_val = (s); \
216 #define BER_BVISNULL(bv) ((bv)->bv_val == NULL)
217 #define BER_BVISEMPTY(bv) ((bv)->bv_len == 0)