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.

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