Skip to content

Commit

Permalink
tm: implemented rpc command tm.reply_callid
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Jan 2, 2017
1 parent 647cacd commit 5839001
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
72 changes: 72 additions & 0 deletions src/modules/tm/t_reply.c
Expand Up @@ -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
*/
Expand Down
11 changes: 6 additions & 5 deletions src/modules/tm/t_reply.h
Expand Up @@ -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
*/

Expand All @@ -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 */
Expand Down Expand Up @@ -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 *);
*/

Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/modules/tm/tm.c
Expand Up @@ -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
Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit 5839001

Please sign in to comment.