summaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2011-08-18 13:48:26 +0200
committerHarald Welte <laforge@gnumonks.org>2014-08-21 15:34:14 +0200
commit5d9b203db61b1840562b040411ca69a0fed9d80f (patch)
tree91da83a519f5ce0c7478bd99d5815bb61417d6af /openbsc
parentbed515f5d6b049eccc2b135be17874156f598705 (diff)
ctrl: Improve error messages in ctrl_cmd_handle
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/src/libctrl/control_if.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/openbsc/src/libctrl/control_if.c b/openbsc/src/libctrl/control_if.c
index 19f1013d..98748d58 100644
--- a/openbsc/src/libctrl/control_if.c
+++ b/openbsc/src/libctrl/control_if.c
@@ -143,8 +143,10 @@ int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
vline = cmd_make_strvec(request);
talloc_free(request);
- if (!vline)
+ if (!vline) {
+ cmd->reply = "cmd_make_strvec failed.";
goto err;
+ }
for (i=0;i<vector_active(vline);i++) {
token = vector_slot(vline, i);
@@ -154,47 +156,47 @@ int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
if (!strcmp(token, "net")) {
net = gsmnet;
if (!net)
- break;
+ goto err_missing;
cmd->node = net;
node = CTRL_NODE_NET;
} else if (!strcmp(token, "bts")) {
if (!net)
- break;
+ goto err_missing;
i++;
if (i >= vector_active(vline))
- break;
+ goto err_index;
token = vector_slot(vline, i);
num = atoi(token);
bts = gsm_bts_num(net, num);
if (!bts)
- break;
+ goto err_missing;
cmd->node = bts;
node = CTRL_NODE_BTS;
} else if (!strcmp(token, "trx")) {
if (!bts)
- break;
+ goto err_missing;
i++;
if (i >= vector_active(vline))
- break;
+ goto err_index;
token = vector_slot(vline, i);
num = atoi(token);
trx = gsm_bts_trx_num(bts, num);
if (!trx)
- break;
+ goto err_missing;
cmd->node = trx;
node = CTRL_NODE_TRX;
} else if (!strcmp(token, "ts")) {
if (!trx)
- break;
+ goto err_missing;
i++;
if (i >= vector_active(vline))
- break;
+ goto err_index;
token = vector_slot(vline, i);
num = atoi(token);
if ((num >= 0) && (num < TRX_NR_TS))
ts = &trx->ts[num];
if (!ts)
- break;
+ goto err_missing;
cmd->node = ts;
node = CTRL_NODE_TS;
} else {
@@ -208,7 +210,7 @@ int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
cmds_vec = vector_lookup(ctrl_node_vec, node);
if (!cmds_vec) {
- cmd->reply = "Command not found";
+ cmd->reply = "Command not found.";
vector_free(cmdvec);
break;
}
@@ -218,6 +220,9 @@ int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
vector_free(cmdvec);
break;
}
+
+ if (i+1 == vector_active(vline))
+ cmd->reply = "Command not present.";
}
cmd_free_strvec(vline);
@@ -226,6 +231,17 @@ err:
if (ret == CTRL_CMD_ERROR)
cmd->type = CTRL_TYPE_ERROR;
return ret;
+
+err_missing:
+ cmd_free_strvec(vline);
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "Error while resolving object";
+ return ret;
+err_index:
+ cmd_free_strvec(vline);
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "Error while parsing the index.";
+ return ret;
}
static void control_close_conn(struct ctrl_connection *ccon)