[Asterisk-code-review] manager: Fix GetConfigJSON returning invalid JSON (asterisk[master])

Ivan Poddubny asteriskteam at digium.com
Sat Oct 3 08:08:23 CDT 2015


Ivan Poddubny has uploaded a new change for review.

  https://gerrit.asterisk.org/1370

Change subject: manager: Fix GetConfigJSON returning invalid JSON
......................................................................

manager: Fix GetConfigJSON returning invalid JSON

When GetConfigJSON was introduced back in 1.6, it returned each
section as an array of strings: ["key=value", "key2=value2"].
Afterwards, it was changed a few times and became
["key": "value", "key2": "value2"], which is not a correct JSON.
This patch fixes that by constructing a JSON object {} instead of
an array [].

Also, the keys "istemplate" and "tempates" that are used to
indicate templates and their inherited categories are now wrapped in
quotes.

ASTERISK-25391 #close
Reported by: Bojan Nemčić

Change-Id: Ibbe93c6a227dff14d4a54b0d152341857bcf6ad8
---
M main/manager.c
1 file changed, 4 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/70/1370/1

diff --git a/main/manager.c b/main/manager.c
index 60e185b..2ea6fae 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -3477,18 +3477,18 @@
 		category_name = ast_category_get_name(cur_category);
 		astman_append(s, "%s\"", comma1 ? "," : "");
 		astman_append_json(s, category_name);
-		astman_append(s, "\":[");
+		astman_append(s, "\":{");
 		comma1 = 1;
 
 		if (ast_category_is_template(cur_category)) {
-			astman_append(s, "istemplate:1");
+			astman_append(s, "\"istemplate\":1");
 			comma2 = 1;
 		}
 
 		if ((templates = ast_category_get_templates(cur_category))
 			&& ast_str_strlen(templates) > 0) {
 			astman_append(s, "%s", comma2 ? "," : "");
-			astman_append(s, "templates:\"%s\"", ast_str_buffer(templates));
+			astman_append(s, "\"templates\":\"%s\"", ast_str_buffer(templates));
 			ast_free(templates);
 			comma2 = 1;
 		}
@@ -3502,7 +3502,7 @@
 			comma2 = 1;
 		}
 
-		astman_append(s, "]");
+		astman_append(s, "}");
 	}
 	astman_append(s, "}\r\n\r\n");
 

-- 
To view, visit https://gerrit.asterisk.org/1370
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibbe93c6a227dff14d4a54b0d152341857bcf6ad8
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Ivan Poddubny <ivan.poddubny at gmail.com>



More information about the asterisk-code-review mailing list