summaryrefslogtreecommitdiffstats
path: root/nserver/src/protocol.c
blob: 69631164ef5319e50976055465377b4418daaa83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <protocol.h>

static Hashmap *hash;

int ssinit()
{
    if (hash == NULL) {
        hash = Hashmap_create(NULL, NULL);
        check(hash != NULL, "unable to create hashmap");
    }

    return 0;
 error:
    return -1;
}

int sscreate(char *key)
{
    int rc = 0;

    check(ssinit() == 0, "ssinit failed");

    // 1. create bstring from 'key'.
    bstring k = bfromcstr(key);
    check(k != NULL, "key creation failed");

    // 2. allocate fresh Stats.
    Stats *st = Stats_create();
    check(st != NULL, "stats creation failed");

    // 3. add to hashmap.
    rc = Hashmap_set(hash, k, st);
    check(rc == 0, "hashmap set failed");

    return 0;
 error:
    return -1;
}