<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10383">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Verified
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_smdi.c: Made use defaults if the smdi.conf file does not exist.<br><br>This module is an optional dependency of a couple of other modules. If it<br>declines to load, it then forces other modules that can optionally use<br>this module to also decline.<br><br>* Made use the default configuration if the config file does not exist and<br>simplified some of the logic.<br><br>Change-Id: Ib93191f1fe28c0dd9ebe3d84c7762b32f83c4eb9<br>---<br>M res/res_smdi.c<br>1 file changed, 24 insertions(+), 45 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_smdi.c b/res/res_smdi.c</span><br><span>index 1d4826a..b8bf5d8 100644</span><br><span>--- a/res/res_smdi.c</span><br><span>+++ b/res/res_smdi.c</span><br><span>@@ -162,7 +162,6 @@</span><br><span> ***/</span><br><span> </span><br><span> static const char config_file[] = "smdi.conf";</span><br><span style="color: hsl(0, 100%, 40%);">-static int smdi_loaded;</span><br><span> </span><br><span> struct ast_smdi_interface {</span><br><span> char name[SMDI_MAX_FILENAME_LEN];</span><br><span>@@ -1035,7 +1034,7 @@</span><br><span> } else if (!strcasecmp(v->name, "twostopbits")) {</span><br><span> stopbits = ast_true(v->name);</span><br><span> } else if (!strcasecmp(v->name, "smdiport")) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (reload) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (reload && old_ifaces) {</span><br><span> /* we are reloading, check if we are already</span><br><span> * monitoring this interface, if we are we do</span><br><span> * not want to start it again. This also has</span><br><span>@@ -1371,7 +1370,26 @@</span><br><span> .read = smdi_msg_read,</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static int _unload_module(int fromload);</span><br><span style="color: hsl(120, 100%, 40%);">+static int unload_module(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_global_obj_release(smdi_ifaces);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ destroy_all_mailbox_mappings();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_lock(&mwi_monitor.lock);</span><br><span style="color: hsl(120, 100%, 40%);">+ mwi_monitor.stop = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cond_signal(&mwi_monitor.cond);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_unlock(&mwi_monitor.lock);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (mwi_monitor.thread != AST_PTHREADT_NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pthread_join(mwi_monitor.thread, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_custom_function_unregister(&smdi_msg_retrieve_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_custom_function_unregister(&smdi_msg_function);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span> </span><br><span> /*!</span><br><span> * \brief Load the module</span><br><span>@@ -1386,7 +1404,6 @@</span><br><span> static int load_module(void)</span><br><span> {</span><br><span> int res;</span><br><span style="color: hsl(0, 100%, 40%);">- smdi_loaded = 1;</span><br><span> </span><br><span> ast_mutex_init(&mwi_monitor.lock);</span><br><span> ast_cond_init(&mwi_monitor.cond, NULL);</span><br><span>@@ -1394,12 +1411,10 @@</span><br><span> /* load the config and start the listener threads*/</span><br><span> res = smdi_load(0);</span><br><span> if (res < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- _unload_module(1);</span><br><span style="color: hsl(120, 100%, 40%);">+ unload_module();</span><br><span> return AST_MODULE_LOAD_DECLINE;</span><br><span> } else if (res == 1) {</span><br><span style="color: hsl(0, 100%, 40%);">- _unload_module(1);</span><br><span> ast_log(LOG_NOTICE, "No SMDI interfaces are available to listen on, not starting SMDI listener.\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return AST_MODULE_LOAD_DECLINE;</span><br><span> }</span><br><span> </span><br><span> ast_custom_function_register(&smdi_msg_retrieve_function);</span><br><span>@@ -1408,53 +1423,17 @@</span><br><span> return AST_MODULE_LOAD_SUCCESS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static int _unload_module(int fromload)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- if (!smdi_loaded) {</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_global_obj_release(smdi_ifaces);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- destroy_all_mailbox_mappings();</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ast_mutex_lock(&mwi_monitor.lock);</span><br><span style="color: hsl(0, 100%, 40%);">- mwi_monitor.stop = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- ast_cond_signal(&mwi_monitor.cond);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_mutex_unlock(&mwi_monitor.lock);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (mwi_monitor.thread != AST_PTHREADT_NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">- pthread_join(mwi_monitor.thread, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!fromload) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_custom_function_unregister(&smdi_msg_retrieve_function);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_custom_function_unregister(&smdi_msg_function);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- smdi_loaded = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int unload_module(void)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- return _unload_module(0);</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static int reload(void)</span><br><span> {</span><br><span> int res;</span><br><span> </span><br><span> res = smdi_load(1);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> if (res < 0) {</span><br><span> return res;</span><br><span> } else if (res == 1) {</span><br><span> ast_log(LOG_WARNING, "No SMDI interfaces were specified to listen on, not starting SDMI listener.\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- } else</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span> }</span><br><span> </span><br><span> AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Simplified Message Desk Interface (SMDI) Resource",</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10383">change 10383</a>. To unsubscribe, or for help writing mail filters, 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/10383"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ib93191f1fe28c0dd9ebe3d84c7762b32f83c4eb9 </div>
<div style="display:none"> Gerrit-Change-Number: 10383 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>