<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/5810">View Change</a></p><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, 46 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/10/5810/1</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 478a258..87d22a8 100644<br>--- a/res/res_ari_applications.c<br>+++ b/res/res_ari_applications.c<br>@@ -502,6 +502,9 @@<br> static int load_module(void)<br> {<br>      int res = 0;<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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 f81f647..9d1c07b 100644<br>--- a/res/res_ari_asterisk.c<br>+++ b/res/res_ari_asterisk.c<br>@@ -1223,6 +1223,9 @@<br> static int load_module(void)<br> {<br>         int res = 0;<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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 305e70f..cabf6c0 100644<br>--- a/res/res_ari_bridges.c<br>+++ b/res/res_ari_bridges.c<br>@@ -1549,6 +1549,9 @@<br> static int load_module(void)<br> {<br>     int res = 0;<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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 64acfa9..3a9e32c 100644<br>--- a/res/res_ari_channels.c<br>+++ b/res/res_ari_channels.c<br>@@ -2853,6 +2853,9 @@<br> static int load_module(void)<br> {<br>         int res = 0;<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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 678e40c..b56b0f7 100644<br>--- a/res/res_ari_device_states.c<br>+++ b/res/res_ari_device_states.c<br>@@ -333,6 +333,9 @@<br> static int load_module(void)<br> {<br>       int res = 0;<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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 eee1c84..d40cd74 100644<br>--- a/res/res_ari_endpoints.c<br>+++ b/res/res_ari_endpoints.c<br>@@ -457,6 +457,9 @@<br> static int load_module(void)<br> {<br>       int res = 0;<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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 42862b6..c06a4d2 100644<br>--- a/res/res_ari_events.c<br>+++ b/res/res_ari_events.c<br>@@ -454,6 +454,9 @@<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>+    CHECK_ARI_MODULE_LOADED();<br>+<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 2f6e752..3ce6a66 100644<br>--- a/res/res_ari_mailboxes.c<br>+++ b/res/res_ari_mailboxes.c<br>@@ -339,6 +339,9 @@<br> static int load_module(void)<br> {<br>       int res = 0;<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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 2329bb0..df3fb61 100644<br>--- a/res/res_ari_playbacks.c<br>+++ b/res/res_ari_playbacks.c<br>@@ -291,6 +291,9 @@<br> static int load_module(void)<br> {<br>       int res = 0;<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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 4d8bc6f..92e8acd 100644<br>--- a/res/res_ari_recordings.c<br>+++ b/res/res_ari_recordings.c<br>@@ -875,6 +875,9 @@<br> static int load_module(void)<br> {<br>   int res = 0;<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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 c4a5837..544c9af 100644<br>--- a/res/res_ari_sounds.c<br>+++ b/res/res_ari_sounds.c<br>@@ -221,6 +221,9 @@<br> static int load_module(void)<br> {<br>   int res = 0;<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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 883f1fd..8843515 100644<br>--- a/rest-api-templates/res_ari_resource.c.mustache<br>+++ b/rest-api-templates/res_ari_resource.c.mustache<br>@@ -305,6 +305,9 @@<br> {{/is_websocket}}<br> {{/operations}}<br> {{/apis}}<br>+<br>+    CHECK_ARI_MODULE_LOADED();<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/5810">change 5810</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/5810"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 14 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I263d56efa628ee3c411bdcd16d49af6260c6c91d </div>
<div style="display:none"> Gerrit-Change-Number: 5810 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>