From fc82b2083322f07940453e4a8407602a6142e034 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 10:36:22 +0200 Subject: [PATCH] removed old serialization code in msgs --- .../src/rsitems/rsdiscovery2items.cc | 663 ---------- libretroshare/src/serialiser/rsmsgitems.cc | 1111 ----------------- 2 files changed, 1774 deletions(-) diff --git a/libretroshare/src/rsitems/rsdiscovery2items.cc b/libretroshare/src/rsitems/rsdiscovery2items.cc index 687f32f21..8e4175a9e 100644 --- a/libretroshare/src/rsitems/rsdiscovery2items.cc +++ b/libretroshare/src/rsitems/rsdiscovery2items.cc @@ -156,228 +156,6 @@ void RsDiscContactItem::serial_process(SerializeJob j,SerializeContext& ctx) } /*************************************************************************/ - - - -#ifdef TO_REMOVE -/*************************************************************************/ - -uint32_t RsDiscSerialiser::size(RsItem *i) -{ - RsDiscPgpListItem *pgplist; - RsDiscPgpCertItem *pgpcert; - RsDiscContactItem *contact; - //RsDiscServicesItem *services; - - if (NULL != (pgplist = dynamic_cast(i))) - { - return sizePgpList(pgplist); - } - else if (NULL != (pgpcert = dynamic_cast(i))) - { - return sizePgpCert(pgpcert); - } - else if (NULL != (contact = dynamic_cast(i))) - { - return sizeContact(contact); - } -#if 0 - else if (NULL != (services = dynamic_cast(i))) - { - return sizeServices(services); - } -#endif - return 0; -} - -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsDiscPgpListItem *pgplist; - RsDiscPgpCertItem *pgpcert; - RsDiscContactItem *contact; - //RsDiscServicesItem *services; - - if (NULL != (pgplist = dynamic_cast(i))) - { - return serialisePgpList(pgplist, data, pktsize); - } - else if (NULL != (pgpcert = dynamic_cast(i))) - { - return serialisePgpCert(pgpcert, data, pktsize); - } - else if (NULL != (contact = dynamic_cast(i))) - { - return serialiseContact(contact, data, pktsize); - } -#if 0 - else if (NULL != (services = dynamic_cast(i))) - { - return serialiseServices(services, data, pktsize); - } -#endif - - return false; -} - -RsItem *RsDiscSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_DISC != getRsItemService(rstype))) - { - std::cerr << "RsDiscSerialiser::deserialise() Wrong Type" << std::endl; - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_DISC_PGP_LIST: - return deserialisePgpList(data, pktsize); - break; - case RS_PKT_SUBTYPE_DISC_PGP_CERT: - return deserialisePgpCert(data, pktsize); - break; - case RS_PKT_SUBTYPE_DISC_CONTACT: - return deserialiseContact(data, pktsize); - break; -#if 0 - case RS_PKT_SUBTYPE_DISC_SERVICES: - return deserialiseServices(data, pktsize); - break; -#endif - default: - return NULL; - break; - } - return NULL; -} -std::ostream &RsDiscPgpListItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsDiscPgpListItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "mode: " << mode << std::endl; - pgpIdSet.print(out, int_Indent); - - printRsItemEnd(out, "RsDiscPgpList", indent); - return out; -} - - -uint32_t RsDiscSerialiser::sizePgpList(RsDiscPgpListItem *item) -{ - uint32_t s = 8; /* header */ - s += 4; /* mode */ - s += item->pgpIdSet.TlvSize(); - return s; -} -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialisePgpList(RsDiscPgpListItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizePgpList(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialisePgpList() Header: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialisePgpList() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->mode); - ok &= item->pgpIdSet.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialisePgpList() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsDiscPgpListItem *RsDiscSerialiser::deserialisePgpList(void *data, uint32_t *pktsize) { - /* 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_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_PGP_LIST != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpList() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpList() Not Enough Space" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsDiscPgpListItem *item = new RsDiscPgpListItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->mode)); - ok &= item->pgpIdSet.GetTlv(data, rssize, &offset); - - if (offset != rssize) { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpList() offset != rssize" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpList() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -#endif - -/*************************************************************************/ -/*************************************************************************/ #if 0 RsDiscServicesItem::~RsDiscServicesItem() @@ -512,445 +290,4 @@ RsDiscServicesItem *RsDiscSerialiser::deserialiseServices(void *data, uint32_t * return item; } -RsDiscPgpCertItem::~RsDiscPgpCertItem() -{ - return; -} - -std::ostream &RsDiscPgpCertItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsDiscPgpCertItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "pgpId: " << pgpId << std::endl; - printIndent(out, int_Indent); - out << "pgpCert: " << pgpCert << std::endl; - - printRsItemEnd(out, "RsDiscPgpCert", indent); - return out; -} - - -uint32_t RsDiscSerialiser::sizePgpCert(RsDiscPgpCertItem *item) -{ - uint32_t s = 8; /* header */ - s += item->pgpId.serial_size(); - s += GetTlvStringSize(item->pgpCert); - return s; -} -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialisePgpCert(RsDiscPgpCertItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizePgpCert(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialisePgpCert() Header: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialisePgpCert() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->pgpId.serialise(data, tlvsize, offset) ; - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PGPCERT, item->pgpCert); - - if (offset != tlvsize) { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialisePgpCert() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsDiscPgpCertItem *RsDiscSerialiser::deserialisePgpCert(void *data, uint32_t *pktsize) { - /* 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_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_PGP_CERT != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpCert() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpCert() Not Enough Space" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsDiscPgpCertItem *item = new RsDiscPgpCertItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->pgpId.deserialise(data, rssize, offset) ; - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PGPCERT, item->pgpCert); - - if (offset != rssize) { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpCert() offset != rssize" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpCert() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*************************************************************************/ - - -RsDiscContactItem::~RsDiscContactItem() -{ - return; -} - -std::ostream &RsDiscContactItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsDiscContact", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "pgpId: " << pgpId << std::endl; - - printIndent(out, int_Indent); - out << "sslId: " << sslId << std::endl; - - printIndent(out, int_Indent); - out << "location: " << location << std::endl; - - printIndent(out, int_Indent); - out << "version: " << version << std::endl; - - printIndent(out, int_Indent); - out << "netMode: " << netMode << std::endl; - - printIndent(out, int_Indent); - out << "vs_disc: " << vs_disc << std::endl; - - printIndent(out, int_Indent); - out << "vs_dht: " << vs_dht << std::endl; - - printIndent(out, int_Indent); - out << "lastContact: " << lastContact << std::endl; - - if (isHidden) - { - printIndent(out, int_Indent); - out << "hiddenAddr: " << hiddenAddr << std::endl; - - printIndent(out, int_Indent); - out << "hiddenPort: " << hiddenPort << std::endl; - } - else - { - printIndent(out, int_Indent); - out << "localAddrV4: " << std::endl; - localAddrV4.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "extAddrV4: " << std::endl; - extAddrV4.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "localAddrV6: " << std::endl; - localAddrV6.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "extAddrV6: " << std::endl; - extAddrV6.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "DynDNS: " << dyndns << std::endl; - - printIndent(out, int_Indent); - out << "localAddrList: " << std::endl; - localAddrList.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "extAddrList: " << std::endl; - extAddrList.print(out, int_Indent); - } - - printRsItemEnd(out, "RsDiscContact", indent); - return out; -} - -uint32_t RsDiscSerialiser::sizeContact(RsDiscContactItem *item) -{ - uint32_t s = 8; /* header */ - s += item->pgpId.serial_size(); - s += item->sslId.serial_size(); - - s += GetTlvStringSize(item->location); - s += GetTlvStringSize(item->version); - - s += 4; // netMode - s += 2; // vs_disc - s += 2; // vs_dht - s += 4; // last contact - - if (item->isHidden) - { - s += GetTlvStringSize(item->hiddenAddr); - s += 2; /* hidden port */ - } - else - { - s += item->localAddrV4.TlvSize(); /* localaddr */ - s += item->extAddrV4.TlvSize(); /* remoteaddr */ - - s += item->currentConnectAddress.TlvSize() ; - - s += item->localAddrV6.TlvSize(); /* localaddr */ - s += item->extAddrV6.TlvSize(); /* remoteaddr */ - - s += GetTlvStringSize(item->dyndns); - - //add the size of the ip list - s += item->localAddrList.TlvSize(); - s += item->extAddrList.TlvSize(); - } - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::sizeContact() Total Size: " << s << std::endl; -#endif - - return s; -} - -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialiseContact(RsDiscContactItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeContact(item); - uint32_t offset = 0; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseContact() tlvsize: " << tlvsize; - std::cerr << std::endl; -#endif - - if (*pktsize < tlvsize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialiseContact() ERROR not enough space" << std::endl; - std::cerr << "RsDiscSerialiser::serialiseContact() ERROR *pktsize: " << *pktsize << " tlvsize: " << tlvsize; - std::cerr << std::endl; -#endif - return false; /* not enough space */ - } - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseContact() Header: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialiseContact() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->pgpId.serialise(data, tlvsize, offset) ; - ok &= item->sslId.serialise(data, tlvsize, offset) ; - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->location); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VERSION, item->version); - - ok &= setRawUInt32(data, tlvsize, &offset, item->netMode); - ok &= setRawUInt16(data, tlvsize, &offset, item->vs_disc); - ok &= setRawUInt16(data, tlvsize, &offset, item->vs_dht); - ok &= setRawUInt32(data, tlvsize, &offset, item->lastContact); /* Mandatory */ - - if (item->isHidden) - { - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DOMADDR, item->hiddenAddr); - ok &= setRawUInt16(data, tlvsize, &offset, item->hiddenPort); - } - else - { - ok &= item->localAddrV4.SetTlv(data, tlvsize, &offset); - ok &= item->extAddrV4.SetTlv(data, tlvsize, &offset); - ok &= item->localAddrV6.SetTlv(data, tlvsize, &offset); - ok &= item->extAddrV6.SetTlv(data, tlvsize, &offset); - - ok &= item->currentConnectAddress.SetTlv(data, tlvsize, &offset); - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); - - ok &= item->localAddrList.SetTlv(data, tlvsize, &offset); - ok &= item->extAddrList.SetTlv(data, tlvsize, &offset); - } - - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialiseContact() Size Error: " << tlvsize << " != " << offset << std::endl; -#endif - } - - return ok; -} - -RsDiscContactItem *RsDiscSerialiser::deserialiseContact(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() Pkt Type: " << std::hex << rstype << std::dec; - std::cerr << "RsDiscSerialiser::deserialiseContact() Pkt Size: " << rssize << std::endl; -#endif - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_CONTACT != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() Not enough space" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsDiscContactItem *item = new RsDiscContactItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->pgpId.deserialise(data, rssize, offset) ; - ok &= item->sslId.deserialise(data, rssize, offset) ; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->location); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VERSION, item->version); - - ok &= getRawUInt32(data, rssize, &offset, &(item->netMode)); /* Mandatory */ - ok &= getRawUInt16(data, rssize, &offset, &(item->vs_disc)); /* Mandatory */ - ok &= getRawUInt16(data, rssize, &offset, &(item->vs_dht)); /* Mandatory */ - ok &= getRawUInt32(data, rssize, &offset, &(item->lastContact)); - - if (rssize < offset + TLV_HEADER_SIZE) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() missized" << std::endl; -#endif - /* no extra */ - delete item; - return NULL; - } - - uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[offset]) ); - - if (tlvtype == TLV_TYPE_STR_DOMADDR) - { - item->isHidden = true; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DOMADDR, item->hiddenAddr); - ok &= getRawUInt16(data, rssize, &offset, &(item->hiddenPort)); /* Mandatory */ - - } - else - { - item->isHidden = false; - - ok &= item->localAddrV4.GetTlv(data, rssize, &offset); - ok &= item->extAddrV4.GetTlv(data, rssize, &offset); - ok &= item->localAddrV6.GetTlv(data, rssize, &offset); - ok &= item->extAddrV6.GetTlv(data, rssize, &offset); - - ok &= item->currentConnectAddress.GetTlv(data, rssize, &offset); - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); - ok &= item->localAddrList.GetTlv(data, rssize, &offset); - ok &= item->extAddrList.GetTlv(data, rssize, &offset); - } - - - if (offset != rssize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() offset != rssize" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} #endif diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index 9fc3d7e40..6dee2f2be 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -179,1114 +179,3 @@ void RsMsgTags::clear() tagIds.clear(); } -#ifdef TO_REMOVE -std::ostream &RsMsgItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "msgId (not serialised): " << msgId << std::endl; - printIndent(out, int_Indent); - out << "msgFlags: " << msgFlags << std::endl; - - printIndent(out, int_Indent); - out << "sendTime: " << sendTime << std::endl; - printIndent(out, int_Indent); - out << "recvTime: " << recvTime << std::endl; - - printIndent(out, int_Indent); - out << "Message To: " << std::endl; - rspeerid_msgto.print(out, int_Indent); - rsgxsid_msgto.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "Message CC: " << std::endl; - rspeerid_msgcc.print(out, int_Indent); - rsgxsid_msgcc.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "Message BCC: " << std::endl; - rspeerid_msgbcc.print(out, int_Indent); - rsgxsid_msgbcc.print(out, int_Indent); - - printIndent(out, int_Indent); - std::string cnv_subject(subject.begin(), subject.end()); - out << "subject: " << cnv_subject << std::endl; - - printIndent(out, int_Indent); - std::string cnv_message(message.begin(), message.end()); - out << "msg: " << cnv_message << std::endl; - - printIndent(out, int_Indent); - out << "Attachment: " << std::endl; - attachment.print(out, int_Indent); - - printRsItemEnd(out, "RsMsgItem", indent); - return out; -} -std::ostream& RsPublicMsgInviteConfigItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsPublicMsgInviteConfigItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "hash : " << hash << std::endl; - - printIndent(out, int_Indent); - out << "timt : " << time_stamp << std::endl; - - printRsItemEnd(out, "RsPublicMsgInviteConfigItem", indent); - - return out; -} -std::ostream& RsMsgTagType::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgTagType", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "rgb_color : " << rgb_color << std::endl; - - - printIndent(out, int_Indent); - out << "text: " << text << std::endl; - - printIndent(out, int_Indent); - out << "tagId: " << tagId << std::endl; - - printRsItemEnd(out, "RsMsgTagTypeItem", indent); - - return out; -} - -std::ostream& RsMsgTags::print(std::ostream &out, uint16_t indent) -{ - - printRsItemBase(out, "RsMsgTagsItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "msgId : " << msgId << std::endl; - - std::list::iterator it; - - for(it=tagIds.begin(); it != tagIds.end(); ++it) - { - printIndent(out, int_Indent); - out << "tagId : " << *it << std::endl; - } - - printRsItemEnd(out, "RsMsgTags", indent); - - return out; -} - -uint32_t RsMsgItem::serial_size(bool m_bConfiguration) -{ - uint32_t s = 8; /* header */ - s += 4; /* msgFlags */ - s += 4; /* sendTime */ - s += 4; /* recvTime */ - - s += GetTlvStringSize(subject); - s += GetTlvStringSize(message); - - s += rspeerid_msgto.TlvSize(); - s += rspeerid_msgcc.TlvSize(); - s += rspeerid_msgbcc.TlvSize(); - - s += rsgxsid_msgto.TlvSize(); - s += rsgxsid_msgcc.TlvSize(); - s += rsgxsid_msgbcc.TlvSize(); - - s += attachment.TlvSize(); - - if (m_bConfiguration) { - // serialise msgId too - s += 4; - } - - return s; -} - -/* serialise the data to the buffer */ -bool RsMsgItem::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size( config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, msgFlags); - ok &= setRawUInt32(data, tlvsize, &offset, sendTime); - ok &= setRawUInt32(data, tlvsize, &offset, recvTime); - - ok &= SetTlvString(data,tlvsize,&offset,TLV_TYPE_STR_SUBJECT,subject); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, message); - - ok &= rspeerid_msgto.SetTlv(data, tlvsize, &offset); - ok &= rspeerid_msgcc.SetTlv(data, tlvsize, &offset); - ok &= rspeerid_msgbcc.SetTlv(data, tlvsize, &offset); - - ok &= rsgxsid_msgto.SetTlv(data, tlvsize, &offset); - ok &= rsgxsid_msgcc.SetTlv(data, tlvsize, &offset); - ok &= rsgxsid_msgbcc.SetTlv(data, tlvsize, &offset); - - ok &= attachment.SetTlv(data, tlvsize, &offset); - - if (config) // serialise msgId too - ok &= setRawUInt32(data, tlvsize, &offset, msgId); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseItem() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgItem *RsMsgSerialiser::deserialiseMsgItem(void *data, uint32_t *pktsize) -{ - /* 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_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgItem *item = new RsMsgItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->msgFlags)); - ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime)); - ok &= getRawUInt32(data, rssize, &offset, &(item->recvTime)); - - ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_SUBJECT,item->subject); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message); - - ok &= item->rspeerid_msgto.GetTlv(data, rssize, &offset); - ok &= item->rspeerid_msgcc.GetTlv(data, rssize, &offset); - ok &= item->rspeerid_msgbcc.GetTlv(data, rssize, &offset); - ok &= item->rsgxsid_msgto.GetTlv(data, rssize, &offset); - ok &= item->rsgxsid_msgcc.GetTlv(data, rssize, &offset); - ok &= item->rsgxsid_msgbcc.GetTlv(data, rssize, &offset); - - ok &= item->attachment.GetTlv(data, rssize, &offset); - - if (m_bConfiguration) { - // deserialise msgId too - // ok &= getRawUInt32(data, rssize, &offset, &(item->msgId)); - getRawUInt32(data, rssize, &offset, &(item->msgId)); //use this line for backward compatibility - } - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} -uint32_t RsPublicMsgInviteConfigItem::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += GetTlvStringSize(hash); - s += 4; /* time_stamp */ - - return s; -} - -uint32_t RsMsgTagType::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += GetTlvStringSize(text); - s += 4; /* color */ - s += 4; /* tag id */ - - return s; -} -bool RsPublicMsgInviteConfigItem::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size(config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_HASH_SHA1, hash); - ok &= setRawUInt32(data,tlvsize,&offset, time_stamp); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl; - } - - return ok; -} -bool RsMsgTagType::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size( config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_NAME, text); - ok &= setRawUInt32(data, tlvsize, &offset, rgb_color); - ok &= setRawUInt32(data, tlvsize, &offset, tagId); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl; - } - - return ok; -} -RsPublicMsgInviteConfigItem* RsMsgSerialiser::deserialisePublicMsgInviteConfigItem(void *data,uint32_t* pktsize) -{ - /* 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_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_INVITE != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsPublicMsgInviteConfigItem *item = new RsPublicMsgInviteConfigItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_HASH_SHA1,item->hash); - - uint32_t ts ; - ok &= getRawUInt32(data, rssize, &offset, &ts) ; - item->time_stamp = ts ; - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - - -RsMsgTagType* RsMsgSerialiser::deserialiseTagItem(void *data,uint32_t* pktsize) -{ - /* 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_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_TAG_TYPE != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgTagType *item = new RsMsgTagType(); - item->clear(); - - /* skip the header */ - offset += 8; - - - /* get mandatory parts first */ - ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_NAME,item->text); - ok &= getRawUInt32(data, rssize, &offset, &(item->rgb_color)); - ok &= getRawUInt32(data, rssize, &offset, &(item->tagId)); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -uint32_t RsMsgTags::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += 4; /* msgId */ - s += tagIds.size() * 4; /* tagIds */ - - return s; -} -bool RsMsgTags::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size( config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data,tlvsize,&offset, msgId); - - std::list::iterator mit = tagIds.begin(); - for(;mit != tagIds.end(); ++mit) - ok &= setRawUInt32(data, tlvsize, &offset, *mit); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgTags* RsMsgSerialiser::deserialiseMsgTagItem(void* data, uint32_t* pktsize) -{ - /* 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_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_TAGS != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgTags *item = new RsMsgTags(); - item->clear(); - - /* skip the header */ - offset += 8; - - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &item->msgId); - - uint32_t tagId; - while (offset != rssize) - { - tagId = 0; - - ok &= getRawUInt32(data, rssize, &offset, &tagId); - - item->tagIds.push_back(tagId); - } - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - - -/************************************** Message SrcId **********************/ - -std::ostream& RsMsgSrcId::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgSrcIdItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "msgId : " << msgId << std::endl; - - printIndent(out, int_Indent); - out << "SrcId: " << srcId << std::endl; - - - printRsItemEnd(out, "RsMsgItem", indent); - - return out; -} - -void RsMsgSrcId::clear() -{ - msgId = 0; - srcId.clear(); - - return; -} - -uint32_t RsMsgSrcId::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += 4; - s += srcId.serial_size() ; - - return s; -} -bool RsMsgSrcId::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size(config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data, tlvsize, &offset, msgId); - ok &= srcId.serialise(data, tlvsize, offset) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgSrcId* RsMsgSerialiser::deserialiseMsgSrcIdItem(void* data, uint32_t* pktsize) -{ - /* 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_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_SRC_TAG != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgSrcId *item = new RsMsgSrcId(); - item->clear(); - - /* skip the header */ - offset += 8; - - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->msgId)); - ok &= item->srcId.deserialise(data, rssize, offset); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/************************* end of definition of msgSrcId serialisation functions ************************/ - -std::ostream& RsMsgGRouterMap::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgGRouterMap", indent); - uint16_t int_Indent = indent + 2; - - for(std::map::const_iterator it(ongoing_msgs.begin());it!=ongoing_msgs.end();++it) - { - printIndent(out, int_Indent); - out << " " << std::hex << it->first << std::dec << " : " << it->second << std::endl; - } - - printRsItemEnd(out, "RsMsgGRouterMap", indent); - - return out; -} -uint32_t RsMsgGRouterMap::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += 4; // number of entries - s += (8+4)*ongoing_msgs.size(); // entries - - return s; -} - -bool RsMsgGRouterMap::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size( config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data, tlvsize, &offset, ongoing_msgs.size()); - - for(std::map::const_iterator it=ongoing_msgs.begin();ok && it!=ongoing_msgs.end();++it) - { - ok &= setRawUInt64(data, tlvsize, &offset, it->first); - ok &= setRawUInt32(data, tlvsize, &offset, it->second); - } - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgGRouterMap() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgGRouterMap* RsMsgSerialiser::deserialiseMsgGRouterMap(void* data, uint32_t* pktsize) -{ - /* 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_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_GROUTER_MAP != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgGRouterMap *item = new RsMsgGRouterMap(); - item->clear(); - - /* skip the header */ - offset += 8; - - uint32_t s=0 ; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &s); - - for(uint32_t i=0;iongoing_msgs.insert(std::make_pair(routing_id,mid)) ; - } - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/************************* end of definition of msgGRouterMap serialisation functions ************************/ - -/************************* definition of msgDistantMessageMap serialisation functions ************************/ - -std::ostream& RsMsgDistantMessagesHashMap::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgDistantMessagesHashMap", indent); - uint16_t int_Indent = indent + 2; - - for(std::map::const_iterator it(hash_map.begin());it!=hash_map.end();++it) - { - printIndent(out, int_Indent); - out << " " << std::hex << it->first << std::dec << " : " << it->second << std::endl; - } - - printRsItemEnd(out, "RsMsgDistantMessagesHashMap", indent); - - return out; -} - -void RsMsgDistantMessagesHashMap::clear() -{ - hash_map.clear() ; - - return; -} - -uint32_t RsMsgDistantMessagesHashMap::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += 4; // number of entries - s += (Sha1CheckSum::SIZE_IN_BYTES+4)*hash_map.size(); // entries - - return s; -} -bool RsMsgDistantMessagesHashMap::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size(config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgDistantMessagesHashMap() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgDistantMessagesHashMap() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data, tlvsize, &offset, hash_map.size()); - - for(std::map::const_iterator it=hash_map.begin();ok && it!=hash_map.end();++it) - { - ok &= it->first.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, it->second); - } - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgDistantMessagesHashMap() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgDistantMessagesHashMap* RsMsgSerialiser::deserialiseMsgDistantMessageHashMap(void* data, uint32_t* pktsize) -{ - /* 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_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgDistantMessagesHashMap *item = new RsMsgDistantMessagesHashMap(); - item->clear(); - - /* skip the header */ - offset += 8; - - uint32_t s=0 ; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &s); - - for(uint32_t i=0;ihash_map.insert(std::make_pair(s,tm)) ; - } - - if (offset != rssize) - { - /* error */ - std::cerr << "(EE) size error in packet deserialisation: p3MsgItem, subtype " << getRsItemSubType(rstype) << ". offset=" << offset << " != rssize=" << rssize << std::endl; - delete item; - return NULL; - } - - if (!ok) - { - std::cerr << "(EE) size error in packet deserialisation: p3MsgItem, subtype " << getRsItemSubType(rstype) << std::endl; - delete item; - return NULL; - } - - return item; -} -/************************************** Message ParentId **********************/ - -std::ostream& RsMsgParentId::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgParentIdItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "msgId : " << msgId << std::endl; - - printIndent(out, int_Indent); - out << "msgParentId: " << msgParentId << std::endl; - - - printRsItemEnd(out, "RsMsgParentId", indent); - - return out; -} - -void RsMsgParentId::clear() -{ - msgId = 0; - msgParentId = 0; - - return; -} - -uint32_t RsMsgParentId::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += 4; // srcId - s += 4; // msgParentId - - return s; -} -bool RsMsgParentId::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size( config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data, tlvsize, &offset, msgId); - ok &= setRawUInt32(data, tlvsize, &offset, msgParentId); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgParentId* RsMsgSerialiser::deserialiseMsgParentIdItem(void* data, uint32_t* pktsize) -{ - /* 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_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_PARENT_TAG != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgParentId *item = new RsMsgParentId(); - item->clear(); - - /* skip the header */ - offset += 8; - - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->msgId)); - ok &= getRawUInt32(data, rssize, &offset, &(item->msgParentId)); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/************************* end of definition of msgParentId serialisation functions ************************/ - -RsItem* RsMsgSerialiser::deserialise(void *data, uint32_t *pktsize) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::deserialise()" << std::endl; -#endif - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_MSG != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_DEFAULT: return deserialiseMsgItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_SRC_TAG: return deserialiseMsgSrcIdItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_PARENT_TAG: return deserialiseMsgParentIdItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_TAG_TYPE: return deserialiseTagItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_INVITE: return deserialisePublicMsgInviteConfigItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_TAGS: return deserialiseMsgTagItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_GROUTER_MAP: return deserialiseMsgGRouterMap(data, pktsize); - case RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP: return deserialiseMsgDistantMessageHashMap(data, pktsize); - default: - return NULL; - break; - } - - return NULL; -} - - -/*************************************************************************/ - -#endif - -