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.

144 lines
4.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: N C I N F . C P P
  7. //
  8. // Contents: ???
  9. //
  10. // Notes:
  11. //
  12. // Author: ???
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.h>
  16. #pragma hdrstop
  17. #include "ncinf.h"
  18. #include "ncsetup.h"
  19. #include "ncstring.h"
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Function: HrProcessInfExtension
  23. //
  24. // Purpose: Given the appropriate keywords, returns information about an
  25. // INF file that contains extended commands to add and remove
  26. // fixed components such as WinSock or SNMP Agent support.
  27. //
  28. // Arguments:
  29. // hinfInstallFile [in] The handle to the inf file to install
  30. // from
  31. // pszSectionName [in] The Base install section name.
  32. // pszSuffix [in] Suffix to append to base. (i.e. "Winsock")
  33. // pszAddLabel [in] Label for Add command (i.e. "AddSock")
  34. // pszRemoveLabel [in] Label for Remove command (i.e. "DelSock")
  35. // pfnHrAdd [in] Callback function to be called when adding.
  36. // pfnHrRemove [in] Callback function to be called when removing.
  37. //
  38. // Returns: HRESULT, S_OK on success
  39. //
  40. // Author: danielwe 27 Apr 1997
  41. //
  42. // Notes:
  43. //
  44. HRESULT
  45. HrProcessInfExtension (
  46. IN HINF hinfInstallFile,
  47. IN PCWSTR pszSectionName,
  48. IN PCWSTR pszSuffix,
  49. IN PCWSTR pszAddLabel,
  50. IN PCWSTR pszRemoveLabel,
  51. IN PFNADDCALLBACK pfnHrAdd,
  52. IN PFNREMOVECALLBACK pfnHrRemove)
  53. {
  54. Assert(IsValidHandle(hinfInstallFile));
  55. BOOL fAdd;
  56. HRESULT hr = S_OK;
  57. tstring strSectionName;
  58. INFCONTEXT infContext;
  59. WCHAR szCmd[LINE_LEN]; // LINE_LEN defined in setupapi.h as 256
  60. // Construct the section name for which we're looking
  61. // (ie. "Inst_Section.Winsock")
  62. strSectionName = pszSectionName;
  63. strSectionName += L".";
  64. strSectionName += pszSuffix;
  65. // Loop over the elements of the section and process the
  66. // appropriate AddSock/DelSock sections found
  67. hr = HrSetupFindFirstLine(hinfInstallFile, strSectionName.c_str(),
  68. NULL, &infContext);
  69. if (S_OK == hr)
  70. {
  71. tstring strName;
  72. do
  73. {
  74. // Retrieve a line from the section, hopefully in the format:
  75. // AddSock=section_name or DelSock=section_name
  76. hr = HrSetupGetStringField(infContext, 0, szCmd, celems(szCmd),
  77. NULL);
  78. if (FAILED(hr))
  79. {
  80. goto Done;
  81. }
  82. // Check for the <add> or <remove> command
  83. szCmd[celems(szCmd)-1] = L'\0';
  84. if (!lstrcmpiW(szCmd, pszAddLabel))
  85. {
  86. fAdd = TRUE;
  87. }
  88. else if (!lstrcmpiW(szCmd, pszRemoveLabel))
  89. {
  90. fAdd = FALSE;
  91. }
  92. else
  93. {
  94. continue; // Other things are in this install section
  95. }
  96. // Query the Add/Remove value from the .inf
  97. hr = HrSetupGetStringField(infContext, 1, &strName);
  98. if (S_OK == hr)
  99. {
  100. if (fAdd)
  101. {
  102. // Call Add callback
  103. hr = pfnHrAdd(hinfInstallFile, strName.c_str());
  104. }
  105. else
  106. {
  107. // Call remove callback
  108. hr = pfnHrRemove(hinfInstallFile, strName.c_str());
  109. }
  110. if (FAILED(hr))
  111. {
  112. goto Done;
  113. }
  114. }
  115. else
  116. {
  117. goto Done;
  118. }
  119. }
  120. while (S_OK == (hr = HrSetupFindNextLine(infContext, &infContext)));
  121. }
  122. if (hr == S_FALSE)
  123. {
  124. // S_FALSE will terminate the loop successfully, so convert it to S_OK
  125. // here.
  126. hr = S_OK;
  127. }
  128. Done:
  129. TraceHr (ttidError, FAL, hr, (SPAPI_E_LINE_NOT_FOUND == hr),
  130. "HrProcessInfExtension");
  131. return hr;
  132. }