2013-04-25 18:25:31 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Mark Michelson <mmichelson@digium.com>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2013-04-26 21:52:06 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<depend>pjproject</depend>
|
2013-07-30 18:14:50 +00:00
|
|
|
<depend>res_pjsip</depend>
|
2013-10-14 15:01:59 +00:00
|
|
|
<depend>res_pjsip_pubsub</depend>
|
2013-04-26 21:52:06 +00:00
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
#include <pjsip.h>
|
|
|
|
#include <pjsip_simple.h>
|
|
|
|
#include <pjlib.h>
|
|
|
|
|
2013-07-30 18:14:50 +00:00
|
|
|
#include "asterisk/res_pjsip.h"
|
|
|
|
#include "asterisk/res_pjsip_pubsub.h"
|
Decouple subscription handling from NOTIFY/PUBLISH body generation.
When the PJSIP pubsub framework was created, subscription handlers were required
to state what event they handled along with what body types they knew how to
generate. While this serves well when implementing a base RFC, it has problems
when trying to extend the body to support non-standard or proprietary body
elements. The code also was NOTIFY-specific, meaning that when the time comes
that we start writing code to send out PUBLISH requests with MWI or presence
bodies, we would likely find ourselves duplicating code that had previously been
written.
This changeset introduces the concept of body generators and body supplements. A
body generator is responsible for allocating a native structure for a given body
type, providing the primary body content, converting the native structure to a
string, and deallocating resources. A body supplement takes the primary body
content (the native structure, not a string) generated by the body generator and
adds nonstandard elements to the body. With these elements living in their own
module, it becomes easy to extend our support for body types and to re-use
resources when sending a PUBLISH request.
Body generators and body supplements register themselves with the pubsub core,
similar to how subscription and publish handlers had done. Now, subscription
handlers do not need to know what type of body content they generate, but they
still need to inform the pubsub core about what the default body type for a
given event package is. The pubsub core keeps track of what body generators and
body supplements have been registered. When a SUBSCRIBE arrives, the pubsub core
will check that there is a subscription handler for the event in the SUBSCRIBE,
then it will check that there is a body generator that can provide the content
specified in the Accept header(s).
Because of the nature of body generators and supplements, it means
res_pjsip_exten_state and res_pjsip_mwi have been completely gutted. They no
longer worry about body types, instead calling
ast_sip_pubsub_generate_body_content() when they need to generate a NOTIFY body.
Review: https://reviewboard.asterisk.org/r/3150
........
Merged revisions 407016 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407030 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-01-31 22:27:07 +00:00
|
|
|
#include "asterisk/res_pjsip_body_generator_types.h"
|
2013-04-25 18:25:31 +00:00
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/astobj2.h"
|
|
|
|
#include "asterisk/sorcery.h"
|
|
|
|
#include "asterisk/stasis.h"
|
|
|
|
#include "asterisk/app.h"
|
|
|
|
|
|
|
|
struct mwi_subscription;
|
|
|
|
AO2_GLOBAL_OBJ_STATIC(unsolicited_mwi);
|
|
|
|
|
|
|
|
#define STASIS_BUCKETS 13
|
|
|
|
#define MWI_BUCKETS 53
|
Decouple subscription handling from NOTIFY/PUBLISH body generation.
When the PJSIP pubsub framework was created, subscription handlers were required
to state what event they handled along with what body types they knew how to
generate. While this serves well when implementing a base RFC, it has problems
when trying to extend the body to support non-standard or proprietary body
elements. The code also was NOTIFY-specific, meaning that when the time comes
that we start writing code to send out PUBLISH requests with MWI or presence
bodies, we would likely find ourselves duplicating code that had previously been
written.
This changeset introduces the concept of body generators and body supplements. A
body generator is responsible for allocating a native structure for a given body
type, providing the primary body content, converting the native structure to a
string, and deallocating resources. A body supplement takes the primary body
content (the native structure, not a string) generated by the body generator and
adds nonstandard elements to the body. With these elements living in their own
module, it becomes easy to extend our support for body types and to re-use
resources when sending a PUBLISH request.
Body generators and body supplements register themselves with the pubsub core,
similar to how subscription and publish handlers had done. Now, subscription
handlers do not need to know what type of body content they generate, but they
still need to inform the pubsub core about what the default body type for a
given event package is. The pubsub core keeps track of what body generators and
body supplements have been registered. When a SUBSCRIBE arrives, the pubsub core
will check that there is a subscription handler for the event in the SUBSCRIBE,
then it will check that there is a body generator that can provide the content
specified in the Accept header(s).
Because of the nature of body generators and supplements, it means
res_pjsip_exten_state and res_pjsip_mwi have been completely gutted. They no
longer worry about body types, instead calling
ast_sip_pubsub_generate_body_content() when they need to generate a NOTIFY body.
Review: https://reviewboard.asterisk.org/r/3150
........
Merged revisions 407016 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407030 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-01-31 22:27:07 +00:00
|
|
|
|
|
|
|
#define MWI_TYPE "application"
|
|
|
|
#define MWI_SUBTYPE "simple-message-summary"
|
|
|
|
|
2014-08-07 19:26:32 +00:00
|
|
|
#define MWI_DATASTORE "MWI datastore"
|
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
static void mwi_subscription_shutdown(struct ast_sip_subscription *sub);
|
2013-11-23 17:26:57 +00:00
|
|
|
static void mwi_to_ami(struct ast_sip_subscription *sub, struct ast_str **buf);
|
2014-06-25 20:57:28 +00:00
|
|
|
static int mwi_new_subscribe(struct ast_sip_endpoint *endpoint,
|
|
|
|
const char *resource);
|
2014-08-07 19:26:32 +00:00
|
|
|
static int mwi_subscription_established(struct ast_sip_subscription *sub);
|
|
|
|
static void *mwi_get_notify_data(struct ast_sip_subscription *sub);
|
2014-06-25 20:57:28 +00:00
|
|
|
|
|
|
|
static struct ast_sip_notifier mwi_notifier = {
|
|
|
|
.default_accept = MWI_TYPE"/"MWI_SUBTYPE,
|
|
|
|
.new_subscribe = mwi_new_subscribe,
|
2014-08-07 19:26:32 +00:00
|
|
|
.subscription_established = mwi_subscription_established,
|
|
|
|
.get_notify_data = mwi_get_notify_data,
|
2014-06-25 20:57:28 +00:00
|
|
|
};
|
2013-04-25 18:25:31 +00:00
|
|
|
|
|
|
|
static struct ast_sip_subscription_handler mwi_handler = {
|
|
|
|
.event_name = "message-summary",
|
2014-09-18 16:09:25 +00:00
|
|
|
.body_type = AST_SIP_MESSAGE_ACCUMULATOR,
|
Decouple subscription handling from NOTIFY/PUBLISH body generation.
When the PJSIP pubsub framework was created, subscription handlers were required
to state what event they handled along with what body types they knew how to
generate. While this serves well when implementing a base RFC, it has problems
when trying to extend the body to support non-standard or proprietary body
elements. The code also was NOTIFY-specific, meaning that when the time comes
that we start writing code to send out PUBLISH requests with MWI or presence
bodies, we would likely find ourselves duplicating code that had previously been
written.
This changeset introduces the concept of body generators and body supplements. A
body generator is responsible for allocating a native structure for a given body
type, providing the primary body content, converting the native structure to a
string, and deallocating resources. A body supplement takes the primary body
content (the native structure, not a string) generated by the body generator and
adds nonstandard elements to the body. With these elements living in their own
module, it becomes easy to extend our support for body types and to re-use
resources when sending a PUBLISH request.
Body generators and body supplements register themselves with the pubsub core,
similar to how subscription and publish handlers had done. Now, subscription
handlers do not need to know what type of body content they generate, but they
still need to inform the pubsub core about what the default body type for a
given event package is. The pubsub core keeps track of what body generators and
body supplements have been registered. When a SUBSCRIBE arrives, the pubsub core
will check that there is a subscription handler for the event in the SUBSCRIBE,
then it will check that there is a body generator that can provide the content
specified in the Accept header(s).
Because of the nature of body generators and supplements, it means
res_pjsip_exten_state and res_pjsip_mwi have been completely gutted. They no
longer worry about body types, instead calling
ast_sip_pubsub_generate_body_content() when they need to generate a NOTIFY body.
Review: https://reviewboard.asterisk.org/r/3150
........
Merged revisions 407016 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407030 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-01-31 22:27:07 +00:00
|
|
|
.accept = { MWI_TYPE"/"MWI_SUBTYPE, },
|
2013-04-25 18:25:31 +00:00
|
|
|
.subscription_shutdown = mwi_subscription_shutdown,
|
2013-11-23 17:26:57 +00:00
|
|
|
.to_ami = mwi_to_ami,
|
2014-06-25 20:57:28 +00:00
|
|
|
.notifier = &mwi_notifier,
|
2013-04-25 18:25:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Wrapper for stasis subscription
|
|
|
|
*
|
|
|
|
* An MWI subscription has a container of these. This
|
|
|
|
* represents a stasis subscription for MWI state.
|
|
|
|
*/
|
|
|
|
struct mwi_stasis_subscription {
|
|
|
|
/*! The MWI stasis subscription */
|
|
|
|
struct stasis_subscription *stasis_sub;
|
|
|
|
/*! The mailbox corresponding with the MWI subscription. Used as a hash key */
|
|
|
|
char mailbox[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief A subscription for MWI
|
|
|
|
*
|
|
|
|
* This subscription is the basis for MWI for an endpoint. Each
|
|
|
|
* endpoint that uses MWI will have a corresponding mwi_subscription.
|
|
|
|
*
|
|
|
|
* This structure acts as the owner for the underlying SIP subscription.
|
|
|
|
* When the mwi_subscription is destroyed, the SIP subscription dies, too.
|
|
|
|
* The mwi_subscription's lifetime is governed by its underlying stasis
|
|
|
|
* subscriptions. When all stasis subscriptions are destroyed, the
|
|
|
|
* mwi_subscription is destroyed as well.
|
|
|
|
*/
|
|
|
|
struct mwi_subscription {
|
|
|
|
/*! Container of \ref mwi_stasis_subscription structures.
|
|
|
|
* A single MWI subscription may be fore multiple mailboxes, thus
|
|
|
|
* requiring multiple stasis subscriptions
|
|
|
|
*/
|
|
|
|
struct ao2_container *stasis_subs;
|
|
|
|
/*! The SIP subscription. Unsolicited MWI does not use this */
|
|
|
|
struct ast_sip_subscription *sip_sub;
|
|
|
|
/*! Is the MWI solicited (i.e. Initiated with an external SUBSCRIBE) ? */
|
|
|
|
unsigned int is_solicited;
|
|
|
|
/*! Identifier for the subscription.
|
|
|
|
* The identifier is the same as the corresponding endpoint's stasis ID.
|
|
|
|
* Used as a hash key
|
|
|
|
*/
|
|
|
|
char id[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
static void mwi_stasis_cb(void *userdata, struct stasis_subscription *sub,
|
Multiple revisions 399887,400138,400178,400180-400181
........
r399887 | dlee | 2013-09-26 10:41:47 -0500 (Thu, 26 Sep 2013) | 1 line
Minor performance bump by not allocate manager variable struct if we don't need it
........
r400138 | dlee | 2013-09-30 10:24:00 -0500 (Mon, 30 Sep 2013) | 23 lines
Stasis performance improvements
This patch addresses several performance problems that were found in
the initial performance testing of Asterisk 12.
The Stasis dispatch object was allocated as an AO2 object, even though
it has a very confined lifecycle. This was replaced with a straight
ast_malloc().
The Stasis message router was spending an inordinate amount of time
searching hash tables. In this case, most of our routers had 6 or
fewer routes in them to begin with. This was replaced with an array
that's searched linearly for the route.
We more heavily rely on AO2 objects in Asterisk 12, and the memset()
in ao2_ref() actually became noticeable on the profile. This was
#ifdef'ed to only run when AO2_DEBUG was enabled.
After being misled by an erroneous comment in taskprocessor.c during
profiling, the wrong comment was removed.
Review: https://reviewboard.asterisk.org/r/2873/
........
r400178 | dlee | 2013-09-30 13:26:27 -0500 (Mon, 30 Sep 2013) | 24 lines
Taskprocessor optimization; switch Stasis to use taskprocessors
This patch optimizes taskprocessor to use a semaphore for signaling,
which the OS can do a better job at managing contention and waiting
that we can with a mutex and condition.
The taskprocessor execution was also slightly optimized to reduce the
number of locks taken.
The only observable difference in the taskprocessor implementation is
that when the final reference to the taskprocessor goes away, it will
execute all tasks to completion instead of discarding the unexecuted
tasks.
For systems where unnamed semaphores are not supported, a really
simple semaphore implementation is provided. (Which gives identical
performance as the original taskprocessor implementation).
The way we ended up implementing Stasis caused the threadpool to be a
burden instead of a boost to performance. This was switched to just
use taskprocessors directly for subscriptions.
Review: https://reviewboard.asterisk.org/r/2881/
........
r400180 | dlee | 2013-09-30 13:39:34 -0500 (Mon, 30 Sep 2013) | 28 lines
Optimize how Stasis forwards are dispatched
This patch optimizes how forwards are dispatched in Stasis.
Originally, forwards were dispatched as subscriptions that are invoked
on the publishing thread. This did not account for the vast number of
forwards we would end up having in the system, and the amount of work it
would take to walk though the forward subscriptions.
This patch modifies Stasis so that rather than walking the tree of
forwards on every dispatch, when forwards and subscriptions are changed,
the subscriber list for every topic in the tree is changed.
This has a couple of benefits. First, this reduces the workload of
dispatching messages. It also reduces contention when dispatching to
different topics that happen to forward to the same aggregation topic
(as happens with all of the channel, bridge and endpoint topics).
Since forwards are no longer subscriptions, the bulk of this patch is
simply changing stasis_subscription objects to stasis_forward objects
(which, admittedly, I should have done in the first place.)
Since this required me to yet again put in a growing array, I finally
abstracted that out into a set of ast_vector macros in
asterisk/vector.h.
Review: https://reviewboard.asterisk.org/r/2883/
........
r400181 | dlee | 2013-09-30 13:48:57 -0500 (Mon, 30 Sep 2013) | 28 lines
Remove dispatch object allocation from Stasis publishing
While looking for areas for performance improvement, I realized that an
unused feature in Stasis was negatively impacting performance.
When a message is sent to a subscriber, a dispatch object is allocated
for the dispatch, containing the topic the message was published to, the
subscriber the message is being sent to, and the message itself.
The topic is actually unused by any subscriber in Asterisk today. And
the subscriber is associated with the taskprocessor the message is being
dispatched to.
First, this patch removes the unused topic parameter from Stasis
subscription callbacks.
Second, this patch introduces the concept of taskprocessor local data,
data that may be set on a taskprocessor and provided along with the data
pointer when a task is pushed using the ast_taskprocessor_push_local()
call. This allows the task to have both data specific to that
taskprocessor, in addition to data specific to that invocation.
With those two changes, the dispatch object can be removed completely,
and the message is simply refcounted and sent directly to the
taskprocessor.
Review: https://reviewboard.asterisk.org/r/2884/
........
Merged revisions 399887,400138,400178,400180-400181 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@400186 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-09-30 18:55:27 +00:00
|
|
|
struct stasis_message *msg);
|
2013-04-25 18:25:31 +00:00
|
|
|
|
|
|
|
static struct mwi_stasis_subscription *mwi_stasis_subscription_alloc(const char *mailbox, struct mwi_subscription *mwi_sub)
|
|
|
|
{
|
|
|
|
struct mwi_stasis_subscription *mwi_stasis_sub;
|
|
|
|
struct stasis_topic *topic;
|
2013-11-23 17:26:57 +00:00
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
if (!mwi_sub) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-11-23 17:26:57 +00:00
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
mwi_stasis_sub = ao2_alloc(sizeof(*mwi_stasis_sub) + strlen(mailbox), NULL);
|
|
|
|
if (!mwi_stasis_sub) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-24 20:44:07 +00:00
|
|
|
topic = ast_mwi_topic(mailbox);
|
2013-04-25 18:25:31 +00:00
|
|
|
|
|
|
|
/* Safe strcpy */
|
|
|
|
strcpy(mwi_stasis_sub->mailbox, mailbox);
|
|
|
|
ao2_ref(mwi_sub, +1);
|
|
|
|
ast_debug(3, "Creating stasis MWI subscription to mailbox %s for endpoint %s\n", mailbox, mwi_sub->id);
|
|
|
|
mwi_stasis_sub->stasis_sub = stasis_subscribe(topic, mwi_stasis_cb, mwi_sub);
|
|
|
|
return mwi_stasis_sub;
|
|
|
|
}
|
|
|
|
|
2014-03-14 18:05:04 +00:00
|
|
|
static int stasis_sub_hash(const void *obj, const int flags)
|
2013-04-25 18:25:31 +00:00
|
|
|
{
|
2014-03-14 18:05:04 +00:00
|
|
|
const struct mwi_stasis_subscription *object;
|
|
|
|
const char *key;
|
2013-04-25 18:25:31 +00:00
|
|
|
|
2014-03-14 18:05:04 +00:00
|
|
|
switch (flags & OBJ_SEARCH_MASK) {
|
|
|
|
case OBJ_SEARCH_KEY:
|
|
|
|
key = obj;
|
|
|
|
break;
|
|
|
|
case OBJ_SEARCH_OBJECT:
|
|
|
|
object = obj;
|
|
|
|
key = object->mailbox;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ast_assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ast_str_hash(key);
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int stasis_sub_cmp(void *obj, void *arg, int flags)
|
|
|
|
{
|
2014-03-14 18:05:04 +00:00
|
|
|
const struct mwi_stasis_subscription *sub_left = obj;
|
|
|
|
const struct mwi_stasis_subscription *sub_right = arg;
|
|
|
|
const char *right_key = arg;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
switch (flags & OBJ_SEARCH_MASK) {
|
|
|
|
case OBJ_SEARCH_OBJECT:
|
|
|
|
right_key = sub_right->mailbox;
|
|
|
|
/* Fall through */
|
|
|
|
case OBJ_SEARCH_KEY:
|
|
|
|
cmp = strcmp(sub_left->mailbox, right_key);
|
|
|
|
break;
|
|
|
|
case OBJ_SEARCH_PARTIAL_KEY:
|
|
|
|
cmp = strncmp(sub_left->mailbox, right_key, strlen(right_key));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cmp = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cmp) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return CMP_MATCH;
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mwi_subscription_destructor(void *obj)
|
|
|
|
{
|
|
|
|
struct mwi_subscription *sub = obj;
|
|
|
|
|
|
|
|
ast_debug(3, "Destroying MWI subscription for endpoint %s\n", sub->id);
|
|
|
|
ao2_cleanup(sub->sip_sub);
|
|
|
|
ao2_cleanup(sub->stasis_subs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mwi_subscription *mwi_subscription_alloc(struct ast_sip_endpoint *endpoint,
|
2014-06-25 20:57:28 +00:00
|
|
|
unsigned int is_solicited, struct ast_sip_subscription *sip_sub)
|
2013-04-25 18:25:31 +00:00
|
|
|
{
|
|
|
|
struct mwi_subscription *sub;
|
|
|
|
const char *endpoint_id = ast_sorcery_object_get_id(endpoint);
|
|
|
|
|
|
|
|
sub = ao2_alloc(sizeof(*sub) + strlen(endpoint_id),
|
|
|
|
mwi_subscription_destructor);
|
|
|
|
|
|
|
|
if (!sub) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Safe strcpy */
|
|
|
|
strcpy(sub->id, endpoint_id);
|
2014-06-25 20:57:28 +00:00
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
/* Unsolicited MWI doesn't actually result in a SIP subscription being
|
|
|
|
* created. This is because a SIP subscription associates with a dialog.
|
|
|
|
* Most devices expect unsolicited MWI NOTIFYs to appear out of dialog. If
|
|
|
|
* they receive an in-dialog MWI NOTIFY (i.e. with a to-tag), then they
|
|
|
|
* will reject the NOTIFY with a 481, thus resulting in message-waiting
|
|
|
|
* state not being updated on the device
|
|
|
|
*/
|
|
|
|
if (is_solicited) {
|
2014-06-25 20:57:28 +00:00
|
|
|
sub->sip_sub = ao2_bump(sip_sub);
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub->stasis_subs = ao2_container_alloc(STASIS_BUCKETS, stasis_sub_hash, stasis_sub_cmp);
|
|
|
|
if (!sub->stasis_subs) {
|
|
|
|
ao2_cleanup(sub);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
sub->is_solicited = is_solicited;
|
|
|
|
|
|
|
|
ast_debug(3, "Created %s MWI subscription for endpoint %s\n", is_solicited ? "solicited" : "unsolicited", sub->id);
|
|
|
|
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2014-03-14 18:05:04 +00:00
|
|
|
static int mwi_sub_hash(const void *obj, const int flags)
|
2013-04-25 18:25:31 +00:00
|
|
|
{
|
2014-03-14 18:05:04 +00:00
|
|
|
const struct mwi_subscription *object;
|
|
|
|
const char *key;
|
2013-11-23 17:26:57 +00:00
|
|
|
|
2014-03-14 18:05:04 +00:00
|
|
|
switch (flags & OBJ_SEARCH_MASK) {
|
|
|
|
case OBJ_SEARCH_KEY:
|
|
|
|
key = obj;
|
|
|
|
break;
|
|
|
|
case OBJ_SEARCH_OBJECT:
|
|
|
|
object = obj;
|
|
|
|
key = object->id;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ast_assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ast_str_hash(key);
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mwi_sub_cmp(void *obj, void *arg, int flags)
|
|
|
|
{
|
2014-03-14 18:05:04 +00:00
|
|
|
const struct mwi_subscription *sub_left = obj;
|
|
|
|
const struct mwi_subscription *sub_right = arg;
|
|
|
|
const char *right_key = arg;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
switch (flags & OBJ_SEARCH_MASK) {
|
|
|
|
case OBJ_SEARCH_OBJECT:
|
|
|
|
right_key = sub_right->id;
|
|
|
|
/* Fall through */
|
|
|
|
case OBJ_SEARCH_KEY:
|
|
|
|
cmp = strcmp(sub_left->id, right_key);
|
|
|
|
break;
|
|
|
|
case OBJ_SEARCH_PARTIAL_KEY:
|
|
|
|
cmp = strncmp(sub_left->id, right_key, strlen(right_key));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cmp = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cmp) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return CMP_MATCH;
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_message_count(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
|
|
|
|
struct mwi_stasis_subscription *mwi_stasis = obj;
|
Decouple subscription handling from NOTIFY/PUBLISH body generation.
When the PJSIP pubsub framework was created, subscription handlers were required
to state what event they handled along with what body types they knew how to
generate. While this serves well when implementing a base RFC, it has problems
when trying to extend the body to support non-standard or proprietary body
elements. The code also was NOTIFY-specific, meaning that when the time comes
that we start writing code to send out PUBLISH requests with MWI or presence
bodies, we would likely find ourselves duplicating code that had previously been
written.
This changeset introduces the concept of body generators and body supplements. A
body generator is responsible for allocating a native structure for a given body
type, providing the primary body content, converting the native structure to a
string, and deallocating resources. A body supplement takes the primary body
content (the native structure, not a string) generated by the body generator and
adds nonstandard elements to the body. With these elements living in their own
module, it becomes easy to extend our support for body types and to re-use
resources when sending a PUBLISH request.
Body generators and body supplements register themselves with the pubsub core,
similar to how subscription and publish handlers had done. Now, subscription
handlers do not need to know what type of body content they generate, but they
still need to inform the pubsub core about what the default body type for a
given event package is. The pubsub core keeps track of what body generators and
body supplements have been registered. When a SUBSCRIBE arrives, the pubsub core
will check that there is a subscription handler for the event in the SUBSCRIBE,
then it will check that there is a body generator that can provide the content
specified in the Accept header(s).
Because of the nature of body generators and supplements, it means
res_pjsip_exten_state and res_pjsip_mwi have been completely gutted. They no
longer worry about body types, instead calling
ast_sip_pubsub_generate_body_content() when they need to generate a NOTIFY body.
Review: https://reviewboard.asterisk.org/r/3150
........
Merged revisions 407016 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407030 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-01-31 22:27:07 +00:00
|
|
|
struct ast_sip_message_accumulator *counter = arg;
|
2013-05-24 20:44:07 +00:00
|
|
|
struct ast_mwi_state *mwi_state;
|
2013-04-25 18:25:31 +00:00
|
|
|
|
2013-08-01 15:31:03 +00:00
|
|
|
msg = stasis_cache_get(ast_mwi_state_cache(), ast_mwi_state_type(), mwi_stasis->mailbox);
|
2013-04-25 18:25:31 +00:00
|
|
|
if (!msg) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mwi_state = stasis_message_data(msg);
|
|
|
|
counter->old_msgs += mwi_state->old_msgs;
|
|
|
|
counter->new_msgs += mwi_state->new_msgs;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct unsolicited_mwi_data {
|
|
|
|
struct mwi_subscription *sub;
|
|
|
|
struct ast_sip_endpoint *endpoint;
|
|
|
|
pjsip_evsub_state state;
|
2014-02-13 18:52:08 +00:00
|
|
|
const struct ast_sip_body *body;
|
2013-04-25 18:25:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int send_unsolicited_mwi_notify_to_contact(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct unsolicited_mwi_data *mwi_data = arg;
|
|
|
|
struct mwi_subscription *sub = mwi_data->sub;
|
|
|
|
struct ast_sip_endpoint *endpoint = mwi_data->endpoint;
|
|
|
|
pjsip_evsub_state state = mwi_data->state;
|
2014-02-13 18:52:08 +00:00
|
|
|
const struct ast_sip_body *body = mwi_data->body;
|
2013-04-25 18:25:31 +00:00
|
|
|
struct ast_sip_contact *contact = obj;
|
|
|
|
const char *state_name;
|
|
|
|
pjsip_tx_data *tdata;
|
|
|
|
pjsip_sub_state_hdr *sub_state;
|
|
|
|
pjsip_event_hdr *event;
|
|
|
|
const pjsip_hdr *allow_events = pjsip_evsub_get_allow_events_hdr(NULL);
|
|
|
|
|
2014-01-15 13:16:10 +00:00
|
|
|
if (ast_sip_create_request("NOTIFY", NULL, endpoint, NULL, contact, &tdata)) {
|
2013-04-25 18:25:31 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to create unsolicited NOTIFY request to endpoint %s URI %s\n", sub->id, contact->uri);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-30 15:17:56 +00:00
|
|
|
if (!ast_strlen_zero(endpoint->subscription.mwi.fromuser)) {
|
2013-07-18 19:25:51 +00:00
|
|
|
pjsip_fromto_hdr *from = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_FROM, NULL);
|
|
|
|
pjsip_name_addr *from_name_addr = (pjsip_name_addr *) from->uri;
|
|
|
|
pjsip_sip_uri *from_uri = pjsip_uri_get_uri(from_name_addr->uri);
|
|
|
|
|
2013-07-30 15:17:56 +00:00
|
|
|
pj_strdup2(tdata->pool, &from_uri->user, endpoint->subscription.mwi.fromuser);
|
2013-07-18 19:25:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
switch (state) {
|
|
|
|
case PJSIP_EVSUB_STATE_ACTIVE:
|
|
|
|
state_name = "active";
|
|
|
|
break;
|
|
|
|
case PJSIP_EVSUB_STATE_TERMINATED:
|
|
|
|
default:
|
|
|
|
state_name = "terminated";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub_state = pjsip_sub_state_hdr_create(tdata->pool);
|
|
|
|
pj_cstr(&sub_state->sub_state, state_name);
|
|
|
|
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) sub_state);
|
|
|
|
|
|
|
|
event = pjsip_event_hdr_create(tdata->pool);
|
|
|
|
pj_cstr(&event->event_type, "message-summary");
|
|
|
|
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) event);
|
|
|
|
|
|
|
|
pjsip_msg_add_hdr(tdata->msg, pjsip_hdr_shallow_clone(tdata->pool, allow_events));
|
2014-02-13 18:52:08 +00:00
|
|
|
ast_sip_add_body(tdata, body);
|
2014-01-15 13:16:10 +00:00
|
|
|
ast_sip_send_request(tdata, NULL, endpoint, NULL, NULL);
|
2013-04-25 18:25:31 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
static void send_unsolicited_mwi_notify(struct mwi_subscription *sub,
|
|
|
|
struct ast_sip_message_accumulator *counter)
|
2013-04-25 18:25:31 +00:00
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_sip_endpoint *, endpoint, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(),
|
|
|
|
"endpoint", sub->id), ao2_cleanup);
|
|
|
|
char *endpoint_aors;
|
|
|
|
char *aor_name;
|
2014-06-25 20:57:28 +00:00
|
|
|
struct ast_sip_body body;
|
|
|
|
struct ast_str *body_text;
|
2014-09-18 16:09:25 +00:00
|
|
|
struct ast_sip_body_data body_data = {
|
|
|
|
.body_type = AST_SIP_MESSAGE_ACCUMULATOR,
|
|
|
|
.body_data = counter,
|
|
|
|
};
|
2013-04-25 18:25:31 +00:00
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to send unsolicited MWI to %s because endpoint does not exist\n",
|
|
|
|
sub->id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ast_strlen_zero(endpoint->aors)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to send unsolicited MWI to %s because the endpoint has no"
|
|
|
|
" configured AORs\n", sub->id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
body.type = MWI_TYPE;
|
|
|
|
body.subtype = MWI_SUBTYPE;
|
|
|
|
|
|
|
|
body_text = ast_str_create(64);
|
|
|
|
|
|
|
|
if (!body_text) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-18 16:09:25 +00:00
|
|
|
if (ast_sip_pubsub_generate_body_content(body.type, body.subtype, &body_data, &body_text)) {
|
2014-06-25 20:57:28 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to generate SIP MWI NOTIFY body.\n");
|
|
|
|
ast_free(body_text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
body.body_text = ast_str_buffer(body_text);
|
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
endpoint_aors = ast_strdupa(endpoint->aors);
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
ast_debug(5, "Sending unsolicited MWI NOTIFY to endpoint %s, new messages: %d, old messages: %d\n",
|
|
|
|
sub->id, counter->new_msgs, counter->old_msgs);
|
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
while ((aor_name = strsep(&endpoint_aors, ","))) {
|
|
|
|
RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
|
|
|
|
RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
|
|
|
|
struct unsolicited_mwi_data mwi_data = {
|
|
|
|
.sub = sub,
|
|
|
|
.endpoint = endpoint,
|
2014-06-25 20:57:28 +00:00
|
|
|
.body = &body,
|
2013-04-25 18:25:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!aor) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to locate AOR %s for unsolicited MWI\n", aor_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
contacts = ast_sip_location_retrieve_aor_contacts(aor);
|
|
|
|
if (!contacts || (ao2_container_count(contacts) == 0)) {
|
|
|
|
ast_log(LOG_WARNING, "No contacts bound to AOR %s. Cannot send unsolicited MWI.\n", aor_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ao2_callback(contacts, OBJ_NODATA, send_unsolicited_mwi_notify_to_contact, &mwi_data);
|
|
|
|
}
|
2014-06-25 20:57:28 +00:00
|
|
|
|
|
|
|
ast_free(body_text);
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
static void send_mwi_notify(struct mwi_subscription *sub)
|
2013-04-25 18:25:31 +00:00
|
|
|
{
|
Decouple subscription handling from NOTIFY/PUBLISH body generation.
When the PJSIP pubsub framework was created, subscription handlers were required
to state what event they handled along with what body types they knew how to
generate. While this serves well when implementing a base RFC, it has problems
when trying to extend the body to support non-standard or proprietary body
elements. The code also was NOTIFY-specific, meaning that when the time comes
that we start writing code to send out PUBLISH requests with MWI or presence
bodies, we would likely find ourselves duplicating code that had previously been
written.
This changeset introduces the concept of body generators and body supplements. A
body generator is responsible for allocating a native structure for a given body
type, providing the primary body content, converting the native structure to a
string, and deallocating resources. A body supplement takes the primary body
content (the native structure, not a string) generated by the body generator and
adds nonstandard elements to the body. With these elements living in their own
module, it becomes easy to extend our support for body types and to re-use
resources when sending a PUBLISH request.
Body generators and body supplements register themselves with the pubsub core,
similar to how subscription and publish handlers had done. Now, subscription
handlers do not need to know what type of body content they generate, but they
still need to inform the pubsub core about what the default body type for a
given event package is. The pubsub core keeps track of what body generators and
body supplements have been registered. When a SUBSCRIBE arrives, the pubsub core
will check that there is a subscription handler for the event in the SUBSCRIBE,
then it will check that there is a body generator that can provide the content
specified in the Accept header(s).
Because of the nature of body generators and supplements, it means
res_pjsip_exten_state and res_pjsip_mwi have been completely gutted. They no
longer worry about body types, instead calling
ast_sip_pubsub_generate_body_content() when they need to generate a NOTIFY body.
Review: https://reviewboard.asterisk.org/r/3150
........
Merged revisions 407016 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407030 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-01-31 22:27:07 +00:00
|
|
|
struct ast_sip_message_accumulator counter = {
|
2013-04-25 18:25:31 +00:00
|
|
|
.old_msgs = 0,
|
|
|
|
.new_msgs = 0,
|
|
|
|
};
|
2014-09-18 16:09:25 +00:00
|
|
|
struct ast_sip_body_data data = {
|
|
|
|
.body_type = AST_SIP_MESSAGE_ACCUMULATOR,
|
|
|
|
.body_data = &counter,
|
|
|
|
};
|
2013-04-25 18:25:31 +00:00
|
|
|
|
|
|
|
ao2_callback(sub->stasis_subs, OBJ_NODATA, get_message_count, &counter);
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
if (sub->is_solicited) {
|
2014-09-18 16:09:25 +00:00
|
|
|
ast_sip_subscription_notify(sub->sip_sub, &data, 0);
|
Decouple subscription handling from NOTIFY/PUBLISH body generation.
When the PJSIP pubsub framework was created, subscription handlers were required
to state what event they handled along with what body types they knew how to
generate. While this serves well when implementing a base RFC, it has problems
when trying to extend the body to support non-standard or proprietary body
elements. The code also was NOTIFY-specific, meaning that when the time comes
that we start writing code to send out PUBLISH requests with MWI or presence
bodies, we would likely find ourselves duplicating code that had previously been
written.
This changeset introduces the concept of body generators and body supplements. A
body generator is responsible for allocating a native structure for a given body
type, providing the primary body content, converting the native structure to a
string, and deallocating resources. A body supplement takes the primary body
content (the native structure, not a string) generated by the body generator and
adds nonstandard elements to the body. With these elements living in their own
module, it becomes easy to extend our support for body types and to re-use
resources when sending a PUBLISH request.
Body generators and body supplements register themselves with the pubsub core,
similar to how subscription and publish handlers had done. Now, subscription
handlers do not need to know what type of body content they generate, but they
still need to inform the pubsub core about what the default body type for a
given event package is. The pubsub core keeps track of what body generators and
body supplements have been registered. When a SUBSCRIBE arrives, the pubsub core
will check that there is a subscription handler for the event in the SUBSCRIBE,
then it will check that there is a body generator that can provide the content
specified in the Accept header(s).
Because of the nature of body generators and supplements, it means
res_pjsip_exten_state and res_pjsip_mwi have been completely gutted. They no
longer worry about body types, instead calling
ast_sip_pubsub_generate_body_content() when they need to generate a NOTIFY body.
Review: https://reviewboard.asterisk.org/r/3150
........
Merged revisions 407016 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407030 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-01-31 22:27:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
send_unsolicited_mwi_notify(sub, &counter);
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int unsubscribe_stasis(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct mwi_stasis_subscription *mwi_stasis = obj;
|
|
|
|
if (mwi_stasis->stasis_sub) {
|
|
|
|
ast_debug(3, "Removing stasis subscription to mailbox %s\n", mwi_stasis->mailbox);
|
|
|
|
mwi_stasis->stasis_sub = stasis_unsubscribe(mwi_stasis->stasis_sub);
|
|
|
|
}
|
|
|
|
return CMP_MATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mwi_subscription_shutdown(struct ast_sip_subscription *sub)
|
|
|
|
{
|
|
|
|
struct mwi_subscription *mwi_sub;
|
|
|
|
RAII_VAR(struct ast_datastore *, mwi_datastore,
|
2014-08-07 19:26:32 +00:00
|
|
|
ast_sip_subscription_get_datastore(sub, MWI_DATASTORE), ao2_cleanup);
|
2013-04-25 18:25:31 +00:00
|
|
|
|
|
|
|
if (!mwi_datastore) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mwi_sub = mwi_datastore->data;
|
|
|
|
ao2_callback(mwi_sub->stasis_subs, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe_stasis, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_datastore_info mwi_ds_info = { };
|
|
|
|
|
|
|
|
static int add_mwi_datastore(struct mwi_subscription *sub)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_datastore *, mwi_datastore, NULL, ao2_cleanup);
|
|
|
|
|
2014-08-07 19:26:32 +00:00
|
|
|
mwi_datastore = ast_sip_subscription_alloc_datastore(&mwi_ds_info, MWI_DATASTORE);
|
2013-04-25 18:25:31 +00:00
|
|
|
if (!mwi_datastore) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
mwi_datastore->data = sub;
|
|
|
|
|
|
|
|
ast_sip_subscription_add_datastore(sub->sip_sub, mwi_datastore);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-14 18:05:04 +00:00
|
|
|
/*!
|
|
|
|
* \brief Determines if an endpoint is receiving unsolicited MWI for a particular mailbox.
|
|
|
|
*
|
|
|
|
* \param endpoint The endpoint to check
|
|
|
|
* \param mailbox The candidate mailbox
|
|
|
|
* \retval 0 The endpoint does not receive unsolicited MWI for this mailbox
|
|
|
|
* \retval 1 The endpoint receives unsolicited MWI for this mailbox
|
|
|
|
*/
|
|
|
|
static int endpoint_receives_unsolicited_mwi_for_mailbox(struct ast_sip_endpoint *endpoint,
|
|
|
|
const char *mailbox)
|
|
|
|
{
|
|
|
|
struct ao2_container *unsolicited = ao2_global_obj_ref(unsolicited_mwi);
|
|
|
|
struct ao2_iterator *mwi_subs;
|
|
|
|
struct mwi_subscription *mwi_sub;
|
|
|
|
const char *endpoint_id = ast_sorcery_object_get_id(endpoint);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!unsolicited) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mwi_subs = ao2_find(unsolicited, endpoint_id, OBJ_SEARCH_KEY | OBJ_MULTIPLE);
|
|
|
|
ao2_cleanup(unsolicited);
|
|
|
|
|
|
|
|
if (!mwi_subs) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; (mwi_sub = ao2_iterator_next(mwi_subs)) && !ret; ao2_cleanup(mwi_sub)) {
|
|
|
|
struct mwi_stasis_subscription *mwi_stasis;
|
|
|
|
|
|
|
|
mwi_stasis = ao2_find(mwi_sub->stasis_subs, mailbox, OBJ_SEARCH_KEY);
|
|
|
|
if (mwi_stasis) {
|
|
|
|
ret = 1;
|
|
|
|
ao2_cleanup(mwi_stasis);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ao2_iterator_destroy(mwi_subs);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Determine if an endpoint is a candidate to be able to subscribe for MWI
|
|
|
|
*
|
|
|
|
* Currently, this just makes sure that the endpoint is not already receiving unsolicted
|
|
|
|
* MWI for any of an AOR's configured mailboxes.
|
|
|
|
*
|
|
|
|
* \param obj The AOR to which the endpoint is subscribing.
|
|
|
|
* \param arg The endpoint that is attempting to subscribe.
|
|
|
|
* \param flags Unused.
|
|
|
|
* \retval 0 Endpoint is a candidate to subscribe to MWI on the AOR.
|
|
|
|
* \retval -1 The endpoint cannot subscribe to MWI on the AOR.
|
|
|
|
*/
|
|
|
|
static int mwi_validate_for_aor(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct ast_sip_aor *aor = obj;
|
|
|
|
struct ast_sip_endpoint *endpoint = arg;
|
|
|
|
char *mailboxes;
|
|
|
|
char *mailbox;
|
|
|
|
|
|
|
|
if (ast_strlen_zero(aor->mailboxes)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mailboxes = ast_strdupa(aor->mailboxes);
|
|
|
|
while ((mailbox = strsep(&mailboxes, ","))) {
|
|
|
|
if (endpoint_receives_unsolicited_mwi_for_mailbox(endpoint, mailbox)) {
|
|
|
|
ast_log(LOG_NOTICE, "Endpoint '%s' already configured for unsolicited MWI for mailbox '%s'. "
|
|
|
|
"Denying MWI subscription to %s\n", ast_sorcery_object_get_id(endpoint), mailbox,
|
|
|
|
ast_sorcery_object_get_id(aor));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-31 22:08:46 +00:00
|
|
|
static int mwi_on_aor(void *obj, void *arg, int flags)
|
2013-04-25 18:25:31 +00:00
|
|
|
{
|
2014-01-31 22:08:46 +00:00
|
|
|
struct ast_sip_aor *aor = obj;
|
|
|
|
struct mwi_subscription *sub = arg;
|
2013-04-25 18:25:31 +00:00
|
|
|
char *mailboxes;
|
|
|
|
char *mailbox;
|
|
|
|
|
2014-01-31 22:08:46 +00:00
|
|
|
if (ast_strlen_zero(aor->mailboxes)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mailboxes = ast_strdupa(aor->mailboxes);
|
|
|
|
while ((mailbox = strsep(&mailboxes, ","))) {
|
|
|
|
RAII_VAR(struct mwi_stasis_subscription *, mwi_stasis_sub,
|
|
|
|
mwi_stasis_subscription_alloc(mailbox, sub), ao2_cleanup);
|
|
|
|
if (mwi_stasis_sub) {
|
|
|
|
ao2_link(sub->stasis_subs, mwi_stasis_sub);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mwi_subscription *mwi_create_subscription(
|
2014-06-25 20:57:28 +00:00
|
|
|
struct ast_sip_endpoint *endpoint, struct ast_sip_subscription *sip_sub)
|
2014-01-31 22:08:46 +00:00
|
|
|
{
|
2014-06-25 20:57:28 +00:00
|
|
|
struct mwi_subscription *sub = mwi_subscription_alloc(endpoint, 1, sip_sub);
|
2014-01-31 22:08:46 +00:00
|
|
|
|
|
|
|
if (!sub) {
|
2013-04-25 18:25:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-31 22:08:46 +00:00
|
|
|
if (add_mwi_datastore(sub)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to allocate datastore on MWI "
|
|
|
|
"subscription from %s\n", sub->id);
|
|
|
|
ao2_ref(sub, -1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mwi_subscription *mwi_subscribe_single(
|
2014-06-25 20:57:28 +00:00
|
|
|
struct ast_sip_endpoint *endpoint, struct ast_sip_subscription *sip_sub, const char *name)
|
2014-01-31 22:08:46 +00:00
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_sip_aor *, aor,
|
|
|
|
ast_sip_location_retrieve_aor(name), ao2_cleanup);
|
|
|
|
struct mwi_subscription *sub;
|
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
if (!aor) {
|
2014-06-25 20:57:28 +00:00
|
|
|
/*! I suppose it's possible for the AOR to disappear on us
|
|
|
|
* between accepting the subscription and sending the first
|
|
|
|
* NOTIFY...
|
|
|
|
*/
|
2014-01-31 22:08:46 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to locate aor %s. MWI "
|
|
|
|
"subscription failed.\n", name);
|
2013-04-25 18:25:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
if (!(sub = mwi_create_subscription(endpoint, sip_sub))) {
|
2013-04-25 18:25:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-31 22:08:46 +00:00
|
|
|
mwi_on_aor(aor, sub, 0);
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mwi_subscription *mwi_subscribe_all(
|
2014-06-25 20:57:28 +00:00
|
|
|
struct ast_sip_endpoint *endpoint, struct ast_sip_subscription *sip_sub)
|
2014-01-31 22:08:46 +00:00
|
|
|
{
|
2014-03-14 18:05:04 +00:00
|
|
|
struct mwi_subscription *sub;
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
sub = mwi_create_subscription(endpoint, sip_sub);
|
2014-01-31 22:08:46 +00:00
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
if (!sub) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-31 22:08:46 +00:00
|
|
|
ast_sip_for_each_aor(endpoint->aors, mwi_on_aor, sub);
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
static int mwi_new_subscribe(struct ast_sip_endpoint *endpoint,
|
|
|
|
const char *resource)
|
2014-01-31 22:08:46 +00:00
|
|
|
{
|
2014-06-25 20:57:28 +00:00
|
|
|
struct ast_sip_aor *aor;
|
2014-01-31 22:08:46 +00:00
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
if (ast_strlen_zero(resource)) {
|
|
|
|
if (ast_sip_for_each_aor(endpoint->aors, mwi_validate_for_aor, endpoint)) {
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
return 200;
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
aor = ast_sip_location_retrieve_aor(resource);
|
2013-04-25 18:25:31 +00:00
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
if (!aor) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to locate aor %s. MWI "
|
|
|
|
"subscription failed.\n", resource);
|
|
|
|
return 404;
|
|
|
|
}
|
2014-02-13 18:52:08 +00:00
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
if (ast_strlen_zero(aor->mailboxes)) {
|
|
|
|
ast_log(LOG_WARNING, "AOR %s has no configured mailboxes. "
|
|
|
|
"MWI subscription failed\n", resource);
|
|
|
|
return 404;
|
2014-02-13 18:52:08 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
if (mwi_validate_for_aor(aor, endpoint, 0)) {
|
|
|
|
return 500;
|
|
|
|
}
|
2013-04-25 18:25:31 +00:00
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
return 200;
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
2014-08-07 19:26:32 +00:00
|
|
|
static int mwi_subscription_established(struct ast_sip_subscription *sip_sub)
|
2013-04-25 18:25:31 +00:00
|
|
|
{
|
2014-06-25 20:57:28 +00:00
|
|
|
const char *resource = ast_sip_subscription_get_resource_name(sip_sub);
|
|
|
|
struct mwi_subscription *sub;
|
|
|
|
struct ast_sip_endpoint *endpoint = ast_sip_subscription_get_endpoint(sip_sub);
|
2013-04-25 18:25:31 +00:00
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
/* no aor in uri? subscribe to all on endpoint */
|
|
|
|
if (ast_strlen_zero(resource)) {
|
|
|
|
sub = mwi_subscribe_all(endpoint, sip_sub);
|
|
|
|
} else {
|
|
|
|
sub = mwi_subscribe_single(endpoint, sip_sub, resource);
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
if (!sub) {
|
|
|
|
ao2_cleanup(endpoint);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-04-25 18:25:31 +00:00
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
ao2_cleanup(sub);
|
|
|
|
ao2_cleanup(endpoint);
|
|
|
|
return 0;
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
2014-08-07 19:26:32 +00:00
|
|
|
static void *mwi_get_notify_data(struct ast_sip_subscription *sub)
|
2013-04-25 18:25:31 +00:00
|
|
|
{
|
2014-08-07 19:26:32 +00:00
|
|
|
struct ast_sip_message_accumulator *counter;
|
2013-04-25 18:25:31 +00:00
|
|
|
struct mwi_subscription *mwi_sub;
|
2014-06-25 20:57:28 +00:00
|
|
|
struct ast_datastore *mwi_datastore;
|
2013-04-25 18:25:31 +00:00
|
|
|
|
2014-08-07 19:26:32 +00:00
|
|
|
mwi_datastore = ast_sip_subscription_get_datastore(sub, MWI_DATASTORE);
|
|
|
|
if (!mwi_datastore) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
mwi_sub = mwi_datastore->data;
|
2013-04-25 18:25:31 +00:00
|
|
|
|
2014-08-07 19:26:32 +00:00
|
|
|
counter = ao2_alloc(sizeof(*counter), NULL);
|
|
|
|
if (!counter) {
|
2014-06-25 20:57:28 +00:00
|
|
|
ao2_cleanup(mwi_datastore);
|
2014-08-07 19:26:32 +00:00
|
|
|
return NULL;
|
2014-06-25 20:57:28 +00:00
|
|
|
}
|
2013-04-25 18:25:31 +00:00
|
|
|
|
2014-08-07 19:26:32 +00:00
|
|
|
ao2_callback(mwi_sub->stasis_subs, OBJ_NODATA, get_message_count, counter);
|
|
|
|
ao2_cleanup(mwi_datastore);
|
|
|
|
return counter;
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 17:26:57 +00:00
|
|
|
static void mwi_subscription_mailboxes_str(struct ao2_container *stasis_subs,
|
|
|
|
struct ast_str **str)
|
|
|
|
{
|
|
|
|
int num = ao2_container_count(stasis_subs);
|
|
|
|
|
|
|
|
struct mwi_stasis_subscription *node;
|
|
|
|
struct ao2_iterator i = ao2_iterator_init(stasis_subs, 0);
|
|
|
|
|
|
|
|
while ((node = ao2_iterator_next(&i))) {
|
|
|
|
if (--num) {
|
|
|
|
ast_str_append(str, 0, "%s,", node->mailbox);
|
|
|
|
} else {
|
|
|
|
ast_str_append(str, 0, "%s", node->mailbox);
|
|
|
|
}
|
|
|
|
ao2_ref(node, -1);
|
|
|
|
}
|
|
|
|
ao2_iterator_destroy(&i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mwi_to_ami(struct ast_sip_subscription *sub,
|
|
|
|
struct ast_str **buf)
|
|
|
|
{
|
|
|
|
struct mwi_subscription *mwi_sub;
|
|
|
|
RAII_VAR(struct ast_datastore *, mwi_datastore,
|
2014-08-07 19:26:32 +00:00
|
|
|
ast_sip_subscription_get_datastore(sub, MWI_DATASTORE), ao2_cleanup);
|
2013-11-23 17:26:57 +00:00
|
|
|
|
|
|
|
if (!mwi_datastore) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mwi_sub = mwi_datastore->data;
|
|
|
|
|
|
|
|
ast_str_append(buf, 0, "SubscriptionType: mwi\r\n");
|
|
|
|
ast_str_append(buf, 0, "Mailboxes: ");
|
|
|
|
mwi_subscription_mailboxes_str(mwi_sub->stasis_subs, buf);
|
|
|
|
ast_str_append(buf, 0, "\r\n");
|
|
|
|
}
|
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
static int serialized_notify(void *userdata)
|
|
|
|
{
|
|
|
|
struct mwi_subscription *mwi_sub = userdata;
|
|
|
|
|
2014-06-25 20:57:28 +00:00
|
|
|
send_mwi_notify(mwi_sub);
|
2013-04-25 18:25:31 +00:00
|
|
|
ao2_ref(mwi_sub, -1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int serialized_cleanup(void *userdata)
|
|
|
|
{
|
|
|
|
struct mwi_subscription *mwi_sub = userdata;
|
|
|
|
|
|
|
|
/* This is getting rid of the reference that was added
|
|
|
|
* just before this serialized task was pushed.
|
|
|
|
*/
|
|
|
|
ao2_cleanup(mwi_sub);
|
|
|
|
/* This is getting rid of the reference held by the
|
|
|
|
* stasis subscription
|
|
|
|
*/
|
|
|
|
ao2_cleanup(mwi_sub);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mwi_stasis_cb(void *userdata, struct stasis_subscription *sub,
|
Multiple revisions 399887,400138,400178,400180-400181
........
r399887 | dlee | 2013-09-26 10:41:47 -0500 (Thu, 26 Sep 2013) | 1 line
Minor performance bump by not allocate manager variable struct if we don't need it
........
r400138 | dlee | 2013-09-30 10:24:00 -0500 (Mon, 30 Sep 2013) | 23 lines
Stasis performance improvements
This patch addresses several performance problems that were found in
the initial performance testing of Asterisk 12.
The Stasis dispatch object was allocated as an AO2 object, even though
it has a very confined lifecycle. This was replaced with a straight
ast_malloc().
The Stasis message router was spending an inordinate amount of time
searching hash tables. In this case, most of our routers had 6 or
fewer routes in them to begin with. This was replaced with an array
that's searched linearly for the route.
We more heavily rely on AO2 objects in Asterisk 12, and the memset()
in ao2_ref() actually became noticeable on the profile. This was
#ifdef'ed to only run when AO2_DEBUG was enabled.
After being misled by an erroneous comment in taskprocessor.c during
profiling, the wrong comment was removed.
Review: https://reviewboard.asterisk.org/r/2873/
........
r400178 | dlee | 2013-09-30 13:26:27 -0500 (Mon, 30 Sep 2013) | 24 lines
Taskprocessor optimization; switch Stasis to use taskprocessors
This patch optimizes taskprocessor to use a semaphore for signaling,
which the OS can do a better job at managing contention and waiting
that we can with a mutex and condition.
The taskprocessor execution was also slightly optimized to reduce the
number of locks taken.
The only observable difference in the taskprocessor implementation is
that when the final reference to the taskprocessor goes away, it will
execute all tasks to completion instead of discarding the unexecuted
tasks.
For systems where unnamed semaphores are not supported, a really
simple semaphore implementation is provided. (Which gives identical
performance as the original taskprocessor implementation).
The way we ended up implementing Stasis caused the threadpool to be a
burden instead of a boost to performance. This was switched to just
use taskprocessors directly for subscriptions.
Review: https://reviewboard.asterisk.org/r/2881/
........
r400180 | dlee | 2013-09-30 13:39:34 -0500 (Mon, 30 Sep 2013) | 28 lines
Optimize how Stasis forwards are dispatched
This patch optimizes how forwards are dispatched in Stasis.
Originally, forwards were dispatched as subscriptions that are invoked
on the publishing thread. This did not account for the vast number of
forwards we would end up having in the system, and the amount of work it
would take to walk though the forward subscriptions.
This patch modifies Stasis so that rather than walking the tree of
forwards on every dispatch, when forwards and subscriptions are changed,
the subscriber list for every topic in the tree is changed.
This has a couple of benefits. First, this reduces the workload of
dispatching messages. It also reduces contention when dispatching to
different topics that happen to forward to the same aggregation topic
(as happens with all of the channel, bridge and endpoint topics).
Since forwards are no longer subscriptions, the bulk of this patch is
simply changing stasis_subscription objects to stasis_forward objects
(which, admittedly, I should have done in the first place.)
Since this required me to yet again put in a growing array, I finally
abstracted that out into a set of ast_vector macros in
asterisk/vector.h.
Review: https://reviewboard.asterisk.org/r/2883/
........
r400181 | dlee | 2013-09-30 13:48:57 -0500 (Mon, 30 Sep 2013) | 28 lines
Remove dispatch object allocation from Stasis publishing
While looking for areas for performance improvement, I realized that an
unused feature in Stasis was negatively impacting performance.
When a message is sent to a subscriber, a dispatch object is allocated
for the dispatch, containing the topic the message was published to, the
subscriber the message is being sent to, and the message itself.
The topic is actually unused by any subscriber in Asterisk today. And
the subscriber is associated with the taskprocessor the message is being
dispatched to.
First, this patch removes the unused topic parameter from Stasis
subscription callbacks.
Second, this patch introduces the concept of taskprocessor local data,
data that may be set on a taskprocessor and provided along with the data
pointer when a task is pushed using the ast_taskprocessor_push_local()
call. This allows the task to have both data specific to that
taskprocessor, in addition to data specific to that invocation.
With those two changes, the dispatch object can be removed completely,
and the message is simply refcounted and sent directly to the
taskprocessor.
Review: https://reviewboard.asterisk.org/r/2884/
........
Merged revisions 399887,400138,400178,400180-400181 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@400186 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-09-30 18:55:27 +00:00
|
|
|
struct stasis_message *msg)
|
2013-04-25 18:25:31 +00:00
|
|
|
{
|
|
|
|
struct mwi_subscription *mwi_sub = userdata;
|
|
|
|
|
|
|
|
if (stasis_subscription_final_message(sub, msg)) {
|
|
|
|
ao2_ref(mwi_sub, +1);
|
|
|
|
ast_sip_push_task(NULL, serialized_cleanup, mwi_sub);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-24 20:44:07 +00:00
|
|
|
if (ast_mwi_state_type() == stasis_message_type(msg)) {
|
2013-04-25 18:25:31 +00:00
|
|
|
struct ast_taskprocessor *serializer = mwi_sub->is_solicited ? ast_sip_subscription_get_serializer(mwi_sub->sip_sub) : NULL;
|
|
|
|
ao2_ref(mwi_sub, +1);
|
|
|
|
ast_sip_push_task(serializer, serialized_notify, mwi_sub);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int create_mwi_subscriptions_for_endpoint(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct mwi_subscription *, aggregate_sub, NULL, ao2_cleanup);
|
|
|
|
struct ast_sip_endpoint *endpoint = obj;
|
|
|
|
struct ao2_container *mwi_subscriptions = arg;
|
|
|
|
char *mailboxes;
|
|
|
|
char *mailbox;
|
|
|
|
|
2013-07-30 15:17:56 +00:00
|
|
|
if (ast_strlen_zero(endpoint->subscription.mwi.mailboxes)) {
|
2013-04-25 18:25:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-30 15:17:56 +00:00
|
|
|
if (endpoint->subscription.mwi.aggregate) {
|
2014-06-25 20:57:28 +00:00
|
|
|
aggregate_sub = mwi_subscription_alloc(endpoint, 0, NULL);
|
2013-04-25 18:25:31 +00:00
|
|
|
if (!aggregate_sub) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 15:17:56 +00:00
|
|
|
mailboxes = ast_strdupa(endpoint->subscription.mwi.mailboxes);
|
2013-04-25 18:25:31 +00:00
|
|
|
while ((mailbox = strsep(&mailboxes, ","))) {
|
|
|
|
struct mwi_subscription *sub = aggregate_sub ?:
|
2014-06-25 20:57:28 +00:00
|
|
|
mwi_subscription_alloc(endpoint, 0, NULL);
|
2013-04-25 18:25:31 +00:00
|
|
|
RAII_VAR(struct mwi_stasis_subscription *, mwi_stasis_sub,
|
|
|
|
mwi_stasis_subscription_alloc(mailbox, sub), ao2_cleanup);
|
|
|
|
if (mwi_stasis_sub) {
|
|
|
|
ao2_link(sub->stasis_subs, mwi_stasis_sub);
|
|
|
|
}
|
|
|
|
if (!aggregate_sub) {
|
|
|
|
ao2_link(mwi_subscriptions, sub);
|
|
|
|
ao2_cleanup(sub);
|
|
|
|
}
|
|
|
|
}
|
2014-03-06 15:58:13 +00:00
|
|
|
if (aggregate_sub) {
|
|
|
|
ao2_link(mwi_subscriptions, aggregate_sub);
|
|
|
|
}
|
2013-04-25 18:25:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int unsubscribe(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct mwi_subscription *mwi_sub = obj;
|
|
|
|
|
|
|
|
ao2_callback(mwi_sub->stasis_subs, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe_stasis, NULL);
|
|
|
|
return CMP_MATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_mwi_subscriptions(void)
|
|
|
|
{
|
|
|
|
struct ao2_container *mwi_subscriptions = ao2_container_alloc(MWI_BUCKETS, mwi_sub_hash, mwi_sub_cmp);
|
|
|
|
RAII_VAR(struct ao2_container *, old_mwi_subscriptions, ao2_global_obj_ref(unsolicited_mwi), ao2_cleanup);
|
|
|
|
RAII_VAR(struct ao2_container *, endpoints, ast_sorcery_retrieve_by_fields(
|
|
|
|
ast_sip_get_sorcery(), "endpoint", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL),
|
|
|
|
ao2_cleanup);
|
|
|
|
|
|
|
|
if (!mwi_subscriptions) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We remove all the old stasis subscriptions first before applying the new configuration. This
|
|
|
|
* prevents a situation where there might be multiple overlapping stasis subscriptions for an
|
|
|
|
* endpoint for mailboxes. Though there may be mailbox changes during the gap between unsubscribing
|
|
|
|
* and resubscribing, up-to-date mailbox state will be sent out to the endpoint when the
|
|
|
|
* new stasis subscription is established
|
|
|
|
*/
|
|
|
|
if (old_mwi_subscriptions) {
|
|
|
|
ao2_callback(old_mwi_subscriptions, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe, NULL);
|
|
|
|
}
|
|
|
|
ao2_callback(endpoints, OBJ_NODATA, create_mwi_subscriptions_for_endpoint, mwi_subscriptions);
|
|
|
|
ao2_global_obj_replace_unref(unsolicited_mwi, mwi_subscriptions);
|
2013-11-21 17:53:22 +00:00
|
|
|
ao2_ref(mwi_subscriptions, -1);
|
2013-04-25 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int reload(void)
|
|
|
|
{
|
|
|
|
create_mwi_subscriptions();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_module(void)
|
|
|
|
{
|
2014-10-16 16:32:25 +00:00
|
|
|
CHECK_PJSIP_MODULE_LOADED();
|
|
|
|
|
2013-04-25 18:25:31 +00:00
|
|
|
if (ast_sip_register_subscription_handler(&mwi_handler)) {
|
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
|
|
|
}
|
|
|
|
create_mwi_subscriptions();
|
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int unload_module(void)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ao2_container *, mwi_subscriptions, ao2_global_obj_ref(unsolicited_mwi), ao2_cleanup);
|
|
|
|
if (mwi_subscriptions) {
|
|
|
|
ao2_callback(mwi_subscriptions, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe, NULL);
|
|
|
|
ao2_global_obj_release(unsolicited_mwi);
|
|
|
|
}
|
|
|
|
ast_sip_unregister_subscription_handler(&mwi_handler);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-30 18:14:50 +00:00
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP MWI resource",
|
2014-07-25 16:47:17 +00:00
|
|
|
.support_level = AST_MODULE_SUPPORT_CORE,
|
2013-04-25 18:25:31 +00:00
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module,
|
|
|
|
.reload = reload,
|
|
|
|
.load_pri = AST_MODPRI_CHANNEL_DEPEND,
|
|
|
|
);
|