From 5839001872ba6afa8fae2db34a01154b9a0c897f Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Mon, 2 Jan 2017 22:04:34 +0100 Subject: [PATCH] tm: implemented rpc command tm.reply_callid --- src/modules/tm/t_reply.c | 72 ++++++++++++++++++++++++++++++++++++++++ src/modules/tm/t_reply.h | 11 +++--- src/modules/tm/tm.c | 6 ++++ 3 files changed, 84 insertions(+), 5 deletions(-) diff --git a/src/modules/tm/t_reply.c b/src/modules/tm/t_reply.c index 1abab0913ec..bb44d136c4f 100644 --- a/src/modules/tm/t_reply.c +++ b/src/modules/tm/t_reply.c @@ -2740,6 +2740,78 @@ void rpc_reply(rpc_t* rpc, void* c) } } +/* + * Syntax of "t_reply_callid" : + * code + * reason + * callid + * cseq + * to_tag + * new headers + * [Body] +*/ +void rpc_reply_callid(rpc_t* rpc, void* c) +{ + int code; + tm_cell_t *trans; + str reason = {0, 0}; + str totag = {0, 0}; + str hdrs = {0, 0}; + str body = {0, 0}; + str callid = {0, 0}; + str cseq = {0, 0}; + int n; + + if (rpc->scan(c, "d", &code) < 1) { + rpc->fault(c, 400, "Reply code expected"); + return; + } + + if (rpc->scan(c, "S", &reason) < 1) { + rpc->fault(c, 400, "Reason phrase expected"); + return; + } + + 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; + } + + if (rpc->scan(c, "S", &totag) < 1) { + rpc->fault(c, 400, "To tag expected"); + return; + } + + if (rpc->scan(c, "S", &hdrs) < 0) { + rpc->fault(c, 500, "Read error"); + return; + } + if (rpc->scan(c, "S", &body) < 0) { + rpc->fault(c, 500, "Read error"); + return; + } + + if(t_lookup_callid( &trans, callid, cseq) < 0 ) { + rpc->fault(c, 404, "Transaction not found"); + return; + } + + /* it's refcounted now, t_reply_with body unrefs for me -- I can + * continue but may not use T anymore */ + n = t_reply_with_body(trans, code, &reason, &body, + &hdrs, &totag); + + if (n<0) { + rpc->fault(c, 500, "Reply 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 297ca5ba0e2..57501a1c7a3 100644 --- a/src/modules/tm/t_reply.h +++ b/src/modules/tm/t_reply.h @@ -13,8 +13,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -33,7 +33,7 @@ /* reply processing status */ enum rps { /* something bad happened */ - RPS_ERROR=0, + RPS_ERROR=0, /* transaction completed but we still accept the reply */ RPS_PUSHED_AFTER_COMPLETION, /* reply discarded */ @@ -161,7 +161,7 @@ typedef int (*run_branch_failure_handlers_f)(struct cell*, struct sip_msg*, int, /* Retransmits the last sent inbound reply. * Returns -1 - error * 1 - OK - + *int t_retransmit_reply(struct sip_msg *); */ @@ -201,7 +201,7 @@ void on_failure_reply( struct cell* t, struct sip_msg* msg, int code, void *param ); /* set which 'reply' structure to take if only negative - replies arrive + replies arrive */ void t_on_failure( unsigned int go_to ); unsigned int get_on_failure(void); @@ -225,6 +225,7 @@ int t_pick_branch_blind(struct cell *t, int *res_code); void t_drop_replies(int v); void rpc_reply(rpc_t* rpc, void* c); +void rpc_reply_callid(rpc_t* rpc, void* c); void faked_env( struct cell *t,struct sip_msg *msg, int is_async_env); int fake_req(struct sip_msg *faked_req, diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c index 935d25fc9bf..a223e7efda9 100644 --- a/src/modules/tm/tm.c +++ b/src/modules/tm/tm.c @@ -2292,6 +2292,11 @@ static const char* rpc_reply_doc[2] = { 0 }; +static const char* rpc_reply_callid_doc[2] = { + "Reply transaction by call-id", + 0 +}; + static const char* tm_rpc_stats_doc[2] = { "Print transaction statistics.", 0 @@ -2321,6 +2326,7 @@ static const char* rpc_t_uac_wait_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.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}, {"tm.t_uac_start", rpc_t_uac_start, rpc_t_uac_start_doc, 0 },