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.

426 lines
9.8 KiB

  1. /****************************************************************************\
  2. *
  3. * PARSERAT.H --Structures for holding pics information
  4. *
  5. * Created: Jason Thomas
  6. * Updated: Ann McCurdy
  7. *
  8. \****************************************************************************/
  9. #ifndef _PARSERAT_H_
  10. #define _PARSERAT_H_
  11. // output defines ---------------------------------------
  12. #define OUTPUT_PICS
  13. /*Array template---------------------------------------------------*/
  14. /*Interface-------------------------------------------------------------------*/
  15. template <class T>
  16. class array {
  17. private:
  18. int nLen, nMax;
  19. T *pData;
  20. void Destruct();
  21. public:
  22. array();
  23. ~array();
  24. BOOL Append(T v);
  25. int Length() const;
  26. void ClearAll();
  27. void DeleteAll();
  28. T& operator[](int index);
  29. };
  30. /*definitions of everything*/
  31. #ifndef ARRAY_CXX
  32. #define ARRAY_CXX
  33. /*Implementation------------------------------------------------------------*/
  34. template <class T>
  35. array<T>::array(){
  36. nLen = nMax = 0;
  37. pData = NULL;
  38. }
  39. template <class T>
  40. inline array<T>::~array() {
  41. if (pData) ::MemFree(pData);
  42. pData = NULL;
  43. nMax = nLen = 0;
  44. }
  45. template <class T>
  46. inline int array<T>::Length() const{
  47. return nLen;
  48. }
  49. template <class T>
  50. inline T& array<T>::operator[](int index){
  51. assert(index<Length());
  52. assert(index>=0);
  53. assert(pData);
  54. return pData[index];
  55. }
  56. template <class T>
  57. BOOL array<T>::Append(T v) {
  58. if (nLen == nMax){
  59. nMax = nMax + 8; /* grow by bigger chunks */
  60. T* pNew = (T*)::MemReAlloc(pData, sizeof(T)*nMax);
  61. if (pNew == NULL)
  62. return FALSE;
  63. pData = pNew;
  64. }
  65. assert(pData);
  66. assert(nMax);
  67. pData[nLen++] = v;
  68. return TRUE;
  69. }
  70. template <class T>
  71. void array<T>::Destruct(){
  72. while (nLen){
  73. delete pData[--nLen];
  74. }
  75. }
  76. template <class T>
  77. inline void array<T>::ClearAll() {
  78. nLen = 0;
  79. }
  80. template <class T>
  81. inline void array<T>::DeleteAll() {
  82. Destruct();
  83. }
  84. #endif
  85. /* ARRAY_CXX */
  86. #define P_INFINITY 9999
  87. #define N_INFINITY -9999
  88. /*Simple PICS types------------------------------------------------*/
  89. #if 0
  90. class ET{
  91. private:
  92. BOOL m_fInit;
  93. public:
  94. ET();
  95. void Init();
  96. void UnInit();
  97. BOOL fIsInit();
  98. };
  99. #endif
  100. class ETN
  101. {
  102. private:
  103. INT_PTR r;
  104. BOOL m_fInit;
  105. public:
  106. ETN() { m_fInit = FALSE; }
  107. void Init() { m_fInit = TRUE; }
  108. void UnInit() { m_fInit = FALSE; }
  109. BOOL fIsInit() { return m_fInit; }
  110. #ifdef DEBUG
  111. void Set(INT_PTR rIn);
  112. INT_PTR Get();
  113. #else
  114. void Set(INT_PTR rIn) { Init(); r = rIn; }
  115. INT_PTR Get() { return r; }
  116. #endif
  117. ETN* Duplicate();
  118. };
  119. const UINT ETB_VALUE = 0x01;
  120. const UINT ETB_ISINIT = 0x02;
  121. class ETB
  122. {
  123. private:
  124. UINT m_nFlags;
  125. public:
  126. ETB() { m_nFlags = 0; }
  127. #ifdef DEBUG
  128. INT_PTR Get();
  129. void Set(INT_PTR b);
  130. #else
  131. INT_PTR Get() { return m_nFlags & ETB_VALUE; }
  132. void Set(INT_PTR b) { m_nFlags = ETB_ISINIT | (b ? ETB_VALUE : 0); }
  133. #endif
  134. ETB *Duplicate();
  135. BOOL fIsInit() { return m_nFlags & ETB_ISINIT; }
  136. };
  137. class ETS
  138. {
  139. private:
  140. char *pc;
  141. public:
  142. ETS() { pc = NULL; }
  143. ~ETS();
  144. #ifdef DEBUG
  145. char* Get();
  146. #else
  147. char *Get() { return pc; }
  148. #endif
  149. void Set(const char *pIn);
  150. ETS* Duplicate();
  151. void SetTo(char *pIn);
  152. BOOL fIsInit() { return pc != NULL; }
  153. };
  154. /*Complex PICS types-----------------------------------------------*/
  155. enum RatObjectID
  156. {
  157. ROID_INVALID, /* dummy entry for terminating arrays */
  158. ROID_PICSDOCUMENT, /* value representing the entire document (i.e., no token) */
  159. ROID_PICSVERSION,
  160. ROID_RATINGSYSTEM,
  161. ROID_RATINGSERVICE,
  162. ROID_RATINGBUREAU,
  163. ROID_BUREAUREQUIRED,
  164. ROID_CATEGORY,
  165. ROID_TRANSMITAS,
  166. ROID_LABEL,
  167. ROID_VALUE,
  168. ROID_DEFAULT,
  169. ROID_DESCRIPTION,
  170. ROID_EXTENSION,
  171. ROID_MANDATORY,
  172. ROID_OPTIONAL,
  173. ROID_ICON,
  174. ROID_INTEGER,
  175. ROID_LABELONLY,
  176. ROID_MAX,
  177. ROID_MIN,
  178. ROID_MULTIVALUE,
  179. ROID_NAME,
  180. ROID_UNORDERED
  181. };
  182. /* A RatObjectHandler parses the contents of a parenthesized object and
  183. * spits out a binary representation of that data, suitable for passing
  184. * to an object's AddItem function. It does not consume the ')' which
  185. * closes the object.
  186. */
  187. class RatFileParser;
  188. typedef HRESULT (*RatObjectHandler)(LPSTR *ppszIn, LPVOID *ppOut, RatFileParser *pParser);
  189. class PicsCategory;
  190. class PicsObjectBase : public CObject
  191. {
  192. public:
  193. virtual HRESULT AddItem(RatObjectID roid, LPVOID pData) = 0;
  194. virtual HRESULT InitializeMyDefaults(PicsCategory *pCategory) = 0;
  195. virtual void Dump( void ) = 0;
  196. };
  197. const DWORD AO_SINGLE = 0x01;
  198. const DWORD AO_SEEN = 0x02;
  199. const DWORD AO_MANDATORY = 0x04;
  200. struct AllowableOption
  201. {
  202. RatObjectID roid;
  203. DWORD fdwOptions;
  204. };
  205. class PicsEnum : public PicsObjectBase
  206. {
  207. private:
  208. public:
  209. ETS etstrName, etstrIcon, etstrDesc;
  210. ETN etnValue;
  211. PicsEnum() {}
  212. ~PicsEnum() {}
  213. HRESULT AddItem(RatObjectID roid, LPVOID pData);
  214. HRESULT InitializeMyDefaults(PicsCategory *pCategory);
  215. void Dump( void );
  216. };
  217. class PicsRatingSystem;
  218. class PicsCategory : public PicsObjectBase
  219. {
  220. public:
  221. PicsCategory():currentValue(0) {;}
  222. ~PicsCategory()
  223. {
  224. arrpPC.DeleteAll();
  225. arrpPE.DeleteAll();
  226. }
  227. private:
  228. public:
  229. array<PicsCategory*> arrpPC;
  230. array<PicsEnum*> arrpPE;
  231. ETS etstrTransmitAs, etstrName, etstrIcon, etstrDesc;
  232. ETN etnMin, etnMax;
  233. ETB etfMulti, etfInteger, etfLabelled, etfUnordered;
  234. PicsRatingSystem *pPRS;
  235. WORD currentValue;
  236. void FixupLimits();
  237. void SetParents(PicsRatingSystem *pOwner);
  238. HRESULT AddItem(RatObjectID roid, LPVOID pData);
  239. HRESULT InitializeMyDefaults(PicsCategory *pCategory);
  240. void Dump( void );
  241. // boydm
  242. void OutputLabel( CString &sz );
  243. BOOL FSetValuePair( CHAR chCat, WORD value );
  244. };
  245. class PicsDefault : public PicsObjectBase
  246. {
  247. public:
  248. ETB etfInteger, etfLabelled, etfMulti, etfUnordered;
  249. ETN etnMax, etnMin;
  250. PicsDefault() {}
  251. ~PicsDefault() {}
  252. HRESULT AddItem(RatObjectID roid, LPVOID pData);
  253. HRESULT InitializeMyDefaults(PicsCategory *pCategory);
  254. void Dump( void );
  255. };
  256. class PicsExtension : public PicsObjectBase
  257. {
  258. public:
  259. LPSTR m_pszRatingBureau;
  260. PicsExtension();
  261. ~PicsExtension();
  262. HRESULT AddItem(RatObjectID roid, LPVOID pData);
  263. HRESULT InitializeMyDefaults(PicsCategory *pCategory);
  264. void Dump( void );
  265. };
  266. class PicsRatingSystem : public PicsObjectBase
  267. {
  268. private:
  269. public:
  270. array<PicsCategory*> arrpPC;
  271. ETS etstrFile, etstrName, etstrIcon, etstrDesc,
  272. etstrRatingService, etstrRatingSystem, etstrRatingBureau;
  273. ETN etnPicsVersion;
  274. ETB etbBureauRequired;
  275. PicsDefault * m_pDefaultOptions;
  276. DWORD dwFlags;
  277. UINT nErrLine;
  278. PicsRatingSystem() :
  279. m_pDefaultOptions( NULL ),
  280. dwFlags( 0 ),
  281. nErrLine( 0 ) {}
  282. ~PicsRatingSystem()
  283. {
  284. arrpPC.DeleteAll();
  285. if (m_pDefaultOptions != NULL)
  286. delete m_pDefaultOptions;
  287. }
  288. HRESULT Parse(LPSTR pStreamIn);
  289. HRESULT AddItem(RatObjectID roid, LPVOID pData);
  290. HRESULT InitializeMyDefaults(PicsCategory *pCategory);
  291. VOID Dump();
  292. void ReportError(HRESULT hres);
  293. void OutputLabels( CString &sz, CString szURL,CString szName, CString szStart, CString szEnd );
  294. };
  295. void SkipWhitespace(LPSTR *ppsz);
  296. BOOL IsEqualToken(LPCSTR pszTokenStart, LPCSTR pszTokenEnd, LPCSTR pszTokenToMatch);
  297. LPSTR FindTokenEnd(LPSTR pszStart);
  298. HRESULT GetBool(LPSTR *ppszToken, BOOL *pfOut);
  299. HRESULT ParseNumber(LPSTR *ppszNumber, INT *pnOut);
  300. /*Memory utility functions-----------------------------------------------*/
  301. inline void * WINAPI MemAlloc(long cb)
  302. {
  303. return (void *)::LocalAlloc(LPTR, cb);
  304. }
  305. inline void * WINAPI MemReAlloc(void * pb, long cb)
  306. {
  307. if (pb == NULL)
  308. return MemAlloc(cb);
  309. return (void *)::LocalReAlloc((HLOCAL)pb, cb, LMEM_MOVEABLE | LMEM_ZEROINIT);
  310. }
  311. inline BOOL WINAPI MemFree(void * pb)
  312. {
  313. return (BOOL)HandleToUlong(::LocalFree((HLOCAL)pb));
  314. }
  315. /*String manipulation wrappers---------------------------------------------*/
  316. #ifdef __cplusplus
  317. extern "C" {
  318. #endif
  319. #define memcmpf(d,s,l) memcmp((d),(s),(l))
  320. #define memcpyf(d,s,l) memcpy((d),(s),(l))
  321. #define memmovef(d,s,l) MoveMemory((d),(s),(l))
  322. #define memsetf(s,c,l) memset((s),(c),(l))
  323. #define strcatf(d,s) strcat((d),(s))
  324. #define strcmpf(s1,s2) lstrcmp(s1,s2)
  325. #define strcpyf(d,s) strcpy((d),(s))
  326. #define stricmpf(s1,s2) lstrcmpi(s1,s2)
  327. #define strlenf(s) strlen((s))
  328. #define strchrf(s,c) strchr((s),(c))
  329. #define strrchrf(s,c) strrchr((s),(c))
  330. #define strspnf(s1,s2) strspn((s1),(s2))
  331. #define strnicmpf(s1,s2,i) _strnicmp((s1),(s2),(i))
  332. #define strncpyf(s1,s2,i) strncpy((s1),(s2),(i))
  333. #define strcspnf(s1,s2) strcspn((s1),(s2))
  334. #define strtokf(s1,s2) strtok((s1),(s2))
  335. #define strstrf(s1,s2) strstr((s1),(s2))
  336. #ifdef __cplusplus
  337. }
  338. #endif
  339. #endif