Blob Blame History Raw
From fa7d98b0cb0512d84355e3aafdc5a3e366842f2a Mon Sep 17 00:00:00 2001
From: Radovan Sroka <rsroka@redhat.com>
Date: Mon, 21 Nov 2016 13:38:18 +0100
Subject: [PATCH 2/4] Rebased from: Patch2:
 rsyslog-7.2.1-msg_c_nonoverwrite_merge.patch

Resolves:
	no adressed bugzila
---
 runtime/msg.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/runtime/msg.c b/runtime/msg.c
index f6e017b..5430331 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -4632,6 +4632,27 @@ finalize_it:
 	RETiRet;
 }
 
+static rsRetVal jsonMerge(struct json_object *existing, struct json_object *json);
+
+static rsRetVal
+jsonMergeNonOverwrite(struct json_object *existing, struct json_object *json)
+{
+	DEFiRet;
+
+	struct json_object_iterator it = json_object_iter_begin(existing);
+	struct json_object_iterator itEnd = json_object_iter_end(existing);
+	while (!json_object_iter_equal(&it, &itEnd)) {
+		json_object_object_add(json, json_object_iter_peek_name(&it),
+			json_object_get(json_object_iter_peek_value(&it)));
+		json_object_iter_next(&it);
+	}
+
+	CHKiRet(jsonMerge(existing, json));
+finalize_it:
+	RETiRet;
+}
+
+
 static rsRetVal
 jsonMerge(struct json_object *existing, struct json_object *json)
 {
@@ -4714,7 +4735,7 @@ msgAddJSON(msg_t * const pM, uchar *name, struct json_object *json, int force_re
 		if(*pjroot == NULL)
 			*pjroot = json;
 		else
-			CHKiRet(jsonMerge(*pjroot, json));
+			CHKiRet(jsonMergeNonOverwrite(*pjroot, json));
 	} else {
 		if(*pjroot == NULL) {
 			/* now we need a root obj */
@@ -4742,7 +4763,7 @@ msgAddJSON(msg_t * const pM, uchar *name, struct json_object *json, int force_re
 			json_object_object_add(parent, (char*)leaf, json);
 		} else {
 			if(json_object_get_type(json) == json_type_object) {
-				CHKiRet(jsonMerge(*pjroot, json));
+				CHKiRet(jsonMergeNonOverwrite(*pjroot, json));
 			} else {
 				/* TODO: improve the code below, however, the current
 				 *       state is not really bad */
-- 
2.7.4