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

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

#include <CAXMLErrorMessage.hpp>

Inheritance diagram for CAXMLErrorMessage:
[legend]
Collaboration diagram for CAXMLErrorMessage:
[legend]

List of all members.

Public Member Functions

 CAXMLErrorMessage (const UINT32 errorCode, UINT8 *message)
 Creates an errorMessage object.
 CAXMLErrorMessage (UINT32 errorCode)
 Uses a default description String.
 CAXMLErrorMessage (const UINT32 errorCode, UINT8 *message, CAAbstractXMLEncodable *messageObject)
 attaches an object to the error message
 CAXMLErrorMessage (UINT8 *strXmlData)
 Parses the string XML representation.
 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.
UINT32 getErrorCode ()
UINT8getDescription ()
void * getMessageObject ()

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::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.

References m_iErrorCode, m_messageObject, and m_strErrMsg.

  : CAAbstractXMLEncodable()
{
  m_iErrorCode = errorCode;
  m_strErrMsg = new UINT8[strlen((char *)message)+1];
  strcpy((char *)m_strErrMsg, (char *)message);
  m_messageObject = NULL;
}

Uses a default description String.

Parameters:
errorCodeUINT32

Definition at line 44 of file CAXMLErrorMessage.cpp.

References m_iErrorCode, m_messageObject, and m_strErrMsg.

  : CAAbstractXMLEncodable()
{
  UINT8 *errors[] = {
    (UINT8*)"Success",
    (UINT8*)"Internal Server Error",
    (UINT8*)"Wrong format",
    (UINT8*)"Wrong Data",
    (UINT8*)"Key not found",
    (UINT8*)"Bad Signature",
    (UINT8*)"Bad request",
    (UINT8*)"You refused to send an account certificate. I will close the connection.",
    (UINT8*)"You refused to send a current balance. I will close the connection.",
    (UINT8*)"You refused to send a cost confirmation. I will close the connection.",
    (UINT8*)"Your account is empty.",
    (UINT8*)"Cascade is too long",
    (UINT8*)"Database error",
    (UINT8*)"Insufficient balance",
    (UINT8*)"No flatrate offered",
    (UINT8*)"Invalid code",
    (UINT8*)"Costconfirmation is not valid, possible attempt at doublespending!",
    (UINT8*)"One or more price certificates are invalid!",
    (UINT8*)"User is logged in more than once!",
    (UINT8*)"No database record for this cost confirmation was found!",
    (UINT8*)"Operation may have succeded, but this is not clear!",
    (UINT8*)"Account is blocked!"
  };
  m_iErrorCode = errorCode;
  if (m_iErrorCode < 0 || m_iErrorCode >= 19)
  {
    UINT8 defaultMsg[] = "Unknown Error";
    m_strErrMsg = new UINT8[strlen((char *)defaultMsg)+1];
    strcpy((char *)m_strErrMsg, (char *)defaultMsg);
  }
  else
  {
    m_strErrMsg = new UINT8[strlen((char *)errors[errorCode])+1];
    strcpy((char *)m_strErrMsg, (char *)errors[errorCode]);
  }
  m_messageObject = NULL;
}
CAXMLErrorMessage::CAXMLErrorMessage ( const UINT32  errorCode,
UINT8 message,
CAAbstractXMLEncodable messageObject 
)

attaches an object to the error message

Definition at line 88 of file CAXMLErrorMessage.cpp.

References m_iErrorCode, m_messageObject, and m_strErrMsg.

{
  m_iErrorCode = errorCode;
  m_strErrMsg = new UINT8[strlen((char *)message)+1];
  strcpy((char *)m_strErrMsg, (char *)message);

  m_messageObject = messageObject;
}

Parses the string XML representation.

Definition at line 116 of file CAXMLErrorMessage.cpp.

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

  : CAAbstractXMLEncodable()
{
  m_strErrMsg=NULL;
  m_messageObject = NULL;

  XERCES_CPP_NAMESPACE::DOMDocument* doc = parseDOMDocument(strXmlData,strlen((char*)strXmlData));

  if(doc != NULL)
  {
    DOMElement* elemRoot = doc->getDocumentElement();
    if (setValues(elemRoot) != E_SUCCESS)
    {
      m_iErrorCode = ERR_NO_ERROR_GIVEN;
    }
    if(doc != NULL)
    {
      doc->release();
      doc = NULL;
    }
  }
  else
  {
    m_iErrorCode = ERR_NO_ERROR_GIVEN;
  }
}

Here is the call graph for this function:

CAXMLErrorMessage::CAXMLErrorMessage ( DOMElement *  elemRoot)

Definition at line 97 of file CAXMLErrorMessage.cpp.

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

  : CAAbstractXMLEncodable()
{
  m_strErrMsg=NULL;
  m_messageObject = NULL;

  if(elemRoot != NULL)
  {
    if (setValues(elemRoot) != E_SUCCESS)
    {
      m_iErrorCode = ERR_NO_ERROR_GIVEN;
    }
  }
  else
  {
    m_iErrorCode = ERR_NO_ERROR_GIVEN;
  }
}

Here is the call graph for this function:

Definition at line 219 of file CAXMLErrorMessage.cpp.

References m_messageObject, and m_strErrMsg.

{
  if(m_strErrMsg)
  {
    delete [] m_strErrMsg;
    m_strErrMsg = NULL;
  }
  if (m_messageObject != NULL)
  {
    delete m_messageObject;
    m_messageObject = NULL;
  }
}

Member Function Documentation

SINT32 CAXMLErrorMessage::setValues ( DOMElement *  elemRoot) [private]

Definition at line 144 of file CAXMLErrorMessage.cpp.

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

Referenced by CAXMLErrorMessage().

{
  UINT8 strGeneral[256];
  UINT32 strGeneralLen = 256;

  SINT32 tmp;
  SINT32 rc;

  if( ((rc=getDOMElementAttribute(elemRoot, "code", &tmp)) !=E_SUCCESS) ||
       ((rc=getDOMElementValue(elemRoot, strGeneral, &strGeneralLen)) !=E_SUCCESS)
    )
  {
    UINT8 buff[8192];
    UINT32 len=8192;
    DOM_Output::dumpToMem(elemRoot,buff,&len);
    CAMsg::printMsg(LOG_DEBUG,(char*)buff);

    return rc;
  }

  m_iErrorCode = (UINT32)tmp;
  delete [] m_strErrMsg;
  m_strErrMsg = NULL;
  m_strErrMsg = new UINT8[strGeneralLen+1];
  strcpy((char*)m_strErrMsg, (char*)strGeneral);

  /*if((rc=getDOMElementAttribute(elemRoot, "expires", (UINT8*) strExp, &strExpLen)) ==E_SUCCESS)
  {
    if(m_strExpires != NULL)
    {
      strncpy(m_strExpires, strExp, 10);
    }
  }*/
  DOMElement* objectRootElem=NULL;
  getDOMChildByName(elemRoot, "MessageObject", objectRootElem, false);

  //due to lack of RTTI, we need to hardcode how to deal with each specific object type
  if (ERR_OUTDATED_CC == m_iErrorCode)
  {
    DOMElement* ccElem=NULL;
    if (getDOMChildByName(objectRootElem,"CC",ccElem,true) == E_SUCCESS)
    {
      m_messageObject = CAXMLCostConfirmation::getInstance(ccElem);
    }
  }
  else if (ERR_ACCOUNT_EMPTY == m_iErrorCode)
  {
    if (objectRootElem != NULL)
    {
      CAMsg::printMsg(LOG_INFO, "XMLErrorMessage: appended object found...\n");
      UINT8* buff = DOM_Output::dumpToString(objectRootElem, true);
      CAMsg::printMsg(LOG_DEBUG,(char*)buff);
      delete[] buff;
    }
    DOMElement* confirmedElem=NULL;
    if (getDOMChildByName(objectRootElem,"GenericText",confirmedElem,true) == E_SUCCESS)
    {
      m_messageObject = new UINT64;
      if(getDOMElementValue(confirmedElem, (*(UINT64*)m_messageObject)) != E_SUCCESS)
      {
        delete (UINT64*)m_messageObject;
        m_messageObject = NULL;
      }
    }
  }
  else
  {
    m_messageObject = NULL;
  }
  //add code to parse other types of objects here when adding new error codes with corresponding objects

  return E_SUCCESS;
}

Here is the call graph for this function:

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.

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

{
  elemRoot = createDOMElement(a_doc, XML_ELEMENT_ERROR_MSG);
  setDOMElementAttribute(elemRoot, "code", m_iErrorCode);
  /*if(m_strExpires != NULL)
  {
    if(m_strExpires[0] != 0)
    {
      setDOMElementAttribute(elemRoot, "expires", (UINT8*)m_strExpires);
    }
  }*/
  setDOMElementValue(elemRoot, m_strErrMsg);

  if (m_messageObject)
  {
    DOMElement* objectRoot = createDOMElement(a_doc,"MessageObject");
    DOMElement* objectElem=NULL;
    //WARNING: this will fail for CAXMLCostConfirmation!!! (since it is not a subclass of CAAbstractXMLEncodable)
    CAAbstractXMLEncodable* encodableObject = (CAAbstractXMLEncodable*) m_messageObject;
    encodableObject->toXmlElement(a_doc,objectElem);
    objectRoot->appendChild(objectElem);
    elemRoot->appendChild(objectRoot);
  }

  return E_SUCCESS;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 59 of file CAXMLErrorMessage.hpp.

Definition at line 61 of file CAXMLErrorMessage.hpp.

Definition at line 63 of file CAXMLErrorMessage.hpp.

Definition at line 65 of file CAXMLErrorMessage.hpp.

Definition at line 55 of file CAXMLErrorMessage.hpp.

Definition at line 56 of file CAXMLErrorMessage.hpp.

Referenced by CAAccountingInstance::finishLoginProcess().

Definition at line 62 of file CAXMLErrorMessage.hpp.

const UINT32 CAXMLErrorMessage::ERR_OK = 0 [static]

Definition at line 121 of file CAXMLErrorMessage.hpp.

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


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