summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/baresip.h3
-rw-r--r--src/main.c11
-rw-r--r--src/ua.c21
-rw-r--r--test/main.c14
-rw-r--r--test/sip/sipsrv.c2
5 files changed, 43 insertions, 8 deletions
diff --git a/include/baresip.h b/include/baresip.h
index 201ecb5..68cf423 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -518,6 +518,8 @@ typedef void (ua_event_h)(struct ua *ua, enum ua_event ev,
struct call *call, const char *prm, void *arg);
typedef void (options_resp_h)(int err, const struct sip_msg *msg, void *arg);
+typedef void (ua_exit_h)(void *arg);
+
/* Multiple instances */
int ua_alloc(struct ua **uap, const char *aor);
int ua_connect(struct ua *ua, struct call **callp,
@@ -557,6 +559,7 @@ int ua_init(const char *software, bool udp, bool tcp, bool tls,
bool prefer_ipv6);
void ua_close(void);
void ua_stop_all(bool forced);
+void uag_set_exit_handler(ua_exit_h *exith, void *arg);
int uag_reset_transp(bool reg, bool reinvite);
int uag_event_register(ua_event_h *eh, void *arg);
void uag_event_unregister(ua_event_h *eh);
diff --git a/src/main.c b/src/main.c
index 9193053..ca9c9c0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -34,6 +34,15 @@ static void signal_handler(int sig)
}
+static void ua_exit_handler(void *arg)
+{
+ debug("ua exited -- stopping main runloop\n");
+
+ /* The main run-loop can be stopped now */
+ re_cancel();
+}
+
+
static void usage(void)
{
(void)re_fprintf(stderr,
@@ -170,6 +179,8 @@ int main(int argc, char *argv[])
if (err)
goto out;
+ uag_set_exit_handler(ua_exit_handler, NULL);
+
if (ua_eprm) {
err = uag_set_extra_params(ua_eprm);
if (err)
diff --git a/src/ua.c b/src/ua.c
index 575c752..6c7c758 100644
--- a/src/ua.c
+++ b/src/ua.c
@@ -57,6 +57,8 @@ static struct {
bool use_tls; /**< Use TLS transport */
bool prefer_ipv6; /**< Force IPv6 transport */
sip_msg_h *subh;
+ ua_exit_h *exith; /**< UA Exit handler */
+ void *arg; /**< UA Exit handler argument */
char *eprm; /**< Extra UA parameters */
#ifdef USE_TLS
struct tls *tls; /**< TLS Context */
@@ -76,6 +78,8 @@ static struct {
false,
NULL,
NULL,
+ NULL,
+ NULL,
#ifdef USE_TLS
NULL,
#endif
@@ -98,7 +102,8 @@ static void exit_handler(void *arg)
debug("ua: sip-stack exit\n");
module_app_unload();
- re_cancel();
+ if (uag.exith)
+ uag.exith(uag.arg);
}
@@ -1454,6 +1459,20 @@ void ua_stop_all(bool forced)
/**
+ * Set the global UA exit handler. The exit handler will be called
+ * asyncronously when the SIP stack has exited.
+ *
+ * @param exith Exit handler
+ * @param arg Handler argument
+ */
+void uag_set_exit_handler(ua_exit_h *exith, void *arg)
+{
+ uag.exith = exith;
+ uag.arg = arg;
+}
+
+
+/**
* Reset the SIP transports for all User-Agents
*
* @param reg True to reset registration
diff --git a/test/main.c b/test/main.c
index eb1530e..955643a 100644
--- a/test/main.c
+++ b/test/main.c
@@ -111,6 +111,13 @@ static const struct test *find_test(const char *name)
}
+static void ua_exit_handler(void *arg)
+{
+ debug("ua exited -- stopping main runloop\n");
+ re_cancel();
+}
+
+
static void usage(void)
{
(void)re_fprintf(stderr,
@@ -175,12 +182,7 @@ int main(int argc, char *argv[])
}
str_ncpy(config->sip.local, "127.0.0.1:0", sizeof(config->sip.local));
-#if 0
- /* XXX: needed for ua tests */
- err = ua_init("test", true, true, true, false);
- if (err)
- goto out;
-#endif
+ uag_set_exit_handler(ua_exit_handler, NULL);
if (argc >= (optind + 1)) {
diff --git a/test/sip/sipsrv.c b/test/sip/sipsrv.c
index 76b4b6f..ce1d562 100644
--- a/test/sip/sipsrv.c
+++ b/test/sip/sipsrv.c
@@ -216,7 +216,7 @@ static bool sip_msg_handler(const struct sip_msg *msg, void *arg)
out:
if (srv->terminate)
- re_cancel();
+ re_cancel(); /* XXX: avoid this */
return true;
}