diff options
author | Alfred E. Heggestad <aeh@db.org> | 2015-10-31 19:53:31 +0100 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2015-10-31 19:53:31 +0100 |
commit | 7c2feeeafb9ffb672697872adda0bdb155df53bc (patch) | |
tree | 4aca3982dd8ce04741bdd63d38885eb15c5be69f /src/ua.c | |
parent | 136f8543e65e29fea1538fa7cd9a4dbdd533a6eb (diff) |
presence: use struct sipevent_sock instance from core
- remove own instance of "struct sipevent_sock" in notifier
- add a new handler uag_set_sub_handler for incoming SUBSCRIBE messages
after this patch there should be only 1 global instance
of sipevent_sock, in ua.c -- this patch will also fix a bug
where sipevent could not find the subscription/notification
and replies with 481
Diffstat (limited to 'src/ua.c')
-rw-r--r-- | src/ua.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -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; |