1 /** @file 2 The implementation of delete policy entry function 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 "Indexer.h" 18 #include "Delete.h" 19 #include "Match.h" 20 #include "ForEach.h" 21 22 /** 23 Private function to delete entry information in database. 24 25 @param[in] Selector The pointer to EFI_IPSEC_CONFIG_SELECTOR structure. 26 @param[in] Data The pointer to Data. 27 @param[in] Context The pointer to DELETE_POLICY_ENTRY_CONTEXT. 28 29 @retval EFI_ABORTED Abort the iteration. 30 @retval EFI_SUCCESS Continue the iteration. 31 **/ 32 EFI_STATUS 33 DeletePolicyEntry ( 34 IN EFI_IPSEC_CONFIG_SELECTOR *Selector, 35 IN VOID *Data, 36 IN DELETE_POLICY_ENTRY_CONTEXT *Context 37 ) 38 { 39 if (mMatchPolicyEntry[Context->DataType] (Selector, Data, &Context->Indexer)) { 40 Context->Status = mIpSecConfig->SetData ( 41 mIpSecConfig, 42 Context->DataType, 43 Selector, 44 NULL, 45 NULL 46 ); 47 // 48 // Abort the iteration after the insertion. 49 // 50 return EFI_ABORTED; 51 } 52 53 return EFI_SUCCESS; 54 } 55 56 /** 57 Flush or delete entry information in the database according to datatype. 58 59 @param[in] DataType The value of EFI_IPSEC_CONFIG_DATA_TYPE. 60 @param[in] ParamPackage The pointer to the ParamPackage list. 61 62 @retval EFI_SUCCESS Delete entry information successfully. 63 @retval EFI_NOT_FOUND Can't find the specified entry. 64 @retval Others Some mistaken case. 65 **/ 66 EFI_STATUS 67 FlushOrDeletePolicyEntry ( 68 IN EFI_IPSEC_CONFIG_DATA_TYPE DataType, 69 IN LIST_ENTRY *ParamPackage 70 ) 71 { 72 EFI_STATUS Status; 73 DELETE_POLICY_ENTRY_CONTEXT Context; 74 CONST CHAR16 *ValueStr; 75 76 // 77 // If user wants to remove all. 78 // 79 if (ShellCommandLineGetFlag (ParamPackage, L"-f")) { 80 Status = mIpSecConfig->SetData ( 81 mIpSecConfig, 82 DataType, 83 NULL, 84 NULL, 85 NULL 86 ); 87 } else { 88 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d"); 89 if (ValueStr == NULL) { 90 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IPSEC_CONFIG_INDEX_NOT_SPECIFIED), mHiiHandle, mAppName, ValueStr); 91 return EFI_NOT_FOUND; 92 } 93 94 Status = mConstructPolicyEntryIndexer[DataType] (&Context.Indexer, ParamPackage); 95 if (!EFI_ERROR (Status)) { 96 Context.DataType = DataType; 97 Context.Status = EFI_NOT_FOUND; 98 ForeachPolicyEntry (DataType, (VISIT_POLICY_ENTRY) DeletePolicyEntry, &Context); 99 Status = Context.Status; 100 101 if (Status == EFI_NOT_FOUND) { 102 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IPSEC_CONFIG_INDEX_NOT_FOUND), mHiiHandle, mAppName, ValueStr); 103 } else if (EFI_ERROR (Status)) { 104 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IPSEC_CONFIG_DELETE_FAILED), mHiiHandle, mAppName); 105 } 106 } 107 } 108 109 return Status; 110 } 111