summaryrefslogtreecommitdiff
path: root/code/core/htable/htable.c
blob: 552a03b50adf19fc7173bae54edb55561c973c2a (plain)
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
39
40
41
42
#include <core.h>

#include <string.h>

#include "hashtable.h"

static void *h_create(ECPContext *ctx) {
    int rv;
    struct hashtable *h = create_hashtable(1000, (unsigned int (*)(void *))ctx->cr.dh_pub_hash_fn, (int (*)(void *, void *))ctx->cr.dh_pub_hash_eq, NULL, NULL, NULL);
    if (h == NULL) return NULL;
        
    return h;
}

static void h_destroy(void *h) {
    hashtable_destroy(h);
}

static int h_insert(void *h, unsigned char *k, ECPConnection *v) {
    int rv = hashtable_insert(h, k, v);
    if (!rv) return ECP_ERR;
    return ECP_OK;
}

static ECPConnection *h_remove(void *h, unsigned char *k) {
    printf("REMOVE!!!\n");
    return hashtable_remove(h, k);
}

static ECPConnection *h_search(void *h, unsigned char *k) {
    return hashtable_search(h, k);
}

int ecp_htable_init(ECPHTableIface *h) {
    h->init = 1;
    h->create = h_create;
    h->destroy = h_destroy;
    h->insert = h_insert;
    h->remove = h_remove;
    h->search = h_search;
    return 0;
}