lber_pvt.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* $OpenLDAP$ */
  2. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  3. *
  4. * Copyright 1998-2022 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. * lber_pvt.h - Header for ber_pvt_ functions.
  17. * These are meant to be internal to OpenLDAP Software.
  18. */
  19. #ifndef _LBER_PVT_H
  20. #define _LBER_PVT_H 1
  21. #include <lber.h>
  22. LDAP_BEGIN_DECL
  23. /* for allocating aligned buffers (on the stack) */
  24. #define LBER_ALIGNED_BUFFER(uname,size) \
  25. union uname { \
  26. char buffer[size]; \
  27. /* force alignment */ \
  28. int ialign; \
  29. long lalign; \
  30. float falign; \
  31. double dalign; \
  32. char* palign; \
  33. }
  34. #define LBER_ELEMENT_SIZEOF (256) /* must be >= sizeof(BerElement) */
  35. typedef LBER_ALIGNED_BUFFER(lber_berelement_u,LBER_ELEMENT_SIZEOF)
  36. BerElementBuffer;
  37. typedef struct sockbuf_buf {
  38. ber_len_t buf_size;
  39. ber_len_t buf_ptr;
  40. ber_len_t buf_end;
  41. char *buf_base;
  42. } Sockbuf_Buf;
  43. /*
  44. * bprint.c
  45. */
  46. LBER_V( BER_LOG_PRINT_FN ) ber_pvt_log_print;
  47. LBER_F( int )
  48. ber_pvt_log_printf LDAP_P((
  49. int errlvl,
  50. int loglvl,
  51. const char *fmt,
  52. ... )) LDAP_GCCATTR((format(printf, 3, 4)));
  53. /*
  54. * sockbuf.c
  55. */
  56. LBER_F( ber_slen_t )
  57. ber_pvt_sb_do_write LDAP_P(( Sockbuf_IO_Desc *sbiod, Sockbuf_Buf *buf_out ));
  58. LBER_F( void )
  59. ber_pvt_sb_buf_init LDAP_P(( Sockbuf_Buf *buf ));
  60. LBER_F( void )
  61. ber_pvt_sb_buf_destroy LDAP_P(( Sockbuf_Buf *buf ));
  62. LBER_F( int )
  63. ber_pvt_sb_grow_buffer LDAP_P(( Sockbuf_Buf *buf, ber_len_t minsize ));
  64. LBER_F( ber_len_t )
  65. ber_pvt_sb_copy_out LDAP_P(( Sockbuf_Buf *sbb, char *buf, ber_len_t len ));
  66. LBER_F( int )
  67. ber_pvt_socket_set_nonblock LDAP_P(( ber_socket_t sd, int nb ));
  68. /*
  69. * memory.c
  70. */
  71. LBER_F( void * )
  72. ber_memalloc_x LDAP_P((
  73. ber_len_t s, void *ctx));
  74. LBER_F( void * )
  75. ber_memrealloc_x LDAP_P((
  76. void* p,
  77. ber_len_t s, void *ctx ));
  78. LBER_F( void * )
  79. ber_memcalloc_x LDAP_P((
  80. ber_len_t n,
  81. ber_len_t s, void *ctx ));
  82. LBER_F( void )
  83. ber_memfree_x LDAP_P((
  84. void* p, void *ctx ));
  85. LBER_F( void )
  86. ber_memvfree_x LDAP_P((
  87. void** vector, void *ctx ));
  88. LBER_F( void )
  89. ber_bvfree_x LDAP_P((
  90. struct berval *bv, void *ctx ));
  91. LBER_F( void )
  92. ber_bvecfree_x LDAP_P((
  93. struct berval **bv, void *ctx ));
  94. LBER_F( int )
  95. ber_bvecadd_x LDAP_P((
  96. struct berval ***bvec,
  97. struct berval *bv, void *ctx ));
  98. LBER_F( struct berval * )
  99. ber_dupbv_x LDAP_P((
  100. struct berval *dst, struct berval *src, void *ctx ));
  101. LBER_F( struct berval * )
  102. ber_str2bv_x LDAP_P((
  103. LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
  104. LBER_F( struct berval * )
  105. ber_mem2bv_x LDAP_P((
  106. LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
  107. LBER_F( char * )
  108. ber_strdup_x LDAP_P((
  109. LDAP_CONST char *, void *ctx ));
  110. LBER_F( struct berval * )
  111. ber_bvreplace_x LDAP_P((
  112. struct berval *dst, LDAP_CONST struct berval *src, void *ctx ));
  113. LBER_F( void )
  114. ber_bvarray_free_x LDAP_P(( BerVarray p, void *ctx ));
  115. LBER_F( int )
  116. ber_bvarray_add_x LDAP_P(( BerVarray *p, BerValue *bv, void *ctx ));
  117. LBER_F( int )
  118. ber_bvarray_dup_x LDAP_P(( BerVarray *dst, BerVarray src, void *ctx ));
  119. #if 0
  120. #define ber_bvstrcmp(v1,v2) \
  121. ((v1)->bv_len < (v2)->bv_len \
  122. ? -1 : ((v1)->bv_len > (v2)->bv_len \
  123. ? 1 : strncmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
  124. #else
  125. /* avoid strncmp() */
  126. #define ber_bvstrcmp(v1,v2) ber_bvcmp((v1),(v2))
  127. #endif
  128. #define ber_bvstrcasecmp(v1,v2) \
  129. ((v1)->bv_len < (v2)->bv_len \
  130. ? -1 : ((v1)->bv_len > (v2)->bv_len \
  131. ? 1 : strncasecmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
  132. #define ber_bvccmp(v1,c) \
  133. ( (v1)->bv_len == 1 && (v1)->bv_val[0] == (c) )
  134. #define ber_strccmp(s,c) \
  135. ( (s)[0] == (c) && (s)[1] == '\0' )
  136. #define ber_bvchr(bv,c) \
  137. ((char *) memchr( (bv)->bv_val, (c), (bv)->bv_len ))
  138. #define ber_bvrchr(bv,c) \
  139. ((char *) lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ))
  140. #define ber_bvchr_post(dst,bv,c) \
  141. do { \
  142. (dst)->bv_val = memchr( (bv)->bv_val, (c), (bv)->bv_len ); \
  143. (dst)->bv_len = (dst)->bv_val ? (bv)->bv_len - ((dst)->bv_val - (bv)->bv_val) : 0; \
  144. } while (0)
  145. #define ber_bvchr_pre(dst,bv,c) \
  146. do { \
  147. (dst)->bv_val = memchr( (bv)->bv_val, (c), (bv)->bv_len ); \
  148. (dst)->bv_len = (dst)->bv_val ? ((dst)->bv_val - (bv)->bv_val) : (bv)->bv_len; \
  149. (dst)->bv_val = (bv)->bv_val; \
  150. } while (0)
  151. #define ber_bvrchr_post(dst,bv,c) \
  152. do { \
  153. (dst)->bv_val = lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ); \
  154. (dst)->bv_len = (dst)->bv_val ? (bv)->bv_len - ((dst)->bv_val - (bv)->bv_val) : 0; \
  155. } while (0)
  156. #define ber_bvrchr_pre(dst,bv,c) \
  157. do { \
  158. (dst)->bv_val = lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ); \
  159. (dst)->bv_len = (dst)->bv_val ? ((dst)->bv_val - (bv)->bv_val) : (bv)->bv_len; \
  160. (dst)->bv_val = (bv)->bv_val; \
  161. } while (0)
  162. #define BER_STRLENOF(s) (sizeof(s)-1)
  163. #define BER_BVC(s) { BER_STRLENOF(s), (char *)(s) }
  164. #define BER_BVNULL { 0L, NULL }
  165. #define BER_BVZERO(bv) \
  166. do { \
  167. (bv)->bv_len = 0; \
  168. (bv)->bv_val = NULL; \
  169. } while (0)
  170. #define BER_BVSTR(bv,s) \
  171. do { \
  172. (bv)->bv_len = BER_STRLENOF(s); \
  173. (bv)->bv_val = (s); \
  174. } while (0)
  175. #define BER_BVISNULL(bv) ((bv)->bv_val == NULL)
  176. #define BER_BVISEMPTY(bv) ((bv)->bv_len == 0)
  177. LDAP_END_DECL
  178. #endif