PJSIP: Enforce module load dependencies

This enforces that res_pjsip, res_pjsip_session, and res_pjsip_pubsub
have loaded properly before attempting to load any modules that depend
on them since the module loader system is not currently capable of
resolving module dependencies on its own.

ASTERISK-24312 #close
Reported by: Dafi Ni
Review: https://reviewboard.asterisk.org/r/4062/
........

Merged revisions 425690 from http://svn.asterisk.org/svn/asterisk/branches/12
........

Merged revisions 425691 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@425700 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/42/42/1
Kinsey Moore 11 years ago
parent a770ca168d
commit 86a4ce4957

@ -2214,6 +2214,8 @@ static int load_module(void)
{
struct ao2_container *endpoints;
CHECK_PJSIP_SESSION_MODULE_LOADED();
if (!(chan_pjsip_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
return AST_MODULE_LOAD_DECLINE;
}

@ -1944,4 +1944,13 @@ void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement);
*/
char *ast_sip_get_debug(void);
/*! \brief Determines whether the res_pjsip module is loaded */
#define CHECK_PJSIP_MODULE_LOADED() \
do { \
if (!ast_module_check("res_pjsip.so") \
|| !ast_sip_get_pjsip_endpoint()) { \
return AST_MODULE_LOAD_DECLINE; \
} \
} while(0)
#endif /* _RES_PJSIP_H */

@ -674,4 +674,13 @@ const char *ast_sip_subscription_get_body_type(struct ast_sip_subscription *sub)
*/
const char *ast_sip_subscription_get_body_subtype(struct ast_sip_subscription *sub);
/*! \brief Determines whether the res_pjsip_pubsub module is loaded */
#define CHECK_PJSIP_PUBSUB_MODULE_LOADED() \
do { \
CHECK_PJSIP_MODULE_LOADED(); \
if (!ast_module_check("res_pjsip_pubsub.so")) { \
return AST_MODULE_LOAD_DECLINE; \
} \
} while(0)
#endif /* RES_PJSIP_PUBSUB_H */

@ -636,4 +636,13 @@ struct ast_sip_session *ast_sip_dialog_get_session(pjsip_dialog *dlg);
*/
void ast_sip_session_resume_reinvite(struct ast_sip_session *session);
/*! \brief Determines whether the res_pjsip_session module is loaded */
#define CHECK_PJSIP_SESSION_MODULE_LOADED() \
do { \
CHECK_PJSIP_MODULE_LOADED(); \
if (!ast_module_check("res_pjsip_session.so")) { \
return AST_MODULE_LOAD_DECLINE; \
} \
} while(0)
#endif /* _RES_PJSIP_SESSION_H */

@ -159,6 +159,8 @@ static pjsip_module logging_module = {
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
ast_sip_register_service(&logging_module);
return AST_MODULE_LOAD_SUCCESS;
}

@ -266,6 +266,8 @@ static void *acl_alloc(const char *name)
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
ast_sorcery_apply_default(ast_sip_get_sorcery(), SIP_SORCERY_ACL_TYPE,
"config", "pjsip.conf,criteria=type=acl");

@ -466,6 +466,8 @@ static int reload_module(void)
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
if (build_entity_id()) {
return AST_MODULE_LOAD_DECLINE;
}

@ -730,6 +730,8 @@ static struct ast_sip_session_supplement caller_id_supplement = {
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
ast_sip_session_register_supplement(&caller_id_supplement);
return AST_MODULE_LOAD_SUCCESS;
}

@ -191,6 +191,8 @@ static struct ast_sip_pubsub_body_generator dialog_info_body_generator = {
static int load_module(void)
{
CHECK_PJSIP_PUBSUB_MODULE_LOADED();
if (ast_sip_pubsub_register_body_generator(&dialog_info_body_generator)) {
return AST_MODULE_LOAD_DECLINE;
}

@ -330,6 +330,8 @@ static struct ast_sip_session_supplement diversion_supplement = {
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
ast_sip_session_register_supplement(&diversion_supplement);
return AST_MODULE_LOAD_SUCCESS;
}

@ -150,6 +150,8 @@ static struct ast_sip_session_supplement dtmf_info_supplement = {
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
ast_sip_session_register_supplement(&dtmf_info_supplement);
return AST_MODULE_LOAD_SUCCESS;
}

@ -108,6 +108,8 @@ static struct ast_sip_endpoint_identifier anonymous_identifier = {
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
ast_sip_register_endpoint_identifier(&anonymous_identifier);
return AST_MODULE_LOAD_SUCCESS;
}

@ -410,6 +410,8 @@ static struct ast_sip_cli_formatter_entry *cli_formatter;
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
ast_sorcery_apply_config(ast_sip_get_sorcery(), "res_pjsip_endpoint_identifier_ip");
ast_sorcery_apply_default(ast_sip_get_sorcery(), "identify", "config", "pjsip.conf,criteria=type=identify");

@ -114,6 +114,8 @@ static struct ast_sip_endpoint_identifier username_identifier = {
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
ast_sip_register_endpoint_identifier(&username_identifier);
return AST_MODULE_LOAD_SUCCESS;
}

@ -465,6 +465,8 @@ static void to_ami(struct ast_sip_subscription *sub,
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
if (ast_sip_register_subscription_handler(&presence_handler)) {
ast_log(LOG_WARNING, "Unable to register subscription handler %s\n",
presence_handler.event_name);

@ -604,6 +604,8 @@ static struct ast_sip_session_supplement header_funcs_supplement = {
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
ast_sip_session_register_supplement(&header_funcs_supplement);
ast_custom_function_register(&pjsip_header_function);

@ -233,6 +233,8 @@ static const struct ast_sorcery_observer global_observer = {
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
if (ast_sorcery_observer_add(ast_sip_get_sorcery(), "global", &global_observer)) {
ast_log(LOG_WARNING, "Unable to add global observer\n");
return AST_MODULE_LOAD_DECLINE;

@ -723,6 +723,8 @@ static pjsip_module messaging_module = {
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
if (ast_sip_register_service(&messaging_module) != PJ_SUCCESS) {
return AST_MODULE_LOAD_DECLINE;
}

@ -201,6 +201,8 @@ static int load_module(void)
{
pj_sockaddr addr;
CHECK_PJSIP_MODULE_LOADED();
if (!pj_gethostip(pj_AF_INET(), &addr)) {
pj_sockaddr_print(&addr, host_ipv4, sizeof(host_ipv4), 2);
}

@ -895,6 +895,8 @@ static int reload(void)
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
if (ast_sip_register_subscription_handler(&mwi_handler)) {
return AST_MODULE_LOAD_DECLINE;
}

@ -94,6 +94,8 @@ static struct ast_sip_pubsub_body_generator mwi_generator = {
static int load_module(void)
{
CHECK_PJSIP_PUBSUB_MODULE_LOADED();
if (ast_sip_pubsub_register_body_generator(&mwi_generator)) {
return AST_MODULE_LOAD_DECLINE;
}

@ -281,6 +281,8 @@ static int unload_module(void)
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
if (ast_sip_register_service(&nat_module)) {
ast_log(LOG_ERROR, "Could not register NAT module for incoming and outgoing requests\n");
return AST_MODULE_LOAD_FAILURE;

@ -987,6 +987,8 @@ static int manager_notify(struct mansession *s, const struct message *m)
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
if (aco_info_init(&notify_cfg)) {
return AST_MODULE_LOAD_DECLINE;
}

@ -107,6 +107,8 @@ static struct ast_sip_session_supplement info_supplement = {
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
if (ast_sip_session_register_supplement(&info_supplement)) {
ast_log(LOG_ERROR, "Unable to register One Touch Recording supplement\n");
return AST_MODULE_LOAD_FAILURE;

@ -146,6 +146,8 @@ static struct ast_sip_outbound_authenticator digest_authenticator = {
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
if (ast_sip_register_outbound_authenticator(&digest_authenticator)) {
return AST_MODULE_LOAD_DECLINE;
}

@ -1239,6 +1239,8 @@ static struct ast_sip_cli_formatter_entry *cli_formatter;
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
ast_sorcery_apply_default(ast_sip_get_sorcery(), "registration", "config", "pjsip.conf,criteria=type=registration");
if (ast_sorcery_object_register(ast_sip_get_sorcery(), "registration", sip_outbound_registration_alloc, NULL, sip_outbound_registration_apply)) {

@ -224,6 +224,8 @@ static struct ast_sip_session_supplement path_session_supplement = {
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
if (ast_sip_register_supplement(&path_supplement)) {
return AST_MODULE_LOAD_DECLINE;
}

@ -370,6 +370,8 @@ static int users_apply_handler(const struct ast_sorcery *sorcery, void *obj)
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
if (!(sorcery = ast_sorcery_open())) {
ast_log(LOG_ERROR, "Unable to open a sorcery instance.\n");
return AST_MODULE_LOAD_DECLINE;

@ -117,6 +117,8 @@ static struct ast_sip_pubsub_body_generator pidf_body_generator = {
static int load_module(void)
{
CHECK_PJSIP_PUBSUB_MODULE_LOADED();
if (ast_sip_pubsub_register_body_generator(&pidf_body_generator)) {
return AST_MODULE_LOAD_DECLINE;
}

@ -95,6 +95,8 @@ static struct ast_sip_pubsub_body_supplement pidf_supplement = {
static int load_module(void)
{
CHECK_PJSIP_PUBSUB_MODULE_LOADED();
if (ast_sip_pubsub_register_body_supplement(&pidf_supplement)) {
return AST_MODULE_LOAD_DECLINE;
}

@ -94,6 +94,8 @@ static struct ast_sip_pubsub_body_supplement pidf_supplement = {
static int load_module(void)
{
CHECK_PJSIP_PUBSUB_MODULE_LOADED();
if (ast_sip_pubsub_register_body_supplement(&pidf_supplement)) {
return AST_MODULE_LOAD_DECLINE;
}

@ -856,6 +856,8 @@ static int regex_filter_handler(const struct aco_option *opt, struct ast_variabl
static int load_module(void)
{
CHECK_PJSIP_PUBSUB_MODULE_LOADED();
ast_sorcery_apply_default(ast_sip_get_sorcery(), "asterisk-publication", "config", "pjsip.conf,criteria=type=asterisk-publication");
if (ast_sorcery_object_register(ast_sip_get_sorcery(), "asterisk-publication", asterisk_publication_config_alloc, NULL, NULL)) {

@ -4168,7 +4168,11 @@ static int resource_event_handler(const struct aco_option *opt, struct ast_varia
static int load_module(void)
{
static const pj_str_t str_PUBLISH = { "PUBLISH", 7 };
struct ast_sorcery *sorcery = ast_sip_get_sorcery();
struct ast_sorcery *sorcery;
CHECK_PJSIP_MODULE_LOADED();
sorcery = ast_sip_get_sorcery();
pjsip_evsub_init_module(ast_sip_get_pjsip_endpoint());

@ -20,7 +20,6 @@
<depend>pjproject</depend>
<depend>res_pjsip</depend>
<depend>res_pjsip_session</depend>
<depend>res_pjsip_pubsub</depend>
<support_level>core</support_level>
***/
@ -985,6 +984,8 @@ static int load_module(void)
{
const pj_str_t str_norefersub = { "norefersub", 10 };
CHECK_PJSIP_SESSION_MODULE_LOADED();
pjsip_replaces_init_module(ast_sip_get_pjsip_endpoint());
pjsip_xfer_init_module(ast_sip_get_pjsip_endpoint());
pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), NULL, PJSIP_H_SUPPORTED, NULL, 1, &str_norefersub);

@ -793,6 +793,8 @@ static int load_module(void)
{
const pj_str_t STR_REGISTER = { "REGISTER", 8 };
CHECK_PJSIP_MODULE_LOADED();
if (!(serializers = ao2_container_alloc(
SERIALIZER_BUCKETS, serializer_hash, serializer_cmp))) {
return AST_MODULE_LOAD_DECLINE;

@ -177,6 +177,8 @@ static void contact_expiration_initialize_existing(void)
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
if (!(contact_autoexpire = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, CONTACT_AUTOEXPIRE_BUCKETS,
contact_expiration_hash, contact_expiration_cmp))) {
ast_log(LOG_ERROR, "Could not create container for contact auto-expiration\n");

@ -130,6 +130,8 @@ static struct ast_sip_session_supplement rfc3326_supplement = {
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
ast_sip_session_register_supplement(&rfc3326_supplement);
return AST_MODULE_LOAD_SUCCESS;
}

@ -1230,6 +1230,8 @@ static int unload_module(void)
*/
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
ast_sockaddr_parse(&address_ipv4, "0.0.0.0", 0);
ast_sockaddr_parse(&address_ipv6, "::", 0);

@ -207,6 +207,8 @@ static struct ast_sip_session_supplement refer_supplement = {
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
if (ast_sip_session_register_supplement(&refer_supplement)) {
ast_log(LOG_ERROR, "Unable to register Send to Voicemail supplement\n");
return AST_MODULE_LOAD_FAILURE;

@ -2415,6 +2415,8 @@ static int load_module(void)
{
pjsip_endpoint *endpt;
CHECK_PJSIP_MODULE_LOADED();
if (!ast_sip_get_sorcery() || !ast_sip_get_pjsip_endpoint()) {
return AST_MODULE_LOAD_DECLINE;
}

@ -850,6 +850,8 @@ static int unload_module(void)
*/
static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
ast_sockaddr_parse(&address_ipv4, "0.0.0.0", 0);
ast_sockaddr_parse(&address_ipv6, "::", 0);

@ -361,6 +361,8 @@ static struct ast_sip_session_supplement websocket_supplement = {
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
pjsip_transport_register_type(PJSIP_TRANSPORT_RELIABLE, "WS", 5060, &transport_type_ws);
pjsip_transport_register_type(PJSIP_TRANSPORT_RELIABLE, "WSS", 5060, &transport_type_wss);

@ -150,6 +150,8 @@ static void unregister_all(void)
static int load_module(void)
{
CHECK_PJSIP_PUBSUB_MODULE_LOADED();
if (ast_sip_pubsub_register_body_generator(&xpidf_body_generator)) {
goto fail;
}

Loading…
Cancel
Save