<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13628">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved
George Joseph: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_realtime: Fix 'realtime update2' argument handling<br><br>The change in 9b99ef50b5d01ee8111d26efa7b926bdfaf3f980 updated the<br>syntax of the 'realtime update2' CLI command but did not correctly<br>update the calls to ast_update2_realtime().<br><br>The issue this addresses was originally opened because we aren't<br>allowing a SQL NULL to be set as part of the update, but this is a<br>limitation of the Realtime API and is not a bug.<br><br>Additionally, this patch:<br><br>* Corrects the example in the command documentation to reflect<br> 'update2' instead of 'update.'<br><br>* Fixes the leading spacing of the command documentation.<br><br>* Checks that the required 'NULL' literal argument is present where we<br> expect it to be.<br><br>ASTERISK-21794 #close<br>Reported by: Cédric Bassaget<br><br>Change-Id: Idda63a5dc50d5f9bcb34c27ea3238d90f733b2cd<br>---<br>M res/res_realtime.c<br>1 file changed, 37 insertions(+), 19 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_realtime.c b/res/res_realtime.c</span><br><span>index 9a8e648..d57c2d8 100644</span><br><span>--- a/res/res_realtime.c</span><br><span>+++ b/res/res_realtime.c</span><br><span>@@ -122,32 +122,50 @@</span><br><span> e->command = "realtime update2";</span><br><span> e->usage =</span><br><span> "Usage: realtime update2 <family> <colmatch> <valuematch> [... <colmatch5> <valuematch5>] NULL <colupdate> <newvalue>\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " Update a single variable, requiring one or more fields to match using the\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " RealTime driver. You must supply a family name, a column to update, a new\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " value, and at least one column and value to match.\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " Ex: realtime update sippeers name bobsphone ipaddr 127.0.0.1 NULL port 4343\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " will execute SQL as\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " UPDATE sippeers SET port='4343' WHERE name='bobsphone' and ipaddr='127.0.0.1'\n";</span><br><span style="color: hsl(120, 100%, 40%);">+ " Update a single variable, requiring one or more fields to match using the\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " RealTime driver. You must supply a family name, a column to update, a new\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " value, and at least one column and value to match.\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " Ex: realtime update2 sippeers name bobsphone ipaddr 127.0.0.1 NULL port 4343\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " will execute SQL as\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " UPDATE sippeers SET port='4343' WHERE name='bobsphone' and ipaddr='127.0.0.1'\n";</span><br><span> return NULL;</span><br><span> case CLI_GENERATE:</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (a->argc < 7)</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Make sure we have the right number of arguments and that the required literal NULL</span><br><span style="color: hsl(120, 100%, 40%);">+ is present */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (a->argc < 8 || a->argc > 16 || a->argc % 2</span><br><span style="color: hsl(120, 100%, 40%);">+ || strcmp(a->argv[a->argc - 3], "NULL")) {</span><br><span> return CLI_SHOWUSAGE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (a->argc == 7) {</span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL, a->argv[5], a->argv[6], SENTINEL);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (a->argc == 9) {</span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL, a->argv[7], a->argv[8], SENTINEL);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (a->argc == 11) {</span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL, a->argv[9], a->argv[10], SENTINEL);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (a->argc == 13) {</span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL, a->argv[11], a->argv[12], SENTINEL);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (a->argc == 15) {</span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL, a->argv[13], a->argv[14], SENTINEL);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- return CLI_SHOWUSAGE;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (a->argc == 8) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_update2_realtime(</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[2], a->argv[3], a->argv[4], SENTINEL,</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[6], a->argv[7], SENTINEL);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (a->argc == 10) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_update2_realtime(</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[2], a->argv[3], a->argv[4], a->argv[5],</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[6], SENTINEL,</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[8], a->argv[9], SENTINEL);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (a->argc == 12) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_update2_realtime(</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[2], a->argv[3], a->argv[4], a->argv[5],</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[6], a->argv[7], a->argv[8], SENTINEL,</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[10], a->argv[11], SENTINEL);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (a->argc == 14) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_update2_realtime(</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[2], a->argv[3], a->argv[4], a->argv[5],</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[6], a->argv[7], a->argv[8], a->argv[9],</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[10], SENTINEL,</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[12], a->argv[13], SENTINEL);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (a->argc == 16) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_update2_realtime(</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[2], a->argv[3], a->argv[4], a->argv[5],</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[6], a->argv[7], a->argv[8], a->argv[9],</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[10], a->argv[11], a->argv[12], SENTINEL,</span><br><span style="color: hsl(120, 100%, 40%);">+ a->argv[14], a->argv[15], SENTINEL);</span><br><span> }</span><br><span> </span><br><span> if (res < 0) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13628">change 13628</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/+/13628"/><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: Idda63a5dc50d5f9bcb34c27ea3238d90f733b2cd </div>
<div style="display:none"> Gerrit-Change-Number: 13628 </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: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>