]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Application/IpsecConfig/ForEach.c
Add NetworkPkg (P.UDK2010.UP3.Network.P1)
[mirror_edk2.git] / NetworkPkg / Application / IpsecConfig / ForEach.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 The implementation to go through each entry in IpSecConfig application.\r
3\r
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "IpSecConfig.h"\r
17#include "ForEach.h"\r
18\r
19\r
20/**\r
21 Enumerate all entries in the database to execute specified operations according to datatype.\r
22\r
23 @param[in] DataType The value of EFI_IPSEC_CONFIG_DATA_TYPE.\r
24 @param[in] Routine The pointer to the function of a specified operation.\r
25 @param[in] Context The pointer to the context of a function.\r
26\r
27 @retval EFI_SUCCESS Execute specified operation successfully.\r
28**/\r
29EFI_STATUS\r
30ForeachPolicyEntry (\r
31 IN EFI_IPSEC_CONFIG_DATA_TYPE DataType,\r
32 IN VISIT_POLICY_ENTRY Routine,\r
33 IN VOID *Context\r
34 )\r
35{\r
36 EFI_STATUS GetNextStatus;\r
37 EFI_STATUS GetDataStatus;\r
38 EFI_IPSEC_CONFIG_SELECTOR *Selector;\r
39 VOID *Data;\r
40 UINTN SelectorSize;\r
41 UINTN DataSize;\r
42 BOOLEAN FirstGetNext;\r
43\r
44 FirstGetNext = TRUE;\r
45 SelectorSize = sizeof (EFI_IPSEC_CONFIG_SELECTOR);\r
46 Selector = AllocateZeroPool (SelectorSize);\r
47\r
48 DataSize = 0;\r
49 Data = NULL;\r
50\r
51 while (TRUE) {\r
52 GetNextStatus = mIpSecConfig->GetNextSelector (\r
53 mIpSecConfig,\r
54 DataType,\r
55 &SelectorSize,\r
56 Selector\r
57 );\r
58 if (GetNextStatus == EFI_BUFFER_TOO_SMALL) {\r
59 gBS->FreePool (Selector);\r
60 Selector = FirstGetNext ? AllocateZeroPool (SelectorSize) : AllocatePool (SelectorSize);\r
61\r
62 GetNextStatus = mIpSecConfig->GetNextSelector (\r
63 mIpSecConfig,\r
64 DataType,\r
65 &SelectorSize,\r
66 Selector\r
67 );\r
68 }\r
69\r
70 if (EFI_ERROR (GetNextStatus)) {\r
71 break;\r
72 }\r
73\r
74 FirstGetNext = FALSE;\r
75\r
76 GetDataStatus = mIpSecConfig->GetData (\r
77 mIpSecConfig,\r
78 DataType,\r
79 Selector,\r
80 &DataSize,\r
81 Data\r
82 );\r
83 if (GetDataStatus == EFI_BUFFER_TOO_SMALL) {\r
84 if (Data != NULL) {\r
85 gBS->FreePool (Data);\r
86 }\r
87\r
88 Data = AllocateZeroPool (DataSize);\r
89 GetDataStatus = mIpSecConfig->GetData (\r
90 mIpSecConfig,\r
91 DataType,\r
92 Selector,\r
93 &DataSize,\r
94 Data\r
95 );\r
96 }\r
97\r
98 ASSERT_EFI_ERROR (GetDataStatus);\r
99\r
100 if (EFI_ERROR (Routine (Selector, Data, Context))) {\r
101 break;\r
102 }\r
103 }\r
104\r
105 if (Data != NULL) {\r
106 gBS->FreePool (Data);\r
107 }\r
108\r
109 if (Selector != NULL) {\r
110 gBS->FreePool (Selector);\r
111 }\r
112\r
113 return EFI_SUCCESS;\r
114}\r
115\r