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