Commit 7a750d63 authored by Mickaël Turnel's avatar Mickaël Turnel

Fix belle_sip refresher's contact comparison that did not check missing default ports

parent 1cea94b9
Pipeline #225 failed with stage
in 0 seconds
......@@ -187,18 +187,31 @@ BELLESIP_EXPORT belle_sip_header_contact_t* belle_sip_header_contact_create (con
*
*/
BELLESIP_EXPORT void belle_sip_header_contact_set_wildcard(belle_sip_header_contact_t* contact,unsigned int is_wildcard);
/** Contact heaader equality function
/** Contact header equality function
* @return 0 if not equals
*
* */
BELLESIP_EXPORT unsigned int belle_sip_header_contact_equals(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b);
/** Contact heaader equality function, same as #belle_sip_header_contact_equals but return 0 if equals, very useful with #belle_sip_list
/** Contact header equality function, same as #belle_sip_header_contact_equals but return 0 if equals, very useful with #belle_sip_list
* @return 0 if equals
*
* */
BELLESIP_EXPORT unsigned int belle_sip_header_contact_not_equals(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b);
/** Contact header equality function
* @return 0 if not equals
*
* */
BELLESIP_EXPORT unsigned int belle_sip_header_contact_equals_with_uri_omitting(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b);
/** Contact header equality function, same as #belle_sip_header_contact_equals but return 0 if equals, very useful with #belle_sip_list
* @return 0 if equals
*
* */
BELLESIP_EXPORT unsigned int belle_sip_header_contact_not_equals_with_uri_omitting(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b);
/**
* Enable automatic filling of the contact ip, port and transport according to the channel that sends this message.
* @deprecated use belle_sip_header_address_set_automatic();
......
......@@ -220,10 +220,20 @@ belle_sip_error_code belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buf
*
* */
BELLESIP_EXPORT int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri_b);
/**define URI equality as belle_sip_uri_equals but allows URI omitting for the port
* @param belle_sip_uri_t* uri_a
* @param belle_sip_uri_t* uri_a
* @return 0 if not matched.
*
* */
BELLESIP_EXPORT int belle_sip_uri_equals_with_uri_omitting(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri_b);
/**
* returns 0 if uri does follows components requirement for being a request uri
* */
BELLESIP_EXPORT int belle_sip_uri_check_components_from_request_uri(const belle_sip_uri_t* uri);
/**
* returns 0 if uri does follows components requirement for a given method/header
*/
......
......@@ -431,6 +431,7 @@ int belle_sip_header_contact_set_qvalue(belle_sip_header_contact_t* contact, flo
float belle_sip_header_contact_get_qvalue(const belle_sip_header_contact_t* contact) {
return belle_sip_header_contact_get_q(contact);
}
unsigned int belle_sip_header_contact_equals(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b) {
if (!a | !b) return 0;
return belle_sip_uri_equals(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(a))
......@@ -440,6 +441,15 @@ unsigned int belle_sip_header_contact_not_equals(const belle_sip_header_contact_
return !belle_sip_header_contact_equals(a,b);
}
unsigned int belle_sip_header_contact_equals_with_uri_omitting(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b) {
if (!a | !b) return 0;
return belle_sip_uri_equals_with_uri_omitting(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(a))
,belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(b)));
}
unsigned int belle_sip_header_contact_not_equals_with_uri_omitting(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b) {
return !belle_sip_header_contact_equals_with_uri_omitting(a,b);
}
void belle_sip_header_contact_set_automatic(belle_sip_header_contact_t *a, int enabled){
belle_sip_header_address_set_automatic((belle_sip_header_address_t*)a, enabled);
}
......
......@@ -284,7 +284,7 @@ end:
Section 10.3.). SIP and SIPS URIs are compared for equality
according to the following rules:
*/
int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri_b) {
static int belle_sip_uri_equals_with_omission(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri_b,bool_t uri_omitting) {
const belle_sip_list_t * params;
const char* b_param;
const char* a_param;
......@@ -319,7 +319,27 @@ int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri
if (!IS_EQUAL_CASE(uri_a->host,uri_b->host)) {
return 0;
}
if (uri_a->port != uri_b->port) return 0;
if (uri_omitting) {
int port_a = uri_a->port;
int port_b = uri_b->port;
if (port_a == 0) {
const char* transport_a = belle_sip_parameters_get_case_parameter((belle_sip_parameters_t*) uri_a, "transport");
if (transport_a == NULL) port_a = belle_sip_listening_point_get_well_known_port("UDP");
else port_a = belle_sip_listening_point_get_well_known_port(transport_a);
}
if (port_b == 0) {
const char* transport_b = belle_sip_parameters_get_case_parameter((belle_sip_parameters_t*) uri_b, "transport");
if (transport_b == NULL) port_b = belle_sip_listening_point_get_well_known_port("UDP");
else port_b = belle_sip_listening_point_get_well_known_port(transport_b);
}
if (port_a != port_b) return 0;
} else {
/* In this case (by default) we respect URI omitting */
if (uri_a->port != uri_b->port) return 0;
}
/*
A URI omitting the user component will not match a URI that
includes one. A URI omitting the password component will not
......@@ -378,6 +398,15 @@ int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri
return 1;
}
int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri_b) {
return belle_sip_uri_equals_with_omission(uri_a, uri_b, FALSE);
}
int belle_sip_uri_equals_with_uri_omitting(const belle_sip_uri_t* uri_a, const belle_sip_uri_t* uri_b) {
return belle_sip_uri_equals_with_omission(uri_a, uri_b, TRUE);
}
/*uri checker*/
......
......@@ -648,13 +648,13 @@ belle_sip_header_contact_t* belle_sip_refresher_get_contact(const belle_sip_refr
if (contact_header_list) {
contact_header_list = belle_sip_list_find_custom((belle_sip_list_t*)contact_header_list
,(belle_sip_compare_func)belle_sip_header_contact_not_equals
,(belle_sip_compare_func)belle_sip_header_contact_not_equals_with_uri_omitting
, (const void*)fixed_local_contact);
if (!contact_header_list) {
/*reset header list*/
contact_header_list = belle_sip_message_get_headers(BELLE_SIP_MESSAGE(response),BELLE_SIP_CONTACT);
contact_header_list = belle_sip_list_find_custom((belle_sip_list_t*)contact_header_list
,(belle_sip_compare_func)belle_sip_header_contact_not_equals
,(belle_sip_compare_func)belle_sip_header_contact_not_equals_with_uri_omitting
,unfixed_local_contact);
}
if (!contact_header_list) {
......
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