Mixe for Privacy and Anonymity in the Internet
CAXMLCostConfirmation.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #include "StdAfx.h"
29 #ifdef PAYMENT
30 #ifndef ONLY_LOCAL_PROXY
32 #include "CAUtil.hpp"
33 #include "CAMsg.hpp"
34 #include "CAPriceInfo.hpp"
35 
36 const char* const CAXMLCostConfirmation::ms_pStrElemName="CC";
37 
38 CAXMLCostConfirmation::CAXMLCostConfirmation()
39  {
40  m_domDocument = NULL;
41  m_pStrPIID = NULL;
42  m_priceCerts = NULL;
43 
44  }
45 
46 CAXMLCostConfirmation* CAXMLCostConfirmation::getInstance(UINT8 * strXmlData,UINT32 strXmlDataLen)
47  {
48  // parse XML
49  if(strXmlData==NULL)
50  return NULL;
51  CAXMLCostConfirmation* pCC=new CAXMLCostConfirmation();
52  pCC->m_domDocument = parseDOMDocument(strXmlData, strXmlDataLen);
53  if(pCC->setValues()!=E_SUCCESS)
54  {
55  delete pCC;
56  pCC = NULL;
57  }
58  return pCC;
59  }
60 
61 CAXMLCostConfirmation* CAXMLCostConfirmation::getInstance(DOMElement* elemRoot)
62  {
63  if(elemRoot==NULL)
64  return NULL;
65  CAXMLCostConfirmation* pCC=new CAXMLCostConfirmation();
66  pCC->m_domDocument=createDOMDocument();
67  pCC->m_domDocument->appendChild(pCC->m_domDocument->importNode(elemRoot,true));
68  if(pCC->setValues()!=E_SUCCESS)
69  {
70  delete pCC;
71  pCC = NULL;
72  }
73  return pCC;
74  }
75 
76 
77 
78 CAXMLCostConfirmation::~CAXMLCostConfirmation()
79  {
80 
81  delete[] m_pStrPIID;
82  m_pStrPIID = NULL;
83 
84 
85  if (m_priceCerts != NULL)
86  {
87  for (UINT32 i = 0; i < m_priceCertsLen; i++)
88  {
89  if (m_priceCerts[i])
90  {
91  delete m_priceCerts[i];
92  m_priceCerts[i] = NULL;
93  }
94  }
95  delete[] m_priceCerts;
96  m_priceCerts = NULL;
97  }
98  if(m_domDocument != NULL)
99  {
100  m_domDocument->release();
101  m_domDocument=NULL;
102  }
103  }
104 
105 
106 SINT32 CAXMLCostConfirmation::setValues()
107  {
108  if(m_domDocument==NULL)
109  return E_UNKNOWN;
110  DOMElement* elemRoot=m_domDocument->getDocumentElement();
111  if (elemRoot == NULL)
112  {
113  return E_UNKNOWN;
114  }
115 
116  DOMElement* elem=NULL;
117 
118 
119  if( !equals(elemRoot->getTagName(),ms_pStrElemName) )
120  {
121  return E_UNKNOWN;
122  }
123 
124  // parse accountnumber
125  getDOMChildByName(elemRoot, "AccountNumber", elem, false);
126  if(getDOMElementValue(elem, m_lAccountNumber)!=E_SUCCESS)
127  return E_UNKNOWN;
128 
129  // parse transferredBytes
130  getDOMChildByName(elemRoot, "TransferredBytes", elem, false);
131  if(getDOMElementValue(elem, m_lTransferredBytes)!=E_SUCCESS)
132  return E_UNKNOWN;
133 
134  // parse PIID
135  delete[] m_pStrPIID;
136  m_pStrPIID=NULL;
137  UINT8 strGeneral[256];
138  UINT32 strGeneralLen = 256;
139  strGeneralLen=255;
140  getDOMChildByName(elemRoot, "PIID", elem, false);
141  if(getDOMElementValue(elem, strGeneral, &strGeneralLen)==E_SUCCESS)
142  {
143  m_pStrPIID = new UINT8[strGeneralLen+1];
144  memcpy(m_pStrPIID, strGeneral,strGeneralLen+1);
145  }
146  else
147  {
148  return E_UNKNOWN;
149  }
150 
151 
161  //CAMsg::printMsg(LOG_DEBUG, "Parsing PriceCertificates\n");
162 
163  //parse PriceCertHash elements
164  //currently does not check syntax, e.g. whether <PriceCertHash> is within <PriceCertificates>
165  if (getDOMChildByName(elemRoot, "PriceCertificates", elem, false) != E_SUCCESS)
166  {
167  return E_UNKNOWN;
168  }
169 
170  //CAMsg::printMsg(LOG_DEBUG, "Looking for PriceCertHash\n");
171 
172  // one last test if the tag is really in the right XML layer; throw away elemRoot here...
173  if (getDOMChildByName(elem, "PriceCertHash", elemRoot, false) != E_SUCCESS)
174  {
175  return E_UNKNOWN;
176  }
177 
178  //CAMsg::printMsg(LOG_DEBUG, "Parsing PriceCertHash\n");
179 
180  DOMNodeList* theNodes = getElementsByTagName(elem,"PriceCertHash");
181  if (theNodes->getLength() <= 0)
182  {
183  return E_UNKNOWN;
184  }
185 
186  //determine size and build array
187  m_priceCertsLen = theNodes->getLength();
188  m_priceCerts = new CAPriceInfo*[m_priceCertsLen];
189 
190  //loop through nodes
191  const DOMNode* curNode=NULL;
192  UINT8* curId;
193  UINT8* curHash;
194  UINT32 len;
195  SINT32 curPosition;
196 
197  for (UINT32 i = 0; i < m_priceCertsLen; i++ )
198  {
199  m_priceCerts[i] = NULL;
200  }
201 
202  for (UINT32 i = 0; i < m_priceCertsLen; i++ )
203  {
204  //get single node
205  curNode = theNodes->item(i);
206 
207 
208  //CAMsg::printMsg(LOG_DEBUG, "Parsing id\n");
209 
210  //extract strings for mixid and pricecerthash, and check isAI attribute
211  curId = new UINT8[100];
212  len = 100;
213  if (getDOMElementAttribute(curNode, "id", curId, &len) != E_SUCCESS)
214  {
215  delete[] curId;
216  curId = NULL;
217  return E_UNKNOWN;
218  }
219 
220 
221  //CAMsg::printMsg(LOG_DEBUG, "Parsing hash\n");
222  curHash = new UINT8[100];
223  len = 100;
224  if (getDOMElementValue(curNode, curHash, &len) != E_SUCCESS)
225  {
226  delete[] curId;
227  curId = NULL;
228  delete[] curHash;
229  curHash = NULL;
230  return E_UNKNOWN;
231  }
232 
233  //CAMsg::printMsg(LOG_DEBUG, "Parsing position\n");
234  if (getDOMElementAttribute(curNode, "position", &curPosition) != E_SUCCESS)
235  {
236  curPosition = -1;
237  }
238 
239  //CAMsg::printMsg(LOG_DEBUG, "Adding cert info\n");
240  m_priceCerts[i] = new CAPriceInfo(curId, curHash, curPosition);
241  }
242 
243 
244 
245  return E_SUCCESS;
246  }
247 #endif //ONLY_LOCAL_PROXY
248 #endif //PAYMENT
SINT32 getDOMElementValue(const DOMNode *const pElem, UINT8 *value, UINT32 *valuelen)
Returns the content of the text node(s) under elem as null-terminated C String.
Definition: CAUtil.cpp:746
bool equals(const XMLCh *const e1, const char *const e2)
Definition: CAUtil.cpp:645
XERCES_CPP_NAMESPACE::DOMDocument * parseDOMDocument(const UINT8 *const buff, UINT32 len)
Parses a buffer containing an XML document and returns this document.
Definition: CAUtil.cpp:663
DOMNodeList * getElementsByTagName(DOMElement *pElem, const char *const name)
Definition: CAUtil.cpp:1711
XERCES_CPP_NAMESPACE::DOMDocument * createDOMDocument()
Parses a timestamp in JDBC timestamp escape format (as it comes from the BI) and outputs the value in...
Definition: CAUtil.cpp:1568
SINT32 getDOMChildByName(const DOMNode *pNode, const char *const name, DOMElement *&child, bool deep)
Definition: CAUtil.cpp:458
SINT32 getDOMElementAttribute(const DOMNode *const elem, const char *attrName, UINT8 *value, UINT32 *len)
Definition: CAUtil.cpp:780
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3
UINT16 len
Definition: typedefs.hpp:0