aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-04-15 21:51:41 +0200
committerHarald Welte <laforge@gnumonks.org>2018-04-15 22:12:42 +0200
commit6369f30c4de1726de319edab18f1a6d871d1f4c4 (patch)
tree6a9c44cc1bfbc4694cceea15885050dd6db7982c
parent65fa803f0c6fceb64c1bc157852ad5dcd0ce934e (diff)
sip: Register log callback function with sofia-sip
sofia-sip allows applications to register a log backend function which will be called every time the library wants to log something. We register such a call-back and make it log using the libosmocore logging framework. The problem is that sofia-sip has its own log level management, and by the time the message hits libosmocore, we don't know which log level we shall use :( Change-Id: Ib269b6b50f9d79bbd13acc43a626834921f05edb Related: OS#3105
-rw-r--r--src/app.h1
-rw-r--r--src/main.c2
-rw-r--r--src/sip.c13
-rw-r--r--src/vty.c18
4 files changed, 33 insertions, 1 deletions
diff --git a/src/app.h b/src/app.h
index ff48c79..96c8902 100644
--- a/src/app.h
+++ b/src/app.h
@@ -9,6 +9,7 @@ struct app_config {
struct {
const char *local_addr;
int local_port;
+ int sofia_log_level;
const char *remote_addr;
int remote_port;
diff --git a/src/main.c b/src/main.c
index 558eaec..b4ffb63 100644
--- a/src/main.c
+++ b/src/main.c
@@ -126,7 +126,7 @@ int main(int argc, char **argv)
/* parsing and setup */
-
+ g_app.sip.sofia_log_level = 2;
handle_options(argc, argv);
rc = vty_read_config_file(config_file, NULL);
if (rc < 0) {
diff --git a/src/sip.c b/src/sip.c
index 4f3d034..84d1f6e 100644
--- a/src/sip.c
+++ b/src/sip.c
@@ -27,6 +27,7 @@
#include <osmocom/core/utils.h>
#include <sofia-sip/sip_status.h>
+#include <sofia-sip/su_log.h>
#include <talloc.h>
@@ -383,12 +384,24 @@ char *make_sip_uri(struct sip_agent *agent)
agent->app->sip.local_port);
}
+/* http://sofia-sip.sourceforge.net/refdocs/debug_logs.html */
+static void sip_logger(void *stream, char const *fmt, va_list ap)
+{
+ /* this is ugly, as unfortunately sofia-sip does not pass the log level to
+ * the log handler call-back function, so we have no clue what log level the
+ * currently logged message was sent for :( As a result, we can only use one
+ * hard-coded LOGL_NOTICE here */
+ osmo_vlogp(DSIP, LOGL_NOTICE, "", 0, 0, fmt, ap);
+}
+
void sip_agent_init(struct sip_agent *agent, struct app_config *app)
{
agent->app = app;
su_init();
su_home_init(&agent->home);
+ su_log_redirect(su_log_default, &sip_logger, NULL);
+ su_log_redirect(su_log_global, &sip_logger, NULL);
agent->root = su_glib_root_create(NULL);
su_root_threading(agent->root, 0);
}
diff --git a/src/vty.c b/src/vty.c
index bea1f9f..540e2de 100644
--- a/src/vty.c
+++ b/src/vty.c
@@ -1,5 +1,6 @@
/*
* (C) 2016 by Holger Hans Peter Freyther
+ * (C) 2018 by Harald Welte <laforge@gnumonks.org>
*
* All Rights Reserved
*
@@ -25,6 +26,8 @@
#include <talloc.h>
+#include <sofia-sip/su_log.h>
+
extern void *tall_mncc_ctx;
struct app_config g_app;
@@ -88,6 +91,7 @@ static int config_write_sip(struct vty *vty)
vty_out(vty, "sip%s", VTY_NEWLINE);
vty_out(vty, " local %s %d%s", g_app.sip.local_addr, g_app.sip.local_port, VTY_NEWLINE);
vty_out(vty, " remote %s %d%s", g_app.sip.remote_addr, g_app.sip.remote_port, VTY_NEWLINE);
+ vty_out(vty, " sofia-sip log-level %d%s", g_app.sip.sofia_log_level, VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -133,6 +137,19 @@ DEFUN(cfg_sip_remote_addr, cfg_sip_remote_addr_cmd,
return CMD_SUCCESS;
}
+DEFUN(cfg_sip_sofia_log_level, cfg_sip_sofia_log_level_cmd,
+ "sofia-sip log-level <0-9>",
+ "sofia-sip library configuration\n"
+ "global log-level for sofia-sip\n"
+ "(0 = nothing, 9 = super-verbose)\n")
+{
+ g_app.sip.sofia_log_level = atoi(argv[0]);
+ su_log_set_level(su_log_default, g_app.sip.sofia_log_level);
+ su_log_set_level(su_log_global, g_app.sip.sofia_log_level);
+
+ return CMD_SUCCESS;
+}
+
DEFUN(cfg_mncc, cfg_mncc_cmd,
"mncc",
"MNCC\n")
@@ -302,6 +319,7 @@ void mncc_sip_vty_init(void)
install_node(&sip_node, config_write_sip);
install_element(SIP_NODE, &cfg_sip_local_addr_cmd);
install_element(SIP_NODE, &cfg_sip_remote_addr_cmd);
+ install_element(SIP_NODE, &cfg_sip_sofia_log_level_cmd);
install_element(CONFIG_NODE, &cfg_mncc_cmd);
install_node(&mncc_node, config_write_mncc);