⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webserver.h

📁 电驴的MAC源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
//// This file is part of the aMule Project.//// Copyright (c) 2003-2008 Kry ( elkry@users.sourceforge.net / http://www.amule.org )// Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )// Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )//// Any parts of this program derived from the xMule, lMule or eMule project,// or contributed by third-party developers are copyrighted by their// respective authors.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.// // You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA//#ifndef WEBSERVER_H#define WEBSERVER_H#ifdef WITH_LIBPNG	#include <png.h>#endif#include "WebInterface.h"#include "KnownFile.h"#include "RLE.h"#include "OtherStructs.h"#ifdef ENABLE_UPNP#	include "UPnPBase.h"#endif#include <wx/datetime.h>  // For DownloadFile::wxtLastSeenComplete//class TransferredData;class CWSThread;class CWebSocket;class CMD4Hash;#define SESSION_TIMEOUT_SECS	300	// 5 minutes session expiration#define SHORT_FILENAME_LENGTH	40	// Max size of file name.////uint8 GetHigherPrio(uint32 prio, bool autoprio);//uint8 GetHigherPrioShared(uint32 prio, bool autoprio);//uint8 GetLowerPrio(uint32 prio, bool autoprio);//uint8 GetLowerPrioShared(uint32 prio, bool autoprio);wxString _SpecialChars(wxString str);class CEC_PartFile_Tag;class CEC_SharedFile_Tag;class CEC_UpDownClient_Tag;class CEC_SearchFile_Tag;class CProgressImage;class CEC_KadNode_Tag;class DownloadFile {	public:		wxString	sFileName;		uint8		nFileStatus;		uint64		lFileSize;		uint64		lFileCompleted;		uint64		lFileTransferred;		unsigned long	lFileSpeed;		long		lSourceCount;		long		lNotCurrentSourceCount;		long		lTransferringSourceCount;		long		lSourceCountA4AF;		double		fCompleted;		uint32		lFilePrio;		bool		bFileAutoPriority;		wxString	sFileHash;		wxString	sED2kLink;		uint8		nCat;		wxDateTime	wxtLastSeenComplete;		CMD4Hash	nHash;				CProgressImage *m_Image;		PartFileEncoderData m_Encoder;		std::vector<Gap_Struct> m_ReqParts;		// container require this				static class DownloadFileInfo *GetContainerInstance();		DownloadFile(CEC_PartFile_Tag *);		void ProcessUpdate(CEC_PartFile_Tag *);		CMD4Hash ID() { return nHash; }};class SharedFile {	public:		wxString	sFileName;		uint64		lFileSize;		uint64		nFileTransferred;		uint64		nFileAllTimeTransferred;		uint16		nFileRequests;		uint32		nFileAllTimeRequests;		uint16		nFileAccepts;		uint32		nFileAllTimeAccepts;		uint8		nFilePriority;		bool		bFileAutoPriority;		wxString 	sFileHash;		wxString	sED2kLink;		CMD4Hash	nHash;		static class SharedFileInfo *GetContainerInstance();		SharedFile(CEC_SharedFile_Tag *);		void ProcessUpdate(CEC_SharedFile_Tag *);		CMD4Hash ID() { return nHash; }};class ServerEntry {	public:		wxString	sServerName;		wxString	sServerDescription;		uint32		nServerIP;		uint16		nServerPort;		wxString	sServerIP;		int		nServerUsers;		int		nServerMaxUsers;		int		nServerFiles;			static class ServersInfo *GetContainerInstance();		uint32 ID() { return nServerIP; }};class UploadFile {	public:		wxString  sUserName;		uint32 nTransferredUp;		uint32 nTransferredDown;		uint32 nSpeed;		//		// Don't need filename - sharedfiles already have it		CMD4Hash  nHash;		UploadFile(CEC_UpDownClient_Tag *tag);				static class UploadsInfo *GetContainerInstance();		CMD4Hash ID() { return nHash; }};class SearchFile {	public:		wxString sFileName;		unsigned long lFileSize;		CMD4Hash  nHash;		wxString  sHash;		long lSourceCount;		bool bPresent;				SearchFile(CEC_SearchFile_Tag *);				void ProcessUpdate(CEC_SearchFile_Tag *);		static class SearchInfo *GetContainerInstance();		CMD4Hash ID() { return nHash; }};/*! * T - type of items in container */template <class T>class ItemsContainer {	protected:		CamulewebApp *m_webApp;		std::list<T> m_items;			void EraseAll()		{			m_items.erase(m_items.begin(), m_items.end());		}	public:		ItemsContainer(CamulewebApp *webApp)		{			m_webApp = webApp;		}		virtual ~ItemsContainer() { }				int ItemCount()		{			return m_items.size();		}						T *AddItem(T &item)		{			m_items.push_back(item);			T *real_ptr = &(m_items.back());			return real_ptr;		}		/*!		 * Re-query server: refresh all dataset		 */		virtual bool ReQuery() = 0;		typedef typename std::list<T>::iterator ItemIterator;		ItemIterator GetBeginIterator()		{			return m_items.begin();		}		ItemIterator GetEndIterator()		{			return m_items.end();		}};/*! * T - type of items in container * I - type of item ID * G - type of tag in EC */template <class T, class G, class I>class UpdatableItemsContainer : public ItemsContainer<T> {	protected:		// need duplicate list with a map, so check "do we already have"		// will take O(log(n)) instead of O(n)		// map will contain pointers to items in list 		std::map<I, T *> m_items_hash;	public:		UpdatableItemsContainer(CamulewebApp *webApp) : ItemsContainer<T>(webApp)		{		}				T *AddItem(T &item)		{			T *real_ptr = ItemsContainer<T>::AddItem(item);			m_items_hash[item.ID()] = real_ptr;			return real_ptr;		}			T *GetByID(I id)		{			// avoid creating nodes			return m_items_hash.count(id) ? m_items_hash[id] : NULL;		}		/*!		 * Process answer of update request, create list of new items for		 * full request later. Also remove items that no longer exist in core		 */		void ProcessUpdate(const CECPacket *reply, CECPacket *full_req, int req_type)		{			std::set<I> core_files;			for (int i = 0;i < reply->GetTagCount();i++) {				G *tag = (G *)reply->GetTagByIndex(i);						core_files.insert(tag->ID());				if ( m_items_hash.count(tag->ID()) ) {					T *item = m_items_hash[tag->ID()];					item->ProcessUpdate(tag);				} else {					full_req->AddTag(CECTag(req_type, tag->ID()));				}			}			std::list<I> del_ids;			for(typename std::list<T>::iterator j = this->m_items.begin(); j != this->m_items.end(); j++) {				if ( core_files.count(j->ID()) == 0 ) {					// item may contain data that need to be freed externally, before					// dtor is called and memory freed										T *real_ptr = &*j;					this->ItemDeleted(real_ptr);										del_ids.push_back(j->ID());				}			}			for(typename std::list<I>::iterator j = del_ids.begin(); j != del_ids.end(); j++) {				m_items_hash.erase(*j);				for(typename std::list<T>::iterator k = this->m_items.begin(); k != this->m_items.end(); k++) {					if ( *j == k->ID() ) {						this->m_items.erase(k);						break;					}				}			}		}				void ProcessFull(const CECPacket *reply)		{			for (int i = 0;i < reply->GetTagCount();i++) {				G *tag = (G *)reply->GetTagByIndex(i);				// initialize item data from EC tag				T item(tag);				T *real_ptr = AddItem(item);				// initialize any external data that may depend on this item				this->ItemInserted(real_ptr);			}		}				bool DoRequery(int cmd, int tag)		{			CECPacket req_sts(cmd, EC_DETAIL_UPDATE);					//			// Phase 1: request status			const CECPacket *reply = this->m_webApp->SendRecvMsg_v2(&req_sts);			if ( !reply ) {				return false;			}						//			// Phase 2: update status, mark new files for subsequent query			CECPacket req_full(cmd);					ProcessUpdate(reply, &req_full, tag);					delete reply;					// Phase 3: request full info about files we don't have yet			if ( req_full.GetTagCount() ) {				reply = this->m_webApp->SendRecvMsg_v2(&req_full);				if ( !reply ) {					return false;				}				ProcessFull(reply);					delete reply;			}			return true;		}				virtual void ItemDeleted(T *) { }		virtual void ItemInserted(T *) { }};class UploadsInfo : public ItemsContainer<UploadFile> {	public:		// can be only one instance.		static UploadsInfo *m_This;		UploadsInfo(CamulewebApp *webApp);		virtual bool ReQuery();};class ServersInfo : public ItemsContainer<ServerEntry> {	public:		// can be only one instance.		static ServersInfo *m_This;				ServersInfo(CamulewebApp *webApp);		virtual bool ReQuery();};class SharedFileInfo : public UpdatableItemsContainer<SharedFile, CEC_SharedFile_Tag, CMD4Hash> {	public:		// can be only one instance.		static SharedFileInfo *m_This;		SharedFileInfo(CamulewebApp *webApp);		virtual bool ReQuery();};class SearchInfo : public UpdatableItemsContainer<SearchFile, CEC_SearchFile_Tag, CMD4Hash> {	public:		static SearchInfo *m_This;				SearchInfo(CamulewebApp *webApp);				virtual bool ReQuery();};class CImageLib;class DownloadFileInfo : public UpdatableItemsContainer<DownloadFile, CEC_PartFile_Tag, CMD4Hash> {		CImageLib *m_ImageLib;				// parameters of progress images		wxString m_Template;		int m_width, m_height;	public:		// can be only one instance.		static DownloadFileInfo *m_This;				DownloadFileInfo(CamulewebApp *webApp, CImageLib *imlib);				void LoadImageParams(wxString &tpl, int width, int height);				virtual bool ReQuery();		// container requirements		void ItemInserted(DownloadFile *item);		void ItemDeleted(DownloadFile *item);};class CAnyImage {	protected:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -