rendered paste body#ifndef HTTP_H
#define HTTP_H
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "zlib\zlib.h"
#ifdef WIN32
# include <windows.h>
#else
# ifdef __GNUG__ // most platforms which use GNU C don't
extern "C" { // have this in their system header files
# endif
# include <stdio.h>
# include <stdlib.h>
# include <signal.h>
# include <unistd.h>
# include <strings.h>
# include <fcntl.h>
# include <errno.h>
# include <sys/types.h>
# include <sys/time.h>
# include <sys/socket.h>
# include <sys/ioctl.h>
# include <sys/stat.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <net/if.h>
# include <netdb.h>
# ifdef __GNUG__
}
# endif
# ifdef __sgi
# include <bstring.h>
# 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