mirror of
https://github.com/uroni/urbackup_backend.git
synced 2025-10-26 11:36:50 +00:00
Removed UTF16 string (std::wstring) in most places. UTF8 everywhere!
This commit is contained in:
parent
f6be707746
commit
9bab514e22
@ -54,7 +54,7 @@ void OutputCallback::operator() (const void* buf, size_t count)
|
||||
#else
|
||||
ec=errno;
|
||||
#endif
|
||||
Server->Log("Send failed in OutputCallback ec="+nconvert(ec), LL_INFO);
|
||||
Server->Log("Send failed in OutputCallback ec="+convert(ec), LL_INFO);
|
||||
throw std::runtime_error("Send failed in OutputCallback");
|
||||
}
|
||||
else
|
||||
@ -83,7 +83,7 @@ CAcceptThread::CAcceptThread( unsigned int nWorkerThreadsPerMaster, unsigned sho
|
||||
int rc=setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof(int));
|
||||
if(rc==SOCKET_ERROR)
|
||||
{
|
||||
Server->Log("Failed setting SO_REUSEADDR for port "+nconvert(uPort),LL_ERROR);
|
||||
Server->Log("Failed setting SO_REUSEADDR for port "+convert(uPort),LL_ERROR);
|
||||
error=true;
|
||||
return;
|
||||
}
|
||||
@ -98,7 +98,7 @@ CAcceptThread::CAcceptThread( unsigned int nWorkerThreadsPerMaster, unsigned sho
|
||||
rc=bind(s,(sockaddr*)&addr,sizeof(addr));
|
||||
if(rc==SOCKET_ERROR)
|
||||
{
|
||||
Server->Log("Failed binding SOCKET to Port "+nconvert(uPort),LL_ERROR);
|
||||
Server->Log("Failed binding SOCKET to Port "+convert(uPort),LL_ERROR);
|
||||
error=true;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ CCondition::~CCondition()
|
||||
int rc=pthread_cond_destroy(&cond);
|
||||
if(rc!=0)
|
||||
{
|
||||
Server->Log("Destroying condition failed ec="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Destroying condition failed ec="+convert(rc), LL_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ bool CDBSettingsReader::getValue(std::string key, std::string *value)
|
||||
}
|
||||
|
||||
query->Bind(key);
|
||||
db_nresults res=query->ReadN();
|
||||
db_results res=query->Read();
|
||||
query->Reset();
|
||||
|
||||
if( res.size()>0 )
|
||||
@ -66,27 +66,7 @@ bool CDBSettingsReader::getValue(std::string key, std::string *value)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CDBSettingsReader::getValue(std::wstring key, std::wstring *value)
|
||||
std::vector<std::string> CDBSettingsReader::getKeys()
|
||||
{
|
||||
if(query==NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
query->Bind(key);
|
||||
db_results res=query->Read();
|
||||
query->Reset();
|
||||
|
||||
if( res.size()>0 )
|
||||
{
|
||||
*value=res[0][L"value"];
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CDBSettingsReader::getKeys()
|
||||
{
|
||||
return std::vector<std::wstring>();
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
@ -8,9 +8,8 @@ public:
|
||||
CDBSettingsReader(IDatabase *pDB, const std::string &pTable, const std::string &pSQL="");
|
||||
|
||||
bool getValue(std::string key, std::string *value);
|
||||
bool getValue(std::wstring key, std::wstring *value);
|
||||
|
||||
std::vector<std::wstring> getKeys();
|
||||
std::vector<std::string> getKeys();
|
||||
|
||||
private:
|
||||
std::string table;
|
||||
|
||||
49
Database.cpp
49
Database.cpp
@ -72,23 +72,6 @@ struct UnlockNotification {
|
||||
IMutex *mutex;
|
||||
};
|
||||
|
||||
static int callback(void *CPtr, int argc, char **argv, char **azColName)
|
||||
{
|
||||
CDatabase* db=(CDatabase*)CPtr;
|
||||
db_nsingle_result result;
|
||||
|
||||
for(int i=0; i<argc; i++)
|
||||
{
|
||||
//printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
|
||||
if( azColName[i] && argv[i])
|
||||
result.insert(std::pair<std::string,std::string>(azColName[i], argv[i]) );
|
||||
}
|
||||
|
||||
db->InsertResults(result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void unlock_notify_cb(void **apArg, int nArg)
|
||||
{
|
||||
for(int i=0; i<nArg; i++)
|
||||
@ -149,7 +132,7 @@ bool CDatabase::Open(std::string pFile, const std::vector<std::pair<std::string,
|
||||
}
|
||||
|
||||
static size_t sqlite_cache_size = get_sqlite_cache_size();
|
||||
Write("PRAGMA cache_size = -"+nconvert(sqlite_cache_size));
|
||||
Write("PRAGMA cache_size = -"+convert(sqlite_cache_size));
|
||||
|
||||
sqlite3_busy_timeout(db, c_sqlite_busy_timeout_default);
|
||||
AttachDBs();
|
||||
@ -170,22 +153,6 @@ void CDatabase::destroyMutex(void)
|
||||
Server->destroy(unlock_cond);
|
||||
}
|
||||
|
||||
db_nresults CDatabase::ReadN(std::string pQuery)
|
||||
{
|
||||
//Server->Log("SQL Query(Read): "+pQuery);
|
||||
results.clear();
|
||||
char *zErrMsg = 0;
|
||||
int rc=sqlite3_exec(db, pQuery.c_str(), callback, this, &zErrMsg);
|
||||
if( rc!=SQLITE_OK )
|
||||
{
|
||||
Server->Log("SQL ERROR: "+(std::string)zErrMsg);
|
||||
}
|
||||
if( zErrMsg!=NULL )
|
||||
sqlite3_free(zErrMsg);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
db_results CDatabase::Read(std::string pQuery)
|
||||
{
|
||||
//Server->Log("SQL Query(Read): "+pQuery, LL_DEBUG);
|
||||
@ -215,12 +182,6 @@ bool CDatabase::Write(std::string pQuery)
|
||||
}
|
||||
}
|
||||
|
||||
void CDatabase::InsertResults(const db_nsingle_result &pResult)
|
||||
{
|
||||
results.push_back(pResult);
|
||||
}
|
||||
|
||||
|
||||
//ToDo: Cache Writings
|
||||
|
||||
bool CDatabase::BeginReadTransaction()
|
||||
@ -552,7 +513,7 @@ bool CDatabase::backup_db(const std::string &pFile, const std::string &pDB)
|
||||
rc = sqlite3_errcode(pBackupDB);
|
||||
if(rc!=0)
|
||||
{
|
||||
Server->Log("Database backup failed with error code: "+nconvert(rc)+" err: "+sqlite3_errmsg(pBackupDB), LL_ERROR);
|
||||
Server->Log("Database backup failed with error code: "+convert(rc)+" err: "+sqlite3_errmsg(pBackupDB), LL_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -589,18 +550,18 @@ int CDatabase::getLastChanges()
|
||||
return sqlite3_changes(db);
|
||||
}
|
||||
|
||||
std::wstring CDatabase::getTempDirectoryPath()
|
||||
std::string CDatabase::getTempDirectoryPath()
|
||||
{
|
||||
char* tmpfn = NULL;
|
||||
if(sqlite3_file_control(db, NULL, SQLITE_FCNTL_TEMPFILENAME, &tmpfn)==SQLITE_OK && tmpfn!=NULL)
|
||||
{
|
||||
std::wstring ret = ExtractFilePath(Server->ConvertToUnicode(tmpfn));
|
||||
std::string ret = ExtractFilePath(tmpfn);
|
||||
sqlite3_free(tmpfn);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::wstring();
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,6 @@ public:
|
||||
size_t allocation_chunk_size);
|
||||
~CDatabase();
|
||||
|
||||
virtual db_nresults ReadN(std::string pQuery);
|
||||
virtual db_results Read(std::string pQuery);
|
||||
virtual bool Write(std::string pQuery);
|
||||
|
||||
@ -36,7 +35,6 @@ public:
|
||||
sqlite3 *getDatabase(void);
|
||||
|
||||
//private function
|
||||
void InsertResults(const db_nsingle_result &pResult);
|
||||
bool WaitForUnlock(void);
|
||||
|
||||
bool LockForTransaction(void);
|
||||
@ -60,12 +58,11 @@ public:
|
||||
|
||||
virtual int getLastChanges();
|
||||
|
||||
virtual std::wstring getTempDirectoryPath();
|
||||
virtual std::string getTempDirectoryPath();
|
||||
private:
|
||||
|
||||
bool backup_db(const std::string &pFile, const std::string &pDB);
|
||||
|
||||
db_nresults results;
|
||||
sqlite3 *db;
|
||||
bool in_transaction;
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ IMutex* CFileSettingsReader::settings_mutex=NULL;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string readFile(const std::wstring& fn)
|
||||
std::string readFile(const std::string& fn)
|
||||
{
|
||||
std::auto_ptr<IFile> file(Server->openFile(fn));
|
||||
if(file.get()==NULL)
|
||||
@ -71,27 +71,6 @@ CFileSettingsReader::CFileSettingsReader(std::string pFile)
|
||||
|
||||
}
|
||||
|
||||
CFileSettingsReader::CFileSettingsReader( std::wstring pFile )
|
||||
{
|
||||
std::map<std::string, SCachedSettings*>::iterator iter;
|
||||
{
|
||||
IScopedLock lock(settings_mutex);
|
||||
iter=settings->find(Server->ConvertToUTF8(pFile));
|
||||
}
|
||||
if( iter==settings->end() )
|
||||
{
|
||||
std::string fdata=readFile(pFile);
|
||||
|
||||
read(fdata, Server->ConvertToUTF8(pFile));
|
||||
}
|
||||
else
|
||||
{
|
||||
IScopedLock lock(settings_mutex);
|
||||
cached_settings=iter->second;
|
||||
++cached_settings->refcount;
|
||||
}
|
||||
}
|
||||
|
||||
CFileSettingsReader::~CFileSettingsReader()
|
||||
{
|
||||
IScopedLock lock(settings_mutex);
|
||||
@ -109,25 +88,10 @@ CFileSettingsReader::~CFileSettingsReader()
|
||||
}
|
||||
|
||||
bool CFileSettingsReader::getValue(std::string key, std::string *value)
|
||||
{
|
||||
std::wstring s_value;
|
||||
bool b=getValue( widen(key), &s_value);
|
||||
|
||||
if(b==true)
|
||||
{
|
||||
std::string nvalue=wnarrow(s_value);
|
||||
*value=nvalue;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CFileSettingsReader::getValue(std::wstring key, std::wstring *value)
|
||||
{
|
||||
IScopedLock lock(cached_settings->smutex);
|
||||
|
||||
std::map<std::wstring,std::wstring>::iterator i=cached_settings->mSettingsMap.find(key);
|
||||
std::map<std::string,std::string>::iterator i=cached_settings->mSettingsMap.find(key);
|
||||
if( i!= cached_settings->mSettingsMap.end() )
|
||||
{
|
||||
*value=i->second;
|
||||
@ -155,12 +119,12 @@ void CFileSettingsReader::setup()
|
||||
settings_mutex=Server->createMutex();
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CFileSettingsReader::getKeys()
|
||||
std::vector<std::string> CFileSettingsReader::getKeys()
|
||||
{
|
||||
IScopedLock lock(cached_settings->smutex);
|
||||
|
||||
std::vector<std::wstring> ret;
|
||||
for(std::map<std::wstring,std::wstring>::iterator i=cached_settings->mSettingsMap.begin();
|
||||
std::vector<std::string> ret;
|
||||
for(std::map<std::string,std::string>::iterator i=cached_settings->mSettingsMap.begin();
|
||||
i!=cached_settings->mSettingsMap.end();++i)
|
||||
{
|
||||
ret.push_back(i->first);
|
||||
@ -198,7 +162,7 @@ void CFileSettingsReader::read( const std::string& fdata, const std::string& pFi
|
||||
|
||||
for(size_t i=0;i<mSettings.size();++i)
|
||||
{
|
||||
cached_settings->mSettingsMap[Server->ConvertToUnicode(mSettings[i].key)]=Server->ConvertToUnicode(mSettings[i].value);
|
||||
cached_settings->mSettingsMap[(mSettings[i].key)]=(mSettings[i].value);
|
||||
}
|
||||
|
||||
cached_settings->refcount=1;
|
||||
|
||||
@ -11,7 +11,7 @@ struct SSetting
|
||||
|
||||
struct SCachedSettings
|
||||
{
|
||||
std::map<std::wstring,std::wstring> mSettingsMap;
|
||||
std::map<std::string,std::string> mSettingsMap;
|
||||
IMutex *smutex;
|
||||
int refcount;
|
||||
std::string key;
|
||||
@ -22,16 +22,14 @@ class CFileSettingsReader : public CSettingsReader
|
||||
{
|
||||
public:
|
||||
CFileSettingsReader(std::string pFile);
|
||||
CFileSettingsReader(std::wstring pFile);
|
||||
~CFileSettingsReader();
|
||||
|
||||
virtual bool getValue(std::string key, std::string *value);
|
||||
virtual bool getValue(std::wstring key, std::wstring *value);
|
||||
|
||||
static void cleanup();
|
||||
static void setup();
|
||||
|
||||
virtual std::vector<std::wstring> getKeys();
|
||||
virtual std::vector<std::string> getKeys();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@ -8,15 +8,15 @@
|
||||
#include "Object.h"
|
||||
|
||||
#define ACTION(x) class x : public IAction\
|
||||
{public: virtual void Execute(str_map &GET, str_map &POST, THREAD_ID tid, str_nmap &PARAMS); virtual std::wstring getName(void);};
|
||||
#define ACTION_IMPL(x) std::wstring Actions::x::getName(void){ return L ## #x; }\
|
||||
void Actions::x::Execute(str_map &GET, str_map &POST, THREAD_ID tid, str_nmap &PARAMS)
|
||||
{public: virtual void Execute(str_map &GET, str_map &POST, THREAD_ID tid, str_map &PARAMS); virtual std::string getName(void);};
|
||||
#define ACTION_IMPL(x) std::string Actions::x::getName(void){ return #x; }\
|
||||
void Actions::x::Execute(str_map &GET, str_map &POST, THREAD_ID tid, str_map &PARAMS)
|
||||
|
||||
class IAction : public IObject
|
||||
{
|
||||
public:
|
||||
virtual void Execute(str_map &GET, str_map &POST, THREAD_ID tid, str_nmap &PARAMS)=0;
|
||||
virtual std::wstring getName(void)=0;
|
||||
virtual void Execute(str_map &GET, str_map &POST, THREAD_ID tid, str_map &PARAMS)=0;
|
||||
virtual std::string getName(void)=0;
|
||||
};
|
||||
|
||||
#endif //IACTION_H
|
||||
@ -10,7 +10,6 @@
|
||||
class IDatabase : public IObject
|
||||
{
|
||||
public:
|
||||
virtual db_nresults ReadN(std::string pQuery)=0;
|
||||
virtual db_results Read(std::string pQuery)=0;
|
||||
virtual bool Write(std::string pQuery)=0;
|
||||
|
||||
@ -38,7 +37,7 @@ public:
|
||||
|
||||
virtual int getLastChanges()=0;
|
||||
|
||||
virtual std::wstring getTempDirectoryPath() = 0;
|
||||
virtual std::string getTempDirectoryPath() = 0;
|
||||
};
|
||||
|
||||
class DBScopedFreeMemory
|
||||
|
||||
@ -33,7 +33,6 @@ public:
|
||||
virtual bool Sync() = 0;
|
||||
|
||||
virtual std::string getFilename(void)=0;
|
||||
virtual std::wstring getFilenameW(void)=0;
|
||||
};
|
||||
|
||||
class ScopedDeleteFile
|
||||
@ -57,7 +56,7 @@ public:
|
||||
private:
|
||||
void del() {
|
||||
if(file!=NULL) {
|
||||
std::wstring tmpfn=file->getFilenameW();
|
||||
std::string tmpfn=file->getFilename();
|
||||
file->Remove();
|
||||
Server->deleteFile(tmpfn);
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ class IQuery
|
||||
{
|
||||
public:
|
||||
virtual void Bind(const std::string &str)=0;
|
||||
virtual void Bind(const std::wstring &str)=0;
|
||||
virtual void Bind(unsigned int p)=0;
|
||||
virtual void Bind(int p)=0;
|
||||
virtual void Bind(double p)=0;
|
||||
@ -22,7 +21,6 @@ public:
|
||||
virtual void Reset(void)=0;
|
||||
|
||||
virtual bool Write(int timeoutms=-1)=0;
|
||||
virtual db_nresults ReadN(int *timeoutms=NULL)=0;
|
||||
virtual db_results Read(int *timeoutms=NULL)=0;
|
||||
|
||||
virtual IDatabaseCursor* Cursor(int *timeoutms=NULL)=0;
|
||||
|
||||
@ -33,11 +33,11 @@ class IPipeThrottlerUpdater;
|
||||
|
||||
struct SPostfile
|
||||
{
|
||||
SPostfile(IFile *f, std::wstring n, std::wstring ct){ file=f; name=n; contenttype=ct; }
|
||||
SPostfile(IFile *f, std::string n, std::string ct){ file=f; name=n; contenttype=ct; }
|
||||
SPostfile(){ file=NULL; }
|
||||
IFile *file;
|
||||
std::wstring name;
|
||||
std::wstring contenttype;
|
||||
std::string name;
|
||||
std::string contenttype;
|
||||
};
|
||||
|
||||
struct SCircularLogEntry
|
||||
@ -61,7 +61,6 @@ public:
|
||||
virtual void setLogCircularBufferSize(size_t size)=0;
|
||||
virtual std::vector<SCircularLogEntry> getCicularLogBuffer(size_t minid)=0;
|
||||
virtual void Log(const std::string &pStr, int LogLevel=LL_INFO)=0;
|
||||
virtual void Log(const std::wstring &pStr, int LogLevel=LL_INFO)=0;
|
||||
virtual bool Write(THREAD_ID tid, const std::string &str, bool cached=true)=0;
|
||||
virtual bool WriteRaw(THREAD_ID tid, const char *buf, size_t bsize, bool cached=true)=0;
|
||||
|
||||
@ -72,12 +71,12 @@ public:
|
||||
virtual void setContentType(THREAD_ID tid, const std::string &str)=0;
|
||||
virtual void addHeader(THREAD_ID tid, const std::string &str)=0;
|
||||
|
||||
virtual THREAD_ID Execute(const std::wstring &action, const std::wstring &context, str_map &GET, str_map &POST, str_nmap &PARAMS, IOutputStream *req)=0;
|
||||
virtual std::string Execute(const std::wstring &action, const std::wstring &context, str_map &GET, str_map &POST, str_nmap &PARAMS)=0;
|
||||
virtual THREAD_ID Execute(const std::string &action, const std::string &context, str_map &GET, str_map &POST, str_map &PARAMS, IOutputStream *req)=0;
|
||||
virtual std::string Execute(const std::string &action, const std::string &context, str_map &GET, str_map &POST, str_map &PARAMS)=0;
|
||||
|
||||
virtual void AddAction(IAction *action)=0;
|
||||
virtual bool RemoveAction(IAction *action)=0;
|
||||
virtual void setActionContext(std::wstring context)=0;
|
||||
virtual void setActionContext(std::string context)=0;
|
||||
virtual void resetActionContext(void)=0;
|
||||
|
||||
virtual int64 getTimeSeconds(void)=0;
|
||||
@ -98,7 +97,6 @@ public:
|
||||
virtual IPipe *createMemoryPipe(void)=0;
|
||||
virtual IThreadPool *getThreadPool(void)=0;
|
||||
virtual ISettingsReader* createFileSettingsReader(const std::string& pFile)=0;
|
||||
virtual ISettingsReader* createFileSettingsReader(const std::wstring& pFile)=0;
|
||||
virtual ISettingsReader* createDBSettingsReader(THREAD_ID tid, DATABASE_ID pIdentifier, const std::string &pTable, const std::string &pSQL="")=0;
|
||||
virtual ISettingsReader* createDBSettingsReader(IDatabase *db, const std::string &pTable, const std::string &pSQL="")=0;
|
||||
virtual ISettingsReader* createMemorySettingsReader(const std::string &pData)=0;
|
||||
@ -113,15 +111,13 @@ public:
|
||||
|
||||
virtual THREAD_ID getThreadID(void)=0;
|
||||
|
||||
virtual std::string ConvertToUTF8(const std::wstring &input)=0;
|
||||
virtual std::wstring ConvertToUnicode(const std::string &input)=0;
|
||||
virtual std::string ConvertToUTF16(const std::wstring &input)=0;
|
||||
virtual std::string ConvertToUTF32(const std::wstring &input)=0;
|
||||
virtual std::wstring ConvertFromUTF16(const std::string &input)=0;
|
||||
virtual std::wstring ConvertFromUTF32(const std::string &input)=0;
|
||||
virtual std::string ConvertToUTF16(const std::string &input)=0;
|
||||
virtual std::string ConvertToUTF32(const std::string &input)=0;
|
||||
virtual std::wstring ConvertToWchar(const std::string &input)=0;
|
||||
virtual std::string ConvertFromWchar(const std::wstring &input)=0;
|
||||
virtual std::string ConvertFromUTF16(const std::string &input)=0;
|
||||
virtual std::string ConvertFromUTF32(const std::string &input)=0;
|
||||
|
||||
virtual std::string GenerateHexMD5(const std::wstring &input)=0;
|
||||
virtual std::string GenerateBinaryMD5(const std::wstring &input)=0;
|
||||
virtual std::string GenerateHexMD5(const std::string &input)=0;
|
||||
virtual std::string GenerateBinaryMD5(const std::string &input)=0;
|
||||
|
||||
@ -147,23 +143,20 @@ public:
|
||||
virtual void addRequest(void)=0;
|
||||
|
||||
virtual IFile* openFile(std::string pFilename, int pMode=0)=0;
|
||||
virtual IFile* openFile(std::wstring pFilename, int pMode=0)=0;
|
||||
virtual IFile* openFileFromHandle(void *handle)=0;
|
||||
virtual IFile* openTemporaryFile(void)=0;
|
||||
virtual IFile* openMemoryFile(void)=0;
|
||||
virtual bool deleteFile(std::string pFilename)=0;
|
||||
virtual bool deleteFile(std::wstring pFilename)=0;
|
||||
virtual bool fileExists(std::string pFilename)=0;
|
||||
virtual bool fileExists(std::wstring pFilename)=0;
|
||||
|
||||
virtual POSTFILE_KEY getPostFileKey()=0;
|
||||
virtual void addPostFile(POSTFILE_KEY pfkey, const std::string &name, const SPostfile &pf)=0;
|
||||
virtual SPostfile getPostFile(POSTFILE_KEY pfkey, const std::string &name)=0;
|
||||
virtual void clearPostFiles(POSTFILE_KEY pfkey)=0;
|
||||
|
||||
virtual std::wstring getServerWorkingDir(void)=0;
|
||||
virtual std::string getServerWorkingDir(void)=0;
|
||||
|
||||
virtual void setTemporaryDirectory(const std::wstring &dir)=0;
|
||||
virtual void setTemporaryDirectory(const std::string &dir)=0;
|
||||
|
||||
virtual void registerDatabaseFactory(const std::string &pEngineName, IDatabaseFactory *factory)=0;
|
||||
virtual bool hasDatabaseFactory(const std::string &pEngineName)=0;
|
||||
|
||||
@ -8,13 +8,13 @@
|
||||
class ISessionMgr
|
||||
{
|
||||
public:
|
||||
virtual std::wstring GenerateSessionIDWithUser(const std::wstring &pUsername, const std::wstring &pIdentData, bool update_user=false)=0;
|
||||
virtual std::string GenerateSessionIDWithUser(const std::string &pUsername, const std::string &pIdentData, bool update_user=false)=0;
|
||||
|
||||
virtual SUser *getUser(const std::wstring &pSID, const std::wstring &pIdentData, bool update=true)=0;
|
||||
virtual SUser *getUser(const std::string &pSID, const std::string &pIdentData, bool update=true)=0;
|
||||
virtual void releaseUser(SUser *user)=0;
|
||||
virtual void lockUser(SUser *user)=0;
|
||||
|
||||
virtual bool RemoveSession(const std::wstring &pSID)=0;
|
||||
virtual bool RemoveSession(const std::string &pSID)=0;
|
||||
};
|
||||
|
||||
#endif //ISESSIONMGR_H
|
||||
@ -9,21 +9,14 @@ class ISettingsReader : public IObject
|
||||
{
|
||||
public:
|
||||
virtual bool getValue(std::string key, std::string *value)=0;
|
||||
virtual bool getValue(std::wstring key, std::wstring *value)=0;
|
||||
|
||||
virtual std::string getValue(std::string key,std::string def)=0;
|
||||
virtual std::string getValue(std::string key, std::string def)=0;
|
||||
virtual std::string getValue(std::string key)=0;
|
||||
virtual int getValue(std::string key, int def)=0;
|
||||
virtual float getValue(std::string key, float def)=0;
|
||||
virtual int64 getValue(std::string key, int64 def)=0;
|
||||
|
||||
virtual std::wstring getValue(std::wstring key,std::wstring def)=0;
|
||||
virtual std::wstring getValue(std::wstring key)=0;
|
||||
virtual int getValue(std::wstring key, int def)=0;
|
||||
virtual float getValue(std::wstring key, float def)=0;
|
||||
virtual int64 getValue(std::wstring key, int64 def)=0;
|
||||
|
||||
virtual std::vector<std::wstring> getKeys() = 0;
|
||||
virtual std::vector<std::string> getKeys() = 0;
|
||||
};
|
||||
|
||||
#endif //INTERFACE_SETTINGSREADER_H
|
||||
@ -7,12 +7,12 @@
|
||||
class ITable : public IObject
|
||||
{
|
||||
public:
|
||||
virtual void addObject(std::wstring key, ITable *tab)=0;
|
||||
virtual void addObject(std::string key, ITable *tab)=0;
|
||||
virtual ITable* getObject(size_t n)=0;
|
||||
virtual ITable* getObject(std::wstring key)=0;
|
||||
virtual std::wstring getValue()=0;
|
||||
virtual ITable* getObject(std::string key)=0;
|
||||
virtual std::string getValue()=0;
|
||||
virtual size_t getSize()=0;
|
||||
virtual void addString(std::wstring key, std::wstring str)=0;
|
||||
virtual void addString(std::string key, std::string str)=0;
|
||||
};
|
||||
|
||||
#endif //ITABLE_H
|
||||
@ -11,8 +11,8 @@ class ITemplate : public IObject
|
||||
public:
|
||||
virtual void Reset(void)=0;
|
||||
|
||||
virtual void setValue(std::wstring key, std::wstring value)=0;
|
||||
virtual ITable* getTable(std::wstring key)=0;
|
||||
virtual void setValue(std::string key, std::string value)=0;
|
||||
virtual ITable* getTable(std::string key)=0;
|
||||
virtual std::string getData(void)=0;
|
||||
|
||||
virtual void addValueTable( IDatabase* db, const std::string &table)=0;
|
||||
|
||||
@ -38,19 +38,11 @@ const THREAD_ID ILLEGAL_THREAD_ID=-1;
|
||||
const PLUGIN_ID ILLEGAL_PLUGIN_ID=-1;
|
||||
const THREADPOOL_TICKET ILLEGAL_THREADPOOL_TICKET=0;
|
||||
|
||||
typedef std::map<std::wstring,std::wstring> str_map;
|
||||
typedef std::map<std::wstring,float> float_map;
|
||||
typedef std::map<std::wstring,int> int_map;
|
||||
typedef std::map<std::string,std::string> str_map;
|
||||
typedef std::map<std::string,float> float_map;
|
||||
typedef std::map<std::string,int> int_map;
|
||||
|
||||
typedef std::map<std::string,std::string> str_nmap;
|
||||
typedef std::map<std::string,float> float_nmap;
|
||||
typedef std::map<std::string,int> int_nmap;
|
||||
|
||||
typedef std::map<std::string, std::string> db_nsingle_result;
|
||||
typedef std::vector< db_nsingle_result > db_nresults;
|
||||
|
||||
|
||||
typedef std::map<std::wstring, std::wstring> db_single_result;
|
||||
typedef std::map<std::string, std::string> db_single_result;
|
||||
typedef std::vector< db_single_result > db_results;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@ -9,9 +9,9 @@
|
||||
|
||||
struct SUser
|
||||
{
|
||||
std::wstring username;
|
||||
std::wstring session;
|
||||
std::wstring ident_data;
|
||||
std::string username;
|
||||
std::string session;
|
||||
std::string ident_data;
|
||||
int id;
|
||||
str_map mStr;
|
||||
int_map mInt;
|
||||
|
||||
@ -41,28 +41,13 @@ CMemorySettingsReader::CMemorySettingsReader(const std::string &pData)
|
||||
value=line;
|
||||
}
|
||||
|
||||
mSettingsMap.insert(std::pair<std::wstring,std::wstring>(Server->ConvertToUnicode(key), Server->ConvertToUnicode(value)) );
|
||||
mSettingsMap.insert(std::pair<std::string,std::string>((key), (value)) );
|
||||
}
|
||||
}
|
||||
|
||||
bool CMemorySettingsReader::getValue(std::string key, std::string *value)
|
||||
{
|
||||
std::wstring s_value;
|
||||
bool b=getValue( widen(key), &s_value);
|
||||
|
||||
if(b==true)
|
||||
{
|
||||
std::string nvalue=wnarrow(s_value);
|
||||
*value=nvalue;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CMemorySettingsReader::getValue(std::wstring key, std::wstring *value)
|
||||
{
|
||||
std::map<std::wstring,std::wstring>::iterator i=mSettingsMap.find(key);
|
||||
std::map<std::string,std::string>::iterator i=mSettingsMap.find(key);
|
||||
if( i!=mSettingsMap.end() )
|
||||
{
|
||||
*value=i->second;
|
||||
@ -72,10 +57,10 @@ bool CMemorySettingsReader::getValue(std::wstring key, std::wstring *value)
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CMemorySettingsReader::getKeys()
|
||||
std::vector<std::string> CMemorySettingsReader::getKeys()
|
||||
{
|
||||
std::vector<std::wstring> ret;
|
||||
for(std::map<std::wstring,std::wstring>::iterator i=mSettingsMap.begin();i!=mSettingsMap.end();++i)
|
||||
std::vector<std::string> ret;
|
||||
for(std::map<std::string,std::string>::iterator i=mSettingsMap.begin();i!=mSettingsMap.end();++i)
|
||||
{
|
||||
ret.push_back(i->first);
|
||||
}
|
||||
|
||||
@ -8,10 +8,9 @@ public:
|
||||
CMemorySettingsReader(const std::string &pData);
|
||||
|
||||
virtual bool getValue(std::string key, std::string *value);
|
||||
virtual bool getValue(std::wstring key, std::wstring *value);
|
||||
|
||||
virtual std::vector<std::wstring> getKeys();
|
||||
virtual std::vector<std::string> getKeys();
|
||||
|
||||
private:
|
||||
std::map<std::wstring,std::wstring> mSettingsMap;
|
||||
std::map<std::string,std::string> mSettingsMap;
|
||||
};
|
||||
@ -27,22 +27,22 @@ CMutex::CMutex(void)
|
||||
int rc;
|
||||
if((rc=pthread_mutexattr_init(&attr))!=0)
|
||||
{
|
||||
Server->Log("Error initializing mutexattr rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error initializing mutexattr rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
if((rc=pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE))!=0)
|
||||
{
|
||||
Server->Log("Error setting PTHREAD_MUTEX_RECURSIVE rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error setting PTHREAD_MUTEX_RECURSIVE rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
if((rc=pthread_mutex_init(&ptmutex, &attr))!=0)
|
||||
{
|
||||
Server->Log("Error initializing mutex rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error initializing mutex rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
if((rc=pthread_mutexattr_destroy(&attr))!=0)
|
||||
{
|
||||
Server->Log("Error destroing mutexattr rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error destroing mutexattr rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@ -52,7 +52,7 @@ CMutex::~CMutex(void)
|
||||
int rc;
|
||||
if( (rc=pthread_mutex_destroy(&ptmutex))!=0)
|
||||
{
|
||||
Server->Log("Error destroying mutex rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error destroying mutex rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,7 @@ void CMutex::Lock(void)
|
||||
int rc;
|
||||
if((rc=pthread_mutex_lock( &ptmutex ))!=0)
|
||||
{
|
||||
Server->Log("Error locking mutex rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error locking mutex rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,7 @@ void CMutex::Unlock(void)
|
||||
int rc;
|
||||
if((rc=pthread_mutex_unlock( &ptmutex ))!=0)
|
||||
{
|
||||
Server->Log("Error unlocking mutex rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error unlocking mutex rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ CLock::CLock(pthread_mutex_t *ptmutex)
|
||||
int rc;
|
||||
if((rc=pthread_mutex_lock(ptmutex))!=0)
|
||||
{
|
||||
Server->Log("Error locking mutex -2 rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error locking mutex -2 rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
lock=ptmutex;
|
||||
@ -103,7 +103,7 @@ CLock::~CLock()
|
||||
int rc;
|
||||
if((rc=pthread_mutex_unlock(lock))!=0)
|
||||
{
|
||||
Server->Log("Error unlocking mutex -2 rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error unlocking mutex -2 rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ bool PipeThrottler::addBytes(size_t new_bytes, bool wait)
|
||||
{
|
||||
if(wait)
|
||||
{
|
||||
DLOG(Server->Log("Throttler: Sleeping for " + nconvert(sleepTime)+ "ms", LL_DEBUG));
|
||||
DLOG(Server->Log("Throttler: Sleeping for " + convert(sleepTime)+ "ms", LL_DEBUG));
|
||||
Server->wait(sleepTime);
|
||||
|
||||
if(Server->getTimeMS()-lastresettime>1000)
|
||||
@ -101,7 +101,7 @@ bool PipeThrottler::addBytes(size_t new_bytes, bool wait)
|
||||
{
|
||||
if(wait)
|
||||
{
|
||||
DLOG(Server->Log("Throttler: Sleeping for " + nconvert(maxRateTime)+ "ms", LL_DEBUG));
|
||||
DLOG(Server->Log("Throttler: Sleeping for " + convert(maxRateTime)+ "ms", LL_DEBUG));
|
||||
Server->wait(static_cast<unsigned int>(maxRateTime));
|
||||
}
|
||||
curr_bytes=0;
|
||||
|
||||
212
Query.cpp
212
Query.cpp
@ -81,28 +81,6 @@ void CQuery::Bind(const std::string &str)
|
||||
++curr_idx;
|
||||
}
|
||||
|
||||
void CQuery::Bind(const std::wstring &str)
|
||||
{
|
||||
int err;
|
||||
if( sizeof(wchar_t)==2 )
|
||||
{
|
||||
err=sqlite3_bind_text16(ps, curr_idx, str.c_str(), (int)str.size()*2, SQLITE_TRANSIENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned short *tmp=new unsigned short[str.size()];
|
||||
for(size_t i=0,l=str.size();i<l;++i)
|
||||
{
|
||||
tmp[i]=str[i];
|
||||
}
|
||||
err=sqlite3_bind_text16(ps, curr_idx, tmp, (int)str.size()*2, SQLITE_TRANSIENT);
|
||||
delete []tmp;
|
||||
}
|
||||
if( err!=SQLITE_OK )
|
||||
Server->Log("Error binding text to Query Stmt: ["+stmt_str+"]", LL_ERROR);
|
||||
++curr_idx;
|
||||
}
|
||||
|
||||
void CQuery::Bind(const char* buffer, _u32 bsize)
|
||||
{
|
||||
int err=sqlite3_bind_blob(ps, curr_idx, buffer, bsize, SQLITE_TRANSIENT);
|
||||
@ -309,42 +287,6 @@ void CQuery::shutdownStepping(int err, int *timeoutms, bool& transaction_lock)
|
||||
}
|
||||
}
|
||||
|
||||
db_nresults CQuery::ReadN(int *timeoutms)
|
||||
{
|
||||
int err;
|
||||
db_nresults rows;
|
||||
|
||||
bool transaction_lock=false;
|
||||
int tries=60; //10min
|
||||
|
||||
#ifdef LOG_READ_QUERIES
|
||||
ScopedAddActiveQuery active_query(this);
|
||||
#endif
|
||||
|
||||
setupStepping(timeoutms);
|
||||
|
||||
db_nsingle_result res;
|
||||
do
|
||||
{
|
||||
bool reset=false;
|
||||
err=stepN(res, timeoutms, tries, transaction_lock, reset);
|
||||
if(reset)
|
||||
{
|
||||
rows.clear();
|
||||
}
|
||||
if(err==SQLITE_ROW)
|
||||
{
|
||||
rows.push_back(res);
|
||||
res.clear();
|
||||
}
|
||||
}
|
||||
while(resultOkay(err));
|
||||
|
||||
shutdownStepping(err, timeoutms, transaction_lock);
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
db_results CQuery::Read(int *timeoutms)
|
||||
{
|
||||
int err;
|
||||
@ -388,6 +330,20 @@ bool CQuery::resultOkay(int rc)
|
||||
rc==SQLITE_IOERR_BLOCKED;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string ustring_sqlite3_column_name(sqlite3_stmt* ps, int N)
|
||||
{
|
||||
const char* c_name = sqlite3_column_name(ps, N);
|
||||
if(c_name==NULL)
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return std::string(c_name);
|
||||
}
|
||||
}
|
||||
|
||||
int CQuery::step(db_single_result& res, int *timeoutms, int& tries, bool& transaction_lock, bool& reset)
|
||||
{
|
||||
int err=sqlite3_step(ps);
|
||||
@ -429,139 +385,23 @@ int CQuery::step(db_single_result& res, int *timeoutms, int& tries, bool& transa
|
||||
else if( err==SQLITE_ROW )
|
||||
{
|
||||
int column=0;
|
||||
const unsigned short *c_name;
|
||||
while( (c_name=(const unsigned short*)sqlite3_column_name16(ps, column) )!=NULL )
|
||||
std::string column_name;
|
||||
while( !(column_name=ustring_sqlite3_column_name(ps, column) ).empty() )
|
||||
{
|
||||
std::wstring column_name;
|
||||
if( sizeof(wchar_t)!=2 )
|
||||
const void* data;
|
||||
int data_size;
|
||||
if(sqlite3_column_type(ps, column)==SQLITE_BLOB)
|
||||
{
|
||||
size_t len=0;
|
||||
while(c_name[len]!=0)
|
||||
++len;
|
||||
|
||||
column_name.resize(len);
|
||||
for(size_t i=0;i<len;++i)
|
||||
{
|
||||
column_name[i]=c_name[i];
|
||||
}
|
||||
data = sqlite3_column_blob(ps, column);
|
||||
data_size =sqlite3_column_bytes(ps, column);
|
||||
}
|
||||
else
|
||||
{
|
||||
column_name=(wchar_t*)c_name;
|
||||
data = sqlite3_column_text(ps, column);
|
||||
data_size = sqlite3_column_bytes(ps, column);
|
||||
}
|
||||
std::wstring data;
|
||||
int blob_size=sqlite3_column_bytes16(ps, column);
|
||||
const void *blob=sqlite3_column_blob(ps, column);
|
||||
//int blob_size2=sqlite3_column_bytes(ps, column);
|
||||
if(blob_size>0)
|
||||
{
|
||||
if( sizeof(wchar_t)==2 )
|
||||
{
|
||||
data.resize(blob_size/2+blob_size%2);
|
||||
memcpy(&data[0], blob, blob_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( SQLITE_BLOB==sqlite3_column_type(ps, column) )
|
||||
{
|
||||
size_t size=(size_t)(blob_size/sizeof(wchar_t))+((blob_size%sizeof(wchar_t))>0?1:0);
|
||||
|
||||
data.resize(size);
|
||||
char* ptr=(char*)data.c_str();
|
||||
memcpy(ptr, blob, blob_size);
|
||||
|
||||
if( blob_size%sizeof(wchar_t)>0 )
|
||||
{
|
||||
memset(ptr+blob_size, 0, sizeof(wchar_t)-blob_size%sizeof(wchar_t) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data.resize(blob_size/sizeof(unsigned short));
|
||||
unsigned short *ip=(unsigned short*)blob;
|
||||
for(int i=0,l=blob_size/sizeof(unsigned short);i<l;++i)
|
||||
{
|
||||
|
||||
data[i]=*ip;
|
||||
++ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
res.insert( std::pair<std::wstring, std::wstring>(column_name, data) );
|
||||
++column;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->wait(1000);
|
||||
if(timeoutms!=NULL && *timeoutms>=0)
|
||||
{
|
||||
*timeoutms-=1000;
|
||||
|
||||
if(*timeoutms<=0)
|
||||
{
|
||||
return SQLITE_ABORT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
int CQuery::stepN(db_nsingle_result& res, int *timeoutms, int& tries, bool& transaction_lock, bool& reset)
|
||||
{
|
||||
int err=sqlite3_step(ps);
|
||||
if(resultOkay(err))
|
||||
{
|
||||
if( err==SQLITE_BUSY || err==SQLITE_IOERR_BLOCKED )
|
||||
{
|
||||
if(timeoutms!=NULL && *timeoutms>=0)
|
||||
{
|
||||
return SQLITE_ABORT;
|
||||
}
|
||||
else if(!db->isInTransaction() && !transaction_lock)
|
||||
{
|
||||
sqlite3_reset(ps);
|
||||
reset=true;
|
||||
if(db->LockForTransaction())
|
||||
{
|
||||
Server->Log("LockForTransaction in CQuery::ReadN Stmt: ["+stmt_str+"]", LL_DEBUG);
|
||||
transaction_lock=true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlite3_reset(ps);
|
||||
reset=true;
|
||||
--tries;
|
||||
if(tries==-1)
|
||||
{
|
||||
Server->Log("SQLITE: Long running query Stmt: ["+stmt_str+"]", LL_ERROR);
|
||||
showActiveQueries(LL_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->Log("SQLITE_BUSY in CQuery::ReadN Stmt: ["+stmt_str+"]", LL_INFO);
|
||||
showActiveQueries(LL_INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( err==SQLITE_ROW )
|
||||
{
|
||||
int column=0;
|
||||
const char *column_name;
|
||||
while( (column_name=sqlite3_column_name(ps, column) )!=NULL )
|
||||
{
|
||||
std::string data;
|
||||
const void *blob=sqlite3_column_blob(ps, column);
|
||||
int blob_size=sqlite3_column_bytes(ps, column);
|
||||
if(blob_size>0 && blob!=NULL)
|
||||
{
|
||||
data.resize(blob_size);
|
||||
memcpy(&data[0], blob, blob_size);
|
||||
}
|
||||
res.insert( std::pair<std::string, std::string>(column_name, data) );
|
||||
std::string datastr(reinterpret_cast<const char*>(data), reinterpret_cast<const char*>(data)+data_size);
|
||||
res.insert( std::pair<std::string, std::string>(column_name, datastr) );
|
||||
++column;
|
||||
}
|
||||
}
|
||||
@ -628,7 +468,7 @@ void CQuery::showActiveQueries(int loglevel)
|
||||
IScopedLock lock(active_mutex);
|
||||
for(size_t i=0;i<active_queries.size();++i)
|
||||
{
|
||||
Server->Log("Active query("+nconvert(i)+"): "+active_queries[i], loglevel);
|
||||
Server->Log("Active query("+convert(i)+"): "+active_queries[i], loglevel);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
4
Query.h
4
Query.h
@ -28,7 +28,6 @@ public:
|
||||
static void init_mutex(void);
|
||||
|
||||
virtual void Bind(const std::string &str);
|
||||
virtual void Bind(const std::wstring &str);
|
||||
virtual void Bind(int p);
|
||||
virtual void Bind(unsigned int p);
|
||||
virtual void Bind(double p);
|
||||
@ -42,7 +41,6 @@ public:
|
||||
|
||||
virtual bool Write(int timeoutms=-1);
|
||||
db_results Read(int *timeoutms=NULL);
|
||||
db_nresults ReadN(int *timeoutms=NULL);
|
||||
|
||||
virtual IDatabaseCursor* Cursor(int *timeoutms=NULL);
|
||||
|
||||
@ -51,8 +49,6 @@ public:
|
||||
|
||||
int step(db_single_result& res, int *timeoutms, int& tries, bool& transaction_lock, bool& reset);
|
||||
|
||||
int stepN(db_nsingle_result& res, int *timeoutms, int& tries, bool& transaction_lock, bool& reset);
|
||||
|
||||
bool resultOkay(int rc);
|
||||
|
||||
std::string getStatement(void);
|
||||
|
||||
@ -110,6 +110,7 @@
|
||||
<ClCompile Include="..\SQLiteFactory.cpp" />
|
||||
<ClCompile Include="..\sqlite\shell.c" />
|
||||
<ClCompile Include="..\sqlite\sqlite3.c" />
|
||||
<ClCompile Include="..\StaticPluginRegistration.cpp" />
|
||||
<ClCompile Include="..\StreamPipe.cpp" />
|
||||
<ClCompile Include="..\stringtools.cpp" />
|
||||
<ClCompile Include="..\Table.cpp" />
|
||||
|
||||
@ -132,6 +132,9 @@
|
||||
<ClCompile Include="..\SharedMutex_boost.cpp">
|
||||
<Filter>Server</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\StaticPluginRegistration.cpp">
|
||||
<Filter>Server</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\Database.h">
|
||||
|
||||
@ -260,7 +260,7 @@ void generateStructure(std::string name, std::vector<ReturnType> return_types, G
|
||||
{
|
||||
std::string type=return_types[i].type;
|
||||
if(type=="string")
|
||||
type="std::wstring";
|
||||
type="std::string";
|
||||
if(type=="blob")
|
||||
type="std::string";
|
||||
|
||||
@ -292,7 +292,7 @@ std::string generateConditional(ReturnType rtype, GeneratedData& gen_data)
|
||||
code+="\t\tbool exists;\r\n";
|
||||
std::string type=rtype.type;
|
||||
if(type=="string")
|
||||
type="std::wstring";
|
||||
type="std::string";
|
||||
if(type=="blob")
|
||||
type="std::string";
|
||||
code+="\t\t"+type+" value;\r\n";
|
||||
@ -321,9 +321,7 @@ std::string return_blob(size_t tabs, std::string value_name, std::string sql_nam
|
||||
static int nb = 0;
|
||||
std::string tabss(tabs, '\t');
|
||||
++nb;
|
||||
ret+=tabss+"std::wstring& val"+nconvert(nb)+" = res["+res_idx+"][L\""+sql_name+"\"];\r\n";
|
||||
ret+=tabss+value_name+".resize(val"+nconvert(nb)+".size()*sizeof(wchar_t));\r\n";
|
||||
ret+=tabss+"memcpy(&"+value_name+"[0], val"+nconvert(nb)+".data(), val"+nconvert(nb)+".size()*sizeof(wchar_t));\r\n";
|
||||
ret+=tabss+value_name+"=res["+res_idx+"][\""+sql_name+"\"];\r\n";
|
||||
if(do_return)
|
||||
{
|
||||
ret+=tabss+"return "+value_name+";\r\n";
|
||||
@ -364,7 +362,7 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
struct_name=getbetween("<", ">", return_type);
|
||||
if(struct_name=="string")
|
||||
{
|
||||
return_type="std::vector<std::wstring>";
|
||||
return_type="std::vector<std::string>";
|
||||
}
|
||||
return_vector=true;
|
||||
}
|
||||
@ -487,7 +485,7 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
{
|
||||
if(return_types[0].type=="string")
|
||||
{
|
||||
return_outer+="std::wstring";
|
||||
return_outer+="std::string";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -511,10 +509,10 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
|
||||
|
||||
if(return_outer=="string")
|
||||
return_outer="std::wstring";
|
||||
return_outer="std::string";
|
||||
|
||||
if(return_type=="string")
|
||||
return_type="std::wstring";
|
||||
return_type="std::string";
|
||||
|
||||
std::string funcdecl=return_type+" "+func_s_name+"(";
|
||||
std::string code="\r\n"+return_outer+" "+funcsig+"(";
|
||||
@ -540,9 +538,9 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
funcdecl+=", ";
|
||||
}
|
||||
std::string type=params[i].type;
|
||||
if(type=="string" || type=="std::wstring" )
|
||||
if(type=="string" || type=="std::string" )
|
||||
{
|
||||
type="const std::wstring&";
|
||||
type="const std::string&";
|
||||
}
|
||||
else if(type=="blob")
|
||||
{
|
||||
@ -626,7 +624,7 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
{
|
||||
if(return_types[0].type=="string")
|
||||
{
|
||||
code+="std::wstring";
|
||||
code+="std::string";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -653,11 +651,11 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
{
|
||||
if(return_types[i].type=="int")
|
||||
{
|
||||
code+="\t\tret[i]."+return_types[i].name+"=watoi(res[i][L\""+return_types[i].name+"\"]);\r\n";
|
||||
code+="\t\tret[i]."+return_types[i].name+"=watoi(res[i][\""+return_types[i].name+"\"]);\r\n";
|
||||
}
|
||||
else if(return_types[i].type=="int64")
|
||||
{
|
||||
code+="\t\tret[i]."+return_types[i].name+"=watoi64(res[i][L\""+return_types[i].name+"\"]);\r\n";
|
||||
code+="\t\tret[i]."+return_types[i].name+"=watoi64(res[i][\""+return_types[i].name+"\"]);\r\n";
|
||||
}
|
||||
else if(return_types[i].type=="blob")
|
||||
{
|
||||
@ -665,7 +663,7 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
}
|
||||
else
|
||||
{
|
||||
code+="\t\tret[i]."+return_types[i].name+"=res[i][L\""+return_types[i].name+"\"];\r\n";
|
||||
code+="\t\tret[i]."+return_types[i].name+"=res[i][\""+return_types[i].name+"\"];\r\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -675,11 +673,11 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
{
|
||||
if(return_types[0].type=="int")
|
||||
{
|
||||
code+="\t\tret[i]=watoi(res[i][L\""+return_types[0].name+"\"]);\r\n";
|
||||
code+="\t\tret[i]=watoi(res[i][\""+return_types[0].name+"\"]);\r\n";
|
||||
}
|
||||
else if(return_types[0].type=="int64")
|
||||
{
|
||||
code+="\t\tret[i]=watoi64(res[i][L\""+return_types[0].name+"\"]);\r\n";
|
||||
code+="\t\tret[i]=watoi64(res[i][\""+return_types[0].name+"\"]);\r\n";
|
||||
}
|
||||
else if(return_types[0].type=="blob")
|
||||
{
|
||||
@ -687,7 +685,7 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
}
|
||||
else
|
||||
{
|
||||
code+="\t\tret[i]=res[i][L\""+return_types[0].name+"\"];\r\n";
|
||||
code+="\t\tret[i]=res[i][\""+return_types[0].name+"\"];\r\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -716,7 +714,7 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
}
|
||||
else
|
||||
{
|
||||
code+="L\"\"";
|
||||
code+="\"\"";
|
||||
}
|
||||
if(i+1<return_types.size())
|
||||
{
|
||||
@ -737,7 +735,7 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
}
|
||||
else
|
||||
{
|
||||
code+="L\"\"";
|
||||
code+="\"\"";
|
||||
}
|
||||
}
|
||||
code+=" };\r\n";
|
||||
@ -753,11 +751,11 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
{
|
||||
if(return_types[i].type=="int")
|
||||
{
|
||||
code+="\t\tret."+return_types[i].name+"=watoi(res[0][L\""+return_types[i].name+"\"]);\r\n";
|
||||
code+="\t\tret."+return_types[i].name+"=watoi(res[0][\""+return_types[i].name+"\"]);\r\n";
|
||||
}
|
||||
else if(return_types[i].type=="int64")
|
||||
{
|
||||
code+="\t\tret."+return_types[i].name+"=watoi64(res[0][L\""+return_types[i].name+"\"]);\r\n";
|
||||
code+="\t\tret."+return_types[i].name+"=watoi64(res[0][\""+return_types[i].name+"\"]);\r\n";
|
||||
}
|
||||
else if(return_types[i].type=="blob")
|
||||
{
|
||||
@ -765,7 +763,7 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
}
|
||||
else
|
||||
{
|
||||
code+="\t\tret."+return_types[i].name+"=res[0][L\""+return_types[i].name+"\"];\r\n";
|
||||
code+="\t\tret."+return_types[i].name+"=res[0][\""+return_types[i].name+"\"];\r\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -773,11 +771,11 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
{
|
||||
if(return_types[0].type=="int")
|
||||
{
|
||||
code+="\t\tret.value=watoi(res[0][L\""+return_types[0].name+"\"]);\r\n";
|
||||
code+="\t\tret.value=watoi(res[0][\""+return_types[0].name+"\"]);\r\n";
|
||||
}
|
||||
else if(return_types[0].type=="int64")
|
||||
{
|
||||
code+="\t\tret.value=watoi64(res[0][L\""+return_types[0].name+"\"]);\r\n";
|
||||
code+="\t\tret.value=watoi64(res[0][\""+return_types[0].name+"\"]);\r\n";
|
||||
}
|
||||
else if(return_types[0].type=="blob")
|
||||
{
|
||||
@ -785,7 +783,7 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
}
|
||||
else
|
||||
{
|
||||
code+="\t\tret.value=res[0][L\""+return_types[0].name+"\"];\r\n";
|
||||
code+="\t\tret.value=res[0][\""+return_types[0].name+"\"];\r\n";
|
||||
}
|
||||
}
|
||||
code+="\t}\r\n";
|
||||
@ -796,11 +794,11 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
code+="\tassert(!res.empty());\r\n";
|
||||
if(return_types[0].type=="int")
|
||||
{
|
||||
code+="\treturn watoi(res[0][L\""+return_types[0].name+"\"]);\r\n";
|
||||
code+="\treturn watoi(res[0][\""+return_types[0].name+"\"]);\r\n";
|
||||
}
|
||||
else if(return_types[0].type=="int64")
|
||||
{
|
||||
code+="\treturn watoi64(res[0][L\""+return_types[0].name+"\"]);\r\n";
|
||||
code+="\treturn watoi64(res[0][\""+return_types[0].name+"\"]);\r\n";
|
||||
}
|
||||
else if(return_types[0].type=="blob")
|
||||
{
|
||||
@ -808,7 +806,7 @@ AnnotatedCode generateSqlFunction(IDatabase* db, AnnotatedCode input, GeneratedD
|
||||
}
|
||||
else
|
||||
{
|
||||
code+="\treturn res[0][L\""+return_types[0].name+"\"];\r\n";
|
||||
code+="\treturn res[0][\""+return_types[0].name+"\"];\r\n";
|
||||
}
|
||||
}
|
||||
code+="}";
|
||||
|
||||
@ -82,7 +82,7 @@ CSelectThread::~CSelectThread()
|
||||
IScopedLock lock(workers_mutex);
|
||||
for(size_t i=0;i<workers.size();++i)
|
||||
{
|
||||
Server->Log("worker: "+nconvert(i));
|
||||
Server->Log("worker: "+convert(i));
|
||||
delete workers[i];
|
||||
}
|
||||
workers.clear();
|
||||
@ -226,7 +226,7 @@ void CSelectThread::operator()()
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->Log("Select error: "+nconvert(errno),LL_ERROR);
|
||||
Server->Log("Select error: "+convert(errno),LL_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
340
Server.cpp
340
Server.cpp
@ -267,9 +267,9 @@ CServer::~CServer()
|
||||
|
||||
Log("Deleting actions...");
|
||||
|
||||
for(std::map< std::wstring, std::map<std::wstring, IAction*> >::iterator iter1=actions.begin();iter1!=actions.end();++iter1)
|
||||
for(std::map< std::string, std::map<std::string, IAction*> >::iterator iter1=actions.begin();iter1!=actions.end();++iter1)
|
||||
{
|
||||
for(std::map<std::wstring, IAction*>::iterator iter2=iter1->second.begin();iter2!=iter1->second.end();++iter2)
|
||||
for(std::map<std::string, IAction*>::iterator iter2=iter1->second.begin();iter2!=iter1->second.end();++iter2)
|
||||
{
|
||||
iter2->second->Remove();
|
||||
}
|
||||
@ -322,7 +322,7 @@ CServer::~CServer()
|
||||
std::cout << "Server cleanup done..." << std::endl;
|
||||
}
|
||||
|
||||
void CServer::setServerParameters(const str_nmap &pServerParams)
|
||||
void CServer::setServerParameters(const str_map &pServerParams)
|
||||
{
|
||||
IScopedLock lock(param_mutex);
|
||||
server_params=pServerParams;
|
||||
@ -336,7 +336,7 @@ std::string CServer::getServerParameter(const std::string &key)
|
||||
std::string CServer::getServerParameter(const std::string &key, const std::string &def)
|
||||
{
|
||||
IScopedLock lock(param_mutex);
|
||||
str_nmap::iterator iter=server_params.find(key);
|
||||
str_map::iterator iter=server_params.find(key);
|
||||
if( iter!=server_params.end() )
|
||||
{
|
||||
return iter->second;
|
||||
@ -424,10 +424,10 @@ void CServer::rotateLogfile()
|
||||
|
||||
for(size_t i=log_rotation_files-1;i>0;--i)
|
||||
{
|
||||
rename((logfile_fn+"."+nconvert(i)).c_str(), (logfile_fn+"."+nconvert(i+1)).c_str());
|
||||
rename((logfile_fn+"."+convert(i)).c_str(), (logfile_fn+"."+convert(i+1)).c_str());
|
||||
}
|
||||
|
||||
deleteFile(logfile_fn+"."+nconvert(log_rotation_files));
|
||||
deleteFile(logfile_fn+"."+convert(log_rotation_files));
|
||||
|
||||
rename(logfile_fn.c_str(), (logfile_fn+".1").c_str());
|
||||
|
||||
@ -435,71 +435,6 @@ void CServer::rotateLogfile()
|
||||
}
|
||||
}
|
||||
|
||||
void CServer::Log( const std::wstring &pStr, int LogLevel)
|
||||
{
|
||||
if( loglevel <=LogLevel )
|
||||
{
|
||||
IScopedLock lock(log_mutex);
|
||||
|
||||
time_t rawtime;
|
||||
char buffer [100];
|
||||
time ( &rawtime );
|
||||
#ifdef _WIN32
|
||||
struct tm timeinfo;
|
||||
localtime_s(&timeinfo, &rawtime);
|
||||
strftime (buffer,100,"%Y-%m-%d %X: ",&timeinfo);
|
||||
#else
|
||||
struct tm *timeinfo;
|
||||
timeinfo = localtime ( &rawtime );
|
||||
strftime (buffer,100,"%Y-%m-%d %X: ",timeinfo);
|
||||
#endif
|
||||
|
||||
std::string out_str=ConvertToUTF8(pStr);
|
||||
|
||||
if(log_console_time)
|
||||
{
|
||||
std::cout << buffer;
|
||||
}
|
||||
|
||||
if( LogLevel==LL_ERROR )
|
||||
{
|
||||
std::cout << "ERROR: " << out_str << std::endl;
|
||||
if(logfile_a)
|
||||
logfile << buffer << "ERROR: " << out_str << std::endl;
|
||||
}
|
||||
else if( LogLevel==LL_WARNING )
|
||||
{
|
||||
std::cout << "WARNING: " << out_str << std::endl;
|
||||
if(logfile_a)
|
||||
logfile << buffer << "WARNING: " << out_str << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << out_str << std::endl;
|
||||
if(logfile_a)
|
||||
logfile << buffer << out_str<< std::endl;
|
||||
}
|
||||
|
||||
if(logfile_a)
|
||||
{
|
||||
logfile.flush();
|
||||
|
||||
rotateLogfile();
|
||||
}
|
||||
|
||||
if(has_circular_log_buffer)
|
||||
{
|
||||
logToCircularBuffer(out_str, LogLevel);
|
||||
}
|
||||
}
|
||||
else if(has_circular_log_buffer)
|
||||
{
|
||||
IScopedLock lock(log_mutex);
|
||||
|
||||
logToCircularBuffer(ConvertToUTF8(pStr), LogLevel);
|
||||
}
|
||||
}
|
||||
|
||||
void CServer::setLogFile(const std::string &plf, std::string chown_user)
|
||||
{
|
||||
IScopedLock lock(log_mutex);
|
||||
@ -540,15 +475,15 @@ void CServer::setLogLevel(int LogLevel)
|
||||
loglevel=LogLevel;
|
||||
}
|
||||
|
||||
THREAD_ID CServer::Execute(const std::wstring &action, const std::wstring &context, str_map &GET, str_map &POST, str_nmap &PARAMS, IOutputStream *req)
|
||||
THREAD_ID CServer::Execute(const std::string &action, const std::string &context, str_map &GET, str_map &POST, str_map &PARAMS, IOutputStream *req)
|
||||
{
|
||||
IAction *action_ptr=NULL;
|
||||
{
|
||||
IScopedLock lock(action_mutex);
|
||||
std::map<std::wstring, std::map<std::wstring, IAction*> >::iterator iter1=actions.find( context );
|
||||
std::map<std::string, std::map<std::string, IAction*> >::iterator iter1=actions.find( context );
|
||||
if( iter1!=actions.end() )
|
||||
{
|
||||
std::map<std::wstring, IAction*>::iterator iter2=iter1->second.find(action);
|
||||
std::map<std::string, IAction*>::iterator iter2=iter1->second.find(action);
|
||||
if( iter2!=iter1->second.end() )
|
||||
action_ptr=iter2->second;
|
||||
}
|
||||
@ -599,7 +534,7 @@ THREAD_ID CServer::Execute(const std::wstring &action, const std::wstring &conte
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string CServer::Execute(const std::wstring &action, const std::wstring &context, str_map &GET, str_map &POST, str_nmap &PARAMS)
|
||||
std::string CServer::Execute(const std::string &action, const std::string &context, str_map &GET, str_map &POST, str_map &PARAMS)
|
||||
{
|
||||
CStringOutputStream cos;
|
||||
Execute(action, context, GET, POST, PARAMS, &cos);
|
||||
@ -610,19 +545,19 @@ void CServer::AddAction(IAction *action)
|
||||
{
|
||||
IScopedLock lock(action_mutex);
|
||||
|
||||
std::map<std::wstring, IAction*> *ptr=&actions[action_context];
|
||||
ptr->insert( std::pair<std::wstring, IAction*>(action->getName(), action ) );
|
||||
std::map<std::string, IAction*> *ptr=&actions[action_context];
|
||||
ptr->insert( std::pair<std::string, IAction*>(action->getName(), action ) );
|
||||
}
|
||||
|
||||
bool CServer::RemoveAction(IAction *action)
|
||||
{
|
||||
IScopedLock lock(action_mutex);
|
||||
|
||||
std::map<std::wstring, std::map<std::wstring, IAction*> >::iterator iter1=actions.find(action_context);
|
||||
std::map<std::string, std::map<std::string, IAction*> >::iterator iter1=actions.find(action_context);
|
||||
|
||||
if( iter1!=actions.end() )
|
||||
{
|
||||
std::map<std::wstring, IAction*>::iterator iter2=iter1->second.find( action->getName() );
|
||||
std::map<std::string, IAction*>::iterator iter2=iter1->second.find( action->getName() );
|
||||
if( iter2!=iter1->second.end() )
|
||||
{
|
||||
iter1->second.erase( iter2 );
|
||||
@ -632,7 +567,7 @@ bool CServer::RemoveAction(IAction *action)
|
||||
return false;
|
||||
}
|
||||
|
||||
void CServer::setActionContext(std::wstring context)
|
||||
void CServer::setActionContext(std::string context)
|
||||
{
|
||||
action_context=context;
|
||||
}
|
||||
@ -909,7 +844,7 @@ IDatabase* CServer::getDatabase(THREAD_ID tid, DATABASE_ID pIdentifier)
|
||||
std::map<DATABASE_ID, SDatabase >::iterator database_iter=databases.find(pIdentifier);
|
||||
if( database_iter==databases.end() )
|
||||
{
|
||||
Log("Database with identifier \""+nconvert((int)pIdentifier)+"\" couldn't be opened", LL_ERROR);
|
||||
Log("Database with identifier \""+convert((int)pIdentifier)+"\" couldn't be opened", LL_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1014,50 +949,12 @@ std::string CServer::GenerateHexMD5(const std::string &input)
|
||||
|
||||
std::string CServer::GenerateBinaryMD5(const std::string &input)
|
||||
{
|
||||
MD5 md((unsigned char*)input.c_str() );
|
||||
unsigned char *p=md.raw_digest();
|
||||
std::string ret;
|
||||
ret.resize(16);
|
||||
for(size_t i=0;i<16;++i)
|
||||
ret[i]=p[i];
|
||||
delete []p;
|
||||
MD5 md((unsigned char*)input.c_str(), static_cast<unsigned int>(input.size()));
|
||||
unsigned char *p=md.raw_digest_int();
|
||||
std::string ret(reinterpret_cast<char*>(p), reinterpret_cast<char*>(p)+16);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string CServer::GenerateHexMD5(const std::wstring &input)
|
||||
{
|
||||
unsigned int *tmp=new unsigned int[input.size()];
|
||||
for(size_t i=0,l=input.size();i<l;++i)
|
||||
{
|
||||
tmp[i]=input[i];
|
||||
}
|
||||
MD5 md((unsigned char*)tmp, (unsigned int)input.size()*sizeof(unsigned int) );
|
||||
char *p=md.hex_digest();
|
||||
std::string ret=p;
|
||||
delete []p;
|
||||
delete []tmp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string CServer::GenerateBinaryMD5(const std::wstring &input)
|
||||
{
|
||||
unsigned int *tmp=new unsigned int[input.size()];
|
||||
for(size_t i=0,l=input.size();i<l;++i)
|
||||
{
|
||||
tmp[i]=input[i];
|
||||
}
|
||||
MD5 md((unsigned char*)tmp, (unsigned int)input.size()*sizeof(unsigned int) );
|
||||
unsigned char *p=md.raw_digest();
|
||||
std::string ret;
|
||||
ret.resize(16);
|
||||
for(size_t i=0;i<16;++i)
|
||||
ret[i]=p[i];
|
||||
delete []p;
|
||||
delete []tmp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void CServer::StartCustomStreamService(IService *pService, std::string pServiceName, unsigned short pPort, int pMaxClientsPerThread, IServer::BindTarget bindTarget)
|
||||
{
|
||||
CServiceAcceptor *acc=new CServiceAcceptor(pService, pServiceName, pPort, pMaxClientsPerThread, bindTarget);
|
||||
@ -1143,7 +1040,7 @@ IPipe* CServer::ConnectStream(std::string pServer, unsigned short pPort, unsigne
|
||||
if(err)
|
||||
{
|
||||
closesocket(s);
|
||||
Server->Log("Socket has error: "+nconvert(err), LL_INFO);
|
||||
Server->Log("Socket has error: "+convert(err), LL_INFO);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
@ -1373,11 +1270,6 @@ ISettingsReader* CServer::createFileSettingsReader(const std::string& pFile)
|
||||
return new CFileSettingsReader(pFile);
|
||||
}
|
||||
|
||||
ISettingsReader* CServer::createFileSettingsReader(const std::wstring& pFile)
|
||||
{
|
||||
return new CFileSettingsReader(pFile);
|
||||
}
|
||||
|
||||
ISettingsReader* CServer::createDBSettingsReader(THREAD_ID tid, DATABASE_ID pIdentifier, const std::string &pTable, const std::string &pSQL)
|
||||
{
|
||||
return new CDBSettingsReader(tid, pIdentifier, pTable, pSQL);
|
||||
@ -1417,11 +1309,6 @@ void CServer::addRequest(void)
|
||||
}
|
||||
|
||||
IFile* CServer::openFile(std::string pFilename, int pMode)
|
||||
{
|
||||
return openFile(ConvertToUnicode(pFilename), pMode);
|
||||
}
|
||||
|
||||
IFile* CServer::openFile(std::wstring pFilename, int pMode)
|
||||
{
|
||||
File *file=new File;
|
||||
if(!file->Open(pFilename, pMode) )
|
||||
@ -1466,22 +1353,12 @@ bool CServer::deleteFile(std::string pFilename)
|
||||
return DeleteFileInt(pFilename);
|
||||
}
|
||||
|
||||
bool CServer::deleteFile(std::wstring pFilename)
|
||||
{
|
||||
return DeleteFileInt(pFilename);
|
||||
}
|
||||
|
||||
bool CServer::fileExists(std::string pFilename)
|
||||
{
|
||||
return FileExists(pFilename);
|
||||
}
|
||||
|
||||
bool CServer::fileExists(std::wstring pFilename)
|
||||
{
|
||||
#ifndef WIN32
|
||||
return FileExists(ConvertToUTF8(pFilename));
|
||||
return ::FileExists(pFilename);
|
||||
#else
|
||||
fstream in(pFilename.c_str(), ios::in);
|
||||
fstream in(ConvertToWchar(pFilename).c_str(), ios::in);
|
||||
if( in.is_open()==false )
|
||||
return false;
|
||||
|
||||
@ -1490,141 +1367,106 @@ bool CServer::fileExists(std::wstring pFilename)
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string CServer::ConvertToUTF8(const std::wstring &input)
|
||||
{
|
||||
std::string ret;
|
||||
try
|
||||
{
|
||||
if(sizeof(wchar_t)==2 )
|
||||
utf8::utf16to8(input.begin(), input.end(), back_inserter(ret));
|
||||
else
|
||||
utf8::utf32to8(input.begin(), input.end(), back_inserter(ret));
|
||||
}
|
||||
catch(...){}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::wstring CServer::ConvertToUnicode(const std::string &input)
|
||||
{
|
||||
std::wstring ret;
|
||||
try
|
||||
{
|
||||
if(sizeof(wchar_t)==2)
|
||||
utf8::utf8to16(input.begin(), input.end(), back_inserter(ret));
|
||||
else
|
||||
utf8::utf8to32(input.begin(), input.end(), back_inserter(ret));
|
||||
}
|
||||
catch(...){}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string CServer::ConvertToUTF16(const std::wstring &input)
|
||||
std::string CServer::ConvertToUTF16(const std::string &input)
|
||||
{
|
||||
std::string ret;
|
||||
try
|
||||
{
|
||||
if(sizeof(wchar_t)==2)
|
||||
{
|
||||
ret.resize(input.size()*2);
|
||||
memcpy(&ret[0], &input[0], input.size()*2);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string utf8=ConvertToUTF8(input);
|
||||
std::vector<utf8::uint16_t> tmp;
|
||||
utf8::utf8to16(utf8.begin(), utf8.end(), back_inserter(tmp) );
|
||||
ret.resize(tmp.size()*2);
|
||||
memcpy(&ret[0], &tmp[0], tmp.size()*2);
|
||||
}
|
||||
std::vector<utf8::uint16_t> tmp;
|
||||
utf8::utf8to16(input.begin(), input.end(), back_inserter(tmp) );
|
||||
ret.resize(tmp.size()*2);
|
||||
memcpy(&ret[0], &tmp[0], tmp.size()*2);
|
||||
}
|
||||
catch(...){}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string CServer::ConvertToUTF32(const std::wstring &input)
|
||||
std::string CServer::ConvertToUTF32(const std::string &input)
|
||||
{
|
||||
std::string ret;
|
||||
try
|
||||
{
|
||||
if(sizeof(wchar_t)==4)
|
||||
{
|
||||
ret.resize(input.size()*4);
|
||||
memcpy(&ret[0], &input[0], input.size()*4);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string utf8=ConvertToUTF8(input);
|
||||
std::vector<utf8::uint32_t> tmp;
|
||||
utf8::utf8to32(utf8.begin(), utf8.end(), back_inserter(tmp) );
|
||||
ret.resize(tmp.size()*4);
|
||||
memcpy(&ret[0], &tmp[0], tmp.size()*4);
|
||||
}
|
||||
std::vector<utf8::uint32_t> tmp;
|
||||
utf8::utf8to32(input.begin(), input.end(), back_inserter(tmp) );
|
||||
ret.resize(tmp.size()*4);
|
||||
memcpy(&ret[0], &tmp[0], tmp.size()*4);
|
||||
}
|
||||
catch(...){}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::wstring CServer::ConvertFromUTF16(const std::string &input)
|
||||
std::string CServer::ConvertFromUTF16(const std::string &input)
|
||||
{
|
||||
std::wstring ret;
|
||||
std::string ret;
|
||||
try
|
||||
{
|
||||
if(sizeof(wchar_t)==2)
|
||||
{
|
||||
ret.resize(input.size()/2);
|
||||
memcpy(&ret[0], &input[0], input.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
if(input.empty())
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string tmp;
|
||||
utf8::utf16to8((utf8::uint16_t*)&input[0], (utf8::uint16_t*)(&input[input.size()-1]+1), back_inserter(tmp));
|
||||
ret=ConvertToUnicode(tmp);
|
||||
}
|
||||
}
|
||||
utf8::utf16to8((utf8::uint16_t*)&input[0], (utf8::uint16_t*)(&input[input.size()-1]+1), back_inserter(ret));
|
||||
}
|
||||
catch(...){}
|
||||
|
||||
catch(...){}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::wstring CServer::ConvertFromUTF32(const std::string &input)
|
||||
std::string CServer::ConvertFromUTF32(const std::string &input)
|
||||
{
|
||||
std::wstring ret;
|
||||
std::string ret;
|
||||
try
|
||||
{
|
||||
if(sizeof(wchar_t)==4)
|
||||
{
|
||||
ret.resize(input.size()/4);
|
||||
memcpy(&ret[0], &input[0], input.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
if(input.empty())
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string tmp;
|
||||
utf8::utf32to8((utf8::uint32_t*)&input[0], (utf8::uint32_t*)(&input[input.size()-1]+1), back_inserter(tmp));
|
||||
ret=ConvertToUnicode(tmp);
|
||||
}
|
||||
}
|
||||
utf8::utf32to8((utf8::uint32_t*)&input[0], (utf8::uint32_t*)(&input[input.size()-1]+1), back_inserter(ret));
|
||||
}
|
||||
catch(...){}
|
||||
|
||||
catch(...){}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::wstring CServer::ConvertToWchar(const std::string &input)
|
||||
{
|
||||
if(input.empty())
|
||||
{
|
||||
return std::wstring();
|
||||
}
|
||||
|
||||
std::wstring ret;
|
||||
try
|
||||
{
|
||||
if(sizeof(wchar_t)==2)
|
||||
{
|
||||
utf8::utf8to16(&input[0], &input[input.size()-1]+1, back_inserter(ret));
|
||||
}
|
||||
else if(sizeof(wchar_t)==4)
|
||||
{
|
||||
utf8::utf8to32(&input[0], &input[input.size()-1]+1, back_inserter(ret));
|
||||
}
|
||||
|
||||
}
|
||||
catch(...){}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string CServer::ConvertFromWchar(const std::wstring &input)
|
||||
{
|
||||
if(input.empty())
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string ret;
|
||||
try
|
||||
{
|
||||
if(sizeof(wchar_t)==2)
|
||||
{
|
||||
utf8::utf16to8(&input[0], &input[input.size()-1]+1, back_inserter(ret));
|
||||
}
|
||||
else if(sizeof(wchar_t)==4)
|
||||
{
|
||||
utf8::utf32to8(&input[0], &input[input.size()-1]+1, back_inserter(ret));
|
||||
}
|
||||
|
||||
}
|
||||
catch(...){}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ICondition* CServer::createCondition(void)
|
||||
{
|
||||
return new CCondition();
|
||||
@ -1672,17 +1514,17 @@ POSTFILE_KEY CServer::getPostFileKey()
|
||||
return curr_postfilekey++;
|
||||
}
|
||||
|
||||
std::wstring CServer::getServerWorkingDir(void)
|
||||
std::string CServer::getServerWorkingDir(void)
|
||||
{
|
||||
return workingdir;
|
||||
}
|
||||
|
||||
void CServer::setServerWorkingDir(const std::wstring &wdir)
|
||||
void CServer::setServerWorkingDir(const std::string &wdir)
|
||||
{
|
||||
workingdir=wdir;
|
||||
}
|
||||
|
||||
void CServer::setTemporaryDirectory(const std::wstring &dir)
|
||||
void CServer::setTemporaryDirectory(const std::string &dir)
|
||||
{
|
||||
tmpdir=dir;
|
||||
}
|
||||
|
||||
43
Server.h
43
Server.h
@ -51,7 +51,7 @@ public:
|
||||
CServer();
|
||||
~CServer();
|
||||
void setup(void);
|
||||
void setServerParameters(const str_nmap &pServerParams);
|
||||
void setServerParameters(const str_map &pServerParams);
|
||||
|
||||
virtual std::string getServerParameter(const std::string &key);
|
||||
virtual std::string getServerParameter(const std::string &key, const std::string &def);
|
||||
@ -61,19 +61,18 @@ public:
|
||||
virtual void setLogCircularBufferSize(size_t size);
|
||||
virtual std::vector<SCircularLogEntry> getCicularLogBuffer(size_t minid);
|
||||
virtual void Log(const std::string &pStr, int LogLevel=LL_INFO);
|
||||
virtual void Log(const std::wstring &pStr, int LogLevel=LL_INFO);
|
||||
virtual bool Write(THREAD_ID tid, const std::string &str, bool cached=true);
|
||||
virtual bool WriteRaw(THREAD_ID tid, const char *buf, size_t bsize, bool cached=true);
|
||||
|
||||
virtual void setContentType(THREAD_ID tid, const std::string &str);
|
||||
virtual void addHeader(THREAD_ID tid, const std::string &str);
|
||||
|
||||
THREAD_ID Execute(const std::wstring &action, const std::wstring &context, str_map &GET, str_map &POST, str_nmap &PARAMS, IOutputStream *req);
|
||||
std::string Execute(const std::wstring &action, const std::wstring &context, str_map &GET, str_map &POST, str_nmap &PARAMS);
|
||||
THREAD_ID Execute(const std::string &action, const std::string &context, str_map &GET, str_map &POST, str_map &PARAMS, IOutputStream *req);
|
||||
std::string Execute(const std::string &action, const std::string &context, str_map &GET, str_map &POST, str_map &PARAMS);
|
||||
|
||||
virtual void AddAction(IAction *action);
|
||||
virtual bool RemoveAction(IAction *action);
|
||||
virtual void setActionContext(std::wstring context);
|
||||
virtual void setActionContext(std::string context);
|
||||
virtual void resetActionContext(void);
|
||||
|
||||
virtual int64 getTimeSeconds(void);
|
||||
@ -95,7 +94,6 @@ public:
|
||||
virtual void createThread(IThread *thread);
|
||||
virtual IThreadPool *getThreadPool(void);
|
||||
virtual ISettingsReader* createFileSettingsReader(const std::string& pFile);
|
||||
virtual ISettingsReader* createFileSettingsReader(const std::wstring& pFile);
|
||||
virtual ISettingsReader* createDBSettingsReader(THREAD_ID tid, DATABASE_ID pIdentifier, const std::string &pTable, const std::string &pSQL="");
|
||||
virtual ISettingsReader* createDBSettingsReader(IDatabase *db, const std::string &pTable, const std::string &pSQL="");
|
||||
virtual ISettingsReader* createMemorySettingsReader(const std::string &pData);
|
||||
@ -111,17 +109,15 @@ public:
|
||||
|
||||
virtual THREAD_ID getThreadID(void);
|
||||
|
||||
virtual std::string ConvertToUTF8(const std::wstring &input);
|
||||
virtual std::wstring ConvertToUnicode(const std::string &input);
|
||||
virtual std::string ConvertToUTF16(const std::wstring &input);
|
||||
virtual std::string ConvertToUTF32(const std::wstring &input);
|
||||
virtual std::wstring ConvertFromUTF16(const std::string &input);
|
||||
virtual std::wstring ConvertFromUTF32(const std::string &input);
|
||||
virtual std::string ConvertToUTF16(const std::string &input);
|
||||
virtual std::string ConvertToUTF32(const std::string &input);
|
||||
virtual std::wstring ConvertToWchar(const std::string &input);
|
||||
virtual std::string ConvertFromWchar(const std::wstring &input);
|
||||
virtual std::string ConvertFromUTF16(const std::string &input);
|
||||
virtual std::string ConvertFromUTF32(const std::string &input);
|
||||
|
||||
virtual std::string GenerateHexMD5(const std::string &input);
|
||||
virtual std::string GenerateBinaryMD5(const std::string &input);
|
||||
virtual std::string GenerateHexMD5(const std::wstring &input);
|
||||
virtual std::string GenerateBinaryMD5(const std::wstring &input);
|
||||
|
||||
virtual void StartCustomStreamService(IService *pService, std::string pServiceName, unsigned short pPort, int pMaxClientsPerThread=-1, IServer::BindTarget bindTarget=IServer::BindTarget_All);
|
||||
virtual IPipe* ConnectStream(std::string pServer, unsigned short pPort, unsigned int pTimeoutms);
|
||||
@ -139,26 +135,23 @@ public:
|
||||
virtual void addRequest(void);
|
||||
|
||||
virtual IFile* openFile(std::string pFilename, int pMode=0);
|
||||
virtual IFile* openFile(std::wstring pFilename, int pMode=0);
|
||||
virtual IFile* openFileFromHandle(void *handle);
|
||||
virtual IFile* openTemporaryFile(void);
|
||||
virtual IFile* openMemoryFile(void);
|
||||
virtual bool deleteFile(std::string pFilename);
|
||||
virtual bool deleteFile(std::wstring pFilename);
|
||||
virtual bool fileExists(std::string pFilename);
|
||||
virtual bool fileExists(std::wstring pFilename);
|
||||
|
||||
virtual POSTFILE_KEY getPostFileKey();
|
||||
virtual void addPostFile(POSTFILE_KEY pfkey, const std::string &name, const SPostfile &pf);
|
||||
virtual SPostfile getPostFile(POSTFILE_KEY pfkey, const std::string &name);
|
||||
virtual void clearPostFiles(POSTFILE_KEY pfkey);
|
||||
|
||||
virtual std::wstring getServerWorkingDir(void);
|
||||
void setServerWorkingDir(const std::wstring &wdir);
|
||||
virtual std::string getServerWorkingDir(void);
|
||||
void setServerWorkingDir(const std::string &wdir);
|
||||
|
||||
void ShutdownPlugins(void);
|
||||
|
||||
void setTemporaryDirectory(const std::wstring &dir);
|
||||
void setTemporaryDirectory(const std::string &dir);
|
||||
|
||||
virtual void registerDatabaseFactory(const std::string &pEngineName, IDatabaseFactory *factory);
|
||||
virtual bool hasDatabaseFactory(const std::string &pEngineName);
|
||||
@ -225,7 +218,7 @@ private:
|
||||
ICondition *startup_complete_cond;
|
||||
bool startup_complete;
|
||||
|
||||
std::map< std::wstring, std::map<std::wstring, IAction*> > actions;
|
||||
std::map< std::string, std::map<std::string, IAction*> > actions;
|
||||
|
||||
std::map<std::string, UNLOADACTIONS> unload_functs;
|
||||
std::vector<HMODULE> unload_handles;
|
||||
@ -259,7 +252,7 @@ private:
|
||||
std::map<POSTFILE_KEY, std::map<std::string, SPostfile > > postfiles;
|
||||
POSTFILE_KEY curr_postfilekey;
|
||||
|
||||
str_nmap server_params;
|
||||
str_map server_params;
|
||||
|
||||
PLUGIN_ID curr_pluginid;
|
||||
|
||||
@ -267,11 +260,11 @@ private:
|
||||
|
||||
CThreadPool* threadpool;
|
||||
|
||||
std::wstring action_context;
|
||||
std::string action_context;
|
||||
|
||||
std::wstring workingdir;
|
||||
std::string workingdir;
|
||||
|
||||
std::wstring tmpdir;
|
||||
std::string tmpdir;
|
||||
|
||||
std::map<std::string, IDatabaseFactory*> database_factories;
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ bool CServer::LoadDLL(const std::string &name)
|
||||
|
||||
if(dll==NULL)
|
||||
{
|
||||
Server->Log("Loading DLL \""+name+"\" failed. Error Code: "+nconvert((int)GetLastError()));
|
||||
Server->Log("Loading DLL \""+name+"\" failed. Error Code: "+convert((int)GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ int CServer::WriteDump(void* pExceptionPointers)
|
||||
WCHAR szPath[MAX_PATH];
|
||||
WCHAR szFileName[MAX_PATH];
|
||||
WCHAR* szAppName = L"UrBackup";
|
||||
WCHAR* szVersion = L"v0.25.1";
|
||||
WCHAR* szVersion = L"v2.0.0";
|
||||
DWORD dwBufferSize = MAX_PATH;
|
||||
HANDLE hDumpFile;
|
||||
SYSTEMTIME stLocalTime;
|
||||
@ -93,13 +93,13 @@ int CServer::WriteDump(void* pExceptionPointers)
|
||||
|
||||
if(!bMiniDumpSuccessful)
|
||||
{
|
||||
Server->Log("Writing minidump failed: Last error="+nconvert((int)GetLastError()), LL_ERROR);
|
||||
Server->Log("Writing minidump failed: Last error="+convert((int)GetLastError()), LL_ERROR);
|
||||
}
|
||||
|
||||
CloseHandle(hDumpFile);
|
||||
}
|
||||
|
||||
Server->Log(L"Fatal exception (APPLICATION CRASHED). Crash dump written to \""+(std::wstring)szFileName+L"\"", LL_ERROR);
|
||||
Server->Log("Fatal exception (APPLICATION CRASHED). Crash dump written to \""+Server->ConvertFromWchar(szFileName)+"\"", LL_ERROR);
|
||||
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
@ -1,21 +1,21 @@
|
||||
/*************************************************************************
|
||||
* UrBackup - Client/Server backup system
|
||||
* Copyright (C) 2011-2015 Martin Raiber
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* UrBackup - Client/Server backup system
|
||||
* Copyright (C) 2011-2015 Martin Raiber
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************/
|
||||
|
||||
#include "vld.h"
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
#include "Interface/Mutex.h"
|
||||
#include "Interface/Condition.h"
|
||||
#include "Interface/Service.h"
|
||||
#include "Interface/Service.h"
|
||||
|
||||
CServiceAcceptor::CServiceAcceptor(IService * pService, std::string pName, unsigned short port, int pMaxClientsPerThread, IServer::BindTarget bindTarget)
|
||||
: maxClientsPerThread(pMaxClientsPerThread)
|
||||
@ -37,8 +37,8 @@ CServiceAcceptor::CServiceAcceptor(IService * pService, std::string pName, unsig
|
||||
exitpipe=Server->createMemoryPipe();
|
||||
do_exit=false;
|
||||
has_error=false;
|
||||
#ifndef _WIN32
|
||||
pipe(xpipe);
|
||||
#ifndef _WIN32
|
||||
pipe(xpipe);
|
||||
#endif
|
||||
|
||||
int rc;
|
||||
@ -60,8 +60,8 @@ CServiceAcceptor::CServiceAcceptor(IService * pService, std::string pName, unsig
|
||||
rc=setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof(int));
|
||||
if(rc==SOCKET_ERROR)
|
||||
{
|
||||
Server->Log("Failed setting SO_REUSEADDR for port "+nconvert(port),LL_ERROR);
|
||||
has_error=true;
|
||||
Server->Log("Failed setting SO_REUSEADDR for port "+convert(port),LL_ERROR);
|
||||
has_error=true;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -83,14 +83,14 @@ CServiceAcceptor::CServiceAcceptor(IService * pService, std::string pName, unsig
|
||||
rc=bind(s,(sockaddr*)&addr,sizeof(addr));
|
||||
if(rc==SOCKET_ERROR)
|
||||
{
|
||||
Server->Log(name+": Failed binding socket to port "+nconvert(port)+". Another instance of this application may already be active and bound to this port.",LL_ERROR);
|
||||
Server->Log(name+": Failed binding socket to port "+convert(port)+". Another instance of this application may already be active and bound to this port.",LL_ERROR);
|
||||
has_error=true;
|
||||
return;
|
||||
}
|
||||
|
||||
listen(s, 10000);
|
||||
|
||||
Server->Log(name+": Server started up sucessfully!",LL_INFO);
|
||||
Server->Log(name+": Server started up sucessfully!",LL_INFO);
|
||||
}
|
||||
|
||||
CServiceAcceptor::~CServiceAcceptor()
|
||||
@ -99,33 +99,33 @@ CServiceAcceptor::~CServiceAcceptor()
|
||||
return;
|
||||
|
||||
do_exit=true;
|
||||
#ifndef _WIN32
|
||||
char ch=0;
|
||||
write(xpipe[1], &ch, 1);
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
char ch=0;
|
||||
write(xpipe[1], &ch, 1);
|
||||
#endif
|
||||
closesocket(s);
|
||||
for(size_t i=0;i<workers.size();++i)
|
||||
{
|
||||
workers[i]->stop();
|
||||
}
|
||||
size_t c=0;
|
||||
Server->Log("c=0/"+nconvert(workers.size()+1));
|
||||
Server->Log("c=0/"+convert(workers.size()+1));
|
||||
while(c<workers.size()+1)
|
||||
{
|
||||
std::string r;
|
||||
exitpipe->Read(&r);
|
||||
if(r=="ok")
|
||||
{
|
||||
{
|
||||
++c;
|
||||
Server->Log("c="+nconvert(c)+"/"+nconvert(workers.size()+1));
|
||||
}
|
||||
Server->Log("c="+convert(c)+"/"+convert(workers.size()+1));
|
||||
}
|
||||
}
|
||||
Server->destroy(exitpipe);
|
||||
for(size_t i=0;i<workers.size();++i)
|
||||
{
|
||||
delete workers[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
delete service;
|
||||
}
|
||||
|
||||
@ -140,10 +140,10 @@ void CServiceAcceptor::operator()(void)
|
||||
|
||||
#ifdef _WIN32
|
||||
fd_set fdset;
|
||||
FD_ZERO(&fdset);
|
||||
FD_ZERO(&fdset);
|
||||
SOCKET maxs=s;
|
||||
FD_SET(s, &fdset);
|
||||
++maxs;
|
||||
++maxs;
|
||||
|
||||
timeval lon;
|
||||
lon.tv_sec=100;
|
||||
@ -172,7 +172,7 @@ void CServiceAcceptor::operator()(void)
|
||||
SOCKET ns=accept(s, (sockaddr*)&naddr, &addrsize);
|
||||
if(ns!=SOCKET_ERROR)
|
||||
{
|
||||
//Server->Log(name+": New Connection incomming "+nconvert(Server->getTimeMS())+" s: "+nconvert((int)ns), LL_DEBUG);
|
||||
//Server->Log(name+": New Connection incomming "+convert(Server->getTimeMS())+" s: "+convert((int)ns), LL_DEBUG);
|
||||
|
||||
#ifdef _WIN32
|
||||
int window_size=512*1024;
|
||||
@ -191,7 +191,7 @@ void CServiceAcceptor::operator()(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
Server->Log("ServiceAcceptor finished", LL_DEBUG);
|
||||
Server->Log("ServiceAcceptor finished", LL_DEBUG);
|
||||
exitpipe->Write("ok");
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
#include "StreamPipe.h"
|
||||
#include "Server.h"
|
||||
#include "stringtools.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
CServiceWorker::CServiceWorker(IService *pService, std::string pName, IPipe * pExit, int pMaxClientsPerThread)
|
||||
: exit(pExit), tid(0)
|
||||
@ -94,10 +94,10 @@ void CServiceWorker::operator()(void)
|
||||
#ifdef _WIN32
|
||||
fd_set fdset;
|
||||
int max;
|
||||
#else
|
||||
#else
|
||||
std::vector<pollfd> conn;
|
||||
std::vector<ICustomClient*> conn_clients;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
while(!do_stop)
|
||||
{
|
||||
@ -114,9 +114,9 @@ void CServiceWorker::operator()(void)
|
||||
IScopedLock lock(mutex);
|
||||
if(new_clients.empty() && !do_stop)
|
||||
{
|
||||
//Server->Log(name+": Sleeping..."+nconvert(Server->getTimeMS()), LL_DEBUG);
|
||||
//Server->Log(name+": Sleeping..."+convert(Server->getTimeMS()), LL_DEBUG);
|
||||
cond->wait(&lock);
|
||||
//Server->Log(name+": Waking up..."+nconvert(Server->getTimeMS()), LL_DEBUG);
|
||||
//Server->Log(name+": Waking up..."+convert(Server->getTimeMS()), LL_DEBUG);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
@ -133,7 +133,7 @@ void CServiceWorker::operator()(void)
|
||||
if( b==false )
|
||||
{
|
||||
IScopedLock lock(mutex);
|
||||
//Server->Log(name+": Removing user"+nconvert(Server->getTimeMS()), LL_DEBUG);
|
||||
//Server->Log(name+": Removing user"+convert(Server->getTimeMS()), LL_DEBUG);
|
||||
if(clients[i].first->closeSocket())
|
||||
{
|
||||
delete clients[i].second;
|
||||
@ -153,8 +153,8 @@ void CServiceWorker::operator()(void)
|
||||
FD_ZERO(&fdset);
|
||||
max=0;
|
||||
#else
|
||||
conn.clear();
|
||||
conn_clients.clear();
|
||||
conn.clear();
|
||||
conn_clients.clear();
|
||||
#endif
|
||||
|
||||
for(size_t i=0;i<clients.size();++i)
|
||||
@ -199,7 +199,7 @@ void CServiceWorker::operator()(void)
|
||||
SOCKET s=clients[i].second->getSocket();
|
||||
if( FD_ISSET(s,&fdset) )
|
||||
{
|
||||
//Server->Log("Incoming data for client..", LL_DEBUG);
|
||||
//Server->Log("Incoming data for client..", LL_DEBUG);
|
||||
clients[i].first->ReceivePackets();
|
||||
}
|
||||
}
|
||||
@ -219,7 +219,7 @@ void CServiceWorker::operator()(void)
|
||||
Server->wait(10);
|
||||
}
|
||||
}
|
||||
Server->Log("ServiceWorker finished", LL_DEBUG);
|
||||
Server->Log("ServiceWorker finished", LL_DEBUG);
|
||||
exit->Write("ok");
|
||||
}
|
||||
|
||||
|
||||
@ -52,8 +52,8 @@ CSessionMgr::~CSessionMgr()
|
||||
Server->Log("removing sessions...");
|
||||
if(!mSessions.empty() )
|
||||
{
|
||||
std::vector<std::wstring> sesids;
|
||||
for(std::map<std::wstring, SUser*>::iterator i=mSessions.begin();i!=mSessions.end();++i)
|
||||
std::vector<std::string> sesids;
|
||||
for(std::map<std::string, SUser*>::iterator i=mSessions.begin();i!=mSessions.end();++i)
|
||||
{
|
||||
sesids.push_back(i->first);
|
||||
}
|
||||
@ -90,9 +90,9 @@ void CSessionMgr::startTimeoutSessionThread()
|
||||
Server->createThread(this);
|
||||
}
|
||||
|
||||
std::wstring CSessionMgr::GenerateSessionIDWithUser(const std::wstring &pUsername, const std::wstring &pIdentData, bool update_user)
|
||||
std::string CSessionMgr::GenerateSessionIDWithUser(const std::string &pUsername, const std::string &pIdentData, bool update_user)
|
||||
{
|
||||
std::wstring ret;
|
||||
std::string ret;
|
||||
ret.resize(SESSIONID_LEN);
|
||||
std::vector<unsigned int> rnd_n=Server->getSecureRandomNumbers(SESSIONID_LEN);
|
||||
for(int i=0;i<SESSIONID_LEN;++i)
|
||||
@ -101,8 +101,8 @@ std::wstring CSessionMgr::GenerateSessionIDWithUser(const std::wstring &pUsernam
|
||||
IScopedLock lock( sess_mutex );
|
||||
if(update_user)
|
||||
{
|
||||
std::vector<std::wstring> to_remove;
|
||||
for(std::map<std::wstring, SUser*>::iterator i=mSessions.begin();i!=mSessions.end();++i)
|
||||
std::vector<std::string> to_remove;
|
||||
for(std::map<std::string, SUser*>::iterator i=mSessions.begin();i!=mSessions.end();++i)
|
||||
{
|
||||
if( i->second->username==pUsername )
|
||||
{
|
||||
@ -129,15 +129,15 @@ std::wstring CSessionMgr::GenerateSessionIDWithUser(const std::wstring &pUsernam
|
||||
user->ident_data=pIdentData;
|
||||
user->id=-1;
|
||||
user->lastused=Server->getTimeMS();
|
||||
mSessions.insert(std::pair<std::wstring, SUser*>(ret, user) );
|
||||
mSessions.insert(std::pair<std::string, SUser*>(ret, user) );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SUser *CSessionMgr::getUser(const std::wstring &pSID, const std::wstring &pIdentData, bool update)
|
||||
SUser *CSessionMgr::getUser(const std::string &pSID, const std::string &pIdentData, bool update)
|
||||
{
|
||||
IScopedLock lock( sess_mutex );
|
||||
std::map<std::wstring, SUser*>::iterator i=mSessions.find(pSID);
|
||||
std::map<std::string, SUser*>::iterator i=mSessions.find(pSID);
|
||||
if( i!=mSessions.end() )
|
||||
{
|
||||
if( i->second->ident_data!=pIdentData )
|
||||
@ -172,10 +172,10 @@ void CSessionMgr::lockUser(SUser *user)
|
||||
}
|
||||
}
|
||||
|
||||
bool CSessionMgr::RemoveSession(const std::wstring &pSID)
|
||||
bool CSessionMgr::RemoveSession(const std::string &pSID)
|
||||
{
|
||||
IScopedLock lock( sess_mutex );
|
||||
std::map<std::wstring, SUser*>::iterator i=mSessions.find(pSID);
|
||||
std::map<std::string, SUser*>::iterator i=mSessions.find(pSID);
|
||||
if( i!=mSessions.end() )
|
||||
{
|
||||
SUser* user=i->second;
|
||||
@ -205,17 +205,17 @@ bool CSessionMgr::RemoveSession(const std::wstring &pSID)
|
||||
unsigned int CSessionMgr::TimeoutSessions(void)
|
||||
{
|
||||
if(Server!=NULL)
|
||||
Server->Log("Looking for old Sessions... "+nconvert(mSessions.size())+" sessions", LL_INFO);
|
||||
Server->Log("Looking for old Sessions... "+convert(mSessions.size())+" sessions", LL_INFO);
|
||||
unsigned int ret=0;
|
||||
IScopedLock lock( sess_mutex );
|
||||
int64 ttime=Server->getTimeMS();
|
||||
std::vector<std::wstring> to_timeout;
|
||||
for(std::map<std::wstring, SUser*>::iterator i=mSessions.begin();i!=mSessions.end();++i)
|
||||
std::vector<std::string> to_timeout;
|
||||
for(std::map<std::string, SUser*>::iterator i=mSessions.begin();i!=mSessions.end();++i)
|
||||
{
|
||||
int64 diff=ttime-i->second->lastused;
|
||||
if( diff > (unsigned int)(SESSION_TIMEOUT_S)*1000 )
|
||||
{
|
||||
Server->Log(L"Session timeout: Session "+i->first, LL_INFO);
|
||||
Server->Log("Session timeout: Session "+i->first, LL_INFO);
|
||||
to_timeout.push_back(i->first);
|
||||
}
|
||||
else
|
||||
|
||||
@ -11,13 +11,13 @@ class CSessionMgr : public ISessionMgr, public IThread
|
||||
public:
|
||||
CSessionMgr(void);
|
||||
~CSessionMgr();
|
||||
virtual std::wstring GenerateSessionIDWithUser(const std::wstring &pUsername, const std::wstring &pIdentData, bool update_user=false);
|
||||
virtual std::string GenerateSessionIDWithUser(const std::string &pUsername, const std::string &pIdentData, bool update_user=false);
|
||||
|
||||
virtual SUser *getUser(const std::wstring &pSID, const std::wstring &pIdentData, bool update=true);
|
||||
virtual SUser *getUser(const std::string &pSID, const std::string &pIdentData, bool update=true);
|
||||
virtual void releaseUser(SUser *user);
|
||||
virtual void lockUser(SUser *user);
|
||||
|
||||
virtual bool RemoveSession(const std::wstring &pSID);
|
||||
virtual bool RemoveSession(const std::string &pSID);
|
||||
|
||||
void startTimeoutSessionThread();
|
||||
void operator()(void);
|
||||
@ -29,7 +29,7 @@ private:
|
||||
int SESSION_TIMEOUT_S;
|
||||
|
||||
std::vector<wchar_t> Pool;
|
||||
std::map<std::wstring, SUser*> mSessions;
|
||||
std::map<std::string, SUser*> mSessions;
|
||||
|
||||
IMutex* sess_mutex;
|
||||
|
||||
|
||||
@ -66,56 +66,6 @@ int64 CSettingsReader::getValue(std::string key, int64 def)
|
||||
{
|
||||
std::string value;
|
||||
bool b=getValue(key,&value);
|
||||
if(b==false)
|
||||
return def;
|
||||
else
|
||||
return watoi64(widen(value));
|
||||
}
|
||||
|
||||
std::wstring CSettingsReader::getValue(std::wstring key,std::wstring def)
|
||||
{
|
||||
std::wstring value;
|
||||
bool b=getValue(key,&value);
|
||||
if(b==false)
|
||||
return def;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
std::wstring CSettingsReader::getValue(std::wstring key)
|
||||
{
|
||||
std::wstring value;
|
||||
bool b=getValue(key,&value);
|
||||
if(b==false)
|
||||
return L"";
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
int CSettingsReader::getValue(std::wstring key, int def)
|
||||
{
|
||||
std::wstring value;
|
||||
bool b=getValue(key,&value);
|
||||
if(b==false)
|
||||
return def;
|
||||
else
|
||||
return atoi(wnarrow(value).c_str());
|
||||
}
|
||||
|
||||
float CSettingsReader::getValue(std::wstring key, float def)
|
||||
{
|
||||
std::wstring value;
|
||||
bool b=getValue(key,&value);
|
||||
if(b==false)
|
||||
return def;
|
||||
else
|
||||
return (float)atof(wnarrow(value).c_str());
|
||||
}
|
||||
|
||||
int64 CSettingsReader::getValue(std::wstring key, int64 def)
|
||||
{
|
||||
std::wstring value;
|
||||
bool b=getValue(key,&value);
|
||||
if(b==false)
|
||||
return def;
|
||||
else
|
||||
|
||||
@ -7,7 +7,6 @@ class CSettingsReader : public ISettingsReader
|
||||
{
|
||||
public:
|
||||
virtual bool getValue(std::string key, std::string *value)=0;
|
||||
virtual bool getValue(std::wstring key, std::wstring *value)=0;
|
||||
|
||||
|
||||
std::string getValue(std::string key,std::string def);
|
||||
@ -15,12 +14,6 @@ public:
|
||||
int getValue(std::string key, int def);
|
||||
float getValue(std::string key, float def);
|
||||
int64 getValue(std::string key, int64 def);
|
||||
|
||||
std::wstring getValue(std::wstring key,std::wstring def);
|
||||
std::wstring getValue(std::wstring key);
|
||||
int getValue(std::wstring key, int def);
|
||||
float getValue(std::wstring key, float def);
|
||||
int64 getValue(std::wstring key, int64 def);
|
||||
};
|
||||
|
||||
#endif //CSETTINGSREADER_H
|
||||
|
||||
@ -8,7 +8,7 @@ SharedMutex::SharedMutex()
|
||||
int rc = pthread_rwlock_init(&lock, NULL);
|
||||
if(rc)
|
||||
{
|
||||
Server->Log("Error initializing rwlock rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error initializing rwlock rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,7 @@ SharedMutex::~SharedMutex()
|
||||
int rc = pthread_rwlock_destroy(&lock);
|
||||
if(rc)
|
||||
{
|
||||
Server->Log("Error destroying rwlock rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error destroying rwlock rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@ -40,7 +40,7 @@ ReadLock::ReadLock( pthread_rwlock_t* read_lock )
|
||||
int rc = pthread_rwlock_rdlock(read_lock);
|
||||
if(rc)
|
||||
{
|
||||
Server->Log("Error locking rwlock rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error locking rwlock rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@ -50,7 +50,7 @@ ReadLock::~ReadLock()
|
||||
int rc = pthread_rwlock_unlock(read_lock);
|
||||
if(rc)
|
||||
{
|
||||
Server->Log("Error unlocking rwlock rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error unlocking rwlock rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@ -61,7 +61,7 @@ WriteLock::WriteLock( pthread_rwlock_t* write_lock )
|
||||
int rc = pthread_rwlock_wrlock(write_lock);
|
||||
if(rc)
|
||||
{
|
||||
Server->Log("Error locking rwlock rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error locking rwlock rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@ -71,7 +71,7 @@ WriteLock::~WriteLock()
|
||||
int rc = pthread_rwlock_unlock(write_lock);
|
||||
if(rc)
|
||||
{
|
||||
Server->Log("Error unlocking rwlock rc="+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error unlocking rwlock rc="+convert(rc), LL_ERROR);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
36
Table.cpp
36
Table.cpp
@ -26,7 +26,7 @@ CRATable::~CRATable()
|
||||
}
|
||||
}
|
||||
|
||||
void CRATable::addObject(std::wstring key, ITable *tab)
|
||||
void CRATable::addObject(std::string key, ITable *tab)
|
||||
{
|
||||
table_map[key]=tab;
|
||||
tables.push_back(tab);
|
||||
@ -40,9 +40,9 @@ ITable* CRATable::getObject(size_t n)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ITable* CRATable::getObject(std::wstring str)
|
||||
ITable* CRATable::getObject(std::string str)
|
||||
{
|
||||
std::map<std::wstring, ITable*>::iterator iter=table_map.find(str);
|
||||
std::map<std::string, ITable*>::iterator iter=table_map.find(str);
|
||||
if( iter!= table_map.end() )
|
||||
{
|
||||
return iter->second;
|
||||
@ -51,9 +51,9 @@ ITable* CRATable::getObject(std::wstring str)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::wstring CRATable::getValue()
|
||||
std::string CRATable::getValue()
|
||||
{
|
||||
return L"";
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t CRATable::getSize()
|
||||
@ -61,7 +61,7 @@ size_t CRATable::getSize()
|
||||
return tables.size();
|
||||
}
|
||||
|
||||
void CRATable::addString(std::wstring key, std::wstring str)
|
||||
void CRATable::addString(std::string key, std::string str)
|
||||
{
|
||||
CTablestring *ts=new CTablestring(str);
|
||||
this->addObject(key, ts);
|
||||
@ -70,13 +70,13 @@ void CRATable::addString(std::wstring key, std::wstring str)
|
||||
//-------------------------
|
||||
CTable::~CTable()
|
||||
{
|
||||
for(std::map<std::wstring, ITable*>::iterator i=table_map.begin();i!=table_map.end();++i)
|
||||
for(std::map<std::string, ITable*>::iterator i=table_map.begin();i!=table_map.end();++i)
|
||||
{
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
||||
void CTable::addObject(std::wstring key, ITable *tab)
|
||||
void CTable::addObject(std::string key, ITable *tab)
|
||||
{
|
||||
table_map[key]=tab;
|
||||
}
|
||||
@ -86,9 +86,9 @@ ITable* CTable::getObject(size_t n)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ITable* CTable::getObject(std::wstring str)
|
||||
ITable* CTable::getObject(std::string str)
|
||||
{
|
||||
std::map<std::wstring, ITable*>::iterator iter=table_map.find(str);
|
||||
std::map<std::string, ITable*>::iterator iter=table_map.find(str);
|
||||
if( iter!= table_map.end() )
|
||||
{
|
||||
return iter->second;
|
||||
@ -97,9 +97,9 @@ ITable* CTable::getObject(std::wstring str)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::wstring CTable::getValue()
|
||||
std::string CTable::getValue()
|
||||
{
|
||||
return L"";
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t CTable::getSize()
|
||||
@ -107,18 +107,18 @@ size_t CTable::getSize()
|
||||
return table_map.size();
|
||||
}
|
||||
|
||||
void CTable::addString(std::wstring key, std::wstring str)
|
||||
void CTable::addString(std::string key, std::string str)
|
||||
{
|
||||
CTablestring *ts=new CTablestring(str);
|
||||
this->addObject(key, ts);
|
||||
}
|
||||
//------------------------
|
||||
CTablestring::CTablestring(std::wstring pStr)
|
||||
CTablestring::CTablestring(std::string pStr)
|
||||
{
|
||||
str=pStr;
|
||||
}
|
||||
|
||||
void CTablestring::addObject(std::wstring key, ITable *tab)
|
||||
void CTablestring::addObject(std::string key, ITable *tab)
|
||||
{
|
||||
}
|
||||
|
||||
@ -127,12 +127,12 @@ ITable* CTablestring::getObject(size_t n)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ITable* CTablestring::getObject(std::wstring key)
|
||||
ITable* CTablestring::getObject(std::string key)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::wstring CTablestring::getValue()
|
||||
std::string CTablestring::getValue()
|
||||
{
|
||||
return str;
|
||||
}
|
||||
@ -142,6 +142,6 @@ size_t CTablestring::getSize()
|
||||
return 1;
|
||||
}
|
||||
|
||||
void CTablestring::addString(std::wstring key, std::wstring str)
|
||||
void CTablestring::addString(std::string key, std::string str)
|
||||
{
|
||||
}
|
||||
|
||||
32
Table.h
32
Table.h
@ -9,15 +9,15 @@ class CRATable : public ITable
|
||||
public:
|
||||
~CRATable();
|
||||
|
||||
virtual void addObject(std::wstring key, ITable *tab);
|
||||
virtual void addObject(std::string key, ITable *tab);
|
||||
virtual ITable* getObject(size_t n);
|
||||
virtual ITable* getObject(std::wstring key);
|
||||
virtual std::wstring getValue();
|
||||
virtual ITable* getObject(std::string key);
|
||||
virtual std::string getValue();
|
||||
virtual size_t getSize();
|
||||
virtual void addString(std::wstring key, std::wstring str);
|
||||
virtual void addString(std::string key, std::string str);
|
||||
|
||||
private:
|
||||
std::map<std::wstring, ITable*> table_map;
|
||||
std::map<std::string, ITable*> table_map;
|
||||
std::vector<ITable*> tables;
|
||||
};
|
||||
|
||||
@ -26,30 +26,30 @@ class CTable : public ITable
|
||||
public:
|
||||
~CTable();
|
||||
|
||||
virtual void addObject(std::wstring key, ITable *tab);
|
||||
virtual void addObject(std::string key, ITable *tab);
|
||||
virtual ITable* getObject(size_t n);
|
||||
virtual ITable* getObject(std::wstring key);
|
||||
virtual std::wstring getValue();
|
||||
virtual ITable* getObject(std::string key);
|
||||
virtual std::string getValue();
|
||||
virtual size_t getSize();
|
||||
virtual void addString(std::wstring key, std::wstring str);
|
||||
virtual void addString(std::string key, std::string str);
|
||||
|
||||
private:
|
||||
std::map<std::wstring, ITable*> table_map;
|
||||
std::map<std::string, ITable*> table_map;
|
||||
};
|
||||
|
||||
|
||||
class CTablestring : public ITable
|
||||
{
|
||||
public:
|
||||
CTablestring(std::wstring pStr);
|
||||
CTablestring(std::string pStr);
|
||||
|
||||
virtual void addObject(std::wstring key, ITable *tab);
|
||||
virtual void addObject(std::string key, ITable *tab);
|
||||
virtual ITable* getObject(size_t n);
|
||||
virtual ITable* getObject(std::wstring key);
|
||||
virtual std::wstring getValue();
|
||||
virtual ITable* getObject(std::string key);
|
||||
virtual std::string getValue();
|
||||
virtual size_t getSize();
|
||||
virtual void addString(std::wstring key, std::wstring str);
|
||||
virtual void addString(std::string key, std::string str);
|
||||
|
||||
private:
|
||||
std::wstring str;
|
||||
std::string str;
|
||||
};
|
||||
|
||||
106
Template.cpp
106
Template.cpp
@ -28,23 +28,7 @@
|
||||
CTemplate::CTemplate(std::string pFile)
|
||||
{
|
||||
file=pFile;
|
||||
std::string tdata=getFile(pFile);
|
||||
|
||||
//if( utf8::is_bom(tdata.begin()) )
|
||||
{
|
||||
try
|
||||
{
|
||||
utf8::utf8to16(tdata.begin(), tdata.end(), back_inserter(data) );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
data=L"Invalid UTF-8";
|
||||
}
|
||||
}
|
||||
/*else
|
||||
{
|
||||
data=widen(tdata);
|
||||
}*/
|
||||
data=getFile(pFile);
|
||||
|
||||
mCurrValues=new CTable();
|
||||
mValuesRoot=mCurrValues;
|
||||
@ -82,10 +66,10 @@ void CTemplate::AddDefaultReplacements(void)
|
||||
ADD_REPLACEMENT_CODE(223, "\\xDF");*/
|
||||
}
|
||||
|
||||
ITable* CTemplate::createTableRecursive(std::wstring key)
|
||||
ITable* CTemplate::createTableRecursive(std::string key)
|
||||
{
|
||||
std::vector<std::wstring> toks;
|
||||
Tokenize(key, toks, L".");
|
||||
std::vector<std::string> toks;
|
||||
Tokenize(key, toks, ".");
|
||||
ITable *ct=mCurrValues;
|
||||
for(size_t i=0;i<toks.size();++i)
|
||||
{
|
||||
@ -101,7 +85,7 @@ ITable* CTemplate::createTableRecursive(std::wstring key)
|
||||
return ct;
|
||||
}
|
||||
|
||||
ITable* CTemplate::getTable(std::wstring key)
|
||||
ITable* CTemplate::getTable(std::string key)
|
||||
{
|
||||
ITable *ret;
|
||||
if( (ret=findTable(key))!=NULL )
|
||||
@ -110,10 +94,10 @@ ITable* CTemplate::getTable(std::wstring key)
|
||||
return createTableRecursive(key);
|
||||
}
|
||||
|
||||
void CTemplate::setValue(std::wstring key, std::wstring value)
|
||||
void CTemplate::setValue(std::string key, std::string value)
|
||||
{
|
||||
std::vector<std::wstring> toks;
|
||||
Tokenize(key, toks, L".");
|
||||
std::vector<std::string> toks;
|
||||
Tokenize(key, toks, ".");
|
||||
ITable *ct=mCurrValues;
|
||||
if( toks.size()==0 )
|
||||
return;
|
||||
@ -132,10 +116,10 @@ void CTemplate::setValue(std::wstring key, std::wstring value)
|
||||
ct->addString(toks[toks.size()-1], value);
|
||||
}
|
||||
|
||||
ITable *CTemplate::findTable(std::wstring key)
|
||||
ITable *CTemplate::findTable(std::string key)
|
||||
{
|
||||
std::vector<std::wstring> toks;
|
||||
Tokenize(key, toks, L".");
|
||||
std::vector<std::string> toks;
|
||||
Tokenize(key, toks, ".");
|
||||
ITable *ct;
|
||||
|
||||
if( toks.size()>0 )
|
||||
@ -157,7 +141,7 @@ ITable *CTemplate::findTable(std::wstring key)
|
||||
}
|
||||
|
||||
|
||||
bool CTemplate::FindValue(const std::wstring &key, std::wstring &value, bool dbs)
|
||||
bool CTemplate::FindValue(const std::string &key, std::string &value, bool dbs)
|
||||
{
|
||||
ITable *val=findTable(key);
|
||||
|
||||
@ -181,7 +165,7 @@ bool CTemplate::FindValue(const std::wstring &key, std::wstring &value, bool dbs
|
||||
if( res.size() >0 )
|
||||
{
|
||||
db_single_result result=res[0];
|
||||
db_single_result::iterator iter=result.find(L"value");
|
||||
db_single_result::iterator iter=result.find("value");
|
||||
if( iter!= result.end() )
|
||||
{
|
||||
value=iter->second;
|
||||
@ -196,7 +180,7 @@ bool CTemplate::FindValue(const std::wstring &key, std::wstring &value, bool dbs
|
||||
|
||||
std::string CTemplate::getData(void)
|
||||
{
|
||||
std::wstring output=data;
|
||||
std::string output=data;
|
||||
transform(output);
|
||||
std::string ret;
|
||||
try
|
||||
@ -214,13 +198,13 @@ std::string CTemplate::getData(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CTemplate::transform(std::wstring &output)
|
||||
void CTemplate::transform(std::string &output)
|
||||
{
|
||||
for(size_t i=0;i<output.size();++i)
|
||||
{
|
||||
if( output[i]=='\n' && i!=0 && output[i-1]!='\r' )
|
||||
{
|
||||
output.insert(i,L"\r");
|
||||
output.insert(i,"\r");
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,7 +215,7 @@ void CTemplate::transform(std::wstring &output)
|
||||
for(size_t i=0;i<output.size();++i)
|
||||
{
|
||||
// VALUES
|
||||
if( next(output, i, L"#{")==true )
|
||||
if( next(output, i, "#{")==true )
|
||||
{
|
||||
size_t j;
|
||||
for(j=i+2;j<output.size();++j)
|
||||
@ -240,8 +224,8 @@ void CTemplate::transform(std::wstring &output)
|
||||
break;
|
||||
}
|
||||
|
||||
std::wstring var=output.substr(i+2, (j)-(i+2) );
|
||||
std::wstring value;
|
||||
std::string var=output.substr(i+2, (j)-(i+2) );
|
||||
std::string value;
|
||||
|
||||
bool b=FindValue( var, value);
|
||||
if( b==true )
|
||||
@ -255,17 +239,17 @@ void CTemplate::transform(std::wstring &output)
|
||||
}
|
||||
//PREPROCESSOR
|
||||
{
|
||||
if( ((i==0||i==1) && next(output, i, L"#exit" )) || (i!=0 && next(output, i, L"\n#exit")) )
|
||||
if( ((i==0||i==1) && next(output, i, "#exit" )) || (i!=0 && next(output, i, "\n#exit")) )
|
||||
{
|
||||
output.erase(i);
|
||||
break;
|
||||
}
|
||||
bool foreach1=false,foreach2=false;
|
||||
if( ((i==0||i==1) && (foreach1=next(output, i, L"#foreach in ")==true)) || (foreach2=next(output, i, L"\r\n#foreach in "))==true)
|
||||
if( ((i==0||i==1) && (foreach1=next(output, i, "#foreach in ")==true)) || (foreach2=next(output, i, "\r\n#foreach in "))==true)
|
||||
{
|
||||
if( foreach2 )
|
||||
i+=2;
|
||||
std::wstring var;
|
||||
std::string var;
|
||||
for(size_t j=i+12;j<output.size();++j)
|
||||
{
|
||||
if( output[j]=='\n' || output[j]=='\r' )
|
||||
@ -284,11 +268,11 @@ void CTemplate::transform(std::wstring &output)
|
||||
int count=0;
|
||||
for(size_t j=i+len;j<output.size();++j)
|
||||
{
|
||||
if( next(output, j, L"\r\n#foreach") )
|
||||
if( next(output, j, "\r\n#foreach") )
|
||||
{
|
||||
++count;
|
||||
}
|
||||
if( next(output, j, L"\r\n#endfor" ) )
|
||||
if( next(output, j, "\r\n#endfor" ) )
|
||||
{
|
||||
if( count<=0 )
|
||||
{
|
||||
@ -312,14 +296,14 @@ void CTemplate::transform(std::wstring &output)
|
||||
|
||||
if( end!=std::string::npos )
|
||||
{
|
||||
std::wstring mid=output.substr(i+len, end-(i+len));
|
||||
std::wstring strend=output.substr(end+9);
|
||||
std::string mid=output.substr(i+len, end-(i+len));
|
||||
std::string strend=output.substr(end+9);
|
||||
output=output.substr(0,i);
|
||||
ITable *old_values=mCurrValues;
|
||||
|
||||
for(size_t k=0;k<tab->getSize();++k)
|
||||
{
|
||||
std::wstring tmp=mid;
|
||||
std::string tmp=mid;
|
||||
mCurrValues=tab->getObject(k);
|
||||
transform(tmp);
|
||||
output+=tmp;
|
||||
@ -334,8 +318,8 @@ void CTemplate::transform(std::wstring &output)
|
||||
}
|
||||
bool ifndef1=false,ifndef2=false;
|
||||
bool next2=false;
|
||||
if( ((i==0||i==1) && next(output, i, L"#ifdef ")==true) || (next2=next(output, i, L"\r\n#ifdef "))==true
|
||||
||((i==0||i==1) && (ifndef1=next(output, i, L"#ifndef "))==true) || ((ifndef2=next(output, i, L"\r\n#ifndef "))==true)
|
||||
if( ((i==0||i==1) && next(output, i, "#ifdef ")==true) || (next2=next(output, i, "\r\n#ifdef "))==true
|
||||
||((i==0||i==1) && (ifndef1=next(output, i, "#ifndef "))==true) || ((ifndef2=next(output, i, "\r\n#ifndef "))==true)
|
||||
)
|
||||
{
|
||||
bool ifndef=false;
|
||||
@ -345,7 +329,7 @@ void CTemplate::transform(std::wstring &output)
|
||||
if( next2==true||ifndef2==true )
|
||||
i+=2;
|
||||
|
||||
std::wstring var;
|
||||
std::string var;
|
||||
int addi=7;
|
||||
if( ifndef==true )
|
||||
++addi;
|
||||
@ -357,7 +341,7 @@ void CTemplate::transform(std::wstring &output)
|
||||
var+=output[j];
|
||||
}
|
||||
|
||||
std::wstring value;
|
||||
std::string value;
|
||||
|
||||
bool found=FindValue(var, value);
|
||||
|
||||
@ -376,21 +360,21 @@ void CTemplate::transform(std::wstring &output)
|
||||
size_t proc=0;
|
||||
for(j=i;j<output.size();++j)
|
||||
{
|
||||
if( next(output, j , L"\r\n#ifdef") || next(output, j , L"\r\n#ifndef") )
|
||||
if( next(output, j , "\r\n#ifdef") || next(output, j , "\r\n#ifndef") )
|
||||
{
|
||||
++proc;
|
||||
}
|
||||
else if( proc==0 && next(output, j, L"\r\n#elseif" ) )
|
||||
else if( proc==0 && next(output, j, "\r\n#elseif" ) )
|
||||
{
|
||||
if( todel==std::string::npos )
|
||||
todel=j;
|
||||
}
|
||||
else if( proc==0 && next(output, j, L"\r\n#else" ) )
|
||||
else if( proc==0 && next(output, j, "\r\n#else" ) )
|
||||
{
|
||||
if( todel==std::string::npos )
|
||||
todel=j;
|
||||
}
|
||||
else if( next(output, j, L"\r\n#endif" ) )
|
||||
else if( next(output, j, "\r\n#endif" ) )
|
||||
{
|
||||
if( proc!=0 )
|
||||
{
|
||||
@ -414,13 +398,13 @@ void CTemplate::transform(std::wstring &output)
|
||||
size_t proc=0;
|
||||
for(size_t j=i;j<output.size();++j)
|
||||
{
|
||||
if( next(output, j , L"\r\n#ifdef") || next(output, j , L"\r\n#ifndef") )
|
||||
if( next(output, j , "\r\n#ifdef") || next(output, j , "\r\n#ifndef") )
|
||||
{
|
||||
++proc;
|
||||
}
|
||||
else if( proc==0 && next(output, j , L"\r\n#elseif" ) )
|
||||
else if( proc==0 && next(output, j , "\r\n#elseif" ) )
|
||||
{
|
||||
std::wstring key;
|
||||
std::string key;
|
||||
for(size_t k=j+10;k<output.size();++k)
|
||||
{
|
||||
if( output[k]=='\r' || output[k]=='\n' )
|
||||
@ -429,7 +413,7 @@ void CTemplate::transform(std::wstring &output)
|
||||
}
|
||||
if( enterelseif==std::string::npos )
|
||||
{
|
||||
std::wstring value;
|
||||
std::string value;
|
||||
if( FindValue( key, value) )
|
||||
{
|
||||
enterelseif=j;
|
||||
@ -441,7 +425,7 @@ void CTemplate::transform(std::wstring &output)
|
||||
}
|
||||
output.erase(j, 10+key.size() );
|
||||
}
|
||||
else if( proc==0 &&next(output, j, L"\r\n#else") )
|
||||
else if( proc==0 &&next(output, j, "\r\n#else") )
|
||||
{
|
||||
if( enterelseif==std::string::npos )
|
||||
{
|
||||
@ -455,7 +439,7 @@ void CTemplate::transform(std::wstring &output)
|
||||
if( todel>0 )
|
||||
todel--;
|
||||
}
|
||||
else if( next(output, j, L"\r\n#endif" ) )
|
||||
else if( next(output, j, "\r\n#endif" ) )
|
||||
{
|
||||
if( proc!=0 )
|
||||
--proc;
|
||||
@ -469,7 +453,7 @@ void CTemplate::transform(std::wstring &output)
|
||||
}
|
||||
++todel;
|
||||
}
|
||||
std::wstring data;
|
||||
std::string data;
|
||||
if( enterelseif!=std::string::npos )
|
||||
data=output.substr(enterelseif, stopelseif-enterelseif);
|
||||
if( i==0 && data.size()>1 )
|
||||
@ -493,9 +477,9 @@ void CTemplate::transform(std::wstring &output)
|
||||
}
|
||||
}
|
||||
}
|
||||
if( next(output, i, L"#include \"")==true )
|
||||
if( next(output, i, "#include \"")==true )
|
||||
{
|
||||
std::wstring fn;
|
||||
std::string fn;
|
||||
bool inside=false;
|
||||
for(size_t j=i;j<output.size();++j)
|
||||
{
|
||||
@ -508,7 +492,7 @@ void CTemplate::transform(std::wstring &output)
|
||||
}
|
||||
|
||||
output.erase(i,11+fn.size() );
|
||||
std::wstring ttext=getFileUTF8(ExtractFilePath(file)+"/"+wnarrow(fn) );
|
||||
std::string ttext=getFile(ExtractFilePath(file)+"/"+fn );
|
||||
transform(ttext);
|
||||
output.insert(i, ttext );
|
||||
}
|
||||
|
||||
16
Template.h
16
Template.h
@ -14,24 +14,24 @@ public:
|
||||
|
||||
virtual void Reset(void);
|
||||
|
||||
virtual void setValue(std::wstring key, std::wstring value);
|
||||
virtual ITable* getTable(std::wstring key);
|
||||
virtual void setValue(std::string key, std::string value);
|
||||
virtual ITable* getTable(std::string key);
|
||||
virtual std::string getData(void);
|
||||
|
||||
virtual void addValueTable( IDatabase* db, const std::string &table);
|
||||
|
||||
private:
|
||||
void AddDefaultReplacements(void);
|
||||
bool FindValue(const std::wstring &key, std::wstring &value, bool dbs=false);
|
||||
ITable *findTable(std::wstring key);
|
||||
void transform(std::wstring &output);
|
||||
ITable* createTableRecursive(std::wstring key);
|
||||
bool FindValue(const std::string &key, std::string &value, bool dbs=false);
|
||||
ITable *findTable(std::string key);
|
||||
void transform(std::string &output);
|
||||
ITable* createTableRecursive(std::string key);
|
||||
|
||||
std::wstring data;
|
||||
std::string data;
|
||||
std::string file;
|
||||
|
||||
|
||||
std::vector<std::pair<std::wstring, std::wstring> > mReplacements;
|
||||
std::vector<std::pair<std::string, std::string> > mReplacements;
|
||||
ITable* mValuesRoot;
|
||||
ITable* mCurrValues;
|
||||
|
||||
|
||||
@ -187,7 +187,7 @@ void CWorkerThread::ProcessRequest(CClient *client, FCGIRequest *req)
|
||||
|
||||
str_map GET,POST;
|
||||
|
||||
str_nmap::iterator iter=req->params.find("QUERY_STRING");
|
||||
str_map::iterator iter=req->params.find("QUERY_STRING");
|
||||
if( iter!=req->params.end() )
|
||||
{
|
||||
for(size_t i=0,size=iter->second.size();i<size;++i)
|
||||
@ -220,11 +220,11 @@ void CWorkerThread::ProcessRequest(CClient *client, FCGIRequest *req)
|
||||
{
|
||||
std::string boundary=getafter("boundary=",ct);
|
||||
pfkey=ParseMultipartData(req->stdin_stream, boundary);
|
||||
req->params["POSTFILEKEY"]=nconvert(pfkey);
|
||||
req->params["POSTFILEKEY"]=convert(pfkey);
|
||||
postfile=true;
|
||||
}
|
||||
|
||||
str_map::iterator iter2=GET.find(L"a");
|
||||
str_map::iterator iter2=GET.find("a");
|
||||
|
||||
bool has_error=false;
|
||||
|
||||
@ -232,9 +232,9 @@ void CWorkerThread::ProcessRequest(CClient *client, FCGIRequest *req)
|
||||
{
|
||||
int64 starttime=Server->getTimeMS();
|
||||
|
||||
str_map::iterator iter3=GET.find(L"c");
|
||||
str_map::iterator iter3=GET.find("c");
|
||||
|
||||
std::wstring context;
|
||||
std::string context;
|
||||
if( iter3!=GET.end() )
|
||||
context=iter3->second;
|
||||
|
||||
@ -244,11 +244,11 @@ void CWorkerThread::ProcessRequest(CClient *client, FCGIRequest *req)
|
||||
|
||||
if( tid==0 )
|
||||
{
|
||||
std::wstring error=L"Error: Unknown action ["+iter2->second+L"]";
|
||||
std::string error="Error: Unknown action ["+iter2->second+"]";
|
||||
Server->Log(error, LL_WARNING);
|
||||
try
|
||||
{
|
||||
req->write("Content-type: text/html; charset=UTF-8\r\n\r\n"+wnarrow(error));
|
||||
req->write("Content-type: text/html; charset=UTF-8\r\n\r\n"+error);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
@ -264,7 +264,7 @@ void CWorkerThread::ProcessRequest(CClient *client, FCGIRequest *req)
|
||||
}
|
||||
|
||||
starttime=Server->getTimeMS()-starttime;
|
||||
//Server->Log("Execution Time: "+nconvert(starttime)+" ms - time="+nconvert(Server->getTimeMS() ), LL_INFO);
|
||||
//Server->Log("Execution Time: "+convert(starttime)+" ms - time="+convert(Server->getTimeMS() ), LL_INFO);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -370,7 +370,7 @@ POSTFILE_KEY CWorkerThread::ParseMultipartData(const std::string &data, const st
|
||||
IFile *memfile=Server->openMemoryFile();
|
||||
memfile->Write(data.substr(start,i-start-2) );
|
||||
memfile->Seek(0);
|
||||
Server->addPostFile(pfilekey, name, SPostfile(memfile, widen(filename), widen(contenttype)) );
|
||||
Server->addPostFile(pfilekey, name, SPostfile(memfile, filename, contenttype) );
|
||||
state=0;
|
||||
rboundary.erase(rboundary.size()-2,2);
|
||||
i+=rboundary.size()+2;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
const wchar_t* c_client_version=L"$version_short$";
|
||||
const char* c_client_version="$version_short$";
|
||||
}
|
||||
|
||||
#endif //_CLIENT_VERSION_H_
|
||||
@ -63,7 +63,7 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
void read_tokens(std::wstring token_path, std::string& tokens)
|
||||
void read_tokens(std::string token_path, std::string& tokens)
|
||||
{
|
||||
if(os_directory_exists(os_file_prefix(token_path)))
|
||||
{
|
||||
@ -76,7 +76,7 @@ namespace
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string nt = getFile(wnarrow(token_path + os_file_sep() + token_files[i].name));
|
||||
std::string nt = getFile(token_path + os_file_sep() + token_files[i].name);
|
||||
if(!nt.empty())
|
||||
{
|
||||
if(!tokens.empty())
|
||||
@ -208,7 +208,7 @@ bool Connector::saveSharedPaths(const std::vector<SBackupDir> &res)
|
||||
if(i!=0)
|
||||
args+="&";
|
||||
|
||||
args+="dir_"+nconvert(i)+"="+(std::string)res[i].path;
|
||||
args+="dir_"+convert(i)+"="+(std::string)res[i].path;
|
||||
}
|
||||
|
||||
std::string d=getResponse("SAVE BACKUP DIRS", args, false);
|
||||
@ -321,7 +321,7 @@ std::vector<SLogEntry> Connector::getLogEntries(void)
|
||||
|
||||
std::vector<SLogLine> Connector::getLogdata(int logid, int loglevel)
|
||||
{
|
||||
std::string d=getResponse("GET LOGDATA","logid="+nconvert(logid)+"&loglevel="+nconvert(loglevel), true);
|
||||
std::string d=getResponse("GET LOGDATA","logid="+convert(logid)+"&loglevel="+convert(loglevel), true);
|
||||
std::vector<std::string> lines;
|
||||
TokenizeMail(d, lines, "\n");
|
||||
std::vector<SLogLine> ret;
|
||||
@ -408,15 +408,15 @@ bool Connector::readTokens()
|
||||
return true;
|
||||
}
|
||||
|
||||
read_tokens(L"tokens", tokens);
|
||||
read_tokens("tokens", tokens);
|
||||
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
read_tokens(L"/var/urbackup/tokens", tokens);
|
||||
read_tokens(L"/usr/local/var/urbackup/tokens", tokens);
|
||||
read_tokens("/var/urbackup/tokens", tokens);
|
||||
read_tokens("/usr/local/var/urbackup/tokens", tokens);
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
read_tokens(L"/usr/var/urbackup/tokens", tokens);
|
||||
read_tokens("/usr/var/urbackup/tokens", tokens);
|
||||
#endif
|
||||
|
||||
return !tokens.empty();
|
||||
@ -438,7 +438,7 @@ std::string Connector::getFileList( const std::string& path, int* backupid )
|
||||
|
||||
if(backupid!=NULL)
|
||||
{
|
||||
params+="&backupid="+nconvert(*backupid);
|
||||
params+="&backupid="+convert(*backupid);
|
||||
}
|
||||
|
||||
std::string list = getResponse("GET FILE LIST TOKENS",
|
||||
|
||||
@ -122,7 +122,7 @@ bool AESGCMDecryption::put( const char *data, size_t data_size)
|
||||
decryption_filter.Put(reinterpret_cast<const byte*>(data), data_size);
|
||||
}
|
||||
|
||||
Server->Log("Data without end: "+nconvert(data_size));
|
||||
Server->Log("Data without end: "+convert(data_size));
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -146,7 +146,7 @@ bool AESGCMDecryption::put( const char *data, size_t data_size)
|
||||
}
|
||||
try
|
||||
{
|
||||
Server->Log("Message end. Size: "+nconvert(decryption_filter.MaxRetrievable()));
|
||||
Server->Log("Message end. Size: "+convert(decryption_filter.MaxRetrievable()));
|
||||
decryption_filter.MessageEnd();
|
||||
}
|
||||
catch (CryptoPP::Exception&)
|
||||
@ -259,7 +259,7 @@ size_t AESGCMDecryption::findAndUnescapeEndMarker( const char* data, size_t data
|
||||
data_copy.insert(data_copy.begin(), data, data+data_size);
|
||||
}
|
||||
data_copy.erase(data_copy.begin()+i-escaped_zeros);
|
||||
Server->Log("Unescaped something at "+nconvert(i));
|
||||
Server->Log("Unescaped something at "+convert(i));
|
||||
++escaped_zeros;
|
||||
++overhead_bytes;
|
||||
has_copy=true;
|
||||
|
||||
@ -121,7 +121,7 @@ std::string AESGCMEncryption::get()
|
||||
overhead_size+=end_marker_zeros+1;
|
||||
message_size+=end_marker_zeros+1;
|
||||
encryption_filter.GetNextMessage();
|
||||
Server->Log("New message. Size: "+nconvert(message_size));
|
||||
Server->Log("New message. Size: "+convert(message_size));
|
||||
message_size=0;
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ void AESGCMEncryption::escapeEndMarker(std::string& ret, size_t size, size_t off
|
||||
ret.insert(ret.begin()+i+1, ich);
|
||||
++i;
|
||||
end_marker_state=0;
|
||||
Server->Log("Escaped something at "+nconvert(i));
|
||||
Server->Log("Escaped something at "+convert(i));
|
||||
++overhead_size;
|
||||
}
|
||||
}
|
||||
|
||||
11
file.h
11
file.h
@ -38,9 +38,9 @@ class File : public IFile
|
||||
public:
|
||||
File();
|
||||
~File();
|
||||
bool Open(std::wstring pfn, int mode=MODE_READ);
|
||||
bool Open(std::string pfn, int mode=MODE_READ);
|
||||
bool Open(void *handle);
|
||||
bool OpenTemporaryFile(const std::wstring &tmpdir=L"", bool first_try=true);
|
||||
bool OpenTemporaryFile(const std::string &tmpdir="", bool first_try=true);
|
||||
std::string Read(_u32 tr, bool *has_error=NULL);
|
||||
_u32 Read(char* buffer, _u32 bsize, bool *has_error=NULL);
|
||||
_u32 Write(const std::string &tw, bool *has_error=NULL);
|
||||
@ -58,7 +58,6 @@ public:
|
||||
#endif
|
||||
|
||||
std::string getFilename(void);
|
||||
std::wstring getFilenameW(void);
|
||||
|
||||
private:
|
||||
#ifdef MODE_STL
|
||||
@ -71,18 +70,18 @@ private:
|
||||
#ifdef MODE_LIN
|
||||
int fd;
|
||||
#endif
|
||||
std::wstring fn;
|
||||
std::string fn;
|
||||
|
||||
#ifdef _WIN32
|
||||
static size_t tmp_file_index;
|
||||
static IMutex* index_mutex;
|
||||
static std::wstring random_prefix;
|
||||
static std::string random_prefix;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
bool DeleteFileInt(std::string pFilename);
|
||||
bool DeleteFileInt(std::wstring pFilename);
|
||||
bool DeleteFileInt(std::string pFilename);
|
||||
|
||||
#endif //FILE_H
|
||||
|
||||
|
||||
@ -26,25 +26,15 @@ File::~File()
|
||||
}
|
||||
|
||||
std::string File::getFilename(void)
|
||||
{
|
||||
return Server->ConvertToUTF8(getFilenameW());
|
||||
}
|
||||
|
||||
std::wstring File::getFilenameW(void)
|
||||
{
|
||||
return fn;
|
||||
}
|
||||
|
||||
bool DeleteFileInt(std::string pFilename)
|
||||
{
|
||||
return _unlink(pFilename.c_str())==0?true:false;
|
||||
}
|
||||
|
||||
bool DeleteFileInt(std::wstring pFilename)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
return _unlink(Server->ConvertToUTF8(pFilename).c_str())==0?true:false;
|
||||
return _unlink((pFilename).c_str())==0?true:false;
|
||||
#else
|
||||
return DeleteFileW(pFilename.c_str())!=0;
|
||||
return DeleteFileW(Server->ConvertToWchar(pFilename).c_str())!=0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ File::File()
|
||||
|
||||
}
|
||||
|
||||
bool File::Open(std::wstring pfn, int mode)
|
||||
bool File::Open(std::string pfn, int mode)
|
||||
{
|
||||
fn=pfn;
|
||||
std::ios::openmode _mode;
|
||||
@ -58,7 +58,7 @@ bool File::Open(void *handle)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool File::OpenTemporaryFile(const std::wstring &dir, bool first_try)
|
||||
bool File::OpenTemporaryFile(const std::string &dir, bool first_try)
|
||||
{
|
||||
return Open(tmpnam(NULL), MODE_TEMP);
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ File::File()
|
||||
|
||||
}
|
||||
|
||||
bool File::Open(std::wstring pfn, int mode)
|
||||
bool File::Open(std::string pfn, int mode)
|
||||
{
|
||||
fn=pfn;
|
||||
int flags=0;
|
||||
@ -94,14 +94,14 @@ bool File::Open(std::wstring pfn, int mode)
|
||||
}
|
||||
|
||||
struct stat buf;
|
||||
if(stat(Server->ConvertToUTF8(fn).c_str(), &buf)==0)
|
||||
if(stat((fn).c_str(), &buf)==0)
|
||||
{
|
||||
if(S_ISDIR(buf.st_mode) )
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
fd=open64(Server->ConvertToUTF8(fn).c_str(), flags|O_LARGEFILE, imode);
|
||||
fd=open64((fn).c_str(), flags|O_LARGEFILE, imode);
|
||||
|
||||
#ifdef __linux__
|
||||
if(mode==MODE_READ_SEQUENTIAL
|
||||
@ -125,7 +125,7 @@ bool File::Open(std::wstring pfn, int mode)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool File::OpenTemporaryFile(const std::wstring &dir, bool first_try)
|
||||
bool File::OpenTemporaryFile(const std::string &dir, bool first_try)
|
||||
{
|
||||
char *tmpdir=getenv("TMPDIR");
|
||||
std::string stmpdir;
|
||||
@ -140,7 +140,7 @@ bool File::OpenTemporaryFile(const std::wstring &dir, bool first_try)
|
||||
fd=mkstemp((char*)stmpdir.c_str());
|
||||
umask(cur_umask);
|
||||
|
||||
fn=Server->ConvertToUnicode(stmpdir);
|
||||
fn=(stmpdir);
|
||||
if( fd==-1 )
|
||||
return false;
|
||||
else
|
||||
@ -186,7 +186,7 @@ _u32 File::Write(const char* buffer, _u32 bsize, bool *has_error)
|
||||
ssize_t w=write(fd, buffer, bsize);
|
||||
if( w<0 )
|
||||
{
|
||||
Server->Log("Write failed. errno="+nconvert(errno), LL_DEBUG);
|
||||
Server->Log("Write failed. errno="+convert(errno), LL_DEBUG);
|
||||
if(has_error) *has_error=true;
|
||||
w=0;
|
||||
}
|
||||
|
||||
@ -107,11 +107,6 @@ bool CMemoryFile::PunchHole( _i64 spos, _i64 size )
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring CMemoryFile::getFilenameW( )
|
||||
{
|
||||
return L"_MEMORY_";
|
||||
}
|
||||
|
||||
bool CMemoryFile::Sync()
|
||||
{
|
||||
return false;
|
||||
|
||||
@ -19,8 +19,6 @@ public:
|
||||
|
||||
virtual std::string getFilename(void);
|
||||
|
||||
virtual std::wstring getFilenameW( void );
|
||||
|
||||
private:
|
||||
std::string data;
|
||||
size_t pos;
|
||||
|
||||
30
file_win.cpp
30
file_win.cpp
@ -26,7 +26,7 @@
|
||||
|
||||
size_t File::tmp_file_index = 0;
|
||||
IMutex* File::index_mutex = NULL;
|
||||
std::wstring File::random_prefix;
|
||||
std::string File::random_prefix;
|
||||
|
||||
File::File()
|
||||
: hfile(INVALID_HANDLE_VALUE), is_sparse(false)
|
||||
@ -34,7 +34,7 @@ File::File()
|
||||
|
||||
}
|
||||
|
||||
bool File::Open(std::wstring pfn, int mode)
|
||||
bool File::Open(std::string pfn, int mode)
|
||||
{
|
||||
fn=pfn;
|
||||
DWORD dwCreationDisposition;
|
||||
@ -99,7 +99,7 @@ bool File::Open(std::wstring pfn, int mode)
|
||||
flags|=FILE_FLAG_BACKUP_SEMANTICS;
|
||||
}
|
||||
|
||||
hfile=CreateFileW( fn.c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, flags, NULL );
|
||||
hfile=CreateFileW( Server->ConvertToWchar(fn).c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, flags, NULL );
|
||||
|
||||
if( hfile!=INVALID_HANDLE_VALUE )
|
||||
{
|
||||
@ -117,9 +117,9 @@ bool File::Open(std::wstring pfn, int mode)
|
||||
}
|
||||
}
|
||||
|
||||
bool File::OpenTemporaryFile(const std::wstring &tmpdir, bool first_try)
|
||||
bool File::OpenTemporaryFile(const std::string &tmpdir, bool first_try)
|
||||
{
|
||||
std::wostringstream filename;
|
||||
std::ostringstream filename;
|
||||
|
||||
if(tmpdir.empty())
|
||||
{
|
||||
@ -127,10 +127,10 @@ bool File::OpenTemporaryFile(const std::wstring &tmpdir, bool first_try)
|
||||
DWORD l;
|
||||
if((l=GetTempPathW(MAX_PATH, tmpp))==0 || l>MAX_PATH )
|
||||
{
|
||||
wcscpy_s(tmpp,L"C:\\");
|
||||
wcscpy_s(tmpp, L"C:\\");
|
||||
}
|
||||
|
||||
filename << tmpp;
|
||||
filename << Server->ConvertFromWchar(tmpp);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -138,25 +138,25 @@ bool File::OpenTemporaryFile(const std::wstring &tmpdir, bool first_try)
|
||||
|
||||
if(tmpdir[tmpdir.size()-1]!='\\')
|
||||
{
|
||||
filename << L"\\";
|
||||
filename << "\\";
|
||||
}
|
||||
}
|
||||
|
||||
filename << L"urb" << random_prefix << L"-" << std::hex;
|
||||
filename << "urb" << random_prefix << L"-" << std::hex;
|
||||
|
||||
{
|
||||
IScopedLock lock(index_mutex);
|
||||
filename << ++tmp_file_index;
|
||||
}
|
||||
|
||||
filename << L".tmp";
|
||||
filename << ".tmp";
|
||||
|
||||
if(!Open(filename.str(), MODE_TEMP))
|
||||
{
|
||||
if(first_try)
|
||||
{
|
||||
Server->Log(L"Creating temporary file at \"" + filename.str()+L"\" failed. Creating directory \""+tmpdir+L"\"...", LL_WARNING);
|
||||
BOOL b = CreateDirectoryW(tmpdir.c_str(), NULL);
|
||||
Server->Log("Creating temporary file at \"" + filename.str()+"\" failed. Creating directory \""+tmpdir+"\"...", LL_WARNING);
|
||||
BOOL b = CreateDirectoryW(Server->ConvertToWchar(tmpdir).c_str(), NULL);
|
||||
|
||||
if(b)
|
||||
{
|
||||
@ -164,7 +164,7 @@ bool File::OpenTemporaryFile(const std::wstring &tmpdir, bool first_try)
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->Log(L"Creating directory \""+tmpdir+L"\" failed.", LL_WARNING);
|
||||
Server->Log("Creating directory \""+tmpdir+"\" failed.", LL_WARNING);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -211,7 +211,7 @@ _u32 File::Read(char* buffer, _u32 bsize, bool *has_error)
|
||||
if(b==FALSE)
|
||||
{
|
||||
int err=GetLastError();
|
||||
Server->Log("Read error: "+nconvert(err));
|
||||
Server->Log("Read error: "+convert(err));
|
||||
if(has_error)
|
||||
{
|
||||
*has_error=true;
|
||||
@ -284,7 +284,7 @@ void File::init_mutex()
|
||||
memcpy(&rnd[0], ×ec, sizeof(timesec));
|
||||
Server->randomFill(&rnd[4], 4);
|
||||
|
||||
random_prefix = widen(bytesToHex(reinterpret_cast<unsigned char*>(&rnd[0]), rnd.size()));
|
||||
random_prefix = bytesToHex(reinterpret_cast<unsigned char*>(&rnd[0]), rnd.size());
|
||||
}
|
||||
|
||||
void File::destroy_mutex()
|
||||
|
||||
@ -85,7 +85,7 @@ CClientThread::CClientThread(SOCKET pSocket, CTCPFileServ* pParent)
|
||||
int window_size;
|
||||
int window_size_len=sizeof(window_size);
|
||||
getsockopt(pSocket, SOL_SOCKET, SO_SNDBUF,(char *) &window_size, &window_size_len );
|
||||
Log("Info: Window size="+nconvert(window_size));
|
||||
Log("Info: Window size="+convert(window_size));
|
||||
#endif
|
||||
|
||||
close_the_socket=true;
|
||||
@ -199,7 +199,7 @@ bool CClientThread::RecvMessage()
|
||||
rc=-1;
|
||||
if( rc==0 )
|
||||
{
|
||||
Log("1 min Timeout deleting Buffers ("+nconvert((NBUFFERS*READSIZE)/1024 )+" KB) and waiting 1h more...", LL_DEBUG);
|
||||
Log("1 min Timeout deleting Buffers ("+convert((NBUFFERS*READSIZE)/1024 )+" KB) and waiting 1h more...", LL_DEBUG);
|
||||
delete bufmgr;
|
||||
bufmgr=NULL;
|
||||
lon.tv_sec=3600;
|
||||
@ -304,7 +304,7 @@ bool CClientThread::ProcessPacket(CRData *data)
|
||||
is_script=true;
|
||||
}
|
||||
|
||||
std::wstring o_filename=Server->ConvertToUnicode(s_filename);
|
||||
std::string o_filename=s_filename;
|
||||
|
||||
_i64 start_offset=0;
|
||||
bool offset_set=data->getInt64(&start_offset);
|
||||
@ -313,22 +313,22 @@ bool CClientThread::ProcessPacket(CRData *data)
|
||||
{
|
||||
if(!is_script)
|
||||
{
|
||||
Log("Sending file (normal) "+Server->ConvertToUTF8(o_filename), LL_DEBUG);
|
||||
Log("Sending file (normal) "+o_filename, LL_DEBUG);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Sending script output (normal) "+Server->ConvertToUTF8(o_filename), LL_DEBUG);
|
||||
Log("Sending script output (normal) "+o_filename, LL_DEBUG);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Sending meta data of "+Server->ConvertToUTF8(o_filename), LL_DEBUG);
|
||||
Log("Sending meta data of "+o_filename, LL_DEBUG);
|
||||
}
|
||||
|
||||
|
||||
std::wstring filename=map_file(o_filename, ident);
|
||||
std::string filename=map_file(o_filename, ident);
|
||||
|
||||
Log("Mapped name: "+Server->ConvertToUTF8(filename), LL_DEBUG);
|
||||
Log("Mapped name: "+filename, LL_DEBUG);
|
||||
|
||||
if(filename.empty())
|
||||
{
|
||||
@ -358,12 +358,12 @@ bool CClientThread::ProcessPacket(CRData *data)
|
||||
{
|
||||
if(filename.size()<3 || filename[2]!='?')
|
||||
{
|
||||
filename=L"\\\\?\\UNC"+filename.substr(1);
|
||||
filename="\\\\?\\UNC"+filename.substr(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = L"\\\\?\\"+filename;
|
||||
filename = "\\\\?\\"+filename;
|
||||
}
|
||||
}
|
||||
|
||||
@ -401,33 +401,33 @@ bool CClientThread::ProcessPacket(CRData *data)
|
||||
{
|
||||
if(sendFullFile(file, start_offset, id==ID_GET_FILE_RESUME_HASH))
|
||||
{
|
||||
PipeSessions::removeFile(file->getFilenameW());
|
||||
PipeSessions::removeFile(file->getFilename());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(next(s_filename, 0, "clientdl/"))
|
||||
{
|
||||
PipeSessions::transmitFileMetadata(Server->ConvertToUTF8(filename),
|
||||
PipeSessions::transmitFileMetadata(filename,
|
||||
s_filename, ident, ident, folder_items);
|
||||
}
|
||||
else if(s_filename.find("|")!=std::string::npos)
|
||||
{
|
||||
PipeSessions::transmitFileMetadata(Server->ConvertToUTF8(filename),
|
||||
PipeSessions::transmitFileMetadata(filename,
|
||||
getafter("|",s_filename), getuntil("|", s_filename), ident, folder_items);
|
||||
}
|
||||
|
||||
#ifndef LINUX
|
||||
#ifndef BACKUP_SEM
|
||||
hFile=CreateFileW(filename.c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
hFile=CreateFileW(Server->ConvertToWchar(filename).c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
#else
|
||||
hFile=CreateFileW(filename.c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED|FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
hFile=CreateFileW(Server->ConvertToWchar(filename).c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED|FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
#endif
|
||||
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
#ifdef CHECK_BASE_PATH
|
||||
std::wstring basePath=map_file(getuntil(L"/",o_filename)+L"/", ident);
|
||||
std::string basePath=map_file(getuntil("/",o_filename)+"/", ident);
|
||||
if(!isDirectory(basePath))
|
||||
{
|
||||
char ch=ID_BASE_DIR_LOST;
|
||||
@ -496,7 +496,7 @@ bool CClientThread::ProcessPacket(CRData *data)
|
||||
break;
|
||||
}
|
||||
|
||||
assert(!(GetFileAttributesW(filename.c_str()) & FILE_ATTRIBUTE_DIRECTORY));
|
||||
assert(!(GetFileAttributesW(Server->ConvertToWchar(filename).c_str()) & FILE_ATTRIBUTE_DIRECTORY));
|
||||
|
||||
for(_i64 i=start_offset;i<filesize.QuadPart && !stopped;i+=READSIZE)
|
||||
{
|
||||
@ -529,7 +529,7 @@ bool CClientThread::ProcessPacket(CRData *data)
|
||||
|
||||
if(errorcode!=0)
|
||||
{
|
||||
Log("Error occurred while reading from file. Errorcode is "+nconvert(errorcode), LL_ERROR);
|
||||
Log("Error occurred while reading from file. Errorcode is "+convert(errorcode), LL_ERROR);
|
||||
stopped=true;
|
||||
}
|
||||
|
||||
@ -537,7 +537,7 @@ bool CClientThread::ProcessPacket(CRData *data)
|
||||
{
|
||||
if(!ReadFilePart(hFile, i, last))
|
||||
{
|
||||
Log("Reading from file failed. Last error is "+nconvert((unsigned int)GetLastError()), LL_ERROR);
|
||||
Log("Reading from file failed. Last error is "+convert((unsigned int)GetLastError()), LL_ERROR);
|
||||
stopped=true;
|
||||
}
|
||||
}
|
||||
@ -622,12 +622,12 @@ bool CClientThread::ProcessPacket(CRData *data)
|
||||
break;
|
||||
}
|
||||
|
||||
hFile=open64(Server->ConvertToUTF8(filename).c_str(), O_RDONLY|O_LARGEFILE);
|
||||
hFile=open64(filename.c_str(), O_RDONLY|O_LARGEFILE);
|
||||
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
#ifdef CHECK_BASE_PATH
|
||||
std::wstring basePath=map_file(getuntil(L"/",o_filename)+L"/", ident);
|
||||
std::string basePath=map_file(getuntil("/",o_filename)+"/", ident);
|
||||
if(!isDirectory(basePath))
|
||||
{
|
||||
char ch=ID_BASE_DIR_LOST;
|
||||
@ -731,7 +731,7 @@ bool CClientThread::ProcessPacket(CRData *data)
|
||||
#endif
|
||||
if(rc<0)
|
||||
{
|
||||
Log("Error: Reading and sending from file failed. Errno: "+nconvert(errno), LL_DEBUG);
|
||||
Log("Error: Reading and sending from file failed. Errno: "+convert(errno), LL_DEBUG);
|
||||
CloseHandle(hFile);
|
||||
delete []buf;
|
||||
return false;
|
||||
@ -763,7 +763,7 @@ bool CClientThread::ProcessPacket(CRData *data)
|
||||
}
|
||||
else if(rc<0)
|
||||
{
|
||||
Log("Error: Reading from file failed. Errno: "+nconvert(errno), LL_DEBUG);
|
||||
Log("Error: Reading from file failed. Errno: "+convert(errno), LL_DEBUG);
|
||||
CloseHandle(hFile);
|
||||
delete []buf;
|
||||
return false;
|
||||
@ -953,7 +953,7 @@ bool CClientThread::ReadFilePart(HANDLE hFile, const _i64 &offset,const bool &la
|
||||
if( ldata->buffer==NULL )
|
||||
{
|
||||
Log("Error: No Free Buffer", LL_DEBUG);
|
||||
Log("Info: Free Buffers="+nconvert(bufmgr->nfreeBufffer()), LL_DEBUG );
|
||||
Log("Info: Free Buffers="+convert(bufmgr->nfreeBufffer()), LL_DEBUG );
|
||||
delete ldata;
|
||||
return true;
|
||||
}
|
||||
@ -1032,7 +1032,7 @@ int CClientThread::SendData()
|
||||
#else
|
||||
err=errno;
|
||||
#endif
|
||||
Log("SOCKET_ERROR in SendData(). BSize: "+nconvert(ldata->bsize)+" WSAGetLastError: "+nconvert(err), LL_DEBUG);
|
||||
Log("SOCKET_ERROR in SendData(). BSize: "+convert(ldata->bsize)+" WSAGetLastError: "+convert(err), LL_DEBUG);
|
||||
|
||||
if( ldata->delbuf )
|
||||
{
|
||||
@ -1172,7 +1172,7 @@ bool CClientThread::GetFileBlockdiff(CRData *data)
|
||||
s_filename = s_filename.substr(7);
|
||||
}
|
||||
|
||||
std::wstring o_filename=Server->ConvertToUnicode(s_filename);
|
||||
std::string o_filename=s_filename;
|
||||
|
||||
_i64 start_offset=0;
|
||||
data->getInt64(&start_offset);
|
||||
@ -1183,11 +1183,11 @@ bool CClientThread::GetFileBlockdiff(CRData *data)
|
||||
_i64 requested_filesize=-1;
|
||||
data->getInt64(&requested_filesize);
|
||||
|
||||
Log("Sending file (chunked) "+Server->ConvertToUTF8(o_filename), LL_DEBUG);
|
||||
Log("Sending file (chunked) "+o_filename, LL_DEBUG);
|
||||
|
||||
std::wstring filename=map_file(o_filename, ident);
|
||||
std::string filename=map_file(o_filename, ident);
|
||||
|
||||
Log("Mapped name: "+Server->ConvertToUTF8(filename), LL_DEBUG);
|
||||
Log("Mapped name: "+filename, LL_DEBUG);
|
||||
|
||||
state=CS_BLOCKHASH;
|
||||
|
||||
@ -1207,12 +1207,12 @@ bool CClientThread::GetFileBlockdiff(CRData *data)
|
||||
{
|
||||
if(filename.size()<3 || filename[2]!='?')
|
||||
{
|
||||
filename=L"\\\\?\\UNC"+filename.substr(1);
|
||||
filename="\\\\?\\UNC"+filename.substr(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = L"\\\\?\\"+filename;
|
||||
filename = "\\\\?\\"+filename;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1233,24 +1233,24 @@ bool CClientThread::GetFileBlockdiff(CRData *data)
|
||||
{
|
||||
if(s_filename.find("|"))
|
||||
{
|
||||
PipeSessions::transmitFileMetadata(Server->ConvertToUTF8(filename),
|
||||
PipeSessions::transmitFileMetadata(filename,
|
||||
getafter("|",s_filename), getuntil("|", s_filename), ident, 0);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef BACKUP_SEM
|
||||
hFile=CreateFileW(filename.c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
hFile=CreateFileW(Server->ConvertToWchar(filename).c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
#else
|
||||
hFile=CreateFileW(filename.c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
hFile=CreateFileW(Server->ConvertToWchar(filename).c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
#endif
|
||||
#else //_WIN32
|
||||
hFile=open64(Server->ConvertToUTF8(filename).c_str(), O_RDONLY|O_LARGEFILE);
|
||||
hFile=open64(filename.c_str(), O_RDONLY|O_LARGEFILE);
|
||||
#endif //_WIN32
|
||||
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
#ifdef CHECK_BASE_PATH
|
||||
std::wstring basePath=map_file(getuntil(L"/",o_filename)+L"/", ident);
|
||||
std::string basePath=map_file(getuntil("/",o_filename)+"/", ident);
|
||||
if(!isDirectory(basePath))
|
||||
{
|
||||
queueChunk(SChunk(ID_BASE_DIR_LOST));
|
||||
@ -1408,13 +1408,13 @@ bool CClientThread::GetFileHashAndMetadata( CRData* data )
|
||||
}
|
||||
#endif
|
||||
|
||||
std::wstring o_filename=Server->ConvertToUnicode(s_filename);
|
||||
std::string o_filename=s_filename;
|
||||
|
||||
Log("Calculating hash of file "+Server->ConvertToUTF8(o_filename), LL_DEBUG);
|
||||
Log("Calculating hash of file "+o_filename, LL_DEBUG);
|
||||
|
||||
std::wstring filename=map_file(o_filename, ident);
|
||||
std::string filename=map_file(o_filename, ident);
|
||||
|
||||
Log("Mapped name: "+Server->ConvertToUTF8(filename), LL_DEBUG);
|
||||
Log("Mapped name: "+filename, LL_DEBUG);
|
||||
|
||||
if(filename.empty())
|
||||
{
|
||||
@ -1434,29 +1434,29 @@ bool CClientThread::GetFileHashAndMetadata( CRData* data )
|
||||
{
|
||||
if(filename.size()<3 || filename[2]!='?')
|
||||
{
|
||||
filename=L"\\\\?\\UNC"+filename.substr(1);
|
||||
filename="\\\\?\\UNC"+filename.substr(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = L"\\\\?\\"+filename;
|
||||
filename = "\\\\?\\"+filename;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef BACKUP_SEM
|
||||
hFile=CreateFileW(filename.c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
hFile=CreateFileW(Server->ConvertToWchar(filename).c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
#else
|
||||
hFile=CreateFileW(filename.c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
hFile=CreateFileW(Server->ConvertToWchar(filename).c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
#endif
|
||||
#else //_WIN32
|
||||
hFile=open64(Server->ConvertToUTF8(filename).c_str(), O_RDONLY|O_LARGEFILE);
|
||||
hFile=open64(filename.c_str(), O_RDONLY|O_LARGEFILE);
|
||||
#endif //_WIN32
|
||||
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
#ifdef CHECK_BASE_PATH
|
||||
std::wstring basePath=map_file(getuntil(L"/",o_filename)+L"/", ident);
|
||||
std::string basePath=map_file(getuntil("/",o_filename)+"/", ident);
|
||||
if(!isDirectory(basePath))
|
||||
{
|
||||
char ch=ID_BASE_DIR_LOST;
|
||||
@ -1578,12 +1578,12 @@ bool CClientThread::sendFullFile(IFile* file, _i64 start_offset, bool with_hashe
|
||||
|
||||
if(start_offset!=0)
|
||||
{
|
||||
Log("Sending pipe file from offset "+nconvert(start_offset), LL_DEBUG);
|
||||
Log("Sending pipe file from offset "+convert(start_offset), LL_DEBUG);
|
||||
}
|
||||
|
||||
if(!file->Seek(start_offset))
|
||||
{
|
||||
Log("Error: Seeking in file failed (5044) to "+nconvert(start_offset), LL_ERROR);
|
||||
Log("Error: Seeking in file failed (5044) to "+convert(start_offset), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -149,7 +149,7 @@ bool CTCPFileServ::Start(_u16 tcpport,_u16 udpport, std::string pServername, boo
|
||||
if(rc==SOCKET_ERROR)
|
||||
{
|
||||
#ifdef LOG_SERVER
|
||||
Server->Log("Binding tcp socket to port "+nconvert(tcpport)+" failed. Another instance of this application may already be active and bound to this port.", LL_ERROR);
|
||||
Server->Log("Binding tcp socket to port "+convert(tcpport)+" failed. Another instance of this application may already be active and bound to this port.", LL_ERROR);
|
||||
#else
|
||||
Log("Failed. Binding tcp socket.", LL_ERROR);
|
||||
#endif
|
||||
@ -256,7 +256,7 @@ void CTCPFileServ::DelClientThreads(void)
|
||||
delete clientthreads[i];
|
||||
clientthreads.erase( clientthreads.begin()+i );
|
||||
proc=true;
|
||||
Log("ClientThread deleted. "+nconvert((NBUFFERS*READSIZE)/1024)+" KB Memory freed.",LL_DEBUG);
|
||||
Log("ClientThread deleted. "+convert((NBUFFERS*READSIZE)/1024)+" KB Memory freed.",LL_DEBUG);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,12 +126,12 @@ void CUDPThread::init(_u16 udpport,std::string servername, bool use_fqdn)
|
||||
addr_udp.sin_port=htons(udpport);
|
||||
addr_udp.sin_addr.s_addr=INADDR_ANY;
|
||||
|
||||
Log("Binding udp socket at port "+nconvert(udpport)+"...", LL_DEBUG);
|
||||
Log("Binding udp socket at port "+convert(udpport)+"...", LL_DEBUG);
|
||||
rc=bind(udpsock, (sockaddr*)&addr_udp, sizeof(sockaddr_in));
|
||||
if(rc==SOCKET_ERROR)
|
||||
{
|
||||
#ifdef LOG_SERVER
|
||||
Server->Log("Binding udp socket to port "+nconvert(udpport)+" failed", LL_ERROR);
|
||||
Server->Log("Binding udp socket to port "+convert(udpport)+" failed", LL_ERROR);
|
||||
#else
|
||||
Log("Failed binding udp socket.", LL_ERROR);
|
||||
#endif
|
||||
@ -273,7 +273,7 @@ bool CUDPThread::UdpStep(void)
|
||||
#ifdef LOG_SERVER
|
||||
Server->Log("Recvfrom error in CUDPThread::UdpStep", LL_ERROR);
|
||||
#ifdef _WIN32
|
||||
Server->Log("Last error: "+ nconvert((int)GetLastError()), LL_ERROR);
|
||||
Server->Log("Last error: "+ convert((int)GetLastError()), LL_ERROR);
|
||||
#endif
|
||||
#endif
|
||||
has_error=true;
|
||||
@ -284,7 +284,7 @@ bool CUDPThread::UdpStep(void)
|
||||
if(buffer[0]==ID_PING)
|
||||
{
|
||||
unsigned int rsleep=Server->getRandomNumber()%500;
|
||||
Log("UDP: PING received... sending PONG. Delay="+nconvert(rsleep)+"ms", LL_DEBUG);
|
||||
Log("UDP: PING received... sending PONG. Delay="+convert(rsleep)+"ms", LL_DEBUG);
|
||||
Server->wait(rsleep);
|
||||
char *buffer=new char[mServername.size()+2];
|
||||
buffer[0]=ID_PONG;
|
||||
@ -293,7 +293,7 @@ bool CUDPThread::UdpStep(void)
|
||||
int rc=sendto(udpsock, buffer, (int)mServername.size()+2, 0, (sockaddr*)&sender, addrsize );
|
||||
if( rc==SOCKET_ERROR )
|
||||
{
|
||||
Log("Sending reply failed "+nconvert(rc), LL_DEBUG);
|
||||
Log("Sending reply failed "+convert(rc), LL_DEBUG);
|
||||
}
|
||||
delete[] buffer;
|
||||
}
|
||||
@ -310,7 +310,7 @@ bool CUDPThread::UdpStep(void)
|
||||
#ifdef LOG_SERVER
|
||||
Server->Log("Select error in CUDPThread::UdpStep", LL_ERROR);
|
||||
#ifdef _WIN32
|
||||
Server->Log("Last error: "+ nconvert((int)GetLastError()), LL_ERROR);
|
||||
Server->Log("Last error: "+ convert((int)GetLastError()), LL_ERROR);
|
||||
#endif
|
||||
#endif
|
||||
has_error=true;
|
||||
|
||||
@ -102,7 +102,7 @@ void ChunkSendThread::operator()(void)
|
||||
}
|
||||
if(file!=NULL && curr_file_size!=-1)
|
||||
{
|
||||
PipeSessions::removeFile(file->getFilenameW());
|
||||
PipeSessions::removeFile(file->getFilename());
|
||||
Server->destroy(file);
|
||||
file=NULL;
|
||||
}
|
||||
@ -156,7 +156,7 @@ bool ChunkSendThread::sendChunk(SChunk *chunk)
|
||||
unsigned tmp_blockleft=little_endian(blockleft);
|
||||
memcpy(chunk_buf+1+sizeof(_i64), &tmp_blockleft, sizeof(unsigned int));
|
||||
|
||||
Log("Sending whole block start="+nconvert(chunk->startpos)+" size="+nconvert(blockleft), LL_DEBUG);
|
||||
Log("Sending whole block start="+convert(chunk->startpos)+" size="+convert(blockleft), LL_DEBUG);
|
||||
_u32 r;
|
||||
|
||||
bool script_eof=false;
|
||||
@ -320,7 +320,7 @@ bool ChunkSendThread::sendChunk(SChunk *chunk)
|
||||
_u32 r_tmp = little_endian(r);
|
||||
memcpy(cptr-sizeof(_u32), &r_tmp, sizeof(_u32));
|
||||
|
||||
Log("Sending chunk start="+nconvert(curr_pos)+" size="+nconvert(r), LL_DEBUG);
|
||||
Log("Sending chunk start="+convert(curr_pos)+" size="+convert(r), LL_DEBUG);
|
||||
|
||||
if(parent->SendInt(cptr-c_chunk_padding, c_chunk_padding+r)==SOCKET_ERROR)
|
||||
{
|
||||
@ -345,7 +345,7 @@ bool ChunkSendThread::sendChunk(SChunk *chunk)
|
||||
|
||||
if(!sent_update && memcmp(md5_hash.raw_digest_int(), chunk->big_hash, big_hash_size)!=0 )
|
||||
{
|
||||
Log("Sending whole block(2) start="+nconvert(chunk->startpos)+" size="+nconvert(read_total), LL_DEBUG);
|
||||
Log("Sending whole block(2) start="+convert(chunk->startpos)+" size="+convert(read_total), LL_DEBUG);
|
||||
|
||||
*chunk_buf=ID_WHOLE_BLOCK;
|
||||
_i64 chunk_startpos = little_endian(chunk->startpos);
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
const size_t metadata_id_size = 4+4+8+4;
|
||||
|
||||
|
||||
FileMetadataPipe::FileMetadataPipe( IPipe* pipe, const std::wstring& cmd )
|
||||
FileMetadataPipe::FileMetadataPipe( IPipe* pipe, const std::string& cmd )
|
||||
: PipeFileBase(cmd), pipe(pipe),
|
||||
#ifdef _WIN32
|
||||
hFile(INVALID_HANDLE_VALUE),
|
||||
@ -111,7 +111,7 @@ bool FileMetadataPipe::readStdoutIntoBuffer( char* buf, size_t buf_avail, size_t
|
||||
{
|
||||
if(!metadata_file->Seek(metadata_file_off))
|
||||
{
|
||||
errpipe->Write(Server->ConvertToUTF8(L"Error seeking to metadata in \"" + metadata_file->getFilenameW()+L"\""));
|
||||
errpipe->Write("Error seeking to metadata in \"" + metadata_file->getFilename()+"\"");
|
||||
|
||||
read_bytes=0;
|
||||
metadata_state = MetadataState_Wait;
|
||||
@ -128,7 +128,7 @@ bool FileMetadataPipe::readStdoutIntoBuffer( char* buf, size_t buf_avail, size_t
|
||||
{
|
||||
if(metadata_buffer_size==0)
|
||||
{
|
||||
SFile file_meta = getFileMetadata(os_file_prefix(Server->ConvertToUnicode(local_fn)));
|
||||
SFile file_meta = getFileMetadata(os_file_prefix(local_fn));
|
||||
if(file_meta.name.empty())
|
||||
{
|
||||
Server->Log("Error getting metadata (created and last modified time) of "+local_fn, LL_ERROR);
|
||||
@ -142,7 +142,7 @@ bool FileMetadataPipe::readStdoutIntoBuffer( char* buf, size_t buf_avail, size_t
|
||||
meta_data.addVarInt(folder_items);
|
||||
if(token_callback.get()!=NULL)
|
||||
{
|
||||
meta_data.addString(token_callback->getFileTokens(Server->ConvertToUnicode(local_fn)));
|
||||
meta_data.addString(token_callback->getFileTokens(local_fn));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -158,7 +158,7 @@ bool FileMetadataPipe::readStdoutIntoBuffer( char* buf, size_t buf_avail, size_t
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->Log("File metadata of "+local_fn+" too large ("+nconvert((size_t)meta_data.getDataSize())+")", LL_ERROR);
|
||||
Server->Log("File metadata of "+local_fn+" too large ("+convert((size_t)meta_data.getDataSize())+")", LL_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
@ -206,7 +206,7 @@ bool FileMetadataPipe::readStdoutIntoBuffer( char* buf, size_t buf_avail, size_t
|
||||
_u32 read = metadata_file->Read(buf, static_cast<_u32>(read_bytes));
|
||||
if(read!=read_bytes)
|
||||
{
|
||||
errpipe->Write(Server->ConvertToUTF8(L"Error reading metadata stream from file \""+metadata_file->getFilenameW()+L"\"\n"));
|
||||
errpipe->Write("Error reading metadata stream from file \""+metadata_file->getFilename()+"\"\n");
|
||||
memset(buf + read, 0, read_bytes - read);
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ bool FileMetadataPipe::readStdoutIntoBuffer( char* buf, size_t buf_avail, size_t
|
||||
}
|
||||
|
||||
|
||||
int file_type_flags = os_get_file_type(os_file_prefix(Server->ConvertToUnicode(local_fn)));
|
||||
int file_type_flags = os_get_file_type(os_file_prefix(local_fn));
|
||||
|
||||
if(file_type_flags==0)
|
||||
{
|
||||
@ -373,12 +373,12 @@ bool FileMetadataPipe::transmitCurrMetadata( char* buf, size_t buf_avail, size_t
|
||||
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
hFile = CreateFileW(os_file_prefix(Server->ConvertToUnicode(local_fn)).c_str(), GENERIC_READ|ACCESS_SYSTEM_SECURITY|READ_CONTROL, FILE_SHARE_READ, NULL,
|
||||
hFile = CreateFileW(Server->ConvertToWchar(os_file_prefix(local_fn)).c_str(), GENERIC_READ|ACCESS_SYSTEM_SECURITY|READ_CONTROL, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_SEQUENTIAL_SCAN|FILE_FLAG_OPEN_REPARSE_POINT, NULL);
|
||||
|
||||
if(hFile==INVALID_HANDLE_VALUE)
|
||||
{
|
||||
errpipe->Write("Error opening file \""+local_fn+"\" to read metadata. Last error: "+nconvert((int)GetLastError())+"\n");
|
||||
errpipe->Write("Error opening file \""+local_fn+"\" to read metadata. Last error: "+convert((int)GetLastError())+"\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -388,7 +388,7 @@ bool FileMetadataPipe::transmitCurrMetadata( char* buf, size_t buf_avail, size_t
|
||||
BY_HANDLE_FILE_INFORMATION file_information;
|
||||
if(GetFileInformationByHandle(hFile, &file_information)==FALSE)
|
||||
{
|
||||
errpipe->Write("Error getting file attributes of \""+local_fn+"\". Last error: "+nconvert((int)GetLastError())+"\n");
|
||||
errpipe->Write("Error getting file attributes of \""+local_fn+"\". Last error: "+convert((int)GetLastError())+"\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -415,7 +415,7 @@ bool FileMetadataPipe::transmitCurrMetadata( char* buf, size_t buf_avail, size_t
|
||||
|
||||
if(b==FALSE)
|
||||
{
|
||||
errpipe->Write("Error getting metadata of file \""+local_fn+"\". Last error: "+nconvert((int)GetLastError())+"\n");
|
||||
errpipe->Write("Error getting metadata of file \""+local_fn+"\". Last error: "+convert((int)GetLastError())+"\n");
|
||||
*buf = 0;
|
||||
read_bytes = 1;
|
||||
return false;
|
||||
@ -454,7 +454,7 @@ bool FileMetadataPipe::transmitCurrMetadata( char* buf, size_t buf_avail, size_t
|
||||
|
||||
if(b==FALSE)
|
||||
{
|
||||
errpipe->Write("Error getting metadata of file \""+local_fn+"\" (2). Last error: "+nconvert((int)GetLastError())+"\n");
|
||||
errpipe->Write("Error getting metadata of file \""+local_fn+"\" (2). Last error: "+convert((int)GetLastError())+"\n");
|
||||
*buf=0;
|
||||
read_bytes = 1;
|
||||
return false;
|
||||
@ -481,7 +481,7 @@ bool FileMetadataPipe::transmitCurrMetadata( char* buf, size_t buf_avail, size_t
|
||||
|
||||
if(b==FALSE)
|
||||
{
|
||||
errpipe->Write("Error skipping data stream of file \""+local_fn+"\" (1). Last error: "+nconvert((int)GetLastError())+"\n");
|
||||
errpipe->Write("Error skipping data stream of file \""+local_fn+"\" (1). Last error: "+convert((int)GetLastError())+"\n");
|
||||
*buf=0;
|
||||
read_bytes = 1;
|
||||
return false;
|
||||
@ -489,7 +489,7 @@ bool FileMetadataPipe::transmitCurrMetadata( char* buf, size_t buf_avail, size_t
|
||||
|
||||
if(seeked.QuadPart!=curr_stream->Size.QuadPart)
|
||||
{
|
||||
errpipe->Write("Error skipping data stream of file \""+local_fn+"\" (2). Last error: "+nconvert((int)GetLastError())+"\n");
|
||||
errpipe->Write("Error skipping data stream of file \""+local_fn+"\" (2). Last error: "+convert((int)GetLastError())+"\n");
|
||||
*buf=0;
|
||||
read_bytes = 1;
|
||||
return false;
|
||||
@ -515,7 +515,7 @@ bool FileMetadataPipe::transmitCurrMetadata( char* buf, size_t buf_avail, size_t
|
||||
|
||||
if(b==FALSE)
|
||||
{
|
||||
errpipe->Write("Error reading metadata stream of file \""+local_fn+"\". Last error: "+nconvert((int)GetLastError())+"\n");
|
||||
errpipe->Write("Error reading metadata stream of file \""+local_fn+"\". Last error: "+convert((int)GetLastError())+"\n");
|
||||
memset(buf, 0, toread);
|
||||
}
|
||||
|
||||
@ -562,7 +562,7 @@ namespace
|
||||
|
||||
if(bufsize==-1)
|
||||
{
|
||||
Server->Log("Error getting extended attribute list of file "+fn+" errno: "+nconvert(errno), LL_ERROR);
|
||||
Server->Log("Error getting extended attribute list of file "+fn+" errno: "+convert(errno), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -579,7 +579,7 @@ namespace
|
||||
|
||||
if(bufsize==-1)
|
||||
{
|
||||
Server->Log("Error getting extended attribute list of file "+fn+" errno: "+nconvert(errno)+" (2)", LL_ERROR);
|
||||
Server->Log("Error getting extended attribute list of file "+fn+" errno: "+convert(errno)+" (2)", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -606,7 +606,7 @@ namespace
|
||||
|
||||
if(bufsize==-1)
|
||||
{
|
||||
Server->Log("Error getting extended attribute "+key+" of file "+fn+" errno: "+nconvert(errno), LL_ERROR);
|
||||
Server->Log("Error getting extended attribute "+key+" of file "+fn+" errno: "+convert(errno), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -622,7 +622,7 @@ namespace
|
||||
|
||||
if(bufsize==-1)
|
||||
{
|
||||
Server->Log("Error getting extended attribute list of file "+fn+" errno: "+nconvert(errno)+" (2)", LL_ERROR);
|
||||
Server->Log("Error getting extended attribute list of file "+fn+" errno: "+convert(errno)+" (2)", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -651,7 +651,7 @@ bool FileMetadataPipe::transmitCurrMetadata(char* buf, size_t buf_avail, size_t&
|
||||
|
||||
if(rc!=0)
|
||||
{
|
||||
Server->Log("Error with lstat of "+local_fn+" errorcode: "+nconvert(errno), LL_ERROR);
|
||||
Server->Log("Error with lstat of "+local_fn+" errorcode: "+convert(errno), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -659,7 +659,7 @@ bool FileMetadataPipe::transmitCurrMetadata(char* buf, size_t buf_avail, size_t&
|
||||
|
||||
if(data.getDataSize()+sizeof(_u32)>metadata_buffer.size())
|
||||
{
|
||||
Server->Log("File metadata of "+local_fn+" too large ("+nconvert((size_t)data.getDataSize()+sizeof(_u32))+")", LL_ERROR);
|
||||
Server->Log("File metadata of "+local_fn+" too large ("+convert((size_t)data.getDataSize()+sizeof(_u32))+")", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ const _u32 ID_METADATA_V1 = ID_METADATA_OS | 1<<3;
|
||||
class FileMetadataPipe : public PipeFileBase
|
||||
{
|
||||
public:
|
||||
FileMetadataPipe(IPipe* pipe, const std::wstring& cmd);
|
||||
FileMetadataPipe(IPipe* pipe, const std::string& cmd);
|
||||
|
||||
virtual bool getExitCode( int& exit_code );
|
||||
|
||||
|
||||
@ -29,17 +29,17 @@
|
||||
IMutex *FileServ::mutex=NULL;
|
||||
std::vector<std::string> FileServ::identities;
|
||||
bool FileServ::pause=false;
|
||||
std::map<std::wstring, std::wstring> FileServ::script_output_names;
|
||||
std::map<std::string, std::string> FileServ::script_output_names;
|
||||
IFileServ::ITokenCallbackFactory* FileServ::token_callback_factory = NULL;
|
||||
|
||||
|
||||
FileServ::FileServ(bool *pDostop, const std::wstring &pServername, THREADPOOL_TICKET serverticket, bool use_fqdn)
|
||||
FileServ::FileServ(bool *pDostop, const std::string &pServername, THREADPOOL_TICKET serverticket, bool use_fqdn)
|
||||
: servername(pServername), serverticket(serverticket)
|
||||
{
|
||||
dostop=pDostop;
|
||||
if(servername.empty())
|
||||
{
|
||||
servername=Server->ConvertToUnicode(getSystemServerName(use_fqdn));
|
||||
servername=getSystemServerName(use_fqdn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,12 +48,12 @@ FileServ::~FileServ(void)
|
||||
delete dostop;
|
||||
}
|
||||
|
||||
void FileServ::shareDir(const std::wstring &name, const std::wstring &path, const std::string& identity)
|
||||
void FileServ::shareDir(const std::string &name, const std::string &path, const std::string& identity)
|
||||
{
|
||||
add_share_path(name, path, identity);
|
||||
}
|
||||
|
||||
void FileServ::removeDir(const std::wstring &name, const std::string& identity)
|
||||
void FileServ::removeDir(const std::string &name, const std::string& identity)
|
||||
{
|
||||
remove_share_path(name, identity);
|
||||
}
|
||||
@ -64,7 +64,7 @@ void FileServ::stopServer(void)
|
||||
Server->getThreadPool()->waitFor(serverticket);
|
||||
}
|
||||
|
||||
std::wstring FileServ::getShareDir(const std::wstring &name, const std::string& identity)
|
||||
std::string FileServ::getShareDir(const std::string &name, const std::string& identity)
|
||||
{
|
||||
return map_file(name, identity);
|
||||
}
|
||||
@ -117,7 +117,7 @@ bool FileServ::isPause(void)
|
||||
return pause;
|
||||
}
|
||||
|
||||
std::wstring FileServ::getServerName(void)
|
||||
std::string FileServ::getServerName(void)
|
||||
{
|
||||
return servername;
|
||||
}
|
||||
@ -143,7 +143,7 @@ bool FileServ::removeIdentity( const std::string &pIdentity )
|
||||
}
|
||||
}
|
||||
|
||||
bool FileServ::getExitInformation(const std::wstring& cmd, std::string& stderr_data, int& exit_code)
|
||||
bool FileServ::getExitInformation(const std::string& cmd, std::string& stderr_data, int& exit_code)
|
||||
{
|
||||
SExitInformation exit_info = PipeSessions::getExitInformation(map_file(cmd, std::string()));
|
||||
|
||||
@ -160,18 +160,18 @@ bool FileServ::getExitInformation(const std::wstring& cmd, std::string& stderr_d
|
||||
}
|
||||
}
|
||||
|
||||
void FileServ::addScriptOutputFilenameMapping(const std::wstring& script_output_fn, const std::wstring& script_fn)
|
||||
void FileServ::addScriptOutputFilenameMapping(const std::string& script_output_fn, const std::string& script_fn)
|
||||
{
|
||||
IScopedLock lock(mutex);
|
||||
|
||||
script_output_names[script_output_fn] = script_fn;
|
||||
}
|
||||
|
||||
std::wstring FileServ::mapScriptOutputNameToScript(const std::wstring& script_fn)
|
||||
std::string FileServ::mapScriptOutputNameToScript(const std::string& script_fn)
|
||||
{
|
||||
IScopedLock lock(mutex);
|
||||
|
||||
std::map<std::wstring, std::wstring>::iterator it = script_output_names.find(script_fn);
|
||||
std::map<std::string, std::string>::iterator it = script_output_names.find(script_fn);
|
||||
if(it!=script_output_names.end())
|
||||
{
|
||||
return it->second;
|
||||
@ -182,12 +182,12 @@ std::wstring FileServ::mapScriptOutputNameToScript(const std::wstring& script_fn
|
||||
}
|
||||
}
|
||||
|
||||
void FileServ::registerMetadataCallback( const std::wstring &name, const std::string& identity, IMetadataCallback* callback)
|
||||
void FileServ::registerMetadataCallback( const std::string &name, const std::string& identity, IMetadataCallback* callback)
|
||||
{
|
||||
PipeSessions::registerMetadataCallback(name, identity, callback);
|
||||
}
|
||||
|
||||
void FileServ::removeMetadataCallback( const std::wstring &name, const std::string& identity )
|
||||
void FileServ::removeMetadataCallback( const std::string &name, const std::string& identity )
|
||||
{
|
||||
PipeSessions::removeMetadataCallback(name, identity);
|
||||
}
|
||||
|
||||
@ -6,23 +6,23 @@
|
||||
class FileServ : public IFileServ
|
||||
{
|
||||
public:
|
||||
FileServ(bool *pDostop, const std::wstring &servername, THREADPOOL_TICKET serverticket, bool use_fqdn);
|
||||
FileServ(bool *pDostop, const std::string &servername, THREADPOOL_TICKET serverticket, bool use_fqdn);
|
||||
~FileServ(void);
|
||||
void shareDir(const std::wstring &name, const std::wstring &path, const std::string& identity);
|
||||
void removeDir(const std::wstring &name, const std::string& identity);
|
||||
void shareDir(const std::string &name, const std::string &path, const std::string& identity);
|
||||
void removeDir(const std::string &name, const std::string& identity);
|
||||
void stopServer(void);
|
||||
std::wstring getServerName(void);
|
||||
std::wstring getShareDir(const std::wstring &name, const std::string& identity);
|
||||
std::string getServerName(void);
|
||||
std::string getShareDir(const std::string &name, const std::string& identity);
|
||||
void addIdentity(const std::string &pIdentity);
|
||||
bool removeIdentity(const std::string &pIdentity);
|
||||
void setPause(bool b);
|
||||
bool getPause(void);
|
||||
bool getExitInformation(const std::wstring& cmd, std::string& stderr_data, int& exit_code);
|
||||
void addScriptOutputFilenameMapping(const std::wstring& script_output_fn, const std::wstring& script_fn);
|
||||
bool getExitInformation(const std::string& cmd, std::string& stderr_data, int& exit_code);
|
||||
void addScriptOutputFilenameMapping(const std::string& script_output_fn, const std::string& script_fn);
|
||||
|
||||
virtual void registerMetadataCallback(const std::wstring &name, const std::string& identity, IMetadataCallback* callback);
|
||||
virtual void registerMetadataCallback(const std::string &name, const std::string& identity, IMetadataCallback* callback);
|
||||
|
||||
virtual void removeMetadataCallback(const std::wstring &name, const std::string& identity);
|
||||
virtual void removeMetadataCallback(const std::string &name, const std::string& identity);
|
||||
|
||||
virtual void runClient(IPipe *cp);
|
||||
|
||||
@ -33,7 +33,7 @@ public:
|
||||
|
||||
static bool checkIdentity(const std::string &pIdentity);
|
||||
|
||||
static std::wstring mapScriptOutputNameToScript(const std::wstring& script_fn);
|
||||
static std::string mapScriptOutputNameToScript(const std::string& script_fn);
|
||||
|
||||
virtual void registerTokenCallbackFactory( IFileServ::ITokenCallbackFactory* callback_factory );
|
||||
|
||||
@ -42,11 +42,11 @@ public:
|
||||
private:
|
||||
bool *dostop;
|
||||
THREADPOOL_TICKET serverticket;
|
||||
std::wstring servername;
|
||||
std::string servername;
|
||||
|
||||
static std::vector<std::string> identities;
|
||||
static bool pause;
|
||||
static std::map<std::wstring, std::wstring> script_output_names;
|
||||
static std::map<std::string, std::string> script_output_names;
|
||||
|
||||
static IMutex *mutex;
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ bool FileServFactory::backupground_backups_enabled = true;
|
||||
class ExecThread : public IThread
|
||||
{
|
||||
public:
|
||||
ExecThread(unsigned short pTcpport, unsigned short pUdpport, const std::wstring &pName, bool *pDostop, bool pUse_fqdn)
|
||||
ExecThread(unsigned short pTcpport, unsigned short pUdpport, const std::string &pName, bool *pDostop, bool pUse_fqdn)
|
||||
{
|
||||
tcpport=pTcpport;
|
||||
udpport=pUdpport;
|
||||
@ -42,17 +42,17 @@ public:
|
||||
|
||||
void operator()(void)
|
||||
{
|
||||
int r=start_server_int(tcpport, udpport, Server->ConvertToUTF8(name), dostop, use_fqdn);
|
||||
int r=start_server_int(tcpport, udpport, name, dostop, use_fqdn);
|
||||
if(r!=2)
|
||||
{
|
||||
Server->Log("FileServ exit with error code: "+nconvert(r), LL_ERROR);
|
||||
Server->Log("FileServ exit with error code: "+convert(r), LL_ERROR);
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned short tcpport,udpport;
|
||||
std::wstring name;
|
||||
std::string name;
|
||||
bool *dostop;
|
||||
bool use_fqdn;
|
||||
};
|
||||
@ -60,7 +60,7 @@ private:
|
||||
|
||||
IPermissionCallback* FileServFactory::permission_callback = NULL;
|
||||
|
||||
IFileServ * FileServFactory::createFileServ(unsigned short tcpport, unsigned short udpport, const std::wstring &name, bool use_fqdn_default, bool enable_background_priority)
|
||||
IFileServ * FileServFactory::createFileServ(unsigned short tcpport, unsigned short udpport, const std::string &name, bool use_fqdn_default, bool enable_background_priority)
|
||||
{
|
||||
bool *dostop=new bool;
|
||||
*dostop=false;
|
||||
@ -91,7 +91,7 @@ IPermissionCallback* FileServFactory::getPermissionCallback()
|
||||
return permission_callback;
|
||||
}
|
||||
|
||||
IFileServ* FileServFactory::createFileServNoBind(const std::wstring &name, bool use_fqdn_default)
|
||||
IFileServ* FileServFactory::createFileServNoBind(const std::string &name, bool use_fqdn_default)
|
||||
{
|
||||
bool *dostop=new bool;
|
||||
*dostop=false;
|
||||
@ -99,7 +99,7 @@ IFileServ* FileServFactory::createFileServNoBind(const std::wstring &name, bool
|
||||
return fs;
|
||||
}
|
||||
|
||||
std::wstring FileServFactory::getDefaultServerName( bool use_fqdn )
|
||||
std::string FileServFactory::getDefaultServerName( bool use_fqdn )
|
||||
{
|
||||
return Server->ConvertToUnicode(getSystemServerName(use_fqdn));
|
||||
return getSystemServerName(use_fqdn);
|
||||
}
|
||||
|
||||
@ -4,16 +4,16 @@ class FileServFactory : public IFileServFactory
|
||||
{
|
||||
public:
|
||||
static bool backgroundBackupsEnabled();
|
||||
IFileServ * createFileServ(unsigned short tcpport, unsigned short udpport, const std::wstring &name=L"", bool use_fqdn_default=false, bool enable_background_priority=true);
|
||||
IFileServ * createFileServ(unsigned short tcpport, unsigned short udpport, const std::string &name="", bool use_fqdn_default=false, bool enable_background_priority=true);
|
||||
void destroyFileServ(IFileServ *filesrv);
|
||||
|
||||
IFileServ* createFileServNoBind(const std::wstring &name=L"", bool use_fqdn_default=false);
|
||||
IFileServ* createFileServNoBind(const std::string &name="", bool use_fqdn_default=false);
|
||||
|
||||
void setPermissionCallback(IPermissionCallback* new_permission_callback);
|
||||
|
||||
static IPermissionCallback* getPermissionCallback();
|
||||
|
||||
std::wstring getDefaultServerName(bool use_fqdn);
|
||||
std::string getDefaultServerName(bool use_fqdn);
|
||||
|
||||
private:
|
||||
static IPermissionCallback* permission_callback;
|
||||
|
||||
@ -23,7 +23,7 @@ public:
|
||||
class ITokenCallback
|
||||
{
|
||||
public:
|
||||
virtual std::string getFileTokens(const std::wstring& fn) = 0;
|
||||
virtual std::string getFileTokens(const std::string& fn) = 0;
|
||||
};
|
||||
|
||||
class ITokenCallbackFactory
|
||||
@ -33,20 +33,20 @@ public:
|
||||
};
|
||||
|
||||
|
||||
virtual void shareDir(const std::wstring &name, const std::wstring &path, const std::string& identity)=0;
|
||||
virtual void removeDir(const std::wstring &name, const std::string& identity)=0;
|
||||
virtual std::wstring getServerName(void)=0;
|
||||
virtual void shareDir(const std::string &name, const std::string &path, const std::string& identity)=0;
|
||||
virtual void removeDir(const std::string &name, const std::string& identity)=0;
|
||||
virtual std::string getServerName(void)=0;
|
||||
virtual void stopServer(void)=0;
|
||||
virtual std::wstring getShareDir(const std::wstring &name, const std::string& identity)=0;
|
||||
virtual std::string getShareDir(const std::string &name, const std::string& identity)=0;
|
||||
virtual void addIdentity(const std::string &pIdentity)=0;
|
||||
virtual bool removeIdentity(const std::string &pIdentity)=0;
|
||||
virtual void setPause(bool b)=0;
|
||||
virtual bool getPause(void)=0;
|
||||
virtual void runClient(IPipe *cp)=0;
|
||||
virtual bool getExitInformation(const std::wstring& cmd, std::string& stderr_data, int& exit_code) = 0;
|
||||
virtual void addScriptOutputFilenameMapping(const std::wstring& script_output_fn, const std::wstring& script_fn) = 0;
|
||||
virtual void registerMetadataCallback(const std::wstring &name, const std::string& identity, IMetadataCallback* callback) = 0;
|
||||
virtual void removeMetadataCallback(const std::wstring &name, const std::string& identity) = 0;
|
||||
virtual bool getExitInformation(const std::string& cmd, std::string& stderr_data, int& exit_code) = 0;
|
||||
virtual void addScriptOutputFilenameMapping(const std::string& script_output_fn, const std::string& script_fn) = 0;
|
||||
virtual void registerMetadataCallback(const std::string &name, const std::string& identity, IMetadataCallback* callback) = 0;
|
||||
virtual void removeMetadataCallback(const std::string &name, const std::string& identity) = 0;
|
||||
virtual void registerTokenCallbackFactory(ITokenCallbackFactory* callback_factory) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -12,11 +12,11 @@
|
||||
class IFileServFactory : public IPlugin
|
||||
{
|
||||
public:
|
||||
virtual IFileServ * createFileServ(unsigned short tcpport, unsigned short udpport, const std::wstring &name=L"", bool use_fqdn_default=false, bool enable_background_priority=true)=0;
|
||||
virtual IFileServ * createFileServNoBind(const std::wstring &name=L"", bool use_fqdn_default=false)=0;
|
||||
virtual IFileServ * createFileServ(unsigned short tcpport, unsigned short udpport, const std::string &name="", bool use_fqdn_default=false, bool enable_background_priority=true)=0;
|
||||
virtual IFileServ * createFileServNoBind(const std::string &name="", bool use_fqdn_default=false)=0;
|
||||
virtual void destroyFileServ(IFileServ *filesrv)=0;
|
||||
virtual void setPermissionCallback(IPermissionCallback* new_permission_callback)=0;
|
||||
virtual std::wstring getDefaultServerName(bool use_fqdn)=0;
|
||||
virtual std::string getDefaultServerName(bool use_fqdn)=0;
|
||||
};
|
||||
|
||||
#endif //IFILESERVFACTORY_H
|
||||
@ -6,5 +6,5 @@
|
||||
class IPermissionCallback
|
||||
{
|
||||
public:
|
||||
virtual std::string getPermissions(const std::wstring& path) = 0;
|
||||
virtual std::string getPermissions(const std::string& path) = 0;
|
||||
};
|
||||
@ -16,7 +16,7 @@
|
||||
class PipeFile : public PipeFileBase
|
||||
{
|
||||
public:
|
||||
PipeFile(const std::wstring& pCmd);
|
||||
PipeFile(const std::string& pCmd);
|
||||
~PipeFile();
|
||||
|
||||
virtual bool getExitCode(int& exit_code);
|
||||
|
||||
@ -27,7 +27,7 @@ const size_t buffer_size = 5*1024*1024;
|
||||
const _u32 buffer_keep_free = 1*1024*1024;
|
||||
|
||||
|
||||
PipeFileBase::PipeFileBase(const std::wstring& pCmd)
|
||||
PipeFileBase::PipeFileBase(const std::string& pCmd)
|
||||
: curr_pos(0), has_error(false), cmd(pCmd), buf_w_pos(0), buf_r_pos(0), buf_w_reserved_pos(0),
|
||||
threadidx(0), has_eof(false), stream_size(-1),
|
||||
buf_circle(false), stdout_thread(ILLEGAL_THREADPOOL_TICKET), stderr_thread(ILLEGAL_THREADPOOL_TICKET)
|
||||
@ -200,11 +200,6 @@ _i64 PipeFileBase::RealSize()
|
||||
}
|
||||
|
||||
std::string PipeFileBase::getFilename(void)
|
||||
{
|
||||
return Server->ConvertToUTF8(cmd);
|
||||
}
|
||||
|
||||
std::wstring PipeFileBase::getFilenameW(void)
|
||||
{
|
||||
return cmd;
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
class PipeFileBase : public IFile, public IThread
|
||||
{
|
||||
public:
|
||||
PipeFileBase(const std::wstring& pCmd);
|
||||
PipeFileBase(const std::string& pCmd);
|
||||
|
||||
virtual void operator()();
|
||||
|
||||
@ -28,8 +28,6 @@ public:
|
||||
|
||||
virtual std::string getFilename(void);
|
||||
|
||||
virtual std::wstring getFilenameW(void);
|
||||
|
||||
int64 getLastRead();
|
||||
|
||||
bool getHasError();
|
||||
@ -63,7 +61,7 @@ private:
|
||||
void readBuf(char* buf, size_t toread);
|
||||
|
||||
|
||||
std::wstring cmd;
|
||||
std::string cmd;
|
||||
|
||||
int64 curr_pos;
|
||||
size_t buf_w_pos;
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
#include <sys/wait.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
PipeFile::PipeFile(const std::wstring& pCmd)
|
||||
PipeFile::PipeFile(const std::string& pCmd)
|
||||
: PipeFileBase(pCmd),
|
||||
hStderr(0),
|
||||
hStdout(0)
|
||||
@ -35,7 +35,7 @@ PipeFile::PipeFile(const std::wstring& pCmd)
|
||||
|
||||
if(pipe(stdout_pipe) == -1)
|
||||
{
|
||||
Server->Log("Error creating stdout pipe: " + nconvert(errno), LL_ERROR);
|
||||
Server->Log("Error creating stdout pipe: " + convert(errno), LL_ERROR);
|
||||
has_error=true;
|
||||
return;
|
||||
}
|
||||
@ -43,7 +43,7 @@ PipeFile::PipeFile(const std::wstring& pCmd)
|
||||
int stderr_pipe[2];
|
||||
if(pipe(stderr_pipe) == -1)
|
||||
{
|
||||
Server->Log("Error creating stderr pipe: " + nconvert(errno), LL_ERROR);
|
||||
Server->Log("Error creating stderr pipe: " + convert(errno), LL_ERROR);
|
||||
has_error=true;
|
||||
return;
|
||||
}
|
||||
@ -52,7 +52,7 @@ PipeFile::PipeFile(const std::wstring& pCmd)
|
||||
|
||||
if(child_pid==-1)
|
||||
{
|
||||
Server->Log("Error forking to execute command: " + nconvert(errno), LL_ERROR);
|
||||
Server->Log("Error forking to execute command: " + convert(errno), LL_ERROR);
|
||||
has_error=true;
|
||||
return;
|
||||
}
|
||||
@ -66,7 +66,7 @@ PipeFile::PipeFile(const std::wstring& pCmd)
|
||||
close(stderr_pipe[0]);
|
||||
close(stderr_pipe[1]);
|
||||
|
||||
int rc = system(Server->ConvertToUTF8(pCmd).c_str());
|
||||
int rc = system((pCmd).c_str());
|
||||
|
||||
_exit(rc);
|
||||
}
|
||||
@ -138,7 +138,7 @@ bool PipeFile::getExitCode(int& exit_code)
|
||||
|
||||
if(rc==-1)
|
||||
{
|
||||
Server->Log("Error while waiting for exit code: " + nconvert(errno), LL_ERROR);
|
||||
Server->Log("Error while waiting for exit code: " + convert(errno), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@ -150,7 +150,7 @@ bool PipeFile::getExitCode(int& exit_code)
|
||||
}
|
||||
else if(WIFSIGNALED(status))
|
||||
{
|
||||
Server->Log("Script was terminated by signal " + nconvert(WTERMSIG(status)), LL_ERROR);
|
||||
Server->Log("Script was terminated by signal " + convert(WTERMSIG(status)), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
else if(WCOREDUMP(status))
|
||||
@ -160,7 +160,7 @@ bool PipeFile::getExitCode(int& exit_code)
|
||||
}
|
||||
else if(WIFSTOPPED(status))
|
||||
{
|
||||
Server->Log("Script was stopped by signal " + nconvert(WSTOPSIG(status)), LL_ERROR);
|
||||
Server->Log("Script was stopped by signal " + convert(WSTOPSIG(status)), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
#include "PipeFile.h"
|
||||
|
||||
PipeFile::PipeFile(const std::wstring& pCmd)
|
||||
PipeFile::PipeFile(const std::string& pCmd)
|
||||
: PipeFileBase(pCmd),
|
||||
hStderr(INVALID_HANDLE_VALUE),
|
||||
hStdout(INVALID_HANDLE_VALUE)
|
||||
@ -67,13 +67,13 @@ PipeFile::PipeFile(const std::wstring& pCmd)
|
||||
start_info.hStdOutput = hStdoutW;
|
||||
start_info.dwFlags |= STARTF_USESTDHANDLES;
|
||||
|
||||
BOOL b = CreateProcessW(NULL, const_cast<LPWSTR>(getFilenameW().c_str()),
|
||||
BOOL b = CreateProcessW(NULL, const_cast<LPWSTR>(Server->ConvertToWchar(getFilename()).c_str()),
|
||||
&saAttr, NULL, TRUE, 0, NULL, NULL, &start_info,
|
||||
&proc_info);
|
||||
|
||||
if(!b)
|
||||
{
|
||||
Server->Log(L"Error starting script \"" + getFilenameW() + L"\"", LL_ERROR);
|
||||
Server->Log("Error starting script \"" + getFilename() + "\"", LL_ERROR);
|
||||
has_error=true;
|
||||
}
|
||||
|
||||
|
||||
@ -28,30 +28,30 @@
|
||||
|
||||
volatile bool PipeSessions::do_stop = false;
|
||||
IMutex* PipeSessions::mutex = NULL;
|
||||
std::map<std::wstring, SPipeSession> PipeSessions::pipe_files;
|
||||
std::map<std::wstring, SExitInformation> PipeSessions::exit_information;
|
||||
std::map<std::string, SPipeSession> PipeSessions::pipe_files;
|
||||
std::map<std::string, SExitInformation> PipeSessions::exit_information;
|
||||
std::map<std::pair<std::string, std::string>, IFileServ::IMetadataCallback*> PipeSessions::metadata_callbacks;
|
||||
|
||||
|
||||
const int64 pipe_file_timeout = 1*60*60*1000;
|
||||
|
||||
|
||||
IFile* PipeSessions::getFile(const std::wstring& cmd)
|
||||
IFile* PipeSessions::getFile(const std::string& cmd)
|
||||
{
|
||||
IScopedLock lock(mutex);
|
||||
|
||||
std::map<std::wstring, SPipeSession>::iterator it = pipe_files.find(cmd);
|
||||
std::map<std::string, SPipeSession>::iterator it = pipe_files.find(cmd);
|
||||
if(it != pipe_files.end())
|
||||
{
|
||||
return it->second.file;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring script_cmd = getuntil(L"|", cmd);
|
||||
std::string script_cmd = getuntil("|", cmd);
|
||||
|
||||
if(script_cmd==L"urbackup/FILE_METADATA")
|
||||
if(script_cmd=="urbackup/FILE_METADATA")
|
||||
{
|
||||
std::wstring server_token = getafter(L"|", cmd);
|
||||
std::string server_token = getafter("|", cmd);
|
||||
|
||||
IPipe* cmd_pipe = Server->createMemoryPipe();
|
||||
FileMetadataPipe* nf = new FileMetadataPipe(cmd_pipe, cmd);
|
||||
@ -66,16 +66,16 @@ IFile* PipeSessions::getFile(const std::wstring& cmd)
|
||||
}
|
||||
else
|
||||
{
|
||||
int backupnum = watoi(getuntil(L"|", getafter(L"|", cmd)));
|
||||
int backupnum = watoi(getuntil("|", getafter("|", cmd)));
|
||||
|
||||
std::wstring output_filename = ExtractFileName(script_cmd);
|
||||
std::string output_filename = ExtractFileName(script_cmd);
|
||||
|
||||
script_cmd.erase(script_cmd.size()-output_filename.size(), output_filename.size());
|
||||
|
||||
std::wstring script_filename = FileServ::mapScriptOutputNameToScript(output_filename);
|
||||
std::string script_filename = FileServ::mapScriptOutputNameToScript(output_filename);
|
||||
|
||||
script_cmd = L"\"" + script_cmd + script_filename +
|
||||
L"\" \"" + output_filename + L"\" "+convert(backupnum);
|
||||
script_cmd = "\"" + script_cmd + script_filename +
|
||||
"\" \"" + output_filename + "\" "+convert(backupnum);
|
||||
|
||||
PipeFile* nf = new PipeFile(script_cmd);
|
||||
if(nf->getHasError())
|
||||
@ -108,14 +108,14 @@ void PipeSessions::destroy()
|
||||
do_stop=true;
|
||||
}
|
||||
|
||||
void PipeSessions::removeFile(const std::wstring& cmd)
|
||||
void PipeSessions::removeFile(const std::string& cmd)
|
||||
{
|
||||
IScopedLock lock(mutex);
|
||||
|
||||
std::map<std::wstring, SPipeSession>::iterator it = pipe_files.find(cmd);
|
||||
std::map<std::string, SPipeSession>::iterator it = pipe_files.find(cmd);
|
||||
if(it != pipe_files.end())
|
||||
{
|
||||
Server->Log(L"Removing pipe file "+cmd, LL_DEBUG);
|
||||
Server->Log("Removing pipe file "+cmd, LL_DEBUG);
|
||||
|
||||
if(!it->second.retrieved_exit_info)
|
||||
{
|
||||
@ -128,7 +128,7 @@ void PipeSessions::removeFile(const std::wstring& cmd)
|
||||
|
||||
exit_information[cmd] = exit_info;
|
||||
|
||||
Server->Log("Pipe file has exit code "+nconvert(exit_code), LL_DEBUG);
|
||||
Server->Log("Pipe file has exit code "+convert(exit_code), LL_DEBUG);
|
||||
}
|
||||
|
||||
it->second.file->forceExitWait();
|
||||
@ -141,16 +141,16 @@ void PipeSessions::removeFile(const std::wstring& cmd)
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->Log(L"Pipe file "+cmd+L" not found while removing pipe file", LL_WARNING);
|
||||
Server->Log("Pipe file "+cmd+" not found while removing pipe file", LL_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
SExitInformation PipeSessions::getExitInformation(const std::wstring& cmd)
|
||||
SExitInformation PipeSessions::getExitInformation(const std::string& cmd)
|
||||
{
|
||||
IScopedLock lock(mutex);
|
||||
|
||||
{
|
||||
std::map<std::wstring, SExitInformation>::iterator it=exit_information.find(cmd);
|
||||
std::map<std::string, SExitInformation>::iterator it=exit_information.find(cmd);
|
||||
|
||||
if(it!=exit_information.end())
|
||||
{
|
||||
@ -161,7 +161,7 @@ SExitInformation PipeSessions::getExitInformation(const std::wstring& cmd)
|
||||
}
|
||||
|
||||
{
|
||||
std::map<std::wstring, SPipeSession>::iterator it = pipe_files.find(cmd);
|
||||
std::map<std::string, SPipeSession>::iterator it = pipe_files.find(cmd);
|
||||
if(it != pipe_files.end() && !it->second.retrieved_exit_info)
|
||||
{
|
||||
int exit_code = -1;
|
||||
@ -195,7 +195,7 @@ void PipeSessions::operator()()
|
||||
|
||||
int64 currtime = Server->getTimeMS();
|
||||
|
||||
for(std::map<std::wstring, SPipeSession>::iterator it=pipe_files.begin();
|
||||
for(std::map<std::string, SPipeSession>::iterator it=pipe_files.begin();
|
||||
it!=pipe_files.end();)
|
||||
{
|
||||
if(currtime - it->second.file->getLastRead() > pipe_file_timeout)
|
||||
@ -203,7 +203,7 @@ void PipeSessions::operator()()
|
||||
it->second.file->forceExitWait();
|
||||
delete it->second.file;
|
||||
delete it->second.input_pipe;
|
||||
std::map<std::wstring, SPipeSession>::iterator del_it = it;
|
||||
std::map<std::string, SPipeSession>::iterator del_it = it;
|
||||
++it;
|
||||
pipe_files.erase(del_it);
|
||||
}
|
||||
@ -213,12 +213,12 @@ void PipeSessions::operator()()
|
||||
}
|
||||
}
|
||||
|
||||
for(std::map<std::wstring, SExitInformation>::iterator it=exit_information.begin();
|
||||
for(std::map<std::string, SExitInformation>::iterator it=exit_information.begin();
|
||||
it!=exit_information.end();)
|
||||
{
|
||||
if(currtime - it->second.created > pipe_file_timeout)
|
||||
{
|
||||
std::map<std::wstring, SExitInformation>::iterator del_it = it;
|
||||
std::map<std::string, SExitInformation>::iterator del_it = it;
|
||||
++it;
|
||||
exit_information.erase(del_it);
|
||||
}
|
||||
@ -255,7 +255,7 @@ void PipeSessions::transmitFileMetadata( const std::string& local_fn, const std:
|
||||
data.addVoidPtr(iter_cb->second);
|
||||
}
|
||||
|
||||
std::map<std::wstring, SPipeSession>::iterator it = pipe_files.find(widen("urbackup/FILE_METADATA|"+server_token));
|
||||
std::map<std::string, SPipeSession>::iterator it = pipe_files.find("urbackup/FILE_METADATA|"+server_token);
|
||||
|
||||
if(it!=pipe_files.end() && it->second.input_pipe!=NULL)
|
||||
{
|
||||
@ -267,7 +267,7 @@ void PipeSessions::metadataStreamEnd( const std::string& server_token )
|
||||
{
|
||||
IScopedLock lock(mutex);
|
||||
|
||||
std::map<std::wstring, SPipeSession>::iterator it = pipe_files.find(widen("urbackup/FILE_METADATA|"+server_token));
|
||||
std::map<std::string, SPipeSession>::iterator it = pipe_files.find("urbackup/FILE_METADATA|"+server_token);
|
||||
|
||||
if(it!=pipe_files.end() && it->second.input_pipe!=NULL)
|
||||
{
|
||||
@ -280,27 +280,27 @@ void PipeSessions::metadataStreamEnd( const std::string& server_token )
|
||||
}
|
||||
}
|
||||
|
||||
void PipeSessions::registerMetadataCallback( const std::wstring &name, const std::string& identity, IFileServ::IMetadataCallback* callback )
|
||||
void PipeSessions::registerMetadataCallback( const std::string &name, const std::string& identity, IFileServ::IMetadataCallback* callback )
|
||||
{
|
||||
IScopedLock lock(mutex);
|
||||
|
||||
std::map<std::pair<std::string, std::string>, IFileServ::IMetadataCallback*>::iterator iter
|
||||
= metadata_callbacks.find(std::make_pair(Server->ConvertToUTF8(name), identity));
|
||||
= metadata_callbacks.find(std::make_pair(name, identity));
|
||||
|
||||
if(iter!=metadata_callbacks.end())
|
||||
{
|
||||
delete iter->second;
|
||||
}
|
||||
|
||||
metadata_callbacks[std::make_pair(Server->ConvertToUTF8(name), identity)] = callback;
|
||||
metadata_callbacks[std::make_pair(name, identity)] = callback;
|
||||
}
|
||||
|
||||
void PipeSessions::removeMetadataCallback( const std::wstring &name, const std::string& identity )
|
||||
void PipeSessions::removeMetadataCallback( const std::string &name, const std::string& identity )
|
||||
{
|
||||
IScopedLock lock(mutex);
|
||||
|
||||
std::map<std::pair<std::string, std::string>, IFileServ::IMetadataCallback*>::iterator iter
|
||||
= metadata_callbacks.find(std::make_pair(Server->ConvertToUTF8(name), identity));
|
||||
= metadata_callbacks.find(std::make_pair(name, identity));
|
||||
|
||||
if(iter!=metadata_callbacks.end())
|
||||
{
|
||||
|
||||
@ -35,24 +35,24 @@ public:
|
||||
static void init();
|
||||
static void destroy();
|
||||
|
||||
static IFile* getFile(const std::wstring& cmd);
|
||||
static void removeFile(const std::wstring& cmd);
|
||||
static SExitInformation getExitInformation(const std::wstring& cmd);
|
||||
static IFile* getFile(const std::string& cmd);
|
||||
static void removeFile(const std::string& cmd);
|
||||
static SExitInformation getExitInformation(const std::string& cmd);
|
||||
|
||||
static void transmitFileMetadata(const std::string& local_fn, const std::string& public_fn,
|
||||
const std::string& server_token, const std::string& identity, int64 folder_items);
|
||||
|
||||
static void metadataStreamEnd(const std::string& server_token);
|
||||
|
||||
static void registerMetadataCallback(const std::wstring &name, const std::string& identity, IFileServ::IMetadataCallback* callback);
|
||||
static void removeMetadataCallback(const std::wstring &name, const std::string& identity);
|
||||
static void registerMetadataCallback(const std::string &name, const std::string& identity, IFileServ::IMetadataCallback* callback);
|
||||
static void removeMetadataCallback(const std::string &name, const std::string& identity);
|
||||
|
||||
void operator()();
|
||||
|
||||
private:
|
||||
static IMutex* mutex;
|
||||
static volatile bool do_stop;
|
||||
static std::map<std::wstring, SPipeSession> pipe_files;
|
||||
static std::map<std::wstring, SExitInformation> exit_information;
|
||||
static std::map<std::string, SPipeSession> pipe_files;
|
||||
static std::map<std::string, SExitInformation> exit_information;
|
||||
static std::map<std::pair<std::string, std::string>, IFileServ::IMetadataCallback*> metadata_callbacks;
|
||||
};
|
||||
@ -74,7 +74,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
udpport=atoi(s_udpport.c_str());
|
||||
|
||||
IFileServ *fileserv=fileserv_fak->createFileServ(tcpport, udpport);
|
||||
fileserv->shareDir(widen(ExtractFileName(share_dir)), widen(share_dir), std::string());
|
||||
fileserv->shareDir(ExtractFileName(share_dir), share_dir, std::string());
|
||||
fileserv->addIdentity("");
|
||||
}
|
||||
|
||||
|
||||
@ -153,7 +153,7 @@ bool SetPrivilege(
|
||||
lpszPrivilege, // privilege to lookup
|
||||
&luid ) ) // receives LUID of privilege
|
||||
{
|
||||
Log("LookupPrivilegeValue error: "+nconvert((int)GetLastError()), LL_ERROR );
|
||||
Log("LookupPrivilegeValue error: "+convert((int)GetLastError()), LL_ERROR );
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ bool SetPrivilege(
|
||||
(PTOKEN_PRIVILEGES) NULL,
|
||||
(PDWORD) NULL) )
|
||||
{
|
||||
Log("AdjustTokenPrivileges error: "+nconvert((int)GetLastError()), LL_ERROR );
|
||||
Log("AdjustTokenPrivileges error: "+convert((int)GetLastError()), LL_ERROR );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -29,18 +29,18 @@
|
||||
|
||||
struct s_mapl
|
||||
{
|
||||
std::wstring value;
|
||||
std::string value;
|
||||
_u32 lastmaptime;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
std::map<std::pair<std::wstring, std::string>, s_mapl> mapbuffer;
|
||||
std::map<std::pair<std::string, std::string>, s_mapl> mapbuffer;
|
||||
CriticalSection mapcs;
|
||||
}
|
||||
|
||||
|
||||
std::wstring getOsDir(std::wstring input)
|
||||
std::string getOsDir(std::string input)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
for(size_t i=0;i<input.size();++i)
|
||||
@ -52,21 +52,21 @@ std::wstring getOsDir(std::wstring input)
|
||||
return input;
|
||||
}
|
||||
|
||||
std::wstring map_file(std::wstring fn, const std::string& identity)
|
||||
std::string map_file(std::string fn, const std::string& identity)
|
||||
{
|
||||
std::wstring ts=getuntil(L"/",fn);
|
||||
std::string ts=getuntil("/",fn);
|
||||
if(ts.empty())
|
||||
ts=fn;
|
||||
fn.erase(0,ts.size());
|
||||
|
||||
std::wstring cp;
|
||||
std::string cp;
|
||||
for(size_t i=0;i<fn.size();++i)
|
||||
{
|
||||
if(fn[i]=='/')
|
||||
{
|
||||
if(cp==L"." || cp==L"..")
|
||||
if(cp=="." || cp=="..")
|
||||
{
|
||||
return L"";
|
||||
return "";
|
||||
}
|
||||
cp.clear();
|
||||
}
|
||||
@ -77,7 +77,7 @@ std::wstring map_file(std::wstring fn, const std::string& identity)
|
||||
}
|
||||
|
||||
mapcs.Enter();
|
||||
std::map<std::pair<std::wstring, std::string>, s_mapl>::iterator i=mapbuffer.find(std::make_pair(ts, std::string()));
|
||||
std::map<std::pair<std::string, std::string>, s_mapl>::iterator i=mapbuffer.find(std::make_pair(ts, std::string()));
|
||||
|
||||
if(i==mapbuffer.end())
|
||||
{
|
||||
@ -87,13 +87,13 @@ std::wstring map_file(std::wstring fn, const std::string& identity)
|
||||
if(i==mapbuffer.end() )
|
||||
{
|
||||
mapcs.Leave();
|
||||
Log("Could not find share \""+Server->ConvertToUTF8(ts)+"\"", LL_WARNING);
|
||||
return L"";
|
||||
Log("Could not find share \""+ts+"\"", LL_WARNING);
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring ret;
|
||||
if(i->second.value!=L"/" || fn.empty() || fn[0]!='/')
|
||||
std::string ret;
|
||||
if(i->second.value!="/" || fn.empty() || fn[0]!='/')
|
||||
ret = i->second.value + getOsDir(fn);
|
||||
else
|
||||
ret = getOsDir(fn);
|
||||
@ -103,7 +103,7 @@ std::wstring map_file(std::wstring fn, const std::string& identity)
|
||||
}
|
||||
}
|
||||
|
||||
void add_share_path(const std::wstring &name, const std::wstring &path, const std::string& identity)
|
||||
void add_share_path(const std::string &name, const std::string &path, const std::string& identity)
|
||||
{
|
||||
s_mapl m;
|
||||
m.value=getOsDir(path);
|
||||
@ -113,11 +113,11 @@ void add_share_path(const std::wstring &name, const std::wstring &path, const st
|
||||
mapcs.Leave();
|
||||
}
|
||||
|
||||
void remove_share_path(const std::wstring &name, const std::string& identity)
|
||||
void remove_share_path(const std::string &name, const std::string& identity)
|
||||
{
|
||||
mapcs.Enter();
|
||||
|
||||
std::map<std::pair<std::wstring, std::string>, s_mapl>::iterator it=mapbuffer.find(std::make_pair(name, identity));
|
||||
std::map<std::pair<std::string, std::string>, s_mapl>::iterator it=mapbuffer.find(std::make_pair(name, identity));
|
||||
if(it!=mapbuffer.end())
|
||||
{
|
||||
mapbuffer.erase(it);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::wstring map_file(std::wstring fn, const std::string& identity);
|
||||
void add_share_path(const std::wstring &name, const std::wstring &path, const std::string& identity);
|
||||
void remove_share_path(const std::wstring &name, const std::string& identity);
|
||||
std::string map_file(std::string fn, const std::string& identity);
|
||||
void add_share_path(const std::string &name, const std::string &path, const std::string& identity);
|
||||
void remove_share_path(const std::string &name, const std::string& identity);
|
||||
|
||||
@ -37,7 +37,7 @@ const _u32 mode_zlib = 1;
|
||||
const size_t c_header_size = sizeof(headerMagic) + sizeof(__int64) + sizeof(__int64) + sizeof(_u32);
|
||||
|
||||
|
||||
CompressedFile::CompressedFile( std::wstring pFilename, int pMode )
|
||||
CompressedFile::CompressedFile( std::string pFilename, int pMode )
|
||||
: hotCache(NULL), error(false), currentPosition(0),
|
||||
finished(false), filesize(0), noMagic(false)
|
||||
{
|
||||
@ -45,7 +45,7 @@ CompressedFile::CompressedFile( std::wstring pFilename, int pMode )
|
||||
|
||||
if(uncompressedFile==NULL)
|
||||
{
|
||||
Server->Log(L"Could not open compressed file \""+pFilename+L"\"", LL_ERROR);
|
||||
Server->Log("Could not open compressed file \""+pFilename+"\"", LL_ERROR);
|
||||
error=true;
|
||||
return;
|
||||
}
|
||||
@ -261,7 +261,7 @@ bool CompressedFile::fillCache( __int64 offset, bool errorMsg, bool *has_error)
|
||||
{
|
||||
if(errorMsg)
|
||||
{
|
||||
Server->Log("Block "+nconvert(block)+" to read not found in block index", LL_ERROR);
|
||||
Server->Log("Block "+convert(block)+" to read not found in block index", LL_ERROR);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -283,7 +283,7 @@ bool CompressedFile::fillCache( __int64 offset, bool errorMsg, bool *has_error)
|
||||
|
||||
if(!uncompressedFile->Seek(blockDataOffset))
|
||||
{
|
||||
Server->Log("Error while seeking to offset "+nconvert(blockDataOffset)+" to read compressed data", LL_ERROR);
|
||||
Server->Log("Error while seeking to offset "+convert(blockDataOffset)+" to read compressed data", LL_ERROR);
|
||||
if(has_error) *has_error=true;
|
||||
return false;
|
||||
}
|
||||
@ -305,13 +305,13 @@ bool CompressedFile::fillCache( __int64 offset, bool errorMsg, bool *has_error)
|
||||
{
|
||||
if(compressedSize>blocksize)
|
||||
{
|
||||
Server->Log("Blocksize too large at offset "+nconvert(blockDataOffset)+" ("+nconvert(compressedSize)+" bytes)", LL_ERROR);
|
||||
Server->Log("Blocksize too large at offset "+convert(blockDataOffset)+" ("+convert(compressedSize)+" bytes)", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(readFromFile(buf, compressedSize, has_error)!=compressedSize)
|
||||
{
|
||||
Server->Log("Error while reading uncompressed data from "+nconvert(blockDataOffset)+" ("+nconvert(compressedSize)+" bytes)", LL_ERROR);
|
||||
Server->Log("Error while reading uncompressed data from "+convert(blockDataOffset)+" ("+convert(compressedSize)+" bytes)", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -326,7 +326,7 @@ bool CompressedFile::fillCache( __int64 offset, bool errorMsg, bool *has_error)
|
||||
|
||||
if(readFromFile(&compressedBuffer[0], compressedSize, has_error)!=compressedSize)
|
||||
{
|
||||
Server->Log("Error while reading compressed data from "+nconvert(blockDataOffset)+" ("+nconvert(compressedSize)+" bytes)", LL_ERROR);
|
||||
Server->Log("Error while reading compressed data from "+convert(blockDataOffset)+" ("+convert(compressedSize)+" bytes)", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -340,7 +340,7 @@ bool CompressedFile::fillCache( __int64 offset, bool errorMsg, bool *has_error)
|
||||
|
||||
if(rc != MZ_OK)
|
||||
{
|
||||
Server->Log("Error while decompressing file. Error code "+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error while decompressing file. Error code "+convert(rc), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -348,7 +348,7 @@ bool CompressedFile::fillCache( __int64 offset, bool errorMsg, bool *has_error)
|
||||
|
||||
if(rdecomp!=blocksize && offset+blocksize<filesize)
|
||||
{
|
||||
Server->Log("Did not receive enough bytes from compressed stream. Expected "+nconvert(blocksize)+" received "+nconvert((size_t)rdecomp), LL_ERROR);
|
||||
Server->Log("Did not receive enough bytes from compressed stream. Expected "+convert(blocksize)+" received "+convert((size_t)rdecomp), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -427,7 +427,7 @@ void CompressedFile::evictFromLruCache( const SCacheItem& item )
|
||||
if(rc!=MZ_OK)
|
||||
{
|
||||
error=true;
|
||||
Server->Log("Error while compressing data. Error code: "+nconvert(rc), LL_ERROR);
|
||||
Server->Log("Error while compressing data. Error code: "+convert(rc), LL_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -561,11 +561,6 @@ std::string CompressedFile::getFilename( void )
|
||||
return uncompressedFile->getFilename();
|
||||
}
|
||||
|
||||
std::wstring CompressedFile::getFilenameW( void )
|
||||
{
|
||||
return uncompressedFile->getFilenameW();
|
||||
}
|
||||
|
||||
_u32 CompressedFile::readFromFile(char* buffer, _u32 bsize, bool *has_error)
|
||||
{
|
||||
_u32 read = 0;
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
class CompressedFile : public IFile, public ICacheEvictionCallback
|
||||
{
|
||||
public:
|
||||
CompressedFile(std::wstring pFilename, int pMode);
|
||||
CompressedFile(std::string pFilename, int pMode);
|
||||
CompressedFile(IFile* file, bool openExisting, bool readOnly);
|
||||
~CompressedFile();
|
||||
|
||||
@ -25,7 +25,6 @@ public:
|
||||
virtual bool PunchHole( _i64 spos, _i64 size );
|
||||
|
||||
virtual std::string getFilename(void);
|
||||
virtual std::wstring getFilenameW(void);
|
||||
|
||||
virtual bool Sync();
|
||||
|
||||
|
||||
@ -38,10 +38,10 @@
|
||||
|
||||
void PrintInfo(IFilesystem *fs)
|
||||
{
|
||||
Server->Log("FSINFO: blocksize="+nconvert(fs->getBlocksize())+" size="+nconvert(fs->getSize())+" has_error="+nconvert(fs->hasError())+" used_space="+nconvert(fs->calculateUsedSpace()), LL_DEBUG);
|
||||
Server->Log("FSINFO: blocksize="+convert(fs->getBlocksize())+" size="+convert(fs->getSize())+" has_error="+convert(fs->hasError())+" used_space="+convert(fs->calculateUsedSpace()), LL_DEBUG);
|
||||
}
|
||||
|
||||
IFilesystem *FSImageFactory::createFilesystem(const std::wstring &pDev, bool read_ahead, bool background_priority, bool exclude_shadow_storage)
|
||||
IFilesystem *FSImageFactory::createFilesystem(const std::string &pDev, bool read_ahead, bool background_priority, bool exclude_shadow_storage)
|
||||
{
|
||||
IFile *dev=Server->openFile(pDev, MODE_READ_DEVICE);
|
||||
if(dev==NULL)
|
||||
@ -52,14 +52,14 @@ IFilesystem *FSImageFactory::createFilesystem(const std::wstring &pDev, bool rea
|
||||
#else
|
||||
last_error=errno;
|
||||
#endif
|
||||
Server->Log(L"Error opening device file ("+pDev+L") Errorcode: "+convert(last_error), LL_ERROR);
|
||||
Server->Log("Error opening device file ("+pDev+") Errorcode: "+convert(last_error), LL_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
char buffer[1024];
|
||||
_u32 rc=dev->Read(buffer, 1024);
|
||||
if(rc!=1024)
|
||||
{
|
||||
Server->Log(L"Error reading data from device ("+pDev+L")", LL_ERROR);
|
||||
Server->Log("Error reading data from device ("+pDev+")", LL_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ IFilesystem *FSImageFactory::createFilesystem(const std::wstring &pDev, bool rea
|
||||
|
||||
if(isNTFS(buffer) )
|
||||
{
|
||||
Server->Log(L"Filesystem type is ntfs ("+pDev+L")", LL_DEBUG);
|
||||
Server->Log("Filesystem type is ntfs ("+pDev+")", LL_DEBUG);
|
||||
FSNTFS *fs=new FSNTFS(pDev, read_ahead, background_priority);
|
||||
|
||||
|
||||
@ -87,14 +87,14 @@ IFilesystem *FSImageFactory::createFilesystem(const std::wstring &pDev, bool rea
|
||||
int64 idx_start=idx;
|
||||
for(size_t i=0;i<100;++i)
|
||||
{
|
||||
b1+=nconvert((int)fs->readBlock(idx, NULL));
|
||||
b2+=nconvert((int)fs2->readBlock(idx, NULL));
|
||||
b1+=convert((int)fs->readBlock(idx, NULL));
|
||||
b2+=convert((int)fs2->readBlock(idx, NULL));
|
||||
++idx;
|
||||
}
|
||||
if(b1!=b2)
|
||||
{
|
||||
Server->Log(nconvert(idx_start)+" fs1: "+b1, LL_DEBUG);
|
||||
Server->Log(nconvert(idx_start)+" fs2: "+b2, LL_DEBUG);
|
||||
Server->Log(convert(idx_start)+" fs1: "+b1, LL_DEBUG);
|
||||
Server->Log(convert(idx_start)+" fs2: "+b2, LL_DEBUG);
|
||||
}
|
||||
}*/
|
||||
|
||||
@ -142,7 +142,7 @@ bool FSImageFactory::isNTFS(char *buffer)
|
||||
}
|
||||
}
|
||||
|
||||
IVHDFile *FSImageFactory::createVHDFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize,
|
||||
IVHDFile *FSImageFactory::createVHDFile(const std::string &fn, bool pRead_only, uint64 pDstsize,
|
||||
unsigned int pBlocksize, bool fast_mode, ImageFormat format)
|
||||
{
|
||||
switch(format)
|
||||
@ -160,7 +160,7 @@ IVHDFile *FSImageFactory::createVHDFile(const std::wstring &fn, bool pRead_only,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IVHDFile *FSImageFactory::createVHDFile(const std::wstring &fn, const std::wstring &parent_fn,
|
||||
IVHDFile *FSImageFactory::createVHDFile(const std::string &fn, const std::string &parent_fn,
|
||||
bool pRead_only, bool fast_mode, ImageFormat format)
|
||||
{
|
||||
switch(format)
|
||||
|
||||
@ -5,12 +5,12 @@
|
||||
class FSImageFactory : public IFSImageFactory
|
||||
{
|
||||
public:
|
||||
virtual IFilesystem *createFilesystem(const std::wstring &pDev, bool read_ahead, bool background_priority, bool exclude_shadow_storage);
|
||||
virtual IFilesystem *createFilesystem(const std::string &pDev, bool read_ahead, bool background_priority, bool exclude_shadow_storage);
|
||||
|
||||
virtual IVHDFile *createVHDFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize,
|
||||
virtual IVHDFile *createVHDFile(const std::string &fn, bool pRead_only, uint64 pDstsize,
|
||||
unsigned int pBlocksize=2*1024*1024, bool fast_mode=false, IFSImageFactory::ImageFormat format=IFSImageFactory::ImageFormat_VHD);
|
||||
|
||||
virtual IVHDFile *createVHDFile(const std::wstring &fn, const std::wstring &parent_fn,
|
||||
virtual IVHDFile *createVHDFile(const std::string &fn, const std::string &parent_fn,
|
||||
bool pRead_only, bool fast_mode=false, IFSImageFactory::ImageFormat format=IFSImageFactory::ImageFormat_VHD);
|
||||
|
||||
virtual void destroyVHDFile(IVHDFile *vhd);
|
||||
|
||||
@ -18,11 +18,6 @@
|
||||
|
||||
#include "FileWrapper.h"
|
||||
|
||||
std::wstring FileWrapper::getFilenameW( void )
|
||||
{
|
||||
return wfile->getFilenameW();
|
||||
}
|
||||
|
||||
std::string FileWrapper::getFilename( void )
|
||||
{
|
||||
return wfile->getFilename();
|
||||
|
||||
@ -26,8 +26,6 @@ public:
|
||||
|
||||
virtual std::string getFilename(void);
|
||||
|
||||
virtual std::wstring getFilenameW(void);
|
||||
|
||||
virtual bool PunchHole( _i64 spos, _i64 size );
|
||||
|
||||
virtual bool Sync();
|
||||
|
||||
@ -9,7 +9,7 @@ class IVHDFile;
|
||||
class IFSImageFactory : public IPlugin
|
||||
{
|
||||
public:
|
||||
virtual IFilesystem *createFilesystem(const std::wstring &pDev, bool read_ahead, bool background_priority, bool exclude_shadow_storage)=0;
|
||||
virtual IFilesystem *createFilesystem(const std::string &pDev, bool read_ahead, bool background_priority, bool exclude_shadow_storage)=0;
|
||||
|
||||
enum ImageFormat
|
||||
{
|
||||
@ -18,10 +18,10 @@ public:
|
||||
ImageFormat_RawCowFile=2
|
||||
};
|
||||
|
||||
virtual IVHDFile *createVHDFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize,
|
||||
virtual IVHDFile *createVHDFile(const std::string &fn, bool pRead_only, uint64 pDstsize,
|
||||
unsigned int pBlocksize=2*1024*1024, bool fast_mode=false, ImageFormat compress=ImageFormat_VHD)=0;
|
||||
|
||||
virtual IVHDFile *createVHDFile(const std::wstring &fn, const std::wstring &parent_fn,
|
||||
virtual IVHDFile *createVHDFile(const std::string &fn, const std::string &parent_fn,
|
||||
bool pRead_only, bool fast_mode=false, ImageFormat compress=ImageFormat_VHD)=0;
|
||||
|
||||
virtual void destroyVHDFile(IVHDFile *vhd)=0;
|
||||
|
||||
@ -27,7 +27,6 @@ public:
|
||||
virtual uint64 getSize(void)=0;
|
||||
virtual uint64 usedSize(void)=0;
|
||||
virtual std::string getFilename(void)=0;
|
||||
virtual std::wstring getFilenameW(void)=0;
|
||||
virtual bool has_sector(_i64 sector_size=-1)=0;
|
||||
virtual bool this_has_sector(_i64 sector_size=-1)=0;
|
||||
virtual unsigned int getBlocksize()=0;
|
||||
|
||||
@ -25,14 +25,14 @@ bool create_reflink(const std::string &linkname, const std::string &fname)
|
||||
int src_desc=open64(fname.c_str(), O_RDONLY);
|
||||
if( src_desc<0)
|
||||
{
|
||||
Server->Log("Error opening source file. errno="+nconvert(errno));
|
||||
Server->Log("Error opening source file. errno="+convert(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
int dst_desc=open64(linkname.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRWXU | S_IRWXG);
|
||||
if( dst_desc<0 )
|
||||
{
|
||||
Server->Log("Error opening destination file. errno="+nconvert(errno));
|
||||
Server->Log("Error opening destination file. errno="+convert(errno));
|
||||
close(src_desc);
|
||||
return false;
|
||||
}
|
||||
@ -44,7 +44,7 @@ bool create_reflink(const std::string &linkname, const std::string &fname)
|
||||
|
||||
if(rc)
|
||||
{
|
||||
Server->Log("Reflink ioctl failed. errno="+nconvert(errno));
|
||||
Server->Log("Reflink ioctl failed. errno="+convert(errno));
|
||||
}
|
||||
|
||||
close(src_desc);
|
||||
@ -57,10 +57,10 @@ bool create_reflink(const std::string &linkname, const std::string &fname)
|
||||
}
|
||||
|
||||
|
||||
CowFile::CowFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize)
|
||||
CowFile::CowFile(const std::string &fn, bool pRead_only, uint64 pDstsize)
|
||||
: bitmap_dirty(false), finished(false), curr_offset(0)
|
||||
{
|
||||
filename = Server->ConvertToUTF8(fn);
|
||||
filename = (fn);
|
||||
read_only = pRead_only;
|
||||
filesize = pDstsize;
|
||||
|
||||
@ -104,7 +104,7 @@ CowFile::CowFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize)
|
||||
|
||||
if(rc!=0)
|
||||
{
|
||||
Server->Log("Truncating cow file to size "+nconvert(filesize)+" failed", LL_ERROR);
|
||||
Server->Log("Truncating cow file to size "+convert(filesize)+" failed", LL_ERROR);
|
||||
is_open=false;
|
||||
close(fd);
|
||||
}
|
||||
@ -127,15 +127,15 @@ CowFile::CowFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize)
|
||||
}
|
||||
}
|
||||
|
||||
CowFile::CowFile(const std::wstring &fn, const std::wstring &parent_fn, bool pRead_only)
|
||||
CowFile::CowFile(const std::string &fn, const std::string &parent_fn, bool pRead_only)
|
||||
: bitmap_dirty(false), finished(false), curr_offset(0)
|
||||
{
|
||||
filename = Server->ConvertToUTF8(fn);
|
||||
filename = (fn);
|
||||
read_only = pRead_only;
|
||||
|
||||
|
||||
struct stat64 statbuf;
|
||||
int rc = stat64(Server->ConvertToUTF8(parent_fn).c_str(), &statbuf);
|
||||
int rc = stat64((parent_fn).c_str(), &statbuf);
|
||||
if(rc==0)
|
||||
{
|
||||
filesize = statbuf.st_size;
|
||||
@ -155,7 +155,7 @@ CowFile::CowFile(const std::wstring &fn, const std::wstring &parent_fn, bool pRe
|
||||
}
|
||||
else if(!read_only)
|
||||
{
|
||||
is_open = loadBitmap(Server->ConvertToUTF8(parent_fn)+".bitmap");
|
||||
is_open = loadBitmap((parent_fn)+".bitmap");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -167,7 +167,7 @@ CowFile::CowFile(const std::wstring &fn, const std::wstring &parent_fn, bool pRe
|
||||
{
|
||||
if(!FileExists(filename))
|
||||
{
|
||||
is_open = create_reflink(filename, Server->ConvertToUTF8(parent_fn));
|
||||
is_open = create_reflink(filename, (parent_fn));
|
||||
}
|
||||
|
||||
if(is_open)
|
||||
@ -204,7 +204,7 @@ CowFile::CowFile(const std::wstring &fn, const std::wstring &parent_fn, bool pRe
|
||||
|
||||
if(rc!=0)
|
||||
{
|
||||
Server->Log("Truncating cow file to parent size "+nconvert(filesize)+" failed", LL_ERROR);
|
||||
Server->Log("Truncating cow file to parent size "+convert(filesize)+" failed", LL_ERROR);
|
||||
is_open=false;
|
||||
close(fd);
|
||||
}
|
||||
@ -242,7 +242,7 @@ bool CowFile::Seek(_i64 offset)
|
||||
|
||||
if(off!=curr_offset)
|
||||
{
|
||||
Server->Log("Seeking in file failed. errno="+nconvert(errno), LL_ERROR);
|
||||
Server->Log("Seeking in file failed. errno="+convert(errno), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ _u32 CowFile::Write(const char* buffer, _u32 bsize, bool *has_error)
|
||||
if( w<0 )
|
||||
{
|
||||
if(has_error) *has_error=true;
|
||||
Server->Log("Write to CowFile failed. errno="+nconvert(errno), LL_DEBUG);
|
||||
Server->Log("Write to CowFile failed. errno="+convert(errno), LL_DEBUG);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -325,11 +325,6 @@ std::string CowFile::getFilename(void)
|
||||
return filename;
|
||||
}
|
||||
|
||||
std::wstring CowFile::getFilenameW(void)
|
||||
{
|
||||
return Server->ConvertToUnicode(filename);
|
||||
}
|
||||
|
||||
bool CowFile::has_sector(_i64 sector_size)
|
||||
{
|
||||
if(sector_size<0)
|
||||
@ -465,7 +460,7 @@ bool CowFile::setUnused(_i64 unused_start, _i64 unused_end)
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->Log("fallocate failed (setting unused image range) with errno "+nconvert((int)errno), LL_WARNING);
|
||||
Server->Log("fallocate failed (setting unused image range) with errno "+convert((int)errno), LL_WARNING);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
class CowFile : public IVHDFile
|
||||
{
|
||||
public:
|
||||
CowFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize);
|
||||
CowFile(const std::wstring &fn, const std::wstring &parent_fn, bool pRead_only);
|
||||
CowFile(const std::string &fn, bool pRead_only, uint64 pDstsize);
|
||||
CowFile(const std::string &fn, const std::string &parent_fn, bool pRead_only);
|
||||
~CowFile();
|
||||
|
||||
|
||||
@ -18,7 +18,6 @@ public:
|
||||
virtual uint64 getSize(void);
|
||||
virtual uint64 usedSize(void);
|
||||
virtual std::string getFilename(void);
|
||||
virtual std::wstring getFilenameW(void);
|
||||
virtual bool has_sector(_i64 sector_size=-1);
|
||||
virtual bool this_has_sector(_i64 sector_size=-1);
|
||||
virtual unsigned int getBlocksize();
|
||||
|
||||
@ -75,13 +75,13 @@ void PrintInfo(IFilesystem *fs);
|
||||
|
||||
namespace
|
||||
{
|
||||
bool decompress_vhd(const std::wstring& fn, const std::wstring& output)
|
||||
bool decompress_vhd(const std::string& fn, const std::string& output)
|
||||
{
|
||||
std::wstring tmp_output=output;
|
||||
std::string tmp_output=output;
|
||||
|
||||
if(fn==output)
|
||||
{
|
||||
tmp_output+=L".tmp";
|
||||
tmp_output+=".tmp";
|
||||
}
|
||||
|
||||
IFile* out = Server->openFile(tmp_output, MODE_WRITE);
|
||||
@ -89,11 +89,11 @@ namespace
|
||||
|
||||
if(out==NULL)
|
||||
{
|
||||
Server->Log(L"Error opening output file \""+output+L"\"", LL_ERROR);
|
||||
Server->Log("Error opening output file \""+output+"\"", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(findextension(fn)==L"vhdz")
|
||||
if(findextension(fn)=="vhdz")
|
||||
{
|
||||
std::auto_ptr<VHDFile> vhdfile(new VHDFile(fn, true, 0));
|
||||
|
||||
@ -101,9 +101,9 @@ namespace
|
||||
{
|
||||
if(vhdfile->isCompressed())
|
||||
{
|
||||
std::wstring parent_fn = vhdfile->getParent()->getFilenameW();
|
||||
std::string parent_fn = vhdfile->getParent()->getFilename();
|
||||
vhdfile.reset();
|
||||
Server->Log(L"Decompressing parent VHD \""+parent_fn+L"\"...", LL_INFO);
|
||||
Server->Log("Decompressing parent VHD \""+parent_fn+"\"...", LL_INFO);
|
||||
bool b = decompress_vhd(parent_fn, parent_fn);
|
||||
|
||||
if(!b)
|
||||
@ -152,7 +152,7 @@ namespace
|
||||
if(currentpc!=pcdone)
|
||||
{
|
||||
pcdone=currentpc;
|
||||
Server->Log(L"Decompressing \""+fn+L"\"... "+convert(pcdone)+L"%", LL_INFO);
|
||||
Server->Log("Decompressing \""+fn+"\"... "+convert(pcdone)+"%", LL_INFO);
|
||||
}
|
||||
} while (read>0);
|
||||
|
||||
@ -163,9 +163,9 @@ namespace
|
||||
{
|
||||
out_file.clear();
|
||||
#ifdef _WIN32
|
||||
return MoveFileExW(tmp_output.c_str(), fn.c_str(), MOVEFILE_REPLACE_EXISTING)==TRUE;
|
||||
return MoveFileExW(Server->ConvertToWchar(tmp_output).c_str(), Server->ConvertToWchar(fn).c_str(), MOVEFILE_REPLACE_EXISTING)==TRUE;
|
||||
#else
|
||||
return rename(Server->ConvertToUTF8(tmp_output).c_str(), Server->ConvertToUTF8(fn).c_str())==0;
|
||||
return rename(tmp_output.c_str(), fn.c_str())==0;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@ -180,12 +180,12 @@ namespace
|
||||
std::string ext = strlower(findextension(device_verify));
|
||||
if(ext=="vhd" || ext=="vhdz")
|
||||
{
|
||||
return new VHDFile(Server->ConvertToUnicode(device_verify), true,0);
|
||||
return new VHDFile(device_verify, true,0);
|
||||
}
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
else if(ext=="raw")
|
||||
{
|
||||
return new CowFile(Server->ConvertToUnicode(device_verify), true,0);
|
||||
return new CowFile(device_verify, true,0);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
@ -217,12 +217,12 @@ namespace
|
||||
if(currentpc!=lastpc)
|
||||
{
|
||||
lastpc=currentpc;
|
||||
Server->Log(L"Assembling... "+convert(currentpc)+L"%", LL_INFO);
|
||||
Server->Log("Assembling... "+convert(currentpc)+"%", LL_INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool assemble_vhd(const std::vector<std::wstring>& fn, const std::wstring& output)
|
||||
bool assemble_vhd(const std::vector<std::string>& fn, const std::string& output)
|
||||
{
|
||||
//This function leaks currently. Do exit program after function!
|
||||
|
||||
@ -236,10 +236,10 @@ namespace
|
||||
|
||||
for(size_t i=0;i<fn.size();++i)
|
||||
{
|
||||
std::auto_ptr<IFile> f(Server->openFile(fn[i]+L".mbr", MODE_READ));
|
||||
std::auto_ptr<IFile> f(Server->openFile(fn[i]+".mbr", MODE_READ));
|
||||
if(f.get()==NULL)
|
||||
{
|
||||
Server->Log(L"Could not open MBR file "+fn[i]+L".mbr", LL_ERROR);
|
||||
Server->Log("Could not open MBR file "+fn[i]+".mbr", LL_ERROR);
|
||||
exit(1);
|
||||
}
|
||||
size_t fsize=(size_t)f->Size();
|
||||
@ -259,9 +259,9 @@ namespace
|
||||
{
|
||||
if(mbrdatas[j].partition_number==mbrdata.partition_number)
|
||||
{
|
||||
Server->Log(L"Volume "+mbrdatas[j].volume_name+L" ("+
|
||||
fn[j]+L") has the same partition number as the volume "+mbrdata.volume_name+
|
||||
L" ("+fn[i]+L"). Please make sure you only select volumes from one device.", LL_ERROR);
|
||||
Server->Log("Volume "+mbrdatas[j].volume_name+" ("+
|
||||
fn[j]+") has the same partition number as the volume "+mbrdata.volume_name+
|
||||
" ("+fn[i]+"). Please make sure you only select volumes from one device.", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -297,7 +297,7 @@ namespace
|
||||
VHDFile* in(new VHDFile(fn[i], true, 0));
|
||||
if(!in->isOpen())
|
||||
{
|
||||
Server->Log(L"Error opening VHD-File \""+fn[i]+L"\"", LL_ERROR);
|
||||
Server->Log("Error opening VHD-File \""+fn[i]+"\"", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -313,7 +313,7 @@ namespace
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->Log(L"Volume "+mbrdatas[i].volume_name+L" not an NTFS volume. Copying all blocks...", LL_WARNING);
|
||||
Server->Log("Volume "+mbrdatas[i].volume_name+" not an NTFS volume. Copying all blocks...", LL_WARNING);
|
||||
total_copy_bytes+=input_files[i]->Size();
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ namespace
|
||||
VHDFile vhdout(output, false, total_size, 2*1024*1024, true, false);
|
||||
if(!vhdout.isOpen())
|
||||
{
|
||||
Server->Log(L"Error opening output VHD-File \""+output+L"\"", LL_ERROR);
|
||||
Server->Log("Error opening output VHD-File \""+output+"\"", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -352,7 +352,7 @@ namespace
|
||||
|
||||
for(size_t i=0;i<fn.size();++i)
|
||||
{
|
||||
Server->Log(L"Writing "+fn[i]+L" into output VHD...");
|
||||
Server->Log("Writing "+fn[i]+" into output VHD...");
|
||||
|
||||
partition* cpart = partitions + (mbrdatas[i].partition_number-1);
|
||||
int64 out_pos = cpart->start_sector*c_sector_size;
|
||||
@ -360,7 +360,7 @@ namespace
|
||||
|
||||
if(input_fs[i]!=NULL)
|
||||
{
|
||||
Server->Log(L"Optimized by only writing used NTFS sectors...");
|
||||
Server->Log("Optimized by only writing used NTFS sectors...");
|
||||
|
||||
int64 blocksize = input_fs[i]->getBlocksize();
|
||||
int64 numblocks = input_fs[i]->getSize()/blocksize;
|
||||
@ -456,7 +456,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
|
||||
{
|
||||
Server->deleteFile(compress_file+".urz");
|
||||
CompressedFile compFile(widen(compress_file+".urz"), MODE_RW_CREATE);
|
||||
CompressedFile compFile(compress_file+".urz", MODE_RW_CREATE);
|
||||
|
||||
if(compFile.hasError())
|
||||
{
|
||||
@ -493,17 +493,17 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
#ifdef _WIN32
|
||||
if(decompress=="SelectViaGUI")
|
||||
{
|
||||
std::wstring filter;
|
||||
filter += L"Compressed image files (*.vhdz)";
|
||||
filter += (wchar_t)'\0';
|
||||
filter += L"*.vhdz";
|
||||
filter += (wchar_t)'\0';
|
||||
filter += (wchar_t)'\0';
|
||||
std::vector<std::wstring> res = file_via_dialog(L"Please select compressed image file to decompress",
|
||||
filter, false, true, L"");
|
||||
std::string filter;
|
||||
filter += "Compressed image files (*.vhdz)";
|
||||
filter += '\0';
|
||||
filter += "*.vhdz";
|
||||
filter += '\0';
|
||||
filter += '\0';
|
||||
std::vector<std::string> res = file_via_dialog("Please select compressed image file to decompress",
|
||||
filter, false, true, "");
|
||||
if(!res.empty())
|
||||
{
|
||||
decompress = Server->ConvertToUTF8(res[0]);
|
||||
decompress = res[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -534,7 +534,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
targetName = Server->getServerParameter("output_fn");
|
||||
}
|
||||
|
||||
bool b = decompress_vhd(Server->ConvertToUnicode(decompress), Server->ConvertToUnicode(targetName));
|
||||
bool b = decompress_vhd(decompress, targetName);
|
||||
|
||||
exit(b?0:3);
|
||||
}
|
||||
@ -543,33 +543,33 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
if(!assemble.empty())
|
||||
{
|
||||
bool selected_via_gui=false;
|
||||
std::vector<std::wstring> input_files;
|
||||
std::wstring output_file;
|
||||
std::vector<std::string> input_files;
|
||||
std::string output_file;
|
||||
#ifdef _WIN32
|
||||
if(assemble=="SelectViaGUI")
|
||||
{
|
||||
std::wstring filter;
|
||||
filter += L"Image files (*.vhdz;*.vhd)";
|
||||
filter += (wchar_t)'\0';
|
||||
filter += L"*.vhdz;*.vhd";
|
||||
filter += (wchar_t)'\0';
|
||||
std::string filter;
|
||||
filter += "Image files (*.vhdz;*.vhd)";
|
||||
filter += '\0';
|
||||
filter += "*.vhdz;*.vhd";
|
||||
filter += '\0';
|
||||
/*filter += L"Image files (*.vhd)";
|
||||
filter += (wchar_t)'\0';
|
||||
filter += '\0';
|
||||
filter += L"*.vhd";
|
||||
filter += (wchar_t)'\0';*/
|
||||
filter += (wchar_t)'\0';
|
||||
input_files = file_via_dialog(L"Please select all the images to assemble into one image",
|
||||
filter, true, true, L"");
|
||||
filter += '\0';*/
|
||||
filter += '\0';
|
||||
input_files = file_via_dialog("Please select all the images to assemble into one image",
|
||||
filter, true, true, "");
|
||||
|
||||
filter.clear();
|
||||
filter += L"Image file (*.vhd)";
|
||||
filter += (wchar_t)'\0';
|
||||
filter += L"*.vhd";
|
||||
filter += (wchar_t)'\0';
|
||||
filter += (wchar_t)'\0';
|
||||
filter += "Image file (*.vhd)";
|
||||
filter += '\0';
|
||||
filter += "*.vhd";
|
||||
filter += '\0';
|
||||
filter += '\0';
|
||||
|
||||
std::vector<std::wstring> output_files = file_via_dialog(L"Please select where to save the output image",
|
||||
filter, false, false, L"vhd");
|
||||
std::vector<std::string> output_files = file_via_dialog("Please select where to save the output image",
|
||||
filter, false, false, "vhd");
|
||||
|
||||
if(!output_files.empty())
|
||||
{
|
||||
@ -582,8 +582,8 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
|
||||
if(!selected_via_gui)
|
||||
{
|
||||
TokenizeMail(Server->ConvertToUnicode(assemble), input_files, L";");
|
||||
output_file = Server->ConvertToUnicode(Server->getServerParameter("output_file"));
|
||||
TokenizeMail(assemble, input_files, ";");
|
||||
output_file = Server->getServerParameter("output_file");
|
||||
}
|
||||
|
||||
if(input_files.empty())
|
||||
@ -608,12 +608,12 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
|
||||
if(!devinfo.empty())
|
||||
{
|
||||
FSNTFS ntfs(L"\\\\.\\"+widen(devinfo)+L":", false, true);
|
||||
FSNTFS ntfs("\\\\.\\"+devinfo+":", false, true);
|
||||
|
||||
if(!ntfs.hasError())
|
||||
{
|
||||
Server->Log("Used Space: "+nconvert(ntfs.calculateUsedSpace())+" of "+nconvert(ntfs.getSize()));
|
||||
Server->Log(nconvert(((float)ntfs.calculateUsedSpace()/(float)ntfs.getSize())*100.0f)+" %");
|
||||
Server->Log("Used Space: "+convert(ntfs.calculateUsedSpace())+" of "+convert(ntfs.getSize()));
|
||||
Server->Log(convert(((float)ntfs.calculateUsedSpace()/(float)ntfs.getSize())*100.0f)+" %");
|
||||
}
|
||||
}
|
||||
|
||||
@ -621,7 +621,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
if(!vhdcopy_in.empty())
|
||||
{
|
||||
Server->Log("VHDCopy.");
|
||||
VHDFile in(Server->ConvertToUnicode(vhdcopy_in), true,0);
|
||||
VHDFile in(vhdcopy_in, true,0);
|
||||
if(in.isOpen()==false)
|
||||
{
|
||||
Server->Log("Error opening VHD-File \""+vhdcopy_in+"\"", LL_ERROR);
|
||||
@ -631,7 +631,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
uint64 vhdsize=in.getSize();
|
||||
float vhdsize_gb=(vhdsize/1024)/1024.f/1024.f;
|
||||
uint64 vhdsize_mb=vhdsize/1024/1024;
|
||||
Server->Log("VHD Info: Size: "+nconvert(vhdsize_gb)+" GB "+nconvert(vhdsize_mb)+" MB",LL_INFO);
|
||||
Server->Log("VHD Info: Size: "+convert(vhdsize_gb)+" GB "+convert(vhdsize_mb)+" MB",LL_INFO);
|
||||
unsigned int vhd_blocksize=in.getBlocksize();
|
||||
|
||||
std::string vhdcopy_out=Server->getServerParameter("vhdcopy_out");
|
||||
@ -657,7 +657,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
skip=atoi(skip_s.c_str());
|
||||
}
|
||||
|
||||
Server->Log("Skipping "+nconvert(skip)+" bytes...", LL_INFO);
|
||||
Server->Log("Skipping "+convert(skip)+" bytes...", LL_INFO);
|
||||
in.Seek(skip);
|
||||
char buffer[4096];
|
||||
size_t read;
|
||||
@ -684,7 +684,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
|
||||
if(currpos!=skip)
|
||||
{
|
||||
Server->Log("First VHD sector at "+nconvert(currpos), LL_INFO);
|
||||
Server->Log("First VHD sector at "+convert(currpos), LL_INFO);
|
||||
}
|
||||
|
||||
do
|
||||
@ -718,7 +718,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
int pc=(int)(((float)currpos/(float)vhdsize)*100.f+0.5f);
|
||||
if(pc!=last_pc)
|
||||
{
|
||||
Server->Log(nconvert(pc)+"%", LL_INFO);
|
||||
Server->Log(convert(pc)+"%", LL_INFO);
|
||||
last_pc=pc;
|
||||
}
|
||||
}
|
||||
@ -773,7 +773,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
if(!vhdinfo.empty())
|
||||
{
|
||||
std::cout << "--VHDINFO--" << std::endl;
|
||||
VHDFile in(Server->ConvertToUnicode(vhdinfo), true,0);
|
||||
VHDFile in(vhdinfo, true,0);
|
||||
if(in.isOpen()==false)
|
||||
{
|
||||
Server->Log("Error opening VHD-File \""+vhdinfo+"\"", LL_ERROR);
|
||||
@ -783,7 +783,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
uint64 vhdsize=in.getSize();
|
||||
float vhdsize_gb=(vhdsize/1024)/1024.f/1024.f;
|
||||
uint64 vhdsize_mb=vhdsize/1024/1024;
|
||||
std::cout << ("VHD Info: Size: "+nconvert(vhdsize_gb)+" GB "+nconvert(vhdsize_mb)+" MB") << std::endl;
|
||||
std::cout << ("VHD Info: Size: "+convert(vhdsize_gb)+" GB "+convert(vhdsize_mb)+" MB") << std::endl;
|
||||
std::cout << "Blocksize: " << in.getBlocksize() << " Bytes" << std::endl;
|
||||
|
||||
uint64 new_blocks=0;
|
||||
@ -889,12 +889,12 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
if(memcmp(dig_r, dig_f, 32)!=0)
|
||||
{
|
||||
++diff;
|
||||
Server->Log("Different blocks: "+nconvert(diff)+" at pos "+nconvert(currpos)+" has_sector="+nconvert(has_sector));
|
||||
Server->Log("Different blocks: "+convert(diff)+" at pos "+convert(currpos)+" has_sector="+convert(has_sector));
|
||||
}
|
||||
else if(has_sector && has_hashfile)
|
||||
{
|
||||
++diff_w;
|
||||
Server->Log("Wrong difference: "+nconvert(diff_w)+" at pos "+nconvert(currpos));
|
||||
Server->Log("Wrong difference: "+convert(diff_w)+" at pos "+convert(currpos));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -905,7 +905,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
if(pc!=last_pc)
|
||||
{
|
||||
last_pc=pc;
|
||||
Server->Log("Checking hashfile: "+nconvert(pc)+"%");
|
||||
Server->Log("Checking hashfile: "+convert(pc)+"%");
|
||||
}
|
||||
|
||||
}
|
||||
@ -913,9 +913,9 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
{
|
||||
Server->Log("Hashfile does match");
|
||||
}
|
||||
Server->Log("Blocks with correct hash: "+nconvert(ok_blocks));
|
||||
Server->Log("Different blocks: "+nconvert(diff));
|
||||
Server->Log("Wrong differences: "+nconvert(diff_w));
|
||||
Server->Log("Blocks with correct hash: "+convert(ok_blocks));
|
||||
Server->Log("Different blocks: "+convert(diff));
|
||||
Server->Log("Wrong differences: "+convert(diff_w));
|
||||
exit(diff==0?0:7);
|
||||
}
|
||||
|
||||
@ -978,7 +978,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
|
||||
if(buf.get())
|
||||
{
|
||||
Server->Log("Could not read block "+nconvert(currpos/ntfs_blocksize), LL_ERROR);
|
||||
Server->Log("Could not read block "+convert(currpos/ntfs_blocksize), LL_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1010,7 +1010,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
if(memcmp(dig_r, dig_f, 32)!=0 && mixed!=2)
|
||||
{
|
||||
++diff;
|
||||
Server->Log("Different blocks: "+nconvert(diff)+" at pos "+nconvert(currpos)+" mixed = "+
|
||||
Server->Log("Different blocks: "+convert(diff)+" at pos "+convert(currpos)+" mixed = "+
|
||||
(mixed==3? "true":"false") );
|
||||
}
|
||||
|
||||
@ -1021,7 +1021,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
if(pc!=last_pc)
|
||||
{
|
||||
last_pc=pc;
|
||||
Server->Log("Checking device hashsums: "+nconvert(pc)+"%");
|
||||
Server->Log("Checking device hashsums: "+convert(pc)+"%");
|
||||
}
|
||||
|
||||
}
|
||||
@ -1029,14 +1029,14 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
{
|
||||
Server->Log("Device does not match hash file");
|
||||
}
|
||||
Server->Log("Different blocks: "+nconvert(diff));
|
||||
Server->Log("Different blocks: "+convert(diff));
|
||||
exit(7);
|
||||
}
|
||||
|
||||
std::string vhd_cmp=Server->getServerParameter("vhd_cmp");
|
||||
if(!vhd_cmp.empty())
|
||||
{
|
||||
VHDFile in(Server->ConvertToUnicode(vhd_cmp), true,0);
|
||||
VHDFile in(vhd_cmp, true,0);
|
||||
if(in.isOpen()==false)
|
||||
{
|
||||
Server->Log("Error opening VHD-File \""+vhd_cmp+"\"", LL_ERROR);
|
||||
@ -1044,7 +1044,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
}
|
||||
|
||||
std::string other=Server->getServerParameter("other");
|
||||
VHDFile other_in(Server->ConvertToUnicode(other), true,0);
|
||||
VHDFile other_in(other, true,0);
|
||||
if(other_in.isOpen()==false)
|
||||
{
|
||||
Server->Log("Error opening VHD-File \""+other+"\"", LL_ERROR);
|
||||
@ -1071,11 +1071,11 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
|
||||
if(in.this_has_sector() && !other_in.this_has_sector())
|
||||
{
|
||||
Server->Log("Sector only in file 1 at pos "+nconvert(currpos));
|
||||
Server->Log("Sector only in file 1 at pos "+convert(currpos));
|
||||
}
|
||||
if(!in.this_has_sector() && other_in.this_has_sector())
|
||||
{
|
||||
Server->Log("Sector only in file 2 at pos "+nconvert(currpos));
|
||||
Server->Log("Sector only in file 2 at pos "+convert(currpos));
|
||||
}
|
||||
|
||||
if(has_sector)
|
||||
@ -1116,9 +1116,9 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
std::string fn_uc;
|
||||
fn_uc.resize(fn.filename_length*2);
|
||||
memcpy(&fn_uc[0], buf1+pos+attr.attribute_offset+sizeof(MFTAttributeFilename), fn.filename_length*2);
|
||||
Server->Log(L"Filename="+Server->ConvertFromUTF16(fn_uc) , LL_DEBUG);
|
||||
Server->Log("Filename="+Server->ConvertFromUTF16(fn_uc) , LL_DEBUG);
|
||||
}
|
||||
Server->Log("Attribute Type: "+nconvert(attr.type)+" nonresident="+nconvert(attr.nonresident)+" length="+nconvert(attr.length), LL_DEBUG);
|
||||
Server->Log("Attribute Type: "+convert(attr.type)+" nonresident="+convert(attr.nonresident)+" length="+convert(attr.length), LL_DEBUG);
|
||||
}while( attr.type!=0xFFFFFFFF && attr.type!=0x80);
|
||||
}
|
||||
|
||||
@ -1126,7 +1126,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
{
|
||||
if(buf1[i]!=buf2[i])
|
||||
{
|
||||
Server->Log("Position "+nconvert(i)+": "+nconvert((int)buf1[i])+"<->"+nconvert((int)buf2[i]));
|
||||
Server->Log("Position "+convert(i)+": "+convert((int)buf1[i])+"<->"+convert((int)buf2[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1138,7 +1138,7 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
if(hdiff)
|
||||
{
|
||||
++diff;
|
||||
Server->Log("Different blocks: "+nconvert(diff)+" at pos "+nconvert(currpos));
|
||||
Server->Log("Different blocks: "+convert(diff)+" at pos "+convert(currpos));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1146,18 +1146,18 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
if(pc!=last_pc)
|
||||
{
|
||||
last_pc=pc;
|
||||
Server->Log("Checking hashfile: "+nconvert(pc)+"%");
|
||||
Server->Log("Checking hashfile: "+convert(pc)+"%");
|
||||
}
|
||||
|
||||
}
|
||||
Server->Log("Different blocks: "+nconvert(diff));
|
||||
Server->Log("Different blocks: "+convert(diff));
|
||||
exit(7);
|
||||
}
|
||||
|
||||
std::string vhd_fixmftmirr=Server->getServerParameter("vhd_checkmftmirr");
|
||||
if(!vhd_fixmftmirr.empty())
|
||||
{
|
||||
VHDFile vhd(Server->ConvertToUnicode(vhd_fixmftmirr), false, 0);
|
||||
VHDFile vhd(vhd_fixmftmirr, false, 0);
|
||||
vhd.addVolumeOffset(1024*512);
|
||||
|
||||
if(vhd.isOpen()==false)
|
||||
|
||||
@ -247,7 +247,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
Filesystem::Filesystem(const std::wstring &pDev, bool read_ahead, bool background_priority)
|
||||
Filesystem::Filesystem(const std::string &pDev, bool read_ahead, bool background_priority)
|
||||
: buffer_mutex(Server->createMutex())
|
||||
{
|
||||
has_error=false;
|
||||
@ -255,7 +255,7 @@ Filesystem::Filesystem(const std::wstring &pDev, bool read_ahead, bool backgroun
|
||||
dev=Server->openFile(pDev, MODE_READ_DEVICE);
|
||||
if(dev==NULL)
|
||||
{
|
||||
Server->Log("Error opening device file. Errorcode: "+nconvert(getLastSystemError()), LL_ERROR);
|
||||
Server->Log("Error opening device file. Errorcode: "+convert(getLastSystemError()), LL_ERROR);
|
||||
has_error=true;
|
||||
}
|
||||
own_dev=true;
|
||||
@ -386,12 +386,12 @@ bool Filesystem::readFromDev(char *buf, _u32 bsize)
|
||||
while(rc<bsize)
|
||||
{
|
||||
Server->wait(200);
|
||||
Server->Log("Reading from device failed. Retrying. Errorcode: "+nconvert(getLastSystemError()), LL_WARNING);
|
||||
Server->Log("Reading from device failed. Retrying. Errorcode: "+convert(getLastSystemError()), LL_WARNING);
|
||||
rc+=dev->Read(buf+rc, bsize-rc);
|
||||
--tries;
|
||||
if(tries<0)
|
||||
{
|
||||
Server->Log("Reading from device failed. Errorcode: "+nconvert(getLastSystemError()), LL_ERROR);
|
||||
Server->Log("Reading from device failed. Errorcode: "+convert(getLastSystemError()), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ namespace
|
||||
class Filesystem : public IFilesystem
|
||||
{
|
||||
public:
|
||||
Filesystem(const std::wstring &pDev, bool read_ahead, bool background_priority);
|
||||
Filesystem(const std::string &pDev, bool read_ahead, bool background_priority);
|
||||
Filesystem(IFile *pDev, bool read_ahead, bool background_priority);
|
||||
virtual ~Filesystem();
|
||||
virtual int64 getBlocksize(void)=0;
|
||||
|
||||
@ -38,7 +38,7 @@ private:
|
||||
char* buf;
|
||||
};
|
||||
|
||||
FSNTFS::FSNTFS(const std::wstring &pDev, bool read_ahead, bool background_priority, bool check_mft_mirror, bool fix)
|
||||
FSNTFS::FSNTFS(const std::string &pDev, bool read_ahead, bool background_priority, bool check_mft_mirror, bool fix)
|
||||
: Filesystem(pDev, read_ahead, background_priority), bitmap(NULL)
|
||||
{
|
||||
init(check_mft_mirror, fix);
|
||||
@ -76,9 +76,9 @@ void FSNTFS::init(bool check_mft_mirror, bool fix)
|
||||
clustersize=sectorsize*br.sectorspercluster;
|
||||
drivesize=br.numberofsectors*sectorsize;
|
||||
|
||||
Server->Log("Sectorsize: "+nconvert(sectorsize), LL_DEBUG);
|
||||
Server->Log("Clustersize: "+nconvert(clustersize), LL_DEBUG);
|
||||
Server->Log("ClustersPerMFTNode Offset: "+nconvert((uint64)&br.mftlcn-(uint64)&br), LL_DEBUG);
|
||||
Server->Log("Sectorsize: "+convert(sectorsize), LL_DEBUG);
|
||||
Server->Log("Clustersize: "+convert(clustersize), LL_DEBUG);
|
||||
Server->Log("ClustersPerMFTNode Offset: "+convert((uint64)&br.mftlcn-(uint64)&br), LL_DEBUG);
|
||||
|
||||
unsigned int mftrecordsize;
|
||||
if(br.clusterspermftrecord<0)
|
||||
@ -91,7 +91,7 @@ void FSNTFS::init(bool check_mft_mirror, bool fix)
|
||||
}
|
||||
|
||||
uint64 mftstart=br.mftlcn*clustersize;
|
||||
Server->Log("MFTStart: "+nconvert(br.mftlcn), LL_DEBUG);
|
||||
Server->Log("MFTStart: "+convert(br.mftlcn), LL_DEBUG);
|
||||
|
||||
char *mftrecord=new char[mftrecordsize];
|
||||
MemFree mftrecord_free(mftrecord);
|
||||
@ -135,9 +135,9 @@ void FSNTFS::init(bool check_mft_mirror, bool fix)
|
||||
std::string fn_uc;
|
||||
fn_uc.resize(fn.filename_length*2);
|
||||
memcpy(&fn_uc[0], mftrecord+currpos+attr.attribute_offset+sizeof(MFTAttributeFilename), fn.filename_length*2);
|
||||
Server->Log(L"Filename="+Server->ConvertFromUTF16(fn_uc) , LL_DEBUG);
|
||||
Server->Log("Filename="+Server->ConvertFromUTF16(fn_uc) , LL_DEBUG);
|
||||
}
|
||||
Server->Log("Attribute Type: "+nconvert(attr.type)+" nonresident="+nconvert(attr.nonresident)+" length="+nconvert(attr.length), LL_DEBUG);
|
||||
Server->Log("Attribute Type: "+convert(attr.type)+" nonresident="+convert(attr.nonresident)+" length="+convert(attr.length), LL_DEBUG);
|
||||
}while( attr.type!=0xFFFFFFFF && attr.type!=0x80);
|
||||
|
||||
if(attr.type==0xFFFFFFFF )
|
||||
@ -216,18 +216,18 @@ void FSNTFS::init(bool check_mft_mirror, bool fix)
|
||||
std::string fn_uc;
|
||||
fn_uc.resize(fn.filename_length*2);
|
||||
memcpy(&fn_uc[0], bitmaprecord+currpos+attr.attribute_offset+sizeof(MFTAttributeFilename), fn.filename_length*2);
|
||||
Server->Log(L"Filename="+Server->ConvertFromUTF16(fn_uc) , LL_DEBUG);
|
||||
if(Server->ConvertFromUTF16(fn_uc)==L"$Bitmap")
|
||||
Server->Log("Filename="+Server->ConvertFromUTF16(fn_uc) , LL_DEBUG);
|
||||
if(Server->ConvertFromUTF16(fn_uc)=="$Bitmap")
|
||||
{
|
||||
is_bitmap=true;
|
||||
}
|
||||
}
|
||||
Server->Log("Attribute Type: "+nconvert(attr.type)+" nonresident="+nconvert(attr.nonresident)+" length="+nconvert(attr.length), LL_DEBUG);
|
||||
Server->Log("Attribute Type: "+convert(attr.type)+" nonresident="+convert(attr.nonresident)+" length="+convert(attr.length), LL_DEBUG);
|
||||
}while( attr.type!=0xFFFFFFFF && attr.type!=0x80);
|
||||
|
||||
if(!is_bitmap)
|
||||
{
|
||||
Server->Log(L"Filename attribute not found or filename wrong", LL_ERROR);
|
||||
Server->Log("Filename attribute not found or filename wrong", LL_ERROR);
|
||||
has_error=true;
|
||||
return;
|
||||
}
|
||||
@ -274,7 +274,7 @@ void FSNTFS::init(bool check_mft_mirror, bool fix)
|
||||
rc=dev->Read(buffer, clustersize);
|
||||
if(rc!=clustersize)
|
||||
{
|
||||
Server->Log("Error reading cluster "+nconvert(lcn)+" code: 529", LL_ERROR);
|
||||
Server->Log("Error reading cluster "+convert(lcn)+" code: 529", LL_ERROR);
|
||||
has_error=true;
|
||||
return;
|
||||
}
|
||||
@ -406,18 +406,18 @@ bool FSNTFS::checkMFTMirror(unsigned int mftrecordsize, Runlist &mftrunlist, NTF
|
||||
std::string fn_uc;
|
||||
fn_uc.resize(fn.filename_length*2);
|
||||
memcpy(&fn_uc[0], mirrrecord+currpos+attr.attribute_offset+sizeof(MFTAttributeFilename), fn.filename_length*2);
|
||||
Server->Log(L"Filename="+Server->ConvertFromUTF16(fn_uc) , LL_DEBUG);
|
||||
if(Server->ConvertFromUTF16(fn_uc)==L"$MFTMirr")
|
||||
Server->Log("Filename="+Server->ConvertFromUTF16(fn_uc) , LL_DEBUG);
|
||||
if(Server->ConvertFromUTF16(fn_uc)=="$MFTMirr")
|
||||
{
|
||||
is_mftmirr=true;
|
||||
}
|
||||
}
|
||||
Server->Log("Attribute Type: "+nconvert(attr.type)+" nonresident="+nconvert(attr.nonresident)+" length="+nconvert(attr.length), LL_DEBUG);
|
||||
Server->Log("Attribute Type: "+convert(attr.type)+" nonresident="+convert(attr.nonresident)+" length="+convert(attr.length), LL_DEBUG);
|
||||
}while( attr.type!=0xFFFFFFFF && attr.type!=0x80);
|
||||
|
||||
if(!is_mftmirr)
|
||||
{
|
||||
Server->Log(L"Filename attribute not found or filename wrong", LL_ERROR);
|
||||
Server->Log("Filename attribute not found or filename wrong", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -459,7 +459,7 @@ bool FSNTFS::checkMFTMirror(unsigned int mftrecordsize, Runlist &mftrunlist, NTF
|
||||
rc=dev->Read(buffer, clustersize);
|
||||
if(rc!=clustersize)
|
||||
{
|
||||
Server->Log("Error reading cluster "+nconvert(lcn)+" code: 529", LL_ERROR);
|
||||
Server->Log("Error reading cluster "+convert(lcn)+" code: 529", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
memcpy(&mftmirr_data[mirr_pos], buffer, (size_t)(std::min)(mftmirrstream.real_size-mirr_pos, (uint64)clustersize) );
|
||||
@ -493,12 +493,12 @@ bool FSNTFS::checkMFTMirror(unsigned int mftrecordsize, Runlist &mftrunlist, NTF
|
||||
|
||||
if(A->lsn!=B->lsn)
|
||||
{
|
||||
Server->Log("MFT file record in MFT mirror differs in file record "+nconvert(i)+": Logfile sequence number differs", LL_WARNING);
|
||||
Server->Log("MFT file record in MFT mirror differs in file record "+convert(i)+": Logfile sequence number differs", LL_WARNING);
|
||||
}
|
||||
|
||||
if(memcmp(currfilerecord, mftmirr_data+i*mftrecordsize, mftrecordsize)!=0)
|
||||
{
|
||||
Server->Log("MFT file record in MFT mirror differs in file record "+nconvert(i), LL_WARNING);
|
||||
Server->Log("MFT file record in MFT mirror differs in file record "+convert(i), LL_WARNING);
|
||||
if(fix)
|
||||
{
|
||||
memcpy(mftmirr_data+i*mftrecordsize, currfilerecord, mftrecordsize);
|
||||
@ -526,7 +526,7 @@ bool FSNTFS::checkMFTMirror(unsigned int mftrecordsize, Runlist &mftrunlist, NTF
|
||||
rc=dev->Write((const char*)(mftmirr_data+i*clustersize), clustersize);
|
||||
if(rc!=clustersize)
|
||||
{
|
||||
Server->Log("Error writing cluster "+nconvert(lcn)+" code: 652", LL_WARNING);
|
||||
Server->Log("Error writing cluster "+convert(lcn)+" code: 652", LL_WARNING);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ class IFile;
|
||||
class FSNTFS : public Filesystem
|
||||
{
|
||||
public:
|
||||
FSNTFS(const std::wstring &pDev, bool read_ahead, bool background_priority, bool check_mft_mirror=false, bool fix=false);
|
||||
FSNTFS(const std::string &pDev, bool read_ahead, bool background_priority, bool check_mft_mirror=false, bool fix=false);
|
||||
FSNTFS(IFile *pDev, bool read_ahead, bool background_priority, bool check_mft_mirror=false, bool fix=false);
|
||||
~FSNTFS(void);
|
||||
|
||||
|
||||
@ -21,10 +21,10 @@
|
||||
#include "../../Interface/Server.h"
|
||||
#include "../../stringtools.h"
|
||||
|
||||
FSNTFSWIN::FSNTFSWIN(const std::wstring &pDev, bool read_ahead, bool background_priority)
|
||||
FSNTFSWIN::FSNTFSWIN(const std::string &pDev, bool read_ahead, bool background_priority)
|
||||
: Filesystem(pDev, read_ahead, background_priority), bitmap(NULL)
|
||||
{
|
||||
HANDLE hDev=CreateFileW( pDev.c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL );
|
||||
HANDLE hDev=CreateFileW( Server->ConvertToWchar(pDev).c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL );
|
||||
if(hDev==INVALID_HANDLE_VALUE)
|
||||
{
|
||||
Server->Log("Error opening device -2", LL_ERROR);
|
||||
@ -36,7 +36,7 @@ FSNTFSWIN::FSNTFSWIN(const std::wstring &pDev, bool read_ahead, bool background_
|
||||
DWORD bytes_per_sector;
|
||||
DWORD NumberOfFreeClusters;
|
||||
DWORD TotalNumberOfClusters;
|
||||
BOOL b=GetDiskFreeSpaceW((pDev+L"\\").c_str(), §ors_per_cluster, &bytes_per_sector, &NumberOfFreeClusters, &TotalNumberOfClusters);
|
||||
BOOL b=GetDiskFreeSpaceW((Server->ConvertToWchar(pDev)+L"\\").c_str(), §ors_per_cluster, &bytes_per_sector, &NumberOfFreeClusters, &TotalNumberOfClusters);
|
||||
if(!b)
|
||||
{
|
||||
Server->Log("Error in GetDiskFreeSpaceW", LL_ERROR);
|
||||
@ -87,7 +87,7 @@ FSNTFSWIN::FSNTFSWIN(const std::wstring &pDev, bool read_ahead, bool background_
|
||||
return;
|
||||
}
|
||||
|
||||
Server->Log("TotalNumberOfClusters="+nconvert((size_t)TotalNumberOfClusters)+" numberOfClusters="+nconvert(numberOfClusters)+" n_clusters="+nconvert(n_clusters)+" StartingLcn="+nconvert(vbb->StartingLcn.QuadPart)+" BitmapSize="+nconvert(vbb->BitmapSize.QuadPart)+" r_bytes="+nconvert((size_t)r_bytes), LL_DEBUG);
|
||||
Server->Log("TotalNumberOfClusters="+convert((size_t)TotalNumberOfClusters)+" numberOfClusters="+convert(numberOfClusters)+" n_clusters="+convert(n_clusters)+" StartingLcn="+convert(vbb->StartingLcn.QuadPart)+" BitmapSize="+convert(vbb->BitmapSize.QuadPart)+" r_bytes="+convert((size_t)r_bytes), LL_DEBUG);
|
||||
|
||||
bitmap=new unsigned char[(unsigned int)(n_clusters)];
|
||||
memset(bitmap, 0xFF, n_clusters);
|
||||
@ -118,30 +118,30 @@ const unsigned char * FSNTFSWIN::getBitmap(void)
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
bool FSNTFSWIN::excludeFiles( const std::wstring& path, const std::wstring& fn_contains )
|
||||
bool FSNTFSWIN::excludeFiles( const std::string& path, const std::string& fn_contains )
|
||||
{
|
||||
HANDLE fHandle;
|
||||
WIN32_FIND_DATAW wfd;
|
||||
std::wstring tpath=path;
|
||||
std::wstring tpath=Server->ConvertToWchar(path);
|
||||
if(!tpath.empty() && tpath[tpath.size()-1]=='\\' ) tpath.erase(path.size()-1, 1);
|
||||
fHandle=FindFirstFileW((tpath+L"\\*"+fn_contains+L"*").c_str(),&wfd);
|
||||
fHandle=FindFirstFileW((tpath+L"\\*"+Server->ConvertToWchar(fn_contains)+L"*").c_str(),&wfd);
|
||||
|
||||
if(fHandle==INVALID_HANDLE_VALUE)
|
||||
{
|
||||
Server->Log(L"Error opening find handle to "+tpath+L" err: "+convert((int)GetLastError()), LL_WARNING);
|
||||
Server->Log("Error opening find handle to "+path+" err: "+convert((int)GetLastError()), LL_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret=true;
|
||||
do
|
||||
{
|
||||
std::wstring name = wfd.cFileName;
|
||||
if(name==L"." || name==L".." )
|
||||
std::string name = Server->ConvertFromWchar(wfd.cFileName);
|
||||
if(name=="." || name==".." )
|
||||
continue;
|
||||
|
||||
if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
if(!excludeFile(tpath+L"\\"+name))
|
||||
if(!excludeFile(tpath+L"\\"+wfd.cFileName))
|
||||
{
|
||||
ret=false;
|
||||
}
|
||||
@ -184,7 +184,7 @@ bool FSNTFSWIN::excludeBlock( int64 block )
|
||||
|
||||
bool FSNTFSWIN::excludeFile( const std::wstring& path )
|
||||
{
|
||||
Server->Log(L"Trying to exclude contents of file "+path+L" from backup...", LL_DEBUG);
|
||||
Server->Log("Trying to exclude contents of file "+Server->ConvertFromWchar(path)+" from backup...", LL_DEBUG);
|
||||
|
||||
HANDLE hFile = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
@ -218,7 +218,7 @@ bool FSNTFSWIN::excludeFile( const std::wstring& path )
|
||||
|
||||
if(!excludeSectors(ret_ptrs->Extents[i].Lcn.QuadPart, count))
|
||||
{
|
||||
Server->Log(L"Error excluding sectors of file "+path, LL_WARNING);
|
||||
Server->Log("Error excluding sectors of file "+Server->ConvertFromWchar(path), LL_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ bool FSNTFSWIN::excludeFile( const std::wstring& path )
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->Log("Error "+nconvert((int)GetLastError())+" while accessing retrieval points", LL_WARNING);
|
||||
Server->Log("Error "+convert((int)GetLastError())+" while accessing retrieval points", LL_WARNING);
|
||||
CloseHandle(hFile);
|
||||
break;
|
||||
}
|
||||
@ -249,7 +249,7 @@ bool FSNTFSWIN::excludeFile( const std::wstring& path )
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->Log(L"Error opening file handle to "+path, LL_WARNING);
|
||||
Server->Log("Error opening file handle to "+Server->ConvertFromWchar(path), LL_WARNING);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,14 +4,14 @@
|
||||
class FSNTFSWIN : public Filesystem
|
||||
{
|
||||
public:
|
||||
FSNTFSWIN(const std::wstring &pDev, bool read_ahead, bool backgournd_priority);
|
||||
FSNTFSWIN(const std::string &pDev, bool read_ahead, bool backgournd_priority);
|
||||
~FSNTFSWIN(void);
|
||||
|
||||
int64 getBlocksize(void);
|
||||
virtual int64 getSize(void);
|
||||
const unsigned char * getBitmap(void);
|
||||
|
||||
bool excludeFiles(const std::wstring& path, const std::wstring& fn_contains);
|
||||
bool excludeFiles(const std::string& path, const std::string& fn_contains);
|
||||
bool excludeFile(const std::wstring& path);
|
||||
bool excludeSectors(int64 start, int64 count);
|
||||
bool excludeBlock(int64 block);
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#define DEF_BLOCKSIZE 4096
|
||||
|
||||
FSUnknown::FSUnknown(const std::wstring &pDev, bool read_ahead, bool background_priority)
|
||||
FSUnknown::FSUnknown(const std::string &pDev, bool read_ahead, bool background_priority)
|
||||
: Filesystem(pDev, read_ahead, background_priority)
|
||||
{
|
||||
if(has_error)
|
||||
return;
|
||||
|
||||
#ifdef _WIN32
|
||||
HANDLE hDev=CreateFileW( pDev.c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL );
|
||||
HANDLE hDev=CreateFileW( Server->ConvertToWchar(pDev).c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL );
|
||||
if(hDev==INVALID_HANDLE_VALUE)
|
||||
{
|
||||
Server->Log("Error opening device -2", LL_ERROR);
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
class FSUnknown : public Filesystem
|
||||
{
|
||||
public:
|
||||
FSUnknown(const std::wstring &pDev, bool read_ahead, bool background_priority);
|
||||
FSUnknown(const std::string &pDev, bool read_ahead, bool background_priority);
|
||||
~FSUnknown(void);
|
||||
|
||||
int64 getBlocksize(void);
|
||||
|
||||
@ -40,7 +40,7 @@ const int64 unixtime_offset=946684800;
|
||||
|
||||
const unsigned int sector_size=512;
|
||||
|
||||
VHDFile::VHDFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize, unsigned int pBlocksize, bool fast_mode, bool compress)
|
||||
VHDFile::VHDFile(const std::string &fn, bool pRead_only, uint64 pDstsize, unsigned int pBlocksize, bool fast_mode, bool compress)
|
||||
: dstsize(pDstsize), blocksize(pBlocksize), fast_mode(fast_mode), bitmap_offset(0), bitmap_dirty(false), volume_offset(0), finished(false),
|
||||
file(NULL)
|
||||
{
|
||||
@ -101,7 +101,7 @@ VHDFile::VHDFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize, unsig
|
||||
}
|
||||
|
||||
write_header(false);
|
||||
write_dynamicheader(NULL, 0, L"");
|
||||
write_dynamicheader(NULL, 0, "");
|
||||
write_bat();
|
||||
|
||||
nextblock_offset=bat_offset+batsize*sizeof(unsigned int);
|
||||
@ -135,7 +135,7 @@ VHDFile::VHDFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize, unsig
|
||||
}
|
||||
}
|
||||
|
||||
VHDFile::VHDFile(const std::wstring &fn, const std::wstring &parent_fn, bool pRead_only, bool fast_mode, bool compress)
|
||||
VHDFile::VHDFile(const std::string &fn, const std::string &parent_fn, bool pRead_only, bool fast_mode, bool compress)
|
||||
: fast_mode(fast_mode), bitmap_offset(0), bitmap_dirty(false), volume_offset(0), finished(false), file(NULL)
|
||||
{
|
||||
compressed_file=NULL;
|
||||
@ -348,7 +348,7 @@ unsigned int VHDFile::calculate_checksum(const unsigned char * data, size_t dsiz
|
||||
return ~big_endian(checksum);
|
||||
}
|
||||
|
||||
bool VHDFile::write_dynamicheader(char *parent_uid, unsigned int parent_timestamp, std::wstring parentfn)
|
||||
bool VHDFile::write_dynamicheader(char *parent_uid, unsigned int parent_timestamp, std::string parentfn)
|
||||
{
|
||||
memset(&dynamicheader, 0, sizeof(VHDDynamicHeader) );
|
||||
|
||||
@ -376,7 +376,7 @@ bool VHDFile::write_dynamicheader(char *parent_uid, unsigned int parent_timestam
|
||||
memcpy(dynamicheader.parent_uid, parent_uid, 16);
|
||||
dynamicheader.parent_timestamp=big_endian(parent_timestamp);
|
||||
std::string unicodename=big_endian_utf16(Server->ConvertToUTF16(ExtractFileName(parentfn)));
|
||||
std::string rel_unicodename=Server->ConvertToUTF16(L".\\"+ExtractFileName(parentfn));
|
||||
std::string rel_unicodename=Server->ConvertToUTF16(".\\"+ExtractFileName(parentfn));
|
||||
std::string abs_unicodename=Server->ConvertToUTF16(parentfn);
|
||||
unicodename.resize(unicodename.size()+2);
|
||||
unicodename[unicodename.size()-2]=0;
|
||||
@ -557,15 +557,16 @@ bool VHDFile::read_dynamicheader(void)
|
||||
parent_unicodename.resize(512);
|
||||
memcpy(&parent_unicodename[0], dynamicheader.parent_unicodename, 512);
|
||||
parent_unicodename=big_endian_utf16(parent_unicodename);
|
||||
std::wstring parent_fn=Server->ConvertFromUTF16(parent_unicodename);
|
||||
std::wstring parent_fn=Server->ConvertToWchar(Server->ConvertFromUTF16(parent_unicodename));
|
||||
parent_fn.resize(wcslen(parent_fn.c_str()));
|
||||
parent_fn=ExtractFilePath(file->getFilenameW())+L"/"+parent_fn;
|
||||
Server->Log(L"VHD-Parent: \""+parent_fn+L"\"", LL_INFO);
|
||||
parent=new VHDFile(parent_fn, true, 0);
|
||||
parent_fn=Server->ConvertToWchar(ExtractFilePath(file->getFilename()))+L"/"+parent_fn;
|
||||
std::string utf8_parent_fn = Server->ConvertFromWchar(parent_fn);
|
||||
Server->Log("VHD-Parent: \""+utf8_parent_fn+"\"", LL_INFO);
|
||||
parent=new VHDFile(utf8_parent_fn, true, 0);
|
||||
|
||||
if(parent->isOpen()==false)
|
||||
{
|
||||
Server->Log(L"Error opening Parentvhdfile \""+parent_fn+L"\"", LL_ERROR);
|
||||
Server->Log("Error opening Parentvhdfile \""+utf8_parent_fn+"\"", LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -710,7 +711,7 @@ bool VHDFile::Read(char* buffer, size_t bsize, size_t &read)
|
||||
|
||||
if(dataoffset+bitmap_size+blockoffset+bsize>(uint64)file->Size() )
|
||||
{
|
||||
Server->Log("Wrong dataoffset: "+nconvert(dataoffset), LL_ERROR);
|
||||
Server->Log("Wrong dataoffset: "+convert(dataoffset), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -808,7 +809,7 @@ _u32 VHDFile::Write(const char *buffer, _u32 bsize, bool *has_error)
|
||||
}
|
||||
if(bsize+curr_offset>dstsize)
|
||||
{
|
||||
Server->Log("VHD file is not large enough. Want to write till "+nconvert(bsize+curr_offset)+" but size is "+nconvert(dstsize), LL_ERROR);
|
||||
Server->Log("VHD file is not large enough. Want to write till "+convert(bsize+curr_offset)+" but size is "+convert(dstsize), LL_ERROR);
|
||||
if(has_error) *has_error=true;
|
||||
return 0;
|
||||
}
|
||||
@ -988,7 +989,7 @@ bool VHDFile::has_block(bool use_parent)
|
||||
|
||||
if(dataoffset+bitmap_size+blockoffset>(uint64)file->Size() )
|
||||
{
|
||||
Server->Log("Wrong dataoffset: "+nconvert(dataoffset), LL_ERROR);
|
||||
Server->Log("Wrong dataoffset: "+convert(dataoffset), LL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1124,11 +1125,6 @@ std::string VHDFile::getFilename(void)
|
||||
return file->getFilename();
|
||||
}
|
||||
|
||||
std::wstring VHDFile::getFilenameW(void)
|
||||
{
|
||||
return file->getFilenameW();
|
||||
}
|
||||
|
||||
std::string VHDFile::Read(_u32 tr, bool *has_error)
|
||||
{
|
||||
std::string ret;
|
||||
@ -1184,9 +1180,9 @@ void VHDFile::addVolumeOffset(_i64 offset)
|
||||
void VHDFile::print_last_error()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Server->Log("Last error: "+nconvert((int)GetLastError()), LL_ERROR);
|
||||
Server->Log("Last error: "+convert((int)GetLastError()), LL_ERROR);
|
||||
#else
|
||||
Server->Log("Last error: "+nconvert(errno), LL_ERROR);
|
||||
Server->Log("Last error: "+convert(errno), LL_ERROR);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1276,13 +1272,13 @@ bool VHDFile::makeFull( _i64 fs_offset, IVHDWriteCallback* write_callback)
|
||||
bool has_error = false;
|
||||
if(Read(buffer.data(), sector_size)!=sector_size)
|
||||
{
|
||||
Server->Log("Error converting incremental to full image. Cannot read from parent VHD file at position "+nconvert(block_pos + i), LL_WARNING);
|
||||
Server->Log("Error converting incremental to full image. Cannot read from parent VHD file at position "+convert(block_pos + i), LL_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!write_callback->writeVHD(block_pos + i, buffer.data(), sector_size))
|
||||
{
|
||||
Server->Log("Error converting incremental to full image. Cannot write to VHD file at position "+nconvert(block_pos + i), LL_WARNING);
|
||||
Server->Log("Error converting incremental to full image. Cannot write to VHD file at position "+convert(block_pos + i), LL_WARNING);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1296,7 +1292,7 @@ bool VHDFile::makeFull( _i64 fs_offset, IVHDWriteCallback* write_callback)
|
||||
Server->Log("Writing new headers...", LL_INFO);
|
||||
|
||||
if(!write_header(false) ||
|
||||
!write_dynamicheader(NULL, 0, L"") ||
|
||||
!write_dynamicheader(NULL, 0, "") ||
|
||||
!write_footer() )
|
||||
{
|
||||
Server->Log("Error writing new headers", LL_WARNING);
|
||||
|
||||
@ -64,8 +64,8 @@ class CompressedFile;
|
||||
class VHDFile : public IVHDFile, public IFile
|
||||
{
|
||||
public:
|
||||
VHDFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize, unsigned int pBlocksize=2*1024*1024, bool fast_mode=false, bool compress=false);
|
||||
VHDFile(const std::wstring &fn, const std::wstring &parent_fn, bool pRead_only, bool fast_mode=false, bool compress=false);
|
||||
VHDFile(const std::string &fn, bool pRead_only, uint64 pDstsize, unsigned int pBlocksize=2*1024*1024, bool fast_mode=false, bool compress=false);
|
||||
VHDFile(const std::string &fn, const std::string &parent_fn, bool pRead_only, bool fast_mode=false, bool compress=false);
|
||||
~VHDFile();
|
||||
|
||||
virtual std::string Read(_u32 tr, bool *has_error=NULL);
|
||||
@ -85,7 +85,6 @@ public:
|
||||
char *getUID(void);
|
||||
unsigned int getTimestamp(void);
|
||||
std::string getFilename(void);
|
||||
std::wstring getFilenameW(void);
|
||||
|
||||
bool has_sector(_i64 sector_size=-1);
|
||||
bool this_has_sector(_i64 sector_size=-1);
|
||||
@ -121,7 +120,7 @@ private:
|
||||
bool check_if_compressed();
|
||||
|
||||
bool write_header(bool diff);
|
||||
bool write_dynamicheader(char *parent_uid, unsigned int parent_timestamp, std::wstring parentfn);
|
||||
bool write_dynamicheader(char *parent_uid, unsigned int parent_timestamp, std::string parentfn);
|
||||
bool write_bat(void);
|
||||
bool write_footer(void);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user