summaryrefslogtreecommitdiff
path: root/src/parse_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse_file.c')
-rw-r--r--src/parse_file.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/parse_file.c b/src/parse_file.c
index ae3a67b..59ed212 100644
--- a/src/parse_file.c
+++ b/src/parse_file.c
@@ -408,17 +408,22 @@ int __get_jsonobj_from_file(struct json_object **jsonObj, char *file_name)
int __create_system_config_file(struct json_object *jsonObj, char *write_file)
{
- int ret = 0;
+ int ret = 0, rv = 0;
if (jsonObj) {
struct json_object *jsonObjVer = NULL; // extract version object
// prepare json objects
- json_object_object_get_ex(jsonObj, "version", &jsonObjVer);
- json_object_object_del(jsonObj, "wifi");
- json_object_object_del(jsonObj, "ethernet");
+ if (json_object_object_get_ex(jsonObj, "version", &jsonObjVer)) {
+ json_object_object_del(jsonObj, "wifi");
+ json_object_object_del(jsonObj, "ethernet");
- json_object_to_file_ext(write_file, jsonObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+ rv = json_object_to_file_ext(write_file, jsonObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+ if (rv < 0)
+ ret = -1;
+ } else {
+ ret = -1;
+ }
} else {
ret = -1;
}
@@ -428,23 +433,31 @@ int __create_system_config_file(struct json_object *jsonObj, char *write_file)
int __create_target_config_file(struct json_object *jsonObj, char *write_file)
{
- int ret = 0;
+ int ret = 0, rv = 0;
if (jsonObj) {
struct json_object *jsonObjVer = NULL; // extract version object
struct json_object *jsonObjName = NULL; // extract deviceName object
// prepare json objects
- json_object_object_get_ex(jsonObj, "version", &jsonObjVer);
- json_object_object_get_ex(jsonObj, "deviceName", &jsonObjName);
+ if (json_object_object_get_ex(jsonObj, "version", &jsonObjVer)) {
+ if (json_object_object_get_ex(jsonObj, "deviceName", &jsonObjName)) {
- // result string for target
- struct json_object *jsonObjResultTarget = json_object_new_object();
- json_object_object_add(jsonObjResultTarget, "version", jsonObjVer);
- if (jsonObjName)
- json_object_object_add(jsonObjResultTarget, "deviceName", jsonObjName);
+ // result string for target
+ struct json_object *jsonObjResultTarget = json_object_new_object();
+ json_object_object_add(jsonObjResultTarget, "version", jsonObjVer);
+ if (jsonObjName)
+ json_object_object_add(jsonObjResultTarget, "deviceName", jsonObjName);
- json_object_to_file_ext(write_file, jsonObjResultTarget, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+ rv = json_object_to_file_ext(write_file, jsonObjResultTarget, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+ if (rv < 0)
+ ret = -1;
+ } else {
+ ret = -1;
+ }
+ } else {
+ ret = -1;
+ }
} else {
ret = -1;
}