summaryrefslogtreecommitdiff
path: root/res/res_pjsip_logger.c
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2014-01-31 23:15:47 +0000
committerKevin Harwell <kharwell@digium.com>2014-01-31 23:15:47 +0000
commit10e38fb10cb07b0eb60375cc2a8cd46da86b7c5b (patch)
tree38e54ecc0d4dd32e5d2fcdd6b28be23a4b6ddf5d /res/res_pjsip_logger.c
parentf5bb5b3e8c48d130b06f43eba380f15568706775 (diff)
res_pjsip: Config option to enable PJSIP logger at load time.
Added a "debug" configuration option for res_pjsip that when set to "yes" enables SIP messages to be logged. It is specified under the "system" type. Also added an alembic script to add the option to realtime. (closes issue ASTERISK-23038) Reported by: Rusty Newton Review: https://reviewboard.asterisk.org/r/3148/ ........ Merged revisions 407036 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407037 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_pjsip_logger.c')
-rw-r--r--res/res_pjsip_logger.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/res/res_pjsip_logger.c b/res/res_pjsip_logger.c
index 19b276c2e..c1785b5db 100644
--- a/res/res_pjsip_logger.c
+++ b/res/res_pjsip_logger.c
@@ -195,10 +195,50 @@ static struct ast_cli_entry cli_pjsip[] = {
AST_CLI_DEFINE(pjsip_set_logger, "Enable/Disable PJSIP Logger Output")
};
+static void check_debug(void)
+{
+ RAII_VAR(char *, debug, ast_sip_get_debug(), ast_free);
+
+ if (ast_false(debug)) {
+ logging_mode = LOGGING_MODE_DISABLED;
+ return;
+ }
+
+ logging_mode = LOGGING_MODE_ENABLED;
+
+ if (ast_true(debug)) {
+ ast_sockaddr_setnull(&log_addr);
+ return;
+ }
+
+ /* assume host */
+ if (ast_sockaddr_resolve_first_af(&log_addr, debug, 0, AST_AF_UNSPEC)) {
+ ast_log(LOG_WARNING, "Could not resolve host %s for debug "
+ "logging\n", debug);
+ }
+}
+
+static void global_reloaded(const char *object_type)
+{
+ check_debug();
+}
+
+static const struct ast_sorcery_observer global_observer = {
+ .loaded = global_reloaded
+};
+
static int load_module(void)
{
+ if (ast_sorcery_observer_add(ast_sip_get_sorcery(), "global", &global_observer)) {
+ ast_log(LOG_WARNING, "Unable to add global observer\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ check_debug();
+
ast_sip_register_service(&logging_module);
ast_cli_register_multiple(cli_pjsip, ARRAY_LEN(cli_pjsip));
+
return AST_MODULE_LOAD_SUCCESS;
}
@@ -206,6 +246,10 @@ static int unload_module(void)
{
ast_cli_unregister_multiple(cli_pjsip, ARRAY_LEN(cli_pjsip));
ast_sip_unregister_service(&logging_module);
+
+ ast_sorcery_observer_remove(
+ ast_sip_get_sorcery(), "global", &global_observer);
+
return 0;
}