]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/ShellParametersProtocol.h
ShellPkg: Fix memory leak in 'InternalShellExecuteDevicePath'.
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellParametersProtocol.h
CommitLineData
a405b86d 1/** @file\r
2 Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,\r
3 manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.\r
4\r
4ccd9214 5 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
a405b86d 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#ifndef _SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_\r
17#define _SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_\r
18\r
a405b86d 19#include "Shell.h"\r
20\r
d1c275c6
QS
21typedef enum {\r
22 Internal_Command,\r
23 Script_File_Name,\r
24 Efi_Application,\r
25 File_Sys_Change,\r
26 Unknown_Invalid\r
27} SHELL_OPERATION_TYPES;\r
28\r
a405b86d 29/**\r
30 creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then\r
31 installs it on our handle and if there is an existing version of the protocol\r
32 that one is cached for removal later.\r
33\r
4ff7e37b 34 @param[in, out] NewShellParameters on a successful return, a pointer to pointer\r
a405b86d 35 to the newly installed interface.\r
4ff7e37b 36 @param[in, out] RootShellInstance on a successful return, pointer to boolean.\r
a405b86d 37 TRUE if this is the root shell instance.\r
38\r
39 @retval EFI_SUCCESS the operation completed successfully.\r
40 @return other the operation failed.\r
41 @sa ReinstallProtocolInterface\r
42 @sa InstallProtocolInterface\r
43 @sa ParseCommandLineToArgs\r
44**/\r
45EFI_STATUS\r
46EFIAPI\r
47CreatePopulateInstallShellParametersProtocol (\r
48 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL **NewShellParameters,\r
49 IN OUT BOOLEAN *RootShellInstance\r
50 );\r
51\r
52/**\r
53 frees all memory used by createion and installation of shell parameters protocol\r
54 and if there was an old version installed it will restore that one.\r
55\r
56 @param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is\r
57 being cleaned up.\r
58\r
59 @retval EFI_SUCCESS the cleanup was successful\r
60 @return other the cleanup failed\r
61 @sa ReinstallProtocolInterface\r
62 @sa UninstallProtocolInterface\r
63**/\r
64EFI_STATUS\r
65EFIAPI\r
66CleanUpShellParametersProtocol (\r
67 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParameters\r
68 );\r
69\r
70/**\r
71 Funcion will replace the current Argc and Argv in the ShellParameters protocol\r
72 structure by parsing NewCommandLine. The current values are returned to the\r
73 user.\r
74\r
4ff7e37b 75 @param[in, out] ShellParameters pointer to parameter structure to modify\r
a405b86d 76 @param[in] NewCommandLine the new command line to parse and use\r
d1c275c6 77 @param[in] Type the type of operation.\r
a405b86d 78 @param[out] OldArgv pointer to old list of parameters\r
79 @param[out] OldArgc pointer to old number of items in Argv list\r
80\r
81 @retval EFI_SUCCESS operation was sucessful, Argv and Argc are valid\r
82 @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r
83**/\r
84EFI_STATUS\r
85EFIAPI\r
86UpdateArgcArgv(\r
87 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,\r
88 IN CONST CHAR16 *NewCommandLine,\r
d1c275c6 89 IN SHELL_OPERATION_TYPES Type,\r
a405b86d 90 OUT CHAR16 ***OldArgv,\r
91 OUT UINTN *OldArgc\r
92 );\r
93\r
94/**\r
95 Funcion will replace the current Argc and Argv in the ShellParameters protocol\r
96 structure with Argv and Argc. The current values are de-allocated and the\r
97 OldArgv must not be deallocated by the caller.\r
98\r
4ff7e37b
ED
99 @param[in, out] ShellParameters pointer to parameter structure to modify\r
100 @param[in] OldArgv pointer to old list of parameters\r
101 @param[in] OldArgc pointer to old number of items in Argv list\r
a405b86d 102**/\r
103VOID\r
104EFIAPI\r
105RestoreArgcArgv(\r
106 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,\r
107 IN CHAR16 ***OldArgv,\r
108 IN UINTN *OldArgc\r
109 );\r
110\r
8be0ba36 111typedef struct {\r
112 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;\r
113 EFI_HANDLE ConInHandle;\r
114 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;\r
115 EFI_HANDLE ConOutHandle;\r
4ccd9214
ED
116 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ErrOut;\r
117 EFI_HANDLE ErrOutHandle;\r
8be0ba36 118} SYSTEM_TABLE_INFO;\r
119\r
a405b86d 120/**\r
121 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol\r
122 structure by parsing NewCommandLine. The current values are returned to the\r
123 user.\r
124\r
fb84495a 125 This will also update the system table.\r
a405b86d 126\r
4ff7e37b
ED
127 @param[in, out] ShellParameters Pointer to parameter structure to modify.\r
128 @param[in] NewCommandLine The new command line to parse and use.\r
129 @param[out] OldStdIn Pointer to old StdIn.\r
130 @param[out] OldStdOut Pointer to old StdOut.\r
131 @param[out] OldStdErr Pointer to old StdErr.\r
132 @param[out] SystemTableInfo Pointer to old system table information.\r
a405b86d 133\r
134 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.\r
135 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
136**/\r
137EFI_STATUS\r
138EFIAPI\r
139UpdateStdInStdOutStdErr(\r
140 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,\r
fb84495a 141 IN CHAR16 *NewCommandLine,\r
8be0ba36 142 OUT SHELL_FILE_HANDLE *OldStdIn,\r
143 OUT SHELL_FILE_HANDLE *OldStdOut,\r
144 OUT SHELL_FILE_HANDLE *OldStdErr,\r
145 OUT SYSTEM_TABLE_INFO *SystemTableInfo\r
a405b86d 146 );\r
147\r
148/**\r
149 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol\r
150 structure with StdIn and StdOut. The current values are de-allocated.\r
151\r
4ff7e37b
ED
152 @param[in, out] ShellParameters Pointer to parameter structure to modify.\r
153 @param[in] OldStdIn Pointer to old StdIn.\r
154 @param[in] OldStdOut Pointer to old StdOut.\r
155 @param[in] OldStdErr Pointer to old StdErr.\r
156 @param[in] SystemTableInfo Pointer to old system table information.\r
a405b86d 157**/\r
158EFI_STATUS\r
159EFIAPI\r
160RestoreStdInStdOutStdErr (\r
161 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,\r
8be0ba36 162 IN SHELL_FILE_HANDLE *OldStdIn,\r
163 IN SHELL_FILE_HANDLE *OldStdOut,\r
164 IN SHELL_FILE_HANDLE *OldStdErr,\r
165 IN SYSTEM_TABLE_INFO *SystemTableInfo\r
a405b86d 166 );\r
167\r
168/**\r
169 function to populate Argc and Argv.\r
170\r
171 This function parses the CommandLine and divides it into standard C style Argc/Argv\r
172 parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space\r
173 delimited and quote surrounded parameter definition.\r
174\r
d1c275c6
QS
175 @param[in] CommandLine String of command line to parse\r
176 @param[in] StripQuotation if TRUE then strip the quotation marks surrounding\r
177 the parameters.\r
178 @param[in, out] Argv pointer to array of strings; one for each parameter\r
179 @param[in, out] Argc pointer to number of strings in Argv array\r
a405b86d 180\r
181 @return EFI_SUCCESS the operation was sucessful\r
182 @return EFI_OUT_OF_RESOURCES a memory allocation failed.\r
183**/\r
184EFI_STATUS\r
185EFIAPI\r
186ParseCommandLineToArgs(\r
187 IN CONST CHAR16 *CommandLine,\r
d1c275c6
QS
188 IN BOOLEAN StripQuotation,\r
189 IN OUT CHAR16 ***Argv,\r
190 IN OUT UINTN *Argc\r
a405b86d 191 );\r
192\r
193/**\r
194 return the next parameter from a command line string;\r
195\r
196 This function moves the next parameter from Walker into TempParameter and moves\r
197 Walker up past that parameter for recursive calling. When the final parameter\r
198 is moved *Walker will be set to NULL;\r
199\r
200 Temp Parameter must be large enough to hold the parameter before calling this\r
201 function.\r
202\r
d1c275c6
QS
203 @param[in, out] Walker pointer to string of command line. Adjusted to\r
204 reminaing command line on return\r
205 @param[in, out] TempParameter pointer to string of command line item extracted.\r
206 @param[in] Length Length of (*TempParameter) in bytes\r
207 @param[in] StripQuotation if TRUE then strip the quotation marks surrounding\r
208 the parameters.\r
a405b86d 209\r
14030c5c
JC
210 @return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.\r
211 @return EFI_NOT_FOUND A closing " could not be found on the specified string\r
a405b86d 212**/\r
14030c5c 213EFI_STATUS\r
a405b86d 214EFIAPI\r
215GetNextParameter(\r
7f79b01e
JC
216 IN OUT CHAR16 **Walker,\r
217 IN OUT CHAR16 **TempParameter,\r
d1c275c6
QS
218 IN CONST UINTN Length,\r
219 IN BOOLEAN StripQuotation\r
a405b86d 220 );\r
221\r
222#endif //_SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_\r
223\r