Due to the original patch causing memory corruptions it was removed until the problem could be resolved. This patch is the original patch plus some added locking around stasis router subcription that was needed to avoid the memory corruption. Description of the original problem and patch (still applicable): The res_pjsip module was previously unloadable. With this patch it can now be unloaded. This patch is based off the original patch on the issue (listed below) by Corey Farrell with a few modifications. Namely, removed a few changes not required to make the module unloadable and also fixed a bug that would cause asterisk to crash on unloading. This patch is the first step (should hopefully be followed by another/others at some point) in allowing res_pjsip and the modules that depend on it to be unloadable. At this time, res_pjsip and some of the modules that depend on res_pjsip cannot be unloaded without causing problems of some sort. The goal of this patch is to get res_pjsip and only res_pjsip to be able to unload successfully and/or shutdown without incident (crashes, leaks, etc...). Other dependent modules may still cause problems on unload. Basically made sure, with the patch applied, that res_pjsip (with no other dependent modules loaded) could be succesfully unloaded and Asterisk could shutdown without any leaks or crashes that pertained directly to res_pjsip. ASTERISK-24485 #close Reported by: Corey Farrell Review: https://reviewboard.asterisk.org/r/4363/ patches: pjsip_unload-broken-r1.patch submitted by Corey Farrell (license 5909) ........ Merged revisions 431179 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@431180 65c4cc65-6c06-0410-ace0-fbb531ad65f3
102 lines
2.6 KiB
C
102 lines
2.6 KiB
C
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include "asterisk.h"
|
|
#undef bzero
|
|
#define bzero bzero
|
|
#include "pjsip.h"
|
|
|
|
#include "asterisk/res_pjsip.h"
|
|
#include "asterisk/module.h"
|
|
#include "include/res_pjsip_private.h"
|
|
|
|
static pj_bool_t outbound_auth(pjsip_rx_data *rdata);
|
|
|
|
static pjsip_module outbound_auth_mod = {
|
|
.name = {"Outbound Authentication", 19},
|
|
.priority = PJSIP_MOD_PRIORITY_DIALOG_USAGE,
|
|
.on_rx_response = outbound_auth,
|
|
};
|
|
|
|
struct outbound_auth_cb_data {
|
|
ast_sip_dialog_outbound_auth_cb cb;
|
|
void *user_data;
|
|
};
|
|
|
|
static pj_bool_t outbound_auth(pjsip_rx_data *rdata)
|
|
{
|
|
RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
|
|
pjsip_transaction *tsx;
|
|
pjsip_dialog *dlg;
|
|
struct outbound_auth_cb_data *cb_data;
|
|
pjsip_tx_data *tdata;
|
|
|
|
if (rdata->msg_info.msg->line.status.code != 401 &&
|
|
rdata->msg_info.msg->line.status.code != 407) {
|
|
/* Doesn't pertain to us. Move on */
|
|
return PJ_FALSE;
|
|
}
|
|
|
|
tsx = pjsip_rdata_get_tsx(rdata);
|
|
dlg = pjsip_rdata_get_dlg(rdata);
|
|
if (!dlg || !tsx) {
|
|
return PJ_FALSE;
|
|
}
|
|
|
|
endpoint = ast_sip_dialog_get_endpoint(dlg);
|
|
if (!endpoint) {
|
|
return PJ_FALSE;
|
|
}
|
|
|
|
if (ast_sip_create_request_with_auth(&endpoint->outbound_auths, rdata, tsx, &tdata)) {
|
|
return PJ_FALSE;
|
|
}
|
|
|
|
cb_data = dlg->mod_data[outbound_auth_mod.id];
|
|
if (cb_data) {
|
|
cb_data->cb(dlg, tdata, cb_data->user_data);
|
|
return PJ_TRUE;
|
|
}
|
|
|
|
pjsip_dlg_send_request(dlg, tdata, -1, NULL);
|
|
return PJ_TRUE;
|
|
}
|
|
|
|
int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, const struct ast_sip_endpoint *endpoint,
|
|
ast_sip_dialog_outbound_auth_cb cb, void *user_data)
|
|
{
|
|
struct outbound_auth_cb_data *cb_data = PJ_POOL_ZALLOC_T(dlg->pool, struct outbound_auth_cb_data);
|
|
cb_data->cb = cb;
|
|
cb_data->user_data = user_data;
|
|
|
|
dlg->sess_count++;
|
|
pjsip_dlg_add_usage(dlg, &outbound_auth_mod, cb_data);
|
|
dlg->sess_count--;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int internal_sip_initialize_outbound_authentication(void) {
|
|
return internal_sip_register_service(&outbound_auth_mod);
|
|
}
|
|
|
|
|
|
void internal_sip_destroy_outbound_authentication(void) {
|
|
internal_sip_unregister_service(&outbound_auth_mod);
|
|
}
|