Back to index

openldap  2.4.31
lber_pvt.h
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1998-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 
00016 /*
00017  * lber_pvt.h - Header for ber_pvt_ functions. 
00018  * These are meant to be internal to OpenLDAP Software.
00019  */
00020 
00021 #ifndef _LBER_PVT_H
00022 #define _LBER_PVT_H 1
00023 
00024 #include <lber.h>
00025 
00026 LDAP_BEGIN_DECL
00027 
00028 /* for allocating aligned buffers (on the stack) */
00029 #define LBER_ALIGNED_BUFFER(uname,size) \
00030        union uname { \
00031               char buffer[size]; \
00032               /* force alignment */ \
00033               int ialign; \
00034               long lalign; \
00035               float falign; \
00036               double dalign; \
00037               char* palign; \
00038        }
00039 
00040 #define LBER_ELEMENT_SIZEOF (256) /* must be >= sizeof(BerElement) */
00041 typedef LBER_ALIGNED_BUFFER(lber_berelement_u,LBER_ELEMENT_SIZEOF)
00042        BerElementBuffer;
00043 
00044 typedef struct sockbuf_buf {
00045        ber_len_t            buf_size;
00046        ber_len_t            buf_ptr;
00047        ber_len_t            buf_end;
00048        char                 *buf_base;
00049 } Sockbuf_Buf;
00050 
00051 /*
00052  * bprint.c
00053  */
00054 LBER_V( BER_LOG_PRINT_FN ) ber_pvt_log_print;
00055 
00056 LBER_F( int )
00057 ber_pvt_log_printf LDAP_P((
00058        int errlvl,
00059        int loglvl,
00060        const char *fmt,
00061        ... )) LDAP_GCCATTR((format(printf, 3, 4)));
00062 
00063 /*
00064  * sockbuf.c
00065  */
00066 LBER_F( ber_slen_t )
00067 ber_pvt_sb_do_write LDAP_P(( Sockbuf_IO_Desc *sbiod, Sockbuf_Buf *buf_out ));
00068 
00069 LBER_F( void )
00070 ber_pvt_sb_buf_init LDAP_P(( Sockbuf_Buf *buf ));
00071 
00072 LBER_F( void )
00073 ber_pvt_sb_buf_destroy LDAP_P(( Sockbuf_Buf *buf ));
00074 
00075 LBER_F( int )
00076 ber_pvt_sb_grow_buffer LDAP_P(( Sockbuf_Buf *buf, ber_len_t minsize ));
00077 
00078 LBER_F( ber_len_t )
00079 ber_pvt_sb_copy_out LDAP_P(( Sockbuf_Buf *sbb, char *buf, ber_len_t len ));
00080 
00081 LBER_F( int )
00082 ber_pvt_socket_set_nonblock LDAP_P(( ber_socket_t sd, int nb ));
00083 
00084 /*
00085  * memory.c
00086  */
00087 LBER_F( void * )
00088 ber_memalloc_x LDAP_P((
00089        ber_len_t s, void *ctx));
00090 
00091 LBER_F( void * )
00092 ber_memrealloc_x LDAP_P((
00093        void* p,
00094        ber_len_t s, void *ctx ));
00095 
00096 LBER_F( void * )
00097 ber_memcalloc_x LDAP_P((
00098        ber_len_t n,
00099        ber_len_t s, void *ctx ));
00100 
00101 LBER_F( void )
00102 ber_memfree_x LDAP_P((
00103        void* p, void *ctx ));
00104 
00105 LBER_F( void )
00106 ber_memvfree_x LDAP_P((
00107        void** vector, void *ctx ));
00108 
00109 LBER_F( void )
00110 ber_bvfree_x LDAP_P((
00111        struct berval *bv, void *ctx ));
00112 
00113 LBER_F( void )
00114 ber_bvecfree_x LDAP_P((
00115        struct berval **bv, void *ctx ));
00116 
00117 LBER_F( int )
00118 ber_bvecadd_x LDAP_P((
00119        struct berval ***bvec,
00120        struct berval *bv, void *ctx ));
00121 
00122 LBER_F( struct berval * )
00123 ber_dupbv_x LDAP_P((
00124        struct berval *dst, struct berval *src, void *ctx ));
00125 
00126 LBER_F( struct berval * )
00127 ber_str2bv_x LDAP_P((
00128        LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
00129 
00130 LBER_F( struct berval * )
00131 ber_mem2bv_x LDAP_P((
00132        LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
00133 
00134 LBER_F( char * )
00135 ber_strdup_x LDAP_P((
00136        LDAP_CONST char *, void *ctx ));
00137 
00138 LBER_F( struct berval * )
00139 ber_bvreplace_x LDAP_P((
00140        struct berval *dst, LDAP_CONST struct berval *src, void *ctx ));
00141 
00142 LBER_F( void )
00143 ber_bvarray_free_x LDAP_P(( BerVarray p, void *ctx ));
00144 
00145 LBER_F( int )
00146 ber_bvarray_add_x LDAP_P(( BerVarray *p, BerValue *bv, void *ctx ));
00147 
00148 LBER_F( int )
00149 ber_bvarray_dup_x LDAP_P(( BerVarray *dst, BerVarray src, void *ctx ));
00150 
00151 #if 0
00152 #define ber_bvstrcmp(v1,v2) \
00153        ((v1)->bv_len < (v2)->bv_len \
00154               ? -1 : ((v1)->bv_len > (v2)->bv_len \
00155                      ? 1 : strncmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
00156 #else
00157        /* avoid strncmp() */
00158 #define ber_bvstrcmp(v1,v2) ber_bvcmp((v1),(v2))
00159 #endif
00160 
00161 #define ber_bvstrcasecmp(v1,v2) \
00162        ((v1)->bv_len < (v2)->bv_len \
00163               ? -1 : ((v1)->bv_len > (v2)->bv_len \
00164                      ? 1 : strncasecmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
00165 
00166 #define ber_bvccmp(v1,c) \
00167        ( (v1)->bv_len == 1 && (v1)->bv_val[0] == (c) )
00168 
00169 #define ber_strccmp(s,c) \
00170        ( (s)[0] == (c) && (s)[1] == '\0' )
00171 
00172 #define ber_bvchr(bv,c) \
00173        ((char *) memchr( (bv)->bv_val, (c), (bv)->bv_len ))
00174 
00175 #define ber_bvrchr(bv,c) \
00176        ((char *) lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ))
00177 
00178 #define ber_bvchr_post(dst,bv,c) \
00179        do { \
00180               (dst)->bv_val = memchr( (bv)->bv_val, (c), (bv)->bv_len ); \
00181               (dst)->bv_len = (dst)->bv_val ? (bv)->bv_len - ((dst)->bv_val - (bv)->bv_val) : 0; \
00182        } while (0)
00183 
00184 #define ber_bvchr_pre(dst,bv,c) \
00185        do { \
00186               (dst)->bv_val = memchr( (bv)->bv_val, (c), (bv)->bv_len ); \
00187               (dst)->bv_len = (dst)->bv_val ? ((dst)->bv_val - (bv)->bv_val) : (bv)->bv_len; \
00188               (dst)->bv_val = (bv)->bv_val; \
00189        } while (0)
00190 
00191 #define ber_bvrchr_post(dst,bv,c) \
00192        do { \
00193               (dst)->bv_val = lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ); \
00194               (dst)->bv_len = (dst)->bv_val ? (bv)->bv_len - ((dst)->bv_val - (bv)->bv_val) : 0; \
00195        } while (0)
00196 
00197 #define ber_bvrchr_pre(dst,bv,c) \
00198        do { \
00199               (dst)->bv_val = lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ); \
00200               (dst)->bv_len = (dst)->bv_val ? ((dst)->bv_val - (bv)->bv_val) : (bv)->bv_len; \
00201               (dst)->bv_val = (bv)->bv_val; \
00202        } while (0)
00203 
00204 #define BER_BVC(s)          { STRLENOF(s), (char *)(s) }
00205 #define BER_BVNULL          { 0L, NULL }
00206 #define BER_BVZERO(bv) \
00207        do { \
00208               (bv)->bv_len = 0; \
00209               (bv)->bv_val = NULL; \
00210        } while (0)
00211 #define BER_BVSTR(bv,s)     \
00212        do { \
00213               (bv)->bv_len = STRLENOF(s); \
00214               (bv)->bv_val = (s); \
00215        } while (0)
00216 #define BER_BVISNULL(bv)    ((bv)->bv_val == NULL)
00217 #define BER_BVISEMPTY(bv)   ((bv)->bv_len == 0)
00218 
00219 LDAP_END_DECL
00220 
00221 #endif
00222