HttpDynamicCommand.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /** @file
  2. Produce "http" shell dynamic command.
  3. Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
  4. Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
  5. Copyright (c) 2020, Broadcom. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include <Protocol/ShellDynamicCommand.h>
  9. #include "Http.h"
  10. /**
  11. This is the shell command handler function pointer callback type. This
  12. function handles the command when it is invoked in the shell.
  13. @param[in] This The instance of the
  14. EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
  15. @param[in] SystemTable The pointer to the system table.
  16. @param[in] ShellParameters The parameters associated with the command.
  17. @param[in] Shell The instance of the shell protocol used in
  18. the context of processing this command.
  19. @return EFI_SUCCESS the operation was sucessful
  20. @return other the operation failed.
  21. **/
  22. SHELL_STATUS
  23. EFIAPI
  24. HttpCommandHandler (
  25. IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
  26. IN EFI_SYSTEM_TABLE *SystemTable,
  27. IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
  28. IN EFI_SHELL_PROTOCOL *Shell
  29. )
  30. {
  31. gEfiShellParametersProtocol = ShellParameters;
  32. gEfiShellProtocol = Shell;
  33. return RunHttp (gImageHandle, SystemTable);
  34. }
  35. /**
  36. This is the command help handler function pointer callback type. This
  37. function is responsible for displaying help information for the associated
  38. command.
  39. @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
  40. @param[in] Language The pointer to the language string to use.
  41. @return string Pool allocated help string, must be freed by caller
  42. **/
  43. CHAR16 *
  44. EFIAPI
  45. HttpCommandGetHelp (
  46. IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
  47. IN CONST CHAR8 *Language
  48. )
  49. {
  50. return HiiGetString (
  51. mHttpHiiHandle,
  52. STRING_TOKEN (STR_GET_HELP_HTTP),
  53. Language
  54. );
  55. }
  56. EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mHttpDynamicCommand = {
  57. HTTP_APP_NAME,
  58. HttpCommandHandler,
  59. HttpCommandGetHelp
  60. };
  61. /**
  62. Entry point of Http Dynamic Command.
  63. Produce the DynamicCommand protocol to handle "http" command.
  64. @param ImageHandle The image handle of the process.
  65. @param SystemTable The EFI System Table pointer.
  66. @retval EFI_SUCCESS Http command is executed sucessfully.
  67. @retval EFI_ABORTED HII package was failed to initialize.
  68. @retval others Other errors when executing http command.
  69. **/
  70. EFI_STATUS
  71. EFIAPI
  72. HttpCommandInitialize (
  73. IN EFI_HANDLE ImageHandle,
  74. IN EFI_SYSTEM_TABLE *SystemTable
  75. )
  76. {
  77. EFI_STATUS Status;
  78. mHttpHiiHandle = InitializeHiiPackage (ImageHandle);
  79. if (mHttpHiiHandle == NULL) {
  80. return EFI_ABORTED;
  81. }
  82. Status = gBS->InstallProtocolInterface (
  83. &ImageHandle,
  84. &gEfiShellDynamicCommandProtocolGuid,
  85. EFI_NATIVE_INTERFACE,
  86. &mHttpDynamicCommand
  87. );
  88. ASSERT_EFI_ERROR (Status);
  89. return Status;
  90. }
  91. /**
  92. Http driver unload handler.
  93. @param ImageHandle The image handle of the process.
  94. @retval EFI_SUCCESS The image is unloaded.
  95. @retval Others Failed to unload the image.
  96. **/
  97. EFI_STATUS
  98. EFIAPI
  99. HttpUnload (
  100. IN EFI_HANDLE ImageHandle
  101. )
  102. {
  103. EFI_STATUS Status;
  104. Status = gBS->UninstallProtocolInterface (
  105. ImageHandle,
  106. &gEfiShellDynamicCommandProtocolGuid,
  107. &mHttpDynamicCommand
  108. );
  109. if (EFI_ERROR (Status)) {
  110. return Status;
  111. }
  112. HiiRemovePackages (mHttpHiiHandle);
  113. return EFI_SUCCESS;
  114. }