<p>sungtae kim has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12811">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Added unregister realtime moh class<br><br>Change-Id: Ibc4c6834592257c4bb90601ee299682d15befbce<br>---<br>M res/res_musiconhold.c<br>1 file changed, 87 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/11/12811/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><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/+/12811">change 12811</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/+/12811"/><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-Change-Id: Ibc4c6834592257c4bb90601ee299682d15befbce </div>
<div style="display:none"> Gerrit-Change-Number: 12811 </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-MessageType: newchange </div>