2 * Copyright (c) 2001 by Sun Microsystems, Inc.
7 * The contents of this file are subject to the Netscape Public
8 * License Version 1.1 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.mozilla.org/NPL/
12 * Software distributed under the License is distributed on an "AS
13 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The Original Code is Mozilla Communicator client code, released
20 * The Initial Developer of the Original Code is Netscape
21 * Communications Corporation. Portions created by Netscape are
22 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
28 #pragma ident "%Z%%M% %I% %E% SMI"
31 * errormap.c - map NSPR and OS errors to strings
33 * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF NETSCAPE COMMUNICATIONS
36 * Copyright (C) 1998-9 Netscape Communications Corporation. All Rights Reserved.
38 * Use of this Source Code is subject to the terms of the applicable license
39 * agreement from Netscape Communications Corporation.
41 * The copyright notice(s) in this Source Code does not indicate actual or
42 * intended publication of this Source Code.
46 * This code was stolen from Directory server.
47 * ns/netsite/ldap/servers/slapd/errormap.c
48 * OS errors are not handled, so the os error has been removed.
52 #if defined( _WINDOWS )
54 #include "proto-ntutil.h"
65 #endif /* _SOLARIS_SDK */
71 static const char *SECU_Strerror(PRErrorCode errNum
);
76 * return the string equivalent of an NSPR error
81 ldapssl_err2string( const int prerrno
)
85 if (( s
= SECU_Strerror( (PRErrorCode
)prerrno
)) == NULL
) {
86 s
= dgettext(TEXT_DOMAIN
, "unknown");
93 ****************************************************************************
94 * The code below this point was provided by Nelson Bolyard <nelsonb> of the
95 * Netscape Certificate Server team on 27-March-1998.
96 * Taken from the file ns/security/cmd/lib/secerror.c on NSS_1_BRANCH.
97 * Last updated from there: 24-July-1998 by Mark Smith <mcs>
98 * Last updated from there: 14-July-1999 by chuck boatwright <cboatwri>
101 * All of the Directory Server specific changes are enclosed inside
102 * #ifdef NS_DIRECTORY.
103 ****************************************************************************
108 * XXXceb as a hack, we will locally define NS_DIRECTORY
110 #define NS_DIRECTORY 1
114 const char * errString
;
117 typedef struct tuple_str tuple_str
;
120 #define ER2(a,b) {a, b},
121 #define ER3(a,b,c) {a, c},
123 #define ER2(a,b) {a, NULL},
124 #define ER3(a,b,c) {a, NULL},
131 const tuple_str errStrings
[] = {
133 tuple_str errStrings
[] = {
136 /* keep this list in asceding order of error numbers */
138 #include "sslerrstrs.h"
139 #include "secerrstrs.h"
140 #include "prerrstrs.h"
142 * XXXceb -- LDAPSDK won't care about disconnect
143 #include "disconnect_error_strings.h"
146 #else /* NS_DIRECTORY */
149 #include "NSPRerrs.h"
150 #endif /* NS_DIRECTORY */
154 const PRInt32 numStrings
= sizeof(errStrings
) / sizeof(tuple_str
);
156 /* Returns a UTF-8 encoded constant error string for "errNum".
157 * Returns NULL of errNum is unknown.
162 #endif /* NS_DIRECTORY */
164 SECU_Strerror(PRErrorCode errNum
) {
166 PRInt32 high
= numStrings
- 1;
171 /* make sure table is in ascending order.
172 * binary search depends on it.
175 PRErrorCode lastNum
= 0x80000000;
176 for (i
= low
; i
<= high
; ++i
) {
177 num
= errStrings
[i
].errNum
;
178 if (num
<= lastNum
) {
182 * We aren't handling out of sequence errors.
188 LDAPDebug( LDAP_DEBUG_ANY
,
189 "sequence error in error strings at item %d\n"
191 i
, lastNum
, errStrings
[i
-1].errString
);
192 LDAPDebug( LDAP_DEBUG_ANY
,
193 "should come after \n"
195 num
, errStrings
[i
].errString
, 0 );
196 #else /* NS_DIRECTORY */
198 "sequence error in error strings at item %d\n"
200 "should come after \n"
202 i
, lastNum
, errStrings
[i
-1].errString
,
203 num
, errStrings
[i
].errString
);
204 #endif /* NS_DIRECTORY */
212 /* Do binary search of table. */
213 while (low
+ 1 < high
) {
214 i
= (low
+ high
) / 2;
215 num
= errStrings
[i
].errNum
;
217 return errStrings
[i
].errString
;
223 if (errNum
== errStrings
[low
].errNum
)
224 return errStrings
[low
].errString
;
225 if (errNum
== errStrings
[high
].errNum
)
226 return errStrings
[high
].errString
;
229 #else /* _SOLARIS_SDK */
231 #define ER3(x, y, z) case (x): \
235 #define ER2(x, y) case (x): \
239 static mutex_t err_mutex
= DEFAULTMUTEX
;
242 getErrString(PRInt32 i
, PRErrorCode errNum
)
246 mutex_lock(&err_mutex
);
248 if (errStrings
[i
].errString
!= NULL
) {
249 mutex_unlock(&err_mutex
);
250 return (errStrings
[i
].errString
);
254 #include "sslerrstrs.h"
255 #include "secerrstrs.h"
256 #include "prerrstrs.h"
261 errStrings
[i
].errString
= s
;
262 mutex_unlock(&err_mutex
);
268 SECU_Strerror(PRErrorCode errNum
) {
270 PRInt32 high
= numStrings
- 1;
274 /* ASSUME table is in ascending order.
275 * binary search depends on it.
278 /* Do binary search of table. */
279 while (low
+ 1 < high
) {
280 i
= (low
+ high
) / 2;
281 num
= errStrings
[i
].errNum
;
283 return getErrString(i
, errNum
);
289 if (errNum
== errStrings
[low
].errNum
)
290 return getErrString(low
, errNum
);
291 if (errNum
== errStrings
[high
].errNum
)
292 return getErrString(high
, errNum
);