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.

406 lines
7.7 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: xfiledataobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dxfile.h"
  14. #include "XFileBinaryObj.h"
  15. #include "XFileReferenceObj.h"
  16. #include "XFileDataObj.h"
  17. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  18. extern BSTR GUIDtoBSTR(LPGUID);
  19. extern BSTR XFILEGUIDtoBSTR(LPGUID);
  20. extern HRESULT XFILEBSTRtoGUID(LPGUID,BSTR);
  21. C_dxj_DirectXFileDataObject::C_dxj_DirectXFileDataObject()
  22. {
  23. m_pXFileData=NULL;
  24. }
  25. C_dxj_DirectXFileDataObject::~C_dxj_DirectXFileDataObject()
  26. {
  27. if (m_pXFileData) m_pXFileData->Release();
  28. }
  29. HRESULT C_dxj_DirectXFileDataObject::create( IDirectXFileData *pData,I_dxj_DirectXFileData **ret)
  30. {
  31. HRESULT hr;
  32. if (!ret) return E_INVALIDARG;
  33. C_dxj_DirectXFileDataObject *c=NULL;
  34. c=new CComObject<C_dxj_DirectXFileDataObject>;
  35. if( c == NULL ) return E_OUTOFMEMORY;
  36. hr=c->InternalSetObject((IUnknown*)pData);
  37. if FAILED(hr){
  38. delete c;
  39. return hr;
  40. }
  41. hr=IUNK(c)->QueryInterface(IID_I_dxj_DirectXFileData, (void**)ret);
  42. return hr;
  43. }
  44. HRESULT C_dxj_DirectXFileDataObject::InternalSetObject(IUnknown *pUnk)
  45. {
  46. m_pXFileData=(IDirectXFileData*)pUnk;
  47. return S_OK;
  48. }
  49. HRESULT C_dxj_DirectXFileDataObject::InternalGetObject(IUnknown **pUnk)
  50. {
  51. *pUnk=(IUnknown*)m_pXFileData;
  52. return S_OK;
  53. }
  54. STDMETHODIMP C_dxj_DirectXFileDataObject::GetName(
  55. /* [retval][out] */ BSTR __RPC_FAR *name)
  56. {
  57. HRESULT hr;
  58. USES_CONVERSION;
  59. char szName[1024];
  60. DWORD dwSize=1024;
  61. hr=m_pXFileData->GetName(szName,&dwSize);
  62. if FAILED(hr) return hr;
  63. *name=T2BSTR(szName);
  64. return S_OK;
  65. }
  66. STDMETHODIMP C_dxj_DirectXFileDataObject::GetId(
  67. /* [retval][out] */ BSTR __RPC_FAR *name)
  68. {
  69. HRESULT hr;
  70. GUID g;
  71. ZeroMemory(&g,sizeof(GUID));
  72. hr=m_pXFileData->GetId(&g);
  73. if FAILED(hr) return hr;
  74. *name=XFILEGUIDtoBSTR(&g);
  75. return hr;
  76. }
  77. STDMETHODIMP C_dxj_DirectXFileDataObject::GetDataSize(
  78. /* [in] */ BSTR name,
  79. /* [retval][out] */ long __RPC_FAR *size)
  80. {
  81. USES_CONVERSION;
  82. HRESULT hr;
  83. LPVOID pvData=NULL;
  84. DWORD dwSize=0;
  85. if (name[0]==0)
  86. {
  87. hr=m_pXFileData->GetData(NULL,&dwSize,&pvData);
  88. }
  89. else
  90. {
  91. LPSTR szName = NULL;
  92. __try { szName = W2T(name); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  93. hr=m_pXFileData->GetData(szName,&dwSize,&pvData);
  94. }
  95. *size=dwSize;
  96. return hr;
  97. }
  98. STDMETHODIMP C_dxj_DirectXFileDataObject::GetData(
  99. /* [in] */ BSTR name,
  100. /* [in] */ void __RPC_FAR *data)
  101. {
  102. USES_CONVERSION;
  103. HRESULT hr;
  104. LPVOID pvData=NULL;
  105. DWORD dwSize=0;
  106. if (name[0]==0)
  107. {
  108. hr=m_pXFileData->GetData(NULL,&dwSize,&pvData);
  109. }
  110. else
  111. {
  112. LPSTR szName = NULL;
  113. __try { szName = W2T(name); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  114. hr=m_pXFileData->GetData(szName,&dwSize,&pvData);
  115. }
  116. __try{
  117. memcpy(data,pvData,dwSize);
  118. }
  119. __except(1,1){
  120. return E_INVALIDARG;
  121. }
  122. return hr;
  123. }
  124. STDMETHODIMP C_dxj_DirectXFileDataObject::GetType(
  125. /* [retval][out] */ BSTR __RPC_FAR *type)
  126. {
  127. HRESULT hr;
  128. const GUID* pGUID;
  129. hr=m_pXFileData->GetType(&pGUID);
  130. if FAILED(hr) return hr;
  131. *type=XFILEGUIDtoBSTR((GUID*)pGUID);
  132. return hr;
  133. }
  134. STDMETHODIMP C_dxj_DirectXFileDataObject::GetNextObject(
  135. /* [retval][out] */ I_dxj_DirectXFileObject __RPC_FAR *__RPC_FAR *type)
  136. {
  137. HRESULT hr;
  138. IDirectXFileObject *pObj=NULL;
  139. hr=m_pXFileData->GetNextObject(&pObj);
  140. if (hr==DXFILEERR_NOMOREOBJECTS){
  141. *type=NULL;
  142. return S_OK;
  143. }
  144. if FAILED(hr) return hr;
  145. LPUNKNOWN pUnk=NULL;
  146. LPUNKNOWN pCover=NULL;
  147. if (!pObj){
  148. *type=NULL;
  149. return S_OK;
  150. }
  151. hr=pObj->QueryInterface(IID_IDirectXFileData,(void**)&pUnk);
  152. if SUCCEEDED(hr)
  153. {
  154. pObj->Release();
  155. hr=C_dxj_DirectXFileDataObject::create((IDirectXFileData*)pUnk,(I_dxj_DirectXFileData**)&pCover);
  156. if FAILED(hr)
  157. {
  158. pUnk->Release();
  159. return hr;
  160. }
  161. hr=pCover->QueryInterface(IID_I_dxj_DirectXFileObject,(void**)type);
  162. pCover->Release();
  163. if FAILED(hr) pUnk->Release();
  164. return hr;
  165. }
  166. hr=pObj->QueryInterface(IID_IDirectXFileBinary,(void**)&pUnk);
  167. if SUCCEEDED(hr)
  168. {
  169. pObj->Release();
  170. hr=C_dxj_DirectXFileBinaryObject::create((IDirectXFileBinary*)pUnk,(I_dxj_DirectXFileBinary**)&pCover);
  171. if FAILED(hr)
  172. {
  173. pUnk->Release();
  174. return hr;
  175. }
  176. hr=pCover->QueryInterface(IID_I_dxj_DirectXFileObject,(void**)type);
  177. pCover->Release();
  178. if FAILED(hr) pUnk->Release();
  179. return hr;
  180. }
  181. hr=pObj->QueryInterface(IID_IDirectXFileDataReference,(void**)&pUnk);
  182. if SUCCEEDED(hr)
  183. {
  184. pObj->Release();
  185. hr=C_dxj_DirectXFileReferenceObject::create((IDirectXFileDataReference*)pUnk,(I_dxj_DirectXFileReference**)&pCover);
  186. if FAILED(hr)
  187. {
  188. pUnk->Release();
  189. return hr;
  190. }
  191. hr=pCover->QueryInterface(IID_I_dxj_DirectXFileObject,(void**)type);
  192. pCover->Release();
  193. if FAILED(hr) pUnk->Release();
  194. return hr;
  195. }
  196. return E_NOTIMPL;
  197. }
  198. STDMETHODIMP C_dxj_DirectXFileDataObject::AddDataObject(
  199. /* [in] */ I_dxj_DirectXFileData __RPC_FAR *data)
  200. {
  201. HRESULT hr;
  202. if (!data) return E_INVALIDARG;
  203. IDirectXFileData *pData=NULL;
  204. //note does not addref
  205. data->InternalGetObject((IUnknown**)&pData);
  206. if (!pData) return E_FAIL;
  207. hr=m_pXFileData->AddDataObject(pData);
  208. return hr;
  209. }
  210. STDMETHODIMP C_dxj_DirectXFileDataObject::AddDataReference(
  211. /* [in] */ BSTR name,
  212. /* [in] */ BSTR guid)
  213. {
  214. USES_CONVERSION;
  215. HRESULT hr;
  216. LPSTR szName=NULL;
  217. GUID *lpGuid=NULL;
  218. GUID g;
  219. ZeroMemory(&g,sizeof(GUID));
  220. if (name[0]!=0)
  221. {
  222. __try { szName = W2T(name); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  223. }
  224. if (guid[0]!=0)
  225. {
  226. hr=XFILEBSTRtoGUID(&g,guid);
  227. if FAILED(hr) return hr;
  228. lpGuid=&g;
  229. }
  230. hr=m_pXFileData->AddDataReference(szName,lpGuid);
  231. return hr;
  232. }
  233. STDMETHODIMP C_dxj_DirectXFileDataObject::AddBinaryObject(
  234. /* [in] */ BSTR name,
  235. /* [in] */ BSTR guidObject,
  236. /* [in] */ BSTR MimeType,
  237. void __RPC_FAR *data,
  238. /* [in] */ long size)
  239. {
  240. USES_CONVERSION;
  241. HRESULT hr;
  242. GUID gObj;
  243. GUID *lpGuid=NULL;
  244. LPSTR szMime=NULL;
  245. LPSTR szName=NULL;
  246. ZeroMemory(&gObj,sizeof(GUID));
  247. if (!data) return E_INVALIDARG;
  248. if ((guidObject) && (guidObject[0]!=0))
  249. {
  250. hr=XFILEBSTRtoGUID(&gObj,guidObject);
  251. if FAILED(hr) return hr;
  252. lpGuid=&gObj;
  253. }
  254. if ((name) && (name[0]!=0))
  255. {
  256. __try { szName = W2T(name); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  257. }
  258. if ((MimeType) && (MimeType[0]!=0))
  259. {
  260. __try { szMime = W2T(MimeType); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  261. }
  262. IDirectXFileData *pData=NULL;
  263. __try
  264. {
  265. hr=m_pXFileData->AddBinaryObject(szName,lpGuid,szMime,data,size);
  266. }
  267. __except(1,1)
  268. {
  269. return E_INVALIDARG;
  270. }
  271. return hr;
  272. }
  273. STDMETHODIMP C_dxj_DirectXFileDataObject::GetDataFromOffset(
  274. /* [in] */ BSTR name,
  275. /* [in] */ long offset,
  276. /* [in] */ long bytecount,
  277. /* [in] */ void *data)
  278. {
  279. USES_CONVERSION;
  280. HRESULT hr;
  281. LPVOID pvData=NULL;
  282. DWORD dwSize=0;
  283. if (name[0]==0)
  284. {
  285. hr=m_pXFileData->GetData(NULL,&dwSize,&pvData);
  286. }
  287. else
  288. {
  289. LPSTR szName = NULL;
  290. __try { szName = W2T(name); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  291. hr=m_pXFileData->GetData(szName,&dwSize,&pvData);
  292. }
  293. __try{
  294. memcpy(data,&((char*)pvData)[offset],bytecount);
  295. }
  296. __except(1,1){
  297. return E_INVALIDARG;
  298. }
  299. return hr;
  300. }