www.pudn.com > NetTest2nd.rar > m5httpdown.h
#ifndef _M5_HTTP_DOWN_H_ #include#include #include "socketsengine.h" #include "uinotifier.h" #include "m5httpdownnotifier.h" #define HTTP_WEB_PORT 80 #define HTTP_TEMP_BUF_LEN 120 #define HTTP_SEND_BUF_LEN 256 #define HTTP_DOWN_CMWAP 0 #define HTTP_DOWN_CMNET 1 _LIT8(KHttpRespOK, "200 OK") ; _LIT8(KHttpCMWapHdrFileLen, "Content-length: ") ; _LIT8(KHttpCMNetHdrFileLen, "Content-Length: ") ; _LIT8(KHttpClip, "/") ; _LIT8(KHttpHdrDiv, "\r\n") ; _LIT8(KHttpHdrEnd, "\r\n\r\n") ; _LIT8(KHttpPrefix, "http://") ; _LIT8(KHttpsPrefix, "https://") ; _LIT8(KHttpCommonGet1, "GET ") ; _LIT8(KHttpCommonGet2, " HTTP/1.1\r\nUser-Agent: Nokia 7610\r\nHost: ") ; _LIT8(KHttpCommonGet3, ":") ; _LIT8(KHttpCommonGet4, "\r\nAccept: */*\r\nConnection: Keep-Alive\r\n\r\n") ; _LIT8(KHttpResumeGet1, "GET ") ; _LIT8(KHttpResumeGet2, " HTTP/1.1\r\nUser-Agent: Nokia 7610\r\nHost: ") ; _LIT8(KHttpResumeGet3, ":") ; _LIT8(KHttpResumeGet4, "\r\nAccept: */*\r\nRANGE: bytes=") ; _LIT8(KHttpResumeGet5, "-\r\nConnection: Keep-Alive\r\n\r\n") ; class CM5HttpDown : public CBase, public MUINotifier { protected: // socket data TInt m_down_type ; CSocketsEngine * m_sock_eng ; TBool m_running ; TBool m_is_first_resp ; TInt m_web_port ; TInt m_total_bytes ; TInt m_recv_bytes; TBuf8 m_send_buf ; TBuf8 m_web_addr ; TBuf8 m_web_fname ; M5HttpDownNotifier& m_m5_notifier ; public: // MUINotifier implements void PrintNotify(const TDesC& aMessage, TUint aAttributes = 0) ; void RecvNotify(const TDesC8& aMessage) ; void ErrorNotify(const TDesC& aErrMessage, TInt aErrCode) ; void SetStatus(const TDesC& aStatus) ; protected: TInt Str2Int(const TDesC8 & s) ; TBool CheckRecv(const TDesC8& recv_buf) ; TBool ParseUri(TDesC8& uri, TDes8& web_addr, TDes8& web_fname, TInt& web_port) ; TBool ParseWebFileInfo(const TDesC8& recv_buf, TInt& total_length, TInt& jump_len) ; TBool GetRespField(const TDesC8& recv_buf, TDesC8& field_name, TDesC8& end_flag, TDes8& res) ; TBool InitSock(TDesC8& server_name, TInt server_port) ; TBool SendReq(TDesC8& req_str) ; TBool CloseSock() ; private: CM5HttpDown(M5HttpDownNotifier & m5_notifier) ; void ConstructL() ; public: ~CM5HttpDown() ; static CM5HttpDown * NewL(M5HttpDownNotifier& m5_notifier) ; static CM5HttpDown * NewLC(M5HttpDownNotifier& m5_notifier) ; TBool IsRunning() {return m_running ; } TInt HttpTotalSize() { return m_total_bytes ; } TInt HttpRecvSize() { return m_recv_bytes ; } TBool HttpConnPorxy(TDesC8& uri, TInt down_type = HTTP_DOWN_CMWAP) ; TBool HttpDown(TDesC8& uri, TInt recv_bytes = 0) ; TBool HttpStopDown() ; } ; #endif