diff options
author | rsiddharth <s@ricketyspace.net> | 2020-04-13 19:52:19 -0400 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-04-17 20:56:37 -0400 |
commit | 1895277797fab61819ba4c666d259278f1f89c85 (patch) | |
tree | 02f5d93defa678f4bc468086a91c28cfbb13e4e4 /nserver/src/ncmd.c | |
parent | dd0d4c75b2a78f2445eaf1f13bbaa644e578026a (diff) |
nserver: ncmd.h: Add NS_STORE.
* nserver/src/ncmd.c (find_function): Add handling to find NS_STORE.
(call_function): Add handling for NS_STORE.
* nserver/src/ncmd.h (FUNCTIONS): Add NS_STORE
* nserver/tests/ncmd_tests.c (test_find_function)
(test_call_function, test_process): Update tests to check the
correctness of NS_STORE.
Diffstat (limited to 'nserver/src/ncmd.c')
-rw-r--r-- | nserver/src/ncmd.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/nserver/src/ncmd.c b/nserver/src/ncmd.c index 1c11676..6b9298c 100644 --- a/nserver/src/ncmd.c +++ b/nserver/src/ncmd.c @@ -108,6 +108,7 @@ int find_function(struct bstrList *cmd_parts) struct tagbstring fdump = bsStatic("/dump"); struct tagbstring fdelete = bsStatic("/delete"); struct tagbstring flist = bsStatic("/list"); + struct tagbstring fstore = bsStatic("/store"); check(cmd_parts != NULL, "cmd_parts is NULL"); check(cmd_parts->qty > 0, "qty check failed"); @@ -132,6 +133,8 @@ int find_function(struct bstrList *cmd_parts) return NS_DELETE; } else if (bstricmp(cmd_name, &flist) == 0) { return NS_LIST; + } else if (bstricmp(cmd_name, &fstore) == 0) { + return NS_STORE; } else { return NS_NOP; } @@ -275,6 +278,19 @@ int call_function(int func, struct bstrList *cmd_parts, char *out) free(list); break; + case NS_STORE: + if(check_args(cmd_parts, 2) != 0) { + strncpy(out, "error: command invalid\n", RSP_SIZE); + + return -1; + } + if (ssstore(bdata(cmd_parts->entry[1])) < 0) { + strncpy(out, "error: store failed\n", RSP_SIZE); + + return -1; + } + strncpy(out, "OK\n", RSP_SIZE); + break; default: strncpy(out, "error: function not found\n", RSP_SIZE); |