Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

455 lines
13 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name :
  4. ansimeta.cpp
  5. Abstract:
  6. WRAPPER functions for ANSI calls of UNICODE ADMCOM interface
  7. Environment:
  8. Win32 User Mode
  9. Author:
  10. jaroslad (jan 1997)
  11. --*/
  12. #include "ansimeta.h"
  13. #include <mbstring.h>
  14. WCHAR * ConvertToUnicode(unsigned char * pszString);
  15. WCHAR * ConvertToUnicode(CHAR * pszString)
  16. {
  17. return ConvertToUnicode((unsigned char *) pszString);
  18. }
  19. WCHAR * ConvertToUnicode(unsigned char * pszString)
  20. {
  21. if (pszString==NULL)
  22. return NULL;
  23. int Size_wszString = (_mbslen((const unsigned char *) pszString)+1)*sizeof(WCHAR);
  24. WCHAR * pwszString = new WCHAR[Size_wszString];
  25. if (pwszString== NULL)
  26. {
  27. return NULL;
  28. }
  29. MultiByteToWideChar(0, 0, (char *) pszString, -1, pwszString, Size_wszString);
  30. return pwszString;
  31. }
  32. CHAR * ConvertToMultiByte(WCHAR * pwszString)
  33. {
  34. if(pwszString==NULL)
  35. return NULL;
  36. int Size_szString = (wcslen(pwszString)*sizeof(WCHAR)+1);
  37. CHAR * pszString = new CHAR[Size_szString];
  38. if (pszString== NULL)
  39. {
  40. return NULL;
  41. }
  42. WideCharToMultiByte(0, 0, pwszString, -1, pszString,Size_szString, NULL,NULL );
  43. return pszString;
  44. }
  45. HRESULT ConvertMetadataToAnsi(PMETADATA_RECORD pmdrMDData)
  46. {
  47. HRESULT hRes=ERROR_SUCCESS;
  48. //convert data if STRING, EXPAND STRING or MULTISZ
  49. switch(pmdrMDData->dwMDDataType )
  50. {
  51. case STRING_METADATA:
  52. case EXPANDSZ_METADATA:
  53. {
  54. CHAR * pszData= ConvertToMultiByte((WCHAR *) pmdrMDData->pbMDData);
  55. if (pszData==0) {hRes=E_OUTOFMEMORY; goto Exit;}
  56. strcpy((char *)pmdrMDData->pbMDData,pszData);
  57. pmdrMDData->dwMDDataLen=strlen((char *)pmdrMDData->pbMDData)+1;
  58. delete [] pszData;
  59. break;
  60. }
  61. case MULTISZ_METADATA:
  62. {
  63. WCHAR *pwszMultiString = (WCHAR *) pmdrMDData->pbMDData;
  64. DWORD dwAnsiDataLen=0;
  65. do
  66. {
  67. CHAR * pszData= ConvertToMultiByte(pwszMultiString);
  68. if (pszData==0) {hRes=E_OUTOFMEMORY; goto Exit;}
  69. strcpy((char *)(pmdrMDData->pbMDData)+dwAnsiDataLen,pszData);
  70. dwAnsiDataLen+=strlen(pszData)+1;
  71. pwszMultiString+=_mbslen((const unsigned char *)pszData)+1; //move pointer to the next string in MULTISZ
  72. delete [] pszData;
  73. }while((void *) pwszMultiString < (void *) (pmdrMDData->pbMDData+pmdrMDData->dwMDDataLen));
  74. pmdrMDData->dwMDDataLen=dwAnsiDataLen;
  75. break;
  76. }
  77. }
  78. Exit:
  79. return hRes;
  80. }
  81. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::AddKey(
  82. /* [in] */ METADATA_HANDLE hMDHandle,
  83. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath)
  84. {
  85. HRESULT hRes=0;
  86. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  87. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  88. //call real interface function
  89. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  90. hRes= this->m_pcAdmCom->AddKey(hMDHandle, pwszMDPath);
  91. Exit:
  92. //release memory
  93. if( pwszMDPath!=0) delete [] pwszMDPath;
  94. return hRes;
  95. }
  96. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::DeleteKey(
  97. /* [in] */ METADATA_HANDLE hMDHandle,
  98. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath)
  99. {
  100. HRESULT hRes=0;
  101. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  102. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  103. //call real interface function
  104. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  105. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  106. hRes= this->m_pcAdmCom->DeleteKey(hMDHandle, pwszMDPath);
  107. Exit:
  108. //release memory
  109. if( pwszMDPath!=0) delete [] pwszMDPath;
  110. return hRes;
  111. }
  112. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::EnumKeys(
  113. /* [in] */ METADATA_HANDLE hMDHandle,
  114. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  115. /* [size_is][out] */ unsigned char __RPC_FAR *pszMDName,
  116. /* [in] */ DWORD dwMDEnumObjectIndex)
  117. {
  118. HRESULT hRes=0;
  119. CHAR * pszMDName1=0;
  120. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  121. WCHAR pwszMDName[METADATA_MAX_NAME_LEN];
  122. if ((pwszMDPath==0) || (pwszMDName==0)) { hRes=E_OUTOFMEMORY; goto Exit;}
  123. //call real interface function
  124. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  125. hRes= this->m_pcAdmCom->EnumKeys(hMDHandle, pwszMDPath,pwszMDName,dwMDEnumObjectIndex);
  126. //convert pszMDName to ANSI
  127. pszMDName1=ConvertToMultiByte(pwszMDName);
  128. strcpy((char *)pszMDName,pszMDName1);
  129. Exit:
  130. //release memory
  131. if( pwszMDPath!=0) delete [] pwszMDPath;
  132. if( pszMDName1!=0) delete [] pszMDName1;
  133. return hRes;
  134. }
  135. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::CopyKey(
  136. /* [in] */ METADATA_HANDLE hMDSourceHandle,
  137. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDSourcePath,
  138. /* [in] */ METADATA_HANDLE hMDDestHandle,
  139. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDDestPath,
  140. /* [in] */ BOOL bMDOverwriteFlag,
  141. /* [in] */ BOOL bMDCopyFlag)
  142. {
  143. HRESULT hRes=0;
  144. WCHAR * pwszMDSourcePath=ConvertToUnicode(pszMDSourcePath);
  145. WCHAR * pwszMDDestPath=ConvertToUnicode(pszMDDestPath);
  146. if ((pwszMDSourcePath==0) || (pwszMDDestPath==0) ){ hRes=E_OUTOFMEMORY; goto Exit;}
  147. //call real interface function
  148. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  149. hRes= this->m_pcAdmCom->CopyKey(hMDSourceHandle, pwszMDSourcePath,
  150. hMDDestHandle, pwszMDDestPath, bMDOverwriteFlag, bMDCopyFlag);
  151. Exit:
  152. //release memory
  153. if( pwszMDSourcePath!=0) delete [] pwszMDSourcePath;
  154. if( pwszMDDestPath!=0) delete [] pwszMDDestPath;
  155. return hRes;
  156. }
  157. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::RenameKey(
  158. /* [in] */ METADATA_HANDLE hMDHandle,
  159. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  160. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDNewName)
  161. {
  162. HRESULT hRes=0;
  163. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  164. WCHAR * pwszMDNewName=ConvertToUnicode(pszMDNewName);
  165. if ((pwszMDPath==0) || (pwszMDNewName==0)) { hRes=E_OUTOFMEMORY; goto Exit;}
  166. //call real interface function
  167. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  168. hRes= this->m_pcAdmCom->RenameKey(hMDHandle, pwszMDPath,pwszMDNewName);
  169. Exit:
  170. //release memory
  171. if( pwszMDPath!=0) delete [] pwszMDPath;
  172. if( pwszMDNewName!=0) delete [] pwszMDNewName;
  173. return hRes;
  174. }
  175. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::SetData(
  176. /* [in] */ METADATA_HANDLE hMDHandle,
  177. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  178. /* [in] */ PMETADATA_RECORD pmdrMDData)
  179. {
  180. HRESULT hRes=0;
  181. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  182. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  183. //call real interface function
  184. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  185. //convert data if STRING, EXPAND STRING or MULTISZ
  186. switch(pmdrMDData->dwMDDataType )
  187. {
  188. case STRING_METADATA:
  189. case EXPANDSZ_METADATA:
  190. {
  191. WCHAR * pwszData= ConvertToUnicode((CHAR *) pmdrMDData->pbMDData);
  192. if (pwszData==0) {hRes=E_OUTOFMEMORY; goto Exit;}
  193. PBYTE pbMDStoreData=pmdrMDData->pbMDData;
  194. DWORD dwMDStoreDataLen=pmdrMDData->dwMDDataLen;
  195. pmdrMDData->pbMDData= (PBYTE) pwszData;
  196. pmdrMDData->dwMDDataLen=(wcslen((WCHAR *)pmdrMDData->pbMDData)+1)*sizeof(WCHAR);
  197. hRes= this->m_pcAdmCom->SetData(hMDHandle, pwszMDPath,pmdrMDData);
  198. pmdrMDData->dwMDDataLen = dwMDStoreDataLen;
  199. pmdrMDData->pbMDData = pbMDStoreData;
  200. delete [] pwszData;
  201. break;
  202. }
  203. case MULTISZ_METADATA:
  204. {
  205. CHAR *pszMultiString = (CHAR *) pmdrMDData->pbMDData;
  206. WCHAR *pwszMDData=new WCHAR[(pmdrMDData->dwMDDataLen)];
  207. if (pwszMDData==0) {hRes=E_OUTOFMEMORY; goto Exit;}
  208. DWORD dwUniDataLen=0;
  209. do
  210. {
  211. WCHAR * pwszData= ConvertToUnicode(pszMultiString);
  212. if (pwszData==0) {hRes=E_OUTOFMEMORY; goto Exit;}
  213. wcscpy(pwszMDData+dwUniDataLen,pwszData);
  214. dwUniDataLen+=wcslen(pwszData)+1;
  215. delete [] pwszData;
  216. while(*(pszMultiString++)!=0); //move pointer to the next string in MULTISZ
  217. }while(*pszMultiString!=0);
  218. pwszMDData[dwUniDataLen++]=0;
  219. //store original values
  220. PBYTE pbMDStoreData=pmdrMDData->pbMDData;
  221. DWORD dwMDStoreDataLen=pmdrMDData->dwMDDataLen;
  222. pmdrMDData->dwMDDataLen=dwUniDataLen*sizeof(WCHAR);
  223. pmdrMDData->pbMDData= (PBYTE) pwszMDData;
  224. hRes= this->m_pcAdmCom->SetData(hMDHandle, pwszMDPath,pmdrMDData);
  225. delete [] pwszMDData;
  226. //restore original values
  227. pmdrMDData->dwMDDataLen = dwMDStoreDataLen;
  228. pmdrMDData->pbMDData = pbMDStoreData;
  229. break;
  230. }
  231. default:
  232. {
  233. hRes= this->m_pcAdmCom->SetData(hMDHandle, pwszMDPath,pmdrMDData);
  234. }
  235. } //end of switch
  236. Exit:
  237. //release memory
  238. if( pwszMDPath!=0) delete [] pwszMDPath;
  239. return hRes;
  240. }
  241. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::GetData(
  242. /* [in] */ METADATA_HANDLE hMDHandle,
  243. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  244. /* [out][in] */ PMETADATA_RECORD pmdrMDData,
  245. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredDataLen)
  246. {
  247. HRESULT hRes=0;
  248. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  249. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  250. //call real interface function
  251. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  252. hRes= this->m_pcAdmCom->GetData(hMDHandle, pwszMDPath,pmdrMDData,pdwMDRequiredDataLen);
  253. if(SUCCEEDED(hRes))
  254. {
  255. ConvertMetadataToAnsi(pmdrMDData);
  256. }
  257. Exit:
  258. //release memory
  259. if( pwszMDPath!=0) delete [] pwszMDPath;
  260. return hRes;
  261. }
  262. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::DeleteData(
  263. /* [in] */ METADATA_HANDLE hMDHandle,
  264. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  265. /* [in] */ DWORD dwMDIdentifier,
  266. /* [in] */ DWORD dwMDDataType)
  267. {
  268. HRESULT hRes=0;
  269. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  270. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  271. //call real interface function
  272. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  273. hRes= this->m_pcAdmCom->DeleteData(hMDHandle, pwszMDPath,dwMDIdentifier,dwMDDataType);
  274. Exit:
  275. //release memory
  276. if( pwszMDPath!=0) delete [] pwszMDPath;
  277. return hRes;
  278. }
  279. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::EnumData(
  280. /* [in] */ METADATA_HANDLE hMDHandle,
  281. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  282. /* [out][in] */ PMETADATA_RECORD pmdrMDData,
  283. /* [in] */ DWORD dwMDEnumDataIndex,
  284. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredDataLen)
  285. {
  286. HRESULT hRes=0;
  287. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  288. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  289. //call real interface function
  290. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  291. hRes= this->m_pcAdmCom->EnumData(hMDHandle, pwszMDPath,pmdrMDData,dwMDEnumDataIndex,pdwMDRequiredDataLen);
  292. if(SUCCEEDED(hRes))
  293. {
  294. ConvertMetadataToAnsi(pmdrMDData);
  295. }
  296. Exit:
  297. //release memory
  298. if( pwszMDPath!=0) delete [] pwszMDPath;
  299. return hRes;
  300. }
  301. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::CopyData(
  302. /* [in] */ METADATA_HANDLE hMDSourceHandle,
  303. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDSourcePath,
  304. /* [in] */ METADATA_HANDLE hMDDestHandle,
  305. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDDestPath,
  306. /* [in] */ DWORD dwMDAttributes,
  307. /* [in] */ DWORD dwMDUserType,
  308. /* [in] */ DWORD dwMDDataType,
  309. /* [in] */ BOOL bMDCopyFlag)
  310. {
  311. HRESULT hRes=0;
  312. WCHAR * pwszMDSourcePath=ConvertToUnicode(pszMDSourcePath);
  313. WCHAR * pwszMDDestPath=ConvertToUnicode(pszMDDestPath);
  314. if ((pwszMDSourcePath==0) || (pwszMDDestPath==0) ) { hRes=E_OUTOFMEMORY; goto Exit;}
  315. //call real interface function
  316. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  317. hRes= this->m_pcAdmCom->CopyData(hMDSourceHandle, pwszMDSourcePath,
  318. hMDDestHandle, pwszMDDestPath, dwMDAttributes,
  319. dwMDUserType,dwMDDataType,bMDCopyFlag);
  320. Exit:
  321. //release memory
  322. if( pwszMDSourcePath!=0) delete [] pwszMDSourcePath;
  323. if( pwszMDDestPath!=0) delete [] pwszMDDestPath;
  324. return hRes;
  325. }
  326. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::OpenKey(
  327. /* [in] */ METADATA_HANDLE hMDHandle,
  328. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  329. /* [in] */ DWORD dwMDAccessRequested,
  330. /* [in] */ DWORD dwMDTimeOut,
  331. /* [out] */ PMETADATA_HANDLE phMDNewHandle)
  332. {
  333. HRESULT hRes=0;
  334. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  335. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  336. //call real interface function
  337. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  338. hRes= this->m_pcAdmCom->OpenKey(hMDHandle, pwszMDPath, dwMDAccessRequested, dwMDTimeOut, phMDNewHandle);
  339. Exit:
  340. //release memory
  341. if( pwszMDPath!=0) delete [] pwszMDPath;
  342. return hRes;
  343. }
  344. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::CloseKey(
  345. /* [in] */ METADATA_HANDLE hMDHandle)
  346. {
  347. if(this->m_pcAdmCom==0) { return CO_E_NOTINITIALIZED;}
  348. return this->m_pcAdmCom->CloseKey(hMDHandle);
  349. }
  350. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::SaveData( void)
  351. {
  352. if(this->m_pcAdmCom==0) {return CO_E_NOTINITIALIZED;}
  353. return this->m_pcAdmCom->SaveData();
  354. }