瀏覽代碼

siprepo: unlink item from hash table based on rmode

Daniel-Constantin Mierla 3 年之前
父節點
當前提交
5e27471312
共有 2 個文件被更改,包括 29 次插入12 次删除
  1. 27 12
      src/modules/siprepo/siprepo_data.c
  2. 2 0
      src/modules/siprepo/siprepo_data.h

+ 27 - 12
src/modules/siprepo/siprepo_data.c

@@ -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;
+}
+
 /**
  *
  */
@@ -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)
@@ -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;

+ 2 - 0
src/modules/siprepo/siprepo_data.h

@@ -27,6 +27,8 @@
 
 #include "../../core/parser/msg_parser.h"
 
+#define SIPREPO_RMODE_RM 1
+
 typedef struct siprepo_msg {
 	unsigned int hid;
 	int mtype;