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.

1200 lines
35 KiB

  1. /****************************************************************************\
  2. *
  3. * apprdlg.cpp
  4. *
  5. * Created: William Taylor (wtaylor) 01/22/01
  6. *
  7. * MS Ratings Approved Sites Property Page
  8. *
  9. \****************************************************************************/
  10. #include "msrating.h"
  11. #include "mslubase.h"
  12. #include "apprdlg.h" // CApprovedSitesDialog
  13. #include "debug.h" // TraceMsg()
  14. #include "parselbl.h"
  15. #include "picsrule.h"
  16. #include <contxids.h> // Help Context ID's
  17. #include <mluisupp.h> // SHWinHelpOnDemandWrap() and MLLoadStringA()
  18. #include <wininet.h>
  19. #include <comctrlp.h>
  20. // $BUG - These should not be global variables but within CApprovedSitesDialog
  21. int g_iAllowAlways,g_iAllowNever;
  22. // $KLUDGE begins -- These should not be a global set outside the class!!
  23. extern PICSRulesRatingSystem * g_pApprovedPRRS;
  24. extern PICSRulesRatingSystem * g_pApprovedPRRSPreApply;
  25. extern HANDLE g_HandleGlobalCounter,g_ApprovedSitesHandleGlobalCounter;
  26. extern long g_lGlobalCounterValue,g_lApprovedSitesGlobalCounterValue;
  27. extern HMODULE g_hURLMON,g_hWININET;
  28. // $KLUDGE ends -- These should not be a global set outside the class!!
  29. //The FN_INTERNETCRACKURL type describes the URLMON function InternetCrackUrl
  30. typedef BOOL (*FN_INTERNETCRACKURL)(LPCTSTR lpszUrl,DWORD dwUrlLength,DWORD dwFlags,LPURL_COMPONENTS lpUrlComponents);
  31. // useful macro for getting rid of leaks.
  32. #define SAFEDELETE(ptr) \
  33. if(ptr) \
  34. { \
  35. delete ptr; \
  36. ptr = NULL; \
  37. }
  38. DWORD CApprovedSitesDialog::aIds[] = {
  39. IDC_STATIC1, IDH_IGNORE,
  40. IDC_STATIC2, IDH_IGNORE,
  41. IDC_STATIC_ALLOW, IDH_PICSRULES_APPROVEDEDIT,
  42. IDC_PICSRULESAPPROVEDEDIT, IDH_PICSRULES_APPROVEDEDIT,
  43. IDC_PICSRULESAPPROVEDALWAYS, IDH_PICSRULES_APPROVEDALWAYS,
  44. IDC_PICSRULESAPPROVEDNEVER, IDH_PICSRULES_APPROVEDNEVER,
  45. IDC_STATIC_LIST, IDH_PICSRULES_APPROVEDLIST,
  46. IDC_PICSRULESAPPROVEDLIST, IDH_PICSRULES_APPROVEDLIST,
  47. IDC_PICSRULESAPPROVEDREMOVE, IDH_PICSRULES_APPROVEDREMOVE,
  48. 0,0
  49. };
  50. CApprovedSitesDialog::CApprovedSitesDialog( PRSD * p_pPRSD )
  51. {
  52. ASSERT( p_pPRSD );
  53. m_pPRSD = p_pPRSD;
  54. }
  55. void CApprovedSitesDialog::SetListImages( HIMAGELIST hImageList )
  56. {
  57. HIMAGELIST hOldImageList;
  58. hOldImageList = ListView_SetImageList( GetDlgItem(IDC_PICSRULESAPPROVEDLIST), hImageList, LVSIL_SMALL );
  59. if ( hOldImageList != NULL )
  60. {
  61. ImageList_Destroy( hOldImageList );
  62. }
  63. }
  64. LRESULT CApprovedSitesDialog::OnSysColorChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  65. {
  66. HICON hIcon;
  67. HIMAGELIST hImageList;
  68. UINT flags = 0;
  69. HWND hDlg = m_hWnd;
  70. ListView_SetBkColor(GetDlgItem(IDC_PICSRULESAPPROVEDLIST),
  71. GetSysColor(COLOR_WINDOW));
  72. if(IS_WINDOW_RTL_MIRRORED(hDlg))
  73. {
  74. flags |= ILC_MIRROR;
  75. }
  76. hImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
  77. GetSystemMetrics(SM_CYSMICON),
  78. flags,
  79. 2,
  80. 0);
  81. hIcon=(HICON) LoadImage(g_hInstance,
  82. MAKEINTRESOURCE(IDI_ACCEPTALWAYS),
  83. IMAGE_ICON,
  84. 16,
  85. 16,
  86. LR_LOADTRANSPARENT|LR_DEFAULTCOLOR|LR_CREATEDIBSECTION);
  87. g_iAllowAlways=ImageList_AddIcon( hImageList, hIcon );
  88. DestroyIcon(hIcon);
  89. hIcon=(HICON) LoadImage(g_hInstance,
  90. MAKEINTRESOURCE(IDI_ACCEPTNEVER),
  91. IMAGE_ICON,
  92. 16,
  93. 16,
  94. LR_LOADTRANSPARENT|LR_DEFAULTCOLOR|LR_CREATEDIBSECTION);
  95. g_iAllowNever=ImageList_AddIcon( hImageList, hIcon );
  96. DestroyIcon(hIcon);
  97. SetListImages( hImageList );
  98. return 0L;
  99. }
  100. LRESULT CApprovedSitesDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  101. {
  102. RECT Rect;
  103. HDC hDC;
  104. LV_COLUMN lvColumn;
  105. TEXTMETRIC tm;
  106. HICON hIcon;
  107. HIMAGELIST hImageList;
  108. int iCounter;
  109. UINT flags = 0;
  110. HWND hDlg = m_hWnd;
  111. // if (m_pPRSD && m_pPRSD->pPU != NULL) {
  112. //set defaults for controls
  113. // }
  114. ::GetWindowRect(GetDlgItem(IDC_PICSRULESAPPROVEDLIST),&Rect);
  115. tm.tmAveCharWidth=0;
  116. if(hDC=GetDC())
  117. {
  118. GetTextMetrics(hDC,&tm);
  119. ReleaseDC(hDC);
  120. }
  121. lvColumn.mask=LVCF_FMT|LVCF_WIDTH;
  122. lvColumn.fmt=LVCFMT_LEFT;
  123. lvColumn.cx=Rect.right-Rect.left
  124. -GetSystemMetrics(SM_CXVSCROLL)
  125. -GetSystemMetrics(SM_CXSMICON)
  126. -tm.tmAveCharWidth;
  127. SendDlgItemMessage(IDC_PICSRULESAPPROVEDLIST,
  128. LVM_INSERTCOLUMN,
  129. (WPARAM) 0,
  130. (LPARAM) &lvColumn);
  131. if(IS_WINDOW_RTL_MIRRORED(hDlg))
  132. {
  133. flags |= ILC_MIRROR;
  134. }
  135. hImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
  136. GetSystemMetrics(SM_CYSMICON),
  137. flags,
  138. 2,
  139. 0);
  140. hIcon=(HICON) LoadImage(g_hInstance,
  141. MAKEINTRESOURCE(IDI_ACCEPTALWAYS),
  142. IMAGE_ICON,
  143. 16,
  144. 16,
  145. LR_LOADTRANSPARENT|LR_DEFAULTCOLOR|LR_CREATEDIBSECTION);
  146. g_iAllowAlways = ImageList_AddIcon( hImageList, hIcon );
  147. DestroyIcon(hIcon);
  148. hIcon=(HICON) LoadImage(g_hInstance,
  149. MAKEINTRESOURCE(IDI_ACCEPTNEVER),
  150. IMAGE_ICON,
  151. 16,
  152. 16,
  153. LR_LOADTRANSPARENT|LR_DEFAULTCOLOR|LR_CREATEDIBSECTION);
  154. g_iAllowNever = ImageList_AddIcon( hImageList, hIcon );
  155. DestroyIcon(hIcon);
  156. SetListImages( hImageList );
  157. //disable the remove button until someone selects something
  158. ::EnableWindow(GetDlgItem(IDC_PICSRULESAPPROVEDREMOVE),FALSE);
  159. //disable the always and never buttons until someone types something
  160. ::EnableWindow(GetDlgItem(IDC_PICSRULESAPPROVEDNEVER),FALSE);
  161. ::EnableWindow(GetDlgItem(IDC_PICSRULESAPPROVEDALWAYS),FALSE);
  162. if(g_pApprovedPRRSPreApply!=NULL)
  163. {
  164. delete g_pApprovedPRRSPreApply;
  165. g_pApprovedPRRSPreApply=NULL;
  166. }
  167. if(g_lApprovedSitesGlobalCounterValue!=SHGlobalCounterGetValue(g_ApprovedSitesHandleGlobalCounter))
  168. {
  169. PICSRulesRatingSystem * pPRRS=NULL;
  170. HRESULT hRes;
  171. hRes=PICSRulesReadFromRegistry(PICSRULES_APPROVEDSITES,&pPRRS);
  172. if(SUCCEEDED(hRes))
  173. {
  174. if(g_pApprovedPRRS!=NULL)
  175. {
  176. delete g_pApprovedPRRS;
  177. }
  178. g_pApprovedPRRS=pPRRS;
  179. }
  180. g_lApprovedSitesGlobalCounterValue=SHGlobalCounterGetValue(g_ApprovedSitesHandleGlobalCounter);
  181. }
  182. if(g_pApprovedPRRS==NULL)
  183. {
  184. //nothing to do
  185. return 1L;
  186. }
  187. //copy master list to the PreApply list
  188. if(g_pApprovedPRRSPreApply!=NULL)
  189. {
  190. delete g_pApprovedPRRSPreApply;
  191. }
  192. g_pApprovedPRRSPreApply=new PICSRulesRatingSystem;
  193. if (g_pApprovedPRRSPreApply==NULL)
  194. {
  195. char szTitle[MAX_PATH],szMessage[MAX_PATH];
  196. //out of memory, so we init on the stack
  197. MLLoadString(IDS_ERROR,(LPTSTR) szTitle,MAX_PATH);
  198. MLLoadString(IDS_PICSRULES_OUTOFMEMORY,(LPTSTR) szMessage,MAX_PATH);
  199. MessageBox((LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK|MB_ICONERROR);
  200. return 1L;
  201. }
  202. for(iCounter=0;iCounter<g_pApprovedPRRS->m_arrpPRPolicy.Length();iCounter++)
  203. {
  204. PICSRulesPolicy * pPRPolicy,* pPRPolicyToCopy;
  205. PICSRulesByURL * pPRByURL,* pPRByURLToCopy;
  206. PICSRulesByURLExpression * pPRByURLExpression,* pPRByURLExpressionToCopy;
  207. pPRPolicy=new PICSRulesPolicy;
  208. if(pPRPolicy==NULL)
  209. {
  210. char szTitle[MAX_PATH],szMessage[MAX_PATH];
  211. //out of memory, so we init on the stack
  212. MLLoadString(IDS_ERROR,(LPTSTR) szTitle,MAX_PATH);
  213. MLLoadString(IDS_PICSRULES_OUTOFMEMORY,(LPTSTR) szMessage,MAX_PATH);
  214. MessageBox((LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK|MB_ICONERROR);
  215. return 1L;
  216. }
  217. pPRPolicyToCopy=g_pApprovedPRRS->m_arrpPRPolicy[iCounter];
  218. pPRPolicy->m_PRPolicyAttribute=pPRPolicyToCopy->m_PRPolicyAttribute;
  219. pPRByURL=new PICSRulesByURL;
  220. if(pPRByURL==NULL)
  221. {
  222. char szTitle[MAX_PATH],szMessage[MAX_PATH];
  223. //out of memory, so we init on the stack
  224. MLLoadString(IDS_ERROR,(LPTSTR) szTitle,MAX_PATH);
  225. MLLoadString(IDS_PICSRULES_OUTOFMEMORY,(LPTSTR) szMessage,MAX_PATH);
  226. MessageBox((LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK|MB_ICONERROR);
  227. return 1L;
  228. }
  229. if(pPRPolicy->m_PRPolicyAttribute==PR_POLICY_ACCEPTBYURL)
  230. {
  231. pPRByURLToCopy=pPRPolicyToCopy->m_pPRAcceptByURL;
  232. pPRPolicy->m_pPRAcceptByURL=pPRByURL;
  233. }
  234. else
  235. {
  236. pPRByURLToCopy=pPRPolicyToCopy->m_pPRRejectByURL;
  237. pPRPolicy->m_pPRRejectByURL=pPRByURL;
  238. }
  239. pPRByURLExpression=new PICSRulesByURLExpression;
  240. if(pPRByURLExpression==NULL)
  241. {
  242. char szTitle[MAX_PATH],szMessage[MAX_PATH];
  243. //out of memory, so we init on the stack
  244. MLLoadString(IDS_ERROR,(LPTSTR) szTitle,MAX_PATH);
  245. MLLoadString(IDS_PICSRULES_OUTOFMEMORY,(LPTSTR) szMessage,MAX_PATH);
  246. MessageBox((LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK|MB_ICONERROR);
  247. return 1L;
  248. }
  249. pPRByURLExpressionToCopy=pPRByURLToCopy->m_arrpPRByURL[0];
  250. if(pPRByURLExpressionToCopy==NULL)
  251. {
  252. //we shouldn't ever get here
  253. MyMessageBox(m_hWnd, IDS_PICSRULES_NOAPPROVEDSAVE, IDS_ERROR, MB_OK|MB_ICONERROR);
  254. delete pPRPolicy;
  255. pPRPolicy = NULL;
  256. return 1L;
  257. }
  258. pPRByURLExpression->m_fInternetPattern=pPRByURLExpressionToCopy->m_fInternetPattern;
  259. pPRByURLExpression->m_bNonWild=pPRByURLExpressionToCopy->m_bNonWild;
  260. pPRByURLExpression->m_bSpecified=pPRByURLExpressionToCopy->m_bSpecified;
  261. pPRByURLExpression->m_etstrScheme.Set(pPRByURLExpressionToCopy->m_etstrScheme.Get());
  262. pPRByURLExpression->m_etstrUser.Set(pPRByURLExpressionToCopy->m_etstrUser.Get());
  263. pPRByURLExpression->m_etstrHost.Set(pPRByURLExpressionToCopy->m_etstrHost.Get());
  264. pPRByURLExpression->m_etstrPort.Set(pPRByURLExpressionToCopy->m_etstrPort.Get());
  265. pPRByURLExpression->m_etstrPath.Set(pPRByURLExpressionToCopy->m_etstrPath.Get());
  266. pPRByURLExpression->m_etstrURL.Set(pPRByURLExpressionToCopy->m_etstrURL.Get());
  267. pPRByURL->m_arrpPRByURL.Append(pPRByURLExpression);
  268. g_pApprovedPRRSPreApply->m_arrpPRPolicy.Append(pPRPolicy);
  269. }
  270. //fill in the listview with known items
  271. for(iCounter=0;iCounter<g_pApprovedPRRSPreApply->m_arrpPRPolicy.Length();iCounter++)
  272. {
  273. BOOL fAcceptReject;
  274. PICSRulesPolicy * pPRPolicy;
  275. PICSRulesByURLExpression * pPRByURLExpression;
  276. LV_ITEM lvItem;
  277. pPRPolicy=g_pApprovedPRRSPreApply->m_arrpPRPolicy[iCounter];
  278. if(pPRPolicy->m_PRPolicyAttribute==PR_POLICY_ACCEPTBYURL)
  279. {
  280. fAcceptReject=PICSRULES_ALWAYS;
  281. pPRByURLExpression=pPRPolicy->m_pPRAcceptByURL->m_arrpPRByURL[0];
  282. }
  283. else
  284. {
  285. fAcceptReject=PICSRULES_NEVER;
  286. pPRByURLExpression=pPRPolicy->m_pPRRejectByURL->m_arrpPRByURL[0];
  287. }
  288. ZeroMemory(&lvItem,sizeof(lvItem));
  289. lvItem.mask=LVIF_TEXT|LVIF_IMAGE;
  290. lvItem.pszText=pPRByURLExpression->m_etstrURL.Get();
  291. if(fAcceptReject==PICSRULES_NEVER)
  292. {
  293. lvItem.iImage=g_iAllowNever;
  294. }
  295. else
  296. {
  297. lvItem.iImage=g_iAllowAlways;
  298. }
  299. if(SendDlgItemMessage(IDC_PICSRULESAPPROVEDLIST,
  300. LVM_INSERTITEM,
  301. (WPARAM) 0,
  302. (LPARAM) &lvItem)==-1)
  303. {
  304. return 1L;
  305. }
  306. }
  307. // Set the column width to satisfy longest element
  308. ListView_SetColumnWidth(
  309. GetDlgItem(IDC_PICSRULESAPPROVEDLIST),
  310. 0,
  311. LVSCW_AUTOSIZE);
  312. // set focus to first item in list
  313. ListView_SetItemState(
  314. GetDlgItem(IDC_PICSRULESAPPROVEDLIST),
  315. 0,
  316. LVIS_FOCUSED,
  317. LVIS_FOCUSED);
  318. bHandled = FALSE;
  319. return 1L; // Let the system set the focus
  320. }
  321. LRESULT CApprovedSitesDialog::OnPicsRulesEditUpdate(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  322. {
  323. INT_PTR iCount;
  324. iCount=SendDlgItemMessage(IDC_PICSRULESAPPROVEDEDIT,
  325. WM_GETTEXTLENGTH,
  326. (WPARAM) 0,
  327. (LPARAM) 0);
  328. if(iCount>0)
  329. {
  330. ::EnableWindow(GetDlgItem(IDC_PICSRULESAPPROVEDNEVER),TRUE);
  331. ::EnableWindow(GetDlgItem(IDC_PICSRULESAPPROVEDALWAYS),TRUE);
  332. }
  333. else
  334. {
  335. ::SetFocus(GetDlgItem(IDC_PICSRULESAPPROVEDEDIT));
  336. SendDlgItemMessage(IDC_PICSRULESAPPROVEDEDIT,
  337. EM_SETSEL,
  338. (WPARAM) 0,
  339. (LPARAM) -1);
  340. SendDlgItemMessage(IDC_PICSRULESAPPROVEDNEVER,
  341. BM_SETSTYLE,
  342. (WPARAM) BS_PUSHBUTTON,
  343. (LPARAM) MAKELPARAM(TRUE,0));
  344. SendDlgItemMessage(IDC_PICSRULESAPPROVEDALWAYS,
  345. BM_SETSTYLE,
  346. (WPARAM) BS_PUSHBUTTON,
  347. (LPARAM) MAKELPARAM(TRUE,0));
  348. ::EnableWindow(GetDlgItem(IDC_PICSRULESAPPROVEDNEVER),FALSE);
  349. ::EnableWindow(GetDlgItem(IDC_PICSRULESAPPROVEDALWAYS),FALSE);
  350. }
  351. return 1L;
  352. }
  353. LRESULT CApprovedSitesDialog::OnPicsRulesApprovedNever(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  354. {
  355. HRESULT hRes;
  356. hRes=PICSRulesApprovedSites(PICSRULES_NEVER);
  357. return 1L;
  358. }
  359. LRESULT CApprovedSitesDialog::OnPicsRulesApprovedAlways(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  360. {
  361. HRESULT hRes;
  362. hRes=PICSRulesApprovedSites(PICSRULES_ALWAYS);
  363. return 1L;
  364. }
  365. LRESULT CApprovedSitesDialog::OnPicsRulesApprovedRemove(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  366. {
  367. int iNumApproved,iCounter,iNumSelected,
  368. iSubCounter,iItem=-1;
  369. LPTSTR lpszRemoveURL;
  370. LV_ITEM lvItem;
  371. PICSRulesRatingSystem * pNewApprovedPRRS;
  372. if(g_pApprovedPRRSPreApply==NULL)
  373. {
  374. //nothing to do
  375. return 1L;
  376. }
  377. iNumApproved=g_pApprovedPRRSPreApply->m_arrpPRPolicy.Length();
  378. iNumSelected=ListView_GetSelectedCount(GetDlgItem(IDC_PICSRULESAPPROVEDLIST));
  379. if(iNumSelected==0)
  380. {
  381. //nothing to do
  382. return 1L;
  383. }
  384. lpszRemoveURL=new char[INTERNET_MAX_URL_LENGTH+1];
  385. if(lpszRemoveURL==NULL)
  386. {
  387. return(E_OUTOFMEMORY);
  388. }
  389. for(iCounter=0;iCounter<iNumSelected;iCounter++)
  390. {
  391. ZeroMemory(&lvItem,sizeof(lvItem));
  392. iItem=ListView_GetNextItem(GetDlgItem(IDC_PICSRULESAPPROVEDLIST),iItem,LVNI_SELECTED);
  393. lvItem.iItem=iItem;
  394. lvItem.pszText=lpszRemoveURL;
  395. lvItem.cchTextMax=INTERNET_MAX_URL_LENGTH;
  396. SendDlgItemMessage(IDC_PICSRULESAPPROVEDLIST,LVM_GETITEMTEXT,(WPARAM) iItem,(LPARAM) &lvItem);
  397. for(iSubCounter=0;iSubCounter<iNumApproved;iSubCounter++)
  398. {
  399. PICSRulesPolicy *pPRPolicy;
  400. PICSRulesByURLExpression * pPRByURLExpression;
  401. pPRPolicy=g_pApprovedPRRSPreApply->m_arrpPRPolicy[iSubCounter];
  402. if(pPRPolicy==NULL)
  403. {
  404. continue;
  405. }
  406. if(pPRPolicy->m_PRPolicyAttribute==PR_POLICY_REJECTBYURL)
  407. {
  408. if(pPRPolicy->m_pPRRejectByURL==NULL)
  409. {
  410. continue;
  411. }
  412. pPRByURLExpression=pPRPolicy->m_pPRRejectByURL->m_arrpPRByURL[0];
  413. }
  414. else
  415. {
  416. if(pPRPolicy->m_pPRAcceptByURL==NULL)
  417. {
  418. continue;
  419. }
  420. pPRByURLExpression=pPRPolicy->m_pPRAcceptByURL->m_arrpPRByURL[0];
  421. }
  422. if(pPRByURLExpression==NULL)
  423. {
  424. continue;
  425. }
  426. if(pPRByURLExpression->m_etstrURL.Get()==NULL)
  427. {
  428. continue;
  429. }
  430. if(lstrcmp(pPRByURLExpression->m_etstrURL.Get(),lpszRemoveURL)==0)
  431. {
  432. //we found one to delete
  433. if(pPRPolicy!=NULL)
  434. {
  435. delete pPRPolicy;
  436. pPRPolicy = NULL;
  437. }
  438. g_pApprovedPRRSPreApply->m_arrpPRPolicy[iSubCounter]=0;
  439. }
  440. }
  441. }
  442. //delete them from the list view
  443. for(iCounter=0;iCounter<iNumSelected;iCounter++)
  444. {
  445. iItem=ListView_GetNextItem(GetDlgItem(IDC_PICSRULESAPPROVEDLIST),-1,LVNI_SELECTED);
  446. ListView_DeleteItem(GetDlgItem(IDC_PICSRULESAPPROVEDLIST),iItem);
  447. }
  448. //rebuild the approved PICSRules structure
  449. pNewApprovedPRRS=new PICSRulesRatingSystem;
  450. for(iCounter=0;iCounter<iNumApproved;iCounter++)
  451. {
  452. if(g_pApprovedPRRSPreApply->m_arrpPRPolicy[iCounter]!=NULL)
  453. {
  454. pNewApprovedPRRS->m_arrpPRPolicy.Append(g_pApprovedPRRSPreApply->m_arrpPRPolicy[iCounter]);
  455. }
  456. }
  457. g_pApprovedPRRSPreApply->m_arrpPRPolicy.ClearAll();
  458. delete g_pApprovedPRRSPreApply;
  459. g_pApprovedPRRSPreApply=pNewApprovedPRRS;
  460. MarkChanged();
  461. ::SetFocus(GetDlgItem(IDC_PICSRULESAPPROVEDEDIT));
  462. SendDlgItemMessage(IDC_PICSRULESAPPROVEDEDIT,
  463. EM_SETSEL,
  464. (WPARAM) 0,
  465. (LPARAM) -1);
  466. delete lpszRemoveURL;
  467. lpszRemoveURL = NULL;
  468. return 1L;
  469. }
  470. LRESULT CApprovedSitesDialog::OnPicsRulesListChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  471. {
  472. // NMLISTVIEW *pNMListView=(NMLISTVIEW *)pnmh;
  473. BOOL fEnable = FALSE;
  474. if(ListView_GetSelectedCount(GetDlgItem(IDC_PICSRULESAPPROVEDLIST)) > 0)
  475. {
  476. fEnable = TRUE;
  477. }
  478. ::EnableWindow(GetDlgItem(IDC_PICSRULESAPPROVEDREMOVE),fEnable);
  479. return 0L;
  480. }
  481. LRESULT CApprovedSitesDialog::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  482. {
  483. PRSD * pPRSD = m_pPRSD;
  484. LPPSHNOTIFY lpPSHNotify = (LPPSHNOTIFY) pnmh;
  485. int iCounter,iLoopCounter;
  486. if(g_pApprovedPRRSPreApply==NULL)
  487. {
  488. //we don't have anything to set
  489. return PSNRET_NOERROR;
  490. }
  491. //make the Approved Sites Global
  492. if(g_pApprovedPRRS!=NULL)
  493. {
  494. delete g_pApprovedPRRS;
  495. }
  496. g_pApprovedPRRS=new PICSRulesRatingSystem;
  497. if(g_pApprovedPRRS==NULL)
  498. {
  499. char szTitle[MAX_PATH],szMessage[MAX_PATH];
  500. //out of memory, so we init on the stack
  501. MLLoadString(IDS_ERROR,(LPTSTR) szTitle,MAX_PATH);
  502. MLLoadString(IDS_PICSRULES_OUTOFMEMORY,(LPTSTR) szMessage,MAX_PATH);
  503. MessageBox((LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK|MB_ICONERROR);
  504. return PSNRET_INVALID_NOCHANGEPAGE;
  505. }
  506. for(iLoopCounter=0;iLoopCounter<2;iLoopCounter++)
  507. {
  508. for(iCounter=0;iCounter<g_pApprovedPRRSPreApply->m_arrpPRPolicy.Length();iCounter++)
  509. {
  510. PICSRulesPolicy * pPRPolicy,* pPRPolicyToCopy;
  511. PICSRulesByURL * pPRByURL,* pPRByURLToCopy;
  512. PICSRulesByURLExpression * pPRByURLExpression,* pPRByURLExpressionToCopy;
  513. pPRPolicyToCopy=g_pApprovedPRRSPreApply->m_arrpPRPolicy[iCounter];
  514. if(pPRPolicyToCopy->m_PRPolicyAttribute==PR_POLICY_ACCEPTBYURL)
  515. {
  516. pPRByURLToCopy=pPRPolicyToCopy->m_pPRAcceptByURL;
  517. }
  518. else
  519. {
  520. pPRByURLToCopy=pPRPolicyToCopy->m_pPRRejectByURL;
  521. }
  522. pPRByURLExpressionToCopy=pPRByURLToCopy->m_arrpPRByURL[0];
  523. if (!pPRByURLExpressionToCopy)
  524. {
  525. //we shouldn't ever get here
  526. MyMessageBox(m_hWnd, IDS_PICSRULES_NOAPPROVEDSAVE, IDS_ERROR, MB_OK|MB_ICONERROR);
  527. return PSNRET_INVALID_NOCHANGEPAGE;
  528. }
  529. //we want to put all of the non-sitewide approved sites first
  530. //so that a user can specify, allow all of xyz.com except for
  531. //xyz.com/foo.htm
  532. switch(iLoopCounter)
  533. {
  534. case 0:
  535. {
  536. if((pPRByURLExpressionToCopy->m_bNonWild)&BYURL_PATH)
  537. {
  538. break;
  539. }
  540. else
  541. {
  542. continue;
  543. }
  544. }
  545. case 1:
  546. {
  547. if(!((pPRByURLExpressionToCopy->m_bNonWild)&BYURL_PATH))
  548. {
  549. break;
  550. }
  551. else
  552. {
  553. continue;
  554. }
  555. }
  556. }
  557. pPRPolicy=new PICSRulesPolicy;
  558. if(pPRPolicy==NULL)
  559. {
  560. char szTitle[MAX_PATH],szMessage[MAX_PATH];
  561. //out of memory, so we init on the stack
  562. MLLoadString(IDS_ERROR,(LPTSTR) szTitle,MAX_PATH);
  563. MLLoadString(IDS_PICSRULES_OUTOFMEMORY,(LPTSTR) szMessage,MAX_PATH);
  564. MessageBox((LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK|MB_ICONERROR);
  565. return PSNRET_INVALID_NOCHANGEPAGE;
  566. }
  567. pPRPolicy->m_PRPolicyAttribute=pPRPolicyToCopy->m_PRPolicyAttribute;
  568. pPRByURL=new PICSRulesByURL;
  569. if(pPRByURL==NULL)
  570. {
  571. char szTitle[MAX_PATH],szMessage[MAX_PATH];
  572. //out of memory, so we init on the stack
  573. MLLoadString(IDS_ERROR,(LPTSTR) szTitle,MAX_PATH);
  574. MLLoadString(IDS_PICSRULES_OUTOFMEMORY,(LPTSTR) szMessage,MAX_PATH);
  575. MessageBox((LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK|MB_ICONERROR);
  576. return PSNRET_INVALID_NOCHANGEPAGE;
  577. }
  578. if(pPRPolicy->m_PRPolicyAttribute==PR_POLICY_ACCEPTBYURL)
  579. {
  580. pPRPolicy->m_pPRAcceptByURL=pPRByURL;
  581. }
  582. else
  583. {
  584. pPRPolicy->m_pPRRejectByURL=pPRByURL;
  585. }
  586. pPRByURLExpression=new PICSRulesByURLExpression;
  587. if(pPRByURLExpression==NULL)
  588. {
  589. char szTitle[MAX_PATH],szMessage[MAX_PATH];
  590. //out of memory, so we init on the stack
  591. MLLoadString(IDS_ERROR,(LPTSTR) szTitle,MAX_PATH);
  592. MLLoadString(IDS_PICSRULES_OUTOFMEMORY,(LPTSTR) szMessage,MAX_PATH);
  593. MessageBox((LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK|MB_ICONERROR);
  594. return PSNRET_INVALID_NOCHANGEPAGE;
  595. }
  596. pPRByURLExpression->m_fInternetPattern=pPRByURLExpressionToCopy->m_fInternetPattern;
  597. pPRByURLExpression->m_bNonWild=pPRByURLExpressionToCopy->m_bNonWild;
  598. pPRByURLExpression->m_bSpecified=pPRByURLExpressionToCopy->m_bSpecified;
  599. pPRByURLExpression->m_etstrScheme.Set(pPRByURLExpressionToCopy->m_etstrScheme.Get());
  600. pPRByURLExpression->m_etstrUser.Set(pPRByURLExpressionToCopy->m_etstrUser.Get());
  601. pPRByURLExpression->m_etstrHost.Set(pPRByURLExpressionToCopy->m_etstrHost.Get());
  602. pPRByURLExpression->m_etstrPort.Set(pPRByURLExpressionToCopy->m_etstrPort.Get());
  603. pPRByURLExpression->m_etstrPath.Set(pPRByURLExpressionToCopy->m_etstrPath.Get());
  604. pPRByURLExpression->m_etstrURL.Set(pPRByURLExpressionToCopy->m_etstrURL.Get());
  605. pPRByURL->m_arrpPRByURL.Append(pPRByURLExpression);
  606. g_pApprovedPRRS->m_arrpPRPolicy.Append(pPRPolicy);
  607. }
  608. }
  609. PICSRulesDeleteSystem(PICSRULES_APPROVEDSITES);
  610. PICSRulesSaveToRegistry(PICSRULES_APPROVEDSITES,&g_pApprovedPRRS);
  611. SHGlobalCounterIncrement(g_ApprovedSitesHandleGlobalCounter);
  612. if ( ! lpPSHNotify->lParam )
  613. {
  614. // Apply
  615. return PSNRET_NOERROR;
  616. }
  617. // Do this if hit OK or Cancel, not Apply
  618. OnReset( idCtrl, pnmh, bHandled );
  619. return PSNRET_NOERROR;
  620. }
  621. LRESULT CApprovedSitesDialog::OnReset(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  622. {
  623. // Do this if hit OK or Cancel, not Apply
  624. SendMessage( m_hWnd, WM_SETREDRAW, FALSE, 0L );
  625. SetListImages( NULL );
  626. SendMessage( m_hWnd, WM_SETREDRAW, TRUE, 0L );
  627. return 0L;
  628. }
  629. LRESULT CApprovedSitesDialog::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  630. {
  631. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO)lParam)->hItemHandle, ::szHelpFile,
  632. HELP_WM_HELP, (DWORD_PTR)(LPSTR)aIds);
  633. return 0L;
  634. }
  635. LRESULT CApprovedSitesDialog::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  636. {
  637. SHWinHelpOnDemandWrap((HWND)wParam, ::szHelpFile, HELP_CONTEXTMENU,
  638. (DWORD_PTR)(LPVOID)aIds);
  639. return 0L;
  640. }
  641. //
  642. // ShowBadUrl
  643. //
  644. // Show some ui telling user URL is bad when adding an approved site
  645. //
  646. void CApprovedSitesDialog::ShowBadUrl( void )
  647. {
  648. MyMessageBox(m_hWnd, IDS_PICSRULES_BADURLMSG, IDS_PICSRULES_BADURLTITLE, MB_OK|MB_ICONERROR);
  649. // set focus back to edit box and select all of it
  650. ::SetFocus(GetDlgItem(IDC_PICSRULESAPPROVEDEDIT));
  651. SendDlgItemMessage(IDC_PICSRULESAPPROVEDEDIT,
  652. EM_SETSEL,
  653. (WPARAM) 0,
  654. (LPARAM) -1);
  655. }
  656. //Processes adding sites to the Approved Sites list.
  657. //note, users will type in URLs _NOT_ in the form required
  658. //in the PICSRules spec. Thus, we will use InternetCrackURL
  659. //and fill in the appropriate fields for them.
  660. HRESULT CApprovedSitesDialog::PICSRulesApprovedSites(BOOL fAlwaysNever)
  661. {
  662. PICSRulesPolicy * pPRPolicy;
  663. PICSRulesByURL * pPRByURL;
  664. PICSRulesByURLExpression * pPRByURLExpression;
  665. LPSTR lpszSiteURL;
  666. HRESULT hr = NOERROR;
  667. URL_COMPONENTS URLComponents;
  668. FN_INTERNETCRACKURL pfnInternetCrackUrl;
  669. INTERNET_SCHEME INetScheme=INTERNET_SCHEME_DEFAULT;
  670. INTERNET_PORT INetPort=INTERNET_INVALID_PORT_NUMBER;
  671. LPSTR lpszScheme = NULL;
  672. LPSTR lpszHostName = NULL;
  673. LPSTR lpszUserName = NULL;
  674. LPSTR lpszPassword = NULL;
  675. LPSTR lpszUrlPath = NULL;
  676. LPSTR lpszExtraInfo = NULL;
  677. BOOL fAddedScheme=FALSE;
  678. LV_ITEM lvItem;
  679. LV_FINDINFO lvFindInfo;
  680. lpszSiteURL=new char[INTERNET_MAX_URL_LENGTH+1];
  681. if(lpszSiteURL==NULL)
  682. {
  683. return(E_OUTOFMEMORY);
  684. }
  685. //have we already processed it?
  686. SendDlgItemMessage(IDC_PICSRULESAPPROVEDEDIT,
  687. WM_GETTEXT,
  688. (WPARAM) INTERNET_MAX_URL_LENGTH,
  689. (LPARAM) lpszSiteURL);
  690. if(*lpszSiteURL=='\0')
  691. {
  692. //nothing to do
  693. delete lpszSiteURL;
  694. lpszSiteURL = NULL;
  695. return(E_INVALIDARG);
  696. }
  697. ZeroMemory(&lvFindInfo,sizeof(lvFindInfo));
  698. lvFindInfo.flags=LVFI_STRING;
  699. lvFindInfo.psz=lpszSiteURL;
  700. if(SendDlgItemMessage(IDC_PICSRULESAPPROVEDLIST,
  701. LVM_FINDITEM,
  702. (WPARAM) -1,
  703. (LPARAM) &lvFindInfo)!=-1)
  704. {
  705. //we already have settings for this URL
  706. MyMessageBox(m_hWnd, IDS_PICSRULES_DUPLICATEMSG, IDS_PICSRULES_DUPLICATETITLE, MB_OK|MB_ICONERROR);
  707. delete lpszSiteURL;
  708. lpszSiteURL = NULL;
  709. ::SetFocus(GetDlgItem(IDC_PICSRULESAPPROVEDEDIT));
  710. SendDlgItemMessage(IDC_PICSRULESAPPROVEDEDIT,
  711. EM_SETSEL,
  712. (WPARAM) 0,
  713. (LPARAM) -1);
  714. return(E_INVALIDARG);
  715. }
  716. //
  717. // Add a scheme if user didn't type one
  718. //
  719. LPSTR lpszTemp = new char[INTERNET_MAX_URL_LENGTH+1];
  720. DWORD cbBuffer = INTERNET_MAX_URL_LENGTH;
  721. hr = UrlApplySchemeA(lpszSiteURL, lpszTemp, &cbBuffer, 0);
  722. if(S_OK == hr)
  723. {
  724. // actually added a scheme - switch to new buffer
  725. delete lpszSiteURL;
  726. lpszSiteURL = lpszTemp;
  727. fAddedScheme = TRUE;
  728. }
  729. else
  730. {
  731. // delete temp buffer
  732. delete lpszTemp;
  733. lpszTemp = NULL;
  734. }
  735. //
  736. // Allocate all the pics rules structures we need
  737. //
  738. if(g_pApprovedPRRSPreApply==NULL)
  739. {
  740. g_pApprovedPRRSPreApply=new PICSRulesRatingSystem;
  741. if(g_pApprovedPRRSPreApply==NULL)
  742. {
  743. return(E_OUTOFMEMORY);
  744. }
  745. }
  746. pPRPolicy=new PICSRulesPolicy;
  747. if(pPRPolicy==NULL)
  748. {
  749. return(E_OUTOFMEMORY);
  750. }
  751. pPRByURL=new PICSRulesByURL;
  752. if(pPRByURL==NULL)
  753. {
  754. hr = E_OUTOFMEMORY;
  755. goto clean;
  756. }
  757. pPRByURLExpression=new PICSRulesByURLExpression;
  758. if(pPRByURLExpression==NULL)
  759. {
  760. hr = E_OUTOFMEMORY;
  761. goto clean;
  762. }
  763. //
  764. // Crack the URL
  765. //
  766. lpszScheme=new char[INTERNET_MAX_SCHEME_LENGTH+1];
  767. lpszHostName=new char[INTERNET_MAX_PATH_LENGTH+1];
  768. lpszUserName=new char[INTERNET_MAX_PATH_LENGTH+1];
  769. lpszPassword=new char[INTERNET_MAX_PATH_LENGTH+1];
  770. lpszUrlPath=new char[INTERNET_MAX_PATH_LENGTH+1];
  771. lpszExtraInfo=new char[INTERNET_MAX_PATH_LENGTH+1];
  772. if(lpszScheme==NULL ||
  773. lpszHostName==NULL ||
  774. lpszUserName==NULL ||
  775. lpszPassword==NULL ||
  776. lpszUrlPath==NULL ||
  777. lpszExtraInfo==NULL)
  778. {
  779. hr = E_OUTOFMEMORY;
  780. goto clean;
  781. }
  782. URLComponents.dwStructSize=sizeof(URL_COMPONENTS);
  783. URLComponents.lpszScheme=lpszScheme;
  784. URLComponents.dwSchemeLength=INTERNET_MAX_SCHEME_LENGTH;
  785. URLComponents.nScheme=INetScheme;
  786. URLComponents.lpszHostName=lpszHostName;
  787. URLComponents.dwHostNameLength=INTERNET_MAX_PATH_LENGTH;
  788. URLComponents.nPort=INetPort;
  789. URLComponents.lpszUserName=lpszUserName;
  790. URLComponents.dwUserNameLength=INTERNET_MAX_PATH_LENGTH;
  791. URLComponents.lpszPassword=lpszPassword;
  792. URLComponents.dwPasswordLength=INTERNET_MAX_PATH_LENGTH;
  793. URLComponents.lpszUrlPath=lpszUrlPath;
  794. URLComponents.dwUrlPathLength=INTERNET_MAX_PATH_LENGTH;
  795. URLComponents.lpszExtraInfo=lpszExtraInfo;
  796. URLComponents.dwExtraInfoLength=INTERNET_MAX_PATH_LENGTH;
  797. pfnInternetCrackUrl=(FN_INTERNETCRACKURL) GetProcAddress(g_hWININET,"InternetCrackUrlA");
  798. if(pfnInternetCrackUrl==NULL)
  799. {
  800. hr = E_UNEXPECTED;
  801. goto clean;
  802. }
  803. if(FALSE == pfnInternetCrackUrl(lpszSiteURL,0,ICU_DECODE,&URLComponents))
  804. {
  805. // failed to crack url
  806. ShowBadUrl();
  807. hr = E_INVALIDARG;
  808. goto clean;
  809. }
  810. //
  811. // Set up linkages of pics rules structures
  812. //
  813. hr=g_pApprovedPRRSPreApply->AddItem(PROID_POLICY,pPRPolicy);
  814. if(FAILED(hr))
  815. {
  816. goto clean;
  817. }
  818. if(fAlwaysNever==PICSRULES_NEVER)
  819. {
  820. pPRPolicy->m_PRPolicyAttribute=PR_POLICY_REJECTBYURL;
  821. pPRPolicy->AddItem(PROID_REJECTBYURL,pPRByURL);
  822. }
  823. else
  824. {
  825. pPRPolicy->m_PRPolicyAttribute=PR_POLICY_ACCEPTBYURL;
  826. pPRPolicy->AddItem(PROID_ACCEPTBYURL,pPRByURL);
  827. }
  828. pPRByURL->m_arrpPRByURL.Append(pPRByURLExpression);
  829. //
  830. // Use cracked URL components to fill in pics structs
  831. //
  832. pPRByURLExpression->m_fInternetPattern=TRUE;
  833. if((*lpszScheme!=NULL)&&(fAddedScheme==FALSE))
  834. {
  835. pPRByURLExpression->m_bNonWild|=BYURL_SCHEME;
  836. pPRByURLExpression->m_etstrScheme.SetTo(lpszScheme);
  837. }
  838. else
  839. {
  840. delete lpszScheme;
  841. lpszScheme = NULL;
  842. }
  843. pPRByURLExpression->m_bSpecified|=BYURL_SCHEME;
  844. if(*lpszUserName!=NULL)
  845. {
  846. pPRByURLExpression->m_bNonWild|=BYURL_USER;
  847. pPRByURLExpression->m_etstrUser.SetTo(lpszUserName);
  848. }
  849. else
  850. {
  851. delete lpszUserName;
  852. lpszUserName = NULL;
  853. }
  854. pPRByURLExpression->m_bSpecified|=BYURL_USER;
  855. if(*lpszHostName!=NULL)
  856. {
  857. pPRByURLExpression->m_bNonWild|=BYURL_HOST;
  858. pPRByURLExpression->m_etstrHost.SetTo(lpszHostName);
  859. }
  860. else
  861. {
  862. delete lpszHostName;
  863. lpszHostName = NULL;
  864. }
  865. pPRByURLExpression->m_bSpecified|=BYURL_HOST;
  866. if(*lpszUrlPath!=NULL)
  867. {
  868. pPRByURLExpression->m_bNonWild|=BYURL_PATH;
  869. pPRByURLExpression->m_etstrPath.SetTo(lpszUrlPath);
  870. }
  871. else
  872. {
  873. delete lpszUrlPath;
  874. lpszUrlPath = NULL;
  875. }
  876. pPRByURLExpression->m_bSpecified|=BYURL_PATH;
  877. if(URLComponents.nPort!=INTERNET_INVALID_PORT_NUMBER)
  878. {
  879. LPSTR lpszTemp;
  880. lpszTemp=new char[sizeof("65536")];
  881. wsprintf(lpszTemp,"%d",URLComponents.nPort);
  882. pPRByURLExpression->m_bNonWild|=BYURL_PORT;
  883. pPRByURLExpression->m_etstrPort.SetTo(lpszTemp);
  884. }
  885. pPRByURLExpression->m_bSpecified|=BYURL_PORT;
  886. //
  887. // need to make sure we echo exactly what they typed in
  888. //
  889. // just UI stuff left so assume success - we don't want to delete pics
  890. // structs now that they're linked into other pics structs
  891. hr = NOERROR;
  892. SendDlgItemMessage(IDC_PICSRULESAPPROVEDEDIT,
  893. WM_GETTEXT,
  894. (WPARAM) INTERNET_MAX_URL_LENGTH,
  895. (LPARAM) lpszSiteURL);
  896. ZeroMemory(&lvItem,sizeof(lvItem));
  897. lvItem.mask=LVIF_TEXT|LVIF_IMAGE;
  898. lvItem.pszText=lpszSiteURL;
  899. if(fAlwaysNever==PICSRULES_NEVER)
  900. {
  901. lvItem.iImage=g_iAllowNever;
  902. }
  903. else
  904. {
  905. lvItem.iImage=g_iAllowAlways;
  906. }
  907. if(SendDlgItemMessage(IDC_PICSRULESAPPROVEDLIST,
  908. LVM_INSERTITEM,
  909. (WPARAM) 0,
  910. (LPARAM) &lvItem)==-1)
  911. {
  912. goto clean;
  913. }
  914. ListView_SetColumnWidth(GetDlgItem(IDC_PICSRULESAPPROVEDLIST),
  915. 0,
  916. LVSCW_AUTOSIZE);
  917. SendDlgItemMessage(IDC_PICSRULESAPPROVEDEDIT,
  918. WM_SETTEXT,
  919. (WPARAM) 0,
  920. (LPARAM) 0);
  921. MarkChanged();
  922. pPRByURLExpression->m_etstrURL.SetTo(lpszSiteURL);
  923. clean:
  924. SAFEDELETE(lpszPassword);
  925. SAFEDELETE(lpszExtraInfo);
  926. if(FAILED(hr))
  927. {
  928. // failed means we didn't get chance to save or delete these
  929. SAFEDELETE(lpszScheme);
  930. SAFEDELETE(lpszHostName);
  931. SAFEDELETE(lpszUserName);
  932. SAFEDELETE(lpszUrlPath);
  933. // a failed hr means we didn't link these guys together so they need
  934. // to be deleted
  935. SAFEDELETE(lpszSiteURL);
  936. SAFEDELETE(pPRPolicy);
  937. SAFEDELETE(pPRByURL);
  938. SAFEDELETE(pPRByURLExpression);
  939. }
  940. return hr;
  941. }