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 /modules/presence | |
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 'modules/presence')
-rw-r--r-- | modules/presence/notifier.c | 37 |
1 files changed, 11 insertions, 26 deletions
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(¬->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, sock, msg, NULL, se, 200, "OK", + err = sipevent_accept(¬->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(¬, sock, msg, &se, ua); + err = notifier_alloc(¬, 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(¬ifierl); - evsock = mem_deref(evsock); + uag_set_sub_handler(NULL); } |