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