浏览代码

tm: added rpc command tm.retransmit_reply_callid

Daniel-Constantin Mierla 5 月之前
父节点
当前提交
ba662a5001
共有 3 个文件被更改,包括 52 次插入0 次删除
  1. 44 0
      src/modules/tm/t_reply.c
  2. 1 0
      src/modules/tm/t_reply.h
  3. 7 0
      src/modules/tm/tm.c

+ 44 - 0
src/modules/tm/t_reply.c

@@ -3123,6 +3123,50 @@ void rpc_reply_callid(rpc_t *rpc, void *c)
 	}
 }
 
+/*
+ * Syntax:
+ *
+ * ":tm.retransmit_reply:[response file]\n
+ * callid
+ * cseq
+ * \n"
+ */
+void rpc_retransmit_reply_callid(rpc_t *rpc, void *c)
+{
+	int ret;
+	tm_cell_t *trans;
+	tm_cell_t *orig_t = NULL;
+	int orig_branch;
+	str callid = {0, 0};
+	str cseq = {0, 0};
+
+	if(rpc->scan(c, "S", &callid) < 1) {
+		rpc->fault(c, 400, "Call-ID expected");
+		return;
+	}
+
+	if(rpc->scan(c, "S", &cseq) < 1) {
+		rpc->fault(c, 400, "CSeq expected");
+		return;
+	}
+
+	tm_get_tb(&orig_t, &orig_branch);
+	if(t_lookup_callid(&trans, callid, cseq) < 0) {
+		rpc->fault(c, 404, "Transaction not found");
+		return;
+	}
+	/* it is refcounted now */
+	ret = t_retransmit_reply(trans);
+	UNREF(trans);
+	tm_set_tb(orig_t, orig_branch);
+
+	if(ret < 0) {
+		LM_ERR("Reply retransmission failed\n");
+		rpc->fault(c, 500, "Reply retransmission failed");
+		return;
+	}
+}
+
 /*
  * Syntax:
  *

+ 1 - 0
src/modules/tm/t_reply.h

@@ -227,6 +227,7 @@ void t_drop_replies(int v);
 void rpc_reply(rpc_t *rpc, void *c);
 void rpc_reply_callid(rpc_t *rpc, void *c);
 void rpc_retransmit_reply(rpc_t *rpc, void *c);
+void rpc_retransmit_reply_callid(rpc_t *rpc, void *c);
 
 int faked_env(struct cell *t, struct sip_msg *msg, int is_async_env);
 struct sip_msg *fake_req(struct sip_msg *shmem_msg, int extra_flags,

+ 7 - 0
src/modules/tm/tm.c

@@ -2869,6 +2869,11 @@ static const char *rpc_retransmit_reply_doc[2] = {
 	0
 };
 
+static const char *rpc_retransmit_reply_callid_doc[2] = {
+	"Retransmit the transaction reply by call-id",
+	0
+};
+
 static const char *rpc_reply_callid_doc[2] = {
 	"Reply transaction by call-id",
 	0
@@ -2943,6 +2948,8 @@ static rpc_export_t tm_rpc[] = {
 	{"tm.cancel", rpc_cancel, rpc_cancel_doc, 0},
 	{"tm.reply", rpc_reply, rpc_reply_doc, 0},
 	{"tm.retransmit_reply", rpc_retransmit_reply, rpc_retransmit_reply_doc, 0},
+	{"tm.retransmit_reply_callid", rpc_retransmit_reply_callid,
+		rpc_retransmit_reply_callid_doc, 0},
 	{"tm.reply_callid", rpc_reply_callid, rpc_reply_callid_doc, 0},
 	{"tm.stats", tm_rpc_stats, tm_rpc_stats_doc, 0},
 	{"tm.hash_stats", tm_rpc_hash_stats, tm_rpc_hash_stats_doc, 0},