|
Mixe for Privacy and Anonymity in the Internet
|
00001 /* 00002 Copyright (c) 2000, The JAP-Team 00003 All rights reserved. 00004 Redistribution and use in source and binary forms, with or without modification, 00005 are permitted provided that the following conditions are met: 00006 00007 - Redistributions of source code must retain the above copyright notice, 00008 this list of conditions and the following disclaimer. 00009 00010 - Redistributions in binary form must reproduce the above copyright notice, 00011 this list of conditions and the following disclaimer in the documentation and/or 00012 other materials provided with the distribution. 00013 00014 - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 00015 may be used to endorse or promote products derived from this software without specific 00016 prior written permission. 00017 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00021 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 00022 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00025 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00027 */ 00028 #include "StdAfx.h" 00029 #ifdef PAYMENT 00030 #ifndef ONLY_LOCAL_PROXY 00031 #include "CAXMLErrorMessage.hpp" 00032 00033 CAXMLErrorMessage::CAXMLErrorMessage(const UINT32 errorCode, UINT8 * message) 00034 : CAAbstractXMLEncodable() 00035 { 00036 m_iErrorCode = errorCode; 00037 m_strErrMsg = new UINT8[strlen((char *)message)+1]; 00038 strcpy((char *)m_strErrMsg, (char *)message); 00039 m_messageObject = NULL; 00040 } 00041 00042 00043 00044 CAXMLErrorMessage::CAXMLErrorMessage(UINT32 errorCode) 00045 : CAAbstractXMLEncodable() 00046 { 00047 UINT8 *errors[] = { 00048 (UINT8*)"Success", 00049 (UINT8*)"Internal Server Error", 00050 (UINT8*)"Wrong format", 00051 (UINT8*)"Wrong Data", 00052 (UINT8*)"Key not found", 00053 (UINT8*)"Bad Signature", 00054 (UINT8*)"Bad request", 00055 (UINT8*)"You refused to send an account certificate. I will close the connection.", 00056 (UINT8*)"You refused to send a current balance. I will close the connection.", 00057 (UINT8*)"You refused to send a cost confirmation. I will close the connection.", 00058 (UINT8*)"Your account is empty.", 00059 (UINT8*)"Cascade is too long", 00060 (UINT8*)"Database error", 00061 (UINT8*)"Insufficient balance", 00062 (UINT8*)"No flatrate offered", 00063 (UINT8*)"Invalid code", 00064 (UINT8*)"Costconfirmation is not valid, possible attempt at doublespending!", 00065 (UINT8*)"One or more price certificates are invalid!", 00066 (UINT8*)"User is logged in more than once!", 00067 (UINT8*)"No database record for this cost confirmation was found!", 00068 (UINT8*)"Operation may have succeded, but this is not clear!", 00069 (UINT8*)"Account is blocked!" 00070 }; 00071 m_iErrorCode = errorCode; 00072 if (m_iErrorCode < 0 || m_iErrorCode >= 19) 00073 { 00074 UINT8 defaultMsg[] = "Unknown Error"; 00075 m_strErrMsg = new UINT8[strlen((char *)defaultMsg)+1]; 00076 strcpy((char *)m_strErrMsg, (char *)defaultMsg); 00077 } 00078 else 00079 { 00080 m_strErrMsg = new UINT8[strlen((char *)errors[errorCode])+1]; 00081 strcpy((char *)m_strErrMsg, (char *)errors[errorCode]); 00082 } 00083 m_messageObject = NULL; 00084 } 00085 00086 00087 00088 CAXMLErrorMessage::CAXMLErrorMessage(const UINT32 errorCode, UINT8* message, CAAbstractXMLEncodable* messageObject) 00089 { 00090 m_iErrorCode = errorCode; 00091 m_strErrMsg = new UINT8[strlen((char *)message)+1]; 00092 strcpy((char *)m_strErrMsg, (char *)message); 00093 00094 m_messageObject = messageObject; 00095 } 00096 00097 CAXMLErrorMessage::CAXMLErrorMessage(DOMElement* elemRoot) 00098 : CAAbstractXMLEncodable() 00099 { 00100 m_strErrMsg=NULL; 00101 m_messageObject = NULL; 00102 00103 if(elemRoot != NULL) 00104 { 00105 if (setValues(elemRoot) != E_SUCCESS) 00106 { 00107 m_iErrorCode = ERR_NO_ERROR_GIVEN; 00108 } 00109 } 00110 else 00111 { 00112 m_iErrorCode = ERR_NO_ERROR_GIVEN; 00113 } 00114 } 00115 00116 CAXMLErrorMessage::CAXMLErrorMessage(UINT8 * strXmlData) 00117 : CAAbstractXMLEncodable() 00118 { 00119 m_strErrMsg=NULL; 00120 m_messageObject = NULL; 00121 00122 XERCES_CPP_NAMESPACE::DOMDocument* doc = parseDOMDocument(strXmlData,strlen((char*)strXmlData)); 00123 00124 if(doc != NULL) 00125 { 00126 DOMElement* elemRoot = doc->getDocumentElement(); 00127 if (setValues(elemRoot) != E_SUCCESS) 00128 { 00129 m_iErrorCode = ERR_NO_ERROR_GIVEN; 00130 } 00131 if(doc != NULL) 00132 { 00133 doc->release(); 00134 doc = NULL; 00135 } 00136 } 00137 else 00138 { 00139 m_iErrorCode = ERR_NO_ERROR_GIVEN; 00140 } 00141 } 00142 00143 00144 SINT32 CAXMLErrorMessage::setValues(DOMElement* elemRoot) 00145 { 00146 UINT8 strGeneral[256]; 00147 UINT32 strGeneralLen = 256; 00148 00149 SINT32 tmp; 00150 SINT32 rc; 00151 00152 if( ((rc=getDOMElementAttribute(elemRoot, "code", &tmp)) !=E_SUCCESS) || 00153 ((rc=getDOMElementValue(elemRoot, strGeneral, &strGeneralLen)) !=E_SUCCESS) 00154 ) 00155 { 00156 UINT8 buff[8192]; 00157 UINT32 len=8192; 00158 DOM_Output::dumpToMem(elemRoot,buff,&len); 00159 CAMsg::printMsg(LOG_DEBUG,(char*)buff); 00160 00161 return rc; 00162 } 00163 00164 m_iErrorCode = (UINT32)tmp; 00165 delete [] m_strErrMsg; 00166 m_strErrMsg = NULL; 00167 m_strErrMsg = new UINT8[strGeneralLen+1]; 00168 strcpy((char*)m_strErrMsg, (char*)strGeneral); 00169 00170 /*if((rc=getDOMElementAttribute(elemRoot, "expires", (UINT8*) strExp, &strExpLen)) ==E_SUCCESS) 00171 { 00172 if(m_strExpires != NULL) 00173 { 00174 strncpy(m_strExpires, strExp, 10); 00175 } 00176 }*/ 00177 DOMElement* objectRootElem=NULL; 00178 getDOMChildByName(elemRoot, "MessageObject", objectRootElem, false); 00179 00180 //due to lack of RTTI, we need to hardcode how to deal with each specific object type 00181 if (ERR_OUTDATED_CC == m_iErrorCode) 00182 { 00183 DOMElement* ccElem=NULL; 00184 if (getDOMChildByName(objectRootElem,"CC",ccElem,true) == E_SUCCESS) 00185 { 00186 m_messageObject = CAXMLCostConfirmation::getInstance(ccElem); 00187 } 00188 } 00189 else if (ERR_ACCOUNT_EMPTY == m_iErrorCode) 00190 { 00191 if (objectRootElem != NULL) 00192 { 00193 CAMsg::printMsg(LOG_INFO, "XMLErrorMessage: appended object found...\n"); 00194 UINT8* buff = DOM_Output::dumpToString(objectRootElem, true); 00195 CAMsg::printMsg(LOG_DEBUG,(char*)buff); 00196 delete[] buff; 00197 } 00198 DOMElement* confirmedElem=NULL; 00199 if (getDOMChildByName(objectRootElem,"GenericText",confirmedElem,true) == E_SUCCESS) 00200 { 00201 m_messageObject = new UINT64; 00202 if(getDOMElementValue(confirmedElem, (*(UINT64*)m_messageObject)) != E_SUCCESS) 00203 { 00204 delete (UINT64*)m_messageObject; 00205 m_messageObject = NULL; 00206 } 00207 } 00208 } 00209 else 00210 { 00211 m_messageObject = NULL; 00212 } 00213 //add code to parse other types of objects here when adding new error codes with corresponding objects 00214 00215 return E_SUCCESS; 00216 } 00217 00218 00219 CAXMLErrorMessage::~CAXMLErrorMessage() 00220 { 00221 if(m_strErrMsg) 00222 { 00223 delete [] m_strErrMsg; 00224 m_strErrMsg = NULL; 00225 } 00226 if (m_messageObject != NULL) 00227 { 00228 delete m_messageObject; 00229 m_messageObject = NULL; 00230 } 00231 } 00232 00233 00234 SINT32 CAXMLErrorMessage::toXmlElement(XERCES_CPP_NAMESPACE::DOMDocument* a_doc, DOMElement* & elemRoot) 00235 { 00236 elemRoot = createDOMElement(a_doc, XML_ELEMENT_ERROR_MSG); 00237 setDOMElementAttribute(elemRoot, "code", m_iErrorCode); 00238 /*if(m_strExpires != NULL) 00239 { 00240 if(m_strExpires[0] != 0) 00241 { 00242 setDOMElementAttribute(elemRoot, "expires", (UINT8*)m_strExpires); 00243 } 00244 }*/ 00245 setDOMElementValue(elemRoot, m_strErrMsg); 00246 00247 if (m_messageObject) 00248 { 00249 DOMElement* objectRoot = createDOMElement(a_doc,"MessageObject"); 00250 DOMElement* objectElem=NULL; 00251 //WARNING: this will fail for CAXMLCostConfirmation!!! (since it is not a subclass of CAAbstractXMLEncodable) 00252 CAAbstractXMLEncodable* encodableObject = (CAAbstractXMLEncodable*) m_messageObject; 00253 encodableObject->toXmlElement(a_doc,objectElem); 00254 objectRoot->appendChild(objectElem); 00255 elemRoot->appendChild(objectRoot); 00256 } 00257 00258 return E_SUCCESS; 00259 } 00260 #endif //ONLY_LOCAL_PROXY 00261 #endif //PAYMENT
1.7.6.1