]> git.sur5r.net Git - openldap/blob - include/ldif.h
Fix prev commit
[openldap] / include / ldif.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2008 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
26 #ifndef _LDIF_H
27 #define _LDIF_H
28
29 #include <ldap_cdefs.h>
30
31 LDAP_BEGIN_DECL
32
33 /* This is NOT a bogus extern declaration (unlike ldap_debug) */
34 LDAP_LDIF_V (int) ldif_debug;
35
36 #define LDIF_LINE_WIDTH      76      /* maximum length of LDIF lines */
37
38 /*
39  * Macro to calculate maximum number of bytes that the base64 equivalent
40  * of an item that is "len" bytes long will take up.  Base64 encoding
41  * uses one byte for every six bits in the value plus up to two pad bytes.
42  */
43 #define LDIF_BASE64_LEN(len)    (((len) * 4 / 3 ) + 3)
44
45 /*
46  * Macro to calculate maximum size that an LDIF-encoded type (length
47  * tlen) and value (length vlen) will take up:  room for type + ":: " +
48  * first newline + base64 value + continued lines.  Each continued line
49  * needs room for a newline and a leading space character.
50  */
51 #define LDIF_SIZE_NEEDED(nlen,vlen) \
52     ((nlen) + 4 + LDIF_BASE64_LEN(vlen) \
53     + ((LDIF_BASE64_LEN(vlen) + (nlen) + 3) / LDIF_LINE_WIDTH * 2 ))
54
55 LDAP_LDIF_F( int )
56 ldif_parse_line LDAP_P((
57         LDAP_CONST char *line,
58         char **name,
59         char **value,
60         ber_len_t *vlen ));
61
62 LDAP_LDIF_F( int )
63 ldif_parse_line2 LDAP_P((
64         char *line,
65         struct berval *type,
66         struct berval *value,
67         int *freeval ));
68
69 LDAP_LDIF_F( FILE * )
70 ldif_open_url LDAP_P(( LDAP_CONST char *urlstr ));
71
72 LDAP_LDIF_F( int )
73 ldif_fetch_url LDAP_P((
74         LDAP_CONST char *line,
75         char **value,
76         ber_len_t *vlen ));
77
78 LDAP_LDIF_F( char * )
79 ldif_getline LDAP_P(( char **next ));
80
81 LDAP_LDIF_F( int )
82 ldif_countlines LDAP_P(( LDAP_CONST char *line ));
83
84 /* ldif_ropen, rclose, read_record - just for reading LDIF files,
85  * no special open/close needed to write LDIF files.
86  */
87 typedef struct LDIFFP {
88         FILE *fp;
89         struct LDIFFP *prev;
90 } LDIFFP;
91
92 LDAP_LDIF_F( LDIFFP * )
93 ldif_open LDAP_P(( LDAP_CONST char *file, LDAP_CONST char *mode ));
94
95 LDAP_LDIF_F( void )
96 ldif_close LDAP_P(( LDIFFP * ));
97
98 LDAP_LDIF_F( int )
99 ldif_read_record LDAP_P((
100         LDIFFP *fp,
101         int *lineno,
102         char **bufp,
103         int *buflen ));
104
105 LDAP_LDIF_F( int )
106 ldif_must_b64_encode_register LDAP_P((
107         LDAP_CONST char *name,
108         LDAP_CONST char *oid ));
109
110 LDAP_LDIF_F( void )
111 ldif_must_b64_encode_release LDAP_P(( void ));
112
113 #define LDIF_PUT_NOVALUE        0x0000  /* no value */
114 #define LDIF_PUT_VALUE          0x0001  /* value w/ auto detection */
115 #define LDIF_PUT_TEXT           0x0002  /* assume text */
116 #define LDIF_PUT_BINARY         0x0004  /* assume binary (convert to base64) */
117 #define LDIF_PUT_B64            0x0008  /* pre-converted base64 value */
118
119 #define LDIF_PUT_COMMENT        0x0010  /* comment */
120 #define LDIF_PUT_URL            0x0020  /* url */
121 #define LDIF_PUT_SEP            0x0040  /* separator */
122
123 LDAP_LDIF_F( void )
124 ldif_sput LDAP_P((
125         char **out,
126         int type,
127         LDAP_CONST char *name,
128         LDAP_CONST char *val,
129         ber_len_t vlen ));
130
131 LDAP_LDIF_F( char * )
132 ldif_put LDAP_P((
133         int type,
134         LDAP_CONST char *name,
135         LDAP_CONST char *val,
136         ber_len_t vlen ));
137
138 LDAP_LDIF_F( int )
139 ldif_is_not_printable LDAP_P((
140         LDAP_CONST char *val,
141         ber_len_t vlen ));
142
143 LDAP_END_DECL
144
145 #endif /* _LDIF_H */