Re: [OpenSIPStack] RegistrationDatabase and user rights in Windows
Brought to you by:
joegenbaclor
From: H.Kropf <mai...@gl...> - 2007-12-05 14:16:22
|
My "OSSApplication::CreateUserFolder()" implementation Sorry, NOT TESTED //============================================================= // OSSApplication.h //============================================================= class OSSApplication : public OSSApplicationAncestor { ... public: static const OString GetUserHomeDir(); static const OString CreateUserFolder(const char* dir_name); ... }; //============================================================= // OSSApplication.cxx //============================================================= #ifdef _WIN32_WCE #include <shlobj.h> #include <direct.h> #else #include <stdlib.h> #endif const OString OSSApplication::GetUserHomeDir() { #ifdef _WIN32_WCE // === Win32 ========================== char dir[MAX_PATH]; SecureZeroMemory(dir, sizeof(dir)); //Minimal OS: Win2k, WinNT 4.0 + IE 4.0, Win98, Win95 + IE 4.0 // require import lib "shell32.lib" //if( SHGetSpecialFolderPathA(NULL, (LPSTR)dir, CSIDL_APPDATA, TRUE) ) //Minimal OS: //Win95+IE 5.0, Win98+IE 5.0, Win98SE, WinNT 4.0+IE 5.0, WinNT 4.0 SP4 if( SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, (LPSTR)dir)) ) return OString( (LPCSTR)dir ); else return OString(); #else // === POSIX ========================== char* dir = NULL; dir = getenv("HOME"); if(dir) return OString( (const char*)dir ); else return OString(); #endif } //------------------------------------------------------------------ const OString OSSApplication::CreateUserFolder(const char* dir_name) { OString result_path = GetUserHomeDir(); if(result_path.IsEmpty) result_path = PProcess::Current().GetFile().GetDirectory(); #ifdef _WIN32_WCE // === Win32 ========================== if( result_path.Right(1) != "\\") result_path += "\\"; #else // === POSIX ========================== if( result_path.Right(1) != "/") result_path += "/"; #endif if(dir_name) { result_path += dir_name; result_path.Trim(); _mkdir(result_path); } // TO-DO : need check results of "_mkdir" command return result_path; } Joegen E. Baclor wrote: > Good suggestion. I think the best place to put this code is as a static > method in OSSApplication. Something like > OSSApplication::CreateUserFolder() with similar behavior in linux and > window. For linux, it would be create in the $(HOME) directory. For > windows, it would be Document and Settings. Aside from the registry > folder, we have the logs and CALEA folders that are also dynamically > created by OpenSBC. A central function would benefit these two as > well. Would you be able to patch OSSApplicaiton with this method and > behave the same way in linux and windows? I will be glad to add it as > your contribution. > > H.Kropf wrote: > >> I suggest to use the following code:for Win NT / 2k / XP >> >> //-------------------------------------------------------------------------- >> // uses c:\Documents and Settings\[User]\OSS\registry\ >> //-------------------------------------------------------------------------- >> char dir[MAX_PATH+1]; >> SecureZeroMemory(dir, sizeof(dir)); >> >> SHGetSpecialFolderPath(NULL, (LPSTR)dir, CSIDL_APPDATA, TRUE); >> >> PathAppend(dir, "OSS"); >> if( !PathFileExists( dir ) ) _mkdir((LPCSTR)dir); >> PathAppend(dir, "registry"); >> if( !PathFileExists( pb_path ) ) _mkdir(dir); >> //-------------------------------------------------------------------------- >> >> >> instead of >> >> //-------------------------------------------------------------------------- >> // uses c:\Program Files\[program name]\registry\ . Whether the user >> has the rights to create this folder here? >> //-------------------------------------------------------------------------- >> OString dir = PProcess::Current().GetFile().GetDirectory() + "registry"; >> if( !PFile::Exists( dir.c_str() ) ) >> PDirectory::Create( dir.c_str() ); >> //-------------------------------------------------------------------------- >> >> in >> >> //======== RegisterSessionManager.cxx ======== >> >> RegistrationDatabase::RegistrationDatabase() >> { >> #if HAS_CPPSQLITE >> m_HasContactRecovery = PrepareContactRecoveryDB( >> "ContactRecovery.sqlite" ); >> #else >> m_HasContactRecovery = TRUE; >> OString dir = PProcess::Current().GetFile().GetDirectory() + "registry"; >> if( !PFile::Exists( dir.c_str() ) ) >> PDirectory::Create( dir.c_str() ); >> m_RegRecoveryDIR = dir.c_str(); >> #endif >> } >> |