xref: /netbsd-src/external/bsd/openldap/dist/include/ldif.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*	$NetBSD: ldif.h,v 1.2 2020/08/11 13:15:37 christos Exp $	*/
2 
3 /* $OpenLDAP$ */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5  *
6  * Copyright 1998-2020 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      76      /* 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) \
56     ((nlen) + 4 + LDIF_BASE64_LEN(vlen) \
57     + ((LDIF_BASE64_LEN(vlen) + (nlen) + 3) / (LDIF_LINE_WIDTH-1) * 2 ))
58 
59 #define LDIF_SIZE_NEEDED_WRAP(nlen,vlen,wrap) \
60     ((nlen) + 4 + LDIF_BASE64_LEN(vlen) \
61     + ((wrap) == 0 ? ((LDIF_BASE64_LEN(vlen) + (nlen) + 3) / ( LDIF_LINE_WIDTH-1 ) * 2 ) : \
62 	((wrap) == LDIF_LINE_WIDTH_MAX ? 0 : ((LDIF_BASE64_LEN(vlen) + (nlen) + 3) / (wrap-1) * 2 ))))
63 
64 LDAP_LDIF_F( int )
65 ldif_parse_line LDAP_P((
66 	LDAP_CONST char *line,
67 	char **name,
68 	char **value,
69 	ber_len_t *vlen ));
70 
71 LDAP_LDIF_F( int )
72 ldif_parse_line2 LDAP_P((
73 	char *line,
74 	struct berval *type,
75 	struct berval *value,
76 	int *freeval ));
77 
78 LDAP_LDIF_F( FILE * )
79 ldif_open_url LDAP_P(( LDAP_CONST char *urlstr ));
80 
81 LDAP_LDIF_F( int )
82 ldif_fetch_url LDAP_P((
83 	LDAP_CONST char *line,
84 	char **value,
85 	ber_len_t *vlen ));
86 
87 LDAP_LDIF_F( char * )
88 ldif_getline LDAP_P(( char **next ));
89 
90 LDAP_LDIF_F( int )
91 ldif_countlines LDAP_P(( LDAP_CONST char *line ));
92 
93 /* ldif_ropen, rclose, read_record - just for reading LDIF files,
94  * no special open/close needed to write LDIF files.
95  */
96 typedef struct LDIFFP {
97 	FILE *fp;
98 	struct LDIFFP *prev;
99 } LDIFFP;
100 
101 LDAP_LDIF_F( LDIFFP * )
102 ldif_open LDAP_P(( LDAP_CONST char *file, LDAP_CONST char *mode ));
103 
104 LDAP_LDIF_F( void )
105 ldif_close LDAP_P(( LDIFFP * ));
106 
107 LDAP_LDIF_F( int )
108 ldif_read_record LDAP_P((
109 	LDIFFP *fp,
110 	unsigned long *lineno,
111 	char **bufp,
112 	int *buflen ));
113 
114 LDAP_LDIF_F( int )
115 ldif_must_b64_encode_register LDAP_P((
116 	LDAP_CONST char *name,
117 	LDAP_CONST char *oid ));
118 
119 LDAP_LDIF_F( void )
120 ldif_must_b64_encode_release LDAP_P(( void ));
121 
122 #define LDIF_PUT_NOVALUE	0x0000	/* no value */
123 #define LDIF_PUT_VALUE		0x0001	/* value w/ auto detection */
124 #define LDIF_PUT_TEXT		0x0002	/* assume text */
125 #define	LDIF_PUT_BINARY		0x0004	/* assume binary (convert to base64) */
126 #define LDIF_PUT_B64		0x0008	/* pre-converted base64 value */
127 
128 #define LDIF_PUT_COMMENT	0x0010	/* comment */
129 #define LDIF_PUT_URL		0x0020	/* url */
130 #define LDIF_PUT_SEP		0x0040	/* separator */
131 
132 LDAP_LDIF_F( void )
133 ldif_sput LDAP_P((
134 	char **out,
135 	int type,
136 	LDAP_CONST char *name,
137 	LDAP_CONST char *val,
138 	ber_len_t vlen ));
139 
140 LDAP_LDIF_F( void )
141 ldif_sput_wrap LDAP_P((
142 	char **out,
143 	int type,
144 	LDAP_CONST char *name,
145 	LDAP_CONST char *val,
146 	ber_len_t vlen,
147         ber_len_t wrap ));
148 
149 LDAP_LDIF_F( char * )
150 ldif_put LDAP_P((
151 	int type,
152 	LDAP_CONST char *name,
153 	LDAP_CONST char *val,
154 	ber_len_t vlen ));
155 
156 LDAP_LDIF_F( char * )
157 ldif_put_wrap LDAP_P((
158 	int type,
159 	LDAP_CONST char *name,
160 	LDAP_CONST char *val,
161 	ber_len_t vlen,
162 	ber_len_t wrap ));
163 
164 LDAP_LDIF_F( int )
165 ldif_is_not_printable LDAP_P((
166 	LDAP_CONST char *val,
167 	ber_len_t vlen ));
168 
169 LDAP_END_DECL
170 
171 #endif /* _LDIF_H */
172