• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ut_Win32Uuid.h

Go to the documentation of this file.
00001 /* AbiSource Program Utilities
00002  * Copyright (C) 2003-2004 Tomas Frydrych <tomasfrydrych@yahoo.co.uk>
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 #ifndef UT_WIN_32_UUID_H
00021 #define UT_WIN_32_UUID_H
00022 
00023 #include "ut_uuid.h"
00024 #include <windows.h>
00025 #include <wincrypt.h>
00026 
00027 #if defined(__WINCRYPT_H__) && !defined(WINCRYPT32API)
00028 // hack to fix problem in wincrypt.h;  according to the docs the RSA
00029 // cryptographic provider is included from win95OS2 but the include
00030 // file assumes NT >= 4
00031 //
00032 // (I do not want to just test for _WIN32_WINNT < 0x0400, in case this
00033 // problem was fixed in later versions of MSVC)
00034 //
00035 // we need to provide our own definitions here ...
00036 extern "C" {
00037 typedef unsigned long HCRYPTPROV;
00038 
00039 WINADVAPI BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags);
00040 WINADVAPI BOOL WINAPI CryptGenRandom(HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer);
00041 WINADVAPI BOOL WINAPI CryptAcquireContextA(HCRYPTPROV *phProv, LPCSTR pszContainer,
00042                                            LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags);
00043 WINADVAPI BOOL WINAPI CryptAcquireContextW(HCRYPTPROV *phProv, LPCWSTR pszContainer,
00044                                            LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags);
00045 
00046 #define CRYPT_VERIFYCONTEXT     0xF0000000
00047 #define PROV_RSA_FULL           1
00048 
00049 #define CryptAcquireContext  CryptAcquireContextW
00050 } // extern "C"
00051 #endif // #if defined(__WINCRYPT_H__) && !defined(WINCRYPT32API)
00052 
00057 class ABI_EXPORT UT_Win32UUID : public UT_UUID
00058 {
00059   public:
00060     /*
00061        all constructors are protected; instances of UT_UUID will be
00062        created through UT_UUIDGenerator declared below
00063     */
00064 
00065     /* virtual destructor*/
00066     virtual ~UT_Win32UUID ();
00067 
00068   protected:
00069     friend class UT_Win32UUIDGenerator;
00070     /* various protected constructors */
00071     // the first constr. constructs NULL uuid; subsequent call to makeUUID() needed
00072     UT_Win32UUID():UT_UUID(){s_iInstCount++;}
00073 
00074     UT_Win32UUID(const std::string &s):UT_UUID(s){s_iInstCount++;}
00075     UT_Win32UUID(const char *s):UT_UUID(s){s_iInstCount++;}
00076     UT_Win32UUID(const UT_UUID &u):UT_UUID(u){s_iInstCount++;}
00077     UT_Win32UUID(const UT_Win32UUID &u):UT_UUID((UT_UUID&)u){s_iInstCount++;}
00078     UT_Win32UUID(const struct uuid &u):UT_UUID(u){s_iInstCount++;}
00079 
00080     virtual bool    _getRandomBytes(void *buf, int nbytes);
00081 
00082   private:
00083     // had difficulties with including wincrypt.h, so defined this as
00084     // unsigned long
00085     static HCRYPTPROV s_hProv;
00086     static UT_sint32  s_iInstCount;
00087 };
00088 
00089 /*
00090     This class mediates creation of UT_UUID class.
00091 
00092     We create an instance of UT_UUIDGeneratr (or derived) class in
00093     XAP_App() and have XAP_App::getUUIDGenerator() to gain access to
00094     it.  This allows us to create platform specific instances of
00095     UT_UUID from xp code.
00096 */
00097 class ABI_EXPORT UT_Win32UUIDGenerator : public UT_UUIDGenerator
00098 {
00099   public:
00100     UT_Win32UUIDGenerator():UT_UUIDGenerator(){};
00101     virtual ~UT_Win32UUIDGenerator(){};
00102 
00103     // because the default constructor creates NULL uuid, we also need
00104     // to call makeUUID() with this one
00105     virtual UT_UUID * createUUID(){UT_UUID *p=new UT_Win32UUID(); if(p)p->makeUUID(); return p;}
00106 
00107     virtual UT_UUID * createUUID(const std::string &s){return new UT_Win32UUID(s);}
00108     virtual UT_UUID * createUUID(const char *s){return new UT_Win32UUID(s);}
00109     virtual UT_UUID * createUUID(const UT_UUID &u){return new UT_Win32UUID(u);}
00110     virtual UT_UUID * createUUID(const struct uuid &u){return new UT_Win32UUID(u);}
00111 };
00112 
00113 #endif /* UT_WIN32_UUID_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1