C:/fscan/HTTPCore/HTTPCore.cpp File Reference

#include "IoFunctions.h"
#include "Threading.h"
#include "CallBack.h"
#include "Modules/Encoding_Chunked.h"

Include dependency graph for HTTPCore.cpp:

Go to the source code of this file.

Functions

int HTTPCoreCancelHTTPRequest (HTTPHANDLE HTTPHandle, int what)
 This function is used to clean the connection struct and cancel I/O request.
void FreeConnection (STABLISHED_CONNECTION *connection)
 This function is used to clean the status of a connection struct when the conexion socket is closed or when there is a problem reading the HTTP stream (like timeouts).
static void * CleanConnectionTable (void *unused)
 This function analyzes and cleans the internal connection table every 5 seconds. All inactive connections are purged.
static int GetFirstIdleConnectionAgainstTarget (PHHANDLE HTTPHandle)
 This function checks the connection table searching for a free and inactive connection against the remote host.
static int GetFirstUnUsedConnectionAgainstTarget (PHHANDLE HTTPHandle)
 This function checks the connection table searching for the first unused connection.
int RemovePipeLineRequest (STABLISHED_CONNECTION *connection)
 This function Adds a pending request struct to the connection pool.
static unsigned long AddPipeLineRequest (STABLISHED_CONNECTION *connection, PHTTP_DATA request)
 This function is the method for adding a new pending HTTP Request to the connection Pool. This added request will be sent to the server outside this function.
static STABLISHED_CONNECTIONGetSocketConnection (PHHANDLE HTTPHandle, PHTTP_DATA request, unsigned long *id)
 This function returns a CONEXION struct with initialized sockets. If the connection was previously initialized that struct will be resused.
PHTTP_DATA DispatchHTTPRequest (PHHANDLE HTTPHandle, PHTTP_DATA request)
int InitHTTPApiCore (void)
 This function is used to start the HTTP Core Engine and must be called only once.
void CloseHTTPApiCore (void)
 This function stops the HTTP Core Engine.
PHTTP_DATA InitHTTPData (char *header, char *postdata)
 This function Initializes an HTTP_DATA struct with the headers and and data sent or returned by a client or an http server.
void FreeHTTPData (HTTP_DATA *data)
 This function deallocates the memory of an an HTTP_DATA struct.

Variables

static HANDLE FreeConnectionHandle
static STABLISHED_CONNECTIONConnection_Table = NULL
static CRITICAL_SECTION lock
unsigned long PIPELINE_Request_ID


Function Documentation

static unsigned long AddPipeLineRequest ( STABLISHED_CONNECTION connection,
PHTTP_DATA  request 
) [static]

This function is the method for adding a new pending HTTP Request to the connection Pool. This added request will be sent to the server outside this function.

Parameters:
connection CONEXION struct returned by a previous call to GetSocketConnection
request Pointer to a request struct generated by SendHTTPRequest()
Returns:
This function returns the ID of the added Pending pipelined request from the server. This returned ID value is needed by SendRawHTTPRequest() to known when the new response is ready for reading

Definition at line 278 of file HTTPCore.cpp.

References conexiones::id, conexiones::PENDING_PIPELINE_REQUESTS, conexiones::PIPELINE_Request, conexiones::PIPELINE_Request_ID, and PIPELINE_Request_ID.

Referenced by GetSocketConnection().

static void* CleanConnectionTable ( void *  unused  )  [static]

This function analyzes and cleans the internal connection table every 5 seconds. All inactive connections are purged.

Parameters:
unused unused (added for compatibility with win32 CreateThread function).
Note:
this function is only used internally by HTTPCore Module.

The connections are threated as inactive if the connection is unused for more than MAX_INACTIVE_CONNECTION seconds. This value can be modified in the source code.

The connection must have the io flag inaactive (not in use).

Definition at line 130 of file HTTPCore.cpp.

void CloseHTTPApiCore ( void   ) 

This function stops the HTTP Core Engine.

Note:
this function is exported but must be called only from the HTTP.cpp and must not be called manually.

As CallBacks table will be erased (This also include user registered callbacks)

Definition at line 578 of file HTTPCore.cpp.

Referenced by CloseHTTPApi().

PHTTP_DATA DispatchHTTPRequest ( PHHANDLE  HTTPHandle,
PHTTP_DATA  request 
)

This function gets an stablished connection against the remote host, sends the generated HTTP the request and Waits for a response. Callbacks are called at this point.

Parameters:
HTTPHandle Handle to the remote host.
request struct that stores both header and post data that will be delivered to the remote HTTP Host.
Returns:
: returns a PHTTP_DATA struct however, if the remote host can not be reached, NULL is returned instead.
Note:
If the remote host does not return data, and empty struct is returned.

This function shouldnt be called remotely as for example, does not suport authentication. Instead, use SendHTTPRequest() exported at the public interface.

Registered CallBacks are called from this point.

Definition at line 455 of file HTTPCore.cpp.

Referenced by SendHttpRequest().

void FreeConnection ( STABLISHED_CONNECTION connection  ) 

This function is used to clean the status of a connection struct when the conexion socket is closed or when there is a problem reading the HTTP stream (like timeouts).

Parameters:
connection Pointer to a CONEXION struct
Note:
All the internal counters are reset and the first pipelined request is removed.

If there are pending pipelined requests this function will also reconnect the socket and send those requests to the server

Definition at line 67 of file HTTPCore.cpp.

References conexiones::datasock, _data::Header, conexiones::io, conexiones::NeedSSL, conexiones::NumberOfRequests, conexiones::PENDING_PIPELINE_REQUESTS, conexiones::PIPELINE_Request, conexiones::port, RemovePipeLineRequest(), SendHTTPRequestData(), StablishConnection(), conexiones::target, TARGET_FREE, and conexiones::tlastused.

Referenced by GetSocketConnection(), and ReadHTTPResponseData().

Here is the call graph for this function:

void FreeHTTPData ( HTTP_DATA data  ) 

This function deallocates the memory of an an HTTP_DATA struct.

Parameters:
data pointer to an HTTP_DATA struct allocated by a previous call to InitHTTPData().
Note:
This function also tries to match if the assigned memory to HTTP_DATA->Data is a memory mapping. If so, the file mapping will be removed

Definition at line 652 of file HTTPCore.cpp.

Referenced by FreeRequest(), and ParseReturnedBuffer().

static int GetFirstIdleConnectionAgainstTarget ( PHHANDLE  HTTPHandle  )  [static]

This function checks the connection table searching for a free and inactive connection against the remote host.

Parameters:
HTTPHandle Connection handle.
Returns:
Returns an index to the CONEXION item in the connection table.
Note:
This function is only used internally by HTTPCore Module.

If no connection matches, -1 is returned.

Definition at line 206 of file HTTPCore.cpp.

References Connection_Table, _hhandle::port, conexiones::port, _hhandle::target, conexiones::target, and _hhandle::ThreadID.

Referenced by GetSocketConnection().

static int GetFirstUnUsedConnectionAgainstTarget ( PHHANDLE  HTTPHandle  )  [static]

This function checks the connection table searching for the first unused connection.

Parameters:
HTTPHandle Currently ignored.
Returns:
Returns an index to the CONEXION item in the connection table.
Note:
This function is only used internally by HTTPCore Module.

If no free connection is found, -1 is returned.

Definition at line 229 of file HTTPCore.cpp.

References Connection_Table, and TARGET_FREE.

Referenced by GetSocketConnection().

static STABLISHED_CONNECTION* GetSocketConnection ( PHHANDLE  HTTPHandle,
PHTTP_DATA  request,
unsigned long *  id 
) [static]

This function returns a CONEXION struct with initialized sockets. If the connection was previously initialized that struct will be resused.

Parameters:
HTTPHandle handle to the remote host
request To support pipelining, This function adds the request to the connection pool.
id pointer to a long that will store the id asigned to the request. Each request have a unique incremental ID.
Returns:
Initilized CONEXION struct against the remote host.
Note:
This internal function manages the CONEXION sockets and stablish connections when needed .

If the remote target cannot be reached or there are no free sockets the function returns null.

Definition at line 306 of file HTTPCore.cpp.

References AddPipeLineRequest(), conexiones::BwLimit, _hhandle::conexion, Connection_Table, conexiones::ConnectionAgainstProxy, _hhandle::DownloadBwLimit, FreeConnection(), GetFirstIdleConnectionAgainstTarget(), GetFirstUnUsedConnectionAgainstTarget(), conexiones::id, conexiones::io, lock, LockMutex(), _hhandle::NeedSSL, conexiones::NeedSSL, conexiones::NumberOfRequests, _hhandle::port, conexiones::port, _hhandle::ProxyHost, _hhandle::ProxyPort, StablishConnection(), _hhandle::target, conexiones::target, _hhandle::targetDNS, _hhandle::ThreadID, conexiones::ThreadID, and UnLockMutex().

Here is the call graph for this function:

int HTTPCoreCancelHTTPRequest ( HTTPHANDLE  HTTPHandle,
int  what 
)

This function is used to clean the connection struct and cancel I/O request.

Parameters:
HTTPHandle Handle of the remote connection.
what Cancel only the current request HTTP_REQUEST_CURRENT or blocks all connections against the remote HTTP host with HTTP_REQUEST_ALL.
Note:
This function is needed when for example a CONNECT call is sent against a remote HTTP proxy server.

Definition at line 41 of file HTTPCore.cpp.

References _hhandle::conexion, conexiones::datasock, lock, LockMutex(), conexiones::NumberOfRequests, and UnLockMutex().

Referenced by CancelHttpRequest().

Here is the call graph for this function:

int InitHTTPApiCore ( void   ) 

This function is used to start the HTTP Core Engine and must be called only once.

Note:
this function is exported but must be called only from HTTP.cpp and must not be called manually.

Under Win32, WSA Sockets are also initialized.

Supported Core Callbacks must be registered here. Example Chunk encoding, gzip compression..

Definition at line 517 of file HTTPCore.cpp.

Referenced by InitHTTPApi().

PHTTP_DATA InitHTTPData ( char *  header,
char *  postdata 
)

This function Initializes an HTTP_DATA struct with the headers and and data sent or returned by a client or an http server.

Parameters:
header pointer to an string that contains HTTP headers. This value can be null
postdata pointer to an string that contains HTTP data. This value can be null.
Returns:
pointer to an initialized HTTP_DATA struct.
Note:
if header or postdata is null and empy string will be allocated.

Definition at line 622 of file HTTPCore.cpp.

Referenced by ReadHTTPResponseData(), and SendHttpRequest().

int RemovePipeLineRequest ( STABLISHED_CONNECTION connection  ) 

This function Adds a pending request struct to the connection pool.

Parameters:
connection CONEXION struct returned by a previous call to GetSocketConnection. From this connection the first added request struct will be removed (FIFO)
Returns:
This function returns the number of pending pipelined request.

Definition at line 247 of file HTTPCore.cpp.

Referenced by FreeConnection(), and ReadHTTPResponseData().


Variable Documentation

STABLISHED_CONNECTION* Connection_Table = NULL [static]

Definition at line 28 of file HTTPCore.cpp.

Referenced by GetFirstIdleConnectionAgainstTarget(), GetFirstUnUsedConnectionAgainstTarget(), and GetSocketConnection().

HANDLE FreeConnectionHandle [static]

Definition at line 25 of file HTTPCore.cpp.

CRITICAL_SECTION lock [static]

Definition at line 29 of file HTTPCore.cpp.

Referenced by GetSocketConnection(), and HTTPCoreCancelHTTPRequest().

unsigned long PIPELINE_Request_ID

Definition at line 30 of file HTTPCore.cpp.

Referenced by AddPipeLineRequest().


Generated on Sun Jan 18 00:32:04 2009 for Fast HTTP Vulnerability Scanner by  doxygen 1.5.4