Commit 86e6acd0 authored by Simon Morlat's avatar Simon Morlat

fix many crashes.

parent 0663cf17
......@@ -33,11 +33,13 @@ belle_sip_socket_t belle_sip_source_get_socket(const belle_sip_source_t* source)
/**
* Callback function prototype for main loop notifications.
* Return value is important:
* 0 => source is removed from main loop.
* non zero value => source is kept.
* BELLE_SIP_STOP => source is removed from main loop.
* BELLE_SIP_CONTINUE => source is kept.
**/
typedef int (*belle_sip_source_func_t)(void *user_data, unsigned int events);
typedef void (*belle_sip_callback_t)(void *user_data);
typedef struct belle_sip_main_loop belle_sip_main_loop_t;
#define BELLE_SIP_CONTINUE TRUE
......@@ -66,6 +68,8 @@ unsigned long belle_sip_main_loop_add_timeout(belle_sip_main_loop_t *ml, belle_s
/**
* Adds a timeout into the main loop
* The caller of this function is responsible for freeing (with belle_sip_object_unref()) the returned belle_sip_source_t object when it is no longer
* needed.
* @param ml
* @param func a callback function to be called to notify timeout expiration
* @param data a pointer to be passed to the callback
......@@ -74,12 +78,15 @@ unsigned long belle_sip_main_loop_add_timeout(belle_sip_main_loop_t *ml, belle_s
* @returns timeout belle_sip_source_t with ref count = 1
**/
belle_sip_source_t* belle_sip_main_loop_create_timeout(belle_sip_main_loop_t *ml
, belle_sip_source_func_t func
, void *data
, unsigned int timeout_value_ms
,const char* timer_name);
, belle_sip_source_func_t func
, void *data
, unsigned int timeout_value_ms
,const char* timer_name);
/**
* Schedule an arbitrary task at next main loop iteration.
**/
void belle_sip_main_loop_do_later(belle_sip_main_loop_t *ml, belle_sip_callback_t func, void *data);
/**
* Creates a timeout source, similarly to belle_sip_main_loop_add_timeout().
......
......@@ -199,6 +199,7 @@ struct belle_sip_source{
belle_sip_source_remove_callback_t on_remove;
unsigned char cancelled;
unsigned char expired;
unsigned char oneshot;
belle_sip_socket_t sock;
unsigned int notify_required; /*for testing purpose, use to ask for being scheduled*/
};
......@@ -486,7 +487,6 @@ struct belle_sip_provider{
belle_sip_list_t *server_transactions;
belle_sip_list_t *dialogs;
belle_sip_list_t *auth_contexts;
};
belle_sip_provider_t *belle_sip_provider_new(belle_sip_stack_t *s, belle_sip_listening_point_t *lp);
......
......@@ -283,12 +283,20 @@ belle_sip_source_t* belle_sip_main_loop_create_timeout(belle_sip_main_loop_t *ml
belle_sip_main_loop_add_source(ml,s);
return s;
}
unsigned long belle_sip_main_loop_add_timeout(belle_sip_main_loop_t *ml, belle_sip_source_func_t func, void *data, unsigned int timeout_value_ms){
belle_sip_source_t * s=belle_sip_main_loop_create_timeout(ml,func,data,timeout_value_ms,"Timer");
belle_sip_object_unref(s);
return s->id;
}
void belle_sip_main_loop_do_later(belle_sip_main_loop_t *ml, belle_sip_callback_t func, void *data){
belle_sip_source_t * s=belle_sip_main_loop_create_timeout(ml,(belle_sip_source_func_t)func,data,0,"defered task");
s->oneshot=TRUE;
belle_sip_object_unref(s);
}
void belle_sip_source_set_timeout(belle_sip_source_t *s, unsigned int value_ms){
if (!s->expired){
s->expire_ms=belle_sip_time_ms()+value_ms;
......@@ -386,7 +394,7 @@ void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){
if (s->timeout>0)/*to avoid too many traces*/ belle_sip_message("source %s notified revents=%u, timeout=%i",objdesc,revents,s->timeout);
belle_sip_free(objdesc);
ret=s->notify(s->data,revents);
if (ret==0){
if (ret==BELLE_SIP_STOP || s->oneshot){
/*this source needs to be removed*/
belle_sip_main_loop_remove_source(ml,s);
}else if (revents==0){
......
......@@ -112,7 +112,6 @@ void belle_sip_object_weak_unref(void *obj, belle_sip_object_destroy_notify_t de
for(ref=o->weak_refs;ref!=NULL;ref=next){
next=ref->next;
if (ref->notify==destroy_notify && ref->userpointer==userpointer){
belle_sip_message("belle_sip_object_weak_unref(): prefref=%p",prevref);
if (prevref==NULL) o->weak_refs=next;
else prevref->next=next;
belle_sip_free(ref);
......
......@@ -214,7 +214,7 @@ int belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents
message_ready:
obj->incoming_messages=belle_sip_list_append(obj->incoming_messages,obj->input_stream.msg);
belle_sip_channel_input_stream_reset(&obj->input_stream,message_size);
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_event,obj,BELLE_SIP_EVENT_READ/*alway a read event*revents*/);
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_event,obj,BELLE_SIP_EVENT_READ/*always a read event*/);
if (obj->input_stream.write_ptr-obj->input_stream.read_ptr>0) {
/*process residu*/
belle_sip_channel_process_data(obj,0);
......@@ -329,18 +329,30 @@ belle_sip_message_t* belle_sip_channel_pick_message(belle_sip_channel_t *obj) {
return result;
}
static void channel_invoke_state_listener(belle_sip_channel_t *obj){
belle_sip_object_ref(obj);
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_state_changed,obj,obj->state);
belle_sip_object_unref(obj);
}
void channel_set_state(belle_sip_channel_t *obj, belle_sip_channel_state_t state) {
belle_sip_message("channel %p: state %s",obj,belle_sip_channel_state_to_string(state));
obj->state=state;
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_state_changed,obj,state);
if (state==BELLE_SIP_CHANNEL_ERROR){
/*Because error notification will in practice trigger the destruction of possible transactions and this channel,
* it is safer to invoke the listener outside the current call stack.
* Indeed the channel encounters network errors while being called for transmiting by a transaction.
*/
belle_sip_main_loop_do_later(obj->stack->ml,(belle_sip_callback_t)channel_invoke_state_listener,obj);
}else
channel_invoke_state_listener(obj);
}
static void _send_message(belle_sip_channel_t *obj, belle_sip_message_t *msg){
char buffer[belle_sip_network_buffer_size];
int len;
int ret=0;
belle_sip_object_ref(obj);
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_sending,obj,msg);
len=belle_sip_object_marshal((belle_sip_object_t*)msg,buffer,0,sizeof(buffer));
if (len>0){
......@@ -352,12 +364,12 @@ static void _send_message(belle_sip_channel_t *obj, belle_sip_message_t *msg){
if (ret<0){
belle_sip_error("channel [%p]: could not send [%i] bytes from [%s://%s:%i] to [%s:%i]" ,obj
,len
,belle_sip_channel_get_transport_name(obj)
,obj->local_ip
,obj->local_port
,obj->peer_name
,obj->peer_port);
,len
,belle_sip_channel_get_transport_name(obj)
,obj->local_ip
,obj->local_port
,obj->peer_name
,obj->peer_port);
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
belle_sip_channel_close(obj);
}else{
......@@ -369,7 +381,6 @@ static void _send_message(belle_sip_channel_t *obj, belle_sip_message_t *msg){
,buffer);
}
}
belle_sip_object_unref(obj);
}
/* just to emulate network transmission delay */
......@@ -406,6 +417,7 @@ void belle_sip_channel_prepare(belle_sip_channel_t *obj){
}
void channel_process_queue(belle_sip_channel_t *obj){
belle_sip_object_ref(obj);/* we need to ref ourself because code below may trigger our destruction*/
switch(obj->state){
case BELLE_SIP_CHANNEL_INIT:
if (obj->prepare) belle_sip_channel_resolve(obj);
......@@ -419,16 +431,14 @@ void channel_process_queue(belle_sip_channel_t *obj){
belle_sip_object_unref(obj->msg);
obj->msg=NULL;
}
break;
break;
case BELLE_SIP_CHANNEL_ERROR:
if (obj->msg){
belle_sip_object_unref(obj->msg);
obj->msg=NULL;
}
if (obj->msg) belle_sip_error("channel %p: trying to send a message over a broken channel ???",obj);
break;
default:
break;
}
belle_sip_object_unref(obj);
}
void belle_sip_channel_set_ready(belle_sip_channel_t *obj, const struct sockaddr *addr, socklen_t slen){
......@@ -490,5 +500,11 @@ int belle_sip_channel_queue_message(belle_sip_channel_t *obj, belle_sip_message_
return 0;
}
void belle_sip_channel_force_close(belle_sip_channel_t *obj){
obj->force_close=1;
/*first, every existing channel must be set to error*/
channel_set_state(obj,BELLE_SIP_CHANNEL_DISCONNECTED);
belle_sip_channel_close(obj);
}
......@@ -88,7 +88,8 @@ struct belle_sip_channel{
belle_sip_message_t *msg;
belle_sip_list_t* incoming_messages;
belle_sip_channel_input_stream_t input_stream;
int recv_error; /* used to simulate network error. if <=0, channel_recv will return this value*/
unsigned int recv_error:1; /* used to simulate network error. if <=0, channel_recv will return this value*/
unsigned int force_close:1; /* used to simulate network error. if <=0, channel_recv will return this value*/
};
#define BELLE_SIP_CHANNEL(obj) BELLE_SIP_CAST(obj,belle_sip_channel_t)
......@@ -139,11 +140,15 @@ const char *belle_sip_channel_get_local_address(belle_sip_channel_t *obj, int *p
void channel_set_state(belle_sip_channel_t *obj, belle_sip_channel_state_t state);
/*remember that channel_process_queue() might trigger the destruction of the channel*/
void channel_process_queue(belle_sip_channel_t *obj);
/*just invokes the listeners to process data*/
int belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents);
/*this function is to be used only in belle_sip_listening_point_clean_channels()*/
void belle_sip_channel_force_close(belle_sip_channel_t *obj);
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_channel_t,belle_sip_source_t)
const char *transport;
int reliable;
......
......@@ -171,7 +171,6 @@ static void ict_send_request(belle_sip_ict_t *obj){
const belle_sip_timer_config_t *cfg=belle_sip_transaction_get_timer_config(base);
base->state=BELLE_SIP_TRANSACTION_CALLING;
belle_sip_channel_queue_message(base->channel,(belle_sip_message_t*)base->request);
if (!belle_sip_channel_is_reliable(base->channel)){
obj->timer_A=belle_sip_timeout_source_new((belle_sip_source_func_t)ict_on_timer_A,obj,cfg->T1);
......@@ -181,6 +180,7 @@ static void ict_send_request(belle_sip_ict_t *obj){
obj->timer_B=belle_sip_timeout_source_new((belle_sip_source_func_t)ict_on_timer_B,obj,cfg->T1*64);
belle_sip_transaction_start_timer(base,obj->timer_B);
belle_sip_channel_queue_message(base->channel,(belle_sip_message_t*)base->request);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_ict_t);
......
......@@ -32,11 +32,10 @@ static void belle_sip_listening_point_uninit(belle_sip_listening_point_t *lp){
belle_sip_listening_point_clean_channels(lp);
belle_sip_message("Listening point [%p] on [%s://%s:%i] destroyed" ,lp
,belle_sip_uri_get_transport_param(BELLE_SIP_LISTENING_POINT(lp)->listening_uri)
,belle_sip_uri_get_host(BELLE_SIP_LISTENING_POINT(lp)->listening_uri)
,belle_sip_uri_get_port(BELLE_SIP_LISTENING_POINT(lp)->listening_uri));
,belle_sip_uri_get_transport_param(BELLE_SIP_LISTENING_POINT(lp)->listening_uri)
,belle_sip_uri_get_host(BELLE_SIP_LISTENING_POINT(lp)->listening_uri)
,belle_sip_uri_get_port(BELLE_SIP_LISTENING_POINT(lp)->listening_uri));
belle_sip_object_unref(lp->listening_uri);
lp->channel_listener=NULL; /*does not unref provider*/
belle_sip_uninit_sockets();
belle_sip_listening_point_set_keep_alive(lp,-1);
}
......@@ -50,7 +49,6 @@ belle_sip_channel_t *belle_sip_listening_point_create_channel(belle_sip_listenin
belle_sip_channel_t *chan=BELLE_SIP_OBJECT_VPTR(obj,belle_sip_listening_point_t)->create_channel(obj,dest,port);
if (chan){
chan->lp=obj;
belle_sip_channel_add_listener(chan,obj->channel_listener);
belle_sip_listening_point_add_channel(obj,chan);
}
return chan;
......@@ -66,17 +64,14 @@ void belle_sip_listening_point_remove_channel(belle_sip_listening_point_t *lp, b
void belle_sip_listening_point_clean_channels(belle_sip_listening_point_t *lp){
int existing_channels;
belle_sip_list_t* iterator;
belle_sip_list_t* channels=belle_sip_list_copy(lp->channels);
if ((existing_channels=belle_sip_list_size(lp->channels)) > 0) {
belle_sip_warning("Listening point destroying [%i] channels",existing_channels);
}
for (iterator=channels;iterator!=NULL;iterator=iterator->next) {
/*first, every existing channel must be set to error*/
channel_set_state((belle_sip_channel_t*)(iterator->data),BELLE_SIP_CHANNEL_DISCONNECTED);
belle_sip_channel_close((belle_sip_channel_t*)(iterator->data));
for (iterator=lp->channels;iterator!=NULL;iterator=iterator->next) {
belle_sip_channel_t *chan=(belle_sip_channel_t*)iterator->data;
belle_sip_channel_force_close(chan);
}
belle_sip_list_free(channels);
lp->channels=belle_sip_list_free_with_data(lp->channels,(void (*)(void*))belle_sip_object_unref);
}
......@@ -142,32 +137,28 @@ belle_sip_channel_t *belle_sip_listening_point_get_channel(belle_sip_listening_p
return chan;
}
void belle_sip_listener_set_channel_listener(belle_sip_listening_point_t *lp,belle_sip_channel_listener_t* channel_listener) {
lp->channel_listener=channel_listener;
}
static int send_keep_alive(belle_sip_channel_t* obj) {
/*keep alive*/
const char* crlfcrlf = "\r\n\r\n";
int size=strlen(crlfcrlf);
if (belle_sip_channel_send(obj,crlfcrlf,size)<0){
belle_sip_error("channel [%p]: could not send [%i] bytes of keep alive from [%s://%s:%i] to [%s:%i]" ,obj
,size
,belle_sip_channel_get_transport_name(obj)
,obj->local_ip
,obj->local_port
,obj->peer_name
,obj->peer_port);
return -1;
}else{
belle_sip_message("channel [%p]: keep alive sent to [%s://%s:%i]"
,obj
,belle_sip_channel_get_transport_name(obj)
,obj->peer_name
,obj->peer_port);
return 0;
}
const char* crlfcrlf = "\r\n\r\n";
int size=strlen(crlfcrlf);
if (belle_sip_channel_send(obj,crlfcrlf,size)<0){
belle_sip_error("channel [%p]: could not send [%i] bytes of keep alive from [%s://%s:%i] to [%s:%i]" ,obj
,size
,belle_sip_channel_get_transport_name(obj)
,obj->local_ip
,obj->local_port
,obj->peer_name
,obj->peer_port);
return -1;
}else{
belle_sip_message("channel [%p]: keep alive sent to [%s://%s:%i]"
,obj
,belle_sip_channel_get_transport_name(obj)
,obj->peer_name
,obj->peer_port);
return 0;
}
}
static int keep_alive_timer_func(void *user_data, unsigned int events) {
belle_sip_listening_point_t* lp=(belle_sip_listening_point_t*)user_data;
......@@ -186,8 +177,8 @@ static int keep_alive_timer_func(void *user_data, unsigned int events) {
belle_sip_list_free(iterator);
return BELLE_SIP_CONTINUE;
}
void belle_sip_listening_point_set_keep_alive(belle_sip_listening_point_t *lp,int ms) {
void belle_sip_listening_point_set_keep_alive(belle_sip_listening_point_t *lp,int ms) {
if (ms <=0) {
if(lp->keep_alive_timer) {
belle_sip_main_loop_remove_source(lp->stack->ml,lp->keep_alive_timer);
......@@ -199,20 +190,17 @@ void belle_sip_listening_point_set_keep_alive(belle_sip_listening_point_t *lp,in
if (!lp->keep_alive_timer) {
lp->keep_alive_timer = belle_sip_main_loop_create_timeout(lp->stack->ml
, keep_alive_timer_func
, lp
, ms
,"keep alive") ;
, keep_alive_timer_func
, lp
, ms
,"keep alive") ;
} else {
belle_sip_source_set_timeout(lp->keep_alive_timer,ms);
}
return;
}
int belle_sip_listening_point_get_keep_alive(const belle_sip_listening_point_t *lp) {
return lp->keep_alive_timer?belle_sip_source_get_timeout(lp->keep_alive_timer):-1;
}
......@@ -40,7 +40,6 @@ struct belle_sip_listening_point{
belle_sip_object_t base;
belle_sip_stack_t *stack;
belle_sip_list_t *channels;
belle_sip_channel_listener_t* channel_listener; /*initial chennel listener used for channel creation*/
belle_sip_uri_t* listening_uri;
belle_sip_source_t* keep_alive_timer;
};
......@@ -52,8 +51,6 @@ void belle_sip_listening_point_remove_channel(belle_sip_listening_point_t *lp, b
int belle_sip_listening_point_get_well_known_port(const char *transport);
belle_sip_channel_t *belle_sip_listening_point_get_channel(belle_sip_listening_point_t *lp,const char *peer_name, int peer_port);
void belle_sip_listening_point_add_channel(belle_sip_listening_point_t *lp, belle_sip_channel_t *chan);
void belle_sip_listener_set_channel_listener(belle_sip_listening_point_t *lp,belle_sip_channel_listener_t* channel_listener);
/**udp*/
typedef struct belle_sip_udp_listening_point belle_sip_udp_listening_point_t;
......
......@@ -135,13 +135,14 @@ static void nict_send_request(belle_sip_nict_t *obj){
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);
}
belle_sip_channel_queue_message(base->channel,(belle_sip_message_t*)base->request);
}
static void nict_destroy(belle_sip_nict_t *obj){
......
......@@ -77,7 +77,7 @@ static void channel_state_changed(belle_sip_channel_listener_t *obj, belle_sip_c
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov->listeners,process_io_error,&ev);
/*IO error is also relevant for internal listener like refreshers*/
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov->internal_listeners,process_io_error,&ev);
belle_sip_provider_release_channel(prov,chan);
if (!chan->force_close) belle_sip_provider_release_channel(prov,chan);
}
}
......@@ -284,7 +284,6 @@ int belle_sip_provider_add_listening_point(belle_sip_provider_t *p, belle_sip_li
belle_sip_error("Cannot add NULL lp to provider [%p]",p);
return -1;
}
belle_sip_listener_set_channel_listener(lp,BELLE_SIP_CHANNEL_LISTENER(p));
p->lps=belle_sip_list_append(p->lps,belle_sip_object_ref(lp));
return 0;
}
......@@ -476,7 +475,8 @@ belle_sip_channel_t * belle_sip_provider_get_channel(belle_sip_provider_t *p, co
}
if (candidate){
chan=belle_sip_listening_point_create_channel(candidate,name,port);
if (chan==NULL) belle_sip_error("Could not create channel to %s:%s:%i",transport,name,port);
if (chan) belle_sip_channel_add_listener(chan,(belle_sip_channel_listener_t*)p);
else belle_sip_error("Could not create channel to %s:%s:%i",transport,name,port);
return chan;
}
belle_sip_error("No listening point matching for transport %s",transport);
......@@ -490,7 +490,7 @@ void belle_sip_provider_release_channel(belle_sip_provider_t *p, belle_sip_chann
void belle_sip_provider_clean_channels(belle_sip_provider_t *p){
belle_sip_list_t *l;
belle_sip_listening_point_t *lp;
for(l=p->lps;l!=NULL;l=l->next){
lp=(belle_sip_listening_point_t*)l->data;
belle_sip_listening_point_clean_channels(lp);
......
......@@ -312,6 +312,7 @@ void belle_sip_refresher_stop(belle_sip_refresher_t* refresher) {
}
refresher->started=0;
}
belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* transaction) {
belle_sip_refresher_t* refresher;
if (belle_sip_transaction_get_state(BELLE_SIP_TRANSACTION(transaction)) != BELLE_SIP_TRANSACTION_COMPLETED) {
......@@ -335,6 +336,7 @@ belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* t
}
return refresher;
}
int belle_sip_refresher_get_expires(const belle_sip_refresher_t* refresher) {
return refresher->expires;
}
......@@ -34,7 +34,7 @@ belle_sip_stack_t * belle_sip_stack_new(const char *properties){
stack->timer_config.T2=4000;
stack->timer_config.T4=5000;
stack->transport_timeout=30000;
stack->dns_timeout=2000;
stack->dns_timeout=15000;
return stack;
}
......
......@@ -122,7 +122,6 @@ static int on_udp_data(belle_sip_udp_listening_point_t *lp, unsigned int events)
belle_sip_message("udp_listening_point: new channel created to %s:%i",chan->peer_name,chan->peer_port);
chan->lp=(belle_sip_listening_point_t*)lp; /*FIXME, exactly the same code as for channel creation from provider. might be good to factorize*/
belle_sip_listening_point_add_channel((belle_sip_listening_point_t*)lp,chan);
belle_sip_channel_add_listener(chan,lp->base.channel_listener);
}
}
if (chan){
......
......@@ -14,7 +14,8 @@ belle_sip_tester_SOURCES= belle_sip_tester.c \
belle_sip_register_tester.c \
belle_sip_dialog_tester.c \
belle_sip_refresher_tester.c \
belle_sip_resolver_tester.c
belle_sip_resolver_tester.c \
register_tester.h
belle_sip_tester_CFLAGS=$(CUNIT_CFLAGS) $(STRICT_OPTIONS)
......
......@@ -20,21 +20,7 @@
#include "CUnit/Basic.h"
#include "belle-sip/belle-sip.h"
extern belle_sip_stack_t * stack;
extern belle_sip_provider_t *prov;
extern const char *test_domain;
int call_endeed;
extern int register_init(void);
extern int register_uninit(void);
extern belle_sip_request_t* register_user(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,const char *transport
,int use_transaction
,const char* username) ;
extern void unregister_user(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,belle_sip_request_t* initial_request
,int use_transaction);
#include "register_tester.h"
......@@ -299,8 +285,8 @@ static void do_simple_call(void) {
callee_listener_callbacks.process_transaction_terminated=process_transaction_terminated;
callee_listener_callbacks.listener_destroyed=listener_destroyed;
pauline_register_req=register_user(stack, prov, "TCP" ,1 ,CALLER);
marie_register_req=register_user(stack, prov, "TLS" ,1 ,CALLEE);
pauline_register_req=register_user(stack, prov, "TCP" ,1 ,CALLER,NULL);
marie_register_req=register_user(stack, prov, "TLS" ,1 ,CALLEE,NULL);
from=belle_sip_header_address_create(NULL,belle_sip_uri_create(CALLER,test_domain));
to=belle_sip_header_address_create(NULL,belle_sip_uri_create(CALLEE,test_domain));
......
......@@ -241,6 +241,7 @@ static endpoint_t* create_endpoint(int port,const char* transport,belle_sip_list
endpoint->stack=belle_sip_stack_new(NULL);
endpoint->listener_callbacks=listener_callbacks;
endpoint->lp=belle_sip_stack_create_listening_point(endpoint->stack,"0.0.0.0",port,transport);
CU_ASSERT_PTR_NOT_NULL_FATAL(endpoint->lp);
belle_sip_object_ref(endpoint->lp);
endpoint->provider=belle_sip_stack_create_provider(endpoint->stack,endpoint->lp);
belle_sip_provider_add_sip_listener(endpoint->provider,(endpoint->listener=belle_sip_listener_create_from_callbacks(endpoint->listener_callbacks,endpoint)));
......@@ -248,6 +249,7 @@ static endpoint_t* create_endpoint(int port,const char* transport,belle_sip_list
endpoint->nonce_count=1;
return endpoint;
}
static void destroy_endpoint(endpoint_t* endpoint) {
belle_sip_object_unref(endpoint->lp);
belle_sip_object_unref(endpoint->provider);
......@@ -255,9 +257,11 @@ static void destroy_endpoint(endpoint_t* endpoint) {
belle_sip_object_unref(endpoint->listener);
belle_sip_free(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;
......@@ -323,6 +327,7 @@ static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t
CU_ASSERT_TRUE_FATAL(wait_for(server->stack,client->stack,&client->stat.twoHundredOk,1,1000));
}
refresher = belle_sip_client_transaction_create_refresher(trans);
CU_ASSERT_TRUE_FATAL(refresher!=NULL);
belle_sip_object_unref(trans);
belle_sip_refresher_set_listener(refresher,belle_sip_refresher_listener,client);
......
......@@ -21,6 +21,8 @@
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
#include "register_tester.h"
const char *test_domain="test.linphone.org";
const char *auth_domain="sip.linphone.org";
static int is_register_ok;
......@@ -166,12 +168,14 @@ belle_sip_request_t* try_register_user_at_domain(belle_sip_stack_t * stack
,int use_transaction
,const char* username
,const char* domain
,const char* outband
,const char* outbound_proxy
,int success_expected) {
belle_sip_request_t *req,*copy;
char identity[256];
char uri[256];
int i;
char *outbound=NULL;
number_of_challenge=0;
if (transport)
snprintf(uri,sizeof(uri),"sip:%s;transport=%s",domain,transport);
......@@ -181,6 +185,12 @@ belle_sip_request_t* try_register_user_at_domain(belle_sip_stack_t * stack
belle_sip_error("No TLS support, test skipped.");
return NULL;
}
if (outbound_proxy){
if (strstr(outbound_proxy,"sip:")==NULL){
outbound=belle_sip_strdup_printf("sip:%s",outbound_proxy);
}else outbound=belle_sip_strdup(outbound_proxy);
}
snprintf(identity,sizeof(identity),"Tester <sip:%s@%s>",username,domain);
req=belle_sip_request_create(
......@@ -200,7 +210,7 @@ belle_sip_request_t* try_register_user_at_domain(belle_sip_stack_t * stack
belle_sip_provider_add_sip_listener(prov,l=BELLE_SIP_LISTENER(listener));
if (use_transaction){
belle_sip_client_transaction_t *t=belle_sip_provider_create_client_transaction(prov,req);
belle_sip_client_transaction_send_request_to(t,outband?belle_sip_uri_parse(outband):NULL);
belle_sip_client_transaction_send_request_to(t,outbound?belle_sip_uri_parse(outbound):NULL);
}else belle_sip_provider_send_request(prov,req);
for(i=0;!is_register_ok && i<2 ;i++)
belle_sip_stack_sleep(stack,5000);
......@@ -208,7 +218,7 @@ belle_sip_request_t* try_register_user_at_domain(belle_sip_stack_t * stack
if (success_expected) CU_ASSERT_EQUAL(using_transaction,use_transaction);
belle_sip_provider_remove_sip_listener(prov,l);
if (outbound) belle_sip_free(outbound);
return copy;
}
belle_sip_request_t* register_user_at_domain(belle_sip_stack_t * stack
......@@ -226,20 +236,21 @@ belle_sip_request_t* register_user(belle_sip_stack_t * stack
,const char *transport
,int use_transaction
,const char* username
,const char* outband) {
return register_user_at_domain(stack,prov,transport,use_transaction,username,test_domain,outband);
,const char* outbound) {
return register_user_at_domain(stack,prov,transport,use_transaction,username,test_domain,outbound);
}
static void register_with_outband(const char *transport, int use_transaction,const char* outband ) {
static void register_with_outbound(const char *transport, int use_transaction,const char* outbound ) {
belle_sip_request_t *req;
req=register_user(stack, prov, transport,use_transaction,"tester",outband);
req=register_user(stack, prov, transport,use_transaction,"tester",outbound);
if (req) {
unregister_user(stack,prov,req,use_transaction);
belle_sip_object_unref(req);
}
}
static void register_test(const char *transport, int use_transaction) {
register_with_outband(transport,use_transaction,NULL);
register_with_outbound(transport,use_transaction,NULL);
}
static void stateless_register_udp(void){
register_test(NULL,0);
......@@ -262,8 +273,8 @@ static void stateful_register_udp_with_keep_alive(void) {
belle_sip_main_loop_sleep(belle_sip_stack_get_main_loop(stack),500);
belle_sip_listening_point_set_keep_alive(belle_sip_provider_get_listening_point(prov,"udp"),-1);
}
static void stateful_register_udp_with_outband_proxy(void){
register_with_outband("udp",1,test_domain);
static void stateful_register_udp_with_outbound_proxy(void){
register_with_outbound("udp",1,test_domain);
}
static void stateful_register_udp_delayed(void){
......@@ -385,7 +396,7 @@ int belle_sip_register_test_suite(){
if (NULL == CU_add_test(pSuite, "stateful_register_udp_with_send_error", stateful_register_udp_with_send_error)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "stateful_register_udp_with_outband_proxy", stateful_register_udp_with_outband_proxy)) {
if (NULL == CU_add_test(pSuite, "stateful_register_udp_with_outbound_proxy", stateful_register_udp_with_outbound_proxy)) {
return CU_get_error();
}
......
extern belle_sip_stack_t * stack;
extern belle_sip_provider_t *prov;
extern const char *test_domain;
int call_endeed;
extern int register_init(void);
extern int register_uninit(void);
extern belle_sip_request_t* register_user(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,const char *transport
,int use_transaction
,const char* username,const char* outbound) ;
extern void unregister_user(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,belle_sip_request_t* initial_request
,int use_transaction);
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