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.

247 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. cmdline.cpp
  5. Abstract:
  6. Command line class implementation. This class takes care of command line
  7. parsing and validation. And, it will add the user options to global
  8. CUserOptions object.
  9. Author:
  10. Michael Cheuk (mcheuk)
  11. Project:
  12. Link Checker
  13. Revision History:
  14. --*/
  15. #include "stdafx.h"
  16. #include "cmdline.h"
  17. #include "resource.h"
  18. #include "lcmgr.h"
  19. #include "iisinfo.h"
  20. #include "afxpriv.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. CCmdLine::CCmdLine(
  27. )
  28. /*++
  29. Routine Description:
  30. Constructor.
  31. Arguments:
  32. N/A
  33. Return Value:
  34. N/A
  35. --*/
  36. {
  37. m_iInstance = -1;
  38. m_fInvalidParam = FALSE;
  39. } // CCmdLine::CCmdLine
  40. BOOL
  41. CCmdLine::CheckAndAddToUserOptions(
  42. )
  43. /*++
  44. Routine Description:
  45. Validate the command line paramters and add them to global CUserOptions object
  46. Arguments:
  47. N/A
  48. Return Value:
  49. BOOL - TRUE if sucess. FALSE otherwise
  50. --*/
  51. {
  52. // Do we have any invalid parameters so far?
  53. if(m_fInvalidParam)
  54. {
  55. ::MessageBeep(MB_ICONEXCLAMATION);
  56. CDialog dlg(IDD_USAGE);
  57. dlg.DoModal();
  58. return FALSE;
  59. }
  60. // Is the user options valid ?
  61. BOOL fURL = !m_strURL.IsEmpty();
  62. BOOL fDirectories = !m_strAlias.IsEmpty() && !m_strPath.IsEmpty() && !m_strHostName.IsEmpty();
  63. BOOL fInstance = !m_strHostName.IsEmpty() && m_iInstance != -1;
  64. // Command line: linkchk -u URL
  65. if(fURL && !fDirectories && !fInstance)
  66. {
  67. GetLinkCheckerMgr().GetUserOptions().AddURL(m_strURL);
  68. return TRUE;
  69. }
  70. // Command line: linkchk -s ServerName -a VirtualDirectoryAlias -p VirtualDirectoryPath
  71. else if(!fURL && fDirectories && !fInstance)
  72. {
  73. GetLinkCheckerMgr().GetUserOptions().AddDirectory(CVirtualDirInfo(m_strAlias, m_strPath));
  74. GetLinkCheckerMgr().GetUserOptions().SetHostName(m_strHostName);
  75. return TRUE;
  76. }
  77. // Command line: linkchk -s ServerName -i InstanceNumber
  78. else if(!fURL && !fDirectories && fInstance)
  79. {
  80. GetLinkCheckerMgr().GetUserOptions().SetHostName(m_strHostName);
  81. return QueryAndAddDirectories();
  82. }
  83. else
  84. {
  85. ::MessageBeep(MB_ICONEXCLAMATION);
  86. CDialog dlg(IDD_USAGE);
  87. dlg.DoModal();
  88. return FALSE;
  89. }
  90. } // CCmdLine::CheckAndAddToUserOptions
  91. void
  92. CCmdLine::ParseParam(
  93. TCHAR chFlag,
  94. LPCTSTR lpszParam
  95. )
  96. /*++
  97. Routine Description:
  98. Called by CLinkCheckApp for each parameters.
  99. Arguments:
  100. chFlag - parameter flag
  101. lpszParam - value
  102. Return Value:
  103. N/A
  104. --*/
  105. {
  106. // It is invalid to have a flag without any parameters
  107. if(lpszParam == NULL)
  108. {
  109. m_fInvalidParam = TRUE;
  110. return;
  111. }
  112. switch(chFlag)
  113. {
  114. case _TCHAR('a'):
  115. m_strAlias = lpszParam;
  116. break;
  117. case _TCHAR('h'):
  118. m_strHostName = lpszParam;
  119. break;
  120. case _TCHAR('i'):
  121. m_iInstance = _ttoi(lpszParam);
  122. break;
  123. case _TCHAR('u'):
  124. m_strURL = lpszParam;
  125. break;
  126. case _TCHAR('p'):
  127. m_strPath = lpszParam;
  128. default: // unknown flag
  129. m_fInvalidParam = FALSE;
  130. }
  131. } // CCmdLine::ParseParam
  132. BOOL
  133. CCmdLine::QueryAndAddDirectories(
  134. )
  135. /*++
  136. Routine Description:
  137. Query the metabase for server/instance directories and
  138. add them to the global CUserOptions object
  139. Arguments:
  140. N/A
  141. Return Value:
  142. BOOL - TRUE if sucess. FALSE otherwise
  143. --*/
  144. {
  145. USES_CONVERSION; // for A2W
  146. // Get the server info
  147. LPIIS_INSTANCE_INFO_1 lpInfo = NULL;
  148. NET_API_STATUS err = IISGetAdminInformation(
  149. A2W((LPCSTR)m_strHostName),
  150. 1,
  151. INET_HTTP_SVC_ID,
  152. m_iInstance,
  153. (LPBYTE*)&lpInfo
  154. );
  155. if(err != ERROR_SUCCESS)
  156. {
  157. AfxMessageBox(IDS_IISGETADMININFORMATION_ERROR);
  158. return FALSE;
  159. }
  160. // Do we have any virtual directories ?
  161. if(lpInfo->VirtualRoots == NULL)
  162. {
  163. AfxMessageBox(IDS_IIS_VIRTUALROOT_NOT_EXIST);
  164. return FALSE;
  165. }
  166. // Get the virutal directory info
  167. _INET_INFO_VIRTUAL_ROOT_ENTRY_1* pVRoot = NULL;
  168. for(DWORD i=0; i<lpInfo->VirtualRoots->cEntries; i++)
  169. {
  170. pVRoot = &(lpInfo->VirtualRoots->aVirtRootEntry[i]);
  171. GetLinkCheckerMgr().GetUserOptions().
  172. AddDirectory(CVirtualDirInfo(pVRoot->pszRoot, pVRoot->pszDirectory));
  173. }
  174. return TRUE;
  175. } // CCmdLine::QueryAndAddDirectories