]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_ari: Add "module loaded" check to ari stubs
authorGeorge Joseph <gjoseph@digium.com>
Tue, 13 Jun 2017 16:33:34 +0000 (10:33 -0600)
committerGeorge Joseph <gjoseph@digium.com>
Fri, 16 Jun 2017 00:31:53 +0000 (18:31 -0600)
The recent change to make the use of LOAD_DECLINE more consistent
caused res_ari to unload itself before declining if the ari.conf
file wasn't found.  The ari stubs though still tried to use the
configuration resulting in segfaults.

This patch creates a new CHECK_ARI_MODULE_LOADED macro which tests
to see if res_ari is actually loaded and causes the stubs to also
decline if it isn't.  The macro was then added to the mustache
template's "load_module" function.

ASTERISK-27026 #close
Reported-by: Ronald Raikes
Change-Id: I263d56efa628ee3c411bdcd16d49af6260c6c91d

13 files changed:
include/asterisk/ari.h
res/res_ari_applications.c
res/res_ari_asterisk.c
res/res_ari_bridges.c
res/res_ari_channels.c
res/res_ari_device_states.c
res/res_ari_endpoints.c
res/res_ari_events.c
res/res_ari_mailboxes.c
res/res_ari_playbacks.c
res/res_ari_recordings.c
res/res_ari_sounds.c
rest-api-templates/res_ari_resource.c.mustache

index cad9b32c5cecdc25ffd360d2016f39d901c0f656..f83df0469d3955a10a40226f5c6c7381914ac4c6 100644 (file)
@@ -266,4 +266,14 @@ void ast_ari_response_created(struct ast_ari_response *response,
  */
 void ast_ari_response_alloc_failed(struct ast_ari_response *response);
 
+/*! \brief Determines whether the res_ari module is loaded */
+#define CHECK_ARI_MODULE_LOADED()                              \
+       do {                                                    \
+               if (!ast_module_check("res_ari.so")             \
+                       || !ast_ari_oom_json()) {       \
+                       return AST_MODULE_LOAD_DECLINE;         \
+               }                                               \
+       } while(0)
+
+
 #endif /* _ASTERISK_ARI_H */
index cb12e84c8cfc37552c647c03f96edc8c410e2891..290719d36035409cf909a0ab219b57ece0dcdafe 100644 (file)
@@ -502,6 +502,10 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&applications);
        if (res) {
index 1a574aaaf526da791a2bc6dc6056978ac11d51fc..73e4d0ce3a5d9b2f4fdd4fd7a2c8c35fda39dc44 100644 (file)
@@ -1223,6 +1223,10 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&asterisk);
        if (res) {
index 69d4d6ed5da3213c4fcd799aa5d169bac4e61a01..b923330956c58f679751efdec38beb87655e1485 100644 (file)
@@ -1415,6 +1415,10 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&bridges);
        if (res) {
index f59f2063463e13fd862b6707041959d078c5f309..621767980fb2e674d04dc7dd4b4f41c6534045b9 100644 (file)
@@ -2479,6 +2479,10 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&channels);
        if (res) {
index a3711e6ebf94575997b82559ae17dbed2545bf8a..fe1817d5da66fd590532ba0e5b36f025c21a0b97 100644 (file)
@@ -333,6 +333,10 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&deviceStates);
        if (res) {
index 43d25589833f418600cf2f23066d54598fcb9273..a46b0dc610e72b454bf4efb70e66698343314a30 100644 (file)
@@ -457,6 +457,10 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&endpoints);
        if (res) {
index fd208c57bcc045b8d411adf7f63866964128a876..b6a44d9b93a7546b6ac04aa9dddd9849d85718eb 100644 (file)
@@ -430,22 +430,29 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
-       struct ast_websocket_protocol *protocol;
 
-       events.ws_server = ast_websocket_server_create();
-       if (!events.ws_server) {
-               return AST_MODULE_LOAD_DECLINE;
-       }
+       CHECK_ARI_MODULE_LOADED();
 
-       protocol = ast_websocket_sub_protocol_alloc("ari");
-       if (!protocol) {
-               ao2_ref(events.ws_server, -1);
-               events.ws_server = NULL;
-               return AST_MODULE_LOAD_DECLINE;
+       /* This is scoped to not conflict with CHECK_ARI_MODULE_LOADED */
+       {
+               struct ast_websocket_protocol *protocol;
+
+               events.ws_server = ast_websocket_server_create();
+               if (!events.ws_server) {
+                       return AST_MODULE_LOAD_DECLINE;
+               }
+
+               protocol = ast_websocket_sub_protocol_alloc("ari");
+               if (!protocol) {
+                       ao2_ref(events.ws_server, -1);
+                       events.ws_server = NULL;
+                       return AST_MODULE_LOAD_DECLINE;
+               }
+               protocol->session_attempted = ast_ari_events_event_websocket_ws_attempted_cb;
+               protocol->session_established = ast_ari_events_event_websocket_ws_established_cb;
+               res |= ast_websocket_server_add_protocol2(events.ws_server, protocol);
        }
-       protocol->session_attempted = ast_ari_events_event_websocket_ws_attempted_cb;
-       protocol->session_established = ast_ari_events_event_websocket_ws_established_cb;
-       res |= ast_websocket_server_add_protocol2(events.ws_server, protocol);
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&events);
        if (res) {
index f85541cf0428edea1149fe8c5ee4e29f7e6737c2..600ecfd48b163db9e7dd22d5b6729ef1579adcc7 100644 (file)
@@ -339,6 +339,10 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&mailboxes);
        if (res) {
index 25e211c55177263cbeb8b031c461a16038e38950..106463b5b535a4ffd2d5a129cc2ec46a55a496bb 100644 (file)
@@ -291,6 +291,10 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&playbacks);
        if (res) {
index 29720a84aa17920e7b02e43310b31569c2b7f181..c43148d836faf6b5caae8bbd3bd3668a922a7c01 100644 (file)
@@ -807,6 +807,10 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&recordings);
        if (res) {
index 6d09d2cbe0418de82338d8cc283e0c18dd6b1f0f..e58ecd1cf6375ed0e4f5bf9af8f7b9f07bdc1c49 100644 (file)
@@ -221,6 +221,10 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&sounds);
        if (res) {
index 921b007be0b8b56ab3e2721100ad08926fef5877..b4d80101e20532cbbc1bf50829302c896bd42ae6 100644 (file)
@@ -262,30 +262,37 @@ static int unload_module(void)
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
 {{#apis}}
 {{#operations}}
 {{#has_websocket}}
-       struct ast_websocket_protocol *protocol;
+       /* This is scoped to not conflict with CHECK_ARI_MODULE_LOADED */
+       {
+               struct ast_websocket_protocol *protocol;
 
-       {{full_name}}.ws_server = ast_websocket_server_create();
-       if (!{{full_name}}.ws_server) {
-               return AST_MODULE_LOAD_DECLINE;
-       }
+               {{full_name}}.ws_server = ast_websocket_server_create();
+               if (!{{full_name}}.ws_server) {
+                       return AST_MODULE_LOAD_DECLINE;
+               }
 
-       protocol = ast_websocket_sub_protocol_alloc("{{websocket_protocol}}");
-       if (!protocol) {
-               ao2_ref({{full_name}}.ws_server, -1);
-               {{full_name}}.ws_server = NULL;
-               return AST_MODULE_LOAD_DECLINE;
-       }
-       protocol->session_attempted = ast_ari_{{c_name}}_{{c_nickname}}_ws_attempted_cb;
-       protocol->session_established = ast_ari_{{c_name}}_{{c_nickname}}_ws_established_cb;
+               protocol = ast_websocket_sub_protocol_alloc("{{websocket_protocol}}");
+               if (!protocol) {
+                       ao2_ref({{full_name}}.ws_server, -1);
+                       {{full_name}}.ws_server = NULL;
+                       return AST_MODULE_LOAD_DECLINE;
+               }
+               protocol->session_attempted = ast_ari_{{c_name}}_{{c_nickname}}_ws_attempted_cb;
+               protocol->session_established = ast_ari_{{c_name}}_{{c_nickname}}_ws_established_cb;
 {{/has_websocket}}
 {{#is_websocket}}
-       res |= ast_websocket_server_add_protocol2({{full_name}}.ws_server, protocol);
+               res |= ast_websocket_server_add_protocol2({{full_name}}.ws_server, protocol);
+       }
 {{/is_websocket}}
 {{/operations}}
 {{/apis}}
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&{{root_full_name}});
        if (res) {