Skip to content

Commit

Permalink
textopsx: added change_reply_status_code(vcode)
Browse files Browse the repository at this point in the history
- function to change only the status code for non-2xx replies
  • Loading branch information
miconda committed Aug 2, 2020
1 parent bddf16d commit 7b95ddd
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/modules/textopsx/textopsx.c
Expand Up @@ -50,6 +50,8 @@ static int msg_apply_changes_f(sip_msg_t *msg, char *str1, char *str2);
static int change_reply_status_f(sip_msg_t *, char *, char *);
static int change_reply_status_fixup(void **param, int param_no);

static int change_reply_status_code_f(sip_msg_t *, char *, char *);

static int w_keep_hf_f(sip_msg_t *, char *, char *);

static int w_fnmatch2_f(sip_msg_t *, char *, char *);
Expand Down Expand Up @@ -84,6 +86,8 @@ static cmd_export_t cmds[] = {
REQUEST_ROUTE | ONREPLY_ROUTE},
{"change_reply_status", change_reply_status_f, 2,
change_reply_status_fixup, 0, ONREPLY_ROUTE},
{"change_reply_status_code", change_reply_status_code_f, 1,
fixup_igp_null, 0, ONREPLY_ROUTE},
{"remove_body", (cmd_function)w_remove_body_f, 0, 0, 0, ANY_ROUTE},
{"keep_hf", (cmd_function)w_keep_hf_f, 0, fixup_regexp_null, 0, ANY_ROUTE},
{"keep_hf", (cmd_function)w_keep_hf_f, 1, fixup_regexp_null, 0, ANY_ROUTE},
Expand Down Expand Up @@ -275,6 +279,49 @@ static int change_reply_status_f(
}


/**
*
*/
static int ki_change_reply_status_code(sip_msg_t *msg, int code)
{
if((code < 100) || (code > 699)) {
LM_ERR("wrong status code: %d\n", code);
return -1;
}

if(((code < 300) || (msg->REPLY_STATUS < 300))
&& (code / 100 != msg->REPLY_STATUS / 100)) {
LM_ERR("the class of provisional or "
"positive final replies cannot be changed\n");
return -1;
}

/* rewrite the status code directly in the message buffer */
msg->first_line.u.reply.statuscode = code;
msg->first_line.u.reply.status.s[2] = code % 10 + '0';
code /= 10;
msg->first_line.u.reply.status.s[1] = code % 10 + '0';
code /= 10;
msg->first_line.u.reply.status.s[0] = code + '0';

return 1l;
}

/**
*
*/
static int change_reply_status_code_f(sip_msg_t *msg, char *pcode, char *p2)
{
int code;

if(fixup_get_ivalue(msg, (gparam_t*)pcode, &code)<0) {
LM_ERR("cannot get parameters\n");
return -1;
}

return ki_change_reply_status_code(msg, code);
}

/**
*
*/
Expand Down Expand Up @@ -2195,6 +2242,11 @@ static sr_kemi_t sr_kemi_textopsx_exports[] = {
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("textopsx"), str_init("change_reply_status_code"),
SR_KEMIP_INT, ki_change_reply_status_code,
{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("textopsx"), str_init("keep_hf"),
SR_KEMIP_INT, ki_keep_hf,
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
Expand Down

0 comments on commit 7b95ddd

Please sign in to comment.