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.

231 lines
6.6 KiB

  1. /*===================================================================
  2. Microsoft
  3. Microsoft Confidential.
  4. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  5. Component: VPTOOL a WAMREG unit testing tool
  6. File: util.cpp
  7. Owner: leijin
  8. Description:
  9. Contains utility functions used by vptool.
  10. Including Debugging, timing, helping functions.
  11. Note:
  12. ===================================================================*/
  13. #include "util.h"
  14. //
  15. //
  16. //
  17. //
  18. // Local Data Structures.
  19. //
  20. const CommandParam rgCommand[] =
  21. {
  22. {eCommand_INSTALL, "-INSTALL", NULL, FALSE},
  23. {eCommand_UNINSTALL, "-UNINSTALL", NULL, FALSE},
  24. {eCommand_UPGRADE, "-UPGRADE", NULL, TRUE},
  25. {eCommand_CREATEINPROC, "-CREATEINPROC", NULL, TRUE},
  26. {eCommand_CREATEOUTPROC,"-CREATEOUTPROC", NULL, TRUE},
  27. {eCommand_CREATEINPOOL, "-CREATEINPOOL", NULL, TRUE},
  28. {eCommand_DELETE, "-DELETE", NULL, TRUE},
  29. {eCommand_GETSTATUS, "-GETSTATUS", NULL, TRUE},
  30. {eCommand_UNLOAD, "-UNLOAD", NULL, TRUE},
  31. {eCommand_GETSIGNATURE, "-GETSIGNATURE", NULL, FALSE},
  32. {eCommand_SERIALIZE, "-SERIALIZE", NULL, FALSE},
  33. {eCommand_DESERIALIZE, "-GETSERIALIZE", NULL, FALSE},
  34. {eCommand_DELETEREC, "-DELETEREC", NULL, TRUE},
  35. {eCommand_RECOVER, "-RECOVER", NULL, TRUE},
  36. {eCommand_2CREATE, "-2CREATE", NULL, TRUE},
  37. {eCommand_2DELETE, "-2DELETE", NULL, TRUE},
  38. {eCommand_2CREATEPOOL, "-2CREATEPOOL", NULL, TRUE},
  39. {eCommand_2DELETEPOOL, "-2DELETEPOOL", NULL, TRUE},
  40. {eCommand_2ENUMPOOL, "-2ENUMPOOL", NULL, TRUE},
  41. {eCommand_2RECYCLEPOOL, "-RECYCLEPOOL", NULL, TRUE},
  42. {eCommand_2GETMODE, "-GETMODE", NULL, TRUE},
  43. {eCommand_2TestConn, "-TESTCONN", NULL, TRUE}
  44. };
  45. const char* ppszHelpFile[] =
  46. {
  47. {"\n\n\t\t vptool (a simple WAMREG command line tool). \n\n"},
  48. {"Usage: vptool -Options -Command MetabasePath\n"},
  49. {"Command = CREATEINPROC | CREATEOUTPROC | DELETE | UNLOAD | GETSTATUS \n"},
  50. {"\n"},
  51. {"MetabasePath is required for all the commands \n\n"},
  52. {"CREATEINPROC\t - Create an in-proc application on the metabase path\n"},
  53. {"CREATEOUTPROC\t - Create an out-proc application on the metabase path\n"},
  54. {"CREATEINPOOL\t - Create an application in the out proc application pool on the metabase path\n"},
  55. {"DELETE\t\t - Delete the application on the metabase path if there is one\n"},
  56. {"UNLOAD\t\t - Unload an application on the metabase path from w3svc runtime lookup table.\n"},
  57. {"GETSTATUS\t - Get status of the application on the metabase path\n"},
  58. {"DELETEREC\t - Delete Recoverable on the metabase path\n"},
  59. {"RECOVER\t\t - Recover on the metabase path\n"},
  60. {"\n\nReplication testing only\n"},
  61. {"SERIALIZE\t -t Serialize application definitions\n"},
  62. {"DESERIALIZE\t -t DeSerialize application definitions\n"},
  63. {"GETSIGNATURE\t -t Get Signature of application definitions\n"}
  64. };
  65. const char* ppszAdvancedHelpFile[] =
  66. {
  67. {"\t\t\tvptool (a simple WAMREG command line tool). \n"},
  68. {"Advanced features\n"},
  69. {"The follow commands are used for testing purpose of other functions\n"},
  70. {"supported by WAMREG.DLL\n"},
  71. {"Usage: vptool -Command\n"},
  72. {"Command = INSTALL | UNINSTALL | GETSIGNATURE | SERIALIZE | DESERIALIZE\n"},
  73. {"INSTALL : INSTALL IIS default package. Test install function called by Setup\n"},
  74. {"CAUTION: This command will remove your old IIS default package first.\n"},
  75. {"\n"},
  76. {"UNINSTALL: Remove all user defined packages, including IIS default package\n"},
  77. {"\n"},
  78. {"GETSIGNATURE: UNDONE\n"},
  79. {"SERIALIZE: UNDONE\n"},
  80. {"DESERIALIZE: UNDONE\n"},
  81. {"\n"},
  82. {"\n"}
  83. };
  84. CommandParam g_Command;
  85. VP_Options g_Options;
  86. const UINT rgComMax = sizeof(rgCommand) / sizeof(CommandParam);
  87. //
  88. // Utility Functions
  89. //
  90. BOOL ParseCommandLine(int argc, char **argv)
  91. {
  92. BOOL fFound = FALSE;
  93. INT iCurrentArg = 1;
  94. if (argc < 2)
  95. {
  96. g_Command.eCmd = eCommand_HELP;
  97. PrintHelp();
  98. return FALSE;
  99. }
  100. if ((0 == _strnicmp(argv[iCurrentArg], "-?", sizeof("-?"))) ||
  101. (0 == _strnicmp(argv[iCurrentArg], "/?", sizeof("/?"))))
  102. {
  103. g_Command.eCmd = eCommand_HELP;
  104. PrintHelp();
  105. return FALSE;
  106. }
  107. if ((0 == _strnicmp(argv[iCurrentArg], "-?a", sizeof("-?a"))) ||
  108. (0 == _strnicmp(argv[iCurrentArg], "/?a", sizeof("/?a"))))
  109. {
  110. g_Command.eCmd = eCommand_HELP;
  111. PrintHelp(TRUE);
  112. return FALSE;
  113. }
  114. // Options specifed.
  115. if (argc == 4 || argc == 3)
  116. {
  117. BOOL fHasOptions = FALSE;
  118. CHAR *pChar = argv[iCurrentArg];
  119. if (*pChar == '-')
  120. {
  121. pChar++;
  122. }
  123. else
  124. {
  125. PrintHelp();
  126. return FALSE;
  127. }
  128. while(*pChar != '\0')
  129. {
  130. if (*pChar == 't')
  131. {
  132. g_Options.fEnableTimer = TRUE;
  133. fHasOptions = TRUE;
  134. }
  135. pChar++;
  136. }
  137. if (fHasOptions)
  138. {
  139. iCurrentArg++;
  140. }
  141. }
  142. //
  143. // 1. Try to match with supported commands.
  144. //
  145. //
  146. BOOL fRequiredMDPath = TRUE;
  147. for (UINT iArg = 0; iArg < rgComMax; iArg++)
  148. {
  149. if (0 == _strnicmp(argv[iCurrentArg], rgCommand[iArg].szCommandLineSwitch, (strlen(rgCommand[iArg].szCommandLineSwitch) + 1)))
  150. {
  151. g_Command = rgCommand[iArg];
  152. fFound = TRUE;
  153. break;
  154. }
  155. }
  156. if (fFound == TRUE && g_Command.fRequireMDPath == TRUE)
  157. {
  158. iCurrentArg++;
  159. g_Command.szMetabasePath = argv[iCurrentArg];
  160. if (!g_Command.szMetabasePath)
  161. {
  162. fFound = FALSE;
  163. }
  164. }
  165. if (fFound != TRUE)
  166. {
  167. PrintHelp();
  168. return FALSE;
  169. }
  170. return TRUE;
  171. }
  172. VOID Report_Time(double dElaspedSec)
  173. {
  174. if (g_Options.fEnableTimer)
  175. {
  176. printf("PERF[VP]:%f\n", dElaspedSec);
  177. }
  178. return;
  179. }
  180. void PrintHelp(BOOL fAdvanced)
  181. {
  182. UINT cLine = 0;
  183. UINT i = 0;
  184. if (fAdvanced)
  185. {
  186. cLine = sizeof(ppszAdvancedHelpFile) / sizeof(char *);
  187. for (i = 0; i < cLine; i++)
  188. {
  189. printf("%s", ppszAdvancedHelpFile[i]);
  190. }
  191. }
  192. else
  193. {
  194. cLine = sizeof(ppszHelpFile) / sizeof(char *);
  195. for (i = 0; i < cLine; i++)
  196. {
  197. printf("%s", ppszHelpFile[i]);
  198. }
  199. }
  200. }