diff options
Diffstat (limited to 'res')
-rw-r--r-- | res/res_pjproject.c | 2 | ||||
-rw-r--r-- | res/res_pjsip.c | 65 | ||||
-rw-r--r-- | res/res_pjsip.exports.in | 1 | ||||
-rw-r--r-- | res/res_pjsip/include/res_pjsip_private.h | 26 | ||||
-rw-r--r-- | res/res_pjsip/pjsip_configuration.c | 18 | ||||
-rw-r--r-- | res/res_pjsip/pjsip_message_filter.c | 24 | ||||
-rw-r--r-- | res/res_pjsip/pjsip_session.c | 123 | ||||
-rw-r--r-- | res/res_pjsip_session.c | 71 | ||||
-rw-r--r-- | res/res_pjsip_session.exports.in | 1 |
9 files changed, 206 insertions, 125 deletions
diff --git a/res/res_pjproject.c b/res/res_pjproject.c index 1d9d73eaa..46c82aa9e 100644 --- a/res/res_pjproject.c +++ b/res/res_pjproject.c @@ -544,7 +544,7 @@ static int unload_module(void) pj_log_set_log_func(log_cb_orig); pj_log_set_decor(decor_orig); - AST_VECTOR_REMOVE_CMP_UNORDERED(&buildopts, NULL, NOT_EQUALS, ast_free); + AST_VECTOR_CALLBACK_VOID(&buildopts, ast_free); AST_VECTOR_FREE(&buildopts); ast_debug(3, "Stopped PJPROJECT logging to Asterisk logger\n"); diff --git a/res/res_pjsip.c b/res/res_pjsip.c index cbeb5ea3d..a784e1262 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -2448,25 +2448,20 @@ static int register_service_noref(void *data) return 0; } -static int register_service(void *data) -{ - int res; - - if (!(res = register_service_noref(data))) { - ast_module_ref(ast_module_info->self); - } - - return res; -} - int internal_sip_register_service(pjsip_module *module) { return ast_sip_push_task_synchronous(NULL, register_service_noref, &module); } -int ast_sip_register_service(pjsip_module *module) +int __ast_sip_register_service(pjsip_module *module, const char *file, int line, const char *func) { - return ast_sip_push_task_synchronous(NULL, register_service, &module); + int res; + + if (!(res = ast_sip_push_task_synchronous(NULL, register_service_noref, &module))) { + __ast_module_ref(ast_module_info->self, file, line, func); + } + + return res; } static int unregister_service_noref(void *data) @@ -2480,25 +2475,16 @@ static int unregister_service_noref(void *data) return 0; } -static int unregister_service(void *data) -{ - int res; - - if (!(res = unregister_service_noref(data))) { - ast_module_unref(ast_module_info->self); - } - - return res; -} - int internal_sip_unregister_service(pjsip_module *module) { return ast_sip_push_task_synchronous(NULL, unregister_service_noref, &module); } -void ast_sip_unregister_service(pjsip_module *module) +void __ast_sip_unregister_service(pjsip_module *module, const char *file, int line, const char *func) { - ast_sip_push_task_synchronous(NULL, unregister_service, &module); + if (!ast_sip_push_task_synchronous(NULL, unregister_service_noref, &module)) { + __ast_module_unref(ast_module_info->self, file, line, func); + } } static struct ast_sip_authenticator *registered_authenticator; @@ -3542,7 +3528,7 @@ int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg, AST_RWLIST_HEAD_STATIC(supplements, ast_sip_supplement); -int ast_sip_register_supplement(struct ast_sip_supplement *supplement) +void internal_sip_register_supplement(struct ast_sip_supplement *supplement) { struct ast_sip_supplement *iter; int inserted = 0; @@ -3560,22 +3546,41 @@ int ast_sip_register_supplement(struct ast_sip_supplement *supplement) if (!inserted) { AST_RWLIST_INSERT_TAIL(&supplements, supplement, next); } - ast_module_ref(ast_module_info->self); +} + +int __ast_sip_register_supplement(struct ast_sip_supplement *supplement, + const char *file, int line, const char *func) +{ + internal_sip_register_supplement(supplement); + __ast_module_ref(ast_module_info->self, file, line, func); + return 0; } -void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement) +int internal_sip_unregister_supplement(struct ast_sip_supplement *supplement) { struct ast_sip_supplement *iter; SCOPED_LOCK(lock, &supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK); + int res = -1; + AST_RWLIST_TRAVERSE_SAFE_BEGIN(&supplements, iter, next) { if (supplement == iter) { AST_RWLIST_REMOVE_CURRENT(next); - ast_module_unref(ast_module_info->self); + res = 0; break; } } AST_RWLIST_TRAVERSE_SAFE_END; + + return res; +} + +void __ast_sip_unregister_supplement(struct ast_sip_supplement *supplement, + const char *file, int line, const char *func) +{ + if (!internal_sip_unregister_supplement(supplement)) { + __ast_module_unref(ast_module_info->self, file, line, func); + } } static int send_in_dialog_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg) diff --git a/res/res_pjsip.exports.in b/res/res_pjsip.exports.in index 4adecd419..7ac2b7e83 100644 --- a/res/res_pjsip.exports.in +++ b/res/res_pjsip.exports.in @@ -1,6 +1,7 @@ { global: LINKER_SYMBOL_PREFIXast_sip_*; + LINKER_SYMBOL_PREFIX__ast_sip_*; LINKER_SYMBOL_PREFIXast_copy_pj_str; LINKER_SYMBOL_PREFIXast_copy_pj_str2; LINKER_SYMBOL_PREFIXast_pjsip_rdata_get_endpoint; diff --git a/res/res_pjsip/include/res_pjsip_private.h b/res/res_pjsip/include/res_pjsip_private.h index 9fd7aed97..5ce3c6faf 100644 --- a/res/res_pjsip/include/res_pjsip_private.h +++ b/res/res_pjsip/include/res_pjsip_private.h @@ -328,6 +328,18 @@ int internal_sip_unregister_service(pjsip_module *module); /*! * \internal + * \brief Used by res_pjsip.so to register a supplement without adding a self reference + */ +void internal_sip_register_supplement(struct ast_sip_supplement *supplement); + +/*! + * \internal + * \brief Used by res_pjsip.so to unregister a supplement without removing a self reference + */ +int internal_sip_unregister_supplement(struct ast_sip_supplement *supplement); + +/*! + * \internal * \brief Used by res_pjsip.so to register an endpoint formatter without adding a self reference */ void internal_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj); @@ -338,6 +350,20 @@ void internal_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter */ int internal_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj); +struct ast_sip_session_supplement; + +/*! + * \internal + * \brief Used by res_pjsip.so to register a session supplement without adding a self reference + */ +void internal_sip_session_register_supplement(struct ast_sip_session_supplement *supplement); + +/*! + * \internal + * \brief Used by res_pjsip.so to unregister a session supplement without removing a self reference + */ +int internal_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement); + /*! * \internal * \brief Finds or creates contact_status for a contact diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index 3a752c90d..653cb98ac 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -1315,6 +1315,14 @@ static struct ast_endpoint *persistent_endpoint_find_or_create(const struct ast_ ast_endpoint_set_state(persistent->endpoint, AST_ENDPOINT_OFFLINE); ao2_link_flags(persistent_endpoints, persistent, OBJ_NOLOCK); + } else if (strcmp(persistent->aors, endpoint->aors)) { + char *new_aors = ast_strdup(endpoint->aors); + + /* make sure we don't NULL persistent->aors if allocation fails. */ + if (new_aors) { + ast_free(persistent->aors); + persistent->aors = new_aors; + } } ao2_ref(persistent->endpoint, +1); @@ -1821,20 +1829,12 @@ static struct ast_cli_entry cli_commands[] = { struct ast_sip_cli_formatter_entry *channel_formatter; struct ast_sip_cli_formatter_entry *endpoint_formatter; -static int on_load_endpoint(void *obj, void *arg, int flags) -{ - return sip_endpoint_apply_handler(sip_sorcery, obj); -} - static void load_all_endpoints(void) { struct ao2_container *endpoints; endpoints = ast_sorcery_retrieve_by_fields(sip_sorcery, "endpoint", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL); - if (endpoints) { - ao2_callback(endpoints, OBJ_NODATA, on_load_endpoint, NULL); - ao2_ref(endpoints, -1); - } + ao2_cleanup(endpoints); } int ast_res_pjsip_initialize_configuration(void) diff --git a/res/res_pjsip/pjsip_message_filter.c b/res/res_pjsip/pjsip_message_filter.c index d2f9b9562..978aeb070 100644 --- a/res/res_pjsip/pjsip_message_filter.c +++ b/res/res_pjsip/pjsip_message_filter.c @@ -505,32 +505,24 @@ static pj_bool_t filter_on_rx_message(pjsip_rx_data *rdata) void ast_res_pjsip_cleanup_message_filter(void) { - ast_sip_unregister_service(&filter_module_tsx); - ast_sip_unregister_service(&filter_module_transport); - ast_sip_unregister_supplement(&filter_supplement); - ast_sip_session_unregister_supplement(&filter_session_supplement); + internal_sip_unregister_service(&filter_module_tsx); + internal_sip_unregister_service(&filter_module_transport); + internal_sip_unregister_supplement(&filter_supplement); + internal_sip_session_unregister_supplement(&filter_session_supplement); } int ast_res_pjsip_init_message_filter(void) { - if (ast_sip_session_register_supplement(&filter_session_supplement)) { - ast_log(LOG_ERROR, "Could not register message filter session supplement for outgoing requests\n"); - return -1; - } - - if (ast_sip_register_supplement(&filter_supplement)) { - ast_log(LOG_ERROR, "Could not register message filter supplement for outgoing requests\n"); - ast_res_pjsip_cleanup_message_filter(); - return -1; - } + internal_sip_session_register_supplement(&filter_session_supplement); + internal_sip_register_supplement(&filter_supplement); - if (ast_sip_register_service(&filter_module_transport)) { + if (internal_sip_register_service(&filter_module_transport)) { ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n"); ast_res_pjsip_cleanup_message_filter(); return -1; } - if (ast_sip_register_service(&filter_module_tsx)) { + if (internal_sip_register_service(&filter_module_tsx)) { ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n"); ast_res_pjsip_cleanup_message_filter(); return -1; diff --git a/res/res_pjsip/pjsip_session.c b/res/res_pjsip/pjsip_session.c new file mode 100644 index 000000000..4f3e3be55 --- /dev/null +++ b/res/res_pjsip/pjsip_session.c @@ -0,0 +1,123 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2017, CFWare, LLC + * + * Corey Farrell <git@cfware.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. + */ + +#include "asterisk.h" + +#include <pjsip.h> +#include <pjsip_ua.h> +#include <pjlib.h> + +#include "asterisk/res_pjsip.h" +#include "asterisk/res_pjsip_session.h" +#include "include/res_pjsip_private.h" +#include "asterisk/linkedlists.h" +#include "asterisk/lock.h" +#include "asterisk/module.h" + + +AST_RWLIST_HEAD_STATIC(session_supplements, ast_sip_session_supplement); + +void internal_sip_session_register_supplement(struct ast_sip_session_supplement *supplement) +{ + struct ast_sip_session_supplement *iter; + int inserted = 0; + SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK); + + if (!supplement->response_priority) { + supplement->response_priority = AST_SIP_SESSION_BEFORE_MEDIA; + } + + AST_RWLIST_TRAVERSE_SAFE_BEGIN(&session_supplements, iter, next) { + if (iter->priority > supplement->priority) { + AST_RWLIST_INSERT_BEFORE_CURRENT(supplement, next); + inserted = 1; + break; + } + } + AST_RWLIST_TRAVERSE_SAFE_END; + + if (!inserted) { + AST_RWLIST_INSERT_TAIL(&session_supplements, supplement, next); + } +} + +int __ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement, + const char *file, int line, const char *func) +{ + internal_sip_session_register_supplement(supplement); + __ast_module_ref(AST_MODULE_SELF, file, line, func); + + return 0; +} + +int internal_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement) +{ + struct ast_sip_session_supplement *iter; + int res = -1; + SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK); + + AST_RWLIST_TRAVERSE_SAFE_BEGIN(&session_supplements, iter, next) { + if (supplement == iter) { + AST_RWLIST_REMOVE_CURRENT(next); + res = 0; + break; + } + } + AST_RWLIST_TRAVERSE_SAFE_END; + + return res; +} + +void __ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement, + const char *file, int line, const char *func) +{ + if (!internal_sip_session_unregister_supplement(supplement)) { + __ast_module_unref(AST_MODULE_SELF, file, line, func); + } +} + +static struct ast_sip_session_supplement *supplement_dup(const struct ast_sip_session_supplement *src) +{ + struct ast_sip_session_supplement *dst = ast_calloc(1, sizeof(*dst)); + + if (!dst) { + return NULL; + } + /* Will need to revisit if shallow copy becomes an issue */ + *dst = *src; + + return dst; +} + +int ast_sip_session_add_supplements(struct ast_sip_session *session) +{ + struct ast_sip_session_supplement *iter; + SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK); + + AST_RWLIST_TRAVERSE(&session_supplements, iter, next) { + struct ast_sip_session_supplement *copy = supplement_dup(iter); + + if (!copy) { + return -1; + } + AST_LIST_INSERT_TAIL(&session->supplements, copy, next); + } + + return 0; +} + diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index 70c88a504..49f2f17c2 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -907,59 +907,6 @@ static int handle_negotiated_sdp(struct ast_sip_session *session, const pjmedia_ return 0; } -AST_RWLIST_HEAD_STATIC(session_supplements, ast_sip_session_supplement); - -int ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement) -{ - struct ast_sip_session_supplement *iter; - int inserted = 0; - SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK); - - if (!supplement->response_priority) { - supplement->response_priority = AST_SIP_SESSION_BEFORE_MEDIA; - } - - AST_RWLIST_TRAVERSE_SAFE_BEGIN(&session_supplements, iter, next) { - if (iter->priority > supplement->priority) { - AST_RWLIST_INSERT_BEFORE_CURRENT(supplement, next); - inserted = 1; - break; - } - } - AST_RWLIST_TRAVERSE_SAFE_END; - - if (!inserted) { - AST_RWLIST_INSERT_TAIL(&session_supplements, supplement, next); - } - ast_module_ref(ast_module_info->self); - return 0; -} - -void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement) -{ - struct ast_sip_session_supplement *iter; - SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK); - AST_RWLIST_TRAVERSE_SAFE_BEGIN(&session_supplements, iter, next) { - if (supplement == iter) { - AST_RWLIST_REMOVE_CURRENT(next); - ast_module_unref(ast_module_info->self); - break; - } - } - AST_RWLIST_TRAVERSE_SAFE_END; -} - -static struct ast_sip_session_supplement *supplement_dup(const struct ast_sip_session_supplement *src) -{ - struct ast_sip_session_supplement *dst = ast_calloc(1, sizeof(*dst)); - if (!dst) { - return NULL; - } - /* Will need to revisit if shallow copy becomes an issue */ - *dst = *src; - return dst; -} - #define DATASTORE_BUCKETS 53 #define MEDIA_BUCKETS 7 @@ -1547,6 +1494,7 @@ int ast_sip_session_refresh(struct ast_sip_session *session, } } ast_stream_set_formats(stream, joint_cap); + ao2_cleanup(joint_cap); } ++type_streams[ast_stream_get_type(stream)]; @@ -2045,21 +1993,6 @@ static void session_destructor(void *obj) ast_test_suite_event_notify("SESSION_DESTROYED", "Endpoint: %s", endpoint_name); } -static int add_supplements(struct ast_sip_session *session) -{ - struct ast_sip_session_supplement *iter; - SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK); - - AST_RWLIST_TRAVERSE(&session_supplements, iter, next) { - struct ast_sip_session_supplement *copy = supplement_dup(iter); - if (!copy) { - return -1; - } - AST_LIST_INSERT_TAIL(&session->supplements, copy, next); - } - return 0; -} - /*! \brief Destructor for SIP channel */ static void sip_channel_destroy(void *obj) { @@ -2166,7 +2099,7 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint, session->dtmf = endpoint->dtmf; - if (add_supplements(session)) { + if (ast_sip_session_add_supplements(session)) { /* Release the ref held by session->inv_session */ ao2_ref(session, -1); return NULL; diff --git a/res/res_pjsip_session.exports.in b/res/res_pjsip_session.exports.in index b7bd21b89..d65b247c7 100644 --- a/res/res_pjsip_session.exports.in +++ b/res/res_pjsip_session.exports.in @@ -1,6 +1,7 @@ { global: LINKER_SYMBOL_PREFIXast_sip_session_*; + LINKER_SYMBOL_PREFIX__ast_sip_session_*; LINKER_SYMBOL_PREFIXast_sip_dialog_get_session; LINKER_SYMBOL_PREFIXast_sip_channel_pvt_alloc; local: |