xref: /AOO41X/main/xmlsecurity/source/xmlsec/errorcallback.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir /*
32*cdf0e10cSrcweir  * Implementation of the I/O interfaces based on stream and URI binding
33*cdf0e10cSrcweir  */
34*cdf0e10cSrcweir #include "errorcallback.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <sal/types.h>
37*cdf0e10cSrcweir //For reasons that escape me, this is what xmlsec does when size_t is not 4
38*cdf0e10cSrcweir #if SAL_TYPES_SIZEOFPOINTER != 4
39*cdf0e10cSrcweir #    define XMLSEC_NO_SIZE_T
40*cdf0e10cSrcweir #endif
41*cdf0e10cSrcweir #include "xmlsec/xmlsec.h"
42*cdf0e10cSrcweir #include "xmlsec/errors.h"
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir using namespace ::com::sun::star::xml::crypto;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir // ::com::sun::star::uno::Reference< XXMLSecurityTemplate > g_xErrorRecorder;
47*cdf0e10cSrcweir // bool g_bErrorRecorded;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir // SecurityOperationStatus getOperationStatus(int reason)
50*cdf0e10cSrcweir // {
51*cdf0e10cSrcweir // 	switch (reason)
52*cdf0e10cSrcweir // 	{
53*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_XMLSEC_FAILED:
54*cdf0e10cSrcweir // 		return SecurityOperationStatus_ENGINE_FAILED;
55*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_MALLOC_FAILED:
56*cdf0e10cSrcweir // 		return SecurityOperationStatus_MALLOC_FAILED;
57*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_STRDUP_FAILED:
58*cdf0e10cSrcweir // 		return SecurityOperationStatus_STRDUP_FAILED;
59*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_CRYPTO_FAILED:
60*cdf0e10cSrcweir // 		return SecurityOperationStatus_CRYPTO_FAILED;
61*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_XML_FAILED:
62*cdf0e10cSrcweir // 		return SecurityOperationStatus_XML_FAILED;
63*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_XSLT_FAILED:
64*cdf0e10cSrcweir // 		return SecurityOperationStatus_XSLT_FAILED;
65*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_IO_FAILED:
66*cdf0e10cSrcweir // 		return SecurityOperationStatus_IO_FAILED;
67*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_DISABLED:
68*cdf0e10cSrcweir // 		return SecurityOperationStatus_DISABLED;
69*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_NOT_IMPLEMENTED:
70*cdf0e10cSrcweir // 		return SecurityOperationStatus_NOT_IMPLEMENTED;
71*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_SIZE:
72*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_SIZE;
73*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_DATA:
74*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_DATA;
75*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_RESULT:
76*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_RESULT;
77*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_TYPE:
78*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_TYPE;
79*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_OPERATION:
80*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_OPERATION;
81*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_STATUS:
82*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_STATUS;
83*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_FORMAT:
84*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_FORMAT;
85*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_DATA_NOT_MATCH:
86*cdf0e10cSrcweir // 		return SecurityOperationStatus_DATA_NOT_MATCH;
87*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_NODE:
88*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_NODE;
89*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_NODE_CONTENT:
90*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_NODE_CONTENT;
91*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE:
92*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_NODE_ATTRIBUTE;
93*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_MISSING_NODE_ATTRIBUTE:
94*cdf0e10cSrcweir // 		return SecurityOperationStatus_MISSING_NODE_ATTRIBUTE;
95*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT:
96*cdf0e10cSrcweir // 		return SecurityOperationStatus_NODE_ALREADY_PRESENT;
97*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_UNEXPECTED_NODE:
98*cdf0e10cSrcweir // 		return SecurityOperationStatus_UNEXPECTED_NODE;
99*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_NODE_NOT_FOUND:
100*cdf0e10cSrcweir // 		return SecurityOperationStatus_NODE_NOT_FOUND;
101*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_TRANSFORM:
102*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_TRANSFORM;
103*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_TRANSFORM_KEY:
104*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_TRANSFORM_KEY;
105*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_URI_TYPE:
106*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_URI_TYPE;
107*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_TRANSFORM_SAME_DOCUMENT_REQUIRED:
108*cdf0e10cSrcweir // 		return SecurityOperationStatus_TRANSFORM_SAME_DOCUMENT_REQUIRED;
109*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_TRANSFORM_DISABLED:
110*cdf0e10cSrcweir // 		return SecurityOperationStatus_TRANSFORM_DISABLED;
111*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_KEY_DATA:
112*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_KEY_DATA;
113*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_KEY_DATA_NOT_FOUND:
114*cdf0e10cSrcweir // 		return SecurityOperationStatus_KEY_DATA_NOT_FOUND;
115*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_KEY_DATA_ALREADY_EXIST:
116*cdf0e10cSrcweir // 		return SecurityOperationStatus_KEY_DATA_ALREADY_EXIST;
117*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE:
118*cdf0e10cSrcweir // 		return SecurityOperationStatus_INVALID_KEY_DATA_SIZE;
119*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_KEY_NOT_FOUND:
120*cdf0e10cSrcweir // 		return SecurityOperationStatus_KEY_NOT_FOUND;
121*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_KEYDATA_DISABLED:
122*cdf0e10cSrcweir // 		return SecurityOperationStatus_KEYDATA_DISABLED;
123*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_MAX_RETRIEVALS_LEVEL:
124*cdf0e10cSrcweir // 		return SecurityOperationStatus_MAX_RETRIEVALS_LEVEL;
125*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_MAX_RETRIEVAL_TYPE_MISMATCH:
126*cdf0e10cSrcweir // 		return SecurityOperationStatus_MAX_RETRIEVAL_TYPE_MISMATCH;
127*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_MAX_ENCKEY_LEVEL:
128*cdf0e10cSrcweir // 		return SecurityOperationStatus_MAX_ENCKEY_LEVEL;
129*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_CERT_VERIFY_FAILED:
130*cdf0e10cSrcweir // 		return SecurityOperationStatus_CERT_VERIFY_FAILED;
131*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_CERT_NOT_FOUND:
132*cdf0e10cSrcweir // 		return SecurityOperationStatus_CERT_NOT_FOUND;
133*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_CERT_REVOKED:
134*cdf0e10cSrcweir // 		return SecurityOperationStatus_CERT_REVOKED;
135*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_CERT_ISSUER_FAILED:
136*cdf0e10cSrcweir // 		return SecurityOperationStatus_CERT_ISSUER_FAILED;
137*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_CERT_NOT_YET_VALID:
138*cdf0e10cSrcweir // 		return SecurityOperationStatus_CERT_NOT_YET_VALID;
139*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_CERT_HAS_EXPIRED:
140*cdf0e10cSrcweir // 		return SecurityOperationStatus_CERT_HAS_EXPIRED;
141*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_DSIG_NO_REFERENCES:
142*cdf0e10cSrcweir // 		return SecurityOperationStatus_DSIG_NO_REFERENCES;
143*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_DSIG_INVALID_REFERENCE:
144*cdf0e10cSrcweir // 		return SecurityOperationStatus_DSIG_INVALID_REFERENCE;
145*cdf0e10cSrcweir // 	case XMLSEC_ERRORS_R_ASSERTION:
146*cdf0e10cSrcweir // 		return SecurityOperationStatus_ASSERTION;
147*cdf0e10cSrcweir // 	default:
148*cdf0e10cSrcweir // 		return SecurityOperationStatus_RUNTIMEERROR_FAILED;
149*cdf0e10cSrcweir // 	}
150*cdf0e10cSrcweir // }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir extern "C"
154*cdf0e10cSrcweir void errorCallback(const char * /*file*/,
155*cdf0e10cSrcweir                    int /*line*/,
156*cdf0e10cSrcweir                    const char * /*func*/,
157*cdf0e10cSrcweir                    const char * /*errorObject*/,
158*cdf0e10cSrcweir                    const char * /*errorSubject*/,
159*cdf0e10cSrcweir                    int /*reason*/,
160*cdf0e10cSrcweir                    const char  * /*msg*/)
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
163*cdf0e10cSrcweir //     const char * afunc = func ? func : "";
164*cdf0e10cSrcweir //     const char * errObj = errorObject ? errorObject : "";
165*cdf0e10cSrcweir //     const char * errSub = errorSubject ? errorSubject : "";
166*cdf0e10cSrcweir //     const char * amsg = msg ? msg : "";
167*cdf0e10cSrcweir // 	fprintf(stdout, "xmlsec error: %s, %s,  %s, %i %s  \n", afunc, errObj, errSub, reason, amsg);
168*cdf0e10cSrcweir #endif
169*cdf0e10cSrcweir     //ToDo write log message
170*cdf0e10cSrcweir // 	if (g_xErrorRecorder.is() && !g_bErrorRecorded)
171*cdf0e10cSrcweir // 	{
172*cdf0e10cSrcweir // 		g_xErrorRecorder->setStatus(getOperationStatus(reason));
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir // 		if ( reason != XMLSEC_ERRORS_R_ASSERTION && reason!=XMLSEC_ERRORS_R_XMLSEC_FAILED)
175*cdf0e10cSrcweir // 		{
176*cdf0e10cSrcweir //             g_bErrorRecorded = true;
177*cdf0e10cSrcweir // 		}
178*cdf0e10cSrcweir // 	}
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir // void setErrorRecorder(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSecurityTemplate >& xTemplate)
182*cdf0e10cSrcweir // {
183*cdf0e10cSrcweir // 	g_xErrorRecorder = xTemplate;
184*cdf0e10cSrcweir // 	g_xErrorRecorder->setStatus(SecurityOperationStatus_OPERATION_SUCCEEDED);
185*cdf0e10cSrcweir // 	g_bErrorRecorded = false;
186*cdf0e10cSrcweir // 	xmlSecErrorsSetCallback(errorCallback);
187*cdf0e10cSrcweir // }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir //void setErrorRecorder(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSignatureTemplate >& xTemplate)
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir void setErrorRecorder()
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir // 	::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSecurityTemplate >
194*cdf0e10cSrcweir // 		xSecurityTemplate(xTemplate, ::com::sun::star::uno::UNO_QUERY);
195*cdf0e10cSrcweir // 	setErrorRecorder( xSecurityTemplate );
196*cdf0e10cSrcweir     xmlSecErrorsSetCallback(errorCallback);
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir // void setErrorRecorder(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLEncryptionTemplate >& xTemplate)
200*cdf0e10cSrcweir // {
201*cdf0e10cSrcweir // 	::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSecurityTemplate >
202*cdf0e10cSrcweir // 		xSecurityTemplate(xTemplate, ::com::sun::star::uno::UNO_QUERY);
203*cdf0e10cSrcweir // 	setErrorRecorder( xSecurityTemplate );
204*cdf0e10cSrcweir // }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir void clearErrorRecorder()
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir 	xmlSecErrorsSetCallback(NULL);
209*cdf0e10cSrcweir //	g_xErrorRecorder = NULL;
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212