Merged branch v0.5-gxs-b1 into trunk (from -r 5351 -> 5995)

This brings a huge amount of goodness into the trunk,
but there is still a big chunk todo before it can be released.

 * GXS Backend.
 * GXS Services:
	- Identities.
	- Circles
	- Photos
	- Wiki
	- GxsForums
	- Posted.
 * SSH no-gui server.

See branch commits for more info.

To switch on GXS stuff, enable CONFIG += gxs
in both libretroshare.pro and retroshare-gui.pro



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5996 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-12-16 19:17:11 +00:00
commit 069b72e0b2
549 changed files with 111171 additions and 25579 deletions

View file

@ -1,42 +1,38 @@
To use this branch: To use this branch:
chekcout the last version of openpgp SDK: - get source code for libssh-0.5.2, unzip it, and create build directory (if needed)
# svn co svn://openpgp.nominet.org.uk/openpgpsdk/tags/openpgpsdk-0.9 openpgpsdk
# cd openpgpsdk
# ./configure --without-idea
# make
For the moment, the compilation is not workign on ubuntu # wget http://www.libssh.org/files/0.5/libssh-0.5.2.tar.gz
# tar zxvf libssh-0.5.2.tar.gz
# cd libssh-0.5.2
# mkdir build
# cd build
# cmake -DWITH_STATIC_LIB=ON ..
# make
# cd ../..
- build the google proto files
Work to do # cd rsctrl/src
========== # make
Put a 'x' when done. 1,2,3 means started/ongoing/almost finished.
Compilation Don't bother about python related errors.
00 [1] make sure the library compiles on linux
01 [ ] make sure the library compiles on windows
Project - go to retroshare-nogui, and compile it
02 [1] determine what's missing in OpenPGP-SDK
03 [3] make a separate layer in RS to handle PGP. AuthPGP is too close to libretroshare.
04 [1] write the new AuthGPG class
05 [ ] consider removing thread behaviour of AuthGPG
06 [ ] remove callback system and services from AuthGPG, since it's not useful anymore
07 [ ] make all RS use GPGIdType isntead of std::string.
Notes # cd ../../retroshare-nogui
===== # qmake
Questions to answer: # make
- do we rely on updates from openPGP-sdk ? Probably not. This code seems frozen.
- do we need an abstract layer for PGP handling in RS ?
- what new functionalities do we need in RS ?
* pgp keyring sharing/import/export
* identity import/export
Code struture - to use the SSH RS server:
- replace current AuthGPG (virtual class) by a class named GPGHandler,
that is responsible for signing, checking signatures, encrypting etc. # ssh-keygen -t rsa -f rs_ssh_host_rsa_key # this makes a RSA
- add a specific 8-bytes type for GPG Ids. Could be a uint64_t, or a # ./retroshare-nogui -G # generates a login+passwd hash for the RSA key used.
uchar[8] # ./retroshare-nogui -S 7022 -U[SSLid] -P [Passwd hash]
- to connect from a remote place to the server by SSH:
# ssh -T -p 7022 [user]@[host]
and use the command line interface to control your RS instance.

View file

@ -87,6 +87,8 @@ bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string b
mFns->bdPrintNodeId(std::cerr, id); mFns->bdPrintNodeId(std::cerr, id);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mLocalNetEnhancements = true;
} }
int bdNodeManager::stopDht() int bdNodeManager::stopDht()
@ -400,34 +402,39 @@ void bdNodeManager::iteration()
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* run a random search for ourselves, from own App DHT peer */
QueryRandomLocalNet();
/* This stuff is only important for "LocalNet based Features */
if (mLocalNetEnhancements)
{
/* run a random search for ourselves, from own App DHT peer */
QueryRandomLocalNet();
#define SEARCH_MAX_SIZE 10 #define SEARCH_MAX_SIZE 10
if (mBdNetworkSize < SEARCH_MAX_SIZE) if (mBdNetworkSize < SEARCH_MAX_SIZE)
{
#ifdef DEBUG_MGR
std::cerr << "Local Netsize: " << mBdNetworkSize << " to small...searching";
std::cerr << std::endl;
#endif
/* if the network size is very small */
SearchForLocalNet();
mSearchingDone = false;
}
else
{
if (!mSearchingDone)
{ {
mSearchingDone = true;
mSearchTS = now;
#ifdef DEBUG_MGR #ifdef DEBUG_MGR
std::cerr << "Completed LocalNet Search in : " << mSearchTS-mStartTS; std::cerr << "Local Netsize: " << mBdNetworkSize << " to small...searching";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* if the network size is very small */
SearchForLocalNet();
mSearchingDone = false;
}
else
{
if (!mSearchingDone)
{
mSearchingDone = true;
mSearchTS = now;
#ifdef DEBUG_MGR
std::cerr << "Completed LocalNet Search in : " << mSearchTS-mStartTS;
std::cerr << std::endl;
#endif
}
} }
} }
#ifdef DEBUG_MGR #ifdef DEBUG_MGR
std::cerr << "bdNodeManager::iteration(): REFRESH "; std::cerr << "bdNodeManager::iteration(): REFRESH ";
std::cerr << std::endl; std::cerr << std::endl;

View file

@ -187,6 +187,8 @@ void SearchForLocalNet();
bdBloom mBloomFilter; bdBloom mBloomFilter;
bool mLocalNetEnhancements;
/* future node functions */ /* future node functions */
//addPeerPing(foundId); //addPeerPing(foundId);
//clearPing(it->first); //clearPing(it->first);

View file

@ -6,11 +6,11 @@ LIBS = -L../lib -lbitdht -lpthread
EXEC : bdexample EXEC : bssdht
EGOBJ = bdhandler.o bdexample.o EGOBJ = bdhandler.o bssdht.o bootstrap_fn.o
bdexample: $(EGOBJ) bssdht: $(EGOBJ)
$(CXX) $(CXXFLAGS) -o bdexample $(EGOBJ) $(LIBS) $(CXX) $(CXXFLAGS) -o bssdht $(EGOBJ) $(LIBS)

View file

@ -1,42 +0,0 @@
#include "bitdht/bdiface.h"
#include "bitdht/bdstddht.h"
#include "bdhandler.h"
int main(int argc, char **argv)
{
/* startup dht : with a random id! */
bdNodeId ownId;
bdStdRandomNodeId(&ownId);
uint16_t port = 6775;
std::string appId = "exId";
std::string bootstrapfile = "bdboot.txt";
BitDhtHandler dht(&ownId, port, appId, bootstrapfile);
/* run your program */
while(1)
{
bdNodeId searchId;
bdStdRandomNodeId(&searchId);
dht.FindNode(&searchId);
sleep(180);
dht.DropNode(&searchId);
}
return 1;
}

View file

@ -29,8 +29,24 @@
#include <bitdht/bdstddht.h> #include <bitdht/bdstddht.h>
#include <string.h> #include <string.h>
#include <string.h>
#include "bdhandler.h" #include "bdhandler.h"
/****
* This example bitdht app is designed to perform a single shot DHT search.
* Ww want to minimise the dht work, and number of UDP packets sent.
*
* This means we need to add:
* - don't search for App network. (libbitdht option)
* - don't bother filling up Space. (libbitdht option)
* - Programmatically add bootstrap peers. (libbitdht option)
*
*/
/* This is a conversion callback class /* This is a conversion callback class
*/ */
@ -111,6 +127,11 @@ BitDhtHandler::BitDhtHandler(bdNodeId *ownId, uint16_t port, std::string appId,
mUdpBitDht->start(); /* starts up the bitdht thread */ mUdpBitDht->start(); /* starts up the bitdht thread */
/* setup best mode for quick search */
uint32_t dhtFlags = BITDHT_MODE_TRAFFIC_MED | BITDHT_MODE_RELAYSERVERS_IGNORED;
mUdpBitDht->setDhtMode(dhtFlags);
mUdpBitDht->setAttachMode(false);
/* switch on the dht too */ /* switch on the dht too */
mUdpBitDht->startDht(); mUdpBitDht->startDht();
} }
@ -163,8 +184,19 @@ bool BitDhtHandler::FindNode(bdNodeId *peerId)
bdStdPrintNodeId(std::cerr, peerId); bdStdPrintNodeId(std::cerr, peerId);
std::cerr << ")" << std::endl; std::cerr << ")" << std::endl;
BssResult res;
res.id.id = *peerId;
res.mode = BSS_SINGLE_SHOT;
res.status = 0;
{
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
mSearchNodes[*peerId] = res;
}
/* add in peer */ /* add in peer */
mUdpBitDht->addFindNode(peerId, BITDHT_QFLAGS_DO_IDLE); mUdpBitDht->addFindNode(peerId, BITDHT_QFLAGS_DISGUISE);
return true ; return true ;
} }
@ -179,10 +211,50 @@ bool BitDhtHandler::DropNode(bdNodeId *peerId)
/* remove in peer */ /* remove in peer */
mUdpBitDht->removeFindNode(peerId); mUdpBitDht->removeFindNode(peerId);
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
/* find the node from our list */
std::map<bdNodeId, BssResult>::iterator it;
it = mSearchNodes.find(*peerId);
if (it != mSearchNodes.end())
{
std::cerr << "BitDhtHandler::DropNode() Found NodeId, removing";
std::cerr << std::endl;
mSearchNodes.erase(it);
}
return true ; return true ;
} }
bool BitDhtHandler::SearchResult(bdId *id, uint32_t &status)
{
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
/* find the node from our list */
std::map<bdNodeId, BssResult>::iterator it;
it = mSearchNodes.find(id->id);
if (it != mSearchNodes.end())
{
if (it->second.status != 0)
{
std::cerr << "BitDhtHandler::SearchResults() Found Results";
std::cerr << std::endl;
status = it->second.status;
*id = it->second.id;
return true;
}
std::cerr << "BitDhtHandler::SearchResults() No Results Yet";
std::cerr << std::endl;
return false;
}
std::cerr << "BitDhtHandler::SearchResults() ERROR: No Search Entry";
std::cerr << std::endl;
return false;
}
/********************** Callback Functions **************************/ /********************** Callback Functions **************************/
@ -204,6 +276,20 @@ int BitDhtHandler::PeerCallback(const bdId *id, uint32_t status)
bdStdPrintId(std::cerr, id); bdStdPrintId(std::cerr, id);
std::cerr << std::endl; std::cerr << std::endl;
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
/* find the node from our list */
std::map<bdNodeId, BssResult>::iterator it;
it = mSearchNodes.find(id->id);
if (it == mSearchNodes.end())
{
std::cerr << "BitDhtHandler::PeerCallback() Unknown NodeId !!! ";
std::cerr << std::endl;
return 1;
}
it->second.status = status;
bool connect = false; bool connect = false;
switch(status) switch(status)
{ {
@ -212,6 +298,7 @@ int BitDhtHandler::PeerCallback(const bdId *id, uint32_t status)
std::cerr << "BitDhtHandler::PeerCallback() QUERY FAILURE ... do nothin "; std::cerr << "BitDhtHandler::PeerCallback() QUERY FAILURE ... do nothin ";
std::cerr << std::endl; std::cerr << std::endl;
break; break;
case BITDHT_MGR_QUERY_PEER_OFFLINE: case BITDHT_MGR_QUERY_PEER_OFFLINE:
@ -225,19 +312,19 @@ int BitDhtHandler::PeerCallback(const bdId *id, uint32_t status)
case BITDHT_MGR_QUERY_PEER_UNREACHABLE: case BITDHT_MGR_QUERY_PEER_UNREACHABLE:
/* do nothing */ /* do nothing */
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER UNREACHABLE ... flag? / do nothin "; std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER UNREACHABLE ... saving address ";
std::cerr << std::endl; std::cerr << std::endl;
it->second.id = *id;
break; break;
case BITDHT_MGR_QUERY_PEER_ONLINE: case BITDHT_MGR_QUERY_PEER_ONLINE:
/* do something */ /* do something */
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER ONLINE ... try udp connection"; std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER ONLINE ... saving address";
std::cerr << std::endl; std::cerr << std::endl;
connect = true; it->second.id = *id;
break; break;
} }
return 1; return 1;

View file

@ -37,6 +37,18 @@
/*** This class can be overloaded to use the XXXXCallback() Functions *****/ /*** This class can be overloaded to use the XXXXCallback() Functions *****/
class BitDhtIntCallback; class BitDhtIntCallback;
class BssResult
{
public:
bdId id;
uint32_t mode; // single shot
uint32_t status; // SEARCHING, FAILURE, FOUND, MULTIPLE HITS.
};
#define BSS_SINGLE_SHOT 0x0001
class BitDhtHandler class BitDhtHandler
{ {
@ -58,12 +70,17 @@ virtual int NodeCallback(const bdId *id, uint32_t peerflags);
virtual int PeerCallback(const bdId *id, uint32_t status); virtual int PeerCallback(const bdId *id, uint32_t status);
virtual int ValueCallback(const bdNodeId *id, std::string key, uint32_t status); virtual int ValueCallback(const bdNodeId *id, std::string key, uint32_t status);
bool SearchResult(bdId *id, uint32_t &status);
private: private:
/* real DHT classes */ /* real DHT classes */
UdpStack *mStack; UdpStack *mStack;
UdpBitDht *mUdpBitDht; UdpBitDht *mUdpBitDht;
bdMutex resultsMtx; /* for all class data (below) */
std::map<bdNodeId, BssResult> mSearchNodes;
}; };

View file

@ -0,0 +1,60 @@
#include "bitdht/bdiface.h"
#include "bitdht/bdstddht.h"
#include "bdhandler.h"
#include "bootstrap_fn.h"
bool bdSingleShotFindPeer(const std::string bootstrapfile, const std::string peerId, std::string &peer_ip, uint16_t &peer_port)
{
/* startup dht : with a random id! */
bdNodeId ownId;
bdStdRandomNodeId(&ownId);
uint16_t port = 6775;
std::string appId = "bsId";
BitDhtHandler dht(&ownId, port, appId, bootstrapfile);
/* install search node */
bdNodeId searchId;
bdStdRandomNodeId(&searchId);
std::cerr << "bssdht: searching for Id: ";
bdStdPrintNodeId(std::cerr, &searchId);
std::cerr << std::endl;
dht.FindNode(&searchId);
/* run your program */
bdId resultId;
uint32_t status;
resultId.id = searchId;
while(false == dht.SearchResult(&resultId, status))
{
sleep(10);
}
std::cerr << "bdSingleShotFindPeer(): Found Result:" << std::endl;
std::cerr << "\tId: ";
bdStdPrintId(std::cerr, &resultId);
std::cerr << std::endl;
std::cerr << "\tstatus: " << status;
std::cerr << std::endl;
dht.shutdown();
return true;
}

View file

@ -0,0 +1,17 @@
#include <string>
#include <inttypes.h>
/* NOTE. At the moment only the bootstrapfile is actually used.
* peerId is ignored (a random peerId is searched for). ip & port are not filled in either.
*
* This is mainly to finish testing.
*
* Once the best form of the return functions is decided (ipv4 structure, or strings).
* this can be finished off.
*
*/
bool bdSingleShotFindPeer(const std::string bootstrapfile, const std::string peerId, std::string &ip, uint16_t &port);

View file

@ -0,0 +1,31 @@
#include "bootstrap_fn.h"
#include <iostream>
#include <inttypes.h>
int main(int argc, char **argv)
{
std::string bootstrapfile = "bdboot.txt";
std::string peerId;
std::string ip;
uint16_t port;
std::cerr << "bssdht: starting up";
std::cerr << std::endl;
bdSingleShotFindPeer(bootstrapfile, peerId, ip, port);
std::cerr << "bssdht: finished";
std::cerr << std::endl;
return 1;
}

View file

@ -23,6 +23,7 @@
#ifdef WINDOWS_SYS #ifdef WINDOWS_SYS
#include "util/rsstring.h" #include "util/rsstring.h"
#include "util/rswin.h"
#endif #endif
#include "dbase/fimonitor.h" #include "dbase/fimonitor.h"

View file

@ -1,3 +1,7 @@
#ifdef WINDOWS_SYS
#include "util/rswin.h"
#endif // WINDOWS_SYS
#include "ftfileprovider.h" #include "ftfileprovider.h"
#include "ftchunkmap.h" #include "ftchunkmap.h"
@ -5,10 +9,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#ifdef WINDOWS_SYS
#include "util/rswin.h"
#endif // WINDOWS_SYS
/******** /********
* #define DEBUG_FT_FILE_PROVIDER 1 * #define DEBUG_FT_FILE_PROVIDER 1
* #define DEBUG_TRANSFERS 1 // TO GET TIMESTAMPS of DATA READING * #define DEBUG_TRANSFERS 1 // TO GET TIMESTAMPS of DATA READING

View file

@ -1,10 +1,30 @@
/* /*
* gxscoreserver.cpp * libretroshare/src/gxs: gxscoreserver.cc
*
* General Data service, interface for RetroShare.
*
* Copyright 2011-2011 by Evi-Parker Christopher
*
* 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".
* *
* Created on: 24 Jul 2012
* Author: crispy
*/ */
#include "gxscoreserver.h" #include "gxscoreserver.h"
GxsCoreServer::GxsCoreServer() GxsCoreServer::GxsCoreServer()
@ -28,10 +48,12 @@ void GxsCoreServer::run()
{ {
std::set<RsGxsService*>::iterator sit; std::set<RsGxsService*>::iterator sit;
double timeDelta = 0.2; double timeDelta = 0.02;
while(isRunning()) while(isRunning())
{ {
for(sit = mGxsServices.begin(); sit != mGxsServices.end(); sit++)
(*sit)->tick();
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
usleep((int) (timeDelta * 1000000)); usleep((int) (timeDelta * 1000000));
@ -39,9 +61,6 @@ void GxsCoreServer::run()
Sleep((int) (timeDelta * 1000)); Sleep((int) (timeDelta * 1000));
#endif #endif
for(sit = mGxsServices.begin(); sit != mGxsServices.end(); sit++)
(*sit)->tick();
} }
} }

View file

@ -1,17 +1,37 @@
/*
* gxscoreserver.h
*
* Created on: 24 Jul 2012
* Author: crispy
*/
#ifndef GXSCORESERVER_H_ #ifndef GXSCORESERVER_H_
#define GXSCORESERVER_H_ #define GXSCORESERVER_H_
/*
* libretroshare/src/gxs: gxscoreserver.h
*
* General Data service, interface for RetroShare.
*
* Copyright 2011-2011 by Evi-Parker Christopher
*
* 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".
*
*/
#include "util/rsthreads.h" #include "util/rsthreads.h"
#include "gxs/rsgxs.h" #include "gxs/rsgxs.h"
class GxsCoreServer : RsThread { class GxsCoreServer : public RsThread
{
public: public:
GxsCoreServer(); GxsCoreServer();
~GxsCoreServer(); ~GxsCoreServer();

View file

@ -0,0 +1,400 @@
/*
* libretroshare/src/gxs: gxssecurity.cc
*
*
* Copyright 2008-2010 by Robert Fernie
* 2011-2012 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".
*
*/
#include "gxssecurity.h"
#include "pqi/authgpg.h"
#include "retroshare/rspeers.h"
#define GXS_SECURITY_DEBUG
GxsSecurity::GxsSecurity()
{
}
GxsSecurity::~GxsSecurity()
{
}
RSA *GxsSecurity::extractPublicKey(RsTlvSecurityKey& key)
{
const unsigned char *keyptr = (const unsigned char *) key.keyData.bin_data;
long keylen = key.keyData.bin_len;
/* extract admin key */
RSA *rsakey = d2i_RSAPublicKey(NULL, &(keyptr), keylen);
return rsakey;
}
bool GxsSecurity::getSignature(char* data, uint32_t data_len, RsTlvSecurityKey* privKey, RsTlvKeySignature& sign)
{
RSA* rsa_pub = extractPrivateKey(*privKey);
EVP_PKEY *key_pub = EVP_PKEY_new();
EVP_PKEY_assign_RSA(key_pub, rsa_pub);
/* calc and check signature */
EVP_MD_CTX *mdctx = EVP_MD_CTX_create();
bool ok = EVP_SignInit(mdctx, EVP_sha1()) == 1;
ok &= EVP_SignUpdate(mdctx, data, data_len) == 1;
unsigned int siglen = EVP_PKEY_size(key_pub);
unsigned char sigbuf[siglen];
ok &= EVP_SignFinal(mdctx, sigbuf, &siglen, key_pub) == 1;
// clean up
EVP_MD_CTX_destroy(mdctx);
EVP_PKEY_free(key_pub);
sign.signData.setBinData(sigbuf, siglen);
sign.keyId = privKey->keyId;
return ok;
}
bool GxsSecurity::validateNxsMsg(RsNxsMsg& msg, RsTlvKeySignature& sign, RsTlvSecurityKey& key)
{
#ifdef GXS_SECURITY_DEBUG
std::cerr << "GxsSecurity::validateNxsMsg()";
std::cerr << std::endl;
std::cerr << "RsNxsMsg :";
std::cerr << std::endl;
msg.print(std::cerr, 10);
std::cerr << std::endl;
#endif
RsGxsMsgMetaData& msgMeta = *(msg.metaData);
// /********************* check signature *******************/
/* check signature timeperiod */
if ((msgMeta.mPublishTs < key.startTS) ||
(msgMeta.mPublishTs > key.endTS))
{
#ifdef GXS_SECURITY_DEBUG
std::cerr << " GxsSecurity::validateNxsMsg() TS out of range";
std::cerr << std::endl;
#endif
return false;
}
/* decode key */
const unsigned char *keyptr = (const unsigned char *) key.keyData.bin_data;
long keylen = key.keyData.bin_len;
unsigned int siglen = sign.signData.bin_len;
unsigned char *sigbuf = (unsigned char *) sign.signData.bin_data;
#ifdef DISTRIB_DEBUG
std::cerr << "GxsSecurity::validateNxsMsg() Decode Key";
std::cerr << " keylen: " << keylen << " siglen: " << siglen;
std::cerr << std::endl;
#endif
/* extract admin key */
RSA *rsakey = d2i_RSAPublicKey(NULL, &(keyptr), keylen);
if (!rsakey)
{
#ifdef GXS_SECURITY_DEBUG
std::cerr << "GxsSecurity::validateNxsMsg()";
std::cerr << " Invalid RSA Key";
std::cerr << std::endl;
key.print(std::cerr, 10);
#endif
}
RsTlvKeySignatureSet signSet = msgMeta.signSet;
msgMeta.signSet.TlvClear();
uint32_t metaDataLen = msgMeta.serial_size();
uint32_t allMsgDataLen = metaDataLen + msg.msg.bin_len;
char* metaData = new char[metaDataLen];
char* allMsgData = new char[allMsgDataLen]; // msgData + metaData
msgMeta.serialise(metaData, &metaDataLen);
// copy msg data and meta in allmsgData buffer
memcpy(allMsgData, msg.msg.bin_data, msg.msg.bin_len);
memcpy(allMsgData+(msg.msg.bin_len), metaData, metaDataLen);
EVP_PKEY *signKey = EVP_PKEY_new();
EVP_PKEY_assign_RSA(signKey, rsakey);
/* calc and check signature */
EVP_MD_CTX *mdctx = EVP_MD_CTX_create();
EVP_VerifyInit(mdctx, EVP_sha1());
EVP_VerifyUpdate(mdctx, allMsgData, allMsgDataLen);
int signOk = EVP_VerifyFinal(mdctx, sigbuf, siglen, signKey);
/* clean up */
EVP_PKEY_free(signKey);
EVP_MD_CTX_destroy(mdctx);
if (signOk == 1)
{
#ifdef GXS_SECURITY_DEBUG
std::cerr << "GxsSecurity::validateNxsMsg() Signature OK";
std::cerr << std::endl;
#endif
return true;
}
#ifdef GXS_SECURITY_DEBUG
std::cerr << "GxsSecurity::validateNxsMsg() Signature invalid";
std::cerr << std::endl;
#endif
return false;
}
std::string GxsSecurity::getBinDataSign(void *data, int len)
{
unsigned char *tmp = (unsigned char *) data;
// copy first CERTSIGNLEN bytes...
if (len > CERTSIGNLEN)
{
len = CERTSIGNLEN;
}
std::string id;
for(uint32_t i = 0; i < CERTSIGNLEN; i++)
{
rs_sprintf_append(id, "%02x", (uint16_t) (((uint8_t *) (tmp))[i]));
}
return id;
}
bool GxsSecurity::encrypt(void *& out, int & outlen, const void *in, int inlen, EVP_PKEY *privateKey)
{
#ifdef DISTRIB_DEBUG
std::cerr << "GxsSecurity::encrypt() " << std::endl;
#endif
RSA *rsa_publish_pub = NULL;
EVP_PKEY *public_key = NULL;
RSA* rsa_publish = EVP_PKEY_get1_RSA(privateKey);
rsa_publish_pub = RSAPublicKey_dup(rsa_publish);
if(rsa_publish_pub != NULL){
public_key = EVP_PKEY_new();
EVP_PKEY_assign_RSA(public_key, rsa_publish_pub);
}else{
#ifdef DISTRIB_DEBUG
std::cerr << "GxsSecurity(): Could not generate publish key " << grpId
<< std::endl;
#endif
return false;
}
EVP_CIPHER_CTX ctx;
int eklen, net_ekl;
unsigned char *ek;
unsigned char iv[EVP_MAX_IV_LENGTH];
EVP_CIPHER_CTX_init(&ctx);
int out_currOffset = 0;
int out_offset = 0;
int max_evp_key_size = EVP_PKEY_size(public_key);
ek = (unsigned char*)malloc(max_evp_key_size);
const EVP_CIPHER *cipher = EVP_aes_128_cbc();
int cipher_block_size = EVP_CIPHER_block_size(cipher);
int size_net_ekl = sizeof(net_ekl);
int max_outlen = inlen + cipher_block_size + EVP_MAX_IV_LENGTH + max_evp_key_size + size_net_ekl;
// intialize context and send store encrypted cipher in ek
if(!EVP_SealInit(&ctx, EVP_aes_128_cbc(), &ek, &eklen, iv, &public_key, 1)) return false;
// now assign memory to out accounting for data, and cipher block size, key length, and key length val
out = new unsigned char[inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH];
net_ekl = htonl(eklen);
memcpy((unsigned char*)out + out_offset, &net_ekl, size_net_ekl);
out_offset += size_net_ekl;
memcpy((unsigned char*)out + out_offset, ek, eklen);
out_offset += eklen;
memcpy((unsigned char*)out + out_offset, iv, EVP_MAX_IV_LENGTH);
out_offset += EVP_MAX_IV_LENGTH;
// now encrypt actual data
if(!EVP_SealUpdate(&ctx, (unsigned char*) out + out_offset, &out_currOffset, (unsigned char*) in, inlen)) return false;
// move along to partial block space
out_offset += out_currOffset;
// add padding
if(!EVP_SealFinal(&ctx, (unsigned char*) out + out_offset, &out_currOffset)) return false;
// move to end
out_offset += out_currOffset;
// make sure offset has not gone passed valid memory bounds
if(out_offset > max_outlen) return false;
// free encrypted key data
free(ek);
outlen = out_offset;
return true;
delete[] ek;
#ifdef DISTRIB_DEBUG
std::cerr << "GxsSecurity::encrypt() finished with outlen : " << outlen << std::endl;
#endif
return true;
}
bool GxsSecurity::decrypt(void *& out, int & outlen, const void *in, int inlen, EVP_PKEY *privateKey)
{
#ifdef DISTRIB_DEBUG
std::cerr << "GxsSecurity::decrypt() " << std::endl;
#endif
EVP_CIPHER_CTX ctx;
int eklen = 0, net_ekl = 0;
unsigned char *ek = NULL;
unsigned char iv[EVP_MAX_IV_LENGTH];
ek = (unsigned char*)malloc(EVP_PKEY_size(privateKey));
EVP_CIPHER_CTX_init(&ctx);
int in_offset = 0, out_currOffset = 0;
int size_net_ekl = sizeof(net_ekl);
memcpy(&net_ekl, (unsigned char*)in, size_net_ekl);
eklen = ntohl(net_ekl);
in_offset += size_net_ekl;
memcpy(ek, (unsigned char*)in + in_offset, eklen);
in_offset += eklen;
memcpy(iv, (unsigned char*)in + in_offset, EVP_MAX_IV_LENGTH);
in_offset += EVP_MAX_IV_LENGTH;
const EVP_CIPHER* cipher = EVP_aes_128_cbc();
if(!EVP_OpenInit(&ctx, cipher, ek, eklen, iv, privateKey)) return false;
out = new unsigned char[inlen - in_offset];
if(!EVP_OpenUpdate(&ctx, (unsigned char*) out, &out_currOffset, (unsigned char*)in + in_offset, inlen - in_offset)) return false;
in_offset += out_currOffset;
outlen += out_currOffset;
if(!EVP_OpenFinal(&ctx, (unsigned char*)out + out_currOffset, &out_currOffset)) return false;
outlen += out_currOffset;
free(ek);
return true;
}
std::string GxsSecurity::getRsaKeySign(RSA *pubkey)
{
int len = BN_num_bytes(pubkey -> n);
unsigned char tmp[len];
BN_bn2bin(pubkey -> n, tmp);
// copy first CERTSIGNLEN bytes...
if (len > CERTSIGNLEN)
{
len = CERTSIGNLEN;
}
std::string id;
for(uint32_t i = 0; i < CERTSIGNLEN; i++)
{
rs_sprintf_append(id, "%02x", (uint16_t) (((uint8_t *) (tmp))[i]));
}
return id;
}
bool GxsSecurity::validateNxsGrp(RsNxsGrp *newGrp, RsTlvKeySignature& sign, RsTlvSecurityKey& key)
{
return false;
}
void GxsSecurity::setRSAPublicKey(RsTlvSecurityKey & key, RSA *rsa_pub)
{
unsigned char data[10240]; /* more than enough space */
unsigned char *ptr = data;
int reqspace = i2d_RSAPublicKey(rsa_pub, &ptr);
key.keyData.setBinData(data, reqspace);
std::string keyId = getRsaKeySign(rsa_pub);
key.keyId = keyId;
}
void GxsSecurity::setRSAPrivateKey(RsTlvSecurityKey & key, RSA *rsa_priv)
{
unsigned char data[10240]; /* more than enough space */
unsigned char *ptr = data;
int reqspace = i2d_RSAPrivateKey(rsa_priv, &ptr);
key.keyData.setBinData(data, reqspace);
std::string keyId = getRsaKeySign(rsa_priv);
key.keyId = keyId;
}
RSA *GxsSecurity::extractPrivateKey(RsTlvSecurityKey & key)
{
const unsigned char *keyptr = (const unsigned char *) key.keyData.bin_data;
long keylen = key.keyData.bin_len;
/* extract admin key */
RSA *rsakey = d2i_RSAPrivateKey(NULL, &(keyptr), keylen);
return rsakey;
}

View file

@ -0,0 +1,145 @@
#ifndef GXSSECURITY_H
#define GXSSECURITY_H
/*
* libretroshare/src/gxs: gxssecurity.h
*
* Security functions for Gxs
*
* Copyright 2008-2010 by Robert Fernie
* 2011-2012 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".
*
*/
#include "serialiser/rstlvkeys.h"
#include "serialiser/rsnxsitems.h"
#include <openssl/ssl.h>
#include <openssl/evp.h>
/*!
* This contains functionality for performing security
* operations needed to validate data received in RsGenExchange
* Also has routine for creating security objects around msgs and groups
*/
class GxsSecurity {
public:
GxsSecurity();
~GxsSecurity();
/*!
* extracts the public key from an RsTlvSecurityKey
* @param key RsTlvSecurityKey to extract public RSA key from
* @return pointer to the public RSA key if successful, null otherwise
*/
static RSA *extractPublicKey(RsTlvSecurityKey &key);
/*!
* extracts the public key from an RsTlvSecurityKey
* @param key RsTlvSecurityKey to extract private RSA key from
* @return pointer to the private RSA key if successful, null otherwise
*/
static RSA *extractPrivateKey(RsTlvSecurityKey &key);
/*!
* stores the rsa public key in a RsTlvSecurityKey
* @param key RsTlvSecurityKey to store the public rsa key in
* @param rsa_pub
*/
static void setRSAPublicKey(RsTlvSecurityKey &key, RSA *rsa_pub);
/*!
* stores the rsa private key in a RsTlvSecurityKey
* @param key stores the rsa private key in a RsTlvSecurityKey
* @param rsa_priv the rsa private key to store
*/
static void setRSAPrivateKey(RsTlvSecurityKey &key, RSA *rsa_priv);
/*!
* extracts signature from RSA key
* @param pubkey
* @return signature of RSA key in hex format
*/
static std::string getRsaKeySign(RSA *pubkey);
/*!
* extracts the first CERTSIGNLEN bytes of signature and stores it in a string
* in hex format
* @param data signature
* @param len the length of the signature data
* @return returns the first CERTSIGNLEN of the signature as a string
*/
static std::string getBinDataSign(void *data, int len);
/*!
* Encrypts data using envelope encryption (taken from open ssl's evp_sealinit )
* only full publish key holders can encrypt data for given group
*@param out
*@param outlen
*@param in
*@param inlen
*/
static bool encrypt(void *&out, int &outlen, const void *in, int inlen, EVP_PKEY *privateKey);
/**
* Decrypts data using evelope decryption (taken from open ssl's evp_sealinit )
* only full publish key holders can decrypt data for a group
* @param out where decrypted data is written to
* @param outlen
* @param in
* @param inlen
* @return false if encryption failed
*/
static bool decrypt(void *&out, int &outlen, const void *in, int inlen, EVP_PKEY *privateKey);
/*!
* uses grp signature to check if group has been
* tampered with
* @param newGrp the Nxs group to be validated
* @param sign the signature to validdate against
* @param key the public key to use to check signature
* @return true if group valid false otherwise
*/
static bool validateNxsGrp(RsNxsGrp *newGrp, RsTlvKeySignature& sign, RsTlvSecurityKey& key);
/*!
* Validate a msg's signature using the given public key
* @param msg the Nxs message to be validated
* @param sign the signature to validdate against
* @param key the public key to use to check signature
* @return false if verfication of signature is not passed
*/
static bool validateNxsMsg(RsNxsMsg& msg, RsTlvKeySignature& sign, RsTlvSecurityKey& key);
/*!
* @param data data to be signed
* @param data_len length of data to be signed
* @param privKey private key to used to make signature
* @param sign the signature is stored here
* @return false if signature creation failed, true is signature created
*/
static bool getSignature(char* data, uint32_t data_len, RsTlvSecurityKey* privKey, RsTlvKeySignature& sign);
};
#endif // GXSSECURITY_H

View file

@ -0,0 +1,95 @@
/*
* libretroshare/src/gxs gxstokenqueue.cc
*
* Gxs Support for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* 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.1 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".
*
*/
#include "gxs/gxstokenqueue.h"
bool GxsTokenQueue::queueRequest(uint32_t token, uint32_t req_type)
{
RsStackMutex stack(mQueueMtx); /********** STACK LOCKED MTX ******/
mQueue.push_back(GxsTokenQueueItem(token, req_type));
return true;
}
void GxsTokenQueue::checkRequests()
{
{
RsStackMutex stack(mQueueMtx); /********** STACK LOCKED MTX ******/
if (mQueue.empty())
{
return;
}
}
// Must check all, and move to a different list - for reentrant / good mutex behaviour.
std::list<GxsTokenQueueItem> toload;
std::list<GxsTokenQueueItem>::iterator it;
bool stuffToLoad = false;
{
RsStackMutex stack(mQueueMtx); /********** STACK LOCKED MTX ******/
for(it = mQueue.begin(); it != mQueue.end();)
{
uint32_t token = it->mToken;
uint32_t status = mGenExchange->getTokenService()->requestStatus(token);
if (status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
{
toload.push_back(*it);
it = mQueue.erase(it);
stuffToLoad = true;
}
else if (status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
{
// maybe we should do alternative callback?
std::cerr << "GxsTokenQueue::checkRequests() ERROR Request Failed: " << token;
std::cerr << std::endl;
it = mQueue.erase(it);
}
else
{
it++;
}
}
}
if (stuffToLoad)
{
for(it = toload.begin(); it != toload.end(); it++)
{
handleResponse(it->mToken, it->mReqType);
}
}
}
// This must be overloaded to complete the functionality.
void GxsTokenQueue::handleResponse(uint32_t token, uint32_t req_type)
{
std::cerr << "GxsTokenQueue::handleResponse(" << token << "," << req_type << ") ERROR: NOT HANDLED";
std::cerr << std::endl;
}

View file

@ -0,0 +1,73 @@
#ifndef R_GXS_TOKEN_QUEUE_H
#define R_GXS_TOKEN_QUEUE_H
/*
* libretroshare/src/gxs gxstokenqueue.h
*
* Gxs Support for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* 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.1 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".
*
*/
#include "gxs/rsgenexchange.h"
#include "util/rsthreads.h"
/*
*
* A little helper class, to manage callbacks from requests
*
*/
class GxsTokenQueueItem
{
public:
GxsTokenQueueItem(const uint32_t token, const uint32_t req_type)
:mToken(token),mReqType(req_type) { return; }
GxsTokenQueueItem(): mToken(0), mReqType(0) { return; }
uint32_t mToken;
uint32_t mReqType;
};
class GxsTokenQueue
{
public:
GxsTokenQueue(RsGenExchange *gxs)
:mGenExchange(gxs), mQueueMtx("GxsTokenQueueMtx") { return; }
bool queueRequest(uint32_t token, uint32_t req_type);
void checkRequests(); // must be called by
protected:
// This must be overloaded to complete the functionality.
virtual void handleResponse(uint32_t token, uint32_t req_type);
private:
RsGenExchange *mGenExchange;
RsMutex mQueueMtx;
std::list<GxsTokenQueueItem> mQueue;
};
#endif //R_GXS_TOKEN_QUEUE_H

View file

@ -1,3 +1,30 @@
/*
* libretroshare/src/gxs: rsdataservice.cc
*
* Data Access, interface for RetroShare.
*
* Copyright 2011-2011 by Evi-Parker Christopher
*
* 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".
*
*/
#include <fstream> #include <fstream>
#include "rsdataservice.h" #include "rsdataservice.h"
@ -13,16 +40,21 @@
#define KEY_NXS_IDENTITY std::string("identity") #define KEY_NXS_IDENTITY std::string("identity")
#define KEY_GRP_ID std::string("grpId") #define KEY_GRP_ID std::string("grpId")
#define KEY_ORIG_GRP_ID std::string("origGrpId") #define KEY_ORIG_GRP_ID std::string("origGrpId")
#define KEY_IDENTITY_SIGN std::string("idSign") #define KEY_SIGN_SET std::string("signSet")
#define KEY_TIME_STAMP std::string("timeStamp") #define KEY_TIME_STAMP std::string("timeStamp")
#define KEY_NXS_FLAGS std::string("flags") #define KEY_NXS_FLAGS std::string("flags")
#define KEY_NXS_META std::string("meta") #define KEY_NXS_META std::string("meta")
#define KEY_NXS_SERV_STRING std::string("serv_str")
// grp table columns // grp table columns
#define KEY_ADMIN_SIGN std::string("adminSign")
#define KEY_KEY_SET std::string("keySet") #define KEY_KEY_SET std::string("keySet")
#define KEY_GRP_NAME std::string("grpName") #define KEY_GRP_NAME std::string("grpName")
#define KEY_GRP_SIGN_FLAGS std::string("signFlags")
#define KEY_GRP_CIRCLE_ID std::string("circleId")
#define KEY_GRP_CIRCLE_TYPE std::string("circleType")
#define KEY_GRP_INTERNAL_CIRCLE std::string("internalCircle")
#define KEY_GRP_ORIGINATOR std::string("originator")
// grp local // grp local
#define KEY_GRP_SUBCR_FLAG std::string("subscribeFlag") #define KEY_GRP_SUBCR_FLAG std::string("subscribeFlag")
@ -33,7 +65,6 @@
// msg table columns // msg table columns
#define KEY_PUBLISH_SIGN std::string("publishSign")
#define KEY_MSG_ID std::string("msgId") #define KEY_MSG_ID std::string("msgId")
#define KEY_ORIG_MSG_ID std::string("origMsgId") #define KEY_ORIG_MSG_ID std::string("origMsgId")
#define KEY_MSG_PARENT_ID std::string("parentId") #define KEY_MSG_PARENT_ID std::string("parentId")
@ -61,47 +92,62 @@
// grp col numbers // grp col numbers
#define COL_ADMIN_SIGN 5 #define COL_KEY_SET 5
#define COL_KEY_SET 6 #define COL_GRP_SUBCR_FLAG 6
#define COL_GRP_SUBCR_FLAG 7 #define COL_GRP_POP 7
#define COL_GRP_POP 8 #define COL_MSG_COUNT 8
#define COL_MSG_COUNT 9 #define COL_GRP_STATUS 9
#define COL_GRP_STATUS 10 #define COL_GRP_NAME 10
#define COL_GRP_NAME 11 #define COL_GRP_LAST_POST 11
#define COL_GRP_LAST_POST 12 #define COL_ORIG_GRP_ID 12
#define COL_ORIG_GRP_ID 13 #define COL_GRP_SERV_STRING 13
#define COL_GRP_SIGN_FLAGS 14
#define COL_GRP_CIRCLE_ID 15
#define COL_GRP_CIRCL_TYPE 16
#define COL_GRP_INTERN_CIRCLE 17
#define COL_GRP_ORIGINATOR 18
// msg col numbers // msg col numbers
#define COL_PUBLISH_SIGN 5 #define COL_MSG_ID 5
#define COL_MSG_ID 6 #define COL_ORIG_MSG_ID 6
#define COL_ORIG_MSG_ID 7 #define COL_MSG_STATUS 7
#define COL_MSG_STATUS 8 #define COL_CHILD_TS 8
#define COL_CHILD_TS 9 #define COL_PARENT_ID 9
#define COL_PARENT_ID 10 #define COL_THREAD_ID 10
#define COL_THREAD_ID 11 #define COL_MSG_NAME 11
#define COL_MSG_NAME 12 #define COL_MSG_SERV_STRING 12
// generic meta shared col numbers // generic meta shared col numbers
#define COL_GRP_ID 0 #define COL_GRP_ID 0
#define COL_TIME_STAMP 1 #define COL_TIME_STAMP 1
#define COL_NXS_FLAGS 2 #define COL_NXS_FLAGS 2
#define COL_IDENTITY_SIGN 3 #define COL_SIGN_SET 3
#define COL_IDENTITY 4 #define COL_IDENTITY 4
#define RS_DATA_SERVICE_DEBUG #define RS_DATA_SERVICE_DEBUG
const std::string RsGeneralDataService::GRP_META_SERV_STRING = KEY_NXS_SERV_STRING;
const std::string RsGeneralDataService::GRP_META_STATUS = KEY_GRP_STATUS;
const std::string RsGeneralDataService::GRP_META_SUBSCRIBE_FLAG = KEY_GRP_SUBCR_FLAG;
const std::string RsGeneralDataService::MSG_META_SERV_STRING = KEY_NXS_SERV_STRING;
const std::string RsGeneralDataService::MSG_META_STATUS = KEY_MSG_STATUS;
RsDataService::RsDataService(const std::string &serviceDir, const std::string &dbName, uint16_t serviceType, RsDataService::RsDataService(const std::string &serviceDir, const std::string &dbName, uint16_t serviceType,
RsGxsSearchModule *mod) RsGxsSearchModule *mod)
: RsGeneralDataService(), mServiceDir(serviceDir), mDbName(mServiceDir + "/" + dbName), mServType(serviceType){ : RsGeneralDataService(), mServiceDir(serviceDir), mDbName(mServiceDir + "/" + dbName), mServType(serviceType),
mDbMutex("RsDataService"){
initialise(); initialise();
// for retrieving msg meta // for retrieving msg meta
msgMetaColumns.push_back(KEY_GRP_ID); msgMetaColumns.push_back(KEY_TIME_STAMP); msgMetaColumns.push_back(KEY_NXS_FLAGS); msgMetaColumns.push_back(KEY_GRP_ID); msgMetaColumns.push_back(KEY_TIME_STAMP); msgMetaColumns.push_back(KEY_NXS_FLAGS);
msgMetaColumns.push_back(KEY_IDENTITY_SIGN); msgMetaColumns.push_back(KEY_NXS_IDENTITY); msgMetaColumns.push_back(KEY_PUBLISH_SIGN); msgMetaColumns.push_back(KEY_SIGN_SET); msgMetaColumns.push_back(KEY_NXS_IDENTITY);
msgMetaColumns.push_back(KEY_MSG_ID); msgMetaColumns.push_back(KEY_ORIG_MSG_ID); msgMetaColumns.push_back(KEY_MSG_STATUS); msgMetaColumns.push_back(KEY_MSG_ID); msgMetaColumns.push_back(KEY_ORIG_MSG_ID); msgMetaColumns.push_back(KEY_MSG_STATUS);
msgMetaColumns.push_back(KEY_CHILD_TS); msgMetaColumns.push_back(KEY_MSG_PARENT_ID); msgMetaColumns.push_back(KEY_MSG_THREAD_ID); msgMetaColumns.push_back(KEY_CHILD_TS); msgMetaColumns.push_back(KEY_MSG_PARENT_ID); msgMetaColumns.push_back(KEY_MSG_THREAD_ID);
msgMetaColumns.push_back(KEY_MSG_NAME); msgMetaColumns.push_back(KEY_MSG_NAME); msgMetaColumns.push_back(KEY_NXS_SERV_STRING);
// for retrieving actual data // for retrieving actual data
msgColumns.push_back(KEY_GRP_ID); msgColumns.push_back(KEY_NXS_FILE); msgColumns.push_back(KEY_NXS_FILE_OFFSET); msgColumns.push_back(KEY_GRP_ID); msgColumns.push_back(KEY_NXS_FILE); msgColumns.push_back(KEY_NXS_FILE_OFFSET);
@ -109,10 +155,12 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
// for retrieving grp meta data // for retrieving grp meta data
grpMetaColumns.push_back(KEY_GRP_ID); grpMetaColumns.push_back(KEY_TIME_STAMP); grpMetaColumns.push_back(KEY_NXS_FLAGS); grpMetaColumns.push_back(KEY_GRP_ID); grpMetaColumns.push_back(KEY_TIME_STAMP); grpMetaColumns.push_back(KEY_NXS_FLAGS);
grpMetaColumns.push_back(KEY_IDENTITY_SIGN); grpMetaColumns.push_back(KEY_NXS_IDENTITY); grpMetaColumns.push_back(KEY_ADMIN_SIGN); grpMetaColumns.push_back(KEY_SIGN_SET); grpMetaColumns.push_back(KEY_NXS_IDENTITY);
grpMetaColumns.push_back(KEY_KEY_SET); grpMetaColumns.push_back(KEY_GRP_SUBCR_FLAG); grpMetaColumns.push_back(KEY_GRP_POP); grpMetaColumns.push_back(KEY_KEY_SET); grpMetaColumns.push_back(KEY_GRP_SUBCR_FLAG); grpMetaColumns.push_back(KEY_GRP_POP);
grpMetaColumns.push_back(KEY_MSG_COUNT); grpMetaColumns.push_back(KEY_GRP_STATUS); grpMetaColumns.push_back(KEY_GRP_NAME); grpMetaColumns.push_back(KEY_MSG_COUNT); grpMetaColumns.push_back(KEY_GRP_STATUS); grpMetaColumns.push_back(KEY_GRP_NAME);
grpMetaColumns.push_back(KEY_GRP_LAST_POST); grpMetaColumns.push_back(KEY_ORIG_GRP_ID); grpMetaColumns.push_back(KEY_GRP_LAST_POST); grpMetaColumns.push_back(KEY_ORIG_GRP_ID); grpMetaColumns.push_back(KEY_NXS_SERV_STRING);
grpMetaColumns.push_back(KEY_GRP_SIGN_FLAGS); grpMetaColumns.push_back(KEY_GRP_CIRCLE_ID); grpMetaColumns.push_back(KEY_GRP_CIRCLE_TYPE);
grpMetaColumns.push_back(KEY_GRP_INTERNAL_CIRCLE); grpMetaColumns.push_back(KEY_GRP_ORIGINATOR);
// for retrieving actual grp data // for retrieving actual grp data
grpColumns.push_back(KEY_GRP_ID); grpColumns.push_back(KEY_NXS_FILE); grpColumns.push_back(KEY_NXS_FILE_OFFSET); grpColumns.push_back(KEY_GRP_ID); grpColumns.push_back(KEY_NXS_FILE); grpColumns.push_back(KEY_NXS_FILE_OFFSET);
@ -126,6 +174,8 @@ RsDataService::~RsDataService(){
void RsDataService::initialise(){ void RsDataService::initialise(){
RsStackMutex stack(mDbMutex);
// initialise database // initialise database
mDb = new RetroDb(mDbName, RetroDb::OPEN_READWRITE_CREATE); mDb = new RetroDb(mDbName, RetroDb::OPEN_READWRITE_CREATE);
@ -136,9 +186,8 @@ void RsDataService::initialise(){
KEY_NXS_FLAGS + " INT," + KEY_NXS_FLAGS + " INT," +
KEY_ORIG_MSG_ID + " TEXT," + KEY_ORIG_MSG_ID + " TEXT," +
KEY_TIME_STAMP + " INT," + KEY_TIME_STAMP + " INT," +
KEY_PUBLISH_SIGN + " BLOB," +
KEY_NXS_IDENTITY + " TEXT," + KEY_NXS_IDENTITY + " TEXT," +
KEY_IDENTITY_SIGN + " BLOB," + KEY_SIGN_SET + " BLOB," +
KEY_NXS_FILE + " TEXT,"+ KEY_NXS_FILE + " TEXT,"+
KEY_NXS_FILE_OFFSET + " INT," + KEY_NXS_FILE_OFFSET + " INT," +
KEY_MSG_STATUS + " INT," + KEY_MSG_STATUS + " INT," +
@ -147,13 +196,13 @@ void RsDataService::initialise(){
KEY_MSG_THREAD_ID + " TEXT," + KEY_MSG_THREAD_ID + " TEXT," +
KEY_MSG_PARENT_ID + " TEXT,"+ KEY_MSG_PARENT_ID + " TEXT,"+
KEY_MSG_NAME + " TEXT," + KEY_MSG_NAME + " TEXT," +
KEY_NXS_SERV_STRING + " TEXT," +
KEY_NXS_FILE_LEN + " INT);"); KEY_NXS_FILE_LEN + " INT);");
// create table for grp data // create table for grp data
mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" + mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" +
KEY_GRP_ID + " TEXT," + KEY_GRP_ID + " TEXT," +
KEY_TIME_STAMP + " INT," + KEY_TIME_STAMP + " INT," +
KEY_ADMIN_SIGN + " BLOB," + " BLOB," +
KEY_NXS_FILE + " TEXT," + KEY_NXS_FILE + " TEXT," +
KEY_NXS_FILE_OFFSET + " INT," + KEY_NXS_FILE_OFFSET + " INT," +
KEY_KEY_SET + " BLOB," + KEY_KEY_SET + " BLOB," +
@ -167,8 +216,14 @@ void RsDataService::initialise(){
KEY_GRP_STATUS + " INT," + KEY_GRP_STATUS + " INT," +
KEY_NXS_IDENTITY + " TEXT," + KEY_NXS_IDENTITY + " TEXT," +
KEY_ORIG_GRP_ID + " TEXT," + KEY_ORIG_GRP_ID + " TEXT," +
KEY_NXS_SERV_STRING + " TEXT," +
KEY_NXS_FLAGS + " INT," + KEY_NXS_FLAGS + " INT," +
KEY_IDENTITY_SIGN + " BLOB);"); KEY_GRP_SIGN_FLAGS + " INT," +
KEY_GRP_CIRCLE_ID + " TEXT," +
KEY_GRP_CIRCLE_TYPE + " INT," +
KEY_GRP_INTERNAL_CIRCLE + " TEXT," +
KEY_GRP_ORIGINATOR + " TEXT," +
KEY_SIGN_SET + " BLOB);");
} }
@ -193,22 +248,13 @@ RsGxsGrpMetaData* RsDataService::getGrpMeta(RetroCursor &c)
c.getString(COL_IDENTITY, grpMeta->mAuthorId); c.getString(COL_IDENTITY, grpMeta->mAuthorId);
c.getString(COL_GRP_NAME, grpMeta->mGroupName); c.getString(COL_GRP_NAME, grpMeta->mGroupName);
c.getString(COL_ORIG_GRP_ID, grpMeta->mOrigGrpId); c.getString(COL_ORIG_GRP_ID, grpMeta->mOrigGrpId);
c.getString(COL_GRP_SERV_STRING, grpMeta->mServiceString);
grpMeta->mSignFlags = c.getInt32(COL_GRP_SIGN_FLAGS);
grpMeta->mPublishTs = c.getInt32(COL_TIME_STAMP); grpMeta->mPublishTs = c.getInt32(COL_TIME_STAMP);
grpMeta->mGroupFlags = c.getInt32(COL_NXS_FLAGS); grpMeta->mGroupFlags = c.getInt32(COL_NXS_FLAGS);
// identity if any
if(!grpMeta->mAuthorId.empty() && ok){
offset = 0;
data = (char*)c.getData(COL_IDENTITY_SIGN, data_len);
if(data)
grpMeta->idSign.GetTlv(data, data_len, &offset);
}
offset = 0; offset = 0;
data = (char*)c.getData(COL_ADMIN_SIGN, data_len);
if(data)
grpMeta->adminSign.GetTlv(data, data_len, &offset);
offset = 0; data = NULL; data_len = 0; offset = 0; data = NULL; data_len = 0;
@ -224,6 +270,11 @@ RsGxsGrpMetaData* RsDataService::getGrpMeta(RetroCursor &c)
grpMeta->mLastPost = c.getInt32(COL_GRP_LAST_POST); grpMeta->mLastPost = c.getInt32(COL_GRP_LAST_POST);
grpMeta->mGroupStatus = c.getInt32(COL_GRP_STATUS); grpMeta->mGroupStatus = c.getInt32(COL_GRP_STATUS);
c.getString(COL_GRP_CIRCLE_ID, grpMeta->mCircleId);
grpMeta->mCircleType = c.getInt32(COL_GRP_CIRCL_TYPE);
c.getString(COL_GRP_INTERN_CIRCLE, grpMeta->mInternalCircle);
c.getString(COL_GRP_ORIGINATOR, grpMeta->mOriginator);
if(ok) if(ok)
return grpMeta; return grpMeta;
@ -307,26 +358,18 @@ RsGxsMsgMetaData* RsDataService::getMsgMeta(RetroCursor &c)
c.getString(COL_ORIG_MSG_ID, msgMeta->mOrigMsgId); c.getString(COL_ORIG_MSG_ID, msgMeta->mOrigMsgId);
c.getString(COL_IDENTITY, msgMeta->mAuthorId); c.getString(COL_IDENTITY, msgMeta->mAuthorId);
c.getString(COL_MSG_NAME, msgMeta->mMsgName); c.getString(COL_MSG_NAME, msgMeta->mMsgName);
c.getString(COL_MSG_SERV_STRING, msgMeta->mServiceString);
offset = 0;
data = (char*)c.getData(COL_SIGN_SET, data_len);
msgMeta->signSet.GetTlv(data, data_len, &offset);
if(!msgMeta->mAuthorId.empty()){
offset = 0;
data = (char*)c.getData(COL_IDENTITY_SIGN, data_len);
msgMeta->idSign.GetTlv(data, data_len, &offset);
}
msgMeta->mMsgFlags = c.getInt32(COL_NXS_FLAGS); msgMeta->mMsgFlags = c.getInt32(COL_NXS_FLAGS);
msgMeta->mPublishTs = c.getInt32(COL_TIME_STAMP); msgMeta->mPublishTs = c.getInt32(COL_TIME_STAMP);
offset = 0; data_len = 0; offset = 0; data_len = 0;
if(ok){
data = (char*)c.getData(COL_PUBLISH_SIGN, data_len);
if(data)
msgMeta->pubSign.GetTlv(data, data_len, &offset);
}
// thread and parent id // thread and parent id
c.getString(COL_THREAD_ID, msgMeta->mThreadId); c.getString(COL_THREAD_ID, msgMeta->mThreadId);
c.getString(COL_PARENT_ID, msgMeta->mParentId); c.getString(COL_PARENT_ID, msgMeta->mParentId);
@ -376,7 +419,7 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c)
if(ok){ if(ok){
char msg_data[data_len]; char* msg_data = new char[data_len];
std::ifstream istrm(msgFile.c_str(), std::ios::binary); std::ifstream istrm(msgFile.c_str(), std::ios::binary);
istrm.seekg(offset, std::ios::beg); istrm.seekg(offset, std::ios::beg);
istrm.read(msg_data, data_len); istrm.read(msg_data, data_len);
@ -384,6 +427,7 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c)
istrm.close(); istrm.close();
offset = 0; offset = 0;
ok &= msg->msg.GetTlv(msg_data, data_len, &offset); ok &= msg->msg.GetTlv(msg_data, data_len, &offset);
delete[] msg_data;
} }
if(ok) if(ok)
@ -396,6 +440,9 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c)
int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg) int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
{ {
RsStackMutex stack(mDbMutex);
std::map<RsNxsMsg*, RsGxsMsgMetaData* >::iterator mit = msg.begin(); std::map<RsNxsMsg*, RsGxsMsgMetaData* >::iterator mit = msg.begin();
// start a transaction // start a transaction
@ -419,20 +466,16 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
cv.put(KEY_NXS_FILE_LEN, (int32_t)msgPtr->msg.TlvSize()); cv.put(KEY_NXS_FILE_LEN, (int32_t)msgPtr->msg.TlvSize());
cv.put(KEY_MSG_ID, msgMetaPtr->mMsgId); cv.put(KEY_MSG_ID, msgMetaPtr->mMsgId);
cv.put(KEY_GRP_ID, msgMetaPtr->mGroupId); cv.put(KEY_GRP_ID, msgMetaPtr->mGroupId);
char pubSignData[msgMetaPtr->pubSign.TlvSize()]; cv.put(KEY_NXS_SERV_STRING, msgMetaPtr->mServiceString);
char signSetData[msgMetaPtr->signSet.TlvSize()];
offset = 0; offset = 0;
msgMetaPtr->pubSign.SetTlv(pubSignData, msgMetaPtr->pubSign.TlvSize(), &offset); msgMetaPtr->signSet.SetTlv(signSetData, msgMetaPtr->signSet.TlvSize(), &offset);
cv.put(KEY_PUBLISH_SIGN, msgMetaPtr->pubSign.TlvSize(), pubSignData); cv.put(KEY_SIGN_SET, msgMetaPtr->signSet.TlvSize(), signSetData);
cv.put(KEY_NXS_IDENTITY, msgMetaPtr->mAuthorId);
if(! (msgMetaPtr->mAuthorId.empty()) ){
char idSignData[msgMetaPtr->idSign.TlvSize()];
offset = 0;
msgMetaPtr->idSign.SetTlv(idSignData, msgMetaPtr->idSign.TlvSize(), &offset);
cv.put(KEY_IDENTITY_SIGN, msgMetaPtr->idSign.TlvSize(), idSignData);
cv.put(KEY_NXS_IDENTITY, msgMetaPtr->mAuthorId);
}
cv.put(KEY_NXS_FLAGS, (int32_t) msgMetaPtr->mMsgFlags); cv.put(KEY_NXS_FLAGS, (int32_t) msgMetaPtr->mMsgFlags);
cv.put(KEY_TIME_STAMP, (int32_t) msgMetaPtr->mPublishTs); cv.put(KEY_TIME_STAMP, (int32_t) msgMetaPtr->mPublishTs);
@ -451,27 +494,44 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
cv.put(KEY_CHILD_TS, (int32_t)msgMetaPtr->mChildTs); cv.put(KEY_CHILD_TS, (int32_t)msgMetaPtr->mChildTs);
offset = 0; offset = 0;
char msgData[msgPtr->msg.TlvSize()]; char* msgData = new char[msgPtr->msg.TlvSize()];
msgPtr->msg.SetTlv(msgData, msgPtr->msg.TlvSize(), &offset); msgPtr->msg.SetTlv(msgData, msgPtr->msg.TlvSize(), &offset);
ostrm.write(msgData, msgPtr->msg.TlvSize()); ostrm.write(msgData, msgPtr->msg.TlvSize());
ostrm.close(); ostrm.close();
delete[] msgData;
mDb->sqlInsert(MSG_TABLE_NAME, "", cv); mDb->sqlInsert(MSG_TABLE_NAME, "", cv);
} }
// finish transaction // finish transaction
return mDb->execSQL("COMMIT;"); bool ret = mDb->execSQL("COMMIT;");
for(mit = msg.begin(); mit != msg.end(); mit++)
{
//TODO: API encourages aliasing, remove this abomination
if(mit->second != mit->first->metaData)
delete mit->second;
delete mit->first;
;
}
return ret;
} }
int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp) int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
{ {
RsStackMutex stack(mDbMutex);
std::map<RsNxsGrp*, RsGxsGrpMetaData* >::iterator sit = grp.begin(); std::map<RsNxsGrp*, RsGxsGrpMetaData* >::iterator sit = grp.begin();
// begin transaction // begin transaction
mDb->execSQL("BEGIN;"); mDb->execSQL("BEGIN;");
for(; sit != grp.end(); sit++){ for(; sit != grp.end(); sit++)
{
RsNxsGrp* grpPtr = sit->first; RsNxsGrp* grpPtr = sit->first;
RsGxsGrpMetaData* grpMetaPtr = sit->second; RsGxsGrpMetaData* grpMetaPtr = sit->second;
@ -494,25 +554,19 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
cv.put(KEY_GRP_ID, grpPtr->grpId); cv.put(KEY_GRP_ID, grpPtr->grpId);
cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName); cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName);
cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId); cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId);
cv.put(KEY_NXS_SERV_STRING, grpMetaPtr->mServiceString);
cv.put(KEY_NXS_FLAGS, (int32_t)grpMetaPtr->mGroupFlags); cv.put(KEY_NXS_FLAGS, (int32_t)grpMetaPtr->mGroupFlags);
cv.put(KEY_TIME_STAMP, (int32_t)grpMetaPtr->mPublishTs); cv.put(KEY_TIME_STAMP, (int32_t)grpMetaPtr->mPublishTs);
cv.put(KEY_GRP_SIGN_FLAGS, (int32_t)grpMetaPtr->mSignFlags);
cv.put(KEY_GRP_CIRCLE_ID, grpMetaPtr->mCircleId);
cv.put(KEY_GRP_CIRCLE_TYPE, (int32_t)grpMetaPtr->mCircleType);
cv.put(KEY_GRP_INTERNAL_CIRCLE, grpMetaPtr->mInternalCircle);
cv.put(KEY_GRP_ORIGINATOR, grpMetaPtr->mOriginator);
if(! (grpMetaPtr->mAuthorId.empty()) ){ if(! (grpMetaPtr->mAuthorId.empty()) ){
cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId); cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId);
char idSignData[grpMetaPtr->idSign.TlvSize()];
offset = 0;
grpMetaPtr->idSign.SetTlv(idSignData, grpMetaPtr->idSign.TlvSize(), &offset);
cv.put(KEY_IDENTITY_SIGN, grpMetaPtr->idSign.TlvSize(), idSignData);
std::string wat(idSignData, grpMetaPtr->idSign.TlvSize());
std::cerr << wat << std::endl;
} }
char adminSignData[grpMetaPtr->adminSign.TlvSize()];
offset = 0;
grpMetaPtr->adminSign.SetTlv(adminSignData, grpMetaPtr->adminSign.TlvSize(), &offset);
cv.put(KEY_ADMIN_SIGN, grpMetaPtr->adminSign.TlvSize(), adminSignData);
offset = 0; offset = 0;
char keySetData[grpMetaPtr->keys.TlvSize()]; char keySetData[grpMetaPtr->keys.TlvSize()];
grpMetaPtr->keys.SetTlv(keySetData, grpMetaPtr->keys.TlvSize(), &offset); grpMetaPtr->keys.SetTlv(keySetData, grpMetaPtr->keys.TlvSize(), &offset);
@ -539,61 +593,91 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
mDb->sqlInsert(GRP_TABLE_NAME, "", cv); mDb->sqlInsert(GRP_TABLE_NAME, "", cv);
} }
// finish transaction // finish transaction
return mDb->execSQL("COMMIT;"); bool ret = mDb->execSQL("COMMIT;");
for(sit = grp.begin(); sit != grp.end(); sit++)
{
//TODO: API encourages aliasing, remove this abomination
if(sit->second != sit->first->metaData)
delete sit->second;
delete sit->first;
}
return ret;
} }
int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool withMeta, bool cache){ int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool withMeta, bool cache){
if(grp.empty()){ if(grp.empty()){
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "", ""); RsStackMutex stack(mDbMutex);
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "", "");
if(c) if(c)
{ {
std::vector<RsNxsGrp*> grps; std::vector<RsNxsGrp*> grps;
retrieveGroups(c, grps, withMeta); retrieveGroups(c, grps);
std::vector<RsNxsGrp*>::iterator vit = grps.begin(); std::vector<RsNxsGrp*>::iterator vit = grps.begin();
for(; vit != grps.end(); vit++) for(; vit != grps.end(); vit++)
{ {
grp[(*vit)->grpId] = *vit; grp[(*vit)->grpId] = *vit;
} }
delete c; delete c;
} }
}else{ }else{
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin(); RsStackMutex stack(mDbMutex);
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin();
for(; mit != grp.end(); mit++) for(; mit != grp.end(); mit++)
{ {
const std::string& grpId = mit->first; const std::string& grpId = mit->first;
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "grpId='" + grpId + "'", ""); RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "grpId='" + grpId + "'", "");
if(c) if(c)
{ {
std::vector<RsNxsGrp*> grps; std::vector<RsNxsGrp*> grps;
retrieveGroups(c, grps); retrieveGroups(c, grps);
if(!grps.empty()) if(!grps.empty())
{ {
RsNxsGrp* ng = grps.front(); RsNxsGrp* ng = grps.front();
grp[ng->grpId] = ng; grp[ng->grpId] = ng;
}else{ }else{
grp.erase(grpId); grp.erase(grpId);
} }
delete c; delete c;
} }
} }
} }
return 1; if(withMeta)
{
std::map<RsGxsGroupId, RsGxsGrpMetaData*> metaMap;
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin();
for(; mit != grp.end(); mit++)
metaMap.insert(std::make_pair(mit->first, (RsGxsGrpMetaData*)(NULL)));
retrieveGxsGrpMetaData(metaMap);
mit = grp.begin();
for(; mit != grp.end(); mit++)
{
RsNxsGrp* grpPtr = grp[mit->first];
grpPtr->metaData = metaMap[mit->first];
}
}
return 1;
} }
void RsDataService::retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps, bool withMeta){ void RsDataService::retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps){
if(c){ if(c){
bool valid = c->moveToFirst(); bool valid = c->moveToFirst();
@ -604,12 +688,6 @@ void RsDataService::retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps,
// only add the latest grp info // only add the latest grp info
if(g) if(g)
{ {
RsGxsGrpMetaData* meta;
if(withMeta)
meta = getGrpMeta(*c);
if(meta) g->metaData = meta;
grps.push_back(g); grps.push_back(g);
} }
valid = c->moveToNext(); valid = c->moveToNext();
@ -617,11 +695,13 @@ void RsDataService::retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps,
} }
} }
int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, bool cache) int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, bool cache, bool withMeta)
{ {
GxsMsgReq::const_iterator mit = reqIds.begin(); GxsMsgReq::const_iterator mit = reqIds.begin();
GxsMsgReq metaReqIds;// collects metaReqIds if needed
for(; mit != reqIds.end(); mit++) for(; mit != reqIds.end(); mit++)
{ {
@ -632,6 +712,9 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
std::vector<RsNxsMsg*> msgSet; std::vector<RsNxsMsg*> msgSet;
if(msgIdV.empty()){ if(msgIdV.empty()){
RsStackMutex stack(mDbMutex);
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId + "'", ""); RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId + "'", "");
if(c) if(c)
@ -645,6 +728,9 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
for(; sit!=msgIdV.end();sit++){ for(; sit!=msgIdV.end();sit++){
const std::string& msgId = *sit; const std::string& msgId = *sit;
RsStackMutex stack(mDbMutex);
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId
+ "' AND " + KEY_MSG_ID + "='" + msgId + "'", ""); + "' AND " + KEY_MSG_ID + "='" + msgId + "'", "");
@ -657,7 +743,75 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
msg[grpId] = msgSet; msg[grpId] = msgSet;
msgSet.clear(); msgSet.clear();
if(withMeta)
{
std::vector<RsGxsMessageId> msgIds;
std::vector<RsNxsMsg*>::iterator lit = msgSet.begin(),
lit_end = msgSet.end();
for(; lit != lit_end; lit++)
msgIds.push_back( (*lit)->msgId );
metaReqIds[grpId] = msgIds;
}
} }
// tres expensive !?
if(withMeta)
{
GxsMsgMetaResult metaResult;
// request with meta ids so there is no chance of
// a mem leak being left over
retrieveGxsMsgMetaData(metaReqIds, metaResult);
GxsMsgResult::iterator mit2 = msg.begin(), mit2_end = msg.end();
for(; mit2 != mit2_end; mit2++)
{
const RsGxsGroupId& grpId = mit2->first;
std::vector<RsNxsMsg*>& msgV = msg[grpId];
std::vector<RsNxsMsg*>::iterator lit = msgV.begin(),
lit_end = msgV.end();
// as retrieval only attempts to retrieve what was found this elimiates chance
// of a memory fault as all are assigned
for(; lit != lit_end; lit++)
{
std::vector<RsGxsMsgMetaData*>& msgMetaV = metaResult[grpId];
std::vector<RsGxsMsgMetaData*>::iterator meta_lit = msgMetaV.begin();
RsNxsMsg* msgPtr = *lit;
for(; meta_lit != msgMetaV.end(); )
{
RsGxsMsgMetaData* meta = *meta_lit;
if(meta->mMsgId == msgPtr->msgId)
{
msgPtr->metaData = meta;
meta_lit = msgMetaV.erase(meta_lit);
}else{
meta_lit++;
}
}
}
std::vector<RsGxsMsgMetaData*>& msgMetaV = metaResult[grpId];
std::vector<RsGxsMsgMetaData*>::iterator meta_lit;
// clean up just in case, should not go in here
for(meta_lit = msgMetaV.begin(); meta_lit !=
msgMetaV.end(); )
{
RsGxsMsgMetaData* meta = *meta_lit;
delete meta;
meta_lit = msgMetaV.erase(meta_lit);
}
}
}
return 1;
} }
void RsDataService::retrieveMessages(RetroCursor *c, std::vector<RsNxsMsg *> &msgs) void RsDataService::retrieveMessages(RetroCursor *c, std::vector<RsNxsMsg *> &msgs)
@ -668,8 +822,6 @@ void RsDataService::retrieveMessages(RetroCursor *c, std::vector<RsNxsMsg *> &ms
if(m){ if(m){
msgs.push_back(m);; msgs.push_back(m);;
}else{
delete m;
} }
valid = c->moveToNext(); valid = c->moveToNext();
@ -677,60 +829,122 @@ void RsDataService::retrieveMessages(RetroCursor *c, std::vector<RsNxsMsg *> &ms
return; return;
} }
int RsDataService::retrieveGxsMsgMetaData(const std::vector<std::string> &grpIds, GxsMsgMetaResult &msgMeta) int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaResult &msgMeta)
{ {
std::vector<std::string>::const_iterator vit = grpIds.begin();
for(; vit != grpIds.end(); vit++) RsStackMutex stack(mDbMutex);
GxsMsgReq::const_iterator mit = reqIds.begin();
for(; mit != reqIds.end(); mit++)
{ {
const std::string& grpId = *vit;
std::vector<RsGxsMsgMetaData*> meta; const std::string& grpId = mit->first;
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgMetaColumns, "", KEY_GRP_ID+ "='" + grpId + "'"); // if vector empty then request all messages
const std::vector<RsGxsMessageId>& msgIdV = mit->second;
std::vector<RsGxsMsgMetaData*> metaSet;
if(c) if(msgIdV.empty()){
{ RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgMetaColumns, KEY_GRP_ID+ "='" + grpId + "'", "");
bool valid = c->moveToFirst();
while(valid){
RsGxsMsgMetaData* m = getMsgMeta(*c);
if(m){ retrieveMsgMeta(c, metaSet);
meta.push_back(m);
}else{ }else{
delete m;
} // request each grp
valid = c->moveToNext(); std::vector<std::string>::const_iterator sit = msgIdV.begin();
for(; sit!=msgIdV.end();sit++){
const std::string& msgId = *sit;
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgMetaColumns, KEY_GRP_ID+ "='" + grpId
+ "' AND " + KEY_MSG_ID + "='" + msgId + "'", "");
retrieveMsgMeta(c, metaSet);
} }
msgMeta[grpId] = meta;
} }
delete c;
msgMeta[grpId] = metaSet;
} }
return 1; return 1;
} }
int RsDataService::retrieveGxsGrpMetaData(std::map<std::string, RsGxsGrpMetaData *>& grp) void RsDataService::retrieveMsgMeta(RetroCursor *c, std::vector<RsGxsMsgMetaData *> &msgMeta)
{ {
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "", "");
if(c) if(c)
{ {
bool valid = c->moveToFirst(); bool valid = c->moveToFirst();
while(valid){
RsGxsMsgMetaData* m = getMsgMeta(*c);
while(valid) if(m != NULL)
{ msgMeta.push_back(m);
RsGxsGrpMetaData* g = getGrpMeta(*c);
if(g)
{
grp[g->mGroupId] = g;
}
valid = c->moveToNext(); valid = c->moveToNext();
} }
delete c;
} }
delete c; }
int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaData *>& grp)
{
RsStackMutex stack(mDbMutex);
if(grp.empty()){
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "", "");
if(c)
{
bool valid = c->moveToFirst();
while(valid)
{
RsGxsGrpMetaData* g = getGrpMeta(*c);
if(g)
{
grp[g->mGroupId] = g;
}
valid = c->moveToNext();
}
delete c;
}
}else
{
std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin();
for(; mit != grp.end(); mit++)
{
const RsGxsGroupId& grpId = mit->first;
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "grpId='" + grpId + "'", "");
if(c)
{
bool valid = c->moveToFirst();
while(valid)
{
RsGxsGrpMetaData* g = getGrpMeta(*c);
if(g)
{
grp[g->mGroupId] = g;
}
valid = c->moveToNext();
}
delete c;
}
}
}
return 1; return 1;
} }
@ -748,6 +962,7 @@ int RsDataService::resetDataStore()
std::map<std::string, RsNxsGrp*>::iterator mit std::map<std::string, RsNxsGrp*>::iterator mit
= grps.begin(); = grps.begin();
// remove all grp msgs files from service dir // remove all grp msgs files from service dir
for(; mit != grps.end(); mit++){ for(; mit != grps.end(); mit++){
std::string file = mServiceDir + "/" + mit->first; std::string file = mServiceDir + "/" + mit->first;
@ -755,8 +970,11 @@ int RsDataService::resetDataStore()
remove(file.c_str()); // remove group file remove(file.c_str()); // remove group file
remove(msgFile.c_str()); // and remove messages file remove(msgFile.c_str()); // and remove messages file
} }
{
RsStackMutex stack(mDbMutex);
mDb->closeDb();
}
mDb->closeDb();
remove(mDbName.c_str()); // remove db file remove(mDbName.c_str()); // remove db file
// recreate database // recreate database
@ -771,18 +989,22 @@ int RsDataService::removeGroups(const std::vector<std::string> &grpIds)
return 0; return 0;
} }
int RsDataService::updateGroupMetaData(GrpLocMetaData *meta) int RsDataService::updateGroupMetaData(GrpLocMetaData &meta)
{ {
return 0; RsGxsGroupId& grpId = meta.grpId;
return mDb->sqlUpdate(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId + "'", meta.val) ? 1 : 0;
} }
int RsDataService::updateMessageMetaData(MsgLocMetaData *metaData) int RsDataService::updateMessageMetaData(MsgLocMetaData &metaData)
{ {
return 0; RsGxsGroupId& grpId = metaData.msgId.first;
RsGxsMessageId& msgId = metaData.msgId.second;
return mDb->sqlUpdate(MSG_TABLE_NAME, KEY_GRP_ID+ "='" + grpId
+ "' AND " + KEY_MSG_ID + "='" + msgId + "'", metaData.val) ? 1 : 0;
} }
int RsDataService::removeMsgs(const std::string grpId, const std::vector<std::string> &msgIds) int RsDataService::removeMsgs(const GxsMsgReq& msgIds)
{ {
return 0; return 0;
} }

View file

@ -1,6 +1,31 @@
#ifndef RSDATASERVICE_H #ifndef RSDATASERVICE_H
#define RSDATASERVICE_H #define RSDATASERVICE_H
/*
* libretroshare/src/gxs: rsdataservice.h
*
* General Data service, interface for RetroShare.
*
* Copyright 2011-2012 by Evi-Parker Christopher
*
* 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".
*
*/
#include "gxs/rsgds.h" #include "gxs/rsgds.h"
#include "util/retrodb.h" #include "util/retrodb.h"
@ -10,7 +35,7 @@ class RsDataService : public RsGeneralDataService
public: public:
RsDataService(const std::string& serviceDir, const std::string& dbName, uint16_t serviceType, RsGxsSearchModule* mod = NULL); RsDataService(const std::string& serviceDir, const std::string& dbName, uint16_t serviceType, RsGxsSearchModule* mod = NULL);
virtual ~RsDataService() ; virtual ~RsDataService();
/*! /*!
* Retrieves all msgs * Retrieves all msgs
@ -19,7 +44,7 @@ public:
* @param cache whether to store results of this retrieval in memory for faster later retrieval * @param cache whether to store results of this retrieval in memory for faster later retrieval
* @return error code * @return error code
*/ */
int retrieveNxsMsgs(const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache); int retrieveNxsMsgs(const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache, bool withMeta = false);
/*! /*!
* Retrieves groups, if empty, retrieves all grps, if map is not empty * Retrieves groups, if empty, retrieves all grps, if map is not empty
@ -36,7 +61,7 @@ public:
* @param cache whether to store retrieval in mem for faster later retrieval * @param cache whether to store retrieval in mem for faster later retrieval
* @return error code * @return error code
*/ */
int retrieveGxsGrpMetaData(std::map<std::string, RsGxsGrpMetaData*>& grp); int retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaData*>& grp);
/*! /*!
* Retrieves meta data of all groups stored (most current versions only) * Retrieves meta data of all groups stored (most current versions only)
@ -45,7 +70,7 @@ public:
* @param cache whether to store retrieval in mem for faster later retrieval * @param cache whether to store retrieval in mem for faster later retrieval
* @return error code * @return error code
*/ */
int retrieveGxsMsgMetaData(const std::vector<std::string>& grpIds, GxsMsgMetaResult& msgMeta); int retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaResult& msgMeta);
/*! /*!
* remove msgs in data store * remove msgs in data store
@ -53,14 +78,14 @@ public:
* @param msgIds ids of messages to be removed * @param msgIds ids of messages to be removed
* @return error code * @return error code
*/ */
int removeMsgs(const std::string grpId, const std::vector<std::string>& msgIds); int removeMsgs(const GxsMsgReq& msgIds);
/*! /*!
* remove groups in data store listed in grpIds param * remove groups in data store listed in grpIds param
* @param grpIds ids of groups to be removed * @param grpIds ids of groups to be removed
* @return error code * @return error code
*/ */
int removeGroups(const std::vector<std::string>& grpIds); int removeGroups(const std::vector<RsGxsGroupId>& grpIds);
/*! /*!
* @return the cache size set for this RsGeneralDataService in bytes * @return the cache size set for this RsGeneralDataService in bytes
@ -90,13 +115,13 @@ public:
* @param metaData The meta data item to update * @param metaData The meta data item to update
* @return error code * @return error code
*/ */
int updateMessageMetaData(MsgLocMetaData* metaData); int updateMessageMetaData(MsgLocMetaData& metaData);
/*! /*!
* @param metaData The meta data item to update * @param metaData The meta data item to update
* @return error code * @return error code
*/ */
int updateGroupMetaData(GrpLocMetaData* meta); int updateGroupMetaData(GrpLocMetaData& meta);
/*! /*!
@ -117,11 +142,18 @@ private:
void retrieveMessages(RetroCursor* c, std::vector<RsNxsMsg*>& msgs); void retrieveMessages(RetroCursor* c, std::vector<RsNxsMsg*>& msgs);
/*! /*!
* Retrieves all the msg results from a cursor * Retrieves all the grp results from a cursor
* @param c cursor to result set * @param c cursor to result set
* @param msgs messages retrieved from cursor are stored here * @param grps groups retrieved from cursor are stored here
*/ */
void retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps, bool withMeta = false); void retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps);
/*!
* Retrieves all the msg meta results from a cursor
* @param c cursor to result set
* @param metaSet message metadata retrieved from cursor are stored here
*/
void retrieveMsgMeta(RetroCursor* c, std::vector<RsGxsMsgMetaData*>& msgMeta);
/*! /*!
* extracts a msg meta item from a cursor at its * extracts a msg meta item from a cursor at its
@ -158,6 +190,8 @@ private:
RetroDb* mDb; RetroDb* mDb;
RsMutex mDbMutex;
std::list<std::string> msgColumns; std::list<std::string> msgColumns;
std::list<std::string> msgMetaColumns; std::list<std::string> msgMetaColumns;

View file

@ -36,6 +36,7 @@
#include "serialiser/rsnxsitems.h" #include "serialiser/rsnxsitems.h"
#include "gxs/rsgxsdata.h" #include "gxs/rsgxsdata.h"
#include "rsgxs.h" #include "rsgxs.h"
#include "util/contentvalue.h"
class RsGxsSearchModule { class RsGxsSearchModule {
@ -53,6 +54,11 @@ public:
*/ */
class MsgLocMetaData { class MsgLocMetaData {
public:
MsgLocMetaData(const MsgLocMetaData& meta){ msgId = meta.msgId; val = meta.val;}
MsgLocMetaData() {}
RsGxsGrpMsgIdPair msgId;
ContentValue val;
}; };
/*! /*!
@ -61,11 +67,17 @@ class MsgLocMetaData {
*/ */
class GrpLocMetaData { class GrpLocMetaData {
public:
GrpLocMetaData(const GrpLocMetaData& meta){ grpId = meta.grpId; val = meta.val;}
GrpLocMetaData(){}
RsGxsGroupId grpId;
ContentValue val;
}; };
//typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgReq; // <grpId, msgIds> typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > NxsMsgDataResult;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsNxsMsg*> > NxsMsgRelatedDataResult;
//typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgMetaData*> > GxsMsgMetaResult; // <grpId, msg metadatas> typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > GxsMsgResult; // <grpId, msgs>
/*! /*!
* The main role of GDS is the preparation and handing out of messages requested from * The main role of GDS is the preparation and handing out of messages requested from
@ -91,6 +103,15 @@ class GrpLocMetaData {
class RsGeneralDataService class RsGeneralDataService
{ {
public:
static const std::string MSG_META_SERV_STRING;
static const std::string MSG_META_STATUS;
static const std::string GRP_META_SUBSCRIBE_FLAG;
static const std::string GRP_META_STATUS;
static const std::string GRP_META_SERV_STRING;
public: public:
RsGeneralDataService(){} RsGeneralDataService(){}
@ -103,12 +124,12 @@ public:
* @param cache whether to store results of this retrieval in memory for faster later retrieval * @param cache whether to store results of this retrieval in memory for faster later retrieval
* @return error code * @return error code
*/ */
virtual int retrieveNxsMsgs(const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache) = 0; virtual int retrieveNxsMsgs(const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache, bool withMeta=false) = 0;
/*! /*!
* Retrieves all groups stored * Retrieves all groups stored
* @param grp retrieved groups * @param grp retrieved groups
* @param withMeta this initialises the meta handles nxs grps * @param withMeta if true the meta handle of nxs grps is intitialised
* @param cache whether to store retrieval in mem for faster later retrieval * @param cache whether to store retrieval in mem for faster later retrieval
* @return error code * @return error code
*/ */
@ -130,7 +151,7 @@ public:
* @param cache whether to store retrieval in mem for faster later retrieval * @param cache whether to store retrieval in mem for faster later retrieval
* @return error code * @return error code
*/ */
virtual int retrieveGxsMsgMetaData(const std::vector<std::string>& grpIds, GxsMsgMetaResult& msgMeta) = 0; virtual int retrieveGxsMsgMetaData(const GxsMsgReq& msgIds, GxsMsgMetaResult& msgMeta) = 0;
/*! /*!
* remove msgs in data store listed in msgIds param * remove msgs in data store listed in msgIds param
@ -161,25 +182,25 @@ public:
* @param msg map of message and decoded meta data information * @param msg map of message and decoded meta data information
* @return error code * @return error code
*/ */
virtual int storeMessage(std::map<RsNxsMsg*, RsGxsMsgMetaData*>& msg) = 0; virtual int storeMessage(std::map<RsNxsMsg*, RsGxsMsgMetaData*>& msgs) = 0;
/*! /*!
* Stores a list of groups in data store * Stores a list of groups in data store
* @param grp map of group and decoded meta data * @param grp map of group and decoded meta data
* @return error code * @return error code
*/ */
virtual int storeGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grp) = 0; virtual int storeGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grsp) = 0;
/*! /*!
* @param metaData * @param metaData
*/ */
virtual int updateMessageMetaData(MsgLocMetaData* metaData) = 0; virtual int updateMessageMetaData(MsgLocMetaData& metaData) = 0;
/*! /*!
* @param metaData * @param metaData
*/ */
virtual int updateGroupMetaData(GrpLocMetaData* meta) = 0; virtual int updateGroupMetaData(GrpLocMetaData& meta) = 0;
/*! /*!

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
#define RSGENEXCHANGE_H #define RSGENEXCHANGE_H
/* /*
* libretroshare/src/retroshare: rsphoto.h * libretroshare/src/gxs: rsgenexchange.h
* *
* RetroShare C++ Interface. * RetroShare C++ Interface.
* *
@ -27,17 +27,21 @@
*/ */
#include <queue> #include <queue>
#include <ctime>
#include "rsgxs.h" #include "rsgxs.h"
#include "rsgds.h" #include "rsgds.h"
#include "rsnxs.h" #include "rsnxs.h"
#include "rsgxsdataaccess.h" #include "rsgxsdataaccess.h"
#include "rsnxsobserver.h"
#include "retroshare/rsgxsservice.h" #include "retroshare/rsgxsservice.h"
#include "serialiser/rsnxsitems.h" #include "serialiser/rsnxsitems.h"
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > GxsMsgDataMap; typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > GxsMsgDataMap;
typedef std::map<RsGxsGroupId, RsGxsGrpItem*> GxsGroupDataMap; typedef std::map<RsGxsGroupId, RsGxsGrpItem*> GxsGroupDataMap;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMsgItem*> > GxsMsgRelatedDataMap;
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap; typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsMsgMetaData> > GxsMsgRelatedMetaMap;
/*! /*!
* This should form the parent class to \n * This should form the parent class to \n
@ -45,42 +49,49 @@ typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap;
* management/publishing/sync features * management/publishing/sync features
* *
* Features: \n * Features: \n
* a. Data Access: * a. Data Access: \n
* Provided by handle to RsTokenService. This ensure consistency * Provided by handle to RsTokenService. This ensure consistency \n
* of requests and hiearchy of groups -> then messages which are * of requests and hiearchy of groups -> then messages which are \n
* sectioned by group ids. * sectioned by group ids. \n
* The one caveat is that redemption of tokens are done through * The one caveat is that redemption of tokens are done through \n
* the backend of this class * the backend of this class \n
* b. Publishing: * b. Publishing: \n
* Methods are provided to publish msg and group items and also make * Methods are provided to publish msg and group items and also make \n
* changes to meta information of both item types * changes to meta information of both item types \n
* c. Sync/Notification: * c. Sync/Notification: \n
* Also notifications are made here on receipt of new data from * Also notifications are made here on receipt of new data from \n
* connected peers * connected peers
*/ */
class RsGenExchange : public RsGxsService
class RsGixs;
class RsGenExchange : public RsGxsService, public RsNxsObserver, public RsThread
{ {
public: public:
/*! /*!
* Constructs a RsGenExchange object, the owner ship of gds, ns, and serviceserialiser passes * Constructs a RsGenExchange object, the owner ship of gds, ns, and serviceserialiser passes \n
* onto the constructed object * onto the constructed object
* @param gds Data service needed to act as store of message * @param gds Data service needed to act as store of message
* @param ns Network service needed to synchronise data with rs peers * @param ns Network service needed to synchronise data with rs peers
* @param serviceSerialiser The users service needs this \n * @param serviceSerialiser The users service needs this \n
* in order for gen exchange to deal with its data types * in order for gen exchange to deal with its data types
* @param mServType This should be service type used by the serialiser
* @param gixs This is used for verification of msgs and groups received by Gen Exchange using identities, set to NULL if \n
* identity verification is not wanted
* @param authenPolicy This determines the authentication used for verfying authorship of msgs and groups
*/ */
RsGenExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns, RsSerialType* serviceSerialiser, uint16_t mServType); RsGenExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns,
RsSerialType* serviceSerialiser, uint16_t mServType, RsGixs* gixs = NULL, uint32_t authenPolicy = 0);
virtual ~RsGenExchange(); virtual ~RsGenExchange();
/** S: Observer implementation **/ /** S: Observer implementation **/
/*! /*!
* @param messages messages are deleted after function returns * @param messages messages are deleted after function returns
*/ */
void notifyNewMessages(std::vector<RsNxsMsg*> messages); void notifyNewMessages(std::vector<RsNxsMsg*>& messages);
/*! /*!
* @param messages messages are deleted after function returns * @param messages messages are deleted after function returns
@ -96,14 +107,37 @@ public:
*/ */
void tick(); void tick();
/*!
* Any backgroup processing needed by
*/
virtual void service_tick() = 0;
/*! /*!
* *
* @return handle to token service handle for making * @return handle to token service handle for making
* request to this gxs service * request to this gxs service
*/ */
RsTokenServiceV2* getTokenService(); RsTokenService* getTokenService();
protected: void run();
/*!
* Policy bit pattern portion
*/
enum PrivacyBitPos { PUBLIC_GRP_BITS, RESTRICTED_GRP_BITS, PRIVATE_GRP_BITS, GRP_OPTION_BITS } ;
/*!
* Convenience function for setting bit patterns of the individual privacy level authentication
* policy and group options
* @param flag the bit pattern (and policy) set for the privacy policy
* @param authenFlag Only the policy portion chosen will be modified with 'flag'
* @param pos The policy portion to modify
* @see PrivacyBitPos
*/
static bool setAuthenPolicyFlag(const uint8_t& flag, uint32_t& authenFlag, const PrivacyBitPos& pos);
public:
/** data access functions **/ /** data access functions **/
@ -119,14 +153,24 @@ protected:
* Retrieve msg list for a given token sectioned by group Ids * Retrieve msg list for a given token sectioned by group Ids
* @param token token to be redeemed * @param token token to be redeemed
* @param msgIds a map of grpId -> msgList (vector) * @param msgIds a map of grpId -> msgList (vector)
* @return false if could not redeem token
*/ */
bool getMsgList(const uint32_t &token, GxsMsgIdResult &msgIds); bool getMsgList(const uint32_t &token, GxsMsgIdResult &msgIds);
/*!
* Retrieve msg list for a given token for message related info
* @param token token to be redeemed
* @param msgIds a map of RsGxsGrpMsgIdPair -> msgList (vector)
* @return false if could not redeem token
*/
bool getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult& msgIds);
/*! /*!
* retrieve group meta data associated to a request token * retrieve group meta data associated to a request token
* @param token * @param token
* @param groupInfo * @param groupInfo
* @return false if could not redeem token
*/ */
bool getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo); bool getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
@ -137,12 +181,31 @@ protected:
*/ */
bool getMsgMeta(const uint32_t &token, GxsMsgMetaMap &msgInfo); bool getMsgMeta(const uint32_t &token, GxsMsgMetaMap &msgInfo);
/*!
* Retrieve msg meta for a given token for message related info
* @param token token to be redeemed
* @param msgIds a map of RsGxsGrpMsgIdPair -> msgList (vector)
* @return false if could not redeem token
*/
bool getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMap& msgMeta);
protected:
/*!
* @param grpItem
* @deprecated only here temporarily for testing
*/
void createDummyGroup(RsGxsGrpItem* grpItem);
/*! /*!
* retrieves group data associated to a request token * retrieves group data associated to a request token
* @param token token to be redeemed for grpitem retrieval * @param token token to be redeemed for grpitem retrieval
* @param grpItem the items to be retrieved for token are stored here * @param grpItem the items to be retrieved for token are stored here
*/ */
bool getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem*> grpItem); bool getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem*>& grpItem);
/*! /*!
* retrieves message data associated to a request token * retrieves message data associated to a request token
@ -151,30 +214,210 @@ protected:
*/ */
bool getMsgData(const uint32_t &token, GxsMsgDataMap& msgItems); bool getMsgData(const uint32_t &token, GxsMsgDataMap& msgItems);
/*!
* retrieves message related data associated to a request token
* @param token token to be redeemed for message item retrieval
* @param msgItems
*/
bool getMsgRelatedData(const uint32_t &token, GxsMsgRelatedDataMap& msgItems);
/*!
* Convenience template function for retrieve
* msg related data from
* @param GxsMsgType This represent derived msg class type of the service (i.e. msg type that derives from RsGxsMsgItem
* @param MsgType Represents the final type the core data is converted to
* @param token token to be redeemed
*/
template <class GxsMsgType, class MsgType>
bool getMsgRelatedDataT(const uint32_t &token, std::map<RsGxsGrpMsgIdPair, std::vector<MsgType> > &msgItems)
{
RsStackMutex stack(mGenMtx);
NxsMsgRelatedDataResult msgResult;
bool ok = mDataAccess->getMsgRelatedData(token, msgResult);
NxsMsgRelatedDataResult::iterator mit = msgResult.begin();
if(ok)
{
for(; mit != msgResult.end(); mit++)
{
std::vector<MsgType> gxsMsgItems;
const RsGxsGrpMsgIdPair& msgId = mit->first;
std::vector<RsNxsMsg*>& nxsMsgsV = mit->second;
std::vector<RsNxsMsg*>::iterator vit
= nxsMsgsV.begin();
for(; vit != nxsMsgsV.end(); vit++)
{
RsNxsMsg*& msg = *vit;
RsItem* item = mSerialiser->deserialise(msg->msg.bin_data,
&msg->msg.bin_len);
GxsMsgType* mItem = dynamic_cast<GxsMsgType*>(item);
if(mItem == NULL){
delete msg;
continue;
}
mItem->meta = *((*vit)->metaData); // get meta info from nxs msg
// GxsMsgType m = (*mItem); // doesn't work! don't know why, even with overloading done.
MsgType theServMsg = (MsgType)*mItem;
gxsMsgItems.push_back(theServMsg);
delete msg;
}
msgItems[msgId] = gxsMsgItems;
}
}
return ok;
}
/*!
* Assigns a token value to passed integer
* The status of the token can still be queried from request status feature
* @warning the token space is shared with RsGenExchange backend, so do not
* modify tokens except does you have created by calling generatePublicToken()
* @return token
*/
uint32_t generatePublicToken();
/*!
* Updates the status of associate token
* @warning the token space is shared with RsGenExchange backend, so do not
* modify tokens except does you have created by calling generatePublicToken()
* @param token
* @param status
* @return false if token could not be found, true if token disposed of
*/
bool updatePublicRequestStatus(const uint32_t &token, const uint32_t &status);
/*!
* This gets rid of a publicly issued token
* @param token
* @return false if token could not found, true if token is disposed of
*/
bool disposeOfPublicToken(const uint32_t &token);
/*!
* This gives access to the data store which hold msgs and groups
* for the service
* @return Data store for retrieving msgs and groups
*/
RsGeneralDataService* getDataStore();
/*!
* Retrieve keys for a given group, \n
* call is blocking retrieval from underlying db
* @warning under normal circumstance a service should not need this
* @param grpId the id of the group to retrieve keys for
* @param keys this is set to the retrieved keys
* @return false if group does not exist or grpId is empty
*/
bool getGroupKeys(const RsGxsGroupId& grpId, RsTlvSecurityKeySet& keySet);
public:
/*!
* This allows the client service to acknowledge that their msgs has \n
* been created/modified and retrieve the create/modified msg ids
* @param token the token related to modification/create request
* @param msgIds map of grpid->msgIds of message created/modified
* @return true if token exists false otherwise
*/
bool acknowledgeTokenMsg(const uint32_t& token, RsGxsGrpMsgIdPair& msgId);
/*!
* This allows the client service to acknowledge that their grps has \n
* been created/modified and retrieve the create/modified grp ids
* @param token the token related to modification/create request
* @param msgIds vector of ids of groups created/modified
* @return true if token exists false otherwise
*/
bool acknowledgeTokenGrp(const uint32_t& token, RsGxsGroupId& grpId);
protected: protected:
/** Modifications **/ /** Modifications **/
/*! /*!
* Enables publication of a group item * Enables publication of a group item \n
* If the item exists already this is simply versioned * If the item exists already this is simply versioned \n
* This will induce a related change message * This will induce a related change message \n
* Ownership of item passes to this rsgenexchange * Ownership of item passes to this rsgenexchange \n
* @param token
* @param grpItem * @param grpItem
* @param
*/ */
bool publishGroup(RsGxsGrpItem* grpItem); void publishGroup(uint32_t& token, RsGxsGrpItem* grpItem);
/*! /*!
* Enables publication of a message item * Enables publication of a message item \n
* If the item exists already this is simply versioned * Setting mOrigMsgId meta member to blank \n
* This will induce a related a change message * leads to this msg being an original msg \n
* if mOrigMsgId is not blank the msgId then this msg is \n
* considered a versioned msg \n
* Ownership of item passes to this rsgenexchange * Ownership of item passes to this rsgenexchange
* @param token
* @param msgItem * @param msgItem
* @return false if msg creation failed.
*/ */
bool publishMsg(RsGxsMsgItem* msgItem); void publishMsg(uint32_t& token, RsGxsMsgItem* msgItem);
/*!
* This represents the group before its signature is calculated
* Reimplement this function if you need to access keys to further extend
* security of your group items using keyset properties
* @warning do not modify keySet!
* @param grp The group which is stored by GXS prior
* service can make specific modifications need
* in particular access to its keys and meta
* @param keySet this is the key set used to define the group
* contains private and public admin and publish keys
* (use key flags to distinguish)
*/
virtual void service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
public:
/*!
* sets the group subscribe flag
* @param token this is set to token value associated to this request
* @param grpId Id of group whose subscribe file will be changed
* @param status
* @param mask
*/
void setGroupSubscribeFlags(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& status, const uint32_t& mask);
/*!
* sets the group subscribe flag
* @param token this is set to token value associated to this request
* @param grpId Id of group whose subscribe file will be changed
* @param status
* @param mask
*/
void setGroupStatusFlags(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& status, const uint32_t& mask);
/*!
* sets the group service string
* @param token this is set to token value associated to this request
* @param grpId Id of group whose subscribe file will be changed
* @param servString
*/
void setGroupServiceString(uint32_t& token, const RsGxsGroupId& grpId, const std::string& servString);
/*!
* sets the msg status flag
* @param token this is set to token value associated to this request
* @param grpId Id of group whose subscribe file will be changed
* @param status
* @param mask Mask to apply to status flag
*/
void setMsgStatusFlags(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const uint32_t& status, const uint32_t& mask);
/*!
* sets the message service string
* @param token this is set to token value associated to this request
* @param msgId Id of message whose service string will be changed
* @param servString The service string to set msg to
*/
void setMsgServiceString(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const std::string& servString );
protected: protected:
@ -187,11 +430,16 @@ protected:
* as it is called by the backend GXS system to \n * as it is called by the backend GXS system to \n
* update client of changes which should \n * update client of changes which should \n
* instigate client to retrieve new content from the system * instigate client to retrieve new content from the system
* Note! For newly received message and groups, bit 0xf00 is set to
* GXS_SERV::GXS_MSG_STATUS_UNPROCESSED and GXS_SERV::GXS_MSG_STATUS_UNREAD
* @param changes the changes that have occured to data held by this service * @param changes the changes that have occured to data held by this service
*/ */
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) = 0; virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) = 0;
public:
private:
void processRecvdData(); void processRecvdData();
@ -203,6 +451,82 @@ public:
void publishMsgs(); void publishMsgs();
/*!
* processes msg local meta changes
*/
void processMsgMetaChanges();
/*!
* Processes group local meta changes
*/
void processGrpMetaChanges();
/*!
* Convenience function for properly applying masks for status and subscribe flag
* of a group.
* @warning mask entry is removed from grpCv
*/
bool processGrpMask(const RsGxsGroupId& grpId, ContentValue& grpCv);
/*!
* This completes the creation of an instance on RsNxsGrp
* by assigning it a groupId and signature via SHA1 and EVP_sign respectively \n
* Meta is serialised and stored in group at this point also
* @param grp Nxs group to create
*/
bool createGroup(RsNxsGrp* grp, RsTlvSecurityKeySet& keySet);
/*!
* This completes the creation of an instance on RsNxsMsg
* by assigning it a groupId and signature via SHA1 and EVP_sign respectively
* What signatures are calculated are based on the authentication policy
* of the service
* @param msg the Nxs message to create
*/
bool createMessage(RsNxsMsg* msg);
/*!
* convenience function to create sign
* @param signSet signatures are stored here
* @param msgData message data to be signed
* @param grpMeta the meta data for group the message belongs to
* @return false if signature creation for any required signature fails, true otherwise
*/
bool createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinaryData& msgData,
const RsGxsMsgMetaData& msgMeta, RsGxsGrpMetaData& grpMeta);
/*!
* check meta change is legal
* @return false if meta change is not legal
*/
bool locked_validateGrpMetaChange(GrpLocMetaData&);
/*!
* Generate a set of keys that can define a GXS group
* @param keySet this is set generated keys
* @param genPublicKeys should public keys also be generated
*/
void generateGroupKeys(RsTlvSecurityKeySet& keySet, bool genPublishKeys);
/*!
* Attempts to validate msg
* @param msg message to be validated
* @param grpFlag the flag for the group the message belongs to
* @param grpKeySet
* @return true if msg validates, false otherwise
*/
bool validateMsg(RsNxsMsg* msg, const uint32_t& grpFlag, RsTlvSecurityKeySet& grpKeySet);
/*!
* Checks flag against a given privacy bit block
* @param pos Determines 8 bit wide privacy block to check
* @param flag the flag to and(&) against
* @param the result of the (bit-block & flag)
*/
bool checkMsgAuthenFlag(const PrivacyBitPos& pos, const uint8_t& flag) const;
void groupShareKeys(std::list<std::string> peers);
private: private:
RsMutex mGenMtx; RsMutex mGenMtx;
@ -210,18 +534,29 @@ private:
RsGeneralDataService* mDataStore; RsGeneralDataService* mDataStore;
RsNetworkExchangeService *mNetService; RsNetworkExchangeService *mNetService;
RsSerialType *mSerialiser; RsSerialType *mSerialiser;
RsGixs* mGixs;
std::vector<RsNxsMsg*> mReceivedMsgs; std::vector<RsNxsMsg*> mReceivedMsgs;
std::vector<RsNxsGrp*> mReceivedGrps; std::vector<RsNxsGrp*> mReceivedGrps;
std::vector<RsGxsGrpItem*> mGrpsToPublish; std::map<uint32_t, RsGxsGrpItem*> mGrpsToPublish;
std::vector<RsGxsMsgItem*> mMsgsToPublish; std::map<uint32_t, RsGxsMsgItem*> mMsgsToPublish;
std::map<uint32_t, RsGxsGrpMsgIdPair > mMsgNotify;
std::map<uint32_t, RsGxsGroupId> mGrpNotify;
// for loc meta changes
std::map<uint32_t, GrpLocMetaData > mGrpLocMetaMap;
std::map<uint32_t, MsgLocMetaData> mMsgLocMetaMap;
std::vector<RsGxsNotify*> mNotifications; std::vector<RsGxsNotify*> mNotifications;
/// service type /// service type
uint16_t mServType; uint16_t mServType;
/// authentication policy
uint32_t mAuthenPolicy;
private: private:

View file

@ -27,9 +27,11 @@
*/ */
#include "gxs/rsgxs.h" #include "gxs/rsgxs.h"
#include "gxs/rsgenexchange.h"
#include <openssl/ssl.h> #include "retroshare/rsgxscircles.h"
#include <set>
#include "serialiser/rstlvkeys.h"
/*! /*!
* GIXP: General Identity Exchange Service. * GIXP: General Identity Exchange Service.
@ -60,116 +62,93 @@
*/ */
/*! /******
* Storage class for private and public publish keys * More notes. The ideas above have been crystalised somewhat.
* *
* The Identity service will now serve two roles:
* 1) validating msgs.
* 2) reputation of identity.
*
* The identity will be equivalent to a Group Definition.
* and the reputation contained in the group's messages.
*
*
* Group
* MetaData:
* Public Key
* Signatures. (Admin & optional GPG).
* RealData:
* Nickname.
* GPGHash
*
* The GPGHash will allow people to identify the real gpg user behind the identity.
* We must make sure that the Hash input has enough entropy that it cannot be brute-forced (e.g. like password hashes).
*
* The Identity service only has to provide hooks to access the Keys for each group.
* All the key definitions are exactly the same as for GroupMetaData.
*
* The Interface is split into three parts.
* 1) Internal interface used by GXS to verify signatures.
* 2) Internal interface used by GXS to help decide if we get a message or not.
* 3) External interface to access nicknames, generate new identities etc.
*
* The actual implementation will cache frequently used keys and nicknames,
* as these will be used very frequently.
*****/
typedef std::string PeerId; // SHOULD BE REMOVED => RsPeerId (SSLID)
typedef std::string RsPgpId;
typedef std::string RsGxsId;
//
//// External Interface -
//class RsIdentityService
//{
// enum IdentityType { Pseudonym, Signed, Anonymous };
//
// virtual bool loadId(const GxsId &id) = 0;
//
// virtual bool getNickname(const GxsId &id, std::string &nickname) = 0;
//
// virtual bool createKey(RsGixsProfile& profile, uint32_t type) = 0; /* fills in mKeyId, and signature */
//
// virtual RsGixsProfile* getProfile(const KeyRef& keyref) = 0;
//
// // modify reputation.
//
//};
/* Identity Interface for GXS Message Verification.
*/ */
class GixsKey class RsGixs
{
KeyRef mKeyId;
/// public key
EVP_PKEY *mPubKey;
/// NULL if non-existant */
EVP_PKEY *mPrivKey;
};
/*!
*
*
*/
class KeyRef {
std::string refId;
};
class KeyRefSet {
std::set<KeyRef> mKeyRefSet;
};
class SignatureSet {
std::set<RsGxsSignature> mSignatureSet;
};
/*!
*
*
*/
class RsGxsSignature {
KeyRef mKeyRef;
};
/*!
* This is the actual identity \n
* In a sense the group description with the GixsKey the "message"
*/
class RsGixsProfile {
public:
KeyRef mKeyRef;
std::string name;
/// may be superseded by newer timestamps
time_t mTimeStamp;
uint32_t mProfileType;
// TODO: add permissions members
RsGxsSignature mSignature;
};
/*!
* Retroshare general identity exchange service
*
* Purpose: \n
* Provides a means to distribute identities among peers \n
* Also provides encyption, decryption, verification, \n
* and signing functionality using any created or received identities \n
*
* This may best be implemented as a singleton like current AuthGPG? \n
*
*/
class RsIdentityExchangeService : RsGxsService
{ {
public: public:
// Key related interface - used for validating msgs and groups.
enum IdentityType { Pseudonym, Signed, Anonymous };
RsGixs();
/*!
* creates gixs profile and shares it
* @param profile
* @param type the type of profile to create, self signed, anonymous, and GPG signed
*/
virtual bool createKey(RsGixsProfile& profile, uint32_t type) = 0; /* fills in mKeyId, and signature */
/*! /*!
* Use to query a whether given key is available by its key reference * Use to query a whether given key is available by its key reference
* @param keyref the keyref of key that is being checked for * @param keyref the keyref of key that is being checked for
* @return true if available, false otherwise * @return true if available, false otherwise
*/ */
virtual bool haveKey(const KeyRef& keyref) = 0; virtual bool haveKey(const RsGxsId &id) = 0;
/*! /*!
* Use to query whether private key member of the given key reference is available * Use to query whether private key member of the given key reference is available
* @param keyref the KeyRef of the key being checked for * @param keyref the KeyRef of the key being checked for
* @return true if private key is held here, false otherwise * @return true if private key is held here, false otherwise
*/ */
virtual bool havePrivateKey(const KeyRef& keyref) = 0; virtual bool havePrivateKey(const RsGxsId &id) = 0;
// The fetchKey has an optional peerList.. this is people that had the msg with the signature.
// These same people should have the identity - so we ask them first.
/*! /*!
* Use to request a given key reference * Use to request a given key reference
* @param keyref the KeyRef of the key being requested * @param keyref the KeyRef of the key being requested
* @return will * @return will
*/ */
virtual bool requestKey(const KeyRef& keyref) = 0; virtual bool requestKey(const RsGxsId &id, const std::list<PeerId> &peers) = 0;
virtual bool requestPrivateKey(const RsGxsId &id) = 0;
/*! /*!
* Retrieves a key identity * Retrieves a key identity
@ -177,53 +156,68 @@ public:
* @return a pointer to a valid profile if successful, otherwise NULL * @return a pointer to a valid profile if successful, otherwise NULL
* *
*/ */
virtual RsGixsProfile* getProfile(const KeyRef& keyref) = 0; virtual int getKey(const RsGxsId &id, RsTlvSecurityKey &key) = 0;
virtual int getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key) = 0; // For signing outgoing messages.
/*** process data ***/ };
/*! class GixsReputation
* Use to sign data with a given key {
* @param keyref the key to sign the data with public:
* @param data the data to be signed RsGxsId id;
* @param dataLen the length of the data int score;
* @param signature is set with the signature from signing with keyref };
* @return false if signing failed, true otherwise
*/
virtual bool sign(const KeyRef& keyref, unsigned char* data, uint32_t dataLen, std::string& signature) = 0;
/*!
* Verify that the data is signed by the key owner
* @param keyref
* @param data
* @param dataLen
* @param signature
* @return false if verification failed, false otherwise
*/
virtual bool verify(const KeyRef& keyref, unsigned char* data, int dataLen, std::string& signature) = 0;
/*! class RsGixsReputation
* Attempt to decrypt data with a given key {
* @param keyref public:
* @param data data to be decrypted // get Reputation.
* @param dataLen length of data virtual bool getReputation(const RsGxsId &id, const GixsReputation &rep) = 0;
* @param decryptedData decrypted data };
* @param decryptDataLen length of decrypted data
* @return false
*/
virtual bool decrypt(const KeyRef& keyref, unsigned char* data, int dataLen,
unsigned char*& decryptedData, uint32_t& decyptDataLen) = 0;
/*!
* Attempt to encrypt data with a given key /*** This Class pulls all the GXS Interfaces together ****/
* @param keyref
* @param data data to be encrypted class RsGxsIdExchange:
* @param dataLen length of data public RsGenExchange,
* @param encryptedData encrypted data public RsGixsReputation,
* @param encryptDataLen length of encrypted data public RsGixs
*/ {
virtual bool encrypt(const KeyRef& keyref, unsigned char* data, int dataLen, public:
unsigned char*& encryptedData, uint32_t& encryptDataLen) = 0; RsGxsIdExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns, RsSerialType* serviceSerialiser, uint16_t mServType)
:RsGenExchange(gds,ns,serviceSerialiser,mServType, this) { return; }
virtual ~RsGxsIdExchange() { return; }
};
/* For Circles Too */
class RsGcxs
{
public:
/* GXS Interface - for working out who can receive */
virtual bool isLoaded(const RsGxsCircleId &circleId) = 0;
virtual bool loadCircle(const RsGxsCircleId &circleId) = 0;
virtual int canSend(const RsGxsCircleId &circleId, const RsPgpId &id) = 0;
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId> &friendlist) = 0;
};
class RsGxsCircleExchange: public RsGenExchange, public RsGcxs
{
public:
RsGxsCircleExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns, RsSerialType* serviceSerialiser,
uint16_t mServType, RsGixs* gixs, uint32_t authenPolicy)
:RsGenExchange(gds,ns,serviceSerialiser,mServType, gixs, authenPolicy) { return; }
virtual ~RsGxsCircleExchange() { return; }
}; };

View file

@ -4,10 +4,7 @@
/* /*
* libretroshare/src/gxs : rsgxs.h * libretroshare/src/gxs : rsgxs.h
* *
* GXS interface for RetroShare. * Copyright 2012 Christopher Evi-Parker
* Convenience header
*
* Copyright 2011 Christopher Evi-Parker
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -25,34 +22,36 @@
* *
* Please report all bugs and problems to "retroshare@lunamutt.com". * 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.
* *
*/ */
#include "gxs/rsgxsdata.h"
#include <inttypes.h> #include <inttypes.h>
#include <string> #include <string>
#include <list> #include <list>
#include <set> #include <set>
#include <map> #include <map>
#include <vector>
#include "rsnxsobserver.h" /* data types used throughout Gxs from netservice to genexchange */
typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgReq; typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgReq;
typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgIdResult; typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgIdResult;
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgMetaData*> > GxsMsgMetaResult; typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgMetaData*> > GxsMsgMetaResult;
typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > NxsMsgDataResult; typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > MsgMetaResult;
typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > GxsMsgResult; // <grpId, msgs> typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMsgMetaData*> > MsgRelatedMetaResult;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMessageId> > MsgRelatedIdResult;
class RsGxsService : public RsNxsObserver
class RsGxsService
{ {
public: public:
RsGxsService(); RsGxsService(){}
virtual ~RsGxsService(); virtual ~RsGxsService(){}
virtual void tick() = 0; virtual void tick() = 0;

View file

@ -1,10 +1,36 @@
/*
* libretroshare/src/gxs: rsgxsdata.cc
*
* Gxs Data types used to specific services
*
* Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
*
* 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".
*
*/
#include "rsgxsdata.h" #include "rsgxsdata.h"
#include "serialiser/rsbaseserial.h" #include "serialiser/rsbaseserial.h"
#include "serialiser/rstlvbase.h"
RsGxsGrpMetaData::RsGxsGrpMetaData() RsGxsGrpMetaData::RsGxsGrpMetaData()
{ {
clear();
} }
uint32_t RsGxsGrpMetaData::serial_size() uint32_t RsGxsGrpMetaData::serial_size()
@ -17,9 +43,11 @@ uint32_t RsGxsGrpMetaData::serial_size()
s += 4; s += 4;
s += 4; s += 4;
s += GetTlvStringSize(mAuthorId); s += GetTlvStringSize(mAuthorId);
s += adminSign.TlvSize(); s += GetTlvStringSize(mServiceString);
s += signSet.TlvSize();
s += keys.TlvSize(); s += keys.TlvSize();
s += idSign.TlvSize(); s += 4; // for mCircleType
s += GetTlvStringSize(mCircleId);
return s; return s;
} }
@ -30,6 +58,7 @@ void RsGxsGrpMetaData::clear(){
mOrigGrpId.clear(); mOrigGrpId.clear();
mAuthorId.clear(); mAuthorId.clear();
mGroupName.clear(); mGroupName.clear();
mServiceString.clear();
mPublishTs = 0; mPublishTs = 0;
mGroupFlags = 0; mGroupFlags = 0;
mPop = 0; mPop = 0;
@ -37,10 +66,13 @@ void RsGxsGrpMetaData::clear(){
mGroupStatus = 0; mGroupStatus = 0;
mLastPost = 0; mLastPost = 0;
mSubscribeFlags = 0; mSubscribeFlags = 0;
signSet.TlvClear();
adminSign.TlvClear();
keys.TlvClear(); keys.TlvClear();
idSign.TlvClear(); mCircleId.clear();
mInternalCircle.clear();
mOriginator.clear();
mCircleType = 0;
} }
bool RsGxsGrpMetaData::serialise(void *data, uint32_t &pktsize) bool RsGxsGrpMetaData::serialise(void *data, uint32_t &pktsize)
@ -72,11 +104,13 @@ bool RsGxsGrpMetaData::serialise(void *data, uint32_t &pktsize)
ok &= SetTlvString(data, tlvsize, &offset, 0, mGroupName); ok &= SetTlvString(data, tlvsize, &offset, 0, mGroupName);
ok &= setRawUInt32(data, tlvsize, &offset, mGroupFlags); ok &= setRawUInt32(data, tlvsize, &offset, mGroupFlags);
ok &= setRawUInt32(data, tlvsize, &offset, mPublishTs); ok &= setRawUInt32(data, tlvsize, &offset, mPublishTs);
ok &= setRawUInt32(data, tlvsize, &offset, mCircleType);
ok &= SetTlvString(data, tlvsize, &offset, 0, mAuthorId); ok &= SetTlvString(data, tlvsize, &offset, 0, mAuthorId);
ok &= SetTlvString(data, tlvsize, &offset, 0, mServiceString);
ok &= adminSign.SetTlv(data, tlvsize, &offset); ok &= SetTlvString(data, tlvsize, &offset, 0, mCircleId);
ok &= signSet.SetTlv(data, tlvsize, &offset);
ok &= keys.SetTlv(data, tlvsize, &offset); ok &= keys.SetTlv(data, tlvsize, &offset);
ok &= idSign.SetTlv(data, tlvsize, &offset);
return ok; return ok;
} }
@ -98,11 +132,13 @@ bool RsGxsGrpMetaData::deserialise(void *data, uint32_t &pktsize)
ok &= GetTlvString(data, pktsize, &offset, 0, mGroupName); ok &= GetTlvString(data, pktsize, &offset, 0, mGroupName);
ok &= getRawUInt32(data, pktsize, &offset, &mGroupFlags); ok &= getRawUInt32(data, pktsize, &offset, &mGroupFlags);
ok &= getRawUInt32(data, pktsize, &offset, &mPublishTs); ok &= getRawUInt32(data, pktsize, &offset, &mPublishTs);
ok &= getRawUInt32(data, pktsize, &offset, &mCircleType);
ok &= GetTlvString(data, pktsize, &offset, 0, mAuthorId); ok &= GetTlvString(data, pktsize, &offset, 0, mAuthorId);
ok &= GetTlvString(data, pktsize, &offset, 0, mServiceString);
ok &= adminSign.GetTlv(data, pktsize, &offset); ok &= GetTlvString(data, pktsize, &offset, 0, mCircleId);
ok &= signSet.GetTlv(data, pktsize, &offset);
ok &= keys.GetTlv(data, pktsize, &offset); ok &= keys.GetTlv(data, pktsize, &offset);
ok &= idSign.GetTlv(data, pktsize, &offset);
return ok; return ok;
} }
@ -123,8 +159,7 @@ uint32_t RsGxsMsgMetaData::serial_size()
s += GetTlvStringSize(mOrigMsgId); s += GetTlvStringSize(mOrigMsgId);
s += GetTlvStringSize(mAuthorId); s += GetTlvStringSize(mAuthorId);
s += pubSign.TlvSize(); s += signSet.TlvSize();
s += idSign.TlvSize();
s += GetTlvStringSize(mMsgName); s += GetTlvStringSize(mMsgName);
s += 4; s += 4;
s += 4; s += 4;
@ -141,10 +176,9 @@ void RsGxsMsgMetaData::clear()
mAuthorId.clear(); mAuthorId.clear();
mOrigMsgId.clear(); mOrigMsgId.clear();
mMsgName.clear(); mMsgName.clear();
mServiceString.clear();
pubSign.TlvClear(); signSet.TlvClear();
idSign.TlvClear();
mPublishTs = 0; mPublishTs = 0;
mMsgFlags = 0; mMsgFlags = 0;
mMsgStatus = 0; mMsgStatus = 0;
@ -181,8 +215,7 @@ bool RsGxsMsgMetaData::serialise(void *data, uint32_t *size)
ok &= SetTlvString(data, *size, &offset, 0, mOrigMsgId); ok &= SetTlvString(data, *size, &offset, 0, mOrigMsgId);
ok &= SetTlvString(data, *size, &offset, 0, mAuthorId); ok &= SetTlvString(data, *size, &offset, 0, mAuthorId);
ok &= pubSign.SetTlv(data, *size, &offset); ok &= signSet.SetTlv(data, *size, &offset);
ok &= idSign.SetTlv(data, *size, &offset);
ok &= SetTlvString(data, *size, &offset, 0, mMsgName); ok &= SetTlvString(data, *size, &offset, 0, mMsgName);
ok &= setRawUInt32(data, *size, &offset, mPublishTs); ok &= setRawUInt32(data, *size, &offset, mPublishTs);
ok &= setRawUInt32(data, *size, &offset, mMsgFlags); ok &= setRawUInt32(data, *size, &offset, mMsgFlags);
@ -209,8 +242,7 @@ bool RsGxsMsgMetaData::deserialise(void *data, uint32_t *size)
ok &= GetTlvString(data, *size, &offset, 0, mOrigMsgId); ok &= GetTlvString(data, *size, &offset, 0, mOrigMsgId);
ok &= GetTlvString(data, *size, &offset, 0, mAuthorId); ok &= GetTlvString(data, *size, &offset, 0, mAuthorId);
ok &= pubSign.GetTlv(data, *size, &offset); ok &= signSet.GetTlv(data, *size, &offset);
ok &= idSign.GetTlv(data, *size, &offset);
ok &= GetTlvString(data, *size, &offset, 0, mMsgName); ok &= GetTlvString(data, *size, &offset, 0, mMsgName);
uint32_t t; uint32_t t;
ok &= getRawUInt32(data, *size, &offset, &t); ok &= getRawUInt32(data, *size, &offset, &t);
@ -232,6 +264,12 @@ void RsGxsGrpMetaData::operator =(const RsGroupMetaData& rMeta)
this->mPublishTs = rMeta.mPublishTs; this->mPublishTs = rMeta.mPublishTs;
this->mSubscribeFlags = rMeta.mSubscribeFlags; this->mSubscribeFlags = rMeta.mSubscribeFlags;
this->mGroupName = rMeta.mGroupName; this->mGroupName = rMeta.mGroupName;
this->mServiceString = rMeta.mServiceString;
this->mSignFlags = rMeta.mSignFlags;
this->mCircleId = rMeta.mCircleId;
this->mCircleType = rMeta.mCircleType;
this->mInternalCircle = rMeta.mInternalCircle;
this->mOriginator = rMeta.mOriginator;
} }
void RsGxsMsgMetaData::operator =(const RsMsgMetaData& rMeta) void RsGxsMsgMetaData::operator =(const RsMsgMetaData& rMeta)
@ -247,6 +285,7 @@ void RsGxsMsgMetaData::operator =(const RsMsgMetaData& rMeta)
this->mParentId = rMeta.mParentId ; this->mParentId = rMeta.mParentId ;
this->mPublishTs = rMeta.mPublishTs ; this->mPublishTs = rMeta.mPublishTs ;
this->mThreadId = rMeta.mThreadId; this->mThreadId = rMeta.mThreadId;
} this->mServiceString = rMeta.mServiceString;
}

View file

@ -1,10 +1,33 @@
#ifndef RSGXSMETA_H #ifndef RSGXSMETA_H
#define RSGXSMETA_H #define RSGXSMETA_H
#include <string> /*
* libretroshare/src/gxs: rsgxsdata.h
*
* Gxs Data types used to specific services
*
* Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
*
* 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".
*
*/
#include <string>
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvtypes.h" #include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvkeys.h" #include "serialiser/rstlvkeys.h"
#include "serialiser/rsgxsitems.h" #include "serialiser/rsgxsitems.h"
@ -32,14 +55,17 @@ public:
std::string mGroupName; std::string mGroupName;
uint32_t mGroupFlags; uint32_t mGroupFlags;
uint32_t mPublishTs; uint32_t mPublishTs;
uint32_t mSignFlags;
std::string mAuthorId; std::string mAuthorId;
std::string mCircleId;
uint32_t mCircleType;
RsTlvKeySignature adminSign;
RsTlvKeySignatureSet signSet;
RsTlvSecurityKeySet keys; RsTlvSecurityKeySet keys;
RsTlvKeySignature idSign;
std::string mServiceString;
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
@ -50,7 +76,8 @@ public:
time_t mLastPost; // ??? time_t mLastPost; // ???
uint32_t mGroupStatus; uint32_t mGroupStatus;
std::string mOriginator;
std::string mInternalCircle;
}; };
@ -75,8 +102,9 @@ public:
RsGxsMessageId mOrigMsgId; RsGxsMessageId mOrigMsgId;
std::string mAuthorId; std::string mAuthorId;
RsTlvKeySignature pubSign; RsTlvKeySignatureSet signSet;
RsTlvKeySignature idSign;
std::string mServiceString;
std::string mMsgName; std::string mMsgName;
time_t mPublishTs; time_t mPublishTs;
@ -84,8 +112,10 @@ public:
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
// normally READ / UNREAD flags. LOCAL Data. // normally READ / UNREAD flags. LOCAL Data.
uint32_t mMsgStatus; uint32_t mMsgStatus;
time_t mChildTs; time_t mChildTs;
bool validated;
}; };

File diff suppressed because it is too large Load diff

View file

@ -1,323 +1,420 @@
#ifndef RSGXSDATAACCESS_H #ifndef RSGXSDATAACCESS_H
#define RSGXSDATAACCESS_H #define RSGXSDATAACCESS_H
/* /*
* libretroshare/src/retroshare: rsgxsdataaccess.cc * libretroshare/src/retroshare: rsgxsdataaccess.cc
* *
* RetroShare C++ Interface. * RetroShare C++ Interface.
* *
* Copyright 2012-2012 by Robert Fernie, Christopher Evi-Parker * Copyright 2012-2012 by Robert Fernie, Christopher Evi-Parker
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation. * License Version 2 as published by the Free Software Foundation.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details. * Library General Public License for more details.
* *
* You should have received a copy of the GNU Library General Public * You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA. * USA.
* *
* Please report all bugs and problems to "retroshare@lunamutt.com". * Please report all bugs and problems to "retroshare@lunamutt.com".
* *
*/ */
#include "rstokenservice.h" #include "rstokenservice.h"
#include "rsgxsrequesttypes.h" #include "rsgxsrequesttypes.h"
#include "rsgds.h" #include "rsgds.h"
typedef std::map< RsGxsGroupId, std::map<RsGxsMessageId, RsGxsMsgMetaData*> > MsgMetaFilter; typedef std::map< RsGxsGroupId, std::map<RsGxsMessageId, RsGxsMsgMetaData*> > MsgMetaFilter;
typedef std::map< RsGxsGroupId, RsGxsGrpMetaData* > GrpMetaFilter;
class RsGxsDataAccess : public RsTokenServiceV2
{ class RsGxsDataAccess : public RsTokenService
public: {
RsGxsDataAccess(RsGeneralDataService* ds); public:
virtual ~RsGxsDataAccess() { return ;} RsGxsDataAccess(RsGeneralDataService* ds);
virtual ~RsGxsDataAccess() { return ;}
public:
public:
/** S: RsTokenService **/
/** S: RsTokenService **/
/*!
* /*!
* @param token * Use this to request group related information
* @param ansType * @param token The token returned for the request, store this value to pool for request completion
* @param opts * @param ansType The type of result (e.g. group data, meta, ids)
* @param groupIds * @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @return * @param groupIds group id to request info for
*/ * @return
bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<RsGxsGroupId> &groupIds); */
bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<RsGxsGroupId> &groupIds);
/*!
* For requesting info on all messages of one or more groups /*!
* @param token * Use this to request all group related info
* @param ansType * @param token The token returned for the request, store this value to pool for request completion
* @param opts * @param ansType The type of result (e.g. group data, meta, ids)
* @param groupIds * @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @return * @return
*/ */
bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const GxsMsgReq&); bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts);
/*! /*!
* This sets the status of the message * Use this to get msg information (id, meta, or data), store token value to poll for request completion
* @param msgId the message id to set status for * @param token The token returned for the request
* @param status status * @param ansType The type of result wanted
* @param statusMask the mask for the settings targetted * @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @return true if request made successfully, false otherwise * @param groupIds The ids of the groups to get, second entry of map empty to query for all msgs
*/ * @return true if request successful false otherwise
bool requestSetMessageStatus(uint32_t &token, const RsGxsGrpMsgIdPair &msgId, */
const uint32_t status, const uint32_t statusMask); bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const GxsMsgReq& msgIds);
/*! /*!
* * Use this to get message information (id, meta, or data), store token value to poll for request completion
* @param token * @param token The token returned for the request
* @param grpId * @param ansType The type of result wanted
* @param status * @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @param statusMask * @param groupIds The ids of the groups to get, this retrieve all the msgs info for each grpId in list, if group Id list is empty \n
* @return true if request made successfully, false otherwise * all messages for all groups are retrieved
*/ * @return true if request successful false otherwise
bool requestSetGroupStatus(uint32_t &token, const RsGxsGroupId &grpId, const uint32_t status, */
const uint32_t statusMask); bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<RsGxsGroupId>& grpIds);
/*! /*!
* Use request status to find out if successfully set * For requesting msgs related to a given msg id within a group
* @param groupId * @param token The token returned for the request
* @param subscribeFlags * @param ansType The type of result wanted
* @param subscribeMask * @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @return true if request made successfully, false otherwise * @param groupIds The ids of the groups to get, second entry of map empty to query for all msgs
*/ * @return true if request successful false otherwise
bool requestSetGroupSubscribeFlags(uint32_t& token, const RsGxsGroupId &groupId, uint32_t subscribeFlags, */
uint32_t subscribeMask); bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::vector<RsGxsGrpMsgIdPair> &msgIds);
/* Poll */
/* Poll */ uint32_t requestStatus(const uint32_t token);
uint32_t requestStatus(const uint32_t token);
/* Cancel Request */
/* Cancel Request */ bool cancelRequest(const uint32_t &token);
bool cancelRequest(const uint32_t &token);
/** E: RsTokenService **/
/** E: RsTokenService **/
public:
public: /*!
* This adds a groups to the gxs data base, this is a blocking call
/*! * Responsibility for grp still lies with callee \n
* This adds a groups to the gxs data base, this is a blocking call * If function returns successfully DataAccess can be queried for grp
* Responsibility for grp still lies with callee \n * @param grp the group to add, responsibility grp passed lies with callee
* If function returns successfully DataAccess can be queried for grp * @return false if group cound not be added
* @param grp the group to add, responsibility grp passed lies with callee */
* @return false if group cound not be added bool addGroupData(RsNxsGrp* grp);
*/
bool addGroupData(RsNxsGrp* grp); /*!
* This adds a group to the gxs data base, this is a blocking call \n
/*! * Responsibility for msg still lies with callee \n
* This adds a group to the gxs data base, this is a blocking call \n * If function returns successfully DataAccess can be queried for msg
* Responsibility for msg still lies with callee \n * @param msg the msg to add
* If function returns successfully DataAccess can be queried for msg * @return false if msg could not be added, true otherwise
* @param msg the msg to add */
* @return false if msg could not be added, true otherwise bool addMsgData(RsNxsMsg* msg);
*/
bool addMsgData(RsNxsMsg* msg); public:
public: /*!
* This must be called periodically to progress requests
/*! */
* This must be called periodically to progress requests void processRequests();
*/
void processRequests(); /*!
* Retrieve group list for a given token
/*! * @param token request token to be redeemed
* Retrieve group list for a given token * @param groupIds
* @param token request token to be redeemed * @param msgIds
* @param groupIds * @return false if token cannot be redeemed, if false you may have tried to redeem when not ready
* @param msgIds */
* @return false if token cannot be redeemed, if false you may have tried to redeem when not ready bool getGroupList(const uint32_t &token, std::list<std::string> &groupIds);
*/
bool getGroupList(const uint32_t &token, std::list<std::string> &groupIds); /*!
*
/*! * @param token request token to be redeemed
* * @param msgIds
* @param token request token to be redeemed */
* @param msgIds bool getMsgList(const uint32_t &token, GxsMsgIdResult &msgIds);
*/
bool getMsgList(const uint32_t &token, GxsMsgIdResult &msgIds); /*!
* Retrieve msg list for a given token for message related info
* @param token token to be redeemed
/*! * @param msgIds a map of RsGxsGrpMsgIdPair -> msgList (vector)
* @param token request token to be redeemed * @return false if could not redeem token
* @param groupInfo */
*/ bool getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult& msgIds);
bool getGroupSummary(const uint32_t &token, std::list<RsGxsGrpMetaData*> &groupInfo);
/*! /*!
* * @param token request token to be redeemed
* @param token request token to be redeemed * @param groupInfo
* @param msgInfo */
*/ bool getGroupSummary(const uint32_t &token, std::list<RsGxsGrpMetaData*> &groupInfo);
bool getMsgSummary(const uint32_t &token, GxsMsgMetaResult &msgInfo);
/*!
/*! *
* * @param token request token to be redeemed
* @param token request token to be redeemed * @param msgInfo
* @param grpData */
*/ bool getMsgSummary(const uint32_t &token, GxsMsgMetaResult &msgInfo);
bool getGroupData(const uint32_t &token, std::list<RsNxsGrp*>& grpData);
/*! /*!
* * Retrieve msg meta for a given token for message related info
* @param token request token to be redeemed * @param token token to be redeemed
* @param msgData * @param msgIds a map of RsGxsGrpMsgIdPair -> msgList (vector)
* @return false if data cannot be found for token * @return false if could not redeem token
*/ */
bool getMsgData(const uint32_t &token, NxsMsgDataResult& msgData); bool getMsgRelatedSummary(const uint32_t &token, MsgRelatedMetaResult& msgMeta);
private: /*!
*
/** helper functions to implement token service **/ * @param token request token to be redeemed
* @param grpData
/*! */
* Assigns a token value to passed integer bool getGroupData(const uint32_t &token, std::list<RsNxsGrp*>& grpData);
* @param token is assigned a unique token value
*/ /*!
void generateToken(uint32_t &token); *
* @param token request token to be redeemed
/*! * @param msgData
* * @return false if data cannot be found for token
* @param token the value of the token for the request object handle wanted */
* @return the request associated to this token bool getMsgData(const uint32_t &token, NxsMsgDataResult& msgData);
*/
GxsRequest* retrieveRequest(const uint32_t& token); /*!
*
/*! * @param token request token to be redeemed
* Add a gxs request to queue * @param msgData
* @param req gxs request to add * @return false if data cannot be found for token
*/ */
void storeRequest(GxsRequest* req); bool getMsgRelatedData(const uint32_t &token, NxsMsgRelatedDataResult& msgData);
/*! private:
* convenience function to setting members of request
* @param req /** helper functions to implement token service **/
* @param token
* @param ansType /*!
* @param opts * Assigns a token value to passed integer
*/ * @param token is assigned a unique token value
void setReq(GxsRequest* req,const uint32_t &token, const uint32_t& ansType, const RsTokReqOptions &opts) const; */
void generateToken(uint32_t &token);
/*!
* Remove request for request queue /*!
* Request is deleted *
* @param token the token associated to the request * @param token the value of the token for the request object handle wanted
* @return true if token successfully cleared, false if token does not exist * @return the request associated to this token
*/ */
bool clearRequest(const uint32_t &token); GxsRequest* locked_retrieveRequest(const uint32_t& token);
/*! /*!
* Updates the status flag of a request * Add a gxs request to queue
* @param token the token value of the request to set * @param req gxs request to add
* @param status the status to set */
* @return void storeRequest(GxsRequest* req);
*/
bool updateRequestStatus(const uint32_t &token, const uint32_t &status); /*!
* convenience function to setting members of request
/*! * @param req
* Use to query the status and other values of a given token * @param token
* @param token the toke of the request to check for * @param ansType
* @param status set to current status of request * @param opts
* @param reqtype set to request type of request */
* @param anstype set to to anstype of request void setReq(GxsRequest* req,const uint32_t &token, const uint32_t& ansType, const RsTokReqOptions &opts) const;
* @param ts time stamp
* @return false if token does not exist, true otherwise /*!
*/ * Remove request for request queue
bool checkRequestStatus(const uint32_t &token, uint32_t &status, uint32_t &reqtype, uint32_t &anstype, time_t &ts); * Request is deleted
* @param token the token associated to the request
// special ones for testing (not in final design) * @return true if token successfully cleared, false if token does not exist
/*! */
* Get list of active tokens of this token service bool clearRequest(const uint32_t &token);
* @param tokens sets to list of token contained in this tokenservice
*/ /*!
void tokenList(std::list<uint32_t> &tokens); * Updates the status flag of a request
* @param token the token value of the request to set
* @param status the status to set
private: * @return
*/
/* These perform the actual blocking retrieval of data */ bool locked_updateRequestStatus(const uint32_t &token, const uint32_t &status);
/*! /*!
* Attempts to retrieve group id list from data store * Use to query the status and other values of a given token
* @param req * @param token the toke of the request to check for
* @return false if unsuccessful, true otherwise * @param status set to current status of request
*/ * @param reqtype set to request type of request
bool getGroupList(GroupIdReq* req); * @param anstype set to to anstype of request
* @param ts time stamp
/*! * @return false if token does not exist, true otherwise
* Attempts to retrieve msg id list from data store */
* Computationally/CPU-Bandwidth expensive bool checkRequestStatus(const uint32_t &token, uint32_t &status, uint32_t &reqtype, uint32_t &anstype, time_t &ts);
* @param req
* @return false if unsuccessful, true otherwise // special ones for testing (not in final design)
*/ /*!
bool getMsgList(MsgIdReq* req); * Get list of active tokens of this token service
* @param tokens sets to list of token contained in this tokenservice
*/
/*! void tokenList(std::list<uint32_t> &tokens);
* Attempts to retrieve group meta data from data store
* @param req /*!
* @return false if unsuccessful, true otherwise * Convenience function to delete the ids
*/ * @param filter the meta filter to clean
bool getGroupSummary(GroupMetaReq* req); */
void cleanseMsgMetaMap(GxsMsgMetaResult& result);
/*!
* Attempts to retrieve msg meta data from data store public:
* @param req
* @return false if unsuccessful, true otherwise /*!
*/ * Assigns a token value to passed integer
bool getMsgSummary(MsgMetaReq* req); * The status of the token can still be queried from request status feature
* @param token is assigned a unique token value
/*! */
* Attempts to retrieve group data from data store uint32_t generatePublicToken();
* @param req The request specifying data to retrieve
* @return false if unsuccessful, true otherwise /*!
*/ * Updates the status of associate token
bool getGroupData(GroupDataReq* req); * @param token
* @param status
/*! * @return false if token could not be found, true if token disposed of
* Attempts to retrieve message data from data store */
* @param req The request specifying data to retrieve bool updatePublicRequestStatus(const uint32_t &token, const uint32_t &status);
* @return false if unsuccessful, true otherwise
*/ /*!
bool getMsgData(MsgDataReq* req); * This gets rid of a publicly issued token
* @param token
/*! * @return false if token could not found, true if token disposed of
* This filter msgs based of options supplied (at the moment just status masks) */
* @param msgIds The msgsIds to filter bool disposeOfPublicToken(const uint32_t &token);
* @param opts the request options set by user
* @param meta The accompanying meta information for msg, ids private:
*/
void filterMsgList(GxsMsgIdResult& msgIds, const RsTokReqOptions& opts, const MsgMetaFilter& meta) const; /* These perform the actual blocking retrieval of data */
/*!
/*! * Attempts to retrieve group id list from data store
* This applies the options to the meta to find out if the given message satisfies * @param req
* them * @return false if unsuccessful, true otherwise
* @param opts options containing filters to check */
* @param meta meta containing currently defined options for msg bool getGroupList(GroupIdReq* req);
* @return true if msg meta passes all options
*/ /*!
bool checkMsgFilter(const RsTokReqOptions& opts, const RsGxsMsgMetaData* meta) const; * convenience function for filtering grpIds
* @param grpIdsIn The ids to filter with opts
private: * @param opts the filter options
* @param grpIdsOut grpIdsIn filtered with opts
RsGeneralDataService* mDataStore; */
uint32_t mNextToken; bool getGroupList(const std::list<RsGxsGroupId>& grpIdsIn, const RsTokReqOptions& opts, std::list<RsGxsGroupId>& grpIdsOut);
std::map<uint32_t, GxsRequest*> mRequests;
/*!
RsMutex mDataMutex; * Attempts to retrieve msg id list from data store
* Computationally/CPU-Bandwidth expensive
* @param req
}; * @return false if unsuccessful, true otherwise
*/
#endif // RSGXSDATAACCESS_H bool getMsgList(MsgIdReq* req);
/*!
* Attempts to retrieve group meta data from data store
* @param req
* @return false if unsuccessful, true otherwise
*/
bool getGroupSummary(GroupMetaReq* req);
/*!
* Attempts to retrieve msg meta data from data store
* @param req
* @return false if unsuccessful, true otherwise
*/
bool getMsgSummary(MsgMetaReq* req);
/*!
* Attempts to retrieve group data from data store
* @param req The request specifying data to retrieve
* @return false if unsuccessful, true otherwise
*/
bool getGroupData(GroupDataReq* req);
/*!
* Attempts to retrieve message data from data store
* @param req The request specifying data to retrieve
* @return false if unsuccessful, true otherwise
*/
bool getMsgData(MsgDataReq* req);
/*!
* Attempts to retrieve messages related to msgIds of associated equest
* @param token request token to be redeemed
* @param msgIds
* @return false if data cannot be found for token
*/
bool getMsgRelatedInfo(MsgRelatedInfoReq* req);
/*!
* This filter msgs based of options supplied (at the moment just status masks)
* @param msgIds The msgsIds to filter
* @param opts the request options set by user
* @param meta The accompanying meta information for msg, ids
*/
void filterMsgList(GxsMsgIdResult& msgIds, const RsTokReqOptions& opts, const MsgMetaFilter& meta) const;
/*!
* This filter msgs based of options supplied (at the moment just status masks)
* @param grpIds The group ids to filter
* @param opts the request options containing mask set by user
* @param meta The accompanying meta information for group ids
*/
void filterGrpList(std::list<RsGxsGroupId>& msgIds, const RsTokReqOptions& opts, const GrpMetaFilter& meta) const;
/*!
* This applies the options to the meta to find out if the given message satisfies
* them
* @param opts options containing filters to check
* @param meta meta containing currently defined options for msg
* @return true if msg meta passes all options
*/
bool checkMsgFilter(const RsTokReqOptions& opts, const RsGxsMsgMetaData* meta) const;
/*!
* This applies the options to the meta to find out if the given group satisfies
* them
* @param opts options containing filters to check
* @param meta meta containing currently defined options for group
* @return true if group meta passes all options
*/
bool checkGrpFilter(const RsTokReqOptions& opts, const RsGxsGrpMetaData* meta) const;
/*!
* This is a filter method which applies the request options to the list of ids
* requested
* @param msgIds the msg ids for filter to be applied to
* @param opts the options used to parameterise the id filter
* @param msgIdsOut the left overs ids after filter is applied to msgIds
*/
bool getMsgList(const GxsMsgReq& msgIds, const RsTokReqOptions& opts, GxsMsgReq& msgIdsOut);
private:
RsGeneralDataService* mDataStore;
uint32_t mNextToken;
std::map<uint32_t, uint32_t> mPublicToken;
std::map<uint32_t, GxsRequest*> mRequests;
RsMutex mDataMutex;
};
#endif // RSGXSDATAACCESS_H

View file

@ -3,51 +3,105 @@
#include "inttypes.h" #include "inttypes.h"
/**
* The GXS_SERV namespace serves a single point of reference for definining grp and msg flags
* Declared and defined here are:
* - privacy flags which define the level of privacy that can be given \n
* to a group
* - authentication types which defined types of authentication needed for a given message to
* confirm its authenticity
* - subscription flags: This used only locally by the peer to subscription status to a \n
* a group
* -
*/
namespace GXS_SERV { namespace GXS_SERV {
/*** GROUP FLAGS ***/
/* type of group */ /** START privacy **/
static const uint32_t FLAG_GRP_TYPE_MASK; static const uint32_t FLAG_PRIVACY_MASK = 0x0000000f;
// pub key encrypted // pub key encrypted
static const uint32_t FLAG_GRP_TYPE_PRIVATE; static const uint32_t FLAG_PRIVACY_PRIVATE = 0x00000001;
// single publisher, read only // publish private key needed to publish
static const uint32_t FLAG_GRP_TYPE_RESTRICTED; static const uint32_t FLAG_PRIVACY_RESTRICTED = 0x00000002;
// anyone can publish // anyone can publish, publish key pair not needed
static const uint32_t FLAG_GRP_TYPE_PUBLIC; static const uint32_t FLAG_PRIVACY_PUBLIC = 0x00000004;
/** END privacy **/
/* type of msgs allowed */ /** START authentication **/
static const uint32_t FLAG_MSG_TYPE_MASK; static const uint32_t FLAG_AUTHEN_MASK = 0x000000f0;
// only signee can edit, and sign required // identity
static const uint32_t FLAG_MSG_TYPE_SIGNED; static const uint32_t FLAG_AUTHEN_IDENTITY = 0x000000010;
// no sign required, but signee can edit if signed // publish key
static const uint32_t FLAG_MSG_TYPE_ANON; static const uint32_t FLAG_AUTHEN_PUBLISH = 0x000000020;
// anyone can mod but sign must be provided (needed for wikis) // admin key
static const uint32_t FLAG_MSG_TYPE_SIGNED_SHARED; static const uint32_t FLAG_AUTHEN_ADMIN = 0x00000040;
/*** GROUP FLAGS ***/ // pgp sign identity
static const uint32_t FLAG_AUTHEN_PGP_IDENTITY = 0x00000080;
/** END authentication **/
/** START msg authentication flags **/
/*** MESSAGE FLAGS ***/ static const uint8_t MSG_AUTHEN_MASK = 0x0f;
// indicates message edits an existing message static const uint8_t MSG_AUTHEN_ROOT_PUBLISH_SIGN = 0x01;
static const uint32_t FLAG_MSG_EDIT;
// indicates msg is id signed static const uint8_t MSG_AUTHEN_CHILD_PUBLISH_SIGN = 0x02;
static const uint32_t FLAG_MSG_ID_SIGNED;
/*** MESSAGE FLAGS ***/ static const uint8_t MSG_AUTHEN_ROOT_AUTHOR_SIGN = 0x04;
static const uint8_t MSG_AUTHEN_CHILD_AUTHOR_SIGN = 0x08;
/** END msg authentication flags **/
/** START group options flag **/
static const uint8_t GRP_OPTION_AUTHEN_AUTHOR_SIGN = 0x01;
/** END group options flag **/
/** START Subscription Flags. (LOCAL) **/
static const uint32_t GROUP_SUBSCRIBE_ADMIN = 0x01;
static const uint32_t GROUP_SUBSCRIBE_PUBLISH = 0x02;
static const uint32_t GROUP_SUBSCRIBE_SUBSCRIBED = 0x04;
static const uint32_t GROUP_SUBSCRIBE_NOT_SUBSCRIBED = 0x08;
static const uint32_t GROUP_SUBSCRIBE_MASK = 0x0000000f;
/** END Subscription Flags. (LOCAL) **/
/** START GXS Msg status flags **/
static const uint32_t GXS_MSG_STATUS_UNPROCESSED = 0x000000100;
static const uint32_t GXS_MSG_STATUS_UNREAD = 0x00000200;
static const uint32_t GXS_MSG_STATUS_READ = 0x00000400;
/** END GXS Msg status flags **/
/** START GXS Grp status flags **/
static const uint32_t GXS_GRP_STATUS_UNPROCESSED = 0x000000100;
static const uint32_t GXS_GRP_STATUS_UNREAD = 0x00000200;
/** END GXS Grp status flags **/
} }

View file

@ -0,0 +1,170 @@
/*
* libretroshare/src/gxs/rsgxsifaceimpl.cc: rsgxsifaceimpl.cc
*
* RetroShare GXS.
*
* Copyright 2012 by 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".
*
*/
#include "rsgxsifaceimpl.h"
#include "gxs/rsgxs.h"
#include "gxs/rsgxsflags.h"
RsGxsIfaceImpl::RsGxsIfaceImpl(RsGenExchange *gxs)
: mGxsIfaceMutex("RsGxsIfaceImpl"), mGxs(gxs)
{
}
void RsGxsIfaceImpl::groupsChanged(std::list<RsGxsGroupId> &grpIds)
{
RsStackMutex stack(mGxsIfaceMutex);
while(!mGroupChange.empty())
{
RsGxsGroupChange* gc = mGroupChange.back();
std::list<RsGxsGroupId>& gList = gc->grpIdList;
std::list<RsGxsGroupId>::iterator lit = gList.begin();
for(; lit != gList.end(); lit++)
grpIds.push_back(*lit);
mGroupChange.pop_back();
delete gc;
}
}
bool RsGxsIfaceImpl::updated()
{
RsStackMutex stack(mGxsIfaceMutex);
bool changed = (!mGroupChange.empty() || !mMsgChange.empty());
return changed;
}
void RsGxsIfaceImpl::msgsChanged(std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs)
{
RsStackMutex stack(mGxsIfaceMutex);
while(!mMsgChange.empty())
{
RsGxsMsgChange* mc = mMsgChange.back();
msgs = mc->msgChangeMap;
mMsgChange.pop_back();
delete mc;
}
}
void RsGxsIfaceImpl::receiveChanges(std::vector<RsGxsNotify *> &changes)
{
RsStackMutex stack(mGxsIfaceMutex);
std::vector<RsGxsNotify*>::iterator vit = changes.begin();
for(; vit != changes.end(); vit++)
{
RsGxsNotify* n = *vit;
RsGxsGroupChange* gc;
RsGxsMsgChange* mc;
if((mc = dynamic_cast<RsGxsMsgChange*>(n)) != NULL)
{
mMsgChange.push_back(mc);
}
else if((gc = dynamic_cast<RsGxsGroupChange*>(n)) != NULL)
{
mGroupChange.push_back(gc);
}
else
{
delete n;
}
}
}
RsTokenService* RsGxsIfaceImpl::getTokenService()
{
return mGxs->getTokenService();
}
bool RsGxsIfaceImpl::getGroupList(const uint32_t &token,
std::list<RsGxsGroupId> &groupIds)
{
return mGxs->getGroupList(token, groupIds);
}
bool RsGxsIfaceImpl::getMsgList(const uint32_t &token,
GxsMsgIdResult& msgIds)
{
return mGxs->getMsgList(token, msgIds);
}
bool RsGxsIfaceImpl::getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult &msgIds)
{
return mGxs->getMsgRelatedList(token, msgIds);
}
/* Generic Summary */
bool RsGxsIfaceImpl::getGroupSummary(const uint32_t &token,
std::list<RsGroupMetaData> &groupInfo)
{
return mGxs->getGroupMeta(token, groupInfo);
}
bool RsGxsIfaceImpl::getMsgSummary(const uint32_t &token,
GxsMsgMetaMap &msgInfo)
{
return mGxs->getMsgMeta(token, msgInfo);
}
bool RsGxsIfaceImpl::getMsgrelatedSummary(const uint32_t &token, GxsMsgRelatedMetaMap &msgInfo)
{
return mGxs->getMsgRelatedMeta(token, msgInfo);
}
bool RsGxsIfaceImpl::subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe)
{
if(subscribe)
mGxs->setGroupSubscribeFlags(token, grpId, GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED, GXS_SERV::GROUP_SUBSCRIBE_MASK);
else
mGxs->setGroupSubscribeFlags(token, grpId, 0, GXS_SERV::GROUP_SUBSCRIBE_MASK);
return true;
}
bool RsGxsIfaceImpl::acknowledgeMsg(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
return mGxs->acknowledgeTokenMsg(token, msgId);
}
bool RsGxsIfaceImpl::acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId)
{
return mGxs->acknowledgeTokenGrp(token, grpId);
}

View file

@ -0,0 +1,181 @@
#ifndef RSGXSIFACEIMPL_H
#define RSGXSIFACEIMPL_H
/*
* libretroshare/src/gxs/: rsgxsifaceimpl.h
*
* RetroShare GXS. Convenience interface implementation
*
* Copyright 2012 by 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".
*
*/
#include "gxs/rsgenexchange.h"
/*!
* The simple idea of this class is to implement the simple interface functions
* of gen exchange.
* This class provides convenience implementations of:
* - Handle msg and group changes (client class must pass changes sent by RsGenExchange to it)
* - subscription to groups
* - retrieval of msgs and group ids and meta info
*/
class RsGxsIfaceImpl
{
public:
/*!
*
* @param gxs handle to RsGenExchange instance of service (Usually the service class itself)
*/
RsGxsIfaceImpl(RsGenExchange* gxs);
/*!
* Gxs services should call this for automatic handling of
* changes, send
* @param changes
*/
void receiveChanges(std::vector<RsGxsNotify*>& changes);
/*!
* Checks to see if a change has been received for
* for a message or group
* @return true if a change has occured for msg or group
*/
virtual bool updated();
public:
/*!
* The groups changed. \n
* class can reimplement to use to tailor
* the group actually set for ui notification.
* If receivedChanges is not passed RsGxsNotify changes
* this function does nothing
* @param grpIds
*/
virtual void groupsChanged(std::list<RsGxsGroupId>& grpIds);
/*!
* The msg changed. \n
* class can reimplement to use to tailor
* the msg actually set for ui notification.
* If receivedChanges is not passed RsGxsNotify changes
* this function does nothing
* @param msgs
*/
virtual void msgsChanged(std::map<RsGxsGroupId,
std::vector<RsGxsMessageId> >& msgs);
/*!
* @return handle to token service for this GXS service
*/
RsTokenService* getTokenService();
/* Generic Lists */
/*!
* Retrieve list of group ids associated to a request token
* @param token token to be redeemed for this request
* @param groupIds the ids return for given request token
* @return false if request token is invalid, check token status for error report
*/
bool getGroupList(const uint32_t &token,
std::list<RsGxsGroupId> &groupIds);
/*!
* Retrieves list of msg ids associated to a request token
* @param token token to be redeemed for this request
* @param msgIds the ids return for given request token
* @return false if request token is invalid, check token status for error report
*/
bool getMsgList(const uint32_t &token,
GxsMsgIdResult& msgIds);
/*!
* Retrieves list of msg related ids associated to a request token
* @param token token to be redeemed for this request
* @param msgIds the ids return for given request token
* @return false if request token is invalid, check token status for error report
*/
bool getMsgRelatedList(const uint32_t &token,
MsgRelatedIdResult& msgIds);
/*!
* @param token token to be redeemed for group summary request
* @param groupInfo the ids returned for given request token
* @return false if request token is invalid, check token status for error report
*/
bool getGroupSummary(const uint32_t &token,
std::list<RsGroupMetaData> &groupInfo);
/*!
* @param token token to be redeemed for message summary request
* @param msgInfo the message metadata returned for given request token
* @return false if request token is invalid, check token status for error report
*/
bool getMsgSummary(const uint32_t &token,
GxsMsgMetaMap &msgInfo);
/*!
* @param token token to be redeemed for message related summary request
* @param msgInfo the message metadata returned for given request token
* @return false if request token is invalid, check token status for error report
*/
bool getMsgrelatedSummary(const uint32_t &token,
GxsMsgRelatedMetaMap &msgInfo);
/*!
* subscribes to group, and returns token which can be used
* to be acknowledged to get group Id
* @param token token to redeem for acknowledgement
* @param grpId the id of the group to subscribe to
*/
virtual bool subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe);
/*!
* This allows the client service to acknowledge that their msgs has
* been created/modified and retrieve the create/modified msg ids
* @param token the token related to modification/create request
* @param msgIds map of grpid->msgIds of message created/modified
* @return true if token exists false otherwise
*/
bool acknowledgeMsg(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId);
/*!
* This allows the client service to acknowledge that their grps has
* been created/modified and retrieve the create/modified grp ids
* @param token the token related to modification/create request
* @param msgIds vector of ids of groups created/modified
* @return true if token exists false otherwise
*/
bool acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId);
private:
RsGenExchange* mGxs;
std::vector<RsGxsGroupChange*> mGroupChange;
std::vector<RsGxsMsgChange*> mMsgChange;
RsMutex mGxsIfaceMutex;
};
#endif // RSGXSIFACEIMPL_H

View file

@ -1,4 +1,31 @@
/*
* libretroshare/src/gxs: rsgxnetservice.cc
*
* Access to rs network and synchronisation service implementation
*
* Copyright 2012-2012 by 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".
*
*/
#include "rsgxsnetservice.h" #include "rsgxsnetservice.h"
#include "rsgxsflags.h"
#define NXS_NET_DEBUG #define NXS_NET_DEBUG
@ -10,7 +37,7 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs) RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs)
: p3Config(servType), p3ThreadedService(servType), : p3Config(servType), p3ThreadedService(servType),
mTransactionTimeOut(TRANSAC_TIMEOUT), mServType(servType), mDataStore(gds), mTransactionN(0), mTransactionTimeOut(TRANSAC_TIMEOUT), mServType(servType), mDataStore(gds), mTransactionN(0),
mObserver(nxsObs), mNxsMutex("RsGxsNetService"), mNetMgr(netMgr), mSYNC_PERIOD(SYNC_PERIOD) mObserver(nxsObs), mNxsMutex("RsGxsNetService"), mNetMgr(netMgr), mSYNC_PERIOD(SYNC_PERIOD), mSyncTs(0)
{ {
addSerialType(new RsNxsSerialiser(mServType)); addSerialType(new RsNxsSerialiser(mServType));
@ -31,8 +58,9 @@ int RsGxsNetService::tick(){
recvNxsItemQueue(); recvNxsItemQueue();
uint32_t now = time(NULL); uint32_t now = time(NULL);
uint32_t elapsed = mSYNC_PERIOD + mSyncTs;
if((mSYNC_PERIOD + mSyncTs) < now) if((elapsed) < now)
{ {
syncWithPeers(); syncWithPeers();
mSyncTs = now; mSyncTs = now;
@ -49,17 +77,55 @@ void RsGxsNetService::syncWithPeers()
std::set<std::string>::iterator sit = peers.begin(); std::set<std::string>::iterator sit = peers.begin();
// for now just grps // for now just grps
for(; sit != peers.end(); sit++) for(; sit != peers.end(); sit++)
{ {
RsNxsSyncGrp *grp = new RsNxsSyncGrp(mServType); RsNxsSyncGrp *grp = new RsNxsSyncGrp(mServType);
grp->clear(); grp->clear();
grp->PeerId(*sit); grp->PeerId(*sit);
sendItem(grp); sendItem(grp);
} }
// TODO msgs
#ifdef GXS_ENABLE_SYNC_MSGS
std::map<RsGxsGroupId, RsGxsGrpMetaData* > grpMeta;
mDataStore->retrieveGxsGrpMetaData(grpMeta);
std::map<RsGxsGroupId, RsGxsGrpMetaData* >::iterator
mit = grpMeta.begin();
std::vector<RsGxsGroupId> grpIds;
for(; mit != grpMeta.end(); mit++)
{
RsGxsGrpMetaData* meta = mit->second;
if(meta->mSubscribeFlags & (GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED |
GXS_SERV::GROUP_SUBSCRIBE_ADMIN) )
grpIds.push_back(mit->first);
delete meta;
}
sit = peers.begin();
// synchronise group msg for groups which we're subscribed to
for(; sit != peers.end(); sit++)
{
RsStackMutex stack(mNxsMutex);
std::vector<RsGxsGroupId>::iterator vit = grpIds.begin();
for(; vit != grpIds.end(); vit++)
{
RsNxsSyncMsg* msg = new RsNxsSyncMsg(mServType);
msg->clear();
msg->PeerId(*sit);
msg->grpId = *vit;
sendItem(msg);
}
}
#endif
} }
bool RsGxsNetService::loadList(std::list<RsItem*>& load) bool RsGxsNetService::loadList(std::list<RsItem*>& load)
@ -300,7 +366,8 @@ void RsGxsNetService::run(){
bool RsGxsNetService::locked_checkTransacTimedOut(NxsTransaction* tr) bool RsGxsNetService::locked_checkTransacTimedOut(NxsTransaction* tr)
{ {
return tr->mTimeOut < ((uint32_t) time(NULL)); return tr->mTimeOut < ((uint32_t) time(NULL));
// return false;
} }
void RsGxsNetService::processTransactions(){ void RsGxsNetService::processTransactions(){
@ -570,10 +637,11 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
// notify listener of grps // notify listener of grps
mObserver->notifyNewGroups(grps); mObserver->notifyNewGroups(grps);
}else if(flag & RsNxsTransac::FLAG_TYPE_MSGS) }else if(flag & RsNxsTransac::FLAG_TYPE_MSGS)
{ {
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
std::vector<RsNxsMsg*> msgs; std::vector<RsNxsMsg*> msgs;
while(tr->mItems.size() > 0) while(tr->mItems.size() > 0)
@ -697,14 +765,16 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
} }
} }
if(msgItemL.empty())
return;
// get grp id for this transaction // get grp id for this transaction
RsNxsSyncMsgItem* item = msgItemL.front(); RsNxsSyncMsgItem* item = msgItemL.front();
const std::string& grpId = item->grpId; const std::string& grpId = item->grpId;
std::vector<std::string> grpIdV; GxsMsgReq reqIds;
grpIdV.push_back(grpId); reqIds[grpId] = std::vector<RsGxsMessageId>();
GxsMsgMetaResult result; GxsMsgMetaResult result;
mDataStore->retrieveGxsMsgMetaData(grpIdV, result); mDataStore->retrieveGxsMsgMetaData(reqIds, result);
std::vector<RsGxsMsgMetaData*> &msgMetaV = result[grpId]; std::vector<RsGxsMsgMetaData*> &msgMetaV = result[grpId];
std::vector<RsGxsMsgMetaData*>::const_iterator vit = msgMetaV.begin(); std::vector<RsGxsMsgMetaData*>::const_iterator vit = msgMetaV.begin();
@ -722,6 +792,8 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
std::list<RsNxsSyncMsgItem*>::iterator llit = msgItemL.begin(); std::list<RsNxsSyncMsgItem*>::iterator llit = msgItemL.begin();
std::list<RsNxsItem*> reqList; std::list<RsNxsItem*> reqList;
const std::string peerFrom = tr->mTransaction->PeerId();
for(; llit != msgItemL.end(); llit++) for(; llit != msgItemL.end(); llit++)
{ {
const std::string& msgId = (*llit)->msgId; const std::string& msgId = (*llit)->msgId;
@ -732,35 +804,39 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
msgItem->msgId = msgId; msgItem->msgId = msgId;
msgItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST; msgItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST;
msgItem->transactionNumber = transN; msgItem->transactionNumber = transN;
msgItem->PeerId(peerFrom);
reqList.push_back(msgItem); reqList.push_back(msgItem);
} }
} }
if(!reqList.empty())
{
RsNxsTransac* transac = new RsNxsTransac(mServType); RsNxsTransac* transac = new RsNxsTransac(mServType);
transac->transactFlag = RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ transac->transactFlag = RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ
| RsNxsTransac::FLAG_BEGIN_P1; | RsNxsTransac::FLAG_BEGIN_P1;
transac->timestamp = 0; transac->timestamp = 0;
transac->nItems = reqList.size(); transac->nItems = reqList.size();
transac->PeerId(tr->mTransaction->PeerId()); transac->PeerId(tr->mTransaction->PeerId());
transac->transactionNumber = transN; transac->transactionNumber = transN;
NxsTransaction* newTrans = new NxsTransaction(); NxsTransaction* newTrans = new NxsTransaction();
newTrans->mItems = reqList; newTrans->mItems = reqList;
newTrans->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM; newTrans->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
newTrans->mTimeOut = time(NULL) + mTransactionTimeOut; newTrans->mTimeOut = time(NULL) + mTransactionTimeOut;
// create transaction copy with your id to indicate // create transaction copy with your id to indicate
// its an outgoing transaction // its an outgoing transaction
newTrans->mTransaction = new RsNxsTransac(*transac); newTrans->mTransaction = new RsNxsTransac(*transac);
newTrans->mTransaction->PeerId(mOwnId); newTrans->mTransaction->PeerId(mOwnId);
sendItem(transac); sendItem(transac);
{ {
if(!locked_addTransaction(newTrans)) if(!locked_addTransaction(newTrans))
delete newTrans; delete newTrans;
} }
}
} }
void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr) void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
@ -806,7 +882,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
if(grpMetaMap.find(grpId) == grpMetaMap.end()){ if(grpMetaMap.find(grpId) == grpMetaMap.end()){
RsNxsSyncGrpItem* grpItem = new RsNxsSyncGrpItem(mServType); RsNxsSyncGrpItem* grpItem = new RsNxsSyncGrpItem(mServType);
grpItem->PeerId(tr->mTransaction->PeerId());
grpItem->grpId = grpId; grpItem->grpId = grpId;
grpItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST; grpItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST;
grpItem->transactionNumber = transN; grpItem->transactionNumber = transN;
@ -815,26 +891,36 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
} }
RsNxsTransac* transac = new RsNxsTransac(mServType); if(!reqList.empty())
transac->transactFlag = RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ {
| RsNxsTransac::FLAG_BEGIN_P1;
transac->timestamp = 0;
transac->nItems = reqList.size();
transac->PeerId(tr->mTransaction->PeerId());
transac->transactionNumber = transN;
NxsTransaction* newTrans = new NxsTransaction(); RsNxsTransac* transac = new RsNxsTransac(mServType);
newTrans->mItems = reqList; transac->transactFlag = RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ
newTrans->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM; | RsNxsTransac::FLAG_BEGIN_P1;
newTrans->mTimeOut = time(NULL) + mTransactionTimeOut; transac->timestamp = 0;
newTrans->mTransaction = new RsNxsTransac(*transac); transac->nItems = reqList.size();
newTrans->mTransaction->PeerId(mOwnId); transac->PeerId(tr->mTransaction->PeerId());
transac->transactionNumber = transN;
sendItem(transac); NxsTransaction* newTrans = new NxsTransaction();
newTrans->mItems = reqList;
newTrans->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
newTrans->mTimeOut = time(NULL) + mTransactionTimeOut;
newTrans->mTransaction = new RsNxsTransac(*transac);
newTrans->mTransaction->PeerId(mOwnId);
if(!locked_addTransaction(newTrans)) sendItem(transac);
delete newTrans;
if(!locked_addTransaction(newTrans))
delete newTrans;
}
// clean up meta data
std::map<std::string, RsGxsGrpMetaData*>::iterator mit = grpMetaMap.begin();
for(; mit != grpMetaMap.end(); mit++)
delete mit->second;
} }
void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr) void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
@ -858,8 +944,13 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
grps[item->grpId] = NULL; grps[item->grpId] = NULL;
} }
mDataStore->retrieveNxsGrps(grps, false, false); if(!grps.empty())
{
mDataStore->retrieveNxsGrps(grps, false, false);
}
else{
return;
}
NxsTransaction* newTr = new NxsTransaction(); NxsTransaction* newTr = new NxsTransaction();
newTr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM; newTr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
@ -871,7 +962,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
std::string peerId = tr->mTransaction->PeerId(); std::string peerId = tr->mTransaction->PeerId();
for(;mit != grps.end(); mit++) for(;mit != grps.end(); mit++)
{ {
mit->second->PeerId(peerId); // set so it gets send to right peer mit->second->PeerId(peerId); // set so it gets sent to right peer
mit->second->transactionNumber = transN; mit->second->transactionNumber = transN;
newTr->mItems.push_back(mit->second); newTr->mItems.push_back(mit->second);
} }
@ -887,6 +978,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
ntr->transactFlag = RsNxsTransac::FLAG_BEGIN_P1 | ntr->transactFlag = RsNxsTransac::FLAG_BEGIN_P1 |
RsNxsTransac::FLAG_TYPE_GRPS; RsNxsTransac::FLAG_TYPE_GRPS;
ntr->nItems = grps.size(); ntr->nItems = grps.size();
ntr->PeerId(tr->mTransaction->PeerId());
newTr->mTransaction = new RsNxsTransac(*ntr); newTr->mTransaction = new RsNxsTransac(*ntr);
newTr->mTransaction->PeerId(mOwnId); newTr->mTransaction->PeerId(mOwnId);
@ -903,6 +995,77 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr) void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr)
{ {
#ifdef NXS_NET_DEBUG
std::cerr << "locked_genSendMsgsTransaction()" << std::endl;
std::cerr << "Generating Msg data send fron TransN: " << tr->mTransaction->transactionNumber
<< std::endl;
#endif
// go groups requested in transaction tr
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
GxsMsgReq msgIds;
GxsMsgResult msgs;
if(tr->mItems.empty()){
return;
}
for(;lit != tr->mItems.end(); lit++)
{
RsNxsSyncMsgItem* item = dynamic_cast<RsNxsSyncMsgItem*>(*lit);
msgIds[item->grpId].push_back(item->msgId);
}
mDataStore->retrieveNxsMsgs(msgIds, msgs, false, false);
NxsTransaction* newTr = new NxsTransaction();
newTr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
uint32_t transN = locked_getTransactionId();
// store msg items to send in transaction
GxsMsgResult::iterator mit = msgs.begin();
std::string peerId = tr->mTransaction->PeerId();
uint32_t msgSize = 0;
for(;mit != msgs.end(); mit++)
{
std::vector<RsNxsMsg*>& msgV = mit->second;
std::vector<RsNxsMsg*>::iterator vit = msgV.begin();
for(; vit != msgV.end(); vit++)
{
RsNxsMsg* msg = *vit;
msg->PeerId(peerId);
msg->transactionNumber = transN;
newTr->mItems.push_back(msg);
msgSize++;
}
}
if(newTr->mItems.empty()){
delete newTr;
return;
}
RsNxsTransac* ntr = new RsNxsTransac(mServType);
ntr->transactionNumber = transN;
ntr->transactFlag = RsNxsTransac::FLAG_BEGIN_P1 |
RsNxsTransac::FLAG_TYPE_MSGS;
ntr->nItems = msgSize;
ntr->PeerId(peerId);
newTr->mTransaction = new RsNxsTransac(*ntr);
newTr->mTransaction->PeerId(mOwnId);
newTr->mTimeOut = time(NULL) + mTransactionTimeOut;
ntr->PeerId(tr->mTransaction->PeerId());
sendItem(ntr);
locked_addTransaction(newTr);
return; return;
} }
uint32_t RsGxsNetService::locked_getTransactionId() uint32_t RsGxsNetService::locked_getTransactionId()
@ -956,7 +1119,6 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
if(grp.empty()) if(grp.empty())
return; return;
std::vector<RsNxsSyncGrpItem*> grpSyncItems;
std::map<std::string, RsGxsGrpMetaData*>::iterator mit = std::map<std::string, RsGxsGrpMetaData*>::iterator mit =
grp.begin(); grp.begin();
@ -975,6 +1137,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
gItem->PeerId(peer); gItem->PeerId(peer);
gItem->transactionNumber = transN; gItem->transactionNumber = transN;
itemL.push_back(gItem); itemL.push_back(gItem);
delete mit->second; // release resource
} }
tr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM; tr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
@ -1003,6 +1166,61 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item) void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
{ {
RsStackMutex stack(mNxsMutex); RsStackMutex stack(mNxsMutex);
const std::string& peer = item->PeerId();
GxsMsgMetaResult metaResult;
GxsMsgReq req;
req[item->grpId] = std::vector<std::string>();
mDataStore->retrieveGxsMsgMetaData(req, metaResult);
std::vector<RsGxsMsgMetaData*>& msgMeta = metaResult[item->grpId];
if(req.empty()){
return;
}
std::vector<RsGxsMsgMetaData*>::iterator vit = msgMeta.begin();
NxsTransaction* tr = new NxsTransaction();
std::list<RsNxsItem*>& itemL = tr->mItems;
uint32_t transN = locked_getTransactionId();
for(; vit != msgMeta.end(); vit++)
{
RsGxsMsgMetaData* m = *vit;
RsNxsSyncMsgItem* mItem = new
RsNxsSyncMsgItem(mServType);
mItem->flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
mItem->grpId = m->mGroupId;
mItem->msgId = m->mMsgId;
mItem->PeerId(peer);
mItem->transactionNumber = transN;
itemL.push_back(mItem);
}
tr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
RsNxsTransac* trItem = new RsNxsTransac(mServType);
trItem->transactFlag = RsNxsTransac::FLAG_BEGIN_P1
| RsNxsTransac::FLAG_TYPE_MSG_LIST_RESP;
trItem->nItems = itemL.size();
trItem->timestamp = 0;
trItem->PeerId(peer);
trItem->transactionNumber = transN;
// also make a copy for the resident transaction
tr->mTransaction = new RsNxsTransac(*trItem);
tr->mTransaction->PeerId(mOwnId);
tr->mTimeOut = time(NULL) + mTransactionTimeOut;
// signal peer to prepare for transaction
sendItem(trItem);
locked_addTransaction(tr);
return; return;
} }
@ -1047,3 +1265,40 @@ NxsTransaction::~NxsTransaction(){
delete mTransaction; delete mTransaction;
mTransaction = NULL; mTransaction = NULL;
} }
/* Net Manager */
RsNxsNetMgrImpl::RsNxsNetMgrImpl(p3LinkMgr *lMgr)
: mLinkMgr(lMgr), mNxsNetMgrMtx("RsNxsNetMgrImpl")
{
}
std::string RsNxsNetMgrImpl::getOwnId()
{
RsStackMutex stack(mNxsNetMgrMtx);
return mLinkMgr->getOwnId();
}
void RsNxsNetMgrImpl::getOnlineList(std::set<std::string> &ssl_peers)
{
ssl_peers.clear();
std::list<std::string> pList;
{
RsStackMutex stack(mNxsNetMgrMtx);
mLinkMgr->getOnlineList(pList);
}
std::list<std::string>::const_iterator lit = pList.begin();
for(; lit != pList.end(); lit++)
ssl_peers.insert(*lit);
}

View file

@ -1,6 +1,31 @@
#ifndef RSGXSNETSERVICE_H #ifndef RSGXSNETSERVICE_H
#define RSGXSNETSERVICE_H #define RSGXSNETSERVICE_H
/*
* libretroshare/src/gxs: rsgxnetservice.h
*
* Access to rs network and synchronisation service implementation
*
* Copyright 2012-2012 by 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".
*
*/
#include <list> #include <list>
#include <queue> #include <queue>
@ -65,17 +90,22 @@ public:
}; };
//class RsNxsNetMgrImpl : public RsNxsNetMgrImpl class RsNxsNetMgrImpl : public RsNxsNetMgr
//{ {
//public: public:
// RsNxsNetMgrImpl(p3LinkMgr* lMgr); RsNxsNetMgrImpl(p3LinkMgr* lMgr);
// std::string getOwnId(); std::string getOwnId();
// void getOnlineList(std::set<std::string>& ssl_peers); void getOnlineList(std::set<std::string>& ssl_peers);
//}; private:
p3LinkMgr* mLinkMgr;
RsMutex mNxsNetMgrMtx;
};
/// keep track of transaction number /// keep track of transaction number
@ -265,44 +295,44 @@ private:
* of msgs received from peer stored in passed transaction * of msgs received from peer stored in passed transaction
* @param tr transaction responsible for generating msg request * @param tr transaction responsible for generating msg request
*/ */
void locked_genReqMsgTransaction(NxsTransaction* tr); void locked_genReqMsgTransaction(NxsTransaction* tr);
/*! /*!
* Generates new transaction to send grp requests based on list * Generates new transaction to send grp requests based on list
* of grps received from peer stored in passed transaction * of grps received from peer stored in passed transaction
* @param tr transaction responsible for generating grp request * @param tr transaction responsible for generating grp request
*/ */
void locked_genReqGrpTransaction(NxsTransaction* tr); void locked_genReqGrpTransaction(NxsTransaction* tr);
/*! /*!
* Generates new transaction to send msg data based on list * Generates new transaction to send msg data based on list
* of grpids received from peer stored in passed transaction * of grpids received from peer stored in passed transaction
* @param tr transaction responsible for generating grp request * @param tr transaction responsible for generating grp request
*/ */
void locked_genSendMsgsTransaction(NxsTransaction* tr); void locked_genSendMsgsTransaction(NxsTransaction* tr);
/*! /*!
* Generates new transaction to send grp data based on list * Generates new transaction to send grp data based on list
* of grps received from peer stored in passed transaction * of grps received from peer stored in passed transaction
* @param tr transaction responsible for generating grp request * @param tr transaction responsible for generating grp request
*/ */
void locked_genSendGrpsTransaction(NxsTransaction* tr); void locked_genSendGrpsTransaction(NxsTransaction* tr);
/*! /*!
* convenience function to add a transaction to list * convenience function to add a transaction to list
* @param tr transaction to add * @param tr transaction to add
*/ */
bool locked_addTransaction(NxsTransaction* tr); bool locked_addTransaction(NxsTransaction* tr);
void cleanTransactionItems(NxsTransaction* tr) const; void cleanTransactionItems(NxsTransaction* tr) const;
/*! /*!
* @param tr the transaction to check for timeout * @param tr the transaction to check for timeout
* @return false if transaction has timed out, true otherwise * @return false if transaction has timed out, true otherwise
*/ */
bool locked_checkTransacTimedOut(NxsTransaction* tr); bool locked_checkTransacTimedOut(NxsTransaction* tr);
/** E: Transaction processing **/ /** E: Transaction processing **/
/** S: item handlers **/ /** S: item handlers **/
@ -370,6 +400,7 @@ private:
RsMutex mNxsMutex; RsMutex mNxsMutex;
uint32_t mSyncTs; uint32_t mSyncTs;
const uint32_t mSYNC_PERIOD; const uint32_t mSYNC_PERIOD;
}; };

View file

@ -1,13 +1,33 @@
/*
* rsgxsrequesttypes.h
*
* Created on: 21 Jul 2012
* Author: crispy
*/
#ifndef RSGXSREQUESTTYPES_H_ #ifndef RSGXSREQUESTTYPES_H_
#define RSGXSREQUESTTYPES_H_ #define RSGXSREQUESTTYPES_H_
/*
* libretroshare/src/gxs: rgxsrequesttypes.h
*
* Type introspect request types for data access request implementation
*
* Copyright 2012-2012 by 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".
*
*/
#include "gxs/rstokenservice.h"
#include "gxs/rsgds.h"
class GxsRequest class GxsRequest
{ {
@ -21,7 +41,7 @@ public:
uint32_t ansType; uint32_t ansType;
uint32_t reqType; uint32_t reqType;
RsTokReqOptions Options; RsTokReqOptions Options;
uint32_t status; uint32_t status;
}; };
@ -46,7 +66,7 @@ class GroupDataReq : public GxsRequest
{ {
public: public:
std::list<std::string> mGroupIds; std::list<RsGxsGroupId> mGroupIds;
std::list<RsNxsGrp*> mGroupData; std::list<RsNxsGrp*> mGroupData;
}; };
@ -76,6 +96,16 @@ public:
NxsMsgDataResult mMsgData; NxsMsgDataResult mMsgData;
}; };
class MsgRelatedInfoReq : public GxsRequest
{
public:
std::vector<RsGxsGrpMsgIdPair> mMsgIds;
MsgRelatedIdResult mMsgIdResult;
MsgRelatedMetaResult mMsgMetaResult;
NxsMsgRelatedDataResult mMsgDataResult;
};
class GroupSetFlagReq : public GxsRequest class GroupSetFlagReq : public GxsRequest
{ {
public: public:

View file

@ -2,7 +2,7 @@
#define RSGNP_H #define RSGNP_H
/* /*
* libretroshare/src/gxs: rsgnp.h * libretroshare/src/gxs: rsnxs.h
* *
* Network Exchange Service interface for RetroShare. * Network Exchange Service interface for RetroShare.
* *

View file

@ -2,9 +2,9 @@
#define RSNXSOBSERVER_H #define RSNXSOBSERVER_H
/* /*
* libretroshare/src/gxp: gxp.h * libretroshare/src/gxs: rsnxsobserver.h
* *
* Observer, interface for RetroShare. * Observer interface used by nxs to transport new messages to clients
* *
* Copyright 2011-2012 by Robert Fernie, Evi-Parker Christopher * Copyright 2011-2012 by Robert Fernie, Evi-Parker Christopher
* *

View file

@ -40,6 +40,34 @@
#define GXS_REQUEST_TYPE_MSG_META 0x00100000 #define GXS_REQUEST_TYPE_MSG_META 0x00100000
#define GXS_REQUEST_TYPE_MSG_IDS 0x00200000 #define GXS_REQUEST_TYPE_MSG_IDS 0x00200000
#define GXS_REQUEST_TYPE_MSG_RELATED_DATA 0x00400000
#define GXS_REQUEST_TYPE_MSG_RELATED_META 0x00800000
#define GXS_REQUEST_TYPE_MSG_RELATED_IDS 0x01000000
// This bit will be filled out over time.
#define RS_TOKREQOPT_MSG_VERSIONS 0x0001 // MSGRELATED: Returns All MsgIds with OrigMsgId = MsgId.
#define RS_TOKREQOPT_MSG_ORIGMSG 0x0002 // MSGLIST: All Unique OrigMsgIds in a Group.
#define RS_TOKREQOPT_MSG_LATEST 0x0004 // MSGLIST: All Latest MsgIds in Group. MSGRELATED: Latest MsgIds for Input Msgs.
#define RS_TOKREQOPT_MSG_THREAD 0x0010 // MSGRELATED: All Msgs in Thread. MSGLIST: All Unique Thread Ids in Group.
#define RS_TOKREQOPT_MSG_PARENT 0x0020 // MSGRELATED: All Children Msgs.
#define RS_TOKREQOPT_MSG_AUTHOR 0x0040 // MSGLIST: Messages from this AuthorId
// Read Status.
#define RS_TOKREQOPT_READ 0x0001
#define RS_TOKREQOPT_UNREAD 0x0002
#define RS_TOKREQ_ANSTYPE_LIST 0x0001
#define RS_TOKREQ_ANSTYPE_SUMMARY 0x0002
#define RS_TOKREQ_ANSTYPE_DATA 0x0003
#define RS_TOKREQ_ANSTYPE_ACK 0x0004
/*! /*!
* This class provides useful generic support for GXS style services. * This class provides useful generic support for GXS style services.
* I expect much of this will be incorporated into the base GXS. * I expect much of this will be incorporated into the base GXS.
@ -50,7 +78,9 @@ public:
RsTokReqOptions() RsTokReqOptions()
{ {
mOptions = 0; mOptions = 0;
mStatusFilter = 0; mStatusMask = 0; mSubscribeFilter = 0; mStatusFilter = 0; mStatusMask = 0; mSubscribeFilter = 0;
mSubscribeMask = 0;
mMsgFlagMask = 0; mMsgFlagFilter = 0;
mBefore = 0; mAfter = 0; mReqType = 0; mBefore = 0; mAfter = 0; mReqType = 0;
} }
@ -61,97 +91,95 @@ uint32_t mOptions;
uint32_t mStatusFilter; uint32_t mStatusFilter;
uint32_t mStatusMask; uint32_t mStatusMask;
// use
uint32_t mMsgFlagMask, mMsgFlagFilter;
uint32_t mReqType; uint32_t mReqType;
uint32_t mSubscribeFilter; // Only for Groups. uint32_t mSubscribeFilter, mSubscribeMask; // Only for Groups.
// Time range... again applied after Options. // Time range... again applied after Options.
time_t mBefore; time_t mBefore;
time_t mAfter; time_t mAfter;
}; };
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta);
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta);
/*! /*!
* A proxy class for requesting generic service data for GXS * A proxy class for requesting generic service data for GXS
* This seperates the request mechanism from the actual retrieval of data * This seperates the request mechanism from the actual retrieval of data
*/ */
class RsTokenServiceV2 class RsTokenService
{ {
public: public:
static const uint8_t GXS_REQUEST_STATUS_FAILED; static const uint8_t GXS_REQUEST_V2_STATUS_FAILED;
static const uint8_t GXS_REQUEST_STATUS_PENDING; static const uint8_t GXS_REQUEST_V2_STATUS_PENDING;
static const uint8_t GXS_REQUEST_STATUS_PARTIAL; static const uint8_t GXS_REQUEST_V2_STATUS_PARTIAL;
static const uint8_t GXS_REQUEST_STATUS_FINISHED_INCOMPLETE; static const uint8_t GXS_REQUEST_V2_STATUS_FINISHED_INCOMPLETE;
static const uint8_t GXS_REQUEST_STATUS_COMPLETE; static const uint8_t GXS_REQUEST_V2_STATUS_COMPLETE;
static const uint8_t GXS_REQUEST_STATUS_DONE; // ONCE ALL DATA RETRIEVED. static const uint8_t GXS_REQUEST_V2_STATUS_DONE; // ONCE ALL DATA RETRIEVED.
public: public:
RsTokenServiceV2() { return; } RsTokenService() { return; }
virtual ~RsTokenServiceV2() { return; } virtual ~RsTokenService() { return; }
/* Data Requests */ /* Data Requests */
/*! /*!
* Use this to request group related information * Use this to request group related information
* @param token The token returned for the request, store this value to pool for request completion * @param token The token returned for the request, store this value to pool for request completion
* @param ansType The type of result (e.g. group data, meta, ids) * @param ansType The type of result (e.g. group data, meta, ids)
* @param opts Additional option that affect outcome of request. Please see specific services, for valid values * @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @param groupIds group id to request info for. Leave empty to get info on all groups, * @param groupIds group id to request info for
* @return * @return
*/ */
virtual bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<RsGxsGroupId> &groupIds) = 0; virtual bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<RsGxsGroupId> &groupIds) = 0;
/*!
* Use this to request all group related info
* @param token The token returned for the request, store this value to pool for request completion
* @param ansType The type of result (e.g. group data, meta, ids)
* @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @return
*/
virtual bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts) = 0;
/*! /*!
* Use this to get msg related information, store this value to pole for request completion * Use this to get msg related information, store this value to pole for request completion
* @param token The token returned for the request * @param token The token returned for the request
* @param ansType The type of result wanted * @param ansType The type of result wanted
* @param opts Additional option that affect outcome of request. Please see specific services, for valid values * @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @param groupIds The ids of the groups to get, second entry of map empty to query for all msgs * @param groupIds The ids of the groups to get, second entry of map empty to query for all msgs
* @return * @return true if request successful false otherwise
*/ */
virtual bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const GxsMsgReq& msgIds) = 0; virtual bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const GxsMsgReq& msgIds) = 0;
/*!
* Use this to get msg related information, store this value to pole for request completion
* @param token The token returned for the request
* @param ansType The type of result wanted
* @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @param groupIds The ids of the groups to get, this retrieves all the msgs info for each grpId in list
* @return true if request successful false otherwise
*/
virtual bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<RsGxsGroupId>& grpIds) = 0;
/*! /*!
* This sets the status of the message * For requesting msgs related to a given msg id within a group
* @param msgId the message id to set status for * @param token The token returned for the request
* @param status status * @param ansType The type of result wanted
* @param statusMask the mask for the settings targetted * @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @return true if request made successfully, false otherwise * @param groupIds The ids of the groups to get, second entry of map empty to query for all msgs
* @return true if request successful false otherwise
*/ */
virtual bool requestSetMessageStatus(uint32_t &token, const RsGxsGrpMsgIdPair &msgId, virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::vector<RsGxsGrpMsgIdPair>& msgIds) = 0;
const uint32_t status, const uint32_t statusMask) = 0;
/*!
* Set the status of a group given by group Id
* @param token The token returned for this request
* @param grpId The Id of the group to apply status change to
* @param status The status to apply
* @param statusMask The status mask (target particular type of status)
* @return true if request made successfully, false otherwise
*/
virtual bool requestSetGroupStatus(uint32_t &token, const RsGxsGroupId &grpId, const uint32_t status,
const uint32_t statusMask) = 0;
/*!
* Use request status to find out if successfully set
* @param groupId
* @param subscribeFlags
* @param subscribeMask
* @return true if request made successfully, false otherwise
*/
virtual bool requestSetGroupSubscribeFlags(uint32_t& token, const RsGxsGroupId &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) = 0;
// (FUTURE WORK). /* Poll */
//virtual bool groupRestoreKeys(const std::string &groupId) = 0;
//virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers) = 0;
/* Poll */
/*! /*!
* Request the status of ongoing request. * Request the status of ongoing request.

View file

@ -1,6 +1,4 @@
TEMPLATE = lib TEMPLATE = lib
#CONFIG += staticlib release
#CONFIG += staticlib testnetwork
CONFIG += staticlib bitdht CONFIG += staticlib bitdht
CONFIG -= qt CONFIG -= qt
TARGET = retroshare TARGET = retroshare
@ -8,8 +6,8 @@ TARGET = retroshare
CONFIG += test_voip CONFIG += test_voip
# GXS Stuff. # GXS Stuff.
#CONFIG += newcache # This should be disabled for releases until further notice.
#CONFIG += newservices #CONFIG += gxs
# Beware: All data of the stripped services are lost # Beware: All data of the stripped services are lost
DEFINES *= PQI_DISABLE_TUNNEL DEFINES *= PQI_DISABLE_TUNNEL
@ -20,39 +18,10 @@ profiling {
QMAKE_CXXFLAGS *= -pg -g -fno-omit-frame-pointer QMAKE_CXXFLAGS *= -pg -g -fno-omit-frame-pointer
} }
release {
# UDP and TUNNEL dont work anymore.
#DEFINES *= PQI_DISABLE_UDP
}
# treat warnings as error for better removing # treat warnings as error for better removing
#QMAKE_CFLAGS += -Werror #QMAKE_CFLAGS += -Werror
#QMAKE_CXXFLAGS += -Werror #QMAKE_CXXFLAGS += -Werror
testnetwork {
# used in rsserver/rsinit.cc Enabled Port Restrictions, and makes Proxy Port next to Dht Port.
DEFINES *= LOCALNET_TESTING
# used in tcponudp/udprelay.cc Debugging Info for Relays.
DEFINES *= DEBUG_UDP_RELAY
# used in tcponudp/udpstunner.[h | cc] enables local stun (careful - modifies class variables).
DEFINES *= UDPSTUN_ALLOW_LOCALNET
# used in pqi/p3linkmgr.cc prints out extra debug.
DEFINES *= LINKMGR_DEBUG_LINKTYPE
# used in dht/connectstatebox to reduce connection times and display debug.
# DEFINES *= TESTING_PERIODS
# DEFINES *= DEBUG_CONNECTBOX
QMAKE_CXXFLAGS -= -fomit-frame-pointer
QMAKE_CXXFLAGS -= -O2
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
}
#CONFIG += debug #CONFIG += debug
debug { debug {
# DEFINES *= DEBUG # DEFINES *= DEBUG
@ -68,6 +37,7 @@ debug {
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
} }
bitdht { bitdht {
HEADERS += dht/p3bitdht.h \ HEADERS += dht/p3bitdht.h \
@ -97,45 +67,16 @@ SOURCES += tcponudp/udppeer.cc \
tcponudp/udpstunner.cc \ tcponudp/udpstunner.cc \
tcponudp/udprelay.cc \ tcponudp/udprelay.cc \
# These two aren't actually used (and don't compile) ....
# but could be useful later
#
# tcponudp/udpstunner.h \
# tcponudp/udpstunner.cc \
#
BITDHT_DIR = ../../libbitdht/src BITDHT_DIR = ../../libbitdht/src
INCLUDEPATH += . $${BITDHT_DIR} INCLUDEPATH += . $${BITDHT_DIR}
# The next line if for compliance with debian packages. Keep it! # The next line is for compliance with debian packages. Keep it!
INCLUDEPATH += ../libbitdht INCLUDEPATH += ../libbitdht
DEFINES *= RS_USE_BITDHT DEFINES *= RS_USE_BITDHT
} }
test_bitdht {
# DISABLE TCP CONNECTIONS...
DEFINES *= P3CONNMGR_NO_TCP_CONNECTIONS
# NO AUTO CONNECTIONS??? FOR TESTING DHT STATUS.
DEFINES *= P3CONNMGR_NO_AUTO_CONNECTION
# ENABLED UDP NOW.
}
use_blogs {
HEADERS += services/p3blogs.h
SOURCES += services/p3blogs.cc
DEFINES *= RS_USE_BLOGS
}
PUBLIC_HEADERS = retroshare/rsblogs.h \ PUBLIC_HEADERS = retroshare/rsblogs.h \
retroshare/rschannels.h \ retroshare/rschannels.h \
@ -161,14 +102,14 @@ PUBLIC_HEADERS = retroshare/rsblogs.h \
retroshare/rsconfig.h retroshare/rsconfig.h
HEADERS += plugins/pluginmanager.h \ HEADERS += plugins/pluginmanager.h \
plugins/dlfcn_win32.h \ plugins/dlfcn_win32.h \
serialiser/rspluginitems.h serialiser/rspluginitems.h
HEADERS += $$PUBLIC_HEADERS HEADERS += $$PUBLIC_HEADERS
# public headers to be... # public headers to be...
HEADERS += retroshare/rsgame.h \ HEADERS += retroshare/rsgame.h \
retroshare/rsphoto.h retroshare/rsphoto.h
################################# Linux ########################################## ################################# Linux ##########################################
linux-* { linux-* {
@ -204,22 +145,23 @@ linux-* {
message(Could not find gpgme-config on your system, assuming gpgme.h is in /usr/include) message(Could not find gpgme-config on your system, assuming gpgme.h is in /usr/include)
} }
#libupnp implementation files
HEADERS += upnp/UPnPBase.h
SOURCES += upnp/UPnPBase.cpp
# where to put the shared library itself # where to put the shared library itself
target.path = $$LIB_DIR target.path = $$LIB_DIR
INSTALLS *= target INSTALLS *= target
# where to put the library's interface # where to put the librarys interface
include_rsiface.path = $${INC_DIR} include_rsiface.path = $${INC_DIR}
include_rsiface.files = $$PUBLIC_HEADERS include_rsiface.files = $$PUBLIC_HEADERS
INSTALLS += include_rsiface INSTALLS += include_rsiface
#CONFIG += version_detail_bash_script #CONFIG += version_detail_bash_script
# Check if the system's libupnp has been Debian-patched
# linux/bsd can use either - libupnp is more complete and packaged.
#CONFIG += upnp_miniupnpc
CONFIG += upnp_libupnp
# Check if the systems libupnp has been Debian-patched
system(grep -E 'char[[:space:]]+PublisherUrl' $${UPNP_DIR}/upnp.h >/dev/null 2>&1) { system(grep -E 'char[[:space:]]+PublisherUrl' $${UPNP_DIR}/upnp.h >/dev/null 2>&1) {
# Normal libupnp # Normal libupnp
} else { } else {
@ -258,9 +200,7 @@ win32-x-g++ {
QMAKE_AR = i586-mingw32msvc-ar QMAKE_AR = i586-mingw32msvc-ar
DEFINES *= STATICLIB WIN32 DEFINES *= STATICLIB WIN32
#miniupnp implementation files CONFIG += upnp_miniupnpc
HEADERS += upnp/upnputil.h
SOURCES += upnp/upnputil.c
SSL_DIR=../../../../openssl SSL_DIR=../../../../openssl
UPNPC_DIR = ../../../../miniupnpc-1.3 UPNPC_DIR = ../../../../miniupnpc-1.3
@ -296,9 +236,7 @@ win32 {
DEFINES += USE_CMD_ARGS DEFINES += USE_CMD_ARGS
#miniupnp implementation files CONFIG += upnp_miniupnpc
HEADERS += upnp/upnputil.h
SOURCES += upnp/upnputil.c
UPNPC_DIR = ../../../miniupnpc-1.3 UPNPC_DIR = ../../../miniupnpc-1.3
@ -308,6 +246,13 @@ win32 {
OPENPGPSDK_DIR = ../../openpgpsdk/src OPENPGPSDK_DIR = ../../openpgpsdk/src
INCLUDEPATH += . $${SSL_DIR}/include $${UPNPC_DIR} $${PTHREADS_DIR} $${ZLIB_DIR} $${OPENPGPSDK_DIR} INCLUDEPATH += . $${SSL_DIR}/include $${UPNPC_DIR} $${PTHREADS_DIR} $${ZLIB_DIR} $${OPENPGPSDK_DIR}
# SQLite include path is required to compile GXS.
gxs {
SQLITE_DIR = ../../../../Libraries/sqlite/sqlite-autoconf-3070900
INCLUDEPATH += $${SQLITE_DIR}
}
} }
@ -321,9 +266,7 @@ mac {
#DEFINES *= MINIUPNPC_VERSION=13 #DEFINES *= MINIUPNPC_VERSION=13
DESTDIR = lib DESTDIR = lib
#miniupnp implementation files CONFIG += upnp_miniupnpc
HEADERS += upnp/upnputil.h
SOURCES += upnp/upnputil.c
# zeroconf disabled at the end of libretroshare.pro (but need the code) # zeroconf disabled at the end of libretroshare.pro (but need the code)
CONFIG += zeroconf CONFIG += zeroconf
@ -353,9 +296,10 @@ freebsd-* {
QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dstat64=stat -Dstatvfs64=statvfs -Dfopen64=fopen QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dstat64=stat -Dstatvfs64=statvfs -Dfopen64=fopen
#libupnp implementation files # linux/bsd can use either - libupnp is more complete and packaged.
HEADERS += upnp/UPnPBase.h #CONFIG += upnp_miniupnpc
SOURCES += upnp/UPnPBase.cpp CONFIG += upnp_libupnp
DESTDIR = lib DESTDIR = lib
} }
@ -482,7 +426,6 @@ HEADERS += turtle/p3turtle.h \
turtle/rsturtleitem.h \ turtle/rsturtleitem.h \
turtle/turtletypes.h turtle/turtletypes.h
HEADERS += upnp/upnphandler.h
HEADERS += util/folderiterator.h \ HEADERS += util/folderiterator.h \
util/rsdebug.h \ util/rsdebug.h \
@ -500,6 +443,8 @@ HEADERS += util/folderiterator.h \
util/rsrandom.h \ util/rsrandom.h \
util/radix64.h \ util/radix64.h \
util/pugiconfig.h \ util/pugiconfig.h \
util/rsmemcache.h \
util/rstickevent.h \
SOURCES += dbase/cachestrapper.cc \ SOURCES += dbase/cachestrapper.cc \
dbase/fimonitor.cc \ dbase/fimonitor.cc \
@ -624,7 +569,6 @@ SOURCES += turtle/p3turtle.cc \
# turtle/turtlesearch.cc \ # turtle/turtlesearch.cc \
# turtle/turtletunnels.cc # turtle/turtletunnels.cc
SOURCES += upnp/upnphandler.cc
SOURCES += util/folderiterator.cc \ SOURCES += util/folderiterator.cc \
util/rsdebug.cc \ util/rsdebug.cc \
@ -640,6 +584,21 @@ SOURCES += util/folderiterator.cc \
util/rsversion.cc \ util/rsversion.cc \
util/rswin.cc \ util/rswin.cc \
util/rsrandom.cc \ util/rsrandom.cc \
util/rstickevent.cc \
upnp_miniupnpc {
HEADERS += upnp/upnputil.h upnp/upnphandler_miniupnp.h
SOURCES += upnp/upnputil.c upnp/upnphandler_miniupnp.cc
}
upnp_libupnp {
HEADERS += upnp/UPnPBase.h upnp/upnphandler_linux.h
SOURCES += upnp/UPnPBase.cpp upnp/upnphandler_linux.cc
DEFINES *= RS_USE_LIBUPNP
}
zeroconf { zeroconf {
@ -666,67 +625,151 @@ SOURCES += zeroconf/p3zcnatassist.cc \
} }
# new gxs cache system # new gxs cache system
newcache { # this should be disabled for releases until further notice.
gxs {
DEFINES *= RS_ENABLE_GXS
HEADERS += serialiser/rsnxsitems.h \ HEADERS += serialiser/rsnxsitems.h \
gxs/rsgds.h \ gxs/rsgds.h \
gxs/rsgxs.h \ gxs/rsgxs.h \
gxs/rsdataservice.h \ gxs/rsdataservice.h \
gxs/rsgxsnetservice.h \ gxs/rsgxsnetservice.h \
gxs/rsgxsflags.h \ gxs/rsgxsflags.h \
gxs/rsgenexchange.h \ gxs/rsgenexchange.h \
gxs/rsnxsobserver.h \ gxs/rsnxsobserver.h \
gxs/rsgxsdata.h \ gxs/rsgxsdata.h \
gxs/rstokenservice.h \ gxs/rstokenservice.h \
gxs/rsgxsdataaccess.h \ gxs/rsgxsdataaccess.h \
retroshare/rsgxsservice.h \ retroshare/rsgxsservice.h \
serialiser/rsgxsitems.h \ serialiser/rsgxsitems.h \
util/retrodb.h util/retrodb.h \
util/contentvalue.h \
SOURCES += serialiser/rsnxsitems.cc \ gxs/gxscoreserver.h \
gxs/rsdataservice.cc \ gxs/gxssecurity.h \
gxs/rsgenexchange.cc \ gxs/rsgxsifaceimpl.h \
gxs/rsgxsnetservice.cc \ gxs/gxstokenqueue.h \
gxs/rsgxsdata.cc \
services/p3photoserviceV2.cc \
gxs/rsgxsdataaccess.cc \
util/retrodb.cc
}
SOURCES += serialiser/rsnxsitems.cc \
gxs/rsdataservice.cc \
gxs/rsgenexchange.cc \
gxs/rsgxsnetservice.cc \
gxs/rsgxsdata.cc \
serialiser/rsgxsitems.cc \
gxs/rsgxsdataaccess.cc \
util/retrodb.cc \
util/contentvalue.cc \
gxs/gxscoreserver.cc \
gxs/gxssecurity.cc \
gxs/rsgxsifaceimpl.cc \
gxs/gxstokenqueue.cc \
newservices { # Identity Service
HEADERS += retroshare/rsidentity.h \
HEADERS += services/p3photoservice.h \ gxs/rsgixs.h \
serialiser/rsphotoitems.h \
retroshare/rsphoto.h \
services/p3gxsservice.h \
retroshare/rsidentity.h \
services/p3wikiservice.h \
retroshare/rswiki.h \
retroshare/rswire.h \
services/p3wire.h \
services/p3idservice.h \ services/p3idservice.h \
retroshare/rsforumsv2.h \ serialiser/rsgxsiditems.h
services/p3forumsv2.h \
SOURCES += services/p3idservice.cc \
serialiser/rsgxsiditems.cc \
# GxsCircles Service
HEADERS += services/p3gxscircles.h \
serialiser/rsgxscircleitems.h \
retroshare/rsgxscircles.h \
SOURCES += services/p3gxscircles.cc \
serialiser/rsgxscircleitems.cc \
# GxsForums Service
HEADERS += retroshare/rsgxsforums.h \
services/p3gxsforums.h \
serialiser/rsgxsforumitems.h
SOURCES += services/p3gxsforums.cc \
serialiser/rsgxsforumitems.cc \
# Wiki Service
HEADERS += retroshare/rswiki.h \
services/p3wiki.h \
serialiser/rswikiitems.h
SOURCES += services/p3wiki.cc \
serialiser/rswikiitems.cc \
# Wiki Service
HEADERS += retroshare/rswire.h \
services/p3wire.h \
serialiser/rswireitems.h
SOURCES += services/p3wire.cc \
serialiser/rswireitems.cc \
# Posted Service
HEADERS += services/p3posted.h \
retroshare/rsposted.h \ retroshare/rsposted.h \
services/p3posted.h \ serialiser/rsposteditems.h
services/p3photoserviceV2.h \
retroshare/rsphotoV2.h \
SOURCES += services/p3photoservice.cc \ SOURCES += services/p3posted.cc \
serialiser/rsposteditems.cc
#Photo Service
HEADERS += services/p3photoservice.h \
retroshare/rsphoto.h \
serialiser/rsphotoitems.h \
SOURCES += services/p3photoservice.cc \
serialiser/rsphotoitems.cc \ serialiser/rsphotoitems.cc \
services/p3gxsservice.cc \
services/p3wikiservice.cc \
services/p3wire.cc \
services/p3idservice.cc \
services/p3forumsv2.cc \
services/p3posted.cc \
# Other Old Code.
# rsserver/p3photo.cc \
} }
###########################################################################################################
# OLD CONFIG OPTIONS.
# Not used much - but might be useful one day.
#
testnetwork {
# used in rsserver/rsinit.cc Enabled Port Restrictions, and makes Proxy Port next to Dht Port.
DEFINES *= LOCALNET_TESTING
# used in tcponudp/udprelay.cc Debugging Info for Relays.
DEFINES *= DEBUG_UDP_RELAY
# used in tcponudp/udpstunner.[h | cc] enables local stun (careful - modifies class variables).
DEFINES *= UDPSTUN_ALLOW_LOCALNET
# used in pqi/p3linkmgr.cc prints out extra debug.
DEFINES *= LINKMGR_DEBUG_LINKTYPE
# used in dht/connectstatebox to reduce connection times and display debug.
# DEFINES *= TESTING_PERIODS
# DEFINES *= DEBUG_CONNECTBOX
}
test_bitdht {
# DISABLE TCP CONNECTIONS...
DEFINES *= P3CONNMGR_NO_TCP_CONNECTIONS
# NO AUTO CONNECTIONS??? FOR TESTING DHT STATUS.
DEFINES *= P3CONNMGR_NO_AUTO_CONNECTION
# ENABLED UDP NOW.
}
use_blogs {
HEADERS += services/p3blogs.h
SOURCES += services/p3blogs.cc
DEFINES *= RS_USE_BLOGS
}

View file

@ -8,6 +8,7 @@
#ifdef WINDOWS_SYS #ifdef WINDOWS_SYS
#include "util/rsstring.h" #include "util/rsstring.h"
#include "util/rswin.h"
#endif #endif
extern "C" { extern "C" {

View file

@ -168,6 +168,21 @@ void RsPluginManager::loadPlugins(const std::vector<std::string>& plugin_directo
saveConfiguration(); saveConfiguration();
} }
void RsPluginManager::stopPlugins()
{
std::cerr << " Stopping plugins." << std::endl;
for (uint32_t i = 0; i < _plugins.size(); ++i)
{
if (_plugins[i].plugin != NULL)
{
_plugins[i].plugin->stop();
// delete _plugins[i].plugin;
// _plugins[i].plugin = NULL;
}
}
}
void RsPluginManager::getPluginStatus(int i,uint32_t& status,std::string& file_name,std::string& hash,uint32_t& svn_revision,std::string& error_string) const void RsPluginManager::getPluginStatus(int i,uint32_t& status,std::string& file_name,std::string& hash,uint32_t& svn_revision,std::string& error_string) const
{ {
if((uint32_t)i >= _plugins.size()) if((uint32_t)i >= _plugins.size())

View file

@ -93,6 +93,8 @@ class RsPluginManager: public RsPluginHandler, public p3Config
// //
void loadPlugins(const std::vector<RsPlugin*>& explicit_plugin_entries) ; void loadPlugins(const std::vector<RsPlugin*>& explicit_plugin_entries) ;
void stopPlugins();
void registerCacheServices() ; void registerCacheServices() ;
void registerClientServices(p3ServiceServer *pqih) ; void registerClientServices(p3ServiceServer *pqih) ;

View file

@ -39,7 +39,6 @@
#ifndef RS_GPG_AUTH_HEADER #ifndef RS_GPG_AUTH_HEADER
#define RS_GPG_AUTH_HEADER #define RS_GPG_AUTH_HEADER
#include "util/rswin.h"
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include "util/rsthreads.h" #include "util/rsthreads.h"

View file

@ -28,6 +28,10 @@
* *
*/ */
#ifdef WINDOWS_SYS
#include "util/rswin.h"
#endif // WINDOWS_SYS
#include "authssl.h" #include "authssl.h"
#include "sslfns.h" #include "sslfns.h"

View file

@ -39,8 +39,6 @@
* *
*/ */
#include "util/rswin.h"
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/evp.h> #include <openssl/evp.h>

View file

@ -64,6 +64,20 @@ virtual int tick() { return 0; } /* for internal accounting */
}; };
#define PFP_TYPE_UDP 0x0001
#define PFP_TYPE_TCP 0x0002
class PortForwardParams
{
public:
uint32_t fwdId;
uint32_t status;
uint32_t typeFlags;
struct sockaddr_in intAddr;
struct sockaddr_in extaddr;
};
class pqiNetAssistFirewall: public pqiNetAssist class pqiNetAssistFirewall: public pqiNetAssist
{ {
public: public:
@ -78,6 +92,12 @@ virtual void setExternalPort(unsigned short eport_in) = 0;
virtual bool getInternalAddress(struct sockaddr_in &addr) = 0; virtual bool getInternalAddress(struct sockaddr_in &addr) = 0;
virtual bool getExternalAddress(struct sockaddr_in &addr) = 0; virtual bool getExternalAddress(struct sockaddr_in &addr) = 0;
/* New Port Forward interface to support as many ports as necessary */
virtual bool requestPortForward(const PortForwardParams &params) = 0;
virtual bool statusPortForward(const uint32_t fwdId, PortForwardParams &params) = 0;
}; };

View file

@ -23,10 +23,14 @@
* *
*/ */
#ifndef PQI_HASH_
#define PQI_HASH_
#include <openssl/sha.h> #include <openssl/sha.h>
#include <string> #include <string>
#include <iomanip> #include <iomanip>
#include "util/rsstring.h" #include "util/rsstring.h"
#include <inttypes.h>
class pqihash class pqihash
{ {
@ -85,4 +89,4 @@ void Complete(std::string &hash)
SHA_CTX *sha_ctx; SHA_CTX *sha_ctx;
}; };
#endif

View file

@ -23,8 +23,10 @@
* *
*/ */
#ifdef WINDOWS_SYS
#include "util/rswin.h"
#include <ws2tcpip.h>
#endif // WINDOWS_SYS
#include "pqi/pqinetwork.h" #include "pqi/pqinetwork.h"
#include "util/rsnet.h" #include "util/rsnet.h"

View file

@ -45,12 +45,10 @@
#else #else
#include "util/rswin.h"
#include "util/rsnet.h" /* more generic networking header */ #include "util/rsnet.h" /* more generic networking header */
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h>
typedef int socklen_t; typedef int socklen_t;
//typedef unsigned long in_addr_t; //typedef unsigned long in_addr_t;

View file

@ -28,8 +28,6 @@
#ifndef MRK_PQI_SSL_HEADER #ifndef MRK_PQI_SSL_HEADER
#define MRK_PQI_SSL_HEADER #define MRK_PQI_SSL_HEADER
#include "util/rswin.h"
#include <openssl/ssl.h> #include <openssl/ssl.h>
// operating system specific network header. // operating system specific network header.

View file

@ -28,8 +28,6 @@
#ifndef MRK_PQI_SSL_UDP_HEADER #ifndef MRK_PQI_SSL_UDP_HEADER
#define MRK_PQI_SSL_UDP_HEADER #define MRK_PQI_SSL_UDP_HEADER
#include "util/rswin.h"
#include <openssl/ssl.h> #include <openssl/ssl.h>
// operating system specific network header. // operating system specific network header.

View file

@ -33,8 +33,6 @@
/******************** notify of new Cert **************************/ /******************** notify of new Cert **************************/
#include "util/rswin.h"
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/ssl.h> #include <openssl/ssl.h>

View file

@ -1,106 +0,0 @@
#ifndef RETROSHARE_FORUMV2_GUI_INTERFACE_H
#define RETROSHARE_FORUMV2_GUI_INTERFACE_H
/*
* libretroshare/src/retroshare: rsforumv2.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie.
*
* 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.1 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".
*
*/
#include <inttypes.h>
#include <string>
#include <list>
#include <retroshare/rsidentity.h>
/* The Main Interface Class - for information about your Peers */
class RsForumsV2;
extern RsForumsV2 *rsForumsV2;
class RsForumV2Group
{
public:
// All the MetaData is Stored here:
RsGroupMetaData mMeta;
// THESE ARE IN THE META DATA.
//std::string mGroupId;
//std::string mName;
std::string mDescription;
// THESE ARE CURRENTLY UNUSED.
//std::string mCategory;
//std::string mHashTags;
};
class RsForumV2Msg
{
public:
// All the MetaData is Stored here:
RsMsgMetaData mMeta;
// THESE ARE IN THE META DATA.
//std::string mGroupId;
//std::string mMsgId;
//std::string mOrigMsgId;
//std::string mThreadId;
//std::string mParentId;
//std::string mName; (aka. Title)
std::string mMsg; // all the text is stored here.
// THESE ARE CURRENTLY UNUSED.
//std::string mHashTags;
};
class RsForumsV2: public RsTokenService
{
public:
RsForumsV2() { return; }
virtual ~RsForumsV2() { return; }
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsForumV2Group &group) = 0;
virtual bool getMsgData(const uint32_t &token, RsForumV2Msg &msg) = 0;
// ONES THAT WE ARE NOT IMPLEMENTING. (YET!)
//virtual bool getMessageStatus(const std::string& fId, const std::string& mId, uint32_t& status) = 0;
// THINK WE CAN GENERALISE THIS TO: a list function, and you can just count the list entries...
// requestGroupList(groupId, UNREAD, ...)
//virtual bool getMessageCount(const std::string &groupId, unsigned int &newCount, unsigned int &unreadCount) = 0;
/* details are updated in group - to choose GroupID */
virtual bool createGroup(uint32_t &token, RsForumV2Group &group, bool isNew) = 0;
virtual bool createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew) = 0;
};
#endif

View file

@ -0,0 +1,127 @@
#ifndef RETROSHARE_GXSCIRCLES_INTERFACE_H
#define RETROSHARE_GXSCIRCLES_INTERFACE_H
/*
* libretroshare/src/retroshare: rsgxscircles.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie.
*
* 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.1 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".
*
*/
#include <inttypes.h>
#include <string>
#include <list>
#include "gxs/rstokenservice.h"
#include "gxs/rsgxsifaceimpl.h"
#include "retroshare/rsidentity.h"
/* The Main Interface Class - for information about your Peers */
class RsGxsCircles;
extern RsGxsCircles *rsGxsCircles;
typedef std::string RsGxsCircleId;
typedef std::string RsPeerId; // SSL ID.
typedef std::string RsPgpId;
typedef std::string RsCircleInternalId;
#define GXS_CIRCLE_TYPE_PUBLIC 0x0001
#define GXS_CIRCLE_TYPE_EXTERNAL 0x0002
#define GXS_CIRCLE_TYPE_YOUREYESONLY 0x0003
/* Permissions is part of GroupMetaData
*/
class GxsPermissions
{
public:
uint32_t mCircleType; // PUBLIC, EXTERNAL or YOUREYESONLY.
RsGxsCircleId mCircleId; // If EXTERNAL, otherwise Blank.
// BELOW IS NOT SERIALISED - BUT MUST BE STORED LOCALLY BY GXS. (If YOUREYESONLY)
RsPeerId mOriginator;
RsCircleInternalId mInternalCircle; // if Originator == ownId, otherwise blank.
};
class RsGxsCircleGroup
{
public:
RsGroupMetaData mMeta; // includes GxsPermissions, for control of group distribution.
std::list<RsGxsId> mInvitedMembers;
std::list<RsGxsCircleId> mSubCircles;
// Not Serialised.
// Internally inside rsCircles, this will be turned into:
// std::list<RsPeerId> mAllowedFriends;
};
class RsGxsCircleMsg
{
public:
RsMsgMetaData mMeta;
// Signature by user signifying that they want to be part of the group.
// maybe Phase 3.
std::string stuff;
};
class RsGxsCircleDetails
{
public:
RsGxsCircleId mCircleId;
std::string mCircleName;
std::set<RsGxsId> mUnknownPeers;
std::map<RsPgpId, std::list<RsGxsId> > mAllowedPeers;
};
class RsGxsCircles: public RsGxsIfaceImpl
{
public:
RsGxsCircles(RsGenExchange *gxs)
:RsGxsIfaceImpl(gxs) { return; }
virtual ~RsGxsCircles() { return; }
/* External Interface (Cached stuff) */
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details) = 0;
virtual bool getCircleIdList(std::list<RsGxsCircleId> &circleIds) = 0;
/* standard load */
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups) = 0;
/* make new group */
virtual bool createGroup(uint32_t& token, RsGxsCircleGroup &group) = 0;
};
#endif

View file

@ -0,0 +1,97 @@
#ifndef RETROSHARE_GXS_FORUM_GUI_INTERFACE_H
#define RETROSHARE_GXS_FORUM_GUI_INTERFACE_H
/*
* libretroshare/src/retroshare: rsgxsforum.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie.
*
* 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.1 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".
*
*/
#include <inttypes.h>
#include <string>
#include <list>
#include "gxs/rstokenservice.h"
#include "gxs/rsgxsifaceimpl.h"
#define IS_MSG_NEW(status) (status & GXS_SERV::GXS_MSG_STATUS_UNPROCESSED)
#define IS_MSG_UNREAD(status) (status & GXS_SERV::GXS_MSG_STATUS_UNREAD)
#define IS_GROUP_ADMIN(subscribeFlags) (subscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
#define IS_GROUP_SUBSCRIBED(subscribeFlags) (subscribeFlags & (GXS_SERV::GROUP_SUBSCRIBE_ADMIN | GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED))
/* The Main Interface Class - for information about your Peers */
class RsGxsForums;
extern RsGxsForums *rsGxsForums;
class RsGxsForumGroup
{
public:
RsGroupMetaData mMeta;
std::string mDescription;
};
class RsGxsForumMsg
{
public:
RsMsgMetaData mMeta;
std::string mMsg;
};
//typedef std::map<RsGxsGroupId, std::vector<RsGxsForumMsg> > GxsForumMsgResult;
std::ostream &operator<<(std::ostream &out, const RsGxsForumGroup &group);
std::ostream &operator<<(std::ostream &out, const RsGxsForumMsg &msg);
class RsGxsForums: public RsGxsIfaceImpl
{
public:
RsGxsForums(RsGenExchange *gxs)
:RsGxsIfaceImpl(gxs) { return; }
virtual ~RsGxsForums() { return; }
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsForumGroup> &groups) = 0;
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs) = 0;
virtual bool getRelatedMessages(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs) = 0;
//////////////////////////////////////////////////////////////////////////////
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
//virtual bool groupRestoreKeys(const std::string &groupId);
//virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group) = 0;
virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg) = 0;
};
#endif

View file

@ -17,6 +17,7 @@ class RsGxsNotify
{ {
public: public:
RsGxsNotify(){ return; } RsGxsNotify(){ return; }
virtual ~RsGxsNotify() {return; }
}; };

View file

@ -10,7 +10,7 @@
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation. * License Version 2.1 as published by the Free Software Foundation.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -30,332 +30,19 @@
#include <string> #include <string>
#include <list> #include <list>
// FLAGS WILL BE REUSED FROM RSDISTRIB -> FOR NOW. #include "gxs/rstokenservice.h"
#include <retroshare/rsdistrib.h> #include "gxs/rsgxsifaceimpl.h"
/********** Generic Token Request Interface ***********************
* This is packaged here, as most TokenServices will require ID Services too.
* The requests can be generic, but the reponses are service specific (dependent on data types).
*/
// This bit will be filled out over time.
#define RS_TOKREQOPT_MSG_VERSIONS 0x0001 // MSGRELATED: Returns All MsgIds with OrigMsgId = MsgId.
#define RS_TOKREQOPT_MSG_ORIGMSG 0x0002 // MSGLIST: All Unique OrigMsgIds in a Group.
#define RS_TOKREQOPT_MSG_LATEST 0x0004 // MSGLIST: All Latest MsgIds in Group. MSGRELATED: Latest MsgIds for Input Msgs.
#define RS_TOKREQOPT_MSG_THREAD 0x0010 // MSGRELATED: All Msgs in Thread. MSGLIST: All Unique Thread Ids in Group.
#define RS_TOKREQOPT_MSG_PARENT 0x0020 // MSGRELATED: All Children Msgs.
#define RS_TOKREQOPT_MSG_AUTHOR 0x0040 // MSGLIST: Messages from this AuthorId
// Status Filtering... should it be a different Option Field.
#define RS_TOKREQOPT_GROUP_UPDATED 0x0100 // GROUPLIST: Groups that have been updated.
#define RS_TOKREQOPT_MSG_UPDATED 0x0200 // MSGLIST: Msg that have been updated from specified groups.
#define RS_TOKREQOPT_MSG_UPDATED 0x0200 // MSGLIST: Msg that have been updated from specified groups.
// Read Status.
#define RS_TOKREQOPT_READ 0x0001
#define RS_TOKREQOPT_UNREAD 0x0002
#define RS_TOKREQ_ANSTYPE_LIST 0x0001
#define RS_TOKREQ_ANSTYPE_SUMMARY 0x0002
#define RS_TOKREQ_ANSTYPE_DATA 0x0003
class RsTokReqOptions
{
public:
RsTokReqOptions()
{
mOptions = 0;
mStatusFilter = 0; mStatusMask = 0; mSubscribeFilter = 0;
mBefore = 0; mAfter = 0;
}
uint32_t mOptions;
// Request specific matches with Group / Message Status.
// Should be usable with any Options... applied afterwards.
uint32_t mStatusFilter;
uint32_t mStatusMask;
uint32_t mSubscribeFilter; // Only for Groups.
// Time range... again applied after Options.
time_t mBefore;
time_t mAfter;
};
/*********************************************************
* Documentation for Groups Definitions.
*
* A Group is defined by:
* - TWO RSA Keys. (Admin Key & Publish Key)
* - Publish TS: Used to select the latest definition.
*
* - Operating Mode:
* - Circle (Public, External, Private).
* - Publish Mode: Encrypted / All-Signed / Only ThreadHead / None Required.
* - AuthorId: GPG Required / Any Required / Only if no Publish Signature.
*
* - Description:
* - Name & Description.
* - Optional AuthorId.
*
* Most of this information is contained inside the GroupMetaData.
* except for Actual Admin / Publish Keys, which are maintained internally.
*
*******
* - Group Definition must be signed by Admin Key, otherwise invalid.
* - Circle Definition controls distribution of Group and Messages, see section on this for more details.
* - Public parts of Keys are distributed with Definition.
* - Private parts can be distributed to select people via alternative channels.
* - A Message Requires at least one signature: publish or Author. This signature will be used as MsgId.
*
* Groups will operate in the following modes:
* 1) Public Forum: PublishMode = None Required, AuthorId: Required.
* 2) Closed Forum: PublishMode = All-Signed, AuthorId: Required.
* 3) Private Forum: PublishMode = Encrypted, AuthorId: Required.
*
* 4) Anon Channel: PublishMode = All-Signed, AuthorId: None.
* 5) Anon Channel with Comments: PublishMode = Only ThreadHead, AuthorId: If No Publish Signature.
* 6) Private Channel: PublishMode = Encrypted.
*
* 7) Personal Photos - with comments: PublishMode = Only ThreadHead, AuthorId: Required.
* 8) Personal Photos - no comments: PublishMode = All-Signed, AuthorId: Required.
*
* 9 ) Public Wiki: PublishMode = None Required, AuthorId: Required.
* 10) Closed Wiki: PublishMode = All-Signed, AuthorId: Required.
* 11) Private Wiki: PublishMode = Encrypted, AuthorId: Required.
*
* 12) Twitter: PublishMode = Only ThreadHead, AuthorId: Required.
*
* 13) Posted: PublishMode = None Required, AuthorId: Required.
*
*
******
*
* Additionally to this information. The MetaData also contains several fields which can
* be used to store local information for the benefit of the service.
*
* In Particular: MsgStatus & GroupStatus inform the service if the user has read the message or if anything has changed.
*
***/
// Control of Publish Signatures.
#define RSGXS_GROUP_SIGN_PUBLISH_MASK 0x000000ff
#define RSGXS_GROUP_SIGN_PUBLISH_ENCRYPTED 0x00000001
#define RSGXS_GROUP_SIGN_PUBLISH_ALLSIGNED 0x00000002
#define RSGXS_GROUP_SIGN_PUBLISH_THREADHEAD 0x00000004
#define RSGXS_GROUP_SIGN_PUBLISH_NONEREQ 0x00000008
// Author Signature.
#define RSGXS_GROUP_SIGN_AUTHOR_MASK 0x0000ff00
#define RSGXS_GROUP_SIGN_AUTHOR_GPG 0x00000100
#define RSGXS_GROUP_SIGN_AUTHOR_REQUIRED 0x00000200
#define RSGXS_GROUP_SIGN_AUTHOR_IFNOPUBSIGN 0x00000400
#define RSGXS_GROUP_SIGN_AUTHOR_NONE 0x00000800
// NB: That one signature is required...
// so some combinations are not possible. e.g.
// SIGN_PUBLISH_NONEREQ && SIGN_AUTHOR_NONE is not allowed.
// SIGN_PUBLISH_THREADHEAD && SIGN_AUTHOR_NONE is also invalid.
#define RSGXS_GROUP_SIGN_RESERVED_MASK 0xffff0000
// STATUS FLAGS: There is space here for Service specific flags - if they so desire.
//
// Msgs: UNREAD_BY_USER & PROCESSED are useful.
// Groups: NEW_MESSAGES & GROUP_UPDATED.
#define RSGXS_MSG_STATUS_MASK 0x0000000f
#define RSGXS_MSG_STATUS_READ 0x00000001 // New or Not New
#define RSGXS_MSG_STATUS_UNREAD_BY_USER 0x00000002
#define RSGXS_MSG_STATUS_UNPROCESSED 0x00000004 // By the Service.
#define RSGXS_MSG_STATUS_SERVICE_MASK 0xffff0000
#define RSGXS_GROUP_STATUS_MASK 0x0000000f
#define RSGXS_GROUP_STATUS_UPDATED 0x00000001
#define RSGXS_GROUP_STATUS_NEWGROUP 0x00000002
#define RSGXS_GROUP_STATUS_NEWMSG 0x00000004
#define RSGXS_GROUP_STATUS_SERVICE_MASK 0xffff0000
// Subscription Flags. (LOCAL)
#define RSGXS_GROUP_SUBSCRIBE_MASK 0x0000000f
#define RSGXS_GROUP_SUBSCRIBE_ADMIN 0x00000001
#define RSGXS_GROUP_SUBSCRIBE_PUBLISH 0x00000002
#define RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED 0x00000004
#define RSGXS_GROUP_SUBSCRIBE_MONITOR 0x00000008
// Some MACROS for EASE OF USE. (USED BY FORUMSV2 At the moment.
#define IS_MSG_UNREAD(status) ((status & RSGXS_MSG_STATUS_READ) == 0 || (status & RSGXS_MSG_STATUS_UNREAD_BY_USER))
#define IS_GROUP_ADMIN(subscribeFlags) (subscribeFlags & RSGXS_GROUP_SUBSCRIBE_ADMIN)
#define IS_GROUP_SUBSCRIBED(subscribeFlags) (subscribeFlags & (RSGXS_GROUP_SUBSCRIBE_ADMIN | RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED))
#define RSGXS_MAX_SERVICE_STRING 200 // Sensible limit for dbase usage.
class RsGroupMetaData
{
public:
RsGroupMetaData()
{
mGroupFlags = 0;
mSignFlags = 0;
mSubscribeFlags = 0;
mPop = 0;
mMsgCount = 0;
mLastPost = 0;
mGroupStatus = 0;
//mPublishTs = 0;
}
std::string mGroupId;
std::string mGroupName;
uint32_t mGroupFlags; // Service Specific Options ????
uint32_t mSignFlags; // Combination of RSGXS_GROUP_SIGN_PUBLISH_MASK & RSGXS_GROUP_SIGN_AUTHOR_MASK.
time_t mPublishTs; // Mandatory.
std::string mAuthorId; // Optional.
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
uint32_t mSubscribeFlags;
uint32_t mPop; // HOW DO WE DO THIS NOW.
uint32_t mMsgCount; // ???
time_t mLastPost; // ???
uint32_t mGroupStatus;
std::string mServiceString; // Service Specific Free-Form extra storage.
};
class RsMsgMetaData
{
public:
RsMsgMetaData()
{
mPublishTs = 0;
mMsgFlags = 0;
mMsgStatus = 0;
mChildTs = 0;
}
std::string mGroupId;
std::string mMsgId;
std::string mThreadId;
std::string mParentId;
std::string mOrigMsgId;
std::string mAuthorId;
std::string mMsgName;
time_t mPublishTs;
uint32_t mMsgFlags; // Whats this for? (Optional Service Specific - e.g. flag MsgType)
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
// normally READ / UNREAD flags. LOCAL Data.
uint32_t mMsgStatus;
time_t mChildTs;
std::string mServiceString; // Service Specific Free-Form extra storage.
};
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta);
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta);
class RsTokenService
{
public:
RsTokenService() { return; }
virtual ~RsTokenService() { return; }
/* changed? */
virtual bool updated() = 0;
/* Data Requests */
virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds) = 0;
virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds) = 0;
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &msgIds) = 0;
/* Generic Lists */
virtual bool getGroupList( const uint32_t &token, std::list<std::string> &groupIds) = 0;
virtual bool getMsgList( const uint32_t &token, std::list<std::string> &msgIds) = 0;
/* Generic Summary */
virtual bool getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo) = 0;
virtual bool getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo) = 0;
/* Actual Data -> specific to Interface */
/* Poll */
virtual uint32_t requestStatus(const uint32_t token) = 0;
/* Cancel Request */
virtual bool cancelRequest(const uint32_t &token) = 0;
//////////////////////////////////////////////////////////////////////////////
/* Functions from Forums -> need to be implemented generically */
// Groups Changed is now part of requestGroupInfo request.
//virtual bool groupsChanged(std::list<std::string> &groupIds) = 0;
// Message/Group Status - is retrived via requests...
// These operations could have a token, but for the moment we are going to assume
// they are async and always succeed - (or fail silently).
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) = 0;
virtual bool setGroupStatus(const std::string &grpId, const uint32_t status, const uint32_t statusMask) = 0;
virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) = 0;
virtual bool setMessageServiceString(const std::string &msgId, const std::string &str) = 0;
virtual bool setGroupServiceString(const std::string &grpId, const std::string &str) = 0;
// (FUTURE WORK).
virtual bool groupRestoreKeys(const std::string &groupId) = 0;
virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers) = 0;
};
/* The Main Interface Class - for information about your Peers */ /* The Main Interface Class - for information about your Peers */
class RsIdentity; class RsIdentity;
extern RsIdentity *rsIdentity; extern RsIdentity *rsIdentity;
// GroupFlags: Only one so far:
#define RSGXSID_GROUPFLAG_REALID 0x0001
// THESE ARE FLAGS FOR INTERFACE.
#define RSID_TYPE_MASK 0xff00 #define RSID_TYPE_MASK 0xff00
#define RSID_RELATION_MASK 0x00ff #define RSID_RELATION_MASK 0x00ff
@ -370,9 +57,10 @@ extern RsIdentity *rsIdentity;
std::string rsIdTypeToString(uint32_t idtype); std::string rsIdTypeToString(uint32_t idtype);
class RsIdGroup class RsGxsIdGroup
{ {
public: public:
RsGxsIdGroup():mPgpKnown(false) { return; }
RsGroupMetaData mMeta; RsGroupMetaData mMeta;
@ -380,22 +68,28 @@ class RsIdGroup
// In GroupMetaData. // In GroupMetaData.
//std::string mNickname; (mGroupName) //std::string mNickname; (mGroupName)
//std::string mKeyId; (mGroupId) //std::string mKeyId; (mGroupId)
//uint32_t mIdType; (mGroupFlags)
uint32_t mIdType; // SHA(KeyId + Gpg Fingerprint) -> can only be IDed if GPG known.
// The length of the input must be long enough to make brute force search implausible.
std::string mGpgIdHash; // SHA(KeyId + Gpg Fingerprint) -> can only be IDed if GPG known. // Easy to do 1e9 SHA-1 hash computations per second on a GPU.
// We will need a minimum of 256 bits, ideally 1024 bits or 2048 bits.
// NOTE: These cannot be transmitted as part of underlying messages.... // Actually PgpIdHash is SHA1(.mMeta.mGroupId + PGPHandler->GpgFingerprint(ownId))
// Must use ServiceString. // ??? 160 bits.
bool mGpgIdKnown; // if GpgIdHash has been identified.
std::string mGpgId; // if known. std::string mPgpIdHash;
std::string mGpgName; // if known. std::string mPgpIdSign; // Need a signature as proof - otherwise anyone could add others Hashes.
std::string mGpgEmail; // if known.
// Not Serialised - for GUI's benefit.
bool mPgpKnown;
std::string mPgpId;
}; };
class RsIdMsg class RsGxsIdOpinion
{ {
public: public:
@ -405,7 +99,11 @@ class RsIdMsg
//std::string mKeyId; (mGroupId) //std::string mKeyId; (mGroupId)
//std::string mPeerId; (mAuthorId) ??? //std::string mPeerId; (mAuthorId) ???
int mOpinion; uint32_t mOpinion;
// NOT SERIALISED YET!
double mReputation; double mReputation;
//int mRating; //int mRating;
//int mPeersRating; //int mPeersRating;
@ -413,11 +111,18 @@ class RsIdMsg
}; };
// This will probably be dropped.
class RsGxsIdComment
{
public:
std::ostream &operator<<(std::ostream &out, const RsIdGroup &meta); RsMsgMetaData mMeta;
std::ostream &operator<<(std::ostream &out, const RsIdMsg &meta); std::string mComment;
};
std::ostream &operator<<(std::ostream &out, const RsGxsIdGroup &group);
std::ostream &operator<<(std::ostream &out, const RsGxsIdOpinion &msg);
#if 0 #if 0
class RsIdReputation class RsIdReputation
@ -448,80 +153,84 @@ class RsIdOpinion
#endif #endif
class RsIdentity: public RsTokenService // DATA TYPE FOR EXTERNAL INTERFACE.
typedef std::string RsGxsId; // TMP. =>
class RsIdentityDetails
{ {
public: public:
RsIdentityDetails()
:mIsOwnId(false), mPgpLinked(false), mPgpKnown(false),
mOpinion(0), mReputation(0) { return; }
RsIdentity() { return; } RsGxsId mId;
virtual ~RsIdentity() { return; }
// identity details.
std::string mNickname;
bool mIsOwnId;
/* INCLUDES INTERFACE FROM RS TOKEN SERVICE */ // PGP Stuff.
////////////////////////////////////////////////////////////////////////////// bool mPgpLinked;
bool mPgpKnown;
std::string mPgpId;
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsIdGroup &group) = 0;
virtual bool getMsgData(const uint32_t &token, RsIdMsg &msg) = 0;
virtual bool createGroup(uint32_t &token, RsIdGroup &group, bool isNew) = 0;
virtual bool createMsg(uint32_t &token, RsIdMsg &msg, bool isNew) = 0;
/* In the Identity System - You don't access the Messages Directly.
* as they represent idividuals opinions....
* This is reflected in the TokenService calls returning false.
*
* Below is the additional interface to look at reputation.
*/
/* So we will want to cache much of the identity stuff, so that we have quick access to the results.
* The following bits of data will not use the request/response interface, and should be available immediately.
*
* ID => Nickname, knownGPG, reputation.
*
* This will require quite a bit of data...
* 20 Bytes + 50 + 1 + 4 Bytes? (< 100 Bytes).
* x 10,000 IDs. => ~1 MB of cache (Good).
* x 100,000 IDs. => ~10 MB of cache (Good).
* x 1,000,000 IDs. => ~100 MB of cache (Too Big).
*
* We also need to store quick access to your OwnIds.
*/
//virtual uint32_t getIdDetails(const std::string &id, std::string &nickname, bool &isGpgKnown,
// uint32_t &ownOpinion, float &reputation);
//virtual uint32_t getOwnIds(std::list<std::string> &ownIds);
//virtual bool setOpinion(const std::string &id, uint32_t opinion);
virtual void generateDummyData() = 0;
#if 0
/* Data Requests */
virtual bool requestIdentityList(uint32_t &token) = 0;
virtual bool requestIdentities(uint32_t &token, const std::list<std::string> &ids) = 0;
virtual bool requestIdReputations(uint32_t &token, const std::list<std::string> &ids) = 0;
virtual bool requestIdPeerOpinion(uint32_t &token, const std::string &aboutId, const std::string &peerId) = 0;
//virtual bool requestIdGpgDetails(uint32_t &token, const std::list<std::string> &ids) = 0;
/* Poll */
virtual uint32_t requestStatus(const uint32_t token) = 0;
/* Retrieve Data */
virtual bool getIdentityList(const uint32_t token, std::list<std::string> &ids) = 0;
virtual bool getIdentity(const uint32_t token, RsIdData &data) = 0;
virtual bool getIdReputation(const uint32_t token, RsIdReputation &reputation) = 0;
virtual bool getIdPeerOpinion(const uint32_t token, RsIdOpinion &opinion) = 0;
/* Updates */
virtual bool updateIdentity(RsIdData &data) = 0;
virtual bool updateOpinion(RsIdOpinion &opinion) = 0;
#endif
// reputation details.
double mOpinion;
double mReputation;
}; };
class RsIdOpinion
{
public:
RsGxsId id;
int rating;
};
#endif class RsIdentityParameters
{
public:
RsIdentityParameters(): isPgpLinked(false) { return; }
bool isPgpLinked;
std::string nickname;
};
class RsIdentity: public RsGxsIfaceImpl
{
public:
RsIdentity(RsGenExchange *gxs): RsGxsIfaceImpl(gxs) { return; }
virtual ~RsIdentity() { return; }
/********************************************************************************************/
/********************************************************************************************/
// For Other Services....
// It should be impossible for them to get a message which we don't have the identity.
// Its a major error if we don't have the identity.
// We cache all identities, and provide alternative (instantaneous)
// functions to extract info, rather than the standard Token system.
//virtual bool getNickname(const RsGxsId &id, std::string &nickname) = 0;
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details) = 0;
virtual bool getOwnIds(std::list<RsGxsId> &ownIds) = 0;
//
virtual bool submitOpinion(uint32_t& token, RsIdOpinion &opinion) = 0;
virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params) = 0;
// Specific RsIdentity Functions....
/* Specific Service Data */
/* We expose these initially for testing / GUI purposes.
*/
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0;
};
#endif // RETROSHARE_IDENTITY_GUI_INTERFACE_H

View file

@ -1,179 +1,347 @@
#ifndef RETROSHARE_PHOTO_GUI_INTERFACE_H #ifndef RSPHOTOV2_H
#define RETROSHARE_PHOTO_GUI_INTERFACE_H #define RSPHOTOV2_H
/* /*
* libretroshare/src/retroshare: rsphoto.h * libretroshare/src/retroshare: rsphoto.h
* *
* RetroShare C++ Interface. * RetroShare C++ Interface.
* *
* Copyright 2008-2012 by Robert Fernie. * Copyright 2008-2012 by Robert Fernie, Christopher Evi-Parker
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation. * License Version 2 as published by the Free Software Foundation.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details. * Library General Public License for more details.
* *
* You should have received a copy of the GNU Library General Public * You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA. * USA.
* *
* Please report all bugs and problems to "retroshare@lunamutt.com". * Please report all bugs and problems to "retroshare@lunamutt.com".
* *
*/ */
#include <inttypes.h> #include <inttypes.h>
#include <string> #include <string>
#include <list> #include <list>
#include <retroshare/rsidentity.h> #include "rsgxsservice.h"
/* The Main Interface Class - for information about your Peers */ /* The Main Interface Class - for information about your Peers */
class RsPhoto; class RsPhoto;
extern RsPhoto *rsPhoto; extern RsPhoto *rsPhoto;
/******************* NEW STUFF FOR NEW CACHE SYSTEM *********/ /******************* NEW STUFF FOR NEW CACHE SYSTEM *********/
#define RSPHOTO_MODE_NEW 1 #define RSPHOTO_MODE_NEW 1
#define RSPHOTO_MODE_OWN 2 #define RSPHOTO_MODE_OWN 2
#define RSPHOTO_MODE_REMOTE 3 #define RSPHOTO_MODE_REMOTE 3
class RsPhotoThumbnail class RsPhotoThumbnail
{ {
public: public:
RsPhotoThumbnail() RsPhotoThumbnail()
:data(NULL), size(0), type("N/A") { return; } :data(NULL), size(0), type("N/A") { return; }
bool deleteImage(); bool deleteImage();
bool copyFrom(const RsPhotoThumbnail &nail); bool copyFrom(const RsPhotoThumbnail &nail);
// Holds Thumbnail image. // Holds Thumbnail image.
uint8_t *data; uint8_t *data;
int size; int size;
std::string type; std::string type;
}; };
/* If these flags are no set - the Photo inherits values from the Album
/* If these flags are no set - the Photo inherits values from the Album */
*/
#define RSPHOTO_FLAGS_ATTRIB_TITLE 0x0001
#define RSPHOTO_FLAGS_ATTRIB_TITLE 0x0001 #define RSPHOTO_FLAGS_ATTRIB_CAPTION 0x0002
#define RSPHOTO_FLAGS_ATTRIB_CAPTION 0x0002 #define RSPHOTO_FLAGS_ATTRIB_DESC 0x0004
#define RSPHOTO_FLAGS_ATTRIB_DESC 0x0004 #define RSPHOTO_FLAGS_ATTRIB_PHOTOGRAPHER 0x0008
#define RSPHOTO_FLAGS_ATTRIB_PHOTOGRAPHER 0x0008 #define RSPHOTO_FLAGS_ATTRIB_WHERE 0x0010
#define RSPHOTO_FLAGS_ATTRIB_WHERE 0x0010 #define RSPHOTO_FLAGS_ATTRIB_WHEN 0x0020
#define RSPHOTO_FLAGS_ATTRIB_WHEN 0x0020 #define RSPHOTO_FLAGS_ATTRIB_OTHER 0x0040
#define RSPHOTO_FLAGS_ATTRIB_OTHER 0x0040 #define RSPHOTO_FLAGS_ATTRIB_CATEGORY 0x0080
#define RSPHOTO_FLAGS_ATTRIB_CATEGORY 0x0080 #define RSPHOTO_FLAGS_ATTRIB_HASHTAGS 0x0100
#define RSPHOTO_FLAGS_ATTRIB_HASHTAGS 0x0100 #define RSPHOTO_FLAGS_ATTRIB_ORDER 0x0200
#define RSPHOTO_FLAGS_ATTRIB_ORDER 0x0200 #define RSPHOTO_FLAGS_ATTRIB_THUMBNAIL 0x0400
#define RSPHOTO_FLAGS_ATTRIB_THUMBNAIL 0x0400 #define RSPHOTO_FLAGS_ATTRIB_MODE 0x0800
#define RSPHOTO_FLAGS_ATTRIB_MODE 0x0800 #define RSPHOTO_FLAGS_ATTRIB_AUTHOR 0x1000 // PUSH UP ORDER
#define RSPHOTO_FLAGS_ATTRIB_AUTHOR 0x1000 // PUSH UP ORDER #define RSPHOTO_FLAGS_ATTRIB_PHOTO 0x2000 // PUSH UP ORDER.
#define RSPHOTO_FLAGS_ATTRIB_PHOTO 0x2000 // PUSH UP ORDER.
class RsPhotoPhoto
{
class RsPhotoPhoto public:
{
public: RsMsgMetaData mMeta;
RsMsgMetaData mMeta; RsPhotoPhoto();
RsPhotoPhoto(); // THESE ARE IN THE META DATA.
//std::string mAlbumId;
// THESE ARE IN THE META DATA. //std::string mId;
//std::string mAlbumId; //std::string mTitle; // only used by Album.
//std::string mId; std::string mCaption;
//std::string mTitle; // only used by Album. std::string mDescription;
std::string mCaption; std::string mPhotographer;
std::string mDescription; std::string mWhere;
std::string mPhotographer; std::string mWhen;
std::string mWhere; std::string mOther;
std::string mWhen; std::string mCategory;
std::string mOther;
std::string mCategory; std::string mHashTags;
std::string mHashTags; uint32_t mSetFlags;
uint32_t mSetFlags; int mOrder;
int mOrder; RsPhotoThumbnail mThumbnail;
RsPhotoThumbnail mThumbnail; int mMode;
int mMode; // These are not saved.
std::string path; // if in Mode NEW.
// These are not saved. uint32_t mModFlags;
std::string path; // if in Mode NEW. };
uint32_t mModFlags;
}; class RsPhotoAlbumShare
{
class RsPhotoAlbumShare public:
{
public: uint32_t mShareType;
std::string mShareGroupId;
uint32_t mShareType; std::string mPublishKey;
std::string mShareGroupId; uint32_t mCommentMode;
std::string mPublishKey; uint32_t mResizeMode;
uint32_t mCommentMode; };
uint32_t mResizeMode;
}; class RsPhotoAlbum
{
class RsPhotoAlbum public:
{ RsPhotoAlbum();
public:
RsPhotoAlbum(); RsGroupMetaData mMeta;
RsGroupMetaData mMeta; // THESE ARE IN THE META DATA.
//std::string mAlbumId;
// THESE ARE IN THE META DATA. //std::string mTitle; // only used by Album.
//std::string mAlbumId;
//std::string mTitle; // only used by Album. std::string mCaption;
std::string mDescription;
std::string mCaption; std::string mPhotographer;
std::string mDescription; std::string mWhere;
std::string mPhotographer; std::string mWhen;
std::string mWhere; std::string mOther;
std::string mWhen; std::string mCategory;
std::string mOther;
std::string mCategory; std::string mHashTags;
std::string mHashTags; RsPhotoThumbnail mThumbnail;
RsPhotoThumbnail mThumbnail; int mMode;
int mMode; std::string mPhotoPath;
RsPhotoAlbumShare mShareOptions;
std::string mPhotoPath;
RsPhotoAlbumShare mShareOptions; // These aren't saved.
uint32_t mSetFlags;
// These aren't saved. uint32_t mModFlags;
uint32_t mSetFlags; };
uint32_t mModFlags;
}; class RsGxsPhotoCommentItem;
class RsPhotoComment
std::ostream &operator<<(std::ostream &out, const RsPhotoPhoto &photo); {
std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album); public:
RsPhotoComment();
class RsPhoto: public RsTokenService RsPhotoComment(const RsGxsPhotoCommentItem& comment);
{
public: RsPhotoComment& operator=(const RsGxsPhotoCommentItem& comment);
RsPhoto() { return; } RsMsgMetaData mMeta;
virtual ~RsPhoto() { return; }
std::string mComment;
/* Specific Service Data */ uint32_t mCommentFlag;
virtual bool getAlbum(const uint32_t &token, RsPhotoAlbum &album) = 0; };
virtual bool getPhoto(const uint32_t &token, RsPhotoPhoto &photo) = 0;
std::ostream &operator<<(std::ostream &out, const RsPhotoPhoto &photo);
virtual bool submitAlbumDetails(uint32_t &token, RsPhotoAlbum &album, bool isNew) = 0; std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album);
virtual bool submitPhoto(uint32_t &token, RsPhotoPhoto &photo, bool isNew) = 0;
typedef std::map<RsGxsGroupId, std::vector<RsPhotoPhoto> > PhotoResult;
}; typedef std::map<RsGxsGroupId, std::vector<RsPhotoComment> > PhotoCommentResult;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsPhotoComment> > PhotoRelatedCommentResult;
#endif class RsPhoto
{
public:
static const uint32_t FLAG_MSG_TYPE_PHOTO_POST;
static const uint32_t FLAG_MSG_TYPE_PHOTO_COMMENT;
static const uint32_t FLAG_MSG_TYPE_MASK;
RsPhoto() { return; }
virtual ~RsPhoto() { return; }
/*!
* Use to enquire if groups or msgs have changed
* Poll regularly, particularly after a photo submission
* @return true if msgs or groups have changed
*/
virtual bool updated() = 0;
/*!
*
* @param grpIds
*/
virtual void groupsChanged(std::list<RsGxsGroupId>& grpIds) = 0;
/*!
*
* @param msgs
*/
virtual void msgsChanged(GxsMsgIdResult& msgs) = 0;
/*!
* To acquire a handle to token service handler
* needed to make requests to the service
* @return handle to token service for this gxs service
*/
virtual RsTokenService* getTokenService() = 0;
/* Generic Lists */
/*!
*
* @param token token to be redeemed for this request
* @param groupIds the ids return for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getGroupList(const uint32_t &token,
std::list<RsGxsGroupId> &groupIds) = 0;
/*!
* @param token token to be redeemed for this request
* @param msgIds the ids return for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getMsgList(const uint32_t &token,
GxsMsgIdResult &msgIds) = 0;
/* Generic Summary */
/*!
* @param token token to be redeemed for group summary request
* @param groupInfo the ids returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getGroupSummary(const uint32_t &token,
std::list<RsGroupMetaData> &groupInfo) = 0;
/*!
* @param token token to be redeemed for message summary request
* @param msgInfo the message metadata returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getMsgSummary(const uint32_t &token,
MsgMetaResult &msgInfo) = 0;
/* Specific Service Data */
/*!
* @param token token to be redeemed for album request
* @param album the album returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getAlbum(const uint32_t &token, std::vector<RsPhotoAlbum> &album) = 0;
/*!
* @param token token to be redeemed for photo request
* @param photo the photo returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getPhoto(const uint32_t &token,
PhotoResult &photo) = 0;
/* details are updated in album - to choose Album ID, and storage path */
/*!
* @param token token to be redeemed for photo request
* @param photo the photo returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getPhotoComment(const uint32_t &token,
PhotoCommentResult& comments) = 0;
/*!
* @param token token to be redeemed for photo request
* @param photo the photo returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getPhotoRelatedComment(const uint32_t &token, PhotoRelatedCommentResult &comments) = 0;
/*!
* submits album, which returns a token that needs
* to be acknowledge to get album grp id
* @param token token to redeem for acknowledgement
* @param album album to be submitted
*/
virtual bool submitAlbumDetails(uint32_t& token, RsPhotoAlbum &album) = 0;
/*!
* submits photo, which returns a token that needs
* to be acknowledged to get photo msg-grp id pair
* @param token token to redeem for acknowledgement
* @param photo photo to be submitted
*/
virtual bool submitPhoto(uint32_t& token, RsPhotoPhoto &photo) = 0;
/*!
* submits photo comment, which returns a token that needs
* to be acknowledged to get photo msg-grp id pair
* The mParentId needs to be set to an existing msg for which
* commenting is enabled
* @param token token to redeem for acknowledgement
* @param comment comment to be submitted
*/
virtual bool submitComment(uint32_t& token, RsPhotoComment &photo) = 0;
/*!
* subscribes to group, and returns token which can be used
* to be acknowledged to get group Id
* @param token token to redeem for acknowledgement
* @param grpId the id of the group to subscribe to
*/
virtual bool subscribeToAlbum(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe) = 0;
/*!
* This allows the client service to acknowledge that their msgs has
* been created/modified and retrieve the create/modified msg ids
* @param token the token related to modification/create request
* @param msgIds map of grpid->msgIds of message created/modified
* @return true if token exists false otherwise
*/
virtual bool acknowledgeMsg(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId) = 0;
/*!
* This allows the client service to acknowledge that their grps has
* been created/modified and retrieve the create/modified grp ids
* @param token the token related to modification/create request
* @param msgIds vector of ids of groups created/modified
* @return true if token exists false otherwise
*/
virtual bool acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId) = 0;
};
#endif // RSPHOTOV2_H

View file

@ -1,277 +0,0 @@
#ifndef RSPHOTOV2_H
#define RSPHOTOV2_H
/*
* libretroshare/src/retroshare: rsphoto.h
*
* RetroShare C++ Interface.
*
* Copyright 2008-2012 by Robert Fernie, 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".
*
*/
#include <inttypes.h>
#include <string>
#include <list>
#include "rsgxsservice.h"
/* The Main Interface Class - for information about your Peers */
class RsPhoto;
extern RsPhoto *rsPhoto;
/******************* NEW STUFF FOR NEW CACHE SYSTEM *********/
#define RSPHOTO_MODE_NEW 1
#define RSPHOTO_MODE_OWN 2
#define RSPHOTO_MODE_REMOTE 3
class RsPhotoThumbnail
{
public:
RsPhotoThumbnail()
:data(NULL), size(0), type("N/A") { return; }
bool deleteImage();
bool copyFrom(const RsPhotoThumbnail &nail);
// Holds Thumbnail image.
uint8_t *data;
int size;
std::string type;
};
/* If these flags are no set - the Photo inherits values from the Album
*/
#define RSPHOTO_FLAGS_ATTRIB_TITLE 0x0001
#define RSPHOTO_FLAGS_ATTRIB_CAPTION 0x0002
#define RSPHOTO_FLAGS_ATTRIB_DESC 0x0004
#define RSPHOTO_FLAGS_ATTRIB_PHOTOGRAPHER 0x0008
#define RSPHOTO_FLAGS_ATTRIB_WHERE 0x0010
#define RSPHOTO_FLAGS_ATTRIB_WHEN 0x0020
#define RSPHOTO_FLAGS_ATTRIB_OTHER 0x0040
#define RSPHOTO_FLAGS_ATTRIB_CATEGORY 0x0080
#define RSPHOTO_FLAGS_ATTRIB_HASHTAGS 0x0100
#define RSPHOTO_FLAGS_ATTRIB_ORDER 0x0200
#define RSPHOTO_FLAGS_ATTRIB_THUMBNAIL 0x0400
#define RSPHOTO_FLAGS_ATTRIB_MODE 0x0800
#define RSPHOTO_FLAGS_ATTRIB_AUTHOR 0x1000 // PUSH UP ORDER
#define RSPHOTO_FLAGS_ATTRIB_PHOTO 0x2000 // PUSH UP ORDER.
class RsPhotoPhoto
{
public:
RsMsgMetaData mMeta;
RsPhotoPhoto();
// THESE ARE IN THE META DATA.
//std::string mAlbumId;
//std::string mId;
//std::string mTitle; // only used by Album.
std::string mCaption;
std::string mDescription;
std::string mPhotographer;
std::string mWhere;
std::string mWhen;
std::string mOther;
std::string mCategory;
std::string mHashTags;
uint32_t mSetFlags;
int mOrder;
RsPhotoThumbnail mThumbnail;
int mMode;
// These are not saved.
std::string path; // if in Mode NEW.
uint32_t mModFlags;
};
class RsPhotoAlbumShare
{
public:
uint32_t mShareType;
std::string mShareGroupId;
std::string mPublishKey;
uint32_t mCommentMode;
uint32_t mResizeMode;
};
class RsPhotoAlbum
{
public:
RsPhotoAlbum();
RsGroupMetaData mMeta;
// THESE ARE IN THE META DATA.
//std::string mAlbumId;
//std::string mTitle; // only used by Album.
std::string mCaption;
std::string mDescription;
std::string mPhotographer;
std::string mWhere;
std::string mWhen;
std::string mOther;
std::string mCategory;
std::string mHashTags;
RsPhotoThumbnail mThumbnail;
int mMode;
std::string mPhotoPath;
RsPhotoAlbumShare mShareOptions;
// These aren't saved.
uint32_t mSetFlags;
uint32_t mModFlags;
};
std::ostream &operator<<(std::ostream &out, const RsPhotoPhoto &photo);
std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album);
typedef std::map<RsGxsGroupId, std::vector<RsPhotoPhoto> > PhotoResult;
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > MsgMetaResult;
class RsPhotoV2
{
public:
RsPhotoV2() { return; }
virtual ~RsPhotoV2() { return; }
/*!
* Use to enquire if groups or msgs have changed
* Poll regularly, particularly after a photo submission
* @return true if msgs or groups have changed
*/
virtual bool updated() = 0;
/*!
*
* @param grpIds
*/
virtual void groupsChanged(std::list<RsGxsGroupId>& grpIds) = 0;
/*!
*
* @param msgs
*/
virtual void msgsChanged(GxsMsgIdResult& msgs) = 0;
/*!
* To acquire a handle to token service handler
* needed to make requests to the service
* @return handle to token service for this gxs service
*/
virtual RsTokenServiceV2* getTokenService() = 0;
/* Generic Lists */
/*!
*
* @param token token to be redeemed for this request
* @param groupIds the ids return for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getGroupList(const uint32_t &token,
std::list<RsGxsGroupId> &groupIds) = 0;
/*!
* @param token token to be redeemed for this request
* @param msgIds the ids return for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getMsgList(const uint32_t &token,
GxsMsgIdResult &msgIds) = 0;
/* Generic Summary */
/*!
* @param token token to be redeemed for group summary request
* @param groupInfo the ids returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getGroupSummary(const uint32_t &token,
std::list<RsGroupMetaData> &groupInfo) = 0;
/*!
* @param token token to be redeemed for message summary request
* @param msgInfo the message metadata returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getMsgSummary(const uint32_t &token,
MsgMetaResult &msgInfo) = 0;
/* Specific Service Data */
/*!
* @param token token to be redeemed for album request
* @param album the album returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getAlbum(const uint32_t &token, std::vector<RsPhotoAlbum> &album) = 0;
/*!
* @param token token to be redeemed for photo request
* @param photo the photo returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getPhoto(const uint32_t &token,
PhotoResult &photo) = 0;
/* details are updated in album - to choose Album ID, and storage path */
/*!
* This RsGenExchange service will be alerted to this album as \n
* a new album. Do not keep the submitted album as representative, wait for
* notification telling of successful submission
* @param album The album to be submitted
* @return false if submission failed
*/
virtual bool submitAlbumDetails(RsPhotoAlbum &album) = 0;
/*!
* This RsGenExchange service will be alerted to this photo as \n
* a new photo. Do not keep the submitted photo as representative, wait for new photo
* returned
* @param photo photo to submit
* @return
*/
virtual bool submitPhoto(RsPhotoPhoto &photo) = 0;
};
#endif // RSPHOTOV2_H

View file

@ -105,6 +105,9 @@ class RsPlugin
virtual RsPQIService *rs_pqi_service() const { return NULL ; } virtual RsPQIService *rs_pqi_service() const { return NULL ; }
virtual uint16_t rs_service_id() const { return 0 ; } virtual uint16_t rs_service_id() const { return 0 ; }
// Shutdown
virtual void stop() {}
// Filename used for saving the specific plugin configuration. Both RsCacheService and RsPQIService // Filename used for saving the specific plugin configuration. Both RsCacheService and RsPQIService
// derive from p3Config, which means that the service provided by the plugin can load/save its own // derive from p3Config, which means that the service provided by the plugin can load/save its own
// config by deriving loadList() and saveList() from p3Config. // config by deriving loadList() and saveList() from p3Config.

View file

@ -1,140 +1,187 @@
#ifndef RETROSHARE_POSTED_GUI_INTERFACE_H #ifndef RSPOSTED_H
#define RETROSHARE_POSTED_GUI_INTERFACE_H #define RSPOSTED_H
/*
* libretroshare/src/retroshare: rsposted.h /*
* * libretroshare/src/retroshare: rsposted.h
* RetroShare C++ Interface. *
* * RetroShare C++ Interface.
* Copyright 2008-2012 by Robert Fernie. *
* * Copyright 2008-2012 by Robert Fernie, 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 * This library is free software; you can redistribute it and/or
* License Version 2 as published by the Free Software Foundation. * 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 * This library is distributed in the hope that it will be useful,
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * but WITHOUT ANY WARRANTY; without even the implied warranty of
* Library General Public License for more details. * 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 * You should have received a copy of the GNU Library General Public
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * License along with this library; if not, write to the Free Software
* USA. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* * USA.
* Please report all bugs and problems to "retroshare@lunamutt.com". *
* * Please report all bugs and problems to "retroshare@lunamutt.com".
*/ *
*/
#include <inttypes.h>
#include <string> #include <inttypes.h>
#include <list> #include <string>
#include <retroshare/rsidentity.h> #include <list>
#include "gxs/rstokenservice.h"
/* The Main Interface Class - for information about your Peers */ #include "gxs/rsgxsifaceimpl.h"
class RsPosted;
extern RsPosted *rsPosted; class RsPosted;
extern RsPosted *rsPosted;
class RsPostedGroup /* The Main Interface Class - for information about your Peers */
{
public: class RsPostedGroup
RsGroupMetaData mMeta; {
RsPostedGroup() { return; } public:
}; RsGroupMetaData mMeta;
std::string mDescription;
class RsPostedMsg RsPostedGroup() { return; }
{ };
public:
RsPostedMsg(uint32_t t) //#define RSPOSTED_MSGTYPE_POST 0x0001
:postedType(t) { return; } //#define RSPOSTED_MSGTYPE_VOTE 0x0002
//#define RSPOSTED_MSGTYPE_COMMENT 0x0004
RsMsgMetaData mMeta;
uint32_t postedType; #define RSPOSTED_PERIOD_YEAR 1
}; #define RSPOSTED_PERIOD_MONTH 2
#define RSPOSTED_PERIOD_WEEK 3
#define RSPOSTED_MSGTYPE_POST 0x0001 #define RSPOSTED_PERIOD_DAY 4
#define RSPOSTED_MSGTYPE_VOTE 0x0002 #define RSPOSTED_PERIOD_HOUR 5
#define RSPOSTED_MSGTYPE_COMMENT 0x0004
#define RSPOSTED_VIEWMODE_LATEST 1
#define RSPOSTED_PERIOD_YEAR 1 #define RSPOSTED_VIEWMODE_TOP 2
#define RSPOSTED_PERIOD_MONTH 2 #define RSPOSTED_VIEWMODE_HOT 3
#define RSPOSTED_PERIOD_WEEK 3 #define RSPOSTED_VIEWMODE_COMMENTS 4
#define RSPOSTED_PERIOD_DAY 4
#define RSPOSTED_PERIOD_HOUR 5 class RsPostedPost;
class RsPostedComment;
#define RSPOSTED_VIEWMODE_LATEST 1 class RsPostedVote;
#define RSPOSTED_VIEWMODE_TOP 2 class RsPostedPostRanking;
#define RSPOSTED_VIEWMODE_HOT 3
#define RSPOSTED_VIEWMODE_COMMENTS 4 typedef std::map<RsGxsGroupId, std::vector<RsPostedPost> > PostedPostResult;
typedef std::map<RsGxsGroupId, std::vector<RsPostedComment> > PostedCommentResult;
typedef std::map<RsGxsGroupId, std::vector<RsPostedVote> > PostedVoteResult;
class RsPostedPost: public RsPostedMsg typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsPostedComment> > PostedRelatedCommentResult;
{ typedef std::pair<RsGxsGroupId, int32_t> GroupRank;
public: typedef std::map<uint32_t, RsGxsMessageId> PostedRanking;
RsPostedPost(): RsPostedMsg(RSPOSTED_MSGTYPE_POST)
{ std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
mMeta.mMsgFlags = RSPOSTED_MSGTYPE_POST; std::ostream &operator<<(std::ostream &out, const RsPostedPost &post);
return; std::ostream &operator<<(std::ostream &out, const RsPostedVote &vote);
} std::ostream &operator<<(std::ostream &out, const RsPostedComment &comment);
};
class RsPostedVote: public RsPostedMsg class RsPosted : public RsGxsIfaceImpl
{ {
public: public:
RsPostedVote(): RsPostedMsg(RSPOSTED_MSGTYPE_VOTE)
{ enum RankType {TopRankType, HotRankType, NewRankType };
mMeta.mMsgFlags = RSPOSTED_MSGTYPE_VOTE;
return; static const uint32_t FLAG_MSGTYPE_POST;
} static const uint32_t FLAG_MSGTYPE_VOTE;
}; static const uint32_t FLAG_MSGTYPE_COMMENT;
static const uint32_t FLAG_MSGTYPE_MASK;
class RsPostedComment: public RsPostedMsg
{ RsPosted(RsGenExchange* gxs) : RsGxsIfaceImpl(gxs) { return; }
public: virtual ~RsPosted() { return; }
RsPostedComment(): RsPostedMsg(RSPOSTED_MSGTYPE_COMMENT)
{ /* Specific Service Data */
mMeta.mMsgFlags = RSPOSTED_MSGTYPE_COMMENT;
return; virtual bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group) = 0;
} virtual bool getPost(const uint32_t &token, PostedPostResult &post) = 0;
}; virtual bool getComment(const uint32_t &token, PostedCommentResult &comment) = 0;
virtual bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult& comments) = 0;
virtual bool getPostRanking(const uint32_t& token, RsPostedPostRanking& ranking) = 0;
std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
std::ostream &operator<<(std::ostream &out, const RsPostedPost &post); virtual bool submitGroup(uint32_t &token, RsPostedGroup &group) = 0;
std::ostream &operator<<(std::ostream &out, const RsPostedVote &vote); virtual bool submitPost(uint32_t &token, RsPostedPost &post) = 0;
std::ostream &operator<<(std::ostream &out, const RsPostedComment &comment); virtual bool submitVote(uint32_t &token, RsPostedVote &vote) = 0;
virtual bool submitComment(uint32_t &token, RsPostedComment &comment) = 0;
class RsPosted: public RsTokenService virtual bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t& downVotes, uint32_t& nComments) const = 0;
{
public: // Special Ranking Request.
/*!
RsPosted() { return; } * Makes request for posts of a topic
virtual ~RsPosted() { return; } * @param token
* @param rType
/* Specific Service Data */ * @param groupId
virtual bool getGroup(const uint32_t &token, RsPostedGroup &group) = 0; */
virtual bool getPost(const uint32_t &token, RsPostedPost &post) = 0; virtual bool requestPostRankings(uint32_t &token, const RankType& rType, const RsGxsGroupId& groupId) = 0;
virtual bool getComment(const uint32_t &token, RsPostedComment &comment) = 0;
/*!
virtual bool submitGroup(uint32_t &token, RsPostedGroup &group, bool isNew) = 0; * Makes request for ranking of comments for a post
virtual bool submitPost(uint32_t &token, RsPostedPost &post, bool isNew) = 0; * @param token
virtual bool submitVote(uint32_t &token, RsPostedVote &vote, bool isNew) = 0; * @param rType type of ranking to collect
virtual bool submitComment(uint32_t &token, RsPostedComment &comment, bool isNew) = 0; * @param msgId message id of post as groupid-messageid pair
*/
// Special Ranking Request. virtual bool requestCommentRankings(uint32_t &token, const RankType& rType, const RsGxsGrpMsgIdPair& msgId) = 0;
virtual bool requestRanking(uint32_t &token, std::string groupId) = 0;
virtual bool getRankedPost(const uint32_t &token, RsPostedPost &post) = 0; };
virtual bool extractPostedCache(const std::string &str, uint32_t &votes, uint32_t &comments) = 0; class RsPostedPost
{
// exposed for testing... public:
virtual float calcPostScore(const RsMsgMetaData &meta) = 0; RsPostedPost()
{
}; mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_POST;
mMeta.mServiceString = " 0 0 0";
return;
#endif }
RsMsgMetaData mMeta;
std::string mLink;
std::string mNotes;
};
class RsGxsPostedVoteItem;
class RsPostedVote
{
public:
RsPostedVote(const RsGxsPostedVoteItem&);
RsPostedVote()
{
mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_VOTE;
return;
}
uint8_t mDirection;
RsMsgMetaData mMeta;
};
class RsGxsPostedCommentItem;
class RsPostedComment
{
public:
RsPostedComment()
{
mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_COMMENT;
return;
}
RsPostedComment(const RsGxsPostedCommentItem& );
std::string mComment;
RsMsgMetaData mMeta;
};
class RsPostedPostRanking
{
public:
RsGxsGroupId grpId;
PostedRanking ranking;
RsPosted::RankType rType;
};
#endif // RSPOSTED_H

View file

@ -0,0 +1,151 @@
#ifndef RETROSHARE_POSTED_GUI_INTERFACE_H
#define RETROSHARE_POSTED_GUI_INTERFACE_H
/*
* libretroshare/src/retroshare: rsposted.h
*
* RetroShare C++ Interface.
*
* Copyright 2008-2012 by Robert Fernie.
*
* 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".
*
*/
#include <inttypes.h>
#include <string>
#include <list>
#include <retroshare/rsidentityVEG.h>
/* The Main Interface Class - for information about your Peers */
class RsPostedVEG;
extern RsPostedVEG *rsPostedVEG;
class RsPostedGroup
{
public:
RsGroupMetaData mMeta;
RsPostedGroup() { return; }
};
class RsPostedMsg
{
public:
RsPostedMsg(uint32_t t)
:postedType(t) { return; }
RsMsgMetaData mMeta;
uint32_t postedType;
};
#define RSPOSTED_MSGTYPE_POST 0x0001
#define RSPOSTED_MSGTYPE_VOTE 0x0002
#define RSPOSTED_MSGTYPE_COMMENT 0x0004
#define RSPOSTED_PERIOD_YEAR 1
#define RSPOSTED_PERIOD_MONTH 2
#define RSPOSTED_PERIOD_WEEK 3
#define RSPOSTED_PERIOD_DAY 4
#define RSPOSTED_PERIOD_HOUR 5
#define RSPOSTED_VIEWMODE_LATEST 1
#define RSPOSTED_VIEWMODE_TOP 2
#define RSPOSTED_VIEWMODE_HOT 3
#define RSPOSTED_VIEWMODE_COMMENTS 4
class RsPostedPost: public RsPostedMsg
{
public:
RsPostedPost(): RsPostedMsg(RSPOSTED_MSGTYPE_POST)
{
mMeta.mMsgFlags = RSPOSTED_MSGTYPE_POST;
return;
}
std::string mLink;
std::string mNotes;
};
class RsPostedVote: public RsPostedMsg
{
public:
RsPostedVote(): RsPostedMsg(RSPOSTED_MSGTYPE_VOTE)
{
mMeta.mMsgFlags = RSPOSTED_MSGTYPE_VOTE;
return;
}
};
class RsPostedComment: public RsPostedMsg
{
public:
RsPostedComment(): RsPostedMsg(RSPOSTED_MSGTYPE_COMMENT)
{
mMeta.mMsgFlags = RSPOSTED_MSGTYPE_COMMENT;
return;
}
std::string mComment;
};
std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
std::ostream &operator<<(std::ostream &out, const RsPostedPost &post);
std::ostream &operator<<(std::ostream &out, const RsPostedVote &vote);
std::ostream &operator<<(std::ostream &out, const RsPostedComment &comment);
class RsPostedVEG: public RsTokenServiceVEG
{
public:
RsPostedVEG() { return; }
virtual ~RsPostedVEG() { return; }
/* Specific Service Data */
virtual bool getGroup(const uint32_t &token, RsPostedGroup &group) = 0;
virtual bool getPost(const uint32_t &token, RsPostedPost &post) = 0;
virtual bool getComment(const uint32_t &token, RsPostedComment &comment) = 0;
virtual bool submitGroup(uint32_t &token, RsPostedGroup &group, bool isNew) = 0;
virtual bool submitPost(uint32_t &token, RsPostedPost &post, bool isNew) = 0;
virtual bool submitVote(uint32_t &token, RsPostedVote &vote, bool isNew) = 0;
virtual bool submitComment(uint32_t &token, RsPostedComment &comment, bool isNew) = 0;
// Special Ranking Request.
virtual bool requestRanking(uint32_t &token, std::string groupId) = 0;
virtual bool getRankedPost(const uint32_t &token, RsPostedPost &post) = 0;
virtual bool extractPostedCache(const std::string &str, uint32_t &votes, uint32_t &comments) = 0;
// Control Ranking Calculations.
virtual bool setViewMode(uint32_t mode) = 0;
virtual bool setViewPeriod(uint32_t period) = 0;
virtual bool setViewRange(uint32_t first, uint32_t count) = 0;
// exposed for testing...
virtual float calcPostScore(const RsMsgMetaData &meta) = 0;
};
#endif

View file

@ -30,77 +30,107 @@
#include <string> #include <string>
#include <list> #include <list>
#include <retroshare/rsidentity.h> #include "gxs/rstokenservice.h"
#include "gxs/rsgxsifaceimpl.h"
/* The Main Interface Class - for information about your Peers */ /* The Main Interface Class - for information about your Peers */
class RsWiki; class RsWiki;
extern RsWiki *rsWiki; extern RsWiki *rsWiki;
class RsWikiGroupShare
/* so the basic idea of Wiki is a set of Collections about subjects.
*
* Collection: RS
* - page: DHT
* - edit
* - edit
* - official revision. (new version of thread head).
*
* A collection will be moderated by it creator - important to prevent stupid changes.
* We need a way to swap out / replace / fork collections if moderator is rubbish.
*
* This should probably be done that the collection level.
* and enable all the references to be modified.
*
* Collection1 (RS DHT)
* : Turtle Link: Collection 0x54e4dafc34
* - Page 1
* - Page 2
* - Link to Self:Page 1
* - Link to Turtle:Page 1
*
*
*/
#define FLAG_MSG_TYPE_WIKI_SNAPSHOT 0x0001
#define FLAG_MSG_TYPE_WIKI_COMMENT 0x0002
class CollectionRef
{ {
public: public:
uint32_t mShareType; std::string KeyWord;
std::string mShareGroupId; std::string CollectionId;
std::string mPublishKey;
uint32_t mCommentMode;
uint32_t mResizeMode;
}; };
class RsWikiGroup
class RsWikiCollection
{ {
public: public:
RsGroupMetaData mMeta; RsGroupMetaData mMeta;
//std::string mGroupId;
//std::string mName;
std::string mDescription; std::string mDescription;
std::string mCategory; std::string mCategory;
std::string mHashTags; std::string mHashTags;
RsWikiGroupShare mShareOptions; //std::map<std::string, CollectionRef> linkReferences;
}; };
class RsWikiPage
class RsWikiSnapshot
{ {
public: public:
RsMsgMetaData mMeta; RsMsgMetaData mMeta;
// IN META DATA.
//std::string mGroupId;
//std::string mOrigPageId;
//std::string mPageId;
//std::string mName;
// WE SHOULD SWITCH TO USING THREAD/PARENT IDS HERE....
std::string mPrevId;
std::string mPage; // all the text is stored here. std::string mPage; // all the text is stored here.
std::string mHashTags; std::string mHashTags;
}; };
class RsWiki: public RsTokenService
class RsWikiComment
{ {
public: public:
RsWiki() { return; } RsMsgMetaData mMeta;
std::string mComment;
};
std::ostream &operator<<(std::ostream &out, const RsWikiCollection &group);
std::ostream &operator<<(std::ostream &out, const RsWikiSnapshot &shot);
std::ostream &operator<<(std::ostream &out, const RsWikiComment &comment);
class RsWiki: public RsGxsIfaceImpl
{
public:
RsWiki(RsGenExchange *gxs): RsGxsIfaceImpl(gxs) { return; }
virtual ~RsWiki() { return; } virtual ~RsWiki() { return; }
/* Specific Service Data */ /* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsWikiGroup &group) = 0; virtual bool getCollections(const uint32_t &token, std::vector<RsWikiCollection> &collections) = 0;
virtual bool getMsgData(const uint32_t &token, RsWikiPage &page) = 0; virtual bool getSnapshots(const uint32_t &token, std::vector<RsWikiSnapshot> &snapshots) = 0;
virtual bool getComments(const uint32_t &token, std::vector<RsWikiComment> &comments) = 0;
virtual bool createGroup(uint32_t &token, RsWikiGroup &group, bool isNew) = 0; virtual bool getRelatedSnapshots(const uint32_t &token, std::vector<RsWikiSnapshot> &snapshots) = 0;
virtual bool createPage(uint32_t &token, RsWikiPage &page, bool isNew) = 0;
virtual bool submitCollection(uint32_t &token, RsWikiCollection &collection) = 0;
virtual bool submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot) = 0;
virtual bool submitComment(uint32_t &token, RsWikiComment &comment) = 0;
}; };
#endif #endif

View file

@ -30,74 +30,94 @@
#include <string> #include <string>
#include <list> #include <list>
#include <retroshare/rsidentity.h> #include "gxs/rstokenservice.h"
#include "gxs/rsgxsifaceimpl.h"
/* The Main Interface Class - for information about your Peers */ /* The Main Interface Class - for information about your Peers */
class RsWire; class RsWire;
extern RsWire *rsWire; extern RsWire *rsWire;
class RsWireGroupShare
{
public:
uint32_t mShareType;
std::string mShareGroupId;
std::string mPublishKey;
uint32_t mCommentMode;
uint32_t mResizeMode;
};
class RsWireGroup class RsWireGroup
{ {
public: public:
RsGroupMetaData mMeta; RsGroupMetaData mMeta;
//std::string mGroupId;
//std::string mName;
std::string mDescription; std::string mDescription;
std::string mCategory;
std::string mHashTags;
RsWireGroupShare mShareOptions;
}; };
/***********************************************************************
* So pulses operate in the following modes.
*
* => Standard, a post to your own group.
* => @User, gets duplicated on each user's group.
* => RT, duplicated as child of original post.
*
* From Twitter:
* twitter can be: embedded, replied to, favourited, unfavourited,
* retweeted, unretweeted and deleted
*
* See: https://dev.twitter.com/docs/platform-objects
*
* Format of message: ....
*
* #HashTags.
* @68769381495134 => ID of Sender.
* <http>
*
***********************************************************************/
class RsWirePlace
{
public:
};
class RsWirePulse class RsWirePulse
{ {
public: public:
RsMsgMetaData mMeta; RsMsgMetaData mMeta;
//std::string mGroupId; std::string mPulseText; // all the text is stored here.
//std::string mOrigPageId; std::string mHashTags;
//std::string mPrevId;
//std::string mPageId;
//std::string mName;
std::string mPulse; // all the text is stored here. // These will be added at some point.
// std::string mInReplyPulse;
std::string mHashTags; // uint32_t mPulseFlags;
// std::list<std::string> mMentions;
// std::list<std::string> mHashTags;
// std::list<std::string> mUrls;
// RsWirePlace mPlace;
}; };
class RsWire: public RsTokenService
std::ostream &operator<<(std::ostream &out, const RsWireGroup &group);
std::ostream &operator<<(std::ostream &out, const RsWirePulse &pulse);
class RsWire: public RsGxsIfaceImpl
{ {
public: public:
RsWire() { return; } RsWire(RsGenExchange *gxs): RsGxsIfaceImpl(gxs) { return; }
virtual ~RsWire() { return; } virtual ~RsWire() { return; }
/* Specific Service Data */ /* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsWireGroup &group) = 0; virtual bool getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups) = 0;
virtual bool getMsgData(const uint32_t &token, RsWirePulse &pulse) = 0; virtual bool getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses) = 0;
/* Create Stuff */ virtual bool createGroup(uint32_t &token, RsWireGroup &group) = 0;
virtual bool createGroup(uint32_t &token, RsWireGroup &group, bool isNew) = 0; virtual bool createPulse(uint32_t &token, RsWirePulse &pulse) = 0;
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew) = 0;
}; };
#endif #endif

View file

@ -31,6 +31,7 @@
#include "pqi/authssl.h" #include "pqi/authssl.h"
#include "pqi/authgpg.h" #include "pqi/authgpg.h"
#include "retroshare/rsinit.h" #include "retroshare/rsinit.h"
#include "plugins/pluginmanager.h"
#include "util/rsdebug.h" #include "util/rsdebug.h"
const int p3facemsgzone = 11453; const int p3facemsgzone = 11453;
@ -41,6 +42,19 @@ const int p3facemsgzone = 11453;
#include "pqi/p3netmgr.h" #include "pqi/p3netmgr.h"
// TO SHUTDOWN THREADS.
#ifdef RS_ENABLE_GXS
#include "services/p3idservice.h"
#include "services/p3gxscircles.h"
#include "services/p3wiki.h"
#include "services/p3posted.h"
#include "services/p3photoservice.h"
#include "services/p3gxsforums.h"
#include "services/p3wire.h"
#endif
/****************************************/ /****************************************/
/* RsIface Config */ /* RsIface Config */
/* Config */ /* Config */
@ -134,10 +148,28 @@ void RsServer::rsGlobalShutDown()
join(); join();
ftserver->StopThreads(); ftserver->StopThreads();
mPluginsManager->stopPlugins();
// stop the p3distrib threads // stop the p3distrib threads
mForums->join(); mForums->join();
mChannels->join(); mChannels->join();
#ifdef RS_ENABLE_GXS
if(mGxsCircles) mGxsCircles->join();
if(mGxsForums) mGxsForums->join();
if(mGxsIdService) mGxsIdService->join();
if(mPosted) mPosted->join();
if(mPhoto) mPhoto->join();
if(mWiki) mWiki->join();
if(mWire) mWire->join();
#endif
#ifdef RS_USE_BLOGS #ifdef RS_USE_BLOGS
mBlogs->join(); mBlogs->join();
#endif #endif

View file

@ -62,6 +62,8 @@ RsServer::RsServer(RsIface &i, NotifyBase &callback)
pqih = NULL; pqih = NULL;
mPluginsManager = NULL;
/* services */ /* services */
ad = NULL; ad = NULL;
msgSrv = NULL; msgSrv = NULL;
@ -74,6 +76,18 @@ RsServer::RsServer(RsIface &i, NotifyBase &callback)
/* Config */ /* Config */
mConfigMgr = NULL; mConfigMgr = NULL;
mGeneralConfig = NULL; mGeneralConfig = NULL;
/* GXS - Amazingly we can still initialise these
* even without knowing the data-types (they are just pointers???)
*/
mPhoto = NULL;
mWiki = NULL;
mPosted = NULL;
mGxsCircles = NULL;
mGxsIdService = NULL;
mGxsForums = NULL;
mWire = NULL;
} }
RsServer::~RsServer() RsServer::~RsServer()

View file

@ -45,10 +45,23 @@
#include "services/p3channels.h" #include "services/p3channels.h"
#include "services/p3forums.h" #include "services/p3forums.h"
/* GXS Classes - just declare the classes.
so we don't have to totally recompile to switch */
class p3IdService;
class p3GxsCircles;
class p3GxsForums;
class p3Wiki;
class p3Posted;
class p3PhotoService;
class p3Wire;
class p3PeerMgrIMPL; class p3PeerMgrIMPL;
class p3LinkMgrIMPL; class p3LinkMgrIMPL;
class p3NetMgrIMPL; class p3NetMgrIMPL;
class p3HistoryMgr; class p3HistoryMgr;
class RsPluginManager;
/* The Main Interface Class - for controlling the server */ /* The Main Interface Class - for controlling the server */
@ -159,6 +172,8 @@ class RsServer: public RsControl, public RsThread
pqipersongrp *pqih; pqipersongrp *pqih;
RsPluginManager *mPluginsManager;
//sslroot *sslr; //sslroot *sslr;
/* services */ /* services */
@ -170,6 +185,15 @@ class RsServer: public RsControl, public RsThread
p3Forums *mForums; p3Forums *mForums;
/* caches (that need ticking) */ /* caches (that need ticking) */
/* GXS */
p3Wiki *mWiki;
p3Posted *mPosted;
p3PhotoService *mPhoto;
p3GxsCircles *mGxsCircles;
p3IdService *mGxsIdService;
p3GxsForums *mGxsForums;
p3Wire *mWire;
/* Config */ /* Config */
p3ConfigMgr *mConfigMgr; p3ConfigMgr *mConfigMgr;
p3GeneralConfig *mGeneralConfig; p3GeneralConfig *mGeneralConfig;

View file

@ -28,9 +28,11 @@
#include <unistd.h> #include <unistd.h>
// for locking instances
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
// for locking instances
#include <errno.h> #include <errno.h>
#else
#include "util/rswin.h"
#endif #endif
#include "util/rsdebug.h" #include "util/rsdebug.h"
@ -1804,7 +1806,11 @@ RsTurtle *rsTurtle = NULL ;
#ifdef RS_ENABLE_ZCNATASSIST #ifdef RS_ENABLE_ZCNATASSIST
#include "zeroconf/p3zcnatassist.h" #include "zeroconf/p3zcnatassist.h"
#else #else
#include "upnp/upnphandler.h" #ifdef RS_USE_LIBUPNP
#include "upnp/upnphandler_linux.h"
#else
#include "upnp/upnphandler_miniupnp.h"
#endif
#endif #endif
#include "services/p3disc.h" #include "services/p3disc.h"
@ -1817,14 +1823,22 @@ RsTurtle *rsTurtle = NULL ;
#include "services/p3blogs.h" #include "services/p3blogs.h"
#include "turtle/p3turtle.h" #include "turtle/p3turtle.h"
#ifdef ENABLE_GXS_SERVICES #ifdef RS_ENABLE_GXS
#include "services/p3photoservice.h" // NEW GXS SYSTEMS.
#include "services/p3wikiservice.h" #include "gxs/gxscoreserver.h"
#include "services/p3wire.h" #include "gxs/rsdataservice.h"
#include "gxs/rsgxsnetservice.h"
#include "gxs/rsgxsflags.h"
#include "services/p3idservice.h" #include "services/p3idservice.h"
#include "services/p3forumsv2.h" #include "services/p3gxscircles.h"
#include "services/p3wiki.h"
#include "services/p3posted.h" #include "services/p3posted.h"
#endif #include "services/p3photoservice.h"
#include "services/p3gxsforums.h"
#include "services/p3wire.h"
#endif // RS_ENABLE_GXS
#ifndef PQI_DISABLE_TUNNEL #ifndef PQI_DISABLE_TUNNEL
#include "services/p3tunnel.h" #include "services/p3tunnel.h"
@ -2187,7 +2201,7 @@ int RsServer::StartupRetroShare()
// possible entries include: /usr/lib/retroshare, ~/.retroshare/extensions/, etc. // possible entries include: /usr/lib/retroshare, ~/.retroshare/extensions/, etc.
#endif #endif
RsPluginManager *mPluginsManager = new RsPluginManager(RsInitConfig::main_executable_hash) ; mPluginsManager = new RsPluginManager(RsInitConfig::main_executable_hash) ;
rsPlugins = mPluginsManager ; rsPlugins = mPluginsManager ;
mConfigMgr->addConfiguration("plugins.cfg", mPluginsManager); mConfigMgr->addConfiguration("plugins.cfg", mPluginsManager);
@ -2266,31 +2280,184 @@ int RsServer::StartupRetroShare()
mPluginsManager->registerClientServices(pqih) ; mPluginsManager->registerClientServices(pqih) ;
mPluginsManager->registerCacheServices() ; mPluginsManager->registerCacheServices() ;
#ifdef ENABLE_GXS_SERVICES
// Testing New Cache Services.
p3PhotoService *mPhotos = new p3PhotoService(RS_SERVICE_TYPE_PHOTO);
pqih -> addService(mPhotos);
// Testing New Cache Services. #ifdef RS_ENABLE_GXS
p3WikiService *mWikis = new p3WikiService(RS_SERVICE_TYPE_WIKI);
pqih -> addService(mWikis);
// Testing New Cache Services. // The idea is that if priorGxsDir is non
p3Wire *mWire = new p3Wire(RS_SERVICE_TYPE_WIRE); // empty and matches an exist directory location
pqih -> addService(mWire); // the given ssl user id then this directory is cleaned
// and deleted
std::string priorGxsDir = "./" + mLinkMgr->getOwnId() + "/";
std::string currGxsDir = RsInitConfig::configDir + "/GXS_phase1";
bool cleanUpGxsDir = false;
// Testing New Cache Services. if(!priorGxsDir.empty())
p3IdService *mIdentity = new p3IdService(RS_SERVICE_TYPE_IDENTITY); cleanUpGxsDir = RsDirUtil::checkDirectory(priorGxsDir);
pqih -> addService(mIdentity);
// Testing New Cache Services. std::list<std::string> filesToKeep;
p3ForumsV2 *mForumsV2 = new p3ForumsV2(RS_SERVICE_TYPE_FORUMSV2); bool cleanUpSuccess = RsDirUtil::cleanupDirectory(priorGxsDir, filesToKeep);
pqih -> addService(mForumsV2);
// Testing New Cache Services. if(!cleanUpSuccess)
p3PostedService *mPosted = new p3PostedService(RS_SERVICE_TYPE_POSTED); std::cerr << "RsInit::StartupRetroShare() Clean up of Old Gxs Dir Failed!";
pqih -> addService(mPosted); else
#endif // ENABLE_GXS_SERVICES rmdir(priorGxsDir.c_str());
// TODO: temporary to store GXS service data, remove
RsDirUtil::checkCreateDirectory(currGxsDir);
RsNxsNetMgr* nxsMgr = new RsNxsNetMgrImpl(mLinkMgr);
/**** Identity service ****/
RsGeneralDataService* gxsid_ds = new RsDataService(currGxsDir + "/", "gxsid_db",
RS_SERVICE_GXSV1_TYPE_GXSID, NULL);
gxsid_ds->resetDataStore();
// init gxs services
mGxsIdService = new p3IdService(gxsid_ds, NULL);
// create GXS photo service
RsGxsNetService* gxsid_ns = new RsGxsNetService(
RS_SERVICE_GXSV1_TYPE_GXSID, gxsid_ds, nxsMgr, mGxsIdService);
/**** GxsCircle service ****/
RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db",
RS_SERVICE_GXSV1_TYPE_GXSCIRCLE, NULL);
gxscircles_ds->resetDataStore();
// init gxs services
mGxsCircles = new p3GxsCircles(gxscircles_ds, NULL, mGxsIdService);
// create GXS Circle service
RsGxsNetService* gxscircles_ns = new RsGxsNetService(
RS_SERVICE_GXSV1_TYPE_GXSCIRCLE, gxscircles_ds, nxsMgr, mGxsCircles);
/**** Photo service ****/
// create photo authentication policy
uint32_t photoAuthenPolicy = 0;
uint8_t flag = 0;
flag = GXS_SERV::MSG_AUTHEN_ROOT_PUBLISH_SIGN;
RsGenExchange::setAuthenPolicyFlag(flag, photoAuthenPolicy,
RsGenExchange::RESTRICTED_GRP_BITS);
// Re-enable later, photo not using gixs yet
// flag = GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN;
// RsGenExchange::setAuthenPolicyFlag(flag, photoAuthenPolicy,
// RsGenExchange::RESTRICTED_GRP_BITS);
flag = GXS_SERV::GRP_OPTION_AUTHEN_AUTHOR_SIGN;
RsGenExchange::setAuthenPolicyFlag(flag, photoAuthenPolicy,
RsGenExchange::GRP_OPTION_BITS);
RsGeneralDataService* photo_ds = new RsDataService(currGxsDir + "/", "photoV2_db",
RS_SERVICE_GXSV1_TYPE_PHOTO, NULL);
photo_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
// init gxs services
mPhoto = new p3PhotoService(photo_ds, NULL, mGxsIdService, photoAuthenPolicy);
// create GXS photo service
RsGxsNetService* photo_ns = new RsGxsNetService(
RS_SERVICE_GXSV1_TYPE_PHOTO, photo_ds, nxsMgr, mPhoto);
/**** Posted GXS service ****/
RsGeneralDataService* posted_ds = new RsDataService(currGxsDir + "/", "posted_db",
RS_SERVICE_GXSV1_TYPE_POSTED);
posted_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
mPosted = new p3Posted(posted_ds, NULL);
// create GXS photo service
RsGxsNetService* posted_ns = new RsGxsNetService(
RS_SERVICE_GXSV1_TYPE_POSTED, posted_ds, nxsMgr, mPosted);
/**** Wiki GXS service ****/
RsGeneralDataService* wiki_ds = new RsDataService(currGxsDir + "/", "wiki_db",
RS_SERVICE_GXSV1_TYPE_WIKI);
wiki_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
mWiki = new p3Wiki(wiki_ds, NULL);
// create GXS photo service
RsGxsNetService* wiki_ns = new RsGxsNetService(
RS_SERVICE_GXSV1_TYPE_WIKI, wiki_ds, nxsMgr, mWiki);
/**** Wire GXS service ****/
RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db",
RS_SERVICE_GXSV1_TYPE_WIRE);
wire_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
mWire = new p3Wire(wire_ds, NULL);
// create GXS photo service
RsGxsNetService* wire_ns = new RsGxsNetService(
RS_SERVICE_GXSV1_TYPE_WIRE, wire_ds, nxsMgr, mWire);
/**** Forum GXS service ****/
RsGeneralDataService* gxsforums_ds = new RsDataService(currGxsDir + "/", "gxsforums_db",
RS_SERVICE_GXSV1_TYPE_FORUMS);
gxsforums_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
mGxsForums = new p3GxsForums(gxsforums_ds, NULL);
// create GXS photo service
RsGxsNetService* gxsforums_ns = new RsGxsNetService(
RS_SERVICE_GXSV1_TYPE_FORUMS, gxsforums_ds, nxsMgr, mGxsForums);
/*** start up GXS core runner ***/
createThread(*mGxsIdService);
createThread(*mGxsCircles);
createThread(*mPhoto);
createThread(*mPosted);
createThread(*mWiki);
createThread(*mWire);
createThread(*mGxsForums);
// cores ready start up GXS net servers
createThread(*gxsid_ns);
createThread(*gxscircles_ns);
createThread(*photo_ns);
createThread(*posted_ns);
createThread(*wiki_ns);
createThread(*wire_ns);
createThread(*gxsforums_ns);
// now add to p3service
pqih->addService(gxsid_ns);
pqih->addService(gxscircles_ns);
pqih->addService(photo_ns);
pqih->addService(posted_ns);
pqih->addService(wiki_ns);
pqih->addService(gxsforums_ns);
#endif // RS_ENABLE_GXS.
#ifndef RS_RELEASE #ifndef RS_RELEASE
@ -2548,15 +2715,17 @@ int RsServer::StartupRetroShare()
rsForums = mForums; rsForums = mForums;
rsChannels = mChannels; rsChannels = mChannels;
#ifdef ENABLE_GXS_SERVICES #ifdef RS_ENABLE_GXS
// Testing of new cache system interfaces.
rsIdentity = mIdentity; rsIdentity = mGxsIdService;
rsPhoto = mPhotos; rsGxsCircles = mGxsCircles;
rsWiki = mWikis; rsWiki = mWiki;
rsWire = mWire; rsPosted = mPosted;
rsForumsV2 = mForumsV2; rsPhoto = mPhoto;
rsPosted = mPosted; rsGxsForums = mGxsForums;
#endif // ENABLE_GXS_SERVICES rsWire = mWire;
#endif // RS_ENABLE_GXS
#ifdef RS_USE_BLOGS #ifdef RS_USE_BLOGS
@ -2571,7 +2740,6 @@ int RsServer::StartupRetroShare()
rsGameLauncher = NULL; rsGameLauncher = NULL;
#endif #endif
/* put a welcome message in! */ /* put a welcome message in! */
if (RsInitConfig::firsttime_run) if (RsInitConfig::firsttime_run)
{ {

View file

@ -90,3 +90,6 @@ const uint8_t QOS_PRIORITY_RS_BWCTRL_ALLOWED_ITEM = 9 ;
const uint8_t QOS_PRIORITY_RS_DSDV_ROUTE = 4 ; const uint8_t QOS_PRIORITY_RS_DSDV_ROUTE = 4 ;
const uint8_t QOS_PRIORITY_RS_DSDV_DATA = 2 ; const uint8_t QOS_PRIORITY_RS_DSDV_DATA = 2 ;
// GXS
//
const uint8_t QOS_PRIORITY_RS_GXS_NET = 3 ;

View file

@ -0,0 +1,422 @@
/*
* libretroshare/src/serialiser: rswikiitems.cc
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* 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.1 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".
*
*/
#include <iostream>
#include "rsgxscircleitems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#define CIRCLE_DEBUG 1
uint32_t RsGxsCircleSerialiser::size(RsItem *item)
{
RsGxsCircleGroupItem* grp_item = NULL;
RsGxsCircleMsgItem* snap_item = NULL;
if((grp_item = dynamic_cast<RsGxsCircleGroupItem*>(item)) != NULL)
{
return sizeGxsCircleGroupItem(grp_item);
}
else if((snap_item = dynamic_cast<RsGxsCircleMsgItem*>(item)) != NULL)
{
return sizeGxsCircleMsgItem(snap_item);
}
return NULL;
}
bool RsGxsCircleSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsCircleGroupItem* grp_item = NULL;
RsGxsCircleMsgItem* snap_item = NULL;
if((grp_item = dynamic_cast<RsGxsCircleGroupItem*>(item)) != NULL)
{
return serialiseGxsCircleGroupItem(grp_item, data, size);
}
else if((snap_item = dynamic_cast<RsGxsCircleMsgItem*>(item)) != NULL)
{
return serialiseGxsCircleMsgItem(snap_item, data, size);
}
return false;
}
RsItem* RsGxsCircleSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM:
return deserialiseGxsCircleGroupItem(data, size);
break;
case RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM:
return deserialiseGxsCircleMsgItem(data, size);
break;
default:
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsCircleGroupItem::clear()
{
gxsIdSet.TlvClear();
subCircleSet.TlvClear();
}
bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group)
{
clear();
meta = group.mMeta;
gxsIdSet.ids = group.mInvitedMembers;
subCircleSet.ids = group.mSubCircles;
return true;
}
bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const
{
group.mMeta = meta;
group.mInvitedMembers = gxsIdSet.ids;
group.mSubCircles = subCircleSet.ids;
return true;
}
std::ostream& RsGxsCircleGroupItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsCircleGroupItem", indent);
uint16_t int_Indent = indent + 2;
gxsIdSet.print(out, int_Indent);
subCircleSet.print(out, int_Indent);
printRsItemEnd(out ,"RsGxsCircleGroupItem", indent);
return out;
}
uint32_t RsGxsCircleSerialiser::sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item)
{
uint32_t s = 8; // header
s += item->gxsIdSet.TlvSize();
s += item->subCircleSet.TlvSize();
return s;
}
bool RsGxsCircleSerialiser::serialiseGxsCircleGroupItem(RsGxsCircleGroupItem *item, void *data, uint32_t *size)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsCircleGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsCircleGroupItem */
ok &= item->gxsIdSet.SetTlv(data, tlvsize, &offset);
ok &= item->subCircleSet.SetTlv(data, tlvsize, &offset);
if(offset != tlvsize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef CIRCLE_DEBUG
if (!ok)
{
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsCircleGroupItem* RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem(void *data, uint32_t *size)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM != getRsItemSubType(rstype)))
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsCircleGroupItem* item = new RsGxsCircleGroupItem();
/* skip the header */
offset += 8;
ok &= item->gxsIdSet.GetTlv(data, rssize, &offset);
ok &= item->subCircleSet.GetTlv(data, rssize, &offset);
if (offset != rssize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsCircleMsgItem::clear()
{
msg.stuff.clear();
}
std::ostream& RsGxsCircleMsgItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsCircleMsgItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Stuff: " << msg.stuff << std::endl;
printRsItemEnd(out ,"RsGxsCircleMsgItem", indent);
return out;
}
uint32_t RsGxsCircleSerialiser::sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item)
{
const RsGxsCircleMsg &msg = item->msg;
uint32_t s = 8; // header
s += GetTlvStringSize(msg.stuff);
return s;
}
bool RsGxsCircleSerialiser::serialiseGxsCircleMsgItem(RsGxsCircleMsgItem *item, void *data, uint32_t *size)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsCircleMsgItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsCircleMsgItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->msg.stuff);
if(offset != tlvsize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef CIRCLE_DEBUG
if (!ok)
{
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsCircleMsgItem* RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem(void *data, uint32_t *size)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM != getRsItemSubType(rstype)))
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsCircleMsgItem* item = new RsGxsCircleMsgItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->msg.stuff);
if (offset != rssize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/

View file

@ -0,0 +1,102 @@
/*
* libretroshare/src/serialiser: rsgxscircleitems.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* 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.1 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".
*
*/
#ifndef RS_GXSCIRCLE_ITEMS_H
#define RS_GXSCIRCLE_ITEMS_H
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rsgxscircles.h"
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM = 0x03;
const uint16_t GXSCIRCLE_GXSIDSET = 0x0001;
const uint16_t GXSCIRCLE_SUBCIRCLESET = 0x0002;
class RsGxsCircleGroupItem : public RsGxsGrpItem
{
public:
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE,
RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM),
gxsIdSet(GXSCIRCLE_GXSIDSET),
subCircleSet(GXSCIRCLE_SUBCIRCLESET) { return;}
virtual ~RsGxsCircleGroupItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
bool convertFrom(const RsGxsCircleGroup &group);
bool convertTo(RsGxsCircleGroup &group) const;
// DIFFERENT FROM OTHER ONES, as stupid serialisation otherwise.
RsTlvStringSet gxsIdSet;
RsTlvStringSet subCircleSet;
};
class RsGxsCircleMsgItem : public RsGxsMsgItem
{
public:
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE,
RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {return; }
virtual ~RsGxsCircleMsgItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsCircleMsg msg;
};
class RsGxsCircleSerialiser : public RsSerialType
{
public:
RsGxsCircleSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_GXSCIRCLE)
{ return; }
virtual ~RsGxsCircleSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item);
bool serialiseGxsCircleGroupItem (RsGxsCircleGroupItem *item, void *data, uint32_t *size);
RsGxsCircleGroupItem * deserialiseGxsCircleGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item);
bool serialiseGxsCircleMsgItem (RsGxsCircleMsgItem *item, void *data, uint32_t *size);
RsGxsCircleMsgItem * deserialiseGxsCircleMsgItem(void *data, uint32_t *size);
};
#endif /* RS_GXSCIRCLE_ITEMS_H */

View file

@ -0,0 +1,402 @@
/*
* libretroshare/src/serialiser: rsgxsforumitems.cc
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* 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.1 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".
*
*/
#include <iostream>
#include "rsgxsforumitems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#define GXSFORUM_DEBUG 1
uint32_t RsGxsForumSerialiser::size(RsItem *item)
{
RsGxsForumGroupItem* grp_item = NULL;
RsGxsForumMsgItem* op_item = NULL;
if((grp_item = dynamic_cast<RsGxsForumGroupItem*>(item)) != NULL)
{
return sizeGxsForumGroupItem(grp_item);
}
else if((op_item = dynamic_cast<RsGxsForumMsgItem*>(item)) != NULL)
{
return sizeGxsForumMsgItem(op_item);
}
std::cerr << "RsGxsForumSerialiser::size() ERROR invalid item" << std::endl;
return 0;
}
bool RsGxsForumSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsForumGroupItem* grp_item = NULL;
RsGxsForumMsgItem* op_item = NULL;
if((grp_item = dynamic_cast<RsGxsForumGroupItem*>(item)) != NULL)
{
return serialiseGxsForumGroupItem(grp_item, data, size);
}
else if((op_item = dynamic_cast<RsGxsForumMsgItem*>(item)) != NULL)
{
return serialiseGxsForumMsgItem(op_item, data, size);
}
std::cerr << "RsGxsForumSerialiser::serialise() ERROR invalid item" << std::endl;
return false;
}
RsItem* RsGxsForumSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM:
return deserialiseGxsForumGroupItem(data, size);
break;
case RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM:
return deserialiseGxsForumMsgItem(data, size);
break;
default:
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsForumGroupItem::clear()
{
mGroup.mDescription.clear();
}
std::ostream& RsGxsForumGroupItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsForumGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Description: " << mGroup.mDescription << std::endl;
printRsItemEnd(out ,"RsGxsForumGroupItem", indent);
return out;
}
uint32_t RsGxsForumSerialiser::sizeGxsForumGroupItem(RsGxsForumGroupItem *item)
{
const RsGxsForumGroup& group = item->mGroup;
uint32_t s = 8; // header
s += GetTlvStringSize(group.mDescription);
return s;
}
bool RsGxsForumSerialiser::serialiseGxsForumGroupItem(RsGxsForumGroupItem *item, void *data, uint32_t *size)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsForumGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() Size too small" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsForumGroupItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mGroup.mDescription);
if(offset != tlvsize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSFORUM_DEBUG
if (!ok)
{
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsForumGroupItem* RsGxsForumSerialiser::deserialiseGxsForumGroupItem(void *data, uint32_t *size)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsForumGroupItem* item = new RsGxsForumGroupItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mGroup.mDescription);
if (offset != rssize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsForumMsgItem::clear()
{
mMsg.mMsg.clear();
}
std::ostream& RsGxsForumMsgItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsForumMsgItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Msg: " << mMsg.mMsg << std::endl;
printRsItemEnd(out ,"RsGxsForumMsgItem", indent);
return out;
}
uint32_t RsGxsForumSerialiser::sizeGxsForumMsgItem(RsGxsForumMsgItem *item)
{
const RsGxsForumMsg& msg = item->mMsg;
uint32_t s = 8; // header
s += GetTlvStringSize(msg.mMsg); // mMsg.
return s;
}
bool RsGxsForumSerialiser::serialiseGxsForumMsgItem(RsGxsForumMsgItem *item, void *data, uint32_t *size)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsForumMsgItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsForumMsgItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg.mMsg);
if(offset != tlvsize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSFORUM_DEBUG
if (!ok)
{
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsForumMsgItem* RsGxsForumSerialiser::deserialiseGxsForumMsgItem(void *data, uint32_t *size)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsForumMsgItem* item = new RsGxsForumMsgItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg.mMsg);
if (offset != rssize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/

View file

@ -0,0 +1,95 @@
/*
* libretroshare/src/serialiser: rsgxsforumitems.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* 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".
*
*/
#ifndef RS_GXS_FORUM_ITEMS_H
#define RS_GXS_FORUM_ITEMS_H
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rsgxsforums.h"
const uint8_t RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM = 0x03;
class RsGxsForumGroupItem : public RsGxsGrpItem
{
public:
RsGxsForumGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_FORUMS,
RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM) { return;}
virtual ~RsGxsForumGroupItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsForumGroup mGroup;
};
class RsGxsForumMsgItem : public RsGxsMsgItem
{
public:
RsGxsForumMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_FORUMS,
RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM) {return; }
virtual ~RsGxsForumMsgItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsForumMsg mMsg;
};
class RsGxsForumSerialiser : public RsSerialType
{
public:
RsGxsForumSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_FORUMS)
{ return; }
virtual ~RsGxsForumSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsForumGroupItem(RsGxsForumGroupItem *item);
bool serialiseGxsForumGroupItem (RsGxsForumGroupItem *item, void *data, uint32_t *size);
RsGxsForumGroupItem * deserialiseGxsForumGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsForumMsgItem(RsGxsForumMsgItem *item);
bool serialiseGxsForumMsgItem (RsGxsForumMsgItem *item, void *data, uint32_t *size);
RsGxsForumMsgItem * deserialiseGxsForumMsgItem(void *data, uint32_t *size);
};
#endif /* RS_GXS_FORUM_ITEMS_H */

View file

@ -0,0 +1,576 @@
/*
* libretroshare/src/serialiser: rsgxsiditems.cc
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* 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.1 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".
*
*/
#include <iostream>
#include "rsgxsiditems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#define GXSID_DEBUG 1
uint32_t RsGxsIdSerialiser::size(RsItem *item)
{
RsGxsIdGroupItem* grp_item = NULL;
RsGxsIdOpinionItem* op_item = NULL;
RsGxsIdCommentItem* com_item = NULL;
if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL)
{
return sizeGxsIdGroupItem(grp_item);
}
else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL)
{
return sizeGxsIdOpinionItem(op_item);
}
else if((com_item = dynamic_cast<RsGxsIdCommentItem*>(item)) != NULL)
{
return sizeGxsIdCommentItem(com_item);
}
std::cerr << "RsGxsIdSerialiser::size() ERROR invalid item" << std::endl;
return 0;
}
bool RsGxsIdSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsIdGroupItem* grp_item = NULL;
RsGxsIdOpinionItem* op_item = NULL;
RsGxsIdCommentItem* com_item = NULL;
if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL)
{
return serialiseGxsIdGroupItem(grp_item, data, size);
}
else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL)
{
return serialiseGxsIdOpinionItem(op_item, data, size);
}
else if((com_item = dynamic_cast<RsGxsIdCommentItem*>(item)) != NULL)
{
return serialiseGxsIdCommentItem(com_item, data, size);
}
std::cerr << "RsGxsIdSerialiser::serialise() ERROR invalid item" << std::endl;
return false;
}
RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM:
return deserialiseGxsIdGroupItem(data, size);
break;
case RS_PKT_SUBTYPE_GXSID_OPINION_ITEM:
return deserialiseGxsIdOpinionItem(data, size);
break;
case RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM:
return deserialiseGxsIdCommentItem(data, size);
break;
default:
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsIdGroupItem::clear()
{
group.mPgpIdHash.clear();
group.mPgpIdSign.clear();
group.mPgpKnown = false;
group.mPgpId.clear();
}
std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsIdGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "PgpIdHash: " << group.mPgpIdHash << std::endl;
printIndent(out, int_Indent);
out << "PgpIdSign: " << group.mPgpIdSign << std::endl;
printRsItemEnd(out ,"RsGxsIdGroupItem", indent);
return out;
}
uint32_t RsGxsIdSerialiser::sizeGxsIdGroupItem(RsGxsIdGroupItem *item)
{
const RsGxsIdGroup& group = item->group;
uint32_t s = 8; // header
s += GetTlvStringSize(group.mPgpIdHash);
s += GetTlvStringSize(group.mPgpIdSign);
return s;
}
bool RsGxsIdSerialiser::serialiseGxsIdGroupItem(RsGxsIdGroupItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsIdGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() Size too small" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsIdGroupItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mPgpIdHash);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mPgpIdSign);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSID_GROUP_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsIdGroupItem* item = new RsGxsIdGroupItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mPgpIdHash);
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mPgpIdSign);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsIdOpinionItem::clear()
{
opinion.mOpinion = 0;
// Others that aren't serialised. - but should be cleared anyway
opinion.mReputation = 0;
}
std::ostream& RsGxsIdOpinionItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsIdOpinionItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Opinion: " << opinion.mOpinion << std::endl;
printRsItemEnd(out ,"RsGxsIdOpinionItem", indent);
return out;
}
uint32_t RsGxsIdSerialiser::sizeGxsIdOpinionItem(RsGxsIdOpinionItem *item)
{
const RsGxsIdOpinion& opinion = item->opinion;
uint32_t s = 8; // header
s += 4; // mOpinion.
return s;
}
bool RsGxsIdSerialiser::serialiseGxsIdOpinionItem(RsGxsIdOpinionItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsIdOpinionItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsIdOpinionItem */
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mOpinion);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsIdOpinionItem* RsGxsIdSerialiser::deserialiseGxsIdOpinionItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSID_OPINION_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsIdOpinionItem* item = new RsGxsIdOpinionItem();
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mOpinion));
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsIdCommentItem::clear()
{
comment.mComment.clear();
}
std::ostream& RsGxsIdCommentItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsIdCommentItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Comment: " << comment.mComment << std::endl;
printRsItemEnd(out ,"RsGxsIdCommentItem", indent);
return out;
}
uint32_t RsGxsIdSerialiser::sizeGxsIdCommentItem(RsGxsIdCommentItem *item)
{
const RsGxsIdComment& comment = item->comment;
uint32_t s = 8; // header
s += GetTlvStringSize(comment.mComment);
return s;
}
bool RsGxsIdSerialiser::serialiseGxsIdCommentItem(RsGxsIdCommentItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsIdCommentItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsIdCommentItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->comment.mComment);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsIdCommentItem* RsGxsIdSerialiser::deserialiseGxsIdCommentItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsIdCommentItem* item = new RsGxsIdCommentItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->comment.mComment);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/

View file

@ -0,0 +1,112 @@
/*
* libretroshare/src/serialiser: rsgxsiditems.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* 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".
*
*/
#ifndef RS_GXS_IDENTITY_ITEMS_H
#define RS_GXS_IDENTITY_ITEMS_H
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rsidentity.h"
const uint8_t RS_PKT_SUBTYPE_GXSID_GROUP_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_GXSID_OPINION_ITEM = 0x03;
const uint8_t RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM = 0x04;
class RsGxsIdGroupItem : public RsGxsGrpItem
{
public:
RsGxsIdGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_GXSID,
RS_PKT_SUBTYPE_GXSID_GROUP_ITEM) { return;}
virtual ~RsGxsIdGroupItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsIdGroup group;
};
class RsGxsIdOpinionItem : public RsGxsMsgItem
{
public:
RsGxsIdOpinionItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSID,
RS_PKT_SUBTYPE_GXSID_OPINION_ITEM) {return; }
virtual ~RsGxsIdOpinionItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsIdOpinion opinion;
};
class RsGxsIdCommentItem : public RsGxsMsgItem
{
public:
RsGxsIdCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSID,
RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM) { return; }
virtual ~RsGxsIdCommentItem() { return; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsIdComment comment;
};
class RsGxsIdSerialiser : public RsSerialType
{
public:
RsGxsIdSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_GXSID)
{ return; }
virtual ~RsGxsIdSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsIdGroupItem(RsGxsIdGroupItem *item);
bool serialiseGxsIdGroupItem (RsGxsIdGroupItem *item, void *data, uint32_t *size);
RsGxsIdGroupItem * deserialiseGxsIdGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsIdOpinionItem(RsGxsIdOpinionItem *item);
bool serialiseGxsIdOpinionItem (RsGxsIdOpinionItem *item, void *data, uint32_t *size);
RsGxsIdOpinionItem * deserialiseGxsIdOpinionItem(void *data, uint32_t *size);
uint32_t sizeGxsIdCommentItem(RsGxsIdCommentItem *item);
bool serialiseGxsIdCommentItem (RsGxsIdCommentItem *item, void *data, uint32_t *size);
RsGxsIdCommentItem * deserialiseGxsIdCommentItem(void *data, uint32_t *size);
};
#endif /* RS_GXS_IDENTITY_ITEMS_H */

View file

@ -8,6 +8,7 @@
#include "rsgxsitems.h" #include "rsgxsitems.h"
#include "gxs/rsgxsdata.h" #include "gxs/rsgxsdata.h"
#include <iostream>
void RsMsgMetaData::operator =(const RsGxsMsgMetaData& rGxsMeta) void RsMsgMetaData::operator =(const RsGxsMsgMetaData& rGxsMeta)
{ {
@ -22,6 +23,8 @@
this->mParentId = rGxsMeta.mParentId; this->mParentId = rGxsMeta.mParentId;
this->mPublishTs = rGxsMeta.mPublishTs; this->mPublishTs = rGxsMeta.mPublishTs;
this->mThreadId = rGxsMeta.mThreadId; this->mThreadId = rGxsMeta.mThreadId;
this->mServiceString = rGxsMeta.mServiceString;
} }
@ -37,4 +40,31 @@
this->mPublishTs = rGxsMeta.mPublishTs; this->mPublishTs = rGxsMeta.mPublishTs;
this->mSubscribeFlags = rGxsMeta.mSubscribeFlags; this->mSubscribeFlags = rGxsMeta.mSubscribeFlags;
this->mGroupName = rGxsMeta.mGroupName; this->mGroupName = rGxsMeta.mGroupName;
this->mServiceString = rGxsMeta.mServiceString;
this->mSignFlags = rGxsMeta.mSignFlags;
this->mCircleId = rGxsMeta.mCircleId;
this->mCircleType = rGxsMeta.mCircleType;
this->mInternalCircle = rGxsMeta.mInternalCircle;
this->mOriginator = rGxsMeta.mOriginator;
} }
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta)
{
out << "[ GroupId: " << meta.mGroupId << " Name: " << meta.mGroupName << " ]";
return out;
}
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta)
{
out << "[ GroupId: " << meta.mGroupId << " MsgId: " << meta.mMsgId;
out << " Name: " << meta.mMsgName;
out << " OrigMsgId: " << meta.mOrigMsgId;
out << " ThreadId: " << meta.mThreadId;
out << " ParentId: " << meta.mParentId;
out << " AuthorId: " << meta.mAuthorId;
out << " Name: " << meta.mMsgName << " ]";
return out;
}

View file

@ -28,48 +28,62 @@
#include "serialiser/rsserviceids.h" #include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvtypes.h" #include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvkeys.h" #include "serialiser/rstlvkeys.h"
class RsGxsGrpMetaData; class RsGxsGrpMetaData;
class RsGxsMsgMetaData; class RsGxsMsgMetaData;
class RsGroupMetaData class RsGroupMetaData
{ {
public: public:
RsGroupMetaData() RsGroupMetaData()
{ {
mGroupFlags = 0; mGroupFlags = 0;
mSubscribeFlags = 0; mSubscribeFlags = 0;
mPop = 0; mPop = 0;
mMsgCount = 0; mMsgCount = 0;
mLastPost = 0; mLastPost = 0;
mGroupStatus = 0;
//mPublishTs = 0; mGroupStatus = 0;
} mCircleType = 0;
void operator =(const RsGxsGrpMetaData& rGxsMeta); //mPublishTs = 0;
}
std::string mGroupId; void operator =(const RsGxsGrpMetaData& rGxsMeta);
std::string mGroupName;
uint32_t mGroupFlags;
time_t mPublishTs; // Mandatory. std::string mGroupId;
std::string mAuthorId; // Optional. std::string mGroupName;
uint32_t mGroupFlags;
uint32_t mSignFlags; // Combination of RSGXS_GROUP_SIGN_PUBLISH_MASK & RSGXS_GROUP_SIGN_AUTHOR_MASK.
time_t mPublishTs; // Mandatory.
std::string mAuthorId; // Optional.
// for circles
std::string mCircleId;
uint32_t mCircleType;
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
uint32_t mSubscribeFlags;
uint32_t mPop; // HOW DO WE DO THIS NOW.
uint32_t mMsgCount; // ???
time_t mLastPost; // ???
uint32_t mGroupStatus;
std::string mServiceString; // Service Specific Free-Form extra storage.
std::string mOriginator;
std::string mInternalCircle;
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
uint32_t mSubscribeFlags;
uint32_t mPop; // HOW DO WE DO THIS NOW.
uint32_t mMsgCount; // ???
time_t mLastPost; // ???
uint32_t mGroupStatus;
}; };
@ -78,40 +92,50 @@ class RsGroupMetaData
class RsMsgMetaData class RsMsgMetaData
{ {
public:
RsMsgMetaData() public:
{
mPublishTs = 0;
mMsgFlags = 0;
mMsgStatus = 0;
mChildTs = 0;
}
void operator =(const RsGxsMsgMetaData& rGxsMeta); RsMsgMetaData()
{
mPublishTs = 0;
mMsgFlags = 0;
mMsgStatus = 0;
mChildTs = 0;
}
void operator =(const RsGxsMsgMetaData& rGxsMeta);
std::string mGroupId; std::string mGroupId;
std::string mMsgId; std::string mMsgId;
std::string mThreadId; std::string mThreadId;
std::string mParentId; std::string mParentId;
std::string mOrigMsgId; std::string mOrigMsgId;
std::string mAuthorId; std::string mAuthorId;
std::string mMsgName; std::string mMsgName;
time_t mPublishTs; time_t mPublishTs;
uint32_t mMsgFlags; // Whats this for? /// the first 16 bits for service, last 16 for GXS
uint32_t mMsgFlags;
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
// normally READ / UNREAD flags. LOCAL Data. // normally READ / UNREAD flags. LOCAL Data.
uint32_t mMsgStatus;
time_t mChildTs; /// the first 16 bits for service, last 16 for GXS
uint32_t mMsgStatus;
time_t mChildTs;
std::string mServiceString; // Service Specific Free-Form extra storage.
}; };
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta);
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta);
class RsGxsGrpItem : public RsItem class RsGxsGrpItem : public RsItem
{ {
@ -122,6 +146,7 @@ public:
: RsItem(RS_PKT_VERSION_SERVICE, service, subtype) { return; } : RsItem(RS_PKT_VERSION_SERVICE, service, subtype) { return; }
virtual ~RsGxsGrpItem(){} virtual ~RsGxsGrpItem(){}
RsGroupMetaData meta; RsGroupMetaData meta;
}; };

View file

@ -34,7 +34,6 @@
#include "serialiser/rstlvbase.h" #include "serialiser/rstlvbase.h"
#include "serialiser/rstlvtypes.h" #include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvkeys.h" #include "serialiser/rstlvkeys.h"
#include "gxs/rsgxsdata.h" #include "gxs/rsgxsdata.h"
@ -69,7 +68,11 @@ class RsNxsItem : public RsItem
public: public:
RsNxsItem(uint16_t servtype, uint8_t subtype) RsNxsItem(uint16_t servtype, uint8_t subtype)
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0) { return; } : RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0)
{
setPriorityLevel(QOS_PRIORITY_RS_VOIP_PING);
return;
}
virtual void clear() = 0; virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0; virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
@ -196,7 +199,7 @@ public:
RsTlvBinaryData grp; /// actual group data RsTlvBinaryData grp; /// actual group data
/*! /*!
* This should contains all the data * This should contains all data
* which is not specific to the Gxs service data * which is not specific to the Gxs service data
*/ */
RsTlvBinaryData meta; RsTlvBinaryData meta;
@ -259,7 +262,9 @@ class RsNxsMsg : public RsNxsItem
{ {
public: public:
RsNxsMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG), msg(servtype), meta(servtype) { clear(); return; } RsNxsMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG), meta(servtype), msg(servtype),
metaData(NULL) { clear(); return; }
~RsNxsMsg() { if(metaData) delete metaData; }
virtual void clear(); virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent); virtual std::ostream &print(std::ostream &out, uint16_t indent);
@ -294,7 +299,7 @@ public:
virtual ~RsNxsSearchReq() { return;} virtual ~RsNxsSearchReq() { return;}
virtual void clear() { return;} virtual void clear() { return;}
virtual std::ostream &print(std::ostream &out, uint16_t indent) { return out; } virtual std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; }
uint8_t nHops; /// how many peers to jump to uint8_t nHops; /// how many peers to jump to
uint32_t token; // search token uint32_t token; // search token
@ -332,7 +337,7 @@ public:
RsNxsSearchResultMsg() : context(0) { return;} RsNxsSearchResultMsg() : context(0) { return;}
void clear() {} void clear() {}
std::ostream &print(std::ostream &out, uint16_t indent) { return out; } std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; }
uint32_t token; // search token to be redeemed uint32_t token; // search token to be redeemed
RsTlvBinaryData context; // used by client service RsTlvBinaryData context; // used by client service
@ -353,7 +358,7 @@ public:
RsNxsSearchResultGrp(); RsNxsSearchResultGrp();
void clear() {} void clear() {}
std::ostream &print(std::ostream &out, uint16_t indent) { return out; } std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; }
uint32_t token; // search token to be redeemed uint32_t token; // search token to be redeemed

View file

@ -1,10 +1,9 @@
/* /*
* libretroshare/src/serialiser: rsphotoitems.cc * libretroshare/src/retroshare: rsphoto.h
* *
* RetroShare Serialiser. * RetroShare C++ Interface.
* *
* Copyright 2007-2008 by Robert Fernie. * Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -24,267 +23,631 @@
* *
*/ */
#include "serialiser/rsbaseserial.h"
#include "serialiser/rsphotoitems.h"
#include "serialiser/rstlvbase.h"
#define RSSERIAL_DEBUG 1
#include <iostream> #include <iostream>
/*************************************************************************/ #include "rsphotoitems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
void RsPhotoItem::clear() #define GXS_PHOTO_SERIAL_DEBUG
uint32_t RsGxsPhotoSerialiser::size(RsItem* item)
{ {
srcId.clear(); RsGxsPhotoPhotoItem* ppItem = NULL;
photoId.clear(); RsGxsPhotoAlbumItem* paItem = NULL;
size = 0; RsGxsPhotoCommentItem* cItem = NULL;
name.clear(); if((ppItem = dynamic_cast<RsGxsPhotoPhotoItem*>(item)) != NULL)
comment.clear();
location.clear();
date.clear();
/* not serialised */
isAvailable = false;
path.clear();
}
std::ostream &RsPhotoItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsPhotoItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "srcId: " << srcId << std::endl;
printIndent(out, int_Indent);
out << "photoId: " << photoId << std::endl;
printIndent(out, int_Indent);
out << "size: " << size << std::endl;
printIndent(out, int_Indent);
out << "name: " << name << std::endl;
printIndent(out, int_Indent);
std::string cnv_comment(comment.begin(), comment.end());
out << "msg: " << cnv_comment << std::endl;
printIndent(out, int_Indent);
out << "location: " << location << std::endl;
printIndent(out, int_Indent);
out << "date: " << date << std::endl;
printIndent(out, int_Indent);
out << "(NS) isAvailable: " << isAvailable << std::endl;
printIndent(out, int_Indent);
out << "(NS) path: " << path << std::endl;
printRsItemEnd(out, "RsPhotoItem", indent);
return out;
}
/*************************************************************************/
/*************************************************************************/
void RsPhotoShowItem::clear()
{
showId.clear();
name.clear();
comment.clear();
location.clear();
date.clear();
photos.clear();
}
std::ostream &RsPhotoShowItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsPhotoShowItem", indent);
uint16_t int_Indent = indent + 2;
uint16_t int_Indent2 = int_Indent + 2;
printIndent(out, int_Indent);
out << "showId: " << showId << std::endl;
printIndent(out, int_Indent);
out << "name: " << name << std::endl;
printIndent(out, int_Indent);
std::string cnv_comment(comment.begin(), comment.end());
out << "msg: " << cnv_comment << std::endl;
printIndent(out, int_Indent);
out << "location: " << location << std::endl;
printIndent(out, int_Indent);
out << "date: " << date << std::endl;
printIndent(out, int_Indent);
out << "Photos in Show: " << photos.size() << std::endl;
std::list<RsPhotoRefItem>::iterator it;
for(it = photos.begin(); it != photos.end(); it++)
{ {
printIndent(out, int_Indent2); return sizeGxsPhotoPhotoItem(ppItem);
out << "PhotoId: " << it->photoId << std::endl; }
printIndent(out, int_Indent2 + 2); else if((paItem = dynamic_cast<RsGxsPhotoAlbumItem*>(item)) != NULL)
std::string cnv_comment2(it->altComment.begin(), it->altComment.end()); {
out << "AltComment: " << cnv_comment2 << std::endl; return sizeGxsPhotoAlbumItem(paItem);
printIndent(out, int_Indent2 + 2); }
out << "Delta T: " << it->deltaT << std::endl; else if((cItem = dynamic_cast<RsGxsPhotoCommentItem*>(item)) != NULL)
{
return sizeGxsPhotoCommentItem(cItem);
}
else
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
#endif
return NULL;
} }
printRsItemEnd(out, "RsPhotoShowItem", indent);
return out;
} }
RsPhotoRefItem::RsPhotoRefItem() bool RsGxsPhotoSerialiser::serialise(RsItem* item, void* data, uint32_t* size)
:deltaT(0)
{ {
return;
RsGxsPhotoPhotoItem* ppItem = NULL;
RsGxsPhotoAlbumItem* paItem = NULL;
RsGxsPhotoCommentItem* cItem = NULL;
if((ppItem = dynamic_cast<RsGxsPhotoPhotoItem*>(item)) != NULL)
{
return serialiseGxsPhotoPhotoItem(ppItem, data, size);
}
else if((paItem = dynamic_cast<RsGxsPhotoAlbumItem*>(item)) != NULL)
{
return serialiseGxsPhotoAlbumItem(paItem, data, size);
}else if((cItem = dynamic_cast<RsGxsPhotoCommentItem*>(item)) != NULL)
{
return serialiseGxsPhotoCommentItem(cItem, data, size);
}
else
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
#endif
return false;
}
} }
/*************************************************************************/ RsItem* RsGxsPhotoSerialiser::deserialise(void* data, uint32_t* size)
/*************************************************************************/
/*************************************************************************/
/* TODO serialiser */
#if 0
uint32_t RsPhotoSerialiser::sizeLink(RsPhotoLinkMsg *item)
{ {
uint32_t s = 8; /* header */
s += GetTlvStringSize(item->rid); #ifdef RSSERIAL_DEBUG
s += 4; /* timestamp */ std::cerr << "RsGxsPhotoSerialiser::deserialise()" << std::endl;
s += GetTlvWideStringSize(item->title); #endif
s += GetTlvWideStringSize(item->comment); /* get the type and size */
s += 4; /* linktype */ uint32_t rstype = getRsItemId(data);
s += GetTlvWideStringSize(item->link);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM:
return deserialiseGxsPhotoPhotoItem(data, size);
case RS_PKT_SUBTYPE_PHOTO_ITEM:
return deserialiseGxsPhotoAlbumItem(data, size);
case RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM:
return deserialiseGxsPhotoCommentItem(data, size);
default:
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialise(): subtype could not be dealt with"
<< std::endl;
#endif
break;
}
}
return NULL;
}
uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item)
{
const RsPhotoAlbum& album = item->album;
uint32_t s = 8; // header
s += GetTlvStringSize(album.mCaption);
s += GetTlvStringSize(album.mCategory);
s += GetTlvStringSize(album.mDescription);
s += GetTlvStringSize(album.mHashTags);
s += GetTlvStringSize(album.mOther);
s += GetTlvStringSize(album.mPhotoPath);
s += GetTlvStringSize(album.mPhotographer);
s += GetTlvStringSize(album.mWhen);
s += GetTlvStringSize(album.mWhere);
RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent
b.setBinData(album.mThumbnail.data, album.mThumbnail.size);
s += GetTlvStringSize(album.mThumbnail.type);
s += b.TlvSize();
return s; return s;
} }
/* serialise the data to the buffer */ uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem *item)
bool RsPhotoSerialiser::serialiseLink(RsPhotoLinkMsg *item, void *data, uint32_t *pktsize)
{ {
uint32_t tlvsize = sizeLink(item);
uint32_t offset = 0;
if (*pktsize < tlvsize) const RsPhotoComment& comment = item->comment;
return false; /* not enough space */ uint32_t s = 8; // header
*pktsize = tlvsize; s += GetTlvStringSize(comment.mComment);
s += 4; // mflags
bool ok = true; return s;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Header: " << ok << std::endl;
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Size: " << tlvsize << std::endl;
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GENID, item->rid);
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() rid: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->timestamp);
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() timestamp: " << ok << std::endl;
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_TITLE, item->title);
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Title: " << ok << std::endl;
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Comment: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->linktype);
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() linktype: " << ok << std::endl;
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_LINK, item->link);
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Link: " << ok << std::endl;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Size Error! " << std::endl;
}
return ok;
} }
RsPhotoLinkMsg *RsPhotoSerialiser::deserialiseLink(void *data, uint32_t *pktsize) bool RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item, void* data,
uint32_t* size)
{ {
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_RANK != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_RANK_LINK != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsPhotoLinkMsg *item = new RsPhotoLinkMsg();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GENID, item->rid);
ok &= getRawUInt32(data, rssize, &offset, &(item->timestamp));
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_TITLE, item->title);
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
ok &= getRawUInt32(data, rssize, &offset, &(item->linktype));
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_LINK, item->link);
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
uint32_t RsPhotoSerialiser::size(RsItem *item)
{
return sizeLink((RsPhotoLinkMsg *) item);
}
bool RsPhotoSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
{
return serialiseLink((RsPhotoLinkMsg *) item, data, pktsize);
}
RsItem *RsPhotoSerialiser::deserialise(void *data, uint32_t *pktsize)
{
return deserialiseLink(data, pktsize);
}
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl;
#endif #endif
uint32_t tlvsize = sizeGxsPhotoAlbumItem(item);
uint32_t offset = 0;
/*************************************************************************/ if(*size < tlvsize){
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mCaption);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mCategory);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mDescription);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mHashTags);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mOther);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mPhotoPath);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mPhotographer);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mWhen);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mWhere);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mThumbnail.type);
RsTlvBinaryData b(RS_SERVICE_GXSV1_TYPE_PHOTO); // TODO, need something more persisitent
b.setBinData(item->album.mThumbnail.data, item->album.mThumbnail.size);
ok &= b.SetTlv(data, tlvsize, &offset);
if(offset != tlvsize)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_PHOTO_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsPhotoAlbumItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem(void* data,
uint32_t* size)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_PHOTO_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPhotoAlbumItem* item = new RsGxsPhotoAlbumItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mCaption);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mCategory);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mDescription);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mHashTags);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mOther);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mPhotoPath);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mPhotographer);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mWhen);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mWhere);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mThumbnail.type);
RsTlvBinaryData b(RS_SERVICE_GXSV1_TYPE_PHOTO); // TODO, need something more persisitent
ok &= b.GetTlv(data, rssize, &offset);
item->album.mThumbnail.data = (uint8_t*)b.bin_data;
item->album.mThumbnail.size = b.bin_len;
b.TlvShallowClear();
if (offset != rssize)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item)
{
const RsPhotoPhoto& photo = item->photo;
uint32_t s = 8; // header size
s += GetTlvStringSize(photo.mCaption);
s += GetTlvStringSize(photo.mCategory);
s += GetTlvStringSize(photo.mDescription);
s += GetTlvStringSize(photo.mHashTags);
s += GetTlvStringSize(photo.mOther);
s += GetTlvStringSize(photo.mPhotographer);
s += GetTlvStringSize(photo.mWhen);
s += GetTlvStringSize(photo.mWhere);
RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent
b.setBinData(photo.mThumbnail.data, photo.mThumbnail.size);
s += GetTlvStringSize(photo.mThumbnail.type);
s += b.TlvSize();
return s;
}
bool RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item, void* data,
uint32_t* size)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsPhotoPhotoItem(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mCaption);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mCategory);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mDescription);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mHashTags);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mOther);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mPhotographer);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mWhen);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mWhere);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mThumbnail.type);
RsTlvBinaryData b(RS_SERVICE_GXSV1_TYPE_PHOTO); // TODO, need something more persisitent
b.setBinData(item->photo.mThumbnail.data, item->photo.mThumbnail.size);
ok &= b.SetTlv(data, tlvsize, &offset);
if(offset != tlvsize)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_PHOTO_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* data,
uint32_t* size)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPhotoPhotoItem* item = new RsGxsPhotoPhotoItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mCaption);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mCategory);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mDescription);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mHashTags);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mOther);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mPhotographer);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mWhen);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mWhere);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mThumbnail.type);
RsTlvBinaryData b(RS_SERVICE_GXSV1_TYPE_PHOTO); // TODO, need something more persisitent
ok &= b.GetTlv(data, rssize, &offset);
item->photo.mThumbnail.data = (uint8_t*)(b.bin_data);
item->photo.mThumbnail.size = b.bin_len;
b.TlvShallowClear();
if (offset != rssize)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
bool RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsPhotoCommentItem(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
ok &= SetTlvString(data, tlvsize, &offset, 0, item->comment.mComment);
ok &= setRawUInt32(data, tlvsize, &offset, item->comment.mCommentFlag);
if(offset != tlvsize)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_PHOTO_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsPhotoCommentItem * RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem(void *data, uint32_t *size)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPhotoCommentItem* item = new RsGxsPhotoCommentItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 0, item->comment.mComment);
ok &= getRawUInt32(data, rssize, &offset, &(item->comment.mCommentFlag));
if (offset != rssize)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
void RsGxsPhotoAlbumItem::clear()
{
album.mCaption.clear();
album.mCategory.clear();
album.mDescription.clear();
album.mHashTags.clear();
album.mOther.clear();
album.mPhotoPath.clear();
album.mPhotographer.clear();
album.mWhen.clear();
album.mWhere.clear();
album.mThumbnail.deleteImage();
}
void RsGxsPhotoCommentItem::clear()
{
comment.mComment.clear();
comment.mCommentFlag = 0;
}
std::ostream& RsGxsPhotoCommentItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsPhotoCommentItem", indent);
uint16_t int_Indent = indent + 2;
printRsItemEnd(out ,"RsGxsPhotoCommentItem", indent);
return out;
}
std::ostream& RsGxsPhotoAlbumItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsPhotoAlbumItem", indent);
uint16_t int_Indent = indent + 2;
out << album << std::endl;
printRsItemEnd(out ,"RsGxsPhotoAlbumItem", indent);
return out;
}
void RsGxsPhotoPhotoItem::clear()
{
photo.mCaption.clear();
photo.mCategory.clear();
photo.mDescription.clear();
photo.mHashTags.clear();
photo.mOther.clear();
photo.mPhotographer.clear();
photo.mWhen.clear();
photo.mWhere.clear();
photo.mThumbnail.deleteImage();
}
std::ostream& RsGxsPhotoPhotoItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsPhotoPhotoItem", indent);
uint16_t int_Indent = indent + 2;
printRsItemEnd(out ,"RsGxsPhotoPhotoItem", indent);
return out;
}

View file

@ -1,12 +1,9 @@
#ifndef P3_PHOTO_ITEMS_H
#define P3_PHOTO_ITEMS_H
/* /*
* libretroshare/src/serialiser: rsphotoitems.h * libretroshare/src/retroshare: rsphoto.h
* *
* RetroShare Serialiser. * RetroShare C++ Interface.
* *
* Copyright 2007-2008 by Robert Fernie. * Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -26,113 +23,91 @@
* *
*/ */
#ifndef RSPHOTOV2ITEMS_H_
#define RSPHOTOV2ITEMS_H_
#include <map> #include <map>
#include "serialiser/rsserviceids.h" #include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h" #include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rsphoto.h"
const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02; const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM = 0x03; const uint8_t RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM = 0x03;
const uint8_t RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM = 0x04; const uint8_t RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM = 0x04;
/**************************************************************************/ class RsGxsPhotoAlbumItem : public RsGxsGrpItem
class RsPhotoItem;
class RsPhotoShowItem;
class RsPhotoCommentItem;
class RsPhotoItem: public RsItem
{ {
public:
RsPhotoItem() public:
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO,
RS_PKT_SUBTYPE_PHOTO_ITEM) { return; }
virtual ~RsPhotoItem() { return; }
virtual void clear();
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
std::string srcId; RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
std::string photoId; /* same as hash */ RS_PKT_SUBTYPE_PHOTO_ITEM) { return;}
uint64_t size; /* file size */ virtual ~RsGxsPhotoAlbumItem() { return;}
std::string name; void clear();
std::wstring comment; std::ostream &print(std::ostream &out, uint16_t indent = 0);
std::string location; /* TODO: change to TLV */
std::string date; /* TODO: change to TLV */
/* not serialised */ RsPhotoAlbum album;
bool isAvailable;
std::string path;
}; };
/* THIS must be turned into a TLV type + set (TOD) */ class RsGxsPhotoPhotoItem : public RsGxsMsgItem
class RsPhotoRefItem
{ {
public: public:
RsPhotoRefItem();
std::string photoId; RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
std::wstring altComment; RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {return; }
uint32_t deltaT; /* in 100ths of sec? */ virtual ~RsGxsPhotoPhotoItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPhotoPhoto photo;
}; };
class RsPhotoShowItem: public RsItem class RsGxsPhotoCommentItem : public RsGxsMsgItem
{ {
public: public:
RsPhotoShowItem()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO,
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) { return; }
virtual ~RsPhotoShowItem() { return; } RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
virtual void clear(); RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) { return; }
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); virtual ~RsGxsPhotoCommentItem() { return; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPhotoComment comment;
std::string showId;
std::string name;
std::wstring comment;
std::string location; /* TODO -> TLV */
std::string date; /* TODO -> TLV */
std::list<RsPhotoRefItem> photos; /* list as ordered */
}; };
class RsPhotoSerialiser: public RsSerialType class RsGxsPhotoSerialiser : public RsSerialType
{ {
public: public:
RsPhotoSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO) RsGxsPhotoSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_PHOTO)
{ return; } { return; }
virtual ~RsPhotoSerialiser() virtual ~RsGxsPhotoSerialiser() { return; }
{ return; }
uint32_t size(RsItem *item);
virtual uint32_t size(RsItem *) { return 0; } bool serialise (RsItem *item, void *data, uint32_t *size);
virtual bool serialise (RsItem */*item*/, void */*data*/, uint32_t */*size*/) { return false; } RsItem * deserialise(void *data, uint32_t *size);
virtual RsItem * deserialise(void */*data*/, uint32_t */*size*/) { return NULL; }
private: private:
/* For RS_PKT_SUBTYPE_PHOTO_ITEM */ uint32_t sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem *item);
//virtual uint32_t sizeLink(RsPhotoItem *); bool serialiseGxsPhotoAlbumItem (RsGxsPhotoAlbumItem *item, void *data, uint32_t *size);
//virtual bool serialiseLink (RsPhotoItem *item, void *data, uint32_t *size); RsGxsPhotoAlbumItem * deserialiseGxsPhotoAlbumItem(void *data, uint32_t *size);
//virtual RsPhotoItem *deserialiseLink(void *data, uint32_t *size);
/* For RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM */ uint32_t sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem *item);
//virtual uint32_t sizeLink(RsPhotoShowItem *); bool serialiseGxsPhotoPhotoItem (RsGxsPhotoPhotoItem *item, void *data, uint32_t *size);
//virtual bool serialiseLink (RsPhotoShowItem *item, void *data, uint32_t *size); RsGxsPhotoPhotoItem * deserialiseGxsPhotoPhotoItem(void *data, uint32_t *size);
//virtual RsPhotoShowItem *deserialiseLink(void *data, uint32_t *size);
/* For RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM */ uint32_t sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem *item);
//virtual uint32_t sizeLink(RsPhotoCommentItem *); bool serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size);
//virtual bool serialiseLink (RsPhotoCommentItem *item, void *data, uint32_t *size); RsGxsPhotoCommentItem * deserialiseGxsPhotoCommentItem(void *data, uint32_t *size);
//virtual RsPhotoCommentItem *deserialiseLink(void *data, uint32_t *size);
}; };
/**************************************************************************/ #endif /* RSPHOTOV2ITEMS_H_ */
#endif /* RS_PHOTO_ITEMS_H */

View file

@ -1,491 +0,0 @@
/*
* libretroshare/src/retroshare: rsphoto.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
*
* 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".
*
*/
#include "rsphotov2items.h"
#define GXS_PHOTO_SERIAL_DEBUG
uint32_t RsGxsPhotoSerialiser::size(RsItem* item)
{
RsGxsPhotoPhotoItem* ppItem = NULL;
RsGxsPhotoAlbumItem* paItem = NULL;
if((ppItem = dynamic_cast<RsGxsPhotoPhotoItem*>(item)) != NULL)
{
return sizeGxsPhotoPhotoItem(ppItem);
}
else if((paItem = dynamic_cast<RsGxsPhotoAlbumItem*>(item)) != NULL)
{
return sizeGxsPhotoAlbumItem(paItem);
}
else
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
#endif
return NULL;
}
}
bool RsGxsPhotoSerialiser::serialise(RsItem* item, void* data, uint32_t* size)
{
RsGxsPhotoPhotoItem* ppItem = NULL;
RsGxsPhotoAlbumItem* paItem = NULL;
if((ppItem = dynamic_cast<RsGxsPhotoPhotoItem*>(item)) != NULL)
{
return serialiseGxsPhotoPhotoItem(ppItem, data, size);
}
else if((paItem = dynamic_cast<RsGxsPhotoAlbumItem*>(item)) != NULL)
{
return serialiseGxsPhotoAlbumItem(paItem, data, size);
}
else
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
#endif
return false;
}
}
RsItem* RsGxsPhotoSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_PHOTO != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_NXS_SYNC_GRP:
return deserialiseGxsPhotoPhotoItem(data, size);
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM:
return deserialiseGxsPhotoAlbumItem(data, size);
default:
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialise(): subtype could not be dealt with"
<< std::endl;
#endif
break;
}
}
return NULL;
}
uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item)
{
const RsPhotoAlbum& album = item->album;
uint32_t s = 8; // header
s += GetTlvStringSize(album.mCaption);
s += GetTlvStringSize(album.mCategory);
s += GetTlvStringSize(album.mDescription);
s += GetTlvStringSize(album.mHashTags);
s += GetTlvStringSize(album.mOther);
s += GetTlvStringSize(album.mPhotoPath);
s += GetTlvStringSize(album.mPhotographer);
s += GetTlvStringSize(album.mWhen);
s += GetTlvStringSize(album.mWhere);
RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent
b.setBinData(album.mThumbnail.data, album.mThumbnail.size);
s += GetTlvStringSize(album.mThumbnail.type);
s += b.TlvSize();
return s;
}
bool RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item, void* data,
uint32_t* size)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsPhotoAlbumItem(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mCaption);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mCategory);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mDescription);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mHashTags);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mOther);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mPhotoPath);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mPhotographer);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mWhen);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mWhere);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mThumbnail.type);
RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent
b.setBinData(item->album.mThumbnail.data, item->album.mThumbnail.size);
b.SetTlv(item->album.mThumbnail.data, tlvsize, &offset);
if(offset != tlvsize)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_PHOTO_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsPhotoAlbumItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem(void* data,
uint32_t* size)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_PHOTO != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_PHOTO_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPhotoAlbumItem* item = new RsGxsPhotoAlbumItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mCaption);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mCategory);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mDescription);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mHashTags);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mOther);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mPhotoPath);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mPhotographer);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mWhen);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mWhere);
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mThumbnail.type);
RsTlvBinaryData b(RS_SERVICE_TYPE_PHOTO); // TODO, need something more persisitent
ok &= b.GetTlv(data, rssize, &offset);
item->album.mThumbnail.data = (uint8_t*)b.bin_data;
item->album.mThumbnail.size = b.bin_len;
b.TlvShallowClear();
if (offset != rssize)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item)
{
const RsPhotoPhoto& photo = item->photo;
uint32_t s = 8; // header size
s += GetTlvStringSize(photo.mCaption);
s += GetTlvStringSize(photo.mCategory);
s += GetTlvStringSize(photo.mDescription);
s += GetTlvStringSize(photo.mHashTags);
s += GetTlvStringSize(photo.mOther);
s += GetTlvStringSize(photo.mPhotographer);
s += GetTlvStringSize(photo.mWhen);
s += GetTlvStringSize(photo.mWhere);
RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent
b.setBinData(photo.mThumbnail.data, photo.mThumbnail.size);
s += GetTlvStringSize(photo.mThumbnail.type);
s += b.TlvSize();
return s;
}
bool RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item, void* data,
uint32_t* size)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsPhotoPhotoItem(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mCaption);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mCategory);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mDescription);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mHashTags);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mOther);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mPhotographer);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mWhen);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mWhere);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mThumbnail.type);
RsTlvBinaryData b(RS_SERVICE_TYPE_PHOTO); // TODO, need something more persisitent
b.setBinData(item->photo.mThumbnail.data, item->photo.mThumbnail.size);
b.SetTlv(item->photo.mThumbnail.data, tlvsize, &offset);
if(offset != tlvsize)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_PHOTO_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* data,
uint32_t* size)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_PHOTO != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPhotoPhotoItem* item = new RsGxsPhotoPhotoItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mCaption);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mCategory);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mDescription);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mHashTags);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mOther);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mPhotographer);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mWhen);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mWhere);
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mThumbnail.type);
RsTlvBinaryData b(RS_SERVICE_TYPE_PHOTO); // TODO, need something more persisitent
ok &= b.GetTlv(data, rssize, &offset);
item->photo.mThumbnail.data = (uint8_t*)(b.bin_data);
item->photo.mThumbnail.size = b.bin_len;
b.TlvShallowClear();
if (offset != rssize)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_PHOTO_SERIAL_DEBUG
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
void RsGxsPhotoAlbumItem::clear()
{
album.mCaption.clear();
album.mCategory.clear();
album.mDescription.clear();
album.mHashTags.clear();
album.mOther.clear();
album.mPhotoPath.clear();
album.mPhotographer.clear();
album.mWhen.clear();
album.mWhere.clear();
album.mThumbnail.deleteImage();
}
std::ostream& RsGxsPhotoAlbumItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsPhotoAlbumItem", indent);
uint16_t int_Indent = indent + 2;
printRsItemEnd(out ,"RsGxsPhotoAlbumItem", indent);
return out;
}
void RsGxsPhotoPhotoItem::clear()
{
photo.mCaption.clear();
photo.mCategory.clear();
photo.mDescription.clear();
photo.mHashTags.clear();
photo.mOther.clear();
photo.mPhotographer.clear();
photo.mWhen.clear();
photo.mWhere.clear();
photo.mThumbnail.deleteImage();
}
std::ostream& RsGxsPhotoPhotoItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsPhotoPhotoItem", indent);
uint16_t int_Indent = indent + 2;
printRsItemEnd(out ,"RsGxsPhotoPhotoItem", indent);
return out;
}

View file

@ -1,93 +0,0 @@
/*
* libretroshare/src/retroshare: rsphoto.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
*
* 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".
*
*/
#ifndef RSPHOTOV2ITEMS_H_
#define RSPHOTOV2ITEMS_H_
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "rsphotoitems.h"
#include "retroshare/rsphotoV2.h"
class RsGxsPhotoAlbumItem : public RsGxsGrpItem
{
public:
RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_TYPE_PHOTO,
RS_PKT_SUBTYPE_PHOTO_ITEM) { return;}
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPhotoAlbum album;
};
class RsGxsPhotoPhotoItem : public RsGxsMsgItem
{
public:
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_TYPE_PHOTO,
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {return; }
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPhotoPhoto photo;
};
class RsGxsPhotoSerialiser : public RsSerialType
{
public:
RsGxsPhotoSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO)
{ return; }
virtual ~RsGxsPhotoSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem *item);
bool serialiseGxsPhotoAlbumItem (RsGxsPhotoAlbumItem *item, void *data, uint32_t *size);
RsGxsPhotoAlbumItem * deserialiseGxsPhotoAlbumItem(void *data, uint32_t *size);
uint32_t sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem *item);
bool serialiseGxsPhotoPhotoItem (RsGxsPhotoPhotoItem *item, void *data, uint32_t *size);
RsGxsPhotoPhotoItem * deserialiseGxsPhotoPhotoItem(void *data, uint32_t *size);
};
#endif /* RSPHOTOV2ITEMS_H_ */

View file

@ -0,0 +1,656 @@
/*
* libretroshare/src/gxs: rsopsteditems.cc
*
* RetroShare Serialiser.
*
* Copyright 2012 by 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".
*
*/
#include "serialiser/rsposteditems.h"
#include "rsbaseserial.h"
uint32_t RsGxsPostedSerialiser::size(RsItem *item)
{
RsGxsPostedPostItem* ppItem = NULL;
RsGxsPostedCommentItem* pcItem = NULL;
RsGxsPostedVoteItem* pvItem = NULL;
RsGxsPostedGroupItem* pgItem = NULL;
if((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
{
return sizeGxsPostedPostItem(ppItem);
}
else if((pcItem = dynamic_cast<RsGxsPostedCommentItem*>(item)) != NULL)
{
return sizeGxsPostedCommentItem(pcItem);
}else if((pvItem = dynamic_cast<RsGxsPostedVoteItem*>(item)) != NULL)
{
return sizeGxsPostedVoteItem(pvItem);
}else if((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
{
return sizeGxsPostedGroupItem(pgItem);
}
else
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::size() Failed" << std::endl;
#endif
return NULL;
}
}
bool RsGxsPostedSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsPostedPostItem* ppItem = NULL;
RsGxsPostedCommentItem* pcItem = NULL;
RsGxsPostedVoteItem* pvItem = NULL;
RsGxsPostedGroupItem* pgItem = NULL;
if((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
{
return serialiseGxsPostedPostItem(ppItem, data, size);
}
else if((pcItem = dynamic_cast<RsGxsPostedCommentItem*>(item)) != NULL)
{
return serialiseGxsPostedCommentItem(pcItem, data, size);
}else if((pvItem = dynamic_cast<RsGxsPostedVoteItem*>(item)) != NULL)
{
return serialiseGxsPostedVoteItem(pvItem, data, size);
}else if((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
{
return serialiseGxsPostedGroupItem(pgItem, data, size);
}
else
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialise() FAILED" << std::endl;
#endif
return false;
}
}
RsItem* RsGxsPostedSerialiser::deserialise(void *data, uint32_t *size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM:
return deserialiseGxsPostedCommentItem(data, size);
case RS_PKT_SUBTYPE_POSTED_GRP_ITEM:
return deserialiseGxsPostedGroupItem(data, size);
case RS_PKT_SUBTYPE_POSTED_POST_ITEM:
return deserialiseGxsPostedPostItem(data, size);
case RS_PKT_SUBTYPE_POSTED_VOTE_ITEM:
return deserialiseGxsPostedVoteItem(data, size);
default:
{
#ifdef RS_SSERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialise(): subtype could not be dealt with"
<< std::endl;
#endif
break;
}
}
return NULL;
}
uint32_t RsGxsPostedSerialiser::sizeGxsPostedPostItem(RsGxsPostedPostItem* item)
{
RsPostedPost& p = item->mPost;
uint32_t s = 8;
s += GetTlvStringSize(p.mLink);
s += GetTlvStringSize(p.mNotes);
return s;
}
uint32_t RsGxsPostedSerialiser::sizeGxsPostedCommentItem(RsGxsPostedCommentItem* item)
{
RsPostedComment& c = item->mComment;
uint32_t s = 8;
s += GetTlvStringSize(c.mComment);
return s;
}
uint32_t RsGxsPostedSerialiser::sizeGxsPostedVoteItem(RsGxsPostedVoteItem* item)
{
RsPostedVote& v = item->mVote;
uint32_t s = 8;
s += 1; // for vote direction
return s;
}
uint32_t RsGxsPostedSerialiser::sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item)
{
RsPostedGroup& g = item->mGroup;
uint32_t s = 8;
return s;
}
bool RsGxsPostedSerialiser::serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsPostedPostItem(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mLink);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mNotes);
if(offset != tlvsize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_POSTED_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() NOK" << std::endl;
}
#endif
return ok;
}
bool RsGxsPostedSerialiser::serialiseGxsPostedCommentItem(RsGxsPostedCommentItem* item, void* data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsPostedCommentItem(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mComment.mComment);
if(offset != tlvsize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_POSTED_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()() NOK" << std::endl;
}
#endif
return ok;
}
bool RsGxsPostedSerialiser::serialiseGxsPostedVoteItem(RsGxsPostedVoteItem* item, void* data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsPostedVoteItem(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
ok &= setRawUInt8(data, tlvsize, &offset, item->mVote.mDirection);
if(offset != tlvsize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_POSTED_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem() NOK" << std::endl;
}
#endif
return ok;
}
bool RsGxsPostedSerialiser::serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsPostedGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
if(offset != tlvsize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_POSTED_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsPostedPostItem* RsGxsPostedSerialiser::deserialiseGxsPostedPostItem(void *data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_POSTED_POST_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPostedPostItem* item = new RsGxsPostedPostItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mLink);
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mNotes);
if (offset != rssize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsPostedCommentItem* RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem(void *data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPostedCommentItem* item = new RsGxsPostedCommentItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mComment.mComment);
if (offset != rssize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsPostedVoteItem* RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem(void *data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_POSTED_VOTE_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPostedVoteItem* item = new RsGxsPostedVoteItem();
/* skip the header */
offset += 8;
ok &= getRawUInt8(data, rssize, &offset, &(item->mVote.mDirection));
if (offset != rssize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsPostedGroupItem* RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem(void *data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_POSTED_VOTE_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPostedGroupItem* item = new RsGxsPostedGroupItem();
/* skip the header */
offset += 8;
if (offset != rssize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
void RsGxsPostedPostItem::clear()
{
}
std::ostream & RsGxsPostedPostItem::print(std::ostream &out, uint16_t indent)
{
return out;
}
void RsGxsPostedVoteItem::clear()
{
return;
}
std::ostream & RsGxsPostedVoteItem::print(std::ostream &out, uint16_t indent)
{
return out;
}
void RsGxsPostedCommentItem::clear()
{
return;
}
std::ostream & RsGxsPostedCommentItem::print(std::ostream &out, uint16_t indent)
{
return out;
}
void RsGxsPostedGroupItem::clear()
{
return;
}
std::ostream & RsGxsPostedGroupItem::print(std::ostream &out, uint16_t indent)
{
return out;
}

View file

@ -0,0 +1,103 @@
#ifndef RSPOSTEDITEMS_H
#define RSPOSTEDITEMS_H
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rsposted.h"
const uint8_t RS_PKT_SUBTYPE_POSTED_GRP_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_POSTED_POST_ITEM = 0x03;
const uint8_t RS_PKT_SUBTYPE_POSTED_VOTE_ITEM = 0x04;
const uint8_t RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM = 0x05;
class RsGxsPostedPostItem : public RsGxsMsgItem
{
public:
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
RS_PKT_SUBTYPE_POSTED_POST_ITEM)
{return ; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPostedPost mPost;
};
class RsGxsPostedVoteItem : public RsGxsMsgItem
{
public:
RsGxsPostedVoteItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
RS_PKT_SUBTYPE_POSTED_VOTE_ITEM)
{return ;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPostedVote mVote;
};
class RsGxsPostedCommentItem : public RsGxsMsgItem
{
public:
RsGxsPostedCommentItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM)
{ return; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPostedComment mComment;
};
class RsGxsPostedGroupItem : public RsGxsGrpItem
{
public:
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_POSTED,
RS_PKT_SUBTYPE_POSTED_GRP_ITEM)
{ return; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPostedGroup mGroup;
};
class RsGxsPostedSerialiser : public RsSerialType
{
public:
RsGxsPostedSerialiser()
: RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_PHOTO)
{ return; }
virtual ~RsGxsPostedSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise(RsItem *item, void *data, uint32_t *size);
RsItem* deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsPostedPostItem(RsGxsPostedPostItem* item);
bool serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size);
RsGxsPostedPostItem* deserialiseGxsPostedPostItem(void *data, uint32_t *size);
uint32_t sizeGxsPostedCommentItem(RsGxsPostedCommentItem* item);
bool serialiseGxsPostedCommentItem(RsGxsPostedCommentItem* item, void* data, uint32_t *size);
RsGxsPostedCommentItem* deserialiseGxsPostedCommentItem(void *data, uint32_t *size);
uint32_t sizeGxsPostedVoteItem(RsGxsPostedVoteItem* item);
bool serialiseGxsPostedVoteItem(RsGxsPostedVoteItem* item, void* data, uint32_t *size);
RsGxsPostedVoteItem* deserialiseGxsPostedVoteItem(void *data, uint32_t *size);
uint32_t sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item);
bool serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size);
RsGxsPostedGroupItem* deserialiseGxsPostedGroupItem(void *data, uint32_t *size);
};
#endif // RSPOSTEDITEMS_H

View file

@ -65,6 +65,7 @@ const uint16_t RS_SERVICE_TYPE_STATUS = 0xf020;
const uint16_t RS_SERVICE_TYPE_PLUGIN_ARADO_ID = 0x0401; const uint16_t RS_SERVICE_TYPE_PLUGIN_ARADO_ID = 0x0401;
const uint16_t RS_SERVICE_TYPE_PLUGIN_QCHESS_ID = 0x0402; const uint16_t RS_SERVICE_TYPE_PLUGIN_QCHESS_ID = 0x0402;
const uint16_t RS_SERVICE_TYPE_PLUGIN_FEEDREADER = 0x0403;
/****************** BELOW ARE ONLY THEORETICAL (CAN BE CHANGED) *****/ /****************** BELOW ARE ONLY THEORETICAL (CAN BE CHANGED) *****/
@ -107,13 +108,6 @@ const uint16_t RS_SERVICE_TYPE_DSDV = 0xf050;
const uint16_t RS_SERVICE_TYPE_BWCTRL = 0xf060; const uint16_t RS_SERVICE_TYPE_BWCTRL = 0xf060;
/* New Cache Services */
const uint16_t RS_SERVICE_TYPE_IDENTITY = 0xf100;
const uint16_t RS_SERVICE_TYPE_PHOTO = 0xf101;
const uint16_t RS_SERVICE_TYPE_WIKI = 0xf102;
const uint16_t RS_SERVICE_TYPE_WIRE = 0xf103;
const uint16_t RS_SERVICE_TYPE_FORUMSV2 = 0xf104;
const uint16_t RS_SERVICE_TYPE_POSTED = 0xf105;
//const uint16_t RS_SERVICE_TYPE_DISTRIB = 0xf110; //const uint16_t RS_SERVICE_TYPE_DISTRIB = 0xf110;
//const uint16_t RS_SERVICE_TYPE_FORUM = 0xf120; //const uint16_t RS_SERVICE_TYPE_FORUM = 0xf120;
@ -133,9 +127,35 @@ const uint16_t RS_SERVICE_TYPE_GAME_QGO = 0xf212;
const uint16_t RS_SERVICE_TYPE_GAME_BIGTWO = 0xf213; const uint16_t RS_SERVICE_TYPE_GAME_BIGTWO = 0xf213;
const uint16_t RS_SERVICE_TYPE_GAME_POKER = 0xf214; const uint16_t RS_SERVICE_TYPE_GAME_POKER = 0xf214;
/* New Cache Services */
/* Rs Network Exchange Service */ /* Rs Network Exchange Service */
const uint16_t RS_SERVICE_TYPE_NXS = 0xf300; const uint16_t RS_SERVICE_TYPE_NXS = 0xf300;
const uint16_t RS_SERVICE_GXSV1_TYPE_GXSID = 0xf301;
const uint16_t RS_SERVICE_GXSV1_TYPE_PHOTO = 0xf302;
const uint16_t RS_SERVICE_GXSV1_TYPE_WIKI = 0xf303;
const uint16_t RS_SERVICE_GXSV1_TYPE_WIRE = 0xf304;
const uint16_t RS_SERVICE_GXSV1_TYPE_FORUMS = 0xf305;
const uint16_t RS_SERVICE_GXSV1_TYPE_POSTED = 0xf306;
const uint16_t RS_SERVICE_GXSV1_TYPE_CHANNELS = 0xf307;
const uint16_t RS_SERVICE_GXSV1_TYPE_GXSCIRCLE = 0xf307;
const uint16_t RS_SERVICE_GXSV2_TYPE_GXSID = 0xf311;
const uint16_t RS_SERVICE_GXSV2_TYPE_GXSCIRCLE = 0xf312;
const uint16_t RS_SERVICE_GXSV2_TYPE_PHOTO = 0xf313;
const uint16_t RS_SERVICE_GXSV2_TYPE_WIKI = 0xf314;
const uint16_t RS_SERVICE_GXSV2_TYPE_WIRE = 0xf315;
const uint16_t RS_SERVICE_GXSV2_TYPE_FORUMS = 0xf316;
const uint16_t RS_SERVICE_GXSV2_TYPE_POSTED = 0xf317;
const uint16_t RS_SERVICE_GXSV2_TYPE_CHANNELS = 0xf318;
/* Example Versions (VEG) of New Cache Services */
const uint16_t RS_SERVICE_VEG_TYPE_IDENTITY = 0xf320;
const uint16_t RS_SERVICE_VEG_TYPE_PHOTO = 0xf321;
const uint16_t RS_SERVICE_VEG_TYPE_WIKI = 0xf322;
const uint16_t RS_SERVICE_VEG_TYPE_WIRE = 0xf323;
const uint16_t RS_SERVICE_VEG_TYPE_FORUMS = 0xf324;
const uint16_t RS_SERVICE_VEG_TYPE_POSTED = 0xf325;
/***************** IDS ALLOCATED FOR PLUGINS ******************/ /***************** IDS ALLOCATED FOR PLUGINS ******************/

View file

@ -207,6 +207,8 @@ const uint16_t TLV_TYPE_SECURITYKEY = 0x1040;
const uint16_t TLV_TYPE_SECURITYKEYSET= 0x1041; const uint16_t TLV_TYPE_SECURITYKEYSET= 0x1041;
const uint16_t TLV_TYPE_KEYSIGNATURE = 0x1050; const uint16_t TLV_TYPE_KEYSIGNATURE = 0x1050;
const uint16_t TLV_TYPE_KEYSIGNATURESET = 0x1051;
const uint16_t TLV_TYPE_KEYSIGNATURETYPE = 0x1052;
const uint16_t TLV_TYPE_IMAGE = 0x1060; const uint16_t TLV_TYPE_IMAGE = 0x1060;

View file

@ -34,7 +34,7 @@
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
//#define TLV_DEBUG 1 #define TLV_DEBUG 1
/************************************* RsTlvSecurityKey ************************************/ /************************************* RsTlvSecurityKey ************************************/
@ -322,7 +322,7 @@ bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset) /
if (ok) if (ok)
{ {
keys[key.keyId] = key; keys[key.keyId] = key;
key.ShallowClear(); /* so that the Map can get control - should be ref counted*/ key.TlvClear(); /* so that the Map can get control - should be ref counted*/
} }
} }
break; break;
@ -520,3 +520,170 @@ std::ostream &RsTlvKeySignature::print(std::ostream &out, uint16_t indent)
return out; return out;
} }
/************************************* RsTlvKeySignatureSet ************************************/
RsTlvKeySignatureSet::RsTlvKeySignatureSet()
{
}
std::ostream &RsTlvKeySignatureSet::print(std::ostream &out, uint16_t indent)
{
printBase(out, "RsTlvKeySignatureSet", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
std::map<SignType, RsTlvKeySignature>::iterator mit = keySignSet.begin();
for(; mit != keySignSet.end(); mit++)
{
out << "SignType: " << mit->first << std::endl;
RsTlvKeySignature& sign = mit->second;
sign.print(out, indent);
}
out << std::endl;
printEnd(out, "RsTlvKeySignatureSet", indent);
return out;
}
void RsTlvKeySignatureSet::TlvClear()
{
keySignSet.clear();
}
bool RsTlvKeySignatureSet::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
/* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvKeySignatureSet::SetTlv() Failed not enough space";
std::cerr << std::endl;
#endif
return false; /* not enough space */
}
bool ok = true;
/* start at data[offset] */
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_KEYSIGNATURESET , tlvsize);
if(!keySignSet.empty())
{
std::map<SignType, RsTlvKeySignature>::iterator it;
for(it = keySignSet.begin(); it != keySignSet.end() ; ++it)
{
ok &= SetTlvUInt32(data, size, offset, TLV_TYPE_KEYSIGNATURETYPE, it->first);
ok &= (it->second).SetTlv(data, size, offset);
}
}
return ok;
}
bool RsTlvKeySignatureSet::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend) /* check size */
return false; /* not enough space */
if (tlvtype != TLV_TYPE_KEYSIGNATURESET) /* check type */
return false;
bool ok = true;
/* ready to load */
TlvClear();
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
SignType sign_type = 0;
/* while there is TLV */
while((*offset) + 2 < tlvend)
{
/* get the next type */
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
SignType currType;
switch(tlvsubtype)
{
case TLV_TYPE_KEYSIGNATURE:
{
RsTlvKeySignature sign;
ok &= sign.GetTlv(data, size, offset);
if (ok)
{
keySignSet[currType] = sign;
}
}
break;
case TLV_TYPE_KEYSIGNATURETYPE:
{
ok = GetTlvUInt32(data, size, offset, TLV_TYPE_KEYSIGNATURETYPE, &sign_type);
if(ok)
currType = sign_type;
}
break;
default:
ok &= SkipUnknownTlv(data, tlvend, offset);
break;
}
if (!ok)
break;
}
/***************************************************************************
* NB: extra components could be added (for future expansion of the type).
* or be present (if this code is reading an extended version).
*
* We must chew up the extra characters to conform with TLV specifications
***************************************************************************/
if (*offset != tlvend)
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvKeySignatureSet::GetTlv() Warning extra bytes at end of item";
std::cerr << std::endl;
#endif
*offset = tlvend;
}
return ok;
}
uint32_t RsTlvKeySignatureSet::TlvSize()
{
uint32_t s = TLV_HEADER_SIZE; // header size
std::map<SignType, RsTlvKeySignature>::iterator it;
for(it = keySignSet.begin(); it != keySignSet.end() ; ++it)
{
s += GetTlvUInt32Size(); // sign type
s += it->second.TlvSize(); // signature
}
return s;
}

View file

@ -41,6 +41,7 @@ const uint32_t RSTLV_KEY_TYPE_SHARED = 0x0004;
const uint32_t RSTLV_KEY_DISTRIB_PUBLIC = 0x0010; const uint32_t RSTLV_KEY_DISTRIB_PUBLIC = 0x0010;
const uint32_t RSTLV_KEY_DISTRIB_PRIVATE = 0x0020; const uint32_t RSTLV_KEY_DISTRIB_PRIVATE = 0x0020;
const uint32_t RSTLV_KEY_DISTRIB_ADMIN = 0x0040; const uint32_t RSTLV_KEY_DISTRIB_ADMIN = 0x0040;
const uint32_t RSTLV_KEY_DISTRIB_IDENTITY = 0x0080;
class RsTlvSecurityKey: public RsTlvItem class RsTlvSecurityKey: public RsTlvItem
@ -98,6 +99,21 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
// NO Certificates in Signatures... add as separate data type. // NO Certificates in Signatures... add as separate data type.
}; };
typedef uint32_t SignType;
class RsTlvKeySignatureSet : public RsTlvItem
{
public:
RsTlvKeySignatureSet();
virtual ~RsTlvKeySignatureSet() { return; }
virtual uint32_t TlvSize();
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
virtual std::ostream &print(std::ostream &out, uint16_t indent);
std::map<SignType, RsTlvKeySignature> keySignSet; // mandatory
};
#endif #endif

View file

@ -0,0 +1,580 @@
/*
* libretroshare/src/serialiser: rswikiitems.cc
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* 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.1 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".
*
*/
#include <iostream>
#include "rswikiitems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#define GXSID_DEBUG 1
uint32_t RsGxsWikiSerialiser::size(RsItem *item)
{
RsGxsWikiCollectionItem* grp_item = NULL;
RsGxsWikiSnapshotItem* snap_item = NULL;
RsGxsWikiCommentItem* com_item = NULL;
if((grp_item = dynamic_cast<RsGxsWikiCollectionItem*>(item)) != NULL)
{
return sizeGxsWikiCollectionItem(grp_item);
}
else if((snap_item = dynamic_cast<RsGxsWikiSnapshotItem*>(item)) != NULL)
{
return sizeGxsWikiSnapshotItem(snap_item);
}
else if((com_item = dynamic_cast<RsGxsWikiCommentItem*>(item)) != NULL)
{
return sizeGxsWikiCommentItem(com_item);
}
return NULL;
}
bool RsGxsWikiSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsWikiCollectionItem* grp_item = NULL;
RsGxsWikiSnapshotItem* snap_item = NULL;
RsGxsWikiCommentItem* com_item = NULL;
if((grp_item = dynamic_cast<RsGxsWikiCollectionItem*>(item)) != NULL)
{
return serialiseGxsWikiCollectionItem(grp_item, data, size);
}
else if((snap_item = dynamic_cast<RsGxsWikiSnapshotItem*>(item)) != NULL)
{
return serialiseGxsWikiSnapshotItem(snap_item, data, size);
}
else if((com_item = dynamic_cast<RsGxsWikiCommentItem*>(item)) != NULL)
{
return serialiseGxsWikiCommentItem(com_item, data, size);
}
return false;
}
RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM:
return deserialiseGxsWikiCollectionItem(data, size);
break;
case RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM:
return deserialiseGxsWikiSnapshotItem(data, size);
break;
case RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM:
return deserialiseGxsWikiCommentItem(data, size);
break;
default:
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsWikiCollectionItem::clear()
{
collection.mDescription.clear();
collection.mCategory.clear();
collection.mHashTags.clear();
}
std::ostream& RsGxsWikiCollectionItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWikiCollectionItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Description: " << collection.mDescription << std::endl;
printIndent(out, int_Indent);
out << "Category: " << collection.mCategory << std::endl;
printIndent(out, int_Indent);
out << "HashTags: " << collection.mHashTags << std::endl;
printRsItemEnd(out ,"RsGxsWikiCollectionItem", indent);
return out;
}
uint32_t RsGxsWikiSerialiser::sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item)
{
const RsWikiCollection& collection = item->collection;
uint32_t s = 8; // header
s += GetTlvStringSize(collection.mDescription);
s += GetTlvStringSize(collection.mCategory);
s += GetTlvStringSize(collection.mHashTags);
return s;
}
bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWikiCollectionItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWikiCollectionItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->collection.mDescription);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->collection.mCategory);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->collection.mHashTags);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWikiCollectionItem* RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWikiCollectionItem* item = new RsGxsWikiCollectionItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->collection.mDescription);
ok &= GetTlvString(data, rssize, &offset, 1, item->collection.mCategory);
ok &= GetTlvString(data, rssize, &offset, 1, item->collection.mHashTags);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsWikiSnapshotItem::clear()
{
snapshot.mPage.clear();
snapshot.mHashTags.clear();
}
std::ostream& RsGxsWikiSnapshotItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWikiSnapshotItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Page: " << snapshot.mPage << std::endl;
printIndent(out, int_Indent);
out << "HashTags: " << snapshot.mHashTags << std::endl;
printRsItemEnd(out ,"RsGxsWikiSnapshotItem", indent);
return out;
}
uint32_t RsGxsWikiSerialiser::sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item)
{
const RsWikiSnapshot& snapshot = item->snapshot;
uint32_t s = 8; // header
s += GetTlvStringSize(snapshot.mPage);
s += GetTlvStringSize(snapshot.mHashTags);
return s;
}
bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWikiSnapshotItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWikiSnapshotItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->snapshot.mPage);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->snapshot.mHashTags);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWikiSnapshotItem* RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWikiSnapshotItem* item = new RsGxsWikiSnapshotItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->snapshot.mPage);
ok &= GetTlvString(data, rssize, &offset, 1, item->snapshot.mHashTags);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsWikiCommentItem::clear()
{
comment.mComment.clear();
}
std::ostream& RsGxsWikiCommentItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWikiCommentItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Comment: " << comment.mComment << std::endl;
printRsItemEnd(out ,"RsGxsWikiCommentItem", indent);
return out;
}
uint32_t RsGxsWikiSerialiser::sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item)
{
const RsWikiComment& comment = item->comment;
uint32_t s = 8; // header
s += GetTlvStringSize(comment.mComment);
return s;
}
bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWikiCommentItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWikiCommentItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->comment.mComment);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWikiCommentItem* RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWikiCommentItem* item = new RsGxsWikiCommentItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->comment.mComment);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/

View file

@ -0,0 +1,112 @@
/*
* libretroshare/src/serialiser: rswikiitems.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* 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.1 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".
*
*/
#ifndef RS_WIKI_ITEMS_H
#define RS_WIKI_ITEMS_H
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rswiki.h"
const uint8_t RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM = 0x03;
const uint8_t RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM = 0x04;
class RsGxsWikiCollectionItem : public RsGxsGrpItem
{
public:
RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_WIKI,
RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM) { return;}
virtual ~RsGxsWikiCollectionItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsWikiCollection collection;
};
class RsGxsWikiSnapshotItem : public RsGxsMsgItem
{
public:
RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIKI,
RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM) {return; }
virtual ~RsGxsWikiSnapshotItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsWikiSnapshot snapshot;
};
class RsGxsWikiCommentItem : public RsGxsMsgItem
{
public:
RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIKI,
RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM) { return; }
virtual ~RsGxsWikiCommentItem() { return; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsWikiComment comment;
};
class RsGxsWikiSerialiser : public RsSerialType
{
public:
RsGxsWikiSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_WIKI)
{ return; }
virtual ~RsGxsWikiSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item);
bool serialiseGxsWikiCollectionItem (RsGxsWikiCollectionItem *item, void *data, uint32_t *size);
RsGxsWikiCollectionItem * deserialiseGxsWikiCollectionItem(void *data, uint32_t *size);
uint32_t sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item);
bool serialiseGxsWikiSnapshotItem (RsGxsWikiSnapshotItem *item, void *data, uint32_t *size);
RsGxsWikiSnapshotItem * deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size);
uint32_t sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item);
bool serialiseGxsWikiCommentItem (RsGxsWikiCommentItem *item, void *data, uint32_t *size);
RsGxsWikiCommentItem * deserialiseGxsWikiCommentItem(void *data, uint32_t *size);
};
#endif /* RS_WIKI_ITEMS_H */

View file

@ -0,0 +1,408 @@
/*
* libretroshare/src/serialiser: rswikiitems.cc
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* 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.1 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".
*
*/
#include <iostream>
#include "rswireitems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#define WIRE_DEBUG 1
uint32_t RsGxsWireSerialiser::size(RsItem *item)
{
RsGxsWireGroupItem* grp_item = NULL;
RsGxsWirePulseItem* snap_item = NULL;
if((grp_item = dynamic_cast<RsGxsWireGroupItem*>(item)) != NULL)
{
return sizeGxsWireGroupItem(grp_item);
}
else if((snap_item = dynamic_cast<RsGxsWirePulseItem*>(item)) != NULL)
{
return sizeGxsWirePulseItem(snap_item);
}
return NULL;
}
bool RsGxsWireSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsWireGroupItem* grp_item = NULL;
RsGxsWirePulseItem* snap_item = NULL;
if((grp_item = dynamic_cast<RsGxsWireGroupItem*>(item)) != NULL)
{
return serialiseGxsWireGroupItem(grp_item, data, size);
}
else if((snap_item = dynamic_cast<RsGxsWirePulseItem*>(item)) != NULL)
{
return serialiseGxsWirePulseItem(snap_item, data, size);
}
return false;
}
RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_WIRE != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM:
return deserialiseGxsWireGroupItem(data, size);
break;
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM:
return deserialiseGxsWirePulseItem(data, size);
break;
default:
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsWireGroupItem::clear()
{
group.mDescription.clear();
}
std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWireGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Description: " << group.mDescription << std::endl;
printRsItemEnd(out ,"RsGxsWireGroupItem", indent);
return out;
}
uint32_t RsGxsWireSerialiser::sizeGxsWireGroupItem(RsGxsWireGroupItem *item)
{
const RsWireGroup& group = item->group;
uint32_t s = 8; // header
s += GetTlvStringSize(group.mDescription);
return s;
}
bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWireGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWireGroupItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mDescription);
if(offset != tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef WIRE_DEBUG
if (!ok)
{
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWireGroupItem* RsGxsWireSerialiser::deserialiseGxsWireGroupItem(void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_WIRE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIRE_GROUP_ITEM != getRsItemSubType(rstype)))
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWireGroupItem* item = new RsGxsWireGroupItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mDescription);
if (offset != rssize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsWirePulseItem::clear()
{
pulse.mPulseText.clear();
pulse.mHashTags.clear();
}
std::ostream& RsGxsWirePulseItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWirePulseItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Page: " << pulse.mPulseText << std::endl;
printIndent(out, int_Indent);
out << "HashTags: " << pulse.mHashTags << std::endl;
printRsItemEnd(out ,"RsGxsWirePulseItem", indent);
return out;
}
uint32_t RsGxsWireSerialiser::sizeGxsWirePulseItem(RsGxsWirePulseItem *item)
{
const RsWirePulse& pulse = item->pulse;
uint32_t s = 8; // header
s += GetTlvStringSize(pulse.mPulseText);
s += GetTlvStringSize(pulse.mHashTags);
return s;
}
bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWirePulseItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWirePulseItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mPulseText);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mHashTags);
if(offset != tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef WIRE_DEBUG
if (!ok)
{
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_WIRE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIRE_PULSE_ITEM != getRsItemSubType(rstype)))
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWirePulseItem* item = new RsGxsWirePulseItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->pulse.mPulseText);
ok &= GetTlvString(data, rssize, &offset, 1, item->pulse.mHashTags);
if (offset != rssize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/

View file

@ -0,0 +1,93 @@
/*
* libretroshare/src/serialiser: rswireitems.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* 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.1 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".
*
*/
#ifndef RS_WIRE_ITEMS_H
#define RS_WIRE_ITEMS_H
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rswire.h"
const uint8_t RS_PKT_SUBTYPE_WIRE_GROUP_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_WIRE_PULSE_ITEM = 0x03;
class RsGxsWireGroupItem : public RsGxsGrpItem
{
public:
RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_WIRE,
RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) { return;}
virtual ~RsGxsWireGroupItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsWireGroup group;
};
class RsGxsWirePulseItem : public RsGxsMsgItem
{
public:
RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIRE,
RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {return; }
virtual ~RsGxsWirePulseItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsWirePulse pulse;
};
class RsGxsWireSerialiser : public RsSerialType
{
public:
RsGxsWireSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_WIRE)
{ return; }
virtual ~RsGxsWireSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsWireGroupItem(RsGxsWireGroupItem *item);
bool serialiseGxsWireGroupItem (RsGxsWireGroupItem *item, void *data, uint32_t *size);
RsGxsWireGroupItem * deserialiseGxsWireGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsWirePulseItem(RsGxsWirePulseItem *item);
bool serialiseGxsWirePulseItem (RsGxsWirePulseItem *item, void *data, uint32_t *size);
RsGxsWirePulseItem * deserialiseGxsWirePulseItem(void *data, uint32_t *size);
};
#endif /* RS_WIKI_ITEMS_H */

View file

@ -1,805 +0,0 @@
/*
* libretroshare/src/services p3forumsv2.cc
*
* ForumsV2 interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* 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.1 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".
*
*/
#include "services/p3forumsv2.h"
#include "util/rsrandom.h"
#include <stdio.h>
/****
* #define FORUMV2_DEBUG 1
****/
RsForumsV2 *rsForumsV2 = NULL;
/********************************************************************************/
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3ForumsV2::p3ForumsV2(uint16_t type)
:p3GxsDataService(type, new ForumDataProxy()), mForumMtx("p3ForumsV2"), mUpdated(true)
{
{
RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/
mForumProxy = (ForumDataProxy *) mProxy;
}
generateDummyData();
return;
}
int p3ForumsV2::tick()
{
std::cerr << "p3ForumsV2::tick()";
std::cerr << std::endl;
fakeprocessrequests();
return 0;
}
bool p3ForumsV2::updated()
{
RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/
if (mUpdated)
{
mUpdated = false;
return true;
}
return false;
}
/* Data Requests */
bool p3ForumsV2::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "p3ForumsV2::requestGroupInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
return true;
}
bool p3ForumsV2::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "p3ForumsV2::requestMsgInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds);
return true;
}
bool p3ForumsV2::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &msgIds)
{
generateToken(token);
std::cerr << "p3ForumsV2::requestMsgRelatedInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
/* Generic Lists */
bool p3ForumsV2::getGroupList( const uint32_t &token, std::list<std::string> &groupIds)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
{
std::cerr << "p3ForumsV2::getGroupList() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3ForumsV2::getGroupList() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsV2::getGroupList() ERROR Status Incomplete" << std::endl;
return false;
}
bool ans = loadRequestOutList(token, groupIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return ans;
}
bool p3ForumsV2::getMsgList( const uint32_t &token, std::list<std::string> &msgIds)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
{
std::cerr << "p3ForumsV2::getMsgList() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3ForumsV2::getMsgList() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsV2::getMsgList() ERROR Status Incomplete" << std::endl;
return false;
}
bool ans = loadRequestOutList(token, msgIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return ans;
}
/* Generic Summary */
bool p3ForumsV2::getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "p3ForumsV2::getGroupSummary() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3ForumsV2::getGroupSummary() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsV2::getGroupSummary() ERROR Status Incomplete" << std::endl;
return false;
}
std::list<std::string> groupIds;
bool ans = loadRequestOutList(token, groupIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
/* convert to RsGroupMetaData */
mProxy->getGroupSummary(groupIds, groupInfo);
return ans;
}
bool p3ForumsV2::getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "p3ForumsV2::getMsgSummary() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3ForumsV2::getMsgSummary() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsV2::getMsgSummary() ERROR Status Incomplete" << std::endl;
return false;
}
std::list<std::string> msgIds;
bool ans = loadRequestOutList(token, msgIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
/* convert to RsMsgMetaData */
mProxy->getMsgSummary(msgIds, msgInfo);
return ans;
}
/* Specific Service Data */
bool p3ForumsV2::getGroupData(const uint32_t &token, RsForumV2Group &group)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
{
std::cerr << "p3ForumsV2::getGroupData() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3ForumsV2::getGroupData() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsV2::getGroupData() ERROR Status Incomplete" << std::endl;
return false;
}
std::string id;
if (!popRequestOutList(token, id))
{
/* finished */
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return false;
}
/* convert to RsForumAlbum */
bool ans = mForumProxy->getForumGroup(id, group);
return ans;
}
bool p3ForumsV2::getMsgData(const uint32_t &token, RsForumV2Msg &msg)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
{
std::cerr << "p3ForumsV2::getMsgData() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3ForumsV2::getMsgData() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsV2::getMsgData() ERROR Status Incomplete" << std::endl;
return false;
}
std::string id;
if (!popRequestOutList(token, id))
{
/* finished */
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return false;
}
/* convert to RsForumAlbum */
bool ans = mForumProxy->getForumMsg(id, msg);
return ans;
}
/* Poll */
uint32_t p3ForumsV2::requestStatus(const uint32_t token)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
return status;
}
/* Cancel Request */
bool p3ForumsV2::cancelRequest(const uint32_t &token)
{
return clearRequest(token);
}
//////////////////////////////////////////////////////////////////////////////
bool p3ForumsV2::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask)
{
return mForumProxy->setMessageStatus(msgId, status, statusMask);
}
bool p3ForumsV2::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask)
{
return mForumProxy->setGroupStatus(groupId, status, statusMask);
}
bool p3ForumsV2::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask)
{
return mForumProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask);
}
bool p3ForumsV2::setMessageServiceString(const std::string &msgId, const std::string &str)
{
return mForumProxy->setMessageServiceString(msgId, str);
}
bool p3ForumsV2::setGroupServiceString(const std::string &grpId, const std::string &str)
{
return mForumProxy->setGroupServiceString(grpId, str);
}
bool p3ForumsV2::groupRestoreKeys(const std::string &groupId)
{
return false;
}
bool p3ForumsV2::groupShareKeys(const std::string &groupId, std::list<std::string>& peers)
{
return false;
}
/********************************************************************************************/
std::string p3ForumsV2::genRandomId()
{
std::string randomId;
for(int i = 0; i < 20; i++)
{
randomId += (char) ('a' + (RSRandom::random_u32() % 26));
}
return randomId;
}
bool p3ForumsV2::createGroup(uint32_t &token, RsForumV2Group &group, bool isNew)
{
if (group.mMeta.mGroupId.empty())
{
/* new photo */
/* generate a temp id */
group.mMeta.mGroupId = genRandomId();
}
else
{
std::cerr << "p3ForumsV2::createGroup() Group with existing Id... dropping";
std::cerr << std::endl;
return false;
}
{
RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/
mUpdated = true;
mForumProxy->addForumGroup(group);
}
// Fake a request to return the GroupMetaData.
generateToken(token);
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptions opts; // NULL is good.
std::list<std::string> groupIds;
groupIds.push_back(group.mMeta.mGroupId); // It will just return this one.
std::cerr << "p3ForumsV2::createGroup() Generating Request Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
return true;
}
bool p3ForumsV2::createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew)
{
if (msg.mMeta.mGroupId.empty())
{
/* new photo */
std::cerr << "p3ForumsV2::createForumMsg() Missing MsgID";
std::cerr << std::endl;
return false;
}
/* check if its a mod or new msg */
if (msg.mMeta.mOrigMsgId.empty())
{
std::cerr << "p3ForumsV2::createForumMsg() New Msg";
std::cerr << std::endl;
/* new msg, generate a new OrigMsgId */
msg.mMeta.mOrigMsgId = genRandomId();
msg.mMeta.mMsgId = msg.mMeta.mOrigMsgId;
}
else
{
std::cerr << "p3ForumsV2::createForumMsg() Modified Msg";
std::cerr << std::endl;
/* mod msg, keep orig msg id, generate a new MsgId */
msg.mMeta.mMsgId = genRandomId();
}
std::cerr << "p3ForumsV2::createForumMsg() GroupId: " << msg.mMeta.mGroupId;
std::cerr << std::endl;
std::cerr << "p3ForumsV2::createForumMsg() MsgId: " << msg.mMeta.mMsgId;
std::cerr << std::endl;
std::cerr << "p3ForumsV2::createForumMsg() OrigMsgId: " << msg.mMeta.mOrigMsgId;
std::cerr << std::endl;
{
RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/
mUpdated = true;
mForumProxy->addForumMsg(msg);
}
// Fake a request to return the MsgMetaData.
generateToken(token);
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptions opts; // NULL is good.
std::list<std::string> msgIds;
msgIds.push_back(msg.mMeta.mMsgId); // It will just return this one.
std::cerr << "p3ForumsV2::createMsg() Generating Request Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
/********************************************************************************************/
bool ForumDataProxy::getForumGroup(const std::string &id, RsForumV2Group &group)
{
void *groupData = NULL;
RsGroupMetaData meta;
if (getGroupData(id, groupData) && getGroupSummary(id, meta))
{
RsForumV2Group *pG = (RsForumV2Group *) groupData;
group = *pG;
// update definitive version of the metadata.
group.mMeta = meta;
std::cerr << "ForumDataProxy::getForumGroup() Id: " << id;
std::cerr << " MetaData: " << meta << " DataPointer: " << groupData;
std::cerr << std::endl;
return true;
}
std::cerr << "ForumDataProxy::getForumGroup() FAILED Id: " << id;
std::cerr << std::endl;
return false;
}
bool ForumDataProxy::getForumMsg(const std::string &id, RsForumV2Msg &page)
{
void *msgData = NULL;
RsMsgMetaData meta;
if (getMsgData(id, msgData) && getMsgSummary(id, meta))
{
RsForumV2Msg *pP = (RsForumV2Msg *) msgData;
// Shallow copy of thumbnail.
page = *pP;
// update definitive version of the metadata.
page.mMeta = meta;
std::cerr << "ForumDataProxy::getForumMsg() Id: " << id;
std::cerr << " MetaData: " << meta << " DataPointer: " << msgData;
std::cerr << std::endl;
return true;
}
std::cerr << "ForumDataProxy::getForumMsg() FAILED Id: " << id;
std::cerr << std::endl;
return false;
}
bool ForumDataProxy::addForumGroup(const RsForumV2Group &group)
{
// Make duplicate.
RsForumV2Group *pG = new RsForumV2Group();
*pG = group;
std::cerr << "ForumDataProxy::addForumGroup()";
std::cerr << " MetaData: " << pG->mMeta << " DataPointer: " << pG;
std::cerr << std::endl;
return createGroup(pG);
}
bool ForumDataProxy::addForumMsg(const RsForumV2Msg &msg)
{
// Make duplicate.
RsForumV2Msg *pM = new RsForumV2Msg();
*pM = msg;
std::cerr << "ForumDataProxy::addForumMsg()";
std::cerr << " MetaData: " << pM->mMeta << " DataPointer: " << pM;
std::cerr << std::endl;
return createMsg(pM);
}
/* These Functions must be overloaded to complete the service */
bool ForumDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta)
{
RsForumV2Group *group = (RsForumV2Group *) groupData;
meta = group->mMeta;
return true;
}
bool ForumDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta)
{
RsForumV2Msg *page = (RsForumV2Msg *) msgData;
meta = page->mMeta;
return true;
}
/********************************************************************************************/
bool p3ForumsV2::generateDummyData()
{
/* so we want to generate 100's of forums */
#define MAX_FORUMS 10 //100
#define MAX_THREADS 10 //1000
#define MAX_MSGS 100 //10000
std::list<RsForumV2Group> mGroups;
std::list<RsForumV2Group>::iterator git;
std::list<RsForumV2Msg> mMsgs;
std::list<RsForumV2Msg>::iterator mit;
#define DUMMY_NAME_MAX_LEN 10000
char name[DUMMY_NAME_MAX_LEN];
int i, j;
time_t now = time(NULL);
for(i = 0; i < MAX_FORUMS; i++)
{
/* generate a new forum */
RsForumV2Group forum;
/* generate a temp id */
forum.mMeta.mGroupId = genRandomId();
snprintf(name, DUMMY_NAME_MAX_LEN, "TestForum_%d", i+1);
forum.mMeta.mGroupId = genRandomId();
forum.mMeta.mGroupName = name;
forum.mMeta.mPublishTs = now - (RSRandom::random_f32() * 100000);
/* key fields to fill in:
* GroupId.
* Name.
* Flags.
* Pop.
*/
/* use probability to decide which are subscribed / own / popularity.
*/
float rnd = RSRandom::random_f32();
if (rnd < 0.1)
{
forum.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_ADMIN;
}
else if (rnd < 0.3)
{
forum.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED;
}
else
{
forum.mMeta.mSubscribeFlags = 0;
}
forum.mMeta.mPop = (int) (RSRandom::random_f32() * 10.0);
mGroups.push_back(forum);
//std::cerr << "p3ForumsV2::generateDummyData() Generated Forum: " << forum.mMeta;
//std::cerr << std::endl;
}
for(i = 0; i < MAX_THREADS; i++)
{
/* generate a base thread */
/* rotate the Forum Groups Around, then pick one.
*/
int rnd = (int) (RSRandom::random_f32() * 10.0);
for(j = 0; j < rnd; j++)
{
RsForumV2Group head = mGroups.front();
mGroups.pop_front();
mGroups.push_back(head);
}
RsForumV2Group forum = mGroups.front();
/* now create a new thread */
RsForumV2Msg msg;
/* fill in key data
* GroupId
* MsgId
* OrigMsgId
* ThreadId
* ParentId
* PublishTS (take Forum TS + a bit ).
*
* ChildTS ????
*/
snprintf(name, DUMMY_NAME_MAX_LEN, "%s => ThreadMsg_%d", forum.mMeta.mGroupName.c_str(), i+1);
msg.mMeta.mMsgName = name;
msg.mMeta.mGroupId = forum.mMeta.mGroupId;
msg.mMeta.mMsgId = genRandomId();
msg.mMeta.mOrigMsgId = msg.mMeta.mMsgId;
msg.mMeta.mThreadId = msg.mMeta.mMsgId;
msg.mMeta.mParentId = "";
msg.mMeta.mPublishTs = forum.mMeta.mPublishTs + (RSRandom::random_f32() * 10000);
if (msg.mMeta.mPublishTs > now)
msg.mMeta.mPublishTs = now - 1;
mMsgs.push_back(msg);
//std::cerr << "p3ForumsV2::generateDummyData() Generated Thread: " << msg.mMeta;
//std::cerr << std::endl;
}
for(i = 0; i < MAX_MSGS; i++)
{
/* generate a base thread */
/* rotate the Forum Groups Around, then pick one.
*/
int rnd = (int) (RSRandom::random_f32() * 10.0);
for(j = 0; j < rnd; j++)
{
RsForumV2Msg head = mMsgs.front();
mMsgs.pop_front();
mMsgs.push_back(head);
}
RsForumV2Msg parent = mMsgs.front();
/* now create a new child msg */
RsForumV2Msg msg;
/* fill in key data
* GroupId
* MsgId
* OrigMsgId
* ThreadId
* ParentId
* PublishTS (take Forum TS + a bit ).
*
* ChildTS ????
*/
snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Msg_%d", parent.mMeta.mMsgName.c_str(), i+1);
msg.mMeta.mMsgName = name;
msg.mMsg = name;
msg.mMeta.mGroupId = parent.mMeta.mGroupId;
msg.mMeta.mMsgId = genRandomId();
msg.mMeta.mOrigMsgId = msg.mMeta.mMsgId;
msg.mMeta.mThreadId = parent.mMeta.mThreadId;
msg.mMeta.mParentId = parent.mMeta.mOrigMsgId;
msg.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000);
if (msg.mMeta.mPublishTs > now)
msg.mMeta.mPublishTs = now - 1;
mMsgs.push_back(msg);
//std::cerr << "p3ForumsV2::generateDummyData() Generated Child Msg: " << msg.mMeta;
//std::cerr << std::endl;
}
mUpdated = true;
/* Then - at the end, we push them all into the Proxy */
for(git = mGroups.begin(); git != mGroups.end(); git++)
{
/* pushback */
mForumProxy->addForumGroup(*git);
}
for(mit = mMsgs.begin(); mit != mMsgs.end(); mit++)
{
/* pushback */
mForumProxy->addForumMsg(*mit);
}
return true;
}

View file

@ -1,126 +0,0 @@
/*
* libretroshare/src/services: p3forumsv2.h
*
* Wiki interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* 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".
*
*/
#ifndef P3_FORUMSV2_SERVICE_HEADER
#define P3_FORUMSV2_SERVICE_HEADER
#include "services/p3gxsservice.h"
#include "retroshare/rsforumsv2.h"
#include <map>
#include <string>
/*
*
*/
class ForumDataProxy: public GxsDataProxy
{
public:
bool getForumGroup(const std::string &id, RsForumV2Group &group);
bool getForumMsg(const std::string &id, RsForumV2Msg &msg);
bool addForumGroup(const RsForumV2Group &group);
bool addForumMsg(const RsForumV2Msg &msg);
/* These Functions must be overloaded to complete the service */
virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta);
virtual bool convertMsgToMetaData(void *msgData, RsMsgMetaData &meta);
};
class p3ForumsV2: public p3GxsDataService, public RsForumsV2
{
public:
p3ForumsV2(uint16_t type);
virtual int tick();
public:
virtual bool updated();
/* Data Requests */
virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &msgIds);
/* Generic Lists */
virtual bool getGroupList( const uint32_t &token, std::list<std::string> &groupIds);
virtual bool getMsgList( const uint32_t &token, std::list<std::string> &msgIds);
/* Generic Summary */
virtual bool getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
virtual bool getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo);
/* Actual Data -> specific to Interface */
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsForumV2Group &group);
virtual bool getMsgData(const uint32_t &token, RsForumV2Msg &msg);
/* Poll */
virtual uint32_t requestStatus(const uint32_t token);
/* Cancel Request */
virtual bool cancelRequest(const uint32_t &token);
//////////////////////////////////////////////////////////////////////////////
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
virtual bool setMessageServiceString(const std::string &msgId, const std::string &str);
virtual bool setGroupServiceString(const std::string &grpId, const std::string &str);
virtual bool groupRestoreKeys(const std::string &groupId);
virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
virtual bool createGroup(uint32_t &token, RsForumV2Group &group, bool isNew);
virtual bool createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew);
private:
std::string genRandomId();
bool generateDummyData();
ForumDataProxy *mForumProxy;
RsMutex mForumMtx;
/***** below here is locked *****/
bool mUpdated;
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,246 @@
/*
* libretroshare/src/services: p3circles.h
*
* Identity interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* 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.1 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".
*
*/
#ifndef P3_CIRCLES_SERVICE_HEADER
#define P3_CIRCLES_SERVICE_HEADER
#include "retroshare/rsgxscircles.h" // External Interfaces.
#include "gxs/rsgenexchange.h" // GXS service.
#include "gxs/rsgixs.h" // Internal Interfaces.
#include "services/p3idservice.h" // For constructing Caches
#include "gxs/gxstokenqueue.h"
#include "util/rstickevent.h"
#include "util/rsmemcache.h"
#include <map>
#include <string>
/*
* Circles Identity Service
*
* A collection of notes:
*
* We want to be able to express the following types of Circles.
*
* - Public
* - Groups & Messages can be passed onto anyone. ( No Restrictions. )
* - GXS Notes:
* - This is what we have currently.
*
* - External Circle
* - List of Identities that can receive the Group / Messages.
* - This list will be defined via a set of RsIdentities - which have PGPHashes set.
* - We need the PGPHashes to be able to identify which peers can receive msgs.
* - Messages are passed to the Intersection of (Identified PGPHashes & Friends)
* - Distribution of Circle Definitions can be also be restricted via circles.
* - You can have Public External Groups, or Groups that only the Members know about.
* - Control of these External Groups is determined by Admin / Publish Keys.
* - The Danger with External Groups, is your ID wll be associated with other people...
* - Leaking information!!!
* - GXS Notes:
* - p3Circles will provide a distrib list for a given Circle Group.
*
* - Personal Circle or "Your Eyes Only".
* - Same as an Internal Circle Definition. (What will be used for File Sharing initially)
* - Each peer will have a bunch of these, Friends, Family, etc.
*
* - The list is not publically shared, only the originator of the message will distribute.
* - You can communicate back to the originator, who will share with the other members.
* but you mustn't discuss / share content with anyone else.
* - This is quite a Weak / Fragile Group, as there is only one distributor.
* - GXS NOTES:
* - TO make this work, we need GXS or RsCircles to maintain extra info:
* - GXS stores the original source, so communications can go back there.
* - If Originator, GXS store a REFERENCE, Circles turn this into a distrib list of peers.
*
*
*
* Like RsIdentities are used to validation messages,
* RsCircles will be used to determine if a peer can receive a group / messages.
*
* bool RsCircles::canSend(RsGxsCircleId, RsPeerId)
* bool RsCircles::canSend(RsCircleInternalId, RsPeerId)
*
* or maybe just:
*
* bool RsCircles::recipients(GxsPermission &perms, std::list<RsPeerId> friendlist);
*
*/
/* Permissions is part of GroupMetaData
*/
class RsGxsCircleCache
{
public:
RsGxsCircleCache();
bool loadBaseCircle(const RsGxsCircleGroup &circle);
bool loadSubCircle(const RsGxsCircleCache &subcircle);
bool getAllowedPeersList(std::list<RsPgpId> &friendlist);
bool isAllowedPeer(const RsPgpId &id);
bool addAllowedPeer(const RsPgpId &pgpid, const RsGxsId &gxsId);
RsGxsCircleId mCircleId;
std::string mCircleName;
time_t mUpdateTime;
std::set<RsGxsCircleId> mUnprocessedCircles;
std::set<RsGxsId> mUnprocessedPeers;
std::set<RsGxsCircleId> mProcessedCircles;
std::set<RsGxsId> mUnknownPeers;
std::map<RsPgpId, std::list<RsGxsId> > mAllowedPeers;
};
class RsCircles
{
/* Functions to handle Local / Internal Circles == Same as for file permissions. */
public:
virtual void createLocalCircle() = 0;
virtual void addToLocalCircle() = 0;
virtual void removeFromLocalCircle() = 0;
virtual void getLocalCirclePeers() = 0;
virtual void getListOfLocalCircles() = 0;
/* similar functions for External Groups */
virtual bool createGroup(uint32_t& token, RsGxsCircleGroup &group) = 0;
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups) = 0;
};
class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles,
public GxsTokenQueue, public RsTickEvent
{
public:
p3GxsCircles(RsGeneralDataService* gds, RsNetworkExchangeService* nes,
p3IdService *identities);
/*********** External Interface ***************/
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details);
virtual bool getCircleIdList(std::list<RsGxsCircleId> &circleIds);
virtual bool isLoaded(const RsGxsCircleId &circleId);
virtual bool loadCircle(const RsGxsCircleId &circleId);
virtual int canSend(const RsGxsCircleId &circleId, const RsPgpId &id);
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId> &friendlist);
/*******/
virtual void createLocalCircle();
virtual void addToLocalCircle();
virtual void removeFromLocalCircle();
virtual void getLocalCirclePeers();
virtual void getListOfLocalCircles();
/*******/
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups);
virtual bool createGroup(uint32_t& token, RsGxsCircleGroup &group);
/**********************************************/
// needed for background processing.
virtual void service_tick();
protected:
static uint32_t circleAuthenPolicy();
/** Notifications **/
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
/** Overloaded to add PgpIdHash to Group Definition **/
virtual void service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
// Overloaded from GxsTokenQueue for Request callbacks.
virtual void handleResponse(uint32_t token, uint32_t req_type);
// Overloaded from RsTickEvent.
virtual void handle_event(uint32_t event_type, const std::string &elabel);
private:
// Load data.
bool request_CircleIdList();
bool load_CircleIdList(uint32_t token);
// Need some crazy arsed cache to store the circle info.
// so we don't have to keep loading groups.
int cache_tick();
bool cache_request_load(const RsGxsCircleId &id);
bool cache_start_load();
bool cache_load_for_token(uint32_t token);
bool cache_reloadids(const std::string &circleId);
p3IdService *mIdentities; // Needed for constructing Circle Info,
RsMutex mCircleMtx; /* Locked Below Here */
std::list<RsGxsCircleId> mCircleIdList;
/***** Caching Circle Info, *****/
// initial load queue
std::list<RsGxsCircleId> mCacheLoad_ToCache;
// waiting for subcircle to load. (first is part of each of the second list)
// TODO.
//std::map<RsGxsCircleId, std::list<RsGxsCircleId> > mCacheLoad_SubCircle;
// Circles that are being loaded.
std::map<RsGxsCircleId, RsGxsCircleCache> mLoadingCache;
// actual cache.
RsMemCache<RsGxsCircleId, RsGxsCircleCache> mCircleCache;
private:
std::string genRandomId();
void generateDummyData();
void checkDummyIdData();
void generateDummyCircle();
uint32_t mDummyIdToken;
std::list<RsGxsId> mDummyPgpLinkedIds;
std::list<RsGxsId> mDummyOwnIds;
};
#endif // P3_CIRCLES_SERVICE_HEADER

View file

@ -0,0 +1,471 @@
/*
* libretroshare/src/services p3gxsforums.cc
*
* GxsForums interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* 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.1 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".
*
*/
#include "services/p3gxsforums.h"
#include "serialiser/rsgxsforumitems.h"
#include <retroshare/rsidentity.h>
#include "gxs/rsgxsflags.h"
#include <stdio.h>
// For Dummy Msgs.
#include "util/rsrandom.h"
#include "util/rsstring.h"
/****
* #define GXSFORUM_DEBUG 1
****/
RsGxsForums *rsGxsForums = NULL;
#define FORUM_TESTEVENT_DUMMYDATA 0x0001
#define DUMMYDATA_PERIOD 60 // long enough for some RsIdentities to be generated.
/********************************************************************************/
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3GxsForums::p3GxsForums(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
: RsGenExchange(gds, nes, new RsGxsForumSerialiser(), RS_SERVICE_GXSV1_TYPE_FORUMS), RsGxsForums(this)
{
// For Dummy Msgs.
mGenActive = false;
RsTickEvent::schedule_in(FORUM_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
}
void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
{
receiveChanges(changes);
}
void p3GxsForums::service_tick()
{
dummy_tick();
RsTickEvent::tick_events();
return;
}
bool p3GxsForums::getGroupData(const uint32_t &token, std::vector<RsGxsForumGroup> &groups)
{
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
if(ok)
{
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
for(; vit != grpData.end(); vit++)
{
RsGxsForumGroupItem* item = dynamic_cast<RsGxsForumGroupItem*>(*vit);
RsGxsForumGroup grp = item->mGroup;
item->mGroup.mMeta = item->meta;
grp.mMeta = item->mGroup.mMeta;
delete item;
groups.push_back(grp);
}
}
return ok;
}
/* Okay - chris is not going to be happy with this...
* but I can't be bothered with crazy data structures
* at the moment - fix it up later
*/
bool p3GxsForums::getMsgData(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs)
{
GxsMsgDataMap msgData;
bool ok = RsGenExchange::getMsgData(token, msgData);
if(ok)
{
GxsMsgDataMap::iterator mit = msgData.begin();
for(; mit != msgData.end(); mit++)
{
RsGxsGroupId grpId = mit->first;
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
for(; vit != msgItems.end(); vit++)
{
RsGxsForumMsgItem* item = dynamic_cast<RsGxsForumMsgItem*>(*vit);
if(item)
{
RsGxsForumMsg msg = item->mMsg;
msg.mMeta = item->meta;
msgs.push_back(msg);
delete item;
}
else
{
std::cerr << "Not a GxsForumMsgItem, deleting!" << std::endl;
delete *vit;
}
}
}
}
return ok;
}
bool p3GxsForums::getRelatedMessages(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs)
{
GxsMsgRelatedDataMap msgData;
bool ok = RsGenExchange::getMsgRelatedData(token, msgData);
if(ok)
{
GxsMsgRelatedDataMap::iterator mit = msgData.begin();
for(; mit != msgData.end(); mit++)
{
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
for(; vit != msgItems.end(); vit++)
{
RsGxsForumMsgItem* item = dynamic_cast<RsGxsForumMsgItem*>(*vit);
if(item)
{
/* HACK UNTIL CHRIS FIXES RELATED MSGS in GXS */
if (item->meta.mMsgId == (mit->first).second)
{
std::cerr << "p3GxsForums::getRelatedMessages()";
std::cerr << " ERROR Found Original - discarding";
std::cerr << " Id: " << item->meta.mMsgId;
std::cerr << std::endl;
delete item;
continue;
}
if (item->meta.mParentId != (mit->first).second)
{
std::cerr << "p3GxsForums::getRelatedMessages()";
std::cerr << " ERROR Found !CHILD - discarding";
std::cerr << " Id: " << item->meta.mMsgId;
std::cerr << std::endl;
delete item;
continue;
}
RsGxsForumMsg msg = item->mMsg;
msg.mMeta = item->meta;
msgs.push_back(msg);
delete item;
}
else
{
std::cerr << "Not a GxsForumMsgItem, deleting!" << std::endl;
delete *vit;
}
}
}
}
return ok;
}
/********************************************************************************************/
bool p3GxsForums::createGroup(uint32_t &token, RsGxsForumGroup &group)
{
std::cerr << "p3GxsForums::createGroup()" << std::endl;
RsGxsForumGroupItem* grpItem = new RsGxsForumGroupItem();
grpItem->mGroup = group;
grpItem->meta = group.mMeta;
RsGenExchange::publishGroup(token, grpItem);
return true;
}
bool p3GxsForums::createMsg(uint32_t &token, RsGxsForumMsg &msg)
{
std::cerr << "p3GxsForums::createForumMsg() GroupId: " << msg.mMeta.mGroupId;
std::cerr << std::endl;
RsGxsForumMsgItem* msgItem = new RsGxsForumMsgItem();
msgItem->mMsg = msg;
msgItem->meta = msg.mMeta;
RsGenExchange::publishMsg(token, msgItem);
return true;
}
/********************************************************************************************/
/********************************************************************************************/
void p3GxsForums::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read)
{
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_UNREAD | GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
uint32_t status = GXS_SERV::GXS_MSG_STATUS_UNREAD;
if (read)
{
status = 0;
}
setMsgStatusFlags(token, msgId, status, mask);
}
/********************************************************************************************/
/********************************************************************************************/
/* so we need the same tick idea as wiki for generating dummy forums
*/
#define MAX_GEN_GROUPS 5
#define MAX_GEN_MESSAGES 100
std::string p3GxsForums::genRandomId()
{
std::string randomId;
for(int i = 0; i < 20; i++)
{
randomId += (char) ('a' + (RSRandom::random_u32() % 26));
}
return randomId;
}
bool p3GxsForums::generateDummyData()
{
mGenCount = 0;
mGenRefs.resize(MAX_GEN_MESSAGES);
std::string groupName;
rs_sprintf(groupName, "TestForum_%d", mGenCount);
std::cerr << "p3GxsForums::generateDummyData() Starting off with Group: " << groupName;
std::cerr << std::endl;
/* create a new group */
generateGroup(mGenToken, groupName);
mGenActive = true;
return true;
}
void p3GxsForums::dummy_tick()
{
/* check for a new callback */
if (mGenActive)
{
std::cerr << "p3GxsForums::dummyTick() AboutActive";
std::cerr << std::endl;
uint32_t status = RsGenExchange::getTokenService()->requestStatus(mGenToken);
if (status != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
{
std::cerr << "p3GxsForums::dummy_tick() Status: " << status;
std::cerr << std::endl;
if (status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
{
std::cerr << "p3GxsForums::dummy_tick() generateDummyMsgs() FAILED";
std::cerr << std::endl;
mGenActive = false;
}
return;
}
if (mGenCount < MAX_GEN_GROUPS)
{
/* get the group Id */
RsGxsGroupId groupId;
RsGxsMessageId emptyId;
if (!acknowledgeTokenGrp(mGenToken, groupId))
{
std::cerr << " ERROR ";
std::cerr << std::endl;
mGenActive = false;
return;
}
std::cerr << "p3GxsForums::dummy_tick() Acknowledged GroupId: " << groupId;
std::cerr << std::endl;
ForumDummyRef ref(groupId, emptyId, emptyId);
mGenRefs[mGenCount] = ref;
}
else if (mGenCount < MAX_GEN_MESSAGES)
{
/* get the msg Id, and generate next snapshot */
RsGxsGrpMsgIdPair msgId;
if (!acknowledgeTokenMsg(mGenToken, msgId))
{
std::cerr << " ERROR ";
std::cerr << std::endl;
mGenActive = false;
return;
}
std::cerr << "p3GxsForums::dummy_tick() Acknowledged <GroupId: " << msgId.first << ", MsgId: " << msgId.second << ">";
std::cerr << std::endl;
/* store results for later selection */
ForumDummyRef ref(msgId.first, mGenThreadId, msgId.second);
mGenRefs[mGenCount] = ref;
}
else
{
std::cerr << "p3GxsForums::dummy_tick() Finished";
std::cerr << std::endl;
/* done */
mGenActive = false;
return;
}
mGenCount++;
if (mGenCount < MAX_GEN_GROUPS)
{
std::string groupName;
rs_sprintf(groupName, "TestForum_%d", mGenCount);
std::cerr << "p3GxsForums::dummy_tick() Generating Group: " << groupName;
std::cerr << std::endl;
/* create a new group */
generateGroup(mGenToken, groupName);
}
else
{
/* create a new message */
uint32_t idx = (uint32_t) (mGenCount * RSRandom::random_f32());
ForumDummyRef &ref = mGenRefs[idx];
RsGxsGroupId grpId = ref.mGroupId;
RsGxsMessageId parentId = ref.mMsgId;
mGenThreadId = ref.mThreadId;
if (mGenThreadId.empty())
{
mGenThreadId = parentId;
}
std::cerr << "p3GxsForums::dummy_tick() Generating Msg ... ";
std::cerr << " GroupId: " << grpId;
std::cerr << " ThreadId: " << mGenThreadId;
std::cerr << " ParentId: " << parentId;
std::cerr << std::endl;
generateMessage(mGenToken, grpId, parentId, mGenThreadId);
}
}
}
bool p3GxsForums::generateMessage(uint32_t &token, const RsGxsGroupId &grpId, const RsGxsMessageId &parentId, const RsGxsMessageId &threadId)
{
RsGxsForumMsg msg;
std::string rndId = genRandomId();
rs_sprintf(msg.mMsg, "Forum Msg: GroupId: %s, ThreadId: %s, ParentId: %s + some randomness: %s",
grpId.c_str(), threadId.c_str(), parentId.c_str(), rndId.c_str());
msg.mMeta.mMsgName = msg.mMsg;
msg.mMeta.mGroupId = grpId;
msg.mMeta.mThreadId = threadId;
msg.mMeta.mParentId = parentId;
msg.mMeta.mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_UNREAD;
/* chose a random Id to sign with */
std::list<RsGxsId> ownIds;
std::list<RsGxsId>::iterator it;
rsIdentity->getOwnIds(ownIds);
uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32());
int i = 0;
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++);
if (it != ownIds.end())
{
std::cerr << "p3GxsForums::generateMessage() Author: " << *it;
std::cerr << std::endl;
msg.mMeta.mAuthorId = *it;
}
else
{
std::cerr << "p3GxsForums::generateMessage() No Author!";
std::cerr << std::endl;
}
createMsg(token, msg);
return true;
}
bool p3GxsForums::generateGroup(uint32_t &token, std::string groupName)
{
/* generate a new forum */
RsGxsForumGroup forum;
forum.mMeta.mGroupName = groupName;
createGroup(token, forum);
return true;
}
// Overloaded from RsTickEvent for Event callbacks.
void p3GxsForums::handle_event(uint32_t event_type, const std::string &elabel)
{
std::cerr << "p3GxsForums::handle_event(" << event_type << ")";
std::cerr << std::endl;
// stuff.
switch(event_type)
{
case FORUM_TESTEVENT_DUMMYDATA:
generateDummyData();
break;
default:
/* error */
std::cerr << "p3GxsForums::handle_event() Unknown Event Type: " << event_type;
std::cerr << std::endl;
break;
}
}

View file

@ -0,0 +1,111 @@
/*
* libretroshare/src/services: p3gxsforums.h
*
* GxsForum interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* 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".
*
*/
#ifndef P3_GXSFORUMS_SERVICE_HEADER
#define P3_GXSFORUMS_SERVICE_HEADER
#include "retroshare/rsgxsforums.h"
#include "gxs/rsgenexchange.h"
#include "util/rstickevent.h"
#include <map>
#include <string>
/*
*
*/
class p3GxsForums: public RsGenExchange, public RsGxsForums,
public RsTickEvent /* only needed for testing - remove after */
{
public:
p3GxsForums(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
virtual void service_tick();
protected:
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
// Overloaded from RsTickEvent.
virtual void handle_event(uint32_t event_type, const std::string &elabel);
public:
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsForumGroup> &groups);
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs);
virtual bool getRelatedMessages(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs);
//////////////////////////////////////////////////////////////////////////////
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
//virtual bool groupRestoreKeys(const std::string &groupId);
//virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group);
virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg);
private:
virtual bool generateDummyData();
std::string genRandomId();
void dummy_tick();
bool generateMessage(uint32_t &token, const RsGxsGroupId &grpId,
const RsGxsMessageId &parentId, const RsGxsMessageId &threadId);
bool generateGroup(uint32_t &token, std::string groupName);
class ForumDummyRef
{
public:
ForumDummyRef() { return; }
ForumDummyRef(const RsGxsGroupId &grpId, const RsGxsMessageId &threadId, const RsGxsMessageId &msgId)
:mGroupId(grpId), mThreadId(threadId), mMsgId(msgId) { return; }
RsGxsGroupId mGroupId;
RsGxsMessageId mThreadId;
RsGxsMessageId mMsgId;
};
uint32_t mGenToken;
bool mGenActive;
int mGenCount;
std::vector<ForumDummyRef> mGenRefs;
RsGxsMessageId mGenThreadId;
};
#endif

View file

@ -23,16 +23,16 @@
* *
*/ */
#include "services/p3gxsservice.h" #include "services/p3gxsserviceVEG.h"
p3GxsService::p3GxsService(uint16_t type) p3GxsServiceVEG::p3GxsServiceVEG(uint16_t type)
:p3Service(type), mReqMtx("p3GxsService") :p3Service(type), mReqMtx("p3GxsService")
{ {
mNextToken = 0; mNextToken = 0;
return; return;
} }
bool p3GxsService::generateToken(uint32_t &token) bool p3GxsServiceVEG::generateToken(uint32_t &token)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -41,7 +41,7 @@ bool p3GxsService::generateToken(uint32_t &token)
return true; return true;
} }
bool p3GxsService::storeRequest(const uint32_t &token, const uint32_t &ansType, const RsTokReqOptions &opts, const uint32_t &type, const std::list<std::string> &ids) bool p3GxsServiceVEG::storeRequest(const uint32_t &token, const uint32_t &ansType, const RsTokReqOptionsVEG &opts, const uint32_t &type, const std::list<std::string> &ids)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -60,7 +60,7 @@ bool p3GxsService::storeRequest(const uint32_t &token, const uint32_t &ansTyp
} }
bool p3GxsService::clearRequest(const uint32_t &token) bool p3GxsServiceVEG::clearRequest(const uint32_t &token)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -77,7 +77,7 @@ bool p3GxsService::clearRequest(const uint32_t &token)
return true; return true;
} }
bool p3GxsService::updateRequestStatus(const uint32_t &token, const uint32_t &status) bool p3GxsServiceVEG::updateRequestStatus(const uint32_t &token, const uint32_t &status)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -94,7 +94,7 @@ bool p3GxsService::updateRequestStatus(const uint32_t &token, const uint32_t &st
return true; return true;
} }
bool p3GxsService::updateRequestInList(const uint32_t &token, std::list<std::string> ids) bool p3GxsServiceVEG::updateRequestInList(const uint32_t &token, std::list<std::string> ids)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -116,7 +116,7 @@ bool p3GxsService::updateRequestInList(const uint32_t &token, std::list<std::str
} }
bool p3GxsService::updateRequestOutList(const uint32_t &token, std::list<std::string> ids) bool p3GxsServiceVEG::updateRequestOutList(const uint32_t &token, std::list<std::string> ids)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -138,7 +138,7 @@ bool p3GxsService::updateRequestOutList(const uint32_t &token, std::list<std::st
} }
#if 0 #if 0
bool p3GxsService::updateRequestData(const uint32_t &token, std::map<std::string, void *> data) bool p3GxsServiceVEG::updateRequestData(const uint32_t &token, std::map<std::string, void *> data)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -160,7 +160,7 @@ bool p3GxsService::updateRequestData(const uint32_t &token, std::map<std::string
} }
#endif #endif
bool p3GxsService::checkRequestStatus(const uint32_t &token, uint32_t &status, uint32_t &reqtype, uint32_t &anstype, time_t &ts) bool p3GxsServiceVEG::checkRequestStatus(const uint32_t &token, uint32_t &status, uint32_t &reqtype, uint32_t &anstype, time_t &ts)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -182,7 +182,7 @@ bool p3GxsService::checkRequestStatus(const uint32_t &token, uint32_t &status
// special ones for testing (not in final design) // special ones for testing (not in final design)
bool p3GxsService::tokenList(std::list<uint32_t> &tokens) bool p3GxsServiceVEG::tokenList(std::list<uint32_t> &tokens)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -196,7 +196,7 @@ bool p3GxsService::tokenList(std::list<uint32_t> &tokens)
return true; return true;
} }
bool p3GxsService::popRequestInList(const uint32_t &token, std::string &id) bool p3GxsServiceVEG::popRequestInList(const uint32_t &token, std::string &id)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -220,7 +220,7 @@ bool p3GxsService::popRequestInList(const uint32_t &token, std::string &id)
} }
bool p3GxsService::popRequestOutList(const uint32_t &token, std::string &id) bool p3GxsServiceVEG::popRequestOutList(const uint32_t &token, std::string &id)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -244,7 +244,7 @@ bool p3GxsService::popRequestOutList(const uint32_t &token, std::string &id)
} }
bool p3GxsService::loadRequestOutList(const uint32_t &token, std::list<std::string> &ids) bool p3GxsServiceVEG::loadRequestOutList(const uint32_t &token, std::list<std::string> &ids)
{ {
RsStackMutex stack(mReqMtx); /****** LOCKED *****/ RsStackMutex stack(mReqMtx); /****** LOCKED *****/
@ -270,7 +270,7 @@ bool p3GxsService::loadRequestOutList(const uint32_t &token, std::list<std::s
#define MAX_REQUEST_AGE 10 #define MAX_REQUEST_AGE 10
bool p3GxsService::fakeprocessrequests() bool p3GxsServiceVEG::fakeprocessrequests()
{ {
std::list<uint32_t>::iterator it; std::list<uint32_t>::iterator it;
std::list<uint32_t> tokens; std::list<uint32_t> tokens;
@ -287,7 +287,7 @@ bool p3GxsService::fakeprocessrequests()
time_t ts; time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts); checkRequestStatus(token, status, reqtype, anstype, ts);
std::cerr << "p3GxsService::fakeprocessrequests() Token: " << token << " Status: " << status << " ReqType: " << reqtype << "Age: " << now - ts << std::endl; std::cerr << "p3GxsServiceVEG::fakeprocessrequests() Token: " << token << " Status: " << status << " ReqType: " << reqtype << "Age: " << now - ts << std::endl;
if (status == GXS_REQUEST_STATUS_PENDING) if (status == GXS_REQUEST_STATUS_PENDING)
{ {
@ -299,13 +299,13 @@ bool p3GxsService::fakeprocessrequests()
} }
else if (status == GXS_REQUEST_STATUS_DONE) else if (status == GXS_REQUEST_STATUS_DONE)
{ {
std::cerr << "p3GxsService::fakeprocessrequests() Clearing Done Request Token: " << token; std::cerr << "p3GxsServiceVEG::fakeprocessrequests() Clearing Done Request Token: " << token;
std::cerr << std::endl; std::cerr << std::endl;
clearRequest(token); clearRequest(token);
} }
else if (now - ts > MAX_REQUEST_AGE) else if (now - ts > MAX_REQUEST_AGE)
{ {
std::cerr << "p3GxsService::fakeprocessrequests() Clearing Old Request Token: " << token; std::cerr << "p3GxsServiceVEG::fakeprocessrequests() Clearing Old Request Token: " << token;
std::cerr << std::endl; std::cerr << std::endl;
clearRequest(token); clearRequest(token);
} }
@ -334,14 +334,14 @@ bool p3GxsService::fakeprocessrequests()
* *
****/ ****/
GxsDataProxy::GxsDataProxy() GxsDataProxyVEG::GxsDataProxyVEG()
:mDataMtx("GxsDataProxyMtx") :mDataMtx("GxsDataProxyMtx")
{ {
return; return;
} }
static bool checkGroupFilter(const RsTokReqOptions &opts, const RsGroupMetaData &group) static bool checkGroupFilter(const RsTokReqOptionsVEG &opts, const RsGroupMetaData &group)
{ {
bool statusMatch = false; bool statusMatch = false;
if (opts.mStatusMask) if (opts.mStatusMask)
@ -370,6 +370,33 @@ static bool checkGroupFilter(const RsTokReqOptions &opts, const RsGroupMetaData
statusMatch = true; statusMatch = true;
} }
bool flagsMatch = false;
if (opts.mFlagsMask)
{
// Exact Flags match required.
if ((opts.mFlagsMask & opts.mFlagsFilter) == (opts.mFlagsMask & group.mGroupFlags))
{
std::cerr << "checkGroupFilter() Accepting Group as Flags Match: ";
std::cerr << " Mask: " << opts.mFlagsMask << " FlagsFilter: " << opts.mFlagsFilter;
std::cerr << " GroupFlags: " << group.mGroupFlags << " GroupId: " << group.mGroupId;
std::cerr << std::endl;
flagsMatch = true;
}
else
{
std::cerr << "checkGroupFilter() Dropping Group due to !Flags Match ";
std::cerr << " Mask: " << opts.mFlagsMask << " FlagsFilter: " << opts.mFlagsFilter;
std::cerr << " GroupFlags: " << group.mGroupFlags << " GroupId: " << group.mGroupId;
std::cerr << std::endl;
}
}
else
{
// no status comparision,
flagsMatch = true;
}
bool subMatch = false; bool subMatch = false;
if (opts.mSubscribeFilter) if (opts.mSubscribeFilter)
{ {
@ -397,11 +424,11 @@ static bool checkGroupFilter(const RsTokReqOptions &opts, const RsGroupMetaData
subMatch = true; subMatch = true;
} }
return (statusMatch && subMatch); return (statusMatch && flagsMatch && subMatch);
} }
static bool checkMsgFilter(const RsTokReqOptions &opts, const RsMsgMetaData &msg) static bool checkMsgFilter(const RsTokReqOptionsVEG &opts, const RsMsgMetaData &msg)
{ {
bool statusMatch = false; bool statusMatch = false;
if (opts.mStatusMask) if (opts.mStatusMask)
@ -429,11 +456,39 @@ static bool checkMsgFilter(const RsTokReqOptions &opts, const RsMsgMetaData &msg
// no status comparision, // no status comparision,
statusMatch = true; statusMatch = true;
} }
return statusMatch;
bool flagsMatch = false;
if (opts.mFlagsMask)
{
// Exact Flags match required.
if ((opts.mFlagsMask & opts.mFlagsFilter) == (opts.mFlagsMask & msg.mMsgFlags))
{
std::cerr << "checkMsgFilter() Accepting Msg as Flags Match: ";
std::cerr << " Mask: " << opts.mFlagsMask << " FlagsFilter: " << opts.mFlagsFilter;
std::cerr << " MsgFlags: " << msg.mMsgFlags << " MsgId: " << msg.mMsgId;
std::cerr << std::endl;
flagsMatch = true;
}
else
{
std::cerr << "checkMsgFilter() Dropping Msg due to !Flags Match ";
std::cerr << " Mask: " << opts.mFlagsMask << " FlagsFilter: " << opts.mFlagsFilter;
std::cerr << " MsgFlags: " << msg.mMsgFlags << " MsgId: " << msg.mMsgId;
std::cerr << std::endl;
}
}
else
{
// no status comparision,
flagsMatch = true;
}
return (statusMatch && flagsMatch);
} }
bool GxsDataProxy::filterGroupList(const RsTokReqOptions &opts, std::list<std::string> &groupIds) bool GxsDataProxyVEG::filterGroupList(const RsTokReqOptionsVEG &opts, std::list<std::string> &groupIds)
{ {
std::list<std::string>::iterator it; std::list<std::string>::iterator it;
for(it = groupIds.begin(); it != groupIds.end(); ) for(it = groupIds.begin(); it != groupIds.end(); )
@ -462,7 +517,7 @@ bool GxsDataProxy::filterGroupList(const RsTokReqOptions &opts, std::list<std::s
} }
bool GxsDataProxy::filterMsgList(const RsTokReqOptions &opts, std::list<std::string> &msgIds) bool GxsDataProxyVEG::filterMsgList(const RsTokReqOptionsVEG &opts, std::list<std::string> &msgIds)
{ {
std::list<std::string>::iterator it; std::list<std::string>::iterator it;
for(it = msgIds.begin(); it != msgIds.end(); ) for(it = msgIds.begin(); it != msgIds.end(); )
@ -492,14 +547,14 @@ bool GxsDataProxy::filterMsgList(const RsTokReqOptions &opts, std::list<std::str
bool GxsDataProxy::getGroupList( uint32_t &token, const RsTokReqOptions &opts, const std::list<std::string> &groupIds, std::list<std::string> &outGroupIds) bool GxsDataProxyVEG::getGroupList( uint32_t &token, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds, std::list<std::string> &outGroupIds)
{ {
/* CASEs that this handles ... /* CASEs that this handles ...
* 1) if groupIds is Empty... return all groupIds. * 1) if groupIds is Empty... return all groupIds.
* 2) else copy list. * 2) else copy list.
* *
*/ */
std::cerr << "GxsDataProxy::getGroupList()"; std::cerr << "GxsDataProxyVEG::getGroupList()";
std::cerr << std::endl; std::cerr << std::endl;
if (groupIds.size() == 0) if (groupIds.size() == 0)
@ -524,14 +579,14 @@ bool GxsDataProxy::getGroupList( uint32_t &token, const RsTokReqOptions &opt
} }
bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list<std::string> &groupIds, std::list<std::string> &outMsgIds) bool GxsDataProxyVEG::getMsgList( uint32_t &token, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds, std::list<std::string> &outMsgIds)
{ {
/* CASEs this handles. /* CASEs this handles.
* Input is groupList + Flags. * Input is groupList + Flags.
* 1) No Flags => All Messages in those Groups. * 1) No Flags => All Messages in those Groups.
* *
*/ */
std::cerr << "GxsDataProxy::getMsgList()"; std::cerr << "GxsDataProxyVEG::getMsgList()";
std::cerr << std::endl; std::cerr << std::endl;
@ -542,20 +597,20 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt
// Can only choose one of these two. // Can only choose one of these two.
if (opts.mOptions & RS_TOKREQOPT_MSG_ORIGMSG) if (opts.mOptions & RS_TOKREQOPT_MSG_ORIGMSG)
{ {
std::cerr << "GxsDataProxy::getMsgList() MSG_ORIGMSG"; std::cerr << "GxsDataProxyVEG::getMsgList() MSG_ORIGMSG";
std::cerr << std::endl; std::cerr << std::endl;
onlyOrigMsgs = true; onlyOrigMsgs = true;
} }
else if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST) else if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST)
{ {
std::cerr << "GxsDataProxy::getMsgList() MSG_LATEST"; std::cerr << "GxsDataProxyVEG::getMsgList() MSG_LATEST";
std::cerr << std::endl; std::cerr << std::endl;
onlyLatestMsgs = true; onlyLatestMsgs = true;
} }
if (opts.mOptions & RS_TOKREQOPT_MSG_THREAD) if (opts.mOptions & RS_TOKREQOPT_MSG_THREAD)
{ {
std::cerr << "GxsDataProxy::getMsgList() MSG_THREAD"; std::cerr << "GxsDataProxyVEG::getMsgList() MSG_THREAD";
std::cerr << std::endl; std::cerr << std::endl;
onlyThreadHeadMsgs = true; onlyThreadHeadMsgs = true;
} }
@ -593,7 +648,7 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt
bool addMsg = false; bool addMsg = false;
if (oit == origMsgTs.end()) if (oit == origMsgTs.end())
{ {
std::cerr << "GxsDataProxy::getMsgList() Found New OrigMsgId: "; std::cerr << "GxsDataProxyVEG::getMsgList() Found New OrigMsgId: ";
std::cerr << mit->second.mOrigMsgId; std::cerr << mit->second.mOrigMsgId;
std::cerr << " MsgId: " << mit->second.mMsgId; std::cerr << " MsgId: " << mit->second.mMsgId;
std::cerr << " TS: " << mit->second.mPublishTs; std::cerr << " TS: " << mit->second.mPublishTs;
@ -604,7 +659,7 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt
// check timestamps. // check timestamps.
else if (oit->second.second < mit->second.mPublishTs) else if (oit->second.second < mit->second.mPublishTs)
{ {
std::cerr << "GxsDataProxy::getMsgList() Found Later Msg. OrigMsgId: "; std::cerr << "GxsDataProxyVEG::getMsgList() Found Later Msg. OrigMsgId: ";
std::cerr << mit->second.mOrigMsgId; std::cerr << mit->second.mOrigMsgId;
std::cerr << " MsgId: " << mit->second.mMsgId; std::cerr << " MsgId: " << mit->second.mMsgId;
std::cerr << " TS: " << mit->second.mPublishTs; std::cerr << " TS: " << mit->second.mPublishTs;
@ -673,7 +728,7 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt
} }
bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list<std::string> &msgIds, std::list<std::string> &outMsgIds) bool GxsDataProxyVEG::getMsgRelatedList(uint32_t &token, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds, std::list<std::string> &outMsgIds)
{ {
/* CASEs this handles. /* CASEs this handles.
* Input is msgList + Flags. * Input is msgList + Flags.
@ -681,36 +736,52 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
* *
*/ */
std::cerr << "GxsDataProxy::getMsgRelatedList()"; std::cerr << "GxsDataProxyVEG::getMsgRelatedList()";
std::cerr << std::endl; std::cerr << std::endl;
bool onlyLatestMsgs = false; bool onlyLatestMsgs = false;
bool onlyAllVersions = false; bool onlyAllVersions = false;
bool onlyChildMsgs = false; bool onlyChildMsgs = false;
bool onlyThreadMsgs = false;
if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST) if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST)
{ {
std::cerr << "GxsDataProxy::getMsgRelatedList() MSG_LATEST"; std::cerr << "GxsDataProxyVEG::getMsgRelatedList() MSG_LATEST";
std::cerr << std::endl; std::cerr << std::endl;
onlyLatestMsgs = true; onlyLatestMsgs = true;
} }
else if (opts.mOptions & RS_TOKREQOPT_MSG_VERSIONS) else if (opts.mOptions & RS_TOKREQOPT_MSG_VERSIONS)
{ {
std::cerr << "GxsDataProxy::getMsgRelatedList() MSG_VERSIONS"; std::cerr << "GxsDataProxyVEG::getMsgRelatedList() MSG_VERSIONS";
std::cerr << std::endl; std::cerr << std::endl;
onlyAllVersions = true; onlyAllVersions = true;
} }
if (opts.mOptions & RS_TOKREQOPT_MSG_PARENT) if (opts.mOptions & RS_TOKREQOPT_MSG_PARENT)
{ {
std::cerr << "GxsDataProxy::getMsgRelatedList() MSG_PARENTS"; std::cerr << "GxsDataProxyVEG::getMsgRelatedList() MSG_PARENTS";
std::cerr << std::endl; std::cerr << std::endl;
onlyChildMsgs = true; onlyChildMsgs = true;
} }
if (opts.mOptions & RS_TOKREQOPT_MSG_THREAD)
{
std::cerr << "GxsDataProxyVEG::getMsgRelatedList() MSG_THREAD";
std::cerr << std::endl;
onlyThreadMsgs = true;
}
if (onlyAllVersions && onlyChildMsgs) if (onlyAllVersions && onlyChildMsgs)
{ {
std::cerr << "GxsDataProxy::getMsgRelatedList() ERROR Incompatible FLAGS (VERSIONS & PARENT)"; std::cerr << "GxsDataProxyVEG::getMsgRelatedList() ERROR Incompatible FLAGS (VERSIONS & PARENT)";
std::cerr << std::endl;
return false;
}
if (onlyAllVersions && onlyThreadMsgs)
{
std::cerr << "GxsDataProxyVEG::getMsgRelatedList() ERROR Incompatible FLAGS (VERSIONS & THREAD)";
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
@ -718,7 +789,23 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
if ((!onlyLatestMsgs) && onlyChildMsgs) if ((!onlyLatestMsgs) && onlyChildMsgs)
{ {
std::cerr << "GxsDataProxy::getMsgRelatedList() ERROR Incompatible FLAGS (!LATEST & PARENT)"; std::cerr << "GxsDataProxyVEG::getMsgRelatedList() ERROR Incompatible FLAGS (!LATEST & PARENT)";
std::cerr << std::endl;
return false;
}
if ((!onlyLatestMsgs) && onlyThreadMsgs)
{
std::cerr << "GxsDataProxyVEG::getMsgRelatedList() ERROR Incompatible FLAGS (!LATEST & THREAD)";
std::cerr << std::endl;
return false;
}
if (onlyChildMsgs && onlyThreadMsgs)
{
std::cerr << "GxsDataProxyVEG::getMsgRelatedList() ERROR Incompatible FLAGS (PARENT & THREAD)";
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
@ -726,9 +813,9 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
/* FALL BACK OPTION */ /* FALL BACK OPTION */
if ((!onlyLatestMsgs) && (!onlyAllVersions) && (!onlyChildMsgs)) if ((!onlyLatestMsgs) && (!onlyAllVersions) && (!onlyChildMsgs) && (!onlyThreadMsgs))
{ {
std::cerr << "GxsDataProxy::getMsgRelatedList() FALLBACK -> NO FLAGS -> JUST COPY"; std::cerr << "GxsDataProxyVEG::getMsgRelatedList() FALLBACK -> NO FLAGS -> JUST COPY";
std::cerr << std::endl; std::cerr << std::endl;
/* just copy */ /* just copy */
outMsgIds = msgIds; outMsgIds = msgIds;
@ -755,7 +842,7 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
if (onlyLatestMsgs) if (onlyLatestMsgs)
{ {
if (onlyChildMsgs) if (onlyChildMsgs || onlyThreadMsgs)
{ {
// RUN THROUGH ALL MSGS... in map origId -> TS. // RUN THROUGH ALL MSGS... in map origId -> TS.
std::map<std::string, std::pair<std::string, time_t> > origMsgTs; std::map<std::string, std::pair<std::string, time_t> > origMsgTs;
@ -763,16 +850,27 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
for(mit = mMsgMetaData.begin(); mit != mMsgMetaData.end(); mit++) for(mit = mMsgMetaData.begin(); mit != mMsgMetaData.end(); mit++)
{ {
// skip msgs that aren't children. // skip msgs that aren't children.
if (mit->second.mParentId != origMsgId) if (onlyChildMsgs)
{ {
continue; if (mit->second.mParentId != origMsgId)
{
continue;
}
}
else /* onlyThreadMsgs */
{
if (mit->second.mThreadId != (*it))
{
continue;
}
} }
oit = origMsgTs.find(mit->second.mOrigMsgId); oit = origMsgTs.find(mit->second.mOrigMsgId);
bool addMsg = false; bool addMsg = false;
if (oit == origMsgTs.end()) if (oit == origMsgTs.end())
{ {
std::cerr << "GxsDataProxy::getMsgList() Found New OrigMsgId: "; std::cerr << "GxsDataProxyVEG::getMsgRelatedList() Found New OrigMsgId: ";
std::cerr << mit->second.mOrigMsgId; std::cerr << mit->second.mOrigMsgId;
std::cerr << " MsgId: " << mit->second.mMsgId; std::cerr << " MsgId: " << mit->second.mMsgId;
std::cerr << " TS: " << mit->second.mPublishTs; std::cerr << " TS: " << mit->second.mPublishTs;
@ -783,7 +881,7 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
// check timestamps. // check timestamps.
else if (oit->second.second < mit->second.mPublishTs) else if (oit->second.second < mit->second.mPublishTs)
{ {
std::cerr << "GxsDataProxy::getMsgList() Found Later Msg. OrigMsgId: "; std::cerr << "GxsDataProxyVEG::getMsgRelatedList() Found Later Msg. OrigMsgId: ";
std::cerr << mit->second.mOrigMsgId; std::cerr << mit->second.mOrigMsgId;
std::cerr << " MsgId: " << mit->second.mMsgId; std::cerr << " MsgId: " << mit->second.mMsgId;
std::cerr << " TS: " << mit->second.mPublishTs; std::cerr << " TS: " << mit->second.mPublishTs;
@ -843,14 +941,14 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
} }
bool GxsDataProxy::createGroup(void *groupData) bool GxsDataProxyVEG::createGroup(void *groupData)
{ {
RsGroupMetaData meta; RsGroupMetaData meta;
if (convertGroupToMetaData(groupData, meta)) if (convertGroupToMetaData(groupData, meta))
{ {
if (!isUniqueGroup(meta.mGroupId)) if (!isUniqueGroup(meta.mGroupId))
{ {
std::cerr << "GxsDataProxy::createGroup() ERROR GroupId Clashes, discarding"; std::cerr << "GxsDataProxyVEG::createGroup() ERROR GroupId Clashes, discarding";
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
@ -869,20 +967,20 @@ bool GxsDataProxy::createGroup(void *groupData)
return true; return true;
} }
std::cerr << "GxsDataProxy::createGroup() ERROR Failed to convert Data"; std::cerr << "GxsDataProxyVEG::createGroup() ERROR Failed to convert Data";
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
bool GxsDataProxy::createMsg(void *msgData) bool GxsDataProxyVEG::createMsg(void *msgData)
{ {
RsMsgMetaData meta; RsMsgMetaData meta;
if (convertMsgToMetaData(msgData, meta)) if (convertMsgToMetaData(msgData, meta))
{ {
if (!isUniqueMsg(meta.mMsgId)) if (!isUniqueMsg(meta.mMsgId))
{ {
std::cerr << "GxsDataProxy::createMsg() ERROR MsgId Clashes, discarding"; std::cerr << "GxsDataProxyVEG::createMsg() ERROR MsgId Clashes, discarding";
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
@ -895,7 +993,7 @@ bool GxsDataProxy::createMsg(void *msgData)
git = mGroupMetaData.find(meta.mGroupId); git = mGroupMetaData.find(meta.mGroupId);
if (git == mGroupMetaData.end()) if (git == mGroupMetaData.end())
{ {
std::cerr << "GxsDataProxy::createMsg() ERROR GroupId Doesn't exist, discarding"; std::cerr << "GxsDataProxyVEG::createMsg() ERROR GroupId Doesn't exist, discarding";
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
@ -915,14 +1013,14 @@ bool GxsDataProxy::createMsg(void *msgData)
return true; return true;
} }
std::cerr << "GxsDataProxy::createMsg() ERROR Failed to convert Data"; std::cerr << "GxsDataProxyVEG::createMsg() ERROR Failed to convert Data";
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
// Get Message Status - is retrived via MessageSummary. // Get Message Status - is retrived via MessageSummary.
bool GxsDataProxy::setMessageStatus(const std::string &msgId,const uint32_t status, const uint32_t statusMask) bool GxsDataProxyVEG::setMessageStatus(const std::string &msgId,const uint32_t status, const uint32_t statusMask)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -932,7 +1030,7 @@ bool GxsDataProxy::setMessageStatus(const std::string &msgId,const uint32_t stat
if (mit == mMsgMetaData.end()) if (mit == mMsgMetaData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::getMsgSummary() Error Finding MsgId: " << msgId; std::cerr << "GxsDataProxyVEG::getMsgSummary() Error Finding MsgId: " << msgId;
std::cerr << std::endl; std::cerr << std::endl;
} }
else else
@ -946,7 +1044,7 @@ bool GxsDataProxy::setMessageStatus(const std::string &msgId,const uint32_t stat
return true; return true;
} }
bool GxsDataProxy::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) bool GxsDataProxyVEG::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -956,7 +1054,7 @@ bool GxsDataProxy::setGroupStatus(const std::string &groupId, const uint32_t sta
if (git == mGroupMetaData.end()) if (git == mGroupMetaData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::setGroupStatus() Error Finding GroupId: " << groupId; std::cerr << "GxsDataProxyVEG::setGroupStatus() Error Finding GroupId: " << groupId;
std::cerr << std::endl; std::cerr << std::endl;
} }
else else
@ -971,7 +1069,7 @@ bool GxsDataProxy::setGroupStatus(const std::string &groupId, const uint32_t sta
} }
bool GxsDataProxy::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) bool GxsDataProxyVEG::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -981,7 +1079,7 @@ bool GxsDataProxy::setGroupSubscribeFlags(const std::string &groupId, uint32_t s
if (git == mGroupMetaData.end()) if (git == mGroupMetaData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::setGroupSubscribeFlags() Error Finding GroupId: " << groupId; std::cerr << "GxsDataProxyVEG::setGroupSubscribeFlags() Error Finding GroupId: " << groupId;
std::cerr << std::endl; std::cerr << std::endl;
} }
else else
@ -995,7 +1093,7 @@ bool GxsDataProxy::setGroupSubscribeFlags(const std::string &groupId, uint32_t s
return true; return true;
} }
bool GxsDataProxy::setMessageServiceString(const std::string &msgId, const std::string &str) bool GxsDataProxyVEG::setMessageServiceString(const std::string &msgId, const std::string &str)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -1005,7 +1103,7 @@ bool GxsDataProxy::setMessageServiceString(const std::string &msgId, const std::
if (mit == mMsgMetaData.end()) if (mit == mMsgMetaData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::setMessageServiceString() Error Finding MsgId: " << msgId; std::cerr << "GxsDataProxyVEG::setMessageServiceString() Error Finding MsgId: " << msgId;
std::cerr << std::endl; std::cerr << std::endl;
} }
else else
@ -1017,7 +1115,7 @@ bool GxsDataProxy::setMessageServiceString(const std::string &msgId, const std::
return true; return true;
} }
bool GxsDataProxy::setGroupServiceString(const std::string &groupId, const std::string &str) bool GxsDataProxyVEG::setGroupServiceString(const std::string &groupId, const std::string &str)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -1027,7 +1125,7 @@ bool GxsDataProxy::setGroupServiceString(const std::string &groupId, const std::
if (git == mGroupMetaData.end()) if (git == mGroupMetaData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::setGroupServiceString() Error Finding GroupId: " << groupId; std::cerr << "GxsDataProxyVEG::setGroupServiceString() Error Finding GroupId: " << groupId;
std::cerr << std::endl; std::cerr << std::endl;
} }
else else
@ -1041,22 +1139,22 @@ bool GxsDataProxy::setGroupServiceString(const std::string &groupId, const std::
/* These Functions must be overloaded to complete the service */ /* These Functions must be overloaded to complete the service */
bool GxsDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta) bool GxsDataProxyVEG::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta)
{ {
std::cerr << "GxsDataProxy::convert fn ... please implement!"; std::cerr << "GxsDataProxyVEG::convert fn ... please implement!";
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
bool GxsDataProxy::convertMsgToMetaData(void *groupData, RsMsgMetaData &meta) bool GxsDataProxyVEG::convertMsgToMetaData(void *groupData, RsMsgMetaData &meta)
{ {
std::cerr << "GxsDataProxy::convert fn ... please implement!"; std::cerr << "GxsDataProxyVEG::convert fn ... please implement!";
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
/* extract Data */ /* extract Data */
bool GxsDataProxy::getGroupSummary(const std::string &groupId, RsGroupMetaData &groupSummary) bool GxsDataProxyVEG::getGroupSummary(const std::string &groupId, RsGroupMetaData &groupSummary)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -1066,7 +1164,7 @@ bool GxsDataProxy::getGroupSummary(const std::string &groupId, RsGroupMetaData &
if (mit == mGroupMetaData.end()) if (mit == mGroupMetaData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::getGroupMetaData() Error Finding GroupId: " << groupId; std::cerr << "GxsDataProxyVEG::getGroupMetaData() Error Finding GroupId: " << groupId;
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
@ -1078,7 +1176,7 @@ bool GxsDataProxy::getGroupSummary(const std::string &groupId, RsGroupMetaData &
} }
bool GxsDataProxy::getMsgSummary(const std::string &msgId, RsMsgMetaData &msgSummary) bool GxsDataProxyVEG::getMsgSummary(const std::string &msgId, RsMsgMetaData &msgSummary)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -1088,7 +1186,7 @@ bool GxsDataProxy::getMsgSummary(const std::string &msgId, RsMsgMetaData &msgSum
if (mit == mMsgMetaData.end()) if (mit == mMsgMetaData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::getMsgSummary() Error Finding MsgId: " << msgId; std::cerr << "GxsDataProxyVEG::getMsgSummary() Error Finding MsgId: " << msgId;
std::cerr << std::endl; std::cerr << std::endl;
} }
else else
@ -1100,7 +1198,7 @@ bool GxsDataProxy::getMsgSummary(const std::string &msgId, RsMsgMetaData &msgSum
/* extract Data */ /* extract Data */
bool GxsDataProxy::getGroupSummary(const std::list<std::string> &groupIds, std::list<RsGroupMetaData> &groupSummary) bool GxsDataProxyVEG::getGroupSummary(const std::list<std::string> &groupIds, std::list<RsGroupMetaData> &groupSummary)
{ {
std::list<std::string>::const_iterator it; std::list<std::string>::const_iterator it;
for(it = groupIds.begin(); it != groupIds.end(); it++) for(it = groupIds.begin(); it != groupIds.end(); it++)
@ -1113,7 +1211,7 @@ bool GxsDataProxy::getGroupSummary(const std::list<std::string> &groupIds, std::
if (mit == mGroupMetaData.end()) if (mit == mGroupMetaData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::getGroupMetaData() Error Finding GroupId: " << *it; std::cerr << "GxsDataProxyVEG::getGroupMetaData() Error Finding GroupId: " << *it;
std::cerr << std::endl; std::cerr << std::endl;
} }
else else
@ -1125,7 +1223,7 @@ bool GxsDataProxy::getGroupSummary(const std::list<std::string> &groupIds, std::
} }
bool GxsDataProxy::getMsgSummary(const std::list<std::string> &msgIds, std::list<RsMsgMetaData> &msgSummary) bool GxsDataProxyVEG::getMsgSummary(const std::list<std::string> &msgIds, std::list<RsMsgMetaData> &msgSummary)
{ {
std::list<std::string>::const_iterator it; std::list<std::string>::const_iterator it;
for(it = msgIds.begin(); it != msgIds.end(); it++) for(it = msgIds.begin(); it != msgIds.end(); it++)
@ -1138,7 +1236,7 @@ bool GxsDataProxy::getMsgSummary(const std::list<std::string> &msgIds, std::list
if (mit == mMsgMetaData.end()) if (mit == mMsgMetaData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::getMsgSummary() Error Finding MsgId: " << *it; std::cerr << "GxsDataProxyVEG::getMsgSummary() Error Finding MsgId: " << *it;
std::cerr << std::endl; std::cerr << std::endl;
} }
else else
@ -1150,7 +1248,7 @@ bool GxsDataProxy::getMsgSummary(const std::list<std::string> &msgIds, std::list
} }
bool GxsDataProxy::getGroupData(const std::string &groupId, void * &groupData) bool GxsDataProxyVEG::getGroupData(const std::string &groupId, void * &groupData)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -1160,7 +1258,7 @@ bool GxsDataProxy::getGroupData(const std::string &groupId, void * &groupData)
if (mit == mGroupData.end()) if (mit == mGroupData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::getGroupData() Error Finding GroupId: " << groupId; std::cerr << "GxsDataProxyVEG::getGroupData() Error Finding GroupId: " << groupId;
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
@ -1171,7 +1269,7 @@ bool GxsDataProxy::getGroupData(const std::string &groupId, void * &groupData)
return true; return true;
} }
bool GxsDataProxy::getMsgData(const std::string &msgId, void * &msgData) bool GxsDataProxyVEG::getMsgData(const std::string &msgId, void * &msgData)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -1181,7 +1279,7 @@ bool GxsDataProxy::getMsgData(const std::string &msgId, void * &msgData)
if (mit == mMsgData.end()) if (mit == mMsgData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::getMsgData() Error Finding MsgId: " << msgId; std::cerr << "GxsDataProxyVEG::getMsgData() Error Finding MsgId: " << msgId;
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
@ -1193,7 +1291,7 @@ bool GxsDataProxy::getMsgData(const std::string &msgId, void * &msgData)
} }
#if 0 #if 0
bool GxsDataProxy::getGroupData(const std::list<std::string> &groupIds, std::list<void *> &groupData) bool GxsDataProxyVEG::getGroupData(const std::list<std::string> &groupIds, std::list<void *> &groupData)
{ {
std::list<std::string>::const_iterator it; std::list<std::string>::const_iterator it;
for(it = groupIds.begin(); it != groupIds.end(); it++) for(it = groupIds.begin(); it != groupIds.end(); it++)
@ -1206,7 +1304,7 @@ bool GxsDataProxy::getGroupData(const std::list<std::string> &groupIds, std::lis
if (mit == mGroupData.end()) if (mit == mGroupData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::getGroupData() Error Finding GroupId: " << *it; std::cerr << "GxsDataProxyVEG::getGroupData() Error Finding GroupId: " << *it;
std::cerr << std::endl; std::cerr << std::endl;
} }
else else
@ -1217,7 +1315,7 @@ bool GxsDataProxy::getGroupData(const std::list<std::string> &groupIds, std::lis
return true; return true;
} }
bool GxsDataProxy::getMsgData(const std::list<std::string> &msgIds, std::list<void *> &msgData) bool GxsDataProxyVEG::getMsgData(const std::list<std::string> &msgIds, std::list<void *> &msgData)
{ {
std::list<std::string>::const_iterator it; std::list<std::string>::const_iterator it;
for(it = msgIds.begin(); it != msgIds.end(); it++) for(it = msgIds.begin(); it != msgIds.end(); it++)
@ -1230,7 +1328,7 @@ bool GxsDataProxy::getMsgData(const std::list<std::string> &msgIds, std::list<vo
if (mit == mMsgData.end()) if (mit == mMsgData.end())
{ {
// error. // error.
std::cerr << "GxsDataProxy::getMsgData() Error Finding MsgId: " << *it; std::cerr << "GxsDataProxyVEG::getMsgData() Error Finding MsgId: " << *it;
std::cerr << std::endl; std::cerr << std::endl;
} }
else else
@ -1242,7 +1340,7 @@ bool GxsDataProxy::getMsgData(const std::list<std::string> &msgIds, std::list<vo
} }
#endif #endif
bool GxsDataProxy::isUniqueMsg(const std::string &msgId) bool GxsDataProxyVEG::isUniqueMsg(const std::string &msgId)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -1253,7 +1351,7 @@ bool GxsDataProxy::isUniqueMsg(const std::string &msgId)
} }
bool GxsDataProxy::isUniqueGroup(const std::string &groupId) bool GxsDataProxyVEG::isUniqueGroup(const std::string &groupId)
{ {
RsStackMutex stack(mDataMtx); /***** LOCKED *****/ RsStackMutex stack(mDataMtx); /***** LOCKED *****/
@ -1272,8 +1370,8 @@ bool GxsDataProxy::isUniqueGroup(const std::string &groupId)
/*********************************************************************************************************/ /*********************************************************************************************************/
p3GxsDataService::p3GxsDataService(uint16_t type, GxsDataProxy *proxy) p3GxsDataServiceVEG::p3GxsDataServiceVEG(uint16_t type, GxsDataProxyVEG *proxy)
:p3GxsService(type), mProxy(proxy) :p3GxsServiceVEG(type), mProxy(proxy)
{ {
return; return;
} }
@ -1282,7 +1380,7 @@ p3GxsDataService::p3GxsDataService(uint16_t type, GxsDataProxy *proxy)
bool p3GxsDataService::fakeprocessrequests() bool p3GxsDataServiceVEG::fakeprocessrequests()
{ {
std::list<uint32_t> toClear; std::list<uint32_t> toClear;
std::list<uint32_t>::iterator cit; std::list<uint32_t>::iterator cit;
@ -1294,11 +1392,11 @@ bool p3GxsDataService::fakeprocessrequests()
for(it = mRequests.begin(); it != mRequests.end(); it++) for(it = mRequests.begin(); it != mRequests.end(); it++)
{ {
//std::cerr << "p3GxsDataService::fakeprocessrequests() Token: " << it->second.token << " Status: " << it->second.status << " ReqType: " << it->second.reqType << " Age: " << now - it->second.reqTime << std::endl; //std::cerr << "p3GxsDataServiceVEG::fakeprocessrequests() Token: " << it->second.token << " Status: " << it->second.status << " ReqType: " << it->second.reqType << " Age: " << now - it->second.reqTime << std::endl;
if (it->second.status == GXS_REQUEST_STATUS_PENDING) if (it->second.status == GXS_REQUEST_STATUS_PENDING)
{ {
std::cerr << "p3GxsDataService::fakeprocessrequests() Processing Token: " << it->second.token << " Status: " << it->second.status << " ReqType: " << it->second.reqType << " Age: " << now - it->second.reqTime << std::endl; std::cerr << "p3GxsDataServiceVEG::fakeprocessrequests() Processing Token: " << it->second.token << " Status: " << it->second.status << " ReqType: " << it->second.reqType << " Age: " << now - it->second.reqTime << std::endl;
it->second.status = GXS_REQUEST_STATUS_PARTIAL; it->second.status = GXS_REQUEST_STATUS_PARTIAL;
/* PROCESS REQUEST! */ /* PROCESS REQUEST! */
switch(it->second.reqType) switch(it->second.reqType)
@ -1323,13 +1421,13 @@ bool p3GxsDataService::fakeprocessrequests()
} }
else if (it->second.status == GXS_REQUEST_STATUS_DONE) else if (it->second.status == GXS_REQUEST_STATUS_DONE)
{ {
std::cerr << "p3GxsDataService::fakeprocessrequests() Clearing Done Request Token: " << it->second.token; std::cerr << "p3GxsDataServiceVEG::fakeprocessrequests() Clearing Done Request Token: " << it->second.token;
std::cerr << std::endl; std::cerr << std::endl;
toClear.push_back(it->second.token); toClear.push_back(it->second.token);
} }
else if (now - it->second.reqTime > MAX_REQUEST_AGE) else if (now - it->second.reqTime > MAX_REQUEST_AGE)
{ {
std::cerr << "p3GxsDataService::fakeprocessrequests() Clearing Old Request Token: " << it->second.token; std::cerr << "p3GxsDataServiceVEG::fakeprocessrequests() Clearing Old Request Token: " << it->second.token;
std::cerr << std::endl; std::cerr << std::endl;
toClear.push_back(it->second.token); toClear.push_back(it->second.token);
} }
@ -1345,23 +1443,25 @@ bool p3GxsDataService::fakeprocessrequests()
return true; return true;
} }
#if 0 // DISABLED AND MOVED TO GXS CODE.
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta) //std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta)
{ //{
out << "[ GroupId: " << meta.mGroupId << " Name: " << meta.mGroupName << " ]"; // out << "[ GroupId: " << meta.mGroupId << " Name: " << meta.mGroupName << " ]";
return out; // return out;
} //}
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta) //std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta)
{ //{
out << "[ GroupId: " << meta.mGroupId << " MsgId: " << meta.mMsgId; // out << "[ GroupId: " << meta.mGroupId << " MsgId: " << meta.mMsgId;
out << " Name: " << meta.mMsgName; // out << " Name: " << meta.mMsgName;
out << " OrigMsgId: " << meta.mOrigMsgId; // out << " OrigMsgId: " << meta.mOrigMsgId;
out << " ThreadId: " << meta.mThreadId; // out << " ThreadId: " << meta.mThreadId;
out << " ParentId: " << meta.mParentId; // out << " ParentId: " << meta.mParentId;
out << " AuthorId: " << meta.mAuthorId; // out << " AuthorId: " << meta.mAuthorId;
out << " Name: " << meta.mMsgName << " ]"; // out << " Name: " << meta.mMsgName << " ]";
return out; // return out;
} //}
#endif

View file

@ -27,7 +27,7 @@
#define P3_GXS_SERVICE_HEADER #define P3_GXS_SERVICE_HEADER
#include "services/p3service.h" #include "services/p3service.h"
#include "retroshare/rsidentity.h" #include "retroshare/rsidentityVEG.h"
/* /*
* This class provides useful generic support for GXS style services. * This class provides useful generic support for GXS style services.
@ -54,7 +54,7 @@ class gxsRequest
uint32_t ansType; uint32_t ansType;
uint32_t reqType; uint32_t reqType;
RsTokReqOptions Options; RsTokReqOptionsVEG Options;
uint32_t status; uint32_t status;
@ -64,18 +64,18 @@ class gxsRequest
}; };
class p3GxsService: public p3Service class p3GxsServiceVEG: public p3Service
{ {
protected: protected:
p3GxsService(uint16_t type); p3GxsServiceVEG(uint16_t type);
public: public:
//virtual ~p3Service() { p3Service::~p3Service(); return; } //virtual ~p3Service() { p3Service::~p3Service(); return; }
bool generateToken(uint32_t &token); bool generateToken(uint32_t &token);
bool storeRequest(const uint32_t &token, const uint32_t &ansType, const RsTokReqOptions &opts, const uint32_t &type, const std::list<std::string> &ids); bool storeRequest(const uint32_t &token, const uint32_t &ansType, const RsTokReqOptionsVEG &opts, const uint32_t &type, const std::list<std::string> &ids);
bool clearRequest(const uint32_t &token); bool clearRequest(const uint32_t &token);
bool updateRequestStatus(const uint32_t &token, const uint32_t &status); bool updateRequestStatus(const uint32_t &token, const uint32_t &status);
@ -103,15 +103,15 @@ virtual bool fakeprocessrequests();
}; };
class GxsDataProxy class GxsDataProxyVEG
{ {
public: public:
GxsDataProxy(); GxsDataProxyVEG();
virtual bool getGroupList( uint32_t &token, const RsTokReqOptions &opts, const std::list<std::string> &groupIds, std::list<std::string> &outGroupIds); virtual bool getGroupList( uint32_t &token, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds, std::list<std::string> &outGroupIds);
virtual bool getMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list<std::string> &groupIds, std::list<std::string> &outMsgIds); virtual bool getMsgList( uint32_t &token, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds, std::list<std::string> &outMsgIds);
virtual bool getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list<std::string> &msgIds, std::list<std::string> &outMsgIds); virtual bool getMsgRelatedList(uint32_t &token, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds, std::list<std::string> &outMsgIds);
/* This functions return a token - which can be used to retrieve the RsGroupMetaData, later /* This functions return a token - which can be used to retrieve the RsGroupMetaData, later
@ -157,8 +157,8 @@ virtual bool setGroupServiceString(const std::string &grpId, const std::string &
protected: protected:
bool filterGroupList(const RsTokReqOptions &opts, std::list<std::string> &groupIds); bool filterGroupList(const RsTokReqOptionsVEG &opts, std::list<std::string> &groupIds);
bool filterMsgList(const RsTokReqOptions &opts, std::list<std::string> &msgIds); bool filterMsgList(const RsTokReqOptionsVEG &opts, std::list<std::string> &msgIds);
RsMutex mDataMtx; RsMutex mDataMtx;
@ -172,17 +172,17 @@ virtual bool setGroupServiceString(const std::string &grpId, const std::string &
}; };
class p3GxsDataService: public p3GxsService class p3GxsDataServiceVEG: public p3GxsServiceVEG
{ {
public: public:
p3GxsDataService(uint16_t type, GxsDataProxy *proxy); p3GxsDataServiceVEG(uint16_t type, GxsDataProxyVEG *proxy);
virtual bool fakeprocessrequests(); virtual bool fakeprocessrequests();
protected: protected:
GxsDataProxy *mProxy; GxsDataProxyVEG *mProxy;
}; };

Some files were not shown because too many files have changed in this diff Show more