]> git.sur5r.net Git - openldap/blob - include/ldap_pvt.h
Import latest from devel
[openldap] / include / ldap_pvt.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, Redwood City, California, USA
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted only
7  * as authorized by the OpenLDAP Public License.  A copy of this
8  * license is available at http://www.OpenLDAP.org/license.html or
9  * in file LICENSE in the top-level directory of the distribution.
10  */
11 /*
12  * ldap-pvt.h - Header for ldap_pvt_ functions. These are meant to be used
13  *              by the OpenLDAP distribution only.
14  */
15
16 #ifndef _LDAP_PVT_H
17 #define _LDAP_PVT_H 1
18
19 #include <ldap_cdefs.h>
20 #include <lber.h>                               /* get ber_slen_t */
21
22 LDAP_BEGIN_DECL
23
24 #define LDAP_PROTO_TCP 1
25 #define LDAP_PROTO_UDP 2
26 #define LDAP_PROTO_IPC 3
27
28 LDAP_F ( int )
29 ldap_pvt_url_scheme2proto LDAP_P((
30         const char * ));
31 LDAP_F ( int )
32 ldap_pvt_url_scheme2tls LDAP_P((
33         const char * ));
34
35
36 LDAP_F ( int )
37 ldap_pvt_domain2dn LDAP_P((
38         LDAP_CONST char *domain,
39         char **dn ));
40
41 struct hostent; /* avoid pulling in <netdb.h> */
42
43 LDAP_F( char * )
44 ldap_pvt_ctime LDAP_P((
45         const time_t *tp,
46         char *buf ));
47
48 LDAP_F( int )
49 ldap_pvt_gethostbyname_a LDAP_P((
50         const char *name, 
51         struct hostent *resbuf,
52         char **buf,
53         struct hostent **result,
54         int *herrno_ptr ));
55
56 LDAP_F( int )
57 ldap_pvt_gethostbyaddr_a LDAP_P((
58         const char *addr,
59         int len,
60         int type,
61         struct hostent *resbuf,
62         char **buf,
63         struct hostent **result,
64         int *herrno_ptr ));
65
66
67 /* charray.c */
68
69 LDAP_F( int )
70 ldap_charray_add LDAP_P((
71     char        ***a,
72     char        *s ));
73
74 LDAP_F( int )
75 ldap_charray_merge LDAP_P((
76     char        ***a,
77     char        **s ));
78
79 LDAP_F( void )
80 ldap_charray_free LDAP_P(( char **a ));
81
82 LDAP_F( int )
83 ldap_charray_inlist LDAP_P((
84     char        **a,
85     char        *s ));
86
87 LDAP_F( char ** )
88 ldap_charray_dup LDAP_P(( char **a ));
89
90 LDAP_F( char ** )
91 ldap_str2charray LDAP_P((
92         const char *str,
93         const char *brkstr ));
94
95 LDAP_F( char * )
96 ldap_charray2str LDAP_P((
97         char **array, const char* sep ));
98
99 /* url.c */
100 LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
101 LDAP_F (int) ldap_pvt_unhex( int c );
102
103 /* these macros assume 'x' is an ASCII x */
104 #define LDAP_DNSEPARATOR(c)     ((c) == ',' || (c) == ';')
105 #define LDAP_SEPARATOR(c)       ((c) == ',' || (c) == ';' || (c) == '+')
106 #define LDAP_SPACE(c)           ((c) == ' ' || (c) == '\t' || (c) == '\n')
107
108 #define LDAP_LOWER(c)           ( (c) >= 'a' && (c) <= 'z' )
109 #define LDAP_UPPER(c)           ( (c) >= 'A' && (c) <= 'Z' )
110 #define LDAP_ALPHA(c)           ( LDAP_LOWER(c) || LDAP_UPPER(c) )
111 #define LDAP_DIGIT(c)           ( (c) >= '0' && (c) <= '9' )
112 #define LDAP_ALNUM(c)           ( LDAP_ALPHA(c) || LDAP_DIGIT(c) )
113
114 #define LDAP_LEADKEYCHAR(c)     ( LDAP_ALPHA(c) )
115 #define LDAP_KEYCHAR(c)         ( LDAP_ALNUM(c) || (c) == '-' )
116 #define LDAP_LEADOIDCHAR(c)     ( LDAP_DIGIT(c) )
117 #define LDAP_OIDCHAR(c)         ( LDAP_DIGIT(c) || (c) == '.' )
118
119 #define LDAP_LEADATTRCHAR(c)    ( LDAP_LEADKEYCHAR(c) || LDAP_LEADOIDCHAR(c) )
120 #define LDAP_ATTRCHAR(c)                ( LDAP_KEYCHAR(c) || LDAP_OIDCHAR(c) )
121
122 #define LDAP_NEEDSESCAPE(c)     ((c) == '\\' || (c) == '"')
123
124 #ifdef HAVE_CYRUS_SASL
125 /* cyrus.c */
126 struct sasl_security_properties; /* avoid pulling in <sasl.h> */
127 LDAP_F (int) ldap_pvt_sasl_secprops LDAP_P((
128         const char *in,
129         struct sasl_security_properties *secprops ));
130
131 LDAP_F (void *) ldap_pvt_sasl_mutex_new LDAP_P((void));
132 LDAP_F (int) ldap_pvt_sasl_mutex_lock LDAP_P((void *mutex));
133 LDAP_F (int) ldap_pvt_sasl_mutex_unlock LDAP_P((void *mutex));
134 LDAP_F (void) ldap_pvt_sasl_mutex_dispose LDAP_P((void *mutex));
135
136 struct sockbuf; /* avoid pulling in <lber.h> */
137 LDAP_F (int) ldap_pvt_sasl_install LDAP_P(( struct sockbuf *, void * ));
138 #endif /* HAVE_CYRUS_SASL */
139
140 #define LDAP_PVT_SASL_LOCAL_SSF 52      /* SSF for Unix Domain Sockets */
141
142 /* search.c */
143 LDAP_F( char * )
144 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
145
146 LDAP_F( ber_slen_t )
147 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
148
149 /* string.c */
150 LDAP_F( char * )
151 ldap_pvt_str2upper LDAP_P(( char *str ));
152
153 LDAP_F( char * )
154 ldap_pvt_str2lower LDAP_P(( char *str ));
155
156 /* tls.c */
157 struct ldapoptions;
158 struct ldap;
159
160 LDAP_F (int) ldap_pvt_tls_init LDAP_P(( void ));
161 LDAP_F (int) ldap_pvt_tls_connect LDAP_P(( struct ldap *ld, Sockbuf *sb, void *ctx_arg ));
162 LDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
163 LDAP_F (void *) ldap_pvt_tls_sb_handle LDAP_P(( Sockbuf *sb ));
164 LDAP_F (void *) ldap_pvt_tls_get_handle LDAP_P(( struct ldap *ld ));
165 LDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
166 LDAP_F (int) ldap_pvt_tls_start LDAP_P(( struct ldap *ld, Sockbuf *sb, void *ctx_arg ));
167
168 LDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldapoptions *lo, int option, void *arg ));
169 LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldapoptions *lo, int option, void *arg ));
170
171 /*  
172  * UTF-8 (in utf-8.c)
173  */
174
175 typedef ber_int_t ldap_ucs4_t;
176 typedef short ldap_ucs2_t;
177 typedef ldap_ucs2_t ldap_unicode_t;
178
179 /* returns the number of bytes in the UTF-8 string */
180 LDAP_F (ber_len_t) ldap_utf8_bytes( const char * );
181 /* returns the number of UTF-8 characters in the string */
182 LDAP_F (ber_len_t) ldap_utf8_chars( const char * );
183 /* returns the length (in bytes) of the UTF-8 character */
184 LDAP_F (int) ldap_utf8_offset( const char * );
185 /* returns the length (in bytes) indicated by the UTF-8 character */
186 LDAP_F (int) ldap_utf8_charlen( const char * );
187 /* copies a UTF-8 character and returning number of bytes copied */
188 LDAP_F (int) ldap_utf8_copy( char *, const char *);
189
190 /* returns pointer of next UTF-8 character in string */
191 LDAP_F (char*) ldap_utf8_next( const char * );
192 /* returns pointer of previous UTF-8 character in string */
193 LDAP_F (char*) ldap_utf8_prev( const char * );
194
195 /* primitive ctype routines -- not aware of non-ascii characters */
196 LDAP_F (int) ldap_utf8_isascii( const char * );
197 LDAP_F (int) ldap_utf8_isalpha( const char * );
198 LDAP_F (int) ldap_utf8_isalnum( const char * );
199 LDAP_F (int) ldap_utf8_isdigit( const char * );
200 LDAP_F (int) ldap_utf8_isxdigit( const char * );
201 LDAP_F (int) ldap_utf8_isspace( const char * );
202
203 /* span characters not in set, return bytes spanned */
204 LDAP_F (ber_len_t) ldap_utf8_strcspn( const char* str, const char *set);
205 /* span characters in set, return bytes spanned */
206 LDAP_F (ber_len_t) ldap_utf8_strspn( const char* str, const char *set);
207 /* return first occurance of character in string */
208 LDAP_F (char *) ldap_utf8_strchr( const char* str, const char *chr);
209 /* return first character of set in string */
210 LDAP_F (char *) ldap_utf8_strpbrk( const char* str, const char *set);
211 /* reentrant tokenizer */
212 LDAP_F (char*) ldap_utf8_strtok( char* sp, const char* sep, char **last);
213
214 /* Optimizations */
215 #define LDAP_UTF8_ISASCII(p) ( * (const unsigned char *) (p) < 0x100 )
216 #define LDAP_UTF8_CHARLEN(p) ( LDAP_UTF8_ISASCII(p) \
217         ? 1 : ldap_utf8_charlen((p)) )
218 #define LDAP_UTF8_OFFSET(p) ( LDAP_UTF8_ISASCII(p) \
219         ? 1 : ldap_utf8_offset((p)) )
220
221 #define LDAP_UTF8_COPY(d,s) (   LDAP_UTF8_ISASCII(s) \
222         ? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) )
223
224 #define LDAP_UTF8_NEXT(p) (     LDAP_UTF8_ISASCII(p) \
225         ? (char *)(p)+1 : ldap_utf8_next((p)) )
226
227 #define LDAP_UTF8_INCR(p) ((p) = LDAP_UTF8_NEXT(p))
228
229 /* For symmetry */
230 #define LDAP_UTF8_PREV(p) (ldap_utf8_prev((p)))
231 #define LDAP_UTF8_DECR(p) ((p)=LDAP_UTF8_PREV((p)))
232
233 LDAP_END_DECL
234
235 #endif
236