2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2005 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 ));
139 ber_bvarray_free_x LDAP_P(( BerVarray p, void *ctx ));
142 ber_bvarray_add_x LDAP_P(( BerVarray *p, BerValue *bv, void *ctx ));
145 #define ber_bvstrcmp(v1,v2) \
146 ((v1)->bv_len < (v2)->bv_len \
147 ? -1 : ((v1)->bv_len > (v2)->bv_len \
148 ? 1 : strncmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
150 /* avoid strncmp() */
151 #define ber_bvstrcmp(v1,v2) ber_bvcmp((v1),(v2))
154 #define ber_bvstrcasecmp(v1,v2) \
155 ((v1)->bv_len < (v2)->bv_len \
156 ? -1 : ((v1)->bv_len > (v2)->bv_len \
157 ? 1 : strncasecmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
159 #define ber_bvccmp(v1,c) \
160 ( (v1)->bv_len == 1 && (v1)->bv_val[0] == (c) )
162 #define ber_strccmp(s,c) \
163 ( (s)[0] == (c) && (s)[1] == '\0' )
165 #define ber_bvchr(bv,c) \
166 memchr( (bv)->bv_val, (c), (bv)->bv_len )
168 #define BER_BVC(s) { STRLENOF(s), (s) }
169 #define BER_BVNULL { 0L, NULL }
170 #define BER_BVZERO(bv) \
173 (bv)->bv_val = NULL; \
175 #define BER_BVSTR(bv,s) \
177 (bv)->bv_len = STRLENOF(s); \
178 (bv)->bv_val = (s); \
180 #define BER_BVISNULL(bv) ((bv)->bv_val == NULL)
181 #define BER_BVISEMPTY(bv) ((bv)->bv_len == 0)