summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/baresip.h1
-rw-r--r--modules/presence/notifier.c37
-rw-r--r--src/ua.c30
3 files changed, 41 insertions, 27 deletions
diff --git a/include/baresip.h b/include/baresip.h
index 2f91d6d..74cef89 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -546,6 +546,7 @@ void ua_stop_all(bool forced);
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);
+void uag_set_sub_handler(sip_msg_h *subh);
int ua_print_sip_status(struct re_printf *pf, void *unused);
struct ua *uag_find(const struct pl *cuser);
struct ua *uag_find_aor(const char *aor);
diff --git a/modules/presence/notifier.c b/modules/presence/notifier.c
index 213f937..8927e98 100644
--- a/modules/presence/notifier.c
+++ b/modules/presence/notifier.c
@@ -17,13 +17,11 @@
struct notifier {
struct le le;
- struct sipevent_sock *sock;
struct sipnot *not;
struct ua *ua;
};
static struct list notifierl;
-static struct sipevent_sock *evsock;
static const char *presence_status_str(enum presence_status st)
@@ -101,7 +99,6 @@ static void destructor(void *arg)
list_unlink(&not->le);
mem_deref(not->not);
- mem_deref(not->sock);
mem_deref(not->ua);
}
@@ -113,24 +110,24 @@ static int auth_handler(char **username, char **password,
}
-static int notifier_alloc(struct notifier **notp, struct sipevent_sock *sock,
+static int notifier_alloc(struct notifier **notp,
const struct sip_msg *msg,
const struct sipevent_event *se, struct ua *ua)
{
struct notifier *not;
int err;
- if (!sock || !msg || !se)
+ if (!msg || !se)
return EINVAL;
not = mem_zalloc(sizeof(*not), destructor);
if (!not)
return ENOMEM;
- not->sock = mem_ref(sock);
not->ua = mem_ref(ua);
- err = sipevent_accept(&not->not, sock, msg, NULL, se, 200, "OK",
+ err = sipevent_accept(&not->not, uag_sipevent_sock(),
+ msg, NULL, se, 200, "OK",
600, 600, 600,
ua_cuser(not->ua), "application/pidf+xml",
auth_handler, ua_prm(not->ua), true,
@@ -152,8 +149,7 @@ static int notifier_alloc(struct notifier **notp, struct sipevent_sock *sock,
}
-static int notifier_add(struct sipevent_sock *sock, const struct sip_msg *msg,
- struct ua *ua)
+static int notifier_add(const struct sip_msg *msg, struct ua *ua)
{
const struct sip_hdr *hdr;
struct sipevent_event se;
@@ -173,7 +169,7 @@ static int notifier_add(struct sipevent_sock *sock, const struct sip_msg *msg,
return EPROTO;
}
- err = notifier_alloc(&not, sock, msg, &se, ua);
+ err = notifier_alloc(&not, msg, &se, ua);
if (err)
return err;
@@ -199,18 +195,9 @@ void notifier_update_status(struct ua *ua)
static bool sub_handler(const struct sip_msg *msg, void *arg)
{
- struct ua *ua;
-
- (void)arg;
-
- ua = uag_find(&msg->uri.user);
- if (!ua) {
- warning("presence: no UA found for %r\n", &msg->uri.user);
- (void)sip_treply(NULL, uag_sip(), msg, 404, "Not Found");
- return true;
- }
+ struct ua *ua = arg;
- if (notifier_add(evsock, msg, ua))
+ if (notifier_add(msg, ua))
(void)sip_treply(NULL, uag_sip(), msg, 400, "Bad Presence");
return true;
@@ -219,16 +206,14 @@ static bool sub_handler(const struct sip_msg *msg, void *arg)
int notifier_init(void)
{
- int err;
-
- err = sipevent_listen(&evsock, uag_sip(), 32, 32, sub_handler, NULL);
+ uag_set_sub_handler(sub_handler);
- return err;
+ return 0;
}
void notifier_close(void)
{
list_flush(&notifierl);
- evsock = mem_deref(evsock);
+ uag_set_sub_handler(NULL);
}
diff --git a/src/ua.c b/src/ua.c
index 424a2a1..3ffdcd2 100644
--- a/src/ua.c
+++ b/src/ua.c
@@ -57,6 +57,7 @@ static struct {
bool use_tcp; /**< Use TCP transport */
bool use_tls; /**< Use TLS transport */
bool prefer_ipv6; /**< Force IPv6 transport */
+ sip_msg_h *subh;
#ifdef USE_TLS
struct tls *tls; /**< TLS Context */
#endif
@@ -1286,6 +1287,26 @@ static const struct cmd cmdv[] = {
};
+static bool sub_handler(const struct sip_msg *msg, void *arg)
+{
+ struct ua *ua;
+
+ (void)arg;
+
+ ua = uag_find(&msg->uri.user);
+ if (!ua) {
+ warning("subscribe: no UA found for %r\n", &msg->uri.user);
+ (void)sip_treply(NULL, uag_sip(), msg, 404, "Not Found");
+ return true;
+ }
+
+ if (uag.subh)
+ uag.subh(msg, ua);
+
+ return true;
+}
+
+
/**
* Initialise the User-Agents
*
@@ -1347,7 +1368,8 @@ int ua_init(const char *software, bool udp, bool tcp, bool tls,
if (err)
goto out;
- err = sipevent_listen(&uag.evsock, uag.sip, bsize, bsize, NULL, NULL);
+ err = sipevent_listen(&uag.evsock, uag.sip, bsize, bsize,
+ sub_handler, NULL);
if (err)
goto out;
@@ -1841,6 +1863,12 @@ void uag_event_unregister(ua_event_h *h)
}
+void uag_set_sub_handler(sip_msg_h *subh)
+{
+ uag.subh = subh;
+}
+
+
void uag_current_set(struct ua *ua)
{
uag.ua_cur = ua;