]> git.sur5r.net Git - openldap/blob - include/ldap_pvt.h
Bring UCdata infrastructure.
[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 /* ldap://  */
25 #define LDAP_PROTO_UDP 2 /* reserved */
26 #define LDAP_PROTO_IPC 3 /* ldapi:// */
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( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
49
50 LDAP_F( int )
51 ldap_pvt_gethostbyname_a LDAP_P((
52         const char *name, 
53         struct hostent *resbuf,
54         char **buf,
55         struct hostent **result,
56         int *herrno_ptr ));
57
58 LDAP_F( int )
59 ldap_pvt_gethostbyaddr_a LDAP_P((
60         const char *addr,
61         int len,
62         int type,
63         struct hostent *resbuf,
64         char **buf,
65         struct hostent **result,
66         int *herrno_ptr ));
67
68
69 /* charray.c */
70
71 LDAP_F( int )
72 ldap_charray_add LDAP_P((
73     char        ***a,
74     char        *s ));
75
76 LDAP_F( int )
77 ldap_charray_merge LDAP_P((
78     char        ***a,
79     char        **s ));
80
81 LDAP_F( void )
82 ldap_charray_free LDAP_P(( char **a ));
83
84 LDAP_F( int )
85 ldap_charray_inlist LDAP_P((
86     char        **a,
87     char        *s ));
88
89 LDAP_F( char ** )
90 ldap_charray_dup LDAP_P(( char **a ));
91
92 LDAP_F( char ** )
93 ldap_str2charray LDAP_P((
94         const char *str,
95         const char *brkstr ));
96
97 LDAP_F( char * )
98 ldap_charray2str LDAP_P((
99         char **array, const char* sep ));
100
101 /* url.c */
102 LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
103 LDAP_F (int) ldap_pvt_unhex( int c );
104
105 /* these macros assume 'x' is an ASCII x */
106 #define LDAP_DNSEPARATOR(c)     ((c) == ',' || (c) == ';')
107 #define LDAP_SEPARATOR(c)       ((c) == ',' || (c) == ';' || (c) == '+')
108 #define LDAP_SPACE(c)           ((c) == ' ' || (c) == '\t' || (c) == '\n')
109
110 #define LDAP_LOWER(c)           ( (c) >= 'a' && (c) <= 'z' )
111 #define LDAP_UPPER(c)           ( (c) >= 'A' && (c) <= 'Z' )
112 #define LDAP_ALPHA(c)           ( LDAP_LOWER(c) || LDAP_UPPER(c) )
113 #define LDAP_DIGIT(c)           ( (c) >= '0' && (c) <= '9' )
114 #define LDAP_ALNUM(c)           ( LDAP_ALPHA(c) || LDAP_DIGIT(c) )
115
116 #define LDAP_LEADKEYCHAR(c)     ( LDAP_ALPHA(c) )
117 #define LDAP_KEYCHAR(c)         ( LDAP_ALNUM(c) || (c) == '-' )
118 #define LDAP_LEADOIDCHAR(c)     ( LDAP_DIGIT(c) )
119 #define LDAP_OIDCHAR(c)         ( LDAP_DIGIT(c) || (c) == '.' )
120
121 #define LDAP_LEADATTRCHAR(c)    ( LDAP_LEADKEYCHAR(c) || LDAP_LEADOIDCHAR(c) )
122 #define LDAP_ATTRCHAR(c)                ( LDAP_KEYCHAR(c) || LDAP_OIDCHAR(c) )
123
124 #define LDAP_NEEDSESCAPE(c)     ((c) == '\\' || (c) == '"')
125
126 #ifdef HAVE_CYRUS_SASL
127 /* cyrus.c */
128 struct sasl_security_properties; /* avoid pulling in <sasl.h> */
129 LDAP_F (int) ldap_pvt_sasl_secprops LDAP_P((
130         const char *in,
131         struct sasl_security_properties *secprops ));
132
133 LDAP_F (void *) ldap_pvt_sasl_mutex_new LDAP_P((void));
134 LDAP_F (int) ldap_pvt_sasl_mutex_lock LDAP_P((void *mutex));
135 LDAP_F (int) ldap_pvt_sasl_mutex_unlock LDAP_P((void *mutex));
136 LDAP_F (void) ldap_pvt_sasl_mutex_dispose LDAP_P((void *mutex));
137
138 struct sockbuf; /* avoid pulling in <lber.h> */
139 LDAP_F (int) ldap_pvt_sasl_install LDAP_P(( struct sockbuf *, void * ));
140 #endif /* HAVE_CYRUS_SASL */
141
142 #define LDAP_PVT_SASL_LOCAL_SSF 71      /* SSF for Unix Domain Sockets */
143
144 /* search.c */
145 LDAP_F( char * )
146 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
147
148 LDAP_F( ber_slen_t )
149 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
150
151 /* string.c */
152 LDAP_F( char * )
153 ldap_pvt_str2upper LDAP_P(( char *str ));
154
155 LDAP_F( char * )
156 ldap_pvt_str2lower LDAP_P(( char *str ));
157
158 /* tls.c */
159 struct ldapoptions;
160 struct ldap;
161
162 LDAP_F (int) ldap_pvt_tls_init LDAP_P(( void ));
163 LDAP_F (int) ldap_pvt_tls_connect LDAP_P(( struct ldap *ld, Sockbuf *sb, void *ctx_arg ));
164 LDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
165 LDAP_F (void *) ldap_pvt_tls_sb_handle LDAP_P(( Sockbuf *sb ));
166 LDAP_F (void *) ldap_pvt_tls_get_handle LDAP_P(( struct ldap *ld ));
167 LDAP_F (const char *) ldap_pvt_tls_get_peer LDAP_P(( void *handle ));
168 LDAP_F (int) ldap_pvt_tls_get_strength LDAP_P(( void *handle ));
169 LDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
170 LDAP_F (int) ldap_pvt_tls_start LDAP_P(( struct ldap *ld, Sockbuf *sb, void *ctx_arg ));
171
172 LDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldapoptions *lo, int option, void *arg ));
173 LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldapoptions *lo, int option, void *arg ));
174
175 /*  
176  * UTF-8 (in utf-8.c)
177  */
178
179 typedef ber_int_t ldap_ucs4_t;
180 #define LDAP_UCS4_INVALID (0x80000000U)
181
182 typedef short ldap_ucs2_t;
183
184 /* UCDATA uses UCS-2 passed in an unsigned long */
185 typedef unsigned long ldap_unicode_t;
186
187 /* conversion routines  */
188 LDAP_F( ldap_ucs4_t ) ldap_utf8_to_ucs4( const char * p );
189 LDAP_F( int ) ldap_ucs4_to_utf8( ldap_ucs4_t c, char *buf );
190
191 #define ldap_utf8_to_unicode( p ) ldap_utf8_to_ucs4((p))
192 #define ldap_unicode_to_utf8( c, buf ) ldap_ucs4_to_ucs4((c),(buf))
193
194 /* returns the number of bytes in the UTF-8 string */
195 LDAP_F (ber_len_t) ldap_utf8_bytes( const char * );
196 /* returns the number of UTF-8 characters in the string */
197 LDAP_F (ber_len_t) ldap_utf8_chars( const char * );
198 /* returns the length (in bytes) of the UTF-8 character */
199 LDAP_F (int) ldap_utf8_offset( const char * );
200 /* returns the length (in bytes) indicated by the UTF-8 character */
201 LDAP_F (int) ldap_utf8_charlen( const char * );
202 /* copies a UTF-8 character and returning number of bytes copied */
203 LDAP_F (int) ldap_utf8_copy( char *, const char *);
204
205 /* returns pointer of next UTF-8 character in string */
206 LDAP_F (char*) ldap_utf8_next( const char * );
207 /* returns pointer of previous UTF-8 character in string */
208 LDAP_F (char*) ldap_utf8_prev( const char * );
209
210 /* primitive ctype routines -- not aware of non-ascii characters */
211 LDAP_F (int) ldap_utf8_isascii( const char * );
212 LDAP_F (int) ldap_utf8_isalpha( const char * );
213 LDAP_F (int) ldap_utf8_isalnum( const char * );
214 LDAP_F (int) ldap_utf8_isdigit( const char * );
215 LDAP_F (int) ldap_utf8_isxdigit( const char * );
216 LDAP_F (int) ldap_utf8_isspace( const char * );
217
218 /* span characters not in set, return bytes spanned */
219 LDAP_F (ber_len_t) ldap_utf8_strcspn( const char* str, const char *set);
220 /* span characters in set, return bytes spanned */
221 LDAP_F (ber_len_t) ldap_utf8_strspn( const char* str, const char *set);
222 /* return first occurance of character in string */
223 LDAP_F (char *) ldap_utf8_strchr( const char* str, const char *chr);
224 /* return first character of set in string */
225 LDAP_F (char *) ldap_utf8_strpbrk( const char* str, const char *set);
226 /* reentrant tokenizer */
227 LDAP_F (char*) ldap_utf8_strtok( char* sp, const char* sep, char **last);
228
229 /* Optimizations */
230 #define LDAP_UTF8_ISASCII(p) ( * (const unsigned char *) (p) < 0x100 )
231 #define LDAP_UTF8_CHARLEN(p) ( LDAP_UTF8_ISASCII(p) \
232         ? 1 : ldap_utf8_charlen((p)) )
233 #define LDAP_UTF8_OFFSET(p) ( LDAP_UTF8_ISASCII(p) \
234         ? 1 : ldap_utf8_offset((p)) )
235
236 #define LDAP_UTF8_COPY(d,s) (   LDAP_UTF8_ISASCII(s) \
237         ? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) )
238
239 #define LDAP_UTF8_NEXT(p) (     LDAP_UTF8_ISASCII(p) \
240         ? (char *)(p)+1 : ldap_utf8_next((p)) )
241
242 #define LDAP_UTF8_INCR(p) ((p) = LDAP_UTF8_NEXT(p))
243
244 /* For symmetry */
245 #define LDAP_UTF8_PREV(p) (ldap_utf8_prev((p)))
246 #define LDAP_UTF8_DECR(p) ((p)=LDAP_UTF8_PREV((p)))
247
248 LDAP_END_DECL
249
250 #endif
251