#ifndef _HTTP_H #define _HTTP_H #include "Protocol.h" /* Typical Firefox GET request headers: GET / HTTP/1.1 Host: www.waterjustice.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.10) Gecko/20071115 Firefox/2.0.0.10 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*\/*;q=0.5 Accept-Language: en-gb,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive */ //request settings (HTTP11) #define USERAGENT "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.10) Gecko/2007111504 Firefox/2.0.0.10" //#define USERAGENT "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" //#define ACCEPT "text/html;text/plain;" #define ACCEPT "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" #define ACCEPTLANGUAGE "en-gb,en;q=0.5" #define ACCEPTENCODING "" #define ACCEPTCHARSET "ISO-8859-1,utf-8;q=0.7,*;q=0.7" #define KEEPALIVE "300" #define CONNECTION "keep-alive" #define FORMCONTENTTYPE "application/x-www-form-urlencoded; charset=utf-8;" class HTTP: public Protocol { protected: //Response headers : additional HTTP stateful properties (not static as depend on the input stream) enum responseProtocol { unknownResponseProtocol = 0, http1_0, http1_1 } m_responseProtocol; //base HTTP transport header values int m_httpResponseCode; unsigned int m_contentLength; char *m_headerEnd, *m_bodyStart; const char *m_lastModifiedStr; const char *m_location; //Location field. Used in 302 Object Moved bool m_connectionClose; //text - enum combinations const char *m_charSetText; //-> m_charSet Character set (will be transformed to UTF-8) const char *m_contentTypeText; //-> m_contentType Content-Type (used to decide which IR subclass to create) const char *m_contentLanguageText; //-> m_contentLanguage en-GB //Persistent header information that can be sync'd between 2 Protocol instances const char *m_PHPsessionID; const char *m_ASPsessionID; //finalise comms and create IneternetResource, etc. //standard call from virtual finalise() conversationResult charsetDecode(); //always decodes the set to UTF-8 conversationResult contentDecode(); //for chunked transfer encoding (HTTP/1.1) conversationResult createInternetResource(); // **InternetResource (usually HTMLPage) conversationResult updatePersistentData(); //session data etc. cross-Protocol //additional functions for lookups text -> enum compression textCompressionToEnum(const char *compression) const; contentEncoding textContentEncodingToEnum(const char *contentEncoding) const; charSet textCharsetToEnum(const char *charSet) const; ContentType *textContentTypeToEnum(const char *contentTypeText) const; responseProtocol textResponseProtocolToEnum(const char *protocolText) const; contentLanguage textContentLanguageToEnum(const char *language) const; //this class is abstract and can only be created by derived classes in the constructor HTTP(TIPsDatabase *_db, DomainConnection *_dc, InternetURIRequest *_ir, InternetResource **_resource, char *_buffer, const size_t _buffersize, PersistentData *_permData, const bool _manageBuffer = false); friend class Protocol; virtual const char *generateRequest() const; const bool checkForEOS(); virtual conversationResult finalise(); public: //accessors (note that the private members point to a malloc'd area that will be freed: caller must strdupCheck()) const char *location() const {return m_location;} //needs to be strdupCheck() const int httpResponseCode() const {return m_httpResponseCode;} //primitive, no dup required const bool connectionClose() const {return m_connectionClose;} //primitive, no dup required virtual const char *description() const {return "HTTP Protocol";} //const, no dup required //DomainConnectionEventSink events passed through to DC void connectionClosedOnRead(const size_t bufsize); void finishedRead(const int bytes); }; #endif