summaryrefslogtreecommitdiff
path: root/main/manager.c
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2013-07-02 17:20:20 +0000
committerKevin Harwell <kharwell@digium.com>2013-07-02 17:20:20 +0000
commit05a16729cbdbc5f7e484d75900f01285a2e4dd76 (patch)
treeb898398d8124bf74a440ccf4fce599c4c8e88fba /main/manager.c
parenta25a630659c49e5e5cddacdaa06a0bd323f7c9a1 (diff)
Stasis - Refactor AOC Events
Refactored the AMI events in AOC onto Stasis-Core. The ast_aoc_manager_event function now publishes a channel snapshot, along with a JSON blob describing the advice of charge. A "to_ami" handler has also been added that converts the channel snapshot and AOC event data back into the appropriate data structure for use with AMI. (closes issue ASTERISK-21472) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/2643/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/manager.c')
-rw-r--r--main/manager.c117
1 files changed, 84 insertions, 33 deletions
diff --git a/main/manager.c b/main/manager.c
index ec031303b..2af7fc529 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1274,47 +1274,98 @@ struct stasis_message_router *ast_manager_get_message_router(void)
return stasis_router;
}
-struct ast_str *ast_manager_str_from_json_object(struct ast_json *blob, key_exclusion_cb exclusion_cb)
+static void manager_json_value_str_append(struct ast_json *value, const char *key,
+ struct ast_str **res)
{
- struct ast_str *output_str = ast_str_create(32);
- struct ast_json *value;
- struct ast_json_iter *iter;
- const char *key;
- if (!output_str) {
- return NULL;
+ switch (ast_json_typeof(value)) {
+ case AST_JSON_STRING:
+ ast_str_append(res, 0, "%s: %s\r\n", key, ast_json_string_get(value));
+ break;
+ case AST_JSON_INTEGER:
+ ast_str_append(res, 0, "%s: %jd\r\n", key, ast_json_integer_get(value));
+ break;
+ case AST_JSON_TRUE:
+ ast_str_append(res, 0, "%s: True\r\n", key);
+ break;
+ case AST_JSON_FALSE:
+ ast_str_append(res, 0, "%s: False\r\n", key);
+ break;
+ default:
+ ast_str_append(res, 0, "%s: \r\n", key);
+ break;
}
+}
- for (iter = ast_json_object_iter(blob); iter; iter = ast_json_object_iter_next(blob, iter)) {
- key = ast_json_object_iter_key(iter);
- value = ast_json_object_iter_value(iter);
+static void manager_json_to_ast_str(struct ast_json *obj, const char *key,
+ struct ast_str **res, key_exclusion_cb exclusion_cb);
- if (exclusion_cb && exclusion_cb(key)) {
- continue;
- }
- switch (ast_json_typeof(value)) {
- case AST_JSON_STRING:
- ast_str_append(&output_str, 0, "%s: %s\r\n", key, ast_json_string_get(value));
- break;
- case AST_JSON_INTEGER:
- ast_str_append(&output_str, 0, "%s: %jd\r\n", key, ast_json_integer_get(value));
- break;
- case AST_JSON_TRUE:
- ast_str_append(&output_str, 0, "%s: True\r\n", key);
- break;
- case AST_JSON_FALSE:
- ast_str_append(&output_str, 0, "%s: False\r\n", key);
- break;
- default:
- ast_str_append(&output_str, 0, "%s: \r\n", key);
- break;
- }
+static void manager_json_array_with_key(struct ast_json *obj, const char* key,
+ size_t index, struct ast_str **res,
+ key_exclusion_cb exclusion_cb)
+{
+ struct ast_str *key_str = ast_str_alloca(64);
+ ast_str_set(&key_str, 0, "%s(%zu)", key, index);
+ manager_json_to_ast_str(obj, ast_str_buffer(key_str),
+ res, exclusion_cb);
+}
- if (!output_str) {
- return NULL;
+static void manager_json_obj_with_key(struct ast_json *obj, const char* key,
+ const char *parent_key, struct ast_str **res,
+ key_exclusion_cb exclusion_cb)
+{
+ if (parent_key) {
+ struct ast_str *key_str = ast_str_alloca(64);
+ ast_str_set(&key_str, 0, "%s/%s", parent_key, key);
+ manager_json_to_ast_str(obj, ast_str_buffer(key_str),
+ res, exclusion_cb);
+ return;
+ }
+
+ manager_json_to_ast_str(obj, key, res, exclusion_cb);
+}
+
+void manager_json_to_ast_str(struct ast_json *obj, const char *key,
+ struct ast_str **res, key_exclusion_cb exclusion_cb)
+{
+ struct ast_json_iter *i;
+
+ if (!obj || (!res && !(*res) && (!(*res = ast_str_create(1024))))) {
+ return;
+ }
+
+ if (exclusion_cb && key && exclusion_cb(key)) {
+ return;
+ }
+
+ if (ast_json_typeof(obj) != AST_JSON_OBJECT &&
+ ast_json_typeof(obj) != AST_JSON_ARRAY) {
+ manager_json_value_str_append(obj, key, res);
+ return;
+ }
+
+ if (ast_json_typeof(obj) == AST_JSON_ARRAY) {
+ size_t j;
+ for (j = 0; j < ast_json_array_size(obj); ++j) {
+ manager_json_array_with_key(ast_json_array_get(obj, j),
+ key, j, res, exclusion_cb);
}
+ return;
}
- return output_str;
+ for (i = ast_json_object_iter(obj); i;
+ i = ast_json_object_iter_next(obj, i)) {
+ manager_json_obj_with_key(ast_json_object_iter_value(i),
+ ast_json_object_iter_key(i),
+ key, res, exclusion_cb);
+ }
+}
+
+
+struct ast_str *ast_manager_str_from_json_object(struct ast_json *blob, key_exclusion_cb exclusion_cb)
+{
+ struct ast_str *res = ast_str_create(1024);
+ manager_json_to_ast_str(blob, NULL, &res, exclusion_cb);
+ return res;
}
static void manager_default_msg_cb(void *data, struct stasis_subscription *sub,