|
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 "CAXMLCostConfirmation.hpp" 00032 #include "CAUtil.hpp" 00033 #include "CAMsg.hpp" 00034 #include "CAPriceInfo.hpp" 00035 00036 const char* const CAXMLCostConfirmation::ms_pStrElemName="CC"; 00037 00038 CAXMLCostConfirmation::CAXMLCostConfirmation() 00039 { 00040 m_domDocument = NULL; 00041 m_pStrPIID = NULL; 00042 m_priceCerts = NULL; 00043 00044 } 00045 00046 CAXMLCostConfirmation* CAXMLCostConfirmation::getInstance(UINT8 * strXmlData,UINT32 strXmlDataLen) 00047 { 00048 // parse XML 00049 if(strXmlData==NULL) 00050 return NULL; 00051 CAXMLCostConfirmation* pCC=new CAXMLCostConfirmation(); 00052 pCC->m_domDocument = parseDOMDocument(strXmlData, strXmlDataLen); 00053 if(pCC->setValues()!=E_SUCCESS) 00054 { 00055 delete pCC; 00056 pCC = NULL; 00057 } 00058 return pCC; 00059 } 00060 00061 CAXMLCostConfirmation* CAXMLCostConfirmation::getInstance(DOMElement* elemRoot) 00062 { 00063 if(elemRoot==NULL) 00064 return NULL; 00065 CAXMLCostConfirmation* pCC=new CAXMLCostConfirmation(); 00066 pCC->m_domDocument=createDOMDocument(); 00067 pCC->m_domDocument->appendChild(pCC->m_domDocument->importNode(elemRoot,true)); 00068 if(pCC->setValues()!=E_SUCCESS) 00069 { 00070 delete pCC; 00071 pCC = NULL; 00072 } 00073 return pCC; 00074 } 00075 00076 00077 00078 CAXMLCostConfirmation::~CAXMLCostConfirmation() 00079 { 00080 00081 delete[] m_pStrPIID; 00082 m_pStrPIID = NULL; 00083 00084 00085 if (m_priceCerts != NULL) 00086 { 00087 for (UINT32 i = 0; i < m_priceCertsLen; i++) 00088 { 00089 if (m_priceCerts[i]) 00090 { 00091 delete m_priceCerts[i]; 00092 m_priceCerts[i] = NULL; 00093 } 00094 } 00095 delete[] m_priceCerts; 00096 m_priceCerts = NULL; 00097 } 00098 if(m_domDocument != NULL) 00099 { 00100 m_domDocument->release(); 00101 m_domDocument=NULL; 00102 } 00103 } 00104 00105 00106 SINT32 CAXMLCostConfirmation::setValues() 00107 { 00108 if(m_domDocument==NULL) 00109 return E_UNKNOWN; 00110 DOMElement* elemRoot=m_domDocument->getDocumentElement(); 00111 if (elemRoot == NULL) 00112 { 00113 return E_UNKNOWN; 00114 } 00115 00116 DOMElement* elem=NULL; 00117 00118 00119 if( !equals(elemRoot->getTagName(),ms_pStrElemName) ) 00120 { 00121 return E_UNKNOWN; 00122 } 00123 00124 // parse accountnumber 00125 getDOMChildByName(elemRoot, "AccountNumber", elem, false); 00126 if(getDOMElementValue(elem, m_lAccountNumber)!=E_SUCCESS) 00127 return E_UNKNOWN; 00128 00129 // parse transferredBytes 00130 getDOMChildByName(elemRoot, "TransferredBytes", elem, false); 00131 if(getDOMElementValue(elem, m_lTransferredBytes)!=E_SUCCESS) 00132 return E_UNKNOWN; 00133 00134 // parse PIID 00135 delete[] m_pStrPIID; 00136 m_pStrPIID=NULL; 00137 UINT8 strGeneral[256]; 00138 UINT32 strGeneralLen = 256; 00139 strGeneralLen=255; 00140 getDOMChildByName(elemRoot, "PIID", elem, false); 00141 if(getDOMElementValue(elem, strGeneral, &strGeneralLen)==E_SUCCESS) 00142 { 00143 m_pStrPIID = new UINT8[strGeneralLen+1]; 00144 memcpy(m_pStrPIID, strGeneral,strGeneralLen+1); 00145 } 00146 else 00147 { 00148 return E_UNKNOWN; 00149 } 00150 00151 00161 //CAMsg::printMsg(LOG_DEBUG, "Parsing PriceCertificates\n"); 00162 00163 //parse PriceCertHash elements 00164 //currently does not check syntax, e.g. whether <PriceCertHash> is within <PriceCertificates> 00165 if (getDOMChildByName(elemRoot, "PriceCertificates", elem, false) != E_SUCCESS) 00166 { 00167 return E_UNKNOWN; 00168 } 00169 00170 //CAMsg::printMsg(LOG_DEBUG, "Looking for PriceCertHash\n"); 00171 00172 // one last test if the tag is really in the right XML layer; throw away elemRoot here... 00173 if (getDOMChildByName(elem, "PriceCertHash", elemRoot, false) != E_SUCCESS) 00174 { 00175 return E_UNKNOWN; 00176 } 00177 00178 //CAMsg::printMsg(LOG_DEBUG, "Parsing PriceCertHash\n"); 00179 00180 DOMNodeList* theNodes = getElementsByTagName(elem,"PriceCertHash"); 00181 if (theNodes->getLength() <= 0) 00182 { 00183 return E_UNKNOWN; 00184 } 00185 00186 //determine size and build array 00187 m_priceCertsLen = theNodes->getLength(); 00188 m_priceCerts = new CAPriceInfo*[m_priceCertsLen]; 00189 00190 //loop through nodes 00191 const DOMNode* curNode=NULL; 00192 UINT8* curId; 00193 UINT8* curHash; 00194 UINT32 len; 00195 SINT32 curPosition; 00196 00197 for (UINT32 i = 0; i < m_priceCertsLen; i++ ) 00198 { 00199 m_priceCerts[i] = NULL; 00200 } 00201 00202 for (UINT32 i = 0; i < m_priceCertsLen; i++ ) 00203 { 00204 //get single node 00205 curNode = theNodes->item(i); 00206 00207 00208 //CAMsg::printMsg(LOG_DEBUG, "Parsing id\n"); 00209 00210 //extract strings for mixid and pricecerthash, and check isAI attribute 00211 curId = new UINT8[100]; 00212 len = 100; 00213 if (getDOMElementAttribute(curNode, "id", curId, &len) != E_SUCCESS) 00214 { 00215 delete[] curId; 00216 curId = NULL; 00217 return E_UNKNOWN; 00218 } 00219 00220 00221 //CAMsg::printMsg(LOG_DEBUG, "Parsing hash\n"); 00222 curHash = new UINT8[100]; 00223 len = 100; 00224 if (getDOMElementValue(curNode, curHash, &len) != E_SUCCESS) 00225 { 00226 delete[] curId; 00227 curId = NULL; 00228 delete[] curHash; 00229 curHash = NULL; 00230 return E_UNKNOWN; 00231 } 00232 00233 //CAMsg::printMsg(LOG_DEBUG, "Parsing position\n"); 00234 if (getDOMElementAttribute(curNode, "position", &curPosition) != E_SUCCESS) 00235 { 00236 curPosition = -1; 00237 } 00238 00239 //CAMsg::printMsg(LOG_DEBUG, "Adding cert info\n"); 00240 m_priceCerts[i] = new CAPriceInfo(curId, curHash, curPosition); 00241 } 00242 00243 00244 00245 return E_SUCCESS; 00246 } 00247 #endif //ONLY_LOCAL_PROXY 00248 #endif //PAYMENT
1.7.6.1