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.

148 lines
2.9 KiB

  1. #pragma once
  2. #include "pch.h"
  3. #pragma hdrstop
  4. #include "winsock2.h"
  5. #include "util.h"
  6. HRESULT SetUPnPError(LPOLESTR pszError)
  7. {
  8. HRESULT hr = S_OK;
  9. ICreateErrorInfo* pCreateErrorInfo;
  10. hr = CreateErrorInfo(&pCreateErrorInfo);
  11. if(SUCCEEDED(hr))
  12. {
  13. hr = pCreateErrorInfo->SetSource(pszError);
  14. if(SUCCEEDED(hr))
  15. {
  16. IErrorInfo* pErrorInfo;
  17. hr = pCreateErrorInfo->QueryInterface(IID_IErrorInfo, reinterpret_cast<void**>(&pErrorInfo));
  18. if(SUCCEEDED(hr))
  19. {
  20. hr = SetErrorInfo(0, pErrorInfo);
  21. pErrorInfo->Release();
  22. }
  23. }
  24. pCreateErrorInfo->Release();
  25. }
  26. return hr;
  27. }
  28. DWORD WINAPI
  29. INET_ADDR(LPCWSTR szAddressW)
  30. //
  31. // The 3 "." testing is for the sole purpose of preventing computer
  32. // names with digits to be catched appropriately.
  33. // so we strictly assume a valid IP is number.number.number.number
  34. //
  35. {
  36. CHAR szAddressA[16];
  37. int iCount = 0;
  38. LPCWSTR tmp = szAddressW;
  39. // Check wether it is a non-shortcut IPs.
  40. while(tmp = wcschr(tmp, L'.'))
  41. { tmp++; iCount++; }
  42. if ( iCount < 3)
  43. { return INADDR_NONE; }
  44. wcstombs(szAddressA, szAddressW, 16);
  45. return inet_addr(szAddressA);
  46. }
  47. WCHAR * WINAPI
  48. INET_NTOW( ULONG addr )
  49. {
  50. struct in_addr dwAddress;
  51. static WCHAR szAddress[16];
  52. dwAddress.S_un.S_addr = addr;
  53. char* pAddr = inet_ntoa(*(struct in_addr *) &dwAddress);
  54. if (pAddr)
  55. {
  56. // mbstowcs(szAddress, inet_ntoa(*(struct in_addr *)&dwAddress), 16);
  57. MultiByteToWideChar(CP_ACP, 0, pAddr, -1, szAddress, 16);
  58. return szAddress;
  59. }
  60. else
  61. return NULL;
  62. }
  63. WCHAR * WINAPI
  64. INET_NTOW_TS( ULONG addr )
  65. {
  66. WCHAR* retString = NULL;
  67. CHAR* asciiString = NULL;
  68. struct in_addr dwAddress;
  69. dwAddress.S_un.S_addr = addr;
  70. retString = (WCHAR*)CoTaskMemAlloc( 16 * sizeof(WCHAR) );
  71. if ( NULL == retString )
  72. {
  73. return NULL;
  74. }
  75. //
  76. // note that inet_nota is thread safe
  77. // altough it uses static buffer
  78. //
  79. asciiString = inet_ntoa( dwAddress);
  80. if (asciiString != NULL)
  81. {
  82. MultiByteToWideChar(CP_ACP, 0, asciiString, -1, retString, 16);
  83. return retString;
  84. }
  85. return NULL;
  86. }
  87. CSwitchSecurityContext::CSwitchSecurityContext( )
  88. :m_pOldCtx( NULL )
  89. {
  90. HRESULT hr;
  91. hr = CoSwitchCallContext( NULL, &m_pOldCtx );
  92. _ASSERT( SUCCEEDED(hr) );
  93. _ASSERT( NULL != m_pOldCtx );
  94. }
  95. CSwitchSecurityContext::~CSwitchSecurityContext( )
  96. {
  97. HRESULT hr;
  98. IUnknown * pGarb;
  99. _ASSERT( NULL != m_pOldCtx );
  100. hr = CoSwitchCallContext( m_pOldCtx, &pGarb );
  101. _ASSERT( SUCCEEDED(hr) );
  102. //
  103. // m_pOldCtx->Release();
  104. // and pGarb->Release();
  105. // Should not be released
  106. // Documentation is flawed; the interface is not
  107. // a COM interface actually
  108. //
  109. };