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

📄 warfiledriverdynamic.cpp

📁 ftpserver very good sample
💻 CPP
字号:
#include "StdAfx.h"#include "WarFileDriverDynamic.h"   // class implemented#ifndef WAR_AUTO_LOCK_H#   include "WarAutoLock.h"#endif#ifndef WAR_LOG#   include "WarLog.h"#endif#ifndef WAR_AUTO_DESTRUCT_H#	include "WarAutoDestruct.h"#endif#ifndef WAR_FILE_DRIVER_FILE_DYNAMIC_H#	include "WarFileDriverFileDynamic.h"#endif#define AUTO_LOCK WarAutoLock MyLock((WarCriticalSection &)mLock);/////////////////////////////// PUBLIC /////////////////////////////////////////============================= LIFECYCLE ====================================WarFileDriverDynamic::WarFileDriverDynamic(war_ccstr_t driverName): WarFileDriver(driverName),mLock(true){}// WarFileDriverDynamicWarFileDriverDynamic::~WarFileDriverDynamic(){}// ~WarFileDriverDynamic//============================= OPERATORS ====================================//============================= OPERATIONS ===================================void WarFileDriverDynamic::MountDir(war_ccsvrpath_t newName,									war_ccsvrpath_t mountInDir) 									throw(WarException){	AUTO_LOCK;	// Find the node to use	node_ptr_t my_dir;	if ((mountInDir == NULL) && (NULL == newName))	{		// Mount as root		if (!mRootPtr.IsEmpty())			WarThrow(WarError(WAR_ERR_ALREADY_INITIALIZED), NULL);		mRootPtr = new WarFileDriverDynamicNodeDir;		return;	}	if (NULL == mRootPtr)		MountDir(NULL, NULL); // Create the root-dir    WarLog db_log(WARLOG_DEBUG, "WarFileDriverDynamic::MountDir()");    if (db_log)    {        db_log << "Mounting new virtual directory \""            << newName             << "\" in virtual directory \""            << mountInDir            << "\"."            << war_endl;    }	my_dir = Lookup(mountInDir);	if (!my_dir->IsDir())		WarThrow(WarError(WAR_FERR_NOT_A_DIRECTORY), NULL);	((dir_ptr_t &)my_dir)->MountDir(newName);}WarFileDriverDynamic::node_ptr_t WarFileDriverDynamic::Lookup(war_ccsvrpath_t path) const throw(WarException){	AUTO_LOCK;		node_ptr_t my_dir = mRootPtr;    if (path)    {        if (('.' == path[0]) && WarSysSlash::IsSlash(path[1]))            path += 2;        war_ccsvrpath_t p = path, p_start = path;                while(my_dir && my_dir->IsDir() && *p)		{			if (WarSysSlash::IsSlash(*p))				p_start= ++p;			if (!*p)				break; 						while(*p && !WarSysSlash::IsSlash(*p))				++p;						int len = p - p_start;						if (0 >= len)				WarThrow(WarError(WAR_FERR_NO_SUCH_PATH), NULL);									WarFileDriverDynamicNodeDir::name_t name;			name.resize(len);			memcpy(&name[0], p_start, len * sizeof(war_svrpath_ch_t));						my_dir = ((dir_ptr_t &)my_dir)->Lookup(name);						p_start = p;		}	}	return my_dir; // Can be a "file" or a "dir"}war_flen_t WarFileDriverDynamic::WarGetSize(const WarUrl& Path) constthrow(WarException){	war_stat_t st;	WarStat(Path, st);	return st.st_size;}void WarFileDriverDynamic::WarStat(const WarUrl& Path, 								   war_stat_t& st) const								   throw(WarException){	WarExamine(Path, st);}WarFileDriverDynamic::FileTypeE WarFileDriverDynamic::WarExamine(const WarUrl& Path,  								 war_stat_t& st) const{	memset(&st, 0, sizeof(war_stat_t));	node_ptr_t node = Lookup(Path.GetFilePath().GetPath());	WarFileDriverDynamicNodeBase *pnode = &(*node);	st.st_mode = pnode->mMode;	st.st_atime = pnode->mAccessTime.GetTime();	st.st_ctime = pnode->mCreationTime.GetTime();	st.st_mtime = pnode->mModifyTime.GetTime();	st.st_ino = pnode->mInode;	st.st_nlink = pnode->mLinks;	st.st_size = pnode->mSize;	st.st_uid = pnode->mUid;	st.st_gid = pnode->mGid;	if (!(node->IsDir()))	{		WarAutoDestruct<WarFileDriverFile> pfile;		pfile = WarCreateNewFileObject(Path);				assert(pfile);		pfile.GetPtr()->Open(Path, 0);		st.st_size = pfile.GetPtr()->GetLength();	}	return pnode->mType;}WarFileDriverFile * WarFileDriverDynamic::WarCreateNewFileObject(const WarUrl& fileUrl) const throw(WarException){	AUTO_LOCK;		node_ptr_t my_node = Lookup(fileUrl.GetFilePath().GetPath());	if (my_node->IsDir())		WarThrow(WarError(WAR_FERR_NOT_A_FILE), NULL);	return my_node->CreateInstance((WarFileDriverDynamic *)this);}void WarFileDriverDynamic::WarListDirectory(const WarUrl& Path,											WarDirList& listDestination)											throw(WarException){	AUTO_LOCK;	node_ptr_t my_dir = Lookup(Path.GetFilePath().GetPath());	if (!my_dir->IsDir())		WarThrow(WarError(WAR_FERR_NOT_A_DIRECTORY), NULL);	WarFileDriverDynamicNodeDir *pdir 		= (WarFileDriverDynamicNodeDir *)&(*my_dir);	pdir->WarListDirectory(listDestination);}void WarFileDriverDynamic::MountFile(war_ccsvrpath_t newName,								   node_ptr_t pagePtr, 								   war_ccsvrpath_t mountInDir)								   throw(WarException){	AUTO_LOCK;	node_ptr_t my_dir = Lookup(mountInDir);	if (!my_dir->IsDir())		WarThrow(WarError(WAR_FERR_NOT_A_DIRECTORY), NULL);	WarFileDriverDynamicNodeDir *pdir 		= (WarFileDriverDynamicNodeDir *)&(*my_dir);	pdir->MountFile(newName, pagePtr);}void WarFileDriverDynamic::DeleteNode(war_ccsvrpath_t nodeName)		throw(WarException){	AUTO_LOCK;	WarPath<wchar_t> node_name = nodeName;	node_ptr_t my_dir = Lookup(node_name.GetPathname().GetPath());	if (!my_dir->IsDir())		WarThrow(WarError(WAR_FERR_NOT_A_DIRECTORY), NULL);	WarFileDriverDynamicNodeDir *pdir 		= (WarFileDriverDynamicNodeDir *)&(*my_dir);	pdir->DeleteNode(node_name.GetFilename().GetPath());}//============================= CALLBACK  ===================================//============================= ACCESS     ===================================//============================= INQUIRY    ===================================/////////////////////////////// PROTECTED  ////////////////////////////////////////////////////////////////// PRIVATE    ///////////////////////////////////

⌨️ 快捷键说明

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