nserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit f7217c512e54c0991af35627ecaaba3d8b7fb9be
parent 1993bfc6cee9f87ee50137bfe9bae49d513d7cbb
Author: rsiddharth <s@ricketyspace.net>
Date:   Thu, 14 Nov 2019 18:51:28 -0500

nserver: protocol.h: Add sslist.

* nserver/src/protocol.c (sslist): New function.
* nserver/src/protocol.h (sslist): New function declaration.
* nserver/tests/protocol_tests.c (test_sslist): Test fr sslist.
(all_tests): Add test_sslist.

Diffstat:
nserver/src/protocol.c | 30++++++++++++++++++++++++++++++
nserver/src/protocol.h | 3+++
nserver/tests/protocol_tests.c | 12++++++++++++
3 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c @@ -122,3 +122,33 @@ char *ssdump(char *key) error: return NULL; } + +char *sslist() +{ + check(hash != NULL, "hash not initiliazed"); + + // 1. Get keys. + DArray *ks = Hashmap_keys(hash); + check(ks != NULL, "error getting keys"); + + bstring ks_str = bfromcstr(""); + check(ks_str != NULL, "error creating keys_str"); + + int i, rc; + bstring k = NULL; + for (i = 0; i < DArray_count(ks); ++i) { + k = (bstring) DArray_get(ks, i); + check(k != NULL, "k at %d", i); + + rc = bconcat(ks_str, k); + check(rc == BSTR_OK, "bstr key concat failed"); + + rc = bconchar(ks_str, '\n'); + check(rc == BSTR_OK, "bstr newline concat failed"); + } + + return bstr2cstr(ks_str, ' '); + error: + return NULL; +} + diff --git a/nserver/src/protocol.h b/nserver/src/protocol.h @@ -1,7 +1,9 @@ #ifndef _protocol_h #define _protocol_h + #include <bstrlib.h> +#include <darray.h> #include <hashmap.h> #include <stats.h> #include <dbg.h> @@ -11,6 +13,7 @@ int ssdelete(char *key); int sssample(char *key, double s); double ssmean(char *key); char *ssdump(char *key); +char *sslist(); #endif diff --git a/nserver/tests/protocol_tests.c b/nserver/tests/protocol_tests.c @@ -86,6 +86,17 @@ char *test_ssdump() return NULL; } +char *test_sslist() +{ + char *ks = sslist(); + mu_assert(ks != NULL, "sslist failed"); + mu_assert(strlen(ks) == 19, "length check failed"); + + debug("KEYS:\n %s", ks); + + return NULL; +} + char *test_ssdelete() { int rc = 0; @@ -110,6 +121,7 @@ char *all_tests() mu_run_test(test_sssample); mu_run_test(test_ssmean); mu_run_test(test_ssdump); + mu_run_test(test_sslist); mu_run_test(test_ssdelete); return NULL;