Module: kamailio
Branch: master
Commit: 190e172fee572c169a0caa14bb08d7d271aa4f48
URL:
https://github.com/kamailio/kamailio/commit/190e172fee572c169a0caa14bb08d7d…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-04-14T10:02:50+02:00
siprepo: timer routing to clean up stored items
---
Modified: src/modules/siprepo/siprepo_data.c
Modified: src/modules/siprepo/siprepo_data.h
Modified: src/modules/siprepo/siprepo_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/190e172fee572c169a0caa14bb08d7d…
Patch:
https://github.com/kamailio/kamailio/commit/190e172fee572c169a0caa14bb08d7d…
---
diff --git a/src/modules/siprepo/siprepo_data.c b/src/modules/siprepo/siprepo_data.c
index 9010eceb6d..55deed3b75 100644
--- a/src/modules/siprepo/siprepo_data.c
+++ b/src/modules/siprepo/siprepo_data.c
@@ -43,6 +43,7 @@
static siprepo_slot_t *_siprepo_table = NULL;
extern int _siprepo_table_size;
+extern int _siprepo_expire;
/**
*
@@ -342,3 +343,47 @@ int siprepo_msg_pull(sip_msg_t *msg, str *callid, str *msgid, str
*rname)
return 0;
}
+
+/**
+ *
+ */
+void siprepo_timer_exec(unsigned int ticks, int worker, void *param)
+{
+ time_t tnow;
+ int i;
+ siprepo_msg_t *it = NULL;
+ siprepo_msg_t *elist = NULL;
+
+ tnow = time(NULL);
+ for(i=0; i<_siprepo_table_size; i++) {
+ lock_get(&_siprepo_table[i].lock);
+ for(it=_siprepo_table[i].plist; it!=NULL; it=it->next) {
+ if(it->itime+_siprepo_expire < tnow) {
+ if(it->prev==NULL) {
+ _siprepo_table[i].plist = it->next;
+ if(_siprepo_table[i].plist) {
+ _siprepo_table[i].plist->prev = NULL;
+ }
+ } else {
+ it->prev->next = it->next;
+ }
+ if(it->next!=NULL) {
+ it->next->prev = it->prev;
+ }
+ if(elist) {
+ it->next = elist;
+ elist = it;
+ } else {
+ it->next = NULL;
+ elist = it;
+ }
+ }
+ }
+ lock_release(&_siprepo_table[i].lock);
+ }
+ while(elist) {
+ it = elist;
+ elist = elist->next;
+ shm_free(it);
+ }
+}
diff --git a/src/modules/siprepo/siprepo_data.h b/src/modules/siprepo/siprepo_data.h
index f7c01fbf28..ed568fa90a 100644
--- a/src/modules/siprepo/siprepo_data.h
+++ b/src/modules/siprepo/siprepo_data.h
@@ -55,5 +55,6 @@ int siprepo_msg_set(sip_msg_t *msg, str *msgid);
int siprepo_msg_rm(sip_msg_t *msg, str *callid, str *msgid);
int siprepo_msg_pull(sip_msg_t *msg, str *callid, str *msgid, str *rname);
int siprepo_msg_check(sip_msg_t *msg);
+void siprepo_msg_timer(unsigned int ticks, int worker, void *param);
#endif
diff --git a/src/modules/siprepo/siprepo_mod.c b/src/modules/siprepo/siprepo_mod.c
index 129317b853..5a3210d425 100644
--- a/src/modules/siprepo/siprepo_mod.c
+++ b/src/modules/siprepo/siprepo_mod.c
@@ -32,6 +32,7 @@
#include "../../core/receive.h"
#include "../../core/mod_fix.h"
#include "../../core/async_task.h"
+#include "../../core/timer_proc.h"
#include "../../core/kemi.h"
#include "siprepo_data.h"
@@ -54,6 +55,8 @@ static int w_sr_msg_async_pull(sip_msg_t *msg, char *pcallid, char
*pmsgid,
static int w_sr_msg_rm(sip_msg_t *msg, char *pcallid, char *pmsgid);
static int w_sr_msg_check(sip_msg_t *msg, char *p1, char *p2);
+static void siprepo_timer_exec(unsigned int ticks, int worker, void *param);
+
/* clang-format off */
typedef struct sworker_task_param {
char *buf;
@@ -108,6 +111,7 @@ static int mod_init(void)
LM_ERR("failed to initialize hash table\n");
return -1;
}
+ register_basic_timers(_siprepo_timer_procs);
return 0;
}
@@ -116,6 +120,21 @@ static int mod_init(void)
*/
static int child_init(int rank)
{
+ int i;
+ char si_desc[MAX_PT_DESC];
+
+ if(rank!=PROC_MAIN) {
+ return 0;
+ }
+ for(i=0; i<_siprepo_timer_procs; i++) {
+ snprintf(si_desc, MAX_PT_DESC, "SIPREPO child=%d", i);
+ if(fork_basic_timer_w(PROC_TIMER, si_desc, 1 /*socks flag*/,
+ siprepo_timer_exec, i, NULL, _siprepo_timer_interval
+ /*sec*/)<0) {
+ LM_ERR("failed to start timer routine as process\n");
+ return -1; /* error */
+ }
+ }
return 0;
}
@@ -295,6 +314,11 @@ static int w_sr_msg_check(sip_msg_t *msg, char *p1, char *p2)
return ki_sr_msg_check(msg);
}
+static void siprepo_timer_exec(unsigned int ticks, int worker, void *param)
+{
+ siprepo_msg_timer(ticks, worker, param);
+}
+
/**
*
*/