summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2016-01-13 09:48:57 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-01-13 09:48:58 -0600
commitef57080b27cee39991a2bf501d6fadfe8bc61146 (patch)
treed8d1b0daa573d9b70285dba226e2ec8682c8abe3 /res
parent79a7321a4762fc461e735f9c11b3b9799d1adb2e (diff)
parent1fffe71f77ddcae415f47131fc629a914c1fdde0 (diff)
Merge "res_pjsip_log_forwarder.c: Add CLI "pjsip show buildopts"."
Diffstat (limited to 'res')
-rw-r--r--res/res_pjsip_log_forwarder.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/res/res_pjsip_log_forwarder.c b/res/res_pjsip_log_forwarder.c
index 85ca9358c..c6b396afc 100644
--- a/res/res_pjsip_log_forwarder.c
+++ b/res/res_pjsip_log_forwarder.c
@@ -46,10 +46,24 @@ ASTERISK_REGISTER_FILE()
#include "asterisk/logger.h"
#include "asterisk/module.h"
+#include "asterisk/cli.h"
static pj_log_func *log_cb_orig;
static unsigned decor_orig;
+/*! Protection from other CLI instances. */
+AST_MUTEX_DEFINE_STATIC(show_buildopts_lock);
+
+struct pjsip_show_buildopts {
+ pthread_t thread;
+ int fd;
+};
+
+static struct pjsip_show_buildopts show_buildopts = {
+ .thread = AST_PTHREADT_NULL,
+ .fd = -1,
+};
+
static void log_cb(int level, const char *data, int len)
{
int ast_level;
@@ -59,6 +73,15 @@ static void log_cb(int level, const char *data, int len)
const char *log_func = "<?>";
int mod_level;
+ if (show_buildopts.fd != -1 && show_buildopts.thread == pthread_self()) {
+ /*
+ * We are handling the CLI command dumping the
+ * PJPROJECT compile time config option settings.
+ */
+ ast_cli(show_buildopts.fd, "%s\n", data);
+ return;
+ }
+
/* Lower number indicates higher importance */
switch (level) {
case 0: /* level zero indicates fatal error, according to docs */
@@ -86,6 +109,40 @@ static void log_cb(int level, const char *data, int len)
ast_log(ast_level, log_source, log_line, log_func, "\t%s\n", data);
}
+static char *handle_pjsip_show_buildopts(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ switch(cmd) {
+ case CLI_INIT:
+ e->command = "pjsip show buildopts";
+ e->usage =
+ "Usage: pjsip show buildopts\n"
+ " Show the compile time config of pjproject that res_pjsip is\n"
+ " running against.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ ast_cli(a->fd, "PJPROJECT compile time config currently running against:\n");
+
+ /* Protect from other CLI instances trying to do this at the same time. */
+ ast_mutex_lock(&show_buildopts_lock);
+
+ show_buildopts.thread = pthread_self();
+ show_buildopts.fd = a->fd;
+ pj_dump_config();
+ show_buildopts.fd = -1;
+ show_buildopts.thread = AST_PTHREADT_NULL;
+
+ ast_mutex_unlock(&show_buildopts_lock);
+
+ return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry pjsip_cli[] = {
+ AST_CLI_DEFINE(handle_pjsip_show_buildopts, "Show the compiled config of pjproject in use"),
+};
+
static int load_module(void)
{
pj_init();
@@ -102,11 +159,15 @@ static int load_module(void)
pj_log_set_decor(PJ_LOG_HAS_SENDER | PJ_LOG_HAS_INDENT);
pj_log_set_log_func(log_cb);
+ ast_cli_register_multiple(pjsip_cli, ARRAY_LEN(pjsip_cli));
+
return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
+ ast_cli_unregister_multiple(pjsip_cli, ARRAY_LEN(pjsip_cli));
+
pj_log_set_log_func(log_cb_orig);
pj_log_set_decor(decor_orig);