ldif.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. /* Portions Copyright (c) 1996 Regents of the University of Michigan.
  16. * All rights reserved.
  17. *
  18. * Redistribution and use in source and binary forms are permitted
  19. * provided that this notice is preserved and that due credit is given
  20. * to the University of Michigan at Ann Arbor. The name of the University
  21. * may not be used to endorse or promote products derived from this
  22. * software without specific prior written permission. This software
  23. * is provided ``as is'' without express or implied warranty.
  24. */
  25. #ifndef _LDIF_H
  26. #define _LDIF_H
  27. #include <ldap_cdefs.h>
  28. LDAP_BEGIN_DECL
  29. /* This is NOT a bogus extern declaration (unlike ldap_debug) */
  30. LDAP_LDIF_V (int) ldif_debug;
  31. #define LDIF_LINE_WIDTH 78 /* default maximum length of LDIF lines */
  32. #define LDIF_LINE_WIDTH_MAX ((ber_len_t)-1) /* maximum length of LDIF lines */
  33. #define LDIF_LINE_WIDTH_WRAP(wrap) ((wrap) == 0 ? LDIF_LINE_WIDTH : (wrap))
  34. /*
  35. * Macro to calculate maximum number of bytes that the base64 equivalent
  36. * of an item that is "len" bytes long will take up. Base64 encoding
  37. * uses one byte for every six bits in the value plus up to two pad bytes.
  38. */
  39. #define LDIF_BASE64_LEN(len) (((len) * 4 / 3 ) + 3)
  40. /*
  41. * Macro to calculate maximum size that an LDIF-encoded type (length
  42. * tlen) and value (length vlen) will take up: room for type + ":: " +
  43. * first newline + base64 value + continued lines. Each continued line
  44. * needs room for a newline and a leading space character.
  45. */
  46. #define LDIF_SIZE_NEEDED(nlen,vlen) LDIF_SIZE_NEEDED_WRAP(nlen, vlen, 0)
  47. #define LDIF_SIZE_NEEDED_WRAP(nlen,vlen,wrap) \
  48. ((nlen) + 4 + LDIF_BASE64_LEN(vlen) \
  49. + ((wrap) == 0 ? ((LDIF_BASE64_LEN(vlen) + (nlen) + 3) / ( LDIF_LINE_WIDTH-1 ) * 2 ) : \
  50. ((wrap) == LDIF_LINE_WIDTH_MAX ? 0 : ((LDIF_BASE64_LEN(vlen) + (nlen) + 3) / (wrap-1) * 2 ))))
  51. LDAP_LDIF_F( int )
  52. ldif_parse_line LDAP_P((
  53. LDAP_CONST char *line,
  54. char **name,
  55. char **value,
  56. ber_len_t *vlen ));
  57. LDAP_LDIF_F( int )
  58. ldif_parse_line2 LDAP_P((
  59. char *line,
  60. struct berval *type,
  61. struct berval *value,
  62. int *freeval ));
  63. LDAP_LDIF_F( FILE * )
  64. ldif_open_url LDAP_P(( LDAP_CONST char *urlstr ));
  65. LDAP_LDIF_F( int )
  66. ldif_fetch_url LDAP_P((
  67. LDAP_CONST char *line,
  68. char **value,
  69. ber_len_t *vlen ));
  70. LDAP_LDIF_F( char * )
  71. ldif_getline LDAP_P(( char **next ));
  72. LDAP_LDIF_F( int )
  73. ldif_countlines LDAP_P(( LDAP_CONST char *line ));
  74. /* ldif_ropen, rclose, read_record - just for reading LDIF files,
  75. * no special open/close needed to write LDIF files.
  76. */
  77. typedef struct LDIFFP {
  78. FILE *fp;
  79. struct LDIFFP *prev;
  80. } LDIFFP;
  81. LDAP_LDIF_F( LDIFFP * )
  82. ldif_open LDAP_P(( LDAP_CONST char *file, LDAP_CONST char *mode ));
  83. /* ldif_open equivalent that opens ldif stream in memory rather than from file */
  84. LDAP_LDIF_F( LDIFFP * )
  85. ldif_open_mem LDAP_P(( char *ldif, size_t size, LDAP_CONST char *mode ));
  86. LDAP_LDIF_F( void )
  87. ldif_close LDAP_P(( LDIFFP * ));
  88. LDAP_LDIF_F( int )
  89. ldif_read_record LDAP_P((
  90. LDIFFP *fp,
  91. unsigned long *lineno,
  92. char **bufp,
  93. int *buflen ));
  94. LDAP_LDIF_F( int )
  95. ldif_must_b64_encode_register LDAP_P((
  96. LDAP_CONST char *name,
  97. LDAP_CONST char *oid ));
  98. LDAP_LDIF_F( void )
  99. ldif_must_b64_encode_release LDAP_P(( void ));
  100. #define LDIF_PUT_NOVALUE 0x0000 /* no value */
  101. #define LDIF_PUT_VALUE 0x0001 /* value w/ auto detection */
  102. #define LDIF_PUT_TEXT 0x0002 /* assume text */
  103. #define LDIF_PUT_BINARY 0x0004 /* assume binary (convert to base64) */
  104. #define LDIF_PUT_B64 0x0008 /* pre-converted base64 value */
  105. #define LDIF_PUT_COMMENT 0x0010 /* comment */
  106. #define LDIF_PUT_URL 0x0020 /* url */
  107. #define LDIF_PUT_SEP 0x0040 /* separator */
  108. LDAP_LDIF_F( void )
  109. ldif_sput LDAP_P((
  110. char **out,
  111. int type,
  112. LDAP_CONST char *name,
  113. LDAP_CONST char *val,
  114. ber_len_t vlen ));
  115. LDAP_LDIF_F( void )
  116. ldif_sput_wrap LDAP_P((
  117. char **out,
  118. int type,
  119. LDAP_CONST char *name,
  120. LDAP_CONST char *val,
  121. ber_len_t vlen,
  122. ber_len_t wrap ));
  123. LDAP_LDIF_F( char * )
  124. ldif_put LDAP_P((
  125. int type,
  126. LDAP_CONST char *name,
  127. LDAP_CONST char *val,
  128. ber_len_t vlen ));
  129. LDAP_LDIF_F( char * )
  130. ldif_put_wrap LDAP_P((
  131. int type,
  132. LDAP_CONST char *name,
  133. LDAP_CONST char *val,
  134. ber_len_t vlen,
  135. ber_len_t wrap ));
  136. LDAP_LDIF_F( int )
  137. ldif_is_not_printable LDAP_P((
  138. LDAP_CONST char *val,
  139. ber_len_t vlen ));
  140. LDAP_END_DECL
  141. #endif /* _LDIF_H */