Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
belle-sip
Commits
9f1daa62
Commit
9f1daa62
authored
Nov 18, 2015
by
jehan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a support for multipart related body
parent
f576f14c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
6 deletions
+79
-6
include/belle-sip/bodyhandler.h
include/belle-sip/bodyhandler.h
+7
-0
include/belle-sip/list.h
include/belle-sip/list.h
+2
-1
include/belle-sip/mainloop.h
include/belle-sip/mainloop.h
+25
-0
src/bodyhandler.c
src/bodyhandler.c
+8
-2
src/message.c
src/message.c
+37
-3
No files found.
include/belle-sip/bodyhandler.h
View file @
9f1daa62
...
...
@@ -31,6 +31,7 @@ BELLE_SIP_BEGIN_DECLS
typedef
void
(
*
belle_sip_body_handler_progress_callback_t
)(
belle_sip_body_handler_t
*
obj
,
belle_sip_message_t
*
msg
,
void
*
user_data
,
size_t
transfered
,
size_t
expected_total
);
BELLESIP_EXPORT
void
belle_sip_body_handler_add_header
(
belle_sip_body_handler_t
*
obj
,
belle_sip_header_t
*
header
);
BELLESIP_EXPORT
const
belle_sip_list_t
*
belle_sip_body_handler_get_headers
(
const
belle_sip_body_handler_t
*
obj
);
BELLESIP_EXPORT
size_t
belle_sip_body_handler_get_size
(
const
belle_sip_body_handler_t
*
obj
);
BELLESIP_EXPORT
void
belle_sip_body_handler_set_size
(
belle_sip_body_handler_t
*
obj
,
size_t
size
);
BELLESIP_EXPORT
size_t
belle_sip_body_handler_get_transfered_size
(
const
belle_sip_body_handler_t
*
obj
);
...
...
@@ -84,7 +85,13 @@ BELLESIP_EXPORT belle_sip_file_body_handler_t *belle_sip_file_body_handler_new(c
BELLESIP_EXPORT
belle_sip_multipart_body_handler_t
*
belle_sip_multipart_body_handler_new
(
belle_sip_body_handler_progress_callback_t
progress_cb
,
void
*
data
,
belle_sip_body_handler_t
*
first_part
);
BELLESIP_EXPORT
void
belle_sip_multipart_body_handler_add_part
(
belle_sip_multipart_body_handler_t
*
obj
,
belle_sip_body_handler_t
*
part
);
BELLESIP_EXPORT
const
belle_sip_list_t
*
belle_sip_multipart_body_handler_get_parts
(
const
belle_sip_multipart_body_handler_t
*
obj
);
/*
*multipar body in sens of rfc2387
*/
BELLESIP_EXPORT
unsigned
int
belle_sip_multipart_body_handler_is_related
(
const
belle_sip_multipart_body_handler_t
*
obj
);
BELLESIP_EXPORT
void
belle_sip_multipart_body_handler_set_related
(
belle_sip_multipart_body_handler_t
*
obj
,
unsigned
int
yesno
);
BELLE_SIP_END_DECLS
#endif
include/belle-sip/list.h
View file @
9f1daa62
...
...
@@ -18,6 +18,7 @@
#ifndef BELLE_SIP_LIST_H_
#define BELLE_SIP_LIST_H_
BELLE_SIP_BEGIN_DECLS
struct
_belle_sip_list
{
struct
_belle_sip_list
*
next
;
struct
_belle_sip_list
*
prev
;
...
...
@@ -53,5 +54,5 @@ BELLESIP_EXPORT belle_sip_list_t * belle_sip_list_copy(const belle_sip_list_t *
/*copy list elements and associated data, using the supplied function pointer*/
BELLESIP_EXPORT
belle_sip_list_t
*
belle_sip_list_copy_with_data
(
const
belle_sip_list_t
*
list
,
void
*
(
*
copyfunc
)(
void
*
));
BELLE_SIP_END_DECLS
#endif
/* BELLE_SIP_LIST_H_ */
include/belle-sip/mainloop.h
View file @
9f1daa62
...
...
@@ -127,6 +127,31 @@ BELLESIP_EXPORT int belle_sip_main_loop_quit(belle_sip_main_loop_t *ml);
**/
BELLESIP_EXPORT
void
belle_sip_main_loop_cancel_source
(
belle_sip_main_loop_t
*
ml
,
unsigned
long
id
);
#if defined(__cplusplus) && defined(BELLE_SIP_USE_STL)
#include <functional>
/*purpose of this function is to simplify c++ timer integration.
* ex:
* std::string helloworld("Hello world):
* belle_sip_source_cpp_func_t *func = new belle_sip_source_cpp_func_t([helloworld](unsigned int events) {
* std::cout << helloworld << std::endl;
* return BELLE_SIP_STOP;
* });
*create timer
*mTimer = belle_sip_main_loop_create_timeout( mainloop
* ,(belle_sip_source_func_t)belle_sip_source_cpp_func
* , func
* , 1000
* ,"timer for c++");
*
*/
typedef
std
::
function
<
int
(
unsigned
int
)
>
belle_sip_source_cpp_func_t
;
BELLESIP_EXPORT
inline
int
belle_sip_source_cpp_func
(
belle_sip_source_cpp_func_t
*
user_data
,
unsigned
int
events
)
{
int
result
=
(
*
user_data
)(
events
);
delete
user_data
;
return
result
;
}
#endif
BELLE_SIP_END_DECLS
#endif
src/bodyhandler.c
View file @
9f1daa62
...
...
@@ -37,7 +37,9 @@ void belle_sip_body_handler_add_header(belle_sip_body_handler_t *obj, belle_sip_
obj
->
headers
=
belle_sip_list_append
(
obj
->
headers
,
belle_sip_object_ref
(
header
));
}
}
const
belle_sip_list_t
*
belle_sip_body_handler_get_headers
(
const
belle_sip_body_handler_t
*
obj
)
{
return
obj
->
headers
;
}
static
void
belle_sip_body_handler_clone
(
belle_sip_body_handler_t
*
obj
,
const
belle_sip_body_handler_t
*
orig
){
obj
->
progress_cb
=
orig
->
progress_cb
;
obj
->
user_data
=
orig
->
user_data
;
...
...
@@ -354,7 +356,9 @@ belle_sip_file_body_handler_t *belle_sip_file_body_handler_new(const char *filep
struct
belle_sip_multipart_body_handler
{
belle_sip_body_handler_t
base
;
belle_sip_list_t
*
parts
;
unsigned
int
related
;
};
GET_SET_BOOL
(
belle_sip_multipart_body_handler
,
related
,
is
);
static
void
belle_sip_multipart_body_handler_destroy
(
belle_sip_multipart_body_handler_t
*
obj
){
belle_sip_list_free_with_data
(
obj
->
parts
,
belle_sip_object_unref
);
...
...
@@ -477,5 +481,7 @@ void belle_sip_multipart_body_handler_add_part(belle_sip_multipart_body_handler_
}
obj
->
parts
=
belle_sip_list_append
(
obj
->
parts
,
belle_sip_object_ref
(
part
));
}
const
belle_sip_list_t
*
belle_sip_multipart_body_handler_get_parts
(
const
belle_sip_multipart_body_handler_t
*
obj
)
{
return
obj
->
parts
;
}
src/message.c
View file @
9f1daa62
...
...
@@ -479,9 +479,43 @@ void belle_sip_message_set_body_handler(belle_sip_message_t *msg, belle_sip_body
/* In case of multipart message, we must add the message Content-Type header containing the boundary */
if
(
body_handler
!=
NULL
)
{
if
(
BELLE_SIP_OBJECT_IS_INSTANCE_OF
(
body_handler
,
belle_sip_multipart_body_handler_t
)){
char
*
content_type
=
belle_sip_strdup_printf
(
"multipart/form-data; boundary=%s"
,
BELLESIP_MULTIPART_BOUNDARY
);
belle_sip_message_add_header
(
BELLE_SIP_MESSAGE
(
msg
),
belle_sip_header_create
(
"Content-type"
,
content_type
));
belle_sip_free
(
content_type
);
belle_sip_multipart_body_handler_t
*
multipart_body_handler
=
BELLE_SIP_MULTIPART_BODY_HANDLER
(
body_handler
);
belle_sip_header_content_type_t
*
content_type
=
belle_sip_header_content_type_new
();
belle_sip_header_content_type_set_type
(
content_type
,
"multipart"
);
if
(
belle_sip_multipart_body_handler_is_related
(
multipart_body_handler
))
{
const
belle_sip_list_t
*
parts
=
belle_sip_multipart_body_handler_get_parts
(
multipart_body_handler
);
if
(
parts
)
{
belle_sip_body_handler_t
*
first_part
=
BELLE_SIP_BODY_HANDLER
(
parts
->
data
);
const
belle_sip_list_t
*
first_part_headers
=
belle_sip_body_handler_get_headers
(
first_part
);
belle_sip_list_t
*
it
;
belle_sip_header_content_type_t
*
first_part_content_type
=
NULL
;;
for
(
it
=
(
belle_sip_list_t
*
)
first_part_headers
;
it
!=
NULL
;
it
=
it
->
next
)
{
belle_sip_header_t
*
header
=
BELLE_SIP_HEADER
(
it
->
data
);
if
(
strcasecmp
(
"Content-Type"
,
belle_sip_header_get_name
(
header
))
==
0
)
{
first_part_content_type
=
BELLE_SIP_HEADER_CONTENT_TYPE
(
header
);
break
;
}
}
if
(
first_part_content_type
)
{
char
*
type_slash_subtype
=
belle_sip_strdup_printf
(
"%s/%s"
,
belle_sip_header_content_type_get_type
(
first_part_content_type
)
,
belle_sip_header_content_type_get_subtype
(
first_part_content_type
));
belle_sip_parameters_set_parameter
(
BELLE_SIP_PARAMETERS
(
content_type
),
"type"
,
type_slash_subtype
);
belle_sip_free
(
type_slash_subtype
);
}
else
{
belle_sip_error
(
"Multipart related body handler [%p] cannot be set without first part content type header"
,
body_handler
);
}
}
else
{
belle_sip_error
(
"Multipart related body handler [%p] cannot be set without first part"
,
body_handler
);
}
belle_sip_header_content_type_set_subtype
(
content_type
,
"related"
);
}
else
{
belle_sip_header_content_type_set_subtype
(
content_type
,
"form-data"
);
}
belle_sip_parameters_set_parameter
(
BELLE_SIP_PARAMETERS
(
content_type
),
"boundary"
,
BELLESIP_MULTIPART_BOUNDARY
);
belle_sip_message_add_header
(
BELLE_SIP_MESSAGE
(
msg
),
BELLE_SIP_HEADER
(
content_type
));
}
}
...
...
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