<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/5811">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_ari: Add "module loaded" check to ari stubs<br><br>The recent change to make the use of LOAD_DECLINE more consistent<br>caused res_ari to unload itself before declining if the ari.conf<br>file wasn't found. The ari stubs though still tried to use the<br>configuration resulting in segfaults.<br><br>This patch creates a new CHECK_ARI_MODULE_LOADED macro which tests<br>to see if res_ari is actually loaded and causes the stubs to also<br>decline if it isn't. The macro was then added to the mustache<br>template's "load_module" function.<br><br>ASTERISK-27026 #close<br>Reported-by: Ronald Raikes<br><br>Change-Id: I263d56efa628ee3c411bdcd16d49af6260c6c91d<br>---<br>M include/asterisk/ari.h<br>M res/res_ari_applications.c<br>M res/res_ari_asterisk.c<br>M res/res_ari_bridges.c<br>M res/res_ari_channels.c<br>M res/res_ari_device_states.c<br>M res/res_ari_endpoints.c<br>M res/res_ari_events.c<br>M res/res_ari_mailboxes.c<br>M res/res_ari_playbacks.c<br>M res/res_ari_recordings.c<br>M res/res_ari_sounds.c<br>M rest-api-templates/res_ari_resource.c.mustache<br>13 files changed, 102 insertions(+), 38 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/ari.h b/include/asterisk/ari.h<br>index 865b4b0..f83d596 100644<br>--- a/include/asterisk/ari.h<br>+++ b/include/asterisk/ari.h<br>@@ -268,4 +268,14 @@<br> */<br> void ast_ari_response_alloc_failed(struct ast_ari_response *response);<br> <br>+/*! \brief Determines whether the res_ari module is loaded */<br>+#define CHECK_ARI_MODULE_LOADED() \<br>+ do { \<br>+ if (!ast_module_check("res_ari.so") \<br>+ || !ast_ari_oom_json()) { \<br>+ return AST_MODULE_LOAD_DECLINE; \<br>+ } \<br>+ } while(0)<br>+<br>+<br> #endif /* _ASTERISK_ARI_H */<br>diff --git a/res/res_ari_applications.c b/res/res_ari_applications.c<br>index 21d9f56..cf700c4 100644<br>--- a/res/res_ari_applications.c<br>+++ b/res/res_ari_applications.c<br>@@ -500,6 +500,10 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&applications);<br> if (res) {<br>diff --git a/res/res_ari_asterisk.c b/res/res_ari_asterisk.c<br>index 89517cc..eb0617b 100644<br>--- a/res/res_ari_asterisk.c<br>+++ b/res/res_ari_asterisk.c<br>@@ -1221,6 +1221,10 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&asterisk);<br> if (res) {<br>diff --git a/res/res_ari_bridges.c b/res/res_ari_bridges.c<br>index 5402c2b..65bf7ed 100644<br>--- a/res/res_ari_bridges.c<br>+++ b/res/res_ari_bridges.c<br>@@ -1547,6 +1547,10 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&bridges);<br> if (res) {<br>diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c<br>index 9d218e2..f6befcc 100644<br>--- a/res/res_ari_channels.c<br>+++ b/res/res_ari_channels.c<br>@@ -2851,6 +2851,10 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&channels);<br> if (res) {<br>diff --git a/res/res_ari_device_states.c b/res/res_ari_device_states.c<br>index d6de5df..f393935 100644<br>--- a/res/res_ari_device_states.c<br>+++ b/res/res_ari_device_states.c<br>@@ -331,6 +331,10 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&deviceStates);<br> if (res) {<br>diff --git a/res/res_ari_endpoints.c b/res/res_ari_endpoints.c<br>index d96de08..d1242c0 100644<br>--- a/res/res_ari_endpoints.c<br>+++ b/res/res_ari_endpoints.c<br>@@ -455,6 +455,10 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&endpoints);<br> if (res) {<br>diff --git a/res/res_ari_events.c b/res/res_ari_events.c<br>index 3f5b89a..f916d0e 100644<br>--- a/res/res_ari_events.c<br>+++ b/res/res_ari_events.c<br>@@ -430,28 +430,35 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>- struct ast_websocket_protocol *protocol;<br> <br>- if (ast_ari_websocket_events_event_websocket_init() == -1) {<br>- return AST_MODULE_LOAD_DECLINE;<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+ /* This is scoped to not conflict with CHECK_ARI_MODULE_LOADED */<br>+ {<br>+ struct ast_websocket_protocol *protocol;<br>+<br>+ if (ast_ari_websocket_events_event_websocket_init() == -1) {<br>+ return AST_MODULE_LOAD_DECLINE;<br>+ }<br>+<br>+ events.ws_server = ast_websocket_server_create();<br>+ if (!events.ws_server) {<br>+ ast_ari_websocket_events_event_websocket_dtor();<br>+ return AST_MODULE_LOAD_DECLINE;<br>+ }<br>+<br>+ protocol = ast_websocket_sub_protocol_alloc("ari");<br>+ if (!protocol) {<br>+ ao2_ref(events.ws_server, -1);<br>+ events.ws_server = NULL;<br>+ ast_ari_websocket_events_event_websocket_dtor();<br>+ return AST_MODULE_LOAD_DECLINE;<br>+ }<br>+ protocol->session_attempted = ast_ari_events_event_websocket_ws_attempted_cb;<br>+ protocol->session_established = ast_ari_events_event_websocket_ws_established_cb;<br>+ res |= ast_websocket_server_add_protocol2(events.ws_server, protocol);<br> }<br> <br>- events.ws_server = ast_websocket_server_create();<br>- if (!events.ws_server) {<br>- ast_ari_websocket_events_event_websocket_dtor();<br>- return AST_MODULE_LOAD_DECLINE;<br>- }<br>-<br>- protocol = ast_websocket_sub_protocol_alloc("ari");<br>- if (!protocol) {<br>- ao2_ref(events.ws_server, -1);<br>- events.ws_server = NULL;<br>- ast_ari_websocket_events_event_websocket_dtor();<br>- return AST_MODULE_LOAD_DECLINE;<br>- }<br>- protocol->session_attempted = ast_ari_events_event_websocket_ws_attempted_cb;<br>- protocol->session_established = ast_ari_events_event_websocket_ws_established_cb;<br>- res |= ast_websocket_server_add_protocol2(events.ws_server, protocol);<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&events);<br> if (res) {<br>diff --git a/res/res_ari_mailboxes.c b/res/res_ari_mailboxes.c<br>index 12c33cd..1f6d2cc 100644<br>--- a/res/res_ari_mailboxes.c<br>+++ b/res/res_ari_mailboxes.c<br>@@ -337,6 +337,10 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&mailboxes);<br> if (res) {<br>diff --git a/res/res_ari_playbacks.c b/res/res_ari_playbacks.c<br>index e2c432d..40099cf 100644<br>--- a/res/res_ari_playbacks.c<br>+++ b/res/res_ari_playbacks.c<br>@@ -289,6 +289,10 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&playbacks);<br> if (res) {<br>diff --git a/res/res_ari_recordings.c b/res/res_ari_recordings.c<br>index 57d80f2..fe3d343 100644<br>--- a/res/res_ari_recordings.c<br>+++ b/res/res_ari_recordings.c<br>@@ -873,6 +873,10 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&recordings);<br> if (res) {<br>diff --git a/res/res_ari_sounds.c b/res/res_ari_sounds.c<br>index fded7fb..8d5928a 100644<br>--- a/res/res_ari_sounds.c<br>+++ b/res/res_ari_sounds.c<br>@@ -219,6 +219,10 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&sounds);<br> if (res) {<br>diff --git a/rest-api-templates/res_ari_resource.c.mustache b/rest-api-templates/res_ari_resource.c.mustache<br>index 3ccafcd..d4ccda9 100644<br>--- a/rest-api-templates/res_ari_resource.c.mustache<br>+++ b/rest-api-templates/res_ari_resource.c.mustache<br>@@ -273,36 +273,43 @@<br> static int load_module(void)<br> {<br> int res = 0;<br>+<br>+ CHECK_ARI_MODULE_LOADED();<br>+<br> {{#apis}}<br> {{#operations}}<br> {{#has_websocket}}<br>- struct ast_websocket_protocol *protocol;<br>+ /* This is scoped to not conflict with CHECK_ARI_MODULE_LOADED */<br>+ {<br>+ struct ast_websocket_protocol *protocol;<br> <br>- if (ast_ari_websocket_{{c_name}}_{{c_nickname}}_init() == -1) {<br>- return AST_MODULE_LOAD_DECLINE;<br>- }<br>+ if (ast_ari_websocket_{{c_name}}_{{c_nickname}}_init() == -1) {<br>+ return AST_MODULE_LOAD_DECLINE;<br>+ }<br> <br>- {{full_name}}.ws_server = ast_websocket_server_create();<br>- if (!{{full_name}}.ws_server) {<br>- ast_ari_websocket_events_event_websocket_dtor();<br>- return AST_MODULE_LOAD_DECLINE;<br>- }<br>+ {{full_name}}.ws_server = ast_websocket_server_create();<br>+ if (!{{full_name}}.ws_server) {<br>+ ast_ari_websocket_events_event_websocket_dtor();<br>+ return AST_MODULE_LOAD_DECLINE;<br>+ }<br> <br>- protocol = ast_websocket_sub_protocol_alloc("{{websocket_protocol}}");<br>- if (!protocol) {<br>- ao2_ref({{full_name}}.ws_server, -1);<br>- {{full_name}}.ws_server = NULL;<br>- ast_ari_websocket_events_event_websocket_dtor();<br>- return AST_MODULE_LOAD_DECLINE;<br>- }<br>- protocol->session_attempted = ast_ari_{{c_name}}_{{c_nickname}}_ws_attempted_cb;<br>- protocol->session_established = ast_ari_{{c_name}}_{{c_nickname}}_ws_established_cb;<br>+ protocol = ast_websocket_sub_protocol_alloc("{{websocket_protocol}}");<br>+ if (!protocol) {<br>+ ao2_ref({{full_name}}.ws_server, -1);<br>+ {{full_name}}.ws_server = NULL;<br>+ ast_ari_websocket_events_event_websocket_dtor();<br>+ return AST_MODULE_LOAD_DECLINE;<br>+ }<br>+ protocol->session_attempted = ast_ari_{{c_name}}_{{c_nickname}}_ws_attempted_cb;<br>+ protocol->session_established = ast_ari_{{c_name}}_{{c_nickname}}_ws_established_cb;<br> {{/has_websocket}}<br> {{#is_websocket}}<br>- res |= ast_websocket_server_add_protocol2({{full_name}}.ws_server, protocol);<br>+ res |= ast_websocket_server_add_protocol2({{full_name}}.ws_server, protocol);<br>+ }<br> {{/is_websocket}}<br> {{/operations}}<br> {{/apis}}<br>+<br> stasis_app_ref();<br> res |= ast_ari_add_handler(&{{root_full_name}});<br> if (res) {<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5811">change 5811</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/5811"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I263d56efa628ee3c411bdcd16d49af6260c6c91d </div>
<div style="display:none"> Gerrit-Change-Number: 5811 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>