1*ebfedea0SLionel Sambuc /* ====================================================================
2*ebfedea0SLionel Sambuc * Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved.
3*ebfedea0SLionel Sambuc *
4*ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
5*ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
6*ebfedea0SLionel Sambuc * are met:
7*ebfedea0SLionel Sambuc *
8*ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
9*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
10*ebfedea0SLionel Sambuc *
11*ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
12*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in
13*ebfedea0SLionel Sambuc * the documentation and/or other materials provided with the
14*ebfedea0SLionel Sambuc * distribution.
15*ebfedea0SLionel Sambuc *
16*ebfedea0SLionel Sambuc * 3. All advertising materials mentioning features or use of this
17*ebfedea0SLionel Sambuc * software must display the following acknowledgment:
18*ebfedea0SLionel Sambuc * "This product includes software developed by the OpenSSL Project
19*ebfedea0SLionel Sambuc * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20*ebfedea0SLionel Sambuc *
21*ebfedea0SLionel Sambuc * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22*ebfedea0SLionel Sambuc * endorse or promote products derived from this software without
23*ebfedea0SLionel Sambuc * prior written permission. For written permission, please contact
24*ebfedea0SLionel Sambuc * openssl-core@openssl.org.
25*ebfedea0SLionel Sambuc *
26*ebfedea0SLionel Sambuc * 5. Products derived from this software may not be called "OpenSSL"
27*ebfedea0SLionel Sambuc * nor may "OpenSSL" appear in their names without prior written
28*ebfedea0SLionel Sambuc * permission of the OpenSSL Project.
29*ebfedea0SLionel Sambuc *
30*ebfedea0SLionel Sambuc * 6. Redistributions of any form whatsoever must retain the following
31*ebfedea0SLionel Sambuc * acknowledgment:
32*ebfedea0SLionel Sambuc * "This product includes software developed by the OpenSSL Project
33*ebfedea0SLionel Sambuc * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34*ebfedea0SLionel Sambuc *
35*ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36*ebfedea0SLionel Sambuc * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37*ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38*ebfedea0SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39*ebfedea0SLionel Sambuc * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40*ebfedea0SLionel Sambuc * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41*ebfedea0SLionel Sambuc * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42*ebfedea0SLionel Sambuc * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43*ebfedea0SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44*ebfedea0SLionel Sambuc * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45*ebfedea0SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46*ebfedea0SLionel Sambuc * OF THE POSSIBILITY OF SUCH DAMAGE.
47*ebfedea0SLionel Sambuc * ====================================================================
48*ebfedea0SLionel Sambuc *
49*ebfedea0SLionel Sambuc * This product includes cryptographic software written by Eric Young
50*ebfedea0SLionel Sambuc * (eay@cryptsoft.com). This product includes software written by Tim
51*ebfedea0SLionel Sambuc * Hudson (tjh@cryptsoft.com).
52*ebfedea0SLionel Sambuc *
53*ebfedea0SLionel Sambuc */
54*ebfedea0SLionel Sambuc
55*ebfedea0SLionel Sambuc
56*ebfedea0SLionel Sambuc
57*ebfedea0SLionel Sambuc #include "ErrorHandling.hpp"
58*ebfedea0SLionel Sambuc #include "CPStringUtils.hpp"
59*ebfedea0SLionel Sambuc
60*ebfedea0SLionel Sambuc #ifdef __EXCEPTIONS_ENABLED__
61*ebfedea0SLionel Sambuc #include "CMyException.hpp"
62*ebfedea0SLionel Sambuc #endif
63*ebfedea0SLionel Sambuc
64*ebfedea0SLionel Sambuc
65*ebfedea0SLionel Sambuc static char gErrorMessageBuffer[512];
66*ebfedea0SLionel Sambuc
67*ebfedea0SLionel Sambuc char *gErrorMessage = gErrorMessageBuffer;
68*ebfedea0SLionel Sambuc int gErrorMessageMaxLength = sizeof(gErrorMessageBuffer);
69*ebfedea0SLionel Sambuc
70*ebfedea0SLionel Sambuc
71*ebfedea0SLionel Sambuc
SetErrorMessage(const char * theErrorMessage)72*ebfedea0SLionel Sambuc void SetErrorMessage(const char *theErrorMessage)
73*ebfedea0SLionel Sambuc {
74*ebfedea0SLionel Sambuc if (theErrorMessage != nil)
75*ebfedea0SLionel Sambuc {
76*ebfedea0SLionel Sambuc CopyCStrToCStr(theErrorMessage,gErrorMessage,gErrorMessageMaxLength);
77*ebfedea0SLionel Sambuc }
78*ebfedea0SLionel Sambuc }
79*ebfedea0SLionel Sambuc
80*ebfedea0SLionel Sambuc
SetErrorMessageAndAppendLongInt(const char * theErrorMessage,const long theLongInt)81*ebfedea0SLionel Sambuc void SetErrorMessageAndAppendLongInt(const char *theErrorMessage,const long theLongInt)
82*ebfedea0SLionel Sambuc {
83*ebfedea0SLionel Sambuc if (theErrorMessage != nil)
84*ebfedea0SLionel Sambuc {
85*ebfedea0SLionel Sambuc CopyCStrAndConcatLongIntToCStr(theErrorMessage,theLongInt,gErrorMessage,gErrorMessageMaxLength);
86*ebfedea0SLionel Sambuc }
87*ebfedea0SLionel Sambuc }
88*ebfedea0SLionel Sambuc
SetErrorMessageAndCStrAndLongInt(const char * theErrorMessage,const char * theCStr,const long theLongInt)89*ebfedea0SLionel Sambuc void SetErrorMessageAndCStrAndLongInt(const char *theErrorMessage,const char * theCStr,const long theLongInt)
90*ebfedea0SLionel Sambuc {
91*ebfedea0SLionel Sambuc if (theErrorMessage != nil)
92*ebfedea0SLionel Sambuc {
93*ebfedea0SLionel Sambuc CopyCStrAndInsertCStrLongIntIntoCStr(theErrorMessage,theCStr,theLongInt,gErrorMessage,gErrorMessageMaxLength);
94*ebfedea0SLionel Sambuc }
95*ebfedea0SLionel Sambuc
96*ebfedea0SLionel Sambuc }
97*ebfedea0SLionel Sambuc
SetErrorMessageAndCStr(const char * theErrorMessage,const char * theCStr)98*ebfedea0SLionel Sambuc void SetErrorMessageAndCStr(const char *theErrorMessage,const char * theCStr)
99*ebfedea0SLionel Sambuc {
100*ebfedea0SLionel Sambuc if (theErrorMessage != nil)
101*ebfedea0SLionel Sambuc {
102*ebfedea0SLionel Sambuc CopyCStrAndInsertCStrLongIntIntoCStr(theErrorMessage,theCStr,-1,gErrorMessage,gErrorMessageMaxLength);
103*ebfedea0SLionel Sambuc }
104*ebfedea0SLionel Sambuc }
105*ebfedea0SLionel Sambuc
106*ebfedea0SLionel Sambuc
AppendCStrToErrorMessage(const char * theErrorMessage)107*ebfedea0SLionel Sambuc void AppendCStrToErrorMessage(const char *theErrorMessage)
108*ebfedea0SLionel Sambuc {
109*ebfedea0SLionel Sambuc if (theErrorMessage != nil)
110*ebfedea0SLionel Sambuc {
111*ebfedea0SLionel Sambuc ConcatCStrToCStr(theErrorMessage,gErrorMessage,gErrorMessageMaxLength);
112*ebfedea0SLionel Sambuc }
113*ebfedea0SLionel Sambuc }
114*ebfedea0SLionel Sambuc
115*ebfedea0SLionel Sambuc
AppendLongIntToErrorMessage(const long theLongInt)116*ebfedea0SLionel Sambuc void AppendLongIntToErrorMessage(const long theLongInt)
117*ebfedea0SLionel Sambuc {
118*ebfedea0SLionel Sambuc ConcatLongIntToCStr(theLongInt,gErrorMessage,gErrorMessageMaxLength);
119*ebfedea0SLionel Sambuc }
120*ebfedea0SLionel Sambuc
121*ebfedea0SLionel Sambuc
122*ebfedea0SLionel Sambuc
GetErrorMessage(void)123*ebfedea0SLionel Sambuc char *GetErrorMessage(void)
124*ebfedea0SLionel Sambuc {
125*ebfedea0SLionel Sambuc return gErrorMessage;
126*ebfedea0SLionel Sambuc }
127*ebfedea0SLionel Sambuc
128*ebfedea0SLionel Sambuc
GetErrorMessageInNewHandle(Handle * inoutHandle)129*ebfedea0SLionel Sambuc OSErr GetErrorMessageInNewHandle(Handle *inoutHandle)
130*ebfedea0SLionel Sambuc {
131*ebfedea0SLionel Sambuc OSErr errCode;
132*ebfedea0SLionel Sambuc
133*ebfedea0SLionel Sambuc
134*ebfedea0SLionel Sambuc errCode = CopyCStrToNewHandle(gErrorMessage,inoutHandle);
135*ebfedea0SLionel Sambuc
136*ebfedea0SLionel Sambuc return(errCode);
137*ebfedea0SLionel Sambuc }
138*ebfedea0SLionel Sambuc
139*ebfedea0SLionel Sambuc
GetErrorMessageInExistingHandle(Handle inoutHandle)140*ebfedea0SLionel Sambuc OSErr GetErrorMessageInExistingHandle(Handle inoutHandle)
141*ebfedea0SLionel Sambuc {
142*ebfedea0SLionel Sambuc OSErr errCode;
143*ebfedea0SLionel Sambuc
144*ebfedea0SLionel Sambuc
145*ebfedea0SLionel Sambuc errCode = CopyCStrToExistingHandle(gErrorMessage,inoutHandle);
146*ebfedea0SLionel Sambuc
147*ebfedea0SLionel Sambuc return(errCode);
148*ebfedea0SLionel Sambuc }
149*ebfedea0SLionel Sambuc
150*ebfedea0SLionel Sambuc
151*ebfedea0SLionel Sambuc
AppendErrorMessageToHandle(Handle inoutHandle)152*ebfedea0SLionel Sambuc OSErr AppendErrorMessageToHandle(Handle inoutHandle)
153*ebfedea0SLionel Sambuc {
154*ebfedea0SLionel Sambuc OSErr errCode;
155*ebfedea0SLionel Sambuc
156*ebfedea0SLionel Sambuc
157*ebfedea0SLionel Sambuc errCode = AppendCStrToHandle(gErrorMessage,inoutHandle,nil);
158*ebfedea0SLionel Sambuc
159*ebfedea0SLionel Sambuc return(errCode);
160*ebfedea0SLionel Sambuc }
161*ebfedea0SLionel Sambuc
162*ebfedea0SLionel Sambuc
163*ebfedea0SLionel Sambuc #ifdef __EXCEPTIONS_ENABLED__
164*ebfedea0SLionel Sambuc
ThrowErrorMessageException(void)165*ebfedea0SLionel Sambuc void ThrowErrorMessageException(void)
166*ebfedea0SLionel Sambuc {
167*ebfedea0SLionel Sambuc ThrowDescriptiveException(gErrorMessage);
168*ebfedea0SLionel Sambuc }
169*ebfedea0SLionel Sambuc
170*ebfedea0SLionel Sambuc #endif
171