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

📄 webinterface.cpp

📁 电驴的MAC源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//// This file is part of the aMule Project.//  // Copyright (c) 2004-2008 shakraw ( shakraw@users.sourceforge.net )// Copyright (c) 2003-2008 Kry ( elkry@sourceforge.net / http://www.amule.org )// Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )//// 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//#ifdef HAVE_CONFIG_H	#include "config.h"	// For VERSION and ENABLE_NLS#endif#include <wx/stdpaths.h>#ifdef __WXMAC__	#include <CoreFoundation/CFBundle.h> // Do_not_auto_remove	#include <ApplicationServices/ApplicationServices.h> // Do_not_auto_remove	#include <wx/mac/corefoundation/cfstring.h> // Do_not_auto_remove#endif#include <ec/cpp/ECFileConfig.h>	// Needed for CECFileConfig#include <common/MD5Sum.h>#include "WebServer.h"#include <wx/apptrait.h>#include <wx/socket.h>#ifdef ENABLE_NLS#	include <libintl.h>#endif/* * Socket handling in wxBase (same as amuled) *  */class CSocketSet {		int m_count;		int m_fds[FD_SETSIZE], m_fd_idx[FD_SETSIZE];		GSocket *m_gsocks[FD_SETSIZE];				fd_set m_set;    public:        CSocketSet();        void AddSocket(GSocket *);        void RemoveSocket(GSocket *);        void FillSet(int &max_fd);                void Detected(void (GSocket::*func)());                fd_set *Set() { return &m_set; }};CSocketSet::CSocketSet(){    m_count = 0;    for(int i = 0; i < FD_SETSIZE; i++) {        m_fds[i] = 0;        m_fd_idx[i] = 0xffff;        m_gsocks[i] = 0;    }}void CSocketSet::AddSocket(GSocket *socket){    wxASSERT(socket);        int fd = socket->m_fd;    if ( fd == -1 ) {        return;    }    wxASSERT( (fd >= 0) && (fd < FD_SETSIZE) );        if ( m_gsocks[fd] ) {        return;    }    m_fds[m_count] = fd;    m_fd_idx[fd] = m_count;    m_gsocks[fd] = socket;    m_count++;}void CSocketSet::RemoveSocket(GSocket *socket){    wxASSERT(socket);        int fd = socket->m_fd;    if ( fd == -1 ) {        return;    }        wxASSERT( (fd >= 0) && (fd < FD_SETSIZE) );        int i = m_fd_idx[fd];    if ( i == 0xffff ) {        return;    }    wxASSERT(m_fds[i] == fd);    m_fds[i] = m_fds[m_count-1];    m_gsocks[fd] = 0;    m_fds[m_count-1] = 0;    m_fd_idx[fd] = 0xffff;    m_fd_idx[m_fds[i]] = i;    m_count--;}void CSocketSet::FillSet(int &max_fd){    FD_ZERO(&m_set);    for(int i = 0; i < m_count; i++) {	    FD_SET(m_fds[i], &m_set);	    if ( m_fds[i] > max_fd ) {	        max_fd = m_fds[i];	    }    }}void CSocketSet::Detected(void (GSocket::*func)()){    for (int i = 0; i < m_count; i++) {        int fd = m_fds[i];        if ( FD_ISSET(fd, &m_set) ) {            GSocket *socket = m_gsocks[fd];            (*socket.*func)();        }    }}class CWebserverGSocketFuncTable : public GSocketGUIFunctionsTable{	private:        CSocketSet *m_in_set, *m_out_set;        wxMutex m_lock;	public:	    CWebserverGSocketFuncTable();		    void AddSocket(GSocket *socket, GSocketEvent event);	    void RemoveSocket(GSocket *socket, GSocketEvent event);	    void RunSelect();		    virtual bool OnInit();	    virtual void OnExit();	    virtual bool CanUseEventLoop();	    virtual bool Init_Socket(GSocket *socket);	    virtual void Destroy_Socket(GSocket *socket);	    virtual void Install_Callback(GSocket *socket, GSocketEvent event);	    virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event);	    virtual void Enable_Events(GSocket *socket);	    virtual void Disable_Events(GSocket *socket);};CWebserverGSocketFuncTable::CWebserverGSocketFuncTable() : m_lock(wxMUTEX_RECURSIVE){    m_in_set = new CSocketSet;    m_out_set = new CSocketSet;        m_lock.Unlock();}void CWebserverGSocketFuncTable::AddSocket(GSocket *socket, GSocketEvent event){    wxMutexLocker lock(m_lock);    if ( event == GSOCK_INPUT ) {        m_in_set->AddSocket(socket);    } else {        m_out_set->AddSocket(socket);    }}void CWebserverGSocketFuncTable::RemoveSocket(GSocket *socket, GSocketEvent event){    wxMutexLocker lock(m_lock);    if ( event == GSOCK_INPUT ) {        m_in_set->RemoveSocket(socket);    } else {        m_out_set->RemoveSocket(socket);    }}void CWebserverGSocketFuncTable::RunSelect(){    wxMutexLocker lock(m_lock);    int max_fd = -1;    m_in_set->FillSet(max_fd);    m_out_set->FillSet(max_fd);    struct timeval tv;    tv.tv_sec = 0;    tv.tv_usec = 10000; // 10ms        int result = select(max_fd + 1, m_in_set->Set(), m_out_set->Set(), 0, &tv);    if ( result > 0 ) {        m_in_set->Detected(&GSocket::Detected_Read);        m_out_set->Detected(&GSocket::Detected_Write);    }    }bool CWebserverGSocketFuncTable::OnInit(){    return true;}void CWebserverGSocketFuncTable::OnExit(){}bool CWebserverGSocketFuncTable::CanUseEventLoop(){    return false;}bool CWebserverGSocketFuncTable::Init_Socket(GSocket *){    return true;}void CWebserverGSocketFuncTable::Destroy_Socket(GSocket *){}void CWebserverGSocketFuncTable::Install_Callback(GSocket *sock, GSocketEvent e){    AddSocket(sock, e);}void CWebserverGSocketFuncTable::Uninstall_Callback(GSocket *sock, GSocketEvent e){    RemoveSocket(sock, e);}void CWebserverGSocketFuncTable::Enable_Events(GSocket *socket){    Install_Callback(socket, GSOCK_INPUT);    Install_Callback(socket, GSOCK_OUTPUT);}void CWebserverGSocketFuncTable::Disable_Events(GSocket *socket){    Uninstall_Callback(socket, GSOCK_INPUT);    Uninstall_Callback(socket, GSOCK_OUTPUT);}class CWebserverAppTraits : public wxConsoleAppTraits{	private:	    CWebserverGSocketFuncTable *m_table;	    wxMutex m_lock;	    std::list<wxObject *> m_sched_delete;	public:	    CWebserverAppTraits(CWebserverGSocketFuncTable *table);	    virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable();	    virtual void ScheduleForDestroy(wxObject *object);	    virtual void RemoveFromPendingDelete(wxObject *object);		    void DeletePending();};CWebserverAppTraits::CWebserverAppTraits(CWebserverGSocketFuncTable *table): wxConsoleAppTraits(), m_table(table),m_lock(wxMUTEX_RECURSIVE), m_sched_delete(){    m_lock.Unlock();}GSocketGUIFunctionsTable *CWebserverAppTraits::GetSocketGUIFunctionsTable(){    return m_table;}void CWebserverAppTraits::ScheduleForDestroy(wxObject *object){        wxMutexLocker lock(m_lock);        m_sched_delete.push_back(object);}void CWebserverAppTraits::RemoveFromPendingDelete(wxObject *object){    wxMutexLocker lock(m_lock);    for(std::list<wxObject *>::iterator i = m_sched_delete.begin();    i != m_sched_delete.end(); i++) {        if ( *i == object ) {                m_sched_delete.erase(i);                return;        }    }}void CWebserverAppTraits::DeletePending(){    wxMutexLocker lock(m_lock);    while ( !m_sched_delete.empty() ) {        std::list<wxObject *>::iterator i = m_sched_delete.begin();        wxObject *object = *i;        delete object;    }}//-------------------------------------------------------------------IMPLEMENT_APP(CamulewebApp)//-------------------------------------------------------------------BEGIN_EVENT_TABLE(CamulewebApp, CaMuleExternalConnector)END_EVENT_TABLE()CamulewebApp::CamulewebApp() : m_table(new CWebserverGSocketFuncTable){	wxPendingEventsLocker = new wxCriticalSection;}wxAppTraits *CamulewebApp::CreateTraits(){	return new CWebserverAppTraits(m_table);}void CamulewebApp::Post_Shell() {	m_webserver->StopServer();	delete m_webserver;	m_webserver = 0;}bool CamulewebApp::OnInit() {	return CaMuleExternalConnector::OnInit();}int CamulewebApp::OnRun() {	ConnectAndRun(wxT("aMuleweb"), wxT(VERSION));	return 0;}bool CamulewebApp::CheckDirForTemplate(wxString& dir, const wxString& tmpl){	DebugShow(wxT("checking for directory '") + dir + wxT("'..."));	if (wxFileName::DirExists(dir)) {		DebugShow(wxT(" yes\n"));		dir = JoinPaths(dir, tmpl);		DebugShow(wxT("checking for directory '") + dir + wxT("'..."));		if (wxFileName::DirExists(dir)) {			DebugShow(wxT(" yes\n"));			wxString tmplPath = JoinPaths(dir, wxT("login.php"));			DebugShow(wxT("checking for file '") + tmplPath + wxT("'..."));			if (wxFileName::FileExists(tmplPath)) {				DebugShow(wxT(" yes\n"));				// dir is already set to the directory component of the template path				return true;			} else {				DebugShow(wxT(" no\n"));			}		} else {			DebugShow(wxT(" no\n"));		}	} else {		DebugShow(wxT(" no\n"));	}	return false;}bool CamulewebApp::GetTemplateDir(const wxString& templateName, wxString& templateDir){	wxString dir;	m_localTemplate = false;	DebugShow(wxT("looking for template: ") + templateName + wxT("\n"));

⌨️ 快捷键说明

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