Needed for #86.
Signed-off-by: Martin Milata <mmilata(a)redhat.com>
---
include/report.h | 8 ++++++++
lib/report.c | 14 ++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/include/report.h b/include/report.h
index 634c6e5..52d0149 100644
--- a/include/report.h
+++ b/include/report.h
@@ -28,6 +28,8 @@ extern "C" {
#include <inttypes.h>
#include <stdbool.h>
+struct sr_json_value;
+
struct sr_report
{
uint32_t report_version;
@@ -63,6 +65,12 @@ sr_report_free(struct sr_report *report);
char *
sr_report_to_json(struct sr_report *report);
+struct sr_report *
+sr_report_from_json(struct sr_json_value *root, char **error_message);
+
+struct sr_report *
+sr_report_from_json_text(const char *text, char **error_message);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/report.c b/lib/report.c
index 0b278b4..2b3ace4 100644
--- a/lib/report.c
+++ b/lib/report.c
@@ -375,3 +375,17 @@ fail:
sr_report_free(report);
return NULL;
}
+
+struct sr_report *
+sr_report_from_json_text(const char *report, char **error_message)
+{
+ struct sr_json_value *json_root = sr_json_parse(report, error_message);
+
+ if (!json_root)
+ return NULL;
+
+ struct sr_report *result = sr_report_from_json(json_root, error_message);
+
+ sr_json_value_free(json_root);
+ return result;
+}
--
1.8.3.1