xref: /titanic_51/usr/src/lib/libnisdb/ldap_util.h (revision ad135b5d644628e791c3188a6ecbd9c257961ef8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2001-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <stdarg.h>
28 #include <syslog.h>
29 
30 #include "ldap_structs.h"
31 
32 #ifndef	_LDAP_UTIL_H
33 #define	_LDAP_UTIL_H
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #define	T	1
40 #define	F	0
41 
42 #define	NIL(s)	(((s) != 0) ? (s) : "<nil>")
43 #define	MAX(a, b)	(((a) > (b)) ? (a) : (b))
44 
45 /* Message types */
46 #define	MSG_ALWAYS		-1
47 #define	MSG_NOTIMECHECK		0
48 #define	MSG_NOMEM		1
49 #define	MSG_MEMPARAM		2
50 #define	MSG_TSDERR		3
51 #define	MSG_BER			4
52 #define	MSG_INVALIDDELDISP	5
53 #define	MSG_NORULEVALUE		6
54 #define	MSG_NONPCOLDSTART	7
55 #define	MSG_VLV_INSUFF_ACC	8
56 #define	MSG_LASTMSG		9
57 
58 /* Error numbers (NPL is NisPlusLdap) */
59 #define	NPL_NOERROR	0
60 #define	NPL_NOMEM	1
61 #define	NPL_TSDERR	2
62 #define	NPL_BERENCODE	3
63 #define	NPL_BERDECODE	4
64 
65 /* Structure used to maintain a buffer with a length */
66 typedef struct {
67 	char	*buf;
68 	int	len;
69 } __nis_buffer_t;
70 
71 /* Generic print buffer */
72 extern __nis_buffer_t	pb;
73 
74 /* Deferred error reporting buffer (TSD) */
75 typedef struct {
76 	int		error;
77 	char		*message;
78 }  __nis_deferred_error_t;
79 
80 /* Exported symbols */
81 extern unsigned long	numMisaligned;
82 
83 /* Exported functions */
84 void	logmsg(int msgtype, int priority, const char *fmt, ...);
85 void	reportError(int error, char *fmt, ...);
86 int	getError(char **message);
87 void	clearError(void);
88 void	logError(int priority);
89 void	*am(const char *msg, int size);
90 int	slen(const char *str);
91 char	*sdup(const char *msg, int allocate, char *str);
92 char	*scat(const char *msg, int deallocate, char *s1, char *s2);
93 void	sfree(void *ptr);
94 char	lastChar(__nis_single_value_t *v);
95 void	*appendString2SingleVal(char *str, __nis_single_value_t *v,
96 		int *newLen);
97 int	scmp(char *s, __nis_single_value_t *v);
98 int	scasecmp(char *s, __nis_single_value_t *v);
99 int	vp2buf(const char *msg, char **buf, int buflen, const char *fmt,
100     va_list ap);
101 void	p2buf(char *msg, char *fmt, ...);
102 void	bp2buf(const char *msg, __nis_buffer_t *b, const char *fmt, ...);
103 void	bc2buf(const char *msg, void *buf, int len, __nis_buffer_t *b);
104 void	sbc2buf(const char *msg, void *buf, int len, __nis_buffer_t *b);
105 void	c2buf(char *msg, void *buf, int len);
106 void	sc2buf(char *msg, void *buf, int len);
107 void	printbuf(void);
108 void	*extendArray(void *array, int newsize);
109 int	checkIPaddress(char *addr, int len, char **newaddr);
110 int	sstrncmp(const char *s1, const char *s2, int n);
111 char	*trimWhiteSpaces(char *str, int *len, int deallocate);
112 int	escapeSpecialChars(__nis_value_t *val);
113 void	removeEscapeChars(__nis_value_t *val);
114 
115 
116 #ifdef	__cplusplus
117 }
118 #endif	/* __cplusplus */
119 
120 #endif	/* _LDAP_UTIL_H */
121