Commit 4f2fe6e5 authored by jehan's avatar jehan
Browse files

update refresher to support publish

parent 80f76a47
......@@ -100,11 +100,11 @@ static void ict_on_response(belle_sip_ict_t *obj, belle_sip_response_t *resp){
switch (base->state){
case BELLE_SIP_TRANSACTION_CALLING:
base->state=BELLE_SIP_TRANSACTION_PROCEEDING;
belle_sip_transaction_set_state(base,BELLE_SIP_TRANSACTION_PROCEEDING);
/* no break*/
case BELLE_SIP_TRANSACTION_PROCEEDING:
if (code>=300){
base->state=BELLE_SIP_TRANSACTION_COMPLETED;
belle_sip_transaction_set_state(base,BELLE_SIP_TRANSACTION_COMPLETED);
belle_sip_channel_queue_message(base->channel,(belle_sip_message_t*)make_ack(obj,resp));
belle_sip_client_transaction_notify_response((belle_sip_client_transaction_t*)obj,resp);
obj->timer_D=belle_sip_timeout_source_new((belle_sip_source_func_t)ict_on_timer_D,obj,cfg->T1*64);
......@@ -112,7 +112,7 @@ static void ict_on_response(belle_sip_ict_t *obj, belle_sip_response_t *resp){
}else if (code>=200){
obj->timer_M=belle_sip_timeout_source_new((belle_sip_source_func_t)ict_on_timer_M,obj,cfg->T1*64);
belle_sip_transaction_start_timer(base,obj->timer_M);
base->state=BELLE_SIP_TRANSACTION_ACCEPTED;
belle_sip_transaction_set_state(base,BELLE_SIP_TRANSACTION_ACCEPTED);
belle_sip_client_transaction_notify_response((belle_sip_client_transaction_t*)obj,resp);
}else if (code>=100){
belle_sip_client_transaction_notify_response((belle_sip_client_transaction_t*)obj,resp);
......
......@@ -128,6 +128,18 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even
switch (response_code) {
case 200: {
/*great, success*/
if (strcmp(belle_sip_request_get_method(request),"PUBLISH")==0) {
/*search for etag*/
belle_sip_header_t* etag=belle_sip_message_get_header(BELLE_SIP_MESSAGE(response),"SIP-ETag");
if (etag) {
belle_sip_header_t* sip_if_match = belle_sip_header_create("SIP-If-Match",belle_sip_header_extension_get_value(BELLE_SIP_HEADER_EXTENSION(etag)));
/*update request for next refresh*/
belle_sip_message_remove_header(BELLE_SIP_MESSAGE(request),"SIP-If-Match");
belle_sip_message_add_header(BELLE_SIP_MESSAGE(request),sip_if_match);
} else {
belle_sip_warning("Refresher [%p] receive 200ok to a publish without etag");
}
}
/*update expire if needed*/
set_expires_from_trans(refresher);
schedule_timer(refresher); /*re-arm timer*/
......@@ -275,7 +287,7 @@ static int belle_sip_refresher_refresh_internal(belle_sip_refresher_t* refresher
if (expires_header)
belle_sip_header_expires_set_expires(expires_header,refresher->expires);
contact=belle_sip_message_get_header_by_type(request,belle_sip_header_contact_t);
if (belle_sip_header_contact_get_expires(contact)>=0)
if (contact && belle_sip_header_contact_get_expires(contact)>=0)
belle_sip_header_contact_set_expires(contact,refresher->expires);
client_transaction = belle_sip_provider_create_client_transaction(prov,request);
......@@ -350,13 +362,13 @@ static int set_expires_from_trans(belle_sip_refresher_t* refresher) {
belle_sip_transaction_t* transaction = BELLE_SIP_TRANSACTION(refresher->transaction);
belle_sip_response_t*response=transaction->last_response;
belle_sip_request_t*request=belle_sip_transaction_get_request(transaction);
belle_sip_header_expires_t* expires_header;
belle_sip_header_expires_t* expires_header=belle_sip_message_get_header_by_type(request,belle_sip_header_expires_t);
belle_sip_header_contact_t* contact_header;
refresher->expires=-1;
if (strcmp("REGISTER",belle_sip_request_get_method(request))==0
|| strcmp("SUBSCRIBE",belle_sip_request_get_method(request))==0) {
|| expires_header /*if request has an expire header, refresher can always work*/) {
/*An "expires" parameter on the "Contact" header has no semantics for
* SUBSCRIBE and is explicitly not equivalent to an "Expires" header in
......@@ -424,6 +436,7 @@ belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* t
belle_sip_transaction_state_t state=belle_sip_transaction_get_state(BELLE_SIP_TRANSACTION(transaction));
belle_sip_request_t* request = belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(transaction));
if ( strcmp("REGISTER",belle_sip_request_get_method(request))!=0
&& strcmp("PUBLISH",belle_sip_request_get_method(request))!=0
&& state!=BELLE_SIP_TRANSACTION_TERMINATED
&& state != BELLE_SIP_TRANSACTION_COMPLETED) {
belle_sip_error("Invalid state [%s] for %s transaction [%p], should be BELLE_SIP_TRANSACTION_COMPLETED/BELLE_SIP_TRANSACTION_TERMINATED"
......
......@@ -212,7 +212,16 @@ static void server_process_request_event(void *obj, const belle_sip_request_even
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));
if (strcmp(belle_sip_request_get_method(req),"PUBLISH")==0) {
belle_sip_header_t* etag=belle_sip_message_get_header(BELLE_SIP_MESSAGE(resp),"SIP-ETag");
if (etag) {
/*etag already, check for sip_if_match*/
belle_sip_header_t* sip_if_match=belle_sip_message_get_header(BELLE_SIP_MESSAGE(resp),"SIP-If-Match");
CU_ASSERT_PTR_NOT_NULL(sip_if_match);
if (sip_if_match) CU_ASSERT_EQUAL(belle_sip_header_extension_get_value(BELLE_SIP_HEADER_EXTENSION(sip_if_match)),"blablietag");
}
belle_sip_message_add_header(BELLE_SIP_MESSAGE(resp),belle_sip_header_create("SIP-ETag","blablietag"));
}
} else {
resp=belle_sip_response_create_from_request(belle_sip_request_event_get_request(event),401);
if (www_authenticate)
......@@ -320,7 +329,8 @@ static endpoint_t* create_udp_endpoint(int port,belle_sip_listener_callbacks_t*
return endpoint;
}
static void register_base(endpoint_t* client,endpoint_t *server) {
static void refresher_base(endpoint_t* client,endpoint_t *server, const char* method) {
belle_sip_request_t* req;
belle_sip_client_transaction_t* trans;
belle_sip_header_route_t* destination_route;
......@@ -344,9 +354,9 @@ static void register_base(endpoint_t* client,endpoint_t *server) {
req=belle_sip_request_create(
belle_sip_uri_parse(domain),
"REGISTER",
method,
belle_sip_provider_create_call_id(client->provider),
belle_sip_header_cseq_create(20,"REGISTER"),
belle_sip_header_cseq_create(20,method),
belle_sip_header_from_create2(identity,BELLE_SIP_RANDOM_TAG),
belle_sip_header_to_create2(identity,NULL),
belle_sip_header_via_new(),
......@@ -393,7 +403,10 @@ static void register_base(endpoint_t* client,endpoint_t *server) {
belle_sip_object_unref(refresher);
}
static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t auth_mode) {
static void register_base(endpoint_t* client,endpoint_t *server) {
refresher_base(client,server,"REGISTER");
}
static void refresher_base_with_param(const char* method, 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;
......@@ -406,11 +419,13 @@ static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t
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);
refresher_base(client,server,method);
destroy_endpoint(client);
destroy_endpoint(server);
}
static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t auth_mode) {
refresher_base_with_param("REGISTER",expire_in_contact,auth_mode);
}
static void subscribe_test(void) {
belle_sip_listener_callbacks_t client_callbacks;
belle_sip_listener_callbacks_t server_callbacks;
......@@ -621,7 +636,9 @@ static void register_tcp_test_ipv6_to_ipv6_with_ipv6(void){
register_test_with_interfaces("tcp","::0","::0",AF_INET6);
}
static void simple_publish() {
refresher_base_with_param("PUBLISH",FALSE,TRUE);
}
test_t refresher_tests[] = {
{ "REGISTER Expires header", register_expires_header },
......@@ -631,6 +648,7 @@ test_t refresher_tests[] = {
{ "REGISTER with failure", register_with_failure },
{ "REGISTER with early refresher",register_early_refresher},
{ "SUBSCRIBE", subscribe_test },
{ "PUBLISH", simple_publish },
{ "REGISTER with unrecognizable Contact", register_with_unrecognizable_contact },
{ "REGISTER UDP from ipv6 to ipv4", register_test_ipv6_to_ipv4 },
{ "REGISTER UDP from ipv4 to ipv6", register_test_ipv4_to_ipv6 },
......
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