From 00f4a0e0a5b25624a9662f5178022d6dc621e33d Mon Sep 17 00:00:00 2001 From: Thorsten Engel Date: Fri, 28 Apr 2006 09:58:03 +0000 Subject: [PATCH] - remove stl from vss (vector replaced by alist, wstring replaced by wchar) - take christophers code for waitforasync git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2981 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/win32/compat/vss.cpp | 108 +++++++++++++------------------- bacula/src/win32/compat/vss.h | 20 +++--- 2 files changed, 55 insertions(+), 73 deletions(-) diff --git a/bacula/src/win32/compat/vss.cpp b/bacula/src/win32/compat/vss.cpp index fc7a4fa8f8..ca5c716ef9 100644 --- a/bacula/src/win32/compat/vss.cpp +++ b/bacula/src/win32/compat/vss.cpp @@ -22,53 +22,12 @@ #ifdef WIN32_VSS -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -// STL includes -#include -#include -#include -#include -using namespace std; - -#ifdef HAVE_MINGW - -//#include -#include "ms_atl.h" -#include +#include "compat.h" +#include "bacula.h" -#else - -#include +#include "ms_atl.h" #include -// Used for safe string manipulation -#include -#endif - #include "vss.h" @@ -85,8 +44,8 @@ VSSClient::VSSClient() m_bDuringRestore = false; m_bBackupIsInitialized = false; m_pVssObject = NULL; - m_pVectorWriterStates = new vector; - m_pVectorWriterInfo = new vector; + m_pAlistWriterState = New (alist(10, not_owned_by_alist)); + m_pAlistWriterInfoText = New (alist(10, owned_by_alist)); m_uidCurrentSnapshotSet = GUID_NULL; memset(m_wszUniqueVolumeName, 0, sizeof(m_wszUniqueVolumeName)); memset(m_szShadowCopyName, 0, sizeof(m_szShadowCopyName)); @@ -102,11 +61,9 @@ VSSClient::~VSSClient() m_pVssObject = NULL; } - if (m_pVectorWriterStates) - delete (m_pVectorWriterStates); - - if (m_pVectorWriterInfo) - delete (m_pVectorWriterInfo); + DestroyWriterInfo(); + delete (alist*) m_pAlistWriterState; + delete (alist*) m_pAlistWriterInfoText; // Call CoUninitialize if the CoInitialize was performed successfully if (m_bCoInitializeCalled) @@ -139,10 +96,12 @@ BOOL VSSClient::GetShadowPath(const char *szFilePath, char *szShadowPath, int nB if (bIsValidName) { int nDriveIndex = toupper(szFilePath[0])-'A'; if (m_szShadowCopyName[nDriveIndex][0] != 0) { - strncpy(szShadowPath, m_szShadowCopyName[nDriveIndex], nBuflen); - nBuflen -= (int)strlen(m_szShadowCopyName[nDriveIndex]); - strncat(szShadowPath, szFilePath+2, nBuflen); - return TRUE; + + if (WideCharToMultiByte(CP_UTF8,0,m_szShadowCopyName[nDriveIndex],-1,szShadowPath,nBuflen-1,NULL,NULL)) { + nBuflen -= (int)strlen(szShadowPath); + strncat(szShadowPath, szFilePath+2, nBuflen); + return TRUE; + } } } @@ -168,8 +127,8 @@ BOOL VSSClient::GetShadowPathW(const WCHAR *szFilePath, WCHAR *szShadowPath, int if (bIsValidName) { int nDriveIndex = towupper(szFilePath[0])-'A'; if (m_szShadowCopyName[nDriveIndex][0] != 0) { -// wcsncpy(szShadowPath, CA2W(m_szShadowCopyName[nDriveIndex]), nBuflen); - nBuflen -= (int)strlen(m_szShadowCopyName[nDriveIndex]); + wcsncpy(szShadowPath, m_szShadowCopyName[nDriveIndex], nBuflen); + nBuflen -= (int)wcslen(m_szShadowCopyName[nDriveIndex]); wcsncat(szShadowPath, szFilePath+2, nBuflen); return TRUE; } @@ -183,20 +142,41 @@ BOOL VSSClient::GetShadowPathW(const WCHAR *szFilePath, WCHAR *szShadowPath, int const size_t VSSClient::GetWriterCount() { - vector* pV = (vector*) m_pVectorWriterStates; + alist* pV = (alist*) m_pAlistWriterInfoText; return pV->size(); } -const char* VSSClient::GetWriterInfo(size_t nIndex) +const char* VSSClient::GetWriterInfo(int nIndex) { - vector* pV = (vector*) m_pVectorWriterInfo; - return pV->at(nIndex).c_str(); + alist* pV = (alist*) m_pAlistWriterInfoText; + return (char*) pV->get(nIndex); } -const int VSSClient::GetWriterState(size_t nIndex) +const int VSSClient::GetWriterState(int nIndex) { - vector* pV = (vector*) m_pVectorWriterStates; - return pV->at(nIndex); + alist* pV = (alist*) m_pAlistWriterState; + return (int) pV->get(nIndex); +} + +void VSSClient::AppendWriterInfo(int nState, const char* pszInfo) +{ + alist* pT = (alist*) m_pAlistWriterInfoText; + alist* pS = (alist*) m_pAlistWriterState; + + pT->push (bstrdup(pszInfo)); + pS->push ((void*) nState); +} + +void VSSClient::DestroyWriterInfo() +{ + alist* pT = (alist*) m_pAlistWriterInfoText; + alist* pS = (alist*) m_pAlistWriterState; + + while (!pT->empty()) + free (pT->pop()); + + while (!pS->empty()) + pS->pop(); } #endif diff --git a/bacula/src/win32/compat/vss.h b/bacula/src/win32/compat/vss.h index ec10bfd3e7..6eab807ebb 100644 --- a/bacula/src/win32/compat/vss.h +++ b/bacula/src/win32/compat/vss.h @@ -51,13 +51,15 @@ public: BOOL GetShadowPathW (const WCHAR* szFilePath, WCHAR* szShadowPath, int nBuflen); /* nBuflen in characters */ const size_t GetWriterCount(); - const char* GetWriterInfo(size_t nIndex); - const int GetWriterState(size_t nIndex); + const char* GetWriterInfo(int nIndex); + const int GetWriterState(int nIndex); + void DestroyWriterInfo(); + void AppendWriterInfo(int nState, const char* pszInfo); const BOOL IsInitialized() { return m_bBackupIsInitialized; }; private: virtual BOOL Initialize(DWORD dwContext, BOOL bDuringRestore = FALSE) = 0; - virtual void WaitAndCheckForAsyncOperation(IVssAsync* pAsync) = 0; + virtual BOOL WaitAndCheckForAsyncOperation(IVssAsync* pAsync) = 0; virtual void QuerySnapshotSet(GUID snapshotSetID) = 0; protected: @@ -75,10 +77,10 @@ protected: // drive A will be stored on position 0,Z on pos. 25 WCHAR m_wszUniqueVolumeName[26][MAX_PATH]; // approx. 7 KB - char /* in utf-8 */ m_szShadowCopyName[26][MAX_PATH*2]; // approx. 7 KB - - void* m_pVectorWriterStates; - void* m_pVectorWriterInfo; + WCHAR m_szShadowCopyName[26][MAX_PATH]; // approx. 7 KB + + void* m_pAlistWriterState; + void* m_pAlistWriterInfoText; }; class VSSClientXP:public VSSClient @@ -91,7 +93,7 @@ public: virtual const char* GetDriverName() { return "VSS WinXP"; }; private: virtual BOOL Initialize(DWORD dwContext, BOOL bDuringRestore); - virtual void WaitAndCheckForAsyncOperation(IVssAsync* pAsync); + virtual BOOL WaitAndCheckForAsyncOperation(IVssAsync* pAsync); virtual void QuerySnapshotSet(GUID snapshotSetID); BOOL CheckWriterStatus(); }; @@ -106,7 +108,7 @@ public: virtual const char* GetDriverName() { return "VSS Win 2003"; }; private: virtual BOOL Initialize(DWORD dwContext, BOOL bDuringRestore); - virtual void WaitAndCheckForAsyncOperation(IVssAsync* pAsync); + virtual BOOL WaitAndCheckForAsyncOperation(IVssAsync* pAsync); virtual void QuerySnapshotSet(GUID snapshotSetID); BOOL CheckWriterStatus(); }; -- 2.39.5