1/* $OpenLDAP$ */
2/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 *
4 * Copyright 1998-2011 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
26LDAP_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) */
41typedef LBER_ALIGNED_BUFFER(lber_berelement_u,LBER_ELEMENT_SIZEOF)
42	BerElementBuffer;
43
44typedef 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 */
54LBER_V( BER_LOG_PRINT_FN ) ber_pvt_log_print;
55
56LBER_F( int )
57ber_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 */
66LBER_F( ber_slen_t )
67ber_pvt_sb_do_write LDAP_P(( Sockbuf_IO_Desc *sbiod, Sockbuf_Buf *buf_out ));
68
69LBER_F( void )
70ber_pvt_sb_buf_init LDAP_P(( Sockbuf_Buf *buf ));
71
72LBER_F( void )
73ber_pvt_sb_buf_destroy LDAP_P(( Sockbuf_Buf *buf ));
74
75LBER_F( int )
76ber_pvt_sb_grow_buffer LDAP_P(( Sockbuf_Buf *buf, ber_len_t minsize ));
77
78LBER_F( ber_len_t )
79ber_pvt_sb_copy_out LDAP_P(( Sockbuf_Buf *sbb, char *buf, ber_len_t len ));
80
81LBER_F( int )
82ber_pvt_socket_set_nonblock LDAP_P(( ber_socket_t sd, int nb ));
83
84/*
85 * memory.c
86 */
87LBER_F( void * )
88ber_memalloc_x LDAP_P((
89	ber_len_t s, void *ctx));
90
91LBER_F( void * )
92ber_memrealloc_x LDAP_P((
93	void* p,
94	ber_len_t s, void *ctx ));
95
96LBER_F( void * )
97ber_memcalloc_x LDAP_P((
98	ber_len_t n,
99	ber_len_t s, void *ctx ));
100
101LBER_F( void )
102ber_memfree_x LDAP_P((
103	void* p, void *ctx ));
104
105LBER_F( void )
106ber_memvfree_x LDAP_P((
107	void** vector, void *ctx ));
108
109LBER_F( void )
110ber_bvfree_x LDAP_P((
111	struct berval *bv, void *ctx ));
112
113LBER_F( void )
114ber_bvecfree_x LDAP_P((
115	struct berval **bv, void *ctx ));
116
117LBER_F( int )
118ber_bvecadd_x LDAP_P((
119	struct berval ***bvec,
120	struct berval *bv, void *ctx ));
121
122LBER_F( struct berval * )
123ber_dupbv_x LDAP_P((
124	struct berval *dst, struct berval *src, void *ctx ));
125
126LBER_F( struct berval * )
127ber_str2bv_x LDAP_P((
128	LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
129
130LBER_F( struct berval * )
131ber_mem2bv_x LDAP_P((
132	LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
133
134LBER_F( char * )
135ber_strdup_x LDAP_P((
136	LDAP_CONST char *, void *ctx ));
137
138LBER_F( struct berval * )
139ber_bvreplace_x LDAP_P((
140	struct berval *dst, LDAP_CONST struct berval *src, void *ctx ));
141
142LBER_F( void )
143ber_bvarray_free_x LDAP_P(( BerVarray p, void *ctx ));
144
145LBER_F( int )
146ber_bvarray_add_x LDAP_P(( BerVarray *p, BerValue *bv, void *ctx ));
147
148LBER_F( int )
149ber_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
219LDAP_END_DECL
220
221#endif
222
223