diff --git a/coreapi/private_functions.h b/coreapi/private_functions.h index 2b8991c7b..754bc500d 100644 --- a/coreapi/private_functions.h +++ b/coreapi/private_functions.h @@ -403,7 +403,7 @@ void linphone_event_set_state(LinphoneEvent *lev, LinphoneSubscriptionState stat void linphone_event_set_publish_state(LinphoneEvent *lev, LinphonePublishState state); void _linphone_event_notify_notify_response(const LinphoneEvent *lev); LinphoneSubscriptionState linphone_subscription_state_from_sal(SalSubscribeStatus ss); -LinphoneContent *linphone_content_from_sal_body_handler(const SalBodyHandler *ref); +LinphoneContent *linphone_content_from_sal_body_handler(const SalBodyHandler *ref, bool parseMultipart = true); void linphone_core_invalidate_friend_subscriptions(LinphoneCore *lc); void linphone_core_register_offer_answer_providers(LinphoneCore *lc); diff --git a/src/c-wrapper/api/c-content.cpp b/src/c-wrapper/api/c-content.cpp index 808355f17..741f2a24d 100644 --- a/src/c-wrapper/api/c-content.cpp +++ b/src/c-wrapper/api/c-content.cpp @@ -241,7 +241,7 @@ void linphone_content_set_key (LinphoneContent *content, const char *key, const // Private functions. // ============================================================================= -static LinphoneContent *linphone_content_new_with_body_handler (const SalBodyHandler *body_handler) { +static LinphoneContent *linphone_content_new_with_body_handler (const SalBodyHandler *body_handler, bool parseMultipart) { LinphoneContent *content = L_INIT(Content); content->cryptoContext = NULL; LinphonePrivate::Content *c = new LinphonePrivate::Content(); @@ -256,13 +256,13 @@ static LinphoneContent *linphone_content_new_with_body_handler (const SalBodyHan linphone_content_add_content_type_parameter(content, paramName, paramValue); } - if (!linphone_content_is_multipart(content)) { - linphone_content_set_string_buffer(content, (char *)sal_body_handler_get_data(body_handler)); - } else { + if (linphone_content_is_multipart(content) && parseMultipart) { belle_sip_multipart_body_handler_t *mpbh = BELLE_SIP_MULTIPART_BODY_HANDLER(body_handler); char *body = belle_sip_object_to_string(mpbh); linphone_content_set_string_buffer(content, body); belle_sip_free(body); + } else { + linphone_content_set_string_buffer(content, (char *)sal_body_handler_get_data(body_handler)); } belle_sip_list_t *headers = (belle_sip_list_t *)sal_body_handler_get_headers(body_handler); @@ -279,7 +279,7 @@ static LinphoneContent *linphone_content_new_with_body_handler (const SalBodyHan } LinphoneContent *linphone_content_new (void) { - return linphone_content_new_with_body_handler(NULL); + return linphone_content_new_with_body_handler(NULL, true); } LinphoneContent *linphone_content_copy (const LinphoneContent *ref) { @@ -296,9 +296,9 @@ void **linphone_content_get_cryptoContext_address (LinphoneContent *content) { return &content->cryptoContext; } -LinphoneContent *linphone_content_from_sal_body_handler (const SalBodyHandler *body_handler) { +LinphoneContent *linphone_content_from_sal_body_handler (const SalBodyHandler *body_handler, bool parseMultipart) { if (body_handler) { - return linphone_content_new_with_body_handler(body_handler); + return linphone_content_new_with_body_handler(body_handler, parseMultipart); } return NULL; } diff --git a/src/conference/handlers/local-conference-event-handler.cpp b/src/conference/handlers/local-conference-event-handler.cpp index b9da2b703..de857918a 100644 --- a/src/conference/handlers/local-conference-event-handler.cpp +++ b/src/conference/handlers/local-conference-event-handler.cpp @@ -388,7 +388,6 @@ void LocalConferenceEventHandlerPrivate::notifyParticipantDevice (const string & // TODO: Activate compression LinphoneContent *cContent = L_GET_C_BACK_PTR(&content); linphone_event_notify(ev, cContent); - linphone_content_unref(cContent); } // ============================================================================= diff --git a/src/conference/handlers/local-conference-list-event-handler.cpp b/src/conference/handlers/local-conference-list-event-handler.cpp index fec44a4ee..7da5a72a3 100644 --- a/src/conference/handlers/local-conference-list-event-handler.cpp +++ b/src/conference/handlers/local-conference-list-event-handler.cpp @@ -164,7 +164,6 @@ void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev, con Content multipart = ContentManager::contentListToMultipart(contents, MultipartBoundaryListEventHandler); LinphoneContent *cContent = L_GET_C_BACK_PTR(&multipart); linphone_event_notify(lev, cContent); - linphone_content_unref(cContent); contents.clear(); } diff --git a/src/conference/handlers/remote-conference-list-event-handler.cpp b/src/conference/handlers/remote-conference-list-event-handler.cpp index 4b1512efe..32e07be7c 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.cpp +++ b/src/conference/handlers/remote-conference-list-event-handler.cpp @@ -123,7 +123,6 @@ void RemoteConferenceListEventHandler::subscribe () { linphone_event_set_user_data(lev, this); LinphoneContent *cContent = L_GET_C_BACK_PTR(&content); linphone_event_send_subscribe(lev, cContent); - linphone_content_unref(cContent); } void RemoteConferenceListEventHandler::unsubscribe () { diff --git a/src/content/content-manager.cpp b/src/content/content-manager.cpp index 61e7d3025..e7271a5be 100644 --- a/src/content/content-manager.cpp +++ b/src/content/content-manager.cpp @@ -44,7 +44,7 @@ list ContentManager::multipartToContentList (const Content &content) { list contents; for (const belle_sip_list_t *parts = sal_body_handler_get_parts(sbh); parts; parts = parts->next) { SalBodyHandler *part = (SalBodyHandler *)parts->data; - LinphoneContent *cContent = linphone_content_from_sal_body_handler(part); + LinphoneContent *cContent = linphone_content_from_sal_body_handler(part, false); Content *cppContent = L_GET_CPP_PTR_FROM_C_OBJECT(cContent); if (content.getContentDisposition().isValid()) cppContent->setContentDisposition(content.getContentDisposition()); @@ -69,7 +69,7 @@ Content ContentManager::contentListToMultipart (const list &contents, disposition = content->getContentDisposition(); LinphoneContent *cContent = L_GET_C_BACK_PTR(content); - SalBodyHandler *sbh = sal_body_handler_ref(sal_body_handler_from_content(cContent, false)); + SalBodyHandler *sbh = sal_body_handler_from_content(cContent); belle_sip_multipart_body_handler_add_part(mpbh, BELLE_SIP_BODY_HANDLER(sbh)); } @@ -78,7 +78,7 @@ Content ContentManager::contentListToMultipart (const list &contents, sal_body_handler_set_subtype(sbh, ContentType::Multipart.getSubType().c_str()); sal_body_handler_set_content_type_parameter(sbh, "boundary", boundary.c_str()); - LinphoneContent *cContent = linphone_content_from_sal_body_handler(sbh); + LinphoneContent *cContent = linphone_content_from_sal_body_handler(sbh, false); belle_sip_object_unref(mpbh); Content content = *L_GET_CPP_PTR_FROM_C_OBJECT(cContent);