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