Commit 02a3abf2 authored by Simon Morlat's avatar Simon Morlat

add clone() to belle_sip_message_t, bugfixes

parent 5d8f1072
......@@ -155,11 +155,13 @@ belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){
newobj=belle_sip_malloc0(obj->size);
newobj->ref=obj->vptr->initially_unowned ? 0 : 1;
newobj->vptr=obj->vptr;
newobj->size=obj->size;
if (obj->name) newobj->name=belle_sip_strdup(obj->name);
vptr=obj->vptr;
while(vptr!=NULL){
if (vptr->clone==NULL){
belle_sip_fatal("Object of type %i cannot be cloned, it does not provide a clone() implementation.",vptr->id);
belle_sip_fatal("Object of type %s cannot be cloned, it does not provide a clone() implementation.",vptr->type_name);
return NULL;
}else vptr->clone(newobj,obj);
vptr=vptr->parent;
......
......@@ -311,6 +311,7 @@ typedef struct delayed_send{
}delayed_send_t;
static int on_delayed_send_do(delayed_send_t *ds){
belle_sip_message("on_delayed_send_do(): sending now");
if (ds->chan->state==BELLE_SIP_CHANNEL_READY){
_send_message(ds->chan,ds->msg);
}
......@@ -326,6 +327,7 @@ static void send_message(belle_sip_channel_t *obj, belle_sip_message_t *msg){
ds->chan=(belle_sip_channel_t*)belle_sip_object_ref(obj);
ds->msg=(belle_sip_message_t*)belle_sip_object_ref(msg);
belle_sip_main_loop_add_timeout(obj->stack->ml,(belle_sip_source_func_t)on_delayed_send_do,ds,obj->stack->tx_delay);
belle_sip_message("channel %p: message sending delayed by %i ms",obj,obj->stack->tx_delay);
}else _send_message(obj,msg);
}
......
......@@ -49,9 +49,23 @@ static void belle_sip_message_destroy(belle_sip_message_t *msg){
belle_sip_list_free(msg->header_list);
}
/*very sub-optimal clone method */
static void belle_sip_message_clone(belle_sip_message_t *obj, const belle_sip_message_t *orig){
headers_container_t *c;
const belle_sip_list_t *l;
for(l=orig->header_list;l!=NULL;l=l->next){
c=(headers_container_t*)l->data;
if (c->header_list){
belle_sip_list_t * ll=belle_sip_list_copy_with_data(c->header_list,(void *(*)(void*))belle_sip_object_clone);
belle_sip_message_add_headers(obj,ll);
belle_sip_list_free(ll);
}
}
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_message_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_message_t,belle_sip_object_t,belle_sip_message_destroy,NULL,NULL,FALSE);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_message_t,belle_sip_object_t,belle_sip_message_destroy,belle_sip_message_clone,NULL,FALSE);
belle_sip_message_t* belle_sip_message_parse (const char* value) {
size_t message_length;
......@@ -223,7 +237,8 @@ static void belle_sip_request_init(belle_sip_request_t *message){
}
static void belle_sip_request_clone(belle_sip_request_t *request, const belle_sip_request_t *orig){
if (orig->method) request->method=belle_sip_strdup(orig->method);
if (orig->method) request->method=belle_sip_strdup(orig->method);
if (orig->uri) request->uri=(belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)orig->uri);
}
int belle_sip_request_marshal(belle_sip_request_t* request, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
......
......@@ -41,6 +41,7 @@ static void nict_set_completed(belle_sip_nict_t *obj, belle_sip_response_t *resp
if (!belle_sip_channel_is_reliable(base->channel)){
obj->timer_K=belle_sip_timeout_source_new((belle_sip_source_func_t)nict_on_timer_K,obj,cfg->T4);
belle_sip_object_set_name((belle_sip_object_t*)obj->timer_K,"timer_K");
belle_sip_transaction_start_timer(base,obj->timer_K);
}else belle_sip_transaction_terminate(base);
}
......@@ -120,6 +121,8 @@ static int nict_on_timer_E(belle_sip_nict_t *obj){
belle_sip_channel_queue_message(base->channel,(belle_sip_message_t*)base->request);
break;
default:
/*if we are not in these cases, timer_E does nothing, so remove it*/
return BELLE_SIP_STOP;
break;
}
return BELLE_SIP_CONTINUE;
......@@ -131,11 +134,13 @@ static void nict_send_request(belle_sip_nict_t *obj){
base->state=BELLE_SIP_TRANSACTION_TRYING;
obj->timer_F=belle_sip_timeout_source_new((belle_sip_source_func_t)nict_on_timer_F,obj,cfg->T1*64);
belle_sip_object_set_name((belle_sip_object_t*)obj->timer_F,"timer_F");
belle_sip_transaction_start_timer(base,obj->timer_F);
belle_sip_channel_queue_message(base->channel,(belle_sip_message_t*)base->request);
if (!belle_sip_channel_is_reliable(base->channel)){
obj->timer_E=belle_sip_timeout_source_new((belle_sip_source_func_t)nict_on_timer_E,obj,cfg->T1);
belle_sip_object_set_name((belle_sip_object_t*)obj->timer_E,"timer_E");
belle_sip_transaction_start_timer(base,obj->timer_E);
}
}
......
......@@ -48,6 +48,7 @@ static void transaction_destroy(belle_sip_transaction_t *t){
if (t->request) belle_sip_object_unref(t->request);
if (t->last_response) belle_sip_object_unref(t->last_response);
if (t->channel) belle_sip_object_unref(t->channel);
if (t->branch_id) belle_sip_free(t->branch_id);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_transaction_t);
......@@ -80,8 +81,8 @@ belle_sip_transaction_state_t belle_sip_transaction_get_state(const belle_sip_tr
void belle_sip_transaction_terminate(belle_sip_transaction_t *t){
t->state=BELLE_SIP_TRANSACTION_TERMINATED;
belle_sip_provider_set_transaction_terminated(t->provider,t);
BELLE_SIP_OBJECT_VPTR(t,belle_sip_transaction_t)->on_terminate(t);
belle_sip_provider_set_transaction_terminated(t->provider,t);
}
belle_sip_request_t *belle_sip_transaction_get_request(belle_sip_transaction_t *t){
......
......@@ -147,6 +147,7 @@ static void register_test(const char *transport, int use_transaction) {
/*unregister*/
is_register_ok=0;
using_transaction=0;
req=(belle_sip_request_t*)belle_sip_object_clone((belle_sip_object_t*)req);
belle_sip_header_cseq_t* cseq=(belle_sip_header_cseq_t*)belle_sip_message_get_header((belle_sip_message_t*)req,BELLE_SIP_CSEQ);
belle_sip_header_cseq_set_seq_number(cseq,belle_sip_header_cseq_get_seq_number(cseq)+1);
belle_sip_header_expires_t* expires_header=(belle_sip_header_expires_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_EXPIRES);
......@@ -180,7 +181,7 @@ static void stateful_register_udp(void){
}
static void stateful_register_udp_delayed(void){
belle_sip_stack_set_tx_delay(stack,1000);
belle_sip_stack_set_tx_delay(stack,3000);
register_test(NULL,1);
belle_sip_stack_set_tx_delay(stack,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