Lots of progress with Gxs Services:

- Added gxsForum interface, service + serialiser to libretroshare.
 - Bugfix in rsgenservices getSize() at the wrong point, Added lots of debug too.
 - Dummy Collections to Wiki, can now create and retrieve Groups from the GUI.
 - Bugfix in rsinit (wrong backend for wiki) + added forum to startup.
 - improved debugging in GxsId serialiser.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5797 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-11-09 00:56:07 +00:00
parent 8170697029
commit eeb96c5e62
13 changed files with 1214 additions and 19 deletions

View file

@ -0,0 +1,402 @@
/*
* libretroshare/src/serialiser: rsgxsforumitems.cc
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include <iostream>
#include "rsgxsforumitems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#define GXSFORUM_DEBUG 1
uint32_t RsGxsForumSerialiser::size(RsItem *item)
{
RsGxsForumGroupItem* grp_item = NULL;
RsGxsForumMsgItem* op_item = NULL;
if((grp_item = dynamic_cast<RsGxsForumGroupItem*>(item)) != NULL)
{
return sizeGxsForumGroupItem(grp_item);
}
else if((op_item = dynamic_cast<RsGxsForumMsgItem*>(item)) != NULL)
{
return sizeGxsForumMsgItem(op_item);
}
std::cerr << "RsGxsForumSerialiser::size() ERROR invalid item" << std::endl;
return 0;
}
bool RsGxsForumSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsForumGroupItem* grp_item = NULL;
RsGxsForumMsgItem* op_item = NULL;
if((grp_item = dynamic_cast<RsGxsForumGroupItem*>(item)) != NULL)
{
return serialiseGxsForumGroupItem(grp_item, data, size);
}
else if((op_item = dynamic_cast<RsGxsForumMsgItem*>(item)) != NULL)
{
return serialiseGxsForumMsgItem(op_item, data, size);
}
std::cerr << "RsGxsForumSerialiser::serialise() ERROR invalid item" << std::endl;
return false;
}
RsItem* RsGxsForumSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM:
return deserialiseGxsForumGroupItem(data, size);
break;
case RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM:
return deserialiseGxsForumMsgItem(data, size);
break;
default:
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsForumGroupItem::clear()
{
mGroup.mDescription.clear();
}
std::ostream& RsGxsForumGroupItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsForumGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Description: " << mGroup.mDescription << std::endl;
printRsItemEnd(out ,"RsGxsForumGroupItem", indent);
return out;
}
uint32_t RsGxsForumSerialiser::sizeGxsForumGroupItem(RsGxsForumGroupItem *item)
{
const RsGxsForumGroup& group = item->mGroup;
uint32_t s = 8; // header
s += GetTlvStringSize(group.mDescription);
return s;
}
bool RsGxsForumSerialiser::serialiseGxsForumGroupItem(RsGxsForumGroupItem *item, void *data, uint32_t *size)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsForumGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() Size too small" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsForumGroupItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mGroup.mDescription);
if(offset != tlvsize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSFORUM_DEBUG
if (!ok)
{
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsForumGroupItem* RsGxsForumSerialiser::deserialiseGxsForumGroupItem(void *data, uint32_t *size)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsForumGroupItem* item = new RsGxsForumGroupItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mGroup.mDescription);
if (offset != rssize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsForumMsgItem::clear()
{
mMsg.mMsg.clear();
}
std::ostream& RsGxsForumMsgItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsForumMsgItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Msg: " << mMsg.mMsg << std::endl;
printRsItemEnd(out ,"RsGxsForumMsgItem", indent);
return out;
}
uint32_t RsGxsForumSerialiser::sizeGxsForumMsgItem(RsGxsForumMsgItem *item)
{
const RsGxsForumMsg& msg = item->mMsg;
uint32_t s = 8; // header
s += 4; // mMsg.
return s;
}
bool RsGxsForumSerialiser::serialiseGxsForumMsgItem(RsGxsForumMsgItem *item, void *data, uint32_t *size)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsForumMsgItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsForumMsgItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg.mMsg);
if(offset != tlvsize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSFORUM_DEBUG
if (!ok)
{
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsForumMsgItem* RsGxsForumSerialiser::deserialiseGxsForumMsgItem(void *data, uint32_t *size)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsForumMsgItem* item = new RsGxsForumMsgItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg.mMsg);
if (offset != rssize)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSFORUM_DEBUG
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/

View file

@ -0,0 +1,95 @@
/*
* libretroshare/src/serialiser: rsgxsforumitems.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 by Robert Fernie
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef RS_GXS_FORUM_ITEMS_H
#define RS_GXS_FORUM_ITEMS_H
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rsgxsforums.h"
const uint8_t RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM = 0x03;
class RsGxsForumGroupItem : public RsGxsGrpItem
{
public:
RsGxsForumGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_FORUMS,
RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM) { return;}
virtual ~RsGxsForumGroupItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsForumGroup mGroup;
};
class RsGxsForumMsgItem : public RsGxsMsgItem
{
public:
RsGxsForumMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_FORUMS,
RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM) {return; }
virtual ~RsGxsForumMsgItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsForumMsg mMsg;
};
class RsGxsForumSerialiser : public RsSerialType
{
public:
RsGxsForumSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_FORUMS)
{ return; }
virtual ~RsGxsForumSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsForumGroupItem(RsGxsForumGroupItem *item);
bool serialiseGxsForumGroupItem (RsGxsForumGroupItem *item, void *data, uint32_t *size);
RsGxsForumGroupItem * deserialiseGxsForumGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsForumMsgItem(RsGxsForumMsgItem *item);
bool serialiseGxsForumMsgItem (RsGxsForumMsgItem *item, void *data, uint32_t *size);
RsGxsForumMsgItem * deserialiseGxsForumMsgItem(void *data, uint32_t *size);
};
#endif /* RS_GXS_FORUM_ITEMS_H */

View file

@ -50,7 +50,8 @@ uint32_t RsGxsIdSerialiser::size(RsItem *item)
{
return sizeGxsIdCommentItem(com_item);
}
return NULL;
std::cerr << "RsGxsIdSerialiser::size() ERROR invalid item" << std::endl;
return 0;
}
bool RsGxsIdSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
@ -71,13 +72,14 @@ bool RsGxsIdSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
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 RSSERIAL_DEBUG
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
@ -168,7 +170,7 @@ bool RsGxsIdSerialiser::serialiseGxsIdGroupItem(RsGxsIdGroupItem *item, void *da
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem()" << std::endl;
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() Size too small" << std::endl;
#endif
return false;
}

View file

@ -77,7 +77,7 @@ bool RsGxsWikiSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */