diff options
-rw-r--r-- | include/baresip.h | 2 | ||||
-rw-r--r-- | modules/mwi/mwi.c | 27 | ||||
-rw-r--r-- | src/account.c | 6 | ||||
-rw-r--r-- | src/ua.c | 13 |
4 files changed, 46 insertions, 2 deletions
diff --git a/include/baresip.h b/include/baresip.h index b0f81f2..5325bc2 100644 --- a/include/baresip.h +++ b/include/baresip.h @@ -41,6 +41,7 @@ int account_auth(const struct account *acc, char **username, char **password, struct list *account_aucodecl(const struct account *acc); struct list *account_vidcodecl(const struct account *acc); struct sip_addr *account_laddr(const struct account *acc); +uint32_t account_regint(const struct account *acc); /* @@ -501,6 +502,7 @@ void ua_unregister(struct ua *ua); bool ua_isregistered(const struct ua *ua); const char *ua_aor(const struct ua *ua); const char *ua_cuser(const struct ua *ua); +struct account *ua_account(const struct ua *ua); const char *ua_outbound(const struct ua *ua); struct call *ua_call(const struct ua *ua); struct account *ua_prm(const struct ua *ua); diff --git a/modules/mwi/mwi.c b/modules/mwi/mwi.c index 21aca08..cfc6d9f 100644 --- a/modules/mwi/mwi.c +++ b/modules/mwi/mwi.c @@ -102,6 +102,25 @@ static int mwi_subscribe(struct ua *ua) } +static void ua_event_handler(struct ua *ua, + enum ua_event ev, + struct call *call, + const char *prm, + void *arg ) +{ + (void)call; + (void)prm; + + if (ua != (struct ua *)arg) + return; + + if (ev == UA_EVENT_REGISTER_OK) { + uag_event_unregister(ua_event_handler); + mwi_subscribe(ua); + } +} + + static void tmr_handler(void *arg) { struct le *le; @@ -110,7 +129,11 @@ static void tmr_handler(void *arg) for (le = list_head(uag_list()); le; le = le->next) { struct ua *ua = le->data; - mwi_subscribe(ua); + struct account *acc = ua_account(ua); + if (account_regint(acc) > 0) + uag_event_register(ua_event_handler, ua); + else + mwi_subscribe(ua); } } @@ -118,7 +141,7 @@ static void tmr_handler(void *arg) static int module_init(void) { list_init(&mwil); - tmr_start(&tmr, 10, tmr_handler, 0); + tmr_start(&tmr, 1, tmr_handler, 0); return 0; } diff --git a/src/account.c b/src/account.c index b8945b1..fed2b00 100644 --- a/src/account.c +++ b/src/account.c @@ -504,6 +504,12 @@ struct sip_addr *account_laddr(const struct account *acc) } +uint32_t account_regint(const struct account *acc) +{ + return acc ? acc->regint : 0; +} + + static const char *answermode_str(enum answermode mode) { switch (mode) { @@ -1475,6 +1475,19 @@ const char *ua_cuser(const struct ua *ua) } +/** + * Get Account of a User-Agent + * + * @param ua User-Agent + * + * @return Pointer to UA's account + */ +struct account *ua_account(const struct ua *ua) +{ + return ua->acc; +} + + struct list *uag_list(void) { return &uag.ual; |