📄 warifsite.cpp
字号:
#include "StdAfx.h"#include "WarIfSite.h" // class implemented#include "WarIfServer.h"#include "WarUserAuthWin32Nt.h"#include "WarLog.h"#include "WarIfAuthModule.h"#include "WarSvrProtocolFtp.h"#include "WarOptionWin32.h"#include "WarIfPathList.h"#include "WarIfOptions.h"#include "WarIfMimeTypes.h"/////////////////////////////// PUBLIC /////////////////////////////////////////============================= LIFECYCLE ====================================WarIfSite::WarIfSite(war_if_server_ptr_t& serverPtr, const WarWin32Registry& regKey) :mServerPtr(serverPtr){ // Duplicate the registry key mRegKey.Open(regKey.GetRef()); mName = mRegKey.GetRef().GetPath().GetFilename().GetPath(); // Create reg-keys for all supported protocols for(int i = 0; i < PROT_INVALID; i++) { war_registrypath_t path; path.Reset(); path << mRegKey.GetRef().GetPath().GetPath() << WAR_SYSSLASH << WAR_WINNT_REG_PROTOCOLS << WAR_SYSSLASH << GetProtocolName((ProtocolE)i); mRegSite[i].Create(WarWin32Registry::open_t(mRegKey, path)); }}// WarIfSiteWarIfSite::~WarIfSite(){}// ~WarIfSite//============================= OPERATORS ====================================//============================= OPERATIONS ===================================void WarIfSite::SetEnable(const bool doEnable){ mRegKey.SetValue(WAR_WINNT_REG_ENABLE, doEnable);}void WarIfSite::SetEnableProtocol(const ProtocolE type, const bool doEnable) throw(WarException){ Validate(type); mRegSite[type].SetValue(WAR_WINNT_REG_ENABLE, doEnable);}void WarIfSite::SetName(war_ccsysstr_t newName) throw(WarException){ if (!newName || !*newName) WarThrow(WarError(WAR_ERR_INVALID_ARGUMENT), NULL); mRegKey.Rename(newName); mName = newName;}void WarIfSite::SetSiteName(war_ccsysstr_t newName) throw(WarException){ mRegKey.SetValue(WAR_WINNT_REG_NAME, newName);} void WarIfSite::SetAdress(const ProtocolE type, war_ccsysstr_t newAddress) throw(WarException){ Validate(type); mRegSite[type].SetValue(WAR_WINNT_REG_ADDRESS, newAddress);}void WarIfSite::SetDefaultPage(const ProtocolE type, war_ccsysstr_t newPage) throw(WarException){ Validate(type); mRegSite[type].SetValue(WAR_WINNT_REG_DEFAULT_PAGE, newPage);}void WarIfSite::SetVirtualHostName(const ProtocolE type, war_ccsysstr_t newName) throw(WarException){ Validate(type); mRegSite[type].SetValue(WAR_WINNT_REG_VIRTUAL_HOST, newName);} void WarIfSite::InitializeRealSite(war_svrdef_ptr_t& sitePtr, const ProtocolE siteProtocol) throw(WarException){ if (IsProtocolEnabled(siteProtocol)) { // Set the site address sitePtr->mLocalHost = WarUtf8( GetAddress(siteProtocol)).GetUtf8().c_str(); // Get shares WarIfPathList my_paths(mRegKey); my_paths.EnumPaths(sitePtr->mProperties.mPaths); // Load options WarWin32Registry reg_svr_options; reg_svr_options.Open(mRegKey.GetRef(WAR_WINNT_REG_OPTIONS)); reg_svr_options >> sitePtr->mProperties.mOptions; // Get site name sitePtr->mSiteName = WarUtf8(mRegKey.GetStrValue(WAR_WINNT_REG_NAME, _T("Jgaa's fan club FTP server"))).GetUtf8(); sitePtr->mNativeSiteName = WarUtf8( mRegKey.GetRef().GetPath().GetFilename().GetPath()).GetUtf8(); // Get IP Access list GetIpAccessList(sitePtr->mProperties.mIpAccessList); // Add global options sitePtr->mProperties.mOptions += WarOptionList::GetGlobalOptions(); // Add auth-modules war_if_aut_module_list_t my_auth_modules; EnumAuthModules(my_auth_modules, true); for(war_if_aut_module_list_t::iterator PP = my_auth_modules.begin() ; PP != my_auth_modules.end() ; ++PP) { sitePtr->mAuthEngine.AddAuthModule( WarUserEngine::auth_ptr_t(&((*PP)->GetAuth()))); } // Add mime-types sitePtr->mMimePtr = GetMime(); // Add default pages WarIfSite::namestr_t def_pages = GetDefaultPage(siteProtocol); { WarIfSite::namestr_t name; for(const war_sysch_t *p = def_pages.c_str(); *p; p++) { name.erase(name.begin(), name.end()); while(*p && (' ' != *p) && ('\t' != *p) && (',' != *p) && (':' != *p) && (';' != *p)) name += *p++; if (!name.empty()) sitePtr->mDefaultPage.push_back(name); if (!*p) break; } } }}void WarIfSite::SetIpAccessList(const WarIpAccessList& newList){ mRegKey.SetValue(WAR_WINNT_REG_IP_ACCESS_LIST_MODE, newList.mMode); war_regstr_t ip_list_str; newList.GetStrList(ip_list_str); mRegKey.SetValue(WAR_WINNT_REG_IP_ACCESS_LIST, ip_list_str);}//============================= ACCESS ===================================//============================= INQUIRY ===================================bool WarIfSite::IsEnabled() const{ return mRegKey.GetIntValue(WAR_WINNT_REG_ENABLE, false);}bool WarIfSite::IsProtocolEnabled(const ProtocolE type) const throw(WarException){ Validate(type); return mRegSite[type].GetIntValue(WAR_WINNT_REG_ENABLE, false);}const WarIfSite::namestr_t& WarIfSite::GetName() const throw(WarException){ return mName;}const WarIfSite::namestr_t WarIfSite::GetSiteName() const throw(WarException){ return mRegKey.GetStrValue(WAR_WINNT_REG_NAME);}const WarIfSite::namestr_t WarIfSite::GetAddress(const ProtocolE type) const throw(WarException){ Validate(type); return mRegSite[type].GetStrValue(WAR_WINNT_REG_ADDRESS);}const WarIfSite::namestr_t WarIfSite::GetDefaultPage(const ProtocolE type) const throw(WarException){ Validate(type); return mRegSite[type].GetStrValue(WAR_WINNT_REG_DEFAULT_PAGE);}const WarIfSite::namestr_t WarIfSite::GetVirtualHostName(const ProtocolE type) const throw(WarException){ Validate(type); return mRegSite[type].GetStrValue(WAR_WINNT_REG_VIRTUAL_HOST);}const war_ccstr_t WarIfSite::GetProtocolName(const ProtocolE type) const throw (WarException){ Validate(type); static const war_ccstr_t names[PROT_INVALID] = { {"FTP"}, {"HTTP"}, }; return names[type];}void WarIfSite::Validate(const ProtocolE type) const throw (WarException){ if ((0 > type) || (PROT_INVALID <= type)) WarThrow(WarError(WAR_ERR_OUT_OF_RANGE), NULL);}std::string WarIfSite::Explain() const{ WarCollector<char> str; bool virgin = true; for(int i = 0; i < PROT_INVALID; i++) { if (!virgin) str << ", "; if (!IsProtocolEnabled((ProtocolE)i)) continue; str << GetProtocolName((ProtocolE)i) << ' ' << GetAddress((ProtocolE)i); virgin = false; } if (virgin) str << "(disabled)"; return str.GetValue();}void WarIfSite::EnumAuthModules(war_if_aut_module_list_t& authList, bool hideDisabled) throw (WarException){ WarWin32Registry auth_key, module_key; auth_key.Open(mRegKey.GetRef(WAR_WINNT_REG_AUTH_MODULES)); WarWin32Registry::keyname_list_t keys; auth_key.EnumKey(keys); for(WarWin32Registry::keyname_list_t::const_iterator P = keys.begin() ; P != keys.end() ; ++P) { module_key.Open(auth_key.GetRef(P->c_str())); war_if_aut_module_ptr_t auth_ptr = new WarIfAuthModule; try { auth_ptr->Open(war_if_site_ptr_t(this), module_key); } catch(WarException) { } if (hideDisabled && !auth_ptr->IsEnabled()) continue; // Add the module to the returned list authList.push_back(auth_ptr); }}void WarIfSite::EnumAllUsers(war_if_user_set_t& user_set, bool doIgnoreDisabledUsers) throw(WarException){ war_if_aut_module_list_t auth_modules; EnumAuthModules(auth_modules); for(war_if_aut_module_list_t::iterator P = auth_modules.begin() ; P != auth_modules.end() ; ++P) { (*P)->EnumUsers(user_set, doIgnoreDisabledUsers); }}void WarIfSite::GetIpAccessList(WarIpAccessList& returnList){ returnList.SetValue((WarIpAccessList::ModeE)mRegKey.GetIntValue( WAR_WINNT_REG_IP_ACCESS_LIST_MODE, 0), mRegKey.GetStrValue(WAR_WINNT_REG_IP_ACCESS_LIST).c_str());}war_if_options_ptr_t WarIfSite::GetOptions(){ return new WarIfOptions(*this);}war_if_mime_types_ptr_t WarIfSite::GetMime() throw (WarException){ return new WarIfMimeTypes(*this);}////////////////////////////// PROTECTED ////////////////////////////////////////////////////////////////// PRIVATE ///////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -