summaryrefslogtreecommitdiffstats
path: root/nserver/src/protocol.c
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-04-11 12:53:53 -0400
committerrsiddharth <s@ricketyspace.net>2020-04-17 20:56:37 -0400
commit51a3127d1de8903cfed7837029af223f7b58db07 (patch)
treeadc2881d192ec99572e2d48106eea51c3edcd499 /nserver/src/protocol.c
parent49edbb003a0aef0fd864e5f2a12228807618a175 (diff)
nserver: Add ssstore.
* nserver/src/protocol.c (ssstore): New function definition. * nserver/src/protocol.h (ssstore): New function declaration. * nserver/tests/protocol_tests.c (test_ssstore): New test.
Diffstat (limited to 'nserver/src/protocol.c')
-rw-r--r--nserver/src/protocol.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c
index 84e7323..9c145a6 100644
--- a/nserver/src/protocol.c
+++ b/nserver/src/protocol.c
@@ -207,3 +207,27 @@ char *sslist()
return NULL;
}
+int ssstore(char *key)
+{
+ check(key != NULL && strlen(key) > 0, "key invalid");
+ check(tst != NULL, "tstree not initialized");
+
+ // 1. create bstring from 'key'.
+ Record *rec = (Record *) TSTree_search(tst, key, strlen(key));
+
+ check(rec != NULL, "record not found");
+ check(rec->st != NULL, "stats not found for key");
+ check(rec->deleted != 1, "record was deleted");
+
+ // 2. stringify the stats.
+ char *st_str = Stats_stringify(rec->st);
+ check(st_str != NULL, "stats stringify failed");
+
+ // 3. store stats in db.
+ int rc = db_store(key, st_str);
+ check(rc == 0, "db store failed");
+
+ return 0;
+ error:
+ return -1;
+}