Commit 9c291ba2 authored by Benjamin REIS's avatar Benjamin REIS

add content-manager and content-manager tester

parent 42e2f7f6
......@@ -77,6 +77,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
conference/session/call-session.h
conference/session/media-session.h
conference/session/port-config.h
content/content-manager.h
content/content-type.h
content/content.h
core/core-p.h
......@@ -171,6 +172,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
conference/remote-conference.cpp
conference/session/call-session.cpp
conference/session/media-session.cpp
content/content-manager.cpp
content/content-type.cpp
content/content.cpp
core/core.cpp
......
/*
* content-manager.cpp
* Copyright (C) 2010-2017 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <sstream>
#include "belle-sip/belle-sip.h"
#include "content-manager.h"
#include "content-type.h"
#include "linphone/content.h"
#include "linphone/core.h"
#include "logger/logger.h"
#include "private.h"
// =============================================================================
#define MULTIPART_BOUNDARY "---------------------------14737809831466499882746641449"
using namespace std;
LINPHONE_BEGIN_NAMESPACE
ContentManager::ContentManager (LinphoneCore *core) {
mCore = core;
}
list<Content> ContentManager::multipartToContentLists (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);
belle_sip_object_ref(mpbh);
const belle_sip_list_t *parts = belle_sip_multipart_body_handler_get_parts(mpbh);
list<Content> contentsList = list<Content>();
while (parts) {
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_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);
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));
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;
}
belle_sip_object_unref(mpbh);
return contentsList;
}
Content ContentManager::contentsListToMultipart (list<Content> contents) const {
char *desc;
string sub;
belle_sip_memory_body_handler_t *mbh;
belle_sip_multipart_body_handler_t *mpbh = belle_sip_multipart_body_handler_new(NULL, NULL, NULL, 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_content_type_create(
contentType.getType().c_str(),
subtype.str().c_str()
)
);
mbh = belle_sip_memory_body_handler_new_copy_from_buffer(
(void *)content.getBodyAsString().c_str(),
content.getBodyAsString().length(),
NULL,
NULL
);
belle_sip_body_handler_add_header(BELLE_SIP_BODY_HANDLER(mbh), content_type);
belle_sip_multipart_body_handler_add_part(mpbh, BELLE_SIP_BODY_HANDLER(mbh));
}
desc = belle_sip_object_to_string(mpbh);
belle_sip_object_unref(mpbh);
belle_sip_object_ref(mbh);
Content retContent = Content();
ContentType type("application", sub);
retContent.setBody(desc);
retContent.setContentType(type);
return retContent;
}
LINPHONE_END_NAMESPACE
/*
* content-manager.h
* Copyright (C) 2010-2017 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _CONTENT_MANAGER_H_
#define _CONTENT_MANAGER_H_
#include <list>
#include "content.h"
#include "linphone/types.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class ContentManager {
public:
ContentManager (LinphoneCore *core);
std::list<Content> multipartToContentLists (Content content) const;
Content contentsListToMultipart (std::list<Content> contents) const;
private:
LinphoneCore *mCore = nullptr;
};
LINPHONE_END_NAMESPACE
#endif // ifndef _CONTENT_MANAGER_H_
......@@ -46,6 +46,7 @@ const ContentType ContentType::ImIsComposing("application/im-iscomposing+xml");
const ContentType ContentType::PlainText("text/plain");
const ContentType ContentType::ResourceLists("application/resource-lists+xml");
const ContentType ContentType::Sdp("application/sdp");
const ContentType ContentType::ConferenceInfo("application/conference-info+xml");
// -----------------------------------------------------------------------------
......
......@@ -66,6 +66,7 @@ public:
static const ContentType PlainText;
static const ContentType ResourceLists;
static const ContentType Sdp;
static const ContentType ConferenceInfo;
private:
L_DECLARE_PRIVATE(ContentType);
......
......@@ -198,6 +198,7 @@ set(SOURCE_FILES_CXX
clonable-object-tester.cpp
conference-event-tester.cpp
conference-tester.cpp
content-manager-tester.cpp
cpim-tester.cpp
main-db-tester.cpp
multipart-tester.cpp
......
This diff is collapsed.
......@@ -46,6 +46,7 @@ extern test_suite_t call_video_test_suite;
extern test_suite_t clonable_object_test_suite;
extern test_suite_t conference_event_test_suite;
extern test_suite_t conference_test_suite;
extern test_suite_t content_manager_test_suite;
extern test_suite_t cpim_test_suite;
extern test_suite_t dtmf_test_suite;
extern test_suite_t event_test_suite;
......
......@@ -565,6 +565,7 @@ void liblinphone_tester_add_suites() {
bc_tester_add_suite(&event_test_suite);
bc_tester_add_suite(&conference_event_test_suite);
bc_tester_add_suite(&conference_test_suite);
bc_tester_add_suite(&content_manager_test_suite);
bc_tester_add_suite(&flexisip_test_suite);
bc_tester_add_suite(&remote_provisioning_test_suite);
bc_tester_add_suite(&quality_reporting_test_suite);
......
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