Module: kamailio
Branch: master
Commit: d8b3c16d8b1bd99db758b389ab8147ad43c35e28
URL: 
https://github.com/kamailio/kamailio/commit/d8b3c16d8b1bd99db758b389ab8147ad43c35e28

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2025-04-03T09:03:11+02:00

tm: added rpc.retransmit_reply rpc command

---

Modified: src/modules/tm/t_reply.c
Modified: src/modules/tm/t_reply.h
Modified: src/modules/tm/tm.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/d8b3c16d8b1bd99db758b389ab8147ad43c35e28.diff
Patch: 
https://github.com/kamailio/kamailio/commit/d8b3c16d8b1bd99db758b389ab8147ad43c35e28.patch

---

diff --git a/src/modules/tm/t_reply.c b/src/modules/tm/t_reply.c
index aa899f9acc0..670260d93e8 100644
--- a/src/modules/tm/t_reply.c
+++ b/src/modules/tm/t_reply.c
@@ -3123,6 +3123,53 @@ void rpc_reply_callid(rpc_t *rpc, void *c)
        }
 }
 
+/*
+ * Syntax:
+ *
+ * ":tm.retransmit_reply:[response file]\n
+ * trans_id\n
+ * \n"
+ */
+void rpc_retransmit_reply(rpc_t *rpc, void *c)
+{
+       int ret;
+       tm_cell_t *trans;
+       tm_cell_t *orig_t = NULL;
+       int orig_branch;
+       unsigned int hash_index, label;
+       str ti;
+
+       if(rpc->scan(c, "S", &ti) < 1) {
+               rpc->fault(c, 400, "Transaction ID expected");
+               return;
+       }
+
+       if(sscanf(ti.s, "%u:%u", &hash_index, &label) != 2) {
+               ERR("Invalid trans_id (%s)\n", ti.s);
+               rpc->fault(c, 400, "Invalid transaction ID");
+               return;
+       }
+       LM_DBG("hash_index=%u label=%u\n", hash_index, label);
+
+       tm_get_tb(&orig_t, &orig_branch);
+       if(t_lookup_ident(&trans, hash_index, label) < 0) {
+               ERR("Lookup failed\n");
+               rpc->fault(c, 481, "No such transaction");
+               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;
+       }
+}
+
 /**
  * re-entrant locking of reply mutex
  */
diff --git a/src/modules/tm/t_reply.h b/src/modules/tm/t_reply.h
index 250dd2e347a..0fe1c09eb81 100644
--- a/src/modules/tm/t_reply.h
+++ b/src/modules/tm/t_reply.h
@@ -226,6 +226,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);
 
 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,
diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c
index 8bb6da0a2aa..0df18a8bd1b 100644
--- a/src/modules/tm/tm.c
+++ b/src/modules/tm/tm.c
@@ -2864,6 +2864,11 @@ static const char *rpc_reply_doc[2] = {
        0
 };
 
+static const char *rpc_retransmit_reply_doc[2] = {
+       "Retransmit the transaction reply",
+       0
+};
+
 static const char *rpc_reply_callid_doc[2] = {
        "Reply transaction by call-id",
        0
@@ -2937,6 +2942,7 @@ static const char *tm_rpc_clean_doc[2] = {
 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.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},

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to