]> git.sur5r.net Git - openldap/blob - include/lber_pvt.h
First rounded of changes in prep for 2.2.beta3
[openldap] / include / lber_pvt.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, Redwood City, California, USA
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted only as authorized by the OpenLDAP
8  * Public License.  A copy of this license is available at
9  * http://www.OpenLDAP.org/license.html or in file LICENSE in the
10  * top-level directory of the distribution.
11  */
12 /*
13  * lber_pvt.h - Header for ber_pvt_ functions. These are meant to be used
14  *              by the OpenLDAP distribution only.
15  */
16
17 #ifndef _LBER_PVT_H
18 #define _LBER_PVT_H 1
19
20 #include <lber.h>
21
22 LDAP_BEGIN_DECL
23
24 /* for allocating aligned buffers (on the stack) */
25 #define LBER_ALIGNED_BUFFER(uname,size) \
26         union uname { \
27                 char buffer[size]; \
28                 /* force alignment */ \
29                 int ialign; \
30                 long lalign; \
31                 float falign; \
32                 double dalign; \
33                 char* palign; \
34         }
35
36 #define LBER_ELEMENT_SIZEOF (256) /* must be >= sizeof(BerElement) */
37 typedef LBER_ALIGNED_BUFFER(lber_berelement_u,LBER_ELEMENT_SIZEOF)
38         BerElementBuffer;
39
40 typedef struct sockbuf_buf {
41         ber_len_t               buf_size;
42         ber_len_t               buf_ptr;
43         ber_len_t               buf_end;
44         char                    *buf_base;
45 } Sockbuf_Buf;
46
47 /*
48  * bprint.c
49  */
50 LBER_V( BER_LOG_PRINT_FN ) ber_pvt_log_print;
51
52 LBER_F( int )
53 ber_pvt_log_printf LDAP_P((
54         int errlvl,
55         int loglvl,
56         const char *fmt,
57         ... )) LDAP_GCCATTR((format(printf, 3, 4)));
58
59 /*
60  * sockbuf.c
61  */
62 LBER_F( ber_slen_t )
63 ber_pvt_sb_do_write LDAP_P(( Sockbuf_IO_Desc *sbiod, Sockbuf_Buf *buf_out ));
64
65 LBER_F( void )
66 ber_pvt_sb_buf_init LDAP_P(( Sockbuf_Buf *buf ));
67
68 LBER_F( void )
69 ber_pvt_sb_buf_destroy LDAP_P(( Sockbuf_Buf *buf ));
70
71 LBER_F( int )
72 ber_pvt_sb_grow_buffer LDAP_P(( Sockbuf_Buf *buf, ber_len_t minsize ));
73
74 LBER_F( ber_len_t )
75 ber_pvt_sb_copy_out LDAP_P(( Sockbuf_Buf *sbb, char *buf, ber_len_t len ));
76
77 LBER_F( int )
78 ber_pvt_socket_set_nonblock LDAP_P(( ber_socket_t sd, int nb ));
79
80 /*
81  * memory.c
82  */
83 LBER_F( void * )
84 ber_memalloc_x LDAP_P((
85         ber_len_t s, void *ctx));
86
87 LBER_F( void * )
88 ber_memrealloc_x LDAP_P((
89         void* p,
90         ber_len_t s, void *ctx ));
91
92 LBER_F( void * )
93 ber_memcalloc_x LDAP_P((
94         ber_len_t n,
95         ber_len_t s, void *ctx ));
96
97 LBER_F( void )
98 ber_memfree_x LDAP_P((
99         void* p, void *ctx ));
100
101 LBER_F( void )
102 ber_memvfree_x LDAP_P((
103         void** vector, void *ctx ));
104
105 LBER_F( void )
106 ber_bvfree_x LDAP_P((
107         struct berval *bv, void *ctx ));
108
109 LBER_F( void )
110 ber_bvecfree_x LDAP_P((
111         struct berval **bv, void *ctx ));
112
113 LBER_F( int )
114 ber_bvecadd_x LDAP_P((
115         struct berval ***bvec,
116         struct berval *bv, void *ctx ));
117
118 LBER_F( struct berval * )
119 ber_dupbv_x LDAP_P((
120         struct berval *dst, struct berval *src, void *ctx ));
121
122 LBER_F( struct berval * )
123 ber_str2bv_x LDAP_P((
124         LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
125
126 LBER_F( struct berval * )
127 ber_mem2bv_x LDAP_P((
128         LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
129
130 LBER_F( char * )
131 ber_strdup_x LDAP_P((
132         LDAP_CONST char *, void *ctx ));
133
134 LBER_F( void )
135 ber_bvarray_free_x LDAP_P(( BerVarray p, void *ctx ));
136
137 LBER_F( int )
138 ber_bvarray_add_x LDAP_P(( BerVarray *p, BerValue *bv, void *ctx ));
139
140 #if 0
141 #define ber_bvstrcmp(v1,v2) \
142         ((v1)->bv_len < (v2)->bv_len \
143                 ? -1 : ((v1)->bv_len > (v2)->bv_len \
144                         ? 1 : strncmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
145 #else
146         /* avoid strncmp() */
147 #define ber_bvstrcmp(v1,v2)     ber_bvcmp((v1),(v2))
148 #endif
149
150 #define ber_bvstrcasecmp(v1,v2) \
151         ((v1)->bv_len < (v2)->bv_len \
152                 ? -1 : ((v1)->bv_len > (v2)->bv_len \
153                         ? 1 : strncasecmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
154
155 #define ber_bvccmp(v1,c) \
156         ( (v1)->bv_len == 1 && (v1)->bv_val[0] == (c) )
157
158 #define ber_strccmp(s,c) \
159         ( (s)[0] == (c) && (s)[1] == '\0' )
160
161 #define ber_bvchr(bv,c) \
162         memchr( (bv)->bv_val, (c), (bv)->bv_len )
163
164 #define BER_BVC(x)      { sizeof( (x) ) - 1, (x) }
165 #define BER_BVNULL      { 0L, NULL }
166
167 LDAP_END_DECL
168
169 #endif
170