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