Skip to content

Commit

Permalink
siprepo: unlink item from hash table based on rmode
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 25, 2022
1 parent 7244372 commit 5e27471
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/modules/siprepo/siprepo_data.c
Expand Up @@ -108,6 +108,25 @@ siprepo_msg_t *siprepo_msg_find(sip_msg_t *msg, str *callid, str *msgid, int lmo
return 0;
}

/**
*
*/
void siprepo_msg_unlink(siprepo_msg_t *it, unsigned int slotid)
{
if(it->prev==NULL) {
_siprepo_table[slotid].plist = it->next;
if(_siprepo_table[slotid].plist) {
_siprepo_table[slotid].plist->prev = NULL;
}
} else {
it->prev->next = it->next;
}
if(it->next!=NULL) {
it->next->prev = it->prev;
}
return;
}

/**
*
*/
Expand Down Expand Up @@ -334,9 +353,15 @@ int siprepo_msg_pull(sip_msg_t *msg, str *callid, str *msgid, str *rname,
lmsg.set_global_address = default_global_address;
lmsg.set_global_port = default_global_port;

if(rmode & SIPREPO_RMODE_RM) {
siprepo_msg_unlink(it, slotid);
shm_free(it);
}

lock_release(&_siprepo_table[slotid].lock);

if(parse_msg(lmsg.buf, lmsg.len, &lmsg) != 0) {
LM_ERR("failed to parse msg id [%.*s]\n", msgid->len, msgid->s);
lock_release(&_siprepo_table[slotid].lock);
return 1;
}
if(unlikely(parse_headers(&lmsg, HDR_FROM_F|HDR_TO_F|HDR_CALLID_F|HDR_CSEQ_F, 0)
Expand Down Expand Up @@ -394,17 +419,7 @@ void siprepo_timer_exec(unsigned int ticks, int worker, void *param)
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;
}
siprepo_msg_unlink(it, slotid);
if(elist) {
it->next = elist;
elist = it;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/siprepo/siprepo_data.h
Expand Up @@ -27,6 +27,8 @@

#include "../../core/parser/msg_parser.h"

#define SIPREPO_RMODE_RM 1

typedef struct siprepo_msg {
unsigned int hid;
int mtype;
Expand Down

0 comments on commit 5e27471

Please sign in to comment.