00001 // 00002 // HttpRequest.h 00003 // 00004 // Copyright (c) Shareaza Development Team, 2002-2005. 00005 // This file is part of SHAREAZA (www.shareaza.com) 00006 // 00007 // Shareaza is free software; you can redistribute it 00008 // and/or modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 of 00010 // the License, or (at your option) any later version. 00011 // 00012 // Shareaza is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with Shareaza; if not, write to the Free Software 00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 // 00021 00022 #pragma once 00023 00024 class CBuffer; 00025 00026 00027 class CHttpRequest 00028 { 00029 // Constructions 00030 public: 00031 CHttpRequest(); 00032 virtual ~CHttpRequest(); 00033 00034 // Operations 00035 public: 00036 void Clear(); 00037 public: 00038 CString GetURL(); 00039 BOOL SetURL(LPCTSTR pszURL); 00040 void SetUserAgent(LPCTSTR pszUserAgent); 00041 void AddHeader(LPCTSTR pszKey, LPCTSTR pszValue); 00042 void SetPostData(LPCVOID pBody, DWORD nBody); 00043 void LimitContentLength(DWORD nLimit); 00044 void SetNotify(HWND hWnd, UINT nMsg, WPARAM wParam = 0); 00045 public: 00046 int GetStatusCode(); 00047 BOOL GetStatusSuccess(); 00048 CString GetStatusString(); 00049 CString GetHeader(LPCTSTR pszName); 00050 CString GetResponseString(UINT nCodePage = CP_UTF8); 00051 CBuffer* GetResponseBuffer(); 00052 BOOL InflateResponse(); 00053 public: 00054 BOOL Execute(BOOL bBackground); 00055 BOOL IsPending(); 00056 BOOL IsFinished(); 00057 void Cancel(); 00058 00059 // Data 00060 protected: 00061 CCriticalSection m_pSection; 00062 HANDLE m_hThread; 00063 HINTERNET m_hInternet; 00064 BOOL m_bCancel; 00065 protected: 00066 CString m_sURL; 00067 CString m_sUserAgent; 00068 CString m_sRequestHeaders; 00069 DWORD m_nLimit; 00070 int m_nStatusCode; 00071 CString m_sStatusString; 00072 CBuffer* m_pPost; 00073 CBuffer* m_pResponse; 00074 CMapStringToString m_pResponseHeaders; 00075 protected: 00076 HWND m_hNotifyWnd; 00077 UINT m_nNotifyMsg; 00078 WPARAM m_nNotifyParam; 00079 00080 // Implementation 00081 protected: 00082 static UINT ThreadStart(LPVOID lpParameter); 00083 protected: 00084 int Run(); 00085 void RunRequest(); 00086 void RunResponse(HINTERNET hURL); 00087 00088 // Utilities 00089 public: 00090 static void CloseThread(HANDLE* phThread, LPCTSTR pszName); 00091 };