Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
CAXMLErrorMessage Class Reference

This class encapsulates an error or success message. More...

#include <CAXMLErrorMessage.hpp>

Inheritance diagram for CAXMLErrorMessage:
Collaboration diagram for CAXMLErrorMessage:

Public Member Functions

 CAXMLErrorMessage (const UINT32 errorCode, UINT8 *message)
 Creates an errorMessage object. More...
 
 CAXMLErrorMessage (UINT32 errorCode)
 Uses a default description String. More...
 
 CAXMLErrorMessage (const UINT32 errorCode, UINT8 *message, CAAbstractXMLEncodable *messageObject)
 attaches an object to the error message More...
 
 CAXMLErrorMessage (UINT8 *strXmlData)
 Parses the string XML representation. More...
 
 CAXMLErrorMessage (DOMElement *elemRoot)
 
 ~CAXMLErrorMessage ()
 
SINT32 toXmlElement (XERCES_CPP_NAMESPACE::DOMDocument *a_doc, DOMElement *&elemRoot)
 Creates the XML structure inside an existing DOM_Document, but does not append it to any node. More...
 
UINT32 getErrorCode ()
 
UINT8getDescription ()
 
void * getMessageObject ()
 
- Public Member Functions inherited from CAAbstractXMLEncodable
 CAAbstractXMLEncodable ()
 
virtual ~CAAbstractXMLEncodable ()
 pure virtual destructor. More...
 
SINT32 toXmlDocument (XERCES_CPP_NAMESPACE::DOMDocument *&pDoc)
 returns a pointer to the tagname of this XML structure's top level element. More...
 
UINT8toXmlString (UINT32 *pSize)
 Converts the XML structure to a null-terminated C-String representation. More...
 

Static Public Attributes

static const UINT32 ERR_OK = 0
 
static const UINT32 ERR_INTERNAL_SERVER_ERROR = 1
 
static const UINT32 ERR_WRONG_FORMAT = 2
 
static const UINT32 ERR_WRONG_DATA = 3
 
static const UINT32 ERR_KEY_NOT_FOUND = 4
 
static const UINT32 ERR_BAD_SIGNATURE = 5
 
static const UINT32 ERR_BAD_REQUEST = 6
 
static const UINT32 ERR_NO_ACCOUNTCERT = 7
 
static const UINT32 ERR_NO_BALANCE = 8
 
static const UINT32 ERR_NO_CONFIRMATION = 9
 
static const UINT32 ERR_ACCOUNT_EMPTY = 10
 
static const UINT32 ERR_CASCADE_LENGTH = 11
 
static const UINT32 ERR_DATABASE_ERROR = 12
 
static const UINT32 ERR_INSUFFICIENT_BALANCE = 13
 
static const UINT32 ERR_NO_FLATRATE_OFFERED = 14
 
static const UINT32 ERR_INVALID_CODE = 15
 
static const UINT32 ERR_OUTDATED_CC = 16
 
static const UINT32 ERR_INVALID_PRICE_CERT = 17
 
static const UINT32 ERR_MULTIPLE_LOGIN = 18
 
static const UINT32 ERR_NO_RECORD_FOUND = 19
 
static const UINT32 ERR_SUCCESS_BUT_WITH_ERRORS = 20
 
static const UINT32 ERR_BLOCKED = 21
 
static const UINT32 ERR_NO_ERROR_GIVEN = 100
 

Private Member Functions

SINT32 setValues (DOMElement *elemRoot)
 

Private Attributes

UINT32 m_iErrorCode
 
UINT8m_strErrMsg
 
void * m_messageObject
 

Detailed Description

This class encapsulates an error or success message.

In order to be independent from the HTTP protocol on the higher layer, this is now used instead of http errorcodes.

Author
Bastian Voigt, Elmar Schraml

Definition at line 44 of file CAXMLErrorMessage.hpp.

Constructor & Destructor Documentation

◆ CAXMLErrorMessage() [1/5]

CAXMLErrorMessage::CAXMLErrorMessage ( const UINT32  errorCode,
UINT8 message 
)

Creates an errorMessage object.

The errorcode should be one of the above ERR_* constants.

Parameters
errorCodeUINT32 one of the above constants
messageString a human-readable description of the error

Definition at line 33 of file CAXMLErrorMessage.cpp.

35 {
36  m_iErrorCode = errorCode;
37  m_strErrMsg = new UINT8[strlen((char *)message)+1];
38  strcpy((char *)m_strErrMsg, (char *)message);
39  m_messageObject = NULL;
40 }
unsigned char UINT8
Definition: basetypedefs.h:135

References m_iErrorCode, m_messageObject, and m_strErrMsg.

◆ CAXMLErrorMessage() [2/5]

CAXMLErrorMessage::CAXMLErrorMessage ( UINT32  errorCode)

Uses a default description String.

Parameters
errorCodeUINT32

Definition at line 44 of file CAXMLErrorMessage.cpp.

46 {
47  UINT8 *errors[] = {
48  (UINT8*)"Success",
49  (UINT8*)"Internal Server Error",
50  (UINT8*)"Wrong format",
51  (UINT8*)"Wrong Data",
52  (UINT8*)"Key not found",
53  (UINT8*)"Bad Signature",
54  (UINT8*)"Bad request",
55  (UINT8*)"You refused to send an account certificate. I will close the connection.",
56  (UINT8*)"You refused to send a current balance. I will close the connection.",
57  (UINT8*)"You refused to send a cost confirmation. I will close the connection.",
58  (UINT8*)"Your account is empty.",
59  (UINT8*)"Cascade is too long",
60  (UINT8*)"Database error",
61  (UINT8*)"Insufficient balance",
62  (UINT8*)"No flatrate offered",
63  (UINT8*)"Invalid code",
64  (UINT8*)"Costconfirmation is not valid, possible attempt at doublespending!",
65  (UINT8*)"One or more price certificates are invalid!",
66  (UINT8*)"User is logged in more than once!",
67  (UINT8*)"No database record for this cost confirmation was found!",
68  (UINT8*)"Operation may have succeded, but this is not clear!",
69  (UINT8*)"Account is blocked!"
70  };
71  m_iErrorCode = errorCode;
72  if (m_iErrorCode < 0 || m_iErrorCode >= 19)
73  {
74  UINT8 defaultMsg[] = "Unknown Error";
75  m_strErrMsg = new UINT8[strlen((char *)defaultMsg)+1];
76  strcpy((char *)m_strErrMsg, (char *)defaultMsg);
77  }
78  else
79  {
80  m_strErrMsg = new UINT8[strlen((char *)errors[errorCode])+1];
81  strcpy((char *)m_strErrMsg, (char *)errors[errorCode]);
82  }
83  m_messageObject = NULL;
84 }

References m_iErrorCode, m_messageObject, and m_strErrMsg.

◆ CAXMLErrorMessage() [3/5]

CAXMLErrorMessage::CAXMLErrorMessage ( const UINT32  errorCode,
UINT8 message,
CAAbstractXMLEncodable messageObject 
)

attaches an object to the error message

Definition at line 88 of file CAXMLErrorMessage.cpp.

89 {
90  m_iErrorCode = errorCode;
91  m_strErrMsg = new UINT8[strlen((char *)message)+1];
92  strcpy((char *)m_strErrMsg, (char *)message);
93 
94  m_messageObject = messageObject;
95 }

References m_iErrorCode, m_messageObject, and m_strErrMsg.

◆ CAXMLErrorMessage() [4/5]

CAXMLErrorMessage::CAXMLErrorMessage ( UINT8 strXmlData)

Parses the string XML representation.

Definition at line 116 of file CAXMLErrorMessage.cpp.

118 {
119  m_strErrMsg=NULL;
120  m_messageObject = NULL;
121 
122  XERCES_CPP_NAMESPACE::DOMDocument* doc = parseDOMDocument(strXmlData,strlen((char*)strXmlData));
123 
124  if(doc != NULL)
125  {
126  DOMElement* elemRoot = doc->getDocumentElement();
127  if (setValues(elemRoot) != E_SUCCESS)
128  {
130  }
131  if(doc != NULL)
132  {
133  doc->release();
134  doc = NULL;
135  }
136  }
137  else
138  {
140  }
141 }
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
static const UINT32 ERR_NO_ERROR_GIVEN
SINT32 setValues(DOMElement *elemRoot)
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2

References E_SUCCESS, ERR_NO_ERROR_GIVEN, m_iErrorCode, m_messageObject, m_strErrMsg, parseDOMDocument(), and setValues().

Here is the call graph for this function:

◆ CAXMLErrorMessage() [5/5]

CAXMLErrorMessage::CAXMLErrorMessage ( DOMElement *  elemRoot)

Definition at line 97 of file CAXMLErrorMessage.cpp.

99 {
100  m_strErrMsg=NULL;
101  m_messageObject = NULL;
102 
103  if(elemRoot != NULL)
104  {
105  if (setValues(elemRoot) != E_SUCCESS)
106  {
108  }
109  }
110  else
111  {
113  }
114 }

References E_SUCCESS, ERR_NO_ERROR_GIVEN, m_iErrorCode, m_messageObject, m_strErrMsg, and setValues().

Here is the call graph for this function:

◆ ~CAXMLErrorMessage()

CAXMLErrorMessage::~CAXMLErrorMessage ( )

Definition at line 219 of file CAXMLErrorMessage.cpp.

220 {
221  if(m_strErrMsg)
222  {
223  delete [] m_strErrMsg;
224  m_strErrMsg = NULL;
225  }
226  if (m_messageObject != NULL)
227  {
228  delete m_messageObject;
229  m_messageObject = NULL;
230  }
231 }

References m_messageObject, and m_strErrMsg.

Member Function Documentation

◆ getDescription()

UINT8* CAXMLErrorMessage::getDescription ( )
inline

Definition at line 109 of file CAXMLErrorMessage.hpp.

110  {
111  return m_strErrMsg;
112  }

References m_strErrMsg.

Referenced by CAAccountingInstance::__handleSettleResult(), and CAAccountingInstance::settlementTransaction().

Here is the caller graph for this function:

◆ getErrorCode()

UINT32 CAXMLErrorMessage::getErrorCode ( )
inline

Definition at line 104 of file CAXMLErrorMessage.hpp.

105  {
106  return m_iErrorCode;
107  }

References m_iErrorCode.

Referenced by CAAccountingInstance::__handleSettleResult(), and CAAccountingInstance::settlementTransaction().

Here is the caller graph for this function:

◆ getMessageObject()

void* CAXMLErrorMessage::getMessageObject ( )
inline

Definition at line 114 of file CAXMLErrorMessage.hpp.

115  {
116  return m_messageObject;
117  }

References m_messageObject.

Referenced by CAAccountingInstance::__handleSettleResult(), and CAAccountingInstance::settlementTransaction().

Here is the caller graph for this function:

◆ setValues()

SINT32 CAXMLErrorMessage::setValues ( DOMElement *  elemRoot)
private

Definition at line 144 of file CAXMLErrorMessage.cpp.

145 {
146  UINT8 strGeneral[256];
147  UINT32 strGeneralLen = 256;
148 
149  SINT32 tmp;
150  SINT32 rc;
151 
152  if( ((rc=getDOMElementAttribute(elemRoot, "code", &tmp)) !=E_SUCCESS) ||
153  ((rc=getDOMElementValue(elemRoot, strGeneral, &strGeneralLen)) !=E_SUCCESS)
154  )
155  {
156  UINT8 buff[8192];
157  UINT32 len=8192;
158  DOM_Output::dumpToMem(elemRoot,buff,&len);
159  CAMsg::printMsg(LOG_DEBUG,(char*)buff);
160 
161  return rc;
162  }
163 
164  m_iErrorCode = (UINT32)tmp;
165  delete [] m_strErrMsg;
166  m_strErrMsg = NULL;
167  m_strErrMsg = new UINT8[strGeneralLen+1];
168  strcpy((char*)m_strErrMsg, (char*)strGeneral);
169 
170  /*if((rc=getDOMElementAttribute(elemRoot, "expires", (UINT8*) strExp, &strExpLen)) ==E_SUCCESS)
171  {
172  if(m_strExpires != NULL)
173  {
174  strncpy(m_strExpires, strExp, 10);
175  }
176  }*/
177  DOMElement* objectRootElem=NULL;
178  getDOMChildByName(elemRoot, "MessageObject", objectRootElem, false);
179 
180  //due to lack of RTTI, we need to hardcode how to deal with each specific object type
182  {
183  DOMElement* ccElem=NULL;
184  if (getDOMChildByName(objectRootElem,"CC",ccElem,true) == E_SUCCESS)
185  {
186  m_messageObject = CAXMLCostConfirmation::getInstance(ccElem);
187  }
188  }
189  else if (ERR_ACCOUNT_EMPTY == m_iErrorCode)
190  {
191  if (objectRootElem != NULL)
192  {
193  CAMsg::printMsg(LOG_INFO, "XMLErrorMessage: appended object found...\n");
194  UINT8* buff = DOM_Output::dumpToString(objectRootElem, true);
195  CAMsg::printMsg(LOG_DEBUG,(char*)buff);
196  delete[] buff;
197  }
198  DOMElement* confirmedElem=NULL;
199  if (getDOMChildByName(objectRootElem,"GenericText",confirmedElem,true) == E_SUCCESS)
200  {
201  m_messageObject = new UINT64;
202  if(getDOMElementValue(confirmedElem, (*(UINT64*)m_messageObject)) != E_SUCCESS)
203  {
204  delete (UINT64*)m_messageObject;
205  m_messageObject = NULL;
206  }
207  }
208  }
209  else
210  {
211  m_messageObject = NULL;
212  }
213  //add code to parse other types of objects here when adding new error codes with corresponding objects
214 
215  return E_SUCCESS;
216 }
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
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
struct __UINT64__t_ UINT64
unsigned int UINT32
Definition: basetypedefs.h:131
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
static const UINT32 ERR_ACCOUNT_EMPTY
static const UINT32 ERR_OUTDATED_CC
static UINT8 * dumpToString(const DOMNode *node, bool a_bAddNewLine)
Dumps the Node an returns a pointer to a null terminated string.
Definition: DOM_Output.hpp:190
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.
Definition: DOM_Output.hpp:161
UINT16 len
Definition: typedefs.hpp:0

References DOM_Output::dumpToMem(), DOM_Output::dumpToString(), E_SUCCESS, ERR_ACCOUNT_EMPTY, ERR_OUTDATED_CC, getDOMChildByName(), getDOMElementAttribute(), getDOMElementValue(), len, m_iErrorCode, m_messageObject, m_strErrMsg, and CAMsg::printMsg().

Referenced by CAXMLErrorMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toXmlElement()

SINT32 CAXMLErrorMessage::toXmlElement ( XERCES_CPP_NAMESPACE::DOMDocument *  a_pDoc,
DOMElement *&  pElemRoot 
)
virtual

Creates the XML structure inside an existing DOM_Document, but does not append it to any node.

Parameters
a_docan existing DOM_Document
elemRooton return contains the root element of the created XML structure. Note that the element is not appended to any node in the document

Implements CAAbstractXMLEncodable.

Definition at line 234 of file CAXMLErrorMessage.cpp.

235 {
236  elemRoot = createDOMElement(a_doc, XML_ELEMENT_ERROR_MSG);
237  setDOMElementAttribute(elemRoot, "code", m_iErrorCode);
238  /*if(m_strExpires != NULL)
239  {
240  if(m_strExpires[0] != 0)
241  {
242  setDOMElementAttribute(elemRoot, "expires", (UINT8*)m_strExpires);
243  }
244  }*/
245  setDOMElementValue(elemRoot, m_strErrMsg);
246 
247  if (m_messageObject)
248  {
249  DOMElement* objectRoot = createDOMElement(a_doc,"MessageObject");
250  DOMElement* objectElem=NULL;
251  //WARNING: this will fail for CAXMLCostConfirmation!!! (since it is not a subclass of CAAbstractXMLEncodable)
253  encodableObject->toXmlElement(a_doc,objectElem);
254  objectRoot->appendChild(objectElem);
255  elemRoot->appendChild(objectRoot);
256  }
257 
258  return E_SUCCESS;
259 }
SINT32 setDOMElementAttribute(DOMNode *pElem, const char *attrName, const char *value)
Definition: CAUtil.cpp:831
SINT32 setDOMElementValue(DOMElement *pElem, SINT32 value)
Definition: CAUtil.cpp:939
DOMElement * createDOMElement(XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const name)
Creates a new DOMElement with the given name which belongs to the DOMDocument owernDoc.
Definition: CAUtil.cpp:814
#define XML_ELEMENT_ERROR_MSG
Abstract base class for classes which can be converted to an XML structure.
virtual SINT32 toXmlElement(XERCES_CPP_NAMESPACE::DOMDocument *a_pDoc, DOMElement *&pElemRoot)=0
Creates the XML structure inside an existing DOM_Document, but does not append it to any node.

References createDOMElement(), E_SUCCESS, m_iErrorCode, m_messageObject, m_strErrMsg, setDOMElementAttribute(), setDOMElementValue(), CAAbstractXMLEncodable::toXmlElement(), and XML_ELEMENT_ERROR_MSG.

Here is the call graph for this function:

Member Data Documentation

◆ ERR_ACCOUNT_EMPTY

const UINT32 CAXMLErrorMessage::ERR_ACCOUNT_EMPTY = 10
static

◆ ERR_BAD_REQUEST

const UINT32 CAXMLErrorMessage::ERR_BAD_REQUEST = 6
static

◆ ERR_BAD_SIGNATURE

const UINT32 CAXMLErrorMessage::ERR_BAD_SIGNATURE = 5
static

◆ ERR_BLOCKED

const UINT32 CAXMLErrorMessage::ERR_BLOCKED = 21
static

◆ ERR_CASCADE_LENGTH

const UINT32 CAXMLErrorMessage::ERR_CASCADE_LENGTH = 11
static

Definition at line 59 of file CAXMLErrorMessage.hpp.

◆ ERR_DATABASE_ERROR

const UINT32 CAXMLErrorMessage::ERR_DATABASE_ERROR = 12
static

◆ ERR_INSUFFICIENT_BALANCE

const UINT32 CAXMLErrorMessage::ERR_INSUFFICIENT_BALANCE = 13
static

Definition at line 61 of file CAXMLErrorMessage.hpp.

◆ ERR_INTERNAL_SERVER_ERROR

const UINT32 CAXMLErrorMessage::ERR_INTERNAL_SERVER_ERROR = 1
static

◆ ERR_INVALID_CODE

const UINT32 CAXMLErrorMessage::ERR_INVALID_CODE = 15
static

Definition at line 63 of file CAXMLErrorMessage.hpp.

◆ ERR_INVALID_PRICE_CERT

const UINT32 CAXMLErrorMessage::ERR_INVALID_PRICE_CERT = 17
static

Definition at line 65 of file CAXMLErrorMessage.hpp.

◆ ERR_KEY_NOT_FOUND

const UINT32 CAXMLErrorMessage::ERR_KEY_NOT_FOUND = 4
static

◆ ERR_MULTIPLE_LOGIN

const UINT32 CAXMLErrorMessage::ERR_MULTIPLE_LOGIN = 18
static

◆ ERR_NO_ACCOUNTCERT

const UINT32 CAXMLErrorMessage::ERR_NO_ACCOUNTCERT = 7
static

Definition at line 55 of file CAXMLErrorMessage.hpp.

◆ ERR_NO_BALANCE

const UINT32 CAXMLErrorMessage::ERR_NO_BALANCE = 8
static

Definition at line 56 of file CAXMLErrorMessage.hpp.

Referenced by CAAccountingInstance::finishLoginProcess().

◆ ERR_NO_CONFIRMATION

const UINT32 CAXMLErrorMessage::ERR_NO_CONFIRMATION = 9
static

◆ ERR_NO_ERROR_GIVEN

const UINT32 CAXMLErrorMessage::ERR_NO_ERROR_GIVEN = 100
static

◆ ERR_NO_FLATRATE_OFFERED

const UINT32 CAXMLErrorMessage::ERR_NO_FLATRATE_OFFERED = 14
static

Definition at line 62 of file CAXMLErrorMessage.hpp.

◆ ERR_NO_RECORD_FOUND

const UINT32 CAXMLErrorMessage::ERR_NO_RECORD_FOUND = 19
static

◆ ERR_OK

const UINT32 CAXMLErrorMessage::ERR_OK = 0
static

◆ ERR_OUTDATED_CC

const UINT32 CAXMLErrorMessage::ERR_OUTDATED_CC = 16
static

◆ ERR_SUCCESS_BUT_WITH_ERRORS

const UINT32 CAXMLErrorMessage::ERR_SUCCESS_BUT_WITH_ERRORS = 20
static

◆ ERR_WRONG_DATA

const UINT32 CAXMLErrorMessage::ERR_WRONG_DATA = 3
static

◆ ERR_WRONG_FORMAT

const UINT32 CAXMLErrorMessage::ERR_WRONG_FORMAT = 2
static

◆ m_iErrorCode

UINT32 CAXMLErrorMessage::m_iErrorCode
private

Definition at line 121 of file CAXMLErrorMessage.hpp.

Referenced by CAXMLErrorMessage(), getErrorCode(), setValues(), and toXmlElement().

◆ m_messageObject

void* CAXMLErrorMessage::m_messageObject
private

◆ m_strErrMsg

UINT8* CAXMLErrorMessage::m_strErrMsg
private

The documentation for this class was generated from the following files: