Mixes for Privacy and Anonymity in the Internet
Public Member Functions | Private Attributes | List of all members
CAHttpClient Class Reference

Very simple http client. More...

Public Member Functions

 CAHttpClient (CASocket *pSocket)
 
 CAHttpClient ()
 
 ~CAHttpClient ()
 
SINT32 setSocket (CASocket *pSocket)
 
SINT32 sendGetRequest (const UINT8 *url)
 Sends a HTTP GET request to the server. More...
 
SINT32 sendPostRequest (const UINT8 *url, const UINT8 *data, const UINT32 dataLen)
 Sends a HTTP POST request to the server. More...
 
SINT32 parseHTTPHeader (UINT32 *contentLength, UINT32 *statusCode=NULL, UINT32 msTimeOut=3000)
 receives the HTTP header and parses the content length More...
 
SINT32 getContent (UINT8 *a_pContent, UINT32 *a_pLength)
 Retruns the content of the response. More...
 

Private Attributes

CASocketm_pSocket
 the socket connection to the http server More...
 

Detailed Description

Very simple http client.

Used by CAInfoService and CAAccountingBIInterface. Must be initialized with a connected socket. Note that the socket is still owned by the caller. CAHttpClient will not delete the socket

Author
Bastian Voigt

Constructor & Destructor Documentation

◆ CAHttpClient() [1/2]

CAHttpClient::CAHttpClient ( CASocket pSocket)

References m_pSocket.

◆ CAHttpClient() [2/2]

CAHttpClient::CAHttpClient ( )

References m_pSocket.

◆ ~CAHttpClient()

CAHttpClient::~CAHttpClient ( )

Member Function Documentation

◆ getContent()

SINT32 CAHttpClient::getContent ( UINT8 a_pContent,
UINT32 a_pLength 
)

Retruns the content of the response.

Gets the content of a HTTP response.

Parameters
a_pContentbuff which receives the content
a_pLengthon input contains the size of a_pContent, on return contains the number of received bytes
Return values
E_NOT_CONNECTEDif socket is not connected
E_SUCCESSif successful

References E_NOT_CONNECTED, E_SUCCESS, len, m_pSocket, and CASocket::receive().

Referenced by CAInfoService::getPaymentInstance().

◆ parseHTTPHeader()

SINT32 CAHttpClient::parseHTTPHeader ( UINT32 contentLength,
UINT32 statusCode = NULL,
UINT32  msTimeOut = 3000 
)

receives the HTTP header and parses the content length

Receives the HTTP header and parses the content length.

Parameters
contentLengthreceives the parsed content length
statusCodeif set, receives the http statuscode (200, 403, 404, ...)
Return values
E_SUCCESSif all is OK
E_UNKNOWNif the server returned a http errorcode TODO: Verify that "HTTP/1.1 200 OK" must be the first line!
Parameters
contentLengthreceives the parsed content length
statusCodeif set, receives the http statuscode (200, 403, 404, ...)
msTimeOuttime in ms for receiving the HTTPHeader (<=0 means no timeout)
Return values
E_SUCCESSif all is OK
E_NOT_CONNECTEDif the connection to the Web-Server was lost
E_UNKNOWNif the server returned a http errorcode, in this case statusCode is set to 0 and contentLength is set to 0
Todo:

: Verify that "HTTP/1.1 200 OK" must be the first line!

: Maybe set an other statusCode in case of an error ?

TODO: do it better (case insensitive compare!)

References add64(), diff64(), E_AGAIN, E_NOT_CONNECTED, E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, getcurrentTimeMillis(), CASocket::getNonBlocking(), isLesser64(), m_pSocket, msSleep(), CAMsg::printMsg(), CASocket::receive(), set64(), and CASocket::setNonBlocking().

Referenced by CAInfoService::getPaymentInstance(), CAInfoService::sendMixHelo(), CAAccountingBIInterface::settle(), and CAAccountingBIInterface::settleAll().

◆ sendGetRequest()

SINT32 CAHttpClient::sendGetRequest ( const UINT8 url)

Sends a HTTP GET request to the server.

Parameters
urlthe local part of the URL requested (e.g. "/settle")
Returns
E_UNKNOWN on socket errors
E_NOT_CONNECTED if the connection was lost
E_SUCCESS if all is OK
Parameters
urlthe local part of the URL requested (e.g. "/settle")
Return values
E_UNKNOWNon socket errors
E_NOT_CONNECTEDif the connection was lost
E_SUCCESSif all is OK

References E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, len, m_pSocket, CAMsg::printMsg(), and CASocket::sendFullyTimeOut().

Referenced by CAInfoService::getPaymentInstance().

◆ sendPostRequest()

SINT32 CAHttpClient::sendPostRequest ( const UINT8 url,
const UINT8 data,
const UINT32  dataLen 
)

Sends a HTTP POST request to the server.

Parameters
urlthe local part of the requested URL (e.g. "/settle")
dataa buffer containing the data
dataLenthe length of the data in bytes
Returns
E_UNKNOWN on socket errors
E_NOT_CONNECTED if the connection was lost
E_SUCCESS if all is OK

References data, E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, len, m_pSocket, CAMsg::printMsg(), and CASocket::sendFullyTimeOut().

Referenced by CAAccountingBIInterface::settle(), and CAAccountingBIInterface::settleAll().

◆ setSocket()

SINT32 CAHttpClient::setSocket ( CASocket pSocket)

Member Data Documentation

◆ m_pSocket

CASocket* CAHttpClient::m_pSocket
private

the socket connection to the http server

Referenced by CAHttpClient(), getContent(), parseHTTPHeader(), sendGetRequest(), sendPostRequest(), and setSocket().