diff --git a/src/conference/handlers/local-conference-event-handler.cpp b/src/conference/handlers/local-conference-event-handler.cpp index 6876e3d13..927245f9d 100644 --- a/src/conference/handlers/local-conference-event-handler.cpp +++ b/src/conference/handlers/local-conference-event-handler.cpp @@ -218,9 +218,7 @@ string LocalConferenceEventHandlerPrivate::createNotifyMultipart (int notifyId) contents.push_back(content); } - ContentManager contentManager; - Content multipart = contentManager.contentsListToMultipart(contents); - return multipart.getBodyAsString(); + return ContentManager::contentListToMultipart(contents).getBodyAsString(); } string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdded (const Address &addr, int notifyId) { diff --git a/src/conference/handlers/remote-conference-event-handler.cpp b/src/conference/handlers/remote-conference-event-handler.cpp index 2ce85abae..aadfd5d60 100644 --- a/src/conference/handlers/remote-conference-event-handler.cpp +++ b/src/conference/handlers/remote-conference-event-handler.cpp @@ -220,11 +220,9 @@ void RemoteConferenceEventHandler::multipartNotifyReceived (const string &xmlBod Content multipart; multipart.setBody(xmlBody); - ContentManager manager; - list contents = manager.multipartToContentLists(multipart); - for (const auto &content : contents) { + + for (const auto &content : ContentManager::multipartToContentList(multipart)) d->simpleNotifyReceived(content.getBodyAsString()); - } } // ----------------------------------------------------------------------------- diff --git a/src/content/content-manager.cpp b/src/content/content-manager.cpp index 79e515cb7..e65647124 100644 --- a/src/content/content-manager.cpp +++ b/src/content/content-manager.cpp @@ -17,89 +17,92 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include - -#include "belle-sip/belle-sip.h" +#include #include "content-manager.h" #include "content-type.h" -#include "linphone/content.h" -#include "logger/logger.h" - -// ============================================================================= +#include "content/content.h" #define MULTIPART_BOUNDARY "---------------------------14737809831466499882746641449" +// ============================================================================= + using namespace std; LINPHONE_BEGIN_NAMESPACE -list ContentManager::multipartToContentLists (const Content &content) const { - belle_sip_multipart_body_handler_t *mpbh = belle_sip_multipart_body_handler_new_from_buffer((void *)content.getBodyAsString().c_str(), content.getBodyAsString().length(), MULTIPART_BOUNDARY); +list ContentManager::multipartToContentList (const Content &content) { + belle_sip_multipart_body_handler_t *mpbh = belle_sip_multipart_body_handler_new_from_buffer( + (void *)content.getBodyAsString().c_str(), + content.getBodyAsString().length(), + MULTIPART_BOUNDARY + ); belle_sip_object_ref(mpbh); - const belle_sip_list_t *parts = belle_sip_multipart_body_handler_get_parts(mpbh); - list contentsList = list(); - while (parts) { + list contents; + for (const belle_sip_list_t *parts = belle_sip_multipart_body_handler_get_parts(mpbh); parts; parts = parts->next) { belle_sip_body_handler_t *part = BELLE_SIP_BODY_HANDLER(parts->data); const belle_sip_list_t *part_headers = belle_sip_body_handler_get_headers(part); - belle_sip_list_t *it; - belle_sip_header_content_type_t *part_content_type=NULL;; - for(it = (belle_sip_list_t *)part_headers;it!=NULL;it=it->next) { + belle_sip_header_content_type_t *part_content_type = nullptr; + for (belle_sip_list_t *it = (belle_sip_list_t *)part_headers; it; it = it->next) { belle_sip_header_t *header = BELLE_SIP_HEADER(it->data); - if(strcasecmp("Content-Type",belle_sip_header_get_name(header)) == 0) { - part_content_type=BELLE_SIP_HEADER_CONTENT_TYPE(header); + if (strcasecmp("Content-Type", belle_sip_header_get_name(header)) == 0) { + part_content_type = BELLE_SIP_HEADER_CONTENT_TYPE(header); break; } } - belle_sip_header_content_type_get_type(part_content_type); - belle_sip_memory_body_handler_get_buffer(BELLE_SIP_MEMORY_BODY_HANDLER(part)); - Content retContent = Content(); - ContentType type(belle_sip_header_content_type_get_type(part_content_type), belle_sip_header_content_type_get_subtype(part_content_type)); + + Content retContent; retContent.setBody((const char *)belle_sip_memory_body_handler_get_buffer(BELLE_SIP_MEMORY_BODY_HANDLER(part))); - retContent.setContentType(type); - contentsList.push_back(retContent); - parts = parts->next; + retContent.setContentType(ContentType( + belle_sip_header_content_type_get_type(part_content_type), + belle_sip_header_content_type_get_subtype(part_content_type) + )); + contents.push_back(retContent); } belle_sip_object_unref(mpbh); - return contentsList; + return contents; } -Content ContentManager::contentsListToMultipart (const list &contents) const { - char *desc; +Content ContentManager::contentListToMultipart (const list &contents) { string sub; - belle_sip_memory_body_handler_t *mbh = NULL; - belle_sip_multipart_body_handler_t *mpbh = belle_sip_multipart_body_handler_new(NULL, NULL, NULL, MULTIPART_BOUNDARY); + + belle_sip_memory_body_handler_t *mbh = nullptr; + belle_sip_multipart_body_handler_t *mpbh = belle_sip_multipart_body_handler_new( + nullptr, nullptr, nullptr, MULTIPART_BOUNDARY + ); belle_sip_object_ref(mpbh); + for (const auto &content : contents) { const ContentType &contentType = content.getContentType(); stringstream subtype; sub = contentType.getSubType(); subtype << sub << "; charset=\"UTF-8\""; - belle_sip_header_t *content_type = BELLE_SIP_HEADER( + belle_sip_header_t *cContentType = BELLE_SIP_HEADER( belle_sip_header_content_type_create( contentType.getType().c_str(), subtype.str().c_str() ) ); + + string body = content.getBodyAsString(); mbh = belle_sip_memory_body_handler_new_copy_from_buffer( - (void *)content.getBodyAsString().c_str(), - content.getBodyAsString().length(), - NULL, - NULL + (void *)body.c_str(), body.length(), nullptr, nullptr ); - belle_sip_body_handler_add_header(BELLE_SIP_BODY_HANDLER(mbh), content_type); + belle_sip_body_handler_add_header(BELLE_SIP_BODY_HANDLER(mbh), cContentType); belle_sip_multipart_body_handler_add_part(mpbh, BELLE_SIP_BODY_HANDLER(mbh)); } - desc = belle_sip_object_to_string(mpbh); + char *desc = belle_sip_object_to_string(mpbh); + + Content content; + content.setBody(desc); + content.setContentType(ContentType("application", sub)); + + belle_sip_free(desc); belle_sip_object_unref(mpbh); - Content retContent = Content(); - ContentType type("application", sub); - retContent.setBody(desc); - retContent.setContentType(type); - return retContent; + return content; } LINPHONE_END_NAMESPACE diff --git a/src/content/content-manager.h b/src/content/content-manager.h index 8b15bb6a2..f91adc2ab 100644 --- a/src/content/content-manager.h +++ b/src/content/content-manager.h @@ -24,18 +24,15 @@ #include "linphone/utils/general.h" -#include "content.h" - // ============================================================================= LINPHONE_BEGIN_NAMESPACE -class ContentManager { -public: - ContentManager () = default; +class Content; - std::list multipartToContentLists (const Content &content) const; - Content contentsListToMultipart (const std::list &contents) const; +namespace ContentManager { + std::list multipartToContentList (const Content &content); + Content contentListToMultipart (const std::list &contents); }; LINPHONE_END_NAMESPACE diff --git a/src/content/content.h b/src/content/content.h index 762b2fd01..23aa0446a 100644 --- a/src/content/content.h +++ b/src/content/content.h @@ -22,14 +22,13 @@ #include -// TODO: Remove me. -#include "linphone/content.h" - #include "object/app-data-container.h" #include "object/clonable-object.h" // ============================================================================= +L_DECL_C_STRUCT(LinphoneContent); + LINPHONE_BEGIN_NAMESPACE class ContentType; diff --git a/tester/content-manager-tester.cpp b/tester/content-manager-tester.cpp index 05e4eb893..17cf4328d 100644 --- a/tester/content-manager-tester.cpp +++ b/tester/content-manager-tester.cpp @@ -160,13 +160,11 @@ static const char* part4 = \ ""; void multipart_to_list () { - ContentManager manager; - Content multipartContent; multipartContent.setBody(multipart); multipartContent.setContentType(ContentType("multipart", "related")); - list contents = manager.multipartToContentLists(multipartContent); + list contents = ContentManager::multipartToContentList(multipartContent); BC_ASSERT_EQUAL(contents.size(), 4, int, "%d"); Content content1 = contents.front(); contents.pop_front(); @@ -242,8 +240,6 @@ void multipart_to_list () { } void list_to_multipart () { - ContentManager manager; - Content content1; content1.setBody(part1); content1.setContentType(ContentType("application", "rlmi+xml")); @@ -258,7 +254,7 @@ void list_to_multipart () { content4.setContentType(ContentType("application", "pidf+xml")); list contents = {content1, content2, content3, content4}; - Content multipartContent = manager.contentsListToMultipart(contents); + Content multipartContent = ContentManager::contentListToMultipart(contents); string originalStr(multipart); originalStr.erase(std::remove(originalStr.begin(), originalStr.end(), ' '), originalStr.end()); originalStr.erase(std::remove(originalStr.begin(), originalStr.end(), '\t'), originalStr.end());