nserver

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

commit 6ada988a2f0877094e6749ca43878a86bf9a4ffb
parent 6dac5422ab8b390b8e4d6ecf0313c9c9f448f54a
Author: rsiddharth <s@ricketyspace.net>
Date:   Thu, 16 Apr 2020 21:21:47 -0400

nserver: Update sslist.

* nserver/src/protocol.c (sslist): Don't bomb whent tst is null; just
return "EMPTY". Also bcstrfree the c string return by bstr2cstr.

Diffstat:
nserver/src/protocol.c | 27+++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c @@ -192,7 +192,16 @@ void traverse_tree(void *value, void *data) char *sslist() { - check(tst != NULL, "tstree not initialized"); + char *list = NULL, *tmp = NULL; + + if (tst == NULL) { + list = (char *) calloc(7 + 1, sizeof(char)); + check_mem(list); + + list = strncpy(list, "EMPTY\n\r", 7); + + return list; + } // 1. Create "accumulator" string. bstring ks_str = bfromcstr(""); @@ -201,9 +210,23 @@ char *sslist() // 2. Accumulate keys into "accumulator" string. TSTree_traverse(tst, traverse_tree, ks_str); + // 3. Make result. + tmp = bstr2cstr(ks_str, ' '); + + list = (char *) calloc(strlen(tmp) + 1, sizeof(char)); + check_mem(list); + + list = strncpy(list, tmp, strlen(tmp)); + + // 4. Clean up. + bcstrfree(tmp); + // 3. Return result. - return bstr2cstr(ks_str, ' '); + return list; error: + if (tmp) { + bcstrfree(tmp); + } return NULL; }