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.

164 lines
3.9 KiB

  1. #include <pch.h>
  2. #pragma hdrstop
  3. #include <limits.h>
  4. #include <rpcasync.h> // I_RpcExceptionFilter
  5. #include "status.h"
  6. #include "ssdpapi.h"
  7. #include "common.h"
  8. #include "ncdefine.h"
  9. #include "ncdebug.h"
  10. extern LONG cInitialized;
  11. HANDLE WINAPI RegisterService(PSSDP_MESSAGE pSsdpMessage, DWORD flags)
  12. {
  13. PCONTEXT_HANDLE_TYPE phContext = INVALID_HANDLE_VALUE;
  14. unsigned long status;
  15. if (!cInitialized)
  16. {
  17. SetLastError(ERROR_NOT_READY);
  18. return INVALID_HANDLE_VALUE;
  19. }
  20. if (flags > SSDP_SERVICE_PERSISTENT)
  21. {
  22. SetLastError(ERROR_INVALID_PARAMETER);
  23. return INVALID_HANDLE_VALUE;
  24. }
  25. if (pSsdpMessage == NULL)
  26. {
  27. SetLastError(ERROR_INVALID_PARAMETER);
  28. return INVALID_HANDLE_VALUE;
  29. }
  30. if (pSsdpMessage->szUSN == NULL || pSsdpMessage->szType == NULL)
  31. {
  32. SetLastError(ERROR_INVALID_PARAMETER);
  33. return INVALID_HANDLE_VALUE;
  34. }
  35. if (pSsdpMessage->szAltHeaders == NULL && pSsdpMessage->szLocHeader == NULL)
  36. {
  37. SetLastError(ERROR_INVALID_PARAMETER);
  38. return INVALID_HANDLE_VALUE;
  39. }
  40. if (pSsdpMessage->iLifeTime <= 0)
  41. {
  42. SetLastError(ERROR_INVALID_PARAMETER);
  43. return INVALID_HANDLE_VALUE;
  44. }
  45. if (pSsdpMessage->iLifeTime < (2 * (2*RETRY_INTERVAL*(NUM_RETRIES - 1) +
  46. RETRY_INTERVAL)) / 1000)
  47. {
  48. pSsdpMessage->iLifeTime = (2 * (2*RETRY_INTERVAL*(NUM_RETRIES - 1) +
  49. RETRY_INTERVAL)) / 1000;
  50. }
  51. if (pSsdpMessage->iLifeTime > UINT_MAX / 1000)
  52. {
  53. pSsdpMessage->iLifeTime = UINT_MAX / 1000;
  54. }
  55. RpcTryExcept
  56. {
  57. status = RegisterServiceRpc(&phContext, *pSsdpMessage, flags);
  58. ABORT_ON_FAILURE(status);
  59. }
  60. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  61. {
  62. status = RpcExceptionCode();
  63. TraceTag(ttidSsdpCPublish, "Runtime reported exception 0x%lx = %ld", status, status);
  64. goto cleanup;
  65. }
  66. RpcEndExcept
  67. return phContext;
  68. cleanup:
  69. SetLastError(status);
  70. TraceTag(ttidSsdpCPublish, "Non-zero status: 0x%lx = %ld", status, status);
  71. return INVALID_HANDLE_VALUE;
  72. }
  73. BOOL WINAPI DeregisterService(HANDLE hRegister, BOOL fByebye)
  74. {
  75. INT iRetVal;
  76. if (!cInitialized)
  77. {
  78. SetLastError(ERROR_NOT_READY);
  79. return FALSE;
  80. }
  81. if (!hRegister || (INVALID_HANDLE_VALUE == hRegister))
  82. {
  83. SetLastError(ERROR_INVALID_PARAMETER);
  84. return FALSE;
  85. }
  86. RpcTryExcept
  87. {
  88. iRetVal = DeregisterServiceRpc(&hRegister, fByebye);
  89. if (iRetVal != 0)
  90. {
  91. SetLastError(iRetVal);
  92. return FALSE;
  93. }
  94. else
  95. {
  96. return TRUE;
  97. }
  98. }
  99. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  100. {
  101. unsigned long ExceptionCode = RpcExceptionCode();
  102. SetLastError(ExceptionCode);
  103. TraceTag(ttidSsdpCNotify, "DeregisterServiceRpc Runtime reported exception 0x%lx = %ld", ExceptionCode, ExceptionCode);
  104. return FALSE;
  105. }
  106. RpcEndExcept
  107. }
  108. BOOL WINAPI DeregisterServiceByUSN(char * szUSN, BOOL fByebye)
  109. {
  110. INT iRetVal;
  111. if (!cInitialized)
  112. {
  113. SetLastError(ERROR_NOT_READY);
  114. return FALSE;
  115. }
  116. if (szUSN == NULL)
  117. {
  118. SetLastError(ERROR_INVALID_PARAMETER);
  119. return FALSE;
  120. }
  121. RpcTryExcept
  122. {
  123. iRetVal = DeregisterServiceRpcByUSN(szUSN, fByebye);
  124. if (iRetVal != 0)
  125. {
  126. SetLastError(iRetVal);
  127. return FALSE;
  128. }
  129. else
  130. {
  131. return TRUE;
  132. }
  133. }
  134. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  135. {
  136. unsigned long ExceptionCode = RpcExceptionCode();
  137. SetLastError(ExceptionCode);
  138. TraceTag(ttidSsdpCNotify, "DeregisterServiceRpc Runtime reported exception 0x%lx = %ld", ExceptionCode, ExceptionCode);
  139. return FALSE;
  140. }
  141. RpcEndExcept
  142. }