Commit 1807c18b authored by Benjamin REIS's avatar Benjamin REIS

add correct header to the body handler when receiving a multipart message

parent 635ff339
......@@ -399,24 +399,33 @@ static int check_body(belle_sip_channel_t *obj){
}
if (expect_body){
belle_sip_body_handler_t *bh;
/*should notify the listeners*/
// Should notify the listeners
BELLE_SIP_CHANNEL_INVOKE_MESSAGE_HEADERS_LISTENERS(obj,msg);
/*check if the listener has setup a body handler, otherwise create a default one*/
if ((bh=belle_sip_message_get_body_handler(msg))==NULL){
// Check if the listener has setup a body handler, otherwise create a default one
bh = belle_sip_message_get_body_handler(msg);
if (!bh) {
belle_sip_header_t *content_encoding = belle_sip_message_get_header(msg, "Content-Encoding");
belle_sip_header_content_type_t *content_type = belle_sip_message_get_header_by_type(msg, belle_sip_header_content_type_t);
if (content_encoding != NULL) {
belle_sip_message_set_body_handler(msg, (bh = (belle_sip_body_handler_t *)belle_sip_memory_body_handler_new(NULL, NULL)));
if (content_encoding) {
bh = (belle_sip_body_handler_t *)belle_sip_memory_body_handler_new(NULL, NULL);
belle_sip_body_handler_add_header(bh,BELLE_SIP_HEADER(content_length_header));
belle_sip_body_handler_add_header(bh, BELLE_SIP_HEADER(content_type));
belle_sip_body_handler_add_header(bh, content_encoding);
belle_sip_message_set_body_handler(msg, bh);
} else if (content_type
&& (strcmp(belle_sip_header_content_type_get_type(content_type), "multipart") == 0)) {
const char *unparsed_value = belle_sip_header_get_unparsed_value(BELLE_SIP_HEADER(content_type));
const char *boundary = strstr(unparsed_value, ";boundary=");
if (boundary != NULL) boundary += 10;
if (boundary) boundary += 10;
if (boundary[0] == '\0') boundary = NULL;
belle_sip_message_set_body_handler(msg, (bh = (belle_sip_body_handler_t *)belle_sip_multipart_body_handler_new(belle_sip_multipart_body_handler_progress_cb, NULL, NULL, boundary)));
bh = (belle_sip_body_handler_t *)belle_sip_multipart_body_handler_new(belle_sip_multipart_body_handler_progress_cb, NULL, NULL, boundary);
belle_sip_body_handler_set_size(bh, obj->input_stream.content_length);
belle_sip_body_handler_add_header(bh, BELLE_SIP_HEADER(content_length_header));
belle_sip_body_handler_add_header(bh, BELLE_SIP_HEADER(content_type));
belle_sip_message_set_body_handler(msg, bh);
} else {
belle_sip_message_set_body_handler(msg,(bh=(belle_sip_body_handler_t*)belle_sip_memory_body_handler_new(NULL,NULL)));
bh = (belle_sip_body_handler_t *)belle_sip_memory_body_handler_new(NULL, NULL);
belle_sip_message_set_body_handler(msg, bh);
}
}
belle_sip_body_handler_begin_recv_transfer(bh);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment