From 6862e642e8fb2b34090730b1da50a7bd6cfe319b Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 14 Sep 2019 20:58:04 +0200 Subject: [PATCH 1/2] Provide more usable method to create GXS circles Fix some compiler warnings with out of definition default destructors --- libretroshare/src/retroshare/rsgxscircles.h | 34 ++++++--- libretroshare/src/services/p3gxscircles.cc | 80 ++++++++++++++++++++- libretroshare/src/services/p3gxscircles.h | 9 ++- 3 files changed, 109 insertions(+), 14 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxscircles.h b/libretroshare/src/retroshare/rsgxscircles.h index 83f8e840c..4ff56c4a7 100644 --- a/libretroshare/src/retroshare/rsgxscircles.h +++ b/libretroshare/src/retroshare/rsgxscircles.h @@ -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/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 504dfdc67..9ef33fd84 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -27,7 +27,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 +153,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 +240,9 @@ bool p3GxsCircles::createCircle(RsGxsCircleGroup& cData) return false; } + circleId = static_cast(cData.mMeta.mGroupId); return true; -} +}; bool p3GxsCircles::editCircle(RsGxsCircleGroup& cData) { @@ -2157,3 +2226,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..859d2a6d0 100644 --- a/libretroshare/src/services/p3gxscircles.h +++ b/libretroshare/src/services/p3gxscircles.h @@ -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; From e411b7fb22ab3095d74bae8152becbf201b13968 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sun, 15 Sep 2019 12:10:37 +0200 Subject: [PATCH 2/2] Clean some dust --- libretroshare/src/retroshare/rsgxscircles.h | 4 ++-- libretroshare/src/retroshare/rsmsgs.h | 1 + libretroshare/src/services/p3gxscircles.cc | 3 ++- libretroshare/src/services/p3gxscircles.h | 8 +++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxscircles.h b/libretroshare/src/retroshare/rsgxscircles.h index 4ff56c4a7..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 * 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 9ef33fd84..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 * diff --git a/libretroshare/src/services/p3gxscircles.h b/libretroshare/src/services/p3gxscircles.h index 859d2a6d0..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. @@ -322,5 +322,3 @@ virtual RsServiceInfo getServiceInfo(); std::list mDummyPgpLinkedIds; std::list mDummyOwnIds; }; - -#endif // P3_CIRCLES_SERVICE_HEADER