Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

unipstoregen.cc

Go to the documentation of this file.
00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2003 Net Integration Technologies, Inc. 00004 * 00005 * A generator that exposes Windows protected storage. 00006 */ 00007 #include "unipstoregen.h" 00008 #include "wvmoniker.h" 00009 #include <string> 00010 00011 static const int MAX = 1024; 00012 00013 using namespace PSTORECLib; 00014 00015 typedef HRESULT (WINAPI *PStoreCreateInstancePtr)(IPStore **, DWORD, DWORD, DWORD); 00016 00017 HRESULT UniPStoreGen::create_types(WvString type_name, WvString subtype_name) 00018 { 00019 HRESULT hRes; 00020 00021 _PST_TYPEINFO myTypeInfo; 00022 myTypeInfo.cbSize = strlen(type_name.cstr()) + 1; 00023 myTypeInfo.szDisplayName = new wchar_t[myTypeInfo.cbSize]; 00024 mbstowcs(myTypeInfo.szDisplayName, type_name.cstr(), myTypeInfo.cbSize); 00025 00026 _PST_TYPEINFO mySubTypeInfo; 00027 mySubTypeInfo.cbSize = strlen(subtype_name.cstr()) + 1; 00028 mySubTypeInfo.szDisplayName = new wchar_t[mySubTypeInfo.cbSize]; 00029 mbstowcs(mySubTypeInfo.szDisplayName, subtype_name.cstr(), mySubTypeInfo.cbSize); 00030 00031 _PST_ACCESSRULESET myRuleSet; 00032 myRuleSet.cbSize = sizeof(myRuleSet); 00033 myRuleSet.cRules = 0; 00034 myRuleSet.rgRules = 0; 00035 00036 hRes = m_spPStore->CreateType( m_key, &m_type, &myTypeInfo, 0); 00037 00038 if ((hRes != PST_E_OK) && (hRes != PST_E_TYPE_EXISTS)) 00039 { 00040 m_log("CreateSubtype() returned: %s\n", hRes); 00041 goto done; 00042 } 00043 00044 hRes = m_spPStore->CreateSubtype( m_key, &m_type, &m_subtype, &mySubTypeInfo, &myRuleSet, 0); 00045 if ((hRes != PST_E_OK) && (hRes != PST_E_TYPE_EXISTS)) 00046 { 00047 m_log("CreateSubtype() returned: %s\n", hRes); 00048 goto done; 00049 } 00050 00051 done: 00052 delete[] myTypeInfo.szDisplayName; 00053 delete[] mySubTypeInfo.szDisplayName; 00054 return hRes; 00055 } 00056 00057 // moniker is 00058 // PST_KEY_CURRENT_USER:TYPENAME:TYPEGUID:SUBTYPE:SUBTYPEGUID 00059 UniPStoreGen::UniPStoreGen(WvString _moniker) : 00060 m_log(_moniker), m_key(-1) 00061 { 00062 // load the library and get an entry point function pointer 00063 m_hPstoreDLL = LoadLibrary("pstorec.dll"); 00064 assert(m_hPstoreDLL); 00065 00066 PStoreCreateInstancePtr pPStoreCreateInstance = 00067 (PStoreCreateInstancePtr) GetProcAddress(m_hPstoreDLL, "PStoreCreateInstance"); 00068 assert(pPStoreCreateInstance); 00069 00070 HRESULT hr = pPStoreCreateInstance(&m_spPStore, 0, 0, 0); 00071 assert(SUCCEEDED(hr)); 00072 00073 // parse the moniker 00074 char *moniker = _moniker.edit(); 00075 const char *seps = ":"; 00076 WvString _key = strtok(moniker, seps); 00077 WvString type_name = strtok(NULL, seps); 00078 WvString _type_guid = strtok(NULL, seps); 00079 WvString subtype_name = strtok(NULL, seps); 00080 WvString _subtype_guid = strtok(NULL, seps); 00081 00082 if (!!_key && strcmp(_key, "PST_KEY_CURRENT_USER") == 0) 00083 { 00084 m_key = PST_KEY_CURRENT_USER; 00085 } 00086 else if (!!_key && strcmp(_key, "PST_KEY_LOCAL_MACHINE") == 0) 00087 { 00088 m_key = PST_KEY_LOCAL_MACHINE; 00089 } 00090 00091 if ((m_key >= 0) && !!type_name && !!_type_guid && !!subtype_name && !!_subtype_guid) 00092 { 00093 HRESULT hr; 00094 hr = UuidFromString((unsigned char*)_type_guid.edit(), &m_type); 00095 hr = UuidFromString((unsigned char*)_subtype_guid.edit(), &m_subtype); 00096 int result = create_types(type_name, subtype_name); 00097 assert(SUCCEEDED( result ) || (result == PST_E_TYPE_EXISTS)); 00098 } 00099 } 00100 00101 UniPStoreGen::~UniPStoreGen() 00102 { 00103 if (m_hPstoreDLL) 00104 { 00105 FreeLibrary(m_hPstoreDLL); 00106 m_hPstoreDLL = 0; 00107 } 00108 } 00109 00110 bool UniPStoreGen::isok() 00111 { 00112 return m_key >= 0; 00113 } 00114 00115 00116 WvString UniPStoreGen::get(const UniConfKey &key) 00117 { 00118 HRESULT hRes; 00119 WvString value = WvString::null; 00120 00121 unsigned char *data; 00122 unsigned long cbdata; 00123 00124 WvString _name = key.last().printable(); 00125 WCHAR name[MAX]; 00126 mbstowcs(name, _name.cstr(), MAX); 00127 00128 hRes = m_spPStore->ReadItem( 00129 m_key, 00130 &m_type, 00131 &m_subtype, 00132 name, 00133 &cbdata, 00134 &data, 00135 NULL, 00136 0 00137 ); 00138 00139 if (hRes == PST_E_OK) 00140 { 00141 value = (char*) data; 00142 CoTaskMemFree(data); 00143 } 00144 00145 return value; 00146 } 00147 00148 void UniPStoreGen::set(const UniConfKey &key, WvStringParm value) 00149 { 00150 HRESULT hRes; 00151 unsigned char *data = (unsigned char *) value.cstr(); 00152 00153 WvString _name = key.last().printable(); 00154 WCHAR name[MAX]; 00155 mbstowcs(name, _name.cstr(), MAX); 00156 00157 DWORD cbdata = DWORD((strlen(value.cstr()) + 1) * sizeof(char)); 00158 00159 hRes = m_spPStore->WriteItem( 00160 m_key, 00161 &m_type, 00162 &m_subtype, 00163 name, 00164 cbdata, 00165 data, 00166 NULL, 00167 PST_CF_NONE, 00168 0 00169 ); 00170 00171 if (hRes == PST_E_OK) 00172 { 00173 delta(key, value); 00174 } 00175 } 00176 00177 bool UniPStoreGen::exists(const UniConfKey &key) 00178 { 00179 return false; 00180 } 00181 00182 bool UniPStoreGen::haschildren(const UniConfKey &key) 00183 { 00184 return false; 00185 } 00186 00187 UniConfGen::Iter *UniPStoreGen::iterator(const UniConfKey &key) 00188 { 00189 return new NullIter(); 00190 } 00191 00192 static UniConfGen *creator(WvStringParm s, IObject *, void *) 00193 { 00194 return new UniPStoreGen(s); 00195 } 00196 00197 #pragma warning(disable : 4073) 00198 #pragma init_seg(lib) 00199 WvMoniker<UniConfGen> UniPStoreGenMoniker("pstore", creator);

Generated on Tue Oct 5 01:09:19 2004 for WvStreams by doxygen 1.3.7