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.

6434 lines
190 KiB

  1. //*******************************************************************
  2. //*
  3. //* PICSRule.cpp
  4. //*
  5. //* Revision History:
  6. //* Created 7/98 - Mark Hammond (t-markh)
  7. //*
  8. //* Implements PICSRules parsing, decision making,
  9. //* exporting, and editing.
  10. //*
  11. //*******************************************************************
  12. //*******************************************************************
  13. //*
  14. //* A brief rundown on PICSRules files:
  15. //* (The official spec is at: http://www.w3.org/TR/REC-PICSRules)
  16. //*
  17. //* PICSRules files have MIME type: application/pics-rules and
  18. //* consist of a sequence of parenthesis encapsulated attribute
  19. //* value pairs. Values consist of quoted strings or parenthesized
  20. //* lists of further attribute value pairs. Every subsection of a
  21. //* PICSRules file has a primary attribute (denoted in the outline
  22. //* below by square brackets); if any value is not paired with an
  23. //* attribute, it is assigned to the primary attribute.
  24. //*
  25. //* Whitespace consists of the characters ' ', '\t', '\r', and '\n'
  26. //* and is ignored except between attribute value pairs.
  27. //*
  28. //* Quoted strings can be encapsulated in either single ticks ('')
  29. //* or double ticks (""), but may not use mixed notation ('" or "').
  30. //*
  31. //* The following escape sequences are observed in the quoted strings:
  32. //* " = %22
  33. //* ' = %27
  34. //* % = %25
  35. //* Any other escape sequence is invalid.
  36. //*
  37. //* Both attributes and values are case sensitive.
  38. //*
  39. //* Curly brackets denote comments.
  40. //*
  41. //* --- Code Requirements ---
  42. //*
  43. //* The rule evaluator needs to return yes (accept) or no (reject)
  44. //* AS WELL AS the policy clause that determined the answer.
  45. //*
  46. //* The rule evaluator stops when it hits the first policy clause
  47. //* which is applicable.
  48. //*
  49. //* If no clause is satisfied, the default clause is:
  50. //* AcceptIf "otherwise". In this implementation, if no clause is
  51. //* satisfied, evaluation is passed to our non-PICSRule evaluator.
  52. //*
  53. //* PICSRules 1.1 does NOT support Internationalization of the name
  54. //* section (i.e. each language needs its own PICSRules file).
  55. //* The AddItem function of the PICSRulesName class can easily be
  56. //* extended if this behavior changes in a future revision of the
  57. //* PICSRules spec.
  58. //*
  59. //* The Ratfile attribute is either an entire machine readable .RAT
  60. //* file, or the URL where the .RAT file can be obtained.
  61. //*
  62. //* --- Attribute Value specifications ---
  63. //*
  64. //*
  65. //* The main body of a PICSRules has the form:
  66. //*
  67. //* (PicsRule-%verMajor%.%verMinor%
  68. //* (
  69. //* Attribute Value
  70. //* ...
  71. //* Tag (
  72. //* Attribute Value
  73. //* ...
  74. //* )
  75. //* )
  76. //* )
  77. //*
  78. //* The current %verMajor% is 1
  79. //* The current %verMinor% is 1
  80. //*
  81. //* Possible Tags and their Attribute Value pairs are:
  82. //*
  83. //* Policy (
  84. //* [Explanation] quoted
  85. //* RejectByURL URL | ( [patterns] URL )
  86. //* AcceptByURL URL | ( [patterns] URL )
  87. //* RejectIf PolicyExpression
  88. //* RejectUnless PolicyExpression
  89. //* AcceptIf PolicyExpression
  90. //* AcceptUnless PolicyExpression
  91. //* *Extension* )
  92. //*
  93. //* name (
  94. //* [Rulename] quoted
  95. //* Description quoted
  96. //* *Extension* )
  97. //*
  98. //* source (
  99. //* [SourceURL] URL
  100. //* CreationTool quoted (has format application/version)
  101. //* author email
  102. //* LastModified ISO Date
  103. //* *Extension* )
  104. //*
  105. //* serviceinfo (
  106. //* [Name] URL
  107. //* shortname quoted
  108. //* BureauURL URL
  109. //* UseEmbedded Y|N
  110. //* Ratfile quoted
  111. //* BureauUnavailable PASS|FAIL
  112. //* *Extension* )
  113. //*
  114. //* optextension (
  115. //* [extension-name] URL
  116. //* shortname quoted
  117. //* *Extension* )
  118. //*
  119. //* reqextension (
  120. //* [extension-name] URL
  121. //* shortname quoted
  122. //* *Extension* )
  123. //*
  124. //* *Extension*
  125. //*
  126. //* Further comments are given below
  127. //*
  128. //*******************************************************************
  129. //*******************************************************************
  130. //*
  131. //* #Includes
  132. //*
  133. //*******************************************************************
  134. #include "msrating.h"
  135. #include "mslubase.h"
  136. #include "debug.h"
  137. #include "parselbl.h" /* we use a couple of this guy's subroutines */
  138. #include "msluglob.h"
  139. #include "reghive.h" // CRegistryHive
  140. #include "buffer.h"
  141. #include "resource.h"
  142. #include <wininet.h>
  143. #include "picsrule.h"
  144. #include <mluisupp.h>
  145. #include <winsock2.h>
  146. #include <shlwapip.h>
  147. //*******************************************************************
  148. //*
  149. //* Globals
  150. //*
  151. //*******************************************************************
  152. array<PICSRulesRatingSystem*> g_arrpPRRS; //this is the array of PICSRules systems
  153. //which are inforced while ie is running
  154. PICSRulesRatingSystem * g_pApprovedPRRS; //this is the Approved Sites PICSRules
  155. //system
  156. PICSRulesRatingSystem * g_pPRRS=NULL; //this is a temporary pointer used while
  157. //parsing a PICSRules file
  158. HMODULE g_hURLMON,g_hWININET;
  159. BOOL g_fPICSRulesEnforced,g_fApprovedSitesEnforced;
  160. char g_szLastURL[INTERNET_MAX_URL_LENGTH];
  161. extern DWORD g_dwDataSource;
  162. extern HANDLE g_HandleGlobalCounter,g_ApprovedSitesHandleGlobalCounter;
  163. extern long g_lGlobalCounterValue,g_lApprovedSitesGlobalCounterValue;
  164. //*******************************************************************
  165. //*
  166. //* Function Prototypes
  167. //*
  168. //*******************************************************************
  169. HRESULT PICSRulesParseSubPolicyExpression(LPSTR& lpszCurrent,PICSRulesPolicyExpression *pPRPolicyExpression,PICSRulesFileParser *pParser);
  170. HRESULT PICSRulesParseSimplePolicyExpression(LPSTR& lpszCurrent,PICSRulesPolicyExpression *pPRPolicyExpression,PICSRulesFileParser *pParser);
  171. BOOL IsServiceDefined(LPSTR lpszService,LPSTR lpszFullService,PICSRulesServiceInfo **ppServiceInfo);
  172. BOOL IsOptExtensionDefined(LPSTR lpszExtension);
  173. BOOL IsReqExtensionDefined(LPSTR lpszExtension);
  174. HRESULT PICSRulesParseSingleByURL(LPSTR lpszByURL, PICSRulesByURLExpression *pPRByURLExpression, PICSRulesFileParser *pParser);
  175. //*******************************************************************
  176. //*
  177. //* Some definitions specific to this file
  178. //*
  179. //*******************************************************************
  180. PICSRulesAllowableOption aaoPICSRules[] = {
  181. { PROID_PICSVERSION, 0 },
  182. { PROID_POLICY, AO_MANDATORY },
  183. { PROID_EXPLANATION, AO_SINGLE },
  184. { PROID_REJECTBYURL, AO_SINGLE },
  185. { PROID_ACCEPTBYURL, AO_SINGLE },
  186. { PROID_REJECTIF, AO_SINGLE },
  187. { PROID_ACCEPTIF, AO_SINGLE },
  188. { PROID_ACCEPTUNLESS, AO_SINGLE },
  189. { PROID_REJECTUNLESS, AO_SINGLE },
  190. { PROID_NAME, AO_SINGLE },
  191. { PROID_RULENAME, 0 },
  192. { PROID_DESCRIPTION, 0 },
  193. { PROID_SOURCE, AO_SINGLE },
  194. { PROID_SOURCEURL, 0 },
  195. { PROID_CREATIONTOOL, 0 },
  196. { PROID_AUTHOR, 0 },
  197. { PROID_LASTMODIFIED, 0 },
  198. { PROID_SERVICEINFO, 0 },
  199. { PROID_SINAME, AO_SINGLE },
  200. { PROID_SHORTNAME, AO_SINGLE },
  201. { PROID_BUREAUURL, 0 },
  202. { PROID_USEEMBEDDED, AO_SINGLE },
  203. { PROID_RATFILE, AO_SINGLE },
  204. { PROID_BUREAUUNAVAILABLE, AO_SINGLE },
  205. { PROID_OPTEXTENSION, 0 },
  206. { PROID_EXTENSIONNAME, AO_SINGLE },
  207. //{ PROID_SHORTNAME, AO_SINGLE },
  208. { PROID_REQEXTENSION, 0 },
  209. //{ PROID_EXTENSIONNAME, AO_SINGLE },
  210. //{ PROID_SHORTNAME, AO_SINGLE },
  211. { PROID_EXTENSION, 0 },
  212. { PROID_POLICYDEFAULT, AO_SINGLE },
  213. { PROID_NAMEDEFAULT, AO_SINGLE },
  214. { PROID_SOURCEDEFAULT, AO_SINGLE },
  215. { PROID_SERVICEINFODEFAULT, AO_SINGLE },
  216. { PROID_OPTEXTENSIONDEFAULT, AO_SINGLE },
  217. { PROID_REQEXTENSIONDEFAULT, AO_SINGLE },
  218. { PROID_INVALID, 0 }
  219. };
  220. const UINT caoPICSRules=sizeof(aaoPICSRules)/sizeof(aaoPICSRules[0]);
  221. //The FN_INTERNETCRACKURL type describes the URLMON function InternetCrackUrl
  222. typedef BOOL (*FN_INTERNETCRACKURL)(LPCTSTR lpszUrl,DWORD dwUrlLength,DWORD dwFlags,LPURL_COMPONENTS lpUrlComponents);
  223. //The FN_ISVALIDURL type describes the URLMON function IsValidURL
  224. //and is called by the three IsURLValid methods of PICSRulesQuotedURL
  225. typedef HRESULT (*FN_ISVALIDURL)(LPBC pBC,LPCWSTR szURL,DWORD dwReserved);
  226. //*******************************************************************
  227. //*
  228. //* This function is called by AdvancedDlgProc while processing
  229. //* WM_COMMOND with LOWORD(wParam)==IDC_PICSRULESOPEN in msludlg.cpp
  230. //* The argument lpszFileName is the name of the PICSRules file
  231. //* selected by the user to import.
  232. //*
  233. //* This begins the PICSRules Import process.
  234. //*
  235. //*******************************************************************
  236. HRESULT PICSRulesImport(char *lpszFileName, PICSRulesRatingSystem **pprrsOut)
  237. {
  238. PICSRulesRatingSystem *pPRRS=new PICSRulesRatingSystem;
  239. *pprrsOut=pPRRS;
  240. if(pPRRS==NULL)
  241. {
  242. return E_OUTOFMEMORY;
  243. }
  244. UINT cbFilename=strlenf(lpszFileName)+1+1; //room for marker character
  245. LPSTR lpszNameCopy=new char[cbFilename];
  246. if(lpszNameCopy==NULL)
  247. {
  248. return E_OUTOFMEMORY;
  249. }
  250. strcpyf(lpszNameCopy,lpszFileName);
  251. pPRRS->m_etstrFile.SetTo(lpszNameCopy);
  252. HRESULT hRes;
  253. HANDLE hFile=CreateFile(lpszNameCopy,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,
  254. FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL);
  255. if(hFile!=INVALID_HANDLE_VALUE)
  256. {
  257. DWORD cbFile=::GetFileSize(hFile,NULL);
  258. BUFFER bufData(cbFile+1);
  259. if(bufData.QueryPtr()!=NULL)
  260. {
  261. LPSTR lpszData=(LPSTR)bufData.QueryPtr();
  262. DWORD cbRead;
  263. if(ReadFile(hFile,lpszData,cbFile,&cbRead,NULL))
  264. {
  265. lpszData[cbRead]='\0'; //null terminate whole file
  266. g_pPRRS=pPRRS; //make data available to
  267. //parsing functions during
  268. //parsing
  269. hRes=pPRRS->Parse(lpszFileName,lpszData);
  270. if(SUCCEEDED(hRes))
  271. {
  272. pPRRS->m_dwFlags|=PRRS_ISVALID;
  273. }
  274. else
  275. {
  276. g_pPRRS=NULL;
  277. }
  278. }
  279. else
  280. {
  281. hRes=HRESULT_FROM_WIN32(::GetLastError());
  282. }
  283. CloseHandle(hFile);
  284. }
  285. else
  286. {
  287. hRes=E_OUTOFMEMORY;
  288. }
  289. }
  290. else
  291. {
  292. hRes=HRESULT_FROM_WIN32(::GetLastError());
  293. }
  294. if(!(pPRRS->m_dwFlags&PRS_ISVALID))
  295. {
  296. //file is invalid
  297. }
  298. return hRes;
  299. }
  300. /* White returns a pointer to the first whitespace character starting at pc.*/
  301. extern char* White(char *);
  302. /* NonWhite returns a pointer to the first non-whitespace character starting at pc.*/
  303. extern char* NonWhite(char *);
  304. //*******************************************************************
  305. //*
  306. //* The following are handler functions which parse the various
  307. //* kinds of content which can occur within a parenthesized object.
  308. //*
  309. //* ppszIn is always advanced to the next non-white space token
  310. //* ppszOut returns the processed data
  311. //*
  312. //*******************************************************************
  313. //The following escape sequences are observed:
  314. // " =%22
  315. // ' =%27
  316. // % =%25
  317. //any other escape sequence is invalid
  318. HRESULT PICSRulesParseString(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  319. {
  320. BOOL fQuote;
  321. LPSTR lpszEscapeSequence,lpszNewEnd;
  322. *ppOut=NULL;
  323. LPSTR pszCurrent=*ppszIn;
  324. if(*pszCurrent=='\"')
  325. {
  326. fQuote=PR_QUOTE_DOUBLE;
  327. }
  328. else if(*pszCurrent=='\'')
  329. {
  330. fQuote=PR_QUOTE_SINGLE;
  331. }
  332. else
  333. {
  334. return(PICSRULES_E_EXPECTEDSTRING);
  335. }
  336. pszCurrent++;
  337. LPSTR pszEnd=pParser->EatQuotedString(pszCurrent,fQuote);
  338. if(pszEnd==NULL)
  339. {
  340. return(PICSRULES_E_EXPECTEDSTRING);
  341. }
  342. lpszNewEnd=pszEnd;
  343. do
  344. {
  345. lpszEscapeSequence=strstrf(pszCurrent,"%22");
  346. if(lpszEscapeSequence>lpszNewEnd)
  347. {
  348. lpszEscapeSequence=NULL;
  349. }
  350. if(lpszEscapeSequence!=NULL)
  351. {
  352. *lpszEscapeSequence='\"';
  353. memcpyf(lpszEscapeSequence+1,lpszEscapeSequence+3,(int)(lpszNewEnd-lpszEscapeSequence-3));
  354. lpszNewEnd-=2;
  355. }
  356. } while(lpszEscapeSequence!=NULL);
  357. do
  358. {
  359. lpszEscapeSequence=strstrf(pszCurrent,"%27");
  360. if(lpszEscapeSequence>lpszNewEnd)
  361. {
  362. lpszEscapeSequence=NULL;
  363. }
  364. if(lpszEscapeSequence!=NULL)
  365. {
  366. *lpszEscapeSequence='\'';
  367. memcpyf(lpszEscapeSequence+1,lpszEscapeSequence+3,(int)(lpszNewEnd-lpszEscapeSequence-3));
  368. lpszNewEnd-=2;
  369. }
  370. } while(lpszEscapeSequence!=NULL);
  371. do
  372. {
  373. lpszEscapeSequence=strstrf(pszCurrent,"%25");
  374. if(lpszEscapeSequence>lpszNewEnd)
  375. {
  376. lpszEscapeSequence=NULL;
  377. }
  378. if(lpszEscapeSequence!=NULL)
  379. {
  380. *lpszEscapeSequence='%';
  381. memcpyf(lpszEscapeSequence+1,lpszEscapeSequence+3,(int)(lpszNewEnd-lpszEscapeSequence-3));
  382. lpszNewEnd-=2;
  383. }
  384. } while(lpszEscapeSequence!=NULL);
  385. UINT cbString= (unsigned int) (lpszNewEnd-pszCurrent);
  386. LPSTR pszNew = new char[cbString + 1]; //This memory gets assigned to an ET derived
  387. //type via the AddItem call for the class handling
  388. //the parenthesized object. The memory is
  389. //deallocated when the handling class, and hence
  390. //the ET derived type, goes out of scope.
  391. if (pszNew==NULL)
  392. {
  393. return(E_OUTOFMEMORY);
  394. }
  395. memcpyf(pszNew, pszCurrent, cbString);
  396. pszNew[cbString]='\0';
  397. *ppOut=(LPVOID) pszNew;
  398. *ppszIn=pParser->FindNonWhite(pszEnd+1);
  399. return(NOERROR);
  400. }
  401. HRESULT PICSRulesParseNumber(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  402. {
  403. int n;
  404. LPSTR pszCurrent=*ppszIn;
  405. HRESULT hres=::ParseNumber(&pszCurrent,&n,TRUE);
  406. if(FAILED(hres))
  407. {
  408. return(PICSRULES_E_EXPECTEDNUMBER);
  409. }
  410. *(int *)ppOut=n;
  411. LPSTR pszNewline=strchrf(*ppszIn, '\n');
  412. while((pszNewline!=NULL)&&(pszNewline<pszCurrent))
  413. {
  414. pParser->m_nLine++;
  415. pszNewline=strchrf(pszNewline+1,'\n');
  416. }
  417. *ppszIn=pszCurrent;
  418. return(NOERROR);
  419. }
  420. HRESULT PICSRulesParseYesNo(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  421. {
  422. BOOL b;
  423. //The PICSRules spec allows the following:
  424. //
  425. // "y" == Yes
  426. // "yes" == Yes
  427. // "n" == no
  428. // "no" == no
  429. //
  430. // string comparison is not case sensitive
  431. //
  432. LPSTR pszCurrent=*ppszIn;
  433. if((*pszCurrent=='\"')||(*pszCurrent=='\''))
  434. {
  435. pszCurrent++;
  436. }
  437. HRESULT hres=::GetBool(&pszCurrent,&b,PR_BOOLEAN_YESNO);
  438. if (FAILED(hres))
  439. {
  440. return(PICSRULES_E_EXPECTEDBOOL);
  441. }
  442. LPSTR pszNewline=strchrf(*ppszIn,'\n');
  443. while((pszNewline!=NULL)&&(pszNewline<pszCurrent))
  444. {
  445. pParser->m_nLine++;
  446. pszNewline=strchrf(pszNewline+1,'\n');
  447. }
  448. if((*pszCurrent=='\"')||(*pszCurrent=='\''))
  449. {
  450. pszCurrent++;
  451. }
  452. *ppszIn=pszCurrent;
  453. *(LPBOOL)ppOut=b;
  454. return(NOERROR);
  455. }
  456. HRESULT PICSRulesParsePassFail(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  457. {
  458. BOOL b;
  459. //The PICSRules spec allows the following:
  460. //
  461. // "pass" == pass
  462. // "fail" == fail
  463. //
  464. // for completeness we add:
  465. //
  466. // "p" == pass
  467. // "f" == fail
  468. //
  469. // string comparison is not case sensitive
  470. //
  471. LPSTR pszCurrent=*ppszIn;
  472. if((*pszCurrent=='\"')||(*pszCurrent=='\''))
  473. {
  474. pszCurrent++;
  475. }
  476. HRESULT hres=::GetBool(&pszCurrent,&b,PR_BOOLEAN_PASSFAIL);
  477. if (FAILED(hres))
  478. {
  479. return(PICSRULES_E_EXPECTEDBOOL);
  480. }
  481. LPSTR pszNewline=strchrf(*ppszIn,'\n');
  482. while((pszNewline!=NULL)&&(pszNewline<pszCurrent))
  483. {
  484. pParser->m_nLine++;
  485. pszNewline=strchrf(pszNewline+1,'\n');
  486. }
  487. if((*pszCurrent=='\"')||(*pszCurrent=='\''))
  488. {
  489. pszCurrent++;
  490. }
  491. *ppszIn=pszCurrent;
  492. *(LPBOOL)ppOut=b;
  493. return(NOERROR);
  494. }
  495. HRESULT PICSRulesParseVersion(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  496. {
  497. //t-markh - 8/98 - This shouldn't get called, version info should be filled
  498. // out before processing begins
  499. return(E_UNEXPECTED);
  500. }
  501. PICSRulesAllowableOption aaoPICSRulesPolicy[] = {
  502. { PROID_EXPLANATION, AO_SINGLE },
  503. { PROID_REJECTBYURL, AO_SINGLE },
  504. { PROID_ACCEPTBYURL, AO_SINGLE },
  505. { PROID_REJECTIF, AO_SINGLE },
  506. { PROID_ACCEPTIF, AO_SINGLE },
  507. { PROID_ACCEPTUNLESS, AO_SINGLE },
  508. { PROID_REJECTUNLESS, AO_SINGLE },
  509. { PROID_EXTENSION, 0 },
  510. { PROID_INVALID, 0 }
  511. };
  512. const UINT caoPICSRulesPolicy=sizeof(aaoPICSRulesPolicy)/sizeof(aaoPICSRulesPolicy[0]);
  513. HRESULT PICSRulesParsePolicy(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  514. {
  515. //We must make a copy of the allowable options array because the
  516. //parser will fiddle with the flags in the entries -- specifically,
  517. //setting AO_SEEN. It wouldn't be thread-safe to do this to a
  518. //static array.
  519. PICSRulesAllowableOption aao[caoPICSRulesPolicy];
  520. ::memcpyf(aao,::aaoPICSRulesPolicy,sizeof(aao));
  521. PICSRulesPolicy *pPolicy=new PICSRulesPolicy;
  522. if(pPolicy==NULL)
  523. {
  524. return E_OUTOFMEMORY;
  525. }
  526. HRESULT hres=pParser->ParseParenthesizedObject(
  527. ppszIn, //var containing current ptr
  528. aao, //what's legal in this object
  529. pPolicy); //object to add items back to
  530. if (FAILED(hres))
  531. {
  532. delete pPolicy;
  533. pPolicy = NULL;
  534. return hres;
  535. }
  536. *ppOut=(LPVOID) pPolicy;
  537. return NOERROR;
  538. }
  539. //PICSRules URLpatterns can be presented to ParseByURL as either a single
  540. //pattern, or a parenthesized list of multiple patterns. i.e.
  541. //
  542. // Policy (RejectByURL "http://*@*.badsite.com:*/*" )
  543. // Policy (AcceptByURL (
  544. // "http://*@www.goodsite.com:*/*"
  545. // "ftp://*@www.goodsite.com:*/*" ) )
  546. //
  547. //The general form of an URLpattern is:
  548. //
  549. // internet pattern - internetscheme://user@hostoraddr:port/pathmatch
  550. // other pattern - otherscheme:nonquotedcharacters
  551. //
  552. // in all cases, an ommitted section only matches to a URL if that section
  553. // was omitted in the URL being navigated to.
  554. //
  555. // the wild card character '*' may be used to match any pattern as specified
  556. // on a per section basis below. To encode the actual character '*' the escape
  557. // sequence '%*' is recognized.
  558. //
  559. // recognized internet schemes are:
  560. // ftp, http, gopher, nntp, irc, prospero, telnet, and *
  561. //
  562. // the user section consists of '*' nonquotedcharacters '*', in other words, an
  563. // alphanumeric user name with optional wild card sections before and after the
  564. // name. A single * matches all names.
  565. //
  566. // the hostoraddr section can be in one of two forms, either:
  567. // '*' hostname, or ipnum.ipnum.ipnum.ipnum!bitlength
  568. // hostname must be a substring of a fully qualified domain name
  569. // bitlength is an integer between 0 and 32 inclusive, and
  570. // ipnum is an integer between 0 and 255 inclusive.
  571. // the bitlength parameter masks out the last n bits of the 32 bit ip address
  572. // specified (i.e. treats them as a wild card)
  573. //
  574. // the port section can have one of four forms:
  575. // *
  576. // *-portnum
  577. // portnum-*
  578. // portnum-portnum
  579. //
  580. // a single * matches against all port numbers, *-portnum matches all ports
  581. // lessthan or equal to portnum, portnum-* matches all aports greaterthan or
  582. // equal to portnum, and portnum-portnum matches all ports between the two
  583. // portnums, inclusive.
  584. //
  585. // the pathmatch section has the form:
  586. // '*' nonquotedchars '*'
  587. // i.e. *foo* would match any pathname containing the word foo. A single *
  588. // matches all pathnames.
  589. HRESULT PICSRulesParseByURL(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  590. {
  591. PICSRulesByURLExpression *pPRByURLExpression;
  592. PICSRulesByURL *pPRByURL;
  593. HRESULT hRes;
  594. LPSTR lpszCurrent;
  595. pPRByURL=new PICSRulesByURL;
  596. //first, we need to find out if we have a list of URLpatterns or a single
  597. //URLpattern
  598. if(**ppszIn=='(') //we have a list of patterns
  599. {
  600. lpszCurrent=pParser->FindNonWhite(*ppszIn+1);
  601. while(*lpszCurrent!=')')
  602. {
  603. LPSTR lpszSubString;
  604. if(*lpszCurrent=='\0')
  605. {
  606. delete pPRByURL;
  607. pPRByURL = NULL;
  608. return(E_INVALIDARG);
  609. }
  610. hRes=PICSRulesParseString(&lpszCurrent,ppOut,pParser); //get the string
  611. if(FAILED(hRes))
  612. {
  613. //we couldn't get the string, so lets fail
  614. delete pPRByURL;
  615. pPRByURL = NULL;
  616. return(hRes);
  617. }
  618. lpszSubString=(char *) *ppOut;
  619. //we've got it, so lets instantiate the classes to fill out;
  620. pPRByURLExpression=new PICSRulesByURLExpression;
  621. hRes=pPRByURL->m_arrpPRByURL.Append(pPRByURLExpression) ? S_OK : E_OUTOFMEMORY;
  622. if(FAILED(hRes))
  623. {
  624. delete lpszSubString;
  625. lpszSubString = NULL;
  626. delete pPRByURLExpression;
  627. pPRByURLExpression = NULL;
  628. delete pPRByURL;
  629. pPRByURL = NULL;
  630. return(hRes);
  631. }
  632. hRes=PICSRulesParseSingleByURL(lpszSubString,pPRByURLExpression,pParser);
  633. if(FAILED(hRes))
  634. {
  635. delete lpszSubString;
  636. lpszSubString = NULL;
  637. delete pPRByURL; //deleting the array deletes the embeeded expression
  638. pPRByURL = NULL;
  639. return(hRes);
  640. }
  641. delete lpszSubString;
  642. lpszSubString = NULL;
  643. }
  644. if(*lpszCurrent==')')
  645. {
  646. *ppszIn=pParser->FindNonWhite(lpszCurrent+1);
  647. }
  648. }
  649. else //we have a single pattern
  650. {
  651. hRes=PICSRulesParseString(ppszIn,ppOut,pParser); //get the string
  652. if(FAILED(hRes))
  653. {
  654. //we couldn't get the string, so lets fail
  655. delete pPRByURL;
  656. pPRByURL = NULL;
  657. return(hRes);
  658. }
  659. lpszCurrent=(char *) *ppOut;
  660. //we've got it, so lets instantiate the classes to fill out;
  661. pPRByURLExpression=new PICSRulesByURLExpression;
  662. hRes=pPRByURL->m_arrpPRByURL.Append(pPRByURLExpression) ? S_OK : E_OUTOFMEMORY;
  663. if(FAILED(hRes))
  664. {
  665. delete lpszCurrent;
  666. lpszCurrent = NULL;
  667. delete pPRByURLExpression;
  668. pPRByURLExpression = NULL;
  669. delete pPRByURL;
  670. pPRByURL = NULL;
  671. return(hRes);
  672. }
  673. hRes=PICSRulesParseSingleByURL(lpszCurrent,pPRByURLExpression,pParser);
  674. if(FAILED(hRes))
  675. {
  676. delete lpszCurrent;
  677. lpszCurrent = NULL;
  678. delete pPRByURL; //deleting the array deletes the embeeded expression
  679. pPRByURL = NULL;
  680. return(hRes);
  681. }
  682. delete lpszCurrent;
  683. lpszCurrent= NULL;
  684. }
  685. *ppOut=(void *) pPRByURL;
  686. return(NOERROR);
  687. }
  688. HRESULT PICSRulesParseSingleByURL(LPSTR lpszByURL, PICSRulesByURLExpression *pPRByURLExpression, PICSRulesFileParser *pParser)
  689. {
  690. LPSTR lpszMarker;
  691. lpszMarker=strchrf(lpszByURL,':'); //find the marker '://' for an internet
  692. //pattern or ':' for a non-internet pattern
  693. if(lpszMarker==NULL) //no marker, i.e. our string is invalid
  694. {
  695. return(E_INVALIDARG);
  696. }
  697. //check the scheme for a wild card
  698. if(*lpszByURL=='*')
  699. {
  700. if((lpszByURL+1)!=lpszMarker) //we have a non-internet scheme
  701. {
  702. pPRByURLExpression->m_fInternetPattern=FALSE;
  703. *lpszMarker='\0';
  704. pPRByURLExpression->m_etstrScheme.Set(lpszByURL);
  705. lpszByURL=lpszMarker+1;
  706. pPRByURLExpression->m_etstrPath.Set(lpszByURL);
  707. return(S_OK);
  708. }
  709. //no need to set a NonWild flag, just move
  710. //on to the user name
  711. pPRByURLExpression->m_bSpecified|=BYURL_SCHEME;
  712. }
  713. else
  714. {
  715. *lpszMarker='\0';
  716. //check for an internet pattern
  717. if((lstrcmpi(lpszByURL,szPICSRulesFTP)!=0)&&
  718. (lstrcmpi(lpszByURL,szPICSRulesHTTP)!=0)&&
  719. (lstrcmpi(lpszByURL,szPICSRulesGOPHER)!=0)&&
  720. (lstrcmpi(lpszByURL,szPICSRulesNNTP)!=0)&&
  721. (lstrcmpi(lpszByURL,szPICSRulesIRC)!=0)&&
  722. (lstrcmpi(lpszByURL,szPICSRulesPROSPERO)!=0)&&
  723. (lstrcmpi(lpszByURL,szPICSRulesTELNET)!=0)) //we've got a non-internet pattern
  724. {
  725. pPRByURLExpression->m_fInternetPattern=FALSE;
  726. pPRByURLExpression->m_bNonWild=BYURL_SCHEME|BYURL_PATH;
  727. pPRByURLExpression->m_bSpecified=BYURL_SCHEME|BYURL_PATH;
  728. pPRByURLExpression->m_etstrScheme.Set(lpszByURL);
  729. lpszByURL=lpszMarker+1;
  730. pPRByURLExpression->m_etstrPath.Set(lpszByURL);
  731. return(S_OK);
  732. }
  733. pPRByURLExpression->m_bNonWild|=BYURL_SCHEME;
  734. pPRByURLExpression->m_bSpecified|=BYURL_SCHEME;
  735. pPRByURLExpression->m_etstrScheme.Set(lpszByURL);
  736. }
  737. if((*(lpszMarker+1)=='/')&&(*(lpszMarker+2)=='/'))
  738. {
  739. pPRByURLExpression->m_fInternetPattern=TRUE;
  740. lpszByURL=lpszMarker+3;
  741. }
  742. else
  743. {
  744. return(E_INVALIDARG);
  745. }
  746. //we've got an internet pattern, and lpszURL now points
  747. //to the user field
  748. lpszMarker=strchrf(lpszByURL,'@'); //find the marker between user and host
  749. if(lpszMarker!=NULL) //a user name was specified
  750. {
  751. pPRByURLExpression->m_bSpecified|=BYURL_USER;
  752. //check for a wild card
  753. if(!((*lpszByURL=='*')&&((lpszByURL+1)==lpszMarker)))
  754. {
  755. pPRByURLExpression->m_bNonWild|=BYURL_USER;
  756. *lpszMarker='\0';
  757. pPRByURLExpression->m_etstrUser.Set(lpszByURL);
  758. }
  759. lpszByURL=lpszMarker+1;
  760. }
  761. //lpszByURL now points to host
  762. lpszMarker=strchrf(lpszByURL,':');
  763. if(lpszMarker==NULL) //the port was omitted
  764. {
  765. lpszMarker=strchrf(lpszByURL,'/');
  766. if(lpszMarker!=NULL) //there is a pathmatch
  767. {
  768. pPRByURLExpression->m_bSpecified|=BYURL_PATH;
  769. }
  770. }
  771. else //we have a host and port
  772. {
  773. pPRByURLExpression->m_bSpecified|=BYURL_PORT;
  774. }
  775. pPRByURLExpression->m_bSpecified|=BYURL_HOST;
  776. if(lpszMarker!=NULL)
  777. {
  778. *lpszMarker='\0';
  779. }
  780. if(lstrcmp(lpszByURL,"*")!=0)
  781. {
  782. pPRByURLExpression->m_bNonWild|=BYURL_HOST;
  783. }
  784. pPRByURLExpression->m_etstrHost.Set(lpszByURL);
  785. if(lpszMarker==NULL)
  786. {
  787. return(S_OK);
  788. }
  789. lpszByURL=lpszMarker+1;
  790. if(pPRByURLExpression->m_bSpecified&BYURL_PORT)
  791. {
  792. lpszMarker=strchrf(lpszByURL,'/');
  793. if(lpszMarker!=NULL) //there is a pathmatch
  794. {
  795. pPRByURLExpression->m_bSpecified|=BYURL_PATH;
  796. *lpszMarker='\0';
  797. }
  798. if(!((*lpszByURL=='*')&&(lpszByURL+1==lpszMarker)))
  799. {
  800. pPRByURLExpression->m_bNonWild|=BYURL_PORT;
  801. pPRByURLExpression->m_etstrPort.Set(lpszByURL);
  802. }
  803. if(pPRByURLExpression->m_bSpecified&BYURL_PATH)
  804. {
  805. lpszByURL=lpszMarker+1;
  806. }
  807. }
  808. if(pPRByURLExpression->m_bSpecified&BYURL_PATH)
  809. {
  810. if(!((*lpszByURL=='*')&&(*(lpszByURL+1)==NULL)))
  811. {
  812. pPRByURLExpression->m_bNonWild|=BYURL_PATH;
  813. pPRByURLExpression->m_etstrPath.Set(lpszByURL);
  814. }
  815. }
  816. return(S_OK);
  817. }
  818. //PICSRules PolicyExpressions have 6 possible expressions:
  819. //
  820. // simple-expression - ( Service.Category [Operator] [Constant] )
  821. // or-expression - ( PolicyExpression or PolicyExpression )
  822. // and-expression - ( PolicyExpression and PolicyExpression )
  823. // service & category - ( Service.Category )
  824. // service only - ( Service )
  825. // degenerate-expression - "otherwise"
  826. //
  827. // thus, for example, embedded expressions can take the form:
  828. //
  829. // "((Cool.Coolness < 3) or (Cool.Graphics < 3))"
  830. //
  831. // or
  832. //
  833. // "(((Cool.Coolness < 3) or (Cool.Graphics < 3)) and (Cool.Fun < 2))"
  834. //
  835. // ad infinitum
  836. //
  837. // thus, existing pics labels can be encoded as:
  838. //
  839. // "((((RSACi.s <= 0) and (RSACi.v <= 0)) and (RSACi.n <= 0)) and RSACi.l <=0)"
  840. //
  841. // allowable operators are: '<', '<=', '=', '>=', '>'
  842. //
  843. // the service only expression evaluates to TRUE iff a label from that
  844. // service is found.
  845. //
  846. // the service & category expression evaluates to TRUE iff a label from
  847. // that service is found, and it contains at least one value for the
  848. // indicated category.
  849. //
  850. // the degenerate-expression always evaluates to TRUE
  851. HRESULT PICSRulesParsePolicyExpression(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  852. {
  853. PICSRulesPolicyExpression *pPRPolicyExpression;
  854. HRESULT hRes;
  855. LPSTR lpszPolicyExpression,lpszCurrent;
  856. //first lets get the string
  857. hRes=PICSRulesParseString(ppszIn,ppOut,pParser);
  858. if(FAILED(hRes))
  859. {
  860. //we couldn't get the string, so lets fail
  861. return(hRes);
  862. }
  863. lpszPolicyExpression=(char *) *ppOut;
  864. //we've got it, so lets instantiate a PICSRulesPolicyExpression to fill out
  865. pPRPolicyExpression=new PICSRulesPolicyExpression;
  866. if(pPRPolicyExpression==NULL)
  867. {
  868. return(E_OUTOFMEMORY);
  869. }
  870. pPRPolicyExpression->m_PROPolicyOperator=PR_OPERATOR_RESULT; //set as the topmost node
  871. //of the binary tree
  872. if(lstrcmpi(lpszPolicyExpression,szPICSRulesDegenerateExpression)==0)
  873. {
  874. //we have a degenerate expression, so delete lpszPolicyExpresion
  875. delete lpszPolicyExpression;
  876. lpszPolicyExpression = NULL;
  877. pPRPolicyExpression->m_PROPolicyOperator=PR_OPERATOR_DEGENERATE;
  878. *ppOut=(LPVOID) pPRPolicyExpression;
  879. return(NOERROR);
  880. }
  881. //make sure we have a parenthesized object
  882. if(*lpszPolicyExpression!='(')
  883. {
  884. delete lpszPolicyExpression;
  885. lpszPolicyExpression = NULL;
  886. delete pPRPolicyExpression;
  887. pPRPolicyExpression= NULL;
  888. return(E_INVALIDARG);
  889. }
  890. lpszCurrent=NonWhite(lpszPolicyExpression+1);
  891. //check for an or-expression or an and-expression
  892. if(*lpszCurrent=='(')
  893. {
  894. hRes=PICSRulesParseSubPolicyExpression(lpszCurrent,pPRPolicyExpression,pParser);
  895. if(FAILED(hRes))
  896. {
  897. delete lpszPolicyExpression;
  898. lpszPolicyExpression = NULL;
  899. delete pPRPolicyExpression;
  900. pPRPolicyExpression = NULL;
  901. return(hRes);
  902. }
  903. else
  904. {
  905. if((pPRPolicyExpression->m_pPRPolicyExpressionLeft)!=NULL)
  906. {
  907. BOOL fFlag;
  908. fFlag=pPRPolicyExpression->m_pPRPolicyExpressionLeft->m_prYesNoUseEmbedded.GetYesNo();
  909. pPRPolicyExpression->m_prYesNoUseEmbedded.Set(&fFlag);
  910. }
  911. }
  912. }
  913. else //we've got a simple-expression
  914. {
  915. hRes=PICSRulesParseSimplePolicyExpression(lpszCurrent,pPRPolicyExpression,pParser);
  916. if(FAILED(hRes))
  917. {
  918. delete lpszPolicyExpression;
  919. lpszPolicyExpression = NULL;
  920. delete pPRPolicyExpression;
  921. pPRPolicyExpression= NULL;
  922. return(hRes);
  923. }
  924. }
  925. delete lpszPolicyExpression;
  926. lpszPolicyExpression= NULL;
  927. *ppOut=(void *) pPRPolicyExpression;
  928. return(NOERROR);
  929. }
  930. //Our PolicyExpression is either an or-expression or an and-expression
  931. //so pPRPolicyExpression need to have another PICSRulesPolicyExpression
  932. //embedded in it, with all the details filled out.
  933. HRESULT PICSRulesParseSubPolicyExpression(LPSTR& lpszCurrent,PICSRulesPolicyExpression *pPRPolicyExpression,PICSRulesFileParser *pParser)
  934. {
  935. HRESULT hRes;
  936. PICSRulesPolicyExpression * pPRPolicyExpressionEmbeddedLeft,
  937. * pPRPolicyExpressionEmbeddedRight;
  938. LPSTR lpszNextPolicyExpression,
  939. lpszOrAnd,lpszOrAndEnd;
  940. int iStringLen;
  941. BOOL fFlag;
  942. lpszCurrent=NonWhite(lpszCurrent+1);
  943. //check for nested or-expressions and and-expressions
  944. if(*lpszCurrent=='(')
  945. {
  946. pPRPolicyExpressionEmbeddedLeft=new PICSRulesPolicyExpression;
  947. if(pPRPolicyExpressionEmbeddedLeft==NULL)
  948. {
  949. return(E_OUTOFMEMORY);
  950. }
  951. pPRPolicyExpressionEmbeddedLeft->m_PROPolicyOperator=PR_OPERATOR_RESULT;
  952. hRes=PICSRulesParseSubPolicyExpression(lpszCurrent,pPRPolicyExpressionEmbeddedLeft,pParser);
  953. if(FAILED(hRes))
  954. {
  955. delete pPRPolicyExpressionEmbeddedLeft;
  956. pPRPolicyExpressionEmbeddedLeft = NULL;
  957. return(hRes);
  958. }
  959. pPRPolicyExpression->m_pPRPolicyExpressionLeft=pPRPolicyExpressionEmbeddedLeft;
  960. fFlag=pPRPolicyExpressionEmbeddedLeft->m_prYesNoUseEmbedded.GetYesNo();
  961. pPRPolicyExpression->m_prYesNoUseEmbedded.Set(&fFlag);
  962. }
  963. else //only one level deep
  964. {
  965. pPRPolicyExpressionEmbeddedLeft=new PICSRulesPolicyExpression;
  966. if(pPRPolicyExpressionEmbeddedLeft==NULL)
  967. {
  968. return(E_OUTOFMEMORY);
  969. }
  970. hRes=PICSRulesParseSimplePolicyExpression(lpszCurrent,pPRPolicyExpressionEmbeddedLeft,pParser);
  971. if(FAILED(hRes))
  972. {
  973. delete pPRPolicyExpressionEmbeddedLeft;
  974. pPRPolicyExpressionEmbeddedLeft= NULL;
  975. return(hRes);
  976. }
  977. pPRPolicyExpression->m_pPRPolicyExpressionLeft=pPRPolicyExpressionEmbeddedLeft;
  978. fFlag=pPRPolicyExpressionEmbeddedLeft->m_prYesNoUseEmbedded.GetYesNo();
  979. pPRPolicyExpression->m_prYesNoUseEmbedded.Set(&fFlag);
  980. lpszCurrent=strchrf(lpszCurrent,')');
  981. lpszCurrent=NonWhite(lpszCurrent+1);
  982. }
  983. lpszNextPolicyExpression=strchrf(lpszCurrent,'(');
  984. if(lpszNextPolicyExpression==NULL) //invalid policy expression
  985. {
  986. return(E_INVALIDARG);
  987. }
  988. lpszOrAndEnd=White(lpszCurrent);
  989. if(lpszOrAndEnd>lpszNextPolicyExpression) //no white space
  990. {
  991. lpszOrAndEnd=lpszNextPolicyExpression;
  992. }
  993. iStringLen=(int) (lpszOrAndEnd-lpszCurrent);
  994. lpszOrAnd=new char[iStringLen+1];
  995. if(lpszOrAnd==NULL)
  996. {
  997. return(E_OUTOFMEMORY);
  998. }
  999. memcpyf(lpszOrAnd,lpszCurrent,iStringLen);
  1000. lpszOrAnd[iStringLen]='\0';
  1001. if(lstrcmpi(lpszOrAnd,szPICSRulesAnd)==0)
  1002. {
  1003. pPRPolicyExpression->m_PRPEPolicyEmbedded=PR_POLICYEMBEDDED_AND;
  1004. }
  1005. else if(lstrcmpi(lpszOrAnd,szPICSRulesOr)==0)
  1006. {
  1007. pPRPolicyExpression->m_PRPEPolicyEmbedded=PR_POLICYEMBEDDED_OR;
  1008. }
  1009. else
  1010. {
  1011. delete lpszOrAnd;
  1012. lpszOrAnd = NULL;
  1013. return(E_INVALIDARG);
  1014. }
  1015. delete lpszOrAnd;
  1016. lpszOrAnd= NULL;
  1017. lpszCurrent=NonWhite(lpszOrAndEnd+1);
  1018. if(lpszCurrent!=lpszNextPolicyExpression)
  1019. {
  1020. return(E_INVALIDARG);
  1021. }
  1022. lpszCurrent=NonWhite(lpszCurrent+1);
  1023. //do we have more embedded objects, or another simple-expression?
  1024. if(*lpszCurrent=='(') //more embedded
  1025. {
  1026. pPRPolicyExpressionEmbeddedRight=new PICSRulesPolicyExpression;
  1027. if(pPRPolicyExpressionEmbeddedRight==NULL)
  1028. {
  1029. return(E_OUTOFMEMORY);
  1030. }
  1031. pPRPolicyExpressionEmbeddedRight->m_PROPolicyOperator=PR_OPERATOR_RESULT;
  1032. hRes=PICSRulesParseSubPolicyExpression(lpszCurrent,pPRPolicyExpressionEmbeddedRight,pParser);
  1033. if(FAILED(hRes))
  1034. {
  1035. return(hRes);
  1036. }
  1037. if(*lpszCurrent!=')')
  1038. {
  1039. delete pPRPolicyExpressionEmbeddedRight;
  1040. pPRPolicyExpressionEmbeddedRight= NULL;
  1041. return(E_INVALIDARG);
  1042. }
  1043. lpszCurrent=NonWhite(lpszCurrent+1);
  1044. pPRPolicyExpression->m_pPRPolicyExpressionRight=pPRPolicyExpressionEmbeddedRight;
  1045. fFlag=pPRPolicyExpressionEmbeddedRight->m_prYesNoUseEmbedded.GetYesNo();
  1046. pPRPolicyExpression->m_prYesNoUseEmbedded.Set(&fFlag);
  1047. }
  1048. else //simple expression
  1049. {
  1050. pPRPolicyExpressionEmbeddedRight=new PICSRulesPolicyExpression;
  1051. if(pPRPolicyExpressionEmbeddedRight==NULL)
  1052. {
  1053. return(E_OUTOFMEMORY);
  1054. }
  1055. hRes=PICSRulesParseSimplePolicyExpression(lpszCurrent,pPRPolicyExpressionEmbeddedRight,pParser);
  1056. if(FAILED(hRes))
  1057. {
  1058. delete pPRPolicyExpressionEmbeddedRight;
  1059. pPRPolicyExpressionEmbeddedRight = NULL;
  1060. return(hRes);
  1061. }
  1062. lpszCurrent=strchrf(lpszCurrent,')');
  1063. lpszCurrent=NonWhite(lpszCurrent+1);
  1064. if(*lpszCurrent!=')')
  1065. {
  1066. delete pPRPolicyExpressionEmbeddedRight;
  1067. pPRPolicyExpressionEmbeddedRight= NULL;
  1068. return(E_INVALIDARG);
  1069. }
  1070. lpszCurrent=NonWhite(lpszCurrent+1);
  1071. pPRPolicyExpression->m_pPRPolicyExpressionRight=pPRPolicyExpressionEmbeddedRight;
  1072. fFlag=pPRPolicyExpressionEmbeddedRight->m_prYesNoUseEmbedded.GetYesNo();
  1073. pPRPolicyExpression->m_prYesNoUseEmbedded.Set(&fFlag);
  1074. }
  1075. return(S_OK);
  1076. }
  1077. HRESULT PICSRulesParseSimplePolicyExpression(LPSTR& lpszCurrent,PICSRulesPolicyExpression *pPRPolicyExpression,PICSRulesFileParser *pParser)
  1078. {
  1079. LPSTR lpszEnd,lpszDot;
  1080. PICSRulesServiceInfo *pPRServiceInfo=NULL;
  1081. lpszEnd=strchrf(lpszCurrent,')');
  1082. if(lpszEnd==NULL) //we don't have a valid expression
  1083. {
  1084. return(E_INVALIDARG);
  1085. }
  1086. lpszDot=strchrf(lpszCurrent,'.');
  1087. if(lpszDot==NULL) //we have a service only expression
  1088. {
  1089. LPSTR lpszService,lpszServiceEnd,lpszFullService;
  1090. int iStringLen;
  1091. lpszServiceEnd=White(lpszCurrent);
  1092. if(lpszServiceEnd>lpszEnd) //there isn't any white space between
  1093. //the service name and the closing
  1094. //parenthesis
  1095. {
  1096. lpszServiceEnd=lpszEnd;
  1097. }
  1098. iStringLen=(int)(lpszServiceEnd-lpszCurrent);
  1099. lpszService=new char[iStringLen+1];
  1100. if(lpszService==NULL)
  1101. {
  1102. return(E_OUTOFMEMORY);
  1103. }
  1104. memcpyf(lpszService,lpszCurrent,iStringLen);
  1105. lpszService[iStringLen]='\0';
  1106. lpszFullService=new char[INTERNET_MAX_URL_LENGTH+1];
  1107. if(IsServiceDefined(lpszService,lpszFullService,&pPRServiceInfo)==FALSE)
  1108. {
  1109. delete lpszService;
  1110. lpszService = NULL;
  1111. delete lpszFullService;
  1112. lpszFullService = NULL;
  1113. return(PICSRULES_E_SERVICEUNDEFINED);
  1114. }
  1115. //we have a valid service only expression
  1116. if(pPRServiceInfo!=NULL)
  1117. {
  1118. BOOL fFlag;
  1119. fFlag=pPRServiceInfo->m_prYesNoUseEmbedded.GetYesNo();
  1120. pPRPolicyExpression->m_prYesNoUseEmbedded.Set(&fFlag);
  1121. }
  1122. pPRPolicyExpression->m_etstrServiceName.SetTo(lpszService);
  1123. pPRPolicyExpression->m_etstrFullServiceName.SetTo(lpszFullService);
  1124. pPRPolicyExpression->m_PROPolicyOperator=PR_OPERATOR_SERVICEONLY;
  1125. }
  1126. else //could be service and category or a full simple-expression
  1127. {
  1128. LPSTR lpszService,lpszCategory,lpszCategoryEnd,lpszOperator,lpszFullService;
  1129. int iStringLen;
  1130. lpszCategoryEnd=White(lpszCurrent);
  1131. if(lpszCategoryEnd>lpszEnd) //there isn't any white space between
  1132. //the category name and the closing
  1133. //parenthesis
  1134. {
  1135. lpszCategoryEnd=lpszEnd;
  1136. }
  1137. lpszOperator=strchrf(lpszCurrent,'<');
  1138. if(lpszOperator!=NULL)
  1139. {
  1140. if(lpszOperator<lpszCategoryEnd) //there was an operator with
  1141. //no white space
  1142. {
  1143. lpszCategoryEnd=lpszOperator;
  1144. }
  1145. }
  1146. lpszOperator=strchrf(lpszCurrent,'>');
  1147. if(lpszOperator!=NULL)
  1148. {
  1149. if(lpszOperator<lpszCategoryEnd) //there was an operator with
  1150. //no white space
  1151. {
  1152. lpszCategoryEnd=lpszOperator;
  1153. }
  1154. }
  1155. lpszOperator=strchrf(lpszCurrent,'=');
  1156. if(lpszOperator!=NULL)
  1157. {
  1158. if(lpszOperator<lpszCategoryEnd) //there was an operator with
  1159. //no white space
  1160. {
  1161. lpszCategoryEnd=lpszOperator;
  1162. }
  1163. }
  1164. iStringLen=(int)(lpszDot-lpszCurrent);
  1165. lpszService=new char[iStringLen+1];
  1166. if(lpszService==NULL)
  1167. {
  1168. return(E_OUTOFMEMORY);
  1169. }
  1170. memcpyf(lpszService,lpszCurrent,iStringLen);
  1171. lpszService[iStringLen]='\0';
  1172. lpszFullService=new char[INTERNET_MAX_URL_LENGTH+1];
  1173. if(IsServiceDefined(lpszService,lpszFullService,&pPRServiceInfo)==FALSE)
  1174. {
  1175. delete lpszService;
  1176. lpszService = NULL;
  1177. delete lpszFullService;
  1178. lpszFullService= NULL;
  1179. return(PICSRULES_E_SERVICEUNDEFINED);
  1180. }
  1181. iStringLen=(int)(lpszCategoryEnd-lpszDot-1);
  1182. lpszCategory=new char[iStringLen+1];
  1183. if(lpszCategory==NULL)
  1184. {
  1185. return(E_OUTOFMEMORY);
  1186. }
  1187. memcpyf(lpszCategory,lpszDot+1,iStringLen);
  1188. lpszCategory[iStringLen]='\0';
  1189. lpszCurrent=NonWhite(lpszCategoryEnd);
  1190. if(*lpszCurrent==')') //we have a valid service and category expression
  1191. {
  1192. if(pPRServiceInfo!=NULL)
  1193. {
  1194. BOOL fFlag;
  1195. fFlag=pPRServiceInfo->m_prYesNoUseEmbedded.GetYesNo();
  1196. pPRPolicyExpression->m_prYesNoUseEmbedded.Set(&fFlag);
  1197. }
  1198. pPRPolicyExpression->m_etstrServiceName.SetTo(lpszService);
  1199. pPRPolicyExpression->m_etstrFullServiceName.SetTo(lpszFullService);
  1200. pPRPolicyExpression->m_etstrCategoryName.SetTo(lpszCategory);
  1201. pPRPolicyExpression->m_PROPolicyOperator=PR_OPERATOR_SERVICEANDCATEGORY;
  1202. }
  1203. else //we have a full simple-expression
  1204. {
  1205. //lpszCurrent should be pointing to an operator
  1206. enum PICSRulesOperators PROPolicyOperator;
  1207. int iValue;
  1208. switch(*lpszCurrent)
  1209. {
  1210. case '>':
  1211. {
  1212. if(*(lpszCurrent+1)=='=')
  1213. {
  1214. PROPolicyOperator=PR_OPERATOR_GREATEROREQUAL;
  1215. lpszCurrent=NonWhite(lpszCurrent+2);
  1216. }
  1217. else
  1218. {
  1219. PROPolicyOperator=PR_OPERATOR_GREATER;
  1220. lpszCurrent=NonWhite(lpszCurrent+1);
  1221. }
  1222. break;
  1223. }
  1224. case '<':
  1225. {
  1226. if(*(lpszCurrent+1)=='=')
  1227. {
  1228. PROPolicyOperator=PR_OPERATOR_LESSOREQUAL;
  1229. lpszCurrent=NonWhite(lpszCurrent+2);
  1230. }
  1231. else
  1232. {
  1233. PROPolicyOperator=PR_OPERATOR_LESS;
  1234. lpszCurrent=NonWhite(lpszCurrent+1);
  1235. }
  1236. break;
  1237. }
  1238. case '=':
  1239. {
  1240. PROPolicyOperator=PR_OPERATOR_EQUAL;
  1241. lpszCurrent=NonWhite(lpszCurrent+1);
  1242. break;
  1243. }
  1244. default: //we didn't get a valid operator
  1245. {
  1246. delete lpszService;
  1247. lpszService = NULL;
  1248. delete lpszCategory;
  1249. lpszCategory = NULL;
  1250. return(E_INVALIDARG);
  1251. }
  1252. }
  1253. //lpszCurrent now points at the Value
  1254. if(FAILED(ParseNumber(&lpszCurrent,&iValue,FALSE)))
  1255. {
  1256. delete lpszService;
  1257. lpszService = NULL;
  1258. delete lpszCategory;
  1259. lpszCategory = NULL;
  1260. return(E_INVALIDARG);
  1261. }
  1262. if(*lpszCurrent!=')') //we should be done, so the argument is invalid
  1263. {
  1264. delete lpszService;
  1265. lpszService = NULL;
  1266. delete lpszCategory;
  1267. lpszCategory = NULL;
  1268. return(E_INVALIDARG);
  1269. }
  1270. //we now have a complete simple-expression
  1271. if(pPRServiceInfo!=NULL)
  1272. {
  1273. BOOL fFlag;
  1274. fFlag=pPRServiceInfo->m_prYesNoUseEmbedded.GetYesNo();
  1275. pPRPolicyExpression->m_prYesNoUseEmbedded.Set(&fFlag);
  1276. }
  1277. pPRPolicyExpression->m_etstrServiceName.SetTo(lpszService);
  1278. pPRPolicyExpression->m_etstrFullServiceName.SetTo(lpszFullService);
  1279. pPRPolicyExpression->m_etstrCategoryName.SetTo(lpszCategory);
  1280. pPRPolicyExpression->m_etnValue.Set(iValue);
  1281. pPRPolicyExpression->m_PROPolicyOperator=PROPolicyOperator;
  1282. }
  1283. }
  1284. return(S_OK);
  1285. }
  1286. //Determines if the service name in lpszService has been read in a
  1287. //ServiceInfo section of the PICSRules file
  1288. BOOL IsServiceDefined(LPSTR lpszService,LPSTR lpszFullService,PICSRulesServiceInfo **ppServiceInfo)
  1289. {
  1290. array<PICSRulesServiceInfo*> *arrpPRServiceInfo;
  1291. LPSTR lpszShortName;
  1292. int iNumServices,iCounter;
  1293. BOOL fDefined=FALSE;
  1294. if(g_pPRRS==NULL)
  1295. {
  1296. return(FALSE);
  1297. }
  1298. arrpPRServiceInfo=(array<PICSRulesServiceInfo*> *) &(g_pPRRS->m_arrpPRServiceInfo);
  1299. iNumServices=arrpPRServiceInfo->Length();
  1300. for(iCounter=0;iCounter<iNumServices;iCounter++)
  1301. {
  1302. PICSRulesServiceInfo * pPRServiceInfo;
  1303. pPRServiceInfo=(*arrpPRServiceInfo)[iCounter];
  1304. lpszShortName=pPRServiceInfo->m_etstrShortName.Get();
  1305. if(lstrcmp(lpszService,lpszShortName)==0)
  1306. {
  1307. fDefined=TRUE;
  1308. if(ppServiceInfo!=NULL)
  1309. {
  1310. *ppServiceInfo=pPRServiceInfo;
  1311. }
  1312. lstrcpy(lpszFullService,pPRServiceInfo->m_prURLName.Get());
  1313. break;
  1314. }
  1315. }
  1316. return(fDefined);
  1317. }
  1318. //Determines if the extension name in lpszExtension has been read in a
  1319. //OptExtension of the PICSRules file
  1320. BOOL IsOptExtensionDefined(LPSTR lpszExtension)
  1321. {
  1322. array<PICSRulesOptExtension*> *arrpPROptExtension;
  1323. LPSTR lpszShortName;
  1324. int iNumExtensions,iCounter;
  1325. BOOL fDefined=FALSE;
  1326. if(g_pPRRS==NULL)
  1327. {
  1328. return(FALSE);
  1329. }
  1330. arrpPROptExtension=(array<PICSRulesOptExtension*> *) &(g_pPRRS->m_arrpPROptExtension);
  1331. iNumExtensions=arrpPROptExtension->Length();
  1332. for(iCounter=0;iCounter<iNumExtensions;iCounter++)
  1333. {
  1334. PICSRulesOptExtension * pPROptExtension;
  1335. pPROptExtension=(*arrpPROptExtension)[iCounter];
  1336. lpszShortName=pPROptExtension->m_etstrShortName.Get();
  1337. if(lstrcmp(lpszExtension,lpszShortName)==0)
  1338. {
  1339. fDefined=TRUE;
  1340. break;
  1341. }
  1342. }
  1343. return(fDefined);
  1344. }
  1345. //Deteremines is the extension name in lpszExtension has been read in a
  1346. //ReqExtension of the PICSRules file
  1347. BOOL IsReqExtensionDefined(LPSTR lpszExtension)
  1348. {
  1349. array<PICSRulesReqExtension*> *arrpPRReqExtension;
  1350. LPSTR lpszShortName;
  1351. int iNumExtensions,iCounter;
  1352. BOOL fDefined=FALSE;
  1353. if(g_pPRRS==NULL)
  1354. {
  1355. return(FALSE);
  1356. }
  1357. arrpPRReqExtension=(array<PICSRulesReqExtension*> *) &(g_pPRRS->m_arrpPRReqExtension);
  1358. iNumExtensions=arrpPRReqExtension->Length();
  1359. for(iCounter=0;iCounter<iNumExtensions;iCounter++)
  1360. {
  1361. PICSRulesReqExtension * pPRReqExtension;
  1362. pPRReqExtension=(*arrpPRReqExtension)[iCounter];
  1363. lpszShortName=pPRReqExtension->m_etstrShortName.Get();
  1364. if(lstrcmp(lpszExtension,lpszShortName)==0)
  1365. {
  1366. fDefined=TRUE;
  1367. break;
  1368. }
  1369. }
  1370. return(fDefined);
  1371. }
  1372. PICSRulesAllowableOption aaoPICSRulesName[] = {
  1373. { PROID_RULENAME, 0 },
  1374. { PROID_DESCRIPTION, 0 },
  1375. { PROID_EXTENSION, 0 },
  1376. { PROID_INVALID, 0 }
  1377. };
  1378. const UINT caoPICSRulesName=sizeof(aaoPICSRulesName)/sizeof(aaoPICSRulesName[0]);
  1379. HRESULT PICSRulesParseName(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  1380. {
  1381. //We must make a copy of the allowable options array because the
  1382. //parser will fiddle with the flags in the entries -- specifically,
  1383. //setting AO_SEEN. It wouldn't be thread-safe to do this to a
  1384. //static array.
  1385. PICSRulesAllowableOption aao[caoPICSRulesName];
  1386. ::memcpyf(aao,::aaoPICSRulesName,sizeof(aao));
  1387. PICSRulesName *pName=new PICSRulesName;
  1388. if(pName==NULL)
  1389. {
  1390. return E_OUTOFMEMORY;
  1391. }
  1392. HRESULT hres=pParser->ParseParenthesizedObject(
  1393. ppszIn, //var containing current ptr
  1394. aao, //what's legal in this object
  1395. pName); //object to add items back to
  1396. if (FAILED(hres))
  1397. {
  1398. delete pName;
  1399. pName = NULL;
  1400. return hres;
  1401. }
  1402. *ppOut=(LPVOID) pName;
  1403. return NOERROR;
  1404. }
  1405. PICSRulesAllowableOption aaoPICSRulesSource[] = {
  1406. { PROID_SOURCEURL, 0 },
  1407. { PROID_CREATIONTOOL, 0 },
  1408. { PROID_AUTHOR, 0 },
  1409. { PROID_LASTMODIFIED, 0 },
  1410. { PROID_EXTENSION, 0 },
  1411. { PROID_INVALID, 0 }
  1412. };
  1413. const UINT caoPICSRulesSource=sizeof(aaoPICSRulesSource)/sizeof(aaoPICSRulesSource[0]);
  1414. HRESULT PICSRulesParseSource(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  1415. {
  1416. //We must make a copy of the allowable options array because the
  1417. //parser will fiddle with the flags in the entries -- specifically,
  1418. //setting AO_SEEN. It wouldn't be thread-safe to do this to a
  1419. //static array.
  1420. PICSRulesAllowableOption aao[caoPICSRulesSource];
  1421. ::memcpyf(aao,::aaoPICSRulesSource,sizeof(aao));
  1422. PICSRulesSource *pSource=new PICSRulesSource;
  1423. if(pSource==NULL)
  1424. {
  1425. return E_OUTOFMEMORY;
  1426. }
  1427. HRESULT hres=pParser->ParseParenthesizedObject(
  1428. ppszIn, //var containing current ptr
  1429. aao, //what's legal in this object
  1430. pSource); //object to add items back to
  1431. if (FAILED(hres))
  1432. {
  1433. delete pSource;
  1434. pSource = NULL;
  1435. return hres;
  1436. }
  1437. *ppOut=(LPVOID) pSource;
  1438. return NOERROR;
  1439. }
  1440. PICSRulesAllowableOption aaoPICSRulesServiceInfo[] = {
  1441. { PROID_SINAME, AO_SINGLE },
  1442. { PROID_SHORTNAME, AO_SINGLE },
  1443. { PROID_BUREAUURL, 0 },
  1444. { PROID_USEEMBEDDED, AO_SINGLE },
  1445. { PROID_RATFILE, AO_SINGLE },
  1446. { PROID_BUREAUUNAVAILABLE, AO_SINGLE },
  1447. { PROID_EXTENSION, 0 },
  1448. { PROID_INVALID, 0 }
  1449. };
  1450. const UINT caoPICSRulesServiceInfo=sizeof(aaoPICSRulesServiceInfo)/sizeof(aaoPICSRulesServiceInfo[0]);
  1451. HRESULT PICSRulesParseServiceInfo(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  1452. {
  1453. //We must make a copy of the allowable options array because the
  1454. //parser will fiddle with the flags in the entries -- specifically,
  1455. //setting AO_SEEN. It wouldn't be thread-safe to do this to a
  1456. //static array.
  1457. PICSRulesAllowableOption aao[caoPICSRulesServiceInfo];
  1458. ::memcpyf(aao,::aaoPICSRulesServiceInfo,sizeof(aao));
  1459. PICSRulesServiceInfo *pServiceInfo=new PICSRulesServiceInfo;
  1460. if(pServiceInfo==NULL)
  1461. {
  1462. return E_OUTOFMEMORY;
  1463. }
  1464. HRESULT hres=pParser->ParseParenthesizedObject(
  1465. ppszIn, //var containing current ptr
  1466. aao, //what's legal in this object
  1467. pServiceInfo); //object to add items back to
  1468. if (FAILED(hres))
  1469. {
  1470. delete pServiceInfo;
  1471. pServiceInfo = NULL;
  1472. return hres;
  1473. }
  1474. *ppOut=(LPVOID) pServiceInfo;
  1475. return NOERROR;
  1476. }
  1477. PICSRulesAllowableOption aaoPICSRulesOptExtension[] = {
  1478. { PROID_EXTENSIONNAME, AO_SINGLE },
  1479. { PROID_SHORTNAME, AO_SINGLE },
  1480. { PROID_EXTENSION, 0 },
  1481. { PROID_INVALID, 0 }
  1482. };
  1483. const UINT caoPICSRulesOptExtension=sizeof(aaoPICSRulesOptExtension)/sizeof(aaoPICSRulesOptExtension[0]);
  1484. HRESULT PICSRulesParseOptExtension(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  1485. {
  1486. //We must make a copy of the allowable options array because the
  1487. //parser will fiddle with the flags in the entries -- specifically,
  1488. //setting AO_SEEN. It wouldn't be thread-safe to do this to a
  1489. //static array.
  1490. PICSRulesAllowableOption aao[caoPICSRulesOptExtension];
  1491. ::memcpyf(aao,::aaoPICSRulesOptExtension,sizeof(aao));
  1492. PICSRulesOptExtension *pOptExtension=new PICSRulesOptExtension;
  1493. if(pOptExtension==NULL)
  1494. {
  1495. return E_OUTOFMEMORY;
  1496. }
  1497. HRESULT hres=pParser->ParseParenthesizedObject(
  1498. ppszIn, //var containing current ptr
  1499. aao, //what's legal in this object
  1500. pOptExtension); //object to add items back to
  1501. if (FAILED(hres))
  1502. {
  1503. delete pOptExtension;
  1504. pOptExtension = NULL;
  1505. return hres;
  1506. }
  1507. *ppOut=(LPVOID) pOptExtension;
  1508. return NOERROR;
  1509. }
  1510. PICSRulesAllowableOption aaoPICSRulesReqExtension[] = {
  1511. { PROID_EXTENSIONNAME, AO_SINGLE },
  1512. { PROID_SHORTNAME, AO_SINGLE },
  1513. { PROID_EXTENSION, 0 },
  1514. { PROID_INVALID, 0 }
  1515. };
  1516. const UINT caoPICSRulesReqExtension=sizeof(aaoPICSRulesReqExtension)/sizeof(aaoPICSRulesReqExtension[0]);
  1517. HRESULT PICSRulesParseReqExtension(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  1518. {
  1519. //We must make a copy of the allowable options array because the
  1520. //parser will fiddle with the flags in the entries -- specifically,
  1521. //setting AO_SEEN. It wouldn't be thread-safe to do this to a
  1522. //static array.
  1523. PICSRulesAllowableOption aao[caoPICSRulesReqExtension];
  1524. ::memcpyf(aao,::aaoPICSRulesReqExtension,sizeof(aao));
  1525. PICSRulesReqExtension *pReqExtension=new PICSRulesReqExtension;
  1526. if(pReqExtension==NULL)
  1527. {
  1528. return E_OUTOFMEMORY;
  1529. }
  1530. HRESULT hres=pParser->ParseParenthesizedObject(
  1531. ppszIn, //var containing current ptr
  1532. aao, //what's legal in this object
  1533. pReqExtension); //object to add items back to
  1534. if (FAILED(hres))
  1535. {
  1536. delete pReqExtension;
  1537. pReqExtension = NULL;
  1538. return hres;
  1539. }
  1540. *ppOut=(LPVOID) pReqExtension;
  1541. return NOERROR;
  1542. }
  1543. //Currently, we acknowledge no extensions. If support for an extension
  1544. //needs to be added in the future, a PICSRulesParseExtensionName function
  1545. //should be added, similar to the other PICSRulesParseSection functions.
  1546. //This function should be called after confirming the extension string
  1547. //here.
  1548. //
  1549. //For now, we just eat the extensions
  1550. HRESULT PICSRulesParseExtension(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser)
  1551. {
  1552. LPTSTR lpszExtension,lpszEnd;
  1553. lpszEnd=strchrf(*ppszIn,'.');
  1554. if(lpszEnd==NULL)
  1555. {
  1556. return(PICSRULES_E_UNKNOWNITEM);
  1557. }
  1558. *lpszEnd='\0';
  1559. //*ppszIn now points to the extension name
  1560. //if we ever implement support for extensions, we'll need to do a comparison
  1561. //here. After the comparison is completed, the following code will point
  1562. //to the extension's method.
  1563. *ppszIn=lpszEnd+1;
  1564. lpszEnd=strchrf(*ppszIn,'(');
  1565. if(lpszEnd==NULL)
  1566. {
  1567. return(PICSRULES_E_EXPECTEDLEFT);
  1568. }
  1569. lpszExtension=White(*ppszIn);
  1570. if((lpszExtension!=NULL)&&(lpszExtension<lpszEnd))
  1571. {
  1572. *lpszExtension='\0';
  1573. }
  1574. else
  1575. {
  1576. *lpszEnd='\0';
  1577. }
  1578. lpszExtension=*ppszIn;
  1579. //lpszExtension now points to the clause on the given extension name
  1580. //if we ever implement support for extensions, we'll need to do a comparison
  1581. //here. Using both this comparison and the one above, a callback needs
  1582. //to be implemented to support the extension, for now we'll just parse to
  1583. //the closing parenthesis and eat the extension.
  1584. *ppszIn=lpszEnd+1;
  1585. int iOpenParenthesis=1;
  1586. do
  1587. {
  1588. if(**ppszIn=='(')
  1589. {
  1590. iOpenParenthesis++;
  1591. }
  1592. else if (**ppszIn==')')
  1593. {
  1594. iOpenParenthesis--;
  1595. if(iOpenParenthesis==0)
  1596. {
  1597. break;
  1598. }
  1599. }
  1600. *ppszIn=pParser->FindNonWhite(*ppszIn+1);
  1601. } while (**ppszIn!='\0');
  1602. if(**ppszIn=='\0')
  1603. {
  1604. return(PICSRULES_E_EXPECTEDRIGHT);
  1605. }
  1606. else
  1607. {
  1608. *ppszIn=pParser->FindNonWhite(*ppszIn+1);
  1609. }
  1610. *ppOut=(LPVOID) NULL;
  1611. return NOERROR;
  1612. }
  1613. //*******************************************************************
  1614. //*
  1615. //* Code for the PICSRulesRatingSystem class
  1616. //*
  1617. //*******************************************************************
  1618. PICSRulesRatingSystem::PICSRulesRatingSystem()
  1619. : m_dwFlags(0),
  1620. m_nErrLine(0)
  1621. {
  1622. // nothing to do but construct members
  1623. }
  1624. PICSRulesRatingSystem::~PICSRulesRatingSystem()
  1625. {
  1626. m_arrpPRPolicy.DeleteAll();
  1627. m_arrpPRServiceInfo.DeleteAll();
  1628. m_arrpPROptExtension.DeleteAll();
  1629. m_arrpPRReqExtension.DeleteAll();
  1630. }
  1631. HRESULT PICSRulesRatingSystem::InitializeMyDefaults()
  1632. {
  1633. return NOERROR; //no defaults to initialize
  1634. }
  1635. //Allowable options from within PICSRulesRaginSystem's scope include only the
  1636. //first teer of aaoPICSRules[] defined in picsrule.h
  1637. PICSRulesAllowableOption aaoPICSRulesRatingSystem[] = {
  1638. { PROID_PICSVERSION, 0 },
  1639. { PROID_POLICY, AO_MANDATORY },
  1640. { PROID_NAME, AO_SINGLE },
  1641. { PROID_SOURCE, AO_SINGLE },
  1642. { PROID_SERVICEINFO, 0 },
  1643. { PROID_OPTEXTENSION, 0 },
  1644. { PROID_REQEXTENSION, 0 },
  1645. { PROID_EXTENSION, 0 },
  1646. { PROID_INVALID, 0 }
  1647. };
  1648. const UINT caoPICSRulesRatingSystem=sizeof(aaoPICSRulesRatingSystem)/sizeof(aaoPICSRulesRatingSystem[0]);
  1649. //The following array is indexed by PICSRulesObjectID values.
  1650. //PICSRulesObjectHandler is defined in mslubase.h as:
  1651. //typedef HRESULT (*PICSRulesObjectHandler)(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser);
  1652. struct {
  1653. LPCSTR lpszToken; //token by which we identify it
  1654. PICSRulesObjectHandler pHandler; //function which parses the object's contents
  1655. } aPRObjectDescriptions[] = {
  1656. { szNULL, NULL },
  1657. { szPICSRulesVersion, PICSRulesParseVersion },
  1658. { szPICSRulesPolicy, PICSRulesParsePolicy },
  1659. { szPICSRulesExplanation, PICSRulesParseString },
  1660. { szPICSRulesRejectByURL, PICSRulesParseByURL },
  1661. { szPICSRulesAcceptByURL, PICSRulesParseByURL },
  1662. { szPICSRulesRejectIf, PICSRulesParsePolicyExpression },
  1663. { szPICSRulesAcceptIf, PICSRulesParsePolicyExpression },
  1664. { szPICSRulesAcceptUnless, PICSRulesParsePolicyExpression },
  1665. { szPICSRulesRejectUnless, PICSRulesParsePolicyExpression },
  1666. { szPICSRulesName, PICSRulesParseName },
  1667. { szPICSRulesRuleName, PICSRulesParseString },
  1668. { szPICSRulesDescription, PICSRulesParseString },
  1669. { szPICSRulesSource, PICSRulesParseSource },
  1670. { szPICSRulesSourceURL, PICSRulesParseString },
  1671. { szPICSRulesCreationTool, PICSRulesParseString },
  1672. { szPICSRulesAuthor, PICSRulesParseString },
  1673. { szPICSRulesLastModified, PICSRulesParseString },
  1674. { szPICSRulesServiceInfo, PICSRulesParseServiceInfo },
  1675. { szPICSRulesSIName, PICSRulesParseString },
  1676. { szPICSRulesShortName, PICSRulesParseString },
  1677. { szPICSRulesBureauURL, PICSRulesParseString },
  1678. { szPICSRulesUseEmbedded, PICSRulesParseYesNo },
  1679. { szPICSRulesRATFile, PICSRulesParseString },
  1680. { szPICSRulesBureauUnavailable, PICSRulesParsePassFail },
  1681. { szPICSRulesOptExtension, PICSRulesParseOptExtension },
  1682. { szPICSRulesExtensionName, PICSRulesParseString },
  1683. //{ szPICSRulesShortName, PICSRulesParseString },
  1684. { szPICSRulesReqExtension, PICSRulesParseReqExtension },
  1685. //{ szPICSRulesExtensionName, PICSRulesParseString },
  1686. //{ szPICSRulesShortName, PICSRulesParseString },
  1687. { szPICSRulesExtension, PICSRulesParseExtension },
  1688. { szPICSRulesOptionDefault, PICSRulesParseString },
  1689. { szPICSRulesOptionDefault, PICSRulesParseString },
  1690. { szPICSRulesOptionDefault, PICSRulesParseString },
  1691. { szPICSRulesOptionDefault, PICSRulesParseString },
  1692. { szPICSRulesOptionDefault, PICSRulesParseString },
  1693. { szPICSRulesOptionDefault, PICSRulesParseString }
  1694. };
  1695. HRESULT PICSRulesRatingSystem::Parse(LPCSTR pszFilename, LPSTR pIn)
  1696. {
  1697. //This guy is small enough to just init directly on the stack
  1698. PICSRulesAllowableOption aaoRoot[] = { { PROID_PICSVERSION, 0 }, { PROID_INVALID, 0 } };
  1699. PICSRulesAllowableOption aao[caoPICSRulesRatingSystem];
  1700. ::memcpyf(aao,::aaoPICSRulesRatingSystem,sizeof(aao));
  1701. PICSRulesAllowableOption *pFound;
  1702. PICSRulesFileParser parser;
  1703. LPSTR lpszVersionDash=strchrf(pIn,'-'); //since this is the first
  1704. //time through, we need to
  1705. //prepare the PicsRule
  1706. //token for the parser
  1707. if(lpszVersionDash!=NULL) //check for no dash we'll
  1708. //fail in ParseToOpening
  1709. //if this is the case
  1710. {
  1711. *lpszVersionDash=' '; //set it up for the parser
  1712. }
  1713. HRESULT hres=parser.ParseToOpening(&pIn,aaoRoot,&pFound);
  1714. if (FAILED(hres))
  1715. {
  1716. return hres; //some error early on
  1717. }
  1718. else //we got the PicsRule tag
  1719. //now we need to check
  1720. //the version number
  1721. {
  1722. LPSTR lpszDot=strchrf(pIn,'.');
  1723. if(lpszDot!=NULL) //continue on and fail
  1724. //in ParseParenthesizedObject
  1725. {
  1726. int iVersion;
  1727. *lpszDot=' ';
  1728. ParseNumber(&pIn,&iVersion,TRUE);
  1729. m_etnPRVerMajor.Set(iVersion);
  1730. pIn=parser.FindNonWhite(pIn);
  1731. ParseNumber(&pIn,&iVersion,TRUE);
  1732. m_etnPRVerMinor.Set(iVersion);
  1733. pIn=parser.FindNonWhite(pIn);
  1734. }
  1735. }
  1736. //we'll fail if the version is 1.0, or 2.0 or higher
  1737. //versions 1.1 - 2.0 (not including 2.0) will pass
  1738. int iVerNumber=m_etnPRVerMajor.Get();
  1739. if(iVerNumber!=1)
  1740. {
  1741. hres=PICSRULES_E_VERSION;
  1742. m_nErrLine=parser.m_nLine;
  1743. return(hres);
  1744. }
  1745. else //check the minor version number
  1746. {
  1747. iVerNumber=m_etnPRVerMinor.Get();
  1748. if(iVerNumber==0)
  1749. {
  1750. hres=PICSRULES_E_VERSION;
  1751. m_nErrLine=parser.m_nLine;
  1752. return(hres);
  1753. }
  1754. }
  1755. hres=parser.ParseParenthesizedObject(
  1756. &pIn, //var containing current ptr
  1757. aao, //what's legal in this object
  1758. this); //object to add items back to
  1759. if(SUCCEEDED(hres))
  1760. {
  1761. if(*pIn!=')') //check for a closing parenthesis
  1762. {
  1763. hres=PICSRULES_E_EXPECTEDRIGHT;
  1764. }
  1765. else
  1766. {
  1767. LPTSTR lpszEnd=NonWhite(pIn+1);
  1768. if(*lpszEnd!='\0') // make sure we're at the end of the file
  1769. {
  1770. hres=PICSRULES_E_EXPECTEDEND;
  1771. }
  1772. }
  1773. }
  1774. if(FAILED(hres))
  1775. {
  1776. m_nErrLine=parser.m_nLine;
  1777. }
  1778. return hres;
  1779. }
  1780. HRESULT PICSRulesRatingSystem::AddItem(PICSRulesObjectID roid, LPVOID pData)
  1781. {
  1782. HRESULT hres = S_OK;
  1783. switch (roid)
  1784. {
  1785. case PROID_PICSVERSION:
  1786. {
  1787. //Takes a pointer to a PICSRULES_VERSION struct (defined in picsrule.h)
  1788. PICSRULES_VERSION * PRVer;
  1789. if(PRVer=((PICSRULES_VERSION *) pData))
  1790. {
  1791. m_etnPRVerMajor.Set(PRVer->iPICSRulesVerMajor);
  1792. m_etnPRVerMinor.Set(PRVer->iPICSRulesVerMinor);
  1793. }
  1794. else
  1795. {
  1796. hres=E_INVALIDARG;
  1797. }
  1798. break;
  1799. }
  1800. case PROID_OPTEXTENSION:
  1801. {
  1802. PICSRulesOptExtension *pOptExtension;
  1803. if(pOptExtension=((PICSRulesOptExtension *) pData))
  1804. {
  1805. hres=m_arrpPROptExtension.Append(pOptExtension) ? S_OK : E_OUTOFMEMORY;
  1806. if (FAILED(hres))
  1807. {
  1808. delete pOptExtension;
  1809. pOptExtension = NULL;
  1810. }
  1811. }
  1812. else
  1813. {
  1814. hres=E_INVALIDARG;
  1815. }
  1816. break;
  1817. }
  1818. case PROID_REQEXTENSION:
  1819. {
  1820. PICSRulesReqExtension *pReqExtension;
  1821. if(pReqExtension=((PICSRulesReqExtension *) pData))
  1822. {
  1823. hres=m_arrpPRReqExtension.Append(pReqExtension) ? S_OK : E_OUTOFMEMORY;
  1824. if (FAILED(hres))
  1825. {
  1826. delete pReqExtension;
  1827. pReqExtension= NULL;
  1828. }
  1829. }
  1830. else
  1831. {
  1832. hres=E_INVALIDARG;
  1833. }
  1834. break;
  1835. }
  1836. case PROID_POLICY:
  1837. {
  1838. PICSRulesPolicy *pPolicy;
  1839. if(pPolicy=((PICSRulesPolicy *) pData))
  1840. {
  1841. hres=m_arrpPRPolicy.Append(pPolicy) ? S_OK : E_OUTOFMEMORY;
  1842. if (FAILED(hres))
  1843. {
  1844. delete pPolicy;
  1845. pPolicy = NULL;
  1846. }
  1847. }
  1848. else
  1849. {
  1850. hres=E_INVALIDARG;
  1851. }
  1852. break;
  1853. }
  1854. case PROID_NAME:
  1855. {
  1856. PICSRulesName *pName;
  1857. if(pName=((PICSRulesName *) pData))
  1858. {
  1859. m_pPRName=pName;
  1860. }
  1861. else
  1862. {
  1863. hres=E_INVALIDARG;
  1864. }
  1865. break;
  1866. }
  1867. case PROID_SOURCE:
  1868. {
  1869. PICSRulesSource *pSource;
  1870. if(pSource=((PICSRulesSource *) pData))
  1871. {
  1872. m_pPRSource=pSource;
  1873. }
  1874. else
  1875. {
  1876. hres=E_INVALIDARG;
  1877. }
  1878. break;
  1879. }
  1880. case PROID_SERVICEINFO:
  1881. {
  1882. PICSRulesServiceInfo *pServiceInfo;
  1883. if(pServiceInfo=((PICSRulesServiceInfo *) pData))
  1884. {
  1885. hres=m_arrpPRServiceInfo.Append(pServiceInfo) ? S_OK : E_OUTOFMEMORY;
  1886. if (FAILED(hres))
  1887. {
  1888. delete pServiceInfo;
  1889. pServiceInfo = NULL;
  1890. }
  1891. }
  1892. else
  1893. {
  1894. hres=E_INVALIDARG;
  1895. }
  1896. break;
  1897. }
  1898. case PROID_EXTENSION:
  1899. {
  1900. //just eat extensions
  1901. break;
  1902. }
  1903. case PROID_INVALID:
  1904. default:
  1905. {
  1906. ASSERT(FALSE); // shouldn't have been given a PROID that wasn't in
  1907. // the table we passed to the parser!
  1908. hres=E_UNEXPECTED;
  1909. break;
  1910. }
  1911. }
  1912. return hres;
  1913. }
  1914. void PICSRulesRatingSystem::ReportError(HRESULT hres)
  1915. {
  1916. UINT idMsg,idTemplate;
  1917. WCHAR szErrorMessage[MAX_PATH],szErrorTitle[MAX_PATH],
  1918. szLoadStringTemp[MAX_PATH];
  1919. //we may be reporting E_OUTOFMEMORY, so we'll keep our string memory
  1920. //on the stack so that its gauranteed to be there
  1921. if((hres==E_OUTOFMEMORY)||((hres>PICSRULES_E_BASE)&&(hres<=PICSRULES_E_BASE+0xffff)))
  1922. {
  1923. idTemplate=IDS_PICSRULES_SYNTAX_TEMPLATE; //default is PICSRules content error
  1924. switch(hres)
  1925. {
  1926. case E_OUTOFMEMORY:
  1927. {
  1928. idMsg=IDS_PICSRULES_MEMORY;
  1929. idTemplate=IDS_PICSRULES_GENERIC_TEMPLATE;
  1930. break;
  1931. }
  1932. case PICSRULES_E_EXPECTEDLEFT:
  1933. {
  1934. idMsg=IDS_PICSRULES_EXPECTEDLEFT;
  1935. break;
  1936. }
  1937. case PICSRULES_E_EXPECTEDRIGHT:
  1938. {
  1939. idMsg=IDS_PICSRULES_EXPECTEDRIGHT;
  1940. break;
  1941. }
  1942. case PICSRULES_E_EXPECTEDTOKEN:
  1943. {
  1944. idMsg=IDS_PICSRULES_EXPECTEDTOKEN;
  1945. break;
  1946. }
  1947. case PICSRULES_E_EXPECTEDSTRING:
  1948. {
  1949. idMsg=IDS_PICSRULES_EXPECTEDSTRING;
  1950. break;
  1951. }
  1952. case PICSRULES_E_EXPECTEDNUMBER:
  1953. {
  1954. idMsg=IDS_PICSRULES_EXPECTEDNUMBER;
  1955. break;
  1956. }
  1957. case PICSRULES_E_EXPECTEDBOOL:
  1958. {
  1959. idMsg=IDS_PICSRULES_EXPECTEDBOOL;
  1960. break;
  1961. }
  1962. case PICSRULES_E_DUPLICATEITEM:
  1963. {
  1964. idMsg=IDS_PICSRULES_DUPLICATEITEM;
  1965. break;
  1966. }
  1967. case PICSRULES_E_MISSINGITEM:
  1968. {
  1969. idMsg=IDS_PICSRULES_MISSINGITEM;
  1970. break;
  1971. }
  1972. case PICSRULES_E_UNKNOWNITEM:
  1973. {
  1974. idMsg=IDS_PICSRULES_UNKNOWNITEM;
  1975. break;
  1976. }
  1977. case PICSRULES_E_UNKNOWNMANDATORY:
  1978. {
  1979. idMsg=IDS_PICSRULES_UNKNOWNMANDATORY;
  1980. break;
  1981. }
  1982. case PICSRULES_E_SERVICEUNDEFINED:
  1983. {
  1984. idMsg=IDS_PICSRULES_SERVICEUNDEFINED;
  1985. break;
  1986. }
  1987. case PICSRULES_E_EXPECTEDEND:
  1988. {
  1989. idMsg=IDS_PICSRULES_EXPECTEDEND;
  1990. break;
  1991. }
  1992. case PICSRULES_E_REQEXTENSIONUSED:
  1993. {
  1994. idTemplate=IDS_PICSRULES_GENERIC_TEMPLATE;
  1995. idMsg=IDS_PICSRULES_REQEXTENSIONUSED;
  1996. break;
  1997. }
  1998. case PICSRULES_E_VERSION:
  1999. {
  2000. idTemplate=IDS_PICSRULES_GENERIC_TEMPLATE;
  2001. idMsg=IDS_PICSRULES_BADVERSION;
  2002. break;
  2003. }
  2004. default:
  2005. {
  2006. ASSERT(FALSE); //there aren't any other PICSRULES_E_ errors
  2007. idMsg=IDS_PICSRULES_UNKNOWNERROR;
  2008. break;
  2009. }
  2010. }
  2011. MLLoadString(idTemplate,(LPTSTR) szLoadStringTemp,MAX_PATH);
  2012. wsprintf((LPTSTR) szErrorMessage,(LPTSTR) szLoadStringTemp,m_etstrFile.Get());
  2013. MLLoadString(idMsg,(LPTSTR) szLoadStringTemp,MAX_PATH);
  2014. wsprintf((LPTSTR) szErrorTitle,(LPTSTR) szLoadStringTemp,m_nErrLine);
  2015. lstrcat((LPTSTR) szErrorMessage,(LPTSTR) szErrorTitle);
  2016. }
  2017. else
  2018. {
  2019. idTemplate=IDS_PICSRULES_GENERIC_TEMPLATE;
  2020. if(HRESULT_FACILITY(hres)==FACILITY_WIN32)
  2021. {
  2022. switch(hres)
  2023. {
  2024. case E_OUTOFMEMORY:
  2025. {
  2026. idMsg=IDS_PICSRULES_MEMORY;
  2027. break;
  2028. }
  2029. case E_INVALIDARG:
  2030. {
  2031. idMsg=IDS_PICSRULES_INVALID;
  2032. break;
  2033. }
  2034. default:
  2035. {
  2036. idMsg=IDS_PICSRULES_WINERROR;
  2037. break;
  2038. }
  2039. }
  2040. MLLoadString(idTemplate,(LPTSTR) szLoadStringTemp,MAX_PATH);
  2041. wsprintf((LPTSTR) szErrorMessage,(LPTSTR) szLoadStringTemp,m_etstrFile.Get());
  2042. MLLoadString(idMsg,(LPTSTR) szLoadStringTemp,MAX_PATH);
  2043. if(idMsg==IDS_PICSRULES_WINERROR)
  2044. {
  2045. wsprintf((LPTSTR) szErrorTitle,(LPTSTR) szLoadStringTemp,HRESULT_CODE(hres));
  2046. }
  2047. else
  2048. {
  2049. wsprintf((LPTSTR) szErrorTitle,(LPTSTR) szLoadStringTemp,m_nErrLine);
  2050. }
  2051. lstrcat((LPTSTR) szErrorMessage,(LPTSTR) szErrorTitle);
  2052. }
  2053. else
  2054. {
  2055. idMsg=IDS_PICSRULES_MISCERROR;
  2056. MLLoadString(idTemplate,(LPTSTR) szLoadStringTemp,MAX_PATH);
  2057. wsprintf((LPTSTR) szErrorMessage,(LPTSTR) szLoadStringTemp,m_etstrFile.Get());
  2058. MLLoadString(idMsg,(LPTSTR) szLoadStringTemp,MAX_PATH);
  2059. wsprintf((LPTSTR) szErrorTitle,(LPTSTR) szLoadStringTemp,HRESULT_CODE(hres));
  2060. lstrcat((LPTSTR) szErrorMessage,(LPTSTR) szErrorTitle);
  2061. }
  2062. }
  2063. MLLoadString(IDS_ERROR,(LPTSTR) szErrorTitle,MAX_PATH);
  2064. MessageBox(NULL,(LPCTSTR) szErrorMessage,(LPCTSTR) szErrorTitle,MB_OK|MB_ICONERROR);
  2065. }
  2066. //*******************************************************************
  2067. //*
  2068. //* Code for the PICSRulesByURL class
  2069. //*
  2070. //*******************************************************************
  2071. PICSRulesByURL::PICSRulesByURL()
  2072. {
  2073. //nothing to do
  2074. }
  2075. PICSRulesByURL::~PICSRulesByURL()
  2076. {
  2077. m_arrpPRByURL.DeleteAll();
  2078. }
  2079. PICSRulesEvaluation PICSRulesByURL::EvaluateRule(PICSRulesQuotedURL *pprurlComparisonURL)
  2080. {
  2081. int iCounter;
  2082. URL_COMPONENTS URLComponents;
  2083. FN_INTERNETCRACKURL pfnInternetCrackUrl;
  2084. INTERNET_SCHEME INetScheme=INTERNET_SCHEME_DEFAULT;
  2085. INTERNET_PORT INetPort=INTERNET_INVALID_PORT_NUMBER;
  2086. LPSTR lpszScheme,lpszHostName,lpszUserName,
  2087. lpszPassword,lpszUrlPath,lpszExtraInfo;
  2088. BOOL fApplies=FALSE;
  2089. lpszScheme=new char[INTERNET_MAX_SCHEME_LENGTH+1];
  2090. lpszHostName=new char[INTERNET_MAX_PATH_LENGTH+1];
  2091. lpszUserName=new char[INTERNET_MAX_PATH_LENGTH+1];
  2092. lpszPassword=new char[INTERNET_MAX_PATH_LENGTH+1];
  2093. lpszUrlPath=new char[INTERNET_MAX_PATH_LENGTH+1];
  2094. lpszExtraInfo=new char[INTERNET_MAX_PATH_LENGTH+1];
  2095. if(lpszScheme==NULL ||
  2096. lpszHostName==NULL ||
  2097. lpszUserName==NULL ||
  2098. lpszPassword==NULL ||
  2099. lpszUrlPath==NULL ||
  2100. lpszExtraInfo==NULL)
  2101. {
  2102. if (lpszScheme)
  2103. {
  2104. delete [] lpszScheme;
  2105. lpszScheme = NULL;
  2106. }
  2107. if (lpszHostName)
  2108. {
  2109. delete [] lpszHostName;
  2110. lpszHostName = NULL;
  2111. }
  2112. if (lpszUserName)
  2113. {
  2114. delete [] lpszUserName;
  2115. lpszUserName = NULL;
  2116. }
  2117. if (lpszPassword)
  2118. {
  2119. delete [] lpszPassword;
  2120. lpszPassword = NULL;
  2121. }
  2122. if (lpszUrlPath)
  2123. {
  2124. delete [] lpszUrlPath;
  2125. lpszUrlPath = NULL;
  2126. }
  2127. if (lpszExtraInfo)
  2128. {
  2129. delete [] lpszExtraInfo;
  2130. lpszExtraInfo = NULL;
  2131. }
  2132. return(PR_EVALUATION_DOESNOTAPPLY);
  2133. }
  2134. URLComponents.dwStructSize=sizeof(URL_COMPONENTS);
  2135. URLComponents.lpszScheme=lpszScheme;
  2136. URLComponents.dwSchemeLength=INTERNET_MAX_SCHEME_LENGTH;
  2137. URLComponents.nScheme=INetScheme;
  2138. URLComponents.lpszHostName=lpszHostName;
  2139. URLComponents.dwHostNameLength=INTERNET_MAX_PATH_LENGTH;
  2140. URLComponents.nPort=INetPort;
  2141. URLComponents.lpszUserName=lpszUserName;
  2142. URLComponents.dwUserNameLength=INTERNET_MAX_PATH_LENGTH;
  2143. URLComponents.lpszPassword=lpszPassword;
  2144. URLComponents.dwPasswordLength=INTERNET_MAX_PATH_LENGTH;
  2145. URLComponents.lpszUrlPath=lpszUrlPath;
  2146. URLComponents.dwUrlPathLength=INTERNET_MAX_PATH_LENGTH;
  2147. URLComponents.lpszExtraInfo=lpszExtraInfo;
  2148. URLComponents.dwExtraInfoLength=INTERNET_MAX_PATH_LENGTH;
  2149. pfnInternetCrackUrl=(FN_INTERNETCRACKURL) GetProcAddress(g_hWININET,"InternetCrackUrlA");
  2150. if(pfnInternetCrackUrl==NULL)
  2151. {
  2152. return(PR_EVALUATION_DOESNOTAPPLY);
  2153. }
  2154. pfnInternetCrackUrl(pprurlComparisonURL->Get(),0,ICU_DECODE,&URLComponents);
  2155. for(iCounter=0;iCounter<m_arrpPRByURL.Length();iCounter++)
  2156. {
  2157. PICSRulesByURLExpression * pPRByURLExpression;
  2158. pPRByURLExpression=m_arrpPRByURL[iCounter];
  2159. //schemes must be specified as per the spec, so there is no need to check
  2160. //the m_bSpecified flag against BYURL_SCHEME
  2161. //if the scheme is non-wild then we match against exact strings only, the
  2162. //match is case insensitive as per the spec
  2163. if(pPRByURLExpression->m_bNonWild&BYURL_SCHEME)
  2164. {
  2165. if(lstrcmp(lpszScheme,pPRByURLExpression->m_etstrScheme.Get())!=0)
  2166. {
  2167. continue;
  2168. }
  2169. }
  2170. //if the user name is omitted we only match if the url navigated to also
  2171. //had the user name omitted
  2172. if(!(pPRByURLExpression->m_bSpecified&BYURL_USER))
  2173. {
  2174. if(*lpszUserName!=NULL)
  2175. {
  2176. continue;
  2177. }
  2178. }
  2179. else if(pPRByURLExpression->m_bNonWild&BYURL_USER)
  2180. {
  2181. int iLength;
  2182. char * lpszCurrent,lpszCompare[INTERNET_MAX_URL_LENGTH+1],
  2183. lpszCopy[INTERNET_MAX_URL_LENGTH+1];
  2184. BOOL fFrontWild=0,fBackWild=0,fFrontEscaped=0,fBackEscaped=0;
  2185. //if the user was specified we match a '*' at the beginning as wild, a '*'
  2186. //at the end as wild, and '%*' matches aginst the character '*', this
  2187. //comparison is case sensitive
  2188. lstrcpy(lpszCompare,pPRByURLExpression->m_etstrUser.Get());
  2189. iLength=lstrlen(lpszCompare);
  2190. if(lpszCompare[0]=='*')
  2191. {
  2192. fFrontWild=1;
  2193. }
  2194. if(lpszCompare[iLength-1]=='*')
  2195. {
  2196. fBackWild=1;
  2197. lpszCompare[iLength-1]='\0';
  2198. }
  2199. if((lpszCompare[0]=='%')&&(lpszCompare[1]=='*'))
  2200. {
  2201. fFrontEscaped=1;
  2202. }
  2203. if((lpszCompare[iLength-2]=='%')&&fBackWild)
  2204. {
  2205. fBackWild=0;
  2206. fBackEscaped=1;
  2207. lpszCompare[iLength-2]='*';
  2208. }
  2209. lpszCurrent=lpszCompare+fFrontWild+fFrontEscaped;
  2210. lstrcpy(lpszCopy,lpszCurrent);
  2211. if(fFrontWild==1)
  2212. {
  2213. lpszCurrent=strstrf(lpszUserName,lpszCopy);
  2214. if(lpszCurrent!=NULL)
  2215. {
  2216. if(fBackWild==0)
  2217. {
  2218. if(lstrcmp(lpszCurrent,lpszUserName)!=0)
  2219. {
  2220. continue;
  2221. }
  2222. }
  2223. }
  2224. else
  2225. {
  2226. continue;
  2227. }
  2228. }
  2229. else
  2230. {
  2231. if(fBackWild==1)
  2232. {
  2233. lpszUserName[lstrlen(lpszCopy)]='\0';
  2234. }
  2235. if(lstrcmp(lpszUserName,lpszCopy)!=0)
  2236. {
  2237. continue;
  2238. }
  2239. }
  2240. }
  2241. //the host (or ipwild) must always be specified, so there is no need to
  2242. //check against m_bSpecified
  2243. //the host is either an ipwild (i.e. #.#.#.#!#) or a URL substring. If
  2244. //we have an ipwild, then we have to first resolve the site being browsed
  2245. //to to a set of IP addresses. We consider it a match if we match any
  2246. //of those IPs. If the host is an URL substring, then the first character
  2247. //being a '*' matches any number of characters, and being '%*' matches '*'
  2248. //itself. Everything further must match exactly. The compare is case-
  2249. //insensitive.
  2250. if(pPRByURLExpression->m_bNonWild&BYURL_HOST)
  2251. {
  2252. BOOL fFrontWild=0,fWasIpWild=FALSE,fNoneMatched=TRUE;
  2253. DWORD dwIpRules=0;
  2254. char * lpszCurrent;
  2255. lpszCurrent=pPRByURLExpression->m_etstrHost.Get();
  2256. if((lpszCurrent[0]>='0')&&(lpszCurrent[0]<='9'))
  2257. {
  2258. //make a copy of the string since we are going to delete the masking '!'
  2259. //to test for an ipwild
  2260. char * lpszMask;
  2261. char lpszIpWild[INTERNET_MAX_PATH_LENGTH+1];
  2262. int iBitMask=(sizeof(DWORD)*8);
  2263. lstrcpy(lpszIpWild,lpszCurrent);
  2264. lpszMask=strchrf(lpszIpWild,'!');
  2265. if(lpszMask!=NULL)
  2266. {
  2267. *lpszMask='\0';
  2268. lpszMask++;
  2269. ParseNumber(&lpszMask,&iBitMask,TRUE);
  2270. }
  2271. //test for an ipwild case
  2272. dwIpRules = inet_addr(lpszIpWild);
  2273. if(dwIpRules != INADDR_NONE)
  2274. {
  2275. //we definately have an ipwild
  2276. array<DWORD*> arrpIpCompare;
  2277. HOSTENT * pHostEnt;
  2278. int iCounter;
  2279. fWasIpWild=TRUE;
  2280. pHostEnt=gethostbyname(lpszHostName);
  2281. if(pHostEnt!=NULL)
  2282. {
  2283. char *lpszHosts;
  2284. lpszHosts=pHostEnt->h_addr_list[0];
  2285. iCounter=0;
  2286. while(lpszHosts!=NULL)
  2287. {
  2288. DWORD *pdwIP;
  2289. pdwIP=new DWORD;
  2290. *pdwIP=*((DWORD *) lpszHosts);
  2291. arrpIpCompare.Append(pdwIP);
  2292. iCounter++;
  2293. lpszHosts=pHostEnt->h_addr_list[iCounter];
  2294. }
  2295. }
  2296. //we've got all the IPs to test against, so lets do it
  2297. for(iCounter=0;iCounter<arrpIpCompare.Length();iCounter++)
  2298. {
  2299. DWORD dwIpCompare;
  2300. int iBitCounter;
  2301. BOOL fMatched;
  2302. dwIpCompare=*(arrpIpCompare[iCounter]);
  2303. fMatched=TRUE;
  2304. //compare the first iBitMask bits as per the spec
  2305. for(iBitCounter=0;
  2306. iBitCounter<iBitMask;
  2307. iBitCounter++)
  2308. {
  2309. int iPower;
  2310. DWORD dwMask=1;
  2311. for(iPower=0;iPower<iBitCounter;iPower++)
  2312. {
  2313. dwMask*=2;
  2314. }
  2315. if((dwIpRules&dwMask)!=(dwIpCompare&dwMask))
  2316. {
  2317. //they don't match
  2318. fMatched=FALSE;
  2319. break;
  2320. }
  2321. }
  2322. if(fMatched==TRUE)
  2323. {
  2324. fNoneMatched=FALSE;
  2325. break;
  2326. }
  2327. }
  2328. }
  2329. }
  2330. if(fWasIpWild)
  2331. {
  2332. if(fNoneMatched)
  2333. {
  2334. //if none matched, we don't apply, so continue to the next
  2335. //iteration of the loop
  2336. continue;
  2337. }
  2338. }
  2339. else
  2340. {
  2341. if((lpszCurrent[0]=='%')&&(lpszCurrent[1]=='*'))
  2342. {
  2343. lpszCurrent++;
  2344. }
  2345. else if (lpszCurrent[0]=='*')
  2346. {
  2347. fFrontWild=1;
  2348. lpszCurrent++;
  2349. }
  2350. if(fFrontWild==1)
  2351. {
  2352. char * lpszTest;
  2353. lpszTest=strstrf(lpszHostName,lpszCurrent);
  2354. if(lstrcmpi(lpszTest,lpszCurrent)!=0)
  2355. {
  2356. continue;
  2357. }
  2358. }
  2359. else
  2360. {
  2361. if(lstrcmpi(lpszHostName,lpszCurrent)!=0)
  2362. {
  2363. continue;
  2364. }
  2365. }
  2366. }
  2367. }
  2368. //if the port is ommitted, we only match if the port was also ommitted in
  2369. //the URL being browsed to.
  2370. if(!(pPRByURLExpression->m_bSpecified&BYURL_PORT))
  2371. {
  2372. if(URLComponents.nPort!=INTERNET_INVALID_PORT_NUMBER)
  2373. {
  2374. char * lpszCheck;
  2375. //URLComponents.nPort gets filled in anyway due to the scheme, so
  2376. //check it against the string itself
  2377. lpszCheck=strstrf(pprurlComparisonURL->Get(),lpszHostName);
  2378. if(lpszCheck!=NULL)
  2379. {
  2380. lpszCheck+=lstrlen(lpszHostName);
  2381. if(*lpszCheck==':')
  2382. {
  2383. continue;
  2384. }
  2385. }
  2386. }
  2387. }
  2388. else if(pPRByURLExpression->m_bNonWild&BYURL_PORT)
  2389. {
  2390. char * lpszPort,* lpszRange;
  2391. //the port can be a single number or a range, with wild cards at both ends
  2392. //of the range
  2393. lpszPort=pPRByURLExpression->m_etstrPort.Get();
  2394. lpszRange=strchrf(lpszPort,'-');
  2395. if(lpszRange==NULL)
  2396. {
  2397. int iPort;
  2398. //we've got a single port
  2399. ParseNumber(&lpszPort,&iPort,TRUE);
  2400. if(iPort!=URLComponents.nPort)
  2401. {
  2402. continue;
  2403. }
  2404. }
  2405. else
  2406. {
  2407. int iLow,iHigh;
  2408. *lpszRange='\0';
  2409. lpszRange++;
  2410. if(*lpszPort=='*')
  2411. {
  2412. iLow=0;
  2413. }
  2414. else
  2415. {
  2416. ParseNumber(&lpszPort,&iLow,TRUE);
  2417. }
  2418. if(*lpszRange=='*')
  2419. {
  2420. iHigh=INTERNET_MAX_PORT_NUMBER_VALUE;
  2421. }
  2422. else
  2423. {
  2424. ParseNumber(&lpszRange,&iHigh,TRUE);
  2425. }
  2426. if((URLComponents.nPort>iHigh)||URLComponents.nPort<iLow)
  2427. {
  2428. continue;
  2429. }
  2430. }
  2431. }
  2432. //if the path is ommitted, we only match if the path was also ommitted in
  2433. //the URL being browsed to.
  2434. if(!(pPRByURLExpression->m_bSpecified&BYURL_PATH))
  2435. {
  2436. if(*lpszUrlPath!=NULL)
  2437. {
  2438. if(!((*lpszUrlPath=='/')&&(*(lpszUrlPath+1)==NULL)))
  2439. {
  2440. continue;
  2441. }
  2442. }
  2443. }
  2444. else if(pPRByURLExpression->m_bNonWild&BYURL_PATH)
  2445. {
  2446. int iLength;
  2447. char * lpszCurrent,lpszCompare[INTERNET_MAX_URL_LENGTH+1],
  2448. lpszCopy[INTERNET_MAX_URL_LENGTH+1],* lpszUrlCheck,
  2449. * lpszPreCompare;
  2450. BOOL fFrontWild=0,fBackWild=0,fFrontEscaped=0,fBackEscaped=0;
  2451. //if the path was specified we match a '*' at the beginning as wild, a '*'
  2452. //at the end as wild, and '%*' matches aginst the character '*', this
  2453. //comparison is case sensitive
  2454. //kill leading slashes
  2455. if(*lpszUrlPath=='/')
  2456. {
  2457. lpszUrlCheck=lpszUrlPath+1;
  2458. }
  2459. else
  2460. {
  2461. lpszUrlCheck=lpszUrlPath;
  2462. }
  2463. iLength=lstrlen(lpszUrlCheck);
  2464. //kill trailing slashes
  2465. if(lpszUrlCheck[iLength-1]=='/')
  2466. {
  2467. lpszUrlCheck[iLength-1]='\0';
  2468. }
  2469. lpszPreCompare=pPRByURLExpression->m_etstrPath.Get();
  2470. //kill leading slashes
  2471. if(*lpszPreCompare=='/')
  2472. {
  2473. lstrcpy(lpszCompare,lpszPreCompare+1);
  2474. }
  2475. else
  2476. {
  2477. lstrcpy(lpszCompare,lpszPreCompare);
  2478. }
  2479. iLength=lstrlen(lpszCompare);
  2480. //kill trailing slashes
  2481. if(lpszCompare[iLength-1]=='/')
  2482. {
  2483. lpszCompare[iLength-1]='\0';
  2484. }
  2485. if(lpszCompare[0]=='*')
  2486. {
  2487. fFrontWild=1;
  2488. }
  2489. if(lpszCompare[iLength-1]=='*')
  2490. {
  2491. fBackWild=1;
  2492. lpszCompare[iLength-1]='\0';
  2493. }
  2494. if((lpszCompare[0]=='%')&&(lpszCompare[1]=='*'))
  2495. {
  2496. fFrontEscaped=1;
  2497. }
  2498. if((lpszCompare[iLength-2]=='%')&&fBackWild)
  2499. {
  2500. fBackWild=0;
  2501. fBackEscaped=1;
  2502. lpszCompare[iLength-2]='*';
  2503. }
  2504. lpszCurrent=lpszCompare+fFrontWild+fFrontEscaped;
  2505. lstrcpy(lpszCopy,lpszCurrent);
  2506. if(fFrontWild==1)
  2507. {
  2508. lpszCurrent=strstrf(lpszUrlCheck,lpszCopy);
  2509. if(lpszCurrent!=NULL)
  2510. {
  2511. if(fBackWild==0)
  2512. {
  2513. if(lstrcmp(lpszCurrent,lpszUrlCheck)!=0)
  2514. {
  2515. continue;
  2516. }
  2517. }
  2518. }
  2519. else
  2520. {
  2521. continue;
  2522. }
  2523. }
  2524. else
  2525. {
  2526. if(fBackWild==1)
  2527. {
  2528. lpszUrlCheck[lstrlen(lpszCopy)]='\0';
  2529. }
  2530. if(lstrcmp(lpszUrlCheck,lpszCopy)!=0)
  2531. {
  2532. continue;
  2533. }
  2534. }
  2535. }
  2536. //if we made it this far we do apply!
  2537. fApplies=TRUE;
  2538. break;
  2539. }
  2540. delete lpszScheme;
  2541. lpszScheme = NULL;
  2542. delete lpszHostName;
  2543. lpszHostName = NULL;
  2544. delete lpszUserName;
  2545. lpszUserName = NULL;
  2546. delete lpszPassword;
  2547. lpszPassword = NULL;
  2548. delete lpszUrlPath;
  2549. lpszUrlPath = NULL;
  2550. delete lpszExtraInfo;
  2551. lpszExtraInfo = NULL;
  2552. if(fApplies==TRUE)
  2553. {
  2554. return(PR_EVALUATION_DOESAPPLY);
  2555. }
  2556. else
  2557. {
  2558. return(PR_EVALUATION_DOESNOTAPPLY);
  2559. }
  2560. }
  2561. //*******************************************************************
  2562. //*
  2563. //* Code for the PICSRulesFileParser class
  2564. //*
  2565. //*******************************************************************
  2566. //FindNonWhite returns a pointer to the first non-whitespace
  2567. //character starting at pc.
  2568. char* PICSRulesFileParser::FindNonWhite(char *pc)
  2569. {
  2570. ASSERT(pc);
  2571. while (1)
  2572. {
  2573. if (*pc != ' ' &&
  2574. *pc != '\t' &&
  2575. *pc != '\r' &&
  2576. *pc != '\n') /* includes null terminator */
  2577. {
  2578. return pc;
  2579. }
  2580. if (*pc == '\n')
  2581. m_nLine++;
  2582. pc++;
  2583. }
  2584. }
  2585. //Returns a pointer to the closing quotation mark of a quoted
  2586. //string, counting linefeeds as we go. Returns NULL if no closing
  2587. //quotation mark is found.
  2588. //
  2589. //fQuote can be either PR_QUOTE_DOUBLE or PR_QUOTE_SINGLE
  2590. //defaults to PR_QUOTE_DOUBLE.
  2591. LPSTR PICSRulesFileParser::EatQuotedString(LPSTR pIn,BOOL fQuote)
  2592. {
  2593. LPSTR pszQuote;
  2594. if(fQuote==PR_QUOTE_DOUBLE)
  2595. {
  2596. pszQuote=strchrf(pIn,'\"');
  2597. }
  2598. else
  2599. {
  2600. pszQuote=strchrf(pIn,'\'');
  2601. }
  2602. if (pszQuote == NULL)
  2603. {
  2604. return NULL;
  2605. }
  2606. pIn=strchrf(pIn,'\n');
  2607. while ((pIn!=NULL)&&(pIn<pszQuote))
  2608. {
  2609. m_nLine++;
  2610. pIn=strchrf(pIn+1,'\n');
  2611. }
  2612. return pszQuote;
  2613. }
  2614. //ParseToOpening eats the opening '(' of a parenthesized object, and
  2615. //verifies that the token just inside it is one of the expected ones.
  2616. //If so, *ppIn is advanced past that token to the next non-whitespace
  2617. //character; otherwise, an error is returned.
  2618. //
  2619. //For example, if *ppIn is pointing at "(PicsRule-1.1)", and
  2620. //PROID_PICSVERSION is in the allowable option table supplied, then
  2621. //NOERROR is returned and *ppIn will point at "1.1)".
  2622. //
  2623. //If the function is successful, *ppFound is set to point to the element
  2624. //in the allowable-options table which matches the type of thing this
  2625. //object actually is.
  2626. HRESULT PICSRulesFileParser::ParseToOpening(LPSTR *ppIn,
  2627. PICSRulesAllowableOption *paoExpected,
  2628. PICSRulesAllowableOption **ppFound)
  2629. {
  2630. LPSTR lpszCurrent=*ppIn;
  2631. lpszCurrent=FindNonWhite(lpszCurrent);
  2632. if(*lpszCurrent=='(')
  2633. {
  2634. lpszCurrent=FindNonWhite(lpszCurrent+1); //skip ( and whitespace
  2635. }
  2636. if((*lpszCurrent=='\"')||(*lpszCurrent=='\''))
  2637. {
  2638. //we found a default option section, treat it as a string and return
  2639. //ppFound set to PROID_NAMEDEFAULT
  2640. paoExpected->roid=PROID_NAMEDEFAULT;
  2641. *ppFound=paoExpected;
  2642. *ppIn=lpszCurrent;
  2643. return NOERROR;
  2644. }
  2645. LPSTR lpszTokenEnd=FindTokenEnd(lpszCurrent);
  2646. for(;paoExpected->roid!=PROID_INVALID;paoExpected++)
  2647. {
  2648. LPCSTR lpszThisToken=aPRObjectDescriptions[paoExpected->roid].lpszToken;
  2649. if(paoExpected->roid==PROID_EXTENSION)
  2650. {
  2651. LPTSTR lpszDot;
  2652. lpszDot=strchrf(lpszCurrent,'.');
  2653. if(lpszDot!=NULL)
  2654. {
  2655. *lpszDot='\0';
  2656. if(IsOptExtensionDefined(lpszCurrent)==TRUE)
  2657. {
  2658. *lpszDot='.';
  2659. lpszTokenEnd=lpszCurrent;
  2660. break;
  2661. }
  2662. if(IsReqExtensionDefined(lpszCurrent)==TRUE)
  2663. {
  2664. //currently no extensions are supported so we return
  2665. //an error on a required extension.
  2666. //if support for extensions is implemented
  2667. //this should be identical to above with a different
  2668. //callback for reqextensions defined.
  2669. return(PICSRULES_E_REQEXTENSIONUSED);
  2670. }
  2671. }
  2672. }
  2673. if(IsEqualToken(lpszCurrent,lpszTokenEnd,lpszThisToken))
  2674. {
  2675. break;
  2676. }
  2677. }
  2678. if(paoExpected->roid!=PROID_INVALID)
  2679. {
  2680. *ppIn=FindNonWhite(lpszTokenEnd); //skip token and whitespace
  2681. *ppFound=paoExpected;
  2682. return NOERROR;
  2683. }
  2684. else
  2685. {
  2686. return PICSRULES_E_UNKNOWNITEM;
  2687. }
  2688. }
  2689. //ParseParenthesizedObjectContents is called with a text pointer pointing at
  2690. //the first non-whitespace thing following the token identifying the type of
  2691. //object. It parses the rest of the contents of the object, up to and
  2692. //including the ')' which closes it. The array of PICSRulesAllowableOption
  2693. //structures specifies which understood options are allowed to occur within
  2694. //this object.
  2695. HRESULT PICSRulesFileParser::ParseParenthesizedObject(LPSTR *ppIn,
  2696. PICSRulesAllowableOption aao[],
  2697. PICSRulesObjectBase *pObject)
  2698. {
  2699. PICSRulesAllowableOption *pFound;
  2700. HRESULT hres=S_OK;
  2701. LPSTR pszCurrent=*ppIn;
  2702. for(pFound=aao;pFound->roid!=PROID_INVALID;pFound++)
  2703. {
  2704. pFound->fdwOptions&=~AO_SEEN;
  2705. }
  2706. pFound=NULL;
  2707. while((*pszCurrent!=')')&&(*pszCurrent!='\0')&&(SUCCEEDED(hres)))
  2708. {
  2709. hres=ParseToOpening(&pszCurrent,aao,&pFound);
  2710. if(SUCCEEDED(hres))
  2711. {
  2712. LPVOID pData;
  2713. hres=(*(aPRObjectDescriptions[pFound->roid].pHandler))(&pszCurrent,&pData,this);
  2714. if(SUCCEEDED(hres))
  2715. {
  2716. if((pFound->fdwOptions&(AO_SINGLE|AO_SEEN))==(AO_SINGLE|AO_SEEN))
  2717. {
  2718. hres=PICSRULES_E_DUPLICATEITEM;
  2719. }
  2720. else
  2721. {
  2722. pFound->fdwOptions|=AO_SEEN;
  2723. hres=pObject->AddItem(pFound->roid,pData);
  2724. if(SUCCEEDED(hres))
  2725. {
  2726. pszCurrent=FindNonWhite(pszCurrent);
  2727. }
  2728. }
  2729. }
  2730. }
  2731. }
  2732. if(FAILED(hres))
  2733. {
  2734. return hres;
  2735. }
  2736. for(pFound=aao;pFound->roid!=PROID_INVALID;pFound++)
  2737. {
  2738. if((pFound->fdwOptions&(AO_MANDATORY|AO_SEEN))==AO_MANDATORY)
  2739. {
  2740. return(PICSRULES_E_MISSINGITEM); //mandatory item not found
  2741. }
  2742. }
  2743. pszCurrent=FindNonWhite(pszCurrent+1); //skip the closing parenthesis
  2744. *ppIn=pszCurrent;
  2745. return(hres);
  2746. }
  2747. //*******************************************************************
  2748. //*
  2749. //* Code for the PICSRulesName class
  2750. //*
  2751. //*******************************************************************
  2752. PICSRulesName::PICSRulesName()
  2753. {
  2754. //just need to construct members
  2755. }
  2756. PICSRulesName::~PICSRulesName()
  2757. {
  2758. //nothing to do
  2759. }
  2760. HRESULT PICSRulesName::AddItem(PICSRulesObjectID proid, LPVOID pData)
  2761. {
  2762. HRESULT hRes = S_OK;
  2763. switch (proid)
  2764. {
  2765. case PROID_NAMEDEFAULT:
  2766. case PROID_RULENAME:
  2767. {
  2768. m_etstrRuleName.SetTo((char *) pData);
  2769. break;
  2770. }
  2771. case PROID_DESCRIPTION:
  2772. {
  2773. m_etstrDescription.SetTo((char *) pData);
  2774. break;
  2775. }
  2776. case PROID_EXTENSION:
  2777. {
  2778. //just eat extensions
  2779. break;
  2780. }
  2781. case PROID_INVALID:
  2782. default:
  2783. {
  2784. ASSERT(FALSE); // shouldn't have been given a PROID that wasn't in
  2785. // the table we passed to the parser!
  2786. hRes=E_UNEXPECTED;
  2787. break;
  2788. }
  2789. }
  2790. return hRes;
  2791. }
  2792. HRESULT PICSRulesName::InitializeMyDefaults()
  2793. {
  2794. //no defaults to initialize
  2795. return(NOERROR);
  2796. }
  2797. //*******************************************************************
  2798. //*
  2799. //* Code for the PICSRulesOptExtension class
  2800. //*
  2801. //*******************************************************************
  2802. PICSRulesOptExtension::PICSRulesOptExtension()
  2803. {
  2804. //nothing to do
  2805. }
  2806. PICSRulesOptExtension::~PICSRulesOptExtension()
  2807. {
  2808. //nothing to do
  2809. }
  2810. HRESULT PICSRulesOptExtension::AddItem(PICSRulesObjectID proid, LPVOID pData)
  2811. {
  2812. HRESULT hRes = S_OK;
  2813. switch (proid)
  2814. {
  2815. case PROID_NAMEDEFAULT:
  2816. case PROID_EXTENSIONNAME:
  2817. {
  2818. m_prURLExtensionName.SetTo((char *) pData);
  2819. if(m_prURLExtensionName.IsURLValid()==FALSE)
  2820. {
  2821. hRes=E_INVALIDARG;
  2822. }
  2823. break;
  2824. }
  2825. case PROID_SHORTNAME:
  2826. {
  2827. m_etstrShortName.SetTo((char *) pData);
  2828. break;
  2829. }
  2830. case PROID_EXTENSION:
  2831. {
  2832. //just eat extensions
  2833. break;
  2834. }
  2835. case PROID_INVALID:
  2836. default:
  2837. {
  2838. ASSERT(FALSE); // shouldn't have been given a PROID that wasn't in
  2839. // the table we passed to the parser!
  2840. hRes=E_UNEXPECTED;
  2841. break;
  2842. }
  2843. }
  2844. return hRes;
  2845. }
  2846. HRESULT PICSRulesOptExtension::InitializeMyDefaults()
  2847. {
  2848. //no defaults to initialize
  2849. return(NOERROR);
  2850. }
  2851. //*******************************************************************
  2852. //*
  2853. //* Code for the PICSRulesPassFail class
  2854. //*
  2855. //*******************************************************************
  2856. PICSRulesPassFail::PICSRulesPassFail()
  2857. {
  2858. m_fPassOrFail=PR_PASSFAIL_PASS;
  2859. }
  2860. PICSRulesPassFail::~PICSRulesPassFail()
  2861. {
  2862. //nothing to do
  2863. }
  2864. void PICSRulesPassFail::Set(const BOOL *pIn)
  2865. {
  2866. switch(*pIn)
  2867. {
  2868. case PR_PASSFAIL_PASS:
  2869. {
  2870. ETS::Set(szPRPass);
  2871. m_fPassOrFail=PR_PASSFAIL_PASS;
  2872. break;
  2873. }
  2874. case PR_PASSFAIL_FAIL:
  2875. {
  2876. ETS::Set(szPRFail);
  2877. m_fPassOrFail=PR_PASSFAIL_FAIL;
  2878. break;
  2879. }
  2880. }
  2881. }
  2882. void PICSRulesPassFail::SetTo(BOOL *pIn)
  2883. {
  2884. Set(pIn);
  2885. }
  2886. //*******************************************************************
  2887. //*
  2888. //* Code for the PICSRulesPolicy class
  2889. //*
  2890. //*******************************************************************
  2891. PICSRulesPolicy::PICSRulesPolicy()
  2892. {
  2893. m_PRPolicyAttribute=PR_POLICY_NONEVALID;
  2894. }
  2895. PICSRulesPolicy::~PICSRulesPolicy()
  2896. {
  2897. switch(m_PRPolicyAttribute)
  2898. {
  2899. case PR_POLICY_REJECTBYURL:
  2900. {
  2901. if(m_pPRRejectByURL!=NULL)
  2902. {
  2903. delete m_pPRRejectByURL;
  2904. m_pPRRejectByURL = NULL;
  2905. }
  2906. break;
  2907. }
  2908. case PR_POLICY_ACCEPTBYURL:
  2909. {
  2910. if(m_pPRAcceptByURL!=NULL)
  2911. {
  2912. delete m_pPRAcceptByURL;
  2913. m_pPRAcceptByURL = NULL;
  2914. }
  2915. break;
  2916. }
  2917. case PR_POLICY_REJECTIF:
  2918. {
  2919. if(m_pPRRejectIf!=NULL)
  2920. {
  2921. delete m_pPRRejectIf;
  2922. m_pPRRejectIf = NULL;
  2923. }
  2924. break;
  2925. }
  2926. case PR_POLICY_ACCEPTIF:
  2927. {
  2928. if(m_pPRAcceptIf!=NULL)
  2929. {
  2930. delete m_pPRAcceptIf;
  2931. m_pPRAcceptIf = NULL;
  2932. }
  2933. break;
  2934. }
  2935. case PR_POLICY_REJECTUNLESS:
  2936. {
  2937. if(m_pPRRejectUnless!=NULL)
  2938. {
  2939. delete m_pPRRejectUnless;
  2940. m_pPRRejectUnless = NULL;
  2941. }
  2942. break;
  2943. }
  2944. case PR_POLICY_ACCEPTUNLESS:
  2945. {
  2946. if(m_pPRAcceptUnless!=NULL)
  2947. {
  2948. delete m_pPRAcceptUnless;
  2949. m_pPRAcceptUnless = NULL;
  2950. }
  2951. break;
  2952. }
  2953. case PR_POLICY_NONEVALID:
  2954. default:
  2955. {
  2956. break;
  2957. }
  2958. }
  2959. }
  2960. HRESULT PICSRulesPolicy::AddItem(PICSRulesObjectID proid, LPVOID pData)
  2961. {
  2962. HRESULT hRes = S_OK;
  2963. switch (proid)
  2964. {
  2965. case PROID_NAMEDEFAULT:
  2966. case PROID_EXPLANATION:
  2967. {
  2968. m_etstrExplanation.SetTo((char *) pData);
  2969. break;
  2970. }
  2971. case PROID_REJECTBYURL:
  2972. {
  2973. m_pPRRejectByURL=((PICSRulesByURL *) pData);
  2974. m_PRPolicyAttribute=PR_POLICY_REJECTBYURL;
  2975. break;
  2976. }
  2977. case PROID_ACCEPTBYURL:
  2978. {
  2979. m_pPRAcceptByURL=((PICSRulesByURL *) pData);
  2980. m_PRPolicyAttribute=PR_POLICY_ACCEPTBYURL;
  2981. break;
  2982. }
  2983. case PROID_REJECTIF:
  2984. {
  2985. m_pPRRejectIf=((PICSRulesPolicyExpression *) pData);
  2986. m_PRPolicyAttribute=PR_POLICY_REJECTIF;
  2987. break;
  2988. }
  2989. case PROID_ACCEPTIF:
  2990. {
  2991. m_pPRAcceptIf=((PICSRulesPolicyExpression *) pData);
  2992. m_PRPolicyAttribute=PR_POLICY_ACCEPTIF;
  2993. break;
  2994. }
  2995. case PROID_REJECTUNLESS:
  2996. {
  2997. m_pPRRejectUnless=((PICSRulesPolicyExpression *) pData);
  2998. m_PRPolicyAttribute=PR_POLICY_REJECTUNLESS;
  2999. break;
  3000. }
  3001. case PROID_ACCEPTUNLESS:
  3002. {
  3003. m_pPRAcceptUnless=((PICSRulesPolicyExpression *) pData);
  3004. m_PRPolicyAttribute=PR_POLICY_ACCEPTUNLESS;
  3005. break;
  3006. }
  3007. case PROID_EXTENSION:
  3008. {
  3009. //just eat extensions
  3010. break;
  3011. }
  3012. case PROID_INVALID:
  3013. default:
  3014. {
  3015. ASSERT(FALSE); // shouldn't have been given a PROID that wasn't in
  3016. // the table we passed to the parser!
  3017. hRes=E_UNEXPECTED;
  3018. break;
  3019. }
  3020. }
  3021. return hRes;
  3022. }
  3023. HRESULT PICSRulesPolicy::InitializeMyDefaults()
  3024. {
  3025. return(NOERROR); //no defaults to initialize
  3026. }
  3027. //*******************************************************************
  3028. //*
  3029. //* Code for the PICSRulesPolicyExpression class
  3030. //*
  3031. //*******************************************************************
  3032. PICSRulesPolicyExpression::PICSRulesPolicyExpression()
  3033. {
  3034. m_PRPEPolicyEmbedded= PR_POLICYEMBEDDED_NONE;
  3035. m_PROPolicyOperator= PR_OPERATOR_INVALID;
  3036. m_pPRPolicyExpressionLeft= NULL;
  3037. m_pPRPolicyExpressionRight= NULL;
  3038. }
  3039. PICSRulesPolicyExpression::~PICSRulesPolicyExpression()
  3040. {
  3041. if(m_PRPEPolicyEmbedded!=PR_POLICYEMBEDDED_NONE) //do we need to delete an
  3042. //embedded PolicyExpression?
  3043. {
  3044. if(m_pPRPolicyExpressionLeft!=NULL) //double check, just to make sure
  3045. {
  3046. delete m_pPRPolicyExpressionLeft;
  3047. m_pPRPolicyExpressionLeft = NULL;
  3048. }
  3049. if(m_pPRPolicyExpressionRight!=NULL) //double check, just to make sure
  3050. {
  3051. delete m_pPRPolicyExpressionRight;
  3052. m_pPRPolicyExpressionRight = NULL;
  3053. }
  3054. }
  3055. }
  3056. PICSRulesEvaluation PICSRulesPolicyExpression::EvaluateRule(CParsedLabelList *pParsed)
  3057. {
  3058. PICSRulesEvaluation PREvaluationResult;
  3059. if((pParsed==NULL)||(m_PROPolicyOperator==PR_OPERATOR_DEGENERATE))
  3060. {
  3061. //we can't apply if there is no label, and we
  3062. //don't handle the degenerate case since we have
  3063. //to pass on to the PICS handler
  3064. return(PR_EVALUATION_DOESNOTAPPLY);
  3065. }
  3066. if((m_prYesNoUseEmbedded.GetYesNo()==PR_YESNO_NO)&&(g_dwDataSource==PICS_LABEL_FROM_PAGE))
  3067. {
  3068. return(PR_EVALUATION_DOESNOTAPPLY);
  3069. }
  3070. switch(m_PRPEPolicyEmbedded)
  3071. {
  3072. case PR_POLICYEMBEDDED_NONE:
  3073. {
  3074. switch(m_PROPolicyOperator)
  3075. {
  3076. case PR_OPERATOR_GREATEROREQUAL:
  3077. case PR_OPERATOR_GREATER:
  3078. case PR_OPERATOR_EQUAL:
  3079. case PR_OPERATOR_LESSOREQUAL:
  3080. case PR_OPERATOR_LESS:
  3081. {
  3082. LPCSTR lpszTest;
  3083. CParsedServiceInfo * pCParsedServiceInfo;
  3084. CParsedRating * pCParsedRating;
  3085. PREvaluationResult=PR_EVALUATION_DOESNOTAPPLY;
  3086. pCParsedServiceInfo=&(pParsed->m_ServiceInfo);
  3087. do
  3088. {
  3089. lpszTest=pCParsedServiceInfo->m_pszServiceName;
  3090. if(lstrcmp(lpszTest,m_etstrFullServiceName.Get())==0)
  3091. {
  3092. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3093. break;
  3094. }
  3095. pCParsedServiceInfo=pCParsedServiceInfo->Next();
  3096. } while (pCParsedServiceInfo!=NULL);
  3097. if(PREvaluationResult==PR_EVALUATION_DOESAPPLY)
  3098. {
  3099. int iCounter;
  3100. PREvaluationResult=PR_EVALUATION_DOESNOTAPPLY;
  3101. //we've got the service, now check for the category
  3102. for(iCounter=0;iCounter<pCParsedServiceInfo->aRatings.Length();iCounter++)
  3103. {
  3104. pCParsedRating=&(pCParsedServiceInfo->aRatings[iCounter]);
  3105. if(lstrcmp(pCParsedRating->pszTransmitName,m_etstrCategoryName.Get())==0)
  3106. {
  3107. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3108. break;
  3109. }
  3110. }
  3111. }
  3112. if(PREvaluationResult==PR_EVALUATION_DOESAPPLY)
  3113. {
  3114. int iLabelValue;
  3115. iLabelValue=pCParsedRating->nValue;
  3116. //now check the values
  3117. PREvaluationResult=PR_EVALUATION_DOESNOTAPPLY;
  3118. switch(m_PROPolicyOperator)
  3119. {
  3120. case PR_OPERATOR_GREATEROREQUAL:
  3121. {
  3122. if(iLabelValue>=m_etnValue.Get())
  3123. {
  3124. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3125. }
  3126. break;
  3127. }
  3128. case PR_OPERATOR_GREATER:
  3129. {
  3130. if(iLabelValue>m_etnValue.Get())
  3131. {
  3132. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3133. }
  3134. break;
  3135. }
  3136. case PR_OPERATOR_EQUAL:
  3137. {
  3138. if(iLabelValue==m_etnValue.Get())
  3139. {
  3140. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3141. }
  3142. break;
  3143. }
  3144. case PR_OPERATOR_LESSOREQUAL:
  3145. {
  3146. if(iLabelValue<=m_etnValue.Get())
  3147. {
  3148. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3149. }
  3150. break;
  3151. }
  3152. case PR_OPERATOR_LESS:
  3153. {
  3154. if(iLabelValue<m_etnValue.Get())
  3155. {
  3156. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3157. }
  3158. break;
  3159. }
  3160. }
  3161. }
  3162. break;
  3163. }
  3164. case PR_OPERATOR_SERVICEONLY:
  3165. {
  3166. LPCSTR lpszTest;
  3167. CParsedServiceInfo * pCParsedServiceInfo;
  3168. PREvaluationResult=PR_EVALUATION_DOESNOTAPPLY;
  3169. pCParsedServiceInfo=&(pParsed->m_ServiceInfo);
  3170. do
  3171. {
  3172. lpszTest=pCParsedServiceInfo->m_pszServiceName;
  3173. if(lstrcmp(lpszTest,m_etstrFullServiceName.Get())==0)
  3174. {
  3175. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3176. break;
  3177. }
  3178. pCParsedServiceInfo=pCParsedServiceInfo->Next();
  3179. } while (pCParsedServiceInfo!=NULL);
  3180. break;
  3181. }
  3182. case PR_OPERATOR_SERVICEANDCATEGORY:
  3183. {
  3184. LPCSTR lpszTest;
  3185. CParsedServiceInfo * pCParsedServiceInfo;
  3186. PREvaluationResult=PR_EVALUATION_DOESNOTAPPLY;
  3187. pCParsedServiceInfo=&(pParsed->m_ServiceInfo);
  3188. do
  3189. {
  3190. lpszTest=pCParsedServiceInfo->m_pszServiceName;
  3191. if(lstrcmp(lpszTest,m_etstrFullServiceName.Get())==0)
  3192. {
  3193. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3194. break;
  3195. }
  3196. pCParsedServiceInfo=pCParsedServiceInfo->Next();
  3197. } while (pCParsedServiceInfo!=NULL);
  3198. if(PREvaluationResult==PR_EVALUATION_DOESAPPLY)
  3199. {
  3200. int iCounter;
  3201. PREvaluationResult=PR_EVALUATION_DOESNOTAPPLY;
  3202. //we've got the service, now check for the category
  3203. for(iCounter=0;iCounter<pCParsedServiceInfo->aRatings.Length();iCounter++)
  3204. {
  3205. CParsedRating * pCParsedRating;
  3206. pCParsedRating=&(pCParsedServiceInfo->aRatings[iCounter]);
  3207. if(lstrcmp(pCParsedRating->pszTransmitName,m_etstrCategoryName.Get())==0)
  3208. {
  3209. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3210. break;
  3211. }
  3212. }
  3213. }
  3214. break;
  3215. }
  3216. }
  3217. break;
  3218. }
  3219. case PR_POLICYEMBEDDED_OR:
  3220. {
  3221. PICSRulesEvaluation PREvaluationIntermediate;
  3222. PREvaluationIntermediate=m_pPRPolicyExpressionLeft->EvaluateRule(pParsed);
  3223. if(PREvaluationIntermediate==PR_EVALUATION_DOESAPPLY)
  3224. {
  3225. PREvaluationResult=PR_EVALUATION_DOESAPPLY;
  3226. break;
  3227. }
  3228. else
  3229. {
  3230. PREvaluationResult=m_pPRPolicyExpressionRight->EvaluateRule(pParsed);
  3231. }
  3232. break;
  3233. }
  3234. case PR_POLICYEMBEDDED_AND:
  3235. {
  3236. PICSRulesEvaluation PREvaluationIntermediate;
  3237. PREvaluationIntermediate=m_pPRPolicyExpressionLeft->EvaluateRule(pParsed);
  3238. PREvaluationResult=m_pPRPolicyExpressionRight->EvaluateRule(pParsed);
  3239. if((PREvaluationIntermediate==PR_EVALUATION_DOESAPPLY)&&
  3240. (PREvaluationResult==PR_EVALUATION_DOESAPPLY))
  3241. {
  3242. break;
  3243. }
  3244. else
  3245. {
  3246. PREvaluationResult=PR_EVALUATION_DOESNOTAPPLY;
  3247. }
  3248. break;
  3249. }
  3250. }
  3251. return(PREvaluationResult);
  3252. }
  3253. //*******************************************************************
  3254. //*
  3255. //* Code for the PICSRulesQuotedDate class
  3256. //*
  3257. //*******************************************************************
  3258. PICSRulesQuotedDate::PICSRulesQuotedDate()
  3259. {
  3260. m_dwDate=0;
  3261. }
  3262. PICSRulesQuotedDate::~PICSRulesQuotedDate()
  3263. {
  3264. //nothing to do
  3265. }
  3266. HRESULT PICSRulesQuotedDate::Set(const char *pIn)
  3267. {
  3268. HRESULT hRes;
  3269. DWORD dwDate;
  3270. hRes=ParseTime((char *) pIn,&dwDate);
  3271. if(FAILED(hRes))
  3272. {
  3273. return(E_INVALIDARG);
  3274. }
  3275. m_dwDate=dwDate;
  3276. ETS::Set(pIn);
  3277. return(S_OK);
  3278. }
  3279. HRESULT PICSRulesQuotedDate::SetTo(char *pIn)
  3280. {
  3281. HRESULT hRes;
  3282. DWORD dwDate;
  3283. hRes=ParseTime(pIn,&dwDate,TRUE);
  3284. if(FAILED(hRes))
  3285. {
  3286. return(E_INVALIDARG);
  3287. }
  3288. m_dwDate=dwDate;
  3289. ETS::SetTo(pIn);
  3290. return(S_OK);
  3291. }
  3292. BOOL PICSRulesQuotedDate::IsDateValid()
  3293. {
  3294. if(m_dwDate)
  3295. {
  3296. return(TRUE);
  3297. }
  3298. else
  3299. {
  3300. return(FALSE);
  3301. }
  3302. }
  3303. BOOL PICSRulesQuotedDate::IsDateValid(char * lpszDate)
  3304. {
  3305. HRESULT hRes;
  3306. DWORD dwDate;
  3307. hRes=ParseTime(lpszDate,&dwDate);
  3308. if(SUCCEEDED(hRes))
  3309. {
  3310. return(TRUE);
  3311. }
  3312. else
  3313. {
  3314. return(FALSE);
  3315. }
  3316. }
  3317. BOOL PICSRulesQuotedDate::IsDateValid(ETS etstrDate)
  3318. {
  3319. HRESULT hRes;
  3320. DWORD dwDate;
  3321. LPTSTR lpszDate;
  3322. lpszDate=etstrDate.Get();
  3323. hRes=ParseTime(lpszDate,&dwDate);
  3324. if(SUCCEEDED(hRes))
  3325. {
  3326. return(TRUE);
  3327. }
  3328. else
  3329. {
  3330. return(FALSE);
  3331. }
  3332. }
  3333. //*******************************************************************
  3334. //*
  3335. //* Code for the PICSRulesQuotedEmail class
  3336. //*
  3337. //*******************************************************************
  3338. PICSRulesQuotedEmail::PICSRulesQuotedEmail()
  3339. {
  3340. //nothing to do
  3341. }
  3342. PICSRulesQuotedEmail::~PICSRulesQuotedEmail()
  3343. {
  3344. //nothing to do
  3345. }
  3346. BOOL PICSRulesQuotedEmail::IsEmailValid()
  3347. {
  3348. //We don't use this internally, so as far as we are concerned
  3349. //its always valid.
  3350. //If we ever add UI that displays this, we can defer verification
  3351. //of the email address to the mail client by sticking a mailto://
  3352. //in front of our string
  3353. return(TRUE);
  3354. }
  3355. BOOL PICSRulesQuotedEmail::IsEmailValid(char * lpszEmail)
  3356. {
  3357. //We don't use this internally, so as far as we are concerned
  3358. //its always valid.
  3359. //If we ever add UI that displays this, we can defer verification
  3360. //of the email address to the mail client by sticking a mailto://
  3361. //in front of our string
  3362. return(TRUE);
  3363. }
  3364. BOOL PICSRulesQuotedEmail::IsEmailValid(ETS etstrEmail)
  3365. {
  3366. //We don't use this internally, so as far as we are concerned
  3367. //its always valid.
  3368. //If we ever add UI that displays this, we can defer verification
  3369. //of the email address to the mail client by sticking a mailto://
  3370. //in front of our string
  3371. return(TRUE);
  3372. }
  3373. //*******************************************************************
  3374. //*
  3375. //* Code for the PICSRulesQuotedURL class
  3376. //*
  3377. //*******************************************************************
  3378. PICSRulesQuotedURL::PICSRulesQuotedURL()
  3379. {
  3380. //nothing to do
  3381. }
  3382. PICSRulesQuotedURL::~PICSRulesQuotedURL()
  3383. {
  3384. //nothing to do
  3385. }
  3386. BOOL IsURLValid(WCHAR wcszURL[INTERNET_MAX_URL_LENGTH])
  3387. {
  3388. FN_ISVALIDURL pfnIsValidURL;
  3389. pfnIsValidURL=(FN_ISVALIDURL) GetProcAddress(g_hURLMON,"IsValidURL");
  3390. if(pfnIsValidURL==NULL)
  3391. {
  3392. return(FALSE);
  3393. }
  3394. if(pfnIsValidURL(NULL,wcszURL,0)==S_OK)
  3395. {
  3396. return(TRUE);
  3397. }
  3398. else
  3399. {
  3400. return(FALSE);
  3401. }
  3402. }
  3403. BOOL PICSRulesQuotedURL::IsURLValid()
  3404. {
  3405. char * lpszURL;
  3406. WCHAR wcszURL[INTERNET_MAX_URL_LENGTH];
  3407. lpszURL=Get();
  3408. MultiByteToWideChar(CP_OEMCP,MB_PRECOMPOSED,lpszURL,-1,wcszURL,INTERNET_MAX_URL_LENGTH);
  3409. return(::IsURLValid(wcszURL));
  3410. }
  3411. BOOL PICSRulesQuotedURL::IsURLValid(char * lpszURL)
  3412. {
  3413. WCHAR wcszURL[INTERNET_MAX_URL_LENGTH];
  3414. MultiByteToWideChar(CP_OEMCP,MB_PRECOMPOSED,lpszURL,-1,wcszURL,INTERNET_MAX_URL_LENGTH);
  3415. return(::IsURLValid(wcszURL));
  3416. }
  3417. BOOL PICSRulesQuotedURL::IsURLValid(ETS etstrURL)
  3418. {
  3419. char * lpszURL;
  3420. WCHAR wcszURL[INTERNET_MAX_URL_LENGTH];
  3421. lpszURL=etstrURL.Get();
  3422. MultiByteToWideChar(CP_OEMCP,MB_PRECOMPOSED,lpszURL,-1,wcszURL,INTERNET_MAX_URL_LENGTH);
  3423. return(::IsURLValid(wcszURL));
  3424. }
  3425. //*******************************************************************
  3426. //*
  3427. //* Code for the PICSRulesReqExtension class
  3428. //*
  3429. //*******************************************************************
  3430. PICSRulesReqExtension::PICSRulesReqExtension()
  3431. {
  3432. //nothing to do
  3433. }
  3434. PICSRulesReqExtension::~PICSRulesReqExtension()
  3435. {
  3436. //nothing to do
  3437. }
  3438. HRESULT PICSRulesReqExtension::AddItem(PICSRulesObjectID proid, LPVOID pData)
  3439. {
  3440. HRESULT hRes = S_OK;
  3441. switch (proid)
  3442. {
  3443. case PROID_NAMEDEFAULT:
  3444. case PROID_EXTENSIONNAME:
  3445. {
  3446. m_prURLExtensionName.SetTo((char *) pData);
  3447. if(m_prURLExtensionName.IsURLValid()==FALSE)
  3448. {
  3449. hRes=E_INVALIDARG;
  3450. }
  3451. break;
  3452. }
  3453. case PROID_SHORTNAME:
  3454. {
  3455. m_etstrShortName.SetTo((char *) pData);
  3456. break;
  3457. }
  3458. case PROID_EXTENSION:
  3459. {
  3460. //just eat extensions
  3461. break;
  3462. }
  3463. case PROID_INVALID:
  3464. default:
  3465. {
  3466. ASSERT(FALSE); // shouldn't have been given a PROID that wasn't in
  3467. // the table we passed to the parser!
  3468. hRes=E_UNEXPECTED;
  3469. break;
  3470. }
  3471. }
  3472. return hRes;
  3473. }
  3474. HRESULT PICSRulesReqExtension::InitializeMyDefaults()
  3475. {
  3476. //no defaults to initialize
  3477. return(NOERROR);
  3478. }
  3479. //*******************************************************************
  3480. //*
  3481. //* Code for the PICSRulesServiceInfo class
  3482. //*
  3483. //*******************************************************************
  3484. PICSRulesServiceInfo::PICSRulesServiceInfo()
  3485. {
  3486. const BOOL fYes=PR_YESNO_YES;
  3487. const BOOL fPass=PR_PASSFAIL_PASS;
  3488. m_prPassFailBureauUnavailable.Set(&fPass);
  3489. m_prYesNoUseEmbedded.Set(&fYes);
  3490. }
  3491. PICSRulesServiceInfo::~PICSRulesServiceInfo()
  3492. {
  3493. //nothing to do
  3494. }
  3495. HRESULT PICSRulesServiceInfo::AddItem(PICSRulesObjectID proid, LPVOID pData)
  3496. {
  3497. HRESULT hRes = S_OK;
  3498. switch (proid)
  3499. {
  3500. case PROID_NAMEDEFAULT:
  3501. case PROID_NAME:
  3502. case PROID_SINAME:
  3503. {
  3504. m_prURLName.SetTo((char *) pData);
  3505. if(m_prURLName.IsURLValid()==FALSE)
  3506. {
  3507. hRes=E_INVALIDARG;
  3508. }
  3509. break;
  3510. }
  3511. case PROID_SHORTNAME:
  3512. {
  3513. m_etstrShortName.SetTo((char *) pData);
  3514. break;
  3515. }
  3516. case PROID_BUREAUURL:
  3517. {
  3518. m_prURLBureauURL.SetTo((char *) pData);
  3519. if(m_prURLBureauURL.IsURLValid()==FALSE)
  3520. {
  3521. hRes=E_INVALIDARG;
  3522. }
  3523. break;
  3524. }
  3525. case PROID_USEEMBEDDED:
  3526. {
  3527. m_prYesNoUseEmbedded.SetTo((BOOL *) &pData);
  3528. break;
  3529. }
  3530. case PROID_RATFILE:
  3531. {
  3532. m_etstrRatfile.SetTo((char *) pData);
  3533. break;
  3534. }
  3535. case PROID_BUREAUUNAVAILABLE:
  3536. {
  3537. m_prPassFailBureauUnavailable.SetTo((BOOL *) &pData);
  3538. break;
  3539. }
  3540. case PROID_EXTENSION:
  3541. {
  3542. //just eat extensions
  3543. break;
  3544. }
  3545. case PROID_INVALID:
  3546. default:
  3547. {
  3548. ASSERT(FALSE); // shouldn't have been given a PROID that wasn't in
  3549. // the table we passed to the parser!
  3550. hRes=E_UNEXPECTED;
  3551. break;
  3552. }
  3553. }
  3554. return hRes;
  3555. }
  3556. HRESULT PICSRulesServiceInfo::InitializeMyDefaults()
  3557. {
  3558. //nothing to do
  3559. return(S_OK);
  3560. }
  3561. //*******************************************************************
  3562. //*
  3563. //* Code for the PICSRulesSource class
  3564. //*
  3565. //*******************************************************************
  3566. PICSRulesSource::PICSRulesSource()
  3567. {
  3568. //nothing to do but construct members
  3569. }
  3570. PICSRulesSource::~PICSRulesSource()
  3571. {
  3572. //nothing to do
  3573. }
  3574. HRESULT PICSRulesSource::AddItem(PICSRulesObjectID proid, LPVOID pData)
  3575. {
  3576. HRESULT hRes = S_OK;
  3577. switch (proid)
  3578. {
  3579. case PROID_NAMEDEFAULT:
  3580. case PROID_SOURCEURL:
  3581. {
  3582. m_prURLSourceURL.SetTo((char *) pData);
  3583. if(m_prURLSourceURL.IsURLValid()==FALSE)
  3584. {
  3585. hRes=E_INVALIDARG;
  3586. }
  3587. break;
  3588. }
  3589. case PROID_AUTHOR:
  3590. {
  3591. m_prEmailAuthor.SetTo((char *) pData);
  3592. if(m_prEmailAuthor.IsEmailValid()==FALSE)
  3593. {
  3594. hRes=E_INVALIDARG;
  3595. }
  3596. break;
  3597. }
  3598. case PROID_CREATIONTOOL:
  3599. {
  3600. m_etstrCreationTool.SetTo((char *) pData);
  3601. break;
  3602. }
  3603. case PROID_LASTMODIFIED:
  3604. {
  3605. m_prDateLastModified.SetTo((char *) pData);
  3606. if(m_prDateLastModified.IsDateValid()==FALSE)
  3607. {
  3608. hRes=E_INVALIDARG;
  3609. }
  3610. break;
  3611. }
  3612. case PROID_EXTENSION:
  3613. {
  3614. //just eat extensions
  3615. break;
  3616. }
  3617. case PROID_INVALID:
  3618. default:
  3619. {
  3620. ASSERT(FALSE); // shouldn't have been given a PROID that wasn't in
  3621. // the table we passed to the parser!
  3622. hRes=E_UNEXPECTED;
  3623. break;
  3624. }
  3625. }
  3626. return hRes;
  3627. }
  3628. HRESULT PICSRulesSource::InitializeMyDefaults()
  3629. {
  3630. //no defaults to initialize
  3631. return(NOERROR);
  3632. }
  3633. char * PICSRulesSource::GetToolName()
  3634. {
  3635. return m_etstrCreationTool.Get();
  3636. }
  3637. //*******************************************************************
  3638. //*
  3639. //* Code for the PICSRulesYesNo class
  3640. //*
  3641. //*******************************************************************
  3642. PICSRulesYesNo::PICSRulesYesNo()
  3643. {
  3644. m_fYesOrNo=PR_YESNO_YES;
  3645. }
  3646. PICSRulesYesNo::~PICSRulesYesNo()
  3647. {
  3648. }
  3649. void PICSRulesYesNo::Set(const BOOL *pIn)
  3650. {
  3651. switch(*pIn)
  3652. {
  3653. case PR_YESNO_YES:
  3654. {
  3655. ETS::Set(szPRYes);
  3656. m_fYesOrNo=PR_YESNO_YES;
  3657. break;
  3658. }
  3659. case PR_YESNO_NO:
  3660. {
  3661. ETS::Set(szPRNo);
  3662. m_fYesOrNo=PR_YESNO_NO;
  3663. break;
  3664. }
  3665. }
  3666. }
  3667. void PICSRulesYesNo::SetTo(BOOL *pIn)
  3668. {
  3669. Set(pIn);
  3670. }
  3671. //*******************************************************************
  3672. //*
  3673. //* Code for the PICSRulesByURLExpression class
  3674. //*
  3675. //*******************************************************************
  3676. PICSRulesByURLExpression::PICSRulesByURLExpression()
  3677. {
  3678. m_bNonWild=0;
  3679. m_bSpecified=0;
  3680. }
  3681. PICSRulesByURLExpression::~PICSRulesByURLExpression()
  3682. {
  3683. //nothing to do
  3684. }
  3685. HRESULT EtStringRegWriteCipher(ETS &ets,HKEY hKey,char *pKeyWord)
  3686. {
  3687. if(pKeyWord==NULL)
  3688. {
  3689. return(E_INVALIDARG);
  3690. }
  3691. if(ets.fIsInit())
  3692. {
  3693. return(RegSetValueEx(hKey,pKeyWord,0,REG_SZ,(LPBYTE)ets.Get(),strlenf(ets.Get())+1));
  3694. }
  3695. return(NOERROR);
  3696. }
  3697. HRESULT EtNumRegWriteCipher(ETN &etn,HKEY hKey,char *pKeyWord)
  3698. {
  3699. int iTemp;
  3700. if(pKeyWord==NULL)
  3701. {
  3702. return(E_INVALIDARG);
  3703. }
  3704. if(etn.fIsInit())
  3705. {
  3706. iTemp=etn.Get();
  3707. return(RegSetValueEx(hKey,pKeyWord,0,REG_DWORD,(LPBYTE)&iTemp,sizeof(iTemp)));
  3708. }
  3709. return(NOERROR);
  3710. }
  3711. HRESULT EtBoolRegWriteCipher(ETB &etb,HKEY hKey,char *pKeyWord)
  3712. {
  3713. DWORD dwNum;
  3714. if(pKeyWord==NULL)
  3715. {
  3716. return(E_INVALIDARG);
  3717. }
  3718. if(etb.fIsInit())
  3719. {
  3720. dwNum=etb.Get();
  3721. return(RegSetValueEx(hKey,pKeyWord,0,REG_DWORD,(LPBYTE)&dwNum,sizeof(dwNum)));
  3722. }
  3723. return(NOERROR);
  3724. }
  3725. HRESULT EtStringRegReadCipher(ETS &ets,HKEY hKey,char *pKeyWord)
  3726. {
  3727. unsigned long lType;
  3728. if(pKeyWord==NULL)
  3729. {
  3730. return(E_INVALIDARG);
  3731. }
  3732. char * lpszString=new char[INTERNET_MAX_URL_LENGTH + 1];
  3733. DWORD dwSizeOfString=INTERNET_MAX_URL_LENGTH + 1;
  3734. if(lpszString==NULL)
  3735. {
  3736. return(E_OUTOFMEMORY);
  3737. }
  3738. if(RegQueryValueEx(hKey,pKeyWord,NULL,&lType,(LPBYTE) lpszString,&dwSizeOfString)!=ERROR_SUCCESS)
  3739. {
  3740. ets.SetTo(NULL);
  3741. delete lpszString;
  3742. lpszString = NULL;
  3743. return(E_UNEXPECTED);
  3744. }
  3745. else
  3746. {
  3747. ets.SetTo(lpszString);
  3748. }
  3749. return(NOERROR);
  3750. }
  3751. HRESULT EtNumRegReadCipher(ETN &etn,HKEY hKey,char *pKeyWord)
  3752. {
  3753. unsigned long lType;
  3754. if(pKeyWord==NULL)
  3755. {
  3756. return(E_INVALIDARG);
  3757. }
  3758. DWORD dwNum;
  3759. DWORD dwSizeOfNum=sizeof(DWORD);
  3760. if(RegQueryValueEx(hKey,pKeyWord,NULL,&lType,(LPBYTE) &dwNum,&dwSizeOfNum)!=ERROR_SUCCESS)
  3761. {
  3762. etn.Set(0);
  3763. return(E_UNEXPECTED);
  3764. }
  3765. else
  3766. {
  3767. etn.Set(dwNum);
  3768. }
  3769. return(NOERROR);
  3770. }
  3771. HRESULT EtBoolRegReadCipher(ETB &etb,HKEY hKey,char *pKeyWord)
  3772. {
  3773. unsigned long lType;
  3774. if(pKeyWord==NULL)
  3775. {
  3776. return(E_INVALIDARG);
  3777. }
  3778. BOOL fFlag;
  3779. DWORD dwSizeOfFlag=sizeof(BOOL);
  3780. if(RegQueryValueEx(hKey,pKeyWord,NULL,&lType,(LPBYTE) &fFlag,&dwSizeOfFlag)!=ERROR_SUCCESS)
  3781. {
  3782. etb.Set(0);
  3783. return(E_UNEXPECTED);
  3784. }
  3785. else
  3786. {
  3787. etb.Set(fFlag);
  3788. }
  3789. return(NOERROR);
  3790. }
  3791. void PICSRulesOutOfMemory()
  3792. {
  3793. char szTitle[MAX_PATH],szMessage[MAX_PATH];
  3794. MLLoadString(IDS_ERROR,(LPTSTR) szTitle,MAX_PATH);
  3795. MLLoadString(IDS_PICSRULES_OUTOFMEMORY,(LPTSTR) szMessage,MAX_PATH);
  3796. MessageBox(NULL,(LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK|MB_ICONERROR);
  3797. }
  3798. HRESULT CopySubPolicyExpressionFromRegistry(PICSRulesPolicyExpression * pPRPolicyExpressionBeingCopied,HKEY hKeyExpression)
  3799. {
  3800. PICSRulesPolicyExpression * pPRSubPolicyExpressionToCopy;
  3801. ETB etb;
  3802. ETN etn;
  3803. int iTemp;
  3804. long lError;
  3805. EtBoolRegReadCipher(etb,hKeyExpression,(char *) szPICSRULESEXPRESSIONEMBEDDED);
  3806. iTemp=(int) etb.Get();
  3807. pPRPolicyExpressionBeingCopied->m_prYesNoUseEmbedded.Set(&iTemp);
  3808. EtStringRegReadCipher(pPRPolicyExpressionBeingCopied->m_etstrServiceName,hKeyExpression,(char *) &szPICSRULESEXPRESSIONSERVICENAME);
  3809. EtStringRegReadCipher(pPRPolicyExpressionBeingCopied->m_etstrCategoryName,hKeyExpression,(char *) &szPICSRULESEXPRESSIONCATEGORYNAME);
  3810. EtStringRegReadCipher(pPRPolicyExpressionBeingCopied->m_etstrFullServiceName,hKeyExpression,(char *) &szPICSRULESEXPRESSIONFULLSERVICENAME);
  3811. EtNumRegReadCipher(etn,hKeyExpression,(char *) &szPICSRULESEXPRESSIONVALUE);
  3812. pPRPolicyExpressionBeingCopied->m_etnValue.Set(etn.Get());
  3813. EtNumRegReadCipher(etn,hKeyExpression,(char *) &szPICSRULESEXPRESSIONPOLICYOPERATOR);
  3814. pPRPolicyExpressionBeingCopied->m_PROPolicyOperator=(PICSRulesOperators) etn.Get();
  3815. EtNumRegReadCipher(etn,hKeyExpression,(char *) &szPICSRULESEXPRESSIONOPPOLICYEMBEDDED);
  3816. pPRPolicyExpressionBeingCopied->m_PRPEPolicyEmbedded=(PICSRulesPolicyEmbedded) etn.Get();
  3817. // Handle Left Expression
  3818. {
  3819. CRegKey keyExpressionSubKey;
  3820. lError = keyExpressionSubKey.Open( hKeyExpression, szPICSRULESEXPRESSIONLEFT, KEY_READ );
  3821. if(lError!=ERROR_SUCCESS)
  3822. {
  3823. pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionLeft=NULL;
  3824. }
  3825. else
  3826. {
  3827. pPRSubPolicyExpressionToCopy=new PICSRulesPolicyExpression;
  3828. if(pPRSubPolicyExpressionToCopy==NULL)
  3829. {
  3830. TraceMsg( TF_WARNING, "CopySubPolicyExpressionFromRegistry() - Failed PICSRulesPolicyExpression Creation LEFT '%s' Expression!", szPICSRULESEXPRESSIONLEFT );
  3831. PICSRulesOutOfMemory();
  3832. return(E_OUTOFMEMORY);
  3833. }
  3834. pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionLeft=pPRSubPolicyExpressionToCopy;
  3835. if ( FAILED( CopySubPolicyExpressionFromRegistry( pPRSubPolicyExpressionToCopy, keyExpressionSubKey.m_hKey )))
  3836. {
  3837. TraceMsg( TF_WARNING, "CopySubPolicyExpressionFromRegistry() - Failed Copy LEFT '%s' Expression!", szPICSRULESEXPRESSIONLEFT );
  3838. return(E_OUTOFMEMORY);
  3839. }
  3840. }
  3841. }
  3842. // Handle Right Expression
  3843. {
  3844. CRegKey keyExpressionSubKey;
  3845. lError = keyExpressionSubKey.Open( hKeyExpression, szPICSRULESEXPRESSIONRIGHT, KEY_READ );
  3846. if(lError!=ERROR_SUCCESS)
  3847. {
  3848. pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionRight=NULL;
  3849. }
  3850. else
  3851. {
  3852. pPRSubPolicyExpressionToCopy=new PICSRulesPolicyExpression;
  3853. if(pPRSubPolicyExpressionToCopy==NULL)
  3854. {
  3855. TraceMsg( TF_WARNING, "CopySubPolicyExpressionFromRegistry() - Failed PICSRulesPolicyExpression Creation RIGHT '%s' Expression!", szPICSRULESEXPRESSIONRIGHT );
  3856. PICSRulesOutOfMemory();
  3857. return(E_OUTOFMEMORY);
  3858. }
  3859. pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionRight=pPRSubPolicyExpressionToCopy;
  3860. if ( FAILED( CopySubPolicyExpressionFromRegistry( pPRSubPolicyExpressionToCopy, keyExpressionSubKey.m_hKey ) ) )
  3861. {
  3862. TraceMsg( TF_WARNING, "CopySubPolicyExpressionFromRegistry() - Failed Copy RIGHT '%s' Expression!", szPICSRULESEXPRESSIONRIGHT );
  3863. return(E_OUTOFMEMORY);
  3864. }
  3865. }
  3866. }
  3867. return(NOERROR);
  3868. }
  3869. class CReadRatingSystem
  3870. {
  3871. private:
  3872. PICSRulesRatingSystem ** m_ppPRRS;
  3873. public:
  3874. CReadRatingSystem( PICSRulesRatingSystem ** p_ppPRRS )
  3875. {
  3876. m_ppPRRS = p_ppPRRS;
  3877. }
  3878. ~CReadRatingSystem()
  3879. {
  3880. if ( m_ppPRRS )
  3881. {
  3882. if ( *m_ppPRRS )
  3883. {
  3884. delete *m_ppPRRS;
  3885. *m_ppPRRS = NULL;
  3886. }
  3887. m_ppPRRS = NULL;
  3888. }
  3889. }
  3890. void ValidRatingSystem( void ) { m_ppPRRS = NULL; }
  3891. };
  3892. HRESULT ReadSystemFromRegistry(HKEY hKey,PICSRulesRatingSystem **ppPRRS)
  3893. {
  3894. PICSRulesRatingSystem * pPRRSBeingCopied;
  3895. PICSRulesPolicy * pPRPolicyBeingCopied;
  3896. PICSRulesPolicyExpression * pPRPolicyExpressionBeingCopied;
  3897. PICSRulesServiceInfo * pPRServiceInfoBeingCopied;
  3898. PICSRulesOptExtension * pPROptExtensionBeingCopied;
  3899. PICSRulesReqExtension * pPRReqExtensionBeingCopied;
  3900. PICSRulesName * pPRNameBeingCopied;
  3901. PICSRulesSource * pPRSourceBeingCopied;
  3902. PICSRulesByURL * pPRByURLToCopy;
  3903. PICSRulesByURLExpression * pPRByURLExpressionToCopy;
  3904. ETN etn;
  3905. ETB etb;
  3906. long lError;
  3907. char szNumber[MAX_PATH];
  3908. DWORD dwNumSystems,dwSubCounter,dwNumServiceInfo,dwNumExtensions;
  3909. pPRRSBeingCopied=*ppPRRS;
  3910. if(pPRRSBeingCopied!=NULL)
  3911. {
  3912. delete pPRRSBeingCopied;
  3913. pPRRSBeingCopied = NULL;
  3914. }
  3915. pPRRSBeingCopied=new PICSRulesRatingSystem;
  3916. if(pPRRSBeingCopied==NULL)
  3917. {
  3918. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed PICSRulesRatingSystem Creation!" );
  3919. PICSRulesOutOfMemory();
  3920. return(E_OUTOFMEMORY);
  3921. }
  3922. *ppPRRS=pPRRSBeingCopied;
  3923. CReadRatingSystem readRatingSystem( ppPRRS );
  3924. EtStringRegReadCipher(pPRRSBeingCopied->m_etstrFile,hKey,(char *) &szPICSRULESFILENAME);
  3925. EtNumRegReadCipher(pPRRSBeingCopied->m_etnPRVerMajor,hKey,(char *) &szPICSRULESVERMAJOR);
  3926. EtNumRegReadCipher(pPRRSBeingCopied->m_etnPRVerMinor,hKey,(char *) &szPICSRULESVERMINOR);
  3927. EtNumRegReadCipher(etn,hKey,(char *) &szPICSRULESDWFLAGS);
  3928. pPRRSBeingCopied->m_dwFlags=etn.Get();
  3929. EtNumRegReadCipher(etn,hKey,(char *) &szPICSRULESERRLINE);
  3930. pPRRSBeingCopied->m_nErrLine=etn.Get();
  3931. {
  3932. CRegKey keySubKey;
  3933. //Read in the PICSRulesName Structure
  3934. lError = keySubKey.Open( hKey, szPICSRULESPRNAME, KEY_READ );
  3935. if(lError!=ERROR_SUCCESS)
  3936. {
  3937. pPRRSBeingCopied->m_pPRName=NULL;
  3938. }
  3939. else
  3940. {
  3941. pPRNameBeingCopied=new PICSRulesName;
  3942. if(pPRNameBeingCopied==NULL)
  3943. {
  3944. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed PICSRulesName Creation!" );
  3945. PICSRulesOutOfMemory();
  3946. return(E_OUTOFMEMORY);
  3947. }
  3948. else
  3949. {
  3950. pPRRSBeingCopied->m_pPRName=pPRNameBeingCopied;
  3951. }
  3952. }
  3953. if((pPRRSBeingCopied->m_pPRName)!=NULL)
  3954. {
  3955. EtStringRegReadCipher( pPRNameBeingCopied->m_etstrRuleName, keySubKey.m_hKey, (char *) &szPICSRULESRULENAME );
  3956. EtStringRegReadCipher( pPRNameBeingCopied->m_etstrDescription, keySubKey.m_hKey ,(char *) &szPICSRULESDESCRIPTION );
  3957. }
  3958. }
  3959. {
  3960. CRegKey keySubKey;
  3961. //Read in the PICSRulesSource Structure
  3962. lError = keySubKey.Open( hKey, szPICSRULESPRSOURCE, KEY_READ );
  3963. if(lError!=ERROR_SUCCESS)
  3964. {
  3965. pPRRSBeingCopied->m_pPRSource=NULL;
  3966. }
  3967. else
  3968. {
  3969. pPRSourceBeingCopied=new PICSRulesSource;
  3970. if(pPRSourceBeingCopied==NULL)
  3971. {
  3972. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed PICSRulesSource Creation!" );
  3973. PICSRulesOutOfMemory();
  3974. return(E_OUTOFMEMORY);
  3975. }
  3976. else
  3977. {
  3978. pPRRSBeingCopied->m_pPRSource=pPRSourceBeingCopied;
  3979. }
  3980. }
  3981. if((pPRRSBeingCopied->m_pPRSource)!=NULL)
  3982. {
  3983. EtStringRegReadCipher( pPRSourceBeingCopied->m_prURLSourceURL, keySubKey.m_hKey, (char *) &szPICSRULESSOURCEURL );
  3984. EtStringRegReadCipher( pPRSourceBeingCopied->m_etstrCreationTool, keySubKey.m_hKey, (char *) &szPICSRULESCREATIONTOOL );
  3985. EtStringRegReadCipher( pPRSourceBeingCopied->m_prEmailAuthor, keySubKey.m_hKey, (char *) &szPICSRULESEMAILAUTHOR );
  3986. EtStringRegReadCipher( pPRSourceBeingCopied->m_prDateLastModified, keySubKey.m_hKey, (char *) &szPICSRULESLASTMODIFIED );
  3987. }
  3988. }
  3989. {
  3990. CRegKey keySubKey;
  3991. //Read in the PICSRulesPolicy structure
  3992. lError = keySubKey.Open( hKey, szPICSRULESPRPOLICY, KEY_READ );
  3993. if(lError!=ERROR_SUCCESS)
  3994. {
  3995. dwNumSystems=0;
  3996. }
  3997. else
  3998. {
  3999. EtNumRegReadCipher( etn, keySubKey.m_hKey, (char *) &szPICSRULESNUMPOLICYS );
  4000. dwNumSystems=etn.Get();
  4001. }
  4002. for(dwSubCounter=0;dwSubCounter<dwNumSystems;dwSubCounter++)
  4003. {
  4004. DWORD dwPolicyExpressionSubCounter;
  4005. wsprintf(szNumber,"%d",dwSubCounter);
  4006. CRegKey keyCopy;
  4007. lError = keyCopy.Open( keySubKey.m_hKey, szNumber, KEY_READ );
  4008. if(lError!=ERROR_SUCCESS)
  4009. {
  4010. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed keyCopy Open szNumber='%s'!", szNumber );
  4011. return(E_FAIL);
  4012. }
  4013. else
  4014. {
  4015. pPRPolicyBeingCopied=new PICSRulesPolicy;
  4016. if(pPRPolicyBeingCopied==NULL)
  4017. {
  4018. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed PICSRulesPolicy Creation!" );
  4019. PICSRulesOutOfMemory();
  4020. return(E_OUTOFMEMORY);
  4021. }
  4022. }
  4023. pPRRSBeingCopied->m_arrpPRPolicy.Append(pPRPolicyBeingCopied);
  4024. EtStringRegReadCipher( pPRPolicyBeingCopied->m_etstrExplanation, keyCopy.m_hKey, (char *) &szPICSRULESPOLICYEXPLANATION );
  4025. EtNumRegReadCipher( etn, keyCopy.m_hKey, (char *) &szPICSRULESPOLICYATTRIBUTE );
  4026. pPRPolicyBeingCopied->m_PRPolicyAttribute=(PICSRulesPolicyAttribute) etn.Get();
  4027. CRegKey keyExpression;
  4028. lError = keyExpression.Open( keyCopy.m_hKey, szPICSRULESPOLICYSUB, KEY_READ );
  4029. if(lError!=ERROR_SUCCESS)
  4030. {
  4031. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed keyExpression Open szPICSRULESPOLICYSUB='%s'!", szPICSRULESPOLICYSUB );
  4032. return(E_FAIL);
  4033. }
  4034. pPRByURLToCopy=NULL;
  4035. pPRPolicyExpressionBeingCopied=NULL;
  4036. switch(pPRPolicyBeingCopied->m_PRPolicyAttribute)
  4037. {
  4038. case PR_POLICY_ACCEPTBYURL:
  4039. case PR_POLICY_REJECTBYURL:
  4040. {
  4041. pPRByURLToCopy=new PICSRulesByURL;
  4042. if(pPRByURLToCopy==NULL)
  4043. {
  4044. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed PICSRulesByURL Creation!" );
  4045. PICSRulesOutOfMemory();
  4046. return(E_OUTOFMEMORY);
  4047. }
  4048. break;
  4049. }
  4050. case PR_POLICY_REJECTIF:
  4051. case PR_POLICY_ACCEPTIF:
  4052. case PR_POLICY_REJECTUNLESS:
  4053. case PR_POLICY_ACCEPTUNLESS:
  4054. {
  4055. pPRPolicyExpressionBeingCopied=new PICSRulesPolicyExpression;
  4056. if(pPRPolicyExpressionBeingCopied==NULL)
  4057. {
  4058. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed PICSRulesPolicyExpression Creation!" );
  4059. PICSRulesOutOfMemory();
  4060. return(E_OUTOFMEMORY);
  4061. }
  4062. break;
  4063. }
  4064. }
  4065. switch(pPRPolicyBeingCopied->m_PRPolicyAttribute)
  4066. {
  4067. case PR_POLICY_ACCEPTBYURL:
  4068. {
  4069. pPRPolicyBeingCopied->m_pPRAcceptByURL=pPRByURLToCopy;
  4070. break;
  4071. }
  4072. case PR_POLICY_REJECTBYURL:
  4073. {
  4074. pPRPolicyBeingCopied->m_pPRRejectByURL=pPRByURLToCopy;
  4075. break;
  4076. }
  4077. case PR_POLICY_REJECTIF:
  4078. {
  4079. pPRPolicyBeingCopied->m_pPRRejectIf=pPRPolicyExpressionBeingCopied;
  4080. break;
  4081. }
  4082. case PR_POLICY_ACCEPTIF:
  4083. {
  4084. pPRPolicyBeingCopied->m_pPRAcceptIf=pPRPolicyExpressionBeingCopied;
  4085. break;
  4086. }
  4087. case PR_POLICY_REJECTUNLESS:
  4088. {
  4089. pPRPolicyBeingCopied->m_pPRRejectUnless=pPRPolicyExpressionBeingCopied;
  4090. break;
  4091. }
  4092. case PR_POLICY_ACCEPTUNLESS:
  4093. {
  4094. pPRPolicyBeingCopied->m_pPRAcceptUnless=pPRPolicyExpressionBeingCopied;
  4095. break;
  4096. }
  4097. }
  4098. if(pPRByURLToCopy!=NULL)
  4099. {
  4100. DWORD dwNumExpressions;
  4101. EtNumRegReadCipher( etn, keyExpression.m_hKey, (char *) &szPICSRULESNUMBYURL );
  4102. dwNumExpressions=etn.Get();
  4103. for(dwPolicyExpressionSubCounter=0;
  4104. dwPolicyExpressionSubCounter<dwNumExpressions;
  4105. dwPolicyExpressionSubCounter++)
  4106. {
  4107. CRegKey keyByURL;
  4108. wsprintf(szNumber,"%d",dwPolicyExpressionSubCounter);
  4109. lError = keyByURL.Open( keyExpression.m_hKey, szNumber, KEY_READ );
  4110. if(lError!=ERROR_SUCCESS)
  4111. {
  4112. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed keyByURL Open szNumber='%s'!", szNumber );
  4113. return(E_FAIL);
  4114. }
  4115. else
  4116. {
  4117. pPRByURLExpressionToCopy=new PICSRulesByURLExpression;
  4118. if(pPRByURLExpressionToCopy==NULL)
  4119. {
  4120. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed PICSRulesByURLExpression Creation!" );
  4121. PICSRulesOutOfMemory();
  4122. return(E_FAIL);
  4123. }
  4124. }
  4125. pPRByURLToCopy->m_arrpPRByURL.Append(pPRByURLExpressionToCopy);
  4126. EtBoolRegReadCipher( etb, keyByURL.m_hKey, (char *) szPICSRULESBYURLINTERNETPATTERN );
  4127. pPRByURLExpressionToCopy->m_fInternetPattern=etb.Get();
  4128. EtNumRegReadCipher( etn, keyByURL.m_hKey, (char *) szPICSRULESBYURLNONWILD );
  4129. pPRByURLExpressionToCopy->m_bNonWild = (unsigned char) etn.Get();
  4130. EtNumRegReadCipher( etn, keyByURL.m_hKey, (char *) szPICSRULESBYURLSPECIFIED );
  4131. pPRByURLExpressionToCopy->m_bSpecified = (unsigned char) etn.Get();
  4132. EtStringRegReadCipher( pPRByURLExpressionToCopy->m_etstrScheme, keyByURL.m_hKey, (char *) &szPICSRULESBYURLSCHEME );
  4133. EtStringRegReadCipher( pPRByURLExpressionToCopy->m_etstrUser, keyByURL.m_hKey, (char *) &szPICSRULESBYURLUSER );
  4134. EtStringRegReadCipher( pPRByURLExpressionToCopy->m_etstrHost, keyByURL.m_hKey, (char *) &szPICSRULESBYURLHOST );
  4135. EtStringRegReadCipher( pPRByURLExpressionToCopy->m_etstrPort, keyByURL.m_hKey, (char *) &szPICSRULESBYURLPORT );
  4136. EtStringRegReadCipher( pPRByURLExpressionToCopy->m_etstrPath, keyByURL.m_hKey, (char *) &szPICSRULESBYURLPATH );
  4137. EtStringRegReadCipher( pPRByURLExpressionToCopy->m_etstrURL, keyByURL.m_hKey, (char *) &szPICSRULESBYURLURL );
  4138. }
  4139. }
  4140. if(pPRPolicyExpressionBeingCopied!=NULL)
  4141. {
  4142. PICSRulesPolicyExpression * pPRSubPolicyExpressionToCopy;
  4143. int iTemp;
  4144. EtBoolRegReadCipher( etb, keyExpression.m_hKey,(char *) szPICSRULESEXPRESSIONEMBEDDED );
  4145. iTemp=(int) etb.Get();
  4146. pPRPolicyExpressionBeingCopied->m_prYesNoUseEmbedded.Set(&iTemp);
  4147. EtStringRegReadCipher( pPRPolicyExpressionBeingCopied->m_etstrServiceName, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONSERVICENAME );
  4148. EtStringRegReadCipher( pPRPolicyExpressionBeingCopied->m_etstrCategoryName, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONCATEGORYNAME );
  4149. EtStringRegReadCipher( pPRPolicyExpressionBeingCopied->m_etstrFullServiceName, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONFULLSERVICENAME );
  4150. EtNumRegReadCipher( etn, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONVALUE );
  4151. pPRPolicyExpressionBeingCopied->m_etnValue.Set(etn.Get());
  4152. EtNumRegReadCipher( etn, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONPOLICYOPERATOR );
  4153. pPRPolicyExpressionBeingCopied->m_PROPolicyOperator=(PICSRulesOperators) etn.Get();
  4154. EtNumRegReadCipher( etn, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONOPPOLICYEMBEDDED );
  4155. pPRPolicyExpressionBeingCopied->m_PRPEPolicyEmbedded=(PICSRulesPolicyEmbedded) etn.Get();
  4156. {
  4157. CRegKey keyExpressionSubKey;
  4158. lError = keyExpressionSubKey.Open( keyExpression.m_hKey, szPICSRULESEXPRESSIONLEFT, KEY_READ );
  4159. if(lError!=ERROR_SUCCESS)
  4160. {
  4161. pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionLeft=NULL;
  4162. }
  4163. else
  4164. {
  4165. pPRSubPolicyExpressionToCopy=new PICSRulesPolicyExpression;
  4166. if(pPRSubPolicyExpressionToCopy==NULL)
  4167. {
  4168. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed LEFT PICSRulesPolicyExpression Creation!" );
  4169. PICSRulesOutOfMemory();
  4170. return(E_OUTOFMEMORY);
  4171. }
  4172. pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionLeft=pPRSubPolicyExpressionToCopy;
  4173. if ( FAILED( CopySubPolicyExpressionFromRegistry( pPRSubPolicyExpressionToCopy, keyExpressionSubKey.m_hKey ) ) )
  4174. {
  4175. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed LEFT CopySubPolicyExpressionFromRegistry()!" );
  4176. return(E_FAIL);
  4177. }
  4178. }
  4179. }
  4180. {
  4181. CRegKey keyExpressionSubKey;
  4182. lError = keyExpressionSubKey.Open( keyExpression.m_hKey, szPICSRULESEXPRESSIONRIGHT, KEY_READ );
  4183. if(lError!=ERROR_SUCCESS)
  4184. {
  4185. pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionRight=NULL;
  4186. }
  4187. else
  4188. {
  4189. pPRSubPolicyExpressionToCopy=new PICSRulesPolicyExpression;
  4190. if(pPRSubPolicyExpressionToCopy==NULL)
  4191. {
  4192. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed RIGHT PICSRulesPolicyExpression Creation!" );
  4193. PICSRulesOutOfMemory();
  4194. return(E_OUTOFMEMORY);
  4195. }
  4196. pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionRight=pPRSubPolicyExpressionToCopy;
  4197. if ( FAILED( CopySubPolicyExpressionFromRegistry( pPRSubPolicyExpressionToCopy, keyExpressionSubKey.m_hKey ) ) )
  4198. {
  4199. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed RIGHT CopySubPolicyExpressionFromRegistry()!" );
  4200. return(E_FAIL);
  4201. }
  4202. }
  4203. }
  4204. }
  4205. }
  4206. }
  4207. {
  4208. CRegKey keySubKey;
  4209. //Read In PICSRulesServiceInfo Structure
  4210. lError = keySubKey.Open( hKey, szPICSRULESSERVICEINFO, KEY_READ );
  4211. if(lError!=ERROR_SUCCESS)
  4212. {
  4213. dwNumServiceInfo=0;
  4214. }
  4215. else
  4216. {
  4217. EtNumRegReadCipher( etn, keySubKey.m_hKey ,(char *) &szPICSRULESNUMSERVICEINFO );
  4218. dwNumServiceInfo=etn.Get();
  4219. }
  4220. for(dwSubCounter=0;dwSubCounter<dwNumServiceInfo;dwSubCounter++)
  4221. {
  4222. CRegKey keyCopy;
  4223. int iTemp;
  4224. wsprintf(szNumber,"%d",dwSubCounter);
  4225. lError = keyCopy.Open( keySubKey.m_hKey, szNumber, KEY_READ );
  4226. if(lError!=ERROR_SUCCESS)
  4227. {
  4228. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed szPICSRULESSERVICEINFO keyCopy Open szNumber='%s'!", szNumber );
  4229. return(E_FAIL);
  4230. }
  4231. else
  4232. {
  4233. pPRServiceInfoBeingCopied=new PICSRulesServiceInfo;
  4234. if(pPRServiceInfoBeingCopied==NULL)
  4235. {
  4236. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed PICSRulesServiceInfo Creation!" );
  4237. PICSRulesOutOfMemory();
  4238. return(E_OUTOFMEMORY);
  4239. }
  4240. }
  4241. pPRRSBeingCopied->m_arrpPRServiceInfo.Append(pPRServiceInfoBeingCopied);
  4242. EtStringRegReadCipher( pPRServiceInfoBeingCopied->m_prURLName, keyCopy.m_hKey, (char *) &szPICSRULESSIURLNAME );
  4243. EtStringRegReadCipher( pPRServiceInfoBeingCopied->m_prURLBureauURL, keyCopy.m_hKey, (char *) &szPICSRULESSIBUREAUURL );
  4244. EtStringRegReadCipher( pPRServiceInfoBeingCopied->m_etstrShortName, keyCopy.m_hKey, (char *) &szPICSRULESSISHORTNAME );
  4245. EtStringRegReadCipher( pPRServiceInfoBeingCopied->m_etstrRatfile, keyCopy.m_hKey, (char *) &szPICSRULESSIRATFILE );
  4246. EtBoolRegReadCipher( etb, keyCopy.m_hKey, (char *) &szPICSRULESSIUSEEMBEDDED );
  4247. iTemp=(int) etb.Get();
  4248. pPRServiceInfoBeingCopied->m_prYesNoUseEmbedded.Set(&iTemp);
  4249. EtBoolRegReadCipher( etb, keyCopy.m_hKey, (char *) &szPICSRULESSIBUREAUUNAVAILABLE );
  4250. iTemp=(int) etb.Get();
  4251. pPRServiceInfoBeingCopied->m_prPassFailBureauUnavailable.Set(&iTemp);
  4252. }
  4253. }
  4254. {
  4255. CRegKey keySubKey;
  4256. //Read in OptExtension Structures
  4257. lError = keySubKey.Open( hKey, szPICSRULESOPTEXTENSION, KEY_READ );
  4258. if(lError!=ERROR_SUCCESS)
  4259. {
  4260. dwNumExtensions=0;
  4261. }
  4262. else
  4263. {
  4264. EtNumRegReadCipher( etn, keySubKey.m_hKey, (char *) &szPICSRULESNUMOPTEXTENSIONS );
  4265. dwNumExtensions=etn.Get();
  4266. }
  4267. for(dwSubCounter=0;dwSubCounter<(DWORD) (pPRRSBeingCopied->m_arrpPROptExtension.Length());dwSubCounter++)
  4268. {
  4269. CRegKey keyCopy;
  4270. wsprintf(szNumber,"%d",dwSubCounter);
  4271. lError = keyCopy.Open( keySubKey.m_hKey, szNumber, KEY_READ );
  4272. if(lError!=ERROR_SUCCESS)
  4273. {
  4274. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed szPICSRULESOPTEXTENSION keyCopy Open szNumber='%s'!", szNumber );
  4275. return(E_FAIL);
  4276. }
  4277. else
  4278. {
  4279. pPROptExtensionBeingCopied=new PICSRulesOptExtension;
  4280. if(pPROptExtensionBeingCopied==NULL)
  4281. {
  4282. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed PICSRulesOptExtension Creation!" );
  4283. PICSRulesOutOfMemory();
  4284. return(E_OUTOFMEMORY);
  4285. }
  4286. }
  4287. pPRRSBeingCopied->m_arrpPROptExtension.Append(pPROptExtensionBeingCopied);
  4288. EtStringRegReadCipher( pPROptExtensionBeingCopied->m_prURLExtensionName, keyCopy.m_hKey, (char *) &szPICSRULESOPTEXTNAME );
  4289. EtStringRegReadCipher( pPROptExtensionBeingCopied->m_etstrShortName, keyCopy.m_hKey, (char *) &szPICSRULESOPTEXTSHORTNAME );
  4290. }
  4291. }
  4292. {
  4293. CRegKey keySubKey;
  4294. //Read in ReqExtension Structures
  4295. lError = keySubKey.Open( hKey, szPICSRULESREQEXTENSION, KEY_READ );
  4296. if(lError!=ERROR_SUCCESS)
  4297. {
  4298. dwNumExtensions=0;
  4299. }
  4300. else
  4301. {
  4302. EtNumRegReadCipher( etn, keySubKey.m_hKey, (char *) &szPICSRULESNUMREQEXTENSIONS );
  4303. dwNumExtensions=etn.Get();
  4304. }
  4305. for(dwSubCounter=0;dwSubCounter<(DWORD) (pPRRSBeingCopied->m_arrpPRReqExtension.Length());dwSubCounter++)
  4306. {
  4307. CRegKey keyCopy;
  4308. wsprintf(szNumber,"%d",dwSubCounter);
  4309. lError = keyCopy.Open( keySubKey.m_hKey, szNumber, KEY_READ );
  4310. if(lError!=ERROR_SUCCESS)
  4311. {
  4312. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed szPICSRULESREQEXTENSION keyCopy Open szNumber='%s'!", szNumber );
  4313. return(E_FAIL);
  4314. }
  4315. else
  4316. {
  4317. pPRReqExtensionBeingCopied=new PICSRulesReqExtension;
  4318. if(pPRReqExtensionBeingCopied==NULL)
  4319. {
  4320. TraceMsg( TF_WARNING, "ReadSystemFromRegistry() - Failed PICSRulesReqExtension Creation!" );
  4321. PICSRulesOutOfMemory();
  4322. return(E_OUTOFMEMORY);
  4323. }
  4324. }
  4325. pPRRSBeingCopied->m_arrpPRReqExtension.Append(pPRReqExtensionBeingCopied);
  4326. EtStringRegReadCipher( pPRReqExtensionBeingCopied->m_prURLExtensionName, keyCopy.m_hKey, (char *) &szPICSRULESREQEXTNAME );
  4327. EtStringRegReadCipher( pPRReqExtensionBeingCopied->m_etstrShortName, keyCopy.m_hKey, (char *) &szPICSRULESREQEXTSHORTNAME );
  4328. }
  4329. }
  4330. // Insure the Copied Rating System is not deleted.
  4331. readRatingSystem.ValidRatingSystem();
  4332. TraceMsg( TF_ALWAYS, "ReadSystemFromRegistry() - Successfully Read PICS Rules from Registry!" );
  4333. return(NOERROR);
  4334. }
  4335. HRESULT CopySubPolicyExpressionToRegistry(PICSRulesPolicyExpression * pPRPolicyExpressionBeingCopied,HKEY hKeyExpression)
  4336. {
  4337. ETB etb;
  4338. ETN etn;
  4339. long lError;
  4340. etb.Set(pPRPolicyExpressionBeingCopied->m_prYesNoUseEmbedded.GetYesNo());
  4341. EtBoolRegWriteCipher(etb,hKeyExpression,(char *) szPICSRULESEXPRESSIONEMBEDDED);
  4342. EtStringRegWriteCipher(pPRPolicyExpressionBeingCopied->m_etstrServiceName,hKeyExpression,(char *) &szPICSRULESEXPRESSIONSERVICENAME);
  4343. EtStringRegWriteCipher(pPRPolicyExpressionBeingCopied->m_etstrCategoryName,hKeyExpression,(char *) &szPICSRULESEXPRESSIONCATEGORYNAME);
  4344. EtStringRegWriteCipher(pPRPolicyExpressionBeingCopied->m_etstrFullServiceName,hKeyExpression,(char *) &szPICSRULESEXPRESSIONFULLSERVICENAME);
  4345. etn.Set(pPRPolicyExpressionBeingCopied->m_etnValue.Get());
  4346. EtNumRegWriteCipher(etn,hKeyExpression,(char *) &szPICSRULESEXPRESSIONVALUE);
  4347. etn.Set(pPRPolicyExpressionBeingCopied->m_PROPolicyOperator);
  4348. EtNumRegWriteCipher(etn,hKeyExpression,(char *) &szPICSRULESEXPRESSIONPOLICYOPERATOR);
  4349. etn.Set(pPRPolicyExpressionBeingCopied->m_PRPEPolicyEmbedded);
  4350. EtNumRegWriteCipher(etn,hKeyExpression,(char *) &szPICSRULESEXPRESSIONOPPOLICYEMBEDDED);
  4351. if(pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionLeft!=NULL)
  4352. {
  4353. PICSRulesPolicyExpression * pPRSubPolicyExpressionToCopy;
  4354. CRegKey keyExpressionSubKey;
  4355. lError = keyExpressionSubKey.Create( hKeyExpression, szPICSRULESEXPRESSIONLEFT );
  4356. if ( lError != ERROR_SUCCESS )
  4357. {
  4358. TraceMsg( TF_WARNING, "CopySubPolicyExpressionToRegistry() - Failed Registry Key Creation LEFT '%s' Expression!", szPICSRULESEXPRESSIONLEFT );
  4359. return(E_FAIL);
  4360. }
  4361. pPRSubPolicyExpressionToCopy=pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionLeft;
  4362. if ( FAILED( CopySubPolicyExpressionToRegistry(pPRSubPolicyExpressionToCopy, keyExpressionSubKey.m_hKey ) ) )
  4363. {
  4364. TraceMsg( TF_WARNING, "CopySubPolicyExpressionToRegistry() - Failed LEFT CopySubPolicyExpressionToRegistry() Recursive Call!" );
  4365. return(E_FAIL);
  4366. }
  4367. }
  4368. if(pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionRight!=NULL)
  4369. {
  4370. PICSRulesPolicyExpression * pPRSubPolicyExpressionToCopy;
  4371. CRegKey keyExpressionSubKey;
  4372. lError = keyExpressionSubKey.Create( hKeyExpression, szPICSRULESEXPRESSIONRIGHT );
  4373. if ( lError != ERROR_SUCCESS )
  4374. {
  4375. TraceMsg( TF_WARNING, "CopySubPolicyExpressionToRegistry() - Failed Registry Key Creation RIGHT '%s' Expression!", szPICSRULESEXPRESSIONRIGHT );
  4376. return(E_FAIL);
  4377. }
  4378. pPRSubPolicyExpressionToCopy=pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionRight;
  4379. if ( FAILED( CopySubPolicyExpressionToRegistry(pPRSubPolicyExpressionToCopy, keyExpressionSubKey.m_hKey ) ) )
  4380. {
  4381. TraceMsg( TF_WARNING, "CopySubPolicyExpressionToRegistry() - Failed RIGHT CopySubPolicyExpressionToRegistry() Recursive Call!" );
  4382. return(E_FAIL);
  4383. }
  4384. }
  4385. return(NOERROR);
  4386. }
  4387. HRESULT WriteSystemToRegistry(HKEY hKey,PICSRulesRatingSystem **ppPRRS)
  4388. {
  4389. PICSRulesRatingSystem * pPRRSBeingCopied;
  4390. PICSRulesPolicy * pPRPolicyBeingCopied;
  4391. PICSRulesPolicyExpression * pPRPolicyExpressionBeingCopied;
  4392. PICSRulesServiceInfo * pPRServiceInfoBeingCopied;
  4393. PICSRulesOptExtension * pPROptExtensionBeingCopied;
  4394. PICSRulesReqExtension * pPRReqExtensionBeingCopied;
  4395. PICSRulesName * pPRNameBeingCopied;
  4396. PICSRulesSource * pPRSourceBeingCopied;
  4397. PICSRulesByURL * pPRByURLToCopy;
  4398. PICSRulesByURLExpression * pPRByURLExpressionToCopy;
  4399. ETN etn;
  4400. ETB etb;
  4401. long lError;
  4402. char szNumber[MAX_PATH];
  4403. pPRRSBeingCopied=*ppPRRS;
  4404. if(pPRRSBeingCopied==NULL)
  4405. {
  4406. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - pPRRSBeingCopied is NULL!" );
  4407. return(E_INVALIDARG);
  4408. }
  4409. EtStringRegWriteCipher( pPRRSBeingCopied->m_etstrFile, hKey, (char *) &szPICSRULESFILENAME );
  4410. EtNumRegWriteCipher( pPRRSBeingCopied->m_etnPRVerMajor, hKey, (char *) &szPICSRULESVERMAJOR );
  4411. EtNumRegWriteCipher( pPRRSBeingCopied->m_etnPRVerMinor, hKey, (char *) &szPICSRULESVERMINOR );
  4412. etn.Set(pPRRSBeingCopied->m_dwFlags);
  4413. EtNumRegWriteCipher( etn, hKey, (char *) &szPICSRULESDWFLAGS );
  4414. etn.Set(pPRRSBeingCopied->m_nErrLine);
  4415. EtNumRegWriteCipher( etn, hKey, (char *) &szPICSRULESERRLINE );
  4416. if((pPRRSBeingCopied->m_pPRName)!=NULL)
  4417. {
  4418. CRegKey keySubKey;
  4419. lError = keySubKey.Create( hKey, szPICSRULESPRNAME );
  4420. if ( lError != ERROR_SUCCESS )
  4421. {
  4422. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create szPICSRULESPRNAME='%s' Key!", szPICSRULESPRNAME );
  4423. return(E_FAIL);
  4424. }
  4425. pPRNameBeingCopied=pPRRSBeingCopied->m_pPRName;
  4426. EtStringRegWriteCipher( pPRNameBeingCopied->m_etstrRuleName, hKey, (char *) &szPICSRULESSYSTEMNAME );
  4427. EtStringRegWriteCipher( pPRNameBeingCopied->m_etstrRuleName, keySubKey.m_hKey, (char *) &szPICSRULESRULENAME );
  4428. EtStringRegWriteCipher( pPRNameBeingCopied->m_etstrDescription, keySubKey.m_hKey, (char *) &szPICSRULESDESCRIPTION );
  4429. }
  4430. if((pPRRSBeingCopied->m_pPRSource)!=NULL)
  4431. {
  4432. CRegKey keySubKey;
  4433. lError = keySubKey.Create( hKey, szPICSRULESPRSOURCE );
  4434. if ( lError != ERROR_SUCCESS )
  4435. {
  4436. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create szPICSRULESPRSOURCE='%s' Key!", szPICSRULESPRSOURCE );
  4437. return(E_FAIL);
  4438. }
  4439. pPRSourceBeingCopied=pPRRSBeingCopied->m_pPRSource;
  4440. EtStringRegWriteCipher( pPRSourceBeingCopied->m_prURLSourceURL, keySubKey.m_hKey, (char *) &szPICSRULESSOURCEURL );
  4441. EtStringRegWriteCipher( pPRSourceBeingCopied->m_etstrCreationTool, keySubKey.m_hKey, (char *) &szPICSRULESCREATIONTOOL );
  4442. EtStringRegWriteCipher( pPRSourceBeingCopied->m_prEmailAuthor, keySubKey.m_hKey, (char *) &szPICSRULESEMAILAUTHOR );
  4443. EtStringRegWriteCipher( pPRSourceBeingCopied->m_prDateLastModified, keySubKey.m_hKey, (char *) &szPICSRULESLASTMODIFIED );
  4444. }
  4445. if(pPRRSBeingCopied->m_arrpPRPolicy.Length()>0)
  4446. {
  4447. CRegKey keySubKey;
  4448. DWORD dwSubCounter;
  4449. lError = keySubKey.Create( hKey, szPICSRULESPRPOLICY );
  4450. if ( lError != ERROR_SUCCESS )
  4451. {
  4452. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create szPICSRULESPRPOLICY='%s' Key!", szPICSRULESPRPOLICY );
  4453. return(E_FAIL);
  4454. }
  4455. etn.Set(pPRRSBeingCopied->m_arrpPRPolicy.Length());
  4456. EtNumRegWriteCipher( etn, keySubKey.m_hKey, (char *) &szPICSRULESNUMPOLICYS );
  4457. for(dwSubCounter=0;dwSubCounter<(DWORD) (pPRRSBeingCopied->m_arrpPRPolicy.Length());dwSubCounter++)
  4458. {
  4459. DWORD dwPolicyExpressionSubCounter;
  4460. wsprintf(szNumber,"%d",dwSubCounter);
  4461. CRegKey keyCopy;
  4462. lError = keyCopy.Create( keySubKey.m_hKey, szNumber );
  4463. if ( lError != ERROR_SUCCESS )
  4464. {
  4465. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create m_arrpPRPolicy szNumber='%s' Key!", szNumber );
  4466. return(E_FAIL);
  4467. }
  4468. pPRPolicyBeingCopied=pPRRSBeingCopied->m_arrpPRPolicy[dwSubCounter];
  4469. EtStringRegWriteCipher( pPRPolicyBeingCopied->m_etstrExplanation, keyCopy.m_hKey, (char *) &szPICSRULESPOLICYEXPLANATION );
  4470. etn.Set(pPRPolicyBeingCopied->m_PRPolicyAttribute);
  4471. EtNumRegWriteCipher( etn, keyCopy.m_hKey, (char *) &szPICSRULESPOLICYATTRIBUTE );
  4472. CRegKey keyExpression;
  4473. lError = keyExpression.Create( keyCopy.m_hKey, szPICSRULESPOLICYSUB );
  4474. if ( lError != ERROR_SUCCESS )
  4475. {
  4476. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create szPICSRULESPOLICYSUB='%s' Key!", szPICSRULESPOLICYSUB );
  4477. return(E_FAIL);
  4478. }
  4479. pPRByURLToCopy=NULL;
  4480. pPRPolicyExpressionBeingCopied=NULL;
  4481. switch(pPRPolicyBeingCopied->m_PRPolicyAttribute)
  4482. {
  4483. case PR_POLICY_ACCEPTBYURL:
  4484. {
  4485. pPRByURLToCopy=pPRPolicyBeingCopied->m_pPRAcceptByURL;
  4486. break;
  4487. }
  4488. case PR_POLICY_REJECTBYURL:
  4489. {
  4490. pPRByURLToCopy=pPRPolicyBeingCopied->m_pPRRejectByURL;
  4491. break;
  4492. }
  4493. case PR_POLICY_REJECTIF:
  4494. {
  4495. pPRPolicyExpressionBeingCopied=pPRPolicyBeingCopied->m_pPRRejectIf;
  4496. break;
  4497. }
  4498. case PR_POLICY_ACCEPTIF:
  4499. {
  4500. pPRPolicyExpressionBeingCopied=pPRPolicyBeingCopied->m_pPRAcceptIf;
  4501. break;
  4502. }
  4503. case PR_POLICY_REJECTUNLESS:
  4504. {
  4505. pPRPolicyExpressionBeingCopied=pPRPolicyBeingCopied->m_pPRRejectUnless;
  4506. break;
  4507. }
  4508. case PR_POLICY_ACCEPTUNLESS:
  4509. {
  4510. pPRPolicyExpressionBeingCopied=pPRPolicyBeingCopied->m_pPRAcceptUnless;
  4511. break;
  4512. }
  4513. }
  4514. if(pPRByURLToCopy!=NULL)
  4515. {
  4516. etn.Set(pPRByURLToCopy->m_arrpPRByURL.Length());
  4517. EtNumRegWriteCipher( etn, keyExpression.m_hKey, (char *) &szPICSRULESNUMBYURL );
  4518. for(dwPolicyExpressionSubCounter=0;
  4519. dwPolicyExpressionSubCounter<(DWORD) (pPRByURLToCopy->m_arrpPRByURL.Length());
  4520. dwPolicyExpressionSubCounter++)
  4521. {
  4522. CRegKey keyByURL;
  4523. wsprintf(szNumber,"%d",dwPolicyExpressionSubCounter);
  4524. lError = keyByURL.Create( keyExpression.m_hKey, szNumber );
  4525. if ( lError != ERROR_SUCCESS )
  4526. {
  4527. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create m_arrpPRByURL szNumber='%s' Key!", szNumber );
  4528. return(E_FAIL);
  4529. }
  4530. pPRByURLExpressionToCopy=pPRByURLToCopy->m_arrpPRByURL[dwPolicyExpressionSubCounter];
  4531. etb.Set(pPRByURLExpressionToCopy->m_fInternetPattern);
  4532. EtBoolRegWriteCipher( etb, keyByURL.m_hKey, (char *) szPICSRULESBYURLINTERNETPATTERN );
  4533. etn.Set(pPRByURLExpressionToCopy->m_bNonWild);
  4534. EtNumRegWriteCipher( etn, keyByURL.m_hKey, (char *) szPICSRULESBYURLNONWILD );
  4535. etn.Set(pPRByURLExpressionToCopy->m_bSpecified);
  4536. EtNumRegWriteCipher( etn, keyByURL.m_hKey, (char *) szPICSRULESBYURLSPECIFIED );
  4537. EtStringRegWriteCipher( pPRByURLExpressionToCopy->m_etstrScheme, keyByURL.m_hKey, (char *) &szPICSRULESBYURLSCHEME );
  4538. EtStringRegWriteCipher( pPRByURLExpressionToCopy->m_etstrUser, keyByURL.m_hKey, (char *) &szPICSRULESBYURLUSER );
  4539. EtStringRegWriteCipher( pPRByURLExpressionToCopy->m_etstrHost, keyByURL.m_hKey, (char *) &szPICSRULESBYURLHOST );
  4540. EtStringRegWriteCipher( pPRByURLExpressionToCopy->m_etstrPort, keyByURL.m_hKey, (char *) &szPICSRULESBYURLPORT );
  4541. EtStringRegWriteCipher( pPRByURLExpressionToCopy->m_etstrPath, keyByURL.m_hKey, (char *) &szPICSRULESBYURLPATH );
  4542. EtStringRegWriteCipher( pPRByURLExpressionToCopy->m_etstrURL, keyByURL.m_hKey, (char *) &szPICSRULESBYURLURL );
  4543. }
  4544. }
  4545. if(pPRPolicyExpressionBeingCopied!=NULL)
  4546. {
  4547. etb.Set(pPRPolicyExpressionBeingCopied->m_prYesNoUseEmbedded.GetYesNo());
  4548. EtBoolRegWriteCipher( etb, keyExpression.m_hKey, (char *) szPICSRULESEXPRESSIONEMBEDDED );
  4549. EtStringRegWriteCipher( pPRPolicyExpressionBeingCopied->m_etstrServiceName, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONSERVICENAME );
  4550. EtStringRegWriteCipher( pPRPolicyExpressionBeingCopied->m_etstrCategoryName, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONCATEGORYNAME );
  4551. EtStringRegWriteCipher( pPRPolicyExpressionBeingCopied->m_etstrFullServiceName, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONFULLSERVICENAME );
  4552. etn.Set(pPRPolicyExpressionBeingCopied->m_etnValue.Get());
  4553. EtNumRegWriteCipher( etn, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONVALUE );
  4554. etn.Set(pPRPolicyExpressionBeingCopied->m_PROPolicyOperator);
  4555. EtNumRegWriteCipher( etn, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONPOLICYOPERATOR );
  4556. etn.Set(pPRPolicyExpressionBeingCopied->m_PRPEPolicyEmbedded);
  4557. EtNumRegWriteCipher( etn, keyExpression.m_hKey, (char *) &szPICSRULESEXPRESSIONOPPOLICYEMBEDDED );
  4558. if(pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionLeft!=NULL)
  4559. {
  4560. PICSRulesPolicyExpression * pPRSubPolicyExpressionToCopy;
  4561. CRegKey keyExpressionSubKey;
  4562. lError = keyExpressionSubKey.Create( keyExpression.m_hKey, szPICSRULESEXPRESSIONLEFT );
  4563. if ( lError != ERROR_SUCCESS )
  4564. {
  4565. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create szPICSRULESEXPRESSIONLEFT='%s' Key!", szPICSRULESEXPRESSIONLEFT );
  4566. return(E_FAIL);
  4567. }
  4568. pPRSubPolicyExpressionToCopy=pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionLeft;
  4569. if ( FAILED( CopySubPolicyExpressionToRegistry( pPRSubPolicyExpressionToCopy, keyExpressionSubKey.m_hKey ) ) )
  4570. {
  4571. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed LEFT CopySubPolicyExpressionToRegistry() Call!" );
  4572. return(E_FAIL);
  4573. }
  4574. }
  4575. if(pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionRight!=NULL)
  4576. {
  4577. PICSRulesPolicyExpression * pPRSubPolicyExpressionToCopy;
  4578. CRegKey keyExpressionSubKey;
  4579. lError = keyExpressionSubKey.Create( keyExpression.m_hKey, szPICSRULESEXPRESSIONRIGHT );
  4580. if ( lError != ERROR_SUCCESS )
  4581. {
  4582. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create szPICSRULESEXPRESSIONRIGHT='%s' Key!", szPICSRULESEXPRESSIONRIGHT );
  4583. return(E_FAIL);
  4584. }
  4585. pPRSubPolicyExpressionToCopy=pPRPolicyExpressionBeingCopied->m_pPRPolicyExpressionRight;
  4586. if(FAILED(CopySubPolicyExpressionToRegistry(pPRSubPolicyExpressionToCopy, keyExpressionSubKey.m_hKey )))
  4587. {
  4588. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed RIGHT CopySubPolicyExpressionToRegistry() Call!" );
  4589. return(E_FAIL);
  4590. }
  4591. }
  4592. }
  4593. }
  4594. }
  4595. if(pPRRSBeingCopied->m_arrpPRServiceInfo.Length()>0)
  4596. {
  4597. CRegKey keySubKey;
  4598. DWORD dwSubCounter;
  4599. lError = keySubKey.Create( hKey, szPICSRULESSERVICEINFO );
  4600. if ( lError != ERROR_SUCCESS )
  4601. {
  4602. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create szPICSRULESSERVICEINFO='%s' Key!", szPICSRULESSERVICEINFO );
  4603. return(E_FAIL);
  4604. }
  4605. etn.Set(pPRRSBeingCopied->m_arrpPRServiceInfo.Length());
  4606. EtNumRegWriteCipher( etn, keySubKey.m_hKey, (char *) &szPICSRULESNUMSERVICEINFO );
  4607. for(dwSubCounter=0;dwSubCounter<(DWORD) (pPRRSBeingCopied->m_arrpPRServiceInfo.Length());dwSubCounter++)
  4608. {
  4609. CRegKey keyCopy;
  4610. wsprintf(szNumber,"%d",dwSubCounter);
  4611. lError = keyCopy.Create( keySubKey.m_hKey, szNumber );
  4612. if ( lError != ERROR_SUCCESS )
  4613. {
  4614. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create m_arrpPRServiceInfo szNumber='%s' Key!", szNumber );
  4615. return(E_FAIL);
  4616. }
  4617. pPRServiceInfoBeingCopied=pPRRSBeingCopied->m_arrpPRServiceInfo[dwSubCounter];
  4618. EtStringRegWriteCipher( pPRServiceInfoBeingCopied->m_prURLName, keyCopy.m_hKey, (char *) &szPICSRULESSIURLNAME );
  4619. EtStringRegWriteCipher( pPRServiceInfoBeingCopied->m_prURLBureauURL, keyCopy.m_hKey, (char *) &szPICSRULESSIBUREAUURL );
  4620. EtStringRegWriteCipher( pPRServiceInfoBeingCopied->m_etstrShortName, keyCopy.m_hKey, (char *) &szPICSRULESSISHORTNAME );
  4621. EtStringRegWriteCipher( pPRServiceInfoBeingCopied->m_etstrRatfile, keyCopy.m_hKey, (char *) &szPICSRULESSIRATFILE );
  4622. etb.Set(pPRServiceInfoBeingCopied->m_prYesNoUseEmbedded.GetYesNo());
  4623. EtBoolRegWriteCipher( etb, keyCopy.m_hKey,(char *) &szPICSRULESSIUSEEMBEDDED );
  4624. etb.Set(pPRServiceInfoBeingCopied->m_prPassFailBureauUnavailable.GetPassFail());
  4625. EtBoolRegWriteCipher( etb, keyCopy.m_hKey,(char *) &szPICSRULESSIBUREAUUNAVAILABLE );
  4626. }
  4627. }
  4628. if(pPRRSBeingCopied->m_arrpPROptExtension.Length()>0)
  4629. {
  4630. CRegKey keySubKey;
  4631. DWORD dwSubCounter;
  4632. lError = keySubKey.Create( hKey, szPICSRULESOPTEXTENSION );
  4633. if ( lError != ERROR_SUCCESS )
  4634. {
  4635. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create szPICSRULESOPTEXTENSION='%s' Key!", szPICSRULESOPTEXTENSION );
  4636. return(E_FAIL);
  4637. }
  4638. etn.Set(pPRRSBeingCopied->m_arrpPROptExtension.Length());
  4639. EtNumRegWriteCipher( etn, keySubKey.m_hKey, (char *) &szPICSRULESNUMOPTEXTENSIONS );
  4640. for(dwSubCounter=0;dwSubCounter<(DWORD) (pPRRSBeingCopied->m_arrpPROptExtension.Length());dwSubCounter++)
  4641. {
  4642. CRegKey keyCopy;
  4643. wsprintf(szNumber,"%d",dwSubCounter);
  4644. lError = keyCopy.Create( keySubKey.m_hKey, szNumber );
  4645. if ( lError != ERROR_SUCCESS )
  4646. {
  4647. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create m_arrpPROptExtension szNumber='%s' Key!", szNumber );
  4648. return(E_FAIL);
  4649. }
  4650. pPROptExtensionBeingCopied=pPRRSBeingCopied->m_arrpPROptExtension[dwSubCounter];
  4651. EtStringRegWriteCipher( pPROptExtensionBeingCopied->m_prURLExtensionName, keyCopy.m_hKey, (char *) &szPICSRULESOPTEXTNAME );
  4652. EtStringRegWriteCipher( pPROptExtensionBeingCopied->m_etstrShortName, keyCopy.m_hKey, (char *) &szPICSRULESOPTEXTSHORTNAME );
  4653. }
  4654. }
  4655. if(pPRRSBeingCopied->m_arrpPRReqExtension.Length()>0)
  4656. {
  4657. CRegKey keySubKey;
  4658. DWORD dwSubCounter;
  4659. lError = keySubKey.Create( hKey, szPICSRULESREQEXTENSION );
  4660. if ( lError != ERROR_SUCCESS )
  4661. {
  4662. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create szPICSRULESREQEXTENSION='%s' Key!", szPICSRULESREQEXTENSION );
  4663. return(E_FAIL);
  4664. }
  4665. etn.Set(pPRRSBeingCopied->m_arrpPRReqExtension.Length());
  4666. EtNumRegWriteCipher( etn, keySubKey.m_hKey, (char *) &szPICSRULESNUMREQEXTENSIONS );
  4667. for(dwSubCounter=0;dwSubCounter<(DWORD) (pPRRSBeingCopied->m_arrpPRReqExtension.Length());dwSubCounter++)
  4668. {
  4669. CRegKey keyCopy;
  4670. wsprintf(szNumber,"%d",dwSubCounter);
  4671. lError = keyCopy.Create( keySubKey.m_hKey, szNumber );
  4672. if ( lError != ERROR_SUCCESS )
  4673. {
  4674. TraceMsg( TF_WARNING, "WriteSystemToRegistry() - Failed to Create m_arrpPRReqExtension szNumber='%s' Key!", szNumber );
  4675. return(E_FAIL);
  4676. }
  4677. pPRReqExtensionBeingCopied=pPRRSBeingCopied->m_arrpPRReqExtension[dwSubCounter];
  4678. EtStringRegWriteCipher( pPRReqExtensionBeingCopied->m_prURLExtensionName, keyCopy.m_hKey, (char *) &szPICSRULESREQEXTNAME );
  4679. EtStringRegWriteCipher( pPRReqExtensionBeingCopied->m_etstrShortName, keyCopy.m_hKey, (char *) &szPICSRULESREQEXTSHORTNAME );
  4680. }
  4681. }
  4682. TraceMsg( TF_ALWAYS, "WriteSystemToRegistry() - Successfully Created PICS Rules in Registry!" );
  4683. return(NOERROR);
  4684. }
  4685. //*******************************************************************
  4686. //*
  4687. //* Code for saving and reading processed PICSRules from the registry
  4688. //*
  4689. //*******************************************************************
  4690. HRESULT WritePICSRulesToRegistry(LPCTSTR lpszUserName,HKEY hkeyUser,DWORD dwSystemToSave,PICSRulesRatingSystem **ppPRRS)
  4691. {
  4692. long lError;
  4693. char *lpszSystemNumber;
  4694. HRESULT hRes;
  4695. lpszSystemNumber=(char *) GlobalAlloc(GPTR,MAX_PATH);
  4696. if(lpszSystemNumber==NULL)
  4697. {
  4698. TraceMsg( TF_WARNING, "WritePICSRulesToRegistry() - lpszSystemNumber is NULL!" );
  4699. return(E_OUTOFMEMORY);
  4700. }
  4701. CRegKey keyWrite;
  4702. lError = keyWrite.Create( hkeyUser, lpszUserName );
  4703. if ( lError != ERROR_SUCCESS )
  4704. {
  4705. TraceMsg( TF_WARNING, "WritePICSRulesToRegistry() - Failed to Create lpszUserName='%s' Key!", lpszUserName );
  4706. return(E_FAIL);
  4707. }
  4708. wsprintf(lpszSystemNumber,"%d",dwSystemToSave);
  4709. CRegKey keyNumbered;
  4710. lError = keyNumbered.Create( keyWrite.m_hKey, lpszSystemNumber );
  4711. if ( lError != ERROR_SUCCESS )
  4712. {
  4713. TraceMsg( TF_WARNING, "WritePICSRulesToRegistry() - Failed to Create lpszSystemNumber='%s' Key!", lpszSystemNumber );
  4714. return(E_FAIL);
  4715. }
  4716. hRes = WriteSystemToRegistry( keyNumbered.m_hKey, ppPRRS );
  4717. GlobalFree(lpszSystemNumber);
  4718. lpszSystemNumber = NULL;
  4719. return(hRes);
  4720. }
  4721. HRESULT PICSRulesSaveToRegistry(DWORD dwSystemToSave,PICSRulesRatingSystem **ppPRRS)
  4722. {
  4723. HRESULT hRes;
  4724. CRegistryHive rh;
  4725. CRegKey keyUser;
  4726. if(!(gPRSI->fSettingsValid)||!(gPRSI->fRatingInstalled))
  4727. {
  4728. return(E_INVALIDARG); //there isn't a valid ratings system to save to
  4729. }
  4730. //load the hive file
  4731. if ( gPRSI->fStoreInRegistry )
  4732. {
  4733. keyUser.Create( HKEY_LOCAL_MACHINE, szPICSRULESSYSTEMS );
  4734. }
  4735. else
  4736. {
  4737. if ( rh.OpenHiveFile( true ) )
  4738. {
  4739. keyUser.Create( rh.GetHiveKey().m_hKey, szPICSRULESSYSTEMS );
  4740. }
  4741. }
  4742. //write information to the registry
  4743. if ( keyUser.m_hKey != NULL )
  4744. {
  4745. LPCTSTR lpszUsername;
  4746. lpszUsername=gPRSI->pUserObject->nlsUsername.QueryPch();
  4747. hRes = WritePICSRulesToRegistry( lpszUsername, keyUser.m_hKey, dwSystemToSave, ppPRRS );
  4748. keyUser.Close();
  4749. if ( FAILED(hRes) )
  4750. {
  4751. TraceMsg( TF_WARNING, "PICSRulesSaveToRegistry() - WritePICSRulesToRegistry Failed with hRes=0x%x!", hRes );
  4752. return(hRes);
  4753. }
  4754. }
  4755. else
  4756. {
  4757. // failed to create the registry key
  4758. hRes = E_FAIL;
  4759. }
  4760. return(hRes);
  4761. }
  4762. HRESULT PICSRulesReadFromRegistry(DWORD dwSystemToRead, PICSRulesRatingSystem **ppPRRS)
  4763. {
  4764. long lError;
  4765. if(!(gPRSI->fSettingsValid)||!(gPRSI->fRatingInstalled))
  4766. {
  4767. return(E_INVALIDARG); //there isn't a valid ratings system to read from
  4768. }
  4769. CRegistryHive rh;
  4770. CRegKey keyUser;
  4771. //load the hive file
  4772. if(gPRSI->fStoreInRegistry)
  4773. {
  4774. lError = keyUser.Open( HKEY_LOCAL_MACHINE, szPICSRULESSYSTEMS, KEY_READ );
  4775. }
  4776. else
  4777. {
  4778. if ( rh.OpenHiveFile( false ) )
  4779. {
  4780. ASSERT( rh.GetHiveKey().m_hKey != NULL );
  4781. lError = keyUser.Open( rh.GetHiveKey().m_hKey, szPICSRULESSYSTEMS, KEY_READ );
  4782. }
  4783. }
  4784. //read information from the registry
  4785. if ( keyUser.m_hKey != NULL )
  4786. {
  4787. LPCTSTR lpszUsername;
  4788. TCHAR szSystem[20];
  4789. lpszUsername=gPRSI->pUserObject->nlsUsername.QueryPch();
  4790. CRegKey keyWrite;
  4791. lError = keyWrite.Open( keyUser.m_hKey, lpszUsername, KEY_READ );
  4792. if(lError!=ERROR_SUCCESS)
  4793. {
  4794. TraceMsg( TF_WARNING, "PICSRulesReadFromRegistry() - Failed keyWrite lpszUsername='%s' Key Open!", lpszUsername );
  4795. keyUser.Close();
  4796. return(E_FAIL);
  4797. }
  4798. wnsprintf(szSystem,ARRAYSIZE(szSystem),"%d",dwSystemToRead);
  4799. CRegKey keySystem;
  4800. lError = keySystem.Open( keyWrite.m_hKey, szSystem, KEY_READ );
  4801. if ( lError != ERROR_SUCCESS )
  4802. {
  4803. TraceMsg( TF_WARNING, "PICSRulesReadFromRegistry() - Failed keySystem lpszSystem='%s' Key Open!", szSystem );
  4804. }
  4805. if( lError != ERROR_SUCCESS )
  4806. {
  4807. keyWrite.Close();
  4808. keyUser.Close();
  4809. return(E_FAIL);
  4810. }
  4811. HRESULT hr = ReadSystemFromRegistry( keySystem.m_hKey, ppPRRS );
  4812. keySystem.Close();
  4813. keyWrite.Close();
  4814. keyUser.Close();
  4815. if ( FAILED( hr ) )
  4816. {
  4817. TraceMsg( TF_WARNING, "PICSRulesReadFromRegistry() - Failed ReadSystemFromRegistry()!" );
  4818. return(E_FAIL);
  4819. }
  4820. }
  4821. return(S_OK);
  4822. }
  4823. HRESULT PICSRulesDeleteSystem(DWORD dwSystemToDelete)
  4824. {
  4825. long lError;
  4826. char * lpszSystem;
  4827. CRegistryHive rh;
  4828. CRegKey keyUser;
  4829. if(!(gPRSI->fSettingsValid)||!(gPRSI->fRatingInstalled))
  4830. {
  4831. return(E_INVALIDARG); //there isn't a valid ratings system to read from
  4832. }
  4833. //load the hive file
  4834. if ( gPRSI->fStoreInRegistry )
  4835. {
  4836. keyUser.Create( HKEY_LOCAL_MACHINE, szPICSRULESSYSTEMS );
  4837. }
  4838. else
  4839. {
  4840. if ( rh.OpenHiveFile( true ) )
  4841. {
  4842. keyUser.Create( rh.GetHiveKey().m_hKey, szPICSRULESSYSTEMS );
  4843. }
  4844. }
  4845. //delete information from the registry
  4846. if ( keyUser.m_hKey != NULL )
  4847. {
  4848. CRegKey keyWrite;
  4849. LPCTSTR lpszUsername;
  4850. lpszUsername = gPRSI->pUserObject->nlsUsername.QueryPch();
  4851. lError = keyWrite.Create( keyUser.m_hKey, lpszUsername );
  4852. if ( lError != ERROR_SUCCESS )
  4853. {
  4854. TraceMsg( TF_WARNING, "PICSRulesDeleteSystem() - Failed to Create lpszUsername='%s' Key!", lpszUsername );
  4855. keyUser.Close();
  4856. return(E_FAIL);
  4857. }
  4858. lpszSystem=(char *) GlobalAlloc(GPTR,MAX_PATH);
  4859. wsprintf(lpszSystem,"%d",dwSystemToDelete);
  4860. MyRegDeleteKey( keyWrite.m_hKey, lpszSystem );
  4861. GlobalFree(lpszSystem);
  4862. lpszSystem = NULL;
  4863. keyWrite.Close();
  4864. keyUser.Close();
  4865. }
  4866. return(NOERROR);
  4867. }
  4868. HRESULT PICSRulesGetNumSystems(DWORD * pdwNumSystems)
  4869. {
  4870. long lError;
  4871. if (pdwNumSystems)
  4872. {
  4873. *pdwNumSystems = 0;
  4874. }
  4875. if(!(gPRSI->fSettingsValid)||!(gPRSI->fRatingInstalled))
  4876. {
  4877. return(E_INVALIDARG); //there isn't a valid ratings system to read from
  4878. }
  4879. CRegistryHive rh;
  4880. CRegKey keyUser;
  4881. //load the hive file
  4882. if(gPRSI->fStoreInRegistry)
  4883. {
  4884. keyUser.Open( HKEY_LOCAL_MACHINE, szPICSRULESSYSTEMS, KEY_READ );
  4885. }
  4886. else
  4887. {
  4888. if ( rh.OpenHiveFile( false ) )
  4889. {
  4890. ASSERT( rh.GetHiveKey().m_hKey != NULL );
  4891. keyUser.Open( rh.GetHiveKey().m_hKey, szPICSRULESSYSTEMS, KEY_READ );
  4892. }
  4893. }
  4894. //read information from the registry
  4895. if ( keyUser.m_hKey != NULL )
  4896. {
  4897. LPCTSTR lpszUsername;
  4898. lpszUsername=gPRSI->pUserObject->nlsUsername.QueryPch();
  4899. CRegKey keyWrite;
  4900. lError = keyWrite.Open( keyUser.m_hKey, lpszUsername, KEY_READ );
  4901. if(lError!=ERROR_SUCCESS)
  4902. {
  4903. TraceMsg( TF_WARNING, "PICSRulesGetNumSystems() - Failed keyWrite lpszUsername='%s' Key Open!", lpszUsername );
  4904. return(E_FAIL);
  4905. }
  4906. DWORD dwNumSystems;
  4907. if ( keyWrite.QueryValue( dwNumSystems, szPICSRULESNUMSYS ) != ERROR_SUCCESS )
  4908. {
  4909. //no value set, so we have zero systems installed
  4910. *pdwNumSystems = 0;
  4911. }
  4912. else
  4913. {
  4914. *pdwNumSystems = dwNumSystems;
  4915. }
  4916. keyWrite.Close();
  4917. keyUser.Close();
  4918. }
  4919. return(NOERROR);
  4920. }
  4921. HRESULT PICSRulesSetNumSystems(DWORD dwNumSystems)
  4922. {
  4923. long lError;
  4924. if(!(gPRSI->fSettingsValid)||!(gPRSI->fRatingInstalled))
  4925. {
  4926. return(E_INVALIDARG); //there isn't a valid ratings system to save to
  4927. }
  4928. CRegistryHive rh;
  4929. CRegKey keyUser;
  4930. //load the hive file
  4931. if(gPRSI->fStoreInRegistry)
  4932. {
  4933. keyUser.Create( HKEY_LOCAL_MACHINE, szPICSRULESSYSTEMS );
  4934. }
  4935. else
  4936. {
  4937. if ( rh.OpenHiveFile( true ) )
  4938. {
  4939. ASSERT( rh.GetHiveKey().m_hKey != NULL );
  4940. keyUser.Create( rh.GetHiveKey().m_hKey, szPICSRULESSYSTEMS );
  4941. }
  4942. }
  4943. //write information to the registry
  4944. if ( keyUser.m_hKey != NULL )
  4945. {
  4946. CRegKey keyWrite;
  4947. LPCTSTR lpszUsername;
  4948. lpszUsername=gPRSI->pUserObject->nlsUsername.QueryPch();
  4949. lError = keyWrite.Create( keyUser.m_hKey, lpszUsername );
  4950. if(lError!=ERROR_SUCCESS)
  4951. {
  4952. TraceMsg( TF_WARNING, "PICSRulesSetNumSystems() - Failed to Create keyWrite lpszUsername='%s' Key!", lpszUsername );
  4953. keyUser.Close();
  4954. return(E_FAIL);
  4955. }
  4956. lError = keyWrite.SetValue( dwNumSystems, szPICSRULESNUMSYS );
  4957. keyWrite.Close();
  4958. keyUser.Close();
  4959. if ( lError != ERROR_SUCCESS )
  4960. {
  4961. TraceMsg( TF_WARNING, "PICSRulesSetNumSystems() - Failed to Set keyWrite dwNumSystems='%d' Value!", dwNumSystems );
  4962. return(E_FAIL);
  4963. }
  4964. }
  4965. return(NOERROR);
  4966. }
  4967. HRESULT PICSRulesCheckApprovedSitesAccess(LPCSTR lpszUrl,BOOL *fPassFail)
  4968. {
  4969. int iCounter;
  4970. PICSRulesEvaluation PREvaluation = PR_EVALUATION_DOESNOTAPPLY;
  4971. if(g_pApprovedPRRS==NULL)
  4972. {
  4973. return(E_FAIL);
  4974. }
  4975. if(g_lApprovedSitesGlobalCounterValue!=SHGlobalCounterGetValue(g_ApprovedSitesHandleGlobalCounter))
  4976. {
  4977. PICSRulesRatingSystem * pPRRS=NULL;
  4978. HRESULT hRes;
  4979. hRes=PICSRulesReadFromRegistry(PICSRULES_APPROVEDSITES,&pPRRS);
  4980. if(SUCCEEDED(hRes))
  4981. {
  4982. if(g_pApprovedPRRS!=NULL)
  4983. {
  4984. delete g_pApprovedPRRS;
  4985. }
  4986. g_pApprovedPRRS=pPRRS;
  4987. }
  4988. g_lApprovedSitesGlobalCounterValue=SHGlobalCounterGetValue(g_ApprovedSitesHandleGlobalCounter);
  4989. }
  4990. for(iCounter=0;iCounter<g_pApprovedPRRS->m_arrpPRPolicy.Length();iCounter++)
  4991. {
  4992. PICSRulesPolicy * pPRPolicy;
  4993. PICSRulesByURL * pPRByURL;
  4994. PICSRulesQuotedURL PRQuotedURL;
  4995. pPRPolicy=g_pApprovedPRRS->m_arrpPRPolicy[iCounter];
  4996. if(pPRPolicy->m_PRPolicyAttribute==PR_POLICY_ACCEPTBYURL)
  4997. {
  4998. *fPassFail=PR_PASSFAIL_PASS;
  4999. pPRByURL=pPRPolicy->m_pPRAcceptByURL;
  5000. }
  5001. else
  5002. {
  5003. *fPassFail=PR_PASSFAIL_FAIL;
  5004. pPRByURL=pPRPolicy->m_pPRRejectByURL;
  5005. }
  5006. PRQuotedURL.Set(lpszUrl);
  5007. PREvaluation=pPRByURL->EvaluateRule(&PRQuotedURL);
  5008. if(PREvaluation!=PR_EVALUATION_DOESNOTAPPLY)
  5009. {
  5010. break;
  5011. }
  5012. }
  5013. if(PREvaluation==PR_EVALUATION_DOESAPPLY)
  5014. {
  5015. return(S_OK);
  5016. }
  5017. else
  5018. {
  5019. return(E_FAIL);
  5020. }
  5021. }
  5022. HRESULT PICSRulesCheckAccess(LPCSTR lpszUrl,LPCSTR lpszRatingInfo,BOOL *fPassFail,CParsedLabelList **ppParsed)
  5023. {
  5024. int iCounter,iSystemCounter;
  5025. PICSRulesEvaluation PREvaluation;
  5026. CParsedLabelList *pParsed=NULL;
  5027. if(g_arrpPRRS.Length()==0)
  5028. {
  5029. return(E_FAIL);
  5030. }
  5031. if(g_lGlobalCounterValue!=SHGlobalCounterGetValue(g_HandleGlobalCounter))
  5032. {
  5033. HRESULT hRes;
  5034. DWORD dwNumSystems;
  5035. PICSRulesRatingSystem * pPRRS=NULL;
  5036. g_arrpPRRS.DeleteAll();
  5037. //someone modified our settings, so we'd better reload them.
  5038. hRes=PICSRulesGetNumSystems(&dwNumSystems);
  5039. if(SUCCEEDED(hRes))
  5040. {
  5041. DWORD dwCounter;
  5042. for(dwCounter=PICSRULES_FIRSTSYSTEMINDEX;
  5043. dwCounter<(dwNumSystems+PICSRULES_FIRSTSYSTEMINDEX);
  5044. dwCounter++)
  5045. {
  5046. hRes=PICSRulesReadFromRegistry(dwCounter,&pPRRS);
  5047. if(FAILED(hRes))
  5048. {
  5049. char *lpszTitle,*lpszMessage;
  5050. //we couldn't read in the systems, so don't inforce PICSRules,
  5051. //and notify the user
  5052. g_arrpPRRS.DeleteAll();
  5053. lpszTitle=(char *) GlobalAlloc(GPTR,MAX_PATH);
  5054. lpszMessage=(char *) GlobalAlloc(GPTR,MAX_PATH);
  5055. MLLoadString(IDS_PICSRULES_TAMPEREDREADTITLE,(LPTSTR) lpszTitle,MAX_PATH);
  5056. MLLoadString(IDS_PICSRULES_TAMPEREDREADMSG,(LPTSTR) lpszMessage,MAX_PATH);
  5057. MessageBox(NULL,(LPCTSTR) lpszMessage,(LPCTSTR) lpszTitle,MB_OK|MB_ICONERROR);
  5058. GlobalFree(lpszTitle);
  5059. lpszTitle = NULL;
  5060. GlobalFree(lpszMessage);
  5061. lpszMessage = NULL;
  5062. break;
  5063. }
  5064. else
  5065. {
  5066. g_arrpPRRS.Append(pPRRS);
  5067. pPRRS=NULL;
  5068. }
  5069. }
  5070. }
  5071. g_lGlobalCounterValue=SHGlobalCounterGetValue(g_HandleGlobalCounter);
  5072. }
  5073. if(lpszRatingInfo!=NULL)
  5074. {
  5075. ParseLabelList(lpszRatingInfo,ppParsed);
  5076. pParsed=*ppParsed;
  5077. }
  5078. for(iSystemCounter=0;iSystemCounter<g_arrpPRRS.Length();iSystemCounter++)
  5079. {
  5080. PICSRulesRatingSystem * pPRRSCheck;
  5081. pPRRSCheck=g_arrpPRRS[iSystemCounter];
  5082. for(iCounter=0;iCounter<pPRRSCheck->m_arrpPRPolicy.Length();iCounter++)
  5083. {
  5084. PICSRulesPolicy * pPRPolicy;
  5085. PICSRulesPolicyExpression * pPRPolicyExpression;
  5086. PICSRulesByURL * pPRByURL;
  5087. PICSRulesQuotedURL PRQuotedURL;
  5088. pPRPolicy=pPRRSCheck->m_arrpPRPolicy[iCounter];
  5089. switch(pPRPolicy->m_PRPolicyAttribute)
  5090. {
  5091. case PR_POLICY_ACCEPTBYURL:
  5092. {
  5093. *fPassFail=PR_PASSFAIL_PASS;
  5094. pPRByURL=pPRPolicy->m_pPRAcceptByURL;
  5095. PRQuotedURL.Set(lpszUrl);
  5096. PREvaluation=pPRByURL->EvaluateRule(&PRQuotedURL);
  5097. break;
  5098. }
  5099. case PR_POLICY_REJECTBYURL:
  5100. {
  5101. *fPassFail=PR_PASSFAIL_FAIL;
  5102. pPRByURL=pPRPolicy->m_pPRRejectByURL;
  5103. PRQuotedURL.Set(lpszUrl);
  5104. PREvaluation=pPRByURL->EvaluateRule(&PRQuotedURL);
  5105. break;
  5106. }
  5107. case PR_POLICY_REJECTIF:
  5108. {
  5109. *fPassFail=PR_PASSFAIL_FAIL;
  5110. pPRPolicyExpression=pPRPolicy->m_pPRRejectIf;
  5111. PREvaluation=pPRPolicyExpression->EvaluateRule(pParsed);
  5112. break;
  5113. }
  5114. case PR_POLICY_ACCEPTIF:
  5115. {
  5116. *fPassFail=PR_PASSFAIL_PASS;
  5117. pPRPolicyExpression=pPRPolicy->m_pPRAcceptIf;
  5118. PREvaluation=pPRPolicyExpression->EvaluateRule(pParsed);
  5119. break;
  5120. }
  5121. case PR_POLICY_REJECTUNLESS:
  5122. {
  5123. *fPassFail=PR_PASSFAIL_FAIL;
  5124. pPRPolicyExpression=pPRPolicy->m_pPRRejectUnless;
  5125. PREvaluation=pPRPolicyExpression->EvaluateRule(pParsed);
  5126. if(PREvaluation==PR_EVALUATION_DOESNOTAPPLY)
  5127. {
  5128. PREvaluation=PR_EVALUATION_DOESAPPLY;
  5129. }
  5130. else
  5131. {
  5132. PREvaluation=PR_EVALUATION_DOESNOTAPPLY;
  5133. }
  5134. break;
  5135. }
  5136. case PR_POLICY_ACCEPTUNLESS:
  5137. {
  5138. *fPassFail=PR_PASSFAIL_PASS;
  5139. pPRPolicyExpression=pPRPolicy->m_pPRAcceptUnless;
  5140. PREvaluation=pPRPolicyExpression->EvaluateRule(pParsed);
  5141. if(PREvaluation==PR_EVALUATION_DOESNOTAPPLY)
  5142. {
  5143. PREvaluation=PR_EVALUATION_DOESAPPLY;
  5144. }
  5145. else
  5146. {
  5147. PREvaluation=PR_EVALUATION_DOESNOTAPPLY;
  5148. }
  5149. break;
  5150. }
  5151. case PR_POLICY_NONEVALID:
  5152. default:
  5153. {
  5154. PREvaluation=PR_EVALUATION_DOESNOTAPPLY;
  5155. continue;
  5156. }
  5157. }
  5158. if(PREvaluation!=PR_EVALUATION_DOESNOTAPPLY)
  5159. {
  5160. break;
  5161. }
  5162. }
  5163. if(PREvaluation!=PR_EVALUATION_DOESNOTAPPLY)
  5164. {
  5165. break;
  5166. }
  5167. }
  5168. if(PREvaluation==PR_EVALUATION_DOESAPPLY)
  5169. {
  5170. return(S_OK);
  5171. }
  5172. else
  5173. {
  5174. return(E_FAIL);
  5175. }
  5176. }