Back to index

openldap  2.4.31
ldif.h
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1998-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 /* Portions Copyright (c) 1996 Regents of the University of Michigan.
00016  * All rights reserved.
00017  *
00018  * Redistribution and use in source and binary forms are permitted
00019  * provided that this notice is preserved and that due credit is given
00020  * to the University of Michigan at Ann Arbor. The name of the University
00021  * may not be used to endorse or promote products derived from this
00022  * software without specific prior written permission. This software
00023  * is provided ``as is'' without express or implied warranty.
00024  */
00025 
00026 #ifndef _LDIF_H
00027 #define _LDIF_H
00028 
00029 #include <ldap_cdefs.h>
00030 
00031 LDAP_BEGIN_DECL
00032 
00033 /* This is NOT a bogus extern declaration (unlike ldap_debug) */
00034 LDAP_LDIF_V (int) ldif_debug;
00035 
00036 #define LDIF_LINE_WIDTH      76      /* default maximum length of LDIF lines */
00037 #define LDIF_LINE_WIDTH_MAX  ((ber_len_t)-1) /* maximum length of LDIF lines */
00038 #define LDIF_LINE_WIDTH_WRAP(wrap) ((wrap) == 0 ? LDIF_LINE_WIDTH : (wrap))
00039 
00040 /*
00041  * Macro to calculate maximum number of bytes that the base64 equivalent
00042  * of an item that is "len" bytes long will take up.  Base64 encoding
00043  * uses one byte for every six bits in the value plus up to two pad bytes.
00044  */
00045 #define LDIF_BASE64_LEN(len)       (((len) * 4 / 3 ) + 3)
00046 
00047 /*
00048  * Macro to calculate maximum size that an LDIF-encoded type (length
00049  * tlen) and value (length vlen) will take up:  room for type + ":: " +
00050  * first newline + base64 value + continued lines.  Each continued line
00051  * needs room for a newline and a leading space character.
00052  */
00053 #define LDIF_SIZE_NEEDED(nlen,vlen) \
00054     ((nlen) + 4 + LDIF_BASE64_LEN(vlen) \
00055     + ((LDIF_BASE64_LEN(vlen) + (nlen) + 3) / LDIF_LINE_WIDTH * 2 ))
00056 
00057 #define LDIF_SIZE_NEEDED_WRAP(nlen,vlen,wrap) \
00058     ((nlen) + 4 + LDIF_BASE64_LEN(vlen) \
00059     + ((wrap) == 0 ? ((LDIF_BASE64_LEN(vlen) + (nlen) + 3) / ( LDIF_LINE_WIDTH ) * 2 ) : \
00060        ((wrap) == LDIF_LINE_WIDTH_MAX ? 0 : ((LDIF_BASE64_LEN(vlen) + (nlen) + 3) / (wrap) * 2 ))))
00061 
00062 LDAP_LDIF_F( int )
00063 ldif_parse_line LDAP_P((
00064        LDAP_CONST char *line,
00065        char **name,
00066        char **value,
00067        ber_len_t *vlen ));
00068 
00069 LDAP_LDIF_F( int )
00070 ldif_parse_line2 LDAP_P((
00071        char *line,
00072        struct berval *type,
00073        struct berval *value,
00074        int *freeval ));
00075 
00076 LDAP_LDIF_F( FILE * )
00077 ldif_open_url LDAP_P(( LDAP_CONST char *urlstr ));
00078 
00079 LDAP_LDIF_F( int )
00080 ldif_fetch_url LDAP_P((
00081        LDAP_CONST char *line,
00082        char **value,
00083        ber_len_t *vlen ));
00084 
00085 LDAP_LDIF_F( char * )
00086 ldif_getline LDAP_P(( char **next ));
00087 
00088 LDAP_LDIF_F( int )
00089 ldif_countlines LDAP_P(( LDAP_CONST char *line ));
00090 
00091 /* ldif_ropen, rclose, read_record - just for reading LDIF files,
00092  * no special open/close needed to write LDIF files.
00093  */
00094 typedef struct LDIFFP {
00095        FILE *fp;
00096        struct LDIFFP *prev;
00097 } LDIFFP;
00098 
00099 LDAP_LDIF_F( LDIFFP * )
00100 ldif_open LDAP_P(( LDAP_CONST char *file, LDAP_CONST char *mode ));
00101 
00102 LDAP_LDIF_F( void )
00103 ldif_close LDAP_P(( LDIFFP * ));
00104 
00105 LDAP_LDIF_F( int )
00106 ldif_read_record LDAP_P((
00107        LDIFFP *fp,
00108        int *lineno,
00109        char **bufp,
00110        int *buflen ));
00111 
00112 LDAP_LDIF_F( int )
00113 ldif_must_b64_encode_register LDAP_P((
00114        LDAP_CONST char *name,
00115        LDAP_CONST char *oid ));
00116 
00117 LDAP_LDIF_F( void )
00118 ldif_must_b64_encode_release LDAP_P(( void ));
00119 
00120 #define LDIF_PUT_NOVALUE    0x0000 /* no value */
00121 #define LDIF_PUT_VALUE             0x0001 /* value w/ auto detection */
00122 #define LDIF_PUT_TEXT              0x0002 /* assume text */
00123 #define       LDIF_PUT_BINARY             0x0004 /* assume binary (convert to base64) */
00124 #define LDIF_PUT_B64        0x0008 /* pre-converted base64 value */
00125 
00126 #define LDIF_PUT_COMMENT    0x0010 /* comment */
00127 #define LDIF_PUT_URL        0x0020 /* url */
00128 #define LDIF_PUT_SEP        0x0040 /* separator */
00129 
00130 LDAP_LDIF_F( void )
00131 ldif_sput LDAP_P((
00132        char **out,
00133        int type,
00134        LDAP_CONST char *name,
00135        LDAP_CONST char *val,
00136        ber_len_t vlen ));
00137 
00138 LDAP_LDIF_F( void )
00139 ldif_sput_wrap LDAP_P((
00140        char **out,
00141        int type,
00142        LDAP_CONST char *name,
00143        LDAP_CONST char *val,
00144        ber_len_t vlen,
00145         ber_len_t wrap ));
00146 
00147 LDAP_LDIF_F( char * )
00148 ldif_put LDAP_P((
00149        int type,
00150        LDAP_CONST char *name,
00151        LDAP_CONST char *val,
00152        ber_len_t vlen ));
00153 
00154 LDAP_LDIF_F( char * )
00155 ldif_put_wrap LDAP_P((
00156        int type,
00157        LDAP_CONST char *name,
00158        LDAP_CONST char *val,
00159        ber_len_t vlen,
00160        ber_len_t wrap ));
00161 
00162 LDAP_LDIF_F( int )
00163 ldif_is_not_printable LDAP_P((
00164        LDAP_CONST char *val,
00165        ber_len_t vlen ));
00166 
00167 LDAP_END_DECL
00168 
00169 #endif /* _LDIF_H */