Leaked source code of windows server 2003
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.

462 lines
14 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 = (int)(_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 = (int)(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=(DWORD)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+=(DWORD)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 *pwszMDData = NULL;
  182. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  183. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  184. //call real interface function
  185. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  186. //convert data if STRING, EXPAND STRING or MULTISZ
  187. switch(pmdrMDData->dwMDDataType )
  188. {
  189. case STRING_METADATA:
  190. case EXPANDSZ_METADATA:
  191. {
  192. WCHAR * pwszData= ConvertToUnicode((CHAR *) pmdrMDData->pbMDData);
  193. if (pwszData==0) {hRes=E_OUTOFMEMORY; goto Exit;}
  194. PBYTE pbMDStoreData=pmdrMDData->pbMDData;
  195. DWORD dwMDStoreDataLen=pmdrMDData->dwMDDataLen;
  196. pmdrMDData->pbMDData= (PBYTE) pwszData;
  197. pmdrMDData->dwMDDataLen=(DWORD)(wcslen((WCHAR *)pmdrMDData->pbMDData)+1)*sizeof(WCHAR);
  198. hRes= this->m_pcAdmCom->SetData(hMDHandle, pwszMDPath,pmdrMDData);
  199. pmdrMDData->dwMDDataLen = dwMDStoreDataLen;
  200. pmdrMDData->pbMDData = pbMDStoreData;
  201. delete [] pwszData;
  202. break;
  203. }
  204. case MULTISZ_METADATA:
  205. {
  206. CHAR *pszMultiString = (CHAR *) pmdrMDData->pbMDData;
  207. pwszMDData=new WCHAR[(pmdrMDData->dwMDDataLen)];
  208. if (pwszMDData==0) {hRes=E_OUTOFMEMORY; goto Exit;}
  209. DWORD dwUniDataLen=0;
  210. do
  211. {
  212. WCHAR * pwszData= ConvertToUnicode(pszMultiString);
  213. if (pwszData==0) {hRes=E_OUTOFMEMORY; goto Exit;}
  214. wcscpy(pwszMDData+dwUniDataLen,pwszData);
  215. dwUniDataLen+=(DWORD)wcslen(pwszData)+1;
  216. delete [] pwszData;
  217. while(*(pszMultiString++)!=0); //move pointer to the next string in MULTISZ
  218. }while(*pszMultiString!=0);
  219. pwszMDData[dwUniDataLen++]=0;
  220. //store original values
  221. PBYTE pbMDStoreData=pmdrMDData->pbMDData;
  222. DWORD dwMDStoreDataLen=pmdrMDData->dwMDDataLen;
  223. pmdrMDData->dwMDDataLen=dwUniDataLen*sizeof(WCHAR);
  224. pmdrMDData->pbMDData= (PBYTE) pwszMDData;
  225. hRes= this->m_pcAdmCom->SetData(hMDHandle, pwszMDPath,pmdrMDData);
  226. delete [] pwszMDData;
  227. pwszMDData = NULL;
  228. //restore original values
  229. pmdrMDData->dwMDDataLen = dwMDStoreDataLen;
  230. pmdrMDData->pbMDData = pbMDStoreData;
  231. break;
  232. }
  233. default:
  234. {
  235. hRes= this->m_pcAdmCom->SetData(hMDHandle, pwszMDPath,pmdrMDData);
  236. }
  237. } //end of switch
  238. Exit:
  239. //release memory
  240. if( pwszMDPath!=0) delete [] pwszMDPath;
  241. if( pwszMDData ) delete [] pwszMDData;
  242. return hRes;
  243. }
  244. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::GetData(
  245. /* [in] */ METADATA_HANDLE hMDHandle,
  246. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  247. /* [out][in] */ PMETADATA_RECORD pmdrMDData,
  248. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredDataLen)
  249. {
  250. HRESULT hRes=0;
  251. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  252. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  253. //call real interface function
  254. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  255. hRes= this->m_pcAdmCom->GetData(hMDHandle, pwszMDPath,pmdrMDData,pdwMDRequiredDataLen);
  256. if(SUCCEEDED(hRes))
  257. {
  258. ConvertMetadataToAnsi(pmdrMDData);
  259. }
  260. Exit:
  261. //release memory
  262. if( pwszMDPath!=0) delete [] pwszMDPath;
  263. return hRes;
  264. }
  265. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::DeleteData(
  266. /* [in] */ METADATA_HANDLE hMDHandle,
  267. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  268. /* [in] */ DWORD dwMDIdentifier,
  269. /* [in] */ DWORD dwMDDataType)
  270. {
  271. HRESULT hRes=0;
  272. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  273. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  274. //call real interface function
  275. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  276. hRes= this->m_pcAdmCom->DeleteData(hMDHandle, pwszMDPath,dwMDIdentifier,dwMDDataType);
  277. Exit:
  278. //release memory
  279. if( pwszMDPath!=0) delete [] pwszMDPath;
  280. return hRes;
  281. }
  282. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::EnumData(
  283. /* [in] */ METADATA_HANDLE hMDHandle,
  284. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  285. /* [out][in] */ PMETADATA_RECORD pmdrMDData,
  286. /* [in] */ DWORD dwMDEnumDataIndex,
  287. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredDataLen)
  288. {
  289. HRESULT hRes=0;
  290. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  291. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  292. //call real interface function
  293. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  294. hRes= this->m_pcAdmCom->EnumData(hMDHandle, pwszMDPath,pmdrMDData,dwMDEnumDataIndex,pdwMDRequiredDataLen);
  295. if(SUCCEEDED(hRes))
  296. {
  297. ConvertMetadataToAnsi(pmdrMDData);
  298. }
  299. Exit:
  300. //release memory
  301. if( pwszMDPath!=0) delete [] pwszMDPath;
  302. return hRes;
  303. }
  304. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::CopyData(
  305. /* [in] */ METADATA_HANDLE hMDSourceHandle,
  306. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDSourcePath,
  307. /* [in] */ METADATA_HANDLE hMDDestHandle,
  308. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDDestPath,
  309. /* [in] */ DWORD dwMDAttributes,
  310. /* [in] */ DWORD dwMDUserType,
  311. /* [in] */ DWORD dwMDDataType,
  312. /* [in] */ BOOL bMDCopyFlag)
  313. {
  314. HRESULT hRes=0;
  315. WCHAR * pwszMDSourcePath=ConvertToUnicode(pszMDSourcePath);
  316. WCHAR * pwszMDDestPath=ConvertToUnicode(pszMDDestPath);
  317. if ((pwszMDSourcePath==0) || (pwszMDDestPath==0) ) { hRes=E_OUTOFMEMORY; goto Exit;}
  318. //call real interface function
  319. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  320. hRes= this->m_pcAdmCom->CopyData(hMDSourceHandle, pwszMDSourcePath,
  321. hMDDestHandle, pwszMDDestPath, dwMDAttributes,
  322. dwMDUserType,dwMDDataType,bMDCopyFlag);
  323. Exit:
  324. //release memory
  325. if( pwszMDSourcePath!=0) delete [] pwszMDSourcePath;
  326. if( pwszMDDestPath!=0) delete [] pwszMDDestPath;
  327. return hRes;
  328. }
  329. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::OpenKey(
  330. /* [in] */ METADATA_HANDLE hMDHandle,
  331. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  332. /* [in] */ DWORD dwMDAccessRequested,
  333. /* [in] */ DWORD dwMDTimeOut,
  334. /* [out] */ PMETADATA_HANDLE phMDNewHandle)
  335. {
  336. HRESULT hRes=0;
  337. WCHAR * pwszMDPath=ConvertToUnicode(pszMDPath);
  338. if (pwszMDPath==0) { hRes=E_OUTOFMEMORY; goto Exit;}
  339. //call real interface function
  340. if(this->m_pcAdmCom==0) {hRes=CO_E_NOTINITIALIZED;goto Exit;}
  341. hRes= this->m_pcAdmCom->OpenKey(hMDHandle, pwszMDPath, dwMDAccessRequested, dwMDTimeOut, phMDNewHandle);
  342. Exit:
  343. //release memory
  344. if( pwszMDPath!=0) delete [] pwszMDPath;
  345. return hRes;
  346. }
  347. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::CloseKey(
  348. /* [in] */ METADATA_HANDLE hMDHandle)
  349. {
  350. if(this->m_pcAdmCom==0) { return CO_E_NOTINITIALIZED;}
  351. return this->m_pcAdmCom->CloseKey(hMDHandle);
  352. }
  353. HRESULT STDMETHODCALLTYPE ANSI_smallIMSAdminBase::SaveData( void)
  354. {
  355. if(this->m_pcAdmCom==0) {return CO_E_NOTINITIALIZED;}
  356. return this->m_pcAdmCom->SaveData();
  357. }