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.

389 lines
10 KiB

  1. /*++
  2. Copyright (C) 2000 Microsoft Corporation
  3. Module Name:
  4. iterate.c
  5. Abstract:
  6. This module contains routines that iterate over the MM data structures
  7. --*/
  8. #include <precomp.h>
  9. DWORD
  10. IterateClasses(
  11. IN PM_SERVER Server,
  12. IN PVOID ExtraCtxt,
  13. IN DWORD (*Callback)( IN OUT PMM_ITERATE_CTXT )
  14. )
  15. {
  16. ARRAY_LOCATION Loc;
  17. DWORD Error;
  18. MM_ITERATE_CTXT Ctxt;
  19. PM_CLASSDEF ClassDef;
  20. Ctxt.ExtraCtxt = ExtraCtxt;
  21. Ctxt.Server = Server;
  22. Error = MemArrayInitLoc( &Server->ClassDefs.ClassDefArray, &Loc );
  23. while( NO_ERROR == Error ) {
  24. Error = MemArrayGetElement(
  25. &Server->ClassDefs.ClassDefArray, &Loc, &ClassDef );
  26. ASSERT( NO_ERROR == Error );
  27. Ctxt.ClassDef = ClassDef;
  28. Error = Callback( &Ctxt );
  29. if( ERROR_KEY_DELETED == Error ) {
  30. //
  31. // Delete this class ..
  32. //
  33. MemArrayDelElement(
  34. &Server->ClassDefs.ClassDefArray, &Loc, &ClassDef );
  35. MemClassDefFree( ClassDef );
  36. Error = MemArrayAdjustLocation(
  37. &Server->ClassDefs.ClassDefArray, &Loc );
  38. } else {
  39. if( NO_ERROR != Error ) return Error;
  40. Error = MemArrayNextLoc(
  41. &Server->ClassDefs.ClassDefArray, &Loc );
  42. }
  43. }
  44. if( ERROR_FILE_NOT_FOUND == Error ) Error = NO_ERROR;
  45. return Error;
  46. }
  47. PM_CLASSDEF
  48. FindClass(
  49. IN PM_SERVER Server,
  50. IN ULONG ClassId
  51. )
  52. {
  53. DWORD Error;
  54. PM_CLASSDEF Class;
  55. if( 0 == ClassId ) return NULL;
  56. Error = MemServerGetClassDef(
  57. Server, ClassId, NULL, 0, NULL, &Class );
  58. if( NO_ERROR == Error ) return Class;
  59. return NULL;
  60. }
  61. DWORD
  62. IterateOptDefs(
  63. IN PM_SERVER Server,
  64. IN PVOID ExtraCtxt,
  65. IN DWORD (*Callback)( IN OUT PMM_ITERATE_CTXT )
  66. )
  67. {
  68. ARRAY_LOCATION Loc, Loc2;
  69. DWORD Error;
  70. MM_ITERATE_CTXT Ctxt;
  71. PM_OPTDEF OptDef;
  72. PM_OPTCLASSDEFL_ONE OptClassDefList;
  73. Ctxt.ExtraCtxt = ExtraCtxt;
  74. Ctxt.Server = Server;
  75. Error = MemArrayInitLoc( &Server->OptDefs.Array, &Loc );
  76. while( NO_ERROR == Error ) {
  77. Error = MemArrayGetElement(
  78. &Server->OptDefs.Array, &Loc, &OptClassDefList );
  79. ASSERT( NO_ERROR == Error );
  80. Ctxt.UserClass = FindClass( Server, OptClassDefList->ClassId );
  81. Ctxt.VendorClass = FindClass( Server, OptClassDefList->VendorId );
  82. Error = MemArrayInitLoc(
  83. &OptClassDefList->OptDefList.OptDefArray, &Loc2 );
  84. while( NO_ERROR == Error ) {
  85. Error = MemArrayGetElement(
  86. &OptClassDefList->OptDefList.OptDefArray, &Loc2,
  87. &OptDef );
  88. ASSERT( NO_ERROR == Error );
  89. Ctxt.OptDef = OptDef;
  90. Error = Callback( &Ctxt );
  91. if( ERROR_KEY_DELETED == Error ) {
  92. //
  93. // Delete this optdef..
  94. //
  95. MemArrayDelElement(
  96. &OptClassDefList->OptDefList.OptDefArray,
  97. &Loc2, &OptDef );
  98. MemOptDefFree( OptDef );
  99. Error = MemArrayAdjustLocation(
  100. &OptClassDefList->OptDefList.OptDefArray,
  101. &Loc2 );
  102. } else {
  103. if( NO_ERROR != Error ) return Error;
  104. Error = MemArrayNextLoc(
  105. &OptClassDefList->OptDefList.OptDefArray, &Loc2 );
  106. }
  107. }
  108. if( ERROR_FILE_NOT_FOUND != Error ) return Error;
  109. Error = MemArrayNextLoc( &Server->OptDefs.Array, &Loc );
  110. }
  111. if( ERROR_FILE_NOT_FOUND == Error ) Error = NO_ERROR;
  112. return Error;
  113. }
  114. DWORD
  115. IterateOptionsOnOptClass(
  116. IN PM_SERVER Server,
  117. IN PM_OPTCLASS OptClass,
  118. IN PVOID ExtraCtxt,
  119. IN DWORD (*Callback)( IN OUT PMM_ITERATE_CTXT )
  120. )
  121. {
  122. ARRAY_LOCATION Loc, Loc2;
  123. DWORD Error;
  124. MM_ITERATE_CTXT Ctxt;
  125. PM_OPTION Option;
  126. PM_ONECLASS_OPTLIST OptList;
  127. Ctxt.ExtraCtxt = ExtraCtxt;
  128. Ctxt.Server = Server;
  129. Error = MemArrayInitLoc( &OptClass->Array, &Loc );
  130. while( NO_ERROR == Error ) {
  131. Error = MemArrayGetElement(
  132. &OptClass->Array, &Loc, &OptList );
  133. ASSERT( NO_ERROR == Error );
  134. Ctxt.UserClass = FindClass( Server, OptList->ClassId );
  135. Ctxt.VendorClass = FindClass( Server, OptList->VendorId );
  136. Error = MemArrayInitLoc( &OptList->OptList, &Loc2 );
  137. while( NO_ERROR == Error ) {
  138. Error = MemArrayGetElement(
  139. &OptList->OptList, &Loc2, &Option );
  140. ASSERT( NO_ERROR == Error );
  141. Ctxt.Option = Option;
  142. Error = Callback( &Ctxt );
  143. if( NO_ERROR != Error ) return Error;
  144. Error = MemArrayNextLoc( &OptList->OptList, &Loc2 );
  145. }
  146. if( ERROR_FILE_NOT_FOUND != Error ) return Error;
  147. Error = MemArrayNextLoc( &OptClass->Array, &Loc );
  148. }
  149. if( ERROR_FILE_NOT_FOUND == Error ) Error = NO_ERROR;
  150. return Error;
  151. }
  152. DWORD
  153. IterateServerOptions(
  154. IN PM_SERVER Server,
  155. IN PVOID ExtraCtxt,
  156. IN DWORD (*Callback)( IN OUT PMM_ITERATE_CTXT )
  157. )
  158. {
  159. return IterateOptionsOnOptClass(
  160. Server, &Server->Options, ExtraCtxt, Callback );
  161. }
  162. DWORD
  163. IterateScopeOptions(
  164. IN PM_SUBNET Subnet,
  165. IN PVOID ExtraCtxt,
  166. IN DWORD (*Callback)( IN OUT PMM_ITERATE_CTXT )
  167. )
  168. {
  169. return IterateOptionsOnOptClass(
  170. (PM_SERVER)Subnet->ServerPtr,
  171. &Subnet->Options, ExtraCtxt, Callback );
  172. }
  173. DWORD
  174. IterateReservationOptions(
  175. IN PM_SERVER Server,
  176. IN PM_RESERVATION Res,
  177. IN PVOID ExtraCtxt,
  178. IN DWORD (*Callback)( IN OUT PMM_ITERATE_CTXT )
  179. )
  180. {
  181. PM_SUBNET Subnet = NULL;
  182. MemServerGetUAddressInfo(
  183. Server, Res->Address, &Subnet, NULL, NULL, NULL );
  184. return IterateOptionsOnOptClass(
  185. Server, &Res->Options, ExtraCtxt, Callback );
  186. }
  187. PM_SSCOPE
  188. FindSScope(
  189. IN PM_SERVER Server,
  190. IN DWORD SScopeId
  191. )
  192. {
  193. DWORD Error;
  194. PM_SSCOPE SScope;
  195. if( SScopeId == INVALID_SSCOPE_ID ) return NULL;
  196. Error = MemServerFindSScope(
  197. Server, SScopeId, NULL, &SScope );
  198. if( NO_ERROR != Error ) return NULL;
  199. return SScope;
  200. }
  201. DWORD
  202. IterateScopes(
  203. IN PM_SERVER Server,
  204. IN PVOID ExtraCtxt,
  205. IN DWORD (*Callback)( IN OUT PMM_ITERATE_CTXT )
  206. )
  207. {
  208. ARRAY_LOCATION Loc;
  209. DWORD Error;
  210. MM_ITERATE_CTXT Ctxt;
  211. PM_SUBNET Scope;
  212. Ctxt.ExtraCtxt = ExtraCtxt;
  213. Ctxt.Server = Server;
  214. Error = MemArrayInitLoc( &Server->Subnets, &Loc );
  215. while( NO_ERROR == Error ) {
  216. Error = MemArrayGetElement(
  217. &Server->Subnets, &Loc, &Scope );
  218. ASSERT( NO_ERROR == Error );
  219. Ctxt.SScope = FindSScope( Server, Scope->SuperScopeId );
  220. Ctxt.Scope = Scope;
  221. Error = Callback( &Ctxt );
  222. if( ERROR_KEY_DELETED == Error ) {
  223. //
  224. // Delete this scope
  225. //
  226. MemArrayDelElement(
  227. &Server->Subnets, &Loc, &Scope );
  228. MemSubnetFree( Scope );
  229. Error = MemArrayAdjustLocation(
  230. &Server->Subnets, &Loc );
  231. } else {
  232. if( NO_ERROR != Error ) return Error;
  233. Error = MemArrayNextLoc( &Server->Subnets, &Loc );
  234. }
  235. }
  236. if( ERROR_FILE_NOT_FOUND == Error ) Error = NO_ERROR;
  237. return Error;
  238. }
  239. DWORD
  240. IterateScopeRanges(
  241. IN PM_SUBNET Scope,
  242. IN PVOID ExtraCtxt,
  243. IN DWORD (*Callback)( IN OUT PMM_ITERATE_CTXT )
  244. )
  245. {
  246. ARRAY_LOCATION Loc;
  247. DWORD Error;
  248. MM_ITERATE_CTXT Ctxt;
  249. PM_RANGE Range;
  250. Ctxt.ExtraCtxt = ExtraCtxt;
  251. Ctxt.Server = (PM_SERVER)Scope->ServerPtr;
  252. Error = MemArrayInitLoc( &Scope->Ranges, &Loc );
  253. while( NO_ERROR == Error ) {
  254. Error = MemArrayGetElement(
  255. &Scope->Ranges, &Loc, &Range );
  256. ASSERT( NO_ERROR == Error );
  257. Ctxt.Range = Range;
  258. Error = Callback( &Ctxt );
  259. if( NO_ERROR != Error ) return Error;
  260. Error = MemArrayNextLoc( &Scope->Ranges, &Loc );
  261. }
  262. if( ERROR_FILE_NOT_FOUND == Error ) Error = NO_ERROR;
  263. return Error;
  264. }
  265. DWORD
  266. IterateScopeExclusions(
  267. IN PM_SUBNET Scope,
  268. IN PVOID ExtraCtxt,
  269. IN DWORD (*Callback)( IN OUT PMM_ITERATE_CTXT )
  270. )
  271. {
  272. ARRAY_LOCATION Loc;
  273. DWORD Error;
  274. MM_ITERATE_CTXT Ctxt;
  275. PM_EXCL Excl;
  276. Ctxt.ExtraCtxt = ExtraCtxt;
  277. Ctxt.Server = (PM_SERVER)Scope->ServerPtr;
  278. Error = MemArrayInitLoc( &Scope->Exclusions, &Loc );
  279. while( NO_ERROR == Error ) {
  280. Error = MemArrayGetElement(
  281. &Scope->Exclusions, &Loc, &Excl );
  282. ASSERT( NO_ERROR == Error );
  283. Ctxt.Excl = Excl;
  284. Error = Callback( &Ctxt );
  285. if( NO_ERROR != Error ) return Error;
  286. Error = MemArrayNextLoc( &Scope->Exclusions, &Loc );
  287. }
  288. if( ERROR_FILE_NOT_FOUND == Error ) Error = NO_ERROR;
  289. return Error;
  290. }
  291. DWORD
  292. IterateScopeReservations(
  293. IN PM_SUBNET Scope,
  294. IN PVOID ExtraCtxt,
  295. IN DWORD (*Callback)( IN OUT PMM_ITERATE_CTXT )
  296. )
  297. {
  298. ARRAY_LOCATION Loc;
  299. DWORD Error;
  300. MM_ITERATE_CTXT Ctxt;
  301. PM_RESERVATION Res;
  302. Ctxt.ExtraCtxt = ExtraCtxt;
  303. Ctxt.Server = (PM_SERVER)Scope->ServerPtr;
  304. Error = MemArrayInitLoc( &Scope->Reservations, &Loc );
  305. while( NO_ERROR == Error ) {
  306. Error = MemArrayGetElement(
  307. &Scope->Reservations, &Loc, &Res );
  308. ASSERT( NO_ERROR == Error );
  309. Ctxt.Res = Res;
  310. Error = Callback( &Ctxt );
  311. if( NO_ERROR != Error ) return Error;
  312. Error = MemArrayNextLoc( &Scope->Reservations, &Loc );
  313. }
  314. if( ERROR_FILE_NOT_FOUND == Error ) Error = NO_ERROR;
  315. return Error;
  316. }