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