Dear All,
I've successfully created a Kamailio module(thanks to the concise documentation.) My logic requires a synchronized access to an in-memory-only hash table from multiple Kamailio child-processes. Here is what I am trying to do:
1. Create a hash table(s) upon module init
2. Insert entries from any child process (based on business logic)
3. Retrieve entries from any child process with proper locking
4. Delete entries from any child process
I would really appreciate it if anyone can point me to some samples where I can incorporate into my module the hash table functionalities that already exists in kamailio tree instead of doing my own because I would like to take advantage of Kamailio's memory managers(shared and private).
Best Regards,
Dave
Module: kamailio
Branch: master
Commit: 7ea3b97c8acf8b623563b7a9fbf4ba23ea3e9170
URL: https://github.com/kamailio/kamailio/commit/7ea3b97c8acf8b623563b7a9fbf4ba2…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-04-08T11:37:08+02:00
core: dns cache - safety checks for rdata field
---
Modified: src/core/dns_cache.c
---
Diff: https://github.com/kamailio/kamailio/commit/7ea3b97c8acf8b623563b7a9fbf4ba2…
Patch: https://github.com/kamailio/kamailio/commit/7ea3b97c8acf8b623563b7a9fbf4ba2…
---
diff --git a/src/core/dns_cache.c b/src/core/dns_cache.c
index 9a63a5bd21..7dbde8f378 100644
--- a/src/core/dns_cache.c
+++ b/src/core/dns_cache.c
@@ -4012,7 +4012,7 @@ static struct dns_hash_entry *dns_cache_clone_entry(struct dns_hash_entry *e,
size = e->total_size;
if (rdata_size) {
/* we have to extend the entry */
- rounded_size = ROUND_POINTER(size); /* size may not have been
+ rounded_size = ROUND_POINTER(size); /* size may not have been
rounded previously */
switch (e->type) {
case T_A:
@@ -4064,7 +4064,7 @@ static struct dns_hash_entry *dns_cache_clone_entry(struct dns_hash_entry *e,
/* fix the pointers inside the rr structures */
last_rr = NULL;
for (rr=new->rr_lst; rr; rr=rr->next) {
- rr->rdata = (void*)translate_pointer((char*)new, (char*)e,
+ rr->rdata = (void*)translate_pointer((char*)new, (char*)e,
(char*)rr->rdata);
if (rr->next)
rr->next = (struct dns_rr*)translate_pointer((char*)new, (char*)e,
@@ -4074,6 +4074,10 @@ static struct dns_hash_entry *dns_cache_clone_entry(struct dns_hash_entry *e,
switch(e->type){
case T_NAPTR:
+ if(rr->rdata==NULL) {
+ LM_WARN("null rdata filed for type: %u\n", e->type);
+ break;
+ }
/* there are pointers inside the NAPTR rdata stucture */
((struct naptr_rdata*)rr->rdata)->flags =
translate_pointer((char*)new, (char*)e,
@@ -4092,6 +4096,10 @@ static struct dns_hash_entry *dns_cache_clone_entry(struct dns_hash_entry *e,
((struct naptr_rdata*)rr->rdata)->repl);
break;
case T_TXT:
+ if(rr->rdata==NULL) {
+ LM_WARN("null rdata filed for type: %u\n", e->type);
+ break;
+ }
/* there are pointers inside the TXT structure */
for (i=0; i<((struct txt_rdata*)rr->rdata)->cstr_no; i++){
((struct txt_rdata*)rr->rdata)->txt[i].cstr=
@@ -4100,6 +4108,10 @@ static struct dns_hash_entry *dns_cache_clone_entry(struct dns_hash_entry *e,
}
break;
case T_EBL:
+ if(rr->rdata==NULL) {
+ LM_WARN("null rdata filed for type: %u\n", e->type);
+ break;
+ }
/* there are pointers inside the EBL structure */
((struct ebl_rdata*)rr->rdata)->separator =
translate_pointer((char*)new, (char*)e,
@@ -4140,7 +4152,7 @@ static struct dns_hash_entry *dns_cache_clone_entry(struct dns_hash_entry *e,
* If there is an existing record with the same name and value
* (ip address in case of A/AAAA record, name in case of SRV record)
* only the remaining fields are updated.
- *
+ *
* Note that permanent records cannot be overwritten unless
* the new record is also permanent. A permanent record
* completely replaces a non-permanent one.
Module: kamailio
Branch: master
Commit: 74fa6c5570d6394af8c5352bd37e21e970f1575c
URL: https://github.com/kamailio/kamailio/commit/74fa6c5570d6394af8c5352bd37e21e…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-04-08T09:38:48+02:00
core: main - coherent behaviour for fix_cfg_file()
- duplicate to build the output always, safer not to try to change the
static string defined via macro at runtime
---
Modified: src/main.c
---
Diff: https://github.com/kamailio/kamailio/commit/74fa6c5570d6394af8c5352bd37e21e…
Patch: https://github.com/kamailio/kamailio/commit/74fa6c5570d6394af8c5352bd37e21e…
---
diff --git a/src/main.c b/src/main.c
index 4dac30179c..44fb940393 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1260,14 +1260,15 @@ static struct name_lst* parse_phostport_mh(char* s, char** host, int* hlen,
-/** Update \c cfg_file variable to contain full pathname. The function updates
+/** Update \c cfg_file variable to contain full pathname or '-' (for stdin)
+ * allocated in system memory. The function updates
* the value of \c cfg_file global variable to contain full absolute pathname
- * to the main configuration file of SER. The function uses CFG_FILE macro to
+ * to the main configuration file. The function uses CFG_FILE macro to
* determine the default path to the configuration file if the user did not
* specify one using the command line option. If \c cfg_file contains an
- * absolute pathname then it is used unmodified, if it contains a relative
+ * absolute pathname then it is cloned unmodified, if it contains a relative
* pathanme than the value returned by \c getcwd function will be added at the
- * beginning. This function must be run before SER changes its current working
+ * beginning. This function must be run before changing its current working
* directory to / (in daemon mode).
* @return Zero on success, negative number
* on error.
@@ -1276,34 +1277,55 @@ int fix_cfg_file(void)
{
char* res = NULL;
size_t max_len, cwd_len, cfg_len;
-
+
if (cfg_file == NULL) cfg_file = CFG_FILE;
- if (cfg_file[0] == '/') return 0;
- if (cfg_file[0] == '-' && strlen(cfg_file)==1) return 0;
-
+ if (cfg_file[0] == '/') {
+ cfg_len = strlen(cfg_file);
+ if(cfg_len < 2) {
+ /* do not accept only '/' */
+ fprintf(stderr, "ERROR: invalid cfg file value\n");
+ return -1;
+ }
+ if ((res = malloc(cfg_len + 1)) == NULL) goto error;
+ memcpy(res, cfg_file, cfg_len);
+ cfg_file[cfg_len] = 0;
+ cfg_file = res;
+ return 0;
+ }
+ if (cfg_file[0] == '-') {
+ cfg_len = strlen(cfg_file);
+ if(cfg_len == 1) {
+ if ((res = malloc(2)) == NULL) goto error;
+ res[0] = '-';
+ res[1] = '\0';
+ cfg_file = res;
+ return 0;
+ }
+ }
+
/* cfg_file contains a relative pathname, get the current
* working directory and add it at the beginning
*/
cfg_len = strlen(cfg_file);
-
+
max_len = pathmax();
if ((res = malloc(max_len)) == NULL) goto error;
-
+
if (getcwd(res, max_len) == NULL) goto error;
cwd_len = strlen(res);
-
+
/* Make sure that the buffer is big enough */
if (cwd_len + 1 + cfg_len >= max_len) goto error;
-
+
res[cwd_len] = '/';
memcpy(res + cwd_len + 1, cfg_file, cfg_len);
-
+
res[cwd_len + 1 + cfg_len] = '\0'; /* Add terminating zero */
cfg_file = res;
return 0;
-
+
error:
- fprintf(stderr, "ERROR: Unable to fix cfg_file to contain full pathname\n");
+ fprintf(stderr, "ERROR: Unable to fix cfg file to contain full pathname\n");
if (res) free(res);
return -1;
}