From cf2b6ca2bf87a2333c02d093362981fb25dfbd57 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 21 Mar 2018 10:51:19 +0100 Subject: [PATCH] Fixed content type parameters between SalBodyHandler and Content --- coreapi/bellesip_sal/sal_impl.c | 20 ++++++++++++++++++++ src/c-wrapper/api/c-content.cpp | 24 ++++++++++++++++++------ src/c-wrapper/internal/c-sal.h | 2 ++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index ad11525fb..71578364b 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -348,6 +348,26 @@ void sal_body_handler_set_subtype(SalBodyHandler *body_handler, const char *subt belle_sip_header_content_type_set_subtype(content_type, subtype); } +char * sal_body_handler_get_content_type_parameters(const SalBodyHandler *body_handler) { + belle_sip_header_content_type_t *content_type = BELLE_SIP_HEADER_CONTENT_TYPE(sal_body_handler_find_header(body_handler, "Content-Type")); + if (content_type != NULL) { + char buff[2048]; + size_t buff_size = sizeof(buff); + size_t offset = 0; + belle_sip_parameters_marshal(BELLE_SIP_PARAMETERS(content_type), buff, buff_size, &offset); + buff[offset]='\0'; + return strdup(buff); + } + return NULL; +} + +void sal_body_handler_set_content_type_parameters(SalBodyHandler *body_handler, const char *params) { + belle_sip_header_content_type_t *content_type = BELLE_SIP_HEADER_CONTENT_TYPE(sal_body_handler_find_header(body_handler, "Content-Type")); + if (content_type != NULL) { + belle_sip_parameters_set(BELLE_SIP_PARAMETERS(content_type), params); + } +} + const char * sal_body_handler_get_encoding(const SalBodyHandler *body_handler) { belle_sip_header_t *content_encoding = sal_body_handler_find_header(body_handler, "Content-Encoding"); if (content_encoding != NULL) { diff --git a/src/c-wrapper/api/c-content.cpp b/src/c-wrapper/api/c-content.cpp index d487e8847..572444ddf 100644 --- a/src/c-wrapper/api/c-content.cpp +++ b/src/c-wrapper/api/c-content.cpp @@ -233,9 +233,14 @@ static LinphoneContent * linphone_content_new_with_body_handler(SalBodyHandler * content->cryptoContext = NULL; LinphonePrivate::Content *c = new LinphonePrivate::Content(); L_SET_CPP_PTR_FROM_C_OBJECT(content, c); + if (body_handler != NULL) { - linphone_content_set_type(content, sal_body_handler_get_type(body_handler)); - linphone_content_set_subtype(content, sal_body_handler_get_subtype(body_handler)); + LinphonePrivate::ContentType ct = c->getContentType(); + ct.setType(sal_body_handler_get_type(body_handler)); + ct.setSubType(sal_body_handler_get_subtype(body_handler)); + ct.setParameter(sal_body_handler_get_content_type_parameters(body_handler)); + c->setContentType(ct); + if (!sal_body_handler_is_multipart(body_handler)) { linphone_content_set_string_buffer(content, (char *)sal_body_handler_get_data(body_handler)); } else { @@ -257,8 +262,10 @@ static LinphoneContent * linphone_content_new_with_body_handler(SalBodyHandler * LinphonePrivate::Content multipartContent = LinphonePrivate::ContentManager::contentListToMultipart(contents); linphone_content_set_string_buffer(content, multipartContent.getBodyAsUtf8String().c_str()); } + if (sal_body_handler_get_encoding(body_handler)) linphone_content_set_encoding(content, sal_body_handler_get_encoding(body_handler)); } + return content; } @@ -288,11 +295,14 @@ LinphoneContent * linphone_content_from_sal_body_handler(SalBodyHandler *body_ha SalBodyHandler * sal_body_handler_from_content(const LinphoneContent *content) { if (content == NULL) return NULL; + SalBodyHandler *body_handler; - if (L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType().isMultipart()) { + LinphonePrivate::ContentType contentType = L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType(); + + if (contentType.isMultipart()) { size_t size = linphone_content_get_size(content); char *buffer = ms_strdup(L_GET_CPP_PTR_FROM_C_OBJECT(content)->getBodyAsUtf8String().c_str()); - const char *boundary = L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType().getParameter()); + const char *boundary = L_STRING_TO_C(contentType.getParameter()); belle_sip_multipart_body_handler_t *bh = belle_sip_multipart_body_handler_new_from_buffer(buffer, size, boundary); body_handler = (SalBodyHandler *)BELLE_SIP_BODY_HANDLER(bh); } else { @@ -310,9 +320,11 @@ SalBodyHandler * sal_body_handler_from_content(const LinphoneContent *content) { belle_sip_body_handler_add_header(BELLE_SIP_BODY_HANDLER(body_handler), additionalHeader); } - sal_body_handler_set_type(body_handler, linphone_content_get_type(content)); - sal_body_handler_set_subtype(body_handler, linphone_content_get_subtype(content)); + sal_body_handler_set_type(body_handler, contentType.getType().c_str()); + sal_body_handler_set_subtype(body_handler, contentType.getSubType().c_str()); sal_body_handler_set_size(body_handler, linphone_content_get_size(content)); + sal_body_handler_set_content_type_parameters(body_handler, contentType.getParameter().c_str()); if (content->encoding) sal_body_handler_set_encoding(body_handler, linphone_content_get_encoding(content)); + return body_handler; } diff --git a/src/c-wrapper/internal/c-sal.h b/src/c-wrapper/internal/c-sal.h index 4aeca0042..3f53db90c 100644 --- a/src/c-wrapper/internal/c-sal.h +++ b/src/c-wrapper/internal/c-sal.h @@ -636,6 +636,8 @@ const char * sal_body_handler_get_type(const SalBodyHandler *body_handler); void sal_body_handler_set_type(SalBodyHandler *body_handler, const char *type); const char * sal_body_handler_get_subtype(const SalBodyHandler *body_handler); void sal_body_handler_set_subtype(SalBodyHandler *body_handler, const char *subtype); +char * sal_body_handler_get_content_type_parameters(const SalBodyHandler *body_handler); +void sal_body_handler_set_content_type_parameters(SalBodyHandler *body_handler, const char *params); const char * sal_body_handler_get_encoding(const SalBodyHandler *body_handler); void sal_body_handler_set_encoding(SalBodyHandler *body_handler, const char *encoding); void * sal_body_handler_get_data(const SalBodyHandler *body_handler);