This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Review at https://gerrit.osmocom.org/4069
CTRL: allow argument for GET commands
It is sometimes necessary to pass an argument for GET commands, e.g. to get a
variable's value for a specific subscriber. Example from osmo-hlr:
GET <id> status-ps <IMSI>
Just a 'status-ps' without the IMSI cannot return that IMSI's PS status. So far
osmo-hlr's hack is to implement status-ps as a SET command instead. That's
semantically very ugly: it's a designated write-only acting as read-only.
With this patch, we can easily allow passing a value along with a GET command.
All passing on of the value is already in place, in form of the ctrl_cmd
struct.
So far, string tokens following the variable name would be ignored. All that
this patch needs to do is pass remaining tokens along as value part.
Change-Id: I228342bedd623f6058493e1d0dea0c721d21c4e5
---
M src/ctrl/control_cmd.c
M tests/ctrl/ctrl_test.c
M tests/ctrl/ctrl_test.ok
3 files changed, 14 insertions(+), 10 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/69/4069/1
diff --git a/src/ctrl/control_cmd.c b/src/ctrl/control_cmd.c
index a0476dd..3eeb015 100644
--- a/src/ctrl/control_cmd.c
+++ b/src/ctrl/control_cmd.c
@@ -313,6 +313,7 @@
switch (cmd->type) {
case CTRL_TYPE_GET:
var = strtok_r(NULL, " \n", &saveptr);
+ val = strtok_r(NULL, "\n", &saveptr);
if (!var) {
cmd->type = CTRL_TYPE_ERROR;
cmd->reply = "GET incomplete";
@@ -320,7 +321,9 @@
goto err;
}
cmd->variable = talloc_strdup(cmd, var);
- LOGP(DLCTRL, LOGL_DEBUG, "Command: GET %s\n", cmd->variable);
+ cmd->value = talloc_strdup(cmd, val);
+ LOGP(DLCTRL, LOGL_DEBUG, "Command: GET %s%s%s\n", cmd->variable,
+ cmd->value? " " : "", cmd->value? cmd->value : "");
break;
case CTRL_TYPE_SET:
var = strtok_r(NULL, " ", &saveptr);
diff --git a/tests/ctrl/ctrl_test.c b/tests/ctrl/ctrl_test.c
index bf8abae..a55e788 100644
--- a/tests/ctrl/ctrl_test.c
+++ b/tests/ctrl/ctrl_test.c
@@ -132,6 +132,7 @@
.type = CTRL_TYPE_GET,
.id = "1",
.variable = "var",
+ .value = "i",
}
},
{ "GET 1 variable value",
@@ -139,7 +140,7 @@
.type = CTRL_TYPE_GET,
.id = "1",
.variable = "variable",
- .value = NULL,
+ .value = "value",
}
},
{ "GET 1 variable value\n",
@@ -147,7 +148,7 @@
.type = CTRL_TYPE_GET,
.id = "1",
.variable = "variable",
- .value = NULL,
+ .value = "value",
}
},
{ "GET 1 variable multiple value tokens",
@@ -155,7 +156,7 @@
.type = CTRL_TYPE_GET,
.id = "1",
.variable = "variable",
- .value = NULL,
+ .value = "multiple value tokens",
}
},
{ "GET 1 variable multiple value tokens\n",
@@ -163,7 +164,7 @@
.type = CTRL_TYPE_GET,
.id = "1",
.variable = "variable",
- .value = NULL,
+ .value = "multiple value tokens",
}
},
{ "SET 1 variable value",
diff --git a/tests/ctrl/ctrl_test.ok b/tests/ctrl/ctrl_test.ok
index bca5f4b..3812d9a 100644
--- a/tests/ctrl/ctrl_test.ok
+++ b/tests/ctrl/ctrl_test.ok
@@ -22,31 +22,31 @@
test parsing: 'GET 1 var\ni\nable'
id = '1'
variable = 'var'
-value = NULL
+value = 'i'
reply = NULL
ok
test parsing: 'GET 1 variable value'
id = '1'
variable = 'variable'
-value = NULL
+value = 'value'
reply = NULL
ok
test parsing: 'GET 1 variable value\n'
id = '1'
variable = 'variable'
-value = NULL
+value = 'value'
reply = NULL
ok
test parsing: 'GET 1 variable multiple value tokens'
id = '1'
variable = 'variable'
-value = NULL
+value = 'multiple value tokens'
reply = NULL
ok
test parsing: 'GET 1 variable multiple value tokens\n'
id = '1'
variable = 'variable'
-value = NULL
+value = 'multiple value tokens'
reply = NULL
ok
test parsing: 'SET 1 variable value'
--
To view, visit https://gerrit.osmocom.org/4069
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I228342bedd623f6058493e1d0dea0c721d21c4e5
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>