Commit 89ee87a8 authored by Simon Morlat's avatar Simon Morlat

fix many memory leaks (but still remaning)

implement garbage collection of floating objects.
parent 2dd5a108
......@@ -650,7 +650,7 @@ BELLE_SIP_PARSE(header_route)
belle_sip_header_route_t* belle_sip_header_route_create(const belle_sip_header_address_t* route) {
belle_sip_header_route_t* header= belle_sip_header_route_new();
_belle_sip_object_copy((belle_sip_object_t*)header,(belle_sip_object_t*)route);
belle_sip_header_set_name(BELLE_SIP_HEADER(header),BELLE_SIP_ROUTE); /*restaure header name*/
belle_sip_header_set_name(BELLE_SIP_HEADER(header),BELLE_SIP_ROUTE); /*restore header name*/
return header;
}
/**************************
......
......@@ -144,6 +144,7 @@ typedef struct weak_ref{
void *belle_sip_object_get_interface_methods(belle_sip_object_t *obj, belle_sip_interface_id_t ifid);
void belle_sip_object_delete_unowned(void);
#define BELLE_SIP_OBJECT_VPTR(obj,object_type) ((BELLE_SIP_OBJECT_VPTR_TYPE(object_type)*)(((belle_sip_object_t*)obj)->vptr))
......
......@@ -95,6 +95,7 @@ static void belle_sip_main_loop_destroy(belle_sip_main_loop_t *ml){
close(ml->control_fds[0]);
close(ml->control_fds[1]);
belle_sip_object_unref(ml->control);
belle_sip_object_delete_unowned();
}
static int main_loop_done(void *data, unsigned int events){
......@@ -258,7 +259,7 @@ void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){
if (revents!=0 || (s->timeout>=0 && cur>=s->expire_ms)){
char *objdesc=belle_sip_object_to_string((belle_sip_object_t*)s);
s->expired=TRUE;
if (s->timeout>1 /*FIXME, should be 0*/) belle_sip_message("source %s notified revents=%u, timeout=%i",objdesc,revents,s->timeout);
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){
......@@ -273,6 +274,7 @@ void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){
}else belle_sip_main_loop_remove_source(ml,s);
}
belle_sip_list_free_with_data(copy,belle_sip_object_unref);
belle_sip_object_delete_unowned();
}
void belle_sip_main_loop_run(belle_sip_main_loop_t *ml){
......
......@@ -18,6 +18,8 @@
#include "belle_sip_internal.h"
static belle_sip_list_t *unowned_objects=NULL;
static int has_type(belle_sip_object_t *obj, belle_sip_type_id_t id){
belle_sip_object_vptr_t *vptr=obj->vptr;
......@@ -37,15 +39,36 @@ belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr
obj->ref=vptr->initially_unowned ? 0 : 1;
obj->vptr=vptr;
obj->size=objsize;
if (obj->ref==0){
unowned_objects=belle_sip_list_prepend(unowned_objects,obj);
}
return obj;
}
void belle_sip_object_delete_unowned(void){
belle_sip_list_t *elem,*next;
for(elem=unowned_objects;elem!=NULL;elem=next){
belle_sip_object_t *obj=(belle_sip_object_t*)elem->data;
if (obj->ref==0){
belle_sip_message("Garbage collecting unowned object of type %s",obj->vptr->type_name);
obj->ref=-1;
belle_sip_object_delete(obj);
next=elem->next;
unowned_objects=belle_sip_list_delete_link(unowned_objects,elem);
}else next=elem->next;
}
}
int belle_sip_object_is_initially_unowned(const belle_sip_object_t *obj){
return obj->vptr->initially_unowned;
}
belle_sip_object_t * belle_sip_object_ref(void *obj){
BELLE_SIP_OBJECT(obj)->ref++;
belle_sip_object_t *o=BELLE_SIP_OBJECT(obj);
if (o->ref==0){
unowned_objects=belle_sip_list_remove(unowned_objects,obj);
}
o->ref++;
return obj;
}
......@@ -53,6 +76,7 @@ void belle_sip_object_unref(void *ptr){
belle_sip_object_t *obj=BELLE_SIP_OBJECT(ptr);
if (obj->ref==-1) belle_sip_fatal("Object of type [%s] freed twice !",obj->name);
if (obj->ref==0){
unowned_objects=belle_sip_list_remove(unowned_objects,obj);
obj->ref=-1;
belle_sip_object_delete(obj);
return;
......@@ -183,9 +207,10 @@ belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){
newobj->ref=obj->vptr->initially_unowned ? 0 : 1;
newobj->vptr=obj->vptr;
newobj->size=obj->size;
_belle_sip_object_copy(newobj,obj);
if (newobj->ref==0){
unowned_objects=belle_sip_list_prepend(unowned_objects,newobj);
}
return newobj;
}
......
......@@ -91,6 +91,7 @@ void belle_sip_parameters_set_parameter(belle_sip_parameters_t* params,const cha
const belle_sip_list_t* belle_sip_parameters_get_parameter_names(const belle_sip_parameters_t* params) {
return params?params->paramnames_list:NULL;
}
void belle_sip_parameters_remove_parameter(belle_sip_parameters_t* params,const char* name) {
/*1 check if present*/
belle_sip_list_t * lResult = belle_sip_list_find_custom(params->paramnames_list, (belle_sip_compare_func)strcmp, name);
......
......@@ -62,7 +62,11 @@ static void belle_sip_uri_clone(belle_sip_uri_t* uri, const belle_sip_uri_t *ori
uri->user=orig->user?belle_sip_strdup(orig->user):NULL;
uri->host=orig->host?belle_sip_strdup(orig->host):NULL;
uri->port=orig->port;
uri->header_list=orig->header_list?(belle_sip_parameters_t*)belle_sip_object_clone(BELLE_SIP_OBJECT(orig->header_list)):NULL;
if (orig->header_list){
uri->header_list=(belle_sip_parameters_t*)belle_sip_object_clone(BELLE_SIP_OBJECT(orig->header_list));
belle_sip_object_ref(uri->header_list);
}
}
int belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff,unsigned int offset,unsigned int buff_size) {
......@@ -105,8 +109,10 @@ belle_sip_uri_t* belle_sip_uri_new () {
belle_sip_uri_t* l_object = (belle_sip_uri_t*)belle_sip_object_new(belle_sip_uri_t);
belle_sip_parameters_init((belle_sip_parameters_t*)l_object); /*super*/
l_object->header_list = belle_sip_parameters_new();
belle_sip_object_ref(l_object->header_list);
return l_object;
}
belle_sip_uri_t* belle_sip_uri_create (const char* username,const char* host) {
belle_sip_uri_t* uri = belle_sip_uri_new();
belle_sip_uri_set_user(uri,username);
......@@ -115,15 +121,16 @@ belle_sip_uri_t* belle_sip_uri_create (const char* username,const char* host) {
}
char* belle_sip_uri_to_string(belle_sip_uri_t* uri) {
char* belle_sip_uri_to_string(belle_sip_uri_t* uri) {
return belle_sip_object_to_string(BELLE_SIP_OBJECT(uri));
}
const char* belle_sip_uri_get_header(const belle_sip_uri_t* uri,const char* name) {
const char* belle_sip_uri_get_header(const belle_sip_uri_t* uri,const char* name) {
return belle_sip_parameters_get_parameter(uri->header_list,name);
}
void belle_sip_uri_set_header(belle_sip_uri_t* uri,const char* name,const char* value) {
void belle_sip_uri_set_header(belle_sip_uri_t* uri,const char* name,const char* value) {
belle_sip_parameters_set_parameter(uri->header_list,name,value);
}
......@@ -308,5 +315,5 @@ int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri
to match. The matching rules are defined for each header field
in Section 20.
*/
return 1;
return 1;
}
......@@ -197,6 +197,7 @@ belle_sip_list_t * belle_sip_list_last_elem(const belle_sip_list_t *l){
belle_sip_list_t* belle_sip_list_concat(belle_sip_list_t* first, belle_sip_list_t* second){
belle_sip_list_t* it=first;
if (it==NULL) return second;
if (second==NULL) return first;
while(it->next!=NULL) it=belle_sip_list_next(it);
it->next=second;
second->prev=it;
......
......@@ -175,6 +175,7 @@ void belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revent
,obj->input_stream.write_ptr-obj->input_stream.read_ptr
,&message_size);
if (obj->input_stream.msg){
belle_sip_object_ref(obj->input_stream.msg);
if (belle_sip_message_is_request(obj->input_stream.msg)) fix_incoming_via(BELLE_SIP_REQUEST(obj->input_stream.msg),obj->peer);
/*check for body*/
if ((content_length_header = (belle_sip_header_content_length_t*)belle_sip_message_get_header(obj->input_stream.msg,BELLE_SIP_CONTENT_LENGTH)) != NULL
......
......@@ -64,13 +64,14 @@ static void set_state(belle_sip_dialog_t *obj,belle_sip_dialog_state_t state) {
obj->previous_state=obj->state;
obj->state=state;
}
static void set_to_tag(belle_sip_dialog_t *obj, belle_sip_header_to_t *to){
const char *to_tag=belle_sip_header_to_get_tag(to);
if (obj->is_server){
if (to_tag)
if (to_tag && !obj->local_tag)
obj->local_tag=belle_sip_strdup(to_tag);
}else{
if (to_tag)
if (to_tag && !obj->remote_tag)
obj->remote_tag=belle_sip_strdup(to_tag);
}
}
......@@ -120,8 +121,8 @@ static int belle_sip_dialog_init_as_uas(belle_sip_dialog_t *obj, belle_sip_reque
*/
obj->route_set=belle_sip_list_free_with_data(obj->route_set,belle_sip_object_unref);
for(elem=belle_sip_message_get_headers((belle_sip_message_t*)req,BELLE_SIP_RECORD_ROUTE);elem!=NULL;elem=elem->next){
obj->route_set=belle_sip_list_append(obj->route_set,belle_sip_header_route_create(
(belle_sip_header_address_t*)elem->data));
obj->route_set=belle_sip_list_append(obj->route_set,belle_sip_object_ref(belle_sip_header_route_create(
(belle_sip_header_address_t*)elem->data)));
}
check_route_set(obj->route_set);
obj->remote_target=(belle_sip_header_address_t*)belle_sip_object_ref(ct);
......@@ -178,8 +179,8 @@ static int belle_sip_dialog_init_as_uac(belle_sip_dialog_t *obj, belle_sip_reque
**/
obj->route_set=belle_sip_list_free_with_data(obj->route_set,belle_sip_object_unref);
for(elem=belle_sip_message_get_headers((belle_sip_message_t*)resp,BELLE_SIP_RECORD_ROUTE);elem!=NULL;elem=elem->next){
obj->route_set=belle_sip_list_prepend(obj->route_set,belle_sip_header_route_create(
(belle_sip_header_address_t*)elem->data));
obj->route_set=belle_sip_list_prepend(obj->route_set,belle_sip_object_ref(belle_sip_header_route_create(
(belle_sip_header_address_t*)elem->data)));
}
check_route_set(obj->route_set);
obj->remote_target=(belle_sip_header_address_t*)belle_sip_object_ref(ct);
......@@ -461,7 +462,6 @@ belle_sip_request_t *belle_sip_dialog_create_request(belle_sip_dialog_t *obj, co
belle_sip_header_via_new(),
0);
if (obj->route_set) {
belle_sip_list_for_each(obj->route_set,(void (*)(void *) )belle_sip_object_ref);/*don't forget to inc ref count*/
belle_sip_message_add_headers((belle_sip_message_t*)req,obj->route_set);
}
return req;
......
......@@ -22,8 +22,6 @@
#include "belle_sip_internal.h"
static void ict_destroy(belle_sip_ict_t *obj){
}
static void on_ict_terminate(belle_sip_ict_t *obj){
belle_sip_transaction_t *base=(belle_sip_transaction_t*)obj;
......@@ -53,6 +51,10 @@ static void on_ict_terminate(belle_sip_ict_t *obj){
}
}
static void ict_destroy(belle_sip_ict_t *obj){
on_ict_terminate(obj);
}
static belle_sip_request_t *make_ack(belle_sip_ict_t *obj, belle_sip_response_t *resp){
belle_sip_transaction_t *base=(belle_sip_transaction_t*)obj;
if (obj->ack==NULL){
......
......@@ -22,10 +22,6 @@
#include "belle_sip_internal.h"
static void ist_destroy(belle_sip_ist_t *obj){
}
static void ist_on_terminate(belle_sip_ist_t *obj){
belle_sip_transaction_t *base=(belle_sip_transaction_t*)obj;
/*timer pointers are set to NULL because they can be released later*/
......@@ -51,6 +47,10 @@ static void ist_on_terminate(belle_sip_ist_t *obj){
}
}
static void ist_destroy(belle_sip_ist_t *obj){
ist_on_terminate(obj);
}
static int ist_on_timer_G(belle_sip_ist_t *obj){
belle_sip_transaction_t *base=(belle_sip_transaction_t*)obj;
if (base->state==BELLE_SIP_TRANSACTION_COMPLETED){
......
......@@ -23,6 +23,7 @@
void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_stack_t *s, const char *address, int port){
lp->stack=s;
lp->listening_uri=belle_sip_uri_create(NULL,address);
belle_sip_object_ref(lp->listening_uri);
belle_sip_uri_set_port(lp->listening_uri,port);
belle_sip_uri_set_transport_param(lp->listening_uri,BELLE_SIP_OBJECT_VPTR(lp,belle_sip_listening_point_t)->transport);
}
......
......@@ -276,7 +276,7 @@ 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->uri) request->uri=(belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)orig->uri);
if (orig->uri) request->uri=(belle_sip_uri_t*)belle_sip_object_ref(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;
......@@ -326,6 +326,7 @@ belle_sip_uri_t* belle_sip_request_extract_origin(const belle_sip_request_t* req
}
return uri;
}
int belle_sip_message_is_request(belle_sip_message_t *msg){
return BELLE_SIP_IS_INSTANCE_OF(BELLE_SIP_OBJECT(msg),belle_sip_request_t);
}
......
......@@ -23,9 +23,6 @@
#include "belle_sip_internal.h"
static void nict_destroy(belle_sip_nict_t *obj){
}
static int nict_on_timer_K(belle_sip_nict_t *obj){
belle_sip_transaction_terminate((belle_sip_transaction_t*)obj);
return BELLE_SIP_STOP;
......@@ -147,6 +144,10 @@ static void nict_send_request(belle_sip_nict_t *obj){
}
}
static void nict_destroy(belle_sip_nict_t *obj){
nict_on_terminate(obj);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_nict_t);
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_nict_t)={
......
......@@ -22,9 +22,6 @@
#include "belle_sip_internal.h"
static void nist_destroy(belle_sip_nist_t *obj){
}
static void nist_on_terminate(belle_sip_nist_t *obj){
belle_sip_transaction_t *base=(belle_sip_transaction_t*)obj;
if (obj->timer_J){
......@@ -34,6 +31,10 @@ static void nist_on_terminate(belle_sip_nist_t *obj){
}
}
static void nist_destroy(belle_sip_nist_t *obj){
nist_on_terminate(obj);
}
static int nist_on_timer_J(belle_sip_nist_t *obj){
belle_sip_transaction_terminate((belle_sip_transaction_t *)obj);
return BELLE_SIP_STOP;
......
......@@ -61,6 +61,7 @@ static void belle_sip_provider_uninit(belle_sip_provider_t *p){
belle_sip_list_free_with_data(p->client_transactions,belle_sip_object_unref);
belle_sip_list_free_with_data(p->server_transactions,belle_sip_object_unref);
belle_sip_list_free_with_data(p->auth_contexts,(void(*)(void*))belle_sip_authorization_destroy);
belle_sip_list_free_with_data(p->dialogs,belle_sip_object_unref);
}
static void channel_state_changed(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, belle_sip_channel_state_t state){
......@@ -175,7 +176,7 @@ static void belle_sip_provider_read_message(belle_sip_provider_t *prov, belle_si
*/
static int channel_on_event(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, unsigned int revents){
if (revents & BELLE_SIP_EVENT_READ){
belle_sip_message_t *msg=(belle_sip_message_t*)belle_sip_object_ref(belle_sip_channel_pick_message(chan));
belle_sip_message_t *msg=belle_sip_channel_pick_message(chan);
belle_sip_provider_dispatch_message(BELLE_SIP_PROVIDER(obj),msg);
}
return 0;
......@@ -282,9 +283,11 @@ belle_sip_header_call_id_t * belle_sip_provider_create_call_id(const belle_sip_p
belle_sip_header_call_id_set_call_id(cid,belle_sip_random_token(tmp,sizeof(tmp)));
return cid;
}
belle_sip_dialog_t * belle_sip_provider_create_dialog(belle_sip_provider_t *prov, belle_sip_transaction_t *t) {
return belle_sip_provider_create_dialog_internal(prov,t,TRUE);
}
belle_sip_dialog_t * belle_sip_provider_create_dialog_internal(belle_sip_provider_t *prov, belle_sip_transaction_t *t,unsigned int check_last_resp){
belle_sip_dialog_t *dialog=NULL;
......@@ -586,6 +589,7 @@ static void authorization_context_fill_from_auth(authorization_context_t* auth_c
auth_context->is_proxy=1;
}
}
static belle_sip_list_t* belle_sip_provider_get_auth_context_by_call_id(belle_sip_provider_t *p,belle_sip_header_call_id_t* call_id) {
belle_sip_list_t* auth_context_lst=NULL;
belle_sip_list_t* result=NULL;
......@@ -598,6 +602,7 @@ static belle_sip_list_t* belle_sip_provider_get_auth_context_by_call_id(belle_s
}
return result;
}
static void belle_sip_provider_update_or_create_auth_context(belle_sip_provider_t *p,belle_sip_header_call_id_t* call_id,belle_sip_header_www_authenticate_t* authenticate) {
belle_sip_list_t* auth_context_lst = belle_sip_provider_get_auth_context_by_call_id(p,call_id);
authorization_context_t* auth_context;
......@@ -616,6 +621,7 @@ static void belle_sip_provider_update_or_create_auth_context(belle_sip_provider
if (auth_context_lst) belle_sip_free(auth_context_lst);
return;
}
int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_request_t* request,belle_sip_response_t *resp,belle_sip_list_t** auth_infos) {
belle_sip_header_call_id_t* call_id;
belle_sip_list_t* auth_context_lst;
......@@ -645,15 +651,15 @@ int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_requ
}
/*get authenticates value from response*/
if (resp) {
belle_sip_list_t *it;
call_id = belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(resp),belle_sip_header_call_id_t);
/*searching for authentication headers*/
authenticate_lst = belle_sip_list_copy(belle_sip_message_get_headers(BELLE_SIP_MESSAGE(resp),BELLE_SIP_WWW_AUTHENTICATE));
/*search for proxy authenticate*/
authenticate_lst=belle_sip_list_append_link(authenticate_lst,belle_sip_list_copy(belle_sip_message_get_headers(BELLE_SIP_MESSAGE(resp),BELLE_SIP_PROXY_AUTHENTICATE)));
authenticate_lst=belle_sip_list_concat(authenticate_lst,belle_sip_list_copy(belle_sip_message_get_headers(BELLE_SIP_MESSAGE(resp),BELLE_SIP_PROXY_AUTHENTICATE)));
/*update auth contexts with authenticate headers from response*/
for (;authenticate_lst!=NULL;authenticate_lst=authenticate_lst->next) {
authenticate=BELLE_SIP_HEADER_WWW_AUTHENTICATE(authenticate_lst->data);
for (it=authenticate_lst;it!=NULL;it=it->next) {
authenticate=BELLE_SIP_HEADER_WWW_AUTHENTICATE(it->data);
belle_sip_provider_update_or_create_auth_context(p,call_id,authenticate);
}
belle_sip_list_free(authenticate_lst);
......
......@@ -43,6 +43,10 @@ static int timer_cb(void *user_data, unsigned int events) ;
static void schedule_timer(belle_sip_refresher_t* refresher) {
if (refresher->expires>0) {
if (refresher->timer){
belle_sip_main_loop_remove_source(belle_sip_stack_get_main_loop(refresher->transaction->base.provider->stack),refresher->timer);
belle_sip_object_unref(refresher->timer);
}
refresher->timer=belle_sip_timeout_source_new(timer_cb,refresher,refresher->expires*1000);
belle_sip_object_set_name((belle_sip_object_t*)refresher->timer,"Refresher timeout");
belle_sip_main_loop_add_source(belle_sip_stack_get_main_loop(refresher->transaction->base.provider->stack),refresher->timer);
......@@ -156,7 +160,8 @@ static int refresh(belle_sip_refresher_t* refresher) {
static int timer_cb(void *user_data, unsigned int events) {
belle_sip_refresher_t* refresher = (belle_sip_refresher_t*)user_data;
return refresh(refresher);
refresh(refresher);
return BELLE_SIP_STOP;
}
/*return 0 if succeeded*/
static belle_sip_header_contact_t* get_matching_contact(const belle_sip_transaction_t* transaction) {
......@@ -181,6 +186,7 @@ static belle_sip_header_contact_t* get_matching_contact(const belle_sip_transact
char* contact_string=belle_sip_object_to_string(BELLE_SIP_OBJECT(local_contact));
belle_sip_error("no matching contact for [%s]",contact_string);
belle_sip_free(contact_string);
belle_sip_object_unref(local_contact);
return NULL;
} else {
return BELLE_SIP_HEADER_CONTACT(local_contact);
......@@ -205,12 +211,13 @@ static int set_expires_from_trans(belle_sip_refresher_t* refresher) {
* a SUBSCRIBE request or response.
*/
if (strcmp("REGISTER",belle_sip_request_get_method(request))==0
&& (contact_header=get_matching_contact(transaction))
&& (refresher->expires=belle_sip_header_contact_get_expires(BELLE_SIP_HEADER_CONTACT(contact_header)))>=0) {
&& (contact_header=get_matching_contact(transaction))!=NULL){
refresher->expires=belle_sip_header_contact_get_expires(BELLE_SIP_HEADER_CONTACT(contact_header));
/*great, we have an expire param from contact header*/
belle_sip_object_unref(contact_header);
contact_header=NULL;
} else {
}
if (refresher->expires==-1){
/*no contact with expire or not relevant, looking for Expires header*/
if ((expires_header=(belle_sip_header_expires_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(response),BELLE_SIP_EXPIRES))) {
refresher->expires = belle_sip_header_expires_get_expires(expires_header);
......@@ -245,11 +252,11 @@ int belle_sip_refresher_start(belle_sip_refresher_t* refresher) {
}
void belle_sip_refresher_stop(belle_sip_refresher_t* refresher) {
if (refresher->timer)
belle_sip_main_loop_cancel_source(belle_sip_stack_get_main_loop(refresher->transaction->base.provider->stack),refresher->timer->id);
refresher->timer=NULL;
if (refresher->timer){
belle_sip_main_loop_remove_source(belle_sip_stack_get_main_loop(refresher->transaction->base.provider->stack), refresher->timer);
belle_sip_object_unref(refresher->timer);
refresher->timer=NULL;
}
}
belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* transaction) {
......
......@@ -110,7 +110,7 @@ BELLE_SIP_IMPLEMENT_INTERFACE_END
BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(belle_sip_callbacks_t,belle_sip_listener_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_callbacks_t,belle_sip_object_t,NULL,NULL,NULL,TRUE);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_callbacks_t,belle_sip_object_t,NULL,NULL,NULL,FALSE);
belle_sip_listener_t *belle_sip_listener_create_from_callbacks(const belle_sip_listener_callbacks_t *callbacks, void *user_ctx){
......
......@@ -109,21 +109,21 @@ belle_sip_channel_t * belle_sip_channel_new_udp(belle_sip_stack_t *stack, int so
belle_sip_channel_t * belle_sip_channel_new_udp_with_addr(belle_sip_stack_t *stack, int sock, const char *bindip, int localport, const struct addrinfo *peer){
belle_sip_udp_channel_t *obj=belle_sip_object_new(belle_sip_udp_channel_t);
struct addrinfo *ai=belle_sip_new0(struct addrinfo);
struct addrinfo ai;
char name[NI_MAXHOST];
char serv[NI_MAXSERV];
int err;
obj->sock=sock;
*ai=*peer;
err=getnameinfo(ai->ai_addr,ai->ai_addrlen,name,sizeof(name),serv,sizeof(serv),NI_NUMERICHOST|NI_NUMERICSERV);
ai=*peer;
err=getnameinfo(ai.ai_addr,ai.ai_addrlen,name,sizeof(name),serv,sizeof(serv),NI_NUMERICHOST|NI_NUMERICSERV);
if (err!=0){
belle_sip_error("belle_sip_channel_new_udp_with_addr(): getnameinfo() failed: %s",gai_strerror(err));
belle_sip_object_unref(obj);
return NULL;
}
belle_sip_channel_init((belle_sip_channel_t*)obj,stack,bindip,localport,name,atoi(serv));
err=getaddrinfo(name,serv,ai,&obj->base.peer); /*might be optimized someway ?*/
err=getaddrinfo(name,serv,&ai,&obj->base.peer); /*might be optimized someway ?*/
if (err!=0){
belle_sip_error("getaddrinfo() failed for channel [%p] error [%s]",obj,gai_strerror(err));
}
......
......@@ -165,6 +165,7 @@ static void callee_process_request_event(void *user_ctx, const belle_sip_request
belle_sip_message_add_header(BELLE_SIP_MESSAGE(ok_response),BELLE_SIP_HEADER(content_type));
belle_sip_message_add_header(BELLE_SIP_MESSAGE(ok_response),BELLE_SIP_HEADER(content_length));
belle_sip_message_set_body(BELLE_SIP_MESSAGE(ok_response),sdp,strlen(sdp));
belle_sip_object_ref(ok_response);
/*only send ringing*/
belle_sip_server_transaction_send_response(server_transaction,ringing_response);
} else if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_CONFIRMED) {
......@@ -198,6 +199,8 @@ static void caller_process_response_event(void *user_ctx, const belle_sip_respon
CU_ASSERT_EQUAL(status,180);
/*send 200ok from callee*/
belle_sip_server_transaction_send_response(inserv_transaction,ok_response);
belle_sip_object_unref(ok_response);
ok_response=NULL;
} else if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_CONFIRMED) {
ack=belle_sip_dialog_create_ack(dialog,belle_sip_header_cseq_get_seq_number(invite_cseq));
belle_sip_dialog_send_ack(dialog,ack);
......
......@@ -24,7 +24,7 @@
const char *test_domain="test.linphone.org";
const char *auth_domain="sip.linphone.org";
static int is_register_ok;
static int number_of_challange;
static int number_of_challenge;
static int using_transaction;
belle_sip_stack_t * stack;
belle_sip_provider_t *prov;
......@@ -50,7 +50,7 @@ static void process_response_event(belle_sip_listener_t *obj, const belle_sip_re
,status=belle_sip_response_get_status_code(belle_sip_response_event_get_response(event))
,belle_sip_response_get_reason_phrase(belle_sip_response_event_get_response(event)));
if (status==401) {
CU_ASSERT_NOT_EQUAL_FATAL(number_of_challange,2);
CU_ASSERT_NOT_EQUAL_FATAL(number_of_challenge,2);
CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_response_event_get_client_transaction(event)); /*require transaction mode*/
request=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(belle_sip_response_event_get_client_transaction(event)));
belle_sip_header_cseq_t* cseq=(belle_sip_header_cseq_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_CSEQ);
......@@ -58,7 +58,7 @@ static void process_response_event(belle_sip_listener_t *obj, const belle_sip_re
CU_ASSERT_TRUE_FATAL(belle_sip_provider_add_authorization(prov,request,belle_sip_response_event_get_response(event),NULL));
belle_sip_client_transaction_t *t=belle_sip_provider_create_client_transaction(prov,request);
belle_sip_client_transaction_send_request(t);
number_of_challange++;
number_of_challenge++;
authorized_request=request;
} else {
CU_ASSERT_EQUAL(status,200);
......@@ -171,7 +171,7 @@ belle_sip_request_t* register_user_at_domain(belle_sip_stack_t * stack
belle_sip_request_t *req,*copy;
char identity[256];
char uri[256];
number_of_challange=0;
number_of_challenge=0;
if (transport)
snprintf(uri,sizeof(uri),"sip:%s;transport=%s",domain,transport);
else snprintf(uri,sizeof(uri),"sip:%s",domain);
......@@ -195,7 +195,7 @@ belle_sip_request_t* register_user_at_domain(belle_sip_stack_t * stack
using_transaction=0;
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(600)));
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_contact_new()));
copy=(belle_sip_request_t*)belle_sip_object_clone((belle_sip_object_t*)req);
copy=(belle_sip_request_t*)belle_sip_object_ref(belle_sip_object_clone((belle_sip_object_t*)req));
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);
......@@ -211,6 +211,7 @@ belle_sip_request_t* register_user_at_domain(belle_sip_stack_t * stack
return copy;
}
belle_sip_request_t* register_user(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,const char *transport
......@@ -218,10 +219,14 @@ belle_sip_request_t* register_user(belle_sip_stack_t * stack
,const char* username) {
return register_user_at_domain(stack,prov,transport,use_transaction,username,test_domain);
}
static void register_test(const char *transport, int use_transaction) {
belle_sip_request_t *req;
req=register_user(stack, prov, transport,use_transaction,"tester");
if (req) unregister_user(stack,prov,req,use_transaction);
if (req) {
unregister_user(stack,prov,req,use_transaction);
belle_sip_object_unref(req);
}
}
static void stateless_register_udp(void){
......@@ -298,7 +303,7 @@ static void test_bad_request() {
belle_sip_provider_remove_sip_listener(prov,bad_req_listener);
}
static void test_register_authenticate() {
number_of_challange=0;
number_of_challenge=0;
authorized_request=NULL;
register_user_at_domain(stack, prov, "udp",1,"bellesip",auth_domain);
if (authorized_request) unregister_user(stack,prov,authorized_request,1);
......
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