#include "IoFunctions.h"
#include "Threading.h"
#include "CallBack.h"
#include "Modules/Encoding_Chunked.h"
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_CONNECTION * | GetSocketConnection (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_CONNECTION * | Connection_Table = NULL |
static CRITICAL_SECTION | lock |
unsigned long | PIPELINE_Request_ID |
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.
connection | CONEXION struct returned by a previous call to GetSocketConnection | |
request | Pointer to a request struct generated by SendHTTPRequest() |
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.
unused | unused (added for compatibility with win32 CreateThread function). |
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.
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.
HTTPHandle | Handle to the remote host. | |
request | struct that stores both header and post data that will be delivered to the remote HTTP Host. |
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).
connection | Pointer to a CONEXION struct |
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().
void FreeHTTPData | ( | HTTP_DATA * | data | ) |
This function deallocates the memory of an an HTTP_DATA struct.
data | pointer to an HTTP_DATA struct allocated by a previous call to InitHTTPData(). |
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.
HTTPHandle | Connection handle. |
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.
HTTPHandle | Currently ignored. |
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.
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. |
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().
int HTTPCoreCancelHTTPRequest | ( | HTTPHANDLE | HTTPHandle, | |
int | what | |||
) |
This function is used to clean the connection struct and cancel I/O request.
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. |
Definition at line 41 of file HTTPCore.cpp.
References _hhandle::conexion, conexiones::datasock, lock, LockMutex(), conexiones::NumberOfRequests, and UnLockMutex().
Referenced by CancelHttpRequest().
int InitHTTPApiCore | ( | void | ) |
This function is used to start the HTTP Core Engine and must be called only once.
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.
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. |
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.
connection | CONEXION struct returned by a previous call to GetSocketConnection. From this connection the first added request struct will be removed (FIFO) |
Definition at line 247 of file HTTPCore.cpp.
Referenced by FreeConnection(), and ReadHTTPResponseData().
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 |