Source code of Windows XP (NT5)
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.

453 lines
12 KiB

  1. //
  2. //
  3. //
  4. #include "stdafx.h"
  5. #include "resource.h"
  6. #include "PropSheet.h"
  7. #include <common.h>
  8. #include <algorithm>
  9. #include <functional>
  10. BOOL
  11. PathIsValid(LPCTSTR path)
  12. {
  13. LPCTSTR p = path;
  14. BOOL rc = TRUE;
  15. if (p == NULL || *p == 0)
  16. return FALSE;
  17. while (*p != 0)
  18. {
  19. switch (*p)
  20. {
  21. case TEXT('|'):
  22. case TEXT('>'):
  23. case TEXT('<'):
  24. case TEXT('/'):
  25. case TEXT('?'):
  26. case TEXT('*'):
  27. case TEXT(';'):
  28. case TEXT(','):
  29. case TEXT('"'):
  30. rc = FALSE;
  31. break;
  32. default:
  33. if (*p < TEXT(' '))
  34. {
  35. rc = FALSE;
  36. }
  37. break;
  38. }
  39. if (!rc)
  40. {
  41. break;
  42. }
  43. p++;
  44. }
  45. return rc;
  46. }
  47. HRESULT
  48. CMappings::Load(CMetaKey * pKey)
  49. {
  50. CStringListEx listData;
  51. BOOL fOverride = TRUE;
  52. DWORD dwAttr = 0;
  53. HRESULT hr = pKey->QueryValue(MD_SCRIPT_MAPS, listData, &fOverride, NULL, &dwAttr);
  54. if (SUCCEEDED(hr))
  55. {
  56. m_fInherited = (dwAttr & METADATA_ISINHERITED) != 0;
  57. m_initData.assign(listData.size(), CString(_T("")));
  58. std::copy(listData.begin(), listData.end(), m_initData.begin());
  59. CStringListEx::iterator i;
  60. CString buf;
  61. for (i = listData.begin(); i != listData.end(); i++)
  62. {
  63. buf = *i;
  64. Mapping map;
  65. int len = buf.GetLength();
  66. int pos = buf.find(_T(','));
  67. ASSERT(pos != CString::npos);
  68. map.ext = buf.Left(pos);
  69. int pos1 = buf.find(_T(','), ++pos);
  70. ASSERT(pos1 != CString::npos);
  71. map.path = buf.Mid(pos, pos1 - pos);
  72. pos = pos1;
  73. pos1 = buf.find(_T(','), ++pos);
  74. if (pos1 == CString::npos)
  75. {
  76. map.flags = StrToInt(buf.Right(len - pos));
  77. }
  78. else
  79. {
  80. map.flags = StrToInt(buf.Mid(pos, pos1 - pos));
  81. map.verbs = buf.Right(len - pos1 - 1);
  82. }
  83. insert(begin(), value_type(map.ext, map));
  84. }
  85. }
  86. else
  87. {
  88. hr = S_OK;
  89. }
  90. return hr;
  91. }
  92. inline bool eq_nocase(CString& str1, CString& str2)
  93. {
  94. return str1.CompareNoCase(str2) == 0;
  95. }
  96. struct less_nocase : public std::less<CString>
  97. {
  98. bool operator()(const CString& str1, const CString& str2) const
  99. {
  100. return StrCmpI(str1.c_str(), str2.c_str()) < 0;
  101. }
  102. };
  103. //inline bool less_nocase(const CString& str1, const CString& str2)
  104. //{
  105. // return str1.CompareNoCase(str2) == -1;
  106. //}
  107. HRESULT
  108. CMappings::Save(CMetaKey * pKey)
  109. {
  110. CStringListEx listData;
  111. CMappings::iterator i;
  112. Mapping map;
  113. TCHAR buf[MAX_PATH * 2];
  114. TCHAR num[12];
  115. for (i = begin(); i != end(); i++)
  116. {
  117. map = (*i).second;
  118. StrCpy(buf, map.ext);
  119. StrCat(buf, _T(","));
  120. StrCat(buf, map.path);
  121. StrCat(buf, _T(","));
  122. wsprintf(num, _T("%u"), map.flags);
  123. StrCat(buf, num);
  124. if (!map.verbs.IsEmpty())
  125. {
  126. StrCat(buf, _T(","));
  127. StrCat(buf, map.verbs);
  128. }
  129. listData.PushBack(buf);
  130. buf[0] = 0;
  131. }
  132. HRESULT hr = S_OK;
  133. if (listData.empty())
  134. {
  135. // User must be want to inherit scriptmaps from the parent
  136. if (!m_fInherited)
  137. {
  138. hr = pKey->DeleteValue(MD_SCRIPT_MAPS);
  139. }
  140. }
  141. else
  142. {
  143. if (listData.size() != m_initData.size())
  144. {
  145. VERIFY(SUCCEEDED(hr = pKey->SetValue(MD_SCRIPT_MAPS, listData)));
  146. // If it was inherited, we should reset the flag now, or it will be confusing if
  147. // another save will be performed before load.
  148. m_fInherited = FALSE;
  149. }
  150. else
  151. {
  152. std::vector<CString> newData;
  153. newData.assign(listData.size(), CString(_T("")));
  154. std::copy(listData.begin(), listData.end(), newData.begin());
  155. std::sort(m_initData.begin(), m_initData.end(), less_nocase());
  156. std::sort(newData.begin(), newData.end(), less_nocase());
  157. if (!std::equal(newData.begin(), newData.end(), m_initData.begin(), eq_nocase))
  158. {
  159. VERIFY(SUCCEEDED(hr = pKey->SetValue(MD_SCRIPT_MAPS, listData)));
  160. }
  161. }
  162. }
  163. return hr;
  164. }
  165. HRESULT
  166. CAppData::Load()
  167. {
  168. ASSERT(!m_MetaPath.IsEmpty());
  169. CComAuthInfo auth(m_ServerName, m_UserName, m_UserPassword);
  170. CMetaKey mk(&auth, m_MetaPath, METADATA_PERMISSION_READ);
  171. HRESULT hr = mk.QueryResult();
  172. if (FAILED(hr))
  173. return hr;
  174. do
  175. {
  176. m_fIsLocal = auth.IsLocal();
  177. CString buf;
  178. if (FAILED(hr = mk.QueryValue(MD_APP_ISOLATED, m_AppIsolated)))
  179. break;
  180. if (FAILED(hr = mk.QueryValue(MD_ASP_ALLOWSESSIONSTATE, m_EnableSession)))
  181. break;
  182. if (FAILED(hr = mk.QueryValue(MD_ASP_BUFFERINGON, m_EnableBuffering)))
  183. break;
  184. if (FAILED(hr = mk.QueryValue(MD_ASP_ENABLEPARENTPATHS, m_EnableParents)))
  185. break;
  186. if (FAILED(hr = mk.QueryValue(MD_ASP_SESSIONTIMEOUT, m_SessionTimeout)))
  187. break;
  188. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTTIMEOUT, m_ScriptTimeout)))
  189. break;
  190. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTLANGUAGE, buf)))
  191. break;
  192. StrCpy(m_Languages, buf);
  193. //
  194. if (FAILED(hr = mk.QueryValue(MD_ASP_ENABLESERVERDEBUG, m_ServerDebug)))
  195. break;
  196. if (FAILED(hr = mk.QueryValue(MD_ASP_ENABLECLIENTDEBUG, m_ClientDebug)))
  197. break;
  198. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTERRORSSENTTOBROWSER, m_SendAspError)))
  199. break;
  200. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTERRORMESSAGE, buf)))
  201. break;
  202. StrCpy(m_DefaultError, buf);
  203. //
  204. if (FAILED(hr = m_Mappings.Load(&mk)))
  205. break;
  206. if (FAILED(hr = mk.QueryValue(MD_CACHE_EXTENSIONS, m_CacheISAPI)))
  207. break;
  208. //
  209. if (FAILED(hr = mk.QueryValue(MD_ASP_LOGERRORREQUESTS, m_LogFailures)))
  210. break;
  211. if (FAILED(hr = mk.QueryValue(MD_ASP_EXCEPTIONCATCHENABLE, m_DebugExcept)))
  212. break;
  213. if (FAILED(hr = mk.QueryValue(MD_SCRIPT_TIMEOUT, m_CgiTimeout)))
  214. break;
  215. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTENGINECACHEMAX, m_ScriptEngCacheMax)))
  216. break;
  217. //
  218. if (MajorVersion() == 5 && MinorVersion() == 0)
  219. {
  220. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTFILECACHESIZE, m_LimCacheInMemorySize)))
  221. {
  222. break;
  223. }
  224. m_NoCache = m_UnlimCache = m_LimCache = FALSE;
  225. if (m_LimCacheInMemorySize == 0)
  226. {
  227. m_NoCache = TRUE;
  228. }
  229. else if (m_LimCacheInMemorySize == 0xFFFFFFFF)
  230. {
  231. m_UnlimCache = TRUE;
  232. }
  233. else
  234. {
  235. m_LimCache = TRUE;
  236. }
  237. }
  238. else
  239. {
  240. if (FAILED(hr = mk.QueryValue(MD_ASP_DISKTEMPLATECACHEDIRECTORY, buf)))
  241. {
  242. VERIFY(0 != ExpandEnvironmentStrings(
  243. _T("%windir%\\system32\\inetsrv\\ASP Compiled Templates"),
  244. m_DiskCacheDir, MAX_PATH));
  245. hr = S_OK;
  246. }
  247. else
  248. StrCpy(m_DiskCacheDir, buf);
  249. m_NoCache = m_UnlimCache = m_LimCache = FALSE;
  250. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTFILECACHESIZE, m_AspScriptFileCacheSize)))
  251. {
  252. m_TotalCacheSize = -1;
  253. hr = S_OK;
  254. break;
  255. }
  256. if (m_AspScriptFileCacheSize == 0)
  257. {
  258. m_NoCache = TRUE;
  259. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTFILECACHESIZE, m_UnlimCacheInMemorySize)))
  260. {
  261. break;
  262. }
  263. m_LimCacheInMemorySize = 250;
  264. }
  265. else if (m_AspScriptFileCacheSize == -1)
  266. {
  267. m_UnlimCache = TRUE;
  268. m_UnlimCacheInMemorySize = CACHE_UNLIM_MAX;
  269. m_LimCacheInMemorySize = 0;
  270. }
  271. else
  272. {
  273. m_LimCache = TRUE;
  274. if (FAILED(hr = mk.QueryValue(MD_ASP_MAXDISKTEMPLATECACHEFILES, m_AspMaxDiskTemplateCacheFiles)))
  275. {
  276. break;
  277. m_AspMaxDiskTemplateCacheFiles = -1;
  278. hr = S_OK;
  279. }
  280. if (m_AspMaxDiskTemplateCacheFiles == 0)
  281. {
  282. m_LimCacheInMemorySize = m_TotalCacheSize = m_AspScriptFileCacheSize;
  283. }
  284. else if (m_AspMaxDiskTemplateCacheFiles == -1)
  285. {
  286. m_TotalCacheSize = CACHE_UNLIM_MAX;
  287. m_LimCacheInMemorySize = m_AspScriptFileCacheSize;
  288. }
  289. else
  290. {
  291. m_LimCacheInMemorySize = m_AspScriptFileCacheSize;
  292. m_TotalCacheSize = m_LimCacheInMemorySize + m_AspMaxDiskTemplateCacheFiles;
  293. }
  294. }
  295. }
  296. //
  297. m_MetaPath = mk.QueryMetaPath();
  298. } while (FALSE);
  299. return hr;
  300. }
  301. HRESULT
  302. CAppData::Save()
  303. {
  304. if (!m_Dirty)
  305. {
  306. return S_OK;
  307. }
  308. ASSERT(!m_MetaPath.IsEmpty());
  309. CComAuthInfo auth(m_ServerName, m_UserName, m_UserPassword);
  310. CMetaKey mk(&auth, m_MetaPath, METADATA_PERMISSION_WRITE);
  311. HRESULT hr = mk.QueryResult();
  312. if (FAILED(hr))
  313. return hr;
  314. do
  315. {
  316. CString buf;
  317. if (FAILED(hr = mk.SetValue(MD_ASP_ALLOWSESSIONSTATE, m_EnableSession)))
  318. break;
  319. if (FAILED(hr = mk.SetValue(MD_ASP_BUFFERINGON, m_EnableBuffering)))
  320. break;
  321. if (FAILED(hr = mk.SetValue(MD_ASP_ENABLEPARENTPATHS, m_EnableParents)))
  322. break;
  323. if (FAILED(hr = mk.SetValue(MD_ASP_SESSIONTIMEOUT, m_SessionTimeout)))
  324. break;
  325. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTTIMEOUT, m_ScriptTimeout)))
  326. break;
  327. buf = m_Languages;
  328. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTLANGUAGE, buf)))
  329. break;
  330. //
  331. if (FAILED(hr = mk.SetValue(MD_ASP_ENABLESERVERDEBUG, m_ServerDebug)))
  332. break;
  333. if (FAILED(hr = mk.SetValue(MD_ASP_ENABLECLIENTDEBUG, m_ClientDebug)))
  334. break;
  335. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTERRORSSENTTOBROWSER, m_SendAspError)))
  336. break;
  337. buf = m_DefaultError;
  338. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTERRORMESSAGE, buf)))
  339. break;
  340. //
  341. if (FAILED(hr = m_Mappings.Save(&mk)))
  342. break;
  343. if (FAILED(hr = mk.SetValue(MD_CACHE_EXTENSIONS, m_CacheISAPI)))
  344. break;
  345. //
  346. if (FAILED(hr = mk.SetValue(MD_ASP_LOGERRORREQUESTS, m_LogFailures)))
  347. break;
  348. if (FAILED(hr = mk.SetValue(MD_ASP_EXCEPTIONCATCHENABLE, m_DebugExcept)))
  349. break;
  350. if (FAILED(hr = mk.SetValue(MD_SCRIPT_TIMEOUT, m_CgiTimeout)))
  351. break;
  352. //
  353. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTENGINECACHEMAX, m_ScriptEngCacheMax)))
  354. break;
  355. if (MajorVersion() == 5 && MinorVersion() == 0)
  356. {
  357. if (m_NoCache)
  358. {
  359. m_LimCacheInMemorySize = 0;
  360. }
  361. else if (m_UnlimCache)
  362. {
  363. m_LimCacheInMemorySize = -1;
  364. }
  365. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTFILECACHESIZE, m_LimCacheInMemorySize)))
  366. break;
  367. }
  368. else
  369. {
  370. buf = m_DiskCacheDir;
  371. if (FAILED(hr = mk.SetValue(MD_ASP_DISKTEMPLATECACHEDIRECTORY, buf)))
  372. break;
  373. int inmem = 0;
  374. if (m_NoCache)
  375. {
  376. m_AspScriptFileCacheSize = 0;
  377. m_AspMaxDiskTemplateCacheFiles = 0;
  378. }
  379. else if (m_UnlimCache)
  380. {
  381. m_AspScriptFileCacheSize = -1;
  382. inmem = m_UnlimCacheInMemorySize;
  383. }
  384. else
  385. {
  386. if (m_TotalCacheSize >= CACHE_UNLIM_MAX)
  387. {
  388. // disk cache unlimited
  389. m_AspMaxDiskTemplateCacheFiles = -1;
  390. m_AspScriptFileCacheSize = m_LimCacheInMemorySize;
  391. }
  392. else
  393. {
  394. m_AspMaxDiskTemplateCacheFiles = m_TotalCacheSize - m_LimCacheInMemorySize;
  395. m_AspScriptFileCacheSize = m_LimCacheInMemorySize;
  396. }
  397. }
  398. if (FAILED(hr = mk.SetValue(MD_ASP_MAXDISKTEMPLATECACHEFILES, m_AspMaxDiskTemplateCacheFiles)))
  399. break;
  400. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTFILECACHESIZE, m_AspScriptFileCacheSize)))
  401. break;
  402. }
  403. } while (FALSE);
  404. m_Dirty = SUCCEEDED(hr);
  405. return hr;
  406. }
  407. BOOL
  408. CAppData::IsMasterInstance()
  409. {
  410. return CMetabasePath::IsMasterInstance(m_MetaPath);
  411. }
  412. WORD
  413. CAppData::MajorVersion()
  414. {
  415. return LOWORD(m_dwVersion);
  416. }
  417. WORD
  418. CAppData::MinorVersion()
  419. {
  420. return HIWORD(m_dwVersion);
  421. }
  422. CAppPropSheet::CAppPropSheet()
  423. {
  424. static TCHAR title[256];
  425. ::LoadString(_Module.GetResourceInstance(), IDS_SHEET_TITLE, title, 256);
  426. m_psh.pszCaption = title;
  427. }
  428. LRESULT
  429. CAppPropSheet::OnInitDialog(HWND hDlg, LPARAM)
  430. {
  431. return 0;
  432. }
  433. void
  434. CAppPropSheet::OnKeyDown(UINT nChar, UINT nRepCount, UINT nFlags)
  435. {
  436. }