InternetRequest Class Reference

Class for requesting data from an internet server via HTTP. More...

#include <InternetRequest.h>

List of all members.

Classes

struct  RequestData
 Structure for holding request information; used mostly for requests on a worker thread. More...

Public Member Functions

 InternetRequest ()
 Constructor.
 ~InternetRequest ()
 Destructor.
const std::tstring & GetError ()
 Retrieves the last error string.
bool DoRequest (const std::tstring &sRequest, InternetRequestBuffer &buffer, LPCTSTR lpServer=NULL, LPCSTR lpOptional=NULL, LPCTSTR lpHeaders=NULL, ProgressInterface *pProgress=&gpiDefault)
 Runs an internet request and returns when it is finished.
bool DoRequestThread (const std::tstring &sRequest, InternetRequestBuffer &buffer, LPCTSTR lpServer=NULL, LPCSTR lpOptional=NULL, LPCTSTR lpHeaders=NULL, ProgressInterface *pProgress=&gpiDefault)
 Runs an internet request in a worker thread and returns immediatly.

Protected Member Functions

void OnInternetCallback (DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
 Called when the request changes status.
bool OpenSession ()
 Opens a wininet session.
void CloseAll ()
 Closes all wininet handles.
bool DoRequest (RequestData *pData)
 Runs the request and calles the progress interface when it is finished.
bool InnerDoRequest (RequestData *pData)
 Runs the request (does the actual work).

Static Protected Member Functions

static void __stdcall InternetCallback (HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
 Callback for wininet status changes.
static DWORD WINAPI RequestThreadProc (LPVOID lpData)
 The request worker thread main function.

Protected Attributes

HINTERNET m_hSession
 The wininet session object.
HINTERNET m_hConnection
 The wininet connection object (reused for each different server).
HINTERNET m_hRequest
 The wininet current request (reused for each request).
bool m_bInRequest
 true if currently in a request, false if not
bool m_bInCreation
 true while creating a connection, false if not
std::tstring m_sServer
 Name of server used for the current connection.
std::tstring m_sError
 Last error for the request.

Detailed Description

Class for requesting data from an internet server via HTTP.

Definition at line 81 of file InternetRequest.h.


Member Function Documentation

bool InternetRequest::DoRequest ( RequestData pData  )  [protected]

Runs the request and calles the progress interface when it is finished.

Parameters:
pData Pointer to the request data structure
Returns:
true if request returned the data, false if failed

Definition at line 295 of file InternetRequest.cpp.

References InnerDoRequest(), InternetRequest::RequestData::m_pProgress, and ProgressInterface::OnFinished().

bool InternetRequest::DoRequest ( const std::tstring &  sRequest,
InternetRequestBuffer buffer,
LPCTSTR  lpServer = NULL,
LPCSTR  lpOptional = NULL,
LPCTSTR  lpHeaders = NULL,
ProgressInterface pProgress = &gpiDefault 
)

Runs an internet request and returns when it is finished.

Parameters:
sRequest The page requested from the server
buffer Buffer object to fill with the request response
lpServer Server name (can be NULL; if so, will use the current connection if any or fail if there is none)
lpOptional Additional data for POST (can be NULL)
lpHeaders Additional headers (can be NULL)
pProgress Pointer to the progress interface (can be NULL)
Returns:
true if the request was successful, false if failed

Definition at line 240 of file InternetRequest.cpp.

Referenced by RequestThreadProc().

bool InternetRequest::DoRequestThread ( const std::tstring &  sRequest,
InternetRequestBuffer buffer,
LPCTSTR  lpServer = NULL,
LPCSTR  lpOptional = NULL,
LPCTSTR  lpHeaders = NULL,
ProgressInterface pProgress = &gpiDefault 
)

Runs an internet request in a worker thread and returns immediatly.

Parameters:
sRequest The page requested from the server
buffer Buffer object to fill with the request response
lpServer Server name (can be NULL; if so, will use the current connection if any or fail if there is none)
lpOptional Additional data for POST (can be NULL)
lpHeaders Additional headers (can be NULL)
pProgress Pointer to the progress interface (can be NULL)
Returns:
true if the request worker thread started, false if it failed to start

Definition at line 257 of file InternetRequest.cpp.

References m_sError, and RequestThreadProc().

Referenced by CCPrintProgressDlg::PageProc().

const std::tstring& InternetRequest::GetError (  )  [inline]

Retrieves the last error string.

Returns:
The last error string

Definition at line 151 of file InternetRequest.h.

References m_sError.

bool InternetRequest::InnerDoRequest ( RequestData pData  )  [protected]
void __stdcall InternetRequest::InternetCallback ( HINTERNET  hInternet,
DWORD_PTR  dwContext,
DWORD  dwInternetStatus,
LPVOID  lpvStatusInformation,
DWORD  dwStatusInformationLength 
) [static, protected]

Callback for wininet status changes.

Parameters:
hInternet Handle to the wininet object that requested the callback
dwContext Client-defined data (the pointer to the InternetRequest object, in our case)
dwInternetStatus Callback stauts
lpvStatusInformation Pointer to additional callback information
dwStatusInformationLength Size of information object

Definition at line 182 of file InternetRequest.cpp.

References OnInternetCallback().

Referenced by OpenSession().

void InternetRequest::OnInternetCallback ( DWORD  dwInternetStatus,
LPVOID  lpvStatusInformation,
DWORD  dwStatusInformationLength 
) [protected]

Called when the request changes status.

Parameters:
dwInternetStatus Callback status
lpvStatusInformation Pointer to additional callback information
dwStatusInformationLength Size of information object

Definition at line 195 of file InternetRequest.cpp.

References m_bInCreation, m_bInRequest, and m_sError.

Referenced by InternetCallback().

bool InternetRequest::OpenSession (  )  [protected]

Opens a wininet session.

Returns:
true if a wininet session was initialized successfully, false if failed

Definition at line 142 of file InternetRequest.cpp.

References CloseAll(), InternetCallback(), m_hSession, and m_sError.

Referenced by InnerDoRequest().

DWORD WINAPI InternetRequest::RequestThreadProc ( LPVOID  lpData  )  [static, protected]

The request worker thread main function.

Parameters:
lpData Pointer to the thread data structure (RequestData in this case)
Returns:
0

Definition at line 282 of file InternetRequest.cpp.

References DoRequest(), and InternetRequest::RequestData::m_pThis.

Referenced by DoRequestThread().


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

Generated on Mon Jun 18 12:40:44 2012 for CC PDF Converter by doxygen 1.6.1