Commit 3cfd37d1 authored by jehan's avatar jehan
Browse files

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_ ...@@ -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_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_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); 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); 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_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 * authorization header inherit from parameters
......
...@@ -105,6 +105,7 @@ int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* a ...@@ -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)); uri=belle_sip_uri_to_string(belle_sip_header_authorization_get_uri(authorization));
md5_append(&state,(const md5_byte_t *)uri,strlen(uri)); md5_append(&state,(const md5_byte_t *)uri,strlen(uri));
md5_finish(&state,out); md5_finish(&state,out);
belle_sip_free(uri);
for (di = 0; di < 16; ++di) for (di = 0; di < 16; ++di)
sprintf(ha2 + di * 2, "%02x", out[di]); sprintf(ha2 + di * 2, "%02x", out[di]);
/*response=MD5(HA1:nonce:HA2)*/ /*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 ...@@ -194,6 +194,7 @@ belle_sip_list_t* belle_sdp_media_get_media_formats(const belle_sdp_media_t* med
return media->media_formats; return media->media_formats;
} }
void belle_sdp_media_set_media_formats( belle_sdp_media_t* media, belle_sip_list_t* 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; media->media_formats = formats;
} }
void belle_sdp_media_destroy(belle_sdp_media_t* media) { 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){ ...@@ -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*/ belle_sip_parameters_init((belle_sip_parameters_t*)object); /*super*/
} }
static void belle_sip_header_address_destroy(belle_sip_header_address_t* contact) { static void belle_sip_header_address_destroy(belle_sip_header_address_t* address) {
if (contact->displayname) belle_sip_free((void*)(contact->displayname)); if (address->displayname) belle_sip_free((void*)(address->displayname));
if (contact->uri) belle_sip_object_unref(BELLE_SIP_OBJECT(contact->uri)); 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){ 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 ...@@ -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); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",content_length->content_length);
return current_offset-offset; 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) BELLE_SIP_PARSE(header_content_length)
GET_SET_INT(belle_sip_header_content_length,content_length,unsigned int) 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 * Expires header object inherent from header
**************************** ****************************
...@@ -737,6 +743,8 @@ static void belle_sip_header_authorization_destroy(belle_sip_header_authorizatio ...@@ -737,6 +743,8 @@ static void belle_sip_header_authorization_destroy(belle_sip_header_authorizatio
} }
if (authorization->cnonce) belle_sip_free((void*)authorization->cnonce); if (authorization->cnonce) belle_sip_free((void*)authorization->cnonce);
AUTH_BASE_DESTROY(authorization) 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, static void belle_sip_header_authorization_clone(belle_sip_header_authorization_t* authorization,
...@@ -843,8 +851,9 @@ struct _belle_sip_header_www_authenticate { ...@@ -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) { 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->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) { void belle_sip_header_www_authenticate_init(belle_sip_header_www_authenticate_t* www_authenticate) {
www_authenticate->stale=-1; 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 ...@@ -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_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 * 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); belle_sip_source_t *s=belle_sip_object_new(belle_sip_source_t);
...@@ -69,7 +69,7 @@ struct belle_sip_main_loop{ ...@@ -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){ 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->sources=belle_sip_list_remove_link(ml->sources,&source->node);
ml->nsources--; ml->nsources--;
...@@ -83,6 +83,7 @@ static void belle_sip_main_loop_destroy(belle_sip_main_loop_t *ml){ ...@@ -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); belle_sip_main_loop_remove_source(ml,ml->control);
close(ml->control_fds[0]); close(ml->control_fds[0]);
close(ml->control_fds[1]); close(ml->control_fds[1]);
belle_sip_object_unref(ml->control);
} }
static int main_loop_done(void *data, unsigned int events){ 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_ ...@@ -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){ 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); 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_main_loop_add_source(ml,s);
belle_sip_object_unref(s);
return s->id; return s->id;
} }
......
...@@ -149,7 +149,7 @@ belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){ ...@@ -149,7 +149,7 @@ belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){
belle_sip_object_vptr_t *vptr; belle_sip_object_vptr_t *vptr;
newobj=belle_sip_malloc0(obj->size); newobj=belle_sip_malloc0(obj->size);
newobj->ref=1; newobj->ref=obj->vptr->initially_unowned ? 0 : 1;
newobj->vptr=obj->vptr; newobj->vptr=obj->vptr;
vptr=obj->vptr; vptr=obj->vptr;
......
...@@ -24,8 +24,8 @@ void belle_sip_parameters_init(belle_sip_parameters_t *obj){ ...@@ -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) { static void belle_sip_parameters_destroy(belle_sip_parameters_t* params) {
if (params->param_list) belle_sip_list_free (params->param_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); 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){ 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 ...@@ -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)); belle_sip_header_via_set_rport(via,atoi(rport));
} }
} }
void belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents){ static int get_message_start_pos(char *buff, size_t bufflen) {
int err; /*FIXME still to optimize an better tested, specially REQUEST PATH and error path*/
err=belle_sip_channel_recv(obj,&obj->input_stream.buff,MAX_CHANNEL_BUFF_SIZE-1); int i;
if (err>0){ int res=0;
obj->input_stream.buff[err]='\0'; int status_code;
belle_sip_message("read message from %s:%i\n%s",obj->peer_name,obj->peer_port,&obj->input_stream.buff); char method[16];
obj->input_stream.msg=belle_sip_message_parse(obj->input_stream.buff); char saved_char1;
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); int saved_char1_index;
}else{ for(i=0; i<bufflen-12;i++) { /*9=strlen( SIP/2.0\r\n)*/
belle_sip_error("Could not parse this message."); 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); 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){ 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_name=belle_sip_strdup(peername);
obj->peer_port=peer_port; obj->peer_port=peer_port;
...@@ -94,10 +207,11 @@ void belle_sip_channel_init(belle_sip_channel_t *obj, belle_sip_stack_t *stack, ...@@ -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) if (strcmp(bindip,"::0")!=0 && strcmp(bindip,"0.0.0.0")!=0)
obj->local_ip=belle_sip_strdup(bindip); obj->local_ip=belle_sip_strdup(bindip);
obj->local_port=localport; obj->local_port=localport;
if (process_data) { 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_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){ 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){ ...@@ -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* belle_sip_channel_pick_message(belle_sip_channel_t *obj) {
belle_sip_message_t* result = obj->input_stream.msg; belle_sip_message_t* result=NULL;
obj->input_stream.msg=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; return result;
} }
...@@ -193,6 +314,7 @@ void channel_process_queue(belle_sip_channel_t *obj){ ...@@ -193,6 +314,7 @@ void channel_process_queue(belle_sip_channel_t *obj){
break; break;
case BELLE_SIP_CHANNEL_READY: case BELLE_SIP_CHANNEL_READY:
send_message(obj, obj->msg); send_message(obj, obj->msg);
/* no break */
case BELLE_SIP_CHANNEL_ERROR: case BELLE_SIP_CHANNEL_ERROR:
belle_sip_object_unref(obj->msg); belle_sip_object_unref(obj->msg);
obj->msg=NULL; obj->msg=NULL;
......
...@@ -51,7 +51,7 @@ void (*on_sending)(belle_sip_channel_listener_t *l, belle_sip_channel_t *obj, be ...@@ -51,7 +51,7 @@ void (*on_sending)(belle_sip_channel_listener_t *l, belle_sip_channel_t *obj, be
BELLE_SIP_DECLARE_INTERFACE_END BELLE_SIP_DECLARE_INTERFACE_END
#define BELLE_SIP_CHANNEL_LISTENER(obj) BELLE_SIP_INTERFACE_CAST(obj,belle_sip_channel_listener_t) #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 { typedef enum input_stream_state {
WAITING_MESSAGE_START=0 WAITING_MESSAGE_START=0
...@@ -62,6 +62,8 @@ typedef enum input_stream_state { ...@@ -62,6 +62,8 @@ typedef enum input_stream_state {
typedef struct belle_sip_channel_input_stream{ typedef struct belle_sip_channel_input_stream{
input_stream_state_t state; input_stream_state_t state;
char buff[MAX_CHANNEL_BUFF_SIZE]; char buff[MAX_CHANNEL_BUFF_SIZE];
char* read_ptr;
char* write_ptr;
belle_sip_message_t *msg; belle_sip_message_t *msg;
}belle_sip_channel_input_stream_t; }belle_sip_channel_input_stream_t;
...@@ -79,6 +81,7 @@ struct belle_sip_channel{ ...@@ -79,6 +81,7 @@ struct belle_sip_channel{
unsigned long resolver_id; unsigned long resolver_id;
struct addrinfo *peer; struct addrinfo *peer;
belle_sip_message_t *msg; belle_sip_message_t *msg;
belle_sip_list_t* incoming_messages;
belle_sip_channel_input_stream_t input_stream; 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 ...@@ -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){ 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_list_free_with_data(lp->channels,(void (*)(void*))belle_sip_object_unref);
belle_sip_free(lp->addr); belle_sip_free(lp->addr);
} }
void belle_sip_listening_point_add_channel(belle_sip_listening_point_t *lp, belle_sip_channel_t *chan){ 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){ 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* ...@@ -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){ static void belle_sip_headers_container_delete(headers_container_t *obj){
belle_sip_free(obj->name); belle_sip_free(obj->name);
belle_sip_list_free_with_data(obj->header_list,(void (*)(void*))belle_sip_object_unref);
belle_sip_free(obj); belle_sip_free(obj);
} }
...@@ -70,13 +71,13 @@ belle_sip_message_t* belle_sip_message_parse_raw (const char* buff, size_t buff_ ...@@ -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); tokens = antlr3CommonTokenStreamSourceNew (1025, lex->pLexer->rec->state->tokSource);
parser = belle_sip_messageParserNew (tokens); parser = belle_sip_messageParserNew (tokens);
belle_sip_message_t* l_parsed_object = parser->message_raw(parser,message_length); 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*/ /*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); 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); memcpy(l_parsed_object->body,buff+*message_length,l_parsed_object->body_length);
l_parsed_object->body[l_parsed_object->body_length]='\0'; l_parsed_object->body[l_parsed_object->body_length]='\0';
} }*/
parser ->free(parser); parser ->free(parser);
tokens ->free(tokens); tokens ->free(tokens);
lex ->free(lex); lex ->free(lex);
...@@ -181,6 +182,7 @@ struct _belle_sip_request { ...@@ -181,6 +182,7 @@ struct _belle_sip_request {
static void belle_sip_request_destroy(belle_sip_request_t* request) { static void belle_sip_request_destroy(belle_sip_request_t* request) {
if (request->method) belle_sip_free((void*)(request->method)); 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){ 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 ...@@ -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){ 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_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; belle_sip_uri_t* contact_uri;
/*probably better to be in channel*/ /*probably better to be in channel*/
fix_outgoing_via((belle_sip_provider_t*)obj,chan,msg); 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 ...@@ -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) { if (belle_sip_uri_get_port(contact_uri) == 0 && chan->local_port!=5060) {
belle_sip_uri_set_port(contact_uri,chan->local_port); 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) BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(belle_sip_provider_t,belle_sip_channel_listener_t)
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
#include "listeningpoint_internal.h" #include "listeningpoint_internal.h"
static void belle_sip_stack_destroy(belle_sip_stack_t *stack){ 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_for_each (stack->lp,belle_sip_object_unref);
belle_sip_list_free(stack->lp); belle_sip_list_free(stack->lp);
belle_sip_object_unref(stack->ml);
} }
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_stack_t); BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_stack_t);
......
...@@ -18,13 +18,9 @@ ...@@ -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 <sys/socket.h>
#include <netinet/tcp.h>