Skip to content

Commit

Permalink
mangler: accept variables for the public_ip parameter of encode_conta…
Browse files Browse the repository at this point in the history
…ct()
  • Loading branch information
rvlad-patrascu committed Jan 23, 2018
1 parent 8d3daae commit 7004223
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
35 changes: 28 additions & 7 deletions modules/mangler/contact_ops.c
Expand Up @@ -34,10 +34,21 @@
#include "../../parser/parse_uri.h"
#include "../../parser/contact/parse_contact.h"
#include "../../ut.h"
#include "../../mod_fix.h"

#include <stdio.h>
#include <string.h>

int fixup_encode_ct(void ** param, int param_no)
{
if (param_no == 1)
return 0;
else if (param_no == 2)
return fixup_spve(param);

LM_CRIT("Unknown parameter number %d\n", param_no);
return E_UNSPEC;
}

//#define DEBUG
int
Expand All @@ -50,8 +61,12 @@ encode_contact (struct sip_msg *msg, char *encoding_prefix,char *public_ip)
str newUri;
int res;
char separator;
str public_ip_str;


if (fixup_get_svalue(msg, (gparam_p)public_ip, &public_ip_str) < 0) {
LM_ERR("Failed to fetch public_ip parameter\n");
return -1;
}

/*
* I have a list of contacts in contact->parsed which is of type
Expand Down Expand Up @@ -93,7 +108,7 @@ encode_contact (struct sip_msg *msg, char *encoding_prefix,char *public_ip)
return -1;
}

res = encode_uri(uri, encoding_prefix,public_ip,separator,&newUri);
res = encode_uri(uri, encoding_prefix,&public_ip_str,separator,&newUri);
if (res != 0)
{
LM_ERR("failed encoding contact.Code %d\n", res);
Expand All @@ -115,7 +130,7 @@ encode_contact (struct sip_msg *msg, char *encoding_prefix,char *public_ip)
c = c->next;
uri = c->uri;

res = encode_uri (uri, encoding_prefix,public_ip,separator,&newUri);
res = encode_uri (uri, encoding_prefix,&public_ip_str,separator,&newUri);
if (res != 0)
{
LM_ERR("failed encode_uri.Code %d\n",res);
Expand Down Expand Up @@ -376,7 +391,7 @@ encode2format (str uri, struct uri_format *format)


int
encode_uri (str uri, char *encoding_prefix, char *public_ip,char separator, str * result)
encode_uri (str uri, char *encoding_prefix, str *public_ip,char separator, str * result)
{
struct uri_format format;
char *pos;
Expand All @@ -392,6 +407,12 @@ encode_uri (str uri, char *encoding_prefix, char *public_ip,char separator, str
LM_ERR("invalid NULL value for public_ip parameter\n");
return -2;
}

if (public_ip->s == NULL || public_ip->len == 0) {
LM_ERR("Empty public_ip parameter\n");
return -2;
}

#ifdef DEBUG
fprintf (stdout, "Primit cerere de encodare a [%.*s] cu %s-%s\n", uri.len,uri.s, encoding_prefix, public_ip);
#endif
Expand All @@ -417,7 +438,7 @@ encode_uri (str uri, char *encoding_prefix, char *public_ip,char separator, str
format.username.len + foo +
format.password.len + foo +
format.ip.len + foo + format.port.len + foo +
format.protocol.len + 1 + strlen (public_ip);
format.protocol.len + 1 + public_ip->len;
/* adding one comes from @ */
result->s = pkg_malloc (result->len);
pos = result->s;
Expand Down Expand Up @@ -447,8 +468,8 @@ encode_uri (str uri, char *encoding_prefix, char *public_ip,char separator, str
fprintf(stdout,"res= %d\npos=%s\n",res,pos);
#endif
pos = pos + res ;/* overwriting the \0 from snprintf */
memcpy (pos, public_ip, strlen (public_ip));
pos = pos + strlen (public_ip);
memcpy (pos, public_ip->s, public_ip->len);
pos = pos + public_ip->len;
memcpy (pos, uri.s + format.second, uri.len - format.second);

#ifdef DEBUG
Expand Down
4 changes: 2 additions & 2 deletions modules/mangler/contact_ops.h
Expand Up @@ -66,10 +66,10 @@ int decode_contact_header (struct sip_msg *msg, char *unused1,char *unused2);
int encode2format (str uri, struct uri_format *format);
int decode2format (str uri, char separator, struct uri_format *format);

int encode_uri (str uri, char *encoding_prefix, char *public_ip,char separator, str * result);
int encode_uri (str uri, char *encoding_prefix, str *public_ip,char separator, str * result);
int decode_uri (str uri, char separator, str * result);


int fixup_encode_ct(void ** param, int param_no);



Expand Down
2 changes: 1 addition & 1 deletion modules/mangler/mangler.c
Expand Up @@ -87,7 +87,7 @@ static cmd_export_t cmds[] =
{
{"sdp_mangle_ip", (cmd_function)sdp_mangle_ip, 2,0, 0, REQUEST_ROUTE|ONREPLY_ROUTE},
{"sdp_mangle_port", (cmd_function)sdp_mangle_port, 1,0, 0, REQUEST_ROUTE|ONREPLY_ROUTE},
{"encode_contact", (cmd_function)encode_contact,2,0, 0, REQUEST_ROUTE|ONREPLY_ROUTE},
{"encode_contact", (cmd_function)encode_contact,2,fixup_encode_ct, 0, REQUEST_ROUTE|ONREPLY_ROUTE},
{"decode_contact", (cmd_function)decode_contact,0,0, 0, REQUEST_ROUTE},
{"decode_contact_header", (cmd_function)decode_contact_header,0,0,0,REQUEST_ROUTE|ONREPLY_ROUTE},
{0, 0, 0, 0, 0, 0}
Expand Down

0 comments on commit 7004223

Please sign in to comment.