1 /*
2  * Copyright 2001-2003 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #ifndef _SOLARISINT_H
7 #define _SOLARISINT_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 #include <stdio.h>
14 #include <ctype.h>
15 #include <stdarg.h>
16 #include <stdlib.h>
17 
18 #include "ldap.h"
19 
20 /*
21  * These were moved from lber.h. This should have been ifdef'd with
22  * _SOLARIS_SDK but since we do not want to expose these in lber.h its
23  * not possible to ifndef it there.
24  */
25 
26 /* BerElement set/get options */
27 #define LBER_OPT_REMAINING_BYTES	0x01
28 #define LBER_OPT_TOTAL_BYTES		0x02
29 #define LBER_OPT_USE_DER		0x04
30 #define LBER_OPT_TRANSLATE_STRINGS	0x08
31 #define LBER_OPT_BYTES_TO_WRITE		0x10
32 #define LBER_OPT_MEMALLOC_FN_PTRS	0x20
33 #define LBER_OPT_DEBUG_LEVEL		0x40
34 /*
35  * LBER_USE_DER is defined for compatibility with the C LDAP API RFC.
36  * In our implementation, we recognize it (instead of the numerically
37  * identical LBER_OPT_REMAINING_BYTES) in calls to ber_alloc_t() and
38  * ber_init_w_nullchar() only.  Callers of ber_set_option() or
39  * ber_get_option() must use LBER_OPT_USE_DER instead.  Sorry!
40  */
41 #define LBER_USE_DER			0x01
42 
43 /* Sockbuf set/get options */
44 #define LBER_SOCKBUF_OPT_TO_FILE		0x001
45 #define LBER_SOCKBUF_OPT_TO_FILE_ONLY		0x002
46 #define LBER_SOCKBUF_OPT_MAX_INCOMING_SIZE	0x004
47 #define LBER_SOCKBUF_OPT_NO_READ_AHEAD		0x008
48 #define LBER_SOCKBUF_OPT_DESC			0x010
49 #define LBER_SOCKBUF_OPT_COPYDESC		0x020
50 #define LBER_SOCKBUF_OPT_READ_FN		0x040
51 #define LBER_SOCKBUF_OPT_WRITE_FN		0x080
52 #define LBER_SOCKBUF_OPT_EXT_IO_FNS		0x100
53 
54 #ifndef _SOLARIS_SDK
55 /*
56  * The following is not used by solaris. Just kept to stay in sync with
57  * iplanet and also a place holder (0x200)
58  */
59 #define LBER_SOCKBUF_OPT_VALID_TAG              0x200
60 #endif	/* !_SOLARIS_SDK */
61 
62 /*
63  * Socket buffer structure associated to the LDAP connection
64  */
65 #define LDAP_X_OPT_SOCKBUF	(LDAP_OPT_PRIVATE_EXTENSION_BASE + 0x0F02)
66 	/* 0x4000 + 0x0F02 = 0x4F02 = 20226 - API extension */
67 
68 
69 #define LBER_OPT_ON	((void *) 1)
70 #define LBER_OPT_OFF	((void *) 0)
71 
72 /* Used in various functions */
73 #define LBER_FUNC_VALUE		-1
74 
75 struct lextiof_socket_private;          /* Defined by the extended I/O */
76                                         /* callback functions */
77 struct lextiof_session_private;         /* Defined by the extended I/O */
78                                         /* callback functions */
79 
80 /* This is modeled after the PRIOVec that is passed to the NSPR
81    writev function! The void* is a char* in that struct */
82 typedef struct ldap_x_iovec {
83         char    *ldapiov_base;
84         int     ldapiov_len;
85 } ldap_x_iovec;
86 
87 /*
88  * libldap read and write I/O function callbacks.  The rest of the I/O callback
89  * types are defined in ldap.h
90  */
91 typedef int (LDAP_C LDAP_CALLBACK LDAP_IOF_READ_CALLBACK)( LBER_SOCKET s,
92 	void *buf, int bufsize );
93 typedef int (LDAP_C LDAP_CALLBACK LDAP_IOF_WRITE_CALLBACK)( LBER_SOCKET s,
94 	const void *buf, int len );
95 typedef int (LDAP_C LDAP_CALLBACK LDAP_X_EXTIOF_READ_CALLBACK)( int s,
96 	void *buf, int bufsize, struct lextiof_socket_private *arg );
97 typedef int (LDAP_C LDAP_CALLBACK LDAP_X_EXTIOF_WRITE_CALLBACK)( int s,
98 	const void *buf, int len, struct lextiof_socket_private *arg );
99 typedef int (LDAP_C LDAP_CALLBACK LDAP_X_EXTIOF_WRITEV_CALLBACK)(int s,
100         const ldap_x_iovec iov[], int iovcnt, struct lextiof_socket_private *socketarg);
101 
102 
103 /*
104  * Structure for use with LBER_SOCKBUF_OPT_EXT_IO_FNS:
105  */
106 struct lber_x_ext_io_fns {
107 	    /* lbextiofn_size should always be set to LBER_X_EXTIO_FNS_SIZE */
108 	int				lbextiofn_size;
109 	LDAP_X_EXTIOF_READ_CALLBACK	*lbextiofn_read;
110 	LDAP_X_EXTIOF_WRITE_CALLBACK	*lbextiofn_write;
111 	struct lextiof_socket_private	*lbextiofn_socket_arg;
112         LDAP_X_EXTIOF_WRITEV_CALLBACK   *lbextiofn_writev;
113 };
114 #define LBER_X_EXTIO_FNS_SIZE sizeof(struct lber_x_ext_io_fns)
115 
116 /*
117  * liblber memory allocation callback functions.  These are global to all
118  *  Sockbufs and BerElements.  Install your own functions by using a call
119  *  like this: ber_set_option( NULL, LBER_OPT_MEMALLOC_FN_PTRS, &memalloc_fns );
120  */
121 typedef void * (LDAP_C LDAP_CALLBACK LDAP_MALLOC_CALLBACK)( size_t size );
122 typedef void * (LDAP_C LDAP_CALLBACK LDAP_CALLOC_CALLBACK)( size_t nelem,
123 	size_t elsize );
124 typedef void * (LDAP_C LDAP_CALLBACK LDAP_REALLOC_CALLBACK)( void *ptr,
125 	size_t size );
126 typedef void (LDAP_C LDAP_CALLBACK LDAP_FREE_CALLBACK)( void *ptr );
127 
128 struct lber_memalloc_fns {
129 	LDAP_MALLOC_CALLBACK	*lbermem_malloc;
130 	LDAP_CALLOC_CALLBACK	*lbermem_calloc;
131 	LDAP_REALLOC_CALLBACK	*lbermem_realloc;
132 	LDAP_FREE_CALLBACK	*lbermem_free;
133 };
134 
135 /*
136  * Functions marked as Project Private in PSARC case and moved
137  * from lber.h
138  */
139 typedef struct sockbuf Sockbuf;
140 
141 LDAP_API(void) LDAP_CALL ber_special_free(void* buf, BerElement *ber);
142 LDAP_API(void*) LDAP_CALL ber_special_alloc(size_t size, BerElement **ppBer);
143 LDAP_API(ber_uint_t) LDAP_CALL ber_get_next_buffer( void *buffer,
144 	size_t buffer_size, ber_len_t *len, BerElement *ber,
145 	ber_uint_t *Bytes_Scanned );
146 LDAP_API(ber_uint_t) LDAP_CALL ber_get_next_buffer_ext( void *buffer,
147 	size_t buffer_size, ber_len_t *len, BerElement *ber,
148 	ber_len_t *Bytes_Scanned, Sockbuf *sb );
149 LDAP_API(void) LDAP_CALL ber_init_w_nullchar( BerElement *ber, int options );
150 LDAP_API(int) LDAP_CALL ber_set_option( BerElement *ber, int option,
151 	void *value );
152 LDAP_API(int) LDAP_CALL ber_get_option( BerElement *ber, int option,
153 	void *value );
154 LDAP_API(Sockbuf*) LDAP_CALL ber_sockbuf_alloc( void );
155 LDAP_API(void) LDAP_CALL ber_sockbuf_free( Sockbuf* p );
156 LDAP_API(int) LDAP_CALL ber_sockbuf_set_option( Sockbuf *sb, int option,
157 	void *value );
158 LDAP_API(int) LDAP_CALL ber_sockbuf_get_option( Sockbuf *sb, int option,
159 	void *value );
160 LDAP_API(int) LDAP_CALL ber_flush( Sockbuf *sb, BerElement *ber, int freeit );
161 LDAP_API(ber_tag_t) LDAP_CALL ber_get_next( Sockbuf *sb, ber_len_t *len,
162 	BerElement *ber );
163 
164 /*
165  * The following was moved from ldap.h
166  */
167 
168 /*
169  * These extended I/O function callbacks echo the BSD socket API but accept
170  * an extra pointer parameter at the end of their argument list that can
171  * be used by client applications for their own needs.  For some of the calls,
172  * the pointer is a session argument of type struct lextiof_session_private *
173  * that is associated with the LDAP session handle (LDAP *).  For others, the
174  * pointer is a socket specific struct lextiof_socket_private * argument that
175  * is associated with a particular socket (a TCP connection).
176  *
177  * The lextiof_session_private and lextiof_socket_private structures are not
178  * defined by the LDAP C API; users of this extended I/O interface should
179  * define these themselves.
180  *
181  * The combination of the integer socket number (i.e., lpoll_fd, which is
182  * the value returned by the CONNECT callback) and the application specific
183  * socket argument (i.e., lpoll_socketarg, which is the value set in *sockargpp
184  * by the CONNECT callback) must be unique.
185  *
186  * The types for the extended READ and WRITE callbacks are actually in lber.h.
187  *
188  * The CONNECT callback gets passed both the session argument (sessionarg)
189  * and a pointer to a socket argument (socketargp) so it has the
190  * opportunity to set the socket-specific argument.  The CONNECT callback
191  * also takes a timeout parameter whose value can be set by calling
192  * ldap_set_option( ld, LDAP_X_OPT_..., &val ).  The units used for the
193  * timeout parameter are milliseconds.
194  *
195  * A POLL interface is provided instead of a select() one.  The timeout is
196  * in milliseconds.
197 
198  * A NEWHANDLE callback function is also provided.  It is called right
199  * after the LDAP session handle is created, e.g., during ldap_init().
200  * If the NEWHANDLE callback returns anything other than LDAP_SUCCESS,
201  * the session handle allocation fails.
202  *
203  * A DISPOSEHANDLE callback function is also provided.  It is called right
204  * before the LDAP session handle and its contents are destroyed, e.g.,
205  * during ldap_unbind().
206  */
207 
208 /* LDAP poll()-like descriptor:
209  */
210 typedef struct ldap_x_pollfd {	   /* used by LDAP_X_EXTIOF_POLL_CALLBACK */
211     int		lpoll_fd;	   /* integer file descriptor / socket */
212     struct lextiof_socket_private
213 		*lpoll_socketarg;
214 				   /* pointer socket and for use by */
215 				   /* application */
216     short	lpoll_events;      /* requested event */
217     short	lpoll_revents;     /* returned event */
218 } LDAP_X_PollFD;
219 
220 /* Event flags for lpoll_events and lpoll_revents:
221  */
222 #define LDAP_X_POLLIN    0x01  /* regular data ready for reading */
223 #define LDAP_X_POLLPRI   0x02  /* high priority data available */
224 #define LDAP_X_POLLOUT   0x04  /* ready for writing */
225 #define LDAP_X_POLLERR   0x08  /* error occurred -- only in lpoll_revents */
226 #define LDAP_X_POLLHUP   0x10  /* connection closed -- only in lpoll_revents */
227 #define LDAP_X_POLLNVAL  0x20  /* invalid lpoll_fd -- only in lpoll_revents */
228 
229 /* Options passed to LDAP_X_EXTIOF_CONNECT_CALLBACK to modify socket behavior:
230  */
231 #define LDAP_X_EXTIOF_OPT_NONBLOCKING	0x01  /* turn on non-blocking mode */
232 #define LDAP_X_EXTIOF_OPT_SECURE	0x02  /* turn on 'secure' mode */
233 
234 /* extended I/O callback function prototypes:
235  */
236 typedef int	(LDAP_C LDAP_CALLBACK LDAP_X_EXTIOF_CONNECT_CALLBACK )(
237 	    const char *hostlist, int port, /* host byte order */
238 	    int timeout /* milliseconds */,
239 	    unsigned long options, /* bitmapped options */
240 	    struct lextiof_session_private *sessionarg,
241 	    struct lextiof_socket_private **socketargp
242 #ifdef _SOLARIS_SDK
243 		, void **datapriv );
244 #else
245 		);
246 #endif
247 typedef int	(LDAP_C LDAP_CALLBACK LDAP_X_EXTIOF_CLOSE_CALLBACK )(
248 	    int s, struct lextiof_socket_private *socketarg );
249 typedef int	(LDAP_C LDAP_CALLBACK LDAP_X_EXTIOF_POLL_CALLBACK)(
250 	    LDAP_X_PollFD fds[], int nfds, int timeout /* milliseconds */,
251 	    struct lextiof_session_private *sessionarg );
252 typedef int	(LDAP_C LDAP_CALLBACK LDAP_X_EXTIOF_NEWHANDLE_CALLBACK)(
253 	    LDAP *ld, struct lextiof_session_private *sessionarg );
254 typedef void	(LDAP_C LDAP_CALLBACK LDAP_X_EXTIOF_DISPOSEHANDLE_CALLBACK)(
255 	    LDAP *ld, struct lextiof_session_private *sessionarg );
256 
257 
258 /* Structure to hold extended I/O function pointers:
259  */
260 struct ldap_x_ext_io_fns {
261 	/* lextiof_size should always be set to LDAP_X_EXTIO_FNS_SIZE */
262 	int					lextiof_size;
263 	LDAP_X_EXTIOF_CONNECT_CALLBACK		*lextiof_connect;
264 	LDAP_X_EXTIOF_CLOSE_CALLBACK		*lextiof_close;
265 	LDAP_X_EXTIOF_READ_CALLBACK		*lextiof_read;
266 	LDAP_X_EXTIOF_WRITE_CALLBACK		*lextiof_write;
267 	LDAP_X_EXTIOF_POLL_CALLBACK		*lextiof_poll;
268 	LDAP_X_EXTIOF_NEWHANDLE_CALLBACK	*lextiof_newhandle;
269 	LDAP_X_EXTIOF_DISPOSEHANDLE_CALLBACK	*lextiof_disposehandle;
270 	void					*lextiof_session_arg;
271 	LDAP_X_EXTIOF_WRITEV_CALLBACK           *lextiof_writev;
272 };
273 #define LDAP_X_EXTIO_FNS_SIZE	sizeof(struct ldap_x_ext_io_fns)
274 
275 
276 /*
277  * Utility functions for parsing space-separated host lists (useful for
278  * implementing an extended I/O CONNECT callback function).
279  */
280 struct ldap_x_hostlist_status;
281 LDAP_API(int) LDAP_CALL ldap_x_hostlist_first( const char *hostlist,
282 	int defport, char **hostp, int *portp /* host byte order */,
283 	struct ldap_x_hostlist_status **statusp );
284 LDAP_API(int) LDAP_CALL ldap_x_hostlist_next( char **hostp,
285 	int *portp /* host byte order */, struct ldap_x_hostlist_status *status );
286 LDAP_API(void) LDAP_CALL ldap_x_hostlist_statusfree(
287 	struct ldap_x_hostlist_status *status );
288 
289 
290 /*
291  * I/O callback functions (note that types for the read and write callbacks
292  * are actually in lber.h):
293  */
294 typedef int	(LDAP_C LDAP_CALLBACK LDAP_IOF_SELECT_CALLBACK)( int nfds,
295 	fd_set *readfds, fd_set *writefds, fd_set *errorfds,
296 	struct timeval *timeout );
297 typedef LBER_SOCKET (LDAP_C LDAP_CALLBACK LDAP_IOF_SOCKET_CALLBACK)(
298 	int domain, int type, int protocol );
299 typedef int	(LDAP_C LDAP_CALLBACK LDAP_IOF_IOCTL_CALLBACK)( LBER_SOCKET s,
300 	int option, ... );
301 typedef int	(LDAP_C LDAP_CALLBACK LDAP_IOF_CONNECT_CALLBACK )(
302 	LBER_SOCKET s, struct sockaddr *name, int namelen );
303 typedef int	(LDAP_C LDAP_CALLBACK LDAP_IOF_CLOSE_CALLBACK )(
304 	LBER_SOCKET s );
305 typedef int	(LDAP_C LDAP_CALLBACK LDAP_IOF_SSL_ENABLE_CALLBACK )(
306 	LBER_SOCKET s );
307 
308 
309 /*
310  * Structure to hold I/O function pointers:
311  */
312 struct ldap_io_fns {
313 	LDAP_IOF_READ_CALLBACK *liof_read;
314 	LDAP_IOF_WRITE_CALLBACK *liof_write;
315 	LDAP_IOF_SELECT_CALLBACK *liof_select;
316 	LDAP_IOF_SOCKET_CALLBACK *liof_socket;
317 	LDAP_IOF_IOCTL_CALLBACK *liof_ioctl;
318 	LDAP_IOF_CONNECT_CALLBACK *liof_connect;
319 	LDAP_IOF_CLOSE_CALLBACK *liof_close;
320 	LDAP_IOF_SSL_ENABLE_CALLBACK *liof_ssl_enable;
321 };
322 
323 /********* the functions in the following section are experimental ***********/
324 
325 #define	LDAP_OPT_PREFERRED_LANGUAGE	0x14	/* 20 - API extension */
326 
327 /*
328  * SSL option (an API extension):
329  */
330 #define	LDAP_OPT_SSL			0x0A	/* 10 - API extension */
331 
332 /*
333  * Referral hop limit (an API extension):
334  */
335 #define	LDAP_OPT_REFERRAL_HOP_LIMIT	0x10	/* 16 - API extension */
336 
337 /*
338  * DNS resolver callbacks (an API extension --LDAP_API_FEATURE_X_DNS_FUNCTIONS).
339  * Note that gethostbyaddr() is not currently used.
340  */
341 #define	LDAP_OPT_DNS_FN_PTRS		0x60	/* 96 - API extension */
342 
343 typedef struct LDAPHostEnt {
344     char	*ldaphe_name;		/* official name of host */
345     char	**ldaphe_aliases;	/* alias list */
346     int		ldaphe_addrtype;	/* host address type */
347     int		ldaphe_length;		/* length of address */
348     char	**ldaphe_addr_list;	/* list of addresses from name server */
349 } LDAPHostEnt;
350 
351 typedef LDAPHostEnt * (LDAP_C LDAP_CALLBACK LDAP_DNSFN_GETHOSTBYNAME)(
352 	const char *name, LDAPHostEnt *result, char *buffer,
353 	int buflen, int *statusp, void *extradata);
354 typedef LDAPHostEnt * (LDAP_C LDAP_CALLBACK LDAP_DNSFN_GETHOSTBYADDR)(
355 	const char *addr, int length, int type, LDAPHostEnt *result,
356 	char *buffer, int buflen, int *statusp, void *extradata);
357 typedef int (LDAP_C LDAP_CALLBACK LDAP_DNSFN_GETPEERNAME)(
358 	LDAP *ld, struct sockaddr *netaddr, char *buffer, int buflen);
359 
360 struct ldap_dns_fns {
361 	void				*lddnsfn_extradata;
362 	int				lddnsfn_bufsize;
363 	LDAP_DNSFN_GETHOSTBYNAME	*lddnsfn_gethostbyname;
364 	LDAP_DNSFN_GETHOSTBYADDR	*lddnsfn_gethostbyaddr;
365 	LDAP_DNSFN_GETPEERNAME		*lddnsfn_getpeername;
366 };
367 
368 /*
369  * Generalized cache callback interface:
370  */
371 #define	LDAP_OPT_CACHE_FN_PTRS		0x0D	/* 13 - API extension */
372 #define	LDAP_OPT_CACHE_STRATEGY		0x0E	/* 14 - API extension */
373 #define	LDAP_OPT_CACHE_ENABLE		0x0F	/* 15 - API extension */
374 
375 /* cache strategies */
376 #define	LDAP_CACHE_CHECK		0
377 #define	LDAP_CACHE_POPULATE		1
378 #define	LDAP_CACHE_LOCALDB		2
379 
380 typedef int (LDAP_C LDAP_CALLBACK LDAP_CF_BIND_CALLBACK)(LDAP *ld, int msgid,
381 	ber_tag_t tag, const char *dn, const struct berval *creds,
382 	int method);
383 typedef int (LDAP_C LDAP_CALLBACK LDAP_CF_UNBIND_CALLBACK)(LDAP *ld,
384 	int unused0, unsigned long unused1);
385 typedef int (LDAP_C LDAP_CALLBACK LDAP_CF_SEARCH_CALLBACK)(LDAP *ld,
386 	int msgid, ber_tag_t tag, const char *base, int scope,
387 	const char LDAP_CALLBACK *filter, char **attrs, int attrsonly);
388 typedef int (LDAP_C LDAP_CALLBACK LDAP_CF_COMPARE_CALLBACK)(LDAP *ld,
389 	int msgid, ber_tag_t tag, const char *dn, const char *attr,
390 	const struct berval *value);
391 typedef int (LDAP_C LDAP_CALLBACK LDAP_CF_ADD_CALLBACK)(LDAP *ld,
392 	int msgid, ber_tag_t tag, const char *dn, LDAPMod **attrs);
393 typedef int (LDAP_C LDAP_CALLBACK LDAP_CF_DELETE_CALLBACK)(LDAP *ld,
394 	int msgid, ber_tag_t tag, const char *dn);
395 typedef int (LDAP_C LDAP_CALLBACK LDAP_CF_MODIFY_CALLBACK)(LDAP *ld,
396 	int msgid, ber_tag_t tag, const char *dn, LDAPMod **mods);
397 typedef int (LDAP_C LDAP_CALLBACK LDAP_CF_MODRDN_CALLBACK)(LDAP *ld,
398 	int msgid, ber_tag_t tag, const char *dn, const char *newrdn,
399 	int deleteoldrdn);
400 typedef int (LDAP_C LDAP_CALLBACK LDAP_CF_RESULT_CALLBACK)(LDAP *ld,
401 	int msgid, int all, struct timeval *timeout, LDAPMessage **result);
402 typedef int (LDAP_C LDAP_CALLBACK LDAP_CF_FLUSH_CALLBACK)(LDAP *ld,
403 	const char *dn, const char *filter);
404 
405 struct ldap_cache_fns {
406 	void    *lcf_private;
407 	LDAP_CF_BIND_CALLBACK *lcf_bind;
408 	LDAP_CF_UNBIND_CALLBACK *lcf_unbind;
409 	LDAP_CF_SEARCH_CALLBACK *lcf_search;
410 	LDAP_CF_COMPARE_CALLBACK *lcf_compare;
411 	LDAP_CF_ADD_CALLBACK *lcf_add;
412 	LDAP_CF_DELETE_CALLBACK *lcf_delete;
413 	LDAP_CF_MODIFY_CALLBACK *lcf_modify;
414 	LDAP_CF_MODRDN_CALLBACK *lcf_modrdn;
415 	LDAP_CF_RESULT_CALLBACK *lcf_result;
416 	LDAP_CF_FLUSH_CALLBACK *lcf_flush;
417 };
418 
419 int LDAP_CALL ldap_cache_flush(LDAP *ld, const char *dn,
420 	const char *filter);
421 
422 /*
423  * Memory allocation callback functions (an API extension --
424  * LDAP_API_FEATURE_X_MEMALLOC_FUNCTIONS).  These are global and can
425  * not be set on a per-LDAP session handle basis.  Install your own
426  * functions by making a call like this:
427  *    ldap_set_option( NULL, LDAP_OPT_MEMALLOC_FN_PTRS, &memalloc_fns );
428  *
429  * look in lber.h for the function typedefs themselves.
430  */
431 #define LDAP_OPT_MEMALLOC_FN_PTRS	0x61	/* 97 - API extension */
432 
433 struct ldap_memalloc_fns {
434 	LDAP_MALLOC_CALLBACK	*ldapmem_malloc;
435 	LDAP_CALLOC_CALLBACK	*ldapmem_calloc;
436 	LDAP_REALLOC_CALLBACK	*ldapmem_realloc;
437 	LDAP_FREE_CALLBACK	*ldapmem_free;
438 };
439 
440 
441 /*
442  * Memory allocation functions (an API extension)
443  */
444 void *ldap_x_malloc( size_t size );
445 void *ldap_x_calloc( size_t nelem, size_t elsize );
446 void *ldap_x_realloc( void *ptr, size_t size );
447 void ldap_x_free( void *ptr );
448 
449 /*
450  * Extra thread callback functions (an API extension --
451  * LDAP_API_FEATURE_X_EXTHREAD_FUNCTIONS)
452  */
453 #define LDAP_OPT_EXTRA_THREAD_FN_PTRS  0x65	/* 101 - API extension */
454 
455 typedef int (LDAP_C LDAP_CALLBACK LDAP_TF_MUTEX_TRYLOCK_CALLBACK)( void *m );
456 typedef void *(LDAP_C LDAP_CALLBACK LDAP_TF_SEMA_ALLOC_CALLBACK)( void );
457 typedef void (LDAP_C LDAP_CALLBACK LDAP_TF_SEMA_FREE_CALLBACK)( void *s );
458 typedef int (LDAP_C LDAP_CALLBACK LDAP_TF_SEMA_WAIT_CALLBACK)( void *s );
459 typedef int (LDAP_C LDAP_CALLBACK LDAP_TF_SEMA_POST_CALLBACK)( void *s );
460 typedef void *(LDAP_C LDAP_CALLBACK LDAP_TF_THREADID_CALLBACK)(void);
461 
462 struct ldap_extra_thread_fns {
463         LDAP_TF_MUTEX_TRYLOCK_CALLBACK *ltf_mutex_trylock;
464         LDAP_TF_SEMA_ALLOC_CALLBACK *ltf_sema_alloc;
465         LDAP_TF_SEMA_FREE_CALLBACK *ltf_sema_free;
466         LDAP_TF_SEMA_WAIT_CALLBACK *ltf_sema_wait;
467         LDAP_TF_SEMA_POST_CALLBACK *ltf_sema_post;
468 	LDAP_TF_THREADID_CALLBACK *ltf_threadid_fn;
469 };
470 
471 
472 /*
473  * Debugging level (an API extension)
474  */
475 #define LDAP_OPT_DEBUG_LEVEL		0x6E	/* 110 - API extension */
476 /* On UNIX, there's only one copy of ldap_debug */
477 /* On NT, each dll keeps its own module_ldap_debug, which */
478 /* points to the process' ldap_debug and needs initializing after load */
479 #ifdef _WIN32
480 extern int		*module_ldap_debug;
481 typedef void (*set_debug_level_fn_t)(int*);
482 #endif
483 
484 /************************ end of experimental section ************************/
485 
486 
487 LDAP_API(int) LDAP_CALL ldap_keysort_entries( LDAP *ld, LDAPMessage **chain,
488 	void *arg, LDAP_KEYGEN_CALLBACK *gen, LDAP_KEYCMP_CALLBACK *cmp,
489 	LDAP_KEYFREE_CALLBACK *fre );
490 
491 /*
492  * utility routines
493  */
494 LDAP_API(int) LDAP_CALL ldap_charray_add( char ***a, char *s );
495 LDAP_API(int) LDAP_CALL ldap_charray_merge( char ***a, char **s );
496 LDAP_API(void) LDAP_CALL ldap_charray_free( char **array );
497 LDAP_API(int) LDAP_CALL ldap_charray_inlist( char **a, char *s );
498 LDAP_API(char **) LDAP_CALL ldap_charray_dup( char **a );
499 LDAP_API(char **) LDAP_CALL ldap_str2charray( char *str, char *brkstr );
500 LDAP_API(int) LDAP_CALL ldap_charray_position( char **a, char *s );
501 
502 /*
503  * UTF-8 routines (should these move into libnls?)
504  */
505 /* number of bytes in character */
506 LDAP_API(int) LDAP_CALL ldap_utf8len( const char* );
507 /* find next character */
508 LDAP_API(char*) LDAP_CALL ldap_utf8next( char* );
509 /* find previous character */
510 LDAP_API(char*) LDAP_CALL ldap_utf8prev( char* );
511 /* copy one character */
512 LDAP_API(int) LDAP_CALL ldap_utf8copy( char* dst, const char* src );
513 /* total number of characters */
514 LDAP_API(size_t) LDAP_CALL ldap_utf8characters( const char* );
515 /* get one UCS-4 character, and move *src to the next character */
516 LDAP_API(unsigned long) LDAP_CALL ldap_utf8getcc( const char** src );
517 /* UTF-8 aware strtok_r() */
518 LDAP_API(char*) LDAP_CALL ldap_utf8strtok_r( char* src, const char* brk, char** next);
519 
520 /* like isalnum(*s) in the C locale */
521 LDAP_API(int) LDAP_CALL ldap_utf8isalnum( char* s );
522 /* like isalpha(*s) in the C locale */
523 LDAP_API(int) LDAP_CALL ldap_utf8isalpha( char* s );
524 /* like isdigit(*s) in the C locale */
525 LDAP_API(int) LDAP_CALL ldap_utf8isdigit( char* s );
526 /* like isxdigit(*s) in the C locale */
527 LDAP_API(int) LDAP_CALL ldap_utf8isxdigit(char* s );
528 /* like isspace(*s) in the C locale */
529 LDAP_API(int) LDAP_CALL ldap_utf8isspace( char* s );
530 
531 #define LDAP_UTF8LEN(s)  ((0x80 & *(unsigned char*)(s)) ?   ldap_utf8len (s) : 1)
532 #define LDAP_UTF8NEXT(s) ((0x80 & *(unsigned char*)(s)) ?   ldap_utf8next(s) : (s)+1)
533 #define LDAP_UTF8INC(s)  ((0x80 & *(unsigned char*)(s)) ? s=ldap_utf8next(s) : ++s)
534 
535 #define LDAP_UTF8PREV(s)   ldap_utf8prev(s)
536 #define LDAP_UTF8DEC(s) (s=ldap_utf8prev(s))
537 
538 #define LDAP_UTF8COPY(d,s) ((0x80 & *(unsigned char*)(s)) ? ldap_utf8copy(d,s) : ((*(d) = *(s)), 1))
539 #define LDAP_UTF8GETCC(s) ((0x80 & *(unsigned char*)(s)) ? ldap_utf8getcc (&s) : *s++)
540 #define LDAP_UTF8GETC(s) ((0x80 & *(unsigned char*)(s)) ? ldap_utf8getcc ((const char**)&s) : *s++)
541 
542 #ifdef __cplusplus
543 }
544 #endif
545 #endif /* _SOLARISINT_H */
546 
547