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.

255 lines
8.0 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: implements the basic structures for superscopes
  5. // ThreadSafe: no
  6. // Locks: none
  7. // Please read stdinfo.txt for programming style.
  8. //================================================================================
  9. #include <mm.h>
  10. #include <array.h>
  11. #include <opt.h>
  12. #include <optl.h>
  13. #include <optclass.h>
  14. #include "reserve.h"
  15. //BeginExport(function)
  16. DWORD
  17. MemReserveAdd( // new client, should not exist before
  18. IN OUT PM_RESERVATIONS Reservation,
  19. IN DWORD Address,
  20. IN DWORD Flags,
  21. IN LPBYTE ClientUID,
  22. IN DWORD ClientUIDSize,
  23. IN ULONG UniqId
  24. ) //EndExport(function)
  25. {
  26. DWORD Error;
  27. DWORD LocalError;
  28. PM_RESERVATION Res1;
  29. ARRAY_LOCATION Loc;
  30. AssertRet(Reservation && Address && ClientUID && ClientUIDSize, ERROR_INVALID_PARAMETER);
  31. Error = MemArrayInitLoc(Reservation, &Loc);
  32. while( ERROR_FILE_NOT_FOUND != Error ) { // check to see if this Address already exists
  33. Require(ERROR_SUCCESS == Error );
  34. Error = MemArrayGetElement(Reservation, &Loc, &Res1);
  35. Require(ERROR_SUCCESS == Error && Res1);
  36. if( Address == Res1->Address ) return ERROR_OBJECT_ALREADY_EXISTS;
  37. if( ClientUIDSize == Res1->nBytes && 0 == memcmp(ClientUID, Res1->ClientUID, Res1->nBytes) )
  38. return ERROR_OBJECT_ALREADY_EXISTS;
  39. Error = MemArrayNextLoc(Reservation, &Loc);
  40. }
  41. Error = MemReserve1Init(
  42. &Res1,
  43. Address,
  44. Flags,
  45. ClientUID,
  46. ClientUIDSize
  47. );
  48. if( ERROR_SUCCESS != Error ) return Error;
  49. Res1->UniqId = UniqId;
  50. Error = MemArrayAddElement(Reservation, Res1);
  51. if( ERROR_SUCCESS == Error ) return ERROR_SUCCESS;
  52. LocalError = MemReserve1Cleanup(Res1);
  53. Require(ERROR_SUCCESS == LocalError);
  54. return Error;
  55. }
  56. //BeginExport(function)
  57. DWORD
  58. MemReserveReplace( // old client, should exist before
  59. IN OUT PM_RESERVATIONS Reservation,
  60. IN DWORD Address,
  61. IN DWORD Flags,
  62. IN LPBYTE ClientUID,
  63. IN DWORD ClientUIDSize
  64. ) //EndExport(function)
  65. {
  66. DWORD Error;
  67. DWORD LocalError;
  68. PM_RESERVATION Res1, Res_Deleted;
  69. ARRAY_LOCATION Loc;
  70. AssertRet(Reservation && Address && ClientUID && ClientUIDSize, ERROR_INVALID_PARAMETER);
  71. Error = MemArrayInitLoc(Reservation, &Loc);
  72. while( ERROR_FILE_NOT_FOUND != Error ) { // check to see if this Address already exists
  73. Require(ERROR_SUCCESS == Error );
  74. Error = MemArrayGetElement(Reservation, &Loc, &Res1);
  75. Require(ERROR_SUCCESS == Error && Res1);
  76. if( Address == Res1->Address ) {
  77. Error = DeleteRecord( Res1->UniqId );
  78. if ( ERROR_SUCCESS != Error ) {
  79. return Error;
  80. }
  81. Error = MemArrayDelElement(Reservation, &Loc, (LPVOID *)&Res_Deleted);
  82. Require(ERROR_SUCCESS == Error && Res_Deleted);
  83. break;
  84. }
  85. Error = MemArrayNextLoc(Reservation, &Loc);
  86. } // while
  87. if( ERROR_SUCCESS != Error ) return Error;
  88. Error = MemReserve1Init(
  89. &Res1,
  90. Address,
  91. Flags,
  92. ClientUID,
  93. ClientUIDSize
  94. );
  95. Require( NULL != Res_Deleted );
  96. if( ERROR_SUCCESS != Error ) {
  97. Res_Deleted->UniqId = INVALID_UNIQ_ID;
  98. LocalError = MemArrayAddElement(Reservation, Res_Deleted);
  99. Require(ERROR_SUCCESS == LocalError); // just deleted this guy -- should not have trouble adding back
  100. return Error;
  101. }
  102. Res1->Options = Res_Deleted->Options;
  103. Res1->SubnetPtr = Res_Deleted->SubnetPtr;
  104. MemFree(Res_Deleted);
  105. Res1->UniqId = INVALID_UNIQ_ID;
  106. Error = MemArrayAddElement(Reservation, Res1);
  107. if( ERROR_SUCCESS == Error ) return ERROR_SUCCESS;
  108. LocalError = MemReserve1Cleanup(Res1);
  109. Require(ERROR_SUCCESS == LocalError);
  110. return Error;
  111. } // MemReserveReplace()
  112. //BeginExport(function)
  113. DWORD
  114. MemReserveDel(
  115. IN OUT PM_RESERVATIONS Reservation,
  116. IN DWORD Address
  117. ) //EndExport(function)
  118. {
  119. DWORD Error;
  120. PM_RESERVATION Res1;
  121. ARRAY_LOCATION Loc;
  122. AssertRet(Reservation && Address, ERROR_INVALID_PARAMETER);
  123. Error = MemArrayInitLoc(Reservation, &Loc);
  124. while( ERROR_FILE_NOT_FOUND != Error ) { // check to see if this Address already exists
  125. Require(ERROR_SUCCESS == Error );
  126. Error = MemArrayGetElement(Reservation, &Loc, &Res1);
  127. Require(ERROR_SUCCESS == Error && Res1);
  128. if( Address == Res1->Address ) {
  129. // Delete any associated Options
  130. Error = MemOptClassDelClass( &Res1->Options );
  131. if ( ERROR_SUCCESS != Error ) {
  132. return Error;
  133. }
  134. Error = DeleteRecord( Res1->UniqId );
  135. if ( ERROR_SUCCESS != Error ) {
  136. return Error;
  137. }
  138. Error = MemArrayDelElement(Reservation, &Loc, (LPVOID *)&Res1);
  139. Require(ERROR_SUCCESS == Error && Res1);
  140. Error = MemReserve1Cleanup(Res1);
  141. Require(ERROR_SUCCESS == Error);
  142. return Error;
  143. }
  144. Error = MemArrayNextLoc(Reservation, &Loc);
  145. } // while
  146. return ERROR_FILE_NOT_FOUND;
  147. } // MemReserveDel()
  148. //BeginExport(function)
  149. DWORD
  150. MemReserveFindByClientUID(
  151. IN PM_RESERVATIONS Reservation,
  152. IN LPBYTE ClientUID,
  153. IN DWORD ClientUIDSize,
  154. OUT PM_RESERVATION *Res
  155. ) //EndExport(function)
  156. {
  157. DWORD Error;
  158. PM_RESERVATION Res1;
  159. ARRAY_LOCATION Loc;
  160. AssertRet(Reservation && Res && ClientUID && ClientUIDSize, ERROR_INVALID_PARAMETER);
  161. *Res = NULL;
  162. Error = MemArrayInitLoc(Reservation, &Loc);
  163. while( ERROR_FILE_NOT_FOUND != Error ) { // check to see if this Address already exists
  164. Require(ERROR_SUCCESS == Error );
  165. Error = MemArrayGetElement(Reservation, &Loc, &Res1);
  166. Require(ERROR_SUCCESS == Error && Res1);
  167. if( ClientUIDSize == Res1->nBytes && 0 == memcmp(ClientUID, Res1->ClientUID, ClientUIDSize)) {
  168. *Res = Res1;
  169. return ERROR_SUCCESS;
  170. }
  171. Error = MemArrayNextLoc(Reservation, &Loc);
  172. }
  173. return ERROR_FILE_NOT_FOUND;
  174. }
  175. //BeginExport(function)
  176. DWORD
  177. MemReserveFindByAddress(
  178. IN PM_RESERVATIONS Reservation,
  179. IN DWORD Address,
  180. OUT PM_RESERVATION *Res
  181. ) //EndExport(function)
  182. {
  183. DWORD Error;
  184. PM_RESERVATION Res1;
  185. ARRAY_LOCATION Loc;
  186. AssertRet(Reservation && Address, ERROR_INVALID_PARAMETER);
  187. *Res = 0;
  188. Error = MemArrayInitLoc(Reservation, &Loc);
  189. while( ERROR_FILE_NOT_FOUND != Error ) { // check to see if this Address already exists
  190. Require(ERROR_SUCCESS == Error );
  191. Error = MemArrayGetElement(Reservation, &Loc, &Res1);
  192. Require(ERROR_SUCCESS == Error && Res1);
  193. if( Address == Res1->Address ) {
  194. *Res = Res1;
  195. return ERROR_SUCCESS;
  196. }
  197. Error = MemArrayNextLoc(Reservation, &Loc);
  198. }
  199. return ERROR_FILE_NOT_FOUND;
  200. }
  201. //================================================================================
  202. // end of file
  203. //================================================================================