Merge pull request #1638 from G10h4ck/circle_jsonapi

Provide more usable method to create GXS circles
This commit is contained in:
G10h4ck 2019-09-15 20:06:06 +02:00 committed by GitHub
commit a0622ce3de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 22 deletions

View File

@ -3,8 +3,8 @@
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright (C) 2012 Robert Fernie <retroshare@lunamutt.com> * * Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> * * Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -32,6 +32,7 @@
#include "retroshare/rsgxsifacehelper.h" #include "retroshare/rsgxsifacehelper.h"
#include "retroshare/rsidentity.h" #include "retroshare/rsidentity.h"
#include "serialiser/rsserializable.h" #include "serialiser/rsserializable.h"
#include "util/rsmemory.h"
class RsGxsCircles; class RsGxsCircles;
@ -74,8 +75,6 @@ static const uint32_t GXS_EXTERNAL_CIRCLE_FLAGS_ALLOWED = 0x0007 ;// user
struct RsGxsCircleGroup : RsSerializable struct RsGxsCircleGroup : RsSerializable
{ {
virtual ~RsGxsCircleGroup() {}
RsGroupMetaData mMeta; RsGroupMetaData mMeta;
std::set<RsPgpId> mLocalFriends; std::set<RsPgpId> mLocalFriends;
@ -95,17 +94,17 @@ struct RsGxsCircleGroup : RsSerializable
RS_SERIAL_PROCESS(mInvitedMembers); RS_SERIAL_PROCESS(mInvitedMembers);
RS_SERIAL_PROCESS(mSubCircles); RS_SERIAL_PROCESS(mSubCircles);
} }
~RsGxsCircleGroup() override;
}; };
struct RsGxsCircleMsg : RsSerializable struct RsGxsCircleMsg : RsSerializable
{ {
virtual ~RsGxsCircleMsg() {}
RsMsgMetaData mMeta; RsMsgMetaData mMeta;
#ifndef V07_NON_BACKWARD_COMPATIBLE_CHANGE_UNNAMED #ifndef V07_NON_BACKWARD_COMPATIBLE_CHANGE_UNNAMED
/* This is horrible and should be changed into yet to be defined something /* 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; std::string stuff;
#endif #endif
@ -116,6 +115,8 @@ struct RsGxsCircleMsg : RsSerializable
RS_SERIAL_PROCESS(mMeta); RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(stuff); RS_SERIAL_PROCESS(stuff);
} }
~RsGxsCircleMsg() override;
}; };
struct RsGxsCircleDetails : RsSerializable struct RsGxsCircleDetails : RsSerializable
@ -123,7 +124,7 @@ struct RsGxsCircleDetails : RsSerializable
RsGxsCircleDetails() : RsGxsCircleDetails() :
mCircleType(static_cast<uint32_t>(RsGxsCircleType::EXTERNAL)), mCircleType(static_cast<uint32_t>(RsGxsCircleType::EXTERNAL)),
mAmIAllowed(false) {} mAmIAllowed(false) {}
~RsGxsCircleDetails() override {} ~RsGxsCircleDetails() override;
RsGxsCircleId mCircleId; RsGxsCircleId mCircleId;
std::string mCircleName; std::string mCircleName;
@ -162,16 +163,29 @@ class RsGxsCircles: public RsGxsIfaceHelper
public: public:
RsGxsCircles(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {} RsGxsCircles(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
virtual ~RsGxsCircles() {} virtual ~RsGxsCircles();
/** /**
* @brief Create new circle * @brief Create new circle
* @jsonapi{development} * @jsonapi{development}
* @param[inout] cData input name and flags of the circle, storage for * @param[in] circleName String containing cirlce name
* generated circle data id etc. * @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 * @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<RsGxsId>& gxsIdMembers = std::set<RsGxsId>(),
const std::set<RsPgpId>& localMembers = std::set<RsPgpId>() ) = 0;
/** /**
* @brief Edit own existing circle * @brief Edit own existing circle

View File

@ -522,6 +522,7 @@ public:
* @return true on success * @return true on success
*/ */
virtual bool getMessage(const std::string &msgId, Rs::Msgs::MessageInfo &msg) = 0; virtual bool getMessage(const std::string &msgId, Rs::Msgs::MessageInfo &msg) = 0;
/** /**
* @brief getMessageCount * @brief getMessageCount
* @jsonapi{development} * @jsonapi{development}

View File

@ -3,7 +3,8 @@
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> * * Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -27,7 +28,7 @@
#include "util/rsdir.h" #include "util/rsdir.h"
#include "util/radix64.h" #include "util/radix64.h"
#include "util/rsstring.h" #include "util/rsstring.h"
#include "util/rsdebug.h"
#include "pgp/pgpauxutils.h" #include "pgp/pgpauxutils.h"
#include "retroshare/rsgxscircles.h" #include "retroshare/rsgxscircles.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
@ -153,8 +154,76 @@ RsServiceInfo p3GxsCircles::getServiceInfo()
GXS_CIRCLES_MIN_MINOR_VERSION); 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<RsGxsId>& gxsIdMembers,
const std::set<RsPgpId>& 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<uint32_t>(circleType) << std::endl;
return false;
}
RsGxsCircleGroup cData;
cData.mMeta.mGroupName = circleName;
cData.mMeta.mAuthorId = authorId;
cData.mMeta.mCircleType = static_cast<uint32_t>(circleType);
cData.mMeta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_PUBLIC;
uint32_t token; uint32_t token;
createGroup(token, cData); createGroup(token, cData);
@ -172,8 +241,9 @@ bool p3GxsCircles::createCircle(RsGxsCircleGroup& cData)
return false; return false;
} }
circleId = static_cast<RsGxsCircleId>(cData.mMeta.mGroupId);
return true; return true;
} };
bool p3GxsCircles::editCircle(RsGxsCircleGroup& cData) bool p3GxsCircles::editCircle(RsGxsCircleGroup& cData)
{ {
@ -2157,3 +2227,8 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token)
return true ; return true ;
} }
RsGxsCircles::~RsGxsCircles() = default;
RsGxsCircleMsg::~RsGxsCircleMsg() = default;
RsGxsCircleDetails::~RsGxsCircleDetails() = default;
RsGxsCircleGroup::~RsGxsCircleGroup() = default;

View File

@ -3,7 +3,8 @@
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> * * Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -19,8 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * * along with this program. If not, see <https://www.gnu.org/licenses/>. *
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef P3_CIRCLES_SERVICE_HEADER #pragma once
#define P3_CIRCLES_SERVICE_HEADER
#include "retroshare/rsgxscircles.h" // External Interfaces. #include "retroshare/rsgxscircles.h" // External Interfaces.
@ -180,7 +180,14 @@ virtual RsServiceInfo getServiceInfo();
/*********** External Interface ***************/ /*********** External Interface ***************/
/// @see RsGxsCircles /// @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<RsGxsId>& gxsIdMembers = std::set<RsGxsId>(),
const std::set<RsPgpId>& localMembers = std::set<RsPgpId>()
) override;
/// @see RsGxsCircles /// @see RsGxsCircles
bool editCircle(RsGxsCircleGroup& cData) override; bool editCircle(RsGxsCircleGroup& cData) override;
@ -315,5 +322,3 @@ virtual RsServiceInfo getServiceInfo();
std::list<RsGxsId> mDummyPgpLinkedIds; std::list<RsGxsId> mDummyPgpLinkedIds;
std::list<RsGxsId> mDummyOwnIds; std::list<RsGxsId> mDummyOwnIds;
}; };
#endif // P3_CIRCLES_SERVICE_HEADER