3 * Copyright 1998-2000 The OpenLDAP Foundation, Redwood City, California, USA
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.
12 * ldap-pvt.h - Header for ldap_pvt_ functions. These are meant to be used
13 * by the OpenLDAP distribution only.
19 #include <ldap_cdefs.h>
20 #include <lber.h> /* get ber_slen_t */
24 #define LDAP_PROTO_TCP 1
25 #define LDAP_PROTO_UDP 2
26 #define LDAP_PROTO_IPC 3
29 ldap_pvt_url_scheme2proto LDAP_P((
32 ldap_pvt_url_scheme2tls LDAP_P((
37 ldap_pvt_domain2dn LDAP_P((
38 LDAP_CONST char *domain,
41 struct hostent; /* avoid pulling in <netdb.h> */
44 ldap_pvt_ctime LDAP_P((
49 ldap_pvt_gethostbyname_a LDAP_P((
51 struct hostent *resbuf,
53 struct hostent **result,
57 ldap_pvt_gethostbyaddr_a LDAP_P((
61 struct hostent *resbuf,
63 struct hostent **result,
70 ldap_charray_add LDAP_P((
75 ldap_charray_merge LDAP_P((
80 ldap_charray_free LDAP_P(( char **a ));
83 ldap_charray_inlist LDAP_P((
88 ldap_charray_dup LDAP_P(( char **a ));
91 ldap_str2charray LDAP_P((
93 const char *brkstr ));
96 LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
97 LDAP_F (int) ldap_pvt_unhex( int c );
99 /* these macros assume 'x' is an ASCII x */
100 #define LDAP_DNSEPARATOR(c) ((c) == ',' || (c) == ';')
101 #define LDAP_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '+')
102 #define LDAP_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
104 #define LDAP_LOWER(c) ( (c) >= 'a' && (c) <= 'z' )
105 #define LDAP_UPPER(c) ( (c) >= 'A' && (c) <= 'Z' )
106 #define LDAP_ALPHA(c) ( LDAP_LOWER(c) || LDAP_UPPER(c) )
107 #define LDAP_DIGIT(c) ( (c) >= '0' && (c) <= '9' )
108 #define LDAP_ALNUM(c) ( LDAP_ALPHA(c) || LDAP_DIGIT(c) )
110 #define LDAP_LEADKEYCHAR(c) ( LDAP_ALPHA(c) )
111 #define LDAP_KEYCHAR(c) ( LDAP_ALNUM(c) || (c) == '-' )
112 #define LDAP_LEADOIDCHAR(c) ( LDAP_DIGIT(c) )
113 #define LDAP_OIDCHAR(c) ( LDAP_DIGIT(c) || (c) == '.' )
115 #define LDAP_LEADATTRCHAR(c) ( LDAP_LEADKEYCHAR(c) || LDAP_LEADOIDCHAR(c) )
116 #define LDAP_ATTRCHAR(c) ( LDAP_KEYCHAR((c)) || (c) == '.' )
118 #define LDAP_NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
120 #ifdef HAVE_CYRUS_SASL
127 LDAP_F (int) ldap_pvt_sasl_init LDAP_P(( void )); /* clientside init */
128 LDAP_F (int) ldap_pvt_sasl_install LDAP_P(( Sockbuf *, void * ));
129 LDAP_F (int) ldap_pvt_sasl_bind LDAP_P(( LDAP *, LDAP_CONST char *,
130 LDAP_CONST char *, LDAP_CONST sasl_callback_t *, LDAPControl **,
132 LDAP_F (int) ldap_pvt_sasl_get_option LDAP_P(( LDAP *ld, int option,
134 LDAP_F (int) ldap_pvt_sasl_set_option LDAP_P(( LDAP *ld, int option,
136 #endif /* HAVE_CYRUS_SASL */
140 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
143 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
147 ldap_pvt_str2upper LDAP_P(( char *str ));
150 ldap_pvt_str2lower LDAP_P(( char *str ));
156 LDAP_F (int) ldap_pvt_tls_init LDAP_P(( void ));
157 LDAP_F (int) ldap_pvt_tls_config LDAP_P(( struct ldapoptions *lo, int option, const char *arg ));
158 LDAP_F (int) ldap_pvt_tls_connect LDAP_P(( struct ldap *ld, Sockbuf *sb, void *ctx_arg ));
159 LDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
160 LDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldapoptions *lo, int option, void *arg ));
161 LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldapoptions *lo, int option, void *arg ));
162 LDAP_F (void *) ldap_pvt_tls_sb_handle LDAP_P(( Sockbuf *sb ));
163 LDAP_F (void *) ldap_pvt_tls_get_handle LDAP_P(( struct ldap *ld ));
164 LDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
165 LDAP_F (int) ldap_pvt_tls_start LDAP_P(( struct ldap *ld, Sockbuf *sb, void *ctx_arg ));
171 typedef ber_int_t ldap_ucs4_t;
172 typedef short ldap_ucs2_t;
173 typedef ldap_ucs2_t ldap_unicode_t;
175 /* returns the number of bytes in the UTF-8 string */
176 LDAP_F (ber_len_t) ldap_utf8_bytes( const char * );
177 /* returns the number of UTF-8 characters in the string */
178 LDAP_F (ber_len_t) ldap_utf8_chars( const char * );
179 /* returns the length (in bytes) of the UTF-8 character */
180 LDAP_F (int) ldap_utf8_offset( const char * );
181 /* returns the length (in bytes) indicated by the UTF-8 character */
182 LDAP_F (int) ldap_utf8_charlen( const char * );
183 /* copies a UTF-8 character and returning number of bytes copied */
184 LDAP_F (int) ldap_utf8_copy( char *, const char *);
186 /* returns pointer of next UTF-8 character in string */
187 LDAP_F (char*) ldap_utf8_next( const char * );
188 /* returns pointer of previous UTF-8 character in string */
189 LDAP_F (char*) ldap_utf8_prev( const char * );
191 /* primitive ctype routines -- not aware of non-ascii characters */
192 LDAP_F (int) ldap_utf8_isascii( const char * );
193 LDAP_F (int) ldap_utf8_isalpha( const char * );
194 LDAP_F (int) ldap_utf8_isalnum( const char * );
195 LDAP_F (int) ldap_utf8_isdigit( const char * );
196 LDAP_F (int) ldap_utf8_isxdigit( const char * );
197 LDAP_F (int) ldap_utf8_isspace( const char * );
199 /* span characters not in set, return bytes spanned */
200 LDAP_F (ber_len_t) ldap_utf8_strcspn( const char* str, const char *set);
201 /* span characters in set, return bytes spanned */
202 LDAP_F (ber_len_t) ldap_utf8_strspn( const char* str, const char *set);
203 /* return first occurance of character in string */
204 LDAP_F (char *) ldap_utf8_strchr( const char* str, const char *chr);
205 /* return first character of set in string */
206 LDAP_F (char *) ldap_utf8_strpbrk( const char* str, const char *set);
207 /* reentrant tokenizer */
208 LDAP_F (char*) ldap_utf8_strtok( char* sp, const char* sep, char **last);
211 #define LDAP_UTF8_ISASCII(p) ( * (const unsigned char *) (p) < 0x100 )
212 #define LDAP_UTF8_CHARLEN(p) ( LDAP_UTF8_ISASCII(p) \
213 ? 1 : ldap_utf8_charlen((p)) )
214 #define LDAP_UTF8_OFFSET(p) ( LDAP_UTF8_ISASCII(p) \
215 ? 1 : ldap_utf8_offset((p)) )
217 #define LDAP_UTF8_COPY(d,s) ( LDAP_UTF8_ISASCII(s) \
218 ? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) )
220 #define LDAP_UTF8_NEXT(p) ( LDAP_UTF8_ISASCII(p) \
221 ? (char *)(p)+1 : ldap_utf8_next((p)) )
223 #define LDAP_UTF8_INCR(p) ((p) = LDAP_UTF8_NEXT(p))
226 #define LDAP_UTF8_PREV(p) (ldap_utf8_prev((p)))
227 #define LDAP_UTF8_DECR(p) ((p)=LDAP_UTF8_PREV((p)))