Back to index

lightning-sunbird  0.9+nobinonly
ldappr-error.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Communicator client code, released
00015  * March 31, 1998.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * Utilities for manageing the relationship between NSPR errors and
00040  * OS (errno-style) errors.
00041  *
00042  * The overall strategy used is to map NSPR errors into OS errors.
00043  */
00044 
00045 #include "ldappr-int.h"
00046 
00047 void
00048 prldap_set_system_errno( int oserrno )
00049 {
00050     PR_SetError( PR_UNKNOWN_ERROR, oserrno );
00051 }
00052 
00053 
00054 int
00055 prldap_get_system_errno( void )
00056 {
00057     return( PR_GetOSError());
00058 }
00059 
00060 /*
00061  * Retrieve the NSPR error number, convert to a system error code, and return
00062  * the result.
00063  */
00064 struct prldap_errormap_entry {
00065     PRInt32   erm_nspr;     /* NSPR error code */
00066     int              erm_system;   /* corresponding system error code */
00067 };
00068 
00069 /* XXX: not sure if this extra mapping for Windows is good or correct */
00070 #ifdef _WINDOWS
00071 #ifndef ENOTSUP
00072 #define ENOTSUP             -1
00073 #endif
00074 #ifndef ETIMEDOUT
00075 #define ETIMEDOUT    WSAETIMEDOUT
00076 #endif
00077 #ifndef EADDRNOTAVAIL
00078 #define EADDRNOTAVAIL       WSAEADDRNOTAVAIL
00079 #endif
00080 #ifndef EAFNOSUPPORT
00081 #define EAFNOSUPPORT WSAEAFNOSUPPORT
00082 #endif
00083 #ifndef EISCONN
00084 #define EISCONN             WSAEISCONN
00085 #endif
00086 #ifndef EADDRINUSE
00087 #define EADDRINUSE   WSAEADDRINUSE
00088 #endif
00089 #ifndef ECONNREFUSED
00090 #define ECONNREFUSED WSAECONNREFUSED
00091 #endif
00092 #ifndef EHOSTUNREACH
00093 #define EHOSTUNREACH WSAEHOSTUNREACH
00094 #endif
00095 #ifndef ENOTCONN
00096 #define ENOTCONN     WSAENOTCONN
00097 #endif
00098 #ifndef ENOTSOCK
00099 #define ENOTSOCK     WSAENOTSOCK
00100 #endif
00101 #ifndef EPROTOTYPE
00102 #define EPROTOTYPE   WSAEPROTOTYPE
00103 #endif
00104 #ifndef EOPNOTSUPP
00105 #define EOPNOTSUPP   WSAEOPNOTSUPP
00106 #endif
00107 #ifndef EPROTONOSUPPORT
00108 #define EPROTONOSUPPORT     WSAEPROTONOSUPPORT
00109 #endif
00110 #ifndef EOVERFLOW
00111 #define EOVERFLOW    -1
00112 #endif
00113 #ifndef ECONNRESET
00114 #define ECONNRESET   WSAECONNRESET
00115 #endif
00116 #ifndef ELOOP
00117 #define ELOOP        WSAELOOP
00118 #endif
00119 #ifndef ENOTBLK
00120 #define ENOTBLK             -1
00121 #endif
00122 #ifndef ETXTBSY
00123 #define ETXTBSY             -1
00124 #endif
00125 #ifndef ENETDOWN
00126 #define ENETDOWN     WSAENETDOWN
00127 #endif
00128 #ifndef ESHUTDOWN
00129 #define ESHUTDOWN    WSAESHUTDOWN
00130 #endif
00131 #ifndef ECONNABORTED
00132 #define ECONNABORTED WSAECONNABORTED
00133 #endif
00134 #endif /* _WINDOWS */
00135 
00136 #if defined(macintosh)
00137 /*
00138  * Some Unix error defs. Under CW 7, we can't define OTUNIXERRORS because
00139  * it generates many conflicts with errno.h. Define what we need here.
00140  * These need to be in sync with OpenTransport.h
00141  */
00142 #define EWOULDBLOCK     35
00143 #define ENOTSOCK        38
00144 #define EPROTOTYPE      41
00145 #define EPROTONOSUPPORT 43
00146 #define EOPNOTSUPP      45
00147 #define EADDRINUSE      48
00148 #define EADDRNOTAVAIL   49
00149 #define ENETDOWN        50
00150 #define ECONNABORTED    53
00151 #define ECONNRESET      54
00152 #define EISCONN         56
00153 #define ENOTCONN        57
00154 #define ESHUTDOWN       58
00155 #define ETIMEDOUT       60
00156 #define ECONNREFUSED    61
00157 #define EHOSTUNREACH    65
00158 #define EAFNOSUPPORT    -1
00159 #define ELOOP           -1
00160 #define ENOTBLK         -1
00161 #define ENOTSUP         -1
00162 #define EOVERFLOW       -1
00163 #define ETXTBSY         -1
00164 #endif /* macintosh */
00165 
00166 #ifdef XP_OS2
00167 #ifdef XP_OS2_EMX
00168 #define SOCBASEERR      0
00169 #endif
00170 #ifndef ENOTSUP
00171 #define ENOTSUP         -1
00172 #endif
00173 #ifndef EOVERFLOW
00174 #define EOVERFLOW       -1
00175 #endif
00176 #ifndef EDEADLOCK
00177 #define EDEADLOCK       -1
00178 #endif
00179 #ifndef EFAULT
00180 #define EFAULT          SOCEFAULT
00181 #endif
00182 #ifndef EPIPE
00183 #define EPIPE           SOCEPIPE
00184 #endif
00185 #ifndef EIO
00186 #define EIO             (SOCBASEERR+5)
00187 #endif
00188 #ifndef EDEADLK
00189 #define EDEADLK         (SOCBASEERR+11)
00190 #endif
00191 #ifndef ENOTBLK
00192 #define ENOTBLK         (SOCBASEERR+15)
00193 #endif
00194 #ifndef EBUSY
00195 #define EBUSY           (SOCBASEERR+16)
00196 #endif
00197 #ifndef ENOTDIR
00198 #define ENOTDIR         (SOCBASEERR+20)
00199 #endif
00200 #ifndef EISDIR
00201 #define EISDIR          (SOCBASEERR+21)
00202 #endif
00203 #ifndef ENFILE
00204 #define ENFILE          (SOCBASEERR+23)
00205 #endif
00206 #ifndef ETXTBSY
00207 #define ETXTBSY         (SOCBASEERR+26)
00208 #endif
00209 #ifndef EFBIG
00210 #define EFBIG           (SOCBASEERR+27)
00211 #endif
00212 #ifndef ESPIPE
00213 #define ESPIPE          (SOCBASEERR+29)
00214 #endif
00215 #ifndef EROFS
00216 #define EROFS           (SOCBASEERR+30)
00217 #endif
00218 #endif
00219 
00220 #ifdef BEOS
00221 #define ENOTSUP         -1
00222 #define ENOTBLK         -1
00223 #define ETXTBSY         -1
00224 #endif
00225 
00226 #if defined(BSDI) || defined(OPENBSD) || defined (NETBSD)
00227 #define ENOTSUP             -1
00228 #endif
00229 
00230 #if defined(OSF1) || defined(BSDI) || defined(VMS) || defined(OPENBSD)
00231 #define EOVERFLOW       -1
00232 #endif
00233 
00234 #if defined(__hpux) || defined(_AIX) || defined(OSF1) || defined(DARWIN) || \
00235   defined(BEOS) || defined(FREEBSD) || defined(BSDI) || defined(VMS) || \
00236   defined(OPENBSD) || defined(NETBSD)
00237 #define EDEADLOCK       -1
00238 #endif
00239 
00240 /* XXX: need to verify that the -1 entries are correct (no mapping) */
00241 static struct prldap_errormap_entry prldap_errormap[] = {
00242     {  PR_OUT_OF_MEMORY_ERROR, ENOMEM },
00243     {  PR_BAD_DESCRIPTOR_ERROR, EBADF },
00244     {  PR_WOULD_BLOCK_ERROR, EAGAIN },
00245     {  PR_ACCESS_FAULT_ERROR, EFAULT },
00246     {  PR_INVALID_METHOD_ERROR, EINVAL }, /* XXX: correct mapping ? */
00247     {  PR_ILLEGAL_ACCESS_ERROR, EACCES }, /* XXX: correct mapping ? */
00248     {  PR_UNKNOWN_ERROR, -1 },
00249     {  PR_PENDING_INTERRUPT_ERROR, -1 },
00250     {  PR_NOT_IMPLEMENTED_ERROR, ENOTSUP },
00251     {  PR_IO_ERROR, EIO },
00252     {  PR_IO_TIMEOUT_ERROR, ETIMEDOUT },  /* XXX: correct mapping ? */
00253     {  PR_IO_PENDING_ERROR, -1 },
00254     {  PR_DIRECTORY_OPEN_ERROR, ENOTDIR },
00255     {  PR_INVALID_ARGUMENT_ERROR, EINVAL },
00256     {  PR_ADDRESS_NOT_AVAILABLE_ERROR, EADDRNOTAVAIL },
00257     {  PR_ADDRESS_NOT_SUPPORTED_ERROR, EAFNOSUPPORT },
00258     {  PR_IS_CONNECTED_ERROR, EISCONN },
00259     {  PR_BAD_ADDRESS_ERROR, EFAULT },           /* XXX: correct mapping ? */
00260     {  PR_ADDRESS_IN_USE_ERROR, EADDRINUSE },
00261     {  PR_CONNECT_REFUSED_ERROR, ECONNREFUSED },
00262     {  PR_NETWORK_UNREACHABLE_ERROR, EHOSTUNREACH },
00263     {  PR_CONNECT_TIMEOUT_ERROR, ETIMEDOUT },
00264     {  PR_NOT_CONNECTED_ERROR, ENOTCONN },
00265     {  PR_LOAD_LIBRARY_ERROR, -1 },
00266     {  PR_UNLOAD_LIBRARY_ERROR, -1 },
00267     {  PR_FIND_SYMBOL_ERROR, -1 },
00268     {  PR_INSUFFICIENT_RESOURCES_ERROR, -1 },
00269     {  PR_DIRECTORY_LOOKUP_ERROR, EHOSTUNREACH },/* an approximation */
00270     {  PR_TPD_RANGE_ERROR, -1 },
00271     {  PR_PROC_DESC_TABLE_FULL_ERROR, -1 },
00272     {  PR_SYS_DESC_TABLE_FULL_ERROR, -1 },
00273     {  PR_NOT_SOCKET_ERROR, ENOTSOCK },
00274     {  PR_NOT_TCP_SOCKET_ERROR, EPROTOTYPE },
00275     {  PR_SOCKET_ADDRESS_IS_BOUND_ERROR, -1 },
00276     {  PR_NO_ACCESS_RIGHTS_ERROR, EACCES },      /* XXX: correct mapping ? */
00277     {  PR_OPERATION_NOT_SUPPORTED_ERROR, EOPNOTSUPP },
00278     {  PR_PROTOCOL_NOT_SUPPORTED_ERROR, EPROTONOSUPPORT },
00279     {  PR_REMOTE_FILE_ERROR, -1 },
00280     {  PR_BUFFER_OVERFLOW_ERROR, EOVERFLOW },
00281     {  PR_CONNECT_RESET_ERROR, ECONNRESET },
00282     {  PR_RANGE_ERROR, ERANGE },
00283     {  PR_DEADLOCK_ERROR, EDEADLK },
00284     {  PR_FILE_IS_LOCKED_ERROR, EDEADLOCK },     /* XXX: correct mapping ? */
00285     {  PR_FILE_TOO_BIG_ERROR, EFBIG },
00286     {  PR_NO_DEVICE_SPACE_ERROR, ENOSPC },
00287     {  PR_PIPE_ERROR, EPIPE },
00288     {  PR_NO_SEEK_DEVICE_ERROR, ESPIPE },
00289     {  PR_IS_DIRECTORY_ERROR, EISDIR },
00290     {  PR_LOOP_ERROR, ELOOP },
00291     {  PR_NAME_TOO_LONG_ERROR, ENAMETOOLONG },
00292     {  PR_FILE_NOT_FOUND_ERROR, ENOENT },
00293     {  PR_NOT_DIRECTORY_ERROR, ENOTDIR },
00294     {  PR_READ_ONLY_FILESYSTEM_ERROR, EROFS },
00295     {  PR_DIRECTORY_NOT_EMPTY_ERROR, ENOTEMPTY },
00296     {  PR_FILESYSTEM_MOUNTED_ERROR, EBUSY },
00297     {  PR_NOT_SAME_DEVICE_ERROR, EXDEV },
00298     {  PR_DIRECTORY_CORRUPTED_ERROR, -1 },
00299     {  PR_FILE_EXISTS_ERROR, EEXIST },
00300     {  PR_MAX_DIRECTORY_ENTRIES_ERROR, -1 },
00301     {  PR_INVALID_DEVICE_STATE_ERROR, ENOTBLK }, /* XXX: correct mapping ? */
00302     {  PR_DEVICE_IS_LOCKED_ERROR, -2 },
00303     {  PR_NO_MORE_FILES_ERROR, ENFILE },
00304     {  PR_END_OF_FILE_ERROR, -1 },
00305     {  PR_FILE_SEEK_ERROR, ESPIPE },             /* XXX: correct mapping ? */
00306     {  PR_FILE_IS_BUSY_ERROR, ETXTBSY },
00307     {  PR_OPERATION_ABORTED_ERROR, -1 },
00308     {  PR_IN_PROGRESS_ERROR, -1 },
00309     {  PR_ALREADY_INITIATED_ERROR, -1 },
00310     {  PR_GROUP_EMPTY_ERROR, -1 },
00311     {  PR_INVALID_STATE_ERROR, -1 },
00312     {  PR_NETWORK_DOWN_ERROR, ENETDOWN },
00313     {  PR_SOCKET_SHUTDOWN_ERROR, ESHUTDOWN },
00314     {  PR_CONNECT_ABORTED_ERROR, ECONNABORTED },
00315     {  PR_HOST_UNREACHABLE_ERROR, EHOSTUNREACH },
00316     {  PR_MAX_ERROR, -1 },
00317 };
00318 
00319 
00320 int
00321 prldap_prerr2errno( void )
00322 {
00323     int              oserr, i;
00324     PRInt32   nsprerr;
00325 
00326     nsprerr = PR_GetError();
00327 
00328     oserr = -1;             /* unknown */
00329     for ( i = 0; prldap_errormap[i].erm_nspr != PR_MAX_ERROR; ++i ) {
00330        if ( prldap_errormap[i].erm_nspr == nsprerr ) {
00331            oserr = prldap_errormap[i].erm_system;
00332            break;
00333        }
00334     }
00335 
00336     return( oserr );
00337 }