Commit 7ec48ad6 authored by jehan's avatar jehan
Browse files

add API to better know value of contact header, specially when automatically set by belle-sip

parent 17ca6502
......@@ -120,6 +120,9 @@ BELLESIP_EXPORT void belle_sip_message_remove_last(belle_sip_message_t *msg, con
BELLESIP_EXPORT void belle_sip_message_remove_header(belle_sip_message_t *msg, const char *header_name);
BELLESIP_EXPORT void belle_sip_message_remove_header_from_ptr(belle_sip_message_t *msg, belle_sip_header_t* header);
BELLESIP_EXPORT char *belle_sip_message_to_string(belle_sip_message_t *msg);
BELLESIP_EXPORT belle_sip_body_handler_t *belle_sip_message_get_body_handler(const belle_sip_message_t *msg);
......
......@@ -105,6 +105,10 @@ BELLESIP_EXPORT void belle_sip_refresher_enable_manual_mode(belle_sip_refresher_
* Retrieve last know public ip:port contact used.
**/
BELLESIP_EXPORT char* belle_sip_refresher_get_public_uri(belle_sip_refresher_t* refresher);
/**
* Retrieve last know contact header if known. Only available after a successful registration.
**/
BELLESIP_EXPORT belle_sip_header_contact_t* belle_sip_refresher_get_contact(const belle_sip_refresher_t* refresher);
BELLE_SIP_END_DECLS
......
......@@ -248,8 +248,19 @@ void belle_sip_message_remove_header(belle_sip_message_t *msg, const char *heade
belle_sip_headers_container_delete(headers_container);
}
}
void belle_sip_message_remove_header_from_ptr(belle_sip_message_t *msg, belle_sip_header_t* header) {
headers_container_t* headers_container = belle_sip_headers_container_get(msg,belle_sip_header_get_name(header));
belle_sip_list_t* it;
it=belle_sip_list_find(headers_container->header_list,header);
if (it) {
belle_sip_object_unref(header);
headers_container->header_list=belle_sip_list_delete_link(headers_container->header_list,it);
if (belle_sip_list_size(headers_container->header_list) == 0) {
belle_sip_list_remove(msg->header_list,headers_container);
belle_sip_headers_container_delete(headers_container);
}
}
}
/*
belle_sip_error_code belle_sip_message_named_headers_marshal(belle_sip_message_t *message, const char* header_name, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=BELLE_SIP_OK;
......
......@@ -191,6 +191,7 @@ static void process_response_event(belle_sip_listener_t *user_ctx, const belle_s
belle_sip_refresher_t* refresher=(belle_sip_refresher_t*)user_ctx;
belle_sip_header_contact_t *contact;
if (refresher && (client_transaction !=refresher->transaction))
return; /*not for me*/
......@@ -213,9 +214,24 @@ static void process_response_event(belle_sip_listener_t *user_ctx, const belle_s
}
/*update expire if needed*/
set_expires_from_trans(refresher);
if (refresher->target_expires<=0) {
belle_sip_refresher_stop(refresher); /*doesn't not make sense to refresh if expire =0;*/
} else {
/*remove all contact with expire = 0 from request if any, because no need to refresh them*/
const belle_sip_list_t * contact_list= belle_sip_message_get_headers(BELLE_SIP_MESSAGE(request),BELLE_SIP_CONTACT);
belle_sip_list_t *iterator, *head;
if (contact_list) {
for (iterator=head=belle_sip_list_copy(contact_list);iterator!=NULL;iterator=iterator->next) {
belle_sip_header_contact_t *contact_for_expire = (belle_sip_header_contact_t *)(iterator->data);
if (belle_sip_header_contact_get_expires(contact_for_expire) == 0) {
belle_sip_message_remove_header_from_ptr(BELLE_SIP_MESSAGE(request),BELLE_SIP_HEADER(contact_for_expire));
}
}
belle_sip_list_free(head);
}
}
if (refresher->state==started) {
if (is_contact_address_acurate(refresher,request)) {
schedule_timer(refresher); /*re-arm timer*/
......@@ -483,7 +499,8 @@ static int timer_cb(void *user_data, unsigned int events) {
return BELLE_SIP_STOP;
}
static belle_sip_header_contact_t* get_matching_contact(const belle_sip_transaction_t* transaction) {
belle_sip_header_contact_t* belle_sip_refresher_get_contact(const belle_sip_refresher_t* refresher) {
belle_sip_transaction_t* transaction = BELLE_SIP_TRANSACTION(refresher->transaction);
belle_sip_request_t*request=belle_sip_transaction_get_request(transaction);
belle_sip_response_t*response=transaction->last_response;
const belle_sip_list_t* contact_header_list;
......@@ -552,7 +569,7 @@ static int set_expires_from_trans(belle_sip_refresher_t* refresher) {
if (ct_expires!=-1) refresher->target_expires=ct_expires;
}
/*check in response also to get the obtained expires*/
if ((contact_header=get_matching_contact(transaction))!=NULL){
if ((contact_header=belle_sip_refresher_get_contact(refresher))!=NULL){
/*matching contact, check for its possible expires param*/
refresher->obtained_expires=belle_sip_header_contact_get_expires(BELLE_SIP_HEADER_CONTACT(contact_header));
}
......
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