Module: kamailio Branch: master Commit: 69db5823fc9b8ee98c59d591517a1ecef91b16db URL: https://github.com/kamailio/kamailio/commit/69db5823fc9b8ee98c59d591517a1ece...
Author: Stefan Mititelu stefan.mititelu@net2phone.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2024-12-14T11:52:02+01:00
htable: Updates for topos_htable module
Export table create api functions
Fix ht_cell_pkg_copy str pointers. Otherwise, pkg cell str pointers will still point to shm memory. Set the pkg cell str pointers similar to how ht_cell_new sets the str pointers.
---
Modified: src/modules/htable/api.c Modified: src/modules/htable/api.h Modified: src/modules/htable/ht_api.c
---
Diff: https://github.com/kamailio/kamailio/commit/69db5823fc9b8ee98c59d591517a1ece... Patch: https://github.com/kamailio/kamailio/commit/69db5823fc9b8ee98c59d591517a1ece...
---
diff --git a/src/modules/htable/api.c b/src/modules/htable/api.c index 57b2b4e75f1..94095d3d5d4 100644 --- a/src/modules/htable/api.c +++ b/src/modules/htable/api.c @@ -147,6 +147,16 @@ int ht_api_count_cells_re(str *hname, str *sre, int mode) return 0; }
+int ht_api_table_spec(char *spec) +{ + return ht_table_spec(spec); +} + +int ht_api_init_tables(void) +{ + return ht_init_tables(); +} + /** * */ @@ -156,6 +166,8 @@ int bind_htable(htable_api_t *api) ERR("Invalid parameter value\n"); return -1; } + api->table_spec = ht_api_table_spec; + api->init_tables = ht_api_init_tables; api->set = ht_api_set_cell; api->get_clone = ht_api_get_cell_clone; api->rm = ht_api_del_cell; diff --git a/src/modules/htable/api.h b/src/modules/htable/api.h index 15e5207f1b2..8f67e5ca71a 100644 --- a/src/modules/htable/api.h +++ b/src/modules/htable/api.h @@ -25,6 +25,8 @@ #include "../../core/sr_module.h" #include "../../core/usr_avp.h"
+typedef int (*ht_api_table_spec_f)(char *spec); +typedef int (*ht_api_init_tables_f)(void); typedef int (*ht_api_set_cell_f)( str *hname, str *name, int type, int_str *val, int mode); typedef ht_cell_t *(*ht_api_get_cell_clone_f)(str *hname, str *name); @@ -40,6 +42,8 @@ typedef int (*ht_api_count_cells_re_f)(str *hname, str *sre, int mode);
typedef struct htable_api { + ht_api_table_spec_f table_spec; + ht_api_init_tables_f init_tables; ht_api_set_cell_f set; ht_api_get_cell_clone_f get_clone; ht_api_del_cell_f rm; diff --git a/src/modules/htable/ht_api.c b/src/modules/htable/ht_api.c index ecc49b547d6..8655c2bf443 100644 --- a/src/modules/htable/ht_api.c +++ b/src/modules/htable/ht_api.c @@ -359,6 +359,11 @@ int ht_init_tables(void) ht = _ht_root;
while(ht) { + if(ht->entries != NULL) { + ht = ht->next; + continue; + } + LM_DBG("initializing htable [%.*s] with nr. of slots: %d\n", ht->name.len, ht->name.s, ht->htsize); if(ht->name.len + sizeof("htable:expired:") < HT_EVEX_NAME_SIZE) { @@ -860,8 +865,14 @@ ht_cell_t *ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old) } } cell = (ht_cell_t *)pkg_malloc(it->msize); - if(cell != NULL) + if(cell != NULL) { memcpy(cell, it, it->msize); + + cell->name.s = (char *)cell + sizeof(ht_cell_t); + if(cell->flags & AVP_VAL_STR) { + cell->value.s.s = (char *)cell->name.s + cell->name.len + 1; + } + } ht_slot_unlock(ht, idx); return cell; }