Skip to content

Commit

Permalink
nathelper: fix_nated_sdp can add a new SDP field(s)
Browse files Browse the repository at this point in the history
 - the SDP field(s) is/are added at the end of SDP
 - the SDP field(s) are provided as a thrd param to fix_nated_sdp()
 - each SDP field must be preceeded by "\r\n"
  • Loading branch information
ovidiusas committed Feb 1, 2018
1 parent bd60d31 commit ae13166
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions modules/nathelper/nathelper.c
Expand Up @@ -99,7 +99,7 @@

static int nat_uac_test_f(struct sip_msg* msg, char* str1, char* str2);
static int fix_nated_contact_f(struct sip_msg *, char *, char *);
static int fix_nated_sdp_f(struct sip_msg *, char *, char *);
static int fix_nated_sdp_f(struct sip_msg *, char *, char *, char *);
static int fix_nated_register_f(struct sip_msg *, char *, char *);
static int fixup_fix_nated_register(void** param, int param_no);
static int fixup_fix_sdp(void** param, int param_no);
Expand Down Expand Up @@ -224,6 +224,9 @@ static cmd_export_t cmds[] = {
{"fix_nated_sdp", (cmd_function)fix_nated_sdp_f, 2,
fixup_fix_sdp, 0,
REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
{"fix_nated_sdp", (cmd_function)fix_nated_sdp_f, 3,
fixup_fix_sdp, 0,
REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
{"nat_uac_test", (cmd_function)nat_uac_test_f, 1,
fixup_uint_null, 0,
REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
Expand Down Expand Up @@ -1152,10 +1155,11 @@ replace_sdp_ip(struct sip_msg* msg, str *org_body, char *line, str *ip)


static int
fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)
fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2, char* str3)
{
str body;
str ip;
str new_sdp_lines;
int level;
char *buf;
struct lump* anchor;
Expand All @@ -1164,6 +1168,8 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)
level = (int)*(unsigned int *)str1;
if (str2 && pv_printf_s( msg, (pv_elem_p)str2, &ip)!=0)
return -1;
if (str3 && pv_printf_s( msg, (pv_elem_p)str3, &new_sdp_lines)!=0)
return -1;

if ( parse_sip_body(msg)<0 || msg->body==NULL )
{
Expand Down Expand Up @@ -1218,6 +1224,19 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)
return -1;
}
}
if (str3) {
buf = pkg_malloc((new_sdp_lines.len) * sizeof(char));
if (buf == NULL) {
LM_ERR("out of pkg memory\n");
return -1;
}
memcpy(buf, new_sdp_lines.s, new_sdp_lines.len);
if (insert_new_lump_after(anchor, buf, new_sdp_lines.len, 0) == NULL) {
LM_ERR("insert_new_lump_after failed 3\n");
pkg_free(buf);
return -1;
}
}
}

if (level & FIX_ORGIP) {
Expand Down

0 comments on commit ae13166

Please sign in to comment.