[Asterisk-code-review] res_realtime: Fix 'realtime update2' argument handling (asterisk[13])
Sean Bright
asteriskteam at digium.com
Tue Jan 14 10:06:34 CST 2020
Sean Bright has uploaded this change for review. ( 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(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/93/13593/1
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-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200114/2300d3df/attachment-0001.html>
More information about the asterisk-code-review
mailing list