<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13305">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Benjamin Keith Ford: Looks good to me, but someone else must approve
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;">media_cache.c: Various CLI improvements<br><br>* Use ast_cli_completion_add() to improve performance when large number of<br> cached items are present.<br><br>* Only complete one URI for commands that only accept a single URI.<br><br>* Change command documentation to wrap at 80 characters to improve<br> readability.<br><br>Change-Id: Iedb0a2c3541e49561bc231dca2dcc0ebd8612902<br>---<br>M main/media_cache.c<br>1 file changed, 19 insertions(+), 28 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/media_cache.c b/main/media_cache.c</span><br><span>index 4493235..15f70d0 100644</span><br><span>--- a/main/media_cache.c</span><br><span>+++ b/main/media_cache.c</span><br><span>@@ -493,8 +493,7 @@</span><br><span> e->command = "media cache show all";</span><br><span> e->usage =</span><br><span> "Usage: media cache show all\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " Display a summary of all current items\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " in the media cache.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+ " Display a summary of all current items in the media cache.\n";</span><br><span> return NULL;</span><br><span> case CLI_GENERATE:</span><br><span> return NULL;</span><br><span>@@ -515,27 +514,22 @@</span><br><span> * \internal</span><br><span> * \brief CLI tab completion function for URIs</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-static char *cli_complete_uri(const char *word, int state)</span><br><span style="color: hsl(120, 100%, 40%);">+static char *cli_complete_uri(const char *word)</span><br><span> {</span><br><span> struct ast_bucket_file *bucket_file;</span><br><span> struct ao2_iterator it_media_items;</span><br><span> int wordlen = strlen(word);</span><br><span style="color: hsl(0, 100%, 40%);">- int which = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- char *result = NULL;</span><br><span> </span><br><span> it_media_items = ao2_iterator_init(media_cache, 0);</span><br><span> while ((bucket_file = ao2_iterator_next(&it_media_items))) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!strncasecmp(word, ast_sorcery_object_get_id(bucket_file), wordlen)</span><br><span style="color: hsl(0, 100%, 40%);">- && ++which > state) {</span><br><span style="color: hsl(0, 100%, 40%);">- result = ast_strdup(ast_sorcery_object_get_id(bucket_file));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strncasecmp(word, ast_sorcery_object_get_id(bucket_file), wordlen)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli_completion_add(ast_strdup(ast_sorcery_object_get_id(bucket_file)));</span><br><span> }</span><br><span> ao2_ref(bucket_file, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- if (result) {</span><br><span style="color: hsl(0, 100%, 40%);">- break;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span> }</span><br><span> ao2_iterator_destroy(&it_media_items);</span><br><span style="color: hsl(0, 100%, 40%);">- return result;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span> }</span><br><span> </span><br><span> static char *media_cache_handle_show_item(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span>@@ -550,11 +544,10 @@</span><br><span> e->command = "media cache show";</span><br><span> e->usage =</span><br><span> "Usage: media cache show <uri>\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " Display all information about a particular\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " item in the media cache.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+ " Display all information about a particular item in the media cache.\n";</span><br><span> return NULL;</span><br><span> case CLI_GENERATE:</span><br><span style="color: hsl(0, 100%, 40%);">- return cli_complete_uri(a->word, a->n);</span><br><span style="color: hsl(120, 100%, 40%);">+ return a->pos == e->args ? cli_complete_uri(a->word) : NULL;</span><br><span> }</span><br><span> </span><br><span> if (a->argc != 4) {</span><br><span>@@ -590,14 +583,13 @@</span><br><span> e->command = "media cache delete";</span><br><span> e->usage =</span><br><span> "Usage: media cache delete <uri>\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " Delete an item from the media cache.\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " Note that this will also remove any local\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " storage of the media associated with the URI,\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " and will inform the backend supporting the URI\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " scheme that it should remove the item.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+ " Delete an item from the media cache.\n\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " Note that this will also remove any local storage of the media associated\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " with the URI, and will inform the backend supporting the URI scheme that\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " it should remove the item.\n";</span><br><span> return NULL;</span><br><span> case CLI_GENERATE:</span><br><span style="color: hsl(0, 100%, 40%);">- return cli_complete_uri(a->word, a->n);</span><br><span style="color: hsl(120, 100%, 40%);">+ return a->pos == e->args ? cli_complete_uri(a->word) : NULL;</span><br><span> }</span><br><span> </span><br><span> if (a->argc != 4) {</span><br><span>@@ -622,13 +614,12 @@</span><br><span> e->command = "media cache refresh";</span><br><span> e->usage =</span><br><span> "Usage: media cache refresh <uri>\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " Ask for a refresh of a particular URI.\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " If the item does not already exist in the\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " media cache, the item will be populated from\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " the backend supporting the URI scheme.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+ " Ask for a refresh of a particular URI.\n\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " If the item does not already exist in the media cache, the item will be\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " populated from the backend supporting the URI scheme.\n";</span><br><span> return NULL;</span><br><span> case CLI_GENERATE:</span><br><span style="color: hsl(0, 100%, 40%);">- return cli_complete_uri(a->word, a->n);</span><br><span style="color: hsl(120, 100%, 40%);">+ return a->pos == e->args ? cli_complete_uri(a->word) : NULL;</span><br><span> }</span><br><span> </span><br><span> if (a->argc != 4) {</span><br><span>@@ -651,8 +642,8 @@</span><br><span> e->command = "media cache create";</span><br><span> e->usage =</span><br><span> "Usage: media cache create <uri> <file>\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " Create an item in the media cache by associating\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " a local media file with some URI.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+ " Create an item in the media cache by associating a local media file with\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " some URI.\n";</span><br><span> return NULL;</span><br><span> case CLI_GENERATE:</span><br><span> return NULL;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13305">change 13305</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/+/13305"/><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: Iedb0a2c3541e49561bc231dca2dcc0ebd8612902 </div>
<div style="display:none"> Gerrit-Change-Number: 13305 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.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>