[sr-dev] git:sr_3.0: modules_k/nathelper: handle_uri_alias() alias handling fix
Klaus Darilion
klaus.mailinglists at pernau.at
Wed Dec 30 14:31:17 CET 2009
Hi Juha!
Thanks for the fix, the new version works fine for me.
Nevertheless, I get lots of warnings:
gcc -fPIC -DPIC -g -O9 -funroll-loops -Wcast-align -m32
-minline-all-stringops -falign-loops -ftree-vectorize
-fno-strict-overflow -mtune=athlon64 -Wall -DNAME='"ser"'
-DVERSION='"2.99.99-pre3"' -DARCH='"i386"' -DOS='linux_'
-DOS_QUOTED='"linux"' -DCOMPILER='"gcc 4.3.2"' -D__CPU_i386 -D__OS_linux
-DSER_VER=2099099 -DCFG_DIR='"/usr/local/etc/ser/"' -DPKG_MALLOC
-DSHM_MEM -DSHM_MMAP -DDNS_IP_HACK -DUSE_IPV6 -DUSE_MCAST -DUSE_TCP
-DDISABLE_NAGLE -DHAVE_RESOLV_RES -DUSE_DNS_CACHE -DUSE_DNS_FAILOVER
-DUSE_DST_BLACKLIST -DUSE_NAPTR -DDBG_QM_MALLOC -DUSE_TLS -DTLS_HOOKS
-DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 -DCC_GCC_LIKE_ASM
-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD
-DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H
-DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER -DHAVE_EPOLL -DHAVE_SIGIO_RT
-DSIGINFO64_WORKARROUND -DUSE_FUTEX -DHAVE_SELECT
-DOPENSER_MOD_INTERFACE -DMOD_NAME='"nathelper"' -c nathelper.c -o
nathelper.o
nathelper.c: In function 'pv_get_rr_top_count_f':
nathelper.c:1647: warning: unused variable 'header'
nathelper.c:1646: warning: unused variable 'count'
nathelper.c: At top level:
nathelper.c:286: warning: 'rr_count_f' declared 'static' but never defined
nathelper.c:287: warning: 'rr_top_count_f' declared 'static' but never
defined
regards
Klaus
Juha Heinanen schrieb:
> Module: sip-router
> Branch: sr_3.0
> Commit: 9d98ca32bb131c0fb190e012ed0bff3f9a26557a
> URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9d98ca32bb131c0fb190e012ed0bff3f9a26557a
>
> Author: Juha Heinanen <jh at tutpro.com>
> Committer: Juha Heinanen <jh at tutpro.com>
> Date: Wed Dec 30 12:19:03 2009 +0200
>
> modules_k/nathelper: handle_uri_alias() alias handling fix
> - handle_uri_alias() now finds ;alias r-uri param even if it is not
> the first param.
>
> ---
>
> modules_k/nathelper/nathelper.c | 53 ++++++++++++++++++++++++--------------
> 1 files changed, 33 insertions(+), 20 deletions(-)
>
> diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c
> index fadc93f..27ef349 100644
> --- a/modules_k/nathelper/nathelper.c
> +++ b/modules_k/nathelper/nathelper.c
> @@ -1501,41 +1501,54 @@ add_contact_alias_f(struct sip_msg* msg, char* str1, char* str2)
> static int
> handle_ruri_alias_f(struct sip_msg* msg, char* str1, char* str2)
> {
> - str params, uri, proto;
> - char buf[MAX_URI_SIZE], *val, *sep, *trans, *at, *next, *cur_uri;
> - unsigned int len, plen, alias_len, proto_type, cur_uri_len;
> + str uri, proto;
> + char buf[MAX_URI_SIZE], *val, *sep, *trans, *at, *next, *cur_uri, *rest;
> + unsigned int len, rest_len, val_len, alias_len, proto_type, cur_uri_len,
> + ip_port_len;
>
> if ((msg->parsed_uri_ok == 0) && (parse_sip_msg_uri(msg) < 0)) {
> LM_ERR("while parsing Request-URI\n");
> return -1;
> }
> - params = msg->parsed_uri.params;
> - if (params.len == 0) {
> + rest = msg->parsed_uri.params.s;
> + rest_len = msg->parsed_uri.params.len;
> + if (rest_len == 0) {
> LM_DBG("no params\n");
> return 2;
> }
> - if ((params.len < ALIAS_LEN) ||
> - (strncmp(params.s, ALIAS, ALIAS_LEN) != 0)) {
> + while (rest_len >= ALIAS_LEN) {
> + if (strncmp(rest, ALIAS, ALIAS_LEN) == 0) break;
> + sep = memchr(rest, 59 /* ; */, rest_len);
> + if (sep == NULL) {
> + LM_DBG("no alias param\n");
> + return 2;
> + } else {
> + rest_len = rest_len - (sep - rest + 1);
> + rest = sep + 1;
> + }
> + }
> +
> + if (rest_len < ALIAS_LEN) {
> LM_DBG("no alias param\n");
> return 2;
> }
>
> /* set dst uri based on alias param value */
> - val = params.s + ALIAS_LEN;
> - plen = params.len - ALIAS_LEN;
> - sep = memchr(val, 116 /* t */, plen);
> + val = rest + ALIAS_LEN;
> + val_len = rest_len - ALIAS_LEN;
> + sep = memchr(val, 116 /* t */, val_len);
> if (sep == NULL) {
> - LM_ERR("no 't' in alias param\n");
> + LM_ERR("no 't' in alias param value\n");
> return -1;
> }
> at = &(buf[0]);
> append_str(at, "sip:", 4);
> - len = sep - val;
> - alias_len = SALIAS_LEN + len + 2 /* tn */;
> - memcpy(at, val, len);
> - at = at + len;
> + ip_port_len = sep - val;
> + alias_len = SALIAS_LEN + ip_port_len + 2 /* tn */;
> + memcpy(at, val, ip_port_len);
> + at = at + ip_port_len;
> trans = sep + 1;
> - if ((len + 2 > plen) || (*trans == ';') || (*trans == '?')) {
> + if ((ip_port_len + 2 > val_len) || (*trans == ';') || (*trans == '?')) {
> LM_ERR("no proto in alias param\n");
> return -1;
> }
> @@ -1543,7 +1556,7 @@ handle_ruri_alias_f(struct sip_msg* msg, char* str1, char* str2)
> if (proto_type != PROTO_UDP) {
> proto_type_to_str(proto_type, &proto);
> if (proto.len == 0) {
> - LM_ERR("unkown proto in alias param\n");
> + LM_ERR("unknown proto in alias param\n");
> return -1;
> }
> append_str(at, ";transport=", 11);
> @@ -1551,7 +1564,7 @@ handle_ruri_alias_f(struct sip_msg* msg, char* str1, char* str2)
> at = at + proto.len;
> }
> next = trans + 1;
> - if ((len + 2 < plen) && (*next != ';') && (*next != '?')) {
> + if ((ip_port_len + 2 < val_len) && (*next != ';') && (*next != '?')) {
> LM_ERR("invalid alias param value\n");
> return -1;
> }
> @@ -1572,11 +1585,11 @@ handle_ruri_alias_f(struct sip_msg* msg, char* str1, char* str2)
> cur_uri_len = msg->first_line.u.request.uri.len;
> }
> at = &(buf[0]);
> - len = params.s - 1 /* ; */ - cur_uri;
> + len = rest - 1 /* ; */ - cur_uri;
> memcpy(at, cur_uri, len);
> at = at + len;
> len = cur_uri_len - alias_len - len;
> - memcpy(at, params.s + alias_len - 1, len);
> + memcpy(at, rest + alias_len - 1, len);
> uri.s = &(buf[0]);
> uri.len = cur_uri_len - alias_len;
> LM_DBG("rewriting r-uri to <%.*s>\n", uri.len, uri.s);
>
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
More information about the sr-dev
mailing list