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.

254 lines
8.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: D E S C R I P T I O N M A N A G E R . H
  7. //
  8. // Contents: Process UPnP Description document
  9. //
  10. // Notes:
  11. //
  12. // Author: mbend 18 Aug 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include "uhres.h" // main symbols
  17. #include "ComUtility.h"
  18. #include "Array.h"
  19. #include "hostp.h"
  20. #include "Table.h"
  21. #include "UString.h"
  22. #include "RegDef.h"
  23. #include "uhsync.h"
  24. #include "uhxml.h"
  25. // Forward declarations
  26. struct _SSDP_MESSAGE;
  27. typedef _SSDP_MESSAGE SSDP_MESSAGE;
  28. // Must define these here to satisfy data structure requirements
  29. typedef CUString Filename;
  30. typedef CUString Mimetype;
  31. struct FileInfo
  32. {
  33. Filename m_filename;
  34. Mimetype m_mimetype;
  35. };
  36. inline HRESULT HrTypeAssign(FileInfo & dst, const FileInfo & src)
  37. {
  38. HRESULT hr = S_OK;
  39. hr = HrTypeAssign(dst.m_filename, src.m_filename);
  40. if(SUCCEEDED(hr))
  41. {
  42. hr = HrTypeAssign(dst.m_mimetype, src.m_mimetype);
  43. }
  44. return hr;
  45. }
  46. inline void TypeTransfer(FileInfo & dst, FileInfo & src)
  47. {
  48. TypeTransfer(dst.m_filename, src.m_filename);
  49. TypeTransfer(dst.m_mimetype, src.m_mimetype);
  50. }
  51. inline void TypeClear(FileInfo & type)
  52. {
  53. TypeClear(type.m_filename);
  54. TypeClear(type.m_mimetype);
  55. }
  56. typedef CTable<UDN, UDN> UDNReplacementTable;
  57. // Not implemented - should not use
  58. // inline HRESULT HrTypeAssign(UDNReplacementTable & dst, const UDNReplacementTable & src)
  59. inline void TypeTransfer(UDNReplacementTable & dst, UDNReplacementTable & src)
  60. {
  61. dst.Swap(src);
  62. }
  63. inline void TypeClear(UDNReplacementTable & type)
  64. {
  65. type.Clear();
  66. }
  67. typedef CTable<PhysicalDeviceIdentifier, UDNReplacementTable> ReplacementTable;
  68. /////////////////////////////////////////////////////////////////////////////
  69. // TestObject
  70. class ATL_NO_VTABLE CDescriptionManager :
  71. public CComObjectRootEx<CComMultiThreadModel>,
  72. public CComCoClass<CDescriptionManager, &CLSID_UPnPDescriptionManager>,
  73. public IUPnPDescriptionManager,
  74. public IUPnPDynamicContentProvider
  75. {
  76. public:
  77. CDescriptionManager();
  78. ~CDescriptionManager();
  79. DECLARE_REGISTRY_RESOURCEID(IDR_DESCRIPTION_MANAGER)
  80. DECLARE_NOT_AGGREGATABLE(CDescriptionManager)
  81. BEGIN_COM_MAP(CDescriptionManager)
  82. COM_INTERFACE_ENTRY(IUPnPDescriptionManager)
  83. COM_INTERFACE_ENTRY(IUPnPDynamicContentProvider)
  84. END_COM_MAP()
  85. public:
  86. // IUPnPDescriptionManager methods
  87. STDMETHOD(GetContent)(
  88. /*[in]*/ REFGUID guidContent,
  89. /*[out]*/ long * pnHeaderCount,
  90. /*[out, string, size_is(,*pnHeaderCount)]*/ wchar_t *** arszHeaders,
  91. /*[out]*/ long * pnBytes,
  92. /*[out, size_is(,*pnBytes)]*/ byte ** parBytes);
  93. // IUPnPDynamicContentProvider methods
  94. STDMETHOD(ProcessDescriptionTemplate)(
  95. /*[in]*/ BSTR bstrTemplate,
  96. /*[in, string]*/ const wchar_t * szResourcePath,
  97. /*[in, out]*/ GUID * pguidPhysicalDeviceIdentifier,
  98. /*[in]*/ BOOL bPersist,
  99. /*[in]*/ BOOL bReregister);
  100. STDMETHOD(PublishDescription)(
  101. /*[in]*/ REFGUID guidPhysicalDeviceIdentifier,
  102. /*[in]*/ long nLifeTime);
  103. STDMETHOD(LoadDescription)(
  104. /*[in]*/ REFGUID guidPhysicalDeviceIdentifier);
  105. STDMETHOD(RemoveDescription)(
  106. /*[in]*/ REFGUID guidPhysicalDeviceIdentifier,
  107. /*[in]*/ BOOL bPermanent);
  108. STDMETHOD(GetDescriptionText)(
  109. /*[in]*/ REFGUID guidPhysicalDeviceIdentifier,
  110. /*[out]*/ BSTR * pbstrDescriptionDocument);
  111. STDMETHOD(GetUDNs)(
  112. /*[in]*/ REFGUID guidPhysicalDeviceIdentifier,
  113. /*[out]*/ long * pnUDNCount,
  114. /*[out, size_is(,*pnUDNCount,), string]*/
  115. wchar_t *** parszUDNs);
  116. STDMETHOD(GetUniqueDeviceName)(
  117. /*[in]*/ REFGUID guidPhysicalDeviceIdentifier,
  118. /*[in, string]*/ const wchar_t * szTemplateUDN,
  119. /*[out, string]*/ wchar_t ** pszUDN);
  120. STDMETHOD(GetSCPDText)(
  121. /*[in]*/ REFGUID guidPhysicalDeviceIdentifier,
  122. /*[in, string]*/ const wchar_t * szUDN,
  123. /*[in, string]*/ const wchar_t * szServiceId,
  124. /*[out, string]*/ wchar_t ** pszSCPDText,
  125. /*[out, string]*/ wchar_t ** pszServiceType);
  126. private:
  127. typedef BSTR DescriptionDocument;
  128. typedef CTable<PhysicalDeviceIdentifier, DescriptionDocument> DocumentTable;
  129. typedef GUID FileId;
  130. typedef CTable<FileId, FileInfo> FileTable;
  131. struct CleanupItem
  132. {
  133. PhysicalDeviceIdentifier m_physicalDeviceIdentifier;
  134. FileId m_fileId;
  135. };
  136. typedef CUArray<CleanupItem> CleanupList;
  137. typedef CUArray<HANDLE> HandleList;
  138. typedef CTable<PhysicalDeviceIdentifier, HandleList *> SSDPRegistrationTable;
  139. DocumentTable m_documentTable;
  140. FileTable m_fileTable;
  141. CleanupList m_cleanupList;
  142. CUCriticalSection m_critSecReplacementTable;
  143. ReplacementTable m_replacementTable;
  144. SSDPRegistrationTable m_ssdpRegistrationTable;
  145. // Internal helper routines
  146. HRESULT HrPersistDeviceSettingsToRegistry(
  147. const PhysicalDeviceIdentifier & physicalDeviceIdentifier,
  148. const UDNReplacementTable & udnReplacementTable,
  149. const FileTable & fileTable,
  150. BOOL bPersist);
  151. HRESULT HrLoadDocumentAndRootNode(
  152. const PhysicalDeviceIdentifier & physicalDeviceIdentifier,
  153. IXMLDOMNodePtr & pRootNode);
  154. // (PDT) Process Device Template helper functions
  155. HRESULT HrPDT_FetchCollections(
  156. BSTR bstrTemplate,
  157. IXMLDOMDocumentPtr & pDoc,
  158. IXMLDOMNodePtr & pRootNode,
  159. CUString & strRootUdnOld,
  160. IXMLDOMNodeListPtr & pNodeListDevices,
  161. IXMLDOMNodeListPtr & pNodeListUDNs,
  162. IXMLDOMNodeListPtr & pNodeListSCPDURLs,
  163. IXMLDOMNodeListPtr & pNodeListIcons);
  164. HRESULT HrPDT_DoUDNToUDNMapping(
  165. IXMLDOMNodeListPtr & pNodeListUDNs,
  166. UDNReplacementTable & udnReplacementTable);
  167. HRESULT HrPDT_ReregisterUDNsInDescriptionDocument(
  168. UDNReplacementTable & udnReplacementTable,
  169. IXMLDOMNodeListPtr & pNodeListUDNs);
  170. HRESULT HrPDT_FetchPhysicalIdentifier(
  171. UDNReplacementTable & udnReplacementTable,
  172. const CUString & strRootUdnOld,
  173. PhysicalDeviceIdentifier & pdi);
  174. HRESULT HrPDT_ReplaceSCPDURLs(
  175. IXMLDOMNodeListPtr & pNodeListSCPDURLs,
  176. const wchar_t * szResourcePath,
  177. FileTable & fileTable);
  178. HRESULT HrPDT_ReplaceIcons(
  179. IXMLDOMNodeListPtr & pNodeListIcons,
  180. const wchar_t * szResourcePath,
  181. FileTable & fileTable);
  182. HRESULT HrPDT_ReplaceControlAndEventURLs(
  183. IXMLDOMNodeListPtr & pNodeListDevices);
  184. HRESULT HrPDT_PersistDescriptionDocument(
  185. const PhysicalDeviceIdentifier & pdi,
  186. IXMLDOMDocumentPtr & pDoc);
  187. // presentation specific functions
  188. HRESULT HrPDT_ProcessPresentationURLs(
  189. REFGUID guidPhysicalDeviceIdentifier,
  190. IXMLDOMNodeListPtr & pNodeListDevices,
  191. BOOL *fIsPresURLTagPresent);
  192. // (PD) Publish Description helper functions
  193. HRESULT HrPD_DoRootNotification(
  194. IXMLDOMNodePtr & pNodeRootDevice,
  195. SSDP_MESSAGE * pMsg,
  196. HandleList * pHandleList);
  197. HRESULT HrPD_DoDevicePublication(
  198. IXMLDOMNodeListPtr & pNodeListDevices,
  199. SSDP_MESSAGE * pMsg,
  200. HandleList * pHandleList);
  201. HRESULT HrPD_DoServicePublication(
  202. IXMLDOMNodePtr & pNodeDevice,
  203. const CUString & strUDN,
  204. SSDP_MESSAGE * pMsg,
  205. HandleList * pHandleList);
  206. // (LD) Load Description helper functions
  207. HRESULT HrLD_ReadUDNMappings(
  208. HKEY hKeyPdi,
  209. UDNReplacementTable & udnReplacementTable);
  210. HRESULT HrLD_ReadFileMappings(
  211. HKEY hKeyPdi,
  212. FileTable & fileTable);
  213. HRESULT HrLD_LoadDescriptionDocumentFromDisk(
  214. const PhysicalDeviceIdentifier & pdi,
  215. IXMLDOMDocumentPtr & pDoc);
  216. HRESULT HrLD_SaveDescriptionDocumentText(
  217. IXMLDOMDocumentPtr & pDoc,
  218. const PhysicalDeviceIdentifier & pdi);
  219. // (RD) Remove Description helper functions
  220. HRESULT HrRD_RemoveFromEventing(const PhysicalDeviceIdentifier & pdi);
  221. HRESULT HrRD_RemoveFromDataStructures(const PhysicalDeviceIdentifier & pdi);
  222. HRESULT HrRD_CleanupPublication(const PhysicalDeviceIdentifier & pdi);
  223. };
  224. HRESULT HrCreateOrOpenDescriptionKey(
  225. HKEY * phKeyDescription);
  226. HRESULT HrOpenPhysicalDeviceDescriptionKey(
  227. const UUID & pdi,
  228. HKEY * phKeyPdi);
  229. HRESULT HrGetDescriptionDocumentPath(
  230. const UUID & pdi,
  231. CUString & strPath);
  232. HRESULT HrRegisterServiceWithEventing(
  233. IXMLDOMNodePtr & pNodeService,
  234. const CUString & strUDN,
  235. BOOL bRegister);