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.

366 lines
6.6 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. INFSCAN
  5. filters.inl
  6. Abstract:
  7. Filter INF creation/parsing (inlines)
  8. History:
  9. Created July 2001 - JamieHun
  10. --*/
  11. inline
  12. ReportEntry::ReportEntry()
  13. /*++
  14. Routine Description:
  15. Initialize ReportEntry instance
  16. --*/
  17. {
  18. FilterAction = ACTION_DEFAULT;
  19. hash = 0;
  20. }
  21. inline
  22. ReportEntry::ReportEntry(const StringList & strings) :
  23. args(strings)
  24. /*++
  25. Routine Description:
  26. Initialize ReportEntry instance
  27. Arguments:
  28. strings - list of error parameters
  29. --*/
  30. {
  31. //
  32. // see constructor initializers
  33. //
  34. FilterAction = ACTION_DEFAULT;
  35. CreateHash();
  36. }
  37. inline
  38. ReportEntry::ReportEntry(const ReportEntry & other) :
  39. args(other.args),
  40. hash(other.hash),
  41. FilterAction(other.FilterAction)
  42. /*++
  43. Routine Description:
  44. Copy-Initialize ReportEntry instance
  45. Arguments:
  46. other - another ReportEntry to initialize from
  47. --*/
  48. {
  49. //
  50. // see constructor initializers
  51. //
  52. }
  53. inline
  54. void ReportEntry::Initialize(const StringList & strings)
  55. /*++
  56. Routine Description:
  57. Initialize ReportEntry instance from a list of error strings
  58. Arguments:
  59. strings - list of error parameters
  60. Return Value:
  61. NONE
  62. --*/
  63. {
  64. args = strings;
  65. CreateHash();
  66. }
  67. inline
  68. void ReportEntry::Initialize(const ReportEntry & other)
  69. /*++
  70. Routine Description:
  71. Initialize this ReportEntry instance from another ReportEntry instance
  72. Arguments:
  73. other - another ReportEntry instance
  74. Return Value:
  75. NONE
  76. --*/
  77. {
  78. args = other.args;
  79. hash = other.hash;
  80. FilterAction = other.FilterAction;
  81. }
  82. inline
  83. unsigned long ReportEntry::GetHash() const
  84. /*++
  85. Routine Description:
  86. Retrieve hash (a protected value)
  87. As this routine is const, we can't determine hash
  88. as a side-effect
  89. Arguments:
  90. NONE
  91. Return Value:
  92. current hash value (if initialized)
  93. --*/
  94. {
  95. return hash;
  96. }
  97. inline
  98. unsigned long ReportEntry::CreateHash()
  99. /*++
  100. Routine Description:
  101. Determine and retrieve hash
  102. Hash is always re-determined
  103. Arguments:
  104. NONE
  105. Return Value:
  106. new hash value
  107. --*/
  108. {
  109. StringList::iterator i;
  110. LPCTSTR ptr;
  111. hash = 0;
  112. for(i = args.begin(); i != args.end(); i++) {
  113. //
  114. // each new string weighting
  115. //
  116. int mult = REPORT_HASH_SMULT;
  117. for(ptr = i->c_str(); *ptr; ptr++) {
  118. hash = ((hash * mult) + (*ptr)) % REPORT_HASH_MOD;
  119. //
  120. // change to individual character weighting
  121. //
  122. mult = REPORT_HASH_CMULT;
  123. }
  124. }
  125. return hash;
  126. }
  127. inline
  128. int ReportEntry::compare(const ReportEntry & other) const
  129. /*++
  130. Routine Description:
  131. Compare this report entry with another
  132. a<b implies b>a
  133. a<b and b<c implies a<c
  134. Other than predictability, a returned value !=0
  135. does not imply any real collation order, it's here
  136. to speed up the binary-tree
  137. a returned value==0 (a==b) does however imply that
  138. they are exactly the same.
  139. Arguments:
  140. A ReportEntry instance to compare against
  141. Return Value:
  142. -1 implies this<other wrt binary tree sorting
  143. 0 implies this==other
  144. 1 implies this>other wrt binary tree sorting
  145. --*/
  146. {
  147. //
  148. // compare the hash's first
  149. //
  150. if(hash<other.hash) {
  151. return -1;
  152. }
  153. if(hash>other.hash) {
  154. return 1;
  155. }
  156. //
  157. // if hashes compare we need to do detailed string compare, perf hit time
  158. //
  159. StringList::iterator i,j;
  160. int comp;
  161. for(i = args.begin(), j = other.args.begin(); i != args.end(); i++, j++) {
  162. if(j == other.args.end()) {
  163. //
  164. // other ran out of args before this
  165. // so consider this > other
  166. //
  167. return 1;
  168. }
  169. SafeString &s = *i;
  170. SafeString &t = *j;
  171. comp = s.compare(t);
  172. //
  173. // if we have a non-equal compare
  174. // we can bail now
  175. //
  176. if(comp < 0) {
  177. return -1;
  178. }
  179. if(comp > 0) {
  180. return 1;
  181. }
  182. //
  183. // if they are equal, continue comparing
  184. //
  185. }
  186. if(j == other.args.end()) {
  187. //
  188. // two items compare exactly
  189. //
  190. return 0;
  191. } else {
  192. //
  193. // two string matched for all of this's args
  194. // but other has more args
  195. // so consider this < other
  196. //
  197. return -1;
  198. }
  199. }
  200. inline
  201. bool ReportEntry::operator<(const ReportEntry & other) const
  202. /*++
  203. Routine Description:
  204. Redress compare as '<' operator
  205. Arguments:
  206. A ReportEntry instance to compare against
  207. Return Value:
  208. true if conceptually this<other
  209. false otherwise
  210. --*/
  211. {
  212. return compare(other) < 0 ? true : false;
  213. }
  214. inline
  215. bool ReportEntryBlob::operator<(const ReportEntryBlob & other) const
  216. /*++
  217. Routine Description:
  218. comparing the blob version is same as comparing the members
  219. Arguments:
  220. A ReportEntry instance to compare against
  221. Return Value:
  222. true if conceptually this<other
  223. false otherwise
  224. --*/
  225. {
  226. return (*this)->compare(other) < 0 ? true : false;
  227. }
  228. inline
  229. ReportEntrySet::ReportEntrySet()
  230. /*++
  231. Routine Description:
  232. Initialize ReportEntrySet instance
  233. --*/
  234. {
  235. FilterAction = ACTION_DEFAULT;
  236. }
  237. inline
  238. FileDisposition::FileDisposition()
  239. /*++
  240. Routine Description:
  241. Initialize FileDisposition instance
  242. --*/
  243. {
  244. Filtered = false;
  245. FilterAction = ACTION_DEFAULT;
  246. }
  247. inline
  248. FileDisposition::FileDisposition(const FileDisposition & other) :
  249. Filtered(other.Filtered),
  250. FilterAction(other.FilterAction),
  251. FileGuid(other.FileGuid),
  252. FilterErrorSection(other.FilterErrorSection)
  253. /*++
  254. Routine Description:
  255. Copy-Initialize FileDisposition instance from another instance
  256. Arguments:
  257. A ReportEntry instance to initialize with
  258. --*/
  259. {
  260. //
  261. // see constructor initializers
  262. //
  263. }
  264. inline
  265. FileDisposition & FileDisposition::operator = (const FileDisposition & other)
  266. /*++
  267. Routine Description:
  268. Assignment definition
  269. Arguments:
  270. A ReportEntry instance to copy from
  271. Return Value:
  272. *this
  273. --*/
  274. {
  275. Filtered = other.Filtered;
  276. FilterAction = other.FilterAction;
  277. FileGuid = other.FileGuid;
  278. FilterErrorSection = other.FilterErrorSection;
  279. return *this;
  280. }