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