Commit 3cfd37d1 authored by jehan's avatar jehan

fix memory leaks

parent 9c20abcc
This diff is collapsed.
......@@ -293,9 +293,11 @@ typedef struct _belle_sip_header_content_length belle_sip_header_content_length_
belle_sip_header_content_length_t* belle_sip_header_content_length_new();
belle_sip_header_content_length_t* belle_sip_header_content_length_parse (const char* content_length) ;
belle_sip_header_content_length_t* belle_sip_header_content_length_create (int content_length) ;
unsigned int belle_sip_header_content_length_get_content_length(const belle_sip_header_content_length_t* content_length);
void belle_sip_header_content_length_set_content_length(belle_sip_header_content_length_t* content_length,unsigned int length);
#define BELLE_SIP_HEADER_CONTENT_LENGTH(t) BELLE_SIP_CAST(t,belle_sip_header_content_length_t)
#define BELLE_SIP_CONTENT_LENGTH "Content-Length"
/******************************
* authorization header inherit from parameters
......
......@@ -105,6 +105,7 @@ int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* a
uri=belle_sip_uri_to_string(belle_sip_header_authorization_get_uri(authorization));
md5_append(&state,(const md5_byte_t *)uri,strlen(uri));
md5_finish(&state,out);
belle_sip_free(uri);
for (di = 0; di < 16; ++di)
sprintf(ha2 + di * 2, "%02x", out[di]);
/*response=MD5(HA1:nonce:HA2)*/
......
......@@ -194,6 +194,7 @@ belle_sip_list_t* belle_sdp_media_get_media_formats(const belle_sdp_media_t* med
return media->media_formats;
}
void belle_sdp_media_set_media_formats( belle_sdp_media_t* media, belle_sip_list_t* formats) {
/*belle_sip_list_free(media->media_formats); to allow easy list management might be better to add an append format method*/
media->media_formats = formats;
}
void belle_sdp_media_destroy(belle_sdp_media_t* media) {
......
......@@ -81,9 +81,9 @@ static void belle_sip_header_address_init(belle_sip_header_address_t* object){
belle_sip_parameters_init((belle_sip_parameters_t*)object); /*super*/
}
static void belle_sip_header_address_destroy(belle_sip_header_address_t* contact) {
if (contact->displayname) belle_sip_free((void*)(contact->displayname));
if (contact->uri) belle_sip_object_unref(BELLE_SIP_OBJECT(contact->uri));
static void belle_sip_header_address_destroy(belle_sip_header_address_t* address) {
if (address->displayname) belle_sip_free((void*)(address->displayname));
if (address->uri) belle_sip_object_unref(BELLE_SIP_OBJECT(address->uri));
}
static void belle_sip_header_address_clone(belle_sip_header_address_t *addr, const belle_sip_header_address_t *orig){
......@@ -570,9 +570,15 @@ int belle_sip_header_content_length_marshal(belle_sip_header_content_length_t* c
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",content_length->content_length);
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_content_length,header,"Content-Length")
BELLE_SIP_NEW_HEADER(header_content_length,header,BELLE_SIP_CONTENT_LENGTH)
BELLE_SIP_PARSE(header_content_length)
GET_SET_INT(belle_sip_header_content_length,content_length,unsigned int)
belle_sip_header_content_length_t* belle_sip_header_content_length_create (int content_length) {
belle_sip_header_content_length_t* obj;
obj = belle_sip_header_content_length_new();
belle_sip_header_content_length_set_content_length(obj,content_length);
return obj;
}
/**************************
* Expires header object inherent from header
****************************
......@@ -737,6 +743,8 @@ static void belle_sip_header_authorization_destroy(belle_sip_header_authorizatio
}
if (authorization->cnonce) belle_sip_free((void*)authorization->cnonce);
AUTH_BASE_DESTROY(authorization)
DESTROY_STRING(authorization,response);
DESTROY_STRING(authorization,qop);
}
static void belle_sip_header_authorization_clone(belle_sip_header_authorization_t* authorization,
......@@ -843,8 +851,9 @@ struct _belle_sip_header_www_authenticate {
static void belle_sip_header_www_authenticate_destroy(belle_sip_header_www_authenticate_t* www_authenticate) {
AUTH_BASE_DESTROY(www_authenticate)
if (www_authenticate->domain) belle_sip_free((void*)www_authenticate->domain);
if (www_authenticate->qop) belle_sip_list_free(www_authenticate->qop);\
if (www_authenticate->qop) belle_sip_list_free_with_data(www_authenticate->qop,belle_sip_free);
}
void belle_sip_header_www_authenticate_init(belle_sip_header_www_authenticate_t* www_authenticate) {
www_authenticate->stale=-1;
......
......@@ -43,7 +43,7 @@ void belle_sip_fd_source_init(belle_sip_source_t *s, belle_sip_source_func_t fun
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_source_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_source_t,belle_sip_object_t,belle_sip_source_destroy,NULL,NULL,TRUE);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_source_t,belle_sip_object_t,belle_sip_source_destroy,NULL,NULL,FALSE);
belle_sip_source_t * belle_sip_fd_source_new(belle_sip_source_func_t func, void *data, int fd, unsigned int events, unsigned int timeout_value_ms){
belle_sip_source_t *s=belle_sip_object_new(belle_sip_source_t);
......@@ -69,7 +69,7 @@ struct belle_sip_main_loop{
};
void belle_sip_main_loop_remove_source(belle_sip_main_loop_t *ml, belle_sip_source_t *source){
if (!source->node.next || !source->node.prev) return; /*nothing to do*/
if (!source->node.next && !source->node.prev) return; /*nothing to do*/
ml->sources=belle_sip_list_remove_link(ml->sources,&source->node);
ml->nsources--;
......@@ -83,6 +83,7 @@ static void belle_sip_main_loop_destroy(belle_sip_main_loop_t *ml){
belle_sip_main_loop_remove_source(ml,ml->control);
close(ml->control_fds[0]);
close(ml->control_fds[1]);
belle_sip_object_unref(ml->control);
}
static int main_loop_done(void *data, unsigned int events){
......@@ -120,8 +121,8 @@ void belle_sip_main_loop_add_source(belle_sip_main_loop_t *ml, belle_sip_source_
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_timeout_source_new(func,data,timeout_value_ms);
s->on_remove=(belle_sip_source_remove_callback_t)belle_sip_object_unref;
belle_sip_main_loop_add_source(ml,s);
belle_sip_object_unref(s);
return s->id;
}
......
......@@ -149,7 +149,7 @@ belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){
belle_sip_object_vptr_t *vptr;
newobj=belle_sip_malloc0(obj->size);
newobj->ref=1;
newobj->ref=obj->vptr->initially_unowned ? 0 : 1;
newobj->vptr=obj->vptr;
vptr=obj->vptr;
......
......@@ -24,8 +24,8 @@ void belle_sip_parameters_init(belle_sip_parameters_t *obj){
}
static void belle_sip_parameters_destroy(belle_sip_parameters_t* params) {
if (params->param_list) belle_sip_list_free (params->param_list);
if (params->paramnames_list) belle_sip_list_free (params->paramnames_list);
if (params->param_list) belle_sip_list_free_with_data (params->param_list, (void (*)(void*))belle_sip_param_pair_destroy);
if (params->paramnames_list) belle_sip_list_free(params->paramnames_list);
}
static void belle_sip_parameters_clone(belle_sip_parameters_t *params, const belle_sip_parameters_t *orig){
......
......@@ -70,22 +70,135 @@ static void fix_incoming_via(belle_sip_request_t *msg, const struct addrinfo* or
belle_sip_header_via_set_rport(via,atoi(rport));
}
}
void belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents){
int err;
err=belle_sip_channel_recv(obj,&obj->input_stream.buff,MAX_CHANNEL_BUFF_SIZE-1);
if (err>0){
obj->input_stream.buff[err]='\0';
belle_sip_message("read message from %s:%i\n%s",obj->peer_name,obj->peer_port,&obj->input_stream.buff);
obj->input_stream.msg=belle_sip_message_parse(obj->input_stream.buff);
if (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);
}else{
belle_sip_error("Could not parse this message.");
static int get_message_start_pos(char *buff, size_t bufflen) {
/*FIXME still to optimize an better tested, specially REQUEST PATH and error path*/
int i;
int res=0;
int status_code;
char method[16];
char saved_char1;
int saved_char1_index;
for(i=0; i<bufflen-12;i++) { /*9=strlen( SIP/2.0\r\n)*/
saved_char1_index=bufflen-1;
saved_char1=buff[saved_char1_index]; /*make sure buff is null terminated*/
buff[saved_char1_index]='\0';
if ((res=sscanf(buff+i,"SIP/2.0 %d ",&status_code)) == 1) {
buff[saved_char1_index]=saved_char1;
return i;
}
if (res==1) return i;
else {
res=sscanf(buff+i,"%16s %*s SIP/2.0 ",(char*)&method);
}
}
return -1;
}
static void belle_sip_channel_input_stream_reset(belle_sip_channel_input_stream_t* input_stream,int message_size) {
int message_residu=0;
if (message_size>0 && input_stream->write_ptr-input_stream->read_ptr>message_size) {
/*still message available, copy a beginning of stream ?*/
message_residu = input_stream->write_ptr-input_stream->read_ptr - message_size;
memcpy(input_stream->buff
,input_stream->read_ptr+message_size,
message_residu);
}
input_stream->read_ptr=input_stream->write_ptr=input_stream->buff;
input_stream->write_ptr+=message_residu;
input_stream->state=WAITING_MESSAGE_START;
input_stream->msg=NULL;
}
static size_t belle_sip_channel_input_stream_get_buff_lenght(belle_sip_channel_input_stream_t* input_stream) {
return MAX_CHANNEL_BUFF_SIZE - (input_stream->write_ptr-input_stream->read_ptr);
}
void belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents){
int num;
int offset;
int i;
size_t message_size;
belle_sip_header_content_length_t* content_length_header;
int content_length;
num=belle_sip_channel_recv(obj,obj->input_stream.write_ptr,belle_sip_channel_input_stream_get_buff_lenght(&obj->input_stream)-1);
if (num>0){
/*first null terminate the buff*/
obj->input_stream.write_ptr[num]='\0';
obj->input_stream.write_ptr+=num;
if (obj->input_stream.state == WAITING_MESSAGE_START) {
/*search for request*/
if ((offset=get_message_start_pos(obj->input_stream.read_ptr,num)) >=0 ) {
/*message found !*/
if (offset>0) {
belle_sip_warning("trashing [%i] bytes in frot of sip message on channel [%p]",offset,obj);
obj->input_stream.read_ptr+=offset;
}
obj->input_stream.state=MESSAGE_AQUISITION;
} else {
belle_sip_warning("Unexpected [%s] received on channel [%p], trashing",obj->input_stream.write_ptr,obj);
belle_sip_channel_input_stream_reset(&obj->input_stream,0);
}
}
if (obj->input_stream.state==MESSAGE_AQUISITION) {
/*search for \r\n\r\n*/
for (i=0;i<obj->input_stream.write_ptr-obj->input_stream.read_ptr;i++) {
if (strncmp("\r\n\r\n",&obj->input_stream.read_ptr[i],4)==0) {
/*end of message found*/
belle_sip_message("read message from %s:%i\n%s",obj->peer_name,obj->peer_port,obj->input_stream.read_ptr);
obj->input_stream.msg=belle_sip_message_parse_raw(obj->input_stream.read_ptr
,obj->input_stream.write_ptr-obj->input_stream.read_ptr
,&message_size);
if (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
&& belle_sip_header_content_length_get_content_length(content_length_header)>0) {
obj->input_stream.read_ptr+=message_size;
obj->input_stream.state=BODY_AQUISITION;
} else {
/*no body*/
goto message_ready;
}
}else{
belle_sip_error("Could not parse [%s], resetting channel [%p]",obj->input_stream.read_ptr,obj);
belle_sip_channel_input_stream_reset(&obj->input_stream,0);
}
}
}
}
if (obj->input_stream.state==BODY_AQUISITION) {
content_length=belle_sip_header_content_length_get_content_length((belle_sip_header_content_length_t*)belle_sip_message_get_header(obj->input_stream.msg,BELLE_SIP_CONTENT_LENGTH));
if (content_length >= obj->input_stream.write_ptr-obj->input_stream.read_ptr) {
/*great body completed*/
belle_sip_message_set_body(obj->input_stream.msg,obj->input_stream.read_ptr,content_length);
goto message_ready;
}
}
return;
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,revents);
if (obj->input_stream.write_ptr-obj->input_stream.read_ptr>0) {
/*process residu*/
belle_sip_channel_process_data(obj,revents);
}
return;
} else {
belle_sip_error("Receive error on channel [%p]",obj);
}
return;
}
void belle_sip_channel_init(belle_sip_channel_t *obj, belle_sip_stack_t *stack, int fd, belle_sip_source_func_t process_data,const char *bindip,int localport,const char *peername, int peer_port){
obj->peer_name=belle_sip_strdup(peername);
obj->peer_port=peer_port;
......@@ -94,10 +207,11 @@ void belle_sip_channel_init(belle_sip_channel_t *obj, belle_sip_stack_t *stack,
if (strcmp(bindip,"::0")!=0 && strcmp(bindip,"0.0.0.0")!=0)
obj->local_ip=belle_sip_strdup(bindip);
obj->local_port=localport;
if (process_data) {
belle_sip_fd_source_init((belle_sip_source_t*)obj,(belle_sip_source_func_t)process_data,obj,fd,BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_ERROR,-1);
}
belle_sip_channel_input_stream_reset(&obj->input_stream,0);
}
void belle_sip_channel_add_listener(belle_sip_channel_t *obj, belle_sip_channel_listener_t *l){
......@@ -155,8 +269,15 @@ const struct addrinfo * belle_sip_channel_get_peer(belle_sip_channel_t *obj){
}
belle_sip_message_t* belle_sip_channel_pick_message(belle_sip_channel_t *obj) {
belle_sip_message_t* result = obj->input_stream.msg;
obj->input_stream.msg=NULL;
belle_sip_message_t* result=NULL;
belle_sip_list_t* front;
if ((front=obj->incoming_messages)==NULL) {
belle_sip_error("Cannot pickup incoming message, empty list");
} else {
result = (belle_sip_message_t*)obj->incoming_messages->data;
obj->incoming_messages=belle_sip_list_remove_link(obj->incoming_messages,obj->incoming_messages);
belle_sip_free(front);
}
return result;
}
......@@ -193,6 +314,7 @@ void channel_process_queue(belle_sip_channel_t *obj){
break;
case BELLE_SIP_CHANNEL_READY:
send_message(obj, obj->msg);
/* no break */
case BELLE_SIP_CHANNEL_ERROR:
belle_sip_object_unref(obj->msg);
obj->msg=NULL;
......
......@@ -51,7 +51,7 @@ void (*on_sending)(belle_sip_channel_listener_t *l, belle_sip_channel_t *obj, be
BELLE_SIP_DECLARE_INTERFACE_END
#define BELLE_SIP_CHANNEL_LISTENER(obj) BELLE_SIP_INTERFACE_CAST(obj,belle_sip_channel_listener_t)
#define MAX_CHANNEL_BUFF_SIZE 64000
#define MAX_CHANNEL_BUFF_SIZE 64000 + 1500 + 1
typedef enum input_stream_state {
WAITING_MESSAGE_START=0
......@@ -62,6 +62,8 @@ typedef enum input_stream_state {
typedef struct belle_sip_channel_input_stream{
input_stream_state_t state;
char buff[MAX_CHANNEL_BUFF_SIZE];
char* read_ptr;
char* write_ptr;
belle_sip_message_t *msg;
}belle_sip_channel_input_stream_t;
......@@ -79,6 +81,7 @@ struct belle_sip_channel{
unsigned long resolver_id;
struct addrinfo *peer;
belle_sip_message_t *msg;
belle_sip_list_t* incoming_messages;
belle_sip_channel_input_stream_t input_stream;
};
......
......@@ -27,13 +27,17 @@ void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_s
}
static void belle_sip_listening_point_uninit(belle_sip_listening_point_t *lp){
int existing_channels;
if ((existing_channels=belle_sip_list_size(lp->channels)) > 0) {
belle_sip_warning("Listening point destroying [%i] channels",existing_channels);
}
belle_sip_list_free_with_data(lp->channels,(void (*)(void*))belle_sip_object_unref);
belle_sip_free(lp->addr);
}
void belle_sip_listening_point_add_channel(belle_sip_listening_point_t *lp, belle_sip_channel_t *chan){
lp->channels=belle_sip_list_append(lp->channels,belle_sip_object_ref(chan));
lp->channels=belle_sip_list_append(lp->channels,chan);/*channel is already owned*/
}
belle_sip_channel_t *belle_sip_listening_point_create_channel(belle_sip_listening_point_t *obj, const char *dest, int port){
......
......@@ -33,6 +33,7 @@ static headers_container_t* belle_sip_message_headers_container_new(const char*
static void belle_sip_headers_container_delete(headers_container_t *obj){
belle_sip_free(obj->name);
belle_sip_list_free_with_data(obj->header_list,(void (*)(void*))belle_sip_object_unref);
belle_sip_free(obj);
}
......@@ -70,13 +71,13 @@ belle_sip_message_t* belle_sip_message_parse_raw (const char* buff, size_t buff_
tokens = antlr3CommonTokenStreamSourceNew (1025, lex->pLexer->rec->state->tokSource);
parser = belle_sip_messageParserNew (tokens);
belle_sip_message_t* l_parsed_object = parser->message_raw(parser,message_length);
if (*message_length < buff_length) {
/* if (*message_length < buff_length) {*/
/*there is a body*/
l_parsed_object->body_length=buff_length-*message_length;
/* l_parsed_object->body_length=buff_length-*message_length;
l_parsed_object->body = belle_sip_malloc(l_parsed_object->body_length+1);
memcpy(l_parsed_object->body,buff+*message_length,l_parsed_object->body_length);
l_parsed_object->body[l_parsed_object->body_length]='\0';
}
}*/
parser ->free(parser);
tokens ->free(tokens);
lex ->free(lex);
......@@ -181,6 +182,7 @@ struct _belle_sip_request {
static void belle_sip_request_destroy(belle_sip_request_t* request) {
if (request->method) belle_sip_free((void*)(request->method));
if (request->uri) belle_sip_object_unref(request->uri);
}
static void belle_sip_request_clone(belle_sip_request_t *request, const belle_sip_request_t *orig){
......
......@@ -96,6 +96,7 @@ static int channel_on_event(belle_sip_channel_listener_t *obj, belle_sip_channel
static void channel_on_sending(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, belle_sip_message_t *msg){
belle_sip_header_contact_t* contact = (belle_sip_header_contact_t*)belle_sip_message_get_header(msg,"Contact");
belle_sip_header_content_length_t* content_lenght = (belle_sip_header_content_length_t*)belle_sip_message_get_header(msg,"Content-Length");
belle_sip_uri_t* contact_uri;
/*probably better to be in channel*/
fix_outgoing_via((belle_sip_provider_t*)obj,chan,msg);
......@@ -117,6 +118,10 @@ static void channel_on_sending(belle_sip_channel_listener_t *obj, belle_sip_chan
if (belle_sip_uri_get_port(contact_uri) == 0 && chan->local_port!=5060) {
belle_sip_uri_set_port(contact_uri,chan->local_port);
}
if (!content_lenght && strcasecmp("udp",belle_sip_channel_get_transport_name(chan))!=0) {
content_lenght = belle_sip_header_content_length_create(0);
belle_sip_message_add_header(msg,(belle_sip_header_t*)content_lenght);
}
}
BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(belle_sip_provider_t,belle_sip_channel_listener_t)
......
......@@ -20,9 +20,9 @@
#include "listeningpoint_internal.h"
static void belle_sip_stack_destroy(belle_sip_stack_t *stack){
belle_sip_object_unref(stack->ml);
belle_sip_list_for_each (stack->lp,belle_sip_object_unref);
belle_sip_list_free(stack->lp);
belle_sip_object_unref(stack->ml);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_stack_t);
......
......@@ -18,13 +18,9 @@
/*
typedef enum stream_channel_state {
WAITING_MESSAGE_START=0
,MESSAGE_AQUISITION=1
,BODY_AQUISITION=2
}stream_channel_state_t;
*/
#include <sys/socket.h>
#include <netinet/tcp.h>
......@@ -38,6 +34,7 @@ struct belle_sip_stream_channel{
belle_sip_channel_t base;
};
static void stream_channel_uninit(belle_sip_stream_channel_t *obj){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
if (sock!=-1)
......@@ -115,7 +112,7 @@ static int process_data(belle_sip_channel_t *obj,unsigned int revents){
int err, errnum;
socklen_t optlen=sizeof(errnum);
belle_sip_fd_t fd=belle_sip_source_get_fd((belle_sip_source_t*)obj);
if (obj->state == BELLE_SIP_CHANNEL_CONNECTING && revents&BELLE_SIP_EVENT_WRITE) {
if (obj->state == BELLE_SIP_CHANNEL_CONNECTING && (revents&BELLE_SIP_EVENT_WRITE)) {
err=getsockopt(fd,SOL_SOCKET,SO_ERROR,&errnum,&optlen);
if (err!=0){
belle_sip_error("Failed to retrieve connection status for channel [%p]: cause [%s]",obj,belle_sip_get_socket_error_string());
......@@ -132,7 +129,7 @@ static int process_data(belle_sip_channel_t *obj,unsigned int revents){
}
belle_sip_source_set_event((belle_sip_source_t*)obj,BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_ERROR);
belle_sip_channel_set_ready(obj,(struct sockaddr*)&ss,addrlen);
return 0;
return BELLE_SIP_CONTINUE;
}else{
belle_sip_error("Connection failed for channel [%p]: cause [%s]",obj,belle_sip_get_socket_error_string());
goto connect_error;
......@@ -142,14 +139,14 @@ static int process_data(belle_sip_channel_t *obj,unsigned int revents){
} else if ( obj->state == BELLE_SIP_CHANNEL_READY) {
belle_sip_channel_process_data(obj,revents);
} else {
belle_sip_error("Unexpected event for channel [%p]",obj);
belle_sip_error("Unexpected event [%i], for channel [%p]",revents,obj);
}
return 0;
return BELLE_SIP_CONTINUE;
connect_error:
belle_sip_error("Cannot connect to [%s://%s:%s]",belle_sip_channel_get_transport_name(obj),obj->peer_name,obj->peer_port);
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
channel_process_queue(obj);
return -1;
return BELLE_SIP_STOP;
}
belle_sip_channel_t * belle_sip_channel_new_tcp(belle_sip_stack_t *stack,const char *bindip, int localport, const char *dest, int port){
......
......@@ -27,7 +27,10 @@ struct belle_sip_udp_listening_point{
static void belle_sip_udp_listening_point_uninit(belle_sip_udp_listening_point_t *lp){
if (lp->sock!=-1) close(lp->sock);
if (lp->source) belle_sip_main_loop_remove_source(lp->base.stack->ml,lp->source);
if (lp->source) {
belle_sip_main_loop_remove_source(lp->base.stack->ml,lp->source);
belle_sip_object_unref(lp->source);
}
}
static belle_sip_channel_t *udp_create_channel(belle_sip_listening_point_t *lp, const char *dest_ip, int port){
......
......@@ -31,6 +31,8 @@ static void test_authentication(void) {
belle_sip_header_authorization_set_qop(authorization,"auth");
CU_ASSERT_EQUAL_FATAL(0,belle_sip_auth_helper_fill_authorization(authorization,"REGISTER","jehan-mac","toto"));
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_response(authorization),"77ebf3de72e41934d806175586086508");
belle_sip_object_unref(www_authenticate);
belle_sip_object_unref(authorization);
}
static void test_proxy_authentication(void) {
const char* l_raw_header = "Proxy-Authenticate: Digest "
......@@ -44,6 +46,8 @@ static void test_proxy_authentication(void) {
CU_ASSERT_EQUAL_FATAL(0,belle_sip_auth_helper_fill_proxy_authorization(proxy_authorization,"REGISTER","jehan-mac","toto"));
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_response(BELLE_SIP_HEADER_AUTHORIZATION(proxy_authorization))
,"77ebf3de72e41934d806175586086508");
belle_sip_object_unref(proxy_authenticate);
belle_sip_object_unref(proxy_authorization);
}
int belle_sip_authentication_helper_suite () {
......
......@@ -52,6 +52,7 @@ static void test_attribute(void) {
char* l_raw_attribute = belle_sip_object_to_string(BELLE_SIP_OBJECT(lAttribute));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
lTmp = belle_sdp_attribute_parse(l_raw_attribute);
belle_sip_free(l_raw_attribute);
lAttribute = BELLE_SDP_ATTRIBUTE(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(lAttribute), "rtpmap");
......@@ -70,6 +71,7 @@ static void test_bandwidth(void) {
CU_ASSERT_STRING_EQUAL(belle_sdp_bandwidth_get_type(l_bandwidth), "AS");
CU_ASSERT_EQUAL(belle_sdp_bandwidth_get_value(l_bandwidth),380);
belle_sip_object_unref(BELLE_SIP_OBJECT(l_bandwidth));
belle_sip_free(l_raw_bandwidth);
}
......@@ -85,6 +87,7 @@ static void test_connection(void) {
CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_address_type(lConnection), "IP4");
CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_network_type(lConnection), "IN");
belle_sip_object_unref(BELLE_SIP_OBJECT(lConnection));
belle_sip_free(l_raw_connection);
}
static void test_email(void) {
belle_sdp_email_t* lTmp;
......@@ -96,6 +99,7 @@ static void test_email(void) {
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
CU_ASSERT_STRING_EQUAL(belle_sdp_email_get_value(l_email), " jehan <jehan@linphone.org>");
belle_sip_object_unref(BELLE_SIP_OBJECT(l_email));
belle_sip_free(l_raw_email);
}
static void test_info(void) {
belle_sdp_info_t* lTmp;
......@@ -107,6 +111,7 @@ static void test_info(void) {
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
CU_ASSERT_STRING_EQUAL(belle_sdp_info_get_value(l_info), "A Seminar on the session description protocol");
belle_sip_object_unref(BELLE_SIP_OBJECT(l_info));
belle_sip_free(l_raw_info);
}
static void test_media(void) {
belle_sdp_media_t* lTmp;
......@@ -128,6 +133,7 @@ static void test_media(void) {
}
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media));
belle_sip_free(l_raw_media);
}
static void test_media_description_base(belle_sdp_media_description_t* media_description) {
......@@ -167,7 +173,7 @@ static void test_media_description_base(belle_sdp_media_description_t* media_des
for(;list!=NULL;list=list->next){
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_value((belle_sdp_attribute_t*)(list->data)),attr[i++]);
}
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media_description));
}
static void test_media_description(void) {
......@@ -188,6 +194,8 @@ static void test_media_description(void) {
l_media_description = BELLE_SDP_MEDIA_DESCRIPTION(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
test_media_description_base(l_media_description);
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media_description));
belle_sip_free(l_raw_media_description);
return;
}
static void test_session_description(void) {
......@@ -216,6 +224,7 @@ static void test_session_description(void) {
char* l_raw_session_description = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_session_description));
belle_sip_object_unref(BELLE_SIP_OBJECT(l_session_description));
lTmp = belle_sdp_session_description_parse(l_raw_session_description);
belle_sip_free(l_raw_session_description);
l_session_description = BELLE_SDP_SESSION_DESCRIPTION(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
......@@ -245,6 +254,7 @@ static void test_session_description(void) {
CU_ASSERT_PTR_NOT_NULL(media_descriptions);
test_media_description_base((belle_sdp_media_description_t*)(media_descriptions->data));
belle_sip_object_unref(l_session_description);
return;
}
......@@ -286,25 +296,27 @@ static void test_mime_parameter(void) {
belle_sdp_media_description_t* l_media_description = belle_sdp_media_description_parse(l_src);
belle_sip_list_t* mime_parameter_list = belle_sdp_media_description_build_mime_parameters(l_media_description);
belle_sip_list_t* mime_parameter_list_iterator=mime_parameter_list;
CU_ASSERT_PTR_NOT_NULL(mime_parameter_list);
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media_description));
l_media_description = belle_sdp_media_description_new();
belle_sdp_media_description_set_media(l_media_description,belle_sdp_media_parse("m=audio 7078 RTP/AVP"));
for (;mime_parameter_list!=NULL;mime_parameter_list=mime_parameter_list->next) {
belle_sdp_media_description_append_values_from_mime_parameter(l_media_description,(belle_sdp_mime_parameter_t*)mime_parameter_list->data);
for (;mime_parameter_list_iterator!=NULL;mime_parameter_list_iterator=mime_parameter_list_iterator->next) {
belle_sdp_media_description_append_values_from_mime_parameter(l_media_description,(belle_sdp_mime_parameter_t*)mime_parameter_list_iterator->data);
}
belle_sdp_media_description_set_attribute(l_media_description,"ptime","40");
belle_sip_list_free_with_data(mime_parameter_list, (void (*)(void*))belle_sip_object_unref);
mime_parameter_list = belle_sdp_media_description_build_mime_parameters(l_media_description);
belle_sip_object_unref(l_media_description);
belle_sdp_mime_parameter_t* l_param;
belle_sdp_mime_parameter_t* lTmp = find_mime_parameter(mime_parameter_list,111);
l_param = BELLE_SDP_MIME_PARAMETER(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
CU_ASSERT_PTR_NOT_NULL(l_param);
check_mime_param(l_param,16000,1,40,-1,111,"speex","vbr=on");
belle_sip_object_unref(BELLE_SIP_OBJECT(l_param));
belle_sip_object_unref(l_param);
l_param = find_mime_parameter(mime_parameter_list,110);
CU_ASSERT_PTR_NOT_NULL(l_param);
......@@ -313,27 +325,28 @@ static void test_mime_parameter(void) {
l_param = find_mime_parameter(mime_parameter_list,3);
CU_ASSERT_PTR_NOT_NULL(l_param);
check_mime_param(l_param,8000,1,40,-1,3,"GSM",NULL);
belle_sip_object_unref(BELLE_SIP_OBJECT(l_param));
l_param = find_mime_parameter(mime_parameter_list,0);
CU_ASSERT_PTR_NOT_NULL(l_param);
check_mime_param(l_param,8000,1,40,-1,0,"PCMU",NULL);
belle_sip_object_unref(BELLE_SIP_OBJECT(l_param));
l_param = find_mime_parameter(mime_parameter_list,8);
CU_ASSERT_PTR_NOT_NULL(l_param);
check_mime_param(l_param,8000,1,40,-1,8,"PCMA",NULL);
belle_sip_object_unref(BELLE_SIP_OBJECT(l_param));
l_param = find_mime_parameter(mime_parameter_list,9);
CU_ASSERT_PTR_NOT_NULL(l_param);
check_mime_param(l_param,8000,1,40,-1,9,"G722",NULL);
belle_sip_object_unref(BELLE_SIP_OBJECT(l_param));
l_param = find_mime_parameter(mime_parameter_list,101);
CU_ASSERT_PTR_NOT_NULL(l_param);
check_mime_param(l_param,8000,1,40,-1,101,"telephone-event","0-11");
belle_sip_object_unref(BELLE_SIP_OBJECT(l_param));
belle_sip_list_free_with_data(mime_parameter_list, (void (*)(void*))belle_sip_object_unref);
}
int belle_sdp_test_suite () {
......
......@@ -91,6 +91,8 @@ static void testRegisterMessage(void) {
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Contact"));
check_uri_and_headers(message);
belle_sip_free(encoded_message);
belle_sip_object_unref(message);
}
static void testInviteMessage(void) {
......@@ -117,6 +119,8 @@ static void testInviteMessage(void) {
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Contact"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Authorization"));
check_uri_and_headers(message);
belle_sip_object_unref(message);
belle_sip_free(encoded_message);
}
static void test401Response(void) {
const char* raw_message = "SIP/2.0 401 Unauthorized\r\n"
......@@ -137,6 +141,8 @@ static void test401Response(void) {
CU_ASSERT_STRING_EQUAL(belle_sip_response_get_reason_phrase(response),"Unauthorized");
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"WWW-Authenticate"));
check_uri_and_headers(message);
belle_sip_object_unref(message);
belle_sip_free(encoded_message);
}
static void testRegisterRaw(void) {
const char* raw_message = "REGISTER sip:192.168.0.20 SIP/2.0\r\n"\
......@@ -157,8 +163,8 @@ static void testRegisterRaw(void) {
belle_sip_request_t* request = BELLE_SIP_REQUEST(message);
CU_ASSERT_STRING_EQUAL(belle_sip_request_get_method(request),"REGISTER");
CU_ASSERT_PTR_NOT_NULL(belle_sip_request_get_uri(request));
CU_ASSERT_STRING_EQUAL(belle_sip_message_get_body(message),"123456789");
CU_ASSERT_STRING_EQUAL(&raw_message[size],"123456789");
belle_sip_object_unref(message);
}
static void testOptionMessage(void) {
......@@ -177,6 +183,7 @@ static void testOptionMessage(void) {
belle_sip_request_t* request = BELLE_SIP_REQUEST(message);
CU_ASSERT_STRING_EQUAL(belle_sip_request_get_method(request),"REGISTER");
CU_ASSERT_PTR_NOT_NULL(belle_sip_request_get_uri(request));
belle_sip_object_unref(message);
}
......
......@@ -39,6 +39,7 @@ static void process_response_event(belle_sip_listener_t *obj, const belle_sip_re
CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_response_event_get_response(event));
CU_ASSERT_EQUAL(belle_sip_response_get_status_code(belle_sip_response_event_get_response(event)),200);
is_register_ok=1;
belle_sip_object_unref(belle_sip_response_event_get_response(event));
belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));
}
static void process_timeout(belle_sip_listener_t *obj, const belle_sip_timeout_event_t *event){
......@@ -111,6 +112,7 @@ static void register_test(belle_sip_listening_point_t* lp,belle_sip_uri_t* uri)