Skip to content

Commit

Permalink
tm: new function t_reply_error()
Browse files Browse the repository at this point in the history
- send stateful reply based on internal error code
  • Loading branch information
miconda committed Nov 2, 2023
1 parent c76444d commit ae0b671
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/modules/tm/tm.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static int t_failover_parse_reply_codes();
static int w_t_check(struct sip_msg *msg, char *str, char *str2);
static int w_t_lookup_cancel(struct sip_msg *msg, char *str, char *str2);
static int w_t_reply(struct sip_msg *msg, char *str, char *str2);
static int w_t_reply_error(struct sip_msg *msg, char *str, char *str2);
static int w_t_send_reply(struct sip_msg *msg, char *p1, char *p2);
static int w_t_release(struct sip_msg *msg, char *str, char *str2);
static int w_t_retransmit_reply(struct sip_msg *p_msg, char *foo, char *bar);
Expand Down Expand Up @@ -255,6 +256,7 @@ static cmd_export_t cmds[] = {
REQUEST_ROUTE},
{"t_reply", w_t_reply, 2, fixup_t_reply, 0,
REQUEST_ROUTE | ONREPLY_ROUTE | FAILURE_ROUTE},
{"t_reply_error", w_t_reply_error, 0, 0, 0, REQUEST_ROUTE},
{"t_send_reply", w_t_send_reply, 2, fixup_t_reply, 0,
REQUEST_ROUTE | ONREPLY_ROUTE | FAILURE_ROUTE},
{"t_retransmit_reply", w_t_retransmit_reply, 0, 0, 0, REQUEST_ROUTE},
Expand Down Expand Up @@ -1591,6 +1593,37 @@ int w_t_reply_wrp(struct sip_msg *msg, unsigned int code, char *txt)
return ki_t_reply(msg, code, &reason);
}

/**
* kemi function to send reply based on internal error code
*/
static int ki_t_reply_error(sip_msg_t *msg)
{
char err_buffer[128];
str reason;
int sip_err;
int ret;

ret = err2reason_phrase(
prev_ser_error, &sip_err, err_buffer, sizeof(err_buffer), "TM");
if(ret > 0) {
reason.s = err_buffer;
reason.len = strlen(reason.s);
return ki_t_reply(msg, sip_err, &reason);
} else {
LM_ERR("failed to get internal error reason phrase\n");
return -1;
}
}


/**
* config function to send reply based on internal error code
*/
static int w_t_reply_error(sip_msg_t *msg, char *p1, char *p2)
{
return ki_t_reply_error(msg);
}

/**
*
*/
Expand Down Expand Up @@ -3276,6 +3309,11 @@ static sr_kemi_t tm_kemi_exports[] = {
{ SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("tm"), str_init("t_reply_error"),
SR_KEMIP_INT, ki_t_reply_error,
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("tm"), str_init("t_send_reply"),
SR_KEMIP_INT, ki_t_send_reply,
{ SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_NONE,
Expand Down

0 comments on commit ae0b671

Please sign in to comment.