<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12867">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_musiconhold: Added unregister realtime moh class<br><br>This fix allows a realtime moh class to be unregistered from the command<br>line. This is useful when the contents of a directory referenced by a<br>realtime moh class have changed.<br>The realtime moh class is then reloaded on the next request and uses the<br>new directory contents.<br><br>ASTERISK-17808<br><br>Change-Id: Ibc4c6834592257c4bb90601ee299682d15befbce<br>---<br>A doc/CHANGES-staging/res_musiconhold.txt<br>M res/res_musiconhold.c<br>2 files changed, 94 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/res_musiconhold.txt b/doc/CHANGES-staging/res_musiconhold.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..47ef397</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/res_musiconhold.txt</span><br><span>@@ -0,0 +1,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_musiconhold</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+This fix allows a realtime moh class to be unregistered from the command</span><br><span style="color: hsl(120, 100%, 40%);">+line. This is useful when the contents of a directory referenced by a</span><br><span style="color: hsl(120, 100%, 40%);">+realtime moh class have changed.</span><br><span style="color: hsl(120, 100%, 40%);">+The realtime moh class is then reloaded on the next request and uses the</span><br><span style="color: hsl(120, 100%, 40%);">+new directory contents.</span><br><span>diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c</span><br><span>index 32e77dd..f770075 100644</span><br><span>--- a/res/res_musiconhold.c</span><br><span>+++ b/res/res_musiconhold.c</span><br><span>@@ -1359,6 +1359,13 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define moh_unregister(a) _moh_unregister(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)</span><br><span style="color: hsl(120, 100%, 40%);">+static int _moh_unregister(struct mohclass *moh, const char *file, int line, const char *funcname)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_t_unlink(mohclasses, moh, "Removing class from container");</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void local_ast_moh_cleanup(struct ast_channel *chan)</span><br><span> {</span><br><span> struct moh_files_state *state = ast_channel_music_state(chan);</span><br><span>@@ -1379,6 +1386,82 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Support routing for 'moh unregister class' CLI</span><br><span style="color: hsl(120, 100%, 40%);">+ * This is in charge of generating all strings that match a prefix in the</span><br><span style="color: hsl(120, 100%, 40%);">+ * given position. As many functions of this kind, each invokation has</span><br><span style="color: hsl(120, 100%, 40%);">+ * O(state) time complexity so be careful in using it.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static char *complete_mohclass_realtime(const char *line, const char *word, int pos, int state)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int which=0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct mohclass *cur;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *c = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ int wordlen = strlen(word);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_iterator i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pos != 3) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 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%);">+ i = ao2_iterator_init(mohclasses, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((cur = ao2_t_iterator_next(&i, "iterate thru mohclasses"))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (cur->realtime && !strncasecmp(cur->name, word, wordlen) && ++which > state) {</span><br><span style="color: hsl(120, 100%, 40%);">+ c = ast_strdup(cur->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ mohclass_unref(cur, "drop ref in iterator loop break");</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ mohclass_unref(cur, "drop ref in iterator loop");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_iterator_destroy(&i);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return c;</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%);">+static char *handle_cli_moh_unregister_class(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct mohclass *cur;</span><br><span style="color: hsl(120, 100%, 40%);">+ int len;</span><br><span style="color: hsl(120, 100%, 40%);">+ int found = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_iterator i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case CLI_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+ e->command = "moh unregister class";</span><br><span style="color: hsl(120, 100%, 40%);">+ e->usage =</span><br><span style="color: hsl(120, 100%, 40%);">+ "Usage: moh unregister class <class>\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " Unregisters a realtime moh class.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ case CLI_GENERATE:</span><br><span style="color: hsl(120, 100%, 40%);">+ return complete_mohclass_realtime(a->line, a->word, a->pos, a->n);</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%);">+ if (a->argc != 4)</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_SHOWUSAGE;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ len = strlen(a->argv[3]);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ i = ao2_iterator_init(mohclasses, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((cur = ao2_t_iterator_next(&i, "iterate thru mohclasses"))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (cur->realtime && len == strlen(cur->name) && !strncasecmp(cur->name, a->argv[3], len)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ found = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ mohclass_unref(cur, "drop ref in iterator loop");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_iterator_destroy(&i);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (found) {</span><br><span style="color: hsl(120, 100%, 40%);">+ moh_unregister(cur);</span><br><span style="color: hsl(120, 100%, 40%);">+ mohclass_unref(cur, "drop ref after unregister");</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "No such realtime moh class '%s'\n", a->argv[3]);</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%);">+ return CLI_SUCCESS;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void moh_class_destructor(void *obj);</span><br><span> </span><br><span> #define moh_class_malloc() _moh_class_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__)</span><br><span>@@ -1910,9 +1993,10 @@</span><br><span> }</span><br><span> </span><br><span> static struct ast_cli_entry cli_moh[] = {</span><br><span style="color: hsl(0, 100%, 40%);">- AST_CLI_DEFINE(handle_cli_moh_reload, "Reload MusicOnHold"),</span><br><span style="color: hsl(0, 100%, 40%);">- AST_CLI_DEFINE(handle_cli_moh_show_classes, "List MusicOnHold classes"),</span><br><span style="color: hsl(0, 100%, 40%);">- AST_CLI_DEFINE(handle_cli_moh_show_files, "List MusicOnHold file-based classes")</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_cli_moh_reload, "Reload MusicOnHold"),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_cli_moh_show_classes, "List MusicOnHold classes"),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_cli_moh_show_files, "List MusicOnHold file-based classes"),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_cli_moh_unregister_class, "Unregister realtime MusicOnHold class")</span><br><span> };</span><br><span> </span><br><span> static int moh_class_hash(const void *obj, const int flags)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12867">change 12867</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/c/asterisk/+/12867"/><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-Change-Id: Ibc4c6834592257c4bb90601ee299682d15befbce </div>
<div style="display:none"> Gerrit-Change-Number: 12867 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>