Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

513 lines
16 KiB

  1. //*******************************************************************
  2. //*
  3. //* PICSRule.h
  4. //*
  5. //* Revision History:
  6. //* Created 7/98 - Mark Hammond (t-markh)
  7. //*
  8. //* Contains classes and function prototypes
  9. //* used for processing PICSRules files.
  10. //*
  11. //*******************************************************************
  12. #ifndef PICS_RULE_H
  13. #define PICS_RULE_H
  14. //*******************************************************************
  15. //*
  16. //* Function Prototypes / class declarations
  17. //*
  18. //*******************************************************************
  19. //Forward class declarations
  20. class PICSRulesQuotedURL;
  21. class PICSRulesQuotedEmail;
  22. class PICSRulesQuotedDate;
  23. class PICSRulesYesNo;
  24. class PICSRulesPassFail;
  25. class PICSRulesPolicyExpression;
  26. class PICSRulesByURL;
  27. class PICSRulesPolicy;
  28. class PICSRulesName;
  29. class PICSRulesSource;
  30. class PICSRulesServiceInfo;
  31. class PICSRulesOptExtension;
  32. class PICSRulesReqExtension;
  33. class PICSRulesFileParser;
  34. class PICSRulesRatingSystem;
  35. class CParsedLabelList;
  36. //This function is called by ApprovedSitesDlgProc while processing
  37. //WM_COMMOND with LOWORD(wParam)==IDC_PICSRULESOPEN in msludlg.cpp
  38. //The argument lpszFileName is the name of the PICSRules file
  39. //selected by the user to import.
  40. //
  41. //This begins the PICSRules Import process.
  42. HRESULT PICSRulesImport(char *lpszFileName, PICSRulesRatingSystem **pprrsOut);
  43. //For reading and saving processed PICSRules from the registry
  44. HRESULT PICSRulesSaveToRegistry(DWORD dwSystemToSave, PICSRulesRatingSystem **ppPRRS);
  45. HRESULT PICSRulesReadFromRegistry(DWORD dwSystemToRead, PICSRulesRatingSystem **ppPRRS);
  46. HRESULT PICSRulesDeleteSystem(DWORD dwSystemToDelete);
  47. HRESULT PICSRulesSetNumSystems(DWORD dwNumSystems);
  48. HRESULT PICSRulesGetNumSystems(DWORD * pdwNumSystems);
  49. HRESULT PICSRulesCheckApprovedSitesAccess(LPCSTR lpszUrl,BOOL *fPassFail);
  50. HRESULT PICSRulesCheckAccess(LPCSTR lpszUrl,LPCSTR lpszRatingInfo,BOOL *fPassFail,CParsedLabelList **ppParsed);
  51. void PICSRulesOutOfMemory();
  52. //The following are handler functions which parse the various
  53. //kinds of content which can occur within a parenthesized object.
  54. //
  55. //ppszIn is always advanced to the next non-white space token
  56. //ppszOut returns the processed data
  57. HRESULT PICSRulesParseString(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser);
  58. HRESULT PICSRulesParseNumber(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser);
  59. HRESULT PICSRulesParseYesNo(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser);
  60. HRESULT PICSRulesParsePassFail(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser);
  61. BOOL IsURLValid(WCHAR wcszURL[]);
  62. //*******************************************************************
  63. //*
  64. //* Definitions used by the PICSRules code
  65. //*
  66. //*******************************************************************
  67. #define PR_QUOTE_DOUBLE 1
  68. #define PR_QUOTE_SINGLE 0
  69. #define BYURL_SCHEME 1
  70. #define BYURL_USER 2
  71. #define BYURL_HOST 4
  72. #define BYURL_PORT 8
  73. #define BYURL_PATH 16
  74. #define PICSRULES_FIRSTSYSTEMINDEX 100
  75. #define PICSRULES_MAXSYSTEM 1000000
  76. #define PICSRULES_APPROVEDSITES 0
  77. #define PICSRULES_ALWAYS 1
  78. #define PICSRULES_NEVER 0
  79. #define PICSRULES_PAGE 1
  80. #define PICSRULES_SITE 0
  81. #define PICS_LABEL_FROM_HEADER 0
  82. #define PICS_LABEL_FROM_PAGE 1
  83. #define PICS_LABEL_FROM_BUREAU 2
  84. struct PICSRULES_VERSION
  85. {
  86. int iPICSRulesVerMajor,iPICSRulesVerMinor;
  87. };
  88. //Data types for the necessary logic in evaluating
  89. //the rules.
  90. enum PICSRulesOperators
  91. {
  92. PR_OPERATOR_INVALID,
  93. PR_OPERATOR_GREATEROREQUAL,
  94. PR_OPERATOR_GREATER,
  95. PR_OPERATOR_EQUAL,
  96. PR_OPERATOR_LESSOREQUAL,
  97. PR_OPERATOR_LESS,
  98. PR_OPERATOR_DEGENERATE,
  99. PR_OPERATOR_SERVICEONLY,
  100. PR_OPERATOR_SERVICEANDCATEGORY,
  101. PR_OPERATOR_RESULT
  102. };
  103. enum PICSRulesEvaluation
  104. {
  105. PR_EVALUATION_DOESAPPLY,
  106. PR_EVALUATION_DOESNOTAPPLY
  107. };
  108. //This indicates which member is valid in a PICSRulesPolicy
  109. //Class
  110. enum PICSRulesPolicyAttribute
  111. {
  112. PR_POLICY_NONEVALID,
  113. PR_POLICY_REJECTBYURL,
  114. PR_POLICY_ACCEPTBYURL,
  115. PR_POLICY_REJECTIF,
  116. PR_POLICY_ACCEPTIF,
  117. PR_POLICY_REJECTUNLESS,
  118. PR_POLICY_ACCEPTUNLESS
  119. };
  120. //This indicates if a PolicyExpression is embedded in another
  121. //PolicyExpression, and if so, what logic to use.
  122. enum PICSRulesPolicyEmbedded
  123. {
  124. PR_POLICYEMBEDDED_NONE,
  125. PR_POLICYEMBEDDED_OR,
  126. PR_POLICYEMBEDDED_AND
  127. };
  128. //*******************************************************************
  129. //*
  130. //* Classes to handle possible value types... all derive from
  131. //* ETS (the encapsulated string type) since the are found as
  132. //* strings during processing.
  133. //*
  134. //* The Set() and SetTo() member functions are overloaded on the
  135. //* types which convert from a string. We want to keep the original
  136. //* string in case the data is invalid.
  137. //*
  138. //* Additional member functions are provided to assure that the
  139. //* data is what it says it is, and to return the non-string type.
  140. //*
  141. //*******************************************************************
  142. class PICSRulesByURLExpression
  143. {
  144. public:
  145. PICSRulesByURLExpression();
  146. ~PICSRulesByURLExpression();
  147. BOOL m_fInternetPattern;
  148. BYTE m_bNonWild,m_bSpecified;
  149. ETS m_etstrScheme,m_etstrUser,m_etstrHost,m_etstrPort,m_etstrPath,m_etstrURL;
  150. };
  151. class PICSRulesQuotedURL : public ETS
  152. {
  153. public:
  154. PICSRulesQuotedURL();
  155. ~PICSRulesQuotedURL();
  156. BOOL IsURLValid();
  157. BOOL IsURLValid(char * lpszURL);
  158. BOOL IsURLValid(ETS etstrURL);
  159. };
  160. class PICSRulesQuotedEmail : public ETS
  161. {
  162. public:
  163. PICSRulesQuotedEmail();
  164. ~PICSRulesQuotedEmail();
  165. BOOL IsEmailValid();
  166. BOOL IsEmailValid(char * lpszEmail);
  167. BOOL IsEmailValid(ETS etstrEmail);
  168. };
  169. class PICSRulesQuotedDate : public ETS
  170. {
  171. public:
  172. PICSRulesQuotedDate();
  173. ~PICSRulesQuotedDate();
  174. BOOL IsDateValid();
  175. BOOL IsDateValid(char * lpszDate);
  176. BOOL IsDateValid(ETS etstrDate);
  177. HRESULT Set(const char *pIn);
  178. HRESULT SetTo(char *pIn);
  179. DWORD GetDate()
  180. {
  181. return m_dwDate;
  182. };
  183. private:
  184. DWORD m_dwDate;
  185. };
  186. class PICSRulesYesNo : public ETS
  187. {
  188. public:
  189. PICSRulesYesNo();
  190. ~PICSRulesYesNo();
  191. void Set(const BOOL *pIn);
  192. void SetTo(BOOL *pIn);
  193. BOOL GetYesNo()
  194. {
  195. return m_fYesOrNo;
  196. };
  197. private:
  198. BOOL m_fYesOrNo;
  199. };
  200. class PICSRulesPassFail : public ETS
  201. {
  202. public:
  203. PICSRulesPassFail();
  204. ~PICSRulesPassFail();
  205. void Set(const BOOL *pIn);
  206. void SetTo(BOOL *pIn);
  207. BOOL GetPassFail()
  208. {
  209. return m_fPassOrFail;
  210. };
  211. private:
  212. BOOL m_fPassOrFail;
  213. };
  214. //*******************************************************************
  215. //*
  216. //* The PICSRulesPolicy class handles the "Policy" token
  217. //* from a PICSRules stream, and its attributes (square brackets
  218. //* denote the primary attribute):
  219. //*
  220. //* Policy (
  221. //* [Explanation] quoted
  222. //* RejectByURL URL | ( [patterns] URL )
  223. //* AcceptByURL URL | ( [patterns] URL )
  224. //* RejectIf PolicyExpression
  225. //* RejectUnless PolicyExpression
  226. //* AcceptIf PolicyExpression
  227. //* AcceptUnless PolicyExpression
  228. //* *Extension* )
  229. //*
  230. //*******************************************************************
  231. class PICSRulesPolicyExpression
  232. {
  233. public:
  234. PICSRulesPolicyExpression * m_pPRPolicyExpressionLeft,
  235. * m_pPRPolicyExpressionRight;
  236. ETS m_etstrServiceName,m_etstrCategoryName,
  237. m_etstrFullServiceName;
  238. ETN m_etnValue;
  239. PICSRulesYesNo m_prYesNoUseEmbedded;
  240. enum PICSRulesOperators m_PROPolicyOperator;
  241. enum PICSRulesPolicyEmbedded m_PRPEPolicyEmbedded;
  242. PICSRulesPolicyExpression();
  243. ~PICSRulesPolicyExpression();
  244. PICSRulesEvaluation EvaluateRule(CParsedLabelList *pParsed);
  245. };
  246. class PICSRulesByURL
  247. {
  248. public:
  249. array<PICSRulesByURLExpression*> m_arrpPRByURL;
  250. PICSRulesByURL();
  251. ~PICSRulesByURL();
  252. PICSRulesEvaluation EvaluateRule(PICSRulesQuotedURL *pprurlComparisonURL);
  253. };
  254. class PICSRulesPolicy : public PICSRulesObjectBase
  255. {
  256. public:
  257. ETS m_etstrExplanation;
  258. PICSRulesPolicyExpression * m_pPRRejectIf,* m_pPRRejectUnless,
  259. * m_pPRAcceptIf,* m_pPRAcceptUnless;
  260. PICSRulesByURL * m_pPRRejectByURL,* m_pPRAcceptByURL;
  261. PICSRulesPolicyAttribute m_PRPolicyAttribute;
  262. PICSRulesPolicy();
  263. ~PICSRulesPolicy();
  264. HRESULT AddItem(PICSRulesObjectID proid, LPVOID pData);
  265. HRESULT InitializeMyDefaults();
  266. };
  267. //*******************************************************************
  268. //*
  269. //* The PICSRulesName class handles the "name" token
  270. //* from a PICSRules stream, and its attributes (square brackets
  271. //* denote the primary attribute):
  272. //*
  273. //* name (
  274. //* [Rulename] quoted
  275. //* Description quoted
  276. //* *Extension* )
  277. //*
  278. //*******************************************************************
  279. class PICSRulesName : public PICSRulesObjectBase
  280. {
  281. public:
  282. ETS m_etstrRuleName,m_etstrDescription;
  283. PICSRulesName();
  284. ~PICSRulesName();
  285. HRESULT AddItem(PICSRulesObjectID proid, LPVOID pData);
  286. HRESULT InitializeMyDefaults();
  287. };
  288. //*******************************************************************
  289. //*
  290. //* The PICSRulesSource class handles the "source" token
  291. //* from a PICSRules stream, and its attributes (square brackets
  292. //* denote the primary attribute):
  293. //*
  294. //* source (
  295. //* [SourceURL] URL
  296. //* CreationTool quoted (has format toolname/version)
  297. //* author email
  298. //* LastModified ISO Date
  299. //* *Extension* )
  300. //*
  301. //*******************************************************************
  302. class PICSRulesSource : public PICSRulesObjectBase
  303. {
  304. public:
  305. PICSRulesQuotedURL m_prURLSourceURL;
  306. ETS m_etstrCreationTool;
  307. PICSRulesQuotedEmail m_prEmailAuthor;
  308. PICSRulesQuotedDate m_prDateLastModified;
  309. PICSRulesSource();
  310. ~PICSRulesSource();
  311. HRESULT AddItem(PICSRulesObjectID proid, LPVOID pData);
  312. HRESULT InitializeMyDefaults();
  313. char * GetToolName();
  314. };
  315. //*******************************************************************
  316. //*
  317. //* The PICSRulesServiceInfo class handles the "serviceinfo" token
  318. //* from a PICSRules stream, and its attributes (square brackets
  319. //* denote the primary attribute):
  320. //*
  321. //* The Ratfile attribute is either an entire machine readable .RAT
  322. //* file, or the URL where the .RAT file can be obtained.
  323. //*
  324. //* serviceinfo (
  325. //* [Name] URL
  326. //* shortname quoted
  327. //* BureauURL URL
  328. //* UseEmbedded Y|N
  329. //* Ratfile quoted
  330. //* BureauUnavailable PASS|FAIL
  331. //* *Extension* )
  332. //*
  333. //*******************************************************************
  334. class PICSRulesServiceInfo : public PICSRulesObjectBase
  335. {
  336. public:
  337. PICSRulesQuotedURL m_prURLName,m_prURLBureauURL;
  338. ETS m_etstrShortName,m_etstrRatfile;
  339. PICSRulesYesNo m_prYesNoUseEmbedded;
  340. PICSRulesPassFail m_prPassFailBureauUnavailable;
  341. PICSRulesServiceInfo();
  342. ~PICSRulesServiceInfo();
  343. HRESULT AddItem(PICSRulesObjectID proid, LPVOID pData);
  344. HRESULT InitializeMyDefaults();
  345. };
  346. //*******************************************************************
  347. //*
  348. //* The PICSRulesOptExtension class handles the "optextension" token
  349. //* from a PICSRules stream, and its attributes (square brackets
  350. //* denote the primary attribute):
  351. //*
  352. //* optextension (
  353. //* [extension-name] URL
  354. //* shortname quoted
  355. //* *Extension* )
  356. //*
  357. //*******************************************************************
  358. class PICSRulesOptExtension : public PICSRulesObjectBase
  359. {
  360. public:
  361. PICSRulesQuotedURL m_prURLExtensionName;
  362. ETS m_etstrShortName;
  363. PICSRulesOptExtension();
  364. ~PICSRulesOptExtension();
  365. HRESULT AddItem(PICSRulesObjectID proid, LPVOID pData);
  366. HRESULT InitializeMyDefaults();
  367. };
  368. //*******************************************************************
  369. //*
  370. //* The PICSRulesReqExtension class handles the "reqextension" token
  371. //* from a PICSRules stream, and its attributes (square brackets
  372. //* denote the primary attribute):
  373. //*
  374. //* reqextension (
  375. //* [extension-name] URL
  376. //* shortname quoted
  377. //* *Extension* )
  378. //*
  379. //*******************************************************************
  380. class PICSRulesReqExtension : public PICSRulesObjectBase
  381. {
  382. public:
  383. PICSRulesQuotedURL m_prURLExtensionName;
  384. ETS m_etstrShortName;
  385. PICSRulesReqExtension();
  386. ~PICSRulesReqExtension();
  387. HRESULT AddItem(PICSRulesObjectID proid, LPVOID pData);
  388. HRESULT InitializeMyDefaults();
  389. };
  390. //*******************************************************************
  391. //*
  392. //* The PICSRulesRatingSystem class encapsulates all of the
  393. //* information from a give PICSRules source. Multiple
  394. //* instantiations are created in the PicsRatingSystemInfo class,
  395. //* created at startup and stored in gPRSI.
  396. //*
  397. //*******************************************************************
  398. class PICSRulesRatingSystem : public PICSRulesObjectBase
  399. {
  400. public:
  401. array<PICSRulesPolicy*> m_arrpPRPolicy;
  402. array<PICSRulesServiceInfo*> m_arrpPRServiceInfo;
  403. array<PICSRulesOptExtension*> m_arrpPROptExtension;
  404. array<PICSRulesReqExtension*> m_arrpPRReqExtension;
  405. PICSRulesName * m_pPRName;
  406. PICSRulesSource * m_pPRSource;
  407. ETS m_etstrFile;
  408. ETN m_etnPRVerMajor,m_etnPRVerMinor;
  409. DWORD m_dwFlags;
  410. UINT m_nErrLine;
  411. PICSRulesRatingSystem();
  412. ~PICSRulesRatingSystem();
  413. HRESULT Parse(LPCSTR pszFile, LPSTR pStreamIn);
  414. HRESULT AddItem(PICSRulesObjectID roid, LPVOID pData);
  415. HRESULT InitializeMyDefaults();
  416. void ReportError(HRESULT hres);
  417. };
  418. //*******************************************************************
  419. //*
  420. //* The PICSRulesFileParser class exists to provide a line number
  421. //* shared by all the parsing routines. This line number is updated
  422. //* as the parser walks through the stream, and is frozen as soon as
  423. //* an error is found. This line number can later be reported to the
  424. //* user to help localize errors.
  425. //*
  426. //*******************************************************************
  427. class PICSRulesFileParser
  428. {
  429. public:
  430. UINT m_nLine;
  431. PICSRulesFileParser() { m_nLine = 1; }
  432. LPSTR EatQuotedString(LPSTR pIn,BOOL fQuote=PR_QUOTE_DOUBLE);
  433. HRESULT ParseToOpening(LPSTR *ppIn, PICSRulesAllowableOption *paoExpected,
  434. PICSRulesAllowableOption **ppFound);
  435. HRESULT ParseParenthesizedObject(
  436. LPSTR *ppIn, //where we are in the text stream
  437. PICSRulesAllowableOption aao[], //allowable things inside this object
  438. PICSRulesObjectBase *pObject //object to set parameters into
  439. );
  440. char* FindNonWhite(char *pc);
  441. };
  442. #endif