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
0974a663
Commit
0974a663
authored
Jan 15, 2013
by
jehan
Browse files
add ref to header_set_next, start send error test case implementation
parent
e57c1182
Changes
9
Hide whitespace changes
Inline
Side-by-side
include/belle-sip/sipstack.h
View file @
0974a663
...
...
@@ -61,6 +61,14 @@ void belle_sip_hop_free(belle_sip_hop_t *hop);
* Can be used to simulate network transmission delays, for tests.
**/
void
belle_sip_stack_set_tx_delay
(
belle_sip_stack_t
*
stack
,
int
delay_ms
);
/**
* Can be used to simulate network sending error, for tests.
* @param stack
* @param send_error if <0, will cause channel error to be reported
**/
void
belle_sip_stack_set_send_error
(
belle_sip_stack_t
*
stack
,
int
send_error
);
BELLE_SIP_END_DECLS
...
...
src/belle_sip_headers_impl.c
View file @
0974a663
...
...
@@ -43,7 +43,7 @@ void belle_sip_header_init(belle_sip_header_t *header) {
static
void
belle_sip_header_clone
(
belle_sip_header_t
*
header
,
const
belle_sip_header_t
*
orig
){
CLONE_STRING
(
belle_sip_header
,
name
,
header
,
orig
)
if
(
belle_sip_header_get_next
(
orig
))
{
belle_sip_header_set_next
(
header
,
BELLE_SIP_HEADER
(
belle_sip_object_clone
_and_ref
(
BELLE_SIP_OBJECT
(
belle_sip_header_get_next
(
orig
)))))
;
belle_sip_header_set_next
(
header
,
BELLE_SIP_HEADER
(
belle_sip_object_clone
(
BELLE_SIP_OBJECT
(
belle_sip_header_get_next
(
orig
)))))
;
}
}
static
void
belle_sip_header_destroy
(
belle_sip_header_t
*
header
){
...
...
@@ -51,6 +51,8 @@ static void belle_sip_header_destroy(belle_sip_header_t *header){
if
(
header
->
next
)
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
header
->
next
));
}
void
belle_sip_header_set_next
(
belle_sip_header_t
*
header
,
belle_sip_header_t
*
next
)
{
if
(
next
)
belle_sip_object_ref
(
next
);
if
(
header
->
next
)
belle_sip_object_unref
(
header
->
next
);
header
->
next
=
next
;
}
belle_sip_header_t
*
belle_sip_header_get_next
(
const
belle_sip_header_t
*
header
)
{
...
...
src/belle_sip_internal.h
View file @
0974a663
...
...
@@ -506,6 +506,7 @@ struct belle_sip_stack{
belle_sip_timer_config_t
timer_config
;
int
transport_timeout
;
int
tx_delay
;
/*used to simulate network transmission delay, for tests*/
int
send_error
;
/* used to simulate network error. if <0, channel_send will return this value*/
};
void
belle_sip_stack_get_next_hop
(
belle_sip_stack_t
*
stack
,
belle_sip_request_t
*
req
,
belle_sip_hop_t
*
hop
);
...
...
src/channel.c
View file @
0974a663
...
...
@@ -297,7 +297,8 @@ int belle_sip_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
}
void
belle_sip_channel_close
(
belle_sip_channel_t
*
obj
){
BELLE_SIP_OBJECT_VPTR
(
obj
,
belle_sip_channel_t
)
->
close
(
obj
);
if
(
BELLE_SIP_OBJECT_VPTR
(
obj
,
belle_sip_channel_t
)
->
close
)
BELLE_SIP_OBJECT_VPTR
(
obj
,
belle_sip_channel_t
)
->
close
(
obj
);
/*udp channel don't have close function*/
}
const
struct
addrinfo
*
belle_sip_channel_get_peer
(
belle_sip_channel_t
*
obj
){
...
...
@@ -327,15 +328,28 @@ void channel_set_state(belle_sip_channel_t *obj, belle_sip_channel_state_t state
static
void
_send_message
(
belle_sip_channel_t
*
obj
,
belle_sip_message_t
*
msg
){
char
buffer
[
belle_sip_network_buffer_size
];
int
len
;
int
ret
=
0
;
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2
(
obj
->
listeners
,
belle_sip_channel_listener_t
,
on_sending
,
obj
,
msg
);
len
=
belle_sip_object_marshal
((
belle_sip_object_t
*
)
msg
,
buffer
,
0
,
sizeof
(
buffer
));
if
(
len
>
0
){
int
ret
=
belle_sip_channel_send
(
obj
,
buffer
,
len
);
if
(
ret
==-
1
){
if
(
!
obj
->
stack
->
send_error
)
ret
=
belle_sip_channel_send
(
obj
,
buffer
,
len
);
else
/*debug case*/
ret
=
obj
->
stack
->
send_error
;
if
(
ret
<
0
){
belle_sip_error
(
"channel [%p]: could not send [%i] bytes from [%s://%s:%i] to [%s:%i]"
,
obj
,
len
,
belle_sip_channel_get_transport_name
(
obj
)
,
obj
->
local_ip
,
obj
->
local_port
,
obj
->
peer_name
,
obj
->
peer_port
);
channel_set_state
(
obj
,
BELLE_SIP_CHANNEL_ERROR
);
belle_sip_channel_close
(
obj
);
}
else
{
belle_sip_message
(
"channel %p: message sent to [%s://%s:%i]
\n
%s"
belle_sip_message
(
"channel
[
%p
]
: message sent to [%s://%s:%i]
\n
%s"
,
obj
,
belle_sip_channel_get_transport_name
(
obj
)
,
obj
->
peer_name
...
...
src/channel.h
View file @
0974a663
...
...
@@ -106,7 +106,10 @@ void belle_sip_channel_connect(belle_sip_channel_t *obj);
void
belle_sip_channel_prepare
(
belle_sip_channel_t
*
obj
);
void
belle_sip_channel_close
(
belle_sip_channel_t
*
obj
);
/**
*
* returns number of send byte or <0 in case of error
*/
int
belle_sip_channel_send
(
belle_sip_channel_t
*
obj
,
const
void
*
buf
,
size_t
buflen
);
int
belle_sip_channel_recv
(
belle_sip_channel_t
*
obj
,
void
*
buf
,
size_t
buflen
);
...
...
src/sipstack.c
View file @
0974a663
...
...
@@ -117,6 +117,9 @@ void belle_sip_hop_free(belle_sip_hop_t *hop){
void
belle_sip_stack_set_tx_delay
(
belle_sip_stack_t
*
stack
,
int
delay_ms
){
stack
->
tx_delay
=
delay_ms
;
}
void
belle_sip_stack_set_send_error
(
belle_sip_stack_t
*
stack
,
int
send_error
){
stack
->
send_error
=
send_error
;
}
const
char
*
belle_sip_version_to_string
()
{
return
PACKAGE_VERSION
;
...
...
src/transports/tls_channel.c
View file @
0974a663
...
...
@@ -66,7 +66,7 @@ static int tls_channel_send(belle_sip_channel_t *obj, const void *buf, size_t bu
/*fix me, can block, see gnutls doc*/
err
=
gnutls_record_send
(
channel
->
session
,
buf
,
buflen
);
if
(
err
<
0
){
belle_sip_error
(
"
C
ould not send tls packet
on channel [%p]: %s
"
,
obj
,
gnutls_strerror
(
err
));
belle_sip_error
(
"
channel [%p]: c
ould not send tls packet
because [%s]
"
,
obj
,
gnutls_strerror
(
err
));
return
err
;
}
return
err
;
...
...
src/transports/udp_channel.c
View file @
0974a663
...
...
@@ -40,11 +40,7 @@ static int udp_channel_send(belle_sip_channel_t *obj, const void *buf, size_t bu
int
err
;
err
=
sendto
(
chan
->
sock
,
buf
,
buflen
,
0
,
obj
->
peer
->
ai_addr
,
obj
->
peer
->
ai_addrlen
);
if
(
err
==-
1
){
belle_sip_error
(
"Could not send UDP packet: from [%s:%i] to [%s:%i] because [%s]"
,
obj
->
local_ip
,
obj
->
local_port
,
obj
->
peer_name
,
obj
->
peer_port
,
strerror
(
errno
));
belle_sip_error
(
"channel [%p]: could not send UDP packet because [%s]"
,
strerror
(
errno
));
return
-
errno
;
}
return
err
;
...
...
tester/belle_sip_register_tester.c
View file @
0974a663
...
...
@@ -250,6 +250,12 @@ static void stateful_register_udp_delayed(void){
belle_sip_stack_set_tx_delay
(
stack
,
0
);
}
static
void
stateful_register_udp_with_send_error
(
void
){
belle_sip_stack_set_send_error
(
stack
,
-
1
);
register_test
(
NULL
,
1
);
belle_sip_stack_set_send_error
(
stack
,
0
);
}
static
void
stateful_register_tcp
(
void
){
register_test
(
"tcp"
,
1
);
}
...
...
@@ -344,6 +350,10 @@ int belle_sip_register_test_suite(){
if
(
NULL
==
CU_add_test
(
pSuite
,
"authenticate"
,
test_register_authenticate
))
{
return
CU_get_error
();
}
if
(
NULL
==
CU_add_test
(
pSuite
,
"stateful_register_udp_with_send_error"
,
stateful_register_udp_with_send_error
))
{
return
CU_get_error
();
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment