Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
belle-sip
Commits
3cfd37d1
Commit
3cfd37d1
authored
Mar 15, 2012
by
jehan
Browse files
fix memory leaks
parent
9c20abcc
Changes
22
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
458 additions
and
304 deletions
+458
-304
.cproject
.cproject
+226
-248
include/belle-sip/headers.h
include/belle-sip/headers.h
+2
-0
src/auth_helper.c
src/auth_helper.c
+1
-0
src/belle_sdp_impl.c
src/belle_sdp_impl.c
+1
-0
src/belle_sip_headers_impl.c
src/belle_sip_headers_impl.c
+14
-5
src/belle_sip_loop.c
src/belle_sip_loop.c
+4
-3
src/belle_sip_object.c
src/belle_sip_object.c
+1
-1
src/belle_sip_parameters.c
src/belle_sip_parameters.c
+2
-2
src/channel.c
src/channel.c
+136
-14
src/channel.h
src/channel.h
+4
-1
src/listeningpoint.c
src/listeningpoint.c
+5
-1
src/message.c
src/message.c
+5
-3
src/provider.c
src/provider.c
+5
-0
src/sipstack.c
src/sipstack.c
+1
-1
src/transports/stream_channel.c
src/transports/stream_channel.c
+9
-12
src/transports/udp_listeningpoint.c
src/transports/udp_listeningpoint.c
+4
-1
tester/auth_helper_tester.c
tester/auth_helper_tester.c
+4
-0
tester/belle_sdp_tester.c
tester/belle_sdp_tester.c
+23
-10
tester/belle_sip_message_tester.c
tester/belle_sip_message_tester.c
+9
-2
tester/belle_sip_register_tester.c
tester/belle_sip_register_tester.c
+2
-0
No files found.
.cproject
View file @
3cfd37d1
This diff is collapsed.
Click to expand it.
include/belle-sip/headers.h
View file @
3cfd37d1
...
...
@@ -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
...
...
src/auth_helper.c
View file @
3cfd37d1
...
...
@@ -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)*/
...
...
src/belle_sdp_impl.c
View file @
3cfd37d1
...
...
@@ -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
)
{
...
...
src/belle_sip_headers_impl.c
View file @
3cfd37d1
...
...
@@ -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
;
...
...
src/belle_sip_loop.c
View file @
3cfd37d1
...
...
@@ -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
,
TRU
E
);
BELLE_SIP_INSTANCIATE_VPTR
(
belle_sip_source_t
,
belle_sip_object_t
,
belle_sip_source_destroy
,
NULL
,
NULL
,
FALS
E
);
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
;
}
...
...
src/belle_sip_object.c
View file @
3cfd37d1
...
...
@@ -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
;
...
...
src/belle_sip_parameters.c
View file @
3cfd37d1
...
...
@@ -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
){
...
...
src/channel.c
View file @
3cfd37d1
...
...
@@ -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
;
...
...
src/channel.h
View file @
3cfd37d1
...
...
@@ -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
;
};
...
...
src/listeningpoint.c
View file @
3cfd37d1
...
...
@@ -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
){
...
...
src/message.c
View file @
3cfd37d1
...
...
@@ -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
){
...
...
src/provider.c
View file @
3cfd37d1
...
...
@@ -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
)
...
...
src/sipstack.c
View file @
3cfd37d1
...
...
@@ -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
);
...
...
src/transports/stream_channel.c
View file @
3cfd37d1
...
...
@@ -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
){
...
...
src/transports/udp_listeningpoint.c
View file @
3cfd37d1
...
...
@@ -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
){
...
...
tester/auth_helper_tester.c
View file @
3cfd37d1
...
...
@@ -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
()
{
...
...
tester/belle_sdp_tester.c
View file @
3cfd37d1
...
...
@@ -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
));