Commit ee120693 authored by jehan's avatar jehan

improve refresher expire guess when contact cannot be matched

parent 02a2bb10
......@@ -112,8 +112,8 @@ BELLESIP_EXPORT belle_sip_response_t *belle_sip_response_new(void);
BELLESIP_EXPORT belle_sip_response_t *belle_sip_response_create_from_request(belle_sip_request_t *req, int status_code);
/**
* This method takes the received rport value of the reponse and update the contact IP/port accordingly
* @param response use to extract received/rport from top most via.
* This method takes received/rport/via value of the reponse and update the contact IP/port accordingly
* @param response use to extract via/received/rport from top most via.
* @param contact contact to be updated
* @returns 0 if no error
* */
......
......@@ -573,27 +573,29 @@ int belle_sip_response_fix_contact(const belle_sip_response_t* response,belle_si
via_header= (belle_sip_header_via_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(response),BELLE_SIP_VIA);
received = belle_sip_header_via_get_received(via_header);
rport = belle_sip_header_via_get_rport(via_header);
if (received!=NULL || rport>0) {
contact_uri=belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(contact));
if (received && strcmp(received,belle_sip_uri_get_host(contact_uri))!=0) {
/*need to update host*/
belle_sip_uri_set_host(contact_uri,received);
}
contact_port = belle_sip_uri_get_port(contact_uri);
if (rport>0 && rport!=contact_port && (contact_port+rport)!=5060) {
/*need to update port*/
belle_sip_uri_set_port(contact_uri,rport);
contact_uri=belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(contact));
if (received) {
/*need to update host*/
belle_sip_uri_set_host(contact_uri,received);
} else {
belle_sip_uri_set_host(contact_uri,belle_sip_header_via_get_host(via_header));
}
contact_port = belle_sip_uri_get_port(contact_uri);
if (rport>0 ) {
/*need to update port*/
if ((rport+contact_port)!=5060) belle_sip_uri_set_port(contact_uri,rport);
} else if ((belle_sip_header_via_get_port(via_header)+contact_port)!=5060) {
belle_sip_uri_set_port(contact_uri,belle_sip_header_via_get_port(via_header));
}
/*try to fix transport if needed (very unlikely)*/
if (strcasecmp(belle_sip_header_via_get_transport(via_header),"UDP")!=0) {
if (!belle_sip_uri_get_transport_param(contact_uri)
||strcasecmp(belle_sip_uri_get_transport_param(contact_uri),belle_sip_header_via_get_transport(via_header))!=0) {
belle_sip_uri_set_transport_param(contact_uri,belle_sip_header_via_get_transport_lowercase(via_header));
}
/*try to fix transport if needed (very unlikely)*/
if (strcasecmp(belle_sip_header_via_get_transport(via_header),"UDP")!=0) {
if (!belle_sip_uri_get_transport_param(contact_uri)
||strcasecmp(belle_sip_uri_get_transport_param(contact_uri),belle_sip_header_via_get_transport(via_header))!=0) {
belle_sip_uri_set_transport_param(contact_uri,belle_sip_header_via_get_transport_lowercase(via_header));
}
} else {
if (belle_sip_uri_get_transport_param(contact_uri)) {
belle_sip_uri_set_transport_param(contact_uri,NULL);
}
} else {
if (belle_sip_uri_get_transport_param(contact_uri)) {
belle_sip_uri_set_transport_param(contact_uri,NULL);
}
}
return 0;
......
......@@ -278,16 +278,22 @@ static int set_expires_from_trans(belle_sip_refresher_t* refresher) {
}
}
if (refresher->expires<0) {
belle_sip_message("Neither Expires header nor corresponding Contact header found");
refresher->expires=0;
return 1;
belle_sip_message("Neither Expires header nor corresponding Contact header found, checking from original request");
if ((expires_header=(belle_sip_header_expires_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_EXPIRES))) {
refresher->expires = belle_sip_header_expires_get_expires(expires_header);
} else {
belle_sip_message("Not possible to guess expire value, giving up");
refresher->expires=0;
return 1;
}
}
} else if (strcmp("INVITE",belle_sip_request_get_method(request))==0) {
belle_sip_fatal("Refresher does not support ERROR yet");
belle_sip_error("Refresher does not support ERROR yet");
return -1;
} else {
belle_sip_error("Refresher does not support [%s] yet",belle_sip_request_get_method(request));
return 1;
return -1;
}
return 0;
}
......
......@@ -51,6 +51,7 @@ typedef struct endpoint {
unsigned int nonce_count;
const char* received;
int rport;
unsigned char unreconizable_contact;
} endpoint_t;
static unsigned int wait_for(belle_sip_stack_t*s1, belle_sip_stack_t*s2,int* counter,int value,int timeout) {
......@@ -183,6 +184,10 @@ static void server_process_request_event(void *obj, const belle_sip_request_even
} else {
contact=belle_sip_header_contact_new();
}
if(endpoint->unreconizable_contact) {
/*put an unexopected address*/
belle_sip_uri_set_host(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(contact)),"nimportequoi.com");
}
belle_sip_message_add_header(BELLE_SIP_MESSAGE(resp),BELLE_SIP_HEADER(contact));
} else {
......@@ -261,10 +266,7 @@ static void destroy_endpoint(endpoint_t* endpoint) {
static endpoint_t* create_udp_endpoint(int port,belle_sip_listener_callbacks_t* listener_callbacks) {
return create_endpoint(port,"udp",listener_callbacks);
}
static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t auth_mode) {
belle_sip_listener_callbacks_t client_callbacks;
belle_sip_listener_callbacks_t server_callbacks;
static void register_base(endpoint_t* client,endpoint_t *server) {
belle_sip_request_t* req;
belle_sip_client_transaction_t* trans;
belle_sip_header_route_t* destination_route;
......@@ -273,23 +275,10 @@ static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t
const char* domain="sip:" SIPDOMAIN ;
belle_sip_header_contact_t* contact=belle_sip_header_contact_new();
belle_sip_uri_t *dest_uri;
endpoint_t* client,*server;
uint64_t begin;
uint64_t end;
if (client->expire_in_contact) belle_sip_header_contact_set_expires(contact,1);
memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
if (expire_in_contact) belle_sip_header_contact_set_expires(contact,1);
client_callbacks.process_response_event=client_process_response_event;
client_callbacks.process_auth_requested=client_process_auth_requested;
server_callbacks.process_request_event=server_process_request_event;
client = create_udp_endpoint(3452,&client_callbacks);
server = create_udp_endpoint(6788,&server_callbacks);
server->expire_in_contact=expire_in_contact;
server->auth=auth_mode;
dest_uri=(belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)belle_sip_listening_point_get_uri(server->lp));
belle_sip_uri_set_host(dest_uri,"127.0.0.1");
......@@ -306,7 +295,7 @@ static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t
belle_sip_header_via_new(),
70);
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(contact));
if (!expire_in_contact)
if (!client->expire_in_contact)
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(1)));
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(destination_route));
......@@ -341,6 +330,21 @@ static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t
CU_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.refreshOk,4,1000));
belle_sip_refresher_stop(refresher);
belle_sip_object_unref(refresher);
}
static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t auth_mode) {
belle_sip_listener_callbacks_t client_callbacks;
belle_sip_listener_callbacks_t server_callbacks;
endpoint_t* client,*server;
memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
client_callbacks.process_response_event=client_process_response_event;
client_callbacks.process_auth_requested=client_process_auth_requested;
server_callbacks.process_request_event=server_process_request_event;
client = create_udp_endpoint(3452,&client_callbacks);
server = create_udp_endpoint(6788,&server_callbacks);
server->expire_in_contact=client->expire_in_contact=expire_in_contact;
server->auth=auth_mode;
register_base(client,server);
destroy_endpoint(client);
destroy_endpoint(server);
}
......@@ -434,6 +438,26 @@ static void register_expires_in_contact_header_digest_auth(void) {
register_test_with_param(1,digest_auth);
}
static void register_with_unreconizable_contact(void) {
belle_sip_listener_callbacks_t client_callbacks;
belle_sip_listener_callbacks_t server_callbacks;
endpoint_t* client,*server;
memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
client_callbacks.process_response_event=client_process_response_event;
client_callbacks.process_auth_requested=client_process_auth_requested;
server_callbacks.process_request_event=server_process_request_event;
client = create_udp_endpoint(3452,&client_callbacks);
server = create_udp_endpoint(6788,&server_callbacks);
server->expire_in_contact=1;
server->unreconizable_contact=1;
server->auth=digest;
register_base(client,server);
destroy_endpoint(client);
destroy_endpoint(server);
}
int belle_sip_refresher_test_suite(){
CU_pSuite pSuite = CU_add_suite("Refresher", NULL, NULL);
......@@ -452,6 +476,9 @@ int belle_sip_refresher_test_suite(){
if (NULL == CU_add_test(pSuite, "subscribe_test", subscribe_test)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "register_with_unreconizable_contact", register_with_unreconizable_contact)) {
return CU_get_error();
}
return 0;
}
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