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.

324 lines
9.1 KiB

  1. //
  2. //
  3. //
  4. #include "stdafx.h"
  5. #include "resource.h"
  6. #include "PropSheet.h"
  7. #include <common.h>
  8. HRESULT
  9. CMappings::Load(CMetaKey * pKey)
  10. {
  11. CStringListEx listData;
  12. HRESULT hr = pKey->QueryValue(MD_SCRIPT_MAPS, listData);
  13. if (SUCCEEDED(hr))
  14. {
  15. CStringListEx::iterator i;
  16. CString buf;
  17. for (i = listData.begin(); i != listData.end(); i++)
  18. {
  19. buf = *i;
  20. Mapping map;
  21. int len = buf.GetLength();
  22. int pos = buf.find(_T(','));
  23. ASSERT(pos != CString::npos);
  24. map.ext = buf.Left(pos);
  25. int pos1 = buf.find(_T(','), ++pos);
  26. ASSERT(pos1 != CString::npos);
  27. map.path = buf.Mid(pos, pos1 - pos);
  28. pos = pos1;
  29. pos1 = buf.find(_T(','), ++pos);
  30. if (pos1 == CString::npos)
  31. {
  32. map.flags = StrToInt(buf.Right(len - pos));
  33. map.verbs.LoadString(_Module.GetResourceInstance(), IDS_ALL);
  34. }
  35. else
  36. {
  37. map.flags = StrToInt(buf.Mid(pos, pos1 - pos));
  38. map.verbs = buf.Right(len - pos1 - 1);
  39. }
  40. insert(begin(), value_type(map.ext, map));
  41. }
  42. }
  43. return hr;
  44. }
  45. HRESULT
  46. CMappings::Save(CMetaKey * pKey)
  47. {
  48. CStringListEx listData;
  49. CMappings::iterator i;
  50. Mapping map;
  51. TCHAR buf[MAX_PATH * 2];
  52. TCHAR num[12];
  53. for (i = begin(); i != end(); i++)
  54. {
  55. map = (*i).second;
  56. StrCpy(buf, map.ext);
  57. StrCat(buf, _T(","));
  58. StrCat(buf, map.path);
  59. StrCat(buf, _T(","));
  60. wsprintf(num, _T("%u"), map.flags);
  61. StrCat(buf, num);
  62. if (!map.verbs.IsEmpty())
  63. {
  64. StrCat(buf, _T(","));
  65. StrCat(buf, map.verbs);
  66. }
  67. listData.PushBack(buf);
  68. buf[0] = 0;
  69. }
  70. HRESULT hr;
  71. VERIFY(SUCCEEDED(hr = pKey->SetValue(MD_SCRIPT_MAPS, listData)));
  72. return hr;
  73. }
  74. HRESULT
  75. CAppData::Load()
  76. {
  77. ASSERT(!m_MetaPath.IsEmpty());
  78. CComAuthInfo auth(m_ServerName, m_UserName, m_UserPassword);
  79. CMetaKey mk(&auth, m_MetaPath, METADATA_PERMISSION_READ);
  80. HRESULT hr = mk.QueryResult();
  81. if (FAILED(hr))
  82. return hr;
  83. do
  84. {
  85. CString buf;
  86. if (FAILED(hr = mk.QueryValue(MD_APP_ISOLATED, m_AppIsolated)))
  87. break;
  88. if (FAILED(hr = mk.QueryValue(MD_ASP_ALLOWSESSIONSTATE, m_EnableSession)))
  89. break;
  90. if (FAILED(hr = mk.QueryValue(MD_ASP_BUFFERINGON, m_EnableBuffering)))
  91. break;
  92. if (FAILED(hr = mk.QueryValue(MD_ASP_ENABLEPARENTPATHS, m_EnableParents)))
  93. break;
  94. if (FAILED(hr = mk.QueryValue(MD_ASP_SESSIONTIMEOUT, m_SessionTimeout)))
  95. break;
  96. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTTIMEOUT, m_ScriptTimeout)))
  97. break;
  98. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTLANGUAGE, buf)))
  99. break;
  100. StrCpy(m_Languages, buf);
  101. //
  102. if (FAILED(hr = mk.QueryValue(MD_ASP_ENABLESERVERDEBUG, m_ServerDebug)))
  103. break;
  104. if (FAILED(hr = mk.QueryValue(MD_ASP_ENABLECLIENTDEBUG, m_ClientDebug)))
  105. break;
  106. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTERRORSSENTTOBROWSER, m_SendAspError)))
  107. break;
  108. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTERRORMESSAGE, buf)))
  109. break;
  110. StrCpy(m_DefaultError, buf);
  111. //
  112. if (FAILED(hr = m_Mappings.Load(&mk)))
  113. break;
  114. if (FAILED(hr = mk.QueryValue(MD_CACHE_EXTENSIONS, m_CacheISAPI)))
  115. break;
  116. //
  117. if (FAILED(hr = mk.QueryValue(MD_ASP_LOGERRORREQUESTS, m_LogFailures)))
  118. break;
  119. if (FAILED(hr = mk.QueryValue(MD_ASP_EXCEPTIONCATCHENABLE, m_DebugExcept)))
  120. break;
  121. if (FAILED(hr = mk.QueryValue(MD_SCRIPT_TIMEOUT, m_CgiTimeout)))
  122. break;
  123. //
  124. if (FAILED(hr = mk.QueryValue(MD_APP_PERIODIC_RESTART_TIME, m_Timespan)))
  125. {
  126. m_Timespan = 0;
  127. hr = S_OK;
  128. // break;
  129. }
  130. m_RecycleTimespan = (m_Timespan != 0);
  131. if (FAILED(hr = mk.QueryValue(MD_APP_PERIODIC_RESTART_REQUESTS, m_Requests)))
  132. {
  133. m_Requests = 0;
  134. hr = S_OK;
  135. // break;
  136. }
  137. m_RecycleRequest = (m_Requests != 0);
  138. if (FAILED(hr = mk.QueryValue(MD_APP_PERIODIC_RESTART_SCHEDULE, m_Timers)))
  139. {
  140. hr = S_OK;
  141. // break;
  142. }
  143. m_RecycleTimer = (m_Timers.size() != 0);
  144. //
  145. if (FAILED(hr = mk.QueryValue(MD_ASP_DISKTEMPLATECACHEDIRECTORY, buf)))
  146. {
  147. VERIFY(0 != ExpandEnvironmentStrings(
  148. _T("%windir%\\system32\\inetsrv\\ASP Compiled Templates"),
  149. m_DiskCacheDir, MAX_PATH));
  150. hr = S_OK;
  151. }
  152. else
  153. StrCpy(m_DiskCacheDir, buf);
  154. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTENGINECACHEMAX, m_ScriptEngCacheMax)))
  155. break;
  156. m_NoCache = m_UnlimCache = m_LimCache = FALSE;
  157. if (FAILED(hr = mk.QueryValue(MD_ASP_MAXDISKTEMPLATECACHEFILES, m_TotalCacheSize)))
  158. {
  159. m_TotalCacheSize = -1;
  160. break;
  161. }
  162. if (m_TotalCacheSize == -1)
  163. {
  164. m_UnlimCache = TRUE;
  165. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTFILECACHESIZE, m_UnlimCacheInMemorySize)))
  166. {
  167. // m_UnlimCacheInMemorySize = 250;
  168. break;
  169. }
  170. m_LimCacheInMemorySize = 250;
  171. }
  172. else if (m_TotalCacheSize == 0)
  173. {
  174. m_NoCache = TRUE;
  175. m_UnlimCacheInMemorySize = 250;
  176. m_LimCacheInMemorySize = 0;
  177. }
  178. else
  179. {
  180. m_LimCache = TRUE;
  181. if (FAILED(hr = mk.QueryValue(MD_ASP_SCRIPTFILECACHESIZE, m_LimCacheInMemorySize)))
  182. {
  183. // m_LimCacheInMemorySize = 250;
  184. break;
  185. }
  186. m_UnlimCacheInMemorySize = 250;
  187. }
  188. //
  189. m_MetaPath = mk.QueryMetaPath();
  190. } while (FALSE);
  191. return hr;
  192. }
  193. HRESULT
  194. CAppData::Save()
  195. {
  196. ASSERT(!m_MetaPath.IsEmpty());
  197. CComAuthInfo auth(m_ServerName, m_UserName, m_UserPassword);
  198. CMetaKey mk(&auth, m_MetaPath, METADATA_PERMISSION_WRITE);
  199. HRESULT hr = mk.QueryResult();
  200. if (FAILED(hr))
  201. return hr;
  202. do
  203. {
  204. CString buf;
  205. if (FAILED(hr = mk.SetValue(MD_ASP_ALLOWSESSIONSTATE, m_EnableSession)))
  206. break;
  207. if (FAILED(hr = mk.SetValue(MD_ASP_BUFFERINGON, m_EnableBuffering)))
  208. break;
  209. if (FAILED(hr = mk.SetValue(MD_ASP_ENABLEPARENTPATHS, m_EnableParents)))
  210. break;
  211. if (FAILED(hr = mk.SetValue(MD_ASP_SESSIONTIMEOUT, m_SessionTimeout)))
  212. break;
  213. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTTIMEOUT, m_ScriptTimeout)))
  214. break;
  215. buf = m_Languages;
  216. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTLANGUAGE, buf)))
  217. break;
  218. //
  219. if (FAILED(hr = mk.SetValue(MD_ASP_ENABLESERVERDEBUG, m_ServerDebug)))
  220. break;
  221. if (FAILED(hr = mk.SetValue(MD_ASP_ENABLECLIENTDEBUG, m_ClientDebug)))
  222. break;
  223. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTERRORSSENTTOBROWSER, m_SendAspError)))
  224. break;
  225. buf = m_DefaultError;
  226. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTERRORMESSAGE, buf)))
  227. break;
  228. //
  229. if (FAILED(hr = m_Mappings.Save(&mk)))
  230. break;
  231. if (FAILED(hr = mk.SetValue(MD_CACHE_EXTENSIONS, m_CacheISAPI)))
  232. break;
  233. //
  234. if (FAILED(hr = mk.SetValue(MD_ASP_LOGERRORREQUESTS, m_LogFailures)))
  235. break;
  236. if (FAILED(hr = mk.SetValue(MD_ASP_EXCEPTIONCATCHENABLE, m_DebugExcept)))
  237. break;
  238. if (FAILED(hr = mk.SetValue(MD_SCRIPT_TIMEOUT, m_CgiTimeout)))
  239. break;
  240. //
  241. if (m_RecycleTimespan && m_Timespan > 0)
  242. {
  243. if (FAILED(hr = mk.SetValue(MD_APP_PERIODIC_RESTART_TIME, m_Timespan)))
  244. break;
  245. }
  246. else
  247. {
  248. if (FAILED(hr = mk.SetValue(MD_APP_PERIODIC_RESTART_TIME, 0)))
  249. break;
  250. }
  251. if (m_RecycleRequest && m_Requests > 0)
  252. {
  253. if (FAILED(hr = mk.SetValue(MD_APP_PERIODIC_RESTART_REQUESTS, m_Requests)))
  254. break;
  255. }
  256. else
  257. {
  258. if (FAILED(hr = mk.SetValue(MD_APP_PERIODIC_RESTART_REQUESTS, 0)))
  259. break;
  260. }
  261. if (!m_RecycleTimer)
  262. {
  263. m_Timers.clear();
  264. }
  265. if (FAILED(hr = mk.SetValue(MD_APP_PERIODIC_RESTART_SCHEDULE, m_Timers)))
  266. break;
  267. //
  268. buf = m_DiskCacheDir;
  269. if (FAILED(hr = mk.SetValue(MD_ASP_DISKTEMPLATECACHEDIRECTORY, buf)))
  270. break;
  271. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTENGINECACHEMAX, m_ScriptEngCacheMax)))
  272. break;
  273. int inmem = 0;
  274. if (m_NoCache)
  275. {
  276. m_TotalCacheSize = 0;
  277. }
  278. else if (m_UnlimCache)
  279. {
  280. m_TotalCacheSize = -1;
  281. inmem = m_UnlimCacheInMemorySize;
  282. }
  283. else
  284. {
  285. inmem = m_LimCacheInMemorySize;
  286. }
  287. if (FAILED(hr = mk.SetValue(MD_ASP_MAXDISKTEMPLATECACHEFILES, m_TotalCacheSize)))
  288. break;
  289. if (FAILED(hr = mk.SetValue(MD_ASP_SCRIPTFILECACHESIZE, inmem)))
  290. break;
  291. } while (FALSE);
  292. return hr;
  293. }
  294. BOOL
  295. CAppData::IsMasterInstance()
  296. {
  297. return CMetabasePath::IsMasterInstance(m_MetaPath);
  298. }
  299. CAppPropSheet::CAppPropSheet()
  300. {
  301. static TCHAR title[256];
  302. ::LoadString(_Module.GetResourceInstance(), IDS_SHEET_TITLE, title, 256);
  303. m_psh.pszCaption = title;
  304. }
  305. LRESULT
  306. CAppPropSheet::OnInitDialog(HWND hDlg, LPARAM)
  307. {
  308. return 0;
  309. }
  310. void
  311. CAppPropSheet::OnKeyDown(UINT nChar, UINT nRepCount, UINT nFlags)
  312. {
  313. }