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.

238 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name :
  4. funcdict.cxx
  5. Abstract:
  6. Class that contains all the methods used by the .inf file
  7. Author:
  8. Christopher Achille (cachille)
  9. Project:
  10. Internet Services Setup
  11. Revision History:
  12. June 2001: Created
  13. --*/
  14. #include "stdafx.h"
  15. #include "iadm.h"
  16. #include "iiscnfgp.h"
  17. #include "mdkey.h"
  18. #include "mdentry.h"
  19. #include "metabase.hxx"
  20. #include "reg.hxx"
  21. #include "xmlupgrade.hxx"
  22. #include "common.hxx"
  23. // Constructor
  24. //
  25. // Initialize Everything
  26. //
  27. CFunctionDictionary::CFunctionDictionary()
  28. {
  29. m_bFunctionsLoaded = FALSE;
  30. InitializeFunctions();
  31. }
  32. // Destructor
  33. //
  34. // Clean up memory
  35. CFunctionDictionary::~CFunctionDictionary()
  36. {
  37. DeleteFunctions();
  38. }
  39. // function: DeleteFunctions
  40. //
  41. // Delete all of the functions that are defined
  42. //
  43. void
  44. CFunctionDictionary::DeleteFunctions()
  45. {
  46. DWORD i;
  47. // Delete all functions
  48. for (i = 0; i < DICTIONARY_MAXFUNCTIONS; i++)
  49. {
  50. if ( m_pDict[i] )
  51. {
  52. delete (m_pDict[i]);
  53. }
  54. m_pDict[i] = NULL;
  55. }
  56. m_dwFunctions = 0;
  57. m_bFunctionsLoaded = FALSE;
  58. }
  59. // function: InitializeFunction
  60. //
  61. // Initiliaze all of the functions to NULL
  62. //
  63. void
  64. CFunctionDictionary::InitializeFunctions()
  65. {
  66. DWORD i;
  67. m_dwFunctions = 0;
  68. // Initialize all to NULL
  69. for (i = 0; i < DICTIONARY_MAXFUNCTIONS; i++)
  70. {
  71. m_pDict[i] = NULL;
  72. }
  73. }
  74. // function: LoadFunction
  75. //
  76. // Loads all of the functions that we know about into our list
  77. //
  78. // Return Values:
  79. // TRUE - They loaded successfully
  80. // FALSE - They did not load successully
  81. BOOL
  82. CFunctionDictionary::LoadFunctions()
  83. {
  84. DWORD dwNum = 0;
  85. DWORD i;
  86. BOOL bRet = TRUE;
  87. // Initlize the functions to NULL
  88. InitializeFunctions();
  89. // Create all of the pointers for the classes here
  90. m_pDict[dwNum++] = new (CRegistry_MoveValue);
  91. // m_pDict[dwNum++] = new (CRegistry_SetValue);
  92. m_pDict[dwNum++] = new (CRegistry_DeleteKey);
  93. m_pDict[dwNum++] = new (CMetaBase_SetValue);
  94. m_pDict[dwNum++] = new (CMetaBase_IsAnotherSiteonPort80);
  95. m_pDict[dwNum++] = new (CMetaBase_VerifyValue);
  96. m_pDict[dwNum++] = new (CMetaBase_DelIDOnEverySite);
  97. m_pDict[dwNum++] = new (CIsUpgrade);
  98. m_pDict[dwNum++] = new (CMetaBase_ImportRestrictionList);
  99. m_pDict[dwNum++] = new (CMetaBase_UpdateCustomDescList);
  100. m_pDict[dwNum++] = new (CXML_Metabase_Upgrade);
  101. m_pDict[dwNum++] = new (CXML_Metabase_VerifyVersion);
  102. m_pDict[dwNum++] = new (CXML_MBSchema_Upgrade);
  103. m_pDict[dwNum++] = new (CXML_MBSchema_VerifyVersion);
  104. m_pDict[dwNum++] = new (CFileSys_AddAcl);
  105. m_pDict[dwNum++] = new (CFileSys_RemoveAcl);
  106. m_pDict[dwNum++] = new (CFileSys_SetAcl);
  107. // ...
  108. // Make sure that we did not go over our function size limit
  109. ASSERT(dwNum <= DICTIONARY_MAXFUNCTIONS);
  110. // Make sure that they all loaded correctly
  111. for (i = 0; i < dwNum; i++)
  112. {
  113. if ( !m_pDict[i] )
  114. {
  115. bRet = FALSE;
  116. break;
  117. }
  118. }
  119. if ( bRet )
  120. {
  121. // We successfully created all the functions
  122. m_dwFunctions = dwNum;
  123. m_bFunctionsLoaded = TRUE;
  124. return TRUE;
  125. }
  126. // Since we failed, release all the pointers
  127. DeleteFunctions();
  128. return FALSE;
  129. }
  130. // function: FindFunction
  131. //
  132. // Find a function in the table, given its name
  133. //
  134. // Parameters:
  135. // szFunctionName - The name of the function
  136. //
  137. // Return:
  138. // NULL - Could not find function
  139. // pointer - pointer to the class for that function
  140. //
  141. CBaseFunction *
  142. CFunctionDictionary::FindFunction(LPTSTR szFunctionName)
  143. {
  144. DWORD i;
  145. if ( m_bFunctionsLoaded == FALSE )
  146. {
  147. if ( LoadFunctions() )
  148. {
  149. m_bFunctionsLoaded = TRUE;
  150. }
  151. else
  152. {
  153. return FALSE;
  154. }
  155. }
  156. for (i = 0; i < m_dwFunctions; i++)
  157. {
  158. if ( _tcscmp( szFunctionName, m_pDict[i]->GetMethodName() ) == 0 )
  159. {
  160. return (m_pDict[i]);
  161. }
  162. }
  163. return NULL;
  164. }
  165. // function: CallFunction
  166. //
  167. // Call a function that has been defined in this class
  168. //
  169. // Parameters
  170. // szFunctionName - The Name of the function
  171. // szParameters - The parameters to be sent in
  172. //
  173. // Return Values:
  174. // These return values indicate the return value of the function that was called.
  175. // Higher up, these will sometimes we used for conditional statements in the
  176. // infs
  177. //
  178. BOOL
  179. CFunctionDictionary::CallFunction(LPTSTR szFunctionName, LPTSTR szParameters)
  180. {
  181. CBaseFunction *pFunc;
  182. BOOL bRet;
  183. pFunc = FindFunction( szFunctionName );
  184. if ( !pFunc )
  185. {
  186. iisDebugOut((LOG_TYPE_TRACE, _T("Function '%s' could not be found\n") , szFunctionName ) );
  187. // We could not find the function, so lets return. (The return value does not indicate
  188. // that we did not succeeded it just indicates that the return function returned something)
  189. return FALSE;
  190. }
  191. iisDebugOut((LOG_TYPE_TRACE, _T("Calling function '%s'\n") , pFunc->GetMethodName() ) );
  192. bRet = pFunc->DoWork( szParameters );
  193. iisDebugOut((LOG_TYPE_TRACE, _T("Function '%s' returned 0x%08x\n") , pFunc->GetMethodName(), bRet ) );
  194. return bRet;
  195. }