00001 #ifndef __HTTPCORE__
00002 #define __HTTPCORE__
00003 #include "Build.h"
00004 #include "HTTP.h"
00005 #include "Authentication/base64.h"
00006 #include "Authentication/ntlm.h"
00007 #include "Authentication/digest.h"
00008
00009 #ifdef __WIN32__RELEASE__
00010 #include <sys/timeb.h>
00011 #include <process.h>
00012 #include <time.h>
00013 #include <wininet.h>
00014 #pragma comment(lib, "ws2_32.lib")
00015 #else
00016 #include <stdlib.h>
00017 #include <unistd.h>
00018 #include <fcntl.h>
00019 #include <sys/socket.h>
00020 #include <sys/ioctl.h>
00021 #include <netinet/in.h>
00022 #include <arpa/inet.h>
00023 #include <pthread.h>
00024 #include <ctype.h>
00025 #include <time.h>
00026 #include <sys/timeb.h>
00027 #define FILETIME time_t
00028 #endif
00029
00030 #ifdef _OPENSSL_SUPPORT_
00031
00032 #include <openssl/crypto.h>
00033 #include <openssl/x509.h>
00034 #include <openssl/pem.h>
00035 #include <openssl/ssl.h>
00036 #include <openssl/err.h>
00037 #ifdef __WIN32__RELEASE__
00038 #pragma comment(lib, "libeay32.lib")
00039 #pragma comment(lib, "ssleay32.lib")
00040 #endif
00041 #endif
00042
00043
00044
00045
00046
00047 #define MAX_OPEN_CONNECTIONS 512 //Our Connection table is able to handle 512 concurrent connections
00048 #define PURGETIME 20 //20 secconds
00049 #define MAX_OPEN_CONNETIONS_AGAINST_SAME_HOST 10 //Do not allow more concurrent connections against the same server/port
00050 #define BUFFSIZE 4096 //default read buffer
00051 #define TARGET_FREE 0
00052 #define MAX_INACTIVE_CONNECTION 10000000 *PURGETIME
00053 #define MAXIMUM_OPENED_HANDLES 1024
00054
00055
00056
00057
00058
00059 typedef struct _HTTPmapping_struct_
00060 {
00061 int assigned;
00062 char *BufferedPtr;
00063 unsigned long MemoryLenght;
00064 char BufferedFileName[MAX_PATH];
00065 #ifdef __WIN32__RELEASE__
00066 HANDLE hTmpFilename;
00067 HANDLE hMapping;
00068 #else
00069 int hTmpFilename;
00070 #endif
00071 } HTTPIOMapping, *PHTTPIOMapping;
00072
00073
00074
00075 typedef struct conexiones {
00076 long target;
00077 char targetDNS[256];
00078 int port;
00079 int NeedSSL;
00080 unsigned int datasock;
00081 struct sockaddr_in webserver;
00082 #ifdef _OPENSSL_SUPPORT_
00083 SSL_CTX * ctx;
00084 SSL * ssl;
00085 #endif
00086 FILETIME tlastused;
00087 CRITICAL_SECTION lock;
00088 unsigned int NumberOfRequests;
00089 unsigned int io;
00090 int PENDING_PIPELINE_REQUESTS;
00091 PHTTP_DATA *PIPELINE_Request;
00092 unsigned long *PIPELINE_Request_ID;
00093 int id;
00094 unsigned int BwLimit;
00095 #ifdef __WIN32__RELEASE__
00096 int ThreadID;
00097 #else
00098 pthread_t ThreadID;
00099 #endif
00100 int ConnectionAgainstProxy;
00101 int ProxyMethod;
00102 } STABLISHED_CONNECTION;
00103
00104
00110 typedef struct _hhandle{
00111 long target;
00112 char targetDNS[256];
00113 int port;
00114 #ifdef __WIN32__RELEASE__
00115 int ThreadID;
00116 #else
00117 pthread_t ThreadID;
00118 #endif
00119 int NeedSSL;
00120 int version;
00121 char *AdditionalHeader;
00122 char *Cookie;
00123 char *UserAgent;
00124 char *DownloadBwLimit;
00125 STABLISHED_CONNECTION *conexion;
00126 char LastRequestedUri[512];
00127 char *LastAuthenticationString;
00128 char *ProxyHost;
00129 char *ProxyPort;
00130 char *lpProxyUserName;
00131 char *lpProxyPassword;
00132 } *PHHANDLE;
00133
00134
00135 int HTTPCoreCancelHTTPRequest(HTTPHANDLE HTTPHandle, int what);
00136 void FreeConnection(STABLISHED_CONNECTION *connection);
00137 static void *CleanConnectionTable(void *foo);
00138 static unsigned int GetNumberOfConnectionsAgainstTarget(PHHANDLE HTTPHandle);
00139 static int GetFirstIdleConnectionAgainstTarget(PHHANDLE HTTPHandle);
00140 static int GetFirstUnUsedConnectionAgainstTarget(PHHANDLE HTTPHandle);
00141 int RemovePipeLineRequest(STABLISHED_CONNECTION *connection);
00142 static unsigned long AddPipeLineRequest(STABLISHED_CONNECTION *connection, PHTTP_DATA request);
00143 static STABLISHED_CONNECTION *GetSocketConnection(PHHANDLE HTTPHandle, PHTTP_DATA request, unsigned long *id);
00144 PHTTP_DATA DispatchHTTPRequest(PHHANDLE HTTPHandle,PHTTP_DATA request);
00145 int InitHTTPApiCore(void);
00146 void CloseHTTPApiCore(void);
00147 PHTTP_DATA InitHTTPData(char *header, char *postdata);
00148 void FreeHTTPData(HTTP_DATA *data);
00149
00150
00151 #endif
00152