]> git.proxmox.com Git - mirror_edk2.git/commitdiff
RedfishPkg/JsonLib: Add JsonLoadString function
authorAbner Chang <abner.chang@hpe.com>
Fri, 29 Jan 2021 03:46:53 +0000 (11:46 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 24 Feb 2021 08:27:09 +0000 (08:27 +0000)
Add JsonLoadString function to load a NULL terminated-string JSON

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Nickle Wang <nickle.wang@hpe.com>
RedfishPkg/Include/Library/JsonLib.h
RedfishPkg/Library/JsonLib/JsonLib.c

index 3c10f67d2760a391655d996b7be883587ff62310..8a30c5250bb58a23ea6a6720c8a657c1d43860f4 100644 (file)
@@ -664,6 +664,27 @@ JsonDumpString (
   IN    UINTN               Flags\r
   );\r
 \r
+/**\r
+  Convert a string to JSON object.\r
+  The function is used to convert a NULL terminated CHAR8 string to a JSON\r
+  value. Only object and array represented strings can be converted successfully,\r
+  since they are the only valid root values of a JSON text for UEFI usage.\r
+\r
+  Real number and number with exponent part are not supportted by UEFI.\r
+\r
+  Caller needs to cleanup the root value by calling JsonValueFree().\r
+\r
+  @param[in]   String        The NULL terminated CHAR8 string to convert.\r
+\r
+  @retval      Array JSON value or object JSON value, or NULL when any error occurs.\r
+\r
+**/\r
+EDKII_JSON_VALUE\r
+EFIAPI\r
+JsonLoadString (\r
+  IN   CONST CHAR8*    String\r
+  );\r
+\r
 /**\r
   Load JSON from a buffer.\r
 \r
index 34ff381aee90a6dfcb4f506732adcb02fb3b2805..3693299afb55738b1261097316f7ee9d578c6633 100644 (file)
@@ -819,6 +819,32 @@ JsonDumpString (
     return json_dumps((json_t *)JsonValue, Flags);\r
 }\r
 \r
+/**\r
+  Convert a string to JSON object.\r
+  The function is used to convert a NULL terminated CHAR8 string to a JSON\r
+  value. Only object and array represented strings can be converted successfully,\r
+  since they are the only valid root values of a JSON text for UEFI usage.\r
+\r
+  Real number and number with exponent part are not supportted by UEFI.\r
+\r
+  Caller needs to cleanup the root value by calling JsonValueFree().\r
+\r
+  @param[in]   String        The NULL terminated CHAR8 string to convert.\r
+\r
+  @retval      Array JSON value or object JSON value, or NULL when any error occurs.\r
+\r
+**/\r
+EDKII_JSON_VALUE\r
+EFIAPI\r
+JsonLoadString (\r
+  IN    CONST CHAR8*    String\r
+  )\r
+{\r
+  json_error_t    JsonError;\r
+\r
+  return (EDKII_JSON_VALUE) json_loads ((const char *)String, 0, &JsonError);\r
+}\r
+\r
 /**\r
   Load JSON from a buffer.\r
 \r