Commit 6e488292 authored by Pekka Pessi's avatar Pekka Pessi

nta: nta_msg_request_complete() now adds header from request-URI query part to request message

Headers as well as method parameter are stripped away from request-URI.

darcs-hash:20061005141055-65a35-d45a8f0a9641ed09d79ac9e06a1f599c34468a24.gz
parent 7795afe9
......@@ -2959,8 +2959,13 @@ int nta_msg_ackbye(nta_agent_t *agent, msg_t *msg)
* @param method_name method name (if @a method == #sip_method_unknown)
* @param request_uri request URI
*
* If @a request_uri contains query part, the query part is converted as SIP
* headers and added to the request.
*
* @retval 0 when successful
* @retval -1 upon an error
*
* @sa nta_outgoing_mcreate(), nta_outgoing_tcreate()
*/
int nta_msg_request_complete(msg_t *msg,
nta_leg_t *leg,
......@@ -2970,41 +2975,15 @@ int nta_msg_request_complete(msg_t *msg,
{
su_home_t *home = msg_home(msg);
sip_t *sip = sip_object(msg);
sip_to_t const *to;
sip_cseq_t *cseq;
uint32_t seq;
url_t reg_url[1];
url_string_t const *original = request_uri;
if (!leg || !msg)
return -1;
if (!sip->sip_max_forwards)
sip_add_dup(msg, sip, (sip_header_t *)leg->leg_agent->sa_max_forwards);
if (!sip->sip_call_id) {
if (leg->leg_id)
sip->sip_call_id = sip_call_id_dup(home, leg->leg_id);
else
sip->sip_call_id = sip_call_id_create(home, NULL);
}
if (!sip->sip_from)
sip->sip_from = sip_from_dup(home, leg->leg_local);
else if (leg->leg_local && leg->leg_local->a_tag &&
(!sip->sip_from->a_tag ||
strcasecmp(sip->sip_from->a_tag, leg->leg_local->a_tag)))
sip_from_tag(home, sip->sip_from, leg->leg_local->a_tag);
if (sip->sip_from && !sip->sip_from->a_tag) {
sip_fragment_clear(sip->sip_from->a_common);
sip_from_add_param(home, sip->sip_from,
nta_agent_newtag(home, "tag=%s", leg->leg_agent));
}
if (!sip->sip_to)
sip->sip_to = sip_to_dup(home, leg->leg_remote);
else if (leg->leg_remote && leg->leg_remote->a_tag)
sip_to_tag(home, sip->sip_to, leg->leg_remote->a_tag);
if (!sip->sip_route && leg->leg_route) {
if (leg->leg_loose_route) {
if (leg->leg_target) {
......@@ -3030,21 +3009,27 @@ int nta_msg_request_complete(msg_t *msg,
if (!request_uri && sip->sip_request)
request_uri = (url_string_t *)sip->sip_request->rq_url;
if (!request_uri && sip->sip_to) {
to = sip->sip_to ? sip->sip_to : leg->leg_remote;
if (!request_uri && to) {
if (method != sip_method_register)
request_uri = (url_string_t *)sip->sip_to->a_url;
request_uri = (url_string_t *)to->a_url;
else {
/* Remove user part from REGISTER requests */
*reg_url = *sip->sip_to->a_url;
*reg_url = *to->a_url;
reg_url->url_user = reg_url->url_password = NULL;
request_uri = (url_string_t *)reg_url;
}
}
if (!request_uri)
return -1;
if (method || method_name) {
sip_request_t *rq = sip->sip_request;
int use_headers =
request_uri == original || (url_t *)request_uri == rq->rq_url;
if (!rq
|| request_uri != (url_string_t *)rq->rq_url
......@@ -3057,11 +3042,59 @@ int nta_msg_request_complete(msg_t *msg,
if (msg_header_insert(msg, (msg_pub_t *)sip, (msg_header_t *)rq) < 0)
return -1;
}
/* @RFC3261 table 1 (page 152):
* Req-URI cannot contain method parameter or headers
*/
if (rq->rq_url->url_params) {
rq->rq_url->url_params =
url_strip_param_string((char *)rq->rq_url->url_params, "method");
sip_fragment_clear(rq->rq_common);
}
if (rq->rq_url->url_headers) {
if (use_headers) {
char *s = url_query_as_header_string(msg_home(msg),
rq->rq_url->url_headers);
if (!s)
return -1;
msg_header_parse_str(msg, (msg_pub_t*)sip, s);
}
rq->rq_url->url_headers = NULL, sip_fragment_clear(rq->rq_common);
}
}
if (!sip->sip_request)
return -1;
if (!sip->sip_max_forwards)
sip_add_dup(msg, sip, (sip_header_t *)leg->leg_agent->sa_max_forwards);
if (!sip->sip_call_id) {
if (leg->leg_id)
sip->sip_call_id = sip_call_id_dup(home, leg->leg_id);
else
sip->sip_call_id = sip_call_id_create(home, NULL);
}
if (!sip->sip_from)
sip->sip_from = sip_from_dup(home, leg->leg_local);
else if (leg->leg_local && leg->leg_local->a_tag &&
(!sip->sip_from->a_tag ||
strcasecmp(sip->sip_from->a_tag, leg->leg_local->a_tag)))
sip_from_tag(home, sip->sip_from, leg->leg_local->a_tag);
if (sip->sip_from && !sip->sip_from->a_tag) {
sip_fragment_clear(sip->sip_from->a_common);
sip_from_add_param(home, sip->sip_from,
nta_agent_newtag(home, "tag=%s", leg->leg_agent));
}
if (!sip->sip_to)
sip->sip_to = sip_to_dup(home, leg->leg_remote);
else if (leg->leg_remote && leg->leg_remote->a_tag)
sip_to_tag(home, sip->sip_to, leg->leg_remote->a_tag);
method = sip->sip_request->rq_method;
method_name = sip->sip_request->rq_method_name;
......@@ -3254,6 +3287,7 @@ nta_leg_t *nta_leg_tcreate(nta_agent_t *agent,
sip_contact_t m[1];
sip_contact_init(m);
*m->m_url = *contact->m_url;
m->m_url->url_headers = NULL;
leg->leg_target = sip_contact_dup(home, m);
}
......@@ -4035,13 +4069,22 @@ int leg_route(nta_leg_t *leg,
leg->leg_loose_route = url_has_param(r->r_url, "lr");
if (contact) {
sip_contact_t m[1], *m0;
m0 = leg->leg_target;
sip_contact_t *target, m[1], *m0;
sip_contact_init(m);
*m->m_url = *contact->m_url;
leg->leg_target = sip_contact_dup(leg->leg_home, m);
m->m_url->url_headers = NULL;
target = sip_contact_dup(leg->leg_home, m);
if (target && target->m_url->url_params) {
/* Remove ttl, method. @RFC3261 table 1, page 152 */
char *p = (char *)target->m_url->url_params;
p = url_strip_param_string(p, "method");
p = url_strip_param_string(p, "ttl");
target->m_url->url_params = p;
}
m0 = leg->leg_target, leg->leg_target = target;
if (m0)
su_free(leg->leg_home, m0);
......
......@@ -871,12 +871,57 @@ int test_tports(agent_t *ag)
TEST(ag->ag_latest_leg, ag->ag_default_leg);
TEST_1(ag->ag_request);
msg_destroy(ag->ag_request), ag->ag_request = NULL;
TEST_1(ag->ag_out_via->v_comp == NULL);
nta_leg_bind(ag->ag_default_leg, leg_callback_200, ag);
}
/* Test 0.1.1
{
/* Test 0.1.2: test url_headers
*
* Send a message from default leg to default leg.
*/
url_t url[1];
sip_t *sip;
*url = *ag->ag_contact->m_url;
/* Test that method parameter is stripped and headers in query are used */
url->url_params = "method=MESSAGE;user=IP";
url->url_headers = "organization=United%20Testers";
ag->ag_expect_leg = ag->ag_default_leg;
su_free(ag->ag_home, (void *)ag->ag_out_via), ag->ag_out_via = NULL;
TEST_1(ag->ag_orq =
nta_outgoing_tcreate(ag->ag_default_leg,
outgoing_callback, ag,
ag->ag_obp,
SIP_METHOD_MESSAGE,
(url_string_t *)url,
SIPTAG_SUBJECT_STR("Test 0.1.2"),
SIPTAG_FROM(ag->ag_alice),
SIPTAG_TO(ag->ag_bob),
SIPTAG_CONTACT(ag->ag_m_alice),
TAG_END()));
nta_test_run(ag);
TEST(ag->ag_status, 200);
TEST(ag->ag_orq, NULL);
TEST(ag->ag_latest_leg, ag->ag_default_leg);
TEST_1(ag->ag_request);
TEST_1(sip = sip_object(ag->ag_request));
TEST_1(sip->sip_organization);
TEST_S(sip->sip_organization->g_string, "United Testers");
TEST_S(sip->sip_request->rq_url->url_params, "user=IP");
TEST_1(ag->ag_out_via->v_comp == NULL);
nta_leg_bind(ag->ag_default_leg, leg_callback_200, ag);
}
/* Test 0.1.3
* Send a message from Bob to Alice using SIGCOMP and TCP
*/
if (tcp_comp) {
......@@ -902,7 +947,7 @@ int test_tports(agent_t *ag)
SIP_METHOD_MESSAGE,
(url_string_t *)url,
NTATAG_COMP("sigcomp"),
SIPTAG_SUBJECT_STR("Test 0.1.1"),
SIPTAG_SUBJECT_STR("Test 0.1.3"),
SIPTAG_FROM(ag->ag_bob),
SIPTAG_TO(ag->ag_alice),
SIPTAG_CONTACT(ag->ag_m_bob),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment