summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
Diffstat (limited to 'res')
-rw-r--r--res/res_pjsip/location.c8
-rw-r--r--res/res_pjsip/pjsip_configuration.c40
-rw-r--r--res/res_pjsip/pjsip_distributor.c3
-rw-r--r--res/res_pjsip_mwi.c30
-rw-r--r--res/res_pjsip_registrar.c4
-rw-r--r--res/res_pjsip_registrar_expire.c4
6 files changed, 55 insertions, 34 deletions
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index 67ea204af..d8f0c58b5 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -213,12 +213,12 @@ struct ao2_container *ast_sip_location_retrieve_aor_contacts(const struct ast_si
struct ao2_container *contacts;
struct ast_named_lock *lock;
- lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_RWLOCK, "aor", ast_sorcery_object_get_id(aor));
+ lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_MUTEX, "aor", ast_sorcery_object_get_id(aor));
if (!lock) {
return NULL;
}
- ao2_wrlock(lock);
+ ao2_lock(lock);
contacts = ast_sip_location_retrieve_aor_contacts_nolock(aor);
ao2_unlock(lock);
ast_named_lock_put(lock);
@@ -376,12 +376,12 @@ int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri,
int res;
struct ast_named_lock *lock;
- lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_RWLOCK, "aor", ast_sorcery_object_get_id(aor));
+ lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_MUTEX, "aor", ast_sorcery_object_get_id(aor));
if (!lock) {
return -1;
}
- ao2_wrlock(lock);
+ ao2_lock(lock);
res = ast_sip_location_add_contact_nolock(aor, uri, expiration_time, path_info, user_agent,
via_addr, via_port, call_id,
endpoint);
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index 48d011067..9e757e230 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -169,7 +169,6 @@ static int persistent_endpoint_update_state(void *obj, void *arg, int flags)
contact_status = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(),
CONTACT_STATUS, contact_id);
-
if (contact_status && contact_status->status != UNAVAILABLE) {
state = AST_ENDPOINT_ONLINE;
}
@@ -299,7 +298,8 @@ static void endpoint_deleted_observer(const void *object)
{
const struct ast_sip_endpoint *endpoint = object;
- ao2_find(persistent_endpoints, ast_endpoint_get_resource(endpoint->persistent), OBJ_SEARCH_KEY | OBJ_UNLINK | OBJ_NODATA);
+ ao2_find(persistent_endpoints, ast_endpoint_get_resource(endpoint->persistent),
+ OBJ_SEARCH_KEY | OBJ_UNLINK | OBJ_NODATA);
}
static const struct ast_sorcery_observer endpoint_observers = {
@@ -1227,16 +1227,16 @@ static void persistent_endpoint_destroy(void *obj)
int ast_sip_persistent_endpoint_update_state(const char *endpoint_name, enum ast_endpoint_state state)
{
- RAII_VAR(struct sip_persistent_endpoint *, persistent, NULL, ao2_cleanup);
- SCOPED_AO2LOCK(lock, persistent_endpoints);
+ struct sip_persistent_endpoint *persistent;
- if (!(persistent = ao2_find(persistent_endpoints, endpoint_name, OBJ_KEY | OBJ_NOLOCK))) {
- return -1;
+ ao2_lock(persistent_endpoints);
+ persistent = ao2_find(persistent_endpoints, endpoint_name, OBJ_SEARCH_KEY | OBJ_NOLOCK);
+ if (persistent) {
+ endpoint_update_state(persistent->endpoint, state);
+ ao2_ref(persistent, -1);
}
-
- endpoint_update_state(persistent->endpoint, state);
-
- return 0;
+ ao2_unlock(persistent_endpoints);
+ return persistent ? 0 : -1;
}
/*! \brief Internal function which finds (or creates) persistent endpoint information */
@@ -1245,16 +1245,25 @@ static struct ast_endpoint *persistent_endpoint_find_or_create(const struct ast_
RAII_VAR(struct sip_persistent_endpoint *, persistent, NULL, ao2_cleanup);
SCOPED_AO2LOCK(lock, persistent_endpoints);
- if (!(persistent = ao2_find(persistent_endpoints, ast_sorcery_object_get_id(endpoint), OBJ_KEY | OBJ_NOLOCK))) {
- if (!(persistent = ao2_alloc(sizeof(*persistent), persistent_endpoint_destroy))) {
+ persistent = ao2_find(persistent_endpoints, ast_sorcery_object_get_id(endpoint),
+ OBJ_SEARCH_KEY | OBJ_NOLOCK);
+ if (!persistent) {
+ persistent = ao2_alloc_options(sizeof(*persistent), persistent_endpoint_destroy,
+ AO2_ALLOC_OPT_LOCK_NOLOCK);
+ if (!persistent) {
return NULL;
}
- if (!(persistent->endpoint = ast_endpoint_create("PJSIP", ast_sorcery_object_get_id(endpoint)))) {
+ persistent->endpoint = ast_endpoint_create("PJSIP",
+ ast_sorcery_object_get_id(endpoint));
+ if (!persistent->endpoint) {
return NULL;
}
persistent->aors = ast_strdup(endpoint->aors);
+ if (!persistent->aors) {
+ return NULL;
+ }
ast_endpoint_set_state(persistent->endpoint, AST_ENDPOINT_UNKNOWN);
@@ -1760,7 +1769,9 @@ int ast_res_pjsip_initialize_configuration(const struct ast_module_info *ast_mod
return -1;
}
- if (!(persistent_endpoints = ao2_container_alloc(PERSISTENT_BUCKETS, persistent_endpoint_hash, persistent_endpoint_cmp))) {
+ persistent_endpoints = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+ PERSISTENT_BUCKETS, persistent_endpoint_hash, NULL, persistent_endpoint_cmp);
+ if (!persistent_endpoints) {
return -1;
}
@@ -1981,6 +1992,7 @@ void ast_res_pjsip_destroy_configuration(void)
ast_sip_unregister_cli_formatter(endpoint_formatter);
ast_sip_destroy_cli();
ao2_cleanup(persistent_endpoints);
+ persistent_endpoints = NULL;
}
int ast_res_pjsip_reload_configuration(void)
diff --git a/res/res_pjsip/pjsip_distributor.c b/res/res_pjsip/pjsip_distributor.c
index e8ed89361..8a9119639 100644
--- a/res/res_pjsip/pjsip_distributor.c
+++ b/res/res_pjsip/pjsip_distributor.c
@@ -965,7 +965,7 @@ static int clean_task(const void *data)
static void global_loaded(const char *object_type)
{
char *identifier_order = ast_sip_get_endpoint_identifier_order();
- char *io_copy = ast_strdupa(identifier_order);
+ char *io_copy = identifier_order ? ast_strdupa(identifier_order) : NULL;
char *identify_method;
ast_free(identifier_order);
@@ -982,6 +982,7 @@ static void global_loaded(const char *object_type)
/* Clean out the old task, if any */
ast_sched_clean_by_callback(prune_context, prune_task, clean_task);
+ /* Have to do something with the return value to shut up the stupid compiler. */
if (ast_sched_add_variable(prune_context, unidentified_prune_interval * 1000, prune_task, NULL, 1) < 0) {
return;
}
diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c
index 9553cd732..fb6e6b8f6 100644
--- a/res/res_pjsip_mwi.c
+++ b/res/res_pjsip_mwi.c
@@ -748,7 +748,6 @@ static int endpoint_receives_unsolicited_mwi_for_mailbox(struct ast_sip_endpoint
int ret = 0;
mwi_subs = ao2_find(unsolicited_mwi, endpoint_id, OBJ_SEARCH_KEY | OBJ_MULTIPLE);
-
if (!mwi_subs) {
return 0;
}
@@ -1089,7 +1088,7 @@ static void mwi_stasis_cb(void *userdata, struct stasis_subscription *sub,
}
}
-/*! \note Called with the unsolicited_mwi conainer lock held. */
+/*! \note Called with the unsolicited_mwi container lock held. */
static int create_mwi_subscriptions_for_endpoint(void *obj, void *arg, int flags)
{
RAII_VAR(struct mwi_subscription *, aggregate_sub, NULL, ao2_cleanup);
@@ -1212,7 +1211,8 @@ static void mwi_contact_added(const void *object)
ao2_lock(unsolicited_mwi);
- mwi_subs = ao2_find(unsolicited_mwi, endpoint_id, OBJ_SEARCH_KEY | OBJ_MULTIPLE | OBJ_NOLOCK | OBJ_UNLINK);
+ mwi_subs = ao2_find(unsolicited_mwi, endpoint_id,
+ OBJ_SEARCH_KEY | OBJ_MULTIPLE | OBJ_NOLOCK | OBJ_UNLINK);
if (mwi_subs) {
for (; (mwi_sub = ao2_iterator_next(mwi_subs)); ao2_cleanup(mwi_sub)) {
unsubscribe(mwi_sub, NULL, 0);
@@ -1288,17 +1288,19 @@ static int load_module(void)
return AST_MODULE_LOAD_DECLINE;
}
- unsolicited_mwi = ao2_container_alloc(MWI_BUCKETS, mwi_sub_hash, mwi_sub_cmp);
- if (!unsolicited_mwi) {
- ast_sip_unregister_subscription_handler(&mwi_handler);
- return AST_MODULE_LOAD_DECLINE;
- }
-
if (mwi_serializer_pool_setup()) {
ast_log(AST_LOG_WARNING, "Failed to create MWI serializer pool. The default SIP pool will be used for MWI\n");
}
+ unsolicited_mwi = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MWI_BUCKETS,
+ mwi_sub_hash, NULL, mwi_sub_cmp);
+ if (!unsolicited_mwi) {
+ mwi_serializer_pool_shutdown();
+ ast_sip_unregister_subscription_handler(&mwi_handler);
+ return AST_MODULE_LOAD_DECLINE;
+ }
create_mwi_subscriptions();
+
ast_sorcery_observer_add(ast_sip_get_sorcery(), "contact", &mwi_contact_observer);
ast_sorcery_observer_add(ast_sip_get_sorcery(), "global", &global_observer);
ast_sorcery_reload_object(ast_sip_get_sorcery(), "global");
@@ -1316,13 +1318,19 @@ static int load_module(void)
static int unload_module(void)
{
+ ast_sorcery_observer_remove(ast_sip_get_sorcery(), "global", &global_observer);
+ ast_sorcery_observer_remove(ast_sip_get_sorcery(), "contact", &mwi_contact_observer);
+
ao2_callback(unsolicited_mwi, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe, NULL);
ao2_ref(unsolicited_mwi, -1);
+ unsolicited_mwi = NULL;
+
mwi_serializer_pool_shutdown();
- ast_sorcery_observer_remove(ast_sip_get_sorcery(), "global", &global_observer);
- ast_sorcery_observer_remove(ast_sip_get_sorcery(), "contact", &mwi_contact_observer);
+
ast_sip_unregister_subscription_handler(&mwi_handler);
+
ast_free(default_voicemail_extension);
+ default_voicemail_extension = NULL;
return 0;
}
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index aef0e164b..53209575f 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -525,12 +525,12 @@ static int register_aor(pjsip_rx_data *rdata,
struct ao2_container *contacts = NULL;
struct ast_named_lock *lock;
- lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_RWLOCK, "aor", aor_name);
+ lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_MUTEX, "aor", aor_name);
if (!lock) {
return PJ_TRUE;
}
- ao2_wrlock(lock);
+ ao2_lock(lock);
contacts = ast_sip_location_retrieve_aor_contacts_nolock(aor);
if (!contacts) {
ao2_unlock(lock);
diff --git a/res/res_pjsip_registrar_expire.c b/res/res_pjsip_registrar_expire.c
index 0fddbda91..aeefc3fbc 100644
--- a/res/res_pjsip_registrar_expire.c
+++ b/res/res_pjsip_registrar_expire.c
@@ -44,7 +44,7 @@ static int expire_contact(void *obj, void *arg, int flags)
struct ast_sip_contact *contact = obj;
struct ast_named_lock *lock;
- lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_RWLOCK, "aor", contact->aor);
+ lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_MUTEX, "aor", contact->aor);
if (!lock) {
return 0;
}
@@ -53,7 +53,7 @@ static int expire_contact(void *obj, void *arg, int flags)
* We need to check the expiration again with the aor lock held
* in case another thread is attempting to renew the contact.
*/
- ao2_wrlock(lock);
+ ao2_lock(lock);
if (ast_tvdiff_ms(ast_tvnow(), contact->expiration_time) > 0) {
ast_sip_location_delete_contact(contact);
}