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.

547 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. useropt.h
  5. Abstract:
  6. Global user options class and help class implementations. This class
  7. can only instantiate by CLinkCheckerMgr. Therefore, a single instance
  8. of this class will live inside CLinkCheckerMgr. You can access
  9. the this instance by calling GetLinkCheckMgr().GetUserOptions().
  10. Author:
  11. Michael Cheuk (mcheuk)
  12. Project:
  13. Link Checker
  14. Revision History:
  15. --*/
  16. #include "stdafx.h"
  17. #include "useropt.h"
  18. #include "lcmgr.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. //------------------------------------------------------------------
  25. // CVirtualDirInfo
  26. //
  27. void
  28. CVirtualDirInfo::PreProcessAlias(
  29. )
  30. /*++
  31. Routine Description:
  32. Preprocess the current virtual directory alias. The alias will be in
  33. the form of / or /dir/
  34. Arguments:
  35. N/A
  36. Return Value:
  37. N/A
  38. --*/
  39. {
  40. // Change everything to lower case
  41. m_strAlias.MakeLower();
  42. // Change '\' to '/'
  43. CLinkCheckerMgr::ChangeBackSlash(m_strAlias);
  44. // Make sure strAlias is in the form of / or /dir/
  45. if( m_strAlias.GetAt( m_strAlias.GetLength() - 1 ) != _TCHAR('/') )
  46. {
  47. m_strAlias += _TCHAR('/');
  48. }
  49. } // CVirtualDirInfo::PreProcessAlias
  50. void
  51. CVirtualDirInfo::PreProcessPath(
  52. )
  53. /*++
  54. Routine Description:
  55. Preprocess the current virtual directory path. The alias will be in
  56. the form of c:\ or c:\dir\
  57. Arguments:
  58. N/A
  59. Return Value:
  60. N/A
  61. --*/
  62. {
  63. // Change everything to lower case
  64. m_strPath.MakeLower();
  65. // Make sure strPath is in the form of \ or \dir\
  66. if( m_strPath.GetAt( m_strPath.GetLength() - 1 ) != _TCHAR('\\') )
  67. {
  68. m_strPath += _TCHAR('\\');
  69. }
  70. } // CVirtualDirInfo::PreProcessPath
  71. //------------------------------------------------------------------
  72. // CBrowserInfoList
  73. //
  74. POSITION
  75. CBrowserInfoList::GetHeadSelectedPosition(
  76. ) const
  77. /*++
  78. Routine Description:
  79. Get the first selected browser. It works like GetHeadPosition()
  80. Arguments:
  81. N/A
  82. Return Value:
  83. POSITION - A POSITION value that can be used for iteration or
  84. object pointer retrieval; NULL if the list is empty
  85. --*/
  86. {
  87. POSITION Pos = GetHeadPosition();
  88. while(Pos)
  89. {
  90. POSITION PosCurrent = Pos;
  91. if(GetNext(Pos).IsSelected())
  92. {
  93. return PosCurrent;
  94. break;
  95. }
  96. }
  97. return NULL;
  98. } // CBrowserInfoList::GetHeadSelectedPosition
  99. CBrowserInfo&
  100. CBrowserInfoList::GetNextSelected(
  101. POSITION& Pos
  102. )
  103. /*++
  104. Routine Description:
  105. Get next selected browser. It works like GetNext()
  106. Arguments:
  107. Pos - A reference to a POSITION value returned by
  108. a previous GetHeadSelectedPosition, GetNextSelected
  109. Return Value:
  110. CBrowserInfo& - returns a reference to an element of the list
  111. --*/
  112. {
  113. CBrowserInfo& Info = GetNext(Pos);
  114. while(Pos)
  115. {
  116. POSITION PosCurrent = Pos;
  117. if(GetNext(Pos).IsSelected())
  118. {
  119. Pos = PosCurrent;
  120. break;
  121. }
  122. }
  123. return Info;
  124. } // CBrowserInfoList::GetNextSelected
  125. //------------------------------------------------------------------
  126. // CLanguageInfoList
  127. //
  128. POSITION
  129. CLanguageInfoList::GetHeadSelectedPosition(
  130. ) const
  131. /*++
  132. Routine Description:
  133. Get the first selected browser. It works like GetHeadPosition()
  134. Arguments:
  135. N/A
  136. Return Value:
  137. POSITION - A POSITION value that can be used for iteration or
  138. object pointer retrieval; NULL if the list is empty
  139. --*/
  140. {
  141. POSITION Pos = GetHeadPosition();
  142. while(Pos)
  143. {
  144. POSITION PosCurrent = Pos;
  145. if(GetNext(Pos).IsSelected())
  146. {
  147. return PosCurrent;
  148. break;
  149. }
  150. }
  151. return NULL;
  152. } // CLanguageInfo::GetHeadSelectedPosition
  153. CLanguageInfo&
  154. CLanguageInfoList::GetNextSelected(
  155. POSITION& Pos
  156. )
  157. /*++
  158. Routine Description:
  159. Get next selected language. It works like GetNext()
  160. Arguments:
  161. Pos - A reference to a POSITION value returned by
  162. a previous GetNext, GetHeadPosition, GetNextSelected,
  163. or other member function call
  164. Return Value:
  165. CLanguageInfo& - returns a reference to an element of the list
  166. --*/
  167. {
  168. CLanguageInfo& Info = GetNext(Pos);
  169. while(Pos)
  170. {
  171. POSITION PosCurrent = Pos;
  172. if(GetNext(Pos).IsSelected())
  173. {
  174. Pos = PosCurrent;
  175. break;
  176. }
  177. }
  178. return Info;
  179. } // CLanguageInfoList::GetNextSelected
  180. //------------------------------------------------------------------
  181. // CUserOptions
  182. //
  183. void
  184. CUserOptions::AddDirectory(
  185. const CVirtualDirInfo& Info
  186. )
  187. /*++
  188. Routine Description:
  189. Add this virtual directory to the link list.
  190. Arguments:
  191. Info - virtual directory infomation to add
  192. Return Value:
  193. N/A
  194. --*/
  195. {
  196. // Finally, add it to the array
  197. try
  198. {
  199. m_VirtualDirInfoList.AddTail(Info);
  200. }
  201. catch(CMemoryException* pEx)
  202. {
  203. pEx->Delete();
  204. }
  205. } // CUserOptions::AddDirectory
  206. void
  207. CUserOptions::AddURL(
  208. LPCTSTR lpszURL
  209. )
  210. /*++
  211. Routine Description:
  212. Add this URL to the link list.
  213. Arguments:
  214. lpszURL - URL to add
  215. Return Value:
  216. N/A
  217. --*/
  218. {
  219. CString strURL(lpszURL);
  220. // Change '\' to '/'
  221. CLinkCheckerMgr::ChangeBackSlash(strURL);
  222. try
  223. {
  224. m_strURLList.AddTail(strURL);
  225. }
  226. catch(CMemoryException* pEx)
  227. {
  228. pEx->Delete();
  229. }
  230. } // CUserOptions::AddURL
  231. void
  232. CUserOptions::AddAvailableBrowser(
  233. const CBrowserInfo& Info
  234. )
  235. /*++
  236. Routine Description:
  237. Add this browser information to the available list.
  238. Arguments:
  239. Info - Browser information to add
  240. Return Value:
  241. N/A
  242. --*/
  243. {
  244. try
  245. {
  246. m_BrowserInfoList.AddTail(Info);
  247. }
  248. catch(CMemoryException* pEx)
  249. {
  250. pEx->Delete();
  251. }
  252. } // CUserOptions::AddAvailableBrowser
  253. void
  254. CUserOptions::AddAvailableLanguage(
  255. const CLanguageInfo& Info
  256. )
  257. /*++
  258. Routine Description:
  259. Add this language information to the available list.
  260. Arguments:
  261. Info - Language information to add
  262. Return Value:
  263. N/A
  264. --*/
  265. {
  266. try
  267. {
  268. m_LanguageInfoList.AddTail(Info);
  269. }
  270. catch(CMemoryException* pEx)
  271. {
  272. pEx->Delete();
  273. }
  274. } // CUserOptions::AddAvailableLanguage
  275. void
  276. CUserOptions::SetOptions(
  277. BOOL fCheckLocalLinks,
  278. BOOL fCheckRemoteLinks,
  279. BOOL fLogToFile,
  280. const CString& strLogFilename,
  281. BOOL fLogToEventMgr
  282. )
  283. /*++
  284. Routine Description:
  285. Set the user options in the main dialog
  286. Arguments:
  287. N/A
  288. Return Value:
  289. N/A
  290. --*/
  291. {
  292. m_fCheckLocalLinks = fCheckLocalLinks;
  293. m_fCheckRemoteLinks = fCheckRemoteLinks;
  294. m_fLogToFile= fLogToFile;
  295. m_strLogFilename = strLogFilename;
  296. m_fLogToEventMgr = fLogToEventMgr;
  297. } // CUserOptions::SetOptions
  298. void
  299. CUserOptions::SetAthenication(
  300. const CString& strNTUsername,
  301. const CString& strNTPassword,
  302. const CString& strBasicUsername,
  303. const CString& strBasicPassword
  304. )
  305. /*++
  306. Routine Description:
  307. Set NTLM & HTTP basic athenications.
  308. Arguments:
  309. N/A
  310. Return Value:
  311. N/A
  312. --*/
  313. {
  314. m_strNTUsername = strNTUsername;
  315. m_strNTPassword = strNTPassword;
  316. m_strBasicUsername = strBasicUsername;
  317. m_strBasicPassword = strBasicPassword;
  318. } // CUserOptions::SetAthenication
  319. // Get the hostname
  320. const CString&
  321. CUserOptions::GetHostName(
  322. )
  323. /*++
  324. Routine Description:
  325. Get the hostname.
  326. Arguments:
  327. N/A
  328. Return Value:
  329. N/A
  330. --*/
  331. {
  332. // If the hostname does not exists, it means the user pass in
  333. // a list of URL to link checker. (Server nane is not required for
  334. // this case.) Now, we can get the hostname from the URL
  335. if(m_strHostName.IsEmpty() && m_strURLList.GetCount() > 0)
  336. {
  337. // Set up the current hostname string
  338. LPTSTR lpszHostName = m_strHostName.GetBuffer(INTERNET_MAX_HOST_NAME_LENGTH);
  339. URL_COMPONENTS urlcomp;
  340. memset(&urlcomp, 0, sizeof(urlcomp));
  341. urlcomp.dwStructSize = sizeof(urlcomp);
  342. urlcomp.lpszHostName = lpszHostName;
  343. urlcomp.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
  344. // Crack it
  345. VERIFY(CWininet::InternetCrackUrlA(
  346. m_strURLList.GetHead(), m_strURLList.GetHead().GetLength(), NULL, &urlcomp));
  347. m_strHostName.ReleaseBuffer();
  348. }
  349. return m_strHostName;
  350. } // CUserOptions::GetHostName
  351. void
  352. CUserOptions::PreProcessServerName(
  353. )
  354. /*++
  355. Routine Description:
  356. Preprocess the server name such that for server "\\hostname"
  357. - GetServerName() return \\hostname
  358. - GetHostName() return hostname
  359. Arguments:
  360. N/A
  361. Return Value:
  362. N/A
  363. --*/
  364. {
  365. // Change everything to lower case
  366. m_strHostName.MakeLower();
  367. // Change '\' to '/'
  368. CLinkCheckerMgr::ChangeBackSlash(m_strHostName);
  369. // Make sure m_strHostName is not in front of localhost
  370. const CString strBackSlash(_T("//"));
  371. if( m_strHostName.Find(strBackSlash) == 0 )
  372. {
  373. m_strHostName = m_strHostName.Mid(strBackSlash.GetLength());
  374. }
  375. } // CUserOptions::PreProcessServerName