[Asterisk-code-review] res_realtime: Fix 'realtime update2' argument handling (asterisk[13])

Friendly Automation asteriskteam at digium.com
Fri Jan 17 08:33:28 CST 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/13593 )

Change subject: res_realtime: Fix 'realtime update2' argument handling
......................................................................

res_realtime: Fix 'realtime update2' argument handling

The change in 9b99ef50b5d01ee8111d26efa7b926bdfaf3f980 updated the
syntax of the 'realtime update2' CLI command but did not correctly
update the calls to ast_update2_realtime().

The issue this addresses was originally opened because we aren't
allowing a SQL NULL to be set as part of the update, but this is a
limitation of the Realtime API and is not a bug.

Additionally, this patch:

* Corrects the example in the command documentation to reflect
  'update2' instead of 'update.'

* Fixes the leading spacing of the command documentation.

* Checks that the required 'NULL' literal argument is present where we
  expect it to be.

ASTERISK-21794 #close
Reported by: Cédric Bassaget

Change-Id: Idda63a5dc50d5f9bcb34c27ea3238d90f733b2cd
---
M res/res_realtime.c
1 file changed, 37 insertions(+), 19 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/res/res_realtime.c b/res/res_realtime.c
index 4291b51..d4aa638 100644
--- a/res/res_realtime.c
+++ b/res/res_realtime.c
@@ -124,32 +124,50 @@
 		e->command = "realtime update2";
 		e->usage =
 			"Usage: realtime update2 <family> <colmatch> <valuematch> [... <colmatch5> <valuematch5>] NULL <colupdate> <newvalue>\n"
-			"   Update a single variable, requiring one or more fields to match using the\n"
-			"   RealTime driver.  You must supply a family name, a column to update, a new\n"
-			"   value, and at least one column and value to match.\n"
-			"   Ex: realtime update sippeers name bobsphone ipaddr 127.0.0.1 NULL port 4343\n"
-			"   will execute SQL as\n"
-			"   UPDATE sippeers SET port='4343' WHERE name='bobsphone' and ipaddr='127.0.0.1'\n";
+			"       Update a single variable, requiring one or more fields to match using the\n"
+			"       RealTime driver. You must supply a family name, a column to update, a new\n"
+			"       value, and at least one column and value to match.\n"
+			"       Ex: realtime update2 sippeers name bobsphone ipaddr 127.0.0.1 NULL port 4343\n"
+			"       will execute SQL as\n"
+			"       UPDATE sippeers SET port='4343' WHERE name='bobsphone' and ipaddr='127.0.0.1'\n";
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
 	}
 
-	if (a->argc < 7)
+	/* Make sure we have the right number of arguments and that the required literal NULL
+	   is present */
+	if (a->argc < 8 || a->argc > 16 || a->argc % 2
+	   || strcmp(a->argv[a->argc - 3], "NULL")) {
 		return CLI_SHOWUSAGE;
+	}
 
-	if (a->argc == 7) {
-		res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL, a->argv[5], a->argv[6], SENTINEL);
-	} else if (a->argc == 9) {
-		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);
-	} else if (a->argc == 11) {
-		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);
-	} else if (a->argc == 13) {
-		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);
-	} else if (a->argc == 15) {
-		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);
-	} else {
-		return CLI_SHOWUSAGE;
+	if (a->argc == 8) {
+		res = ast_update2_realtime(
+			a->argv[2], a->argv[3], a->argv[4], SENTINEL,
+			a->argv[6], a->argv[7], SENTINEL);
+	} else if (a->argc == 10) {
+		res = ast_update2_realtime(
+			a->argv[2], a->argv[3], a->argv[4], a->argv[5],
+			a->argv[6], SENTINEL,
+			a->argv[8], a->argv[9], SENTINEL);
+	} else if (a->argc == 12) {
+		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[10], a->argv[11], SENTINEL);
+	} else if (a->argc == 14) {
+		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[12], a->argv[13], SENTINEL);
+	} else if (a->argc == 16) {
+		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[14], a->argv[15], SENTINEL);
 	}
 
 	if (res < 0) {

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13593
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Idda63a5dc50d5f9bcb34c27ea3238d90f733b2cd
Gerrit-Change-Number: 13593
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200117/86e6b21c/attachment-0001.html>


More information about the asterisk-code-review mailing list