#ifndef HTTP_H #define HTTP_H #include #include #include #include "zlib\zlib.h" #ifdef WIN32 # include #else # ifdef __GNUG__ // most platforms which use GNU C don't extern "C" { // have this in their system header files # endif # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # ifdef __GNUG__ } # endif # ifdef __sgi # include # endif # define INVALID_SOCKET (-1) # define SOCKET_ERROR (-1) # define SOCKET int # define ioctlsocket ioctl # define closesocket close # define Sleep sleep #endif #ifdef WIN32 # define HttpFileFolder "C:\\Program Files\\Http" # define HttpFileCookie "C:\\Program Files\\Http\\Cookies.ini" #else # define HttpFileFolder "/tmp/Http/" # define HttpFileCookie "/tmp/Http/Cookies.ini" #endif #define GetHeader1 "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1\r\nAccept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nConnection: close\r\nCookie: %s\r\n\r\n" #define GetHeader2 "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1\r\nAccept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nConnection: close\r\nReferer: %s\r\nCookie: %s\r\n\r\n" #define PostHeader1 "POST %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20051006 Firefox/1.5.0.1\r\nAccept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nConnection: close\r\nCookie: %s\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\n%s" #define PostHeader2 "POST %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20051006 Firefox/1.5.0.1\r\nAccept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nConnection: close\r\nReferer: %s\r\nCookie: %s\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\n%s" #define USE_GET 1 #define USE_POST 2 #define WEB_ERROR 1 #define MEM_ERROR 2 struct strings { char *str; size_t length; size_t storage; }; //----------------------- //Function Prototypes //----------------------- void strinit(int num, ... ); void strcleanup(int num, ... ); int strappend(struct strings *pStr, char *addthis, int num); int strerase(struct strings *pStr, char *start, char *end); int strassign(struct strings *pStr, char *assignthis, int num); int strinsert(struct strings *pStr, char *loc, char *insertthis, int num); class HTTP { public: struct strings Site, LastPage; HTTP(); ~HTTP(); int HttpRequest(int option, char *Url, char *PostData, char *Referer); void ClearCookies() { strassign(&HttpCookie, "", 0); } void SetProxy(char *Proxy, unsigned short ProxyPort) { strassign(&ProxyName, Proxy, strlen(Proxy)); sockserver.sin_port = htons(ProxyPort); bHostHasChanged = 1; } void ClearProxy() { ProxyName.length = 0; sockserver.sin_port = htons(80); bHostHasChanged = 1; } private: #ifdef WIN32 WSADATA WSAData; #endif struct strings HttpCookie, HttpServer, HttpFilepath, HttpIni, ProxyName, serv; struct sockaddr_in sockserver; SOCKET SocketConn; int bHostHasChanged; char HttpBuff[32768]; int HttpConnect(); void BuildCookies(); void ParseCookies(); }; #endif