ForEach.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /** @file
  2. The implementation to go through each entry in IpSecConfig application.
  3. Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "IpSecConfig.h"
  7. #include "ForEach.h"
  8. /**
  9. Enumerate all entries in the database to execute specified operations according to datatype.
  10. @param[in] DataType The value of EFI_IPSEC_CONFIG_DATA_TYPE.
  11. @param[in] Routine The pointer to the function of a specified operation.
  12. @param[in] Context The pointer to the context of a function.
  13. @retval EFI_SUCCESS Execute specified operation successfully.
  14. **/
  15. EFI_STATUS
  16. ForeachPolicyEntry (
  17. IN EFI_IPSEC_CONFIG_DATA_TYPE DataType,
  18. IN VISIT_POLICY_ENTRY Routine,
  19. IN VOID *Context
  20. )
  21. {
  22. EFI_STATUS GetNextStatus;
  23. EFI_STATUS GetDataStatus;
  24. EFI_IPSEC_CONFIG_SELECTOR *Selector;
  25. VOID *Data;
  26. UINTN SelectorSize;
  27. UINTN DataSize;
  28. BOOLEAN FirstGetNext;
  29. FirstGetNext = TRUE;
  30. SelectorSize = sizeof (EFI_IPSEC_CONFIG_SELECTOR);
  31. Selector = AllocateZeroPool (SelectorSize);
  32. DataSize = 0;
  33. Data = NULL;
  34. while (TRUE) {
  35. GetNextStatus = mIpSecConfig->GetNextSelector (
  36. mIpSecConfig,
  37. DataType,
  38. &SelectorSize,
  39. Selector
  40. );
  41. if (GetNextStatus == EFI_BUFFER_TOO_SMALL) {
  42. gBS->FreePool (Selector);
  43. Selector = FirstGetNext ? AllocateZeroPool (SelectorSize) : AllocatePool (SelectorSize);
  44. GetNextStatus = mIpSecConfig->GetNextSelector (
  45. mIpSecConfig,
  46. DataType,
  47. &SelectorSize,
  48. Selector
  49. );
  50. }
  51. if (EFI_ERROR (GetNextStatus)) {
  52. break;
  53. }
  54. FirstGetNext = FALSE;
  55. GetDataStatus = mIpSecConfig->GetData (
  56. mIpSecConfig,
  57. DataType,
  58. Selector,
  59. &DataSize,
  60. Data
  61. );
  62. if (GetDataStatus == EFI_BUFFER_TOO_SMALL) {
  63. if (Data != NULL) {
  64. gBS->FreePool (Data);
  65. }
  66. Data = AllocateZeroPool (DataSize);
  67. GetDataStatus = mIpSecConfig->GetData (
  68. mIpSecConfig,
  69. DataType,
  70. Selector,
  71. &DataSize,
  72. Data
  73. );
  74. }
  75. ASSERT_EFI_ERROR (GetDataStatus);
  76. if (EFI_ERROR (Routine (Selector, Data, Context))) {
  77. break;
  78. }
  79. }
  80. if (Data != NULL) {
  81. gBS->FreePool (Data);
  82. }
  83. if (Selector != NULL) {
  84. gBS->FreePool (Selector);
  85. }
  86. return EFI_SUCCESS;
  87. }