Hello,
In some cases it may be useful to pre-fill only part of user Via and let NTA
fill out the rest of Via. This is particularly useful with respect to v_host
and v_port. Currently, NTA does not allow that. Attached is a simple patch
against sofia-sip-1.12.9 with the change and a test case for the new
functionality.
The patch is also attached for exactness.
Best regards,
Stas.
- NULL host or port in user-supplied Via header will be filled
automaticaly by NTA, just like branch and rport params;
- added related test case to test_nta_api.c;
---
libsofia-sip-ua/nta/nta.c | 4 +-
libsofia-sip-ua/nta/test_nta_api.c | 85 ++++++++++++++++++++++++++++++++++++
2 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/libsofia-sip-ua/nta/nta.c b/libsofia-sip-ua/nta/nta.c
index f8bcce1..015de52 100644
--- a/libsofia-sip-ua/nta/nta.c
+++ b/libsofia-sip-ua/nta/nta.c
@@ -2070,12 +2070,12 @@ int outgoing_insert_via(nta_outgoing_t *orq,
clear = 1, v->v_protocol = via->v_protocol;
/* XXX - should we do this? */
- if (!user_via &&
+ if ((!user_via || !v->v_host) &&
via->v_host != v->v_host &&
str0cmp(via->v_host, v->v_host))
clear = 1, v->v_host = via->v_host;
- if ((!user_via ||
+ if ((!user_via || !v->v_port ||
/* Replace port in user Via only if we use udp and no rport */
(v->v_protocol == sip_transport_udp && !v->v_rport &&
!orq->orq_stateless)) &&
diff --git a/libsofia-sip-ua/nta/test_nta_api.c
b/libsofia-sip-ua/nta/test_nta_api.c
index 9862722..0cec28f 100644
--- a/libsofia-sip-ua/nta/test_nta_api.c
+++ b/libsofia-sip-ua/nta/test_nta_api.c
@@ -865,6 +865,90 @@ static int api_test_dialogs(agent_t *ag)
}
+/* Test that NULL host and/or port fields of user supplied Via header are
+ filled in automaticaly */
+int api_test_user_via_fillin(agent_t *ag)
+{
+ su_home_t home[1];
+ su_root_t *root;
+ nta_agent_t *nta;
+ nta_leg_t *leg;
+ nta_outgoing_t *orq0, *orq1;
+ msg_t *msg0, *msg1;
+ sip_t *sip0, *sip1;
+ sip_via_t *via0, *via1;
+ sip_via_t via[1];
+ static char *via_params[] = { "param1=value1", "param2=value2" };
+ int i;
+
+ BEGIN();
+
+ memset(home, 0, sizeof home);
+ su_home_init(home);
+
+ TEST_1(root = su_root_create(NULL));
+
+ TEST_1(nta = nta_agent_create(root,
+ (url_string_t *)"sip:*:*",
+ NULL,
+ NULL,
+ TAG_END()));
+ TEST_1(leg = nta_leg_tcreate(nta, NULL, NULL,
+ NTATAG_NO_DIALOG(1),
+ TAG_END()));
+
+ /* This creates a delayed response message */
+ orq0 = nta_outgoing_tcreate(leg, outgoing_callback, ag, NULL,
+ SIP_METHOD_MESSAGE,
+ URL_STRING_MAKE("sip:foo.bar;transport=none"),
+ SIPTAG_FROM_STR("<sip:bar.foo>"),
+ SIPTAG_TO_STR("<sip:foo.bar>"),
+ TAG_END());
+ TEST_1(orq0);
+ TEST_1(msg0 = nta_outgoing_getrequest(orq0));
+ TEST_1(sip0 = sip_object(msg0));
+ TEST_1(via0 = sip0->sip_via);
+
+ /* create user Via template to be filled in by NTA */
+ sip_via_init(via);
+ via->v_protocol = "*";
+ for (i = 0; i < sizeof(via_params)/sizeof(via_params[0]); i++)
+ sip_via_add_param(home,via,via_params[i]); /* add param to the template
*/
+
+ /* This creates a delayed response message */
+ orq1 = nta_outgoing_tcreate(leg, outgoing_callback, ag, NULL,
+ SIP_METHOD_MESSAGE,
+ URL_STRING_MAKE("sip:foo.bar;transport=none"),
+ SIPTAG_FROM_STR("<sip:bar.foo>"),
+ SIPTAG_TO_STR("<sip:foo.bar>"),
+ NTATAG_USER_VIA(1),
+ SIPTAG_VIA(via),
+ TAG_END());
+ TEST_1(orq1);
+ TEST_1(msg1 = nta_outgoing_getrequest(orq1));
+ TEST_1(sip1 = sip_object(msg1));
+ TEST_1(via1 = sip1->sip_via);
+
+ /* check that template has been filled correctly */
+ TEST_S(via0->v_protocol,via1->v_protocol);
+ TEST_S(via0->v_host,via1->v_host);
+ TEST_S(via0->v_port,via1->v_port);
+ /* check that the parameter has been preserved */
+ for (i = 0; i < sizeof(via_params)/sizeof(via_params[0]); i++)
+ TEST_S(via1->v_params[i],via_params[i]);
+
+ TEST_VOID(nta_outgoing_destroy(orq0));
+ TEST_VOID(nta_outgoing_destroy(orq1));
+ TEST_VOID(nta_leg_destroy(leg));
+ TEST_VOID(nta_agent_destroy(nta));
+
+ TEST_VOID(su_root_destroy(root));
+ TEST_VOID(su_home_deinit(home));
+
+ END();
+}
+
+
int outgoing_default(agent_t *ag,
nta_outgoing_t *orq,
sip_t const *sip)
@@ -1426,6 +1510,7 @@ int main(int argc, char *argv[])
retval |= api_test_tport(ag); SINGLE_FAILURE_CHECK();
retval |= api_test_dialogs(ag); SINGLE_FAILURE_CHECK();
retval |= api_test_default(ag); SINGLE_FAILURE_CHECK();
+ retval |= api_test_user_via_fillin(ag); SINGLE_FAILURE_CHECK();
}
retval |= api_test_deinit(ag); fflush(stdout);
--
1.5.6.5
From d0cbd50e833bec98fcf2c1a06f497f08be3922d0 Mon Sep 17 00:00:00 2001
From: Stas Maximov <[EMAIL PROTECTED]>
Date: Mon, 1 Dec 2008 21:42:33 -0800
Subject: [PATCH] nta: NULL host and port in user Via are filled automaticaly
- NULL host or port in user-supplied Via header will be filled
automaticaly by NTA, just like branch and rport params;
- added related test case to test_nta_api.c;
Signed-off-by: Stas Maximov <[EMAIL PROTECTED]>
---
libsofia-sip-ua/nta/nta.c | 4 +-
libsofia-sip-ua/nta/test_nta_api.c | 85 ++++++++++++++++++++++++++++++++++++
2 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/libsofia-sip-ua/nta/nta.c b/libsofia-sip-ua/nta/nta.c
index f8bcce1..015de52 100644
--- a/libsofia-sip-ua/nta/nta.c
+++ b/libsofia-sip-ua/nta/nta.c
@@ -2070,12 +2070,12 @@ int outgoing_insert_via(nta_outgoing_t *orq,
clear = 1, v->v_protocol = via->v_protocol;
/* XXX - should we do this? */
- if (!user_via &&
+ if ((!user_via || !v->v_host) &&
via->v_host != v->v_host &&
str0cmp(via->v_host, v->v_host))
clear = 1, v->v_host = via->v_host;
- if ((!user_via ||
+ if ((!user_via || !v->v_port ||
/* Replace port in user Via only if we use udp and no rport */
(v->v_protocol == sip_transport_udp && !v->v_rport &&
!orq->orq_stateless)) &&
diff --git a/libsofia-sip-ua/nta/test_nta_api.c b/libsofia-sip-ua/nta/test_nta_api.c
index 9862722..0cec28f 100644
--- a/libsofia-sip-ua/nta/test_nta_api.c
+++ b/libsofia-sip-ua/nta/test_nta_api.c
@@ -865,6 +865,90 @@ static int api_test_dialogs(agent_t *ag)
}
+/* Test that NULL host and/or port fields of user supplied Via header are
+ filled in automaticaly */
+int api_test_user_via_fillin(agent_t *ag)
+{
+ su_home_t home[1];
+ su_root_t *root;
+ nta_agent_t *nta;
+ nta_leg_t *leg;
+ nta_outgoing_t *orq0, *orq1;
+ msg_t *msg0, *msg1;
+ sip_t *sip0, *sip1;
+ sip_via_t *via0, *via1;
+ sip_via_t via[1];
+ static char *via_params[] = { "param1=value1", "param2=value2" };
+ int i;
+
+ BEGIN();
+
+ memset(home, 0, sizeof home);
+ su_home_init(home);
+
+ TEST_1(root = su_root_create(NULL));
+
+ TEST_1(nta = nta_agent_create(root,
+ (url_string_t *)"sip:*:*",
+ NULL,
+ NULL,
+ TAG_END()));
+ TEST_1(leg = nta_leg_tcreate(nta, NULL, NULL,
+ NTATAG_NO_DIALOG(1),
+ TAG_END()));
+
+ /* This creates a delayed response message */
+ orq0 = nta_outgoing_tcreate(leg, outgoing_callback, ag, NULL,
+ SIP_METHOD_MESSAGE,
+ URL_STRING_MAKE("sip:foo.bar;transport=none"),
+ SIPTAG_FROM_STR("<sip:bar.foo>"),
+ SIPTAG_TO_STR("<sip:foo.bar>"),
+ TAG_END());
+ TEST_1(orq0);
+ TEST_1(msg0 = nta_outgoing_getrequest(orq0));
+ TEST_1(sip0 = sip_object(msg0));
+ TEST_1(via0 = sip0->sip_via);
+
+ /* create user Via template to be filled in by NTA */
+ sip_via_init(via);
+ via->v_protocol = "*";
+ for (i = 0; i < sizeof(via_params)/sizeof(via_params[0]); i++)
+ sip_via_add_param(home,via,via_params[i]); /* add param to the template */
+
+ /* This creates a delayed response message */
+ orq1 = nta_outgoing_tcreate(leg, outgoing_callback, ag, NULL,
+ SIP_METHOD_MESSAGE,
+ URL_STRING_MAKE("sip:foo.bar;transport=none"),
+ SIPTAG_FROM_STR("<sip:bar.foo>"),
+ SIPTAG_TO_STR("<sip:foo.bar>"),
+ NTATAG_USER_VIA(1),
+ SIPTAG_VIA(via),
+ TAG_END());
+ TEST_1(orq1);
+ TEST_1(msg1 = nta_outgoing_getrequest(orq1));
+ TEST_1(sip1 = sip_object(msg1));
+ TEST_1(via1 = sip1->sip_via);
+
+ /* check that template has been filled correctly */
+ TEST_S(via0->v_protocol,via1->v_protocol);
+ TEST_S(via0->v_host,via1->v_host);
+ TEST_S(via0->v_port,via1->v_port);
+ /* check that the parameter has been preserved */
+ for (i = 0; i < sizeof(via_params)/sizeof(via_params[0]); i++)
+ TEST_S(via1->v_params[i],via_params[i]);
+
+ TEST_VOID(nta_outgoing_destroy(orq0));
+ TEST_VOID(nta_outgoing_destroy(orq1));
+ TEST_VOID(nta_leg_destroy(leg));
+ TEST_VOID(nta_agent_destroy(nta));
+
+ TEST_VOID(su_root_destroy(root));
+ TEST_VOID(su_home_deinit(home));
+
+ END();
+}
+
+
int outgoing_default(agent_t *ag,
nta_outgoing_t *orq,
sip_t const *sip)
@@ -1426,6 +1510,7 @@ int main(int argc, char *argv[])
retval |= api_test_tport(ag); SINGLE_FAILURE_CHECK();
retval |= api_test_dialogs(ag); SINGLE_FAILURE_CHECK();
retval |= api_test_default(ag); SINGLE_FAILURE_CHECK();
+ retval |= api_test_user_via_fillin(ag); SINGLE_FAILURE_CHECK();
}
retval |= api_test_deinit(ag); fflush(stdout);
--
1.5.6.5
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel