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