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.

501 lines
15 KiB

  1. /****************************************************************************\
  2. *
  3. * PICS.H --Structures for holding pics information
  4. *
  5. * Created: Jason Thomas
  6. * Updated: Ann McCurdy
  7. *
  8. \****************************************************************************/
  9. #ifndef _PICS_H_
  10. #define _PICS_H_
  11. /*Includes---------------------------------------------------------*/
  12. #include <npassert.h>
  13. #include "array.h"
  14. #include "resource.h"
  15. #include "msluglob.h"
  16. #include <ratings.h>
  17. extern HKEY CreateRegKeyNT(LPCSTR pszKey);
  18. extern BOOL RunningOnNT(void);
  19. extern char PicsDelimChar;
  20. #define PICS_FILE_BUF_LEN 20000
  21. #define PICS_STRING_BUF_LEN 1000
  22. #define P_INFINITY 9999
  23. #define N_INFINITY -9999
  24. /*Simple PICS types------------------------------------------------*/
  25. class ETN
  26. {
  27. private:
  28. int r;
  29. BOOL m_fInit;
  30. public:
  31. ETN() { m_fInit = FALSE; }
  32. void Init() { m_fInit = TRUE; }
  33. void UnInit() { m_fInit = FALSE; }
  34. BOOL fIsInit() { return m_fInit; }
  35. #ifdef DEBUG
  36. void Set(int rIn);
  37. int Get();
  38. #else
  39. void Set(int rIn) { Init(); r = rIn; }
  40. int Get() { return r; }
  41. #endif
  42. ETN* Duplicate();
  43. };
  44. const UINT ETB_VALUE = 0x01;
  45. const UINT ETB_ISINIT = 0x02;
  46. class ETB
  47. {
  48. private:
  49. UINT m_nFlags;
  50. public:
  51. ETB() { m_nFlags = 0; }
  52. #ifdef DEBUG
  53. BOOL Get();
  54. void Set(BOOL b);
  55. #else
  56. BOOL Get() { return m_nFlags & ETB_VALUE; }
  57. void Set(BOOL b) { m_nFlags = ETB_ISINIT | (b ? ETB_VALUE : 0); }
  58. #endif
  59. ETB *Duplicate();
  60. BOOL fIsInit() { return m_nFlags & ETB_ISINIT; }
  61. };
  62. class ETS
  63. {
  64. private:
  65. char *pc;
  66. public:
  67. ETS() { pc = NULL; }
  68. ~ETS();
  69. #ifdef DEBUG
  70. char* Get();
  71. #else
  72. char *Get() { return pc; }
  73. #endif
  74. void Set(const char *pIn);
  75. ETS* Duplicate();
  76. void SetTo(char *pIn);
  77. BOOL fIsInit() { return pc != NULL; }
  78. };
  79. extern UINT EtBoolRegRead(ETB &etb, HKEY hKey, char *pKeyWord);
  80. extern UINT EtBoolRegWrite(ETB &etb, HKEY hKey, char *pKeyWord);
  81. extern UINT EtStringRegRead(ETS &ets, HKEY hKey, char *pKeyWord);
  82. extern UINT EtStringRegWrite(ETS &ets, HKEY hKey, char *pKeyWord);
  83. extern UINT EtNumRegRead(ETN &etn, HKEY hKey, char *pKeyWord);
  84. extern UINT EtNumRegWrite(ETN &etn, HKEY hKey, char *pKeyWord);
  85. /*Complex PICS types-----------------------------------------------*/
  86. enum RatObjectID
  87. {
  88. ROID_INVALID, /* dummy entry for terminating arrays */
  89. ROID_PICSDOCUMENT, /* value representing the entire document (i.e., no token) */
  90. ROID_PICSVERSION,
  91. ROID_RATINGSYSTEM,
  92. ROID_RATINGSERVICE,
  93. ROID_RATINGBUREAU,
  94. ROID_BUREAUREQUIRED,
  95. ROID_CATEGORY,
  96. ROID_TRANSMITAS,
  97. ROID_LABEL,
  98. ROID_VALUE,
  99. ROID_DEFAULT,
  100. ROID_DESCRIPTION,
  101. ROID_EXTENSION,
  102. ROID_MANDATORY,
  103. ROID_OPTIONAL,
  104. ROID_ICON,
  105. ROID_INTEGER,
  106. ROID_LABELONLY,
  107. ROID_MAX,
  108. ROID_MIN,
  109. ROID_MULTIVALUE,
  110. ROID_NAME,
  111. ROID_UNORDERED
  112. };
  113. enum PICSRulesObjectID
  114. {
  115. PROID_INVALID, /* dummy entry for terminating arrays */
  116. PROID_PICSVERSION, /* for holding the PICSRules version ID */
  117. PROID_POLICY, /* for the Policy class */
  118. PROID_EXPLANATION,
  119. PROID_REJECTBYURL,
  120. PROID_ACCEPTBYURL,
  121. PROID_REJECTIF,
  122. PROID_ACCEPTIF,
  123. PROID_ACCEPTUNLESS,
  124. PROID_REJECTUNLESS,
  125. PROID_NAME, /* for the name class */
  126. PROID_RULENAME,
  127. PROID_DESCRIPTION,
  128. PROID_SOURCE, /* for the source class */
  129. PROID_SOURCEURL,
  130. PROID_CREATIONTOOL,
  131. PROID_AUTHOR,
  132. PROID_LASTMODIFIED,
  133. PROID_SERVICEINFO, /* for the serviceinfo class */
  134. PROID_SINAME,
  135. PROID_SHORTNAME,
  136. PROID_BUREAUURL,
  137. PROID_USEEMBEDDED,
  138. PROID_RATFILE,
  139. PROID_BUREAUUNAVAILABLE,
  140. PROID_OPTEXTENSION, /* for the optextension class */
  141. PROID_EXTENSIONNAME,
  142. //PROID_SHORTNAME,
  143. PROID_REQEXTENSION,
  144. //PROID_EXTENSIONNAME,
  145. //PROID_SHORTNAME,
  146. PROID_EXTENSION,
  147. PROID_POLICYDEFAULT,
  148. PROID_NAMEDEFAULT,
  149. PROID_SOURCEDEFAULT,
  150. PROID_SERVICEINFODEFAULT,
  151. PROID_OPTEXTENSIONDEFAULT,
  152. PROID_REQEXTENSIONDEFAULT
  153. };
  154. /* define some error codes */
  155. const HRESULT RAT_E_BASE = 0x80050000; /* just a guess at a free area for internal use */
  156. const HRESULT RAT_E_EXPECTEDLEFT = RAT_E_BASE + 1; /* expected left paren */
  157. const HRESULT RAT_E_EXPECTEDRIGHT = RAT_E_BASE + 2; /* expected right paren */
  158. const HRESULT RAT_E_EXPECTEDTOKEN = RAT_E_BASE + 3; /* expected unquoted token */
  159. const HRESULT RAT_E_EXPECTEDSTRING = RAT_E_BASE + 4; /* expected quoted string */
  160. const HRESULT RAT_E_EXPECTEDNUMBER = RAT_E_BASE + 5; /* expected number */
  161. const HRESULT RAT_E_EXPECTEDBOOL = RAT_E_BASE + 6; /* expected boolean */
  162. const HRESULT RAT_E_DUPLICATEITEM = RAT_E_BASE + 7; /* AO_SINGLE item appeared twice */
  163. const HRESULT RAT_E_MISSINGITEM = RAT_E_BASE + 8; /* AO_MANDATORY item not found */
  164. const HRESULT RAT_E_UNKNOWNITEM = RAT_E_BASE + 9; /* unrecognized token */
  165. const HRESULT RAT_E_UNKNOWNMANDATORY= RAT_E_BASE + 10; /* unrecognized mandatory extension */
  166. const HRESULT RAT_E_EXPECTEDEND = RAT_E_BASE + 11; /* expected end of file */
  167. /* echo for PICSRules with different names for clarity */
  168. const HRESULT PICSRULES_E_BASE = 0x80050000; /* just a guess at a free area for internal use */
  169. const HRESULT PICSRULES_E_EXPECTEDLEFT = RAT_E_BASE + 1; /* expected left paren */
  170. const HRESULT PICSRULES_E_EXPECTEDRIGHT = RAT_E_BASE + 2; /* expected right paren */
  171. const HRESULT PICSRULES_E_EXPECTEDTOKEN = RAT_E_BASE + 3; /* expected unquoted token */
  172. const HRESULT PICSRULES_E_EXPECTEDSTRING = RAT_E_BASE + 4; /* expected quoted string */
  173. const HRESULT PICSRULES_E_EXPECTEDNUMBER = RAT_E_BASE + 5; /* expected number */
  174. const HRESULT PICSRULES_E_EXPECTEDBOOL = RAT_E_BASE + 6; /* expected boolean */
  175. const HRESULT PICSRULES_E_DUPLICATEITEM = RAT_E_BASE + 7; /* AO_SINGLE item appeared twice */
  176. const HRESULT PICSRULES_E_MISSINGITEM = RAT_E_BASE + 8; /* AO_MANDATORY item not found */
  177. const HRESULT PICSRULES_E_UNKNOWNITEM = RAT_E_BASE + 9; /* unrecognized token */
  178. const HRESULT PICSRULES_E_UNKNOWNMANDATORY = RAT_E_BASE + 10; /* unrecognized mandatory extension */
  179. const HRESULT PICSRULES_E_EXPECTEDEND = RAT_E_BASE + 11; /* expected end of file */
  180. const HRESULT PICSRULES_E_SERVICEUNDEFINED = RAT_E_BASE + 12; /* a service referenced is undefined */
  181. const HRESULT PICSRULES_E_REQEXTENSIONUSED = RAT_E_BASE + 13; /* an unknown required extension was used */
  182. const HRESULT PICSRULES_E_VERSION = RAT_E_BASE + 14; /* a non-support version was presented */
  183. /* A RatObjectHandler parses the contents of a parenthesized object and
  184. * spits out a binary representation of that data, suitable for passing
  185. * to an object's AddItem function. It does not consume the ')' which
  186. * closes the object.
  187. */
  188. class RatFileParser;
  189. typedef HRESULT (*RatObjectHandler)(LPSTR *ppszIn, LPVOID *ppOut, RatFileParser *pParser);
  190. class PICSRulesFileParser;
  191. typedef HRESULT (*PICSRulesObjectHandler)(LPSTR *ppszIn, LPVOID *ppOut, PICSRulesFileParser *pParser);
  192. class PicsCategory;
  193. class PicsObjectBase
  194. {
  195. public:
  196. virtual HRESULT AddItem(RatObjectID roid, LPVOID pData) = 0;
  197. virtual HRESULT InitializeMyDefaults(PicsCategory *pCategory) = 0;
  198. };
  199. class PICSRulesObjectBase
  200. {
  201. public:
  202. virtual HRESULT AddItem(PICSRulesObjectID proid, LPVOID pData) = 0;
  203. virtual HRESULT InitializeMyDefaults() = 0;
  204. };
  205. const DWORD AO_SINGLE = 0x01;
  206. const DWORD AO_SEEN = 0x02;
  207. const DWORD AO_MANDATORY = 0x04;
  208. struct AllowableOption
  209. {
  210. RatObjectID roid;
  211. DWORD fdwOptions;
  212. };
  213. struct PICSRulesAllowableOption
  214. {
  215. PICSRulesObjectID roid;
  216. DWORD fdwOptions;
  217. };
  218. class PicsEnum : public PicsObjectBase
  219. {
  220. private:
  221. public:
  222. ETS etstrName, etstrIcon, etstrDesc;
  223. ETN etnValue;
  224. PicsEnum();
  225. ~PicsEnum();
  226. // char* Parse(char *pStreamIn);
  227. HRESULT AddItem(RatObjectID roid, LPVOID pData);
  228. HRESULT InitializeMyDefaults(PicsCategory *pCategory);
  229. };
  230. class PicsRatingSystem;
  231. class PicsCategory : public PicsObjectBase
  232. {
  233. private:
  234. public:
  235. array<PicsCategory*> arrpPC;
  236. array<PicsEnum*> arrpPE;
  237. ETS etstrTransmitAs, etstrName, etstrIcon, etstrDesc;
  238. ETN etnMin, etnMax;
  239. ETB etfMulti, etfInteger, etfLabelled, etfUnordered;
  240. PicsRatingSystem *pPRS;
  241. PicsCategory();
  242. ~PicsCategory();
  243. // char* Parse(char *pStreamIn, char *pBaseName, PicsCategory *pPCparent);
  244. void FixupLimits();
  245. void SetParents(PicsRatingSystem *pOwner);
  246. HRESULT AddItem(RatObjectID roid, LPVOID pData);
  247. HRESULT InitializeMyDefaults(PicsCategory *pCategory);
  248. };
  249. class PicsDefault : public PicsObjectBase
  250. {
  251. public:
  252. ETB etfInteger, etfLabelled, etfMulti, etfUnordered;
  253. ETN etnMax, etnMin;
  254. PicsDefault();
  255. ~PicsDefault();
  256. HRESULT AddItem(RatObjectID roid, LPVOID pData);
  257. HRESULT InitializeMyDefaults(PicsCategory *pCategory);
  258. };
  259. class PicsExtension : public PicsObjectBase
  260. {
  261. public:
  262. LPSTR m_pszRatingBureau;
  263. PicsExtension();
  264. ~PicsExtension();
  265. HRESULT AddItem(RatObjectID roid, LPVOID pData);
  266. HRESULT InitializeMyDefaults(PicsCategory *pCategory);
  267. };
  268. class PicsRatingSystem : public PicsObjectBase
  269. {
  270. private:
  271. public:
  272. array<PicsCategory*> arrpPC;
  273. ETS etstrFile, etstrName, etstrIcon, etstrDesc,
  274. etstrRatingService, etstrRatingSystem, etstrRatingBureau;
  275. ETN etnPicsVersion;
  276. ETB etbBureauRequired;
  277. PicsDefault * m_pDefaultOptions;
  278. DWORD dwFlags;
  279. UINT nErrLine;
  280. PicsRatingSystem();
  281. ~PicsRatingSystem();
  282. HRESULT Parse(LPCSTR pszFile, LPSTR pStreamIn);
  283. HRESULT AddItem(RatObjectID roid, LPVOID pData);
  284. HRESULT InitializeMyDefaults(PicsCategory *pCategory);
  285. void ReportError(HRESULT hres);
  286. };
  287. /* bit values for PicsRatingSystem::dwFlags */
  288. const DWORD PRS_ISVALID = 0x01; /* this rating system was loaded successfully */
  289. const DWORD PRS_WASINVALID = 0x02; /* was invalid last time we tried to load it */
  290. /* echo for PICSRules with different names for clarity */
  291. #define PRRS_ISVALID PRS_ISVALID;
  292. #define PRRS_WASINVALID PRS_WASINVALID;
  293. class UserRating : public NLS_STR
  294. {
  295. public:
  296. INT m_nValue;
  297. UserRating *m_pNext;
  298. PicsCategory *m_pPC;
  299. UserRating();
  300. UserRating(UserRating *pCopyFrom);
  301. ~UserRating();
  302. UserRating *Duplicate(void);
  303. void SetName(LPCSTR pszName) { *(NLS_STR *)this = pszName; }
  304. };
  305. class UserRatingSystem : public NLS_STR
  306. {
  307. public:
  308. UserRating *m_pRatingList;
  309. UserRatingSystem *m_pNext;
  310. PicsRatingSystem *m_pPRS;
  311. UserRatingSystem();
  312. UserRatingSystem(UserRatingSystem *pCopyFrom);
  313. ~UserRatingSystem();
  314. UserRating *FindRating(LPCSTR pszTransmitName);
  315. UINT AddRating(UserRating *pRating);
  316. UINT ReadFromRegistry(HKEY hkeyProvider);
  317. UINT WriteToRegistry(HKEY hkey);
  318. UserRatingSystem *Duplicate(void);
  319. void SetName(LPCSTR pszName) { *(NLS_STR *)this = pszName; }
  320. };
  321. UserRatingSystem *DuplicateRatingSystemList(UserRatingSystem *pOld);
  322. void DestroyRatingSystemList(UserRatingSystem *pList);
  323. UserRatingSystem *FindRatingSystem(UserRatingSystem *pList, LPCSTR pszName);
  324. class PicsUser{
  325. private:
  326. public:
  327. NLS_STR nlsUsername;
  328. BOOL fAllowUnknowns, fPleaseMom, fEnabled;
  329. UserRatingSystem *m_pRatingSystems;
  330. PicsUser();
  331. ~PicsUser();
  332. UserRatingSystem *FindRatingSystem(LPCSTR pszSystemName) { return ::FindRatingSystem(m_pRatingSystems, pszSystemName); }
  333. UINT AddRatingSystem(UserRatingSystem *pRatingSystem);
  334. BOOL NewInstall();
  335. UINT ReadFromRegistry(HKEY hkey, char *pszUserName);
  336. UINT WriteToRegistry(HKEY hkey);
  337. };
  338. PicsUser *GetUserObject(LPCSTR pszUsername=NULL);
  339. extern long GetStateCounter();
  340. class PicsRatingSystemInfo
  341. {
  342. public:
  343. array<PicsRatingSystem*> arrpPRS;
  344. PicsUser * pUserObject;
  345. BOOL fRatingInstalled;
  346. ETS etstrRatingBureau;
  347. long nInfoRev;
  348. BOOL fStoreInRegistry;
  349. BOOL fSettingsValid;
  350. PSTR lpszFileName;
  351. PicsRatingSystemInfo() { lpszFileName=NULL; nInfoRev = ::GetStateCounter(); };
  352. ~PicsRatingSystemInfo();
  353. BOOL Init();
  354. BOOL FreshInstall();
  355. void SaveRatingSystemInfo();
  356. BOOL LoadProviderFiles(HKEY hKey);
  357. protected:
  358. HKEY GetUserProfileKey( void );
  359. };
  360. extern PicsRatingSystemInfo *gPRSI;
  361. void CheckGlobalInfoRev(void);
  362. char* EtStringParse(ETS &ets, char *pIn, const char *pKeyWord, BOOL fParen);
  363. char* EtLabelParse(char *pIn, const char *pszLongName, const char *pszShortName);
  364. char* EtRatingParse(ETN &etn, ETS &ets, char *pInStream);
  365. int MyMessageBox(HWND hwnd, UINT uText, UINT uTitle, UINT uType);
  366. int MyMessageBox(HWND hwnd, UINT uText, UINT uText2, UINT uTitle, UINT uType);
  367. int MyMessageBox(HWND hwnd, LPCSTR pszText, UINT uTitle, UINT uType);
  368. char *NonWhite(char *pIn);
  369. BOOL MyAtoi(char *pIn, int *i);
  370. LONG MyRegDeleteKey(HKEY hkey,LPCSTR pszSubkey);
  371. HRESULT LoadRatingSystem(LPCSTR pszFilename, PicsRatingSystem **pprsOut);
  372. INT_PTR DoProviderDialog(HWND hDlg, PicsRatingSystemInfo *pPRSI);
  373. void DeleteUserSettings(PicsRatingSystem *pPRS);
  374. void CheckUserSettings(PicsRatingSystem *pPRS);
  375. //
  376. // Declarations for Custom
  377. //
  378. extern g_fIsRunningUnderCustom;
  379. struct CustomRatingHelper
  380. {
  381. CustomRatingHelper();
  382. ~CustomRatingHelper();
  383. HMODULE hLibrary;
  384. CLSID clsid;
  385. CustomRatingHelper* pNextHelper;
  386. DWORD dwSort;
  387. };
  388. /*Pics Tree Dialog Stuff------------------------------------------------------*/
  389. struct PRSD
  390. {
  391. PicsRatingSystemInfo *pPRSI;
  392. PicsUser *pPU;
  393. UserRatingSystem *pTempRatings;
  394. HWND hwndBitmapCategory;
  395. HWND hwndBitmapLabel;
  396. BOOL fNewProviders;
  397. };
  398. enum TreeNodeEnum{tneGeneral, tneAccessList, tneRatingSystemRoot, tneRatingSystemInfo, tneRatingSystemNode, tneNone};
  399. struct TreeNode{
  400. TreeNodeEnum tne;
  401. void *pData;
  402. TreeNode(){}
  403. TreeNode(TreeNodeEnum tneInit, void* pDataInit){tne=tneInit;pData=pDataInit;}
  404. };
  405. PicsRatingSystem *FindInstalledRatingSystem(LPCSTR pszRatingService);
  406. PicsCategory *FindInstalledCategory(array<PicsCategory *>&arrpPC, LPCSTR pszName);
  407. HRESULT Ansi2Unicode(LPWSTR *pdest, LPCSTR src);
  408. #endif