Bugfixes to rsmsgitems & rsserial.

removed testing utilites rstlvutil.
fixed up rsgxsiditems printing.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7232 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2014-04-05 04:48:52 +00:00
parent 7fa611b2e7
commit 3eb79bbcba
7 changed files with 16 additions and 241 deletions

View File

@ -412,7 +412,6 @@ HEADERS += serialiser/rsbaseserial.h \
serialiser/rstlvgenericmap.inl \
serialiser/rstlvlist.h \
serialiser/rstlvmaps.h \
serialiser/rstlvutil.h \
serialiser/rstlvbanlist.h \
serialiser/rsbanlistitems.h \
serialiser/rsbwctrlitems.h \
@ -556,7 +555,6 @@ SOURCES += serialiser/rsbaseserial.cc \
serialiser/rstlvkeys.cc \
serialiser/rstlvkeyvalue.cc \
serialiser/rstlvgenericparam.cc \
serialiser/rstlvutil.cc \
serialiser/rstlvbanlist.cc \
serialiser/rsbanlistitems.cc \
serialiser/rsbwctrlitems.cc \

View File

@ -78,6 +78,7 @@ class RsGxsIdGroup
{
public:
RsGxsIdGroup():mPgpKnown(false) { return; }
~RsGxsIdGroup() { return; }
RsGroupMetaData mMeta;

View File

@ -29,6 +29,7 @@
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#include "serialiser/rstlvstring.h"
#include "util/rsstring.h"
#define GXSID_DEBUG 1
@ -151,7 +152,14 @@ std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent)
printIndent(out, int_Indent);
out << "PgpIdHash: " << group.mPgpIdHash << std::endl;
printIndent(out, int_Indent);
out << "PgpIdSign: " << group.mPgpIdSign << std::endl;
std::string signhex;
// convert from binary to hex.
for(unsigned int i = 0; i < group.mPgpIdSign.length(); i++)
{
rs_sprintf_append(signhex, "%02x", (uint32_t) ((uint8_t) group.mPgpIdSign[i]));
}
out << "PgpIdSign: " << signhex << std::endl;
printIndent(out, int_Indent);
out << "RecognTags:" << std::endl;

View File

@ -652,7 +652,10 @@ bool RsChatLobbyListItem::serialise(void *data, uint32_t& pktsize)
if (pktsize < tlvsize)
return false; /* not enough space */
if(lobby_ids.size() != lobby_counts.size() || lobby_ids.size() != lobby_names.size())
if((lobby_ids.size() != lobby_names.size()) ||
(lobby_ids.size() != lobby_topics.size()) ||
(lobby_ids.size() != lobby_counts.size()) ||
(lobby_ids.size() != lobby_privacy_levels.size()))
{
std::cerr << "Consistency error in RsChatLobbyListItem!! Sizes don't match!" << std::endl;
return false ;

View File

@ -374,10 +374,10 @@ RsItem * RsSerialiser::deserialise(void *data, uint32_t *size)
//std::cerr << "RsSerialiser::deserialise() RsItem Type: " << std::hex << getRsItemId(data) << " Size: " << pkt_size;
//std::cerr << std::endl;
if (pkt_size < *size)
if (pkt_size != *size)
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsSerialiser::deserialise() ERROR Not Enough Data(2)";
std::cerr << "RsSerialiser::deserialise() ERROR Size mismatch(2)";
std::cerr << std::endl;
#endif
return NULL;

View File

@ -1,187 +0,0 @@
/*
* libretroshare/src/serialiser: rstlvutil.cc
*
* RetroShare Serialiser.
*
* Copyright 2007-2008 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".
*
*/
/* some utility functions mainly for debugging
*
*
*
*/
#include "serialiser/rstlvutil.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvitem.h"
#include "util/rsstring.h"
#include "util/utest.h"
#include <iostream>
#include <stdlib.h>
#if 0
/* print out a packet */
#include <iomanip>
#include <vector>
#endif
void displayRawPacket(std::ostream &out, void *data, uint32_t size)
{
uint32_t i;
std::string sout;
rs_sprintf(sout, "DisplayRawPacket: Size: %ld", size);
for(i = 0; i < size; i++)
{
if (i % 16 == 0)
{
sout += "\n";
}
rs_sprintf_append(sout, "%02x:", (int) (((unsigned char *) data)[i]));
}
out << sout << std::endl;
}
#define WHOLE_64K_SIZE 65536
int test_SerialiseTlvItem(std::ostream &str, RsTlvItem *in, RsTlvItem *out)
{
uint16_t initsize = in->TlvSize();
uint32_t serialOffset = 0;
uint32_t deserialOffset = 0;
str << "test_SerialiseTlvItem() Testing ... Print/Serialise/Deserialise";
str << std::endl;
/* some space to serialise into */
unsigned char serbuffer[WHOLE_64K_SIZE];
CHECK(in->SetTlv(serbuffer, WHOLE_64K_SIZE, &serialOffset));
CHECK(serialOffset == initsize); /* check that the offset matches the size */
CHECK(in->TlvSize() == initsize); /* check size hasn't changed */
REPORT("Serialise RsTlvItem");
/* now we try to read it back in! */
CHECK(out->GetTlv(serbuffer, serialOffset, &deserialOffset));
/* again check sizes */
CHECK(serialOffset == deserialOffset);
CHECK(deserialOffset == initsize);
CHECK(out->TlvSize() == initsize);
str << "Class In/Serialised/Out!" << std::endl;
in->print(str, 0);
displayRawPacket(str, serbuffer, serialOffset);
out->print(str, 0);
/* Can't check the actual data -> should add function */
REPORT("DeSerialise RsTlvFileItem");
/* print it out */
return 1;
}
/* This function checks the TLV header, and steps on to the next one
*/
bool test_StepThroughTlvStack(std::ostream &str, void *data, int size)
{
uint32_t offset = 0;
uint32_t index = 0;
while (offset + 4 <= size)
{
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[offset]) );
uint16_t tlvsize = GetTlvSize( &(((uint8_t *) data)[offset]) );
str << "Tlv Entry[" << index << "] => Offset: " << offset;
str << " Type: " << tlvtype;
str << " Size: " << tlvsize;
str << std::endl;
offset += tlvsize;
}
CHECK(offset == size); /* we match up exactly */
REPORT("Step Through RsTlvStack");
return 1;
}
int test_CreateTlvStack(std::ostream &str,
std::vector<RsTlvItem *> items, void *data, uint32_t *totalsize)
{
/* (1) select a random item
* (2) check size -> if okay serialise onto the end
* (3) loop!.
*/
uint32_t offset = 0;
uint32_t count = 0;
while(1)
{
int idx = (int) (items.size() * (rand() / (RAND_MAX + 1.0)));
uint32_t tlvsize = items[idx] -> TlvSize();
if (offset + tlvsize > *totalsize)
{
*totalsize = offset;
return count;
}
str << "Stack[" << count << "]";
str << " Offset: " << offset;
str << " TlvSize: " << tlvsize;
str << std::endl;
/* serialise it */
items[idx] -> SetTlv(data, *totalsize, &offset);
items[idx] -> print(str, 10);
count++;
}
*totalsize = offset;
return 0;
}
int test_TlvSet(std::vector<RsTlvItem *> items, int maxsize)
{
int totalsize = maxsize;
void *data = malloc(totalsize);
uint32_t size = totalsize;
test_CreateTlvStack(std::cerr, items, data, &size);
test_StepThroughTlvStack(std::cerr, data, size);
return 1;
}

View File

@ -1,48 +0,0 @@
#ifndef RS_TLV_UTIL_H
#define RS_TLV_UTIL_H
/*
* libretroshare/src/serialiser: rstlvutil.h
*
* RetroShare Serialiser.
*
* Copyright 2007-2008 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".
*
*/
/* some utility functions mainly for debugging
*/
#include <inttypes.h>
#include <ostream>
#include <vector>
class RsTlvItem;
/* print out a packet */
void displayRawPacket(std::ostream &out, void *data, uint32_t size);
int test_SerialiseTlvItem(std::ostream &str, RsTlvItem *in, RsTlvItem *out);
bool test_StepThroughTlvStack(std::ostream &str, void *data, int size);
int test_CreateTlvStack(std::ostream &str,
std::vector<RsTlvItem *> items, void *data, int totalsize);
int test_TlvSet(std::vector<RsTlvItem *> items, int maxsize);
#endif