Home | History | Annotate | Download | only in ssl
      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /*
      3  * This file essentially replicates NSPR's source for the functions that
      4  * map system-specific error codes to NSPR error codes.  We would use
      5  * NSPR's functions, instead of duplicating them, but they're private.
      6  * As long as SSL's server session cache code must do platform native I/O
      7  * to accomplish its job, and NSPR's error mapping functions remain private,
      8  * this code will continue to need to be replicated.
      9  *
     10  * ***** BEGIN LICENSE BLOCK *****
     11  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
     12  *
     13  * The contents of this file are subject to the Mozilla Public License Version
     14  * 1.1 (the "License"); you may not use this file except in compliance with
     15  * the License. You may obtain a copy of the License at
     16  * http://www.mozilla.org/MPL/
     17  *
     18  * Software distributed under the License is distributed on an "AS IS" basis,
     19  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
     20  * for the specific language governing rights and limitations under the
     21  * License.
     22  *
     23  * The Original Code is the Netscape security libraries.
     24  *
     25  * The Initial Developer of the Original Code is
     26  * Netscape Communications Corporation.
     27  * Portions created by the Initial Developer are Copyright (C) 1994-2000
     28  * the Initial Developer. All Rights Reserved.
     29  *
     30  * Contributor(s):
     31  *
     32  * Alternatively, the contents of this file may be used under the terms of
     33  * either the GNU General Public License Version 2 or later (the "GPL"), or
     34  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
     35  * in which case the provisions of the GPL or the LGPL are applicable instead
     36  * of those above. If you wish to allow use of your version of this file only
     37  * under the terms of either the GPL or the LGPL, and not to allow others to
     38  * use your version of this file under the terms of the MPL, indicate your
     39  * decision by deleting the provisions above and replace them with the notice
     40  * and other provisions required by the GPL or the LGPL. If you do not delete
     41  * the provisions above, a recipient may use your version of this file under
     42  * the terms of any one of the MPL, the GPL or the LGPL.
     43  *
     44  * ***** END LICENSE BLOCK ***** */
     45 /* $Id: os2_err.c,v 1.4 2004/04/27 23:04:39 gerv%gerv.net Exp $ */
     46 
     47 #include "prerror.h"
     48 #include "prlog.h"
     49 #include <errno.h>
     50 
     51 
     52 /*
     53  * Based on win32err.c
     54  * OS2TODO Stub everything for now to build. HCT
     55  */
     56 
     57 /* forward declaration. */
     58 void nss_MD_os2_map_default_error(PRInt32 err);
     59 
     60 void nss_MD_os2_map_opendir_error(PRInt32 err)
     61 {
     62     nss_MD_os2_map_default_error(err);
     63 }
     64 
     65 void nss_MD_os2_map_closedir_error(PRInt32 err)
     66 {
     67     nss_MD_os2_map_default_error(err);
     68 }
     69 
     70 void nss_MD_os2_map_readdir_error(PRInt32 err)
     71 {
     72     nss_MD_os2_map_default_error(err);
     73 }
     74 
     75 void nss_MD_os2_map_delete_error(PRInt32 err)
     76 {
     77     nss_MD_os2_map_default_error(err);
     78 }
     79 
     80 /* The error code for stat() is in errno. */
     81 void nss_MD_os2_map_stat_error(PRInt32 err)
     82 {
     83     nss_MD_os2_map_default_error(err);
     84 }
     85 
     86 void nss_MD_os2_map_fstat_error(PRInt32 err)
     87 {
     88     nss_MD_os2_map_default_error(err);
     89 }
     90 
     91 void nss_MD_os2_map_rename_error(PRInt32 err)
     92 {
     93     nss_MD_os2_map_default_error(err);
     94 }
     95 
     96 /* The error code for access() is in errno. */
     97 void nss_MD_os2_map_access_error(PRInt32 err)
     98 {
     99     nss_MD_os2_map_default_error(err);
    100 }
    101 
    102 void nss_MD_os2_map_mkdir_error(PRInt32 err)
    103 {
    104     nss_MD_os2_map_default_error(err);
    105 }
    106 
    107 void nss_MD_os2_map_rmdir_error(PRInt32 err)
    108 {
    109     nss_MD_os2_map_default_error(err);
    110 }
    111 
    112 void nss_MD_os2_map_read_error(PRInt32 err)
    113 {
    114     nss_MD_os2_map_default_error(err);
    115 }
    116 
    117 void nss_MD_os2_map_transmitfile_error(PRInt32 err)
    118 {
    119     nss_MD_os2_map_default_error(err);
    120 }
    121 
    122 void nss_MD_os2_map_write_error(PRInt32 err)
    123 {
    124     nss_MD_os2_map_default_error(err);
    125 }
    126 
    127 void nss_MD_os2_map_lseek_error(PRInt32 err)
    128 {
    129     nss_MD_os2_map_default_error(err);
    130 }
    131 
    132 void nss_MD_os2_map_fsync_error(PRInt32 err)
    133 {
    134     nss_MD_os2_map_default_error(err);
    135 }
    136 
    137 /*
    138  * For both CloseHandle() and closesocket().
    139  */
    140 void nss_MD_os2_map_close_error(PRInt32 err)
    141 {
    142     nss_MD_os2_map_default_error(err);
    143 }
    144 
    145 void nss_MD_os2_map_socket_error(PRInt32 err)
    146 {
    147 //  PR_ASSERT(err != WSANOTINITIALISED);
    148     nss_MD_os2_map_default_error(err);
    149 }
    150 
    151 void nss_MD_os2_map_recv_error(PRInt32 err)
    152 {
    153     nss_MD_os2_map_default_error(err);
    154 }
    155 
    156 void nss_MD_os2_map_recvfrom_error(PRInt32 err)
    157 {
    158     nss_MD_os2_map_default_error(err);
    159 }
    160 
    161 void nss_MD_os2_map_send_error(PRInt32 err)
    162 {
    163     PRErrorCode prError;
    164     switch (err) {
    165 //     case WSAEMSGSIZE: 	prError = PR_INVALID_ARGUMENT_ERROR; break;
    166     default:		nss_MD_os2_map_default_error(err); return;
    167     }
    168     PR_SetError(prError, err);
    169 }
    170 
    171 void nss_MD_os2_map_sendto_error(PRInt32 err)
    172 {
    173     PRErrorCode prError;
    174     switch (err) {
    175 //    case WSAEMSGSIZE: 	prError = PR_INVALID_ARGUMENT_ERROR; break;
    176     default:		nss_MD_os2_map_default_error(err); return;
    177     }
    178     PR_SetError(prError, err);
    179 }
    180 
    181 void nss_MD_os2_map_accept_error(PRInt32 err)
    182 {
    183     PRErrorCode prError;
    184     switch (err) {
    185 //    case WSAEOPNOTSUPP: prError = PR_NOT_TCP_SOCKET_ERROR; break;
    186 //    case WSAEINVAL: 	prError = PR_INVALID_STATE_ERROR; break;
    187     default:		nss_MD_os2_map_default_error(err); return;
    188     }
    189     PR_SetError(prError, err);
    190 }
    191 
    192 void nss_MD_os2_map_acceptex_error(PRInt32 err)
    193 {
    194     nss_MD_os2_map_default_error(err);
    195 }
    196 
    197 void nss_MD_os2_map_connect_error(PRInt32 err)
    198 {
    199     PRErrorCode prError;
    200     switch (err) {
    201 //    case WSAEWOULDBLOCK: prError = PR_IN_PROGRESS_ERROR; break;
    202 //    case WSAEINVAL: 	prError = PR_ALREADY_INITIATED_ERROR; break;
    203 //    case WSAETIMEDOUT: 	prError = PR_IO_TIMEOUT_ERROR; break;
    204     default:		nss_MD_os2_map_default_error(err); return;
    205     }
    206     PR_SetError(prError, err);
    207 }
    208 
    209 void nss_MD_os2_map_bind_error(PRInt32 err)
    210 {
    211     PRErrorCode prError;
    212     switch (err) {
    213 //  case WSAEINVAL: 	prError = PR_SOCKET_ADDRESS_IS_BOUND_ERROR; break;
    214     default:		nss_MD_os2_map_default_error(err); return;
    215     }
    216     PR_SetError(prError, err);
    217 }
    218 
    219 void nss_MD_os2_map_listen_error(PRInt32 err)
    220 {
    221     PRErrorCode prError;
    222     switch (err) {
    223 //    case WSAEOPNOTSUPP: prError = PR_NOT_TCP_SOCKET_ERROR; break;
    224 //    case WSAEINVAL: 	prError = PR_INVALID_STATE_ERROR; break;
    225     default:		nss_MD_os2_map_default_error(err); return;
    226     }
    227     PR_SetError(prError, err);
    228 }
    229 
    230 void nss_MD_os2_map_shutdown_error(PRInt32 err)
    231 {
    232     nss_MD_os2_map_default_error(err);
    233 }
    234 
    235 void nss_MD_os2_map_getsockname_error(PRInt32 err)
    236 {
    237     PRErrorCode prError;
    238     switch (err) {
    239 //    case WSAEINVAL: 	prError = PR_INVALID_STATE_ERROR; break;
    240     default:		nss_MD_os2_map_default_error(err); return;
    241     }
    242     PR_SetError(prError, err);
    243 }
    244 
    245 void nss_MD_os2_map_getpeername_error(PRInt32 err)
    246 {
    247     nss_MD_os2_map_default_error(err);
    248 }
    249 
    250 void nss_MD_os2_map_getsockopt_error(PRInt32 err)
    251 {
    252     nss_MD_os2_map_default_error(err);
    253 }
    254 
    255 void nss_MD_os2_map_setsockopt_error(PRInt32 err)
    256 {
    257     nss_MD_os2_map_default_error(err);
    258 }
    259 
    260 void nss_MD_os2_map_open_error(PRInt32 err)
    261 {
    262     nss_MD_os2_map_default_error(err);
    263 }
    264 
    265 void nss_MD_os2_map_gethostname_error(PRInt32 err)
    266 {
    267     nss_MD_os2_map_default_error(err);
    268 }
    269 
    270 /* Win32 select() only works on sockets.  So in this
    271 ** context, WSAENOTSOCK is equivalent to EBADF on Unix.
    272 */
    273 void nss_MD_os2_map_select_error(PRInt32 err)
    274 {
    275     PRErrorCode prError;
    276     switch (err) {
    277 //    case WSAENOTSOCK:	prError = PR_BAD_DESCRIPTOR_ERROR; break;
    278     default:		nss_MD_os2_map_default_error(err); return;
    279     }
    280     PR_SetError(prError, err);
    281 }
    282 
    283 void nss_MD_os2_map_lockf_error(PRInt32 err)
    284 {
    285     nss_MD_os2_map_default_error(err);
    286 }
    287 
    288 
    289 
    290 void nss_MD_os2_map_default_error(PRInt32 err)
    291 {
    292     PRErrorCode prError;
    293 
    294     switch (err) {
    295 //    case ENOENT: 		prError = PR_FILE_NOT_FOUND_ERROR; break;
    296 //    case ERROR_ACCESS_DENIED: 	prError = PR_NO_ACCESS_RIGHTS_ERROR; break;
    297 //    case ERROR_ALREADY_EXISTS: 	prError = PR_FILE_EXISTS_ERROR; break;
    298 //    case ERROR_DISK_CORRUPT: 	prError = PR_IO_ERROR; break;
    299 //    case ERROR_DISK_FULL: 	prError = PR_NO_DEVICE_SPACE_ERROR; break;
    300 //    case ERROR_DISK_OPERATION_FAILED: prError = PR_IO_ERROR; break;
    301 //    case ERROR_DRIVE_LOCKED: 	prError = PR_FILE_IS_LOCKED_ERROR; break;
    302 //    case ERROR_FILENAME_EXCED_RANGE: prError = PR_NAME_TOO_LONG_ERROR; break;
    303 //    case ERROR_FILE_CORRUPT: 	prError = PR_IO_ERROR; break;
    304 //    case ERROR_FILE_EXISTS: 	prError = PR_FILE_EXISTS_ERROR; break;
    305 //    case ERROR_FILE_INVALID: 	prError = PR_BAD_DESCRIPTOR_ERROR; break;
    306 #if ERROR_FILE_NOT_FOUND != ENOENT
    307 //    case ERROR_FILE_NOT_FOUND: 	prError = PR_FILE_NOT_FOUND_ERROR; break;
    308 #endif
    309     default: 			prError = PR_UNKNOWN_ERROR; break;
    310     }
    311     PR_SetError(prError, err);
    312 }
    313 
    314