mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-04 09:05:34 -05:00
Got group retrieval working with gui and fixed subsequent bugs
add p3distribsecurity mirror gxssecurity (does not have grp or msg verification implemented, but other methods are valid) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5406 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
148d1310a2
commit
acaefada65
280
libretroshare/src/gxs/gxssecurity.cc
Normal file
280
libretroshare/src/gxs/gxssecurity.cc
Normal file
@ -0,0 +1,280 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/distrib: p3distribverify.cc
|
||||
*
|
||||
*
|
||||
* Copyright 2008-2010 by Robert Fernie
|
||||
* 2011 Christopher Evi-Parker
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gxssecurity.h"
|
||||
#include "pqi/authgpg.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
|
||||
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::validateNxsMsg(RsNxsMsg *msg)
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
132
libretroshare/src/gxs/gxssecurity.h
Normal file
132
libretroshare/src/gxs/gxssecurity.h
Normal file
@ -0,0 +1,132 @@
|
||||
#ifndef GXSSECURITY_H
|
||||
#define GXSSECURITY_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/gxs: gxssecurity
|
||||
*
|
||||
* Security functions for Gxs
|
||||
*
|
||||
* Copyright 2008-2010 by Robert Fernie
|
||||
* 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 signature and stores it in a string
|
||||
* in hex format
|
||||
* @param data
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
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
|
||||
* @return true if group valid false otherwise
|
||||
*/
|
||||
static bool validateNxsGrp(RsNxsGrp *newGrp);
|
||||
|
||||
/*!
|
||||
* uses groupinfo public key to verify signature of signed message
|
||||
* @param info groupinfo for which msg is meant for
|
||||
* @param msg
|
||||
* @return false if verfication of signature is not passed
|
||||
*/
|
||||
static bool validateNxsMsg(RsNxsMsg *msg);
|
||||
};
|
||||
|
||||
#endif // GXSSECURITY_H
|
@ -24,7 +24,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include "rsgenexchange.h"
|
||||
#include "gxssecurity.h"
|
||||
|
||||
RsGenExchange::RsGenExchange(RsGeneralDataService *gds,
|
||||
RsNetworkExchangeService *ns, RsSerialType *serviceSerialiser, uint16_t servType)
|
||||
@ -62,6 +68,30 @@ void RsGenExchange::tick()
|
||||
|
||||
}
|
||||
|
||||
void RsGenExchange::createGroup(RsNxsGrp *grp)
|
||||
{
|
||||
/* create Keys */
|
||||
RSA *rsa_admin = RSA_generate_key(2048, 65537, NULL, NULL);
|
||||
RSA *rsa_admin_pub = RSAPublicKey_dup(rsa_admin);
|
||||
|
||||
|
||||
/* set keys */
|
||||
RsTlvSecurityKey adminKey;
|
||||
GxsSecurity::setRSAPublicKey(adminKey, rsa_admin_pub);
|
||||
|
||||
adminKey.startTS = time(NULL);
|
||||
adminKey.endTS = 0; /* no end */
|
||||
RsGxsGrpMetaData* meta = grp->metaData;
|
||||
meta->keys.keys[adminKey.keyId] = adminKey;
|
||||
meta->mGroupId = adminKey.keyId;
|
||||
grp->grpId = meta->mGroupId;
|
||||
|
||||
adminKey.TlvClear();
|
||||
|
||||
// free the private key for now, as it is not in use
|
||||
RSA_free(rsa_admin);
|
||||
}
|
||||
|
||||
|
||||
bool RsGenExchange::getGroupList(const uint32_t &token, std::list<RsGxsGroupId> &groupIds)
|
||||
{
|
||||
@ -125,7 +155,7 @@ bool RsGenExchange::getMsgMeta(const uint32_t &token,
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem *> grpItem)
|
||||
bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem *>& grpItem)
|
||||
{
|
||||
|
||||
std::list<RsNxsGrp*> nxsGrps;
|
||||
@ -294,13 +324,16 @@ void RsGenExchange::publishGrps()
|
||||
|
||||
char gData[size];
|
||||
bool ok = mSerialiser->serialise(grpItem, gData, &size);
|
||||
grp->grp.setBinData(gData, size);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
grp->metaData = new RsGxsGrpMetaData();
|
||||
*(grp->metaData) = grpItem->meta;
|
||||
createGroup(grp);
|
||||
ok = mDataAccess->addGroupData(grp);
|
||||
RsGxsGroupChange* gc = new RsGxsGroupChange();
|
||||
gc->grpIdList.push_back(grp->grpId);
|
||||
mNotifications.push_back(gc);
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ protected:
|
||||
* @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
|
||||
@ -193,9 +193,7 @@ protected:
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) = 0;
|
||||
|
||||
|
||||
void publishGrps();
|
||||
|
||||
void publishMsgs();
|
||||
|
||||
private:
|
||||
|
||||
@ -205,6 +203,12 @@ private:
|
||||
|
||||
void processRecvdGroups();
|
||||
|
||||
void publishGrps();
|
||||
|
||||
void publishMsgs();
|
||||
|
||||
void createGroup(RsNxsGrp* grp);
|
||||
|
||||
private:
|
||||
|
||||
RsMutex mGenMtx;
|
||||
|
@ -57,7 +57,7 @@
|
||||
const uint8_t RsTokenServiceV2::GXS_REQUEST_STATUS_DONE = 5; // ONCE ALL DATA RETRIEVED.
|
||||
|
||||
RsGxsDataAccess::RsGxsDataAccess(RsGeneralDataService* ds)
|
||||
: mDataStore(ds), mDataMutex("RsGxsDataAccess")
|
||||
: mDataStore(ds), mDataMutex("RsGxsDataAccess"), mNextToken(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -217,6 +217,7 @@ void RsGxsDataAccess::storeRequest(GxsRequest* req)
|
||||
{
|
||||
RsStackMutex stack(mDataMutex); /****** LOCKED *****/
|
||||
|
||||
req->status = GXS_REQUEST_STATUS_PENDING;
|
||||
mRequests[req->token] = req;
|
||||
|
||||
return;
|
||||
@ -263,20 +264,22 @@ bool RsGxsDataAccess::clearRequest(const uint32_t& token)
|
||||
bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list<RsGxsGrpMetaData*>& groupInfo)
|
||||
{
|
||||
|
||||
GxsRequest* req = retrieveRequest(token);
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getGroupSummary() Unable to retrieve group summary" << std::endl;
|
||||
return false;
|
||||
}else if(req->token == GXS_REQUEST_STATUS_COMPLETE){
|
||||
}else if(req->status == GXS_REQUEST_STATUS_COMPLETE){
|
||||
|
||||
GroupMetaReq* gmreq = dynamic_cast<GroupMetaReq*>(req);
|
||||
|
||||
if(gmreq)
|
||||
{
|
||||
groupInfo = gmreq->mGroupMetaData;
|
||||
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
}else{
|
||||
std::cerr << "RsGxsDataAccess::getGroupSummary() Req found, failed caste" << std::endl;
|
||||
return false;
|
||||
@ -291,21 +294,22 @@ bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list<RsGxsGrpM
|
||||
|
||||
bool RsGxsDataAccess::getGroupData(const uint32_t& token, std::list<RsNxsGrp*>& grpData)
|
||||
{
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
GxsRequest* req = retrieveRequest(token);
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getGroupData() Unable to retrieve group data" << std::endl;
|
||||
return false;
|
||||
}else if(req->token == GXS_REQUEST_STATUS_COMPLETE){
|
||||
}else if(req->status == GXS_REQUEST_STATUS_COMPLETE){
|
||||
|
||||
GroupDataReq* gmreq = dynamic_cast<GroupDataReq*>(req);
|
||||
|
||||
if(gmreq)
|
||||
{
|
||||
grpData = gmreq->mGroupData;
|
||||
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
}else{
|
||||
std::cerr << "RsGxsDataAccess::getGroupData() Req found, failed caste" << std::endl;
|
||||
return false;
|
||||
@ -320,20 +324,23 @@ bool RsGxsDataAccess::getGroupData(const uint32_t& token, std::list<RsNxsGrp*>&
|
||||
|
||||
bool RsGxsDataAccess::getMsgData(const uint32_t& token, NxsMsgDataResult& msgData)
|
||||
{
|
||||
GxsRequest* req = retrieveRequest(token);
|
||||
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getMsgData() Unable to retrieve group data" << std::endl;
|
||||
return false;
|
||||
}else if(req->token == GXS_REQUEST_STATUS_COMPLETE){
|
||||
}else if(req->status == GXS_REQUEST_STATUS_COMPLETE){
|
||||
|
||||
MsgDataReq* mdreq = dynamic_cast<MsgDataReq*>(req);
|
||||
|
||||
if(mdreq)
|
||||
{
|
||||
msgData = mdreq->mMsgData;
|
||||
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
}else{
|
||||
std::cerr << "RsGxsDataAccess::getMsgData() Req found, failed caste" << std::endl;
|
||||
return false;
|
||||
@ -348,20 +355,23 @@ bool RsGxsDataAccess::getMsgData(const uint32_t& token, NxsMsgDataResult& msgDat
|
||||
|
||||
bool RsGxsDataAccess::getMsgSummary(const uint32_t& token, GxsMsgMetaResult& msgInfo)
|
||||
{
|
||||
GxsRequest* req = retrieveRequest(token);
|
||||
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getMsgSummary() Unable to retrieve group data" << std::endl;
|
||||
return false;
|
||||
}else if(req->token == GXS_REQUEST_STATUS_COMPLETE){
|
||||
}else if(req->status == GXS_REQUEST_STATUS_COMPLETE){
|
||||
|
||||
MsgMetaReq* mmreq = dynamic_cast<MsgMetaReq*>(req);
|
||||
|
||||
if(mmreq)
|
||||
{
|
||||
msgInfo = mmreq->mMsgMetaData;
|
||||
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
|
||||
}else{
|
||||
std::cerr << "RsGxsDataAccess::getMsgSummary() Req found, failed caste" << std::endl;
|
||||
@ -377,20 +387,22 @@ bool RsGxsDataAccess::getMsgSummary(const uint32_t& token, GxsMsgMetaResult& msg
|
||||
|
||||
bool RsGxsDataAccess::getMsgList(const uint32_t& token, GxsMsgIdResult& msgIds)
|
||||
{
|
||||
GxsRequest* req = retrieveRequest(token);
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getMsgList() Unable to retrieve group data" << std::endl;
|
||||
return false;
|
||||
}else if(req->token == GXS_REQUEST_STATUS_COMPLETE){
|
||||
}else if(req->status == GXS_REQUEST_STATUS_COMPLETE){
|
||||
|
||||
MsgIdReq* mireq = dynamic_cast<MsgIdReq*>(req);
|
||||
|
||||
if(mireq)
|
||||
{
|
||||
msgIds = mireq->mMsgIdResult;
|
||||
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
|
||||
}else{
|
||||
std::cerr << "RsGxsDataAccess::getMsgList() Req found, failed caste" << std::endl;
|
||||
@ -406,21 +418,23 @@ bool RsGxsDataAccess::getMsgList(const uint32_t& token, GxsMsgIdResult& msgIds)
|
||||
|
||||
bool RsGxsDataAccess::getGroupList(const uint32_t& token, std::list<RsGxsGroupId>& groupIds)
|
||||
{
|
||||
GxsRequest* req = retrieveRequest(token);
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getGroupList() Unable to retrieve group data,"
|
||||
"\nRequest does not exist" << std::endl;
|
||||
return false;
|
||||
}else if(req->token == GXS_REQUEST_STATUS_COMPLETE){
|
||||
}else if(req->status == GXS_REQUEST_STATUS_COMPLETE){
|
||||
|
||||
GroupIdReq* gireq = dynamic_cast<GroupIdReq*>(req);
|
||||
|
||||
if(gireq)
|
||||
{
|
||||
groupIds = gireq->mGroupIdResult;
|
||||
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||
|
||||
}else{
|
||||
std::cerr << "RsGxsDataAccess::getGroupList() Req found, failed caste" << std::endl;
|
||||
@ -435,11 +449,9 @@ bool RsGxsDataAccess::getGroupList(const uint32_t& token, std::list<RsGxsGroupId
|
||||
}
|
||||
|
||||
|
||||
GxsRequest* RsGxsDataAccess::retrieveRequest(const uint32_t& token)
|
||||
GxsRequest* RsGxsDataAccess::locked_retrieveRequest(const uint32_t& token)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
if(mRequests.find(token) == mRequests.end()) return NULL;
|
||||
|
||||
GxsRequest* req = mRequests[token];
|
||||
@ -528,7 +540,7 @@ void RsGxsDataAccess::processRequests()
|
||||
std::cerr << std::endl;
|
||||
toClear.push_back(req->token);
|
||||
}
|
||||
else if (now - req->reqTime > MAX_REQUEST_AGE)
|
||||
else if (false/*now - req->reqTime > MAX_REQUEST_AGE*/)
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::processrequests() Clearing Old Request Token: " << req->token;
|
||||
std::cerr << std::endl;
|
||||
@ -551,13 +563,13 @@ bool RsGxsDataAccess::getGroupData(GroupDataReq* req)
|
||||
{
|
||||
|
||||
std::map<RsGxsGroupId, RsNxsGrp*> grpData;
|
||||
mDataStore->retrieveNxsGrps(grpData, true, true);
|
||||
bool ok = mDataStore->retrieveNxsGrps(grpData, true, true);
|
||||
|
||||
std::map<RsGxsGroupId, RsNxsGrp*>::iterator mit = grpData.begin();
|
||||
for(; mit != grpData.end(); mit++)
|
||||
req->mGroupData.push_back(mit->second);
|
||||
|
||||
return true;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsDataAccess::getGroupSummary(GroupMetaReq* req)
|
||||
@ -862,11 +874,11 @@ bool RsGxsDataAccess::checkRequestStatus(const uint32_t& token,
|
||||
uint32_t& status, uint32_t& reqtype, uint32_t& anstype, time_t& ts)
|
||||
{
|
||||
|
||||
GxsRequest* req = retrieveRequest(token);
|
||||
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
if(!req)
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
if(req == NULL)
|
||||
return false;
|
||||
|
||||
anstype = req->ansType;
|
||||
@ -911,12 +923,10 @@ void RsGxsDataAccess::tokenList(std::list<uint32_t>& tokens) {
|
||||
}
|
||||
}
|
||||
|
||||
bool RsGxsDataAccess::updateRequestStatus(const uint32_t& token,
|
||||
bool RsGxsDataAccess::locked_updateRequestStatus(const uint32_t& token,
|
||||
const uint32_t& status) {
|
||||
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
GxsRequest* req = retrieveRequest(token);
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
if(req)
|
||||
req->status = status;
|
||||
|
@ -191,7 +191,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 +222,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
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -196,7 +196,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;
|
||||
|
@ -13,12 +13,6 @@ bool p3PhotoServiceV2::updated()
|
||||
{
|
||||
bool changed = (!mGroupChange.empty() || !mMsgChange.empty());
|
||||
|
||||
std::list<RsGxsGroupId> gL;
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
|
||||
|
||||
groupsChanged(gL);
|
||||
msgsChanged(msgs);
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
@ -331,12 +331,8 @@ void PhotoAddDialog::publishAlbum()
|
||||
std::cerr << "PhotoAddDialog::publishAlbum() New Album Mode Submitting.....";
|
||||
std::cerr << std::endl;
|
||||
|
||||
uint32_t token;
|
||||
rsPhotoV2->submitAlbumDetails(album);
|
||||
|
||||
// tell tokenQueue to expect results from submission.
|
||||
mPhotoQueue->queueRequest(token, TOKENREQ_GROUPINFO, RS_TOKREQ_ANSTYPE_SUMMARY, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -408,7 +404,6 @@ void PhotoAddDialog::publishPhotos(std::string albumId)
|
||||
|
||||
std::cerr << "PhotoAddDialog::publishAlbum() Photo(" << i << ") ";
|
||||
|
||||
uint32_t token;
|
||||
if (isNewPhoto)
|
||||
{
|
||||
std::cerr << "Is a New Photo";
|
||||
|
@ -145,7 +145,15 @@ void PhotoDialog::checkUpdate()
|
||||
if (rsPhotoV2->updated())
|
||||
{
|
||||
//insertAlbums();
|
||||
requestAlbumList();
|
||||
std::list<std::string> grpIds;
|
||||
rsPhotoV2->groupsChanged(grpIds);
|
||||
if(!grpIds.empty())
|
||||
requestAlbumList(grpIds);
|
||||
|
||||
GxsMsgIdResult res;
|
||||
rsPhotoV2->msgsChanged(res);
|
||||
if(!res.empty())
|
||||
requestPhotoList(res);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -427,15 +435,23 @@ void PhotoDialog::deletePhotoItem(PhotoItem *item, uint32_t type)
|
||||
/**************************** Request / Response Filling of Data ************************/
|
||||
|
||||
|
||||
void PhotoDialog::requestAlbumList()
|
||||
void PhotoDialog::requestAlbumList(std::list<std::string>& ids)
|
||||
{
|
||||
|
||||
std::list<std::string> ids;
|
||||
RsTokReqOptionsV2 opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_IDS;
|
||||
uint32_t token;
|
||||
mPhotoQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_LIST, opts, ids, 0);
|
||||
}
|
||||
|
||||
void PhotoDialog::requestPhotoList(GxsMsgReq& req)
|
||||
{
|
||||
RsTokReqOptionsV2 opts;
|
||||
uint32_t token;
|
||||
mPhotoQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_LIST, opts, req, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void PhotoDialog::loadAlbumList(const uint32_t &token)
|
||||
{
|
||||
@ -461,6 +477,7 @@ void PhotoDialog::requestAlbumData(std::list<std::string> &ids)
|
||||
{
|
||||
RsTokReqOptionsV2 opts;
|
||||
uint32_t token;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
mPhotoQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids, 0);
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,9 @@ private slots:
|
||||
private:
|
||||
|
||||
/* Request Response Functions for loading data */
|
||||
void requestAlbumList();
|
||||
void requestAlbumList(std::list<std::string>& ids);
|
||||
void requestAlbumData(std::list<std::string> &ids);
|
||||
void requestPhotoList(GxsMsgReq &albumIds);
|
||||
void requestPhotoList(const std::string &albumId);
|
||||
void requestPhotoData(GxsMsgReq &photoIds);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user