Commit 905e47d1 authored by Ghislain MARY's avatar Ghislain MARY

Improve xsd integration.

parent 6d37e56b
...@@ -61,13 +61,6 @@ if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX) ...@@ -61,13 +61,6 @@ if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}") message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
endif() endif()
if(APPLE)
set(XSDCXX_DEFAULT_ROOT_PATH "/usr/local")
else ()
set(XSDCXX_DEFAULT_ROOT_PATH "/usr")
endif()
set(XSDCXX_ROOT_PATH ${XSDCXX_DEFAULT_ROOT_PATH} CACHE STRING "Path of where the bin/xsdcxx executable will be found. Comes from http://www.codesynthesis.com/products/xsd/download.xhtml. On mac use 'brew install xsd'")
set(SYSCONF_INSTALL_DIR ${CMAKE_INSTALL_FULL_SYSCONFDIR} CACHE STRING "Config directory, the place where flexisip expects its flexisip.conf file to reside" ) set(SYSCONF_INSTALL_DIR ${CMAKE_INSTALL_FULL_SYSCONFDIR} CACHE STRING "Config directory, the place where flexisip expects its flexisip.conf file to reside" )
...@@ -94,25 +87,7 @@ endif() ...@@ -94,25 +87,7 @@ endif()
find_package(BcToolbox 0.0.3 REQUIRED) find_package(BcToolbox 0.0.3 REQUIRED)
find_program(XSDCXX_PROG NAMES "xsdcxx" "xsd" find_package(LibXsd)
HINTS ${XSDCXX_ROOT_PATH}/bin
)
if(XSDCXX_PROG)
set(ENABLE_XSD 1)
message(STATUS "XSD found at ${XSDCXX_PROG}, enabling XSD")
# TODO: check XSD is the correct executable
find_library(XERCES_LIBS NAMES xerces-c)
if(NOT XERCES_LIBS)
message(FATAL_ERROR "Failed to find the Xerces library.")
endif()
find_path(XERCES_INCLUDE_DIRS NAMES xercesc/util/XercesDefs.hpp)
if(NOT XERCES_INCLUDE_DIRS)
message(FATAL_ERROR "Failed to find the Xerces includes.")
endif()
else()
set(ENABLE_XSD 0)
message(STATUS "Program 'xsdcxx' could not be found in ${XSDCXX_ROOT_PATH}/bin, disabling XSD features")
endif()
check_function_exists(arc4random HAVE_ARC4RANDOM) check_function_exists(arc4random HAVE_ARC4RANDOM)
find_file(HAVE_SYS_PRCTL_H NAMES sys/prctl.h) find_file(HAVE_SYS_PRCTL_H NAMES sys/prctl.h)
......
############################################################################
# FindLibXsd.cmake
# Copyright (C) 2017 Belledonne Communications, Grenoble France
#
############################################################################
#
# 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.
#
############################################################################
#
# - Find the libxsd library
#
# LIBXSD_FOUND - system has libxsd
# LIBXSD_INCLUDE_DIRS - the libxsd include directory
# LIBXSD_LIBRARIES - The libraries needed to use libxsd
find_package(XercesC)
find_path(LIBXSD_INCLUDE_DIRS
NAMES xsd/cxx/config.hxx
PATH_SUFFIXES include
)
if(LIBXSD_INCLUDE_DIRS)
list(APPEND LIBXSD_INCLUDE_DIRS ${XercesC_INCLUDE_DIRS})
endif()
set(LIBXSD_LIBRARIES ${XercesC_LIBRARIES})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibXsd
DEFAULT_MSG
LIBXSD_INCLUDE_DIRS LIBXSD_LIBRARIES
)
mark_as_advanced(LIBXSD_INCLUDE_DIRS LIBXSD_LIBRARIES)
...@@ -91,35 +91,12 @@ add_custom_target(flexisip-git-version ...@@ -91,35 +91,12 @@ add_custom_target(flexisip-git-version
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/flexisip_gitversion.h" BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/flexisip_gitversion.h"
) )
function(ADD_XSD_WRAPPERS file _comment)
set(destinations ${CMAKE_CURRENT_BINARY_DIR}/xml/${file}.hxx ${CMAKE_CURRENT_BINARY_DIR}/xml/${file}.cxx)
set(source ${CMAKE_CURRENT_LIST_DIR}/xml/${file}.xsd)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/xml")
set(regex "%http://.+/(.+)%\\\$$1%")
add_custom_command(OUTPUT ${destinations}
COMMAND "${XSDCXX_PROG}" "cxx-tree" "--generate-wildcard"
"--generate-serialization" "--generate-ostream"
"--generate-detach" "--std" "c++11" "--type-naming" "java"
"--function-naming" "java" "--location-regex-trace" "--show-sloc"
"--location-regex" "\"${regex}\""
"--output-dir" "${CMAKE_CURRENT_BINARY_DIR}/xml" "${source}"
COMMENT "${_comment}")
add_custom_target(${file} DEPENDS ${destinations} SOURCES ${source})
set_source_files_properties(${destinations} PROPERTIES GENERATED ON)
set(FLEXISIP_SOURCES ${FLEXISIP_SOURCES} ${destinations} PARENT_SCOPE)
endfunction()
list(APPEND FLEXISIP_INCLUDES ${BCTOOLBOX_INCLUDE_DIRS}) list(APPEND FLEXISIP_INCLUDES ${BCTOOLBOX_INCLUDE_DIRS})
if(ENABLE_XSD) if(LIBXSD_FOUND)
list(APPEND FLEXISIP_LIBS ${XERCES_LIBS}) list(APPEND FLEXISIP_LIBS ${LIBXSD_LIBRARIES})
list(APPEND FLEXISIP_INCLUDES ${XERCES_INCLUDE_DIRS} ${XSDCXX_ROOT_PATH}/libxsd ${CMAKE_CURRENT_BINARY_DIR}/xml) list(APPEND FLEXISIP_INCLUDES ${LIBXSD_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/xml)
list(APPEND FLEXISIP_DEPENDENCIES fthttp) list(APPEND FLEXISIP_SOURCES xml/fthttp.cc xml/fthttp.hh)
ADD_XSD_WRAPPERS(fthttp "Generating XSD for FTHTTP")
endif() endif()
if(ENABLE_MSGPACK) if(ENABLE_MSGPACK)
...@@ -176,27 +153,44 @@ if(ENABLE_PROTOBUF) ...@@ -176,27 +153,44 @@ if(ENABLE_PROTOBUF)
endif() endif()
if(ENABLE_PRESENCE) if(ENABLE_PRESENCE)
if (NOT ENABLE_XSD) if(NOT LIBXSD_FOUND)
message(FATAL_ERROR "Presence asked but XSD not enabled! Please enable it first.") message(FATAL_ERROR "Presence asked but XSD not enabled! Please enable it first.")
endif() endif()
file(GLOB PRESENCE_SRCS presence/*.cc presence/*.hh) add_definitions(-DBELLE_SIP_USE_STL ${BELLE_SIP_CFLAGS})
list(APPEND FLEXISIP_SOURCES ${PRESENCE_SRCS})
list(APPEND FLEXISIP_LIBS ${BELLESIP_LIBRARIES} ${XERCES_LIBS}) list(APPEND FLEXISIP_LIBS ${BELLESIP_LIBRARIES} ${XERCES_LIBS})
list(APPEND FLEXISIP_INCLUDES ${BELLESIP_INCLUDE_DIRS} presence) list(APPEND FLEXISIP_INCLUDES ${BELLESIP_INCLUDE_DIRS} presence)
add_definitions(-DBELLE_SIP_USE_STL ${BELLE_SIP_CFLAGS}) list(APPEND FLEXISIP_SOURCES
ADD_XSD_WRAPPERS(xml "Presence XSD - xml.xsd") presence/bellesip-signaling-exception.cc
list(APPEND FLEXISIP_SOURCES xml/xml.xsd) presence/bellesip-signaling-exception.hh
ADD_XSD_WRAPPERS(pidf+xml "Presence XSD - pidf+xml.xsd") presence/etag-manager.hh
list(APPEND FLEXISIP_SOURCES xml/pidf+xml.xsd) presence/file-resource-list-manager.cc
ADD_XSD_WRAPPERS(rlmi+xml "Presence XSD - rlmi+xml.xsd") presence/file-resource-list-manager.hh
list(APPEND FLEXISIP_SOURCES xml/rlmi+xml.xsd) presence/list-subscription.cc
ADD_XSD_WRAPPERS(resource-lists "Presence XSD - resource-lists.xsd") presence/list-subscription.hh
list(APPEND FLEXISIP_SOURCES xml/resource-lists.xsd) presence/presence-configmanager.cc
ADD_XSD_WRAPPERS(rpid "RPID XSD - rpid.xsd") presence/presence-configmanager.hh
list(APPEND FLEXISIP_SOURCES xml/rpid.xsd) presence/presence-longterm.cc
ADD_XSD_WRAPPERS(data-model "Data model XSD - data-model.xsd") presence/presence-longterm.hh
list(APPEND FLEXISIP_SOURCES xml/data-model.xsd) presence/presence-server.cc
list(APPEND FLEXISIP_DEPENDENCIES xml pidf+xml rlmi+xml resource-lists rpid data-model) presence/presence-server.hh
presence/presentity-manager.hh
presence/presentity-presenceinformation.cc
presence/presentity-presenceinformation.hh
presence/subscription.cc
presence/subscription.hh
xml/data-model.cc
xml/data-model.hh
xml/pidf+xml.cc
xml/pidf+xml.hh
xml/resource-lists.cc
xml/resource-lists.hh
xml/rlmi+xml.cc
xml/rlmi+xml.hh
xml/rpid.cc
xml/rpid.hh
xml/xml.cc
xml/xml.hh
)
endif() endif()
if(ENABLE_CONFERENCE) if(ENABLE_CONFERENCE)
...@@ -207,8 +201,25 @@ if(ENABLE_CONFERENCE) ...@@ -207,8 +201,25 @@ if(ENABLE_CONFERENCE)
endif() endif()
if(ENABLE_PUSHNOTIFICATION) if(ENABLE_PUSHNOTIFICATION)
file(GLOB PUSHNOTIFICATION_SRCS pushnotification/*.cc pushnotification/*.hh) list(APPEND FLEXISIP_SOURCES
list(APPEND FLEXISIP_SOURCES module-pushnotification.cc ${PUSHNOTIFICATION_SRCS}) module-pushnotification.cc
pushnotification/applepush.cc
pushnotification/applepush.hh
pushnotification/firebasepush.cc
pushnotification/firebasepush.hh
pushnotification/genericpush.cc
pushnotification/genericpush.hh
pushnotification/googlepush.cc
pushnotification/googlepush.hh
pushnotification/microsoftpush.cc
pushnotification/microsoftpush.hh
pushnotification/pushnotificationclient.cc
pushnotification/pushnotificationclient.hh
pushnotification/pushnotificationclient_wp.cc
pushnotification/pushnotificationclient_wp.hh
pushnotification/pushnotificationservice.cc
pushnotification/pushnotificationservice.hh
)
endif() endif()
list(APPEND FLEXISIP_LIBS ${OPENSSL_LIBRARIES}) list(APPEND FLEXISIP_LIBS ${OPENSSL_LIBRARIES})
list(APPEND FLEXISIP_INCLUDES ${OPENSSL_INCLUDE_DIR}) list(APPEND FLEXISIP_INCLUDES ${OPENSSL_INCLUDE_DIR})
......
...@@ -25,9 +25,8 @@ ...@@ -25,9 +25,8 @@
#if ENABLE_XSD #if ENABLE_XSD
#include "xml/fthttp.hxx" #include "xml/fthttp.h"
#include <xercesc/util/PlatformUtils.hpp> #include <xercesc/util/PlatformUtils.hpp>
using namespace fthttp;
#endif #endif
...@@ -213,23 +212,23 @@ void ForkMessageContext::onNewBranch(const shared_ptr<BranchInfo> &br) { ...@@ -213,23 +212,23 @@ void ForkMessageContext::onNewBranch(const shared_ptr<BranchInfo> &br) {
xercesc::XMLPlatformUtils::Initialize(); xercesc::XMLPlatformUtils::Initialize();
if (payload) { if (payload) {
std::unique_ptr<fthttp::File> file_transfer_infos; std::unique_ptr<Xsd::Fthttp::File> file_transfer_infos;
char *file_url = NULL; char *file_url = NULL;
try { try {
istringstream data(payload->pl_data); istringstream data(payload->pl_data);
file_transfer_infos = parseFile(data, xml_schema::Flags::dont_validate); file_transfer_infos = Xsd::Fthttp::parseFile(data, Xsd::XmlSchema::Flags::dont_validate);
} catch (const xml_schema::Exception &e) { } catch (const Xsd::XmlSchema::Exception &e) {
SLOGE << "Can't parse the content of the message"; SLOGE << "Can't parse the content of the message";
} }
if (file_transfer_infos) { if (file_transfer_infos) {
File::File_infoSequence &infos = file_transfer_infos->getFile_info(); Xsd::Fthttp::File::FileInfoSequence &infos = file_transfer_infos->getFileInfo();
if (infos.size() >= 1) { if (infos.size() >= 1) {
for (File::File_infoConstIterator i(infos.begin()); i != infos.end(); ++i) { for (Xsd::Fthttp::File::FileInfoConstIterator i(infos.begin()); i != infos.end(); ++i) {
const File::File_infoType &info = (*i); const Xsd::Fthttp::File::FileInfoType &info = (*i);
const File_info::DataType &data = info.getData(); const Xsd::Fthttp::FileInfo::DataType &data = info.getData();
const Data::UrlType &url = data.getUrl(); const Xsd::Fthttp::Data::UrlType &url = data.getUrl();
file_url = (char *)url.c_str(); file_url = (char *)url.c_str();
break; break;
} }
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
#include "belle-sip/belle-sip.h" #include "belle-sip/belle-sip.h"
#include "bellesip-signaling-exception.hh" #include "bellesip-signaling-exception.hh"
#include "log/logmanager.hh" #include "log/logmanager.hh"
#include "resource-lists.hxx" #include "resource-lists.hh"
#include <chrono> #include <chrono>
#include "rlmi+xml.hxx" #include "rlmi+xml.hh"
#include "belle-sip/bodyhandler.h" #include "belle-sip/bodyhandler.h"
#include <algorithm> #include <algorithm>
...@@ -49,20 +49,20 @@ ListSubscription::ListSubscription(unsigned int expires, belle_sip_server_transa ...@@ -49,20 +49,20 @@ ListSubscription::ListSubscription(unsigned int expires, belle_sip_server_transa
if (!belle_sip_message_get_body(BELLE_SIP_MESSAGE(request))) { if (!belle_sip_message_get_body(BELLE_SIP_MESSAGE(request))) {
throw BELLESIP_SIGNALING_EXCEPTION_1(400, belle_sip_header_create("Warning", "Empty body")) << "Empty body"; throw BELLESIP_SIGNALING_EXCEPTION_1(400, belle_sip_header_create("Warning", "Empty body")) << "Empty body";
} }
::std::unique_ptr<resource_lists::Resource_lists> resource_list_body = NULL; ::std::unique_ptr<Xsd::ResourceLists::ResourceLists> resource_list_body = NULL;
try { try {
istringstream data(belle_sip_message_get_body(BELLE_SIP_MESSAGE(request))); istringstream data(belle_sip_message_get_body(BELLE_SIP_MESSAGE(request)));
resource_list_body = resource_lists::parseResource_lists(data, xml_schema::Flags::dont_validate); resource_list_body = Xsd::ResourceLists::parseResourceLists(data, Xsd::XmlSchema::Flags::dont_validate);
} catch (const xml_schema::Exception &e) { } catch (const Xsd::XmlSchema::Exception &e) {
ostringstream os; ostringstream os;
os << "Cannot parse body caused by [" << e << "]"; os << "Cannot parse body caused by [" << e << "]";
// todo check error code // todo check error code
throw BELLESIP_SIGNALING_EXCEPTION_1(400, belle_sip_header_create("Warning", os.str().c_str())) << os.str(); throw BELLESIP_SIGNALING_EXCEPTION_1(400, belle_sip_header_create("Warning", os.str().c_str())) << os.str();
} }
for (::resource_lists::List::ListConstIterator listIt = resource_list_body->getList().begin(); for (Xsd::ResourceLists::List::ListConstIterator listIt = resource_list_body->getList().begin();
listIt != resource_list_body->getList().end(); listIt++) { listIt != resource_list_body->getList().end(); listIt++) {
for (::resource_lists::List::EntryConstIterator entryIt = listIt->getEntry().begin(); for (Xsd::ResourceLists::List::EntryConstIterator entryIt = listIt->getEntry().begin();
entryIt != listIt->getEntry().end(); entryIt++) { entryIt != listIt->getEntry().end(); entryIt++) {
//fixme until we have a fast uri parser //fixme until we have a fast uri parser
//belle_sip_uri_t *uri = belle_sip_uri_parse(entryIt->getUri().c_str()); //belle_sip_uri_t *uri = belle_sip_uri_parse(entryIt->getUri().c_str());
...@@ -106,12 +106,12 @@ ListSubscription::~ListSubscription() { ...@@ -106,12 +106,12 @@ ListSubscription::~ListSubscription() {
SLOGD << "List souscription ["<< this <<"] deleted"; SLOGD << "List souscription ["<< this <<"] deleted";
}; };
void ListSubscription::addInstanceToResource(rlmi::Resource &resource, list<belle_sip_body_handler_t *> &multipartList, void ListSubscription::addInstanceToResource(Xsd::Rlmi::Resource &resource, list<belle_sip_body_handler_t *> &multipartList,
PresentityPresenceInformation &presentityInformation, bool extended) { PresentityPresenceInformation &presentityInformation, bool extended) {
// we have a resource instance // we have a resource instance
// subscription state is always active until we implement ACL // subscription state is always active until we implement ACL
rlmi::Instance instance("1", rlmi::State::active); Xsd::Rlmi::Instance instance("1", Xsd::Rlmi::State::active);
char cid_rand_part[8]; char cid_rand_part[8];
belle_sip_random_token(cid_rand_part, sizeof(cid_rand_part)); belle_sip_random_token(cid_rand_part, sizeof(cid_rand_part));
ostringstream cid; ostringstream cid;
...@@ -157,7 +157,7 @@ void ListSubscription::notify(bool isFullState) throw(FlexisipException) { ...@@ -157,7 +157,7 @@ void ListSubscription::notify(bool isFullState) throw(FlexisipException) {
*/ */
SLOGE << "First NOTIFY sent in subscription [" << mName << "] MUST contain full state"; SLOGE << "First NOTIFY sent in subscription [" << mName << "] MUST contain full state";
} }
rlmi::List resourceList(string(uri), mVersion, isFullState); Xsd::Rlmi::List resourceList(string(uri), mVersion, isFullState);
belle_sip_free(uri); belle_sip_free(uri);
list<belle_sip_body_handler_t *> multipartList; list<belle_sip_body_handler_t *> multipartList;
...@@ -165,7 +165,7 @@ void ListSubscription::notify(bool isFullState) throw(FlexisipException) { ...@@ -165,7 +165,7 @@ void ListSubscription::notify(bool isFullState) throw(FlexisipException) {
SLOGI << "Building full state rlmi for list name [" << mName << "]"; SLOGI << "Building full state rlmi for list name [" << mName << "]";
for (shared_ptr<PresentityPresenceInformationListener> &resourceListener : mListeners) { for (shared_ptr<PresentityPresenceInformationListener> &resourceListener : mListeners) {
char *presentityUri = belle_sip_uri_to_string(resourceListener->getPresentityUri()); char *presentityUri = belle_sip_uri_to_string(resourceListener->getPresentityUri());
rlmi::Resource resource(presentityUri); Xsd::Rlmi::Resource resource(presentityUri);
belle_sip_free(presentityUri); belle_sip_free(presentityUri);
PendingStateType::iterator it = mPendingStates.find(resourceListener->getPresentityUri()); PendingStateType::iterator it = mPendingStates.find(resourceListener->getPresentityUri());
if (it != mPendingStates.end() && it->second.first->isKnown()) { if (it != mPendingStates.end() && it->second.first->isKnown()) {
...@@ -183,7 +183,7 @@ void ListSubscription::notify(bool isFullState) throw(FlexisipException) { ...@@ -183,7 +183,7 @@ void ListSubscription::notify(bool isFullState) throw(FlexisipException) {
if (presenceInformationPair.second.first->isKnown()) { /* only notify for entity with known state*/ if (presenceInformationPair.second.first->isKnown()) { /* only notify for entity with known state*/
shared_ptr<PresentityPresenceInformation> presenceInformation = presenceInformationPair.second.first; shared_ptr<PresentityPresenceInformation> presenceInformation = presenceInformationPair.second.first;
char *presentityUri = belle_sip_uri_to_string(presenceInformation->getEntity()); char *presentityUri = belle_sip_uri_to_string(presenceInformation->getEntity());
rlmi::Resource resource(presentityUri); Xsd::Rlmi::Resource resource(presentityUri);
belle_sip_free(presentityUri); belle_sip_free(presentityUri);
addInstanceToResource(resource, multipartList, *presenceInformation, presenceInformationPair.second.second); addInstanceToResource(resource, multipartList, *presenceInformation, presenceInformationPair.second.second);
resourceList.getResource().push_back(resource); resourceList.getResource().push_back(resource);
...@@ -199,10 +199,10 @@ void ListSubscription::notify(bool isFullState) throw(FlexisipException) { ...@@ -199,10 +199,10 @@ void ListSubscription::notify(bool isFullState) throw(FlexisipException) {
// Serialize the object model to XML. // Serialize the object model to XML.
// //
xml_schema::NamespaceInfomap map; Xsd::XmlSchema::NamespaceInfomap map;
map[""].name = "urn:ietf:params:xml:ns:rlmi"; map[""].name = "urn:ietf:params:xml:ns:rlmi";
stringstream out; stringstream out;
rlmi::serializeList(out, resourceList, map); Xsd::Rlmi::serializeList(out, resourceList, map);
belle_sip_memory_body_handler_t *firstBodyPart = belle_sip_memory_body_handler_new_copy_from_buffer( belle_sip_memory_body_handler_t *firstBodyPart = belle_sip_memory_body_handler_new_copy_from_buffer(
(void *)out.str().c_str(), out.str().length(), NULL, NULL); (void *)out.str().c_str(), out.str().length(), NULL, NULL);
...@@ -224,7 +224,7 @@ void ListSubscription::notify(bool isFullState) throw(FlexisipException) { ...@@ -224,7 +224,7 @@ void ListSubscription::notify(bool isFullState) throw(FlexisipException) {
mVersion++; mVersion++;
mLastNotify = chrono::system_clock::now(); mLastNotify = chrono::system_clock::now();
mPendingStates.clear(); mPendingStates.clear();
} catch (const xml_schema::Serialization &e) { } catch (const Xsd::XmlSchema::Serialization &e) {
throw FLEXISIP_EXCEPTION << "serialization error: " << e.diagnostics(); throw FLEXISIP_EXCEPTION << "serialization error: " << e.diagnostics();
} catch (exception &e) { } catch (exception &e) {
throw FLEXISIP_EXCEPTION << "Cannot get build list notidy for [" << mName << "]error [" << e.what() << "]"; throw FLEXISIP_EXCEPTION << "Cannot get build list notidy for [" << mName << "]error [" << e.what() << "]";
......
...@@ -19,13 +19,11 @@ ...@@ -19,13 +19,11 @@
#ifndef flexisip_rls_subscription_hh #ifndef flexisip_rls_subscription_hh
#define flexisip_rls_subscription_hh #define flexisip_rls_subscription_hh
#include "subscription.hh" #include "subscription.hh"
#include "rlmi+xml.hh"
#include <unordered_map> #include <unordered_map>
#include <chrono> #include <chrono>
typedef struct _belle_sip_uri belle_sip_uri_t; typedef struct _belle_sip_uri belle_sip_uri_t;
typedef struct belle_sip_server_transaction belle_sip_server_transaction_t; typedef struct belle_sip_server_transaction belle_sip_server_transaction_t;
namespace rlmi {
class Resource;
}
namespace flexisip { namespace flexisip {
class ListSubscription; class ListSubscription;
...@@ -76,7 +74,7 @@ class ListSubscription : public Subscription { ...@@ -76,7 +74,7 @@ class ListSubscription : public Subscription {
ListSubscription(const ListSubscription &); ListSubscription(const ListSubscription &);
// return true if a real notify can be sent. // return true if a real notify can be sent.
bool isTimeToNotify(); bool isTimeToNotify();
void addInstanceToResource(rlmi::Resource &resource, std::list<belle_sip_body_handler_t *> &multipartList, void addInstanceToResource(Xsd::Rlmi::Resource &resource, std::list<belle_sip_body_handler_t *> &multipartList,
PresentityPresenceInformation &presentityInformation, bool extended); PresentityPresenceInformation &presentityInformation, bool extended);
std::list<std::shared_ptr<PresentityPresenceInformationListener>> mListeners; std::list<std::shared_ptr<PresentityPresenceInformationListener>> mListeners;
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#include "presence-server.hh" #include "presence-server.hh"
#include "belle-sip/belle-sip.h" #include "belle-sip/belle-sip.h"
#include "pidf+xml.hxx" #include "pidf+xml.hh"
#include "resource-lists.hxx" #include "resource-lists.hh"
#include "presentity-presenceinformation.hh" #include "presentity-presenceinformation.hh"
#include "list-subscription.hh" #include "list-subscription.hh"
#include "bellesip-signaling-exception.hh" #include "bellesip-signaling-exception.hh"
...@@ -391,11 +391,11 @@ void PresenceServer::processPublishRequestEvent(const belle_sip_request_event_t ...@@ -391,11 +391,11 @@ void PresenceServer::processPublishRequestEvent(const belle_sip_request_event_t
// At that point, we are safe // At that point, we are safe
if (belle_sip_message_get_body_size(BELLE_SIP_MESSAGE(request)) > 0) { if (belle_sip_message_get_body_size(BELLE_SIP_MESSAGE(request)) > 0) {
::std::unique_ptr<pidf::Presence> presence_body = NULL; ::std::unique_ptr<Xsd::Pidf::Presence> presence_body = NULL;
try { try {
istringstream data(belle_sip_message_get_body(BELLE_SIP_MESSAGE(request))); istringstream data(belle_sip_message_get_body(BELLE_SIP_MESSAGE(request)));
presence_body = parsePresence(data, xml_schema::Flags::dont_validate); presence_body = Xsd::Pidf::parsePresence(data, Xsd::XmlSchema::Flags::dont_validate);
} catch (const xml_schema::Exception &e) { } catch (const Xsd::XmlSchema::Exception &e) {
ostringstream os; ostringstream os;
os << "Cannot parse body caused by [" << e << "]"; os << "Cannot parse body caused by [" << e << "]";
// todo check error code // todo check error code
......
...@@ -21,24 +21,21 @@ ...@@ -21,24 +21,21 @@
#include <ostream> #include <ostream>
#include <functional> #include <functional>
#include "etag-manager.hh" #include "etag-manager.hh"
#include "pidf+xml.hxx" #include "pidf+xml.hh"
#include "rpid.hxx" #include "rpid.hh"
#include "data-model.hxx" #include "data-model.hh"
#include <memory> #include <memory>
#include "presentity-manager.hh" #include "presentity-manager.hh"
#include "log/logmanager.hh" #include "log/logmanager.hh"
#define ETAG_SIZE 8 #define ETAG_SIZE 8
using namespace pidf;
using namespace rpid;
using namespace data_model;
using namespace std; using namespace std;
namespace flexisip { namespace flexisip {
static string generate_presence_id(void); static string generate_presence_id(void);
FlexisipException &operator<<(FlexisipException &e, const xml_schema::Exception &val) { FlexisipException &operator<<(FlexisipException &e, const Xsd::XmlSchema::Exception &val) {
stringstream e_out; stringstream e_out;
e_out << val; e_out << val;
e << e_out.str(); e << e_out.str();
...@@ -51,16 +48,16 @@ PresenceInformationElement::PresenceInformationElement(const belle_sip_uri_t *co ...@@ -51,16 +48,16 @@ PresenceInformationElement::PresenceInformationElement(const belle_sip_uri_t *co
std::time_t t; std::time_t t;
std::time(&t); std::time(&t);
struct tm *now = gmtime(&t); struct tm *now = gmtime(&t);
Status status; Xsd::Pidf::Status status;
status.setBasic(Basic("open")); status.setBasic(Xsd::Pidf::Basic("open"));
unique_ptr<Tuple> tup(new Tuple(status, string(generate_presence_id()))); unique_ptr<Xsd::Pidf::Tuple> tup(new Xsd::Pidf::Tuple(status, string(generate_presence_id())));
tup->setTimestamp(::xml_schema::DateTime(now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, tup->setTimestamp(Xsd::XmlSchema::DateTime(now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour,
now->tm_min, now->tm_sec)); now->tm_min, now->tm_sec));
tup->setContact(::pidf::Contact(contact_as_string)); tup->setContact(Xsd::Pidf::Contact(contact_as_string));
mTuples.clear(); // just in case mTuples.clear(); // just in case
mTuples.push_back(std::unique_ptr<Tuple>(tup.release())); mTuples.push_back(std::unique_ptr<Xsd::Pidf::Tuple>(tup.release()));
Activities act = Activities(); Xsd::Rpid::Activities act = Xsd::Rpid::Activities();
act.getAway().push_back(rpid::Empty()); act.getAway().push_back(Xsd::Rpid::Empty());
mPerson.setId(contact_as_string); mPerson.setId(contact_as_string);
mPerson.getActivities().push_back(act); mPerson.getActivities().push_back(act);
belle_sip_free(contact_as_string); belle_sip_free(contact_as_string);
...@@ -107,20 +104,20 @@ bool PresentityPresenceInformation::findPresenceInfo(std::shared_ptr<PresentityP ...@@ -107,20 +104,20 @@ bool PresentityPresenceInformation::findPresenceInfo(std::shared_ptr<PresentityP
} }
return false; return false;
} }
string PresentityPresenceInformation::putTuples(pidf::Presence::TupleSequence &tuples, string PresentityPresenceInformation::putTuples(Xsd::Pidf::Presence::TupleSequence &tuples,
data_model::Person &person, int expires) { Xsd::DataModel::Person &person, int expires) {
return setOrUpdate(&tuples, &person, NULL, expires); return setOrUpdate(&tuples, &person, NULL, expires);
} }
string PresentityPresenceInformation::updateTuples(pidf::Presence::TupleSequence &tuples, string PresentityPresenceInformation::updateTuples(Xsd::Pidf::Presence::TupleSequence &tuples,
data_model::Person &person, string &eTag, Xsd::DataModel::Person &person, string &eTag,
int expires) throw(FlexisipException) { int expires) throw(FlexisipException) {
return setOrUpdate(&tuples, &person, &eTag, expires); return setOrUpdate(&tuples, &person, &eTag, expires);
} }
void PresenceInformationElement::clearTuples() { void PresenceInformationElement::clearTuples() {
mTuples.clear(); mTuples.clear();
} }
string PresentityPresenceInformation::setOrUpdate(pidf::Presence::TupleSequence *tuples, string PresentityPresenceInformation::setOrUpdate(Xsd::Pidf::Presence::TupleSequence *tuples,
data_model::Person *person, const string *eTag, Xsd::DataModel::Person *person, const string *eTag,
int expires) throw(FlexisipException) { int expires) throw(FlexisipException) {
PresenceInformationElement *informationElement = NULL; PresenceInformationElement *informationElement = NULL;
...@@ -205,7 +202,7 @@ void PresentityPresenceInformation::setDefaultElement(const char *contact) { ...@@ -205,7 +202,7 @@ void PresentityPresenceInformation::setDefaultElement(const char *contact) {
if (contact) { if (contact) {
for (auto & tup : mDefaultInformationElement->getTuples()) { for (auto & tup : mDefaultInformationElement->getTuples()) {
tup->setContact(::pidf::Contact(contact)); tup->setContact(Xsd::Pidf::Contact(contact));
} }
} }
...@@ -334,14 +331,14 @@ string PresentityPresenceInformation::getPidf(bool extended) throw(FlexisipExcep ...@@ -334,14 +331,14 @@ string PresentityPresenceInformation::getPidf(bool extended) throw(FlexisipExcep
stringstream out; stringstream out;
try { try {
char *entity = belle_sip_uri_to_string(getEntity()); char *entity = belle_sip_uri_to_string(getEntity());
pidf::Presence presence((string(entity))); Xsd::Pidf::Presence presence((string(entity)));
belle_sip_free(entity); belle_sip_free(entity);
list<string> tupleList; list<string> tupleList;
if(extended) { if(extended) {
for (auto element : mInformationElements) { for (auto element : mInformationElements) {
// copy pidf // copy pidf
for (const unique_ptr<pidf::Tuple> &tup : element.second->getTuples()) { for (const unique_ptr<Xsd::Pidf::Tuple> &tup : element.second->getTuples()) {
// check for multiple tupple id, may happend with buggy presence publisher // check for multiple tupple id, may happend with buggy presence publisher
if (find(tupleList.begin(), tupleList.end(), tup.get()->getId()) == tupleList.end()) { if (find(tupleList.begin(), tupleList.end(), tup.get()->getId()) == tupleList.end()) {
presence.getTuple().push_back(*tup); presence.getTuple().push_back(*tup);
...@@ -351,10 +348,10 @@ string PresentityPresenceInformation::getPidf(bool extended) throw(FlexisipExcep ...@@ -351,10 +348,10 @@ string PresentityPresenceInformation::getPidf(bool extended) throw(FlexisipExcep
} }
} }
// copy extensions // copy extensions
Person dm_person = element.second->getPerson(); Xsd::DataModel::Person dm_person = element.second->getPerson();
for(data_model::Person::ActivitiesIterator activity = dm_person.getActivities().begin(); activity != dm_person.getActivities().end();activity++) { for(Xsd::DataModel::Person::ActivitiesIterator activity = dm_person.getActivities().begin(); activity != dm_person.getActivities().end();activity++) {
if(!presence.getPerson()) { if(!presence.getPerson()) {
Person person = Person(dm_person.getId()); Xsd::DataModel::Person person = Xsd::DataModel::Person(dm_person.getId());
presence.setPerson(person); presence.setPerson(person);
} }
presence.getPerson()->getActivities().push_back(*activity); presence.getPerson()->getActivities().push_back(*activity);
...@@ -366,17 +363,17 @@ string PresentityPresenceInformation::getPidf(bool extended) throw(FlexisipExcep ...@@ -366,17 +363,17 @@ string PresentityPresenceInformation::getPidf(bool extended) throw(FlexisipExcep
presence.getTuple().push_back(*mDefaultInformationElement->getTuples().begin()->get()); presence.getTuple().push_back(*mDefaultInformationElement->getTuples().begin()->get());
// copy extensions // copy extensions
Person dm_person = mDefaultInformationElement->getPerson(); Xsd::DataModel::Person dm_person = mDefaultInformationElement->getPerson();
for(data_model::Person::ActivitiesIterator activity = dm_person.getActivities().begin(); activity != dm_person.getActivities().end();activity++) { for(Xsd::DataModel::Person::ActivitiesIterator activity = dm_person.getActivities().begin(); activity != dm_person.getActivities().end();activity++) {
if(!presence.getPerson()) { if(!presence.getPerson()) {
Person person = Person(dm_person.getId()); Xsd::DataModel::Person person = Xsd::DataModel::Person(dm_person.getId());
presence.setPerson(person); presence.setPerson