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.

258 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. parmlist.hxx
  5. Abstract:
  6. Simple class for parsing and storing parameter list pairs
  7. Author:
  8. John Ludeman (johnl) 22-Feb-1995
  9. Revision History:
  10. --*/
  11. #ifndef _PARMLIST_HXX_
  12. #define _PARMLIST_HXX_
  13. //
  14. // This is a simple class that parses and stores a field/value list
  15. // of the form
  16. //
  17. // field=value,field2=value2;param,field3=value3
  18. //
  19. // Returned values include any parameters
  20. //
  21. class PARAM_LIST
  22. {
  23. public:
  24. PARAM_LIST(
  25. VOID
  26. )
  27. {
  28. InitializeListHead( &_FieldListHead );
  29. InitializeListHead( &_FreeHead );
  30. _fCanonicalized = FALSE;
  31. }
  32. ~PARAM_LIST();
  33. VOID
  34. Reset(
  35. VOID
  36. );
  37. VOID
  38. SetIsCanonicalized(
  39. BOOL fIsCanon = FALSE
  40. )
  41. {
  42. _fCanonicalized = fIsCanon;
  43. }
  44. //
  45. // Takes a list of '=' or ',' separated strings
  46. //
  47. HRESULT
  48. ParsePairs(
  49. const CHAR * pszList,
  50. BOOL fDefaultParams = FALSE,
  51. BOOL fAddBlankValues = TRUE,
  52. BOOL fCommaIsDelim = TRUE
  53. );
  54. //
  55. // Parses simple comma delimited list and adds with empty value
  56. //
  57. HRESULT
  58. ParseSimpleList(
  59. const CHAR * pszList
  60. );
  61. //
  62. // Looks up a value for a field, returns NULL if not found
  63. //
  64. CHAR *
  65. FindValue(
  66. const CHAR * pszField,
  67. BOOL * pfIsMultiValue = NULL,
  68. DWORD * pcbField = NULL
  69. );
  70. //
  71. // Adds a field/value pair. Field doesn't get replaced if it
  72. // already exists and the value is not empty.
  73. //
  74. HRESULT
  75. AddParam(
  76. const CHAR * pszFieldName,
  77. const CHAR * pszValue
  78. );
  79. //
  80. // Unconditionally adds the field/value pair to the end of the list
  81. //
  82. HRESULT
  83. AddEntry(
  84. const CHAR * pszFieldName,
  85. const CHAR * pszValue,
  86. BOOL fUnescape = FALSE,
  87. BOOL fPossibleFastMap = TRUE
  88. );
  89. //
  90. // Adds an entry not using the fast map and not unescaping
  91. //
  92. HRESULT
  93. AddEntry(
  94. const CHAR * pszField,
  95. DWORD cbField,
  96. const CHAR * pszValue,
  97. DWORD cbValue
  98. );
  99. //
  100. // concatenate with existing entry of same name or
  101. // adds the field/value pair to the end of the list if not
  102. // already present
  103. //
  104. HRESULT
  105. AddEntryUsingConcat(
  106. const CHAR * pszField,
  107. const CHAR * pszValue,
  108. BOOL fPossibleFastMap = TRUE
  109. );
  110. //
  111. // Removes all occurrences of the specified field from the list
  112. //
  113. BOOL
  114. RemoveEntry(
  115. const CHAR * pszFieldName
  116. );
  117. //
  118. // Enumerates the field/value pairs. Pass pCookie as NULL to start,
  119. // pass the return value on subsequent iterations until the return is
  120. // NULL.
  121. //
  122. VOID *
  123. NextPair(
  124. VOID * pCookie,
  125. CHAR * * ppszField,
  126. CHAR * * ppszValue
  127. );
  128. //
  129. // Return lengths also - This version does NOT use the fast map
  130. //
  131. VOID *
  132. NextPair(
  133. VOID * pCookie,
  134. CHAR * * ppszField,
  135. DWORD * pcbField,
  136. CHAR * * ppszValue,
  137. DWORD * pcbValue
  138. );
  139. //
  140. // Gets the number of elements in this parameter list
  141. //
  142. DWORD
  143. GetCount(
  144. VOID
  145. );
  146. //
  147. // Canonicalize the list
  148. //
  149. VOID
  150. CanonList(
  151. VOID
  152. );
  153. BOOL
  154. IsCanonicalized(
  155. VOID
  156. ) const
  157. {
  158. return _fCanonicalized;
  159. }
  160. private:
  161. //
  162. // Actual list of FIELD_VALUE_PAIR object
  163. //
  164. LIST_ENTRY _FieldListHead;
  165. LIST_ENTRY _FreeHead;
  166. BOOL _fCanonicalized;
  167. };
  168. //
  169. // The list of field/value pairs used in the PARAM_LIST class
  170. //
  171. class FIELD_VALUE_PAIR
  172. {
  173. public:
  174. CHAR *
  175. QueryField(
  176. VOID
  177. )
  178. {
  179. return _strField.QueryStr();
  180. }
  181. CHAR *
  182. QueryValue(
  183. VOID
  184. )
  185. {
  186. return _strValue.QueryStr();
  187. }
  188. //
  189. // Means multiple fields were combined to make this value
  190. //
  191. BOOL
  192. IsMultiValued(
  193. VOID
  194. ) const
  195. {
  196. return _cValues > 1;
  197. }
  198. LIST_ENTRY ListEntry;
  199. STRA _strField;
  200. STRA _strValue;
  201. DWORD _cValues;
  202. };
  203. #endif //_PARMLIST_HXX_