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.

643 lines
23 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2001-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: upnpdevice.h
  6. *
  7. * Content: Header for UPnP device object class.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 02/10/01 VanceO Created.
  13. *
  14. ***************************************************************************/
  15. //=============================================================================
  16. // Defines
  17. //=============================================================================
  18. #define MAX_RECEIVE_BUFFER_SIZE (100 * 1024) // 100 K, must be greater than UPNP_STREAM_RECV_BUFFER_INITIAL_SIZE
  19. //=============================================================================
  20. // Object flags
  21. //=============================================================================
  22. #define UPNPDEVICE_WANPPPCONNECTION 0x01 // flag set if the device is a WANPPPConnection device, not set if it is a WANIPConnection device
  23. #define UPNPDEVICE_CONNECTING 0x02 // flag set while the TCP connection is in progress
  24. #define UPNPDEVICE_CONNECTED 0x04 // flag set once the TCP connection has been established
  25. #define UPNPDEVICE_READY 0x08 // flag set once the device is capable of being used
  26. #define UPNPDEVICE_WAITINGFORCONTROLRESPONSE 0x10 // flag set if some function is waiting for a control response
  27. #define UPNPDEVICE_DOESNOTSUPPORTASYMMETRICMAPPINGS 0x20 // flag set when the device has indicated it does not support asymmetric mappings
  28. #define UPNPDEVICE_DOESNOTSUPPORTLEASEDURATIONS 0x40 // flag set when the device has indicated it does not support non-INFINITE lease durations
  29. #define UPNPDEVICE_USINGCHUNKEDTRANSFERENCODING 0x80 // flag set when device is sending current response using chunked transfer encoding
  30. //=============================================================================
  31. // Macros
  32. //=============================================================================
  33. #define UPNPDEVICE_FROM_BILINK(b) (CONTAINING_OBJECT(b, CUPnPDevice, m_blList))
  34. //=============================================================================
  35. // Enums
  36. //=============================================================================
  37. //
  38. // UPnP expected control response enum
  39. //
  40. typedef enum _CONTROLRESPONSETYPE
  41. {
  42. CONTROLRESPONSETYPE_NONE, // no handler
  43. //CONTROLRESPONSETYPE_QUERYSTATEVARIABLE_EXTERNALIPADDRESS, // use the ExternalIPAddress QueryStateVariable handler
  44. CONTROLRESPONSETYPE_GETEXTERNALIPADDRESS, // use the GetExternalIPAddress handler
  45. CONTROLRESPONSETYPE_ADDPORTMAPPING, // use the AddPortMapping handler
  46. CONTROLRESPONSETYPE_GETSPECIFICPORTMAPPINGENTRY, // use the GetSpecificPortMappingEntry handler
  47. CONTROLRESPONSETYPE_DELETEPORTMAPPING // use the DeletePortMapping handler
  48. } CONTROLRESPONSETYPE;
  49. //=============================================================================
  50. // Structures
  51. //=============================================================================
  52. typedef struct _UPNP_CONTROLRESPONSE_INFO
  53. {
  54. HRESULT hrErrorCode; // error code returned by server
  55. DWORD dwInternalClientV4; // internal client address returned by server
  56. WORD wInternalPort; // internal client port returned by server
  57. DWORD dwExternalIPAddressV4; // external IP address returned by server
  58. } UPNP_CONTROLRESPONSE_INFO, * PUPNP_CONTROLRESPONSE_INFO;
  59. //=============================================================================
  60. // UPnP device object class
  61. //=============================================================================
  62. class CUPnPDevice
  63. {
  64. public:
  65. CUPnPDevice(const DWORD dwID)
  66. {
  67. this->m_blList.Initialize();
  68. this->m_Sig[0] = 'U';
  69. this->m_Sig[1] = 'P';
  70. this->m_Sig[2] = 'D';
  71. this->m_Sig[3] = 'V';
  72. this->m_lRefCount = 1; // whoever got a pointer to this has a reference
  73. this->m_dwFlags = 0;
  74. this->m_dwID = dwID;
  75. this->m_pOwningDevice = NULL;
  76. this->m_pszLocationURL = NULL;
  77. ZeroMemory(&this->m_saddrinHost, sizeof(this->m_saddrinHost));
  78. ZeroMemory(&this->m_saddrinControl, sizeof(this->m_saddrinControl));
  79. this->m_pszUSN = NULL;
  80. this->m_pszServiceControlURL = NULL;
  81. this->m_sControl = INVALID_SOCKET;
  82. this->m_pcReceiveBuffer = NULL;
  83. this->m_dwReceiveBufferSize = 0;
  84. this->m_pcReceiveBufferStart = NULL;
  85. this->m_dwUsedReceiveBufferSize = 0;
  86. this->m_dwRemainingReceiveBufferSize = 0;
  87. this->m_dwExternalIPAddressV4 = 0;
  88. this->m_blCachedMaps.Initialize();
  89. this->m_dwExpectedContentLength = 0;
  90. this->m_dwHTTPResponseCode = 0;
  91. this->m_ControlResponseType = CONTROLRESPONSETYPE_NONE;
  92. this->m_pControlResponseInfo = NULL;
  93. };
  94. #undef DPF_MODNAME
  95. #define DPF_MODNAME "CUPnPDevice::~CUPnPDevice"
  96. ~CUPnPDevice(void)
  97. {
  98. DNASSERT(this->m_blList.IsEmpty());
  99. DNASSERT(this->m_lRefCount == 0);
  100. DNASSERT(this->m_pOwningDevice == NULL);
  101. DNASSERT(this->m_pszLocationURL == NULL);
  102. DNASSERT(this->m_pszUSN == NULL);
  103. DNASSERT(this->m_pszServiceControlURL == NULL);
  104. DNASSERT(this->m_sControl == INVALID_SOCKET);
  105. DNASSERT(this->m_pcReceiveBuffer == NULL);
  106. DNASSERT(this->m_blCachedMaps.IsEmpty());
  107. DNASSERT(this->m_ControlResponseType == CONTROLRESPONSETYPE_NONE);
  108. DNASSERT(this->m_pControlResponseInfo == NULL);
  109. };
  110. inline void AddRef(void) { this->m_lRefCount++; };
  111. #undef DPF_MODNAME
  112. #define DPF_MODNAME "CUPnPDevice::DecRef"
  113. inline void DecRef(void)
  114. {
  115. this->m_lRefCount--;
  116. DNASSERT(this->m_lRefCount >= 0);
  117. if (this->m_lRefCount == 0)
  118. {
  119. delete this;
  120. }
  121. };
  122. inline BOOL IsWANPPPConnection(void) const { return ((this->m_dwFlags & UPNPDEVICE_WANPPPCONNECTION) ? TRUE : FALSE); };
  123. inline BOOL IsConnecting(void) const { return ((this->m_dwFlags & UPNPDEVICE_CONNECTING) ? TRUE : FALSE); };
  124. inline BOOL IsConnected(void) const { return ((this->m_dwFlags & UPNPDEVICE_CONNECTED) ? TRUE : FALSE); };
  125. inline BOOL IsReady(void) const { return ((this->m_dwFlags & UPNPDEVICE_READY) ? TRUE : FALSE); };
  126. inline BOOL DoesNotSupportAsymmetricMappings(void) const { return ((this->m_dwFlags & UPNPDEVICE_DOESNOTSUPPORTASYMMETRICMAPPINGS) ? TRUE : FALSE); };
  127. inline BOOL DoesNotSupportLeaseDurations(void) const { return ((this->m_dwFlags & UPNPDEVICE_DOESNOTSUPPORTLEASEDURATIONS) ? TRUE : FALSE); };
  128. inline BOOL IsUsingChunkedTransferEncoding(void) const { return ((this->m_dwFlags & UPNPDEVICE_USINGCHUNKEDTRANSFERENCODING) ? TRUE : FALSE); };
  129. inline DWORD GetID(void) const { return this->m_dwID; };
  130. inline const char * GetStaticServiceURI(void) const { return ((this->m_dwFlags & UPNPDEVICE_WANPPPCONNECTION) ? URI_SERVICE_WANPPPCONNECTION_A : URI_SERVICE_WANIPCONNECTION_A); };
  131. inline int GetStaticServiceURILength(void) const { return ((this->m_dwFlags & UPNPDEVICE_WANPPPCONNECTION) ? strlen(URI_SERVICE_WANPPPCONNECTION_A) : strlen(URI_SERVICE_WANIPCONNECTION_A)); };
  132. inline SOCKADDR_IN * GetHostAddress(void) { return &this->m_saddrinHost; };
  133. inline SOCKADDR_IN * GetControlAddress(void) { return &this->m_saddrinControl; };
  134. inline SOCKET GetControlSocket(void) const { return this->m_sControl; };
  135. inline DWORD GetExternalIPAddressV4(void) const { return this->m_dwExternalIPAddressV4; };
  136. inline CBilink * GetCachedMaps(void) { return &this->m_blCachedMaps; };
  137. #undef DPF_MODNAME
  138. #define DPF_MODNAME "CUPnPDevice::NoteWANPPPConnection"
  139. inline void NoteWANPPPConnection(void)
  140. {
  141. DNASSERT(! (this->m_dwFlags & UPNPDEVICE_WANPPPCONNECTION));
  142. this->m_dwFlags |= UPNPDEVICE_WANPPPCONNECTION;
  143. };
  144. #undef DPF_MODNAME
  145. #define DPF_MODNAME "CUPnPDevice::NoteConnecting"
  146. inline void NoteConnecting(void)
  147. {
  148. DNASSERT(! (this->m_dwFlags & (UPNPDEVICE_CONNECTING | UPNPDEVICE_CONNECTED)));
  149. this->m_dwFlags |= UPNPDEVICE_CONNECTING;
  150. };
  151. #undef DPF_MODNAME
  152. #define DPF_MODNAME "CUPnPDevice::NoteConnected"
  153. inline void NoteConnected(void)
  154. {
  155. DNASSERT(this->m_dwFlags & UPNPDEVICE_CONNECTING);
  156. DNASSERT(! (this->m_dwFlags & UPNPDEVICE_CONNECTED));
  157. this->m_dwFlags &= ~UPNPDEVICE_CONNECTING;
  158. this->m_dwFlags |= UPNPDEVICE_CONNECTED;
  159. };
  160. #undef DPF_MODNAME
  161. #define DPF_MODNAME "CUPnPDevice::NoteNotConnected"
  162. inline void NoteNotConnected(void)
  163. {
  164. DNASSERT(this->m_dwFlags & UPNPDEVICE_CONNECTED);
  165. this->m_dwFlags &= ~UPNPDEVICE_CONNECTED;
  166. };
  167. #undef DPF_MODNAME
  168. #define DPF_MODNAME "CUPnPDevice::NoteReady"
  169. inline void NoteReady(void)
  170. {
  171. DNASSERT(! (this->m_dwFlags & UPNPDEVICE_READY));
  172. this->m_dwFlags |= UPNPDEVICE_READY;
  173. };
  174. #undef DPF_MODNAME
  175. #define DPF_MODNAME "CUPnPDevice::NoteDoesNotSupportAsymmetricMappings"
  176. inline void NoteDoesNotSupportAsymmetricMappings(void)
  177. {
  178. DNASSERT(! (this->m_dwFlags & UPNPDEVICE_DOESNOTSUPPORTASYMMETRICMAPPINGS));
  179. this->m_dwFlags |= UPNPDEVICE_DOESNOTSUPPORTASYMMETRICMAPPINGS;
  180. };
  181. #undef DPF_MODNAME
  182. #define DPF_MODNAME "CUPnPDevice::NoteDoesNotSupportLeaseDurations"
  183. inline void NoteDoesNotSupportLeaseDurations(void)
  184. {
  185. DNASSERT(! (this->m_dwFlags & UPNPDEVICE_DOESNOTSUPPORTLEASEDURATIONS));
  186. this->m_dwFlags |= UPNPDEVICE_DOESNOTSUPPORTLEASEDURATIONS;
  187. };
  188. #undef DPF_MODNAME
  189. #define DPF_MODNAME "CUPnPDevice::NoteUsingChunkedTransferEncoding"
  190. inline void NoteUsingChunkedTransferEncoding(void)
  191. {
  192. DNASSERT(! (this->m_dwFlags & UPNPDEVICE_USINGCHUNKEDTRANSFERENCODING));
  193. this->m_dwFlags |= UPNPDEVICE_USINGCHUNKEDTRANSFERENCODING;
  194. };
  195. #undef DPF_MODNAME
  196. #define DPF_MODNAME "CUPnPDevice::NoteNotUsingChunkedTransferEncoding"
  197. inline void NoteNotUsingChunkedTransferEncoding(void)
  198. {
  199. DNASSERT(this->m_dwFlags & UPNPDEVICE_USINGCHUNKEDTRANSFERENCODING);
  200. this->m_dwFlags &= ~UPNPDEVICE_USINGCHUNKEDTRANSFERENCODING;
  201. };
  202. inline void SetHostAddress(SOCKADDR_IN * psaddrinHost)
  203. {
  204. CopyMemory(&this->m_saddrinHost, psaddrinHost, sizeof(this->m_saddrinHost));
  205. };
  206. inline void SetControlAddress(SOCKADDR_IN * psaddrinControl)
  207. {
  208. CopyMemory(&this->m_saddrinControl, psaddrinControl, sizeof(this->m_saddrinControl));
  209. };
  210. inline BOOL IsLocal(void) const { return ((this->m_saddrinControl.sin_addr.S_un.S_addr == this->m_pOwningDevice->GetLocalAddressV4()) ? TRUE : FALSE); };
  211. #undef DPF_MODNAME
  212. #define DPF_MODNAME "CUPnPDevice::SetLocationURL"
  213. inline HRESULT SetLocationURL(const char * const szLocationURL)
  214. {
  215. DNASSERT(this->m_pszLocationURL == NULL);
  216. this->m_pszLocationURL = (char*) DNMalloc((strlen(szLocationURL) + 1) * sizeof(char));
  217. if (this->m_pszLocationURL == NULL)
  218. {
  219. return DPNHERR_OUTOFMEMORY;
  220. }
  221. strcpy(this->m_pszLocationURL, szLocationURL);
  222. return DPNH_OK;
  223. };
  224. inline char * GetLocationURL(void) { return this->m_pszLocationURL; };
  225. inline void ClearLocationURL(void)
  226. {
  227. if (this->m_pszLocationURL != NULL)
  228. {
  229. DNFree(this->m_pszLocationURL);
  230. this->m_pszLocationURL = NULL;
  231. }
  232. };
  233. #undef DPF_MODNAME
  234. #define DPF_MODNAME "CUPnPDevice::SetUSN"
  235. inline HRESULT SetUSN(const char * const szUSN)
  236. {
  237. DNASSERT(this->m_pszUSN == NULL);
  238. this->m_pszUSN = (char*) DNMalloc((strlen(szUSN) + 1) * sizeof(char));
  239. if (this->m_pszUSN == NULL)
  240. {
  241. return DPNHERR_OUTOFMEMORY;
  242. }
  243. strcpy(this->m_pszUSN, szUSN);
  244. return DPNH_OK;
  245. };
  246. inline char * GetUSN(void) { return this->m_pszUSN; };
  247. inline void ClearUSN(void)
  248. {
  249. if (this->m_pszUSN != NULL)
  250. {
  251. DNFree(this->m_pszUSN);
  252. this->m_pszUSN = NULL;
  253. }
  254. };
  255. #undef DPF_MODNAME
  256. #define DPF_MODNAME "CUPnPDevice::SetServiceControlURL"
  257. inline HRESULT SetServiceControlURL(const char * const szServiceControlURL)
  258. {
  259. DNASSERT(this->m_pszServiceControlURL == NULL);
  260. this->m_pszServiceControlURL = (char*) DNMalloc((strlen(szServiceControlURL) + 1) * sizeof(char));
  261. if (this->m_pszServiceControlURL == NULL)
  262. {
  263. return DPNHERR_OUTOFMEMORY;
  264. }
  265. strcpy(this->m_pszServiceControlURL, szServiceControlURL);
  266. return DPNH_OK;
  267. };
  268. inline char * GetServiceControlURL(void) { return this->m_pszServiceControlURL; };
  269. inline void ClearServiceControlURL(void)
  270. {
  271. if (this->m_pszServiceControlURL != NULL)
  272. {
  273. DNFree(this->m_pszServiceControlURL);
  274. this->m_pszServiceControlURL = NULL;
  275. }
  276. };
  277. inline void SetControlSocket(SOCKET sControl) { this->m_sControl = sControl; };
  278. //
  279. // You must have global object lock to call this function.
  280. //
  281. #undef DPF_MODNAME
  282. #define DPF_MODNAME "CUPnPDevice::MakeDeviceOwner"
  283. inline void MakeDeviceOwner(CDevice * const pDevice)
  284. {
  285. DNASSERT(pDevice != NULL);
  286. DNASSERT(pDevice->GetUPnPDevice() == NULL);
  287. DNASSERT(this->m_pOwningDevice == NULL);
  288. this->m_pOwningDevice = pDevice;
  289. this->AddRef();
  290. pDevice->SetUPnPDevice(this);
  291. };
  292. //
  293. // You must have global object lock to call this function.
  294. //
  295. inline CDevice * GetOwningDevice(void) { return this->m_pOwningDevice; };
  296. //
  297. // You must have global object lock to call this function.
  298. //
  299. #undef DPF_MODNAME
  300. #define DPF_MODNAME "CUPnPDevice::ClearDeviceOwner"
  301. inline void ClearDeviceOwner(void)
  302. {
  303. DNASSERT(this->m_pOwningDevice != NULL);
  304. DNASSERT(this->m_pOwningDevice->GetUPnPDevice() == this);
  305. this->m_pOwningDevice->SetUPnPDevice(NULL);
  306. this->m_pOwningDevice = NULL;
  307. this->DecRef();
  308. };
  309. #undef DPF_MODNAME
  310. #define DPF_MODNAME "CUPnPDevice::CreateReceiveBuffer"
  311. inline HRESULT CreateReceiveBuffer(const DWORD dwSize)
  312. {
  313. DNASSERT(this->m_pcReceiveBuffer == NULL);
  314. this->m_pcReceiveBuffer = (char*) DNMalloc(dwSize);
  315. if (this->m_pcReceiveBuffer == NULL)
  316. {
  317. return DPNHERR_OUTOFMEMORY;
  318. }
  319. this->m_dwReceiveBufferSize = dwSize;
  320. this->m_pcReceiveBufferStart = this->m_pcReceiveBuffer;
  321. this->m_dwRemainingReceiveBufferSize = dwSize;
  322. return DPNH_OK;
  323. };
  324. #undef DPF_MODNAME
  325. #define DPF_MODNAME "CUPnPDevice::IncreaseReceiveBufferSize"
  326. inline HRESULT IncreaseReceiveBufferSize(void)
  327. {
  328. DWORD dwNewBufferSize;
  329. char * pcTemp;
  330. DNASSERT(this->m_pcReceiveBuffer != NULL);
  331. //
  332. // Double the buffer size. Don't let the receive buffer get to
  333. // unrealistic sizes to prevent DoS/resource issues, cap the buffer
  334. // size, and if we've already reached that limit, fail.
  335. //
  336. dwNewBufferSize = this->m_dwReceiveBufferSize * 2;
  337. if (dwNewBufferSize > MAX_RECEIVE_BUFFER_SIZE)
  338. {
  339. dwNewBufferSize = MAX_RECEIVE_BUFFER_SIZE;
  340. if (dwNewBufferSize <= this->m_dwReceiveBufferSize)
  341. {
  342. DPFX(DPFPREP, 0, "Maximum buffer size reached (%u bytes), not allocating more room!",
  343. this->m_dwReceiveBufferSize);
  344. return DPNHERR_OUTOFMEMORY;
  345. }
  346. }
  347. pcTemp = (char*) DNMalloc(dwNewBufferSize);
  348. if (pcTemp == NULL)
  349. {
  350. return DPNHERR_OUTOFMEMORY;
  351. }
  352. //
  353. // If the buffer already had data in it, copy it. The data may not
  354. // have come from the front of the old buffer, but it will
  355. // definitely be the front of the new one.
  356. //
  357. if (this->m_dwUsedReceiveBufferSize > 0)
  358. {
  359. CopyMemory(pcTemp, this->m_pcReceiveBufferStart,
  360. this->m_dwUsedReceiveBufferSize);
  361. }
  362. DNFree(this->m_pcReceiveBuffer);
  363. this->m_pcReceiveBuffer = NULL;
  364. this->m_pcReceiveBuffer = pcTemp;
  365. this->m_dwReceiveBufferSize = dwNewBufferSize;
  366. //
  367. // The buffer now starts at the beginning of the allocated memory
  368. // (we may have just freed up a bunch of wasted space).
  369. //
  370. this->m_pcReceiveBufferStart = this->m_pcReceiveBuffer;
  371. this->m_dwRemainingReceiveBufferSize = this->m_dwReceiveBufferSize - this->m_dwUsedReceiveBufferSize;
  372. return DPNH_OK;
  373. };
  374. #undef DPF_MODNAME
  375. #define DPF_MODNAME "CUPnPDevice::UpdateUsedReceiveBufferSize"
  376. inline void UpdateUsedReceiveBufferSize(const DWORD dwAdditionalSizeUsed)
  377. {
  378. DNASSERT(dwAdditionalSizeUsed <= this->m_dwRemainingReceiveBufferSize);
  379. DNASSERT((this->m_dwUsedReceiveBufferSize + dwAdditionalSizeUsed) <= this->m_dwReceiveBufferSize);
  380. this->m_dwUsedReceiveBufferSize += dwAdditionalSizeUsed;
  381. this->m_dwRemainingReceiveBufferSize -= dwAdditionalSizeUsed;
  382. };
  383. inline void ClearReceiveBuffer(void)
  384. {
  385. this->m_pcReceiveBufferStart = this->m_pcReceiveBuffer;
  386. this->m_dwUsedReceiveBufferSize = 0;
  387. this->m_dwRemainingReceiveBufferSize = this->m_dwReceiveBufferSize;
  388. };
  389. inline char * GetReceiveBufferStart(void) { return this->m_pcReceiveBufferStart; };
  390. inline char * GetCurrentReceiveBufferPtr(void) { return (this->m_pcReceiveBufferStart + this->m_dwUsedReceiveBufferSize); };
  391. inline DWORD GetUsedReceiveBufferSize(void) const { return this->m_dwUsedReceiveBufferSize; };
  392. inline DWORD GetRemainingReceiveBufferSize(void) const { return this->m_dwRemainingReceiveBufferSize; };
  393. #undef DPF_MODNAME
  394. #define DPF_MODNAME "CUPnPDevice::UpdateReceiveBufferStart"
  395. inline void UpdateReceiveBufferStart(char * pszNewStart)
  396. {
  397. DNASSERT(pszNewStart > this->m_pcReceiveBufferStart);
  398. DNASSERT((DWORD) ((DWORD_PTR) (pszNewStart - this->m_pcReceiveBufferStart)) < this->m_dwRemainingReceiveBufferSize);
  399. this->m_dwUsedReceiveBufferSize -= (DWORD) ((DWORD_PTR) (pszNewStart - this->m_pcReceiveBufferStart));
  400. this->m_pcReceiveBufferStart = pszNewStart;
  401. };
  402. inline void DestroyReceiveBuffer(void)
  403. {
  404. if (this->m_pcReceiveBuffer != NULL)
  405. {
  406. DNFree(this->m_pcReceiveBuffer);
  407. this->m_pcReceiveBuffer = NULL;
  408. this->m_dwReceiveBufferSize = 0;
  409. this->m_pcReceiveBufferStart = NULL;
  410. this->m_dwUsedReceiveBufferSize = 0;
  411. this->m_dwRemainingReceiveBufferSize = 0;
  412. }
  413. };
  414. inline void SetExternalIPAddressV4(const DWORD dwExternalIPAddressV4)
  415. {
  416. this->m_dwExternalIPAddressV4 = dwExternalIPAddressV4;
  417. };
  418. #undef DPF_MODNAME
  419. #define DPF_MODNAME "CUPnPDevice::RemoveAllCachedMappings"
  420. inline void RemoveAllCachedMappings(void)
  421. {
  422. CBilink * pCachedMaps;
  423. CBilink * pBilink;
  424. CCacheMap * pCacheMap;
  425. pCachedMaps = this->GetCachedMaps();
  426. pBilink = pCachedMaps->GetNext();
  427. while (pBilink != pCachedMaps)
  428. {
  429. DNASSERT(! pBilink->IsEmpty());
  430. pCacheMap = CACHEMAP_FROM_BILINK(pBilink);
  431. pBilink = pBilink->GetNext();
  432. DPFX(DPFPREP, 5, "Removing UPnP device 0x%p cached mapping 0x%p.",
  433. this, pCacheMap);
  434. pCacheMap->m_blList.RemoveFromList();
  435. delete pCacheMap;
  436. }
  437. };
  438. #undef DPF_MODNAME
  439. #define DPF_MODNAME "CUPnPDevice::NoteWaitingForContent"
  440. inline void NoteWaitingForContent(const DWORD dwContentLength, const DWORD dwHTTPResponseCode)
  441. {
  442. DNASSERT(this->m_dwExpectedContentLength == 0);
  443. this->m_dwExpectedContentLength = dwContentLength;
  444. this->m_dwHTTPResponseCode = dwHTTPResponseCode;
  445. };
  446. #undef DPF_MODNAME
  447. #define DPF_MODNAME "CUPnPDevice::NoteNotWaitingForContent"
  448. inline void NoteNotWaitingForContent(void)
  449. {
  450. DNASSERT(this->m_dwExpectedContentLength != 0);
  451. this->m_dwExpectedContentLength = 0;
  452. this->m_dwHTTPResponseCode = 0;
  453. };
  454. inline BOOL IsWaitingForContent(void) const { return ((this->m_dwExpectedContentLength != 0) ? TRUE : FALSE); };
  455. inline DWORD GetExpectedContentSize(void) const { return this->m_dwExpectedContentLength; };
  456. inline DWORD GetHTTPResponseCode(void) const { return this->m_dwHTTPResponseCode; };
  457. #undef DPF_MODNAME
  458. #define DPF_MODNAME "CUPnPDevice::StartWaitingForControlResponse"
  459. inline void StartWaitingForControlResponse(CONTROLRESPONSETYPE ControlResponseType,
  460. PUPNP_CONTROLRESPONSE_INFO pControlResponseInfo)
  461. {
  462. DNASSERT(ControlResponseType != CONTROLRESPONSETYPE_NONE);
  463. DNASSERT(! (this->m_dwFlags & UPNPDEVICE_WAITINGFORCONTROLRESPONSE));
  464. this->m_dwFlags |= UPNPDEVICE_WAITINGFORCONTROLRESPONSE;
  465. this->m_ControlResponseType = ControlResponseType;
  466. this->m_pControlResponseInfo = pControlResponseInfo;
  467. };
  468. #undef DPF_MODNAME
  469. #define DPF_MODNAME "CUPnPDevice::StopWaitingForControlResponse"
  470. inline void StopWaitingForControlResponse(void)
  471. {
  472. this->m_dwFlags &= ~UPNPDEVICE_WAITINGFORCONTROLRESPONSE;
  473. this->m_ControlResponseType = CONTROLRESPONSETYPE_NONE;
  474. this->m_pControlResponseInfo = NULL;
  475. };
  476. inline BOOL IsWaitingForControlResponse(void) const { return ((this->m_dwFlags & UPNPDEVICE_WAITINGFORCONTROLRESPONSE) ? TRUE : FALSE); };
  477. inline CONTROLRESPONSETYPE GetControlResponseType(void) const { return this->m_ControlResponseType; };
  478. inline PUPNP_CONTROLRESPONSE_INFO GetControlResponseInfo(void) { return this->m_pControlResponseInfo; };
  479. CBilink m_blList; // list of all the UPnP devices known
  480. private:
  481. BYTE m_Sig[4]; // debugging signature ('UPDV')
  482. LONG m_lRefCount; // reference count for this object
  483. DWORD m_dwFlags; // flags indicating current state of UPnP device
  484. DWORD m_dwID; // unique identifier used to correlate crash registry entries with UPnP devices
  485. CDevice * m_pOwningDevice; // pointer to owning device object
  486. char * m_pszLocationURL; // control location URL string
  487. SOCKADDR_IN m_saddrinHost; // UPnP device host address
  488. SOCKADDR_IN m_saddrinControl; // UPnP device control address
  489. char * m_pszUSN; // device's Unique Service Name
  490. char * m_pszServiceControlURL; // URL used to control WANIPConnectionService
  491. SOCKET m_sControl; // TCP socket with connection to the UPnP device
  492. char * m_pcReceiveBuffer; // pointer to receive buffer
  493. DWORD m_dwReceiveBufferSize; // size of receive buffer
  494. char * m_pcReceiveBufferStart; // pointer to start of actual data in receive buffer (anything before this is just wasted space)
  495. DWORD m_dwUsedReceiveBufferSize; // size of receive buffer actually filled with data (beginning at m_pcReceiveBufferStart)
  496. DWORD m_dwRemainingReceiveBufferSize; // size of receive buffer that can hold more data (after m_pcReceiveBufferStart + m_dwUsedReceiveBufferSize)
  497. DWORD m_dwExternalIPAddressV4; // IP v4 external IP address of this UPnP device
  498. CBilink m_blCachedMaps; // list of cached mappings for query addresses performed on this UPnP device
  499. DWORD m_dwExpectedContentLength; // expected size of message content, or 0 if no headers have been read
  500. DWORD m_dwHTTPResponseCode; // HTTP response code previously parsed, if waiting for content
  501. CONTROLRESPONSETYPE m_ControlResponseType; // type of response expected
  502. PUPNP_CONTROLRESPONSE_INFO m_pControlResponseInfo; // place to store info from a received response
  503. };