2012-01-11 18:01:29 -05:00
|
|
|
#ifndef RSGXS_H
|
|
|
|
#define RSGXS_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* libretroshare/src/gxs : rsgxs.h
|
|
|
|
*
|
|
|
|
* GXS interface for RetroShare.
|
2012-01-18 18:20:53 -05:00
|
|
|
* Convenience header
|
2012-01-11 18:01:29 -05:00
|
|
|
*
|
|
|
|
* Copyright 2011 Christopher Evi-Parker
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
* This is *THE* auth manager. It provides the web-of-trust via
|
|
|
|
* gpgme, and authenticates the certificates that are managed
|
|
|
|
* by the sublayer AuthSSL.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-02-24 16:15:08 -05:00
|
|
|
|
2012-01-18 18:20:53 -05:00
|
|
|
#include <inttypes.h>
|
2012-02-24 16:15:08 -05:00
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <set>
|
2012-02-12 10:18:05 -05:00
|
|
|
#include <map>
|
2012-01-11 18:01:29 -05:00
|
|
|
|
2012-05-17 18:45:48 -04:00
|
|
|
#include "serialiser/rsgxsitems.h"
|
2012-06-07 16:43:12 -04:00
|
|
|
#include "rsnxsobserver.h"
|
|
|
|
#include "rsnxs.h"
|
|
|
|
#include "rsgds.h"
|
2012-03-10 19:05:43 -05:00
|
|
|
|
|
|
|
#define GXS_STATUS_GRP_NOT_FOUND 1 /* request resulted in grp not found error */
|
|
|
|
#define GXS_STATUS_MSG_NOT_FOUND 2 /* request resulted in msg not found */
|
|
|
|
#define GXS_STATUS_ERROR 3 /* request is in error */
|
|
|
|
#define GXS_STATUS_OK 4 /* request was successful */
|
|
|
|
|
2012-05-17 18:45:48 -04:00
|
|
|
typedef uint64_t RsGroupId ;
|
2012-04-01 17:10:55 -04:00
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
class RsTokReqOptions
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsTokReqOptions() { mOptions = 0; mBefore = 0; mAfter = 0; }
|
|
|
|
|
|
|
|
uint32_t mOptions;
|
|
|
|
time_t mBefore;
|
|
|
|
time_t mAfter;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-04-01 17:10:55 -04:00
|
|
|
|
2012-02-24 16:15:08 -05:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* The whole idea is to provide a broad enough base class from which
|
2012-03-10 19:05:43 -05:00
|
|
|
* all the services listed in gxs/db_apps.h can be implemented
|
|
|
|
* The exchange service features a token redemption request/receive
|
|
|
|
* design in which services make as request to the underlying base
|
|
|
|
* class which returns a token which the service should redeem later
|
|
|
|
* when the request's corresponding receive is called later
|
2012-02-24 16:15:08 -05:00
|
|
|
* Main functionality: \n
|
2012-01-19 18:32:27 -05:00
|
|
|
*
|
2012-02-24 16:15:08 -05:00
|
|
|
* Compared to previous cache-system, some improvements are: \n
|
2012-01-19 18:32:27 -05:00
|
|
|
*
|
2012-02-24 16:15:08 -05:00
|
|
|
* On-demand: There is granularity both in time and hiearchy on whats \n
|
|
|
|
* locally resident, all this is controlled by service \n
|
2012-03-10 19:05:43 -05:00
|
|
|
* * hiearchy - only grps are completely sync'd, have to request msgs \n
|
|
|
|
* * time - grps and hence messages to sync if in time range, grps locally resident but outside range are kept \n
|
2012-01-19 18:32:27 -05:00
|
|
|
*
|
2012-02-24 16:15:08 -05:00
|
|
|
* Search: \n
|
|
|
|
* User can provide search terms (RsGxsSearchItem) that each service can use to retrieve \n
|
|
|
|
* information on items and groups available in their exchange network \n
|
2012-01-19 18:32:27 -05:00
|
|
|
*
|
|
|
|
*
|
2012-02-24 16:15:08 -05:00
|
|
|
* Actual data exchanging: \n
|
|
|
|
* Currently naming convention is a bit confused between 'items' or 'messages' \n
|
2012-03-10 19:05:43 -05:00
|
|
|
* - consider item and msgs to be the same for now, RsGxsId, gives easy means of associate msgs to grps \n
|
2012-02-24 16:15:08 -05:00
|
|
|
* - all data is received via call back \n
|
|
|
|
* - therefore interface to UI should not be based on being alerted to msg availability \n
|
|
|
|
*/
|
2012-06-07 16:43:12 -04:00
|
|
|
class RsGxsService : public RsNxsObserver
|
2012-02-24 16:15:08 -05:00
|
|
|
{
|
2012-01-19 18:32:27 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-06-07 16:43:12 -04:00
|
|
|
RsGxsService(RsGeneralDataService* gds, RsNetworkExchangeService* ns);
|
2012-05-17 18:45:48 -04:00
|
|
|
virtual ~RsGxsService();
|
2012-02-24 16:15:08 -05:00
|
|
|
|
2012-03-10 19:05:43 -05:00
|
|
|
/***************** Group request receive API ********************/
|
|
|
|
|
2012-06-07 16:43:12 -04:00
|
|
|
/*!
|
|
|
|
* It is critical this service implements
|
|
|
|
* this function and returns a valid service id
|
|
|
|
* @return the service type of the Gxs Service
|
|
|
|
*/
|
|
|
|
virtual uint16_t getServiceType() const = 0;
|
|
|
|
|
2012-01-19 18:32:27 -05:00
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* Request group information
|
|
|
|
* @param token this initialised with a token that can be redeemed for this request
|
|
|
|
* @param ansType type of group result wanted, summary
|
|
|
|
* @param opts token options
|
|
|
|
* @param groupIds list of group ids wanted, leaving this empty will result in a request for only list of group ids for the service
|
|
|
|
* @return false if request failed, true otherwise
|
2012-04-01 17:10:55 -04:00
|
|
|
* @see receiveGrp()
|
2012-01-19 18:32:27 -05:00
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds);
|
2012-03-10 19:05:43 -05:00
|
|
|
|
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* Request message information for a list of groups
|
|
|
|
* @param token this initialised with a token that can be redeemed for this request
|
|
|
|
* @param ansType type of msg info result
|
|
|
|
* @param opts token options
|
|
|
|
* @param groupIds groups ids for which message info will be requested
|
|
|
|
* @return false if request failed, true otherwise
|
|
|
|
* @see receiveGrp()
|
2012-03-10 19:05:43 -05:00
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
virtual bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds);
|
2012-02-12 10:18:05 -05:00
|
|
|
|
2012-02-24 16:15:08 -05:00
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* Request message information for a list of groups
|
|
|
|
* @param token this initialised with a token that can be redeemed for this request
|
|
|
|
* @param ansType type of msg info result
|
|
|
|
* @param opts token options
|
|
|
|
* @param groupIds groups ids for which message info will be requested
|
|
|
|
* @return false if request failed, true otherwise
|
|
|
|
* @see receiveGrp()
|
2012-02-24 16:15:08 -05:00
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &msgIds);
|
2012-03-10 19:05:43 -05:00
|
|
|
|
|
|
|
/*********** Start: publication *****************/
|
2012-02-24 16:15:08 -05:00
|
|
|
|
|
|
|
/*!
|
2012-03-10 19:05:43 -05:00
|
|
|
* Pushes a RsGxsItem for publication
|
|
|
|
* @param msg set of messages to push onto service for publication
|
|
|
|
*/
|
2012-04-01 17:10:55 -04:00
|
|
|
int pushMsg(std::set<RsGxsMsg*>& msg);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Updates an already published message
|
|
|
|
* on your network with this one
|
|
|
|
* Message must be associated to an identity on
|
|
|
|
* publication for this to work
|
|
|
|
* @param msg the message to update
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
int updateMsg(std::set<RsGxsMsg*>& msg);
|
2012-03-10 19:05:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Pushes a RsGxsGroup on RsGxsNetwork and associates it with a \n
|
|
|
|
* given RsGixs profile
|
|
|
|
* @param grp group to push onto network
|
2012-05-17 18:45:48 -04:00
|
|
|
|
2012-03-10 19:05:43 -05:00
|
|
|
* @return error code
|
|
|
|
*/
|
2012-05-17 18:45:48 -04:00
|
|
|
int pushGrp(const RsGxsGroup& grp);
|
2012-03-10 19:05:43 -05:00
|
|
|
|
|
|
|
/*!
|
2012-04-01 17:10:55 -04:00
|
|
|
* Update an already published group with
|
|
|
|
* new information
|
|
|
|
* This increments the version number
|
|
|
|
* @param grp grp to update
|
|
|
|
* @return token to be redeemed
|
|
|
|
*/
|
2012-05-17 18:45:48 -04:00
|
|
|
int updateGrp(const RsGxsGroup& grp);
|
2012-04-01 17:10:55 -04:00
|
|
|
|
2012-03-10 19:05:43 -05:00
|
|
|
|
|
|
|
/*********** End: publication *****************/
|
|
|
|
|
2012-02-24 16:15:08 -05:00
|
|
|
/****************************************************************************************************/
|
|
|
|
// Interface for Message Read Status
|
|
|
|
// At the moment this is overloaded to handle autodownload flags too.
|
|
|
|
// This is a configuration thing.
|
|
|
|
/****************************************************************************************************/
|
|
|
|
|
2012-03-10 19:05:43 -05:00
|
|
|
/*********** Start: Update of groups/messages locally *****************/
|
2012-02-24 16:15:08 -05:00
|
|
|
|
|
|
|
/*!
|
2012-05-17 18:45:48 -04:00
|
|
|
* flags latest message in store as read or not read
|
2012-03-10 19:05:43 -05:00
|
|
|
* @param GrpMsgMap flags this msg,version pair as read
|
|
|
|
* @param read set to true for read and false for unread
|
2012-02-24 16:15:08 -05:00
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
int flagMsgRead(const std::string& msgId, bool read) ;
|
2012-03-10 19:05:43 -05:00
|
|
|
|
2012-02-24 16:15:08 -05:00
|
|
|
|
|
|
|
/*!
|
2012-03-10 19:05:43 -05:00
|
|
|
* To flag group as read or not read
|
|
|
|
* @param grpId the
|
|
|
|
* @param
|
2012-02-24 16:15:08 -05:00
|
|
|
*/
|
2012-05-17 18:45:48 -04:00
|
|
|
int flagGroupRead(const std::string grpId, bool read);
|
2012-02-24 16:15:08 -05:00
|
|
|
|
2012-03-10 19:05:43 -05:00
|
|
|
/*!
|
2012-04-01 17:10:55 -04:00
|
|
|
* This marks a local message created by yourself to
|
|
|
|
* no longer distributed and removed
|
|
|
|
* Entry in db is discarded after expiration date has passed
|
|
|
|
* TODO: this may send a standard marker to user that message
|
|
|
|
* should be removed
|
2012-03-10 19:05:43 -05:00
|
|
|
* @param msgId
|
|
|
|
*/
|
2012-05-17 18:45:48 -04:00
|
|
|
int requestDeleteMsg(const RsGxsMsg& msg);
|
2012-02-24 16:15:08 -05:00
|
|
|
|
|
|
|
/*!
|
2012-03-10 19:05:43 -05:00
|
|
|
* This is grpId is marked in database to be removed
|
|
|
|
* and not circulated. Entry will later be removed
|
|
|
|
* once discard age is reached
|
2012-02-24 16:15:08 -05:00
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
bool requestDeleteGrp(uint32_t& token, const RsGxsGroup& grp);
|
2012-02-24 16:15:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2012-03-10 19:05:43 -05:00
|
|
|
* Use to subscribe or unsubscribe to group
|
|
|
|
* @param grpId the id of the group to scubscribe to
|
|
|
|
* @param subscribe set to false to unsubscribe and true otherwise
|
|
|
|
* @return token to redeem
|
2012-02-24 16:15:08 -05:00
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
bool requestSubscribeToGrp(uint32_t token, const std::string& grpId, bool subscribe);
|
2012-02-24 16:15:08 -05:00
|
|
|
|
2012-06-07 16:43:12 -04:00
|
|
|
public:
|
|
|
|
|
2012-03-10 19:05:43 -05:00
|
|
|
/*!
|
|
|
|
* This called by event runner on status of subscription
|
|
|
|
* @param token the token to be redeemed
|
2012-04-01 17:10:55 -04:00
|
|
|
* @param errCode error code, can be exchanged for error string
|
2012-03-10 19:05:43 -05:00
|
|
|
* @param gxsStatus the status of subscription request
|
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
virtual void receiveSubscribeToGrp(int token, int errCode);
|
2012-04-01 17:10:55 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* @param error_code
|
|
|
|
* @param errorMsg
|
|
|
|
*/
|
|
|
|
virtual void statusMsg(int error_code, const std::string& errorMsg);
|
2012-02-24 16:15:08 -05:00
|
|
|
|
2012-03-10 19:05:43 -05:00
|
|
|
/******************* End: Configuration *************************/
|
2012-02-24 16:15:08 -05:00
|
|
|
|
2012-03-10 19:05:43 -05:00
|
|
|
/****************** Start: Notifications from event runner ***************/
|
2012-02-24 16:15:08 -05:00
|
|
|
|
|
|
|
/*!
|
2012-03-10 19:05:43 -05:00
|
|
|
* This is called by event runner when a group or groups \n
|
|
|
|
* have been updated or newly arrived
|
|
|
|
* @param grpId ids of groups that have changed or newly arrived
|
2012-02-24 16:15:08 -05:00
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
virtual void notifyGroupChanged(std::list<std::string> grpIds);
|
2012-03-10 19:05:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* This is called by event runner when a msg or msg \n
|
|
|
|
* have been updated or newly arrived
|
|
|
|
* @param msgId ids of msgs that have changed or newly arrived
|
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
virtual void notifyMsgChanged(std::list<std::string> msgId);
|
2012-03-10 19:05:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
/****************** End: Notifications from event runner ***************/
|
|
|
|
|
|
|
|
// Users can either search groups or messages
|
|
|
|
|
2012-02-24 16:15:08 -05:00
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
/* Generic Lists */
|
|
|
|
bool getGroupList(const uint32_t &token, std::list<std::string> &groupIds);
|
|
|
|
bool getMsgList(const uint32_t &token, std::list<std::string> &msgIds);
|
2012-03-10 19:05:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
/* Poll */
|
|
|
|
uint32_t requestStatus(const uint32_t token);
|
2012-03-10 19:05:43 -05:00
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
/* Cancel Request */
|
|
|
|
bool cancelRequest(const uint32_t &token);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
|
2012-02-24 16:15:08 -05:00
|
|
|
};
|
2012-01-18 18:20:53 -05:00
|
|
|
|
2012-01-11 18:01:29 -05:00
|
|
|
#endif // RSGXS_H
|