PJSIP: Enforce module load dependencies
authorKinsey Moore <kmoore@digium.com>
Thu, 16 Oct 2014 16:32:25 +0000 (16:32 +0000)
committerKinsey Moore <kmoore@digium.com>
Thu, 16 Oct 2014 16:32:25 +0000 (16:32 +0000)
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

43 files changed:
channels/chan_pjsip.c
include/asterisk/res_pjsip.h
include/asterisk/res_pjsip_pubsub.h
include/asterisk/res_pjsip_session.h
res/res_hep_pjsip.c
res/res_pjsip_acl.c
res/res_pjsip_authenticator_digest.c
res/res_pjsip_caller_id.c
res/res_pjsip_dialog_info_body_generator.c
res/res_pjsip_diversion.c
res/res_pjsip_dtmf_info.c
res/res_pjsip_endpoint_identifier_anonymous.c
res/res_pjsip_endpoint_identifier_ip.c
res/res_pjsip_endpoint_identifier_user.c
res/res_pjsip_exten_state.c
res/res_pjsip_header_funcs.c
res/res_pjsip_logger.c
res/res_pjsip_messaging.c
res/res_pjsip_multihomed.c
res/res_pjsip_mwi.c
res/res_pjsip_mwi_body_generator.c
res/res_pjsip_nat.c
res/res_pjsip_notify.c
res/res_pjsip_one_touch_record_info.c
res/res_pjsip_outbound_authenticator_digest.c
res/res_pjsip_outbound_registration.c
res/res_pjsip_path.c
res/res_pjsip_phoneprov_provider.c
res/res_pjsip_pidf_body_generator.c
res/res_pjsip_pidf_digium_body_supplement.c
res/res_pjsip_pidf_eyebeam_body_supplement.c
res/res_pjsip_publish_asterisk.c
res/res_pjsip_pubsub.c
res/res_pjsip_refer.c
res/res_pjsip_registrar.c
res/res_pjsip_registrar_expire.c
res/res_pjsip_rfc3326.c
res/res_pjsip_sdp_rtp.c
res/res_pjsip_send_to_voicemail.c
res/res_pjsip_session.c
res/res_pjsip_t38.c
res/res_pjsip_transport_websocket.c
res/res_pjsip_xpidf_body_generator.c

index ea55df7..f200a05 100644 (file)
@@ -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;
        }
index fdb2105..302a15d 100644 (file)
@@ -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 */
index aac4261..d32b246 100644 (file)
@@ -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 */
index 3344a6b..d50b431 100644 (file)
@@ -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 */
index 333719d..b5cf0b8 100644 (file)
@@ -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;
 }
index 7cb56e7..8155bf8 100644 (file)
@@ -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");
 
index 2688553..8a78125 100644 (file)
@@ -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;
        }
index 3764931..e22ce6a 100644 (file)
@@ -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;
 }
index 06cff8d..d9725f4 100644 (file)
@@ -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;
        }
index f8aca35..a4ac157 100644 (file)
@@ -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;
 }
index e78f7b7..b0a6649 100644 (file)
@@ -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;
 }
index f0ea6dd..a7956b5 100644 (file)
@@ -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;
 }
index 43f1318..aab2c76 100644 (file)
@@ -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");
 
index dba3541..beae1cd 100644 (file)
@@ -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;
 }
index 4cc5a58..6b8ee6c 100644 (file)
@@ -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);
index d3a4822..4ab3fb1 100644 (file)
@@ -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);
 
index 320bb03..2e5c76c 100644 (file)
@@ -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;
index db97525..0433299 100644 (file)
@@ -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;
        }
index 30d0fd9..38824da 100644 (file)
@@ -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);
        }
index bed0719..eaf0f32 100644 (file)
@@ -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;
        }
index 2020e26..cc558ac 100644 (file)
@@ -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;
        }
index 654e51b..5887343 100644 (file)
@@ -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;
index 8b61d13..d7e3d80 100644 (file)
@@ -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;
        }
index 4d744e3..8b1ff9d 100644 (file)
@@ -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;
index fbd9168..64238a8 100644 (file)
@@ -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;
        }
index 9fd5fe6..3e6c984 100644 (file)
@@ -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)) {
index a7ad3f4..d0ee5a4 100644 (file)
@@ -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;
        }
index 6c2c777..0480f0b 100644 (file)
@@ -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;
index e5002ce..ef0cce5 100644 (file)
@@ -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;
        }
index eff16a8..86e673a 100644 (file)
@@ -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;
        }
index a8be55c..cd590c3 100644 (file)
@@ -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;
        }
index 8d4d851..e1b095e 100644 (file)
@@ -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)) {
index 0d9e25a..4a1076d 100644 (file)
@@ -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());
 
index ff8ceac..f64f77d 100644 (file)
@@ -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);
index b5cb124..aad3dd4 100644 (file)
@@ -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;
index ee168bd..256ed9e 100644 (file)
@@ -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");
index e0b1939..3ed8de6 100644 (file)
@@ -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;
 }
index 1de675b..2aa8acc 100644 (file)
@@ -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);
 
index 3bb5da8..97f55d3 100644 (file)
@@ -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;
index 1d6b36f..5618721 100644 (file)
@@ -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;
        }
index a031716..d1ec076 100644 (file)
@@ -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);
 
index 7de65dd..1db36bb 100644 (file)
@@ -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);
 
index e7009af..43cb1e7 100644 (file)
@@ -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;
        }