|
Mixe for Privacy and Anonymity in the Internet
|
This class encapsulates the connection to the JPI. More...
#include <CAAccountingBIInterface.hpp>
Public Member Functions | |
| CAAccountingBIInterface () | |
| private constructor just initializes fields, server configuration is done separately | |
| ~CAAccountingBIInterface () | |
| private destructor | |
| SINT32 | setPIServerConfiguration (CAXMLBI *pPiServerConfig) |
| SINT32 | initBIConnection () |
| Establishes HTTP(s) connection to the BI (JPI) | |
| SINT32 | terminateBIConnection () |
| Terminate HTTP(s) connection to the BI (JPI) | |
| CAXMLErrorMessage * | settle (CAXMLCostConfirmation &cc) |
| Send a cost confirmation to the JPI. | |
| CAXMLErrorMessage ** | settleAll (CAXMLCostConfirmation **CCs, UINT32 nrOfCCs, CAXMLErrorMessage **settleException) |
Private Attributes | |
| CATLSClientSocket * | m_pSocket |
| CAHttpClient * | m_phttpClient |
| CASocketAddrINet * | m_pPiServerAddress |
| CACertificate * | m_pPiServerCertificate |
This class encapsulates the connection to the JPI.
Definition at line 51 of file CAAccountingBIInterface.hpp.
private constructor just initializes fields, server configuration is done separately
Definition at line 44 of file CAAccountingBIInterface.cpp.
References m_phttpClient, m_pPiServerAddress, and m_pSocket.
{
//m_pSocket =NULL;
//m_pPiInterfaceMutex = new CAMutex();
m_pSocket = new CATLSClientSocket();
m_pPiServerAddress = new CASocketAddrINet();
m_phttpClient = new CAHttpClient();
}
private destructor
Definition at line 56 of file CAAccountingBIInterface.cpp.
References m_phttpClient, m_pPiServerAddress, m_pSocket, and terminateBIConnection().
{
terminateBIConnection();
if(m_pSocket!=NULL)
{
delete m_pSocket;
m_pSocket = NULL;
}
if(m_pPiServerAddress!=NULL)
{
delete m_pPiServerAddress;
m_pPiServerAddress = NULL;
}
if(m_phttpClient!=NULL)
{
delete m_phttpClient;
m_phttpClient = NULL;
}
/*if(m_pPiInterfaceMutex!=NULL)
{
delete m_pPiInterfaceMutex;
m_pPiInterfaceMutex = NULL;
}*/
}
Establishes HTTP(s) connection to the BI (JPI)
Definition at line 131 of file CAAccountingBIInterface.cpp.
References CATLSClientSocket::close(), CATLSClientSocket::connect(), E_SUCCESS, E_UNKNOWN, CASocketAddrINet::getHostName(), CASocketAddrINet::getPort(), m_phttpClient, m_pPiServerAddress, m_pPiServerCertificate, m_pSocket, PI_CONNECT_TIMEOUT, CAMsg::printMsg(), CATLSClientSocket::setServerCertificate(), and CAHttpClient::setSocket().
Referenced by CAAccountingInstance::__newSettlementTransaction(), and CAAccountingInstance::settlementTransaction().
{
SINT32 rc;
UINT8 buf[64];
memset(buf,0,64);
//m_pPiInterfaceMutex->lock();
if(m_pPiServerAddress == NULL)
{
//Should never happen
#ifdef DEBUG
CAMsg::printMsg(LOG_ERR, "CAAccountingBIInterface: no address initialized while trying to connect. Connect aborted.\n");
#endif
//m_pPiInterfaceMutex->unlock();
return E_UNKNOWN;
}
if(m_pSocket == NULL)
{
//Should never happen
#ifdef DEBUG
CAMsg::printMsg(LOG_ERR,"CAAccountingBIInterface: no socket initialized while trying to connect. Creating new one.\n");
#endif
m_pSocket = new CATLSClientSocket();
}
if(m_pPiServerCertificate == NULL)
{
CAMsg::printMsg(LOG_ERR,"CAAccountingBIInterface: no PI server certificate specified. Connect aborted.\n");
//m_pPiInterfaceMutex->unlock();
return E_UNKNOWN;
}
// connect
m_pSocket->setServerCertificate(m_pPiServerCertificate);
rc=m_pSocket->connect(*m_pPiServerAddress, PI_CONNECT_TIMEOUT);
if(rc!=E_SUCCESS)
{
m_pPiServerAddress->getHostName(buf, 64);
CAMsg::printMsg(
LOG_ERR,
"CAAccountingBIInterface: Could not connect to BI at %s:%i. Reason: %i\n",
buf, m_pPiServerAddress->getPort(), rc
//pBI->getHostName(), pBI->getPortNumber(), rc
);
m_pSocket->close();
//m_pPiInterfaceMutex->unlock();
return E_UNKNOWN;
}
m_pPiServerAddress->getHostName(buf, 64);
CAMsg::printMsg(LOG_DEBUG,"CAAccountingBIInterface: BI connection to %s:%i established!\n", buf,m_pPiServerAddress->getPort());
m_phttpClient->setSocket(m_pSocket);
//m_pPiInterfaceMutex->unlock();
return E_SUCCESS;
}
| SINT32 CAAccountingBIInterface::setPIServerConfiguration | ( | CAXMLBI * | pPiServerConfig | ) |
Definition at line 82 of file CAAccountingBIInterface.cpp.
References E_SUCCESS, E_UNKNOWN, CAXMLBI::getCertificate(), CAXMLBI::getHostName(), CAXMLBI::getPortNumber(), m_pPiServerAddress, m_pPiServerCertificate, CAMsg::printMsg(), and CASocketAddrINet::setAddr().
Referenced by CAAccountingInstance::CAAccountingInstance().
{
UINT8 *pPiName = NULL;
UINT16 piPort = 0;
CACertificate *pPiCert = NULL;
//m_pPiInterfaceMutex->lock();
if(pPiServerConfig==NULL)
{
CAMsg::printMsg(LOG_ERR, "CAAccountingBIInterface: could not configure PI interface: no proper configuration given.\n");
//m_pPiInterfaceMutex->unlock();
return E_UNKNOWN;
}
pPiName = pPiServerConfig->getHostName();
pPiCert = pPiServerConfig->getCertificate();
piPort = (UINT16)pPiServerConfig->getPortNumber();
if(pPiName==NULL)
{
CAMsg::printMsg(LOG_ERR, "CAAccountingBIInterface: could not configure PI interface: no PI name specified.\n");
//m_pPiInterfaceMutex->unlock();
return E_UNKNOWN;
}
if(pPiCert==NULL)
{
CAMsg::printMsg(LOG_ERR, "CAAccountingBIInterface: could not configure PI interface: no PI certificate specified.\n");
//m_pPiInterfaceMutex->unlock();
return E_UNKNOWN;
}
if(m_pPiServerAddress == NULL)
{
//Should never happen
#ifdef DEBUG
CAMsg::printMsg(LOG_ERR,"CAAccountingBIInterface: no server address initialized while trying to configure PI interface.\n");
#endif
m_pPiServerAddress = new CASocketAddrINet();
}
m_pPiServerAddress->setAddr(pPiName, piPort);
m_pPiServerCertificate = pPiCert;
//m_pPiInterfaceMutex->unlock();
return E_SUCCESS;
}
Send a cost confirmation to the JPI.
Send a cost confirmation to the JPI TODO: Error handling.
Definition at line 354 of file CAAccountingBIInterface.cpp.
References CAXMLCostConfirmation::dumpToMem(), E_SUCCESS, E_TIMEDOUT, m_phttpClient, m_pSocket, CAHttpClient::parseHTTPHeader(), CAMsg::printMsg(), CASocket::receiveFullyT(), CAHttpClient::sendPostRequest(), and CASocket::setNonBlocking().
Referenced by CAAccountingInstance::settlementTransaction().
{
UINT8 * pStrCC=NULL;
UINT8* response=NULL;
UINT32 contentLen=0, status=0;
SINT32 ret = 0;
CAXMLErrorMessage *pErrMsg;
//m_pPiInterfaceMutex->lock();
pStrCC = cc.dumpToMem(&contentLen);
if( pStrCC==NULL || m_phttpClient->sendPostRequest((UINT8*)"/settle", pStrCC,contentLen)!= E_SUCCESS)
{
delete[] pStrCC;
pStrCC = NULL;
//m_pPiInterfaceMutex->unlock();
return NULL;
}
delete[] pStrCC;
pStrCC = NULL;
contentLen=0;
status=0;
m_pSocket->setNonBlocking(true);
ret = m_phttpClient->parseHTTPHeader(&contentLen, &status, 20000);
if( ret !=E_SUCCESS || (status!=200) || (contentLen==0))
{
if(ret == E_TIMEDOUT)
{
CAMsg::printMsg(LOG_ERR, "CAAccountingBIInterface::settle: timeout while receiving response!\n");
}
else
{
CAMsg::printMsg(LOG_ERR, "CAAccountingBIInterface::settle: received bad response from PI!\n");
}
//m_pPiInterfaceMutex->unlock();
return NULL;
}
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG, "CAAccountingBIInterface::settle: got response header [Status,content-Lenght]=[%i,%i]!\n",status,contentLen);
#endif
response = new UINT8[contentLen+1];
ret = m_pSocket->receiveFullyT(response, contentLen, 3000);
if(ret !=E_SUCCESS)
{
if(ret == E_TIMEDOUT)
{
CAMsg::printMsg(LOG_ERR, "CAAccountingBIInterface::settle: timeout while receiving settle message!\n");
}
else
{
CAMsg::printMsg(LOG_DEBUG, "CAAccountingBIInterface::settle: error\n");
}
delete[] response;
response = NULL;
//m_pPiInterfaceMutex->unlock();
return NULL;
}
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG, "CAAccountingBIInterface::settle: response body received!\n");
#endif
response[contentLen]='\0';
pErrMsg = new CAXMLErrorMessage(response);
delete[] response;
response = NULL;
//m_pPiInterfaceMutex->unlock();
return pErrMsg;
}
| CAXMLErrorMessage ** CAAccountingBIInterface::settleAll | ( | CAXMLCostConfirmation ** | CCs, |
| UINT32 | nrOfCCs, | ||
| CAXMLErrorMessage ** | settleException | ||
| ) |
Definition at line 210 of file CAAccountingBIInterface.cpp.
References createDOMDocument(), createDOMElement(), DOM_Output::dumpToMem(), E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, CAXMLErrorMessage::ERR_INTERNAL_SERVER_ERROR, getDOMElementAttribute(), getElementsByTagName(), CAXMLCostConfirmation::getXMLDocument(), m_phttpClient, m_pSocket, parseDOMDocument(), CAHttpClient::parseHTTPHeader(), POST_CMD_SETTLEALL, CAMsg::printMsg(), CASocket::receiveFullyT(), CAHttpClient::sendPostRequest(), CASocket::setNonBlocking(), XML_ATTR_SETTLE_SUCCESSFUL, XML_ELEMENT_CCS, and XML_ELEMENT_ERROR_MSG.
Referenced by CAAccountingInstance::__newSettlementTransaction().
{
XERCES_CPP_NAMESPACE::DOMDocument *allCCsEnvelopeDoc = createDOMDocument();
DOMElement *allCCsEnvelope = createDOMElement(allCCsEnvelopeDoc, XML_ELEMENT_CCS);
CAXMLErrorMessage **resultMessages = NULL;
DOMNodeList *errorMsgList = NULL;
UINT8 *allCCsAsString = NULL, *response = NULL;
UINT32 contentLength = 0, nrOfErrorMessages = 0, i = 0;
UINT32 status = 0;
SINT32 transmitStatus = 0, domStatus;
bool settleSuccessful = false;
if(nrOfCCs <= 0)
{
return NULL;
}
allCCsEnvelopeDoc->appendChild(allCCsEnvelope);
for (i = 0; i < nrOfCCs; i++)
{
allCCsEnvelope->appendChild(allCCsEnvelopeDoc->importNode(
ccs[i]->getXMLDocument()->getDocumentElement(), true));
}
allCCsAsString = DOM_Output::dumpToMem(allCCsEnvelopeDoc, &contentLength);
transmitStatus = (allCCsAsString != NULL) ?
m_phttpClient->sendPostRequest((UINT8*) POST_CMD_SETTLEALL,
allCCsAsString, contentLength) : E_UNKNOWN;
allCCsEnvelopeDoc->release();
allCCsEnvelopeDoc = NULL;
allCCsEnvelope = NULL;
delete [] allCCsAsString;
allCCsAsString = NULL;
if( transmitStatus != E_SUCCESS )
{
return NULL;
}
m_pSocket->setNonBlocking(true);
transmitStatus = m_phttpClient->parseHTTPHeader(&contentLength, &status, 20000);
if( (transmitStatus != E_SUCCESS) || (status != 200) || (contentLength == 0))
{
if(transmitStatus == E_TIMEDOUT)
{
CAMsg::printMsg(LOG_ERR, "CAAccountingBIInterface::settle: timeout while receiving response!\n");
}
else
{
CAMsg::printMsg(LOG_ERR, "CAAccountingBIInterface::settle: received bad response from PI: %u!\n", status);
}
return NULL;
}
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG, "CAAccountingBIInterface::settle: got response header [Status,content-Length]=[%i,%i]!\n",
status, contentLength);
#endif
response = new UINT8[contentLength+1];
transmitStatus = m_pSocket->receiveFullyT(response, contentLength, 3000);
if(transmitStatus !=E_SUCCESS)
{
if(transmitStatus == E_TIMEDOUT)
{
CAMsg::printMsg(LOG_ERR, "CAAccountingBIInterface::settle: timeout while receiving settle message!\n");
}
else
{
CAMsg::printMsg(LOG_DEBUG, "CAAccountingBIInterface::settle: error\n");
}
delete [] response;
response = NULL;
return NULL;
}
response[contentLength]='\0';
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG, "CAAccountingBIInterface::settle: response body received: %s\n", response);
#endif
allCCsEnvelopeDoc = parseDOMDocument(response, contentLength);
if(allCCsEnvelopeDoc != NULL)
{
errorMsgList = getElementsByTagName(allCCsEnvelopeDoc->getDocumentElement(),
XML_ELEMENT_ERROR_MSG);
domStatus =
getDOMElementAttribute(allCCsEnvelopeDoc->getDocumentElement(), XML_ATTR_SETTLE_SUCCESSFUL, settleSuccessful);
if(domStatus != E_SUCCESS)
{
settleSuccessful = false;
}
nrOfErrorMessages = errorMsgList->getLength();
if(settleSuccessful)
{
if(nrOfErrorMessages == nrOfCCs)
{
resultMessages = new CAXMLErrorMessage *[nrOfCCs];
for (i = 0; i < nrOfErrorMessages; i++)
{
resultMessages[i] = new CAXMLErrorMessage((DOMElement *) errorMsgList->item(i));
}
}
else
{
CAMsg::printMsg(LOG_WARNING, "CAAccountingBIInterface::settle: BUG: number of messages != number of cost confirmations!\n");
//This would be a bug.
*settleException =
new CAXMLErrorMessage(CAXMLErrorMessage::ERR_INTERNAL_SERVER_ERROR);
}
}
else
{
CAMsg::printMsg(LOG_WARNING, "CAAccountingBIInterface::settle: PI exception raised.\n");
*settleException = (nrOfErrorMessages > 0) ?
new CAXMLErrorMessage((DOMElement *) errorMsgList->item(0)) :
new CAXMLErrorMessage(CAXMLErrorMessage::ERR_INTERNAL_SERVER_ERROR);
}
}
delete [] response;
response = NULL;
if(allCCsEnvelopeDoc != NULL)
{
allCCsEnvelopeDoc->release();
allCCsEnvelopeDoc = NULL;
}
return (settleException != NULL) ? resultMessages : NULL;
}
Terminate HTTP(s) connection to the BI (JPI)
Definition at line 192 of file CAAccountingBIInterface.cpp.
References CATLSClientSocket::close(), E_SUCCESS, E_UNKNOWN, m_pSocket, and CAMsg::printMsg().
Referenced by CAAccountingInstance::__newSettlementTransaction(), CAAccountingInstance::settlementTransaction(), and ~CAAccountingBIInterface().
{
//m_pPiInterfaceMutex->lock();
if(m_pSocket == NULL)
{
//Should never happen
#ifdef DEBUG
CAMsg::printMsg(LOG_ERR,"CAAccountingBIInterface: no socket initialized while trying to close connection.\n");
#endif
//m_pPiInterfaceMutex->unlock();
return E_UNKNOWN;
}
m_pSocket->close();
//m_pPiInterfaceMutex->unlock();
return E_SUCCESS;
}
Definition at line 90 of file CAAccountingBIInterface.hpp.
Referenced by CAAccountingBIInterface(), initBIConnection(), settle(), settleAll(), and ~CAAccountingBIInterface().
Definition at line 91 of file CAAccountingBIInterface.hpp.
Referenced by CAAccountingBIInterface(), initBIConnection(), setPIServerConfiguration(), and ~CAAccountingBIInterface().
Definition at line 92 of file CAAccountingBIInterface.hpp.
Referenced by initBIConnection(), and setPIServerConfiguration().
Definition at line 89 of file CAAccountingBIInterface.hpp.
Referenced by CAAccountingBIInterface(), initBIConnection(), settle(), settleAll(), terminateBIConnection(), and ~CAAccountingBIInterface().
1.7.6.1