1 /* 2 * Copyright (c) 2001 by Sun Microsystems, Inc. 3 * All rights reserved. 4 */ 5 6 /* 7 * The contents of this file are subject to the Netscape Public 8 * License Version 1.1 (the "License"); you may not use this file 9 * except in compliance with the License. You may obtain a copy of 10 * the License at http://www.mozilla.org/NPL/ 11 * 12 * Software distributed under the License is distributed on an "AS 13 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 14 * implied. See the License for the specific language governing 15 * rights and limitations under the License. 16 * 17 * The Original Code is Mozilla Communicator client code, released 18 * March 31, 1998. 19 * 20 * The Initial Developer of the Original Code is Netscape 21 * Communications Corporation. Portions created by Netscape are 22 * Copyright (C) 1998-1999 Netscape Communications Corporation. All 23 * Rights Reserved. 24 * 25 * Contributor(s): 26 */ 27 28 /* 29 * Copyright (c) 1996 Regents of the University of Michigan. 30 * All rights reserved. 31 * 32 * Redistribution and use in source and binary forms are permitted 33 * provided that this notice is preserved and that due credit is given 34 * to the University of Michigan at Ann Arbor. The name of the University 35 * may not be used to endorse or promote products derived from this 36 * software without specific prior written permission. This software 37 * is provided ``as is'' without express or implied warranty. 38 */ 39 40 #ifndef _LDIF_H 41 #define _LDIF_H 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 #define LDIF_VERSION_ONE 1 /* LDIF standard version */ 48 49 #define LDIF_MAX_LINE_WIDTH 76 /* maximum length of LDIF lines */ 50 51 /* 52 * Macro to calculate maximum number of bytes that the base64 equivalent 53 * of an item that is "vlen" bytes long will take up. Base64 encoding 54 * uses one byte for every six bits in the value plus up to two pad bytes. 55 */ 56 #define LDIF_BASE64_LEN(vlen) (((vlen) * 4 / 3 ) + 3) 57 58 /* 59 * Macro to calculate maximum size that an LDIF-encoded type (length 60 * tlen) and value (length vlen) will take up: room for type + ":: " + 61 * first newline + base64 value + continued lines. Each continued line 62 * needs room for a newline and a leading space character. 63 */ 64 #define LDIF_SIZE_NEEDED(tlen,vlen) \ 65 ((tlen) + 4 + LDIF_BASE64_LEN(vlen) \ 66 + ((LDIF_BASE64_LEN(vlen) + tlen + 3) / LDIF_MAX_LINE_WIDTH * 2 )) 67 68 /* 69 * Options for ldif_put_type_and_value_with_options() and 70 * ldif_type_and_value_with_options(). 71 */ 72 #define LDIF_OPT_NOWRAP 0x01UL 73 #define LDIF_OPT_VALUE_IS_URL 0x02UL 74 #define LDIF_OPT_MINIMAL_ENCODING 0x04UL 75 76 int str_parse_line( char *line, char **type, char **value, int *vlen); 77 char * str_getline( char **next ); 78 void ldif_put_type_and_value( char **out, char *t, char *val, int vlen ); 79 void ldif_put_type_and_value_nowrap( char **out, char *t, char *val, int vlen ); 80 void ldif_put_type_and_value_with_options( char **out, char *t, char *val, 81 int vlen, unsigned long options ); 82 char *ldif_type_and_value( char *type, char *val, int vlen ); 83 char *ldif_type_and_value_nowrap( char *type, char *val, int vlen ); 84 char *ldif_type_and_value_with_options( char *type, char *val, int vlen, 85 unsigned long options ); 86 int ldif_base64_decode( char *src, unsigned char *dst ); 87 int ldif_base64_encode( unsigned char *src, char *dst, int srclen, 88 int lenused ); 89 int ldif_base64_encode_nowrap( unsigned char *src, char *dst, int srclen, 90 int lenused ); 91 char *ldif_get_entry( FILE *fp, int *lineno ); 92 93 #ifdef __cplusplus 94 } 95 #endif 96 97 #endif /* _LDIF_H */ 98