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
ed09a7e6
Commit
ed09a7e6
authored
May 10, 2012
by
jehan
Browse files
add new header builder functions
parent
dd8fab0f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
14 deletions
+67
-14
include/belle-sip/headers.h
include/belle-sip/headers.h
+14
-3
include/belle-sip/message.h
include/belle-sip/message.h
+2
-0
src/belle_sip_headers_impl.c
src/belle_sip_headers_impl.c
+39
-5
src/message.c
src/message.c
+6
-0
tester/belle_sip_headers_tester.c
tester/belle_sip_headers_tester.c
+4
-4
tester/belle_sip_register_tester.c
tester/belle_sip_register_tester.c
+2
-2
No files found.
include/belle-sip/headers.h
View file @
ed09a7e6
...
...
@@ -62,6 +62,7 @@ void belle_sip_header_address_set_displayname(belle_sip_header_address_t* addres
**************************************************************************************/
typedef
struct
_belle_sip_header
belle_sip_header_t
;
belle_sip_header_t
*
belle_sip_header_create
(
const
char
*
name
,
const
char
*
value
);
const
char
*
belle_sip_header_get_name
(
const
belle_sip_header_t
*
obj
);
void
belle_sip_header_set_name
(
belle_sip_header_t
*
obj
,
const
char
*
value
);
int
belle_sip_header_marshal
(
belle_sip_header_t
*
header
,
char
*
buff
,
unsigned
int
offset
,
unsigned
int
buff_size
);
...
...
@@ -78,6 +79,8 @@ typedef struct _belle_sip_header_allow belle_sip_header_allow_t;
belle_sip_header_allow_t
*
belle_sip_header_allow_new
();
belle_sip_header_allow_t
*
belle_sip_header_allow_parse
(
const
char
*
allow
)
;
belle_sip_header_allow_t
*
belle_sip_header_allow_create
(
const
char
*
methods
)
;
const
char
*
belle_sip_header_allow_get_method
(
const
belle_sip_header_allow_t
*
allow
);
void
belle_sip_header_allow_set_method
(
belle_sip_header_allow_t
*
allow
,
const
char
*
method
);
#define BELLE_SIP_HEADER_ALLOW(t) BELLE_SIP_CAST(t,belle_sip_header_allow_t)
...
...
@@ -92,6 +95,8 @@ belle_sip_header_contact_t* belle_sip_header_contact_new();
belle_sip_header_contact_t
*
belle_sip_header_contact_parse
(
const
char
*
contact
)
;
belle_sip_header_contact_t
*
belle_sip_header_contact_create
(
const
belle_sip_header_address_t
*
contact
)
;
/**
* Returns the value of the expires parameter or -1 if no expires parameter was specified or if the parameter value cannot be parsed as an int.
...
...
@@ -133,7 +138,9 @@ belle_sip_header_contact_t* belle_sip_header_contact_parse (const char* contact)
belle_sip_header_from_t
*
belle_sip_header_from_new
();
belle_sip_header_from_t
*
belle_sip_header_from_create
(
const
char
*
address
,
const
char
*
tag
);
belle_sip_header_from_t
*
belle_sip_header_from_create
(
const
belle_sip_header_address_t
*
address
,
const
char
*
tag
);
belle_sip_header_from_t
*
belle_sip_header_from_create2
(
const
char
*
address
,
const
char
*
tag
);
belle_sip_header_from_t
*
belle_sip_header_from_parse
(
const
char
*
from
)
;
...
...
@@ -155,7 +162,9 @@ belle_sip_header_contact_t* belle_sip_header_contact_parse (const char* contact)
belle_sip_header_to_t
*
belle_sip_header_to_parse
(
const
char
*
to
)
;
belle_sip_header_to_t
*
belle_sip_header_to_create
(
const
char
*
address
,
const
char
*
tag
);
belle_sip_header_to_t
*
belle_sip_header_to_create
(
const
belle_sip_header_address_t
*
address
,
const
char
*
tag
);
belle_sip_header_to_t
*
belle_sip_header_to_create2
(
const
char
*
address
,
const
char
*
tag
);
void
belle_sip_header_to_set_tag
(
belle_sip_header_to_t
*
from
,
const
char
*
tag
);
...
...
@@ -232,8 +241,9 @@ void belle_sip_header_cseq_set_seq_number(belle_sip_header_cseq_t* cseq,unsigned
typedef
struct
_belle_sip_header_content_type
belle_sip_header_content_type_t
;
belle_sip_header_content_type_t
*
belle_sip_header_content_type_new
();
belle_sip_header_content_type_t
*
belle_sip_header_content_type_parse
(
const
char
*
content_type
)
;
belle_sip_header_content_type_t
*
belle_sip_header_content_type_create
(
const
char
*
type
,
const
char
*
sub_type
)
;
const
char
*
belle_sip_header_content_type_get_type
(
const
belle_sip_header_content_type_t
*
content_type
);
void
belle_sip_header_content_type_set_type
(
belle_sip_header_content_type_t
*
content_type
,
const
char
*
type
);
const
char
*
belle_sip_header_content_type_get_subtype
(
const
belle_sip_header_content_type_t
*
content_type
);
...
...
@@ -394,6 +404,7 @@ typedef struct _belle_sip_header_extension belle_sip_header_extension_t;
belle_sip_header_extension_t
*
belle_sip_header_extension_new
();
belle_sip_header_extension_t
*
belle_sip_header_extension_parse
(
const
char
*
extension
)
;
belle_sip_header_extension_t
*
belle_sip_header_extension_create
(
const
char
*
name
,
const
char
*
value
);
const
char
*
belle_sip_header_extension_get_value
(
const
belle_sip_header_extension_t
*
extension
);
void
belle_sip_header_extension_set_value
(
belle_sip_header_extension_t
*
extension
,
const
char
*
value
);
#define BELLE_SIP_HEADER_EXTENSION(t) BELLE_SIP_CAST(t,belle_sip_header_extension_t)
...
...
include/belle-sip/message.h
View file @
ed09a7e6
...
...
@@ -82,6 +82,8 @@ void belle_sip_message_remove_header(belle_sip_message_t *msg, const char *heade
char
*
belle_sip_message_to_string
(
belle_sip_message_t
*
msg
);
const
char
*
belle_sip_message_get_body
(
belle_sip_message_t
*
msg
);
void
belle_sip_message_set_body
(
belle_sip_message_t
*
msg
,
char
*
body
,
unsigned
int
size
);
/*message keep ownership of the null terminated body buffer
void belle_sip_message_assign_body(belle_sip_message_t *msg,char* body);*/
int
belle_sip_response_get_status_code
(
const
belle_sip_response_t
*
response
);
void
belle_sip_response_set_status_code
(
belle_sip_response_t
*
response
,
int
status
);
...
...
src/belle_sip_headers_impl.c
View file @
ed09a7e6
...
...
@@ -34,6 +34,9 @@
GET_SET_STRING
(
belle_sip_header
,
name
);
belle_sip_header_t
*
belle_sip_header_create
(
const
char
*
name
,
const
char
*
value
)
{
return
BELLE_SIP_HEADER
(
belle_sip_header_extension_create
(
name
,
value
));
}
void
belle_sip_header_init
(
belle_sip_header_t
*
header
)
{
}
...
...
@@ -161,6 +164,11 @@ int belle_sip_header_allow_marshal(belle_sip_header_allow_t* allow, char* buff,u
}
BELLE_SIP_NEW_HEADER
(
header_allow
,
header
,
"Allow"
)
BELLE_SIP_PARSE
(
header_allow
)
belle_sip_header_allow_t
*
belle_sip_header_allow_create
(
const
char
*
methods
)
{
belle_sip_header_allow_t
*
allow
=
belle_sip_header_allow_new
();
belle_sip_header_allow_set_method
(
allow
,
methods
);
return
allow
;
}
GET_SET_STRING
(
belle_sip_header_allow
,
method
);
...
...
@@ -191,7 +199,11 @@ int belle_sip_header_contact_marshal(belle_sip_header_contact_t* contact, char*
}
BELLE_SIP_NEW_HEADER
(
header_contact
,
header_address
,
BELLE_SIP_CONTACT
)
BELLE_SIP_PARSE
(
header_contact
)
belle_sip_header_contact_t
*
belle_sip_header_contact_create
(
const
belle_sip_header_address_t
*
contact
)
{
belle_sip_header_contact_t
*
header
=
belle_sip_header_contact_new
();
belle_sip_header_address_clone
(
BELLE_SIP_HEADER_ADDRESS
(
header
),
contact
);
return
header
;
}
GET_SET_INT_PARAM_PRIVATE
(
belle_sip_header_contact
,
expires
,
int
,
_
)
GET_SET_INT_PARAM_PRIVATE
(
belle_sip_header_contact
,
q
,
float
,
_
);
GET_SET_BOOL
(
belle_sip_header_contact
,
wildcard
,
is
);
...
...
@@ -239,14 +251,19 @@ int belle_sip_header_from_marshal(belle_sip_header_from_t* from, char* buff,unsi
BELLE_SIP_FROM_LIKE_MARSHAL
(
from
);
}
belle_sip_header_from_t
*
belle_sip_header_from_create
(
const
char
*
address
,
const
char
*
tag
){
belle_sip_header_from_t
*
belle_sip_header_from_create
2
(
const
char
*
address
,
const
char
*
tag
){
char
*
tmp
=
belle_sip_strdup_printf
(
"From: %s"
,
address
);
belle_sip_header_from_t
*
from
=
belle_sip_header_from_parse
(
tmp
);
if
(
tag
)
belle_sip_header_from_set_tag
(
from
,
tag
);
belle_sip_free
(
tmp
);
return
from
;
}
belle_sip_header_from_t
*
belle_sip_header_from_create
(
const
belle_sip_header_address_t
*
address
,
const
char
*
tag
)
{
belle_sip_header_from_t
*
header
=
belle_sip_header_from_new
();
belle_sip_header_address_clone
(
BELLE_SIP_HEADER_ADDRESS
(
header
),
address
);
belle_sip_header_from_set_tag
(
header
,
tag
);
return
header
;
}
BELLE_SIP_NEW_HEADER
(
header_from
,
header_address
,
BELLE_SIP_FROM
)
BELLE_SIP_PARSE
(
header_from
)
GET_SET_STRING_PARAM
(
belle_sip_header_from
,
tag
);
...
...
@@ -278,14 +295,19 @@ BELLE_SIP_NEW_HEADER(header_to,header_address,"To")
BELLE_SIP_PARSE
(
header_to
)
GET_SET_STRING_PARAM
(
belle_sip_header_to
,
tag
);
belle_sip_header_to_t
*
belle_sip_header_to_create
(
const
char
*
address
,
const
char
*
tag
){
belle_sip_header_to_t
*
belle_sip_header_to_create
2
(
const
char
*
address
,
const
char
*
tag
){
char
*
tmp
=
belle_sip_strdup_printf
(
"To: %s"
,
address
);
belle_sip_header_to_t
*
to
=
belle_sip_header_to_parse
(
tmp
);
if
(
tag
)
belle_sip_header_to_set_tag
(
to
,
tag
);
belle_sip_free
(
tmp
);
return
to
;
}
belle_sip_header_to_t
*
belle_sip_header_to_create
(
const
belle_sip_header_address_t
*
address
,
const
char
*
tag
)
{
belle_sip_header_to_t
*
header
=
belle_sip_header_to_new
();
belle_sip_header_address_clone
(
BELLE_SIP_HEADER_ADDRESS
(
header
),
address
);
belle_sip_header_to_set_tag
(
header
,
tag
);
return
header
;
}
void
belle_sip_header_to_set_random_tag
(
belle_sip_header_to_t
*
obj
){
char
tmp
[
8
];
/*not less than 32bit */
...
...
@@ -528,6 +550,12 @@ int belle_sip_header_content_type_marshal(belle_sip_header_content_type_t* conte
}
BELLE_SIP_NEW_HEADER
(
header_content_type
,
parameters
,
"Content-Type"
)
BELLE_SIP_PARSE
(
header_content_type
)
belle_sip_header_content_type_t
*
belle_sip_header_content_type_create
(
const
char
*
type
,
const
char
*
sub_type
)
{
belle_sip_header_content_type_t
*
header
=
belle_sip_header_content_type_new
();
belle_sip_header_content_type_set_type
(
header
,
type
);
belle_sip_header_content_type_set_subtype
(
header
,
sub_type
);
return
header
;
}
GET_SET_STRING
(
belle_sip_header_content_type
,
type
);
GET_SET_STRING
(
belle_sip_header_content_type
,
subtype
);
/**************************
...
...
@@ -660,7 +688,13 @@ int belle_sip_header_extension_marshal(belle_sip_header_extension_t* extension,
}
BELLE_SIP_NEW_HEADER
(
header_extension
,
header
,
NULL
)
belle_sip_header_extension_t
*
belle_sip_header_extension_create
(
const
char
*
name
,
const
char
*
value
)
{
belle_sip_header_extension_t
*
ext
=
belle_sip_header_extension_new
();
belle_sip_header_set_name
(
BELLE_SIP_HEADER
(
ext
),
name
);
belle_sip_header_extension_set_value
(
ext
,
value
);
return
ext
;
}
/**
* special case for this header. I don't know why
*/
...
...
src/message.c
View file @
ed09a7e6
...
...
@@ -298,6 +298,12 @@ void belle_sip_message_set_body(belle_sip_message_t *msg,char* body,unsigned int
memcpy
(
msg
->
body
,
body
,
size
);
msg
->
body
[
size
]
=
'\0'
;
}
void
belle_sip_message_assign_body
(
belle_sip_message_t
*
msg
,
char
*
body
)
{
if
(
msg
->
body
)
{
belle_sip_free
((
void
*
)
body
);
}
msg
->
body
=
body
;
}
struct
_belle_sip_response
{
belle_sip_message_t
base
;
char
*
sip_version
;
...
...
tester/belle_sip_headers_tester.c
View file @
ed09a7e6
...
...
@@ -103,7 +103,7 @@ void test_simple_header_from(void) {
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_from
));
/*test factory*/
L_from
=
belle_sip_header_from_create
(
"super <sip:titi.com>"
,
"12345-abc"
);
L_from
=
belle_sip_header_from_create
2
(
"super <sip:titi.com>"
,
"12345-abc"
);
CU_ASSERT_PTR_NOT_NULL_FATAL
(
L_from
);
L_uri
=
belle_sip_header_address_get_uri
(
BELLE_SIP_HEADER_ADDRESS
(
L_from
));
CU_ASSERT_PTR_NOT_NULL_FATAL
(
L_uri
);
...
...
@@ -127,7 +127,7 @@ void test_simple_header_to(void) {
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_to_get_tag
(
L_to
),
"dlfjklcn6545614XX"
);
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_to
));
/*test factory*/
L_to
=
belle_sip_header_to_create
(
"
\"
super man
\"
<sip:titi.com>"
,
"12345-abc"
);
L_to
=
belle_sip_header_to_create
2
(
"
\"
super man
\"
<sip:titi.com>"
,
"12345-abc"
);
CU_ASSERT_PTR_NOT_NULL_FATAL
(
L_to
);
L_uri
=
belle_sip_header_address_get_uri
(
BELLE_SIP_HEADER_ADDRESS
(
L_to
));
CU_ASSERT_PTR_NOT_NULL_FATAL
(
L_uri
);
...
...
@@ -251,7 +251,7 @@ void test_header_record_route(void) {
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_record_route
));
}
void
test_header_route
(
void
)
{
belle_sip_header_address_t
*
address
=
belle_sip_header_address_parse
(
"<sip:212.27.52.5:5060;transport=udp;lr>
;charset=ISO-8859-4
"
);
belle_sip_header_address_t
*
address
=
belle_sip_header_address_parse
(
"<sip:212.27.52.5:5060;transport=udp;lr>"
);
CU_ASSERT_PTR_NOT_NULL_FATAL
(
address
);
belle_sip_header_route_t
*
L_route
=
belle_sip_header_route_create
(
address
);
CU_ASSERT_PTR_NOT_NULL_FATAL
(
L_route
);
...
...
@@ -262,7 +262,7 @@ void test_header_route(void) {
belle_sip_uri_t
*
L_uri
=
belle_sip_header_address_get_uri
(
BELLE_SIP_HEADER_ADDRESS
(
L_route
));
CU_ASSERT_PTR_NULL
(
belle_sip_uri_get_user
(
L_uri
));
CU_ASSERT_EQUAL
(
belle_sip_uri_get_port
(
L_uri
),
5060
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_parameters_get_parameter
(
BELLE_SIP_PARAMETERS
(
L_route
),
"charset"
),
"ISO-8859-4"
);
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_route
));
L_route
=
belle_sip_header_route_parse
(
"Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4, <sip:titi.com>"
);
...
...
tester/belle_sip_register_tester.c
View file @
ed09a7e6
...
...
@@ -128,8 +128,8 @@ static void register_test(const char *transport, int use_transaction) {
"REGISTER"
,
belle_sip_provider_create_call_id
(
prov
),
belle_sip_header_cseq_create
(
20
,
"REGISTER"
),
belle_sip_header_from_create
(
identity
,
belle_sip_random_token
(
token
,
sizeof
(
token
))),
belle_sip_header_to_create
(
identity
,
NULL
),
belle_sip_header_from_create
2
(
identity
,
belle_sip_random_token
(
token
,
sizeof
(
token
))),
belle_sip_header_to_create
2
(
identity
,
NULL
),
belle_sip_header_via_new
(),
70
);
...
...
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