1 /*
2 * Function to set error code only when meaningful error has not already
3 * been set.
4 *
5 * ***** BEGIN LICENSE BLOCK *****
6 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 *
8 * The contents of this file are subject to the Mozilla Public License Version
9 * 1.1 (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
12 *
13 * Software distributed under the License is distributed on an "AS IS" basis,
14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15 * for the specific language governing rights and limitations under the
16 * License.
17 *
18 * The Original Code is the Netscape security libraries.
19 *
20 * The Initial Developer of the Original Code is
21 * Netscape Communications Corporation.
22 * Portions created by the Initial Developer are Copyright (C) 1994-2000
23 * the Initial Developer. All Rights Reserved.
24 *
25 * Contributor(s):
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40 /* $Id: sslerr.c,v 1.4 2004/04/27 23:04:39 gerv%gerv.net Exp $ */
41
42 #include "prerror.h"
43 #include "secerr.h"
44 #include "sslerr.h"
45 #include "seccomon.h"
46
47 /* look at the current value of PR_GetError, and evaluate it to see
48 * if it is meaningful or meaningless (out of context).
49 * If it is meaningless, replace it with the hiLevelError.
50 * Returns the chosen error value.
51 */
52 int
ssl_MapLowLevelError(int hiLevelError)53 ssl_MapLowLevelError(int hiLevelError)
54 {
55 int oldErr = PORT_GetError();
56
57 switch (oldErr) {
58
59 case 0:
60 case PR_IO_ERROR:
61 case SEC_ERROR_IO:
62 case SEC_ERROR_BAD_DATA:
63 case SEC_ERROR_LIBRARY_FAILURE:
64 case SEC_ERROR_EXTENSION_NOT_FOUND:
65 case SSL_ERROR_BAD_CLIENT:
66 case SSL_ERROR_BAD_SERVER:
67 case SSL_ERROR_SESSION_NOT_FOUND:
68 PORT_SetError(hiLevelError);
69 return hiLevelError;
70
71 default: /* leave the majority of error codes alone. */
72 return oldErr;
73 }
74 }
75