libqaeda

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

commit ad121546c1b5b01443aa6e97e6f7b13a81033a39
parent 3f0da95564e3de09593b073b65716a041012b163
Author: lash <dev@holbrook.no>
Date:   Mon,  3 Mar 2025 13:27:16 +0000

Add store free

Diffstat:
Msrc/lq/store.h | 1+
Msrc/store/dummy.c | 4++++
Msrc/store/file.c | 4++++
Msrc/store/mem.c | 8++++++++
Msrc/test/test_msg.c | 1+
Msrc/test/test_trust.c | 13++++++++++---
6 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/lq/store.h b/src/lq/store.h @@ -29,6 +29,7 @@ struct lq_store_t { void *userdata; int (*get)(enum payload_e typ, LQStore *store, const char *key, size_t key_len, char *value, size_t *value_len); int (*put)(enum payload_e typ, LQStore *store, const char *key, size_t *key_len, char *value, size_t value_len); + void (*free)(LQStore *store); }; diff --git a/src/store/dummy.c b/src/store/dummy.c @@ -28,9 +28,13 @@ int lq_dummy_content_put(enum payload_e typ, LQStore *store, const char *key, si return 0; } +void lq_dummy_content_free(LQStore *store) { +} + struct lq_store_t LQDummyContent = { .store_typ = store_typ_dummy, .userdata = NULL, .get = lq_dummy_content_get, .put = lq_dummy_content_put, + .free = lq_dummy_content_free, }; diff --git a/src/store/file.c b/src/store/file.c @@ -104,11 +104,15 @@ int lq_file_content_put(enum payload_e typ, LQStore *store, const char *key, siz return ERR_OK; } +void lq_file_content_free(LQStore *store) { +} + struct lq_store_t LQFileContent = { .store_typ = store_typ_file, .userdata = "", .get = lq_file_content_get, .put = lq_file_content_put, + .free = lq_file_content_free, }; //LQStore* lq_file_content_new(const char *dir) { diff --git a/src/store/mem.c b/src/store/mem.c @@ -91,9 +91,17 @@ int lq_mem_content_put(enum payload_e typ, LQStore *store, const char *key, size return ERR_OK; } +void lq_mem_content_free(LQStore *store) { + if (store->userdata != NULL) { + hashmap_free((struct hashmap*)store->userdata); + store->userdata = NULL; + } +} + struct lq_store_t LQMemContent = { .store_typ = store_typ_mem, .userdata = NULL, .get = lq_mem_content_get, .put = lq_mem_content_put, + .free = lq_mem_content_free, }; diff --git a/src/test/test_msg.c b/src/test/test_msg.c @@ -43,6 +43,7 @@ START_TEST(check_msg_symmetric) { ck_assert_ptr_nonnull(msg); ck_assert_int_eq(r, 0); lq_msg_free(msg); + store.free(&store); } END_TEST diff --git a/src/test/test_trust.c b/src/test/test_trust.c @@ -65,6 +65,8 @@ START_TEST(check_trust_none) { store->put(LQ_CONTENT_KEY, store, pubkey_bob->lokey, &pubkey_bob->lolen, (unsigned char*)trust_bob, 2); r = lq_trust_check(pubkey_bob, store, TRUST_MATCH_NONE, flag_test); ck_assert_int_eq(r, 1000000); + + store->free(store); } END_TEST @@ -85,6 +87,8 @@ START_TEST(check_trust_one) { flag_test[1] = 0x40; r = lq_trust_check(pubkey_alice, store, TRUST_MATCH_ONE, (const unsigned char*)flag_test); ck_assert_int_eq(r, 1000000); + + store->free(store); } END_TEST @@ -106,6 +110,7 @@ START_TEST(check_trust_best) { r = lq_trust_check(pubkey_alice, store, TRUST_MATCH_BEST, (const unsigned char*)flag_test); ck_assert_int_eq(r, 600000); + store->free(store); } END_TEST @@ -136,6 +141,8 @@ START_TEST(check_trust_all) { flag_test[1] = 0x78; r = lq_trust_check(pubkey_alice, store, TRUST_MATCH_ALL, (const unsigned char*)flag_test); ck_assert_int_eq(r, 1000000); + + store->free(store); } END_TEST @@ -145,10 +152,10 @@ Suite * common_suite(void) { s = suite_create("trust"); tc = tcase_create("check"); - //tcase_add_test(tc, check_trust_none); - //tcase_add_test(tc, check_trust_one); + tcase_add_test(tc, check_trust_none); + tcase_add_test(tc, check_trust_one); tcase_add_test(tc, check_trust_best); - //tcase_add_test(tc, check_trust_all); + tcase_add_test(tc, check_trust_all); suite_add_tcase(s, tc); return s;