summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2007-02-23 00:45:04 +0000
committerRussell Bryant <russell@russellbryant.com>2007-02-23 00:45:04 +0000
commit0d3a211335b2dcd00c1bb9ff5f991470a1ffca42 (patch)
tree5de242e9187dac9cf8533662abfa92dd95df8cbb
parent9138e53bc9ebff5449484fad08a2c60a5e0dd100 (diff)
Introduce a new manager action, GetConfigJSON, which is intended to improve
performance of the GUI. This encodes the configuration into the JSON format in a manager header, "JSON: ". The encoded information can be directly used as a javascript object, so no parsing is needed. For large configuration files, this can greatly improve loading times in the GUI. Furthermore, the encoding takes up a lot less space when being transmitted than the other alternatives. (Inspired by discussion with Pari) Here is an example of what you get: http://localhost:8088/asterisk/rawman?action=getconfigjson&filename=users.conf Response: Success JSON: {"general":["hasvoicemail=yes"],"6000":["fullname=russell","secret=1234"]} git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@56323 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--main/manager.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/main/manager.c b/main/manager.c
index c1b09c2cb..a88de0cda 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1059,6 +1059,52 @@ static int action_getconfig(struct mansession *s, const struct message *m)
return 0;
}
+static char mandescr_getconfigjson[] =
+"Description: A 'GetConfigJSON' action will dump the contents of a configuration\n"
+"file by category and contents in JSON format. This only makes sense to be used\n"
+"using rawman over the HTTP interface.\n"
+"Variables:\n"
+" Filename: Configuration filename (e.g. foo.conf)\n";
+
+static int action_getconfigjson(struct mansession *s, const struct message *m)
+{
+ struct ast_config *cfg;
+ const char *fn = astman_get_header(m, "Filename");
+ char *category = NULL;
+ struct ast_variable *v;
+ int comma1 = 0;
+
+ if (ast_strlen_zero(fn)) {
+ astman_send_error(s, m, "Filename not specified");
+ return 0;
+ }
+
+ if (!(cfg = ast_config_load_with_comments(fn))) {
+ astman_send_error(s, m, "Config file not found");
+ return 0;
+ }
+
+ astman_start_ack(s, m);
+ astman_append(s, "JSON: {");
+ while ((category = ast_category_browse(cfg, category))) {
+ int comma2 = 0;
+ astman_append(s, "%s\"%s\":[", comma1 ? "," : "", category);
+ if (!comma1)
+ comma1 = 1;
+ for (v = ast_variable_browse(cfg, category); v; v = v->next) {
+ astman_append(s, "%s\"%s=%s\"", comma2 ? "," : "", v->name, v->value);
+ if (!comma2)
+ comma2 = 1;
+ }
+ astman_append(s, "]");
+ }
+ astman_append(s, "}\r\n\r\n");
+
+ ast_config_destroy(cfg);
+
+ return 0;
+}
+
/* helper function for action_updateconfig */
static void handle_updates(struct mansession *s, const struct message *m, struct ast_config *cfg)
{
@@ -2963,6 +3009,7 @@ int init_manager(void)
ast_manager_register2("Setvar", EVENT_FLAG_CALL, action_setvar, "Set Channel Variable", mandescr_setvar );
ast_manager_register2("Getvar", EVENT_FLAG_CALL, action_getvar, "Gets a Channel Variable", mandescr_getvar );
ast_manager_register2("GetConfig", EVENT_FLAG_CONFIG, action_getconfig, "Retrieve configuration", mandescr_getconfig);
+ ast_manager_register2("GetConfigJSON", EVENT_FLAG_CONFIG, action_getconfigjson, "Retrieve configuration (JSON format)", mandescr_getconfigjson);
ast_manager_register2("UpdateConfig", EVENT_FLAG_CONFIG, action_updateconfig, "Update basic configuration", mandescr_updateconfig);
ast_manager_register2("Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect (transfer) a call", mandescr_redirect );
ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate);