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
cde4d7c8
Commit
cde4d7c8
authored
Feb 18, 2013
by
jehan
Browse files
implement escaped to string for replace header
parent
e7bc286c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
8 deletions
+83
-8
include/belle-sip/dialog.h
include/belle-sip/dialog.h
+2
-2
include/belle-sip/headers.h
include/belle-sip/headers.h
+5
-0
src/belle_sip_headers_impl.c
src/belle_sip_headers_impl.c
+62
-0
src/belle_sip_internal.h
src/belle_sip_internal.h
+1
-1
src/belle_sip_object.c
src/belle_sip_object.c
+1
-1
src/dialog.c
src/dialog.c
+2
-2
tester/belle_sip_headers_tester.c
tester/belle_sip_headers_tester.c
+10
-2
No files found.
include/belle-sip/dialog.h
View file @
cde4d7c8
...
...
@@ -54,9 +54,9 @@ const char *belle_sip_dialog_get_dialog_id(const belle_sip_dialog_t *dialog);
const
belle_sip_header_call_id_t
*
belle_sip_dialog_get_call_id
(
const
belle_sip_dialog_t
*
dialog
);
const
belle_sip_header_address_t
*
belle_sip_get_local_party
(
const
belle_sip_dialog_t
*
dialog
);
const
belle_sip_header_address_t
*
belle_sip_
dialog_
get_local_party
(
const
belle_sip_dialog_t
*
dialog
);
const
belle_sip_header_address_t
*
belle_sip_get_remote_party
(
const
belle_sip_dialog_t
*
dialog
);
const
belle_sip_header_address_t
*
belle_sip_
dialog_
get_remote_party
(
const
belle_sip_dialog_t
*
dialog
);
/*
* get the value of the last cseq used to issue a request
*@return local cseq
...
...
include/belle-sip/headers.h
View file @
cde4d7c8
...
...
@@ -556,6 +556,11 @@ BELLESIP_EXPORT const char* belle_sip_header_replaces_get_to_tag(const belle_sip
BELLESIP_EXPORT
void
belle_sip_header_replaces_set_call_id
(
belle_sip_header_replaces_t
*
obj
,
const
char
*
callid
);
BELLESIP_EXPORT
void
belle_sip_header_replaces_set_from_tag
(
belle_sip_header_replaces_t
*
obj
,
const
char
*
from_tag
);
BELLESIP_EXPORT
void
belle_sip_header_replaces_set_to_tag
(
belle_sip_header_replaces_t
*
obj
,
const
char
*
to_tag
);
/*return a newly allocated string with the content of the header value in escaped form.
* <br> Purpose of this function is to be used to set Refer-To uri header Replaces
* @param obj Replaces object
* @return newly allocated string ex: 12345%40192.168.118.3%3Bto-tag%3D12345%3Bfrom-tag%3D5FFE-3994*/
BELLESIP_EXPORT
char
*
belle_sip_header_replaces_value_to_escaped_string
(
const
belle_sip_header_replaces_t
*
obj
);
#define BELLE_SIP_HEADER_REPLACES(t) BELLE_SIP_CAST(t,belle_sip_header_replaces_t)
#define BELLE_SIP_REPLACES "Replaces"
...
...
src/belle_sip_headers_impl.c
View file @
cde4d7c8
...
...
@@ -1270,3 +1270,65 @@ belle_sip_header_replaces_t* belle_sip_header_replaces_create2(const char* escap
belle_sip_free
(
out
);
return
replaces
;
}
char
*
belle_sip_header_replaces_value_to_escaped_string
(
const
belle_sip_header_replaces_t
*
replaces
)
{
char
buff
[
BELLE_SIP_MAX_TO_STRING_SIZE
];
char
output_buff
[
BELLE_SIP_MAX_TO_STRING_SIZE
];
unsigned
int
i
;
unsigned
int
out_buff_index
=
0
;
size_t
buff_size
=
sizeof
(
buff
);
unsigned
int
current_offset
=
0
;
output_buff
[
BELLE_SIP_MAX_TO_STRING_SIZE
-
1
]
=
'\0'
;
/*first, marshall callid/from/to tags*/
current_offset
+=
snprintf
(
buff
+
current_offset
,
buff_size
-
current_offset
,
"%s"
,
replaces
->
call_id
);
current_offset
+=
belle_sip_parameters_marshal
(
BELLE_SIP_PARAMETERS
(
replaces
),
buff
,
current_offset
,
buff_size
);
for
(
i
=
0
;
i
<
current_offset
||
i
<
BELLE_SIP_MAX_TO_STRING_SIZE
-
4
/*to make sure last param can be stored in escaped form*/
;
i
++
)
{
/*hvalue = *( hnv-unreserved / unreserved / escaped )
hnv-unreserved = "[" / "]" / "/" / "?" / ":" / "+" / "$"
unreserved = alphanum / mark
mark = "-" / "_" / "." / "!" / "~" / "*" / "'"
/ "(" / ")"*/
switch
(
buff
[
i
])
{
case
'['
:
case
']'
:
case
'/'
:
case
'?'
:
case
':'
:
case
'+'
:
case
'$'
:
case
'-'
:
case
'_'
:
case
'.'
:
case
'!'
:
case
'~'
:
case
'*'
:
case
'\''
:
case
'('
:
case
')'
:
output_buff
[
out_buff_index
++
]
=
buff
[
i
];
break
;
default:
/*serach for alfanum*/
if
((
buff
[
i
]
>=
'0'
&&
buff
[
i
]
<=
'9'
)
||
(
buff
[
i
]
>=
'A'
&&
buff
[
i
]
<=
'Z'
)
||
(
buff
[
i
]
>=
'a'
&&
buff
[
i
]
<=
'z'
)
||
(
buff
[
i
]
==
'\0'
))
{
output_buff
[
out_buff_index
++
]
=
buff
[
i
];
}
else
{
out_buff_index
+=
sprintf
(
output_buff
+
out_buff_index
,
"%%%02x"
,
buff
[
i
]);
}
break
;
}
}
return
belle_sip_strdup
(
output_buff
);
}
belle_sip_header_replaces_t
*
belle_sip_header_replaces_create
(
const
char
*
call_id
,
const
char
*
from_tag
,
const
char
*
to_tag
)
{
belle_sip_header_replaces_t
*
replaces
=
belle_sip_header_replaces_new
();
belle_sip_header_replaces_set_call_id
(
replaces
,
call_id
);
belle_sip_header_replaces_set_from_tag
(
replaces
,
from_tag
);
belle_sip_header_replaces_set_to_tag
(
replaces
,
to_tag
);
return
replaces
;
}
src/belle_sip_internal.h
View file @
cde4d7c8
...
...
@@ -835,5 +835,5 @@ int belle_sip_get_char (const char*a,int n,char*out);
#define BELLE_SIP_BRANCH_ID_LENGTH 10
/*Shall not be less than 32bit */
#define BELLE_SIP_TAG_LENGTH 6
#define BELLE_SIP_MAX_TO_STRING_SIZE 2048
#endif
src/belle_sip_object.c
View file @
cde4d7c8
...
...
@@ -284,7 +284,7 @@ int belle_sip_object_marshal(belle_sip_object_t* obj, char* buff,unsigned int of
}
char
*
belle_sip_object_to_string
(
belle_sip_object_t
*
obj
)
{
char
buff
[
2048
];
/*to be optimized*/
char
buff
[
BELLE_SIP_MAX_TO_STRING_SIZE
];
/*to be optimized*/
int
size
=
belle_sip_object_marshal
(
obj
,
buff
,
0
,
sizeof
(
buff
));
buff
[
size
]
=
'\0'
;
return
belle_sip_strdup
(
buff
);
...
...
src/dialog.c
View file @
cde4d7c8
...
...
@@ -534,11 +534,11 @@ const char *belle_sip_dialog_get_dialog_id(const belle_sip_dialog_t *dialog){
return
NULL
;
}
const
belle_sip_header_address_t
*
belle_sip_get_local_party
(
const
belle_sip_dialog_t
*
dialog
){
const
belle_sip_header_address_t
*
belle_sip_
dialog_
get_local_party
(
const
belle_sip_dialog_t
*
dialog
){
return
dialog
->
local_party
;
}
const
belle_sip_header_address_t
*
belle_sip_get_remote_party
(
const
belle_sip_dialog_t
*
dialog
){
const
belle_sip_header_address_t
*
belle_sip_
dialog_
get_remote_party
(
const
belle_sip_dialog_t
*
dialog
){
return
dialog
->
remote_party
;
}
...
...
tester/belle_sip_headers_tester.c
View file @
cde4d7c8
...
...
@@ -606,19 +606,27 @@ void test_header_replaces(void) {
}
void
test_header_replaces_escaped
(
void
)
{
belle_sip_header_replaces_t
*
L_tmp
;
belle_sip_header_replaces_t
*
L_replaces
=
belle_sip_header_replaces_create2
(
"12345%40192.168.118.3%3Bto-tag%3D12345%3Bfrom-tag%3D5FFE-3994"
);
belle_sip_header_replaces_t
*
L_replaces
;
char
*
escaped_to_string
;
belle_sip_header_replaces_t
*
L_tmp
=
belle_sip_header_replaces_create
(
"12345@192.168.118.3"
,
"5FFE-3994"
,
"12345"
);
escaped_to_string
=
belle_sip_header_replaces_value_to_escaped_string
(
L_tmp
);
L_replaces
=
belle_sip_header_replaces_create2
(
escaped_to_string
);
char
*
l_raw_header
=
belle_sip_object_to_string
(
BELLE_SIP_OBJECT
(
L_replaces
));
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_replaces
));
L_tmp
=
belle_sip_header_replaces_parse
(
l_raw_header
);
L_replaces
=
BELLE_SIP_HEADER_REPLACES
(
belle_sip_object_clone
(
BELLE_SIP_OBJECT
(
L_tmp
)));
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_tmp
));
belle_sip_free
(
l_raw_header
);
belle_sip_free
(
escaped_to_string
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_replaces_get_call_id
(
L_replaces
),
"12345@192.168.118.3"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_replaces_get_from_tag
(
L_replaces
),
"5FFE-3994"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_replaces_get_to_tag
(
L_replaces
),
"12345"
);
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_replaces
));
}
int
belle_sip_headers_test_suite
()
{
...
...
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