1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public
3*7c478bd9Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file
4*7c478bd9Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of
5*7c478bd9Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/
6*7c478bd9Sstevel@tonic-gate *
7*7c478bd9Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS
8*7c478bd9Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9*7c478bd9Sstevel@tonic-gate * implied. See the License for the specific language governing
10*7c478bd9Sstevel@tonic-gate * rights and limitations under the License.
11*7c478bd9Sstevel@tonic-gate *
12*7c478bd9Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released
13*7c478bd9Sstevel@tonic-gate * March 31, 1998.
14*7c478bd9Sstevel@tonic-gate *
15*7c478bd9Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape
16*7c478bd9Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are
17*7c478bd9Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All
18*7c478bd9Sstevel@tonic-gate * Rights Reserved.
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * Contributor(s):
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate
23*7c478bd9Sstevel@tonic-gate /*
24*7c478bd9Sstevel@tonic-gate * Utilities for manageing the relationship between NSPR errors and
25*7c478bd9Sstevel@tonic-gate * OS (errno-style) errors.
26*7c478bd9Sstevel@tonic-gate *
27*7c478bd9Sstevel@tonic-gate * The overall strategy used is to map NSPR errors into OS errors.
28*7c478bd9Sstevel@tonic-gate */
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate #include "ldappr-int.h"
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate void
prldap_set_system_errno(int oserrno)34*7c478bd9Sstevel@tonic-gate prldap_set_system_errno( int oserrno )
35*7c478bd9Sstevel@tonic-gate {
36*7c478bd9Sstevel@tonic-gate PR_SetError( PR_UNKNOWN_ERROR, oserrno );
37*7c478bd9Sstevel@tonic-gate }
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate
40*7c478bd9Sstevel@tonic-gate int
prldap_get_system_errno(void)41*7c478bd9Sstevel@tonic-gate prldap_get_system_errno( void )
42*7c478bd9Sstevel@tonic-gate {
43*7c478bd9Sstevel@tonic-gate return( PR_GetOSError());
44*7c478bd9Sstevel@tonic-gate }
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate /*
47*7c478bd9Sstevel@tonic-gate * Retrieve the NSPR error number, convert to a system error code, and return
48*7c478bd9Sstevel@tonic-gate * the result.
49*7c478bd9Sstevel@tonic-gate */
50*7c478bd9Sstevel@tonic-gate struct prldap_errormap_entry {
51*7c478bd9Sstevel@tonic-gate PRInt32 erm_nspr; /* NSPR error code */
52*7c478bd9Sstevel@tonic-gate int erm_system; /* corresponding system error code */
53*7c478bd9Sstevel@tonic-gate };
54*7c478bd9Sstevel@tonic-gate
55*7c478bd9Sstevel@tonic-gate /* XXX: not sure if this extra mapping for Windows is good or correct */
56*7c478bd9Sstevel@tonic-gate #ifdef _WINDOWS
57*7c478bd9Sstevel@tonic-gate #ifndef ENOTSUP
58*7c478bd9Sstevel@tonic-gate #define ENOTSUP -1
59*7c478bd9Sstevel@tonic-gate #endif
60*7c478bd9Sstevel@tonic-gate #ifndef ETIMEDOUT
61*7c478bd9Sstevel@tonic-gate #define ETIMEDOUT WSAETIMEDOUT
62*7c478bd9Sstevel@tonic-gate #endif
63*7c478bd9Sstevel@tonic-gate #ifndef EADDRNOTAVAIL
64*7c478bd9Sstevel@tonic-gate #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
65*7c478bd9Sstevel@tonic-gate #endif
66*7c478bd9Sstevel@tonic-gate #ifndef EAFNOSUPPORT
67*7c478bd9Sstevel@tonic-gate #define EAFNOSUPPORT WSAEAFNOSUPPORT
68*7c478bd9Sstevel@tonic-gate #endif
69*7c478bd9Sstevel@tonic-gate #ifndef EISCONN
70*7c478bd9Sstevel@tonic-gate #define EISCONN WSAEISCONN
71*7c478bd9Sstevel@tonic-gate #endif
72*7c478bd9Sstevel@tonic-gate #ifndef EADDRINUSE
73*7c478bd9Sstevel@tonic-gate #define EADDRINUSE WSAEADDRINUSE
74*7c478bd9Sstevel@tonic-gate #endif
75*7c478bd9Sstevel@tonic-gate #ifndef ECONNREFUSED
76*7c478bd9Sstevel@tonic-gate #define ECONNREFUSED WSAECONNREFUSED
77*7c478bd9Sstevel@tonic-gate #endif
78*7c478bd9Sstevel@tonic-gate #ifndef EHOSTUNREACH
79*7c478bd9Sstevel@tonic-gate #define EHOSTUNREACH WSAEHOSTUNREACH
80*7c478bd9Sstevel@tonic-gate #endif
81*7c478bd9Sstevel@tonic-gate #ifndef ENOTCONN
82*7c478bd9Sstevel@tonic-gate #define ENOTCONN WSAENOTCONN
83*7c478bd9Sstevel@tonic-gate #endif
84*7c478bd9Sstevel@tonic-gate #ifndef ENOTSOCK
85*7c478bd9Sstevel@tonic-gate #define ENOTSOCK WSAENOTSOCK
86*7c478bd9Sstevel@tonic-gate #endif
87*7c478bd9Sstevel@tonic-gate #ifndef EPROTOTYPE
88*7c478bd9Sstevel@tonic-gate #define EPROTOTYPE WSAEPROTOTYPE
89*7c478bd9Sstevel@tonic-gate #endif
90*7c478bd9Sstevel@tonic-gate #ifndef EOPNOTSUPP
91*7c478bd9Sstevel@tonic-gate #define EOPNOTSUPP WSAEOPNOTSUPP
92*7c478bd9Sstevel@tonic-gate #endif
93*7c478bd9Sstevel@tonic-gate #ifndef EPROTONOSUPPORT
94*7c478bd9Sstevel@tonic-gate #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
95*7c478bd9Sstevel@tonic-gate #endif
96*7c478bd9Sstevel@tonic-gate #ifndef EOVERFLOW
97*7c478bd9Sstevel@tonic-gate #define EOVERFLOW -1
98*7c478bd9Sstevel@tonic-gate #endif
99*7c478bd9Sstevel@tonic-gate #ifndef ECONNRESET
100*7c478bd9Sstevel@tonic-gate #define ECONNRESET WSAECONNRESET
101*7c478bd9Sstevel@tonic-gate #endif
102*7c478bd9Sstevel@tonic-gate #ifndef ELOOP
103*7c478bd9Sstevel@tonic-gate #define ELOOP WSAELOOP
104*7c478bd9Sstevel@tonic-gate #endif
105*7c478bd9Sstevel@tonic-gate #ifndef ENOTBLK
106*7c478bd9Sstevel@tonic-gate #define ENOTBLK -1
107*7c478bd9Sstevel@tonic-gate #endif
108*7c478bd9Sstevel@tonic-gate #ifndef ETXTBSY
109*7c478bd9Sstevel@tonic-gate #define ETXTBSY -1
110*7c478bd9Sstevel@tonic-gate #endif
111*7c478bd9Sstevel@tonic-gate #ifndef ENETDOWN
112*7c478bd9Sstevel@tonic-gate #define ENETDOWN WSAENETDOWN
113*7c478bd9Sstevel@tonic-gate #endif
114*7c478bd9Sstevel@tonic-gate #ifndef ESHUTDOWN
115*7c478bd9Sstevel@tonic-gate #define ESHUTDOWN WSAESHUTDOWN
116*7c478bd9Sstevel@tonic-gate #endif
117*7c478bd9Sstevel@tonic-gate #ifndef ECONNABORTED
118*7c478bd9Sstevel@tonic-gate #define ECONNABORTED WSAECONNABORTED
119*7c478bd9Sstevel@tonic-gate #endif
120*7c478bd9Sstevel@tonic-gate #endif /* _WINDOWS */
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate /* XXX: need to verify that the -1 entries are correct (no mapping) */
123*7c478bd9Sstevel@tonic-gate static struct prldap_errormap_entry prldap_errormap[] = {
124*7c478bd9Sstevel@tonic-gate { PR_OUT_OF_MEMORY_ERROR, ENOMEM },
125*7c478bd9Sstevel@tonic-gate { PR_BAD_DESCRIPTOR_ERROR, EBADF },
126*7c478bd9Sstevel@tonic-gate { PR_WOULD_BLOCK_ERROR, EAGAIN },
127*7c478bd9Sstevel@tonic-gate { PR_ACCESS_FAULT_ERROR, EFAULT },
128*7c478bd9Sstevel@tonic-gate { PR_INVALID_METHOD_ERROR, EINVAL }, /* XXX: correct mapping ? */
129*7c478bd9Sstevel@tonic-gate { PR_ILLEGAL_ACCESS_ERROR, EACCES }, /* XXX: correct mapping ? */
130*7c478bd9Sstevel@tonic-gate { PR_UNKNOWN_ERROR, -1 },
131*7c478bd9Sstevel@tonic-gate { PR_PENDING_INTERRUPT_ERROR, -1 },
132*7c478bd9Sstevel@tonic-gate { PR_NOT_IMPLEMENTED_ERROR, ENOTSUP },
133*7c478bd9Sstevel@tonic-gate { PR_IO_ERROR, EIO },
134*7c478bd9Sstevel@tonic-gate { PR_IO_TIMEOUT_ERROR, ETIMEDOUT }, /* XXX: correct mapping ? */
135*7c478bd9Sstevel@tonic-gate { PR_IO_PENDING_ERROR, -1 },
136*7c478bd9Sstevel@tonic-gate { PR_DIRECTORY_OPEN_ERROR, ENOTDIR },
137*7c478bd9Sstevel@tonic-gate { PR_INVALID_ARGUMENT_ERROR, EINVAL },
138*7c478bd9Sstevel@tonic-gate { PR_ADDRESS_NOT_AVAILABLE_ERROR, EADDRNOTAVAIL },
139*7c478bd9Sstevel@tonic-gate { PR_ADDRESS_NOT_SUPPORTED_ERROR, EAFNOSUPPORT },
140*7c478bd9Sstevel@tonic-gate { PR_IS_CONNECTED_ERROR, EISCONN },
141*7c478bd9Sstevel@tonic-gate { PR_BAD_ADDRESS_ERROR, EFAULT }, /* XXX: correct mapping ? */
142*7c478bd9Sstevel@tonic-gate { PR_ADDRESS_IN_USE_ERROR, EADDRINUSE },
143*7c478bd9Sstevel@tonic-gate { PR_CONNECT_REFUSED_ERROR, ECONNREFUSED },
144*7c478bd9Sstevel@tonic-gate { PR_NETWORK_UNREACHABLE_ERROR, EHOSTUNREACH },
145*7c478bd9Sstevel@tonic-gate { PR_CONNECT_TIMEOUT_ERROR, ETIMEDOUT },
146*7c478bd9Sstevel@tonic-gate { PR_NOT_CONNECTED_ERROR, ENOTCONN },
147*7c478bd9Sstevel@tonic-gate { PR_LOAD_LIBRARY_ERROR, -1 },
148*7c478bd9Sstevel@tonic-gate { PR_UNLOAD_LIBRARY_ERROR, -1 },
149*7c478bd9Sstevel@tonic-gate { PR_FIND_SYMBOL_ERROR, -1 },
150*7c478bd9Sstevel@tonic-gate { PR_INSUFFICIENT_RESOURCES_ERROR, -1 },
151*7c478bd9Sstevel@tonic-gate { PR_DIRECTORY_LOOKUP_ERROR, -1 },
152*7c478bd9Sstevel@tonic-gate { PR_TPD_RANGE_ERROR, -1 },
153*7c478bd9Sstevel@tonic-gate { PR_PROC_DESC_TABLE_FULL_ERROR, -1 },
154*7c478bd9Sstevel@tonic-gate { PR_SYS_DESC_TABLE_FULL_ERROR, -1 },
155*7c478bd9Sstevel@tonic-gate { PR_NOT_SOCKET_ERROR, ENOTSOCK },
156*7c478bd9Sstevel@tonic-gate { PR_NOT_TCP_SOCKET_ERROR, EPROTOTYPE },
157*7c478bd9Sstevel@tonic-gate { PR_SOCKET_ADDRESS_IS_BOUND_ERROR, -1 },
158*7c478bd9Sstevel@tonic-gate { PR_NO_ACCESS_RIGHTS_ERROR, EACCES }, /* XXX: correct mapping ? */
159*7c478bd9Sstevel@tonic-gate { PR_OPERATION_NOT_SUPPORTED_ERROR, EOPNOTSUPP },
160*7c478bd9Sstevel@tonic-gate { PR_PROTOCOL_NOT_SUPPORTED_ERROR, EPROTONOSUPPORT },
161*7c478bd9Sstevel@tonic-gate { PR_REMOTE_FILE_ERROR, -1 },
162*7c478bd9Sstevel@tonic-gate #if defined(OSF1)
163*7c478bd9Sstevel@tonic-gate { PR_BUFFER_OVERFLOW_ERROR, -1 },
164*7c478bd9Sstevel@tonic-gate #else
165*7c478bd9Sstevel@tonic-gate { PR_BUFFER_OVERFLOW_ERROR, EOVERFLOW },
166*7c478bd9Sstevel@tonic-gate #endif /* OSF1 */
167*7c478bd9Sstevel@tonic-gate { PR_CONNECT_RESET_ERROR, ECONNRESET },
168*7c478bd9Sstevel@tonic-gate { PR_RANGE_ERROR, ERANGE },
169*7c478bd9Sstevel@tonic-gate { PR_DEADLOCK_ERROR, EDEADLK },
170*7c478bd9Sstevel@tonic-gate #if defined(HPUX11) || defined(AIX4_3) || defined(OSF1)
171*7c478bd9Sstevel@tonic-gate { PR_FILE_IS_LOCKED_ERROR, -1 }, /* XXX: correct mapping ? */
172*7c478bd9Sstevel@tonic-gate #else
173*7c478bd9Sstevel@tonic-gate { PR_FILE_IS_LOCKED_ERROR, EDEADLOCK }, /* XXX: correct mapping ? */
174*7c478bd9Sstevel@tonic-gate #endif /* HPUX11 */
175*7c478bd9Sstevel@tonic-gate { PR_FILE_TOO_BIG_ERROR, EFBIG },
176*7c478bd9Sstevel@tonic-gate { PR_NO_DEVICE_SPACE_ERROR, ENOSPC },
177*7c478bd9Sstevel@tonic-gate { PR_PIPE_ERROR, EPIPE },
178*7c478bd9Sstevel@tonic-gate { PR_NO_SEEK_DEVICE_ERROR, ESPIPE },
179*7c478bd9Sstevel@tonic-gate { PR_IS_DIRECTORY_ERROR, EISDIR },
180*7c478bd9Sstevel@tonic-gate { PR_LOOP_ERROR, ELOOP },
181*7c478bd9Sstevel@tonic-gate { PR_NAME_TOO_LONG_ERROR, ENAMETOOLONG },
182*7c478bd9Sstevel@tonic-gate { PR_FILE_NOT_FOUND_ERROR, ENOENT },
183*7c478bd9Sstevel@tonic-gate { PR_NOT_DIRECTORY_ERROR, ENOTDIR },
184*7c478bd9Sstevel@tonic-gate { PR_READ_ONLY_FILESYSTEM_ERROR, EROFS },
185*7c478bd9Sstevel@tonic-gate { PR_DIRECTORY_NOT_EMPTY_ERROR, ENOTEMPTY },
186*7c478bd9Sstevel@tonic-gate { PR_FILESYSTEM_MOUNTED_ERROR, EBUSY },
187*7c478bd9Sstevel@tonic-gate { PR_NOT_SAME_DEVICE_ERROR, EXDEV },
188*7c478bd9Sstevel@tonic-gate { PR_DIRECTORY_CORRUPTED_ERROR, -1 },
189*7c478bd9Sstevel@tonic-gate { PR_FILE_EXISTS_ERROR, EEXIST },
190*7c478bd9Sstevel@tonic-gate { PR_MAX_DIRECTORY_ENTRIES_ERROR, -1 },
191*7c478bd9Sstevel@tonic-gate { PR_INVALID_DEVICE_STATE_ERROR, ENOTBLK }, /* XXX: correct mapping ? */
192*7c478bd9Sstevel@tonic-gate { PR_DEVICE_IS_LOCKED_ERROR, -2 },
193*7c478bd9Sstevel@tonic-gate { PR_NO_MORE_FILES_ERROR, ENFILE },
194*7c478bd9Sstevel@tonic-gate { PR_END_OF_FILE_ERROR, -1 },
195*7c478bd9Sstevel@tonic-gate { PR_FILE_SEEK_ERROR, ESPIPE }, /* XXX: correct mapping ? */
196*7c478bd9Sstevel@tonic-gate { PR_FILE_IS_BUSY_ERROR, ETXTBSY },
197*7c478bd9Sstevel@tonic-gate { PR_OPERATION_ABORTED_ERROR, -1 },
198*7c478bd9Sstevel@tonic-gate { PR_IN_PROGRESS_ERROR, -1 },
199*7c478bd9Sstevel@tonic-gate { PR_ALREADY_INITIATED_ERROR, -1 },
200*7c478bd9Sstevel@tonic-gate { PR_GROUP_EMPTY_ERROR, -1 },
201*7c478bd9Sstevel@tonic-gate { PR_INVALID_STATE_ERROR, -1 },
202*7c478bd9Sstevel@tonic-gate { PR_NETWORK_DOWN_ERROR, ENETDOWN },
203*7c478bd9Sstevel@tonic-gate { PR_SOCKET_SHUTDOWN_ERROR, ESHUTDOWN },
204*7c478bd9Sstevel@tonic-gate { PR_CONNECT_ABORTED_ERROR, ECONNABORTED },
205*7c478bd9Sstevel@tonic-gate { PR_HOST_UNREACHABLE_ERROR, EHOSTUNREACH },
206*7c478bd9Sstevel@tonic-gate { PR_MAX_ERROR, -1 },
207*7c478bd9Sstevel@tonic-gate };
208*7c478bd9Sstevel@tonic-gate
209*7c478bd9Sstevel@tonic-gate
210*7c478bd9Sstevel@tonic-gate int
prldap_prerr2errno(void)211*7c478bd9Sstevel@tonic-gate prldap_prerr2errno( void )
212*7c478bd9Sstevel@tonic-gate {
213*7c478bd9Sstevel@tonic-gate int oserr, i;
214*7c478bd9Sstevel@tonic-gate PRInt32 nsprerr;
215*7c478bd9Sstevel@tonic-gate
216*7c478bd9Sstevel@tonic-gate nsprerr = PR_GetError();
217*7c478bd9Sstevel@tonic-gate
218*7c478bd9Sstevel@tonic-gate oserr = -1; /* unknown */
219*7c478bd9Sstevel@tonic-gate for ( i = 0; prldap_errormap[i].erm_nspr != PR_MAX_ERROR; ++i ) {
220*7c478bd9Sstevel@tonic-gate if ( prldap_errormap[i].erm_nspr == nsprerr ) {
221*7c478bd9Sstevel@tonic-gate oserr = prldap_errormap[i].erm_system;
222*7c478bd9Sstevel@tonic-gate break;
223*7c478bd9Sstevel@tonic-gate }
224*7c478bd9Sstevel@tonic-gate }
225*7c478bd9Sstevel@tonic-gate
226*7c478bd9Sstevel@tonic-gate return( oserr );
227*7c478bd9Sstevel@tonic-gate }
228