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