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.

726 lines
26 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2001-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dpnhupnpintfobj.h
  6. *
  7. * Content: Header for DPNHUPNP main interface object class.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 04/16/01 VanceO Split DPNATHLP into DPNHUPNP and DPNHPAST.
  13. *
  14. ***************************************************************************/
  15. //=============================================================================
  16. // Defines
  17. //=============================================================================
  18. #define NETWORKBYTEORDER_INADDR_LOOPBACK 0x0100007f
  19. #define MAX_XMLELEMENT_DEPTH 15
  20. #define MAX_XMLNAMESPACES_PER_ELEMENT 5
  21. #define MAX_NUM_DESCRIPTION_XML_SUBELEMENTS 10
  22. #define MAX_NUM_UPNPCONTROLOUTARGS 10
  23. //=============================================================================
  24. // Macros
  25. //=============================================================================
  26. #define NATHELPUPNP_FROM_BILINK(b) (CONTAINING_OBJECT(b, CNATHelpUPnP, m_blList))
  27. //=============================================================================
  28. // Typedefs
  29. //=============================================================================
  30. class CNATHelpUPnP;
  31. class CUPnPDevice;
  32. //=============================================================================
  33. // Object flags
  34. //=============================================================================
  35. #define NATHELPUPNPOBJ_NOTCREATEDWITHCOM 0x0001 // object was created through non-COM DirectPlayNATHelpCreate function
  36. #define NATHELPUPNPOBJ_INITIALIZED 0x0002 // object has been initialized
  37. #define NATHELPUPNPOBJ_USEUPNP 0x0004 // UPnP can be used for NAT traversal
  38. #ifndef DPNBUILD_NOHNETFWAPI
  39. #define NATHELPUPNPOBJ_USEHNETFWAPI 0x0008 // the HomeNet firewall port mapping API can be used for opening a local firewall
  40. #endif // ! DPNBUILD_NOHNETFWAPI
  41. #ifndef DPNBUILD_NOWINSOCK2
  42. #define NATHELPUPNPOBJ_WINSOCK1 0x0010 // only WinSock 1 functionality is available
  43. #endif // ! DPNBUILD_NOWINSOCK2
  44. #define NATHELPUPNPOBJ_DEVICECHANGED 0x0020 // short lived flag that overrides min update server status interval when a device is added or removed
  45. #define NATHELPUPNPOBJ_ADDRESSESCHANGED 0x0040 // flag indicating that server status changed since the last time the user checked
  46. #define NATHELPUPNPOBJ_PORTREGISTERED 0x0080 // short lived flag that allows remote gateway check when a port has been registered
  47. #define NATHELPUPNPOBJ_LONGLOCK 0x0100 // a thread dropped the main object lock but still needs ownership of the object during a long operation
  48. #ifndef WINCE
  49. #define NATHELPUPNPOBJ_USEGLOBALNAMESPACEPREFIX 0x0200 // use the "Global\" prefix when creating named kernel objects
  50. #endif // ! WINCE
  51. //=============================================================================
  52. // Structures
  53. //=============================================================================
  54. //
  55. // UPnP header information parsing structure
  56. //
  57. typedef struct _UPNP_HEADER_INFO
  58. {
  59. char * apszHeaderStrings[NUM_RESPONSE_HEADERS]; // place to store pointers to value strings for each header found
  60. char * pszMsgBody; // place to store pointer to message body after the end of the headers
  61. } UPNP_HEADER_INFO, * PUPNP_HEADER_INFO;
  62. //
  63. // UPnP XML parsing structures
  64. //
  65. typedef struct _PARSEXML_SUBELEMENT
  66. {
  67. char * pszNameFound; // name of subelement instance that was found
  68. char * apszAttributeNames[MAX_XMLNAMESPACES_PER_ELEMENT]; // array of attributes for this subelement instance
  69. char * apszAttributeValues[MAX_XMLNAMESPACES_PER_ELEMENT]; // matching array of values for the attributes of this subelement instance
  70. DWORD dwNumAttributes; // number of attributes contained in previous arrays
  71. char * pszValueFound; // pointer to value associated with this subelement instance
  72. } PARSEXML_SUBELEMENT, * PPARSEXML_SUBELEMENT;
  73. typedef struct _PARSEXML_ELEMENT
  74. {
  75. char ** papszElementStack; // array of strings indicating an item's location in the XML document
  76. DWORD dwElementStackDepth; // number of strings in previous array
  77. PARSEXML_SUBELEMENT * paSubElements; // array to store subelement instances found
  78. DWORD dwMaxNumSubElements; // maximum number of subelement instances that can be stored in previous array
  79. DWORD dwNumSubElements; // number of subelement instances actually returned in previous array
  80. BOOL fFoundMatchingElement; // whether the required subelements were found
  81. } PARSEXML_ELEMENT, * PPARSEXML_ELEMENT;
  82. typedef struct tagPARSEXML_STACKENTRY
  83. {
  84. char * pszName; // name of this XML element
  85. char * apszAttributeNames[MAX_XMLNAMESPACES_PER_ELEMENT]; // array of attributes for this XML element
  86. char * apszAttributeValues[MAX_XMLNAMESPACES_PER_ELEMENT]; // matching array of values for the attributes of this XML element
  87. DWORD dwNumAttributes; // number of attributes contained in previous arrays
  88. char * pszValue; // value of this XML element
  89. } PARSEXML_STACKENTRY, * PPARSEXML_STACKENTRY;
  90. typedef enum _PARSECALLBACK
  91. {
  92. PARSECALLBACK_DESCRIPTIONRESPONSE, // use the description response parse callback
  93. PARSECALLBACK_CONTROLRESPONSE // use the control response parse callback
  94. } PARSECALLBACK;
  95. #ifdef DPNBUILD_NOWINSOCK2
  96. //=============================================================================
  97. // WinSock function definitions required when winsock2.h cannot be included
  98. //=============================================================================
  99. #define WSAAPI FAR PASCAL
  100. typedef
  101. int
  102. (WSAAPI * LPFN_WSASTARTUP)(
  103. IN WORD wVersionRequested,
  104. OUT LPWSADATA lpWSAData
  105. );
  106. typedef
  107. int
  108. (WSAAPI * LPFN_WSACLEANUP)(
  109. void
  110. );
  111. typedef
  112. int
  113. (WSAAPI * LPFN_WSAGETLASTERROR)(
  114. void
  115. );
  116. typedef
  117. SOCKET
  118. (WSAAPI * LPFN_SOCKET)(
  119. IN int af,
  120. IN int type,
  121. IN int protocol
  122. );
  123. typedef
  124. int
  125. (WSAAPI * LPFN_CLOSESOCKET)(
  126. IN SOCKET s
  127. );
  128. typedef
  129. int
  130. (WSAAPI * LPFN_BIND)(
  131. IN SOCKET s,
  132. IN const struct sockaddr FAR * name,
  133. IN int namelen
  134. );
  135. typedef
  136. int
  137. (WSAAPI * LPFN_SETSOCKOPT)(
  138. IN SOCKET s,
  139. IN int level,
  140. IN int optname,
  141. IN const char FAR * optval,
  142. IN int optlen
  143. );
  144. typedef
  145. int
  146. (WSAAPI * LPFN_GETSOCKNAME)(
  147. IN SOCKET s,
  148. OUT struct sockaddr FAR * name,
  149. IN OUT int FAR * namelen
  150. );
  151. typedef
  152. int
  153. (WSAAPI * LPFN_SELECT)(
  154. IN int nfds,
  155. IN OUT fd_set FAR * readfds,
  156. IN OUT fd_set FAR * writefds,
  157. IN OUT fd_set FAR *exceptfds,
  158. IN const struct timeval FAR * timeout
  159. );
  160. typedef
  161. int
  162. (WSAAPI * LPFN_RECVFROM)(
  163. IN SOCKET s,
  164. OUT char FAR * buf,
  165. IN int len,
  166. IN int flags,
  167. OUT struct sockaddr FAR * from,
  168. IN OUT int FAR * fromlen
  169. );
  170. typedef
  171. int
  172. (WSAAPI * LPFN_SENDTO)(
  173. IN SOCKET s,
  174. IN const char FAR * buf,
  175. IN int len,
  176. IN int flags,
  177. IN const struct sockaddr FAR * to,
  178. IN int tolen
  179. );
  180. typedef
  181. int
  182. (WSAAPI * LPFN_GETHOSTNAME)(
  183. OUT char FAR * name,
  184. IN int namelen
  185. );
  186. typedef
  187. struct hostent FAR *
  188. (WSAAPI * LPFN_GETHOSTBYNAME)(
  189. IN const char FAR * name
  190. );
  191. typedef
  192. unsigned long
  193. (WSAAPI * LPFN_INET_ADDR)(
  194. IN const char FAR * cp
  195. );
  196. typedef
  197. int
  198. (WSAAPI * LPFN_IOCTLSOCKET)(
  199. IN SOCKET s,
  200. IN long cmd,
  201. IN OUT u_long FAR * argp
  202. );
  203. typedef
  204. int
  205. (WSAAPI * LPFN_CONNECT)(
  206. IN SOCKET s,
  207. IN const struct sockaddr FAR * name,
  208. IN int namelen
  209. );
  210. typedef
  211. int
  212. (WSAAPI * LPFN_SHUTDOWN)(
  213. IN SOCKET s,
  214. IN int how
  215. );
  216. typedef
  217. int
  218. (WSAAPI * LPFN_SEND)(
  219. IN SOCKET s,
  220. IN const char FAR * buf,
  221. IN int len,
  222. IN int flags
  223. );
  224. typedef
  225. int
  226. (WSAAPI * LPFN_RECV)(
  227. IN SOCKET s,
  228. OUT char FAR * buf,
  229. IN int len,
  230. IN int flags
  231. );
  232. typedef
  233. int
  234. (WSAAPI * LPFN_GETSOCKOPT)(
  235. IN SOCKET s,
  236. IN int level,
  237. IN int optname,
  238. OUT char FAR * optval,
  239. IN OUT int FAR * optlen
  240. );
  241. //=============================================================================
  242. // WinSock function definitions left out by winsock2.h
  243. //=============================================================================
  244. typedef INT (WSAAPI * LPFN___WSAFDISSET) (SOCKET, fd_set FAR *);
  245. //=============================================================================
  246. // Macro redefinitions due to WinCE/Desktop differences
  247. //=============================================================================
  248. #undef FD_SET
  249. #define FD_SET(fd, set) do { \
  250. if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  251. ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=(fd);\
  252. } while(0)
  253. #else // ! DPNBUILD_NOWINSOCK2
  254. //=============================================================================
  255. // WinSock function definitions left out by winsock2.h
  256. //=============================================================================
  257. typedef INT (WSAAPI * LPFN___WSAFDISSET) (SOCKET, fd_set FAR *);
  258. //=============================================================================
  259. // IPHLPAPI function prototypes
  260. //=============================================================================
  261. typedef DWORD (WINAPI *PFN_GETADAPTERSINFO) (PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen);
  262. typedef DWORD (WINAPI *PFN_GETIPFORWARDTABLE) (PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder);
  263. typedef DWORD (WINAPI *PFN_GETBESTROUTE) (DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute);
  264. //=============================================================================
  265. // RASAPI32 function prototypes
  266. //=============================================================================
  267. typedef DWORD (WINAPI *PFN_RASGETENTRYHRASCONNW) (IN LPCWSTR pszPhonebook, IN LPCWSTR pszEntry, OUT LPHRASCONN lphrasconn);
  268. #ifdef UNICODE
  269. typedef DWORD (WINAPI *PFN_RASGETPROJECTIONINFOW) (HRASCONN hrasconn, RASPROJECTION rasprojection, LPVOID lpprojection, LPDWORD lpcb);
  270. #define PFN_RASGETPROJECTIONINFO PFN_RASGETPROJECTIONINFOW
  271. #else // ! UNICODE
  272. typedef DWORD (WINAPI *PFN_RASGETPROJECTIONINFOA) (HRASCONN hrasconn, RASPROJECTION rasprojection, LPVOID lpprojection, LPDWORD lpcb);
  273. #define PFN_RASGETPROJECTIONINFO PFN_RASGETPROJECTIONINFOA
  274. #endif // ! UNICODE
  275. #endif // ! DPNBUILD_NOWINSOCK2
  276. //=============================================================================
  277. // Main interface object class
  278. //=============================================================================
  279. class CNATHelpUPnP : public IDirectPlayNATHelp
  280. {
  281. public:
  282. CNATHelpUPnP(const BOOL fNotCreatedWithCOM); // constructor
  283. ~CNATHelpUPnP(void); // destructor
  284. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  285. STDMETHODIMP_(ULONG) AddRef(void);
  286. STDMETHODIMP_(ULONG) Release(void);
  287. STDMETHODIMP Initialize(const DWORD dwFlags);
  288. STDMETHODIMP Close(const DWORD dwFlags);
  289. STDMETHODIMP GetCaps(DPNHCAPS * const pdpnhcaps,
  290. const DWORD dwFlags);
  291. STDMETHODIMP RegisterPorts(const SOCKADDR * const aLocalAddresses,
  292. const DWORD dwAddressesSize,
  293. const DWORD dwNumAddresses,
  294. const DWORD dwLeaseTime,
  295. DPNHHANDLE * const phRegisteredPorts,
  296. const DWORD dwFlags);
  297. STDMETHODIMP GetRegisteredAddresses(const DPNHHANDLE hRegisteredPorts,
  298. SOCKADDR * const paPublicAddresses,
  299. DWORD * const pdwPublicAddressesSize,
  300. DWORD * const pdwAddressTypeFlags,
  301. DWORD * const pdwLeaseTimeRemaining,
  302. const DWORD dwFlags);
  303. STDMETHODIMP DeregisterPorts(const DPNHHANDLE hRegisteredPorts,
  304. const DWORD dwFlags);
  305. STDMETHODIMP QueryAddress(const SOCKADDR * const pSourceAddress,
  306. const SOCKADDR * const pQueryAddress,
  307. SOCKADDR * const pResponseAddress,
  308. const int iAddressesSize,
  309. const DWORD dwFlags);
  310. STDMETHODIMP SetAlertEvent(const HANDLE hEvent, const DWORD dwFlags);
  311. STDMETHODIMP SetAlertIOCompletionPort(const HANDLE hIOCompletionPort,
  312. const DWORD dwCompletionKey,
  313. const DWORD dwNumConcurrentThreads,
  314. const DWORD dwFlags);
  315. STDMETHODIMP ExtendRegisteredPortsLease(const DPNHHANDLE hRegisteredPorts,
  316. const DWORD dwLeaseTime,
  317. const DWORD dwFlags);
  318. HRESULT InitializeObject(void);
  319. void UninitializeObject(void);
  320. CBilink m_blList; // list of all the NATHelper instances in existence
  321. private:
  322. BYTE m_Sig[4]; // debugging signature ('NATH')
  323. LONG m_lRefCount; // reference count for this object
  324. DWORD m_dwFlags; // flags for this object
  325. DNCRITICAL_SECTION m_csLock; // lock preventing simultaneous usage
  326. DNHANDLE m_hLongLockSemaphore; // semaphore used to hold the object lock for a long period of time
  327. LONG m_lNumLongLockWaitingThreads; // number of threads waiting for the long lock to be released
  328. DWORD m_dwLockThreadID; // ID of thread currently holding the lock
  329. #ifndef DPNBUILD_NOHNETFWAPI
  330. HANDLE m_hAlertEvent; // handle to alert event, if any
  331. HANDLE m_hAlertIOCompletionPort; // handle to alert I/O completion port, if any
  332. DWORD m_dwAlertCompletionKey; // alert completion key to use, if any
  333. #endif // ! DPNBUILD_NOHNETFWAPI
  334. CBilink m_blDevices; // list of all IP capable devices
  335. CBilink m_blRegisteredPorts; // list of all the ports registered (may or may not be mapped with an Internet gateway)
  336. CBilink m_blUnownedPorts; // list of all the registered ports which could not be associated with specific devices
  337. DWORD m_dwLastUpdateServerStatusTime; // last time the server status was updated
  338. DWORD m_dwNextPollInterval; // next GetCaps poll interval to use
  339. DWORD m_dwNumLeases; // number of registered ports which have successfully been leased
  340. DWORD m_dwEarliestLeaseExpirationTime; // time when first registered port lease expires, if there are any
  341. CBilink m_blUPnPDevices; // list of all the UPnP devices known (may or may not be connected)
  342. DWORD m_dwInstanceKey; // instance key used for crash cleanup
  343. DWORD m_dwCurrentUPnPDeviceID; // current unique UPnP device ID
  344. DNHANDLE m_hMappingStillActiveNamedObject; // named object used to prevent subsequent objects from cleaning up mappings that are still in use
  345. #ifndef DPNBUILD_NOWINSOCK2
  346. HMODULE m_hIpHlpApiDLL; // handle to iphlpapi.dll, if available
  347. PFN_GETADAPTERSINFO m_pfnGetAdaptersInfo; // pointer to GetAdaptersInfo function
  348. PFN_GETIPFORWARDTABLE m_pfnGetIpForwardTable; // pointer to GetIpForwardTable function
  349. PFN_GETBESTROUTE m_pfnGetBestRoute; // pointer to GetBestRoute function
  350. HMODULE m_hRasApi32DLL; // handle to rasapi32.dll, if available
  351. PFN_RASGETENTRYHRASCONNW m_pfnRasGetEntryHrasconnW; // pointer to RasGetEntryHrasconnW function
  352. PFN_RASGETPROJECTIONINFO m_pfnRasGetProjectionInfo; // pointer to RasGetProjectionInfoA/W function
  353. SOCKET m_sIoctls; // socket being used to submit Ioctls (WinSock2 only)
  354. WSAOVERLAPPED * m_polAddressListChange; // pointer overlapped structure for address list change WSAIoctl call
  355. #endif // ! DPNBUILD_NOWINSOCK2
  356. HMODULE m_hWinSockDLL; // handle to wsock32.dll or ws2_32.dll
  357. LPFN_WSASTARTUP m_pfnWSAStartup; // pointer to WSAStartup function
  358. LPFN_WSACLEANUP m_pfnWSACleanup; // pointer to WSACleanup function
  359. LPFN_WSAGETLASTERROR m_pfnWSAGetLastError; // pointer to WSAGetLastError function
  360. LPFN_SOCKET m_pfnsocket; // pointer to socket function
  361. LPFN_CLOSESOCKET m_pfnclosesocket; // pointer to closesocket function
  362. LPFN_BIND m_pfnbind; // pointer to bind function
  363. LPFN_SETSOCKOPT m_pfnsetsockopt; // pointer to setsockopt function
  364. LPFN_GETSOCKNAME m_pfngetsockname; // pointer to getsockname function
  365. LPFN_SELECT m_pfnselect; // pointer to select function
  366. LPFN___WSAFDISSET m_pfn__WSAFDIsSet; // pointer to __WSAFDIsSet function
  367. LPFN_RECVFROM m_pfnrecvfrom; // pointer to recvfrom function
  368. LPFN_SENDTO m_pfnsendto; // pointer to sendto function
  369. LPFN_GETHOSTNAME m_pfngethostname; // pointer to gethostname function
  370. LPFN_GETHOSTBYNAME m_pfngethostbyname; // pointer to gethostbyname function
  371. LPFN_INET_ADDR m_pfninet_addr; // pointer to inet_addr function
  372. #ifndef DPNBUILD_NOWINSOCK2
  373. LPFN_WSASOCKETA m_pfnWSASocketA; // pointer to WSASocket function
  374. LPFN_WSAIOCTL m_pfnWSAIoctl; // WinSock2 only, pointer to WSAIoctl function
  375. LPFN_WSAGETOVERLAPPEDRESULT m_pfnWSAGetOverlappedResult; // WinSock2 only, pointer to WSAGetOverlappedResult function
  376. #endif // ! DPNBUILD_NOWINSOCK2
  377. LPFN_IOCTLSOCKET m_pfnioctlsocket; // pointer to ioctlsocket function
  378. LPFN_CONNECT m_pfnconnect; // pointer to connect function
  379. LPFN_SHUTDOWN m_pfnshutdown; // pointer to shutdown function
  380. LPFN_SEND m_pfnsend; // pointer to send function
  381. LPFN_RECV m_pfnrecv; // pointer to recv function
  382. #ifdef DBG
  383. LPFN_GETSOCKOPT m_pfngetsockopt; // pointer to getsockopt function
  384. DWORD m_dwNumDeviceAdds; // how many times devices were added
  385. DWORD m_dwNumDeviceRemoves; // how many times devices were removed
  386. DWORD m_dwNumServerFailures; // how many times a UPnP gateway device stopped responding and had to be removed
  387. #endif // DBG
  388. inline BOOL IsValidObject(void)
  389. {
  390. if ((this == NULL) || (IsBadWritePtr(this, sizeof(CNATHelpUPnP))))
  391. {
  392. return FALSE;
  393. }
  394. if (*((DWORD*) (&this->m_Sig)) != 0x4854414E) // 0x48 0x54 0x41 0x4E = 'HTAN' = 'NATH' in Intel order
  395. {
  396. return FALSE;
  397. }
  398. return TRUE;
  399. };
  400. inline void ResetNextPollInterval(void)
  401. {
  402. //
  403. // Reading this DWORD should be atomic, so no need to hold the
  404. // globals lock.
  405. //
  406. this->m_dwNextPollInterval = g_dwNoActiveNotifyPollInterval;
  407. };
  408. HRESULT TakeLock(void);
  409. void DropLock(void);
  410. void SwitchToLongLock(void);
  411. void SwitchFromLongLock(void);
  412. HRESULT LoadWinSockFunctionPointers(void);
  413. HRESULT CheckForNewDevices(BOOL * const pfFoundNewDevices);
  414. #ifndef DPNBUILD_NOHNETFWAPI
  415. HRESULT CheckForLocalHNetFirewallAndMapPorts(CDevice * const pDevice,
  416. CRegisteredPort * const pDontAlertRegisteredPort);
  417. HRESULT GetIHNetConnectionForDeviceIfFirewalled(CDevice * const pDevice,
  418. IHNetCfgMgr * const pHNetCfgMgr,
  419. IHNetConnection ** const ppHNetConnection);
  420. HRESULT GetIPAddressGuidString(const TCHAR * const tszDeviceIPAddress,
  421. TCHAR * const ptszGuidString);
  422. HRESULT OpenDevicesUPnPDiscoveryPort(CDevice * const pDevice,
  423. IHNetCfgMgr * const pHNetCfgMgr,
  424. IHNetConnection * const pHNetConnection);
  425. HRESULT CloseDevicesUPnPDiscoveryPort(CDevice * const pDevice,
  426. IHNetCfgMgr * const pHNetCfgMgr);
  427. HRESULT MapUnmappedPortsOnLocalHNetFirewall(CDevice * const pDevice,
  428. IHNetCfgMgr * const pHNetCfgMgr,
  429. IHNetConnection * const pHNetConnection,
  430. CRegisteredPort * const pDontAlertRegisteredPort);
  431. HRESULT MapPortOnLocalHNetFirewall(CRegisteredPort * const pRegisteredPort,
  432. IHNetCfgMgr * const pHNetCfgMgr,
  433. IHNetConnection * const pHNetConnection,
  434. const BOOL fNoteAddressChange);
  435. HRESULT UnmapPortOnLocalHNetFirewall(CRegisteredPort * const pRegisteredPort,
  436. const BOOL fNeedToDeleteRegValue,
  437. const BOOL fNoteAddressChange);
  438. HRESULT UnmapPortOnLocalHNetFirewallInternal(CRegisteredPort * const pRegisteredPort,
  439. const BOOL fNeedToDeleteRegValue,
  440. IHNetCfgMgr * const pHNetCfgMgr);
  441. HRESULT DisableAllBindingsForHNetPortMappingProtocol(IHNetPortMappingProtocol * const pHNetPortMappingProtocol,
  442. IHNetCfgMgr * const pHNetCfgMgr);
  443. HRESULT CleanupInactiveFirewallMappings(CDevice * const pDevice,
  444. IHNetCfgMgr * const pHNetCfgMgr);
  445. #endif // ! DPNBUILD_NOHNETFWAPI
  446. void RemoveAllItems(void);
  447. CDevice * FindMatchingDevice(const SOCKADDR_IN * const psaddrinMatch,
  448. const BOOL fUseAllInfoSources);
  449. HRESULT ExtendAllExpiringLeases(void);
  450. HRESULT UpdateServerStatus(void);
  451. HRESULT RegisterPreviouslyUnownedPortsWithDevice(CDevice * const pDevice,
  452. const BOOL fWildcardToo);
  453. HRESULT SendUPnPSearchMessagesForDevice(CDevice * const pDevice,
  454. const BOOL fRemoteAllowed);
  455. HRESULT SendUPnPDescriptionRequest(CUPnPDevice * const pUPnPDevice);
  456. HRESULT UpdateUPnPExternalAddress(CUPnPDevice * const pUPnPDevice,
  457. const BOOL fUpdateRegisteredPorts);
  458. HRESULT MapPortsOnUPnPDevice(CUPnPDevice * const pUPnPDevice,
  459. CRegisteredPort * const pRegisteredPort);
  460. HRESULT InternalUPnPQueryAddress(CUPnPDevice * const pUPnPDevice,
  461. const SOCKADDR_IN * const psaddrinQueryAddress,
  462. SOCKADDR_IN * const psaddrinResponseAddress,
  463. const DWORD dwFlags);
  464. HRESULT ExtendUPnPLease(CRegisteredPort * const pRegisteredPort);
  465. HRESULT UnmapUPnPPort(CRegisteredPort * const pRegisteredPort,
  466. const DWORD dwMaxValidPort,
  467. const BOOL fNeedToDeleteRegValue);
  468. HRESULT CleanupInactiveNATMappings(CUPnPDevice * const pUPnPDevice);
  469. BOOL IsNATPublicPortInUseLocally(const WORD wPortHostOrder);
  470. HRESULT CheckForUPnPAnnouncements(const DWORD dwTimeout,
  471. const BOOL fSendRemoteGatewayDiscovery);
  472. HRESULT WaitForUPnPConnectCompletions(void);
  473. HRESULT CheckForReceivedUPnPMsgsOnAllDevices(const DWORD dwTimeout);
  474. HRESULT CheckForReceivedUPnPMsgsOnDevice(CUPnPDevice * const pUPnPDevice,
  475. const DWORD dwTimeout);
  476. HRESULT HandleUPnPDiscoveryResponseMsg(CDevice * const pDevice,
  477. const SOCKADDR_IN * const psaddrinSource,
  478. char * const pcMsg,
  479. const int iMsgSize,
  480. BOOL * const pfInitiatedConnect);
  481. HRESULT ReconnectUPnPControlSocket(CUPnPDevice * const pUPnPDevice);
  482. HRESULT ReceiveUPnPDataStream(CUPnPDevice * const pUPnPDevice);
  483. void ParseUPnPHeaders(char * const pszMsg,
  484. UPNP_HEADER_INFO * pHeaderInfo);
  485. HRESULT GetAddressFromURL(char * const pszLocation,
  486. SOCKADDR_IN * psaddrinLocation,
  487. char ** ppszRelativePath);
  488. HRESULT HandleUPnPDescriptionResponseBody(CUPnPDevice * const pUPnPDevice,
  489. const DWORD dwHTTPResponseCode,
  490. char * const pszDescriptionXML);
  491. HRESULT HandleUPnPControlResponseBody(CUPnPDevice * const pUPnPDevice,
  492. const DWORD dwHTTPResponseCode,
  493. char * const pszControlResponseSOAP);
  494. HRESULT ParseXML(char * const pszXML,
  495. PARSEXML_ELEMENT * const pParseElement,
  496. const PARSECALLBACK ParseCallback,
  497. PVOID pvContext);
  498. static void ParseXMLAttributes(char * const pszString,
  499. char ** const apszAttributeNames,
  500. char ** const apszAttributeValues,
  501. const DWORD dwMaxNumAttributes,
  502. DWORD * const pdwNumAttributes);
  503. BOOL MatchesXMLStringWithoutNamespace(const char * const szCompareString,
  504. const char * const szMatchString,
  505. const PARSEXML_STACKENTRY * const aElementStack,
  506. const PARSEXML_SUBELEMENT * const pSubElement,
  507. const DWORD dwElementStackDepth);
  508. static char * GetStringWithoutNamespacePrefix(const char * const szString,
  509. const PARSEXML_STACKENTRY * const aElementStack,
  510. const PARSEXML_SUBELEMENT * const pSubElement,
  511. const DWORD dwElementStackDepth);
  512. BOOL GetNextChunk(char * const pszBuffer,
  513. const DWORD dwBufferSize,
  514. char ** const ppszChunkData,
  515. DWORD * const pdwChunkSize,
  516. char ** const ppszBufferRemaining,
  517. DWORD * const pdwBufferSizeRemaining);
  518. HRESULT ParseXMLCallback_DescriptionResponse(PARSEXML_ELEMENT * const pParseElement,
  519. PVOID pvContext,
  520. PARSEXML_STACKENTRY * const aElementStack,
  521. BOOL * const pfContinueParsing);
  522. HRESULT ParseXMLCallback_ControlResponse(PARSEXML_ELEMENT * const pParseElement,
  523. PVOID pvContext,
  524. PARSEXML_STACKENTRY * const aElementStack,
  525. BOOL * const pfContinueParsing);
  526. void ClearDevicesUPnPDevice(CDevice * const pDevice);
  527. void ClearAllUPnPRegisteredPorts(CDevice * const pDevice);
  528. #ifndef DPNBUILD_NOWINSOCK2
  529. HRESULT RequestLocalAddressListChangeNotification(void);
  530. #endif // ! DPNBUILD_NOWINSOCK2
  531. SOCKET CreateSocket(SOCKADDR_IN * const psaddrinAddress,
  532. int iType,
  533. int iProtocol);
  534. BOOL GetAddressToReachGateway(CDevice * const pDevice,
  535. IN_ADDR * const pinaddr);
  536. BOOL IsAddressLocal(CDevice * const pDevice,
  537. const SOCKADDR_IN * const psaddrinAddress);
  538. void ExpireOldCachedMappings(void);
  539. #ifdef WINNT
  540. BOOL IsUPnPServiceDisabled(void);
  541. #endif // WINNT
  542. #ifdef DBG
  543. static void PrintUPnPTransactionToFile(const char * const szString,
  544. const int iStringLength,
  545. const char * const szDescription,
  546. CDevice * const pDevice);
  547. #endif // DBG
  548. #ifdef DBG
  549. void DebugPrintCurrentStatus(void);
  550. #ifndef DPNBUILD_NOHNETFWAPI
  551. void DebugPrintActiveFirewallMappings(void);
  552. #endif // ! DPNBUILD_NOHNETFWAPI
  553. void DebugPrintActiveNATMappings(void);
  554. #endif // DBG
  555. };