Add ability to use lib without json-c dependency

Adds 2 wrapper APIs to parse raw CPER & return char* for json
cperbuf_to_str_ir - parses a full CPER
cperbuf_single_section_to_str_ir - parses a single-section CPER

Change-Id: Ief018cc421497a8c366157a21e83ef60641e2646
Signed-off-by: Karthik Rajagopalan <krajagopalan@nvidia.com>
diff --git a/cper-parse.c b/cper-parse.c
index 4181a64..8c8722d 100644
--- a/cper-parse.c
+++ b/cper-parse.c
@@ -6,10 +6,12 @@
  **/
 
 #include <stdio.h>
+#include <string.h>
 #include <json.h>
 #include "base64.h"
 #include "edk/Cper.h"
 #include "cper-parse.h"
+#include "cper-parse-str.h"
 #include "cper-utils.h"
 #include "sections/cper-section.h"
 
@@ -81,6 +83,22 @@
 	return parent;
 }
 
+char *cper_to_str_ir(FILE *cper_file)
+{
+	json_object *jobj = cper_to_ir(cper_file);
+	char *str = jobj ? strdup(json_object_to_json_string(jobj)) : NULL;
+
+	json_object_put(jobj);
+	return str;
+}
+
+char *cperbuf_to_str_ir(const unsigned char *cper, size_t size)
+{
+	FILE *cper_file = fmemopen((void *)cper, size, "r");
+
+	return cper_file ? cper_to_str_ir(cper_file) : NULL;
+}
+
 //Converts a parsed CPER record header into intermediate JSON object format.
 json_object *cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER *header)
 {
@@ -385,3 +403,22 @@
 
 	return ir;
 }
+
+char *cper_single_section_to_str_ir(FILE *cper_section_file)
+{
+	json_object *jobj = cper_single_section_to_ir(cper_section_file);
+	char *str = jobj ? strdup(json_object_to_json_string(jobj)) : NULL;
+
+	json_object_put(jobj);
+	return str;
+}
+
+char *cperbuf_single_section_to_str_ir(const unsigned char *cper_section,
+				       size_t size)
+{
+	FILE *cper_section_file = fmemopen((void *)cper_section, size, "r");
+
+	return cper_section_file ?
+		       cper_single_section_to_str_ir(cper_section_file) :
+		       NULL;
+}