mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
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:
commit
069b72e0b2
549 changed files with 111171 additions and 25579 deletions
58
README.txt
58
README.txt
|
@ -1,42 +1,38 @@
|
|||
To use this branch:
|
||||
|
||||
chekcout the last version of openpgp SDK:
|
||||
# svn co svn://openpgp.nominet.org.uk/openpgpsdk/tags/openpgpsdk-0.9 openpgpsdk
|
||||
# cd openpgpsdk
|
||||
# ./configure --without-idea
|
||||
- get source code for libssh-0.5.2, unzip it, and create build directory (if needed)
|
||||
|
||||
# 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
|
||||
|
||||
# cd rsctrl/src
|
||||
# make
|
||||
|
||||
For the moment, the compilation is not workign on ubuntu
|
||||
Don't bother about python related errors.
|
||||
|
||||
Work to do
|
||||
==========
|
||||
Put a 'x' when done. 1,2,3 means started/ongoing/almost finished.
|
||||
- go to retroshare-nogui, and compile it
|
||||
|
||||
Compilation
|
||||
00 [1] make sure the library compiles on linux
|
||||
01 [ ] make sure the library compiles on windows
|
||||
# cd ../../retroshare-nogui
|
||||
# qmake
|
||||
# make
|
||||
|
||||
Project
|
||||
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.
|
||||
- to use the SSH RS server:
|
||||
|
||||
Notes
|
||||
=====
|
||||
Questions to answer:
|
||||
- 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
|
||||
# ssh-keygen -t rsa -f rs_ssh_host_rsa_key # this makes a RSA
|
||||
# ./retroshare-nogui -G # generates a login+passwd hash for the RSA key used.
|
||||
# ./retroshare-nogui -S 7022 -U[SSLid] -P [Passwd hash]
|
||||
|
||||
Code struture
|
||||
- replace current AuthGPG (virtual class) by a class named GPGHandler,
|
||||
that is responsible for signing, checking signatures, encrypting etc.
|
||||
- add a specific 8-bytes type for GPG Ids. Could be a uint64_t, or a
|
||||
uchar[8]
|
||||
- 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.
|
||||
|
||||
|
|
|
@ -87,6 +87,8 @@ bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string b
|
|||
mFns->bdPrintNodeId(std::cerr, id);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
mLocalNetEnhancements = true;
|
||||
}
|
||||
|
||||
int bdNodeManager::stopDht()
|
||||
|
@ -400,6 +402,10 @@ void bdNodeManager::iteration()
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
/* This stuff is only important for "LocalNet based Features */
|
||||
if (mLocalNetEnhancements)
|
||||
{
|
||||
/* run a random search for ourselves, from own App DHT peer */
|
||||
QueryRandomLocalNet();
|
||||
|
||||
|
@ -427,6 +433,7 @@ void bdNodeManager::iteration()
|
|||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::iteration(): REFRESH ";
|
||||
|
|
|
@ -187,6 +187,8 @@ void SearchForLocalNet();
|
|||
|
||||
bdBloom mBloomFilter;
|
||||
|
||||
bool mLocalNetEnhancements;
|
||||
|
||||
/* future node functions */
|
||||
//addPeerPing(foundId);
|
||||
//clearPing(it->first);
|
||||
|
|
|
@ -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)
|
||||
$(CXX) $(CXXFLAGS) -o bdexample $(EGOBJ) $(LIBS)
|
||||
bssdht: $(EGOBJ)
|
||||
$(CXX) $(CXXFLAGS) -o bssdht $(EGOBJ) $(LIBS)
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -29,8 +29,24 @@
|
|||
#include <bitdht/bdstddht.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <string.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
|
||||
*/
|
||||
|
||||
|
@ -111,6 +127,11 @@ BitDhtHandler::BitDhtHandler(bdNodeId *ownId, uint16_t port, std::string appId,
|
|||
|
||||
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 */
|
||||
mUdpBitDht->startDht();
|
||||
}
|
||||
|
@ -163,8 +184,19 @@ bool BitDhtHandler::FindNode(bdNodeId *peerId)
|
|||
bdStdPrintNodeId(std::cerr, peerId);
|
||||
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 */
|
||||
mUdpBitDht->addFindNode(peerId, BITDHT_QFLAGS_DO_IDLE);
|
||||
mUdpBitDht->addFindNode(peerId, BITDHT_QFLAGS_DISGUISE);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
@ -179,10 +211,50 @@ bool BitDhtHandler::DropNode(bdNodeId *peerId)
|
|||
/* remove in peer */
|
||||
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 ;
|
||||
}
|
||||
|
||||
|
||||
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 **************************/
|
||||
|
||||
|
@ -204,6 +276,20 @@ int BitDhtHandler::PeerCallback(const bdId *id, uint32_t status)
|
|||
bdStdPrintId(std::cerr, id);
|
||||
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;
|
||||
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 << std::endl;
|
||||
|
||||
|
||||
break;
|
||||
|
||||
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:
|
||||
/* 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;
|
||||
|
||||
it->second.id = *id;
|
||||
|
||||
break;
|
||||
|
||||
case BITDHT_MGR_QUERY_PEER_ONLINE:
|
||||
/* 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;
|
||||
|
||||
connect = true;
|
||||
it->second.id = *id;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
|
|
|
@ -37,6 +37,18 @@
|
|||
/*** This class can be overloaded to use the XXXXCallback() Functions *****/
|
||||
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
|
||||
{
|
||||
|
||||
|
@ -58,12 +70,17 @@ virtual int NodeCallback(const bdId *id, uint32_t peerflags);
|
|||
virtual int PeerCallback(const bdId *id, uint32_t status);
|
||||
virtual int ValueCallback(const bdNodeId *id, std::string key, uint32_t status);
|
||||
|
||||
bool SearchResult(bdId *id, uint32_t &status);
|
||||
|
||||
private:
|
||||
|
||||
/* real DHT classes */
|
||||
UdpStack *mStack;
|
||||
UdpBitDht *mUdpBitDht;
|
||||
|
||||
bdMutex resultsMtx; /* for all class data (below) */
|
||||
|
||||
std::map<bdNodeId, BssResult> mSearchNodes;
|
||||
};
|
||||
|
||||
|
||||
|
|
60
libbitdht/src/example/bootstrap_fn.cc
Normal file
60
libbitdht/src/example/bootstrap_fn.cc
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
17
libbitdht/src/example/bootstrap_fn.h
Normal file
17
libbitdht/src/example/bootstrap_fn.h
Normal 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);
|
||||
|
31
libbitdht/src/example/bssdht.cc
Normal file
31
libbitdht/src/example/bssdht.cc
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#ifdef WINDOWS_SYS
|
||||
#include "util/rsstring.h"
|
||||
#include "util/rswin.h"
|
||||
#endif
|
||||
|
||||
#include "dbase/fimonitor.h"
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
#ifdef WINDOWS_SYS
|
||||
#include "util/rswin.h"
|
||||
#endif // WINDOWS_SYS
|
||||
|
||||
#include "ftfileprovider.h"
|
||||
#include "ftchunkmap.h"
|
||||
|
||||
|
@ -5,10 +9,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
#include "util/rswin.h"
|
||||
#endif // WINDOWS_SYS
|
||||
|
||||
/********
|
||||
* #define DEBUG_FT_FILE_PROVIDER 1
|
||||
* #define DEBUG_TRANSFERS 1 // TO GET TIMESTAMPS of DATA READING
|
||||
|
|
|
@ -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"
|
||||
|
||||
GxsCoreServer::GxsCoreServer()
|
||||
|
@ -28,10 +48,12 @@ void GxsCoreServer::run()
|
|||
{
|
||||
std::set<RsGxsService*>::iterator sit;
|
||||
|
||||
double timeDelta = 0.2;
|
||||
double timeDelta = 0.02;
|
||||
|
||||
while(isRunning())
|
||||
{
|
||||
for(sit = mGxsServices.begin(); sit != mGxsServices.end(); sit++)
|
||||
(*sit)->tick();
|
||||
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
|
@ -39,9 +61,6 @@ void GxsCoreServer::run()
|
|||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
for(sit = mGxsServices.begin(); sit != mGxsServices.end(); sit++)
|
||||
(*sit)->tick();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,37 @@
|
|||
/*
|
||||
* gxscoreserver.h
|
||||
*
|
||||
* Created on: 24 Jul 2012
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef 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 "gxs/rsgxs.h"
|
||||
|
||||
class GxsCoreServer : RsThread {
|
||||
class GxsCoreServer : public RsThread
|
||||
{
|
||||
public:
|
||||
GxsCoreServer();
|
||||
~GxsCoreServer();
|
||||
|
|
400
libretroshare/src/gxs/gxssecurity.cc
Normal file
400
libretroshare/src/gxs/gxssecurity.cc
Normal 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;
|
||||
}
|
||||
|
||||
|
145
libretroshare/src/gxs/gxssecurity.h
Normal file
145
libretroshare/src/gxs/gxssecurity.h
Normal 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
|
95
libretroshare/src/gxs/gxstokenqueue.cc
Normal file
95
libretroshare/src/gxs/gxstokenqueue.cc
Normal 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;
|
||||
}
|
||||
|
||||
|
73
libretroshare/src/gxs/gxstokenqueue.h
Normal file
73
libretroshare/src/gxs/gxstokenqueue.h
Normal 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
|
|
@ -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 "rsdataservice.h"
|
||||
|
@ -13,16 +40,21 @@
|
|||
#define KEY_NXS_IDENTITY std::string("identity")
|
||||
#define KEY_GRP_ID std::string("grpId")
|
||||
#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_NXS_FLAGS std::string("flags")
|
||||
#define KEY_NXS_META std::string("meta")
|
||||
#define KEY_NXS_SERV_STRING std::string("serv_str")
|
||||
|
||||
|
||||
// grp table columns
|
||||
#define KEY_ADMIN_SIGN std::string("adminSign")
|
||||
#define KEY_KEY_SET std::string("keySet")
|
||||
#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
|
||||
#define KEY_GRP_SUBCR_FLAG std::string("subscribeFlag")
|
||||
|
@ -33,7 +65,6 @@
|
|||
|
||||
|
||||
// msg table columns
|
||||
#define KEY_PUBLISH_SIGN std::string("publishSign")
|
||||
#define KEY_MSG_ID std::string("msgId")
|
||||
#define KEY_ORIG_MSG_ID std::string("origMsgId")
|
||||
#define KEY_MSG_PARENT_ID std::string("parentId")
|
||||
|
@ -61,47 +92,62 @@
|
|||
|
||||
// grp col numbers
|
||||
|
||||
#define COL_ADMIN_SIGN 5
|
||||
#define COL_KEY_SET 6
|
||||
#define COL_GRP_SUBCR_FLAG 7
|
||||
#define COL_GRP_POP 8
|
||||
#define COL_MSG_COUNT 9
|
||||
#define COL_GRP_STATUS 10
|
||||
#define COL_GRP_NAME 11
|
||||
#define COL_GRP_LAST_POST 12
|
||||
#define COL_ORIG_GRP_ID 13
|
||||
#define COL_KEY_SET 5
|
||||
#define COL_GRP_SUBCR_FLAG 6
|
||||
#define COL_GRP_POP 7
|
||||
#define COL_MSG_COUNT 8
|
||||
#define COL_GRP_STATUS 9
|
||||
#define COL_GRP_NAME 10
|
||||
#define COL_GRP_LAST_POST 11
|
||||
#define COL_ORIG_GRP_ID 12
|
||||
#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
|
||||
#define COL_PUBLISH_SIGN 5
|
||||
#define COL_MSG_ID 6
|
||||
#define COL_ORIG_MSG_ID 7
|
||||
#define COL_MSG_STATUS 8
|
||||
#define COL_CHILD_TS 9
|
||||
#define COL_PARENT_ID 10
|
||||
#define COL_THREAD_ID 11
|
||||
#define COL_MSG_NAME 12
|
||||
#define COL_MSG_ID 5
|
||||
#define COL_ORIG_MSG_ID 6
|
||||
#define COL_MSG_STATUS 7
|
||||
#define COL_CHILD_TS 8
|
||||
#define COL_PARENT_ID 9
|
||||
#define COL_THREAD_ID 10
|
||||
#define COL_MSG_NAME 11
|
||||
#define COL_MSG_SERV_STRING 12
|
||||
|
||||
// generic meta shared col numbers
|
||||
#define COL_GRP_ID 0
|
||||
#define COL_TIME_STAMP 1
|
||||
#define COL_NXS_FLAGS 2
|
||||
#define COL_IDENTITY_SIGN 3
|
||||
#define COL_SIGN_SET 3
|
||||
#define COL_IDENTITY 4
|
||||
|
||||
#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,
|
||||
RsGxsSearchModule *mod)
|
||||
: RsGeneralDataService(), mServiceDir(serviceDir), mDbName(mServiceDir + "/" + dbName), mServType(serviceType){
|
||||
: RsGeneralDataService(), mServiceDir(serviceDir), mDbName(mServiceDir + "/" + dbName), mServType(serviceType),
|
||||
mDbMutex("RsDataService"){
|
||||
|
||||
initialise();
|
||||
|
||||
// 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_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_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
|
||||
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
|
||||
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_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
|
||||
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(){
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
// initialise database
|
||||
mDb = new RetroDb(mDbName, RetroDb::OPEN_READWRITE_CREATE);
|
||||
|
||||
|
@ -136,9 +186,8 @@ void RsDataService::initialise(){
|
|||
KEY_NXS_FLAGS + " INT," +
|
||||
KEY_ORIG_MSG_ID + " TEXT," +
|
||||
KEY_TIME_STAMP + " INT," +
|
||||
KEY_PUBLISH_SIGN + " BLOB," +
|
||||
KEY_NXS_IDENTITY + " TEXT," +
|
||||
KEY_IDENTITY_SIGN + " BLOB," +
|
||||
KEY_SIGN_SET + " BLOB," +
|
||||
KEY_NXS_FILE + " TEXT,"+
|
||||
KEY_NXS_FILE_OFFSET + " INT," +
|
||||
KEY_MSG_STATUS + " INT," +
|
||||
|
@ -147,13 +196,13 @@ void RsDataService::initialise(){
|
|||
KEY_MSG_THREAD_ID + " TEXT," +
|
||||
KEY_MSG_PARENT_ID + " TEXT,"+
|
||||
KEY_MSG_NAME + " TEXT," +
|
||||
KEY_NXS_SERV_STRING + " TEXT," +
|
||||
KEY_NXS_FILE_LEN + " INT);");
|
||||
|
||||
// create table for grp data
|
||||
mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" +
|
||||
KEY_GRP_ID + " TEXT," +
|
||||
KEY_TIME_STAMP + " INT," +
|
||||
KEY_ADMIN_SIGN + " BLOB," + " BLOB," +
|
||||
KEY_NXS_FILE + " TEXT," +
|
||||
KEY_NXS_FILE_OFFSET + " INT," +
|
||||
KEY_KEY_SET + " BLOB," +
|
||||
|
@ -167,8 +216,14 @@ void RsDataService::initialise(){
|
|||
KEY_GRP_STATUS + " INT," +
|
||||
KEY_NXS_IDENTITY + " TEXT," +
|
||||
KEY_ORIG_GRP_ID + " TEXT," +
|
||||
KEY_NXS_SERV_STRING + " TEXT," +
|
||||
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_GRP_NAME, grpMeta->mGroupName);
|
||||
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->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;
|
||||
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;
|
||||
|
@ -224,6 +270,11 @@ RsGxsGrpMetaData* RsDataService::getGrpMeta(RetroCursor &c)
|
|||
grpMeta->mLastPost = c.getInt32(COL_GRP_LAST_POST);
|
||||
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)
|
||||
return grpMeta;
|
||||
|
@ -307,26 +358,18 @@ RsGxsMsgMetaData* RsDataService::getMsgMeta(RetroCursor &c)
|
|||
c.getString(COL_ORIG_MSG_ID, msgMeta->mOrigMsgId);
|
||||
c.getString(COL_IDENTITY, msgMeta->mAuthorId);
|
||||
c.getString(COL_MSG_NAME, msgMeta->mMsgName);
|
||||
c.getString(COL_MSG_SERV_STRING, msgMeta->mServiceString);
|
||||
|
||||
if(!msgMeta->mAuthorId.empty()){
|
||||
offset = 0;
|
||||
data = (char*)c.getData(COL_IDENTITY_SIGN, data_len);
|
||||
msgMeta->idSign.GetTlv(data, data_len, &offset);
|
||||
}
|
||||
data = (char*)c.getData(COL_SIGN_SET, data_len);
|
||||
msgMeta->signSet.GetTlv(data, data_len, &offset);
|
||||
|
||||
|
||||
msgMeta->mMsgFlags = c.getInt32(COL_NXS_FLAGS);
|
||||
msgMeta->mPublishTs = c.getInt32(COL_TIME_STAMP);
|
||||
|
||||
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
|
||||
c.getString(COL_THREAD_ID, msgMeta->mThreadId);
|
||||
c.getString(COL_PARENT_ID, msgMeta->mParentId);
|
||||
|
@ -376,7 +419,7 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c)
|
|||
|
||||
if(ok){
|
||||
|
||||
char msg_data[data_len];
|
||||
char* msg_data = new char[data_len];
|
||||
std::ifstream istrm(msgFile.c_str(), std::ios::binary);
|
||||
istrm.seekg(offset, std::ios::beg);
|
||||
istrm.read(msg_data, data_len);
|
||||
|
@ -384,6 +427,7 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c)
|
|||
istrm.close();
|
||||
offset = 0;
|
||||
ok &= msg->msg.GetTlv(msg_data, data_len, &offset);
|
||||
delete[] msg_data;
|
||||
}
|
||||
|
||||
if(ok)
|
||||
|
@ -396,6 +440,9 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c)
|
|||
|
||||
int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData* >::iterator mit = msg.begin();
|
||||
|
||||
// start a transaction
|
||||
|
@ -419,19 +466,15 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
|||
cv.put(KEY_NXS_FILE_LEN, (int32_t)msgPtr->msg.TlvSize());
|
||||
cv.put(KEY_MSG_ID, msgMetaPtr->mMsgId);
|
||||
cv.put(KEY_GRP_ID, msgMetaPtr->mGroupId);
|
||||
char pubSignData[msgMetaPtr->pubSign.TlvSize()];
|
||||
offset = 0;
|
||||
msgMetaPtr->pubSign.SetTlv(pubSignData, msgMetaPtr->pubSign.TlvSize(), &offset);
|
||||
cv.put(KEY_PUBLISH_SIGN, msgMetaPtr->pubSign.TlvSize(), pubSignData);
|
||||
cv.put(KEY_NXS_SERV_STRING, msgMetaPtr->mServiceString);
|
||||
|
||||
|
||||
if(! (msgMetaPtr->mAuthorId.empty()) ){
|
||||
char idSignData[msgMetaPtr->idSign.TlvSize()];
|
||||
char signSetData[msgMetaPtr->signSet.TlvSize()];
|
||||
offset = 0;
|
||||
msgMetaPtr->idSign.SetTlv(idSignData, msgMetaPtr->idSign.TlvSize(), &offset);
|
||||
cv.put(KEY_IDENTITY_SIGN, msgMetaPtr->idSign.TlvSize(), idSignData);
|
||||
msgMetaPtr->signSet.SetTlv(signSetData, msgMetaPtr->signSet.TlvSize(), &offset);
|
||||
cv.put(KEY_SIGN_SET, msgMetaPtr->signSet.TlvSize(), signSetData);
|
||||
cv.put(KEY_NXS_IDENTITY, msgMetaPtr->mAuthorId);
|
||||
}
|
||||
|
||||
|
||||
cv.put(KEY_NXS_FLAGS, (int32_t) msgMetaPtr->mMsgFlags);
|
||||
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);
|
||||
|
||||
offset = 0;
|
||||
char msgData[msgPtr->msg.TlvSize()];
|
||||
char* msgData = new char[msgPtr->msg.TlvSize()];
|
||||
msgPtr->msg.SetTlv(msgData, msgPtr->msg.TlvSize(), &offset);
|
||||
ostrm.write(msgData, msgPtr->msg.TlvSize());
|
||||
ostrm.close();
|
||||
delete[] msgData;
|
||||
|
||||
mDb->sqlInsert(MSG_TABLE_NAME, "", cv);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData* >::iterator sit = grp.begin();
|
||||
|
||||
// begin transaction
|
||||
mDb->execSQL("BEGIN;");
|
||||
|
||||
for(; sit != grp.end(); sit++){
|
||||
for(; sit != grp.end(); sit++)
|
||||
{
|
||||
|
||||
RsNxsGrp* grpPtr = sit->first;
|
||||
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_NAME, grpMetaPtr->mGroupName);
|
||||
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_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()) ){
|
||||
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;
|
||||
char keySetData[grpMetaPtr->keys.TlvSize()];
|
||||
grpMetaPtr->keys.SetTlv(keySetData, grpMetaPtr->keys.TlvSize(), &offset);
|
||||
|
@ -539,20 +593,32 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
|||
mDb->sqlInsert(GRP_TABLE_NAME, "", cv);
|
||||
}
|
||||
// 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){
|
||||
|
||||
if(grp.empty()){
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "", "");
|
||||
|
||||
if(c)
|
||||
{
|
||||
std::vector<RsNxsGrp*> grps;
|
||||
|
||||
retrieveGroups(c, grps, withMeta);
|
||||
retrieveGroups(c, grps);
|
||||
std::vector<RsNxsGrp*>::iterator vit = grps.begin();
|
||||
|
||||
for(; vit != grps.end(); vit++)
|
||||
|
@ -565,6 +631,7 @@ int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool
|
|||
|
||||
}else{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin();
|
||||
|
||||
for(; mit != grp.end(); mit++)
|
||||
|
@ -590,10 +657,27 @@ int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool
|
|||
}
|
||||
}
|
||||
|
||||
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){
|
||||
bool valid = c->moveToFirst();
|
||||
|
@ -604,12 +688,6 @@ void RsDataService::retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps,
|
|||
// only add the latest grp info
|
||||
if(g)
|
||||
{
|
||||
RsGxsGrpMetaData* meta;
|
||||
|
||||
if(withMeta)
|
||||
meta = getGrpMeta(*c);
|
||||
|
||||
if(meta) g->metaData = meta;
|
||||
grps.push_back(g);
|
||||
}
|
||||
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 metaReqIds;// collects metaReqIds if needed
|
||||
|
||||
for(; mit != reqIds.end(); mit++)
|
||||
{
|
||||
|
||||
|
@ -632,6 +712,9 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
|
|||
std::vector<RsNxsMsg*> msgSet;
|
||||
|
||||
if(msgIdV.empty()){
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId + "'", "");
|
||||
|
||||
if(c)
|
||||
|
@ -645,6 +728,9 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
|
|||
|
||||
for(; sit!=msgIdV.end();sit++){
|
||||
const std::string& msgId = *sit;
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId
|
||||
+ "' AND " + KEY_MSG_ID + "='" + msgId + "'", "");
|
||||
|
||||
|
@ -657,7 +743,75 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
|
|||
|
||||
msg[grpId] = msgSet;
|
||||
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)
|
||||
|
@ -668,8 +822,6 @@ void RsDataService::retrieveMessages(RetroCursor *c, std::vector<RsNxsMsg *> &ms
|
|||
|
||||
if(m){
|
||||
msgs.push_back(m);;
|
||||
}else{
|
||||
delete m;
|
||||
}
|
||||
|
||||
valid = c->moveToNext();
|
||||
|
@ -677,17 +829,49 @@ void RsDataService::retrieveMessages(RetroCursor *c, std::vector<RsNxsMsg *> &ms
|
|||
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(msgIdV.empty()){
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgMetaColumns, KEY_GRP_ID+ "='" + grpId + "'", "");
|
||||
|
||||
retrieveMsgMeta(c, metaSet);
|
||||
|
||||
}else{
|
||||
|
||||
// request each grp
|
||||
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] = metaSet;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RsDataService::retrieveMsgMeta(RetroCursor *c, std::vector<RsGxsMsgMetaData *> &msgMeta)
|
||||
{
|
||||
|
||||
if(c)
|
||||
{
|
||||
|
@ -695,24 +879,22 @@ int RsDataService::retrieveGxsMsgMetaData(const std::vector<std::string> &grpIds
|
|||
while(valid){
|
||||
RsGxsMsgMetaData* m = getMsgMeta(*c);
|
||||
|
||||
if(m){
|
||||
meta.push_back(m);
|
||||
}else{
|
||||
delete m;
|
||||
}
|
||||
if(m != NULL)
|
||||
msgMeta.push_back(m);
|
||||
|
||||
valid = c->moveToNext();
|
||||
}
|
||||
|
||||
msgMeta[grpId] = meta;
|
||||
}
|
||||
delete c;
|
||||
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int RsDataService::retrieveGxsGrpMetaData(std::map<std::string, RsGxsGrpMetaData *>& grp)
|
||||
int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaData *>& grp)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
if(grp.empty()){
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "", "");
|
||||
|
||||
if(c)
|
||||
|
@ -729,8 +911,40 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<std::string, RsGxsGrpMetaData
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
@ -748,6 +962,7 @@ int RsDataService::resetDataStore()
|
|||
std::map<std::string, RsNxsGrp*>::iterator mit
|
||||
= grps.begin();
|
||||
|
||||
|
||||
// remove all grp msgs files from service dir
|
||||
for(; mit != grps.end(); mit++){
|
||||
std::string file = mServiceDir + "/" + mit->first;
|
||||
|
@ -755,8 +970,11 @@ int RsDataService::resetDataStore()
|
|||
remove(file.c_str()); // remove group file
|
||||
remove(msgFile.c_str()); // and remove messages file
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mDbMutex);
|
||||
mDb->closeDb();
|
||||
}
|
||||
|
||||
remove(mDbName.c_str()); // remove db file
|
||||
|
||||
// recreate database
|
||||
|
@ -771,18 +989,22 @@ int RsDataService::removeGroups(const std::vector<std::string> &grpIds)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,31 @@
|
|||
#ifndef 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 "util/retrodb.h"
|
||||
|
||||
|
@ -10,7 +35,7 @@ class RsDataService : public RsGeneralDataService
|
|||
public:
|
||||
|
||||
RsDataService(const std::string& serviceDir, const std::string& dbName, uint16_t serviceType, RsGxsSearchModule* mod = NULL);
|
||||
virtual ~RsDataService() ;
|
||||
virtual ~RsDataService();
|
||||
|
||||
/*!
|
||||
* Retrieves all msgs
|
||||
|
@ -19,7 +44,7 @@ public:
|
|||
* @param cache whether to store results of this retrieval in memory for faster later retrieval
|
||||
* @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
|
||||
|
@ -36,7 +61,7 @@ public:
|
|||
* @param cache whether to store retrieval in mem for faster later retrieval
|
||||
* @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)
|
||||
|
@ -45,7 +70,7 @@ public:
|
|||
* @param cache whether to store retrieval in mem for faster later retrieval
|
||||
* @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
|
||||
|
@ -53,14 +78,14 @@ public:
|
|||
* @param msgIds ids of messages to be removed
|
||||
* @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
|
||||
* @param grpIds ids of groups to be removed
|
||||
* @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
|
||||
|
@ -90,13 +115,13 @@ public:
|
|||
* @param metaData The meta data item to update
|
||||
* @return error code
|
||||
*/
|
||||
int updateMessageMetaData(MsgLocMetaData* metaData);
|
||||
int updateMessageMetaData(MsgLocMetaData& metaData);
|
||||
|
||||
/*!
|
||||
* @param metaData The meta data item to update
|
||||
* @return error code
|
||||
*/
|
||||
int updateGroupMetaData(GrpLocMetaData* meta);
|
||||
int updateGroupMetaData(GrpLocMetaData& meta);
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -117,11 +142,18 @@ private:
|
|||
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 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
|
||||
|
@ -158,6 +190,8 @@ private:
|
|||
|
||||
RetroDb* mDb;
|
||||
|
||||
RsMutex mDbMutex;
|
||||
|
||||
std::list<std::string> msgColumns;
|
||||
std::list<std::string> msgMetaColumns;
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "serialiser/rsnxsitems.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
#include "rsgxs.h"
|
||||
#include "util/contentvalue.h"
|
||||
|
||||
|
||||
class RsGxsSearchModule {
|
||||
|
@ -53,6 +54,11 @@ public:
|
|||
*/
|
||||
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 {
|
||||
|
||||
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<RsGxsMsgMetaData*> > GxsMsgMetaResult; // <grpId, msg metadatas>
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > NxsMsgDataResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsNxsMsg*> > NxsMsgRelatedDataResult;
|
||||
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
|
||||
|
@ -91,6 +103,15 @@ class GrpLocMetaData {
|
|||
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:
|
||||
|
||||
RsGeneralDataService(){}
|
||||
|
@ -103,12 +124,12 @@ public:
|
|||
* @param cache whether to store results of this retrieval in memory for faster later retrieval
|
||||
* @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
|
||||
* @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
|
||||
* @return error code
|
||||
*/
|
||||
|
@ -130,7 +151,7 @@ public:
|
|||
* @param cache whether to store retrieval in mem for faster later retrieval
|
||||
* @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
|
||||
|
@ -161,25 +182,25 @@ public:
|
|||
* @param msg map of message and decoded meta data information
|
||||
* @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
|
||||
* @param grp map of group and decoded meta data
|
||||
* @return error code
|
||||
*/
|
||||
virtual int storeGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grp) = 0;
|
||||
virtual int storeGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grsp) = 0;
|
||||
|
||||
|
||||
/*!
|
||||
* @param metaData
|
||||
*/
|
||||
virtual int updateMessageMetaData(MsgLocMetaData* metaData) = 0;
|
||||
virtual int updateMessageMetaData(MsgLocMetaData& metaData) = 0;
|
||||
|
||||
/*!
|
||||
* @param metaData
|
||||
*/
|
||||
virtual int updateGroupMetaData(GrpLocMetaData* meta) = 0;
|
||||
virtual int updateGroupMetaData(GrpLocMetaData& meta) = 0;
|
||||
|
||||
|
||||
/*!
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,7 @@
|
|||
#define RSGENEXCHANGE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
* libretroshare/src/gxs: rsgenexchange.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
|
@ -27,17 +27,21 @@
|
|||
*/
|
||||
|
||||
#include <queue>
|
||||
#include <ctime>
|
||||
|
||||
#include "rsgxs.h"
|
||||
#include "rsgds.h"
|
||||
#include "rsnxs.h"
|
||||
#include "rsgxsdataaccess.h"
|
||||
#include "rsnxsobserver.h"
|
||||
#include "retroshare/rsgxsservice.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > GxsMsgDataMap;
|
||||
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<RsGxsGrpMsgIdPair, std::vector<RsMsgMetaData> > GxsMsgRelatedMetaMap;
|
||||
|
||||
/*!
|
||||
* This should form the parent class to \n
|
||||
|
@ -45,42 +49,49 @@ typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap;
|
|||
* management/publishing/sync features
|
||||
*
|
||||
* Features: \n
|
||||
* a. Data Access:
|
||||
* Provided by handle to RsTokenService. This ensure consistency
|
||||
* of requests and hiearchy of groups -> then messages which are
|
||||
* sectioned by group ids.
|
||||
* The one caveat is that redemption of tokens are done through
|
||||
* the backend of this class
|
||||
* b. Publishing:
|
||||
* Methods are provided to publish msg and group items and also make
|
||||
* changes to meta information of both item types
|
||||
* c. Sync/Notification:
|
||||
* Also notifications are made here on receipt of new data from
|
||||
* a. Data Access: \n
|
||||
* Provided by handle to RsTokenService. This ensure consistency \n
|
||||
* of requests and hiearchy of groups -> then messages which are \n
|
||||
* sectioned by group ids. \n
|
||||
* The one caveat is that redemption of tokens are done through \n
|
||||
* the backend of this class \n
|
||||
* b. Publishing: \n
|
||||
* Methods are provided to publish msg and group items and also make \n
|
||||
* changes to meta information of both item types \n
|
||||
* c. Sync/Notification: \n
|
||||
* Also notifications are made here on receipt of new data from \n
|
||||
* connected peers
|
||||
*/
|
||||
class RsGenExchange : public RsGxsService
|
||||
|
||||
class RsGixs;
|
||||
|
||||
class RsGenExchange : public RsGxsService, public RsNxsObserver, public RsThread
|
||||
{
|
||||
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
|
||||
* @param gds Data service needed to act as store of message
|
||||
* @param ns Network service needed to synchronise data with rs peers
|
||||
* @param serviceSerialiser The users service needs this \n
|
||||
* 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();
|
||||
|
||||
|
||||
/** S: Observer implementation **/
|
||||
|
||||
/*!
|
||||
* @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
|
||||
|
@ -96,14 +107,37 @@ public:
|
|||
*/
|
||||
void tick();
|
||||
|
||||
/*!
|
||||
* Any backgroup processing needed by
|
||||
*/
|
||||
virtual void service_tick() = 0;
|
||||
|
||||
|
||||
/*!
|
||||
*
|
||||
* @return handle to token service handle for making
|
||||
* 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 **/
|
||||
|
||||
|
@ -119,14 +153,24 @@ protected:
|
|||
* Retrieve msg list for a given token sectioned by group Ids
|
||||
* @param token token to be redeemed
|
||||
* @param msgIds a map of grpId -> msgList (vector)
|
||||
* @return false if could not redeem token
|
||||
*/
|
||||
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
|
||||
* @param token
|
||||
* @param groupInfo
|
||||
* @return false if could not redeem token
|
||||
*/
|
||||
bool getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
|
||||
|
||||
|
@ -137,12 +181,31 @@ protected:
|
|||
*/
|
||||
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
|
||||
* @param token token to be redeemed for grpitem retrieval
|
||||
* @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
|
||||
|
@ -151,30 +214,210 @@ protected:
|
|||
*/
|
||||
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:
|
||||
|
||||
/** Modifications **/
|
||||
|
||||
/*!
|
||||
* Enables publication of a group item
|
||||
* If the item exists already this is simply versioned
|
||||
* This will induce a related change message
|
||||
* Ownership of item passes to this rsgenexchange
|
||||
* Enables publication of a group item \n
|
||||
* If the item exists already this is simply versioned \n
|
||||
* This will induce a related change message \n
|
||||
* Ownership of item passes to this rsgenexchange \n
|
||||
* @param token
|
||||
* @param grpItem
|
||||
* @param
|
||||
*/
|
||||
bool publishGroup(RsGxsGrpItem* grpItem);
|
||||
void publishGroup(uint32_t& token, RsGxsGrpItem* grpItem);
|
||||
|
||||
/*!
|
||||
* Enables publication of a message item
|
||||
* If the item exists already this is simply versioned
|
||||
* This will induce a related a change message
|
||||
* Enables publication of a message item \n
|
||||
* Setting mOrigMsgId meta member to blank \n
|
||||
* 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
|
||||
* @param token
|
||||
* @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:
|
||||
|
||||
|
@ -187,11 +430,16 @@ protected:
|
|||
* as it is called by the backend GXS system to \n
|
||||
* update client of changes which should \n
|
||||
* 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
|
||||
*/
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) = 0;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void processRecvdData();
|
||||
|
||||
|
@ -203,6 +451,82 @@ public:
|
|||
|
||||
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:
|
||||
|
||||
RsMutex mGenMtx;
|
||||
|
@ -210,18 +534,29 @@ private:
|
|||
RsGeneralDataService* mDataStore;
|
||||
RsNetworkExchangeService *mNetService;
|
||||
RsSerialType *mSerialiser;
|
||||
RsGixs* mGixs;
|
||||
|
||||
std::vector<RsNxsMsg*> mReceivedMsgs;
|
||||
std::vector<RsNxsGrp*> mReceivedGrps;
|
||||
|
||||
std::vector<RsGxsGrpItem*> mGrpsToPublish;
|
||||
std::vector<RsGxsMsgItem*> mMsgsToPublish;
|
||||
std::map<uint32_t, RsGxsGrpItem*> mGrpsToPublish;
|
||||
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;
|
||||
|
||||
/// service type
|
||||
uint16_t mServType;
|
||||
|
||||
/// authentication policy
|
||||
uint32_t mAuthenPolicy;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -27,9 +27,11 @@
|
|||
*/
|
||||
|
||||
#include "gxs/rsgxs.h"
|
||||
#include "gxs/rsgenexchange.h"
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <set>
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
/*!
|
||||
* 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
|
||||
{
|
||||
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
|
||||
class RsGixs
|
||||
{
|
||||
public:
|
||||
|
||||
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 */
|
||||
|
||||
// Key related interface - used for validating msgs and groups.
|
||||
/*!
|
||||
* Use to query a whether given key is available by its key reference
|
||||
* @param keyref the keyref of key that is being checked for
|
||||
* @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
|
||||
* @param keyref the KeyRef of the key being checked for
|
||||
* @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
|
||||
* @param keyref the KeyRef of the key being requested
|
||||
* @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
|
||||
|
@ -177,53 +156,68 @@ public:
|
|||
* @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 ***/
|
||||
};
|
||||
|
||||
/*!
|
||||
* Use to sign data with a given key
|
||||
* @param keyref the key to sign the data with
|
||||
* @param data the data to be signed
|
||||
* @param dataLen the length of the data
|
||||
* @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;
|
||||
class GixsReputation
|
||||
{
|
||||
public:
|
||||
RsGxsId id;
|
||||
int score;
|
||||
};
|
||||
|
||||
/*!
|
||||
* 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;
|
||||
|
||||
/*!
|
||||
* Attempt to decrypt data with a given key
|
||||
* @param keyref
|
||||
* @param data data to be decrypted
|
||||
* @param dataLen length of data
|
||||
* @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;
|
||||
class RsGixsReputation
|
||||
{
|
||||
public:
|
||||
// get Reputation.
|
||||
virtual bool getReputation(const RsGxsId &id, const GixsReputation &rep) = 0;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Attempt to encrypt data with a given key
|
||||
* @param keyref
|
||||
* @param data data to be encrypted
|
||||
* @param dataLen length of data
|
||||
* @param encryptedData encrypted data
|
||||
* @param encryptDataLen length of encrypted data
|
||||
*/
|
||||
virtual bool encrypt(const KeyRef& keyref, unsigned char* data, int dataLen,
|
||||
unsigned char*& encryptedData, uint32_t& encryptDataLen) = 0;
|
||||
|
||||
/*** This Class pulls all the GXS Interfaces together ****/
|
||||
|
||||
class RsGxsIdExchange:
|
||||
public RsGenExchange,
|
||||
public RsGixsReputation,
|
||||
public RsGixs
|
||||
{
|
||||
public:
|
||||
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; }
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -4,10 +4,7 @@
|
|||
/*
|
||||
* libretroshare/src/gxs : rsgxs.h
|
||||
*
|
||||
* GXS interface for RetroShare.
|
||||
* Convenience header
|
||||
*
|
||||
* Copyright 2011 Christopher Evi-Parker
|
||||
* Copyright 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
|
||||
|
@ -25,34 +22,36 @@
|
|||
*
|
||||
* 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 <string>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#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> > GxsMsgIdResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgMetaData*> > GxsMsgMetaResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > NxsMsgDataResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > GxsMsgResult; // <grpId, msgs>
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > MsgMetaResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMsgMetaData*> > MsgRelatedMetaResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMessageId> > MsgRelatedIdResult;
|
||||
|
||||
class RsGxsService : public RsNxsObserver
|
||||
|
||||
|
||||
class RsGxsService
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsService();
|
||||
virtual ~RsGxsService();
|
||||
RsGxsService(){}
|
||||
virtual ~RsGxsService(){}
|
||||
|
||||
virtual void tick() = 0;
|
||||
|
||||
|
|
|
@ -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 "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
RsGxsGrpMetaData::RsGxsGrpMetaData()
|
||||
{
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
uint32_t RsGxsGrpMetaData::serial_size()
|
||||
|
@ -17,9 +43,11 @@ uint32_t RsGxsGrpMetaData::serial_size()
|
|||
s += 4;
|
||||
s += 4;
|
||||
s += GetTlvStringSize(mAuthorId);
|
||||
s += adminSign.TlvSize();
|
||||
s += GetTlvStringSize(mServiceString);
|
||||
s += signSet.TlvSize();
|
||||
s += keys.TlvSize();
|
||||
s += idSign.TlvSize();
|
||||
s += 4; // for mCircleType
|
||||
s += GetTlvStringSize(mCircleId);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -30,6 +58,7 @@ void RsGxsGrpMetaData::clear(){
|
|||
mOrigGrpId.clear();
|
||||
mAuthorId.clear();
|
||||
mGroupName.clear();
|
||||
mServiceString.clear();
|
||||
mPublishTs = 0;
|
||||
mGroupFlags = 0;
|
||||
mPop = 0;
|
||||
|
@ -37,10 +66,13 @@ void RsGxsGrpMetaData::clear(){
|
|||
mGroupStatus = 0;
|
||||
mLastPost = 0;
|
||||
mSubscribeFlags = 0;
|
||||
|
||||
adminSign.TlvClear();
|
||||
signSet.TlvClear();
|
||||
keys.TlvClear();
|
||||
idSign.TlvClear();
|
||||
mCircleId.clear();
|
||||
mInternalCircle.clear();
|
||||
mOriginator.clear();
|
||||
mCircleType = 0;
|
||||
|
||||
}
|
||||
|
||||
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 &= setRawUInt32(data, tlvsize, &offset, mGroupFlags);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mPublishTs);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mCircleType);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mAuthorId);
|
||||
|
||||
ok &= adminSign.SetTlv(data, tlvsize, &offset);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mServiceString);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mCircleId);
|
||||
ok &= signSet.SetTlv(data, tlvsize, &offset);
|
||||
ok &= keys.SetTlv(data, tlvsize, &offset);
|
||||
ok &= idSign.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
@ -98,11 +132,13 @@ bool RsGxsGrpMetaData::deserialise(void *data, uint32_t &pktsize)
|
|||
ok &= GetTlvString(data, pktsize, &offset, 0, mGroupName);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mGroupFlags);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mPublishTs);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mCircleType);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mAuthorId);
|
||||
|
||||
ok &= adminSign.GetTlv(data, pktsize, &offset);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mServiceString);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mCircleId);
|
||||
ok &= signSet.GetTlv(data, pktsize, &offset);
|
||||
ok &= keys.GetTlv(data, pktsize, &offset);
|
||||
ok &= idSign.GetTlv(data, pktsize, &offset);
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
@ -123,8 +159,7 @@ uint32_t RsGxsMsgMetaData::serial_size()
|
|||
s += GetTlvStringSize(mOrigMsgId);
|
||||
s += GetTlvStringSize(mAuthorId);
|
||||
|
||||
s += pubSign.TlvSize();
|
||||
s += idSign.TlvSize();
|
||||
s += signSet.TlvSize();
|
||||
s += GetTlvStringSize(mMsgName);
|
||||
s += 4;
|
||||
s += 4;
|
||||
|
@ -141,10 +176,9 @@ void RsGxsMsgMetaData::clear()
|
|||
mAuthorId.clear();
|
||||
mOrigMsgId.clear();
|
||||
mMsgName.clear();
|
||||
mServiceString.clear();
|
||||
|
||||
pubSign.TlvClear();
|
||||
idSign.TlvClear();
|
||||
|
||||
signSet.TlvClear();
|
||||
mPublishTs = 0;
|
||||
mMsgFlags = 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, mAuthorId);
|
||||
|
||||
ok &= pubSign.SetTlv(data, *size, &offset);
|
||||
ok &= idSign.SetTlv(data, *size, &offset);
|
||||
ok &= signSet.SetTlv(data, *size, &offset);
|
||||
ok &= SetTlvString(data, *size, &offset, 0, mMsgName);
|
||||
ok &= setRawUInt32(data, *size, &offset, mPublishTs);
|
||||
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, mAuthorId);
|
||||
|
||||
ok &= pubSign.GetTlv(data, *size, &offset);
|
||||
ok &= idSign.GetTlv(data, *size, &offset);
|
||||
ok &= signSet.GetTlv(data, *size, &offset);
|
||||
ok &= GetTlvString(data, *size, &offset, 0, mMsgName);
|
||||
uint32_t t;
|
||||
ok &= getRawUInt32(data, *size, &offset, &t);
|
||||
|
@ -232,6 +264,12 @@ void RsGxsGrpMetaData::operator =(const RsGroupMetaData& rMeta)
|
|||
this->mPublishTs = rMeta.mPublishTs;
|
||||
this->mSubscribeFlags = rMeta.mSubscribeFlags;
|
||||
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)
|
||||
|
@ -247,6 +285,7 @@ void RsGxsMsgMetaData::operator =(const RsMsgMetaData& rMeta)
|
|||
this->mParentId = rMeta.mParentId ;
|
||||
this->mPublishTs = rMeta.mPublishTs ;
|
||||
this->mThreadId = rMeta.mThreadId;
|
||||
this->mServiceString = rMeta.mServiceString;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,33 @@
|
|||
#ifndef 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/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rsgxsitems.h"
|
||||
|
@ -32,14 +55,17 @@ public:
|
|||
std::string mGroupName;
|
||||
uint32_t mGroupFlags;
|
||||
uint32_t mPublishTs;
|
||||
uint32_t mSignFlags;
|
||||
std::string mAuthorId;
|
||||
|
||||
std::string mCircleId;
|
||||
uint32_t mCircleType;
|
||||
|
||||
RsTlvKeySignature adminSign;
|
||||
|
||||
RsTlvKeySignatureSet signSet;
|
||||
RsTlvSecurityKeySet keys;
|
||||
RsTlvKeySignature idSign;
|
||||
|
||||
|
||||
std::string mServiceString;
|
||||
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
|
||||
|
@ -50,7 +76,8 @@ public:
|
|||
time_t mLastPost; // ???
|
||||
|
||||
uint32_t mGroupStatus;
|
||||
|
||||
std::string mOriginator;
|
||||
std::string mInternalCircle;
|
||||
};
|
||||
|
||||
|
||||
|
@ -75,8 +102,9 @@ public:
|
|||
RsGxsMessageId mOrigMsgId;
|
||||
std::string mAuthorId;
|
||||
|
||||
RsTlvKeySignature pubSign;
|
||||
RsTlvKeySignature idSign;
|
||||
RsTlvKeySignatureSet signSet;
|
||||
|
||||
std::string mServiceString;
|
||||
|
||||
std::string mMsgName;
|
||||
time_t mPublishTs;
|
||||
|
@ -84,8 +112,10 @@ public:
|
|||
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
// normally READ / UNREAD flags. LOCAL Data.
|
||||
|
||||
uint32_t mMsgStatus;
|
||||
time_t mChildTs;
|
||||
bool validated;
|
||||
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -32,8 +32,9 @@
|
|||
|
||||
|
||||
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);
|
||||
|
@ -44,56 +45,54 @@ public:
|
|||
/** S: RsTokenService **/
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param token
|
||||
* @param ansType
|
||||
* @param opts
|
||||
* @param groupIds
|
||||
* Use this to request group related information
|
||||
* @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
|
||||
* @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);
|
||||
|
||||
/*!
|
||||
* For requesting info on all messages of one or more groups
|
||||
* @param token
|
||||
* @param ansType
|
||||
* @param opts
|
||||
* @param groupIds
|
||||
* 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
|
||||
*/
|
||||
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
|
||||
* @param msgId the message id to set status for
|
||||
* @param status status
|
||||
* @param statusMask the mask for the settings targetted
|
||||
* @return true if request made successfully, false otherwise
|
||||
* Use this to get msg information (id, meta, or data), store token value to poll 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, 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);
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param token
|
||||
* @param grpId
|
||||
* @param status
|
||||
* @param statusMask
|
||||
* @return true if request made successfully, false otherwise
|
||||
* Use this to get message information (id, meta, or data), store token value to poll 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 retrieve all the msgs info for each grpId in list, if group Id list is empty \n
|
||||
* 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
|
||||
* @param groupId
|
||||
* @param subscribeFlags
|
||||
* @param subscribeMask
|
||||
* @return true if request made successfully, false otherwise
|
||||
* For requesting msgs related to a given msg id within a group
|
||||
* @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, 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 */
|
||||
uint32_t requestStatus(const uint32_t token);
|
||||
|
@ -103,7 +102,6 @@ public:
|
|||
|
||||
/** E: RsTokenService **/
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
|
@ -147,6 +145,14 @@ public:
|
|||
*/
|
||||
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);
|
||||
|
||||
|
||||
/*!
|
||||
* @param token request token to be redeemed
|
||||
|
@ -161,6 +167,15 @@ public:
|
|||
*/
|
||||
bool getMsgSummary(const uint32_t &token, GxsMsgMetaResult &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 getMsgRelatedSummary(const uint32_t &token, MsgRelatedMetaResult& msgMeta);
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param token request token to be redeemed
|
||||
|
@ -176,6 +191,14 @@ public:
|
|||
*/
|
||||
bool getMsgData(const uint32_t &token, NxsMsgDataResult& msgData);
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param token request token to be redeemed
|
||||
* @param msgData
|
||||
* @return false if data cannot be found for token
|
||||
*/
|
||||
bool getMsgRelatedData(const uint32_t &token, NxsMsgRelatedDataResult& msgData);
|
||||
|
||||
private:
|
||||
|
||||
/** helper functions to implement token service **/
|
||||
|
@ -191,7 +214,7 @@ private:
|
|||
* @param token the value of the token for the request object handle wanted
|
||||
* @return the request associated to this token
|
||||
*/
|
||||
GxsRequest* retrieveRequest(const uint32_t& token);
|
||||
GxsRequest* locked_retrieveRequest(const uint32_t& token);
|
||||
|
||||
/*!
|
||||
* Add a gxs request to queue
|
||||
|
@ -222,7 +245,7 @@ private:
|
|||
* @param status the status to set
|
||||
* @return
|
||||
*/
|
||||
bool updateRequestStatus(const uint32_t &token, const uint32_t &status);
|
||||
bool locked_updateRequestStatus(const uint32_t &token, const uint32_t &status);
|
||||
|
||||
/*!
|
||||
* Use to query the status and other values of a given token
|
||||
|
@ -242,6 +265,35 @@ private:
|
|||
*/
|
||||
void tokenList(std::list<uint32_t> &tokens);
|
||||
|
||||
/*!
|
||||
* Convenience function to delete the ids
|
||||
* @param filter the meta filter to clean
|
||||
*/
|
||||
void cleanseMsgMetaMap(GxsMsgMetaResult& result);
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Assigns a token value to passed integer
|
||||
* The status of the token can still be queried from request status feature
|
||||
* @param token is assigned a unique token value
|
||||
*/
|
||||
uint32_t generatePublicToken();
|
||||
|
||||
/*!
|
||||
* Updates the status of associate token
|
||||
* @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 disposed of
|
||||
*/
|
||||
bool disposeOfPublicToken(const uint32_t &token);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -254,6 +306,14 @@ private:
|
|||
*/
|
||||
bool getGroupList(GroupIdReq* req);
|
||||
|
||||
/*!
|
||||
* convenience function for filtering grpIds
|
||||
* @param grpIdsIn The ids to filter with opts
|
||||
* @param opts the filter options
|
||||
* @param grpIdsOut grpIdsIn filtered with opts
|
||||
*/
|
||||
bool getGroupList(const std::list<RsGxsGroupId>& grpIdsIn, const RsTokReqOptions& opts, std::list<RsGxsGroupId>& grpIdsOut);
|
||||
|
||||
/*!
|
||||
* Attempts to retrieve msg id list from data store
|
||||
* Computationally/CPU-Bandwidth expensive
|
||||
|
@ -291,6 +351,15 @@ private:
|
|||
*/
|
||||
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
|
||||
|
@ -299,6 +368,14 @@ private:
|
|||
*/
|
||||
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
|
||||
|
@ -309,10 +386,30 @@ private:
|
|||
*/
|
||||
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;
|
||||
|
|
|
@ -3,51 +3,105 @@
|
|||
|
||||
#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 {
|
||||
|
||||
|
||||
/*** 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
|
||||
static const uint32_t FLAG_GRP_TYPE_PRIVATE;
|
||||
static const uint32_t FLAG_PRIVACY_PRIVATE = 0x00000001;
|
||||
|
||||
// single publisher, read only
|
||||
static const uint32_t FLAG_GRP_TYPE_RESTRICTED;
|
||||
// publish private key needed to publish
|
||||
static const uint32_t FLAG_PRIVACY_RESTRICTED = 0x00000002;
|
||||
|
||||
// anyone can publish
|
||||
static const uint32_t FLAG_GRP_TYPE_PUBLIC;
|
||||
// anyone can publish, publish key pair not needed
|
||||
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
|
||||
static const uint32_t FLAG_MSG_TYPE_SIGNED;
|
||||
// identity
|
||||
static const uint32_t FLAG_AUTHEN_IDENTITY = 0x000000010;
|
||||
|
||||
// no sign required, but signee can edit if signed
|
||||
static const uint32_t FLAG_MSG_TYPE_ANON;
|
||||
// publish key
|
||||
static const uint32_t FLAG_AUTHEN_PUBLISH = 0x000000020;
|
||||
|
||||
// anyone can mod but sign must be provided (needed for wikis)
|
||||
static const uint32_t FLAG_MSG_TYPE_SIGNED_SHARED;
|
||||
// admin key
|
||||
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 uint32_t FLAG_MSG_EDIT;
|
||||
static const uint8_t MSG_AUTHEN_ROOT_PUBLISH_SIGN = 0x01;
|
||||
|
||||
// indicates msg is id signed
|
||||
static const uint32_t FLAG_MSG_ID_SIGNED;
|
||||
static const uint8_t MSG_AUTHEN_CHILD_PUBLISH_SIGN = 0x02;
|
||||
|
||||
/*** 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 **/
|
||||
|
||||
}
|
||||
|
||||
|
|
170
libretroshare/src/gxs/rsgxsifaceimpl.cc
Normal file
170
libretroshare/src/gxs/rsgxsifaceimpl.cc
Normal 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);
|
||||
}
|
181
libretroshare/src/gxs/rsgxsifaceimpl.h
Normal file
181
libretroshare/src/gxs/rsgxsifaceimpl.h
Normal 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
|
|
@ -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 "rsgxsflags.h"
|
||||
|
||||
#define NXS_NET_DEBUG
|
||||
|
||||
|
@ -10,7 +37,7 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
|
|||
RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs)
|
||||
: p3Config(servType), p3ThreadedService(servType),
|
||||
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));
|
||||
|
@ -31,8 +58,9 @@ int RsGxsNetService::tick(){
|
|||
recvNxsItemQueue();
|
||||
|
||||
uint32_t now = time(NULL);
|
||||
uint32_t elapsed = mSYNC_PERIOD + mSyncTs;
|
||||
|
||||
if((mSYNC_PERIOD + mSyncTs) < now)
|
||||
if((elapsed) < now)
|
||||
{
|
||||
syncWithPeers();
|
||||
mSyncTs = now;
|
||||
|
@ -58,8 +86,46 @@ void RsGxsNetService::syncWithPeers()
|
|||
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)
|
||||
|
@ -301,6 +367,7 @@ void RsGxsNetService::run(){
|
|||
bool RsGxsNetService::locked_checkTransacTimedOut(NxsTransaction* tr)
|
||||
{
|
||||
return tr->mTimeOut < ((uint32_t) time(NULL));
|
||||
// return false;
|
||||
}
|
||||
|
||||
void RsGxsNetService::processTransactions(){
|
||||
|
@ -570,10 +637,11 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
|
|||
// notify listener of grps
|
||||
mObserver->notifyNewGroups(grps);
|
||||
|
||||
|
||||
|
||||
}else if(flag & RsNxsTransac::FLAG_TYPE_MSGS)
|
||||
{
|
||||
|
||||
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
|
||||
std::vector<RsNxsMsg*> msgs;
|
||||
|
||||
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
|
||||
RsNxsSyncMsgItem* item = msgItemL.front();
|
||||
const std::string& grpId = item->grpId;
|
||||
std::vector<std::string> grpIdV;
|
||||
grpIdV.push_back(grpId);
|
||||
GxsMsgReq reqIds;
|
||||
reqIds[grpId] = std::vector<RsGxsMessageId>();
|
||||
GxsMsgMetaResult result;
|
||||
mDataStore->retrieveGxsMsgMetaData(grpIdV, result);
|
||||
mDataStore->retrieveGxsMsgMetaData(reqIds, result);
|
||||
std::vector<RsGxsMsgMetaData*> &msgMetaV = result[grpId];
|
||||
|
||||
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<RsNxsItem*> reqList;
|
||||
|
||||
const std::string peerFrom = tr->mTransaction->PeerId();
|
||||
|
||||
for(; llit != msgItemL.end(); llit++)
|
||||
{
|
||||
const std::string& msgId = (*llit)->msgId;
|
||||
|
@ -732,10 +804,13 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
|||
msgItem->msgId = msgId;
|
||||
msgItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST;
|
||||
msgItem->transactionNumber = transN;
|
||||
msgItem->PeerId(peerFrom);
|
||||
reqList.push_back(msgItem);
|
||||
}
|
||||
}
|
||||
|
||||
if(!reqList.empty())
|
||||
{
|
||||
|
||||
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
||||
transac->transactFlag = RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ
|
||||
|
@ -761,6 +836,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
|||
if(!locked_addTransaction(newTrans))
|
||||
delete newTrans;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
|
@ -806,7 +882,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
|||
|
||||
if(grpMetaMap.find(grpId) == grpMetaMap.end()){
|
||||
RsNxsSyncGrpItem* grpItem = new RsNxsSyncGrpItem(mServType);
|
||||
|
||||
grpItem->PeerId(tr->mTransaction->PeerId());
|
||||
grpItem->grpId = grpId;
|
||||
grpItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST;
|
||||
grpItem->transactionNumber = transN;
|
||||
|
@ -815,6 +891,9 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
|||
}
|
||||
|
||||
|
||||
if(!reqList.empty())
|
||||
{
|
||||
|
||||
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
||||
transac->transactFlag = RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ
|
||||
| RsNxsTransac::FLAG_BEGIN_P1;
|
||||
|
@ -835,6 +914,13 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
|||
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)
|
||||
|
@ -858,8 +944,13 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
|
|||
grps[item->grpId] = NULL;
|
||||
}
|
||||
|
||||
if(!grps.empty())
|
||||
{
|
||||
mDataStore->retrieveNxsGrps(grps, false, false);
|
||||
|
||||
}
|
||||
else{
|
||||
return;
|
||||
}
|
||||
|
||||
NxsTransaction* newTr = new NxsTransaction();
|
||||
newTr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||
|
@ -871,7 +962,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
|
|||
std::string peerId = tr->mTransaction->PeerId();
|
||||
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;
|
||||
newTr->mItems.push_back(mit->second);
|
||||
}
|
||||
|
@ -887,6 +978,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
|
|||
ntr->transactFlag = RsNxsTransac::FLAG_BEGIN_P1 |
|
||||
RsNxsTransac::FLAG_TYPE_GRPS;
|
||||
ntr->nItems = grps.size();
|
||||
ntr->PeerId(tr->mTransaction->PeerId());
|
||||
|
||||
newTr->mTransaction = new RsNxsTransac(*ntr);
|
||||
newTr->mTransaction->PeerId(mOwnId);
|
||||
|
@ -903,6 +995,77 @@ void RsGxsNetService::locked_genSendGrpsTransaction(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;
|
||||
}
|
||||
uint32_t RsGxsNetService::locked_getTransactionId()
|
||||
|
@ -956,7 +1119,6 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
|||
if(grp.empty())
|
||||
return;
|
||||
|
||||
std::vector<RsNxsSyncGrpItem*> grpSyncItems;
|
||||
std::map<std::string, RsGxsGrpMetaData*>::iterator mit =
|
||||
grp.begin();
|
||||
|
||||
|
@ -975,6 +1137,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
|||
gItem->PeerId(peer);
|
||||
gItem->transactionNumber = transN;
|
||||
itemL.push_back(gItem);
|
||||
delete mit->second; // release resource
|
||||
}
|
||||
|
||||
tr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||
|
@ -1003,6 +1166,61 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
|||
void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1047,3 +1265,40 @@ NxsTransaction::~NxsTransaction(){
|
|||
delete mTransaction;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,31 @@
|
|||
#ifndef 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 <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();
|
||||
// void getOnlineList(std::set<std::string>& ssl_peers);
|
||||
std::string getOwnId();
|
||||
void getOnlineList(std::set<std::string>& ssl_peers);
|
||||
|
||||
//};
|
||||
private:
|
||||
|
||||
p3LinkMgr* mLinkMgr;
|
||||
RsMutex mNxsNetMgrMtx;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/// keep track of transaction number
|
||||
|
@ -370,6 +400,7 @@ private:
|
|||
RsMutex mNxsMutex;
|
||||
|
||||
uint32_t mSyncTs;
|
||||
|
||||
const uint32_t mSYNC_PERIOD;
|
||||
|
||||
};
|
||||
|
|
|
@ -1,13 +1,33 @@
|
|||
/*
|
||||
* rsgxsrequesttypes.h
|
||||
*
|
||||
* Created on: 21 Jul 2012
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef 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
|
||||
{
|
||||
|
@ -46,7 +66,7 @@ class GroupDataReq : public GxsRequest
|
|||
{
|
||||
|
||||
public:
|
||||
std::list<std::string> mGroupIds;
|
||||
std::list<RsGxsGroupId> mGroupIds;
|
||||
std::list<RsNxsGrp*> mGroupData;
|
||||
};
|
||||
|
||||
|
@ -76,6 +96,16 @@ public:
|
|||
NxsMsgDataResult mMsgData;
|
||||
};
|
||||
|
||||
class MsgRelatedInfoReq : public GxsRequest
|
||||
{
|
||||
|
||||
public:
|
||||
std::vector<RsGxsGrpMsgIdPair> mMsgIds;
|
||||
MsgRelatedIdResult mMsgIdResult;
|
||||
MsgRelatedMetaResult mMsgMetaResult;
|
||||
NxsMsgRelatedDataResult mMsgDataResult;
|
||||
};
|
||||
|
||||
class GroupSetFlagReq : public GxsRequest
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define RSGNP_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/gxs: rsgnp.h
|
||||
* libretroshare/src/gxs: rsnxs.h
|
||||
*
|
||||
* Network Exchange Service interface for RetroShare.
|
||||
*
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#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
|
||||
*
|
||||
|
|
|
@ -40,6 +40,34 @@
|
|||
#define GXS_REQUEST_TYPE_MSG_META 0x00100000
|
||||
#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.
|
||||
* I expect much of this will be incorporated into the base GXS.
|
||||
|
@ -51,6 +79,8 @@ RsTokReqOptions()
|
|||
{
|
||||
mOptions = 0;
|
||||
mStatusFilter = 0; mStatusMask = 0; mSubscribeFilter = 0;
|
||||
mSubscribeMask = 0;
|
||||
mMsgFlagMask = 0; mMsgFlagFilter = 0;
|
||||
mBefore = 0; mAfter = 0; mReqType = 0;
|
||||
}
|
||||
|
||||
|
@ -61,36 +91,41 @@ uint32_t mOptions;
|
|||
uint32_t mStatusFilter;
|
||||
uint32_t mStatusMask;
|
||||
|
||||
// use
|
||||
uint32_t mMsgFlagMask, mMsgFlagFilter;
|
||||
|
||||
uint32_t mReqType;
|
||||
|
||||
uint32_t mSubscribeFilter; // Only for Groups.
|
||||
uint32_t mSubscribeFilter, mSubscribeMask; // Only for Groups.
|
||||
|
||||
// Time range... again applied after Options.
|
||||
time_t mBefore;
|
||||
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
|
||||
* This seperates the request mechanism from the actual retrieval of data
|
||||
*/
|
||||
class RsTokenServiceV2
|
||||
class RsTokenService
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static const uint8_t GXS_REQUEST_STATUS_FAILED;
|
||||
static const uint8_t GXS_REQUEST_STATUS_PENDING;
|
||||
static const uint8_t GXS_REQUEST_STATUS_PARTIAL;
|
||||
static const uint8_t GXS_REQUEST_STATUS_FINISHED_INCOMPLETE;
|
||||
static const uint8_t GXS_REQUEST_STATUS_COMPLETE;
|
||||
static const uint8_t GXS_REQUEST_STATUS_DONE; // ONCE ALL DATA RETRIEVED.
|
||||
static const uint8_t GXS_REQUEST_V2_STATUS_FAILED;
|
||||
static const uint8_t GXS_REQUEST_V2_STATUS_PENDING;
|
||||
static const uint8_t GXS_REQUEST_V2_STATUS_PARTIAL;
|
||||
static const uint8_t GXS_REQUEST_V2_STATUS_FINISHED_INCOMPLETE;
|
||||
static const uint8_t GXS_REQUEST_V2_STATUS_COMPLETE;
|
||||
static const uint8_t GXS_REQUEST_V2_STATUS_DONE; // ONCE ALL DATA RETRIEVED.
|
||||
|
||||
public:
|
||||
|
||||
RsTokenServiceV2() { return; }
|
||||
virtual ~RsTokenServiceV2() { return; }
|
||||
RsTokenService() { return; }
|
||||
virtual ~RsTokenService() { return; }
|
||||
|
||||
/* Data Requests */
|
||||
|
||||
|
@ -99,57 +134,50 @@ public:
|
|||
* @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
|
||||
* @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
|
||||
*/
|
||||
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
|
||||
* @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, 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;
|
||||
|
||||
|
||||
/*!
|
||||
* 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
|
||||
* @param msgId the message id to set status for
|
||||
* @param status status
|
||||
* @param statusMask the mask for the settings targetted
|
||||
* @return true if request made successfully, false otherwise
|
||||
* For requesting msgs related to a given msg id within a group
|
||||
* @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, 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,
|
||||
const uint32_t status, const uint32_t statusMask) = 0;
|
||||
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::vector<RsGxsGrpMsgIdPair>& msgIds) = 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).
|
||||
//virtual bool groupRestoreKeys(const std::string &groupId) = 0;
|
||||
//virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers) = 0;
|
||||
|
||||
/* Poll */
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
TEMPLATE = lib
|
||||
#CONFIG += staticlib release
|
||||
#CONFIG += staticlib testnetwork
|
||||
CONFIG += staticlib bitdht
|
||||
CONFIG -= qt
|
||||
TARGET = retroshare
|
||||
|
@ -8,8 +6,8 @@ TARGET = retroshare
|
|||
CONFIG += test_voip
|
||||
|
||||
# GXS Stuff.
|
||||
#CONFIG += newcache
|
||||
#CONFIG += newservices
|
||||
# This should be disabled for releases until further notice.
|
||||
#CONFIG += gxs
|
||||
|
||||
# Beware: All data of the stripped services are lost
|
||||
DEFINES *= PQI_DISABLE_TUNNEL
|
||||
|
@ -20,39 +18,10 @@ profiling {
|
|||
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
|
||||
#QMAKE_CFLAGS += -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
|
||||
debug {
|
||||
# DEFINES *= DEBUG
|
||||
|
@ -68,6 +37,7 @@ debug {
|
|||
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
|
||||
}
|
||||
|
||||
|
||||
bitdht {
|
||||
|
||||
HEADERS += dht/p3bitdht.h \
|
||||
|
@ -97,45 +67,16 @@ SOURCES += tcponudp/udppeer.cc \
|
|||
tcponudp/udpstunner.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
|
||||
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
|
||||
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 \
|
||||
retroshare/rschannels.h \
|
||||
|
@ -204,22 +145,23 @@ linux-* {
|
|||
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
|
||||
target.path = $$LIB_DIR
|
||||
INSTALLS *= target
|
||||
|
||||
# where to put the library's interface
|
||||
# where to put the librarys interface
|
||||
include_rsiface.path = $${INC_DIR}
|
||||
include_rsiface.files = $$PUBLIC_HEADERS
|
||||
INSTALLS += include_rsiface
|
||||
|
||||
#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) {
|
||||
# Normal libupnp
|
||||
} else {
|
||||
|
@ -258,9 +200,7 @@ win32-x-g++ {
|
|||
QMAKE_AR = i586-mingw32msvc-ar
|
||||
DEFINES *= STATICLIB WIN32
|
||||
|
||||
#miniupnp implementation files
|
||||
HEADERS += upnp/upnputil.h
|
||||
SOURCES += upnp/upnputil.c
|
||||
CONFIG += upnp_miniupnpc
|
||||
|
||||
SSL_DIR=../../../../openssl
|
||||
UPNPC_DIR = ../../../../miniupnpc-1.3
|
||||
|
@ -296,9 +236,7 @@ win32 {
|
|||
|
||||
DEFINES += USE_CMD_ARGS
|
||||
|
||||
#miniupnp implementation files
|
||||
HEADERS += upnp/upnputil.h
|
||||
SOURCES += upnp/upnputil.c
|
||||
CONFIG += upnp_miniupnpc
|
||||
|
||||
UPNPC_DIR = ../../../miniupnpc-1.3
|
||||
|
||||
|
@ -308,6 +246,13 @@ win32 {
|
|||
OPENPGPSDK_DIR = ../../openpgpsdk/src
|
||||
|
||||
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
|
||||
DESTDIR = lib
|
||||
|
||||
#miniupnp implementation files
|
||||
HEADERS += upnp/upnputil.h
|
||||
SOURCES += upnp/upnputil.c
|
||||
CONFIG += upnp_miniupnpc
|
||||
|
||||
# zeroconf disabled at the end of libretroshare.pro (but need the code)
|
||||
CONFIG += zeroconf
|
||||
|
@ -353,9 +296,10 @@ freebsd-* {
|
|||
|
||||
QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dstat64=stat -Dstatvfs64=statvfs -Dfopen64=fopen
|
||||
|
||||
#libupnp implementation files
|
||||
HEADERS += upnp/UPnPBase.h
|
||||
SOURCES += upnp/UPnPBase.cpp
|
||||
# linux/bsd can use either - libupnp is more complete and packaged.
|
||||
#CONFIG += upnp_miniupnpc
|
||||
CONFIG += upnp_libupnp
|
||||
|
||||
DESTDIR = lib
|
||||
}
|
||||
|
||||
|
@ -482,7 +426,6 @@ HEADERS += turtle/p3turtle.h \
|
|||
turtle/rsturtleitem.h \
|
||||
turtle/turtletypes.h
|
||||
|
||||
HEADERS += upnp/upnphandler.h
|
||||
|
||||
HEADERS += util/folderiterator.h \
|
||||
util/rsdebug.h \
|
||||
|
@ -500,6 +443,8 @@ HEADERS += util/folderiterator.h \
|
|||
util/rsrandom.h \
|
||||
util/radix64.h \
|
||||
util/pugiconfig.h \
|
||||
util/rsmemcache.h \
|
||||
util/rstickevent.h \
|
||||
|
||||
SOURCES += dbase/cachestrapper.cc \
|
||||
dbase/fimonitor.cc \
|
||||
|
@ -624,7 +569,6 @@ SOURCES += turtle/p3turtle.cc \
|
|||
# turtle/turtlesearch.cc \
|
||||
# turtle/turtletunnels.cc
|
||||
|
||||
SOURCES += upnp/upnphandler.cc
|
||||
|
||||
SOURCES += util/folderiterator.cc \
|
||||
util/rsdebug.cc \
|
||||
|
@ -640,6 +584,21 @@ SOURCES += util/folderiterator.cc \
|
|||
util/rsversion.cc \
|
||||
util/rswin.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 {
|
||||
|
||||
|
@ -666,10 +625,12 @@ SOURCES += zeroconf/p3zcnatassist.cc \
|
|||
|
||||
}
|
||||
|
||||
# new gxs cache system
|
||||
newcache {
|
||||
# new gxs cache system
|
||||
# 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/rsgxs.h \
|
||||
gxs/rsdataservice.h \
|
||||
|
@ -682,51 +643,133 @@ HEADERS += serialiser/rsnxsitems.h \
|
|||
gxs/rsgxsdataaccess.h \
|
||||
retroshare/rsgxsservice.h \
|
||||
serialiser/rsgxsitems.h \
|
||||
util/retrodb.h
|
||||
util/retrodb.h \
|
||||
util/contentvalue.h \
|
||||
gxs/gxscoreserver.h \
|
||||
gxs/gxssecurity.h \
|
||||
gxs/rsgxsifaceimpl.h \
|
||||
gxs/gxstokenqueue.h \
|
||||
|
||||
SOURCES += serialiser/rsnxsitems.cc \
|
||||
|
||||
SOURCES += serialiser/rsnxsitems.cc \
|
||||
gxs/rsdataservice.cc \
|
||||
gxs/rsgenexchange.cc \
|
||||
gxs/rsgxsnetservice.cc \
|
||||
gxs/rsgxsdata.cc \
|
||||
services/p3photoserviceV2.cc \
|
||||
serialiser/rsgxsitems.cc \
|
||||
gxs/rsgxsdataaccess.cc \
|
||||
util/retrodb.cc
|
||||
}
|
||||
util/retrodb.cc \
|
||||
util/contentvalue.cc \
|
||||
gxs/gxscoreserver.cc \
|
||||
gxs/gxssecurity.cc \
|
||||
gxs/rsgxsifaceimpl.cc \
|
||||
gxs/gxstokenqueue.cc \
|
||||
|
||||
|
||||
|
||||
newservices {
|
||||
|
||||
HEADERS += services/p3photoservice.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 \
|
||||
# Identity Service
|
||||
HEADERS += retroshare/rsidentity.h \
|
||||
gxs/rsgixs.h \
|
||||
services/p3idservice.h \
|
||||
retroshare/rsforumsv2.h \
|
||||
services/p3forumsv2.h \
|
||||
serialiser/rsgxsiditems.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 \
|
||||
services/p3posted.h \
|
||||
services/p3photoserviceV2.h \
|
||||
retroshare/rsphotoV2.h \
|
||||
serialiser/rsposteditems.h
|
||||
|
||||
SOURCES += services/p3posted.cc \
|
||||
serialiser/rsposteditems.cc
|
||||
|
||||
SOURCES += services/p3photoservice.cc \
|
||||
#Photo Service
|
||||
HEADERS += services/p3photoservice.h \
|
||||
retroshare/rsphoto.h \
|
||||
serialiser/rsphotoitems.h \
|
||||
|
||||
SOURCES += services/p3photoservice.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
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#ifdef WINDOWS_SYS
|
||||
#include "util/rsstring.h"
|
||||
#include "util/rswin.h"
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
|
|
@ -168,6 +168,21 @@ void RsPluginManager::loadPlugins(const std::vector<std::string>& plugin_directo
|
|||
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
|
||||
{
|
||||
if((uint32_t)i >= _plugins.size())
|
||||
|
|
|
@ -93,6 +93,8 @@ class RsPluginManager: public RsPluginHandler, public p3Config
|
|||
//
|
||||
void loadPlugins(const std::vector<RsPlugin*>& explicit_plugin_entries) ;
|
||||
|
||||
void stopPlugins();
|
||||
|
||||
void registerCacheServices() ;
|
||||
void registerClientServices(p3ServiceServer *pqih) ;
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#ifndef RS_GPG_AUTH_HEADER
|
||||
#define RS_GPG_AUTH_HEADER
|
||||
|
||||
#include "util/rswin.h"
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
#include "util/rsthreads.h"
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
#include "util/rswin.h"
|
||||
#endif // WINDOWS_SYS
|
||||
|
||||
#include "authssl.h"
|
||||
#include "sslfns.h"
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "util/rswin.h"
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
public:
|
||||
|
@ -78,6 +92,12 @@ virtual void setExternalPort(unsigned short eport_in) = 0;
|
|||
virtual bool getInternalAddress(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 ¶ms) = 0;
|
||||
virtual bool statusPortForward(const uint32_t fwdId, PortForwardParams ¶ms) = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -23,10 +23,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef PQI_HASH_
|
||||
#define PQI_HASH_
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include "util/rsstring.h"
|
||||
#include <inttypes.h>
|
||||
|
||||
class pqihash
|
||||
{
|
||||
|
@ -85,4 +89,4 @@ void Complete(std::string &hash)
|
|||
SHA_CTX *sha_ctx;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,8 +23,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
#include "util/rswin.h"
|
||||
#include <ws2tcpip.h>
|
||||
#endif // WINDOWS_SYS
|
||||
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "util/rsnet.h"
|
||||
|
|
|
@ -45,12 +45,10 @@
|
|||
|
||||
#else
|
||||
|
||||
#include "util/rswin.h"
|
||||
|
||||
#include "util/rsnet.h" /* more generic networking header */
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
typedef int socklen_t;
|
||||
//typedef unsigned long in_addr_t;
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@
|
|||
#ifndef MRK_PQI_SSL_HEADER
|
||||
#define MRK_PQI_SSL_HEADER
|
||||
|
||||
#include "util/rswin.h"
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
// operating system specific network header.
|
||||
|
|
|
@ -28,8 +28,6 @@
|
|||
#ifndef MRK_PQI_SSL_UDP_HEADER
|
||||
#define MRK_PQI_SSL_UDP_HEADER
|
||||
|
||||
#include "util/rswin.h"
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
// operating system specific network header.
|
||||
|
|
|
@ -33,8 +33,6 @@
|
|||
|
||||
/******************** notify of new Cert **************************/
|
||||
|
||||
#include "util/rswin.h"
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/ssl.h>
|
||||
|
|
|
@ -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
|
127
libretroshare/src/retroshare/rsgxscircles.h
Normal file
127
libretroshare/src/retroshare/rsgxscircles.h
Normal 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
|
97
libretroshare/src/retroshare/rsgxsforums.h
Normal file
97
libretroshare/src/retroshare/rsgxsforums.h
Normal 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
|
|
@ -17,6 +17,7 @@ class RsGxsNotify
|
|||
{
|
||||
public:
|
||||
RsGxsNotify(){ return; }
|
||||
virtual ~RsGxsNotify() {return; }
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*
|
||||
* 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.
|
||||
* 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
|
||||
|
@ -30,332 +30,19 @@
|
|||
#include <string>
|
||||
#include <list>
|
||||
|
||||
// FLAGS WILL BE REUSED FROM RSDISTRIB -> FOR NOW.
|
||||
#include <retroshare/rsdistrib.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;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#include "gxs/rstokenservice.h"
|
||||
#include "gxs/rsgxsifaceimpl.h"
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class 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_RELATION_MASK 0x00ff
|
||||
|
||||
|
@ -370,9 +57,10 @@ extern RsIdentity *rsIdentity;
|
|||
|
||||
std::string rsIdTypeToString(uint32_t idtype);
|
||||
|
||||
class RsIdGroup
|
||||
class RsGxsIdGroup
|
||||
{
|
||||
public:
|
||||
RsGxsIdGroup():mPgpKnown(false) { return; }
|
||||
|
||||
|
||||
RsGroupMetaData mMeta;
|
||||
|
@ -380,22 +68,28 @@ class RsIdGroup
|
|||
// In GroupMetaData.
|
||||
//std::string mNickname; (mGroupName)
|
||||
//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....
|
||||
// Must use ServiceString.
|
||||
bool mGpgIdKnown; // if GpgIdHash has been identified.
|
||||
std::string mGpgId; // if known.
|
||||
std::string mGpgName; // if known.
|
||||
std::string mGpgEmail; // if known.
|
||||
// Actually PgpIdHash is SHA1(.mMeta.mGroupId + PGPHandler->GpgFingerprint(ownId))
|
||||
// ??? 160 bits.
|
||||
|
||||
std::string mPgpIdHash;
|
||||
std::string mPgpIdSign; // Need a signature as proof - otherwise anyone could add others Hashes.
|
||||
|
||||
// Not Serialised - for GUI's benefit.
|
||||
bool mPgpKnown;
|
||||
std::string mPgpId;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class RsIdMsg
|
||||
class RsGxsIdOpinion
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -405,7 +99,11 @@ class RsIdMsg
|
|||
//std::string mKeyId; (mGroupId)
|
||||
//std::string mPeerId; (mAuthorId) ???
|
||||
|
||||
int mOpinion;
|
||||
uint32_t mOpinion;
|
||||
|
||||
|
||||
// NOT SERIALISED YET!
|
||||
|
||||
double mReputation;
|
||||
//int mRating;
|
||||
//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);
|
||||
std::ostream &operator<<(std::ostream &out, const RsIdMsg &meta);
|
||||
RsMsgMetaData mMeta;
|
||||
std::string mComment;
|
||||
};
|
||||
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsGxsIdGroup &group);
|
||||
std::ostream &operator<<(std::ostream &out, const RsGxsIdOpinion &msg);
|
||||
|
||||
#if 0
|
||||
class RsIdReputation
|
||||
|
@ -448,80 +153,84 @@ class RsIdOpinion
|
|||
#endif
|
||||
|
||||
|
||||
class RsIdentity: public RsTokenService
|
||||
// DATA TYPE FOR EXTERNAL INTERFACE.
|
||||
|
||||
typedef std::string RsGxsId; // TMP. =>
|
||||
|
||||
class RsIdentityDetails
|
||||
{
|
||||
public:
|
||||
RsIdentityDetails()
|
||||
:mIsOwnId(false), mPgpLinked(false), mPgpKnown(false),
|
||||
mOpinion(0), mReputation(0) { return; }
|
||||
|
||||
RsIdentity() { return; }
|
||||
virtual ~RsIdentity() { return; }
|
||||
RsGxsId mId;
|
||||
|
||||
// identity details.
|
||||
std::string mNickname;
|
||||
bool mIsOwnId;
|
||||
|
||||
/* INCLUDES INTERFACE FROM RS TOKEN SERVICE */
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/* 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
|
||||
// PGP Stuff.
|
||||
bool mPgpLinked;
|
||||
bool mPgpKnown;
|
||||
std::string mPgpId;
|
||||
|
||||
// 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 ¶ms) = 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
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef RETROSHARE_PHOTO_GUI_INTERFACE_H
|
||||
#define RETROSHARE_PHOTO_GUI_INTERFACE_H
|
||||
#ifndef RSPHOTOV2_H
|
||||
#define RSPHOTOV2_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* 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
|
||||
|
@ -29,7 +29,7 @@
|
|||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include "rsgxsservice.h"
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsPhoto;
|
||||
|
@ -56,7 +56,6 @@ class RsPhotoThumbnail
|
|||
std::string type;
|
||||
};
|
||||
|
||||
|
||||
/* If these flags are no set - the Photo inherits values from the Album
|
||||
*/
|
||||
|
||||
|
@ -75,7 +74,6 @@ class RsPhotoThumbnail
|
|||
#define RSPHOTO_FLAGS_ATTRIB_AUTHOR 0x1000 // PUSH UP ORDER
|
||||
#define RSPHOTO_FLAGS_ATTRIB_PHOTO 0x2000 // PUSH UP ORDER.
|
||||
|
||||
|
||||
class RsPhotoPhoto
|
||||
{
|
||||
public:
|
||||
|
@ -155,25 +153,195 @@ class RsPhotoAlbum
|
|||
uint32_t mModFlags;
|
||||
};
|
||||
|
||||
class RsGxsPhotoCommentItem;
|
||||
class RsPhotoComment
|
||||
{
|
||||
public:
|
||||
RsPhotoComment();
|
||||
|
||||
RsPhotoComment(const RsGxsPhotoCommentItem& comment);
|
||||
|
||||
RsPhotoComment& operator=(const RsGxsPhotoCommentItem& comment);
|
||||
|
||||
RsMsgMetaData mMeta;
|
||||
|
||||
std::string mComment;
|
||||
uint32_t mCommentFlag;
|
||||
};
|
||||
|
||||
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<RsPhotoComment> > PhotoCommentResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsPhotoComment> > PhotoRelatedCommentResult;
|
||||
|
||||
class RsPhoto: public RsTokenService
|
||||
class RsPhoto
|
||||
{
|
||||
public:
|
||||
|
||||
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; }
|
||||
|
||||
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 */
|
||||
virtual bool getAlbum(const uint32_t &token, RsPhotoAlbum &album) = 0;
|
||||
virtual bool getPhoto(const uint32_t &token, RsPhotoPhoto &photo) = 0;
|
||||
|
||||
virtual bool submitAlbumDetails(uint32_t &token, RsPhotoAlbum &album, bool isNew) = 0;
|
||||
virtual bool submitPhoto(uint32_t &token, RsPhotoPhoto &photo, bool isNew) = 0;
|
||||
/*!
|
||||
* @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
|
||||
#endif // RSPHOTOV2_H
|
||||
|
|
|
@ -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
|
|
@ -105,6 +105,9 @@ class RsPlugin
|
|||
virtual RsPQIService *rs_pqi_service() const { return NULL ; }
|
||||
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
|
||||
// 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.
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#ifndef RETROSHARE_POSTED_GUI_INTERFACE_H
|
||||
#define RETROSHARE_POSTED_GUI_INTERFACE_H
|
||||
#ifndef RSPOSTED_H
|
||||
#define RSPOSTED_H
|
||||
|
||||
|
||||
/*
|
||||
* libretroshare/src/retroshare: rsposted.h
|
||||
*
|
||||
* 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
|
||||
|
@ -29,33 +30,25 @@
|
|||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include "gxs/rstokenservice.h"
|
||||
#include "gxs/rsgxsifaceimpl.h"
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsPosted;
|
||||
extern RsPosted *rsPosted;
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
|
||||
class RsPostedGroup
|
||||
{
|
||||
public:
|
||||
RsGroupMetaData mMeta;
|
||||
std::string mDescription;
|
||||
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_MSGTYPE_POST 0x0001
|
||||
//#define RSPOSTED_MSGTYPE_VOTE 0x0002
|
||||
//#define RSPOSTED_MSGTYPE_COMMENT 0x0004
|
||||
|
||||
#define RSPOSTED_PERIOD_YEAR 1
|
||||
#define RSPOSTED_PERIOD_MONTH 2
|
||||
|
@ -68,39 +61,17 @@ class RsPostedMsg
|
|||
#define RSPOSTED_VIEWMODE_HOT 3
|
||||
#define RSPOSTED_VIEWMODE_COMMENTS 4
|
||||
|
||||
class RsPostedPost;
|
||||
class RsPostedComment;
|
||||
class RsPostedVote;
|
||||
class RsPostedPostRanking;
|
||||
|
||||
class RsPostedPost: public RsPostedMsg
|
||||
{
|
||||
public:
|
||||
RsPostedPost(): RsPostedMsg(RSPOSTED_MSGTYPE_POST)
|
||||
{
|
||||
mMeta.mMsgFlags = RSPOSTED_MSGTYPE_POST;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsPostedPost> > PostedPostResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsPostedComment> > PostedCommentResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsPostedVote> > PostedVoteResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsPostedComment> > PostedRelatedCommentResult;
|
||||
typedef std::pair<RsGxsGroupId, int32_t> GroupRank;
|
||||
typedef std::map<uint32_t, RsGxsMessageId> PostedRanking;
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
|
||||
std::ostream &operator<<(std::ostream &out, const RsPostedPost &post);
|
||||
|
@ -108,33 +79,109 @@ std::ostream &operator<<(std::ostream &out, const RsPostedVote &vote);
|
|||
std::ostream &operator<<(std::ostream &out, const RsPostedComment &comment);
|
||||
|
||||
|
||||
class RsPosted: public RsTokenService
|
||||
|
||||
class RsPosted : public RsGxsIfaceImpl
|
||||
{
|
||||
public:
|
||||
|
||||
RsPosted() { return; }
|
||||
enum RankType {TopRankType, HotRankType, NewRankType };
|
||||
|
||||
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;
|
||||
|
||||
|
||||
RsPosted(RsGenExchange* gxs) : RsGxsIfaceImpl(gxs) { return; }
|
||||
virtual ~RsPosted() { 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;
|
||||
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;
|
||||
|
||||
virtual bool submitGroup(uint32_t &token, RsPostedGroup &group) = 0;
|
||||
virtual bool submitPost(uint32_t &token, RsPostedPost &post) = 0;
|
||||
virtual bool submitVote(uint32_t &token, RsPostedVote &vote) = 0;
|
||||
virtual bool submitComment(uint32_t &token, RsPostedComment &comment) = 0;
|
||||
|
||||
virtual bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t& downVotes, uint32_t& nComments) const = 0;
|
||||
|
||||
// Special Ranking Request.
|
||||
virtual bool requestRanking(uint32_t &token, std::string groupId) = 0;
|
||||
virtual bool getRankedPost(const uint32_t &token, RsPostedPost &post) = 0;
|
||||
/*!
|
||||
* Makes request for posts of a topic
|
||||
* @param token
|
||||
* @param rType
|
||||
* @param groupId
|
||||
*/
|
||||
virtual bool requestPostRankings(uint32_t &token, const RankType& rType, const RsGxsGroupId& groupId) = 0;
|
||||
|
||||
virtual bool extractPostedCache(const std::string &str, uint32_t &votes, uint32_t &comments) = 0;
|
||||
|
||||
// exposed for testing...
|
||||
virtual float calcPostScore(const RsMsgMetaData &meta) = 0;
|
||||
/*!
|
||||
* Makes request for ranking of comments for a post
|
||||
* @param token
|
||||
* @param rType type of ranking to collect
|
||||
* @param msgId message id of post as groupid-messageid pair
|
||||
*/
|
||||
virtual bool requestCommentRankings(uint32_t &token, const RankType& rType, const RsGxsGrpMsgIdPair& msgId) = 0;
|
||||
|
||||
};
|
||||
|
||||
class RsPostedPost
|
||||
{
|
||||
public:
|
||||
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
|
||||
|
|
151
libretroshare/src/retroshare/rspostedVEG.h
Normal file
151
libretroshare/src/retroshare/rspostedVEG.h
Normal 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
|
|
@ -30,77 +30,107 @@
|
|||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include "gxs/rstokenservice.h"
|
||||
#include "gxs/rsgxsifaceimpl.h"
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class 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:
|
||||
|
||||
uint32_t mShareType;
|
||||
std::string mShareGroupId;
|
||||
std::string mPublishKey;
|
||||
uint32_t mCommentMode;
|
||||
uint32_t mResizeMode;
|
||||
std::string KeyWord;
|
||||
std::string CollectionId;
|
||||
};
|
||||
|
||||
class RsWikiGroup
|
||||
|
||||
class RsWikiCollection
|
||||
{
|
||||
public:
|
||||
|
||||
RsGroupMetaData mMeta;
|
||||
|
||||
//std::string mGroupId;
|
||||
//std::string mName;
|
||||
|
||||
std::string mDescription;
|
||||
std::string mCategory;
|
||||
|
||||
std::string mHashTags;
|
||||
|
||||
RsWikiGroupShare mShareOptions;
|
||||
//std::map<std::string, CollectionRef> linkReferences;
|
||||
};
|
||||
|
||||
class RsWikiPage
|
||||
|
||||
class RsWikiSnapshot
|
||||
{
|
||||
public:
|
||||
|
||||
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 mHashTags;
|
||||
};
|
||||
|
||||
class RsWiki: public RsTokenService
|
||||
|
||||
class RsWikiComment
|
||||
{
|
||||
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; }
|
||||
|
||||
/* Specific Service Data */
|
||||
virtual bool getGroupData(const uint32_t &token, RsWikiGroup &group) = 0;
|
||||
virtual bool getMsgData(const uint32_t &token, RsWikiPage &page) = 0;
|
||||
virtual bool getCollections(const uint32_t &token, std::vector<RsWikiCollection> &collections) = 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 createPage(uint32_t &token, RsWikiPage &page, bool isNew) = 0;
|
||||
virtual bool getRelatedSnapshots(const uint32_t &token, std::vector<RsWikiSnapshot> &snapshots) = 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
|
||||
|
|
|
@ -30,74 +30,94 @@
|
|||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include "gxs/rstokenservice.h"
|
||||
#include "gxs/rsgxsifaceimpl.h"
|
||||
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsWire;
|
||||
extern RsWire *rsWire;
|
||||
|
||||
class RsWireGroupShare
|
||||
{
|
||||
public:
|
||||
|
||||
uint32_t mShareType;
|
||||
std::string mShareGroupId;
|
||||
std::string mPublishKey;
|
||||
uint32_t mCommentMode;
|
||||
uint32_t mResizeMode;
|
||||
};
|
||||
|
||||
class RsWireGroup
|
||||
{
|
||||
public:
|
||||
|
||||
RsGroupMetaData mMeta;
|
||||
|
||||
//std::string mGroupId;
|
||||
//std::string mName;
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
|
||||
RsMsgMetaData mMeta;
|
||||
|
||||
//std::string mGroupId;
|
||||
//std::string mOrigPageId;
|
||||
//std::string mPrevId;
|
||||
//std::string mPageId;
|
||||
//std::string mName;
|
||||
|
||||
std::string mPulse; // all the text is stored here.
|
||||
|
||||
std::string mPulseText; // all the text is stored here.
|
||||
std::string mHashTags;
|
||||
|
||||
// These will be added at some point.
|
||||
// std::string mInReplyPulse;
|
||||
|
||||
// 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:
|
||||
|
||||
RsWire() { return; }
|
||||
RsWire(RsGenExchange *gxs): RsGxsIfaceImpl(gxs) { return; }
|
||||
virtual ~RsWire() { return; }
|
||||
|
||||
/* Specific Service Data */
|
||||
virtual bool getGroupData(const uint32_t &token, RsWireGroup &group) = 0;
|
||||
virtual bool getMsgData(const uint32_t &token, RsWirePulse &pulse) = 0;
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups) = 0;
|
||||
virtual bool getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses) = 0;
|
||||
|
||||
/* Create Stuff */
|
||||
virtual bool createGroup(uint32_t &token, RsWireGroup &group, bool isNew) = 0;
|
||||
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew) = 0;
|
||||
virtual bool createGroup(uint32_t &token, RsWireGroup &group) = 0;
|
||||
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "pqi/authssl.h"
|
||||
#include "pqi/authgpg.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "plugins/pluginmanager.h"
|
||||
#include "util/rsdebug.h"
|
||||
const int p3facemsgzone = 11453;
|
||||
|
||||
|
@ -41,6 +42,19 @@ const int p3facemsgzone = 11453;
|
|||
#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 */
|
||||
/* Config */
|
||||
|
@ -134,10 +148,28 @@ void RsServer::rsGlobalShutDown()
|
|||
join();
|
||||
ftserver->StopThreads();
|
||||
|
||||
mPluginsManager->stopPlugins();
|
||||
|
||||
// stop the p3distrib threads
|
||||
|
||||
mForums->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
|
||||
mBlogs->join();
|
||||
#endif
|
||||
|
|
|
@ -62,6 +62,8 @@ RsServer::RsServer(RsIface &i, NotifyBase &callback)
|
|||
|
||||
pqih = NULL;
|
||||
|
||||
mPluginsManager = NULL;
|
||||
|
||||
/* services */
|
||||
ad = NULL;
|
||||
msgSrv = NULL;
|
||||
|
@ -74,6 +76,18 @@ RsServer::RsServer(RsIface &i, NotifyBase &callback)
|
|||
/* Config */
|
||||
mConfigMgr = 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()
|
||||
|
|
|
@ -45,10 +45,23 @@
|
|||
#include "services/p3channels.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 p3LinkMgrIMPL;
|
||||
class p3NetMgrIMPL;
|
||||
class p3HistoryMgr;
|
||||
class RsPluginManager;
|
||||
|
||||
/* The Main Interface Class - for controlling the server */
|
||||
|
||||
|
@ -159,6 +172,8 @@ class RsServer: public RsControl, public RsThread
|
|||
|
||||
pqipersongrp *pqih;
|
||||
|
||||
RsPluginManager *mPluginsManager;
|
||||
|
||||
//sslroot *sslr;
|
||||
|
||||
/* services */
|
||||
|
@ -170,6 +185,15 @@ class RsServer: public RsControl, public RsThread
|
|||
p3Forums *mForums;
|
||||
/* caches (that need ticking) */
|
||||
|
||||
/* GXS */
|
||||
p3Wiki *mWiki;
|
||||
p3Posted *mPosted;
|
||||
p3PhotoService *mPhoto;
|
||||
p3GxsCircles *mGxsCircles;
|
||||
p3IdService *mGxsIdService;
|
||||
p3GxsForums *mGxsForums;
|
||||
p3Wire *mWire;
|
||||
|
||||
/* Config */
|
||||
p3ConfigMgr *mConfigMgr;
|
||||
p3GeneralConfig *mGeneralConfig;
|
||||
|
|
|
@ -28,9 +28,11 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
// for locking instances
|
||||
#ifndef WINDOWS_SYS
|
||||
// for locking instances
|
||||
#include <errno.h>
|
||||
#else
|
||||
#include "util/rswin.h"
|
||||
#endif
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
|
@ -1804,7 +1806,11 @@ RsTurtle *rsTurtle = NULL ;
|
|||
#ifdef RS_ENABLE_ZCNATASSIST
|
||||
#include "zeroconf/p3zcnatassist.h"
|
||||
#else
|
||||
#include "upnp/upnphandler.h"
|
||||
#ifdef RS_USE_LIBUPNP
|
||||
#include "upnp/upnphandler_linux.h"
|
||||
#else
|
||||
#include "upnp/upnphandler_miniupnp.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "services/p3disc.h"
|
||||
|
@ -1817,14 +1823,22 @@ RsTurtle *rsTurtle = NULL ;
|
|||
#include "services/p3blogs.h"
|
||||
#include "turtle/p3turtle.h"
|
||||
|
||||
#ifdef ENABLE_GXS_SERVICES
|
||||
#include "services/p3photoservice.h"
|
||||
#include "services/p3wikiservice.h"
|
||||
#include "services/p3wire.h"
|
||||
#ifdef RS_ENABLE_GXS
|
||||
// NEW GXS SYSTEMS.
|
||||
#include "gxs/gxscoreserver.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "gxs/rsgxsnetservice.h"
|
||||
#include "gxs/rsgxsflags.h"
|
||||
|
||||
#include "services/p3idservice.h"
|
||||
#include "services/p3forumsv2.h"
|
||||
#include "services/p3gxscircles.h"
|
||||
#include "services/p3wiki.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
|
||||
#include "services/p3tunnel.h"
|
||||
|
@ -2187,7 +2201,7 @@ int RsServer::StartupRetroShare()
|
|||
// possible entries include: /usr/lib/retroshare, ~/.retroshare/extensions/, etc.
|
||||
#endif
|
||||
|
||||
RsPluginManager *mPluginsManager = new RsPluginManager(RsInitConfig::main_executable_hash) ;
|
||||
mPluginsManager = new RsPluginManager(RsInitConfig::main_executable_hash) ;
|
||||
rsPlugins = mPluginsManager ;
|
||||
mConfigMgr->addConfiguration("plugins.cfg", mPluginsManager);
|
||||
|
||||
|
@ -2266,31 +2280,184 @@ int RsServer::StartupRetroShare()
|
|||
mPluginsManager->registerClientServices(pqih) ;
|
||||
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.
|
||||
p3WikiService *mWikis = new p3WikiService(RS_SERVICE_TYPE_WIKI);
|
||||
pqih -> addService(mWikis);
|
||||
#ifdef RS_ENABLE_GXS
|
||||
|
||||
// Testing New Cache Services.
|
||||
p3Wire *mWire = new p3Wire(RS_SERVICE_TYPE_WIRE);
|
||||
pqih -> addService(mWire);
|
||||
// The idea is that if priorGxsDir is non
|
||||
// empty and matches an exist directory location
|
||||
// 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.
|
||||
p3IdService *mIdentity = new p3IdService(RS_SERVICE_TYPE_IDENTITY);
|
||||
pqih -> addService(mIdentity);
|
||||
if(!priorGxsDir.empty())
|
||||
cleanUpGxsDir = RsDirUtil::checkDirectory(priorGxsDir);
|
||||
|
||||
// Testing New Cache Services.
|
||||
p3ForumsV2 *mForumsV2 = new p3ForumsV2(RS_SERVICE_TYPE_FORUMSV2);
|
||||
pqih -> addService(mForumsV2);
|
||||
std::list<std::string> filesToKeep;
|
||||
bool cleanUpSuccess = RsDirUtil::cleanupDirectory(priorGxsDir, filesToKeep);
|
||||
|
||||
// Testing New Cache Services.
|
||||
p3PostedService *mPosted = new p3PostedService(RS_SERVICE_TYPE_POSTED);
|
||||
pqih -> addService(mPosted);
|
||||
#endif // ENABLE_GXS_SERVICES
|
||||
if(!cleanUpSuccess)
|
||||
std::cerr << "RsInit::StartupRetroShare() Clean up of Old Gxs Dir Failed!";
|
||||
else
|
||||
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
|
||||
|
@ -2548,15 +2715,17 @@ int RsServer::StartupRetroShare()
|
|||
rsForums = mForums;
|
||||
rsChannels = mChannels;
|
||||
|
||||
#ifdef ENABLE_GXS_SERVICES
|
||||
// Testing of new cache system interfaces.
|
||||
rsIdentity = mIdentity;
|
||||
rsPhoto = mPhotos;
|
||||
rsWiki = mWikis;
|
||||
rsWire = mWire;
|
||||
rsForumsV2 = mForumsV2;
|
||||
#ifdef RS_ENABLE_GXS
|
||||
|
||||
rsIdentity = mGxsIdService;
|
||||
rsGxsCircles = mGxsCircles;
|
||||
rsWiki = mWiki;
|
||||
rsPosted = mPosted;
|
||||
#endif // ENABLE_GXS_SERVICES
|
||||
rsPhoto = mPhoto;
|
||||
rsGxsForums = mGxsForums;
|
||||
rsWire = mWire;
|
||||
|
||||
#endif // RS_ENABLE_GXS
|
||||
|
||||
|
||||
#ifdef RS_USE_BLOGS
|
||||
|
@ -2571,7 +2740,6 @@ int RsServer::StartupRetroShare()
|
|||
rsGameLauncher = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
/* put a welcome message in! */
|
||||
if (RsInitConfig::firsttime_run)
|
||||
{
|
||||
|
|
|
@ -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_DATA = 2 ;
|
||||
|
||||
// GXS
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_GXS_NET = 3 ;
|
||||
|
|
422
libretroshare/src/serialiser/rsgxscircleitems.cc
Normal file
422
libretroshare/src/serialiser/rsgxscircleitems.cc
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
102
libretroshare/src/serialiser/rsgxscircleitems.h
Normal file
102
libretroshare/src/serialiser/rsgxscircleitems.h
Normal 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 */
|
402
libretroshare/src/serialiser/rsgxsforumitems.cc
Normal file
402
libretroshare/src/serialiser/rsgxsforumitems.cc
Normal 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;
|
||||
}
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
95
libretroshare/src/serialiser/rsgxsforumitems.h
Normal file
95
libretroshare/src/serialiser/rsgxsforumitems.h
Normal 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 */
|
576
libretroshare/src/serialiser/rsgxsiditems.cc
Normal file
576
libretroshare/src/serialiser/rsgxsiditems.cc
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
112
libretroshare/src/serialiser/rsgxsiditems.h
Normal file
112
libretroshare/src/serialiser/rsgxsiditems.h
Normal 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 */
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "rsgxsitems.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
#include <iostream>
|
||||
|
||||
void RsMsgMetaData::operator =(const RsGxsMsgMetaData& rGxsMeta)
|
||||
{
|
||||
|
@ -22,6 +23,8 @@
|
|||
this->mParentId = rGxsMeta.mParentId;
|
||||
this->mPublishTs = rGxsMeta.mPublishTs;
|
||||
this->mThreadId = rGxsMeta.mThreadId;
|
||||
this->mServiceString = rGxsMeta.mServiceString;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,4 +40,31 @@
|
|||
this->mPublishTs = rGxsMeta.mPublishTs;
|
||||
this->mSubscribeFlags = rGxsMeta.mSubscribeFlags;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,16 +28,16 @@
|
|||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
class RsGxsGrpMetaData;
|
||||
class RsGxsMsgMetaData;
|
||||
|
||||
|
||||
class RsGroupMetaData
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
RsGroupMetaData()
|
||||
{
|
||||
|
@ -47,7 +47,9 @@ class RsGroupMetaData
|
|||
mPop = 0;
|
||||
mMsgCount = 0;
|
||||
mLastPost = 0;
|
||||
|
||||
mGroupStatus = 0;
|
||||
mCircleType = 0;
|
||||
|
||||
//mPublishTs = 0;
|
||||
}
|
||||
|
@ -57,10 +59,15 @@ class RsGroupMetaData
|
|||
std::string mGroupId;
|
||||
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;
|
||||
|
@ -70,6 +77,13 @@ class RsGroupMetaData
|
|||
time_t mLastPost; // ???
|
||||
|
||||
uint32_t mGroupStatus;
|
||||
std::string mServiceString; // Service Specific Free-Form extra storage.
|
||||
std::string mOriginator;
|
||||
std::string mInternalCircle;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -78,12 +92,14 @@ class RsGroupMetaData
|
|||
|
||||
class RsMsgMetaData
|
||||
{
|
||||
public:
|
||||
|
||||
public:
|
||||
|
||||
RsMsgMetaData()
|
||||
{
|
||||
mPublishTs = 0;
|
||||
mMsgFlags = 0;
|
||||
|
||||
mMsgStatus = 0;
|
||||
mChildTs = 0;
|
||||
}
|
||||
|
@ -103,15 +119,23 @@ class RsMsgMetaData
|
|||
std::string mMsgName;
|
||||
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.
|
||||
// normally READ / UNREAD flags. LOCAL Data.
|
||||
|
||||
/// 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
|
||||
{
|
||||
|
@ -122,6 +146,7 @@ public:
|
|||
: RsItem(RS_PKT_VERSION_SERVICE, service, subtype) { return; }
|
||||
virtual ~RsGxsGrpItem(){}
|
||||
|
||||
|
||||
RsGroupMetaData meta;
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
|
||||
|
@ -69,7 +68,11 @@ class RsNxsItem : public RsItem
|
|||
|
||||
public:
|
||||
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 std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
|
||||
|
@ -196,7 +199,7 @@ public:
|
|||
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
|
||||
*/
|
||||
RsTlvBinaryData meta;
|
||||
|
@ -259,7 +262,9 @@ class RsNxsMsg : public RsNxsItem
|
|||
{
|
||||
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 std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
@ -294,7 +299,7 @@ public:
|
|||
virtual ~RsNxsSearchReq() { 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
|
||||
uint32_t token; // search token
|
||||
|
@ -332,7 +337,7 @@ public:
|
|||
|
||||
RsNxsSearchResultMsg() : context(0) { return;}
|
||||
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
|
||||
RsTlvBinaryData context; // used by client service
|
||||
|
@ -353,7 +358,7 @@ public:
|
|||
|
||||
RsNxsSearchResultGrp();
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
|
@ -24,195 +23,213 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsphotoitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#define RSSERIAL_DEBUG 1
|
||||
#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();
|
||||
photoId.clear();
|
||||
size = 0;
|
||||
RsGxsPhotoPhotoItem* ppItem = NULL;
|
||||
RsGxsPhotoAlbumItem* paItem = NULL;
|
||||
RsGxsPhotoCommentItem* cItem = NULL;
|
||||
|
||||
name.clear();
|
||||
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++)
|
||||
if((ppItem = dynamic_cast<RsGxsPhotoPhotoItem*>(item)) != NULL)
|
||||
{
|
||||
printIndent(out, int_Indent2);
|
||||
out << "PhotoId: " << it->photoId << std::endl;
|
||||
printIndent(out, int_Indent2 + 2);
|
||||
std::string cnv_comment2(it->altComment.begin(), it->altComment.end());
|
||||
out << "AltComment: " << cnv_comment2 << std::endl;
|
||||
printIndent(out, int_Indent2 + 2);
|
||||
out << "Delta T: " << it->deltaT << std::endl;
|
||||
return sizeGxsPhotoPhotoItem(ppItem);
|
||||
}
|
||||
else if((paItem = dynamic_cast<RsGxsPhotoAlbumItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPhotoAlbumItem(paItem);
|
||||
}
|
||||
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()
|
||||
:deltaT(0)
|
||||
bool RsGxsPhotoSerialiser::serialise(RsItem* item, void* data, uint32_t* size)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
/* TODO serialiser */
|
||||
|
||||
#if 0
|
||||
|
||||
uint32_t RsPhotoSerialiser::sizeLink(RsPhotoLinkMsg *item)
|
||||
RsItem* RsGxsPhotoSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvStringSize(item->rid);
|
||||
s += 4; /* timestamp */
|
||||
s += GetTlvWideStringSize(item->title);
|
||||
s += GetTlvWideStringSize(item->comment);
|
||||
s += 4; /* linktype */
|
||||
s += GetTlvWideStringSize(item->link);
|
||||
|
||||
#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_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;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsPhotoSerialiser::serialiseLink(RsPhotoLinkMsg *item, void *data, uint32_t *pktsize)
|
||||
uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem *item)
|
||||
{
|
||||
uint32_t tlvsize = sizeLink(item);
|
||||
|
||||
const RsPhotoComment& comment = item->comment;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(comment.mComment);
|
||||
s += 4; // mflags
|
||||
|
||||
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 (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*pktsize = tlvsize;
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
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;
|
||||
/* GxsPhotoAlbumItem */
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->timestamp);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() timestamp: " << ok << std::endl;
|
||||
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);
|
||||
|
||||
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)
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsPhotoLinkMsg *RsPhotoSerialiser::deserialiseLink(void *data, uint32_t *pktsize)
|
||||
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);
|
||||
|
@ -221,37 +238,55 @@ RsPhotoLinkMsg *RsPhotoSerialiser::deserialiseLink(void *data, uint32_t *pktsize
|
|||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_RANK != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_RANK_LINK != getRsItemSubType(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 (*pktsize < rssize) /* check size */
|
||||
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 */
|
||||
*pktsize = rssize;
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsPhotoLinkMsg *item = new RsPhotoLinkMsg();
|
||||
item->clear();
|
||||
|
||||
RsGxsPhotoAlbumItem* item = new RsGxsPhotoAlbumItem();
|
||||
/* 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);
|
||||
|
||||
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;
|
||||
|
@ -259,6 +294,173 @@ RsPhotoLinkMsg *RsPhotoSerialiser::deserialiseLink(void *data, uint32_t *pktsize
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -267,24 +469,185 @@ RsPhotoLinkMsg *RsPhotoSerialiser::deserialiseLink(void *data, uint32_t *pktsize
|
|||
}
|
||||
|
||||
|
||||
uint32_t RsPhotoSerialiser::size(RsItem *item)
|
||||
|
||||
bool RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
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::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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
|
@ -26,113 +23,91 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef RSPHOTOV2ITEMS_H_
|
||||
#define RSPHOTOV2ITEMS_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.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_SHOW_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM = 0x04;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsPhotoItem;
|
||||
class RsPhotoShowItem;
|
||||
class RsPhotoCommentItem;
|
||||
|
||||
class RsPhotoItem: public RsItem
|
||||
class RsGxsPhotoAlbumItem : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsPhotoItem()
|
||||
: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);
|
||||
public:
|
||||
|
||||
std::string srcId;
|
||||
std::string photoId; /* same as hash */
|
||||
uint64_t size; /* file size */
|
||||
RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_ITEM) { return;}
|
||||
virtual ~RsGxsPhotoAlbumItem() { return;}
|
||||
|
||||
std::string name;
|
||||
std::wstring comment;
|
||||
void clear();
|
||||
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 */
|
||||
bool isAvailable;
|
||||
std::string path;
|
||||
RsPhotoAlbum album;
|
||||
};
|
||||
|
||||
/* THIS must be turned into a TLV type + set (TOD) */
|
||||
class RsPhotoRefItem
|
||||
class RsGxsPhotoPhotoItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsPhotoRefItem();
|
||||
public:
|
||||
|
||||
std::string photoId;
|
||||
std::wstring altComment;
|
||||
uint32_t deltaT; /* in 100ths of sec? */
|
||||
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {return; }
|
||||
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:
|
||||
RsPhotoShowItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) { return; }
|
||||
public:
|
||||
|
||||
virtual ~RsPhotoShowItem() { return; }
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) { return; }
|
||||
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:
|
||||
RsPhotoSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO)
|
||||
{ return; }
|
||||
virtual ~RsPhotoSerialiser()
|
||||
public:
|
||||
|
||||
RsGxsPhotoSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_PHOTO)
|
||||
{ return; }
|
||||
virtual ~RsGxsPhotoSerialiser() { return; }
|
||||
|
||||
virtual uint32_t size(RsItem *) { return 0; }
|
||||
virtual bool serialise (RsItem */*item*/, void */*data*/, uint32_t */*size*/) { return false; }
|
||||
virtual RsItem * deserialise(void */*data*/, uint32_t */*size*/) { return NULL; }
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
/* For RS_PKT_SUBTYPE_PHOTO_ITEM */
|
||||
//virtual uint32_t sizeLink(RsPhotoItem *);
|
||||
//virtual bool serialiseLink (RsPhotoItem *item, void *data, uint32_t *size);
|
||||
//virtual RsPhotoItem *deserialiseLink(void *data, uint32_t *size);
|
||||
uint32_t sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem *item);
|
||||
bool serialiseGxsPhotoAlbumItem (RsGxsPhotoAlbumItem *item, void *data, uint32_t *size);
|
||||
RsGxsPhotoAlbumItem * deserialiseGxsPhotoAlbumItem(void *data, uint32_t *size);
|
||||
|
||||
/* For RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM */
|
||||
//virtual uint32_t sizeLink(RsPhotoShowItem *);
|
||||
//virtual bool serialiseLink (RsPhotoShowItem *item, void *data, uint32_t *size);
|
||||
//virtual RsPhotoShowItem *deserialiseLink(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);
|
||||
|
||||
/* For RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM */
|
||||
//virtual uint32_t sizeLink(RsPhotoCommentItem *);
|
||||
//virtual bool serialiseLink (RsPhotoCommentItem *item, void *data, uint32_t *size);
|
||||
//virtual RsPhotoCommentItem *deserialiseLink(void *data, uint32_t *size);
|
||||
uint32_t sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem *item);
|
||||
bool serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size);
|
||||
RsGxsPhotoCommentItem * deserialiseGxsPhotoCommentItem(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_PHOTO_ITEMS_H */
|
||||
|
||||
#endif /* RSPHOTOV2ITEMS_H_ */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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_ */
|
656
libretroshare/src/serialiser/rsposteditems.cc
Normal file
656
libretroshare/src/serialiser/rsposteditems.cc
Normal 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;
|
||||
|
||||
}
|
103
libretroshare/src/serialiser/rsposteditems.h
Normal file
103
libretroshare/src/serialiser/rsposteditems.h
Normal 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
|
|
@ -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_QCHESS_ID = 0x0402;
|
||||
const uint16_t RS_SERVICE_TYPE_PLUGIN_FEEDREADER = 0x0403;
|
||||
|
||||
|
||||
/****************** 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;
|
||||
|
||||
|
||||
/* 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_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_POKER = 0xf214;
|
||||
|
||||
/* New Cache Services */
|
||||
/* Rs Network Exchange Service */
|
||||
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 ******************/
|
||||
|
||||
|
|
|
@ -207,6 +207,8 @@ const uint16_t TLV_TYPE_SECURITYKEY = 0x1040;
|
|||
const uint16_t TLV_TYPE_SECURITYKEYSET= 0x1041;
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
//#define TLV_DEBUG 1
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
/************************************* RsTlvSecurityKey ************************************/
|
||||
|
||||
|
@ -322,7 +322,7 @@ bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset) /
|
|||
if (ok)
|
||||
{
|
||||
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;
|
||||
|
@ -520,3 +520,170 @@ std::ostream &RsTlvKeySignature::print(std::ostream &out, uint16_t indent)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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_PRIVATE = 0x0020;
|
||||
const uint32_t RSTLV_KEY_DISTRIB_ADMIN = 0x0040;
|
||||
const uint32_t RSTLV_KEY_DISTRIB_IDENTITY = 0x0080;
|
||||
|
||||
|
||||
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.
|
||||
};
|
||||
|
||||
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
|
||||
|
|
580
libretroshare/src/serialiser/rswikiitems.cc
Normal file
580
libretroshare/src/serialiser/rswikiitems.cc
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
112
libretroshare/src/serialiser/rswikiitems.h
Normal file
112
libretroshare/src/serialiser/rswikiitems.h
Normal 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 */
|
408
libretroshare/src/serialiser/rswireitems.cc
Normal file
408
libretroshare/src/serialiser/rswireitems.cc
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
93
libretroshare/src/serialiser/rswireitems.h
Normal file
93
libretroshare/src/serialiser/rswireitems.h
Normal 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 */
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
1376
libretroshare/src/services/p3gxscircles.cc
Normal file
1376
libretroshare/src/services/p3gxscircles.cc
Normal file
File diff suppressed because it is too large
Load diff
246
libretroshare/src/services/p3gxscircles.h
Normal file
246
libretroshare/src/services/p3gxscircles.h
Normal 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
|
471
libretroshare/src/services/p3gxsforums.cc
Normal file
471
libretroshare/src/services/p3gxsforums.cc
Normal 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;
|
||||
}
|
||||
}
|
||||
|
111
libretroshare/src/services/p3gxsforums.h
Normal file
111
libretroshare/src/services/p3gxsforums.h
Normal 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
|
|
@ -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")
|
||||
{
|
||||
mNextToken = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
bool p3GxsService::generateToken(uint32_t &token)
|
||||
bool p3GxsServiceVEG::generateToken(uint32_t &token)
|
||||
{
|
||||
RsStackMutex stack(mReqMtx); /****** LOCKED *****/
|
||||
|
||||
|
@ -41,7 +41,7 @@ bool p3GxsService::generateToken(uint32_t &token)
|
|||
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 *****/
|
||||
|
||||
|
@ -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 *****/
|
||||
|
||||
|
@ -77,7 +77,7 @@ bool p3GxsService::clearRequest(const uint32_t &token)
|
|||
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 *****/
|
||||
|
||||
|
@ -94,7 +94,7 @@ bool p3GxsService::updateRequestStatus(const uint32_t &token, const uint32_t &st
|
|||
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 *****/
|
||||
|
||||
|
@ -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 *****/
|
||||
|
||||
|
@ -138,7 +138,7 @@ bool p3GxsService::updateRequestOutList(const uint32_t &token, std::list<std::st
|
|||
}
|
||||
|
||||
#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 *****/
|
||||
|
||||
|
@ -160,7 +160,7 @@ bool p3GxsService::updateRequestData(const uint32_t &token, std::map<std::string
|
|||
}
|
||||
#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 *****/
|
||||
|
||||
|
@ -182,7 +182,7 @@ bool p3GxsService::checkRequestStatus(const uint32_t &token, uint32_t &status
|
|||
|
||||
|
||||
// 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 *****/
|
||||
|
||||
|
@ -196,7 +196,7 @@ bool p3GxsService::tokenList(std::list<uint32_t> &tokens)
|
|||
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 *****/
|
||||
|
||||
|
@ -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 *****/
|
||||
|
||||
|
@ -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 *****/
|
||||
|
||||
|
@ -270,7 +270,7 @@ bool p3GxsService::loadRequestOutList(const uint32_t &token, std::list<std::s
|
|||
|
||||
#define MAX_REQUEST_AGE 10
|
||||
|
||||
bool p3GxsService::fakeprocessrequests()
|
||||
bool p3GxsServiceVEG::fakeprocessrequests()
|
||||
{
|
||||
std::list<uint32_t>::iterator it;
|
||||
std::list<uint32_t> tokens;
|
||||
|
@ -287,7 +287,7 @@ bool p3GxsService::fakeprocessrequests()
|
|||
time_t 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)
|
||||
{
|
||||
|
@ -299,13 +299,13 @@ bool p3GxsService::fakeprocessrequests()
|
|||
}
|
||||
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;
|
||||
clearRequest(token);
|
||||
}
|
||||
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;
|
||||
clearRequest(token);
|
||||
}
|
||||
|
@ -334,14 +334,14 @@ bool p3GxsService::fakeprocessrequests()
|
|||
*
|
||||
****/
|
||||
|
||||
GxsDataProxy::GxsDataProxy()
|
||||
GxsDataProxyVEG::GxsDataProxyVEG()
|
||||
:mDataMtx("GxsDataProxyMtx")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static bool checkGroupFilter(const RsTokReqOptions &opts, const RsGroupMetaData &group)
|
||||
static bool checkGroupFilter(const RsTokReqOptionsVEG &opts, const RsGroupMetaData &group)
|
||||
{
|
||||
bool statusMatch = false;
|
||||
if (opts.mStatusMask)
|
||||
|
@ -370,6 +370,33 @@ static bool checkGroupFilter(const RsTokReqOptions &opts, const RsGroupMetaData
|
|||
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;
|
||||
if (opts.mSubscribeFilter)
|
||||
{
|
||||
|
@ -397,11 +424,11 @@ static bool checkGroupFilter(const RsTokReqOptions &opts, const RsGroupMetaData
|
|||
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;
|
||||
if (opts.mStatusMask)
|
||||
|
@ -429,11 +456,39 @@ static bool checkMsgFilter(const RsTokReqOptions &opts, const RsMsgMetaData &msg
|
|||
// no status comparision,
|
||||
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;
|
||||
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;
|
||||
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 ...
|
||||
* 1) if groupIds is Empty... return all groupIds.
|
||||
* 2) else copy list.
|
||||
*
|
||||
*/
|
||||
std::cerr << "GxsDataProxy::getGroupList()";
|
||||
std::cerr << "GxsDataProxyVEG::getGroupList()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
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.
|
||||
* Input is groupList + Flags.
|
||||
* 1) No Flags => All Messages in those Groups.
|
||||
*
|
||||
*/
|
||||
std::cerr << "GxsDataProxy::getMsgList()";
|
||||
std::cerr << "GxsDataProxyVEG::getMsgList()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
||||
|
@ -542,20 +597,20 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt
|
|||
// Can only choose one of these two.
|
||||
if (opts.mOptions & RS_TOKREQOPT_MSG_ORIGMSG)
|
||||
{
|
||||
std::cerr << "GxsDataProxy::getMsgList() MSG_ORIGMSG";
|
||||
std::cerr << "GxsDataProxyVEG::getMsgList() MSG_ORIGMSG";
|
||||
std::cerr << std::endl;
|
||||
onlyOrigMsgs = true;
|
||||
}
|
||||
else if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST)
|
||||
{
|
||||
std::cerr << "GxsDataProxy::getMsgList() MSG_LATEST";
|
||||
std::cerr << "GxsDataProxyVEG::getMsgList() MSG_LATEST";
|
||||
std::cerr << std::endl;
|
||||
onlyLatestMsgs = true;
|
||||
}
|
||||
|
||||
if (opts.mOptions & RS_TOKREQOPT_MSG_THREAD)
|
||||
{
|
||||
std::cerr << "GxsDataProxy::getMsgList() MSG_THREAD";
|
||||
std::cerr << "GxsDataProxyVEG::getMsgList() MSG_THREAD";
|
||||
std::cerr << std::endl;
|
||||
onlyThreadHeadMsgs = true;
|
||||
}
|
||||
|
@ -593,7 +648,7 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt
|
|||
bool addMsg = false;
|
||||
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 << " MsgId: " << mit->second.mMsgId;
|
||||
std::cerr << " TS: " << mit->second.mPublishTs;
|
||||
|
@ -604,7 +659,7 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt
|
|||
// check timestamps.
|
||||
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 << " MsgId: " << mit->second.mMsgId;
|
||||
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.
|
||||
* 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;
|
||||
|
||||
bool onlyLatestMsgs = false;
|
||||
bool onlyAllVersions = false;
|
||||
bool onlyChildMsgs = false;
|
||||
bool onlyThreadMsgs = false;
|
||||
|
||||
if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST)
|
||||
{
|
||||
std::cerr << "GxsDataProxy::getMsgRelatedList() MSG_LATEST";
|
||||
std::cerr << "GxsDataProxyVEG::getMsgRelatedList() MSG_LATEST";
|
||||
std::cerr << std::endl;
|
||||
onlyLatestMsgs = true;
|
||||
}
|
||||
else if (opts.mOptions & RS_TOKREQOPT_MSG_VERSIONS)
|
||||
{
|
||||
std::cerr << "GxsDataProxy::getMsgRelatedList() MSG_VERSIONS";
|
||||
std::cerr << "GxsDataProxyVEG::getMsgRelatedList() MSG_VERSIONS";
|
||||
std::cerr << std::endl;
|
||||
onlyAllVersions = true;
|
||||
}
|
||||
|
||||
if (opts.mOptions & RS_TOKREQOPT_MSG_PARENT)
|
||||
{
|
||||
std::cerr << "GxsDataProxy::getMsgRelatedList() MSG_PARENTS";
|
||||
std::cerr << "GxsDataProxyVEG::getMsgRelatedList() MSG_PARENTS";
|
||||
std::cerr << std::endl;
|
||||
onlyChildMsgs = true;
|
||||
}
|
||||
|
||||
if (opts.mOptions & RS_TOKREQOPT_MSG_THREAD)
|
||||
{
|
||||
std::cerr << "GxsDataProxyVEG::getMsgRelatedList() MSG_THREAD";
|
||||
std::cerr << std::endl;
|
||||
onlyThreadMsgs = true;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return false;
|
||||
|
@ -718,7 +789,23 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
|
|||
|
||||
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;
|
||||
|
||||
return false;
|
||||
|
@ -726,9 +813,9 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
|
|||
|
||||
|
||||
/* 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;
|
||||
/* just copy */
|
||||
outMsgIds = msgIds;
|
||||
|
@ -755,7 +842,7 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
|
|||
|
||||
if (onlyLatestMsgs)
|
||||
{
|
||||
if (onlyChildMsgs)
|
||||
if (onlyChildMsgs || onlyThreadMsgs)
|
||||
{
|
||||
// RUN THROUGH ALL MSGS... in map origId -> TS.
|
||||
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++)
|
||||
{
|
||||
// skip msgs that aren't children.
|
||||
if (onlyChildMsgs)
|
||||
{
|
||||
if (mit->second.mParentId != origMsgId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else /* onlyThreadMsgs */
|
||||
{
|
||||
if (mit->second.mThreadId != (*it))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
oit = origMsgTs.find(mit->second.mOrigMsgId);
|
||||
bool addMsg = false;
|
||||
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 << " MsgId: " << mit->second.mMsgId;
|
||||
std::cerr << " TS: " << mit->second.mPublishTs;
|
||||
|
@ -783,7 +881,7 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
|
|||
// check timestamps.
|
||||
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 << " MsgId: " << mit->second.mMsgId;
|
||||
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;
|
||||
if (convertGroupToMetaData(groupData, meta))
|
||||
{
|
||||
if (!isUniqueGroup(meta.mGroupId))
|
||||
{
|
||||
std::cerr << "GxsDataProxy::createGroup() ERROR GroupId Clashes, discarding";
|
||||
std::cerr << "GxsDataProxyVEG::createGroup() ERROR GroupId Clashes, discarding";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
@ -869,20 +967,20 @@ bool GxsDataProxy::createGroup(void *groupData)
|
|||
return true;
|
||||
}
|
||||
|
||||
std::cerr << "GxsDataProxy::createGroup() ERROR Failed to convert Data";
|
||||
std::cerr << "GxsDataProxyVEG::createGroup() ERROR Failed to convert Data";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool GxsDataProxy::createMsg(void *msgData)
|
||||
bool GxsDataProxyVEG::createMsg(void *msgData)
|
||||
{
|
||||
RsMsgMetaData meta;
|
||||
if (convertMsgToMetaData(msgData, meta))
|
||||
{
|
||||
if (!isUniqueMsg(meta.mMsgId))
|
||||
{
|
||||
std::cerr << "GxsDataProxy::createMsg() ERROR MsgId Clashes, discarding";
|
||||
std::cerr << "GxsDataProxyVEG::createMsg() ERROR MsgId Clashes, discarding";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
@ -895,7 +993,7 @@ bool GxsDataProxy::createMsg(void *msgData)
|
|||
git = mGroupMetaData.find(meta.mGroupId);
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
@ -915,14 +1013,14 @@ bool GxsDataProxy::createMsg(void *msgData)
|
|||
return true;
|
||||
}
|
||||
|
||||
std::cerr << "GxsDataProxy::createMsg() ERROR Failed to convert Data";
|
||||
std::cerr << "GxsDataProxyVEG::createMsg() ERROR Failed to convert Data";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 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 *****/
|
||||
|
||||
|
@ -932,7 +1030,7 @@ bool GxsDataProxy::setMessageStatus(const std::string &msgId,const uint32_t stat
|
|||
if (mit == mMsgMetaData.end())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::getMsgSummary() Error Finding MsgId: " << msgId;
|
||||
std::cerr << "GxsDataProxyVEG::getMsgSummary() Error Finding MsgId: " << msgId;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
|
@ -946,7 +1044,7 @@ bool GxsDataProxy::setMessageStatus(const std::string &msgId,const uint32_t stat
|
|||
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 *****/
|
||||
|
||||
|
@ -956,7 +1054,7 @@ bool GxsDataProxy::setGroupStatus(const std::string &groupId, const uint32_t sta
|
|||
if (git == mGroupMetaData.end())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::setGroupStatus() Error Finding GroupId: " << groupId;
|
||||
std::cerr << "GxsDataProxyVEG::setGroupStatus() Error Finding GroupId: " << groupId;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
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 *****/
|
||||
|
||||
|
@ -981,7 +1079,7 @@ bool GxsDataProxy::setGroupSubscribeFlags(const std::string &groupId, uint32_t s
|
|||
if (git == mGroupMetaData.end())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::setGroupSubscribeFlags() Error Finding GroupId: " << groupId;
|
||||
std::cerr << "GxsDataProxyVEG::setGroupSubscribeFlags() Error Finding GroupId: " << groupId;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
|
@ -995,7 +1093,7 @@ bool GxsDataProxy::setGroupSubscribeFlags(const std::string &groupId, uint32_t s
|
|||
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 *****/
|
||||
|
||||
|
@ -1005,7 +1103,7 @@ bool GxsDataProxy::setMessageServiceString(const std::string &msgId, const std::
|
|||
if (mit == mMsgMetaData.end())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::setMessageServiceString() Error Finding MsgId: " << msgId;
|
||||
std::cerr << "GxsDataProxyVEG::setMessageServiceString() Error Finding MsgId: " << msgId;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
|
@ -1017,7 +1115,7 @@ bool GxsDataProxy::setMessageServiceString(const std::string &msgId, const std::
|
|||
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 *****/
|
||||
|
||||
|
@ -1027,7 +1125,7 @@ bool GxsDataProxy::setGroupServiceString(const std::string &groupId, const std::
|
|||
if (git == mGroupMetaData.end())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::setGroupServiceString() Error Finding GroupId: " << groupId;
|
||||
std::cerr << "GxsDataProxyVEG::setGroupServiceString() Error Finding GroupId: " << groupId;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
|
@ -1041,22 +1139,22 @@ bool GxsDataProxy::setGroupServiceString(const std::string &groupId, const std::
|
|||
|
||||
|
||||
/* 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;
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* extract Data */
|
||||
bool GxsDataProxy::getGroupSummary(const std::string &groupId, RsGroupMetaData &groupSummary)
|
||||
bool GxsDataProxyVEG::getGroupSummary(const std::string &groupId, RsGroupMetaData &groupSummary)
|
||||
{
|
||||
RsStackMutex stack(mDataMtx); /***** LOCKED *****/
|
||||
|
||||
|
@ -1066,7 +1164,7 @@ bool GxsDataProxy::getGroupSummary(const std::string &groupId, RsGroupMetaData &
|
|||
if (mit == mGroupMetaData.end())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::getGroupMetaData() Error Finding GroupId: " << groupId;
|
||||
std::cerr << "GxsDataProxyVEG::getGroupMetaData() Error Finding GroupId: " << groupId;
|
||||
std::cerr << std::endl;
|
||||
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 *****/
|
||||
|
||||
|
@ -1088,7 +1186,7 @@ bool GxsDataProxy::getMsgSummary(const std::string &msgId, RsMsgMetaData &msgSum
|
|||
if (mit == mMsgMetaData.end())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::getMsgSummary() Error Finding MsgId: " << msgId;
|
||||
std::cerr << "GxsDataProxyVEG::getMsgSummary() Error Finding MsgId: " << msgId;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
|
@ -1100,7 +1198,7 @@ bool GxsDataProxy::getMsgSummary(const std::string &msgId, RsMsgMetaData &msgSum
|
|||
|
||||
|
||||
/* 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;
|
||||
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())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::getGroupMetaData() Error Finding GroupId: " << *it;
|
||||
std::cerr << "GxsDataProxyVEG::getGroupMetaData() Error Finding GroupId: " << *it;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
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;
|
||||
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())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::getMsgSummary() Error Finding MsgId: " << *it;
|
||||
std::cerr << "GxsDataProxyVEG::getMsgSummary() Error Finding MsgId: " << *it;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
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 *****/
|
||||
|
||||
|
@ -1160,7 +1258,7 @@ bool GxsDataProxy::getGroupData(const std::string &groupId, void * &groupData)
|
|||
if (mit == mGroupData.end())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::getGroupData() Error Finding GroupId: " << groupId;
|
||||
std::cerr << "GxsDataProxyVEG::getGroupData() Error Finding GroupId: " << groupId;
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
@ -1171,7 +1269,7 @@ bool GxsDataProxy::getGroupData(const std::string &groupId, void * &groupData)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GxsDataProxy::getMsgData(const std::string &msgId, void * &msgData)
|
||||
bool GxsDataProxyVEG::getMsgData(const std::string &msgId, void * &msgData)
|
||||
{
|
||||
RsStackMutex stack(mDataMtx); /***** LOCKED *****/
|
||||
|
||||
|
@ -1181,7 +1279,7 @@ bool GxsDataProxy::getMsgData(const std::string &msgId, void * &msgData)
|
|||
if (mit == mMsgData.end())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::getMsgData() Error Finding MsgId: " << msgId;
|
||||
std::cerr << "GxsDataProxyVEG::getMsgData() Error Finding MsgId: " << msgId;
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
@ -1193,7 +1291,7 @@ bool GxsDataProxy::getMsgData(const std::string &msgId, void * &msgData)
|
|||
}
|
||||
|
||||
#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;
|
||||
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())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::getGroupData() Error Finding GroupId: " << *it;
|
||||
std::cerr << "GxsDataProxyVEG::getGroupData() Error Finding GroupId: " << *it;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
|
@ -1217,7 +1315,7 @@ bool GxsDataProxy::getGroupData(const std::list<std::string> &groupIds, std::lis
|
|||
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;
|
||||
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())
|
||||
{
|
||||
// error.
|
||||
std::cerr << "GxsDataProxy::getMsgData() Error Finding MsgId: " << *it;
|
||||
std::cerr << "GxsDataProxyVEG::getMsgData() Error Finding MsgId: " << *it;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
|
@ -1242,7 +1340,7 @@ bool GxsDataProxy::getMsgData(const std::list<std::string> &msgIds, std::list<vo
|
|||
}
|
||||
#endif
|
||||
|
||||
bool GxsDataProxy::isUniqueMsg(const std::string &msgId)
|
||||
bool GxsDataProxyVEG::isUniqueMsg(const std::string &msgId)
|
||||
{
|
||||
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 *****/
|
||||
|
||||
|
@ -1272,8 +1370,8 @@ bool GxsDataProxy::isUniqueGroup(const std::string &groupId)
|
|||
/*********************************************************************************************************/
|
||||
|
||||
|
||||
p3GxsDataService::p3GxsDataService(uint16_t type, GxsDataProxy *proxy)
|
||||
:p3GxsService(type), mProxy(proxy)
|
||||
p3GxsDataServiceVEG::p3GxsDataServiceVEG(uint16_t type, GxsDataProxyVEG *proxy)
|
||||
:p3GxsServiceVEG(type), mProxy(proxy)
|
||||
{
|
||||
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>::iterator cit;
|
||||
|
@ -1294,11 +1392,11 @@ bool p3GxsDataService::fakeprocessrequests()
|
|||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
/* PROCESS REQUEST! */
|
||||
switch(it->second.reqType)
|
||||
|
@ -1323,13 +1421,13 @@ bool p3GxsDataService::fakeprocessrequests()
|
|||
}
|
||||
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;
|
||||
toClear.push_back(it->second.token);
|
||||
}
|
||||
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;
|
||||
toClear.push_back(it->second.token);
|
||||
}
|
||||
|
@ -1345,23 +1443,25 @@ bool p3GxsDataService::fakeprocessrequests()
|
|||
return true;
|
||||
}
|
||||
|
||||
#if 0 // DISABLED AND MOVED TO GXS CODE.
|
||||
|
||||
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 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;
|
||||
}
|
||||
//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;
|
||||
//}
|
||||
|
||||
#endif
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#define P3_GXS_SERVICE_HEADER
|
||||
|
||||
#include "services/p3service.h"
|
||||
#include "retroshare/rsidentity.h"
|
||||
#include "retroshare/rsidentityVEG.h"
|
||||
|
||||
/*
|
||||
* This class provides useful generic support for GXS style services.
|
||||
|
@ -54,7 +54,7 @@ class gxsRequest
|
|||
|
||||
uint32_t ansType;
|
||||
uint32_t reqType;
|
||||
RsTokReqOptions Options;
|
||||
RsTokReqOptionsVEG Options;
|
||||
|
||||
uint32_t status;
|
||||
|
||||
|
@ -64,18 +64,18 @@ class gxsRequest
|
|||
};
|
||||
|
||||
|
||||
class p3GxsService: public p3Service
|
||||
class p3GxsServiceVEG: public p3Service
|
||||
{
|
||||
protected:
|
||||
|
||||
p3GxsService(uint16_t type);
|
||||
p3GxsServiceVEG(uint16_t type);
|
||||
|
||||
public:
|
||||
|
||||
//virtual ~p3Service() { p3Service::~p3Service(); return; }
|
||||
|
||||
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 updateRequestStatus(const uint32_t &token, const uint32_t &status);
|
||||
|
@ -103,15 +103,15 @@ virtual bool fakeprocessrequests();
|
|||
};
|
||||
|
||||
|
||||
class GxsDataProxy
|
||||
class GxsDataProxyVEG
|
||||
{
|
||||
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 getMsgList( uint32_t &token, const RsTokReqOptions &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 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 RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds, 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
|
||||
|
@ -157,8 +157,8 @@ virtual bool setGroupServiceString(const std::string &grpId, const std::string &
|
|||
|
||||
protected:
|
||||
|
||||
bool filterGroupList(const RsTokReqOptions &opts, std::list<std::string> &groupIds);
|
||||
bool filterMsgList(const RsTokReqOptions &opts, std::list<std::string> &msgIds);
|
||||
bool filterGroupList(const RsTokReqOptionsVEG &opts, std::list<std::string> &groupIds);
|
||||
bool filterMsgList(const RsTokReqOptionsVEG &opts, std::list<std::string> &msgIds);
|
||||
|
||||
|
||||
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:
|
||||
|
||||
p3GxsDataService(uint16_t type, GxsDataProxy *proxy);
|
||||
p3GxsDataServiceVEG(uint16_t type, GxsDataProxyVEG *proxy);
|
||||
virtual bool fakeprocessrequests();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
GxsDataProxy *mProxy;
|
||||
GxsDataProxyVEG *mProxy;
|
||||
};
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue