MdePkg: Add ToText/FromText support for URI device path node
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 8 May 2015 07:31:39 +0000 (07:31 +0000)
committerniruiyu <niruiyu@Edk2>
Fri, 8 May 2015 07:31:39 +0000 (07:31 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17370 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
MdePkg/Library/UefiDevicePathLib/DevicePathToText.c

index dec084c..e3ab6e1 100644 (file)
@@ -2741,6 +2741,38 @@ DevPathFromTextBluetooth (
   return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothDp;\r
 }\r
 \r
+/**\r
+  Converts a text device path node to URI device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created URI device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUri (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16           *UriStr;\r
+  UINTN            UriLength;\r
+  URI_DEVICE_PATH  *Uri;\r
+\r
+  UriStr = GetNextParamStr (&TextDeviceNode);\r
+  UriLength = StrnLenS (UriStr, MAX_UINT16 - sizeof (URI_DEVICE_PATH));\r
+  Uri    = (URI_DEVICE_PATH *) CreateDeviceNode (\r
+                                 MESSAGING_DEVICE_PATH,\r
+                                 MSG_URI_DP,\r
+                                 (UINT16) (sizeof (URI_DEVICE_PATH) + UriLength)\r
+                                 );\r
+\r
+  while (UriLength-- != 0) {\r
+    Uri->Uri[UriLength] = (CHAR8) UriStr[UriLength];\r
+  }\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Uri;\r
+}\r
+\r
 /**\r
   Converts a media text device path node to media device path structure.\r
 \r
@@ -3181,6 +3213,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
   {L"Unit",                    DevPathFromTextUnit                    },\r
   {L"iSCSI",                   DevPathFromTextiSCSI                   },\r
   {L"Vlan",                    DevPathFromTextVlan                    },\r
+  {L"Uri",                     DevPathFromTextUri                     },\r
   {L"Bluetooth",               DevPathFromTextBluetooth               },\r
   {L"MediaPath",               DevPathFromTextMediaPath               },\r
   {L"HD",                      DevPathFromTextHD                      },\r
index af1a6d6..95d3ecd 100644 (file)
@@ -1530,6 +1530,45 @@ DevPathToTextBluetooth (
     );\r
 }\r
 \r
+/**\r
+  Converts a URI device path structure to its string representative.\r
+\r
+  @param Str             The string representative of input device.\r
+  @param DevPath         The input device path structure.\r
+  @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation\r
+                         of the display node is used, where applicable. If DisplayOnly\r
+                         is FALSE, then the longer text representation of the display node\r
+                         is used.\r
+  @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text\r
+                         representation for a device node can be used, where applicable.\r
+\r
+**/\r
+VOID\r
+DevPathToTextUri (\r
+  IN OUT POOL_PRINT  *Str,\r
+  IN VOID            *DevPath,\r
+  IN BOOLEAN         DisplayOnly,\r
+  IN BOOLEAN         AllowShortcuts\r
+  )\r
+{\r
+  URI_DEVICE_PATH    *Uri;\r
+  UINTN              UriLength;\r
+  CHAR8              *UriStr;\r
+\r
+  //\r
+  // Uri in the device path may not be null terminated.\r
+  //\r
+  Uri       = DevPath;\r
+  UriLength = DevicePathNodeLength (Uri) - sizeof (URI_DEVICE_PATH);\r
+  UriStr = AllocatePool (UriLength + 1);\r
+  ASSERT (UriStr != NULL);\r
+\r
+  CopyMem (UriStr, Uri->Uri, UriLength);\r
+  UriStr[UriLength] = '\0';\r
+  UefiDevicePathLibCatPrint (Str, L"Uri(%a)", UriStr);\r
+  FreePool (UriStr);\r
+}\r
+\r
 /**\r
   Converts a Hard drive device path structure to its string representative.\r
 \r
@@ -1948,6 +1987,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLib
   {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,                    DevPathToTextVendor         },\r
   {MESSAGING_DEVICE_PATH, MSG_ISCSI_DP,                     DevPathToTextiSCSI          },\r
   {MESSAGING_DEVICE_PATH, MSG_VLAN_DP,                      DevPathToTextVlan           },\r
+  {MESSAGING_DEVICE_PATH, MSG_URI_DP,                       DevPathToTextUri            },\r
   {MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_DP,                 DevPathToTextBluetooth      },\r
   {MEDIA_DEVICE_PATH,     MEDIA_HARDDRIVE_DP,               DevPathToTextHardDrive      },\r
   {MEDIA_DEVICE_PATH,     MEDIA_CDROM_DP,                   DevPathToTextCDROM          },\r