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