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.

224 lines
6.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: S E R V I C E . C P P
  7. //
  8. // Contents: Functions dealing with UPnP services.
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 28 Oct 1999
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "oleauto.h"
  18. #include "ncbase.h"
  19. #include "updiagp.h"
  20. #include "ncinet.h"
  21. BOOL DoListServices(DWORD iCmd, DWORD cArgs, LPTSTR *rgArgs)
  22. {
  23. if (g_ctx.ectx == CTX_CD)
  24. {
  25. DWORD isvc;
  26. _tprintf(TEXT("Listing all Services within %s\n"), PDevCur()->szFriendlyName);
  27. _tprintf(TEXT("------------------------------\n"));
  28. for (isvc = 0; isvc < PDevCur()->cSvcs; isvc++)
  29. {
  30. _tprintf(TEXT("%d) %s\n"), isvc + 1,
  31. PDevCur()->rgSvcs[isvc]->szServiceType);
  32. }
  33. _tprintf(TEXT("------------------------------\n\n"));
  34. }
  35. return FALSE;
  36. }
  37. BOOL DoSwitchSvc(DWORD iCmd, DWORD cArgs, LPTSTR *rgArgs)
  38. {
  39. if (g_ctx.ectx == CTX_CD)
  40. {
  41. if (cArgs == 2)
  42. {
  43. DWORD isvc;
  44. isvc = _tcstoul(rgArgs[1], NULL, 10);
  45. if (isvc &&
  46. isvc <= PDevCur()->cSvcs &&
  47. PDevCur()->rgSvcs[isvc - 1])
  48. {
  49. g_ctx.psvcCur = PDevCur()->rgSvcs[isvc - 1];
  50. g_ctx.ectx = CTX_CD_SVC;
  51. }
  52. else
  53. {
  54. _tprintf(TEXT("%d is not a valid Service index!\n"), isvc);
  55. }
  56. }
  57. else
  58. {
  59. Usage(iCmd);
  60. }
  61. }
  62. return FALSE;
  63. }
  64. VOID CleanupService(UPNPSVC *psvc)
  65. {
  66. if (psvc->hSvc)
  67. {
  68. if (DeregisterService(psvc->hSvc, TRUE))
  69. {
  70. TraceTag(ttidUpdiag, "Successfully deregistered %s as a service.",
  71. psvc->szServiceType);
  72. }
  73. else
  74. {
  75. TraceTag(ttidUpdiag, "Error %d deregistering %s as a service.",
  76. GetLastError(), psvc->szServiceType);
  77. }
  78. CHAR szEvtUrl[INTERNET_MAX_URL_LENGTH];
  79. HRESULT hr;
  80. LPSTR pszEvtUrl = SzFromTsz(psvc->szEvtUrl);
  81. if (pszEvtUrl)
  82. {
  83. hr = HrGetRequestUriA(pszEvtUrl,
  84. INTERNET_MAX_URL_LENGTH,
  85. szEvtUrl);
  86. if (SUCCEEDED(hr))
  87. {
  88. if (DeregisterUpnpEventSource(szEvtUrl))
  89. {
  90. TraceTag(ttidUpdiag, "Successfully deregistered %s as an event source.",
  91. psvc->szEvtUrl);
  92. }
  93. else
  94. {
  95. TraceTag(ttidUpdiag, "Error %d deregistering %s as an event source.\n",
  96. GetLastError(), psvc->szEvtUrl);
  97. }
  98. }
  99. TraceError("CleanupService: HrGetRequestUri", hr);
  100. delete [] pszEvtUrl;
  101. }
  102. else
  103. {
  104. TraceTag(ttidUpdiag, "CleanupService: TszToSz failed");
  105. }
  106. }
  107. delete psvc;
  108. }
  109. // print current service state table values
  110. BOOL DoPrintSST(DWORD iCmd, DWORD cArgs, LPTSTR *rgArgs)
  111. {
  112. HRESULT hr;
  113. Assert(g_ctx.ectx == CTX_CD_SVC);
  114. UPNPSVC * psvc = g_ctx.psvcCur;
  115. _tprintf(TEXT("Service State Table: \n"));
  116. _tprintf(TEXT("----------------------------------------------------\n"));
  117. for (DWORD iRow = 0; iRow < psvc->sst.cRows; iRow++)
  118. {
  119. SST_ROW * pRow = &psvc->sst.rgRows[iRow];
  120. VARIANT varDest;
  121. VariantInit(&varDest);
  122. hr = VariantChangeType(&varDest, &(pRow->varValue), 0, VT_BSTR);
  123. if (SUCCEEDED(hr))
  124. {
  125. _tprintf(TEXT("%d) %s = %S "), iRow + 1,
  126. psvc->sst.rgRows[iRow].szPropName, varDest.bstrVal);
  127. VariantClear(&varDest);
  128. if (*pRow->mszAllowedValueList)
  129. {
  130. _tprintf(TEXT(", Allowed Value List: "));
  131. TCHAR * pNextString = pRow->mszAllowedValueList;
  132. while (*pNextString)
  133. {
  134. _tprintf(TEXT("%s"), pNextString);
  135. pNextString += lstrlen(pNextString);
  136. pNextString ++;
  137. if (*pNextString)
  138. _tprintf(TEXT(","));
  139. }
  140. }
  141. else if (*pRow->szMin)
  142. {
  143. _tprintf(TEXT(", Min: %s, Max: %s, Step: %s"),
  144. pRow->szMin, pRow->szMax, pRow->szStep);
  145. }
  146. }
  147. _tprintf(TEXT("\n"));
  148. }
  149. _tprintf(TEXT("----------------------------------------------------\n\n"));
  150. return FALSE;
  151. }
  152. // print current service state table values
  153. BOOL DoPrintActionSet(DWORD iCmd, DWORD cArgs, LPTSTR *rgArgs)
  154. {
  155. Assert(g_ctx.ectx == CTX_CD_SVC);
  156. UPNPSVC * psvc = g_ctx.psvcCur;
  157. _tprintf(TEXT("Service Action Set: \n"));
  158. _tprintf(TEXT("----------------------------------------------------\n"));
  159. for (DWORD iAct = 0; iAct < psvc->action_set.cActions; iAct++)
  160. {
  161. _tprintf(TEXT("%d) %s:\n"), iAct+1,
  162. psvc->action_set.rgActions[iAct].szActionName);
  163. for (DWORD iOpt =0; iOpt<psvc->action_set.rgActions[iAct].cOperations; iOpt++)
  164. {
  165. OPERATION_DATA * pOptData = &psvc->action_set.rgActions[iAct].rgOperations[iOpt];
  166. _tprintf(TEXT("Name = %s, Variable = %s"), pOptData->szOpName, pOptData->szVariableName);
  167. TCHAR * szConst = pOptData->mszConstantList;
  168. if (*szConst)
  169. {
  170. _tprintf(TEXT(", Constants = "));
  171. while (*szConst)
  172. {
  173. _tprintf(TEXT("%s"), szConst);
  174. szConst += lstrlen(szConst);
  175. szConst++;
  176. if (*szConst)
  177. _tprintf(TEXT(", "));
  178. }
  179. }
  180. _tprintf(TEXT("\n"));
  181. }
  182. _tprintf(TEXT("\n"));
  183. }
  184. _tprintf(TEXT("----------------------------------------------------\n\n"));
  185. return FALSE;
  186. }