diff --git a/libretroshare/src/retroshare/rsgxscircles.h b/libretroshare/src/retroshare/rsgxscircles.h index 83f8e840c..407871d80 100644 --- a/libretroshare/src/retroshare/rsgxscircles.h +++ b/libretroshare/src/retroshare/rsgxscircles.h @@ -3,8 +3,8 @@ * * * libretroshare: retroshare core library * * * - * Copyright (C) 2012 Robert Fernie * - * Copyright (C) 2018 Gioacchino Mazzurco * + * Copyright (C) 2012-2014 Robert Fernie * + * Copyright (C) 2018-2019 Gioacchino Mazzurco * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -32,6 +32,7 @@ #include "retroshare/rsgxsifacehelper.h" #include "retroshare/rsidentity.h" #include "serialiser/rsserializable.h" +#include "util/rsmemory.h" class RsGxsCircles; @@ -74,8 +75,6 @@ static const uint32_t GXS_EXTERNAL_CIRCLE_FLAGS_ALLOWED = 0x0007 ;// user struct RsGxsCircleGroup : RsSerializable { - virtual ~RsGxsCircleGroup() {} - RsGroupMetaData mMeta; std::set mLocalFriends; @@ -95,17 +94,17 @@ struct RsGxsCircleGroup : RsSerializable RS_SERIAL_PROCESS(mInvitedMembers); RS_SERIAL_PROCESS(mSubCircles); } + + ~RsGxsCircleGroup() override; }; struct RsGxsCircleMsg : RsSerializable { - virtual ~RsGxsCircleMsg() {} - RsMsgMetaData mMeta; #ifndef V07_NON_BACKWARD_COMPATIBLE_CHANGE_UNNAMED /* This is horrible and should be changed into yet to be defined something - * reasonable in next non retrocompatible version */ + * reasonable in next non-retrocompatible version */ std::string stuff; #endif @@ -116,6 +115,8 @@ struct RsGxsCircleMsg : RsSerializable RS_SERIAL_PROCESS(mMeta); RS_SERIAL_PROCESS(stuff); } + + ~RsGxsCircleMsg() override; }; struct RsGxsCircleDetails : RsSerializable @@ -123,7 +124,7 @@ struct RsGxsCircleDetails : RsSerializable RsGxsCircleDetails() : mCircleType(static_cast(RsGxsCircleType::EXTERNAL)), mAmIAllowed(false) {} - ~RsGxsCircleDetails() override {} + ~RsGxsCircleDetails() override; RsGxsCircleId mCircleId; std::string mCircleName; @@ -162,16 +163,29 @@ class RsGxsCircles: public RsGxsIfaceHelper public: RsGxsCircles(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {} - virtual ~RsGxsCircles() {} + virtual ~RsGxsCircles(); /** * @brief Create new circle * @jsonapi{development} - * @param[inout] cData input name and flags of the circle, storage for - * generated circle data id etc. + * @param[in] circleName String containing cirlce name + * @param[in] circleType Circle type + * @param[out] circleId Optional storage to output created circle id + * @param[in] restrictedId Optional id of a pre-existent circle that see the + * created circle. Meaningful only if circleType == EXTERNAL, must be null + * in all other cases. + * @param[in] authorId Optional author of the circle. + * @param[in] gxsIdMembers GXS ids of the members of the circle. + * @param[in] localMembers PGP ids of the members if the circle. * @return false if something failed, true otherwhise */ - virtual bool createCircle(RsGxsCircleGroup& cData) = 0; + virtual bool createCircle( + const std::string& circleName, RsGxsCircleType circleType, + RsGxsCircleId& circleId = RS_DEFAULT_STORAGE_PARAM(RsGxsCircleId), + const RsGxsCircleId& restrictedId = RsGxsCircleId(), + const RsGxsId& authorId = RsGxsId(), + const std::set& gxsIdMembers = std::set(), + const std::set& localMembers = std::set() ) = 0; /** * @brief Edit own existing circle diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 2df9a7bfd..f56312659 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -522,6 +522,7 @@ public: * @return true on success */ virtual bool getMessage(const std::string &msgId, Rs::Msgs::MessageInfo &msg) = 0; + /** * @brief getMessageCount * @jsonapi{development} diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 504dfdc67..3087fe4c6 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -3,7 +3,8 @@ * * * libretroshare: retroshare core library * * * - * Copyright 2012-2012 Robert Fernie * + * Copyright (C) 2012-2014 Robert Fernie * + * Copyright (C) 2018-2019 Gioacchino Mazzurco * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -27,7 +28,7 @@ #include "util/rsdir.h" #include "util/radix64.h" #include "util/rsstring.h" - +#include "util/rsdebug.h" #include "pgp/pgpauxutils.h" #include "retroshare/rsgxscircles.h" #include "retroshare/rspeers.h" @@ -153,8 +154,76 @@ RsServiceInfo p3GxsCircles::getServiceInfo() GXS_CIRCLES_MIN_MINOR_VERSION); } -bool p3GxsCircles::createCircle(RsGxsCircleGroup& cData) +bool p3GxsCircles::createCircle( + const std::string& circleName, RsGxsCircleType circleType, + RsGxsCircleId& circleId, const RsGxsCircleId& restrictedId, + const RsGxsId& authorId, const std::set& gxsIdMembers, + const std::set& localMembers ) { + if(circleName.empty()) + { + RsErr() << __PRETTY_FUNCTION__ << " Circle name is empty" << std::endl; + return false; + } + + switch(circleType) + { + case RsGxsCircleType::PUBLIC: + if(!restrictedId.isNull()) + { + RsErr() << __PRETTY_FUNCTION__ << " restrictedId: " << restrictedId + << " must be null with RsGxsCircleType::PUBLIC" + << std::endl; + return false; + } + break; + case RsGxsCircleType::EXTERNAL: + if(restrictedId.isNull()) + { + RsErr() << __PRETTY_FUNCTION__ << " restrictedId can't be null " + << "with RsGxsCircleType::EXTERNAL" << std::endl; + return false; + } + break; + case RsGxsCircleType::NODES_GROUP: + if(localMembers.empty()) + { + RsErr() << __PRETTY_FUNCTION__ << " localMembers can't be empty " + << "with RsGxsCircleType::NODES_GROUP" << std::endl; + return false; + } + break; + case RsGxsCircleType::LOCAL: + break; + case RsGxsCircleType::EXT_SELF: + if(!restrictedId.isNull()) + { + RsErr() << __PRETTY_FUNCTION__ << " restrictedId: " << restrictedId + << " must be null with RsGxsCircleType::EXT_SELF" + << std::endl; + return false; + } + if(gxsIdMembers.empty()) + { + RsErr() << __PRETTY_FUNCTION__ << " gxsIdMembers can't be empty " + << "with RsGxsCircleType::EXT_SELF" << std::endl; + return false; + } + break; + case RsGxsCircleType::YOUR_EYES_ONLY: + break; + default: + RsErr() << __PRETTY_FUNCTION__ << " Invalid circle type: " + << static_cast(circleType) << std::endl; + return false; + } + + RsGxsCircleGroup cData; + cData.mMeta.mGroupName = circleName; + cData.mMeta.mAuthorId = authorId; + cData.mMeta.mCircleType = static_cast(circleType); + cData.mMeta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_PUBLIC; + uint32_t token; createGroup(token, cData); @@ -172,8 +241,9 @@ bool p3GxsCircles::createCircle(RsGxsCircleGroup& cData) return false; } + circleId = static_cast(cData.mMeta.mGroupId); return true; -} +}; bool p3GxsCircles::editCircle(RsGxsCircleGroup& cData) { @@ -2157,3 +2227,8 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token) return true ; } + +RsGxsCircles::~RsGxsCircles() = default; +RsGxsCircleMsg::~RsGxsCircleMsg() = default; +RsGxsCircleDetails::~RsGxsCircleDetails() = default; +RsGxsCircleGroup::~RsGxsCircleGroup() = default; diff --git a/libretroshare/src/services/p3gxscircles.h b/libretroshare/src/services/p3gxscircles.h index a23ecbd88..48129a9ba 100644 --- a/libretroshare/src/services/p3gxscircles.h +++ b/libretroshare/src/services/p3gxscircles.h @@ -3,7 +3,8 @@ * * * libretroshare: retroshare core library * * * - * Copyright 2012-2012 Robert Fernie * + * Copyright (C) 2012-2014 Robert Fernie * + * Copyright (C) 2018-2019 Gioacchino Mazzurco * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -19,8 +20,7 @@ * along with this program. If not, see . * * * *******************************************************************************/ -#ifndef P3_CIRCLES_SERVICE_HEADER -#define P3_CIRCLES_SERVICE_HEADER +#pragma once #include "retroshare/rsgxscircles.h" // External Interfaces. @@ -180,7 +180,14 @@ virtual RsServiceInfo getServiceInfo(); /*********** External Interface ***************/ /// @see RsGxsCircles - bool createCircle(RsGxsCircleGroup& cData) override; + bool createCircle( + const std::string& circleName, RsGxsCircleType circleType, + RsGxsCircleId& circleId = RS_DEFAULT_STORAGE_PARAM(RsGxsCircleId), + const RsGxsCircleId& restrictedId = RsGxsCircleId(), + const RsGxsId& authorId = RsGxsId(), + const std::set& gxsIdMembers = std::set(), + const std::set& localMembers = std::set() + ) override; /// @see RsGxsCircles bool editCircle(RsGxsCircleGroup& cData) override; @@ -315,5 +322,3 @@ virtual RsServiceInfo getServiceInfo(); std::list mDummyPgpLinkedIds; std::list mDummyOwnIds; }; - -#endif // P3_CIRCLES_SERVICE_HEADER