summaryrefslogtreecommitdiff
path: root/res/stasis/app.c
diff options
context:
space:
mode:
authorGeorge Joseph <gjoseph@digium.com>2017-01-19 08:05:36 -0700
committerGeorge Joseph <gjoseph@digium.com>2017-01-23 10:25:58 -0700
commit66916067236dc2f5cf54fadee33a5203d8716148 (patch)
tree963dec954768e5eb279af597ea3fc62d9b43af59 /res/stasis/app.c
parente2da0021b99ace55a36ad5d1a497159a2d077025 (diff)
ari: Implement 'debug all' and request/response logging
The 'ari set debug' command has been enhanced to accept 'all' as an application name. This allows dumping of all apps even if an app hasn't registered yet. To accomplish this, a new global_debug global variable was added to res/stasis/app.c and new APIs were added to set and query the value. 'ari set debug' now displays requests and responses as well as events. This required refactoring the existing debug code. * The implementation for 'ari set debug' was moved from stasis/cli.{c,h} to ari/cli.{c,h}, and stasis/cli.{c,h} were deleted. * In order to print the body of incoming requests even if a request failed, the consumption of the body was moved from the ari stubs to ast_ari_callback in res_ari.c and the moustache templates were then regenerated. The body is now passed to ast_ari_invoke and then on to the handlers. This results in code savings since that template was inserted multiple times into all the stubs. An additional change was made to the ao2_str_container implementation to add partial key searching and a sort function. The existing cli code assumed it was already there when it wasn't so the tab completion was never working. Change-Id: Ief936f747ce47f1fb14035fbe61152cf766406bf (cherry picked from commit 1d890874f39a5a81b20da44358143ed9b54ab0fe)
Diffstat (limited to 'res/stasis/app.c')
-rw-r--r--res/stasis/app.c73
1 files changed, 58 insertions, 15 deletions
diff --git a/res/stasis/app.c b/res/stasis/app.c
index 0b75ed5d7..b0bcf3c42 100644
--- a/res/stasis/app.c
+++ b/res/stasis/app.c
@@ -41,6 +41,9 @@
#define CHANNEL_ALL "__AST_CHANNEL_ALL_TOPIC"
#define ENDPOINT_ALL "__AST_ENDPOINT_ALL_TOPIC"
+/*! Global debug flag. No need for locking */
+int global_debug;
+
static int unsubscribe(struct stasis_app *app, const char *kind, const char *id, int terminate);
struct stasis_app {
@@ -840,15 +843,64 @@ static void bridge_default_handler(void *data, struct stasis_subscription *sub,
}
}
-void app_set_debug(struct stasis_app *app, int debug)
+void stasis_app_set_debug(struct stasis_app *app, int debug)
{
if (!app) {
return;
}
- {
- SCOPED_AO2LOCK(lock, app);
- app->debug = debug;
+ app->debug = debug;
+}
+
+void stasis_app_set_debug_by_name(const char *app_name, int debug)
+{
+ struct stasis_app *app = stasis_app_get_by_name(app_name);
+
+ if (!app) {
+ return;
+ }
+
+ app->debug = debug;
+ ao2_cleanup(app);
+}
+
+int stasis_app_get_debug(struct stasis_app *app)
+{
+ return (app ? app->debug : 0) || global_debug;
+}
+
+int stasis_app_get_debug_by_name(const char *app_name)
+{
+ RAII_VAR(struct stasis_app *, app, stasis_app_get_by_name(app_name), ao2_cleanup);
+
+ return (app ? app->debug : 0) || global_debug;
+}
+
+void stasis_app_set_global_debug(int debug)
+{
+ global_debug = debug;
+ if (!global_debug) {
+ struct ao2_container *app_names = stasis_app_get_all();
+ struct ao2_iterator it_app_names;
+ char *app_name;
+ struct stasis_app *app;
+
+ if (!app_names || !ao2_container_count(app_names)) {
+ ao2_cleanup(app_names);
+ return;
+ }
+
+ it_app_names = ao2_iterator_init(app_names, 0);
+ while ((app_name = ao2_iterator_next(&it_app_names))) {
+ if ((app = stasis_app_get_by_name(app_name))) {
+ stasis_app_set_debug(app, 0);
+ }
+
+ ao2_cleanup(app_name);
+ ao2_cleanup(app);
+ }
+ ao2_iterator_cleanup(&it_app_names);
+ ao2_cleanup(app_names);
}
}
@@ -949,7 +1001,6 @@ struct stasis_topic *ast_app_get_topic(struct stasis_app *app)
void app_send(struct stasis_app *app, struct ast_json *message)
{
stasis_app_cb handler;
- int debug;
char eid[20];
RAII_VAR(void *, data, NULL, ao2_cleanup);
@@ -962,7 +1013,6 @@ void app_send(struct stasis_app *app, struct ast_json *message)
/* Copy off mutable state with lock held */
{
SCOPED_AO2LOCK(lock, app);
- debug = app->debug;
handler = app->handler;
if (app->data) {
ao2_ref(app->data, +1);
@@ -971,13 +1021,6 @@ void app_send(struct stasis_app *app, struct ast_json *message)
/* Name is immutable; no need to copy */
}
- if (debug) {
- char *dump = ast_json_dump_string_format(message, AST_JSON_PRETTY);
- ast_verb(0, "Dispatching message to Stasis app '%s':\n%s\n",
- app->name, dump);
- ast_json_free(dump);
- }
-
if (!handler) {
ast_verb(3,
"Inactive Stasis app '%s' missed message\n", app->name);
@@ -1050,7 +1093,7 @@ void app_update(struct stasis_app *app, stasis_app_cb handler, void *data)
app->data = data;
}
-const char *app_name(const struct stasis_app *app)
+const char *stasis_app_name(const struct stasis_app *app)
{
return app->name;
}
@@ -1067,7 +1110,7 @@ static int forwards_filter_by_type(void *obj, void *arg, int flags)
return 0;
}
-void app_to_cli(const struct stasis_app *app, struct ast_cli_args *a)
+void stasis_app_to_cli(const struct stasis_app *app, struct ast_cli_args *a)
{
struct ao2_iterator *channels;
struct ao2_iterator *endpoints;