From 269f9457bebd4881831f908dc5cc2a5183722f0d Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 6 Jul 2016 22:02:56 -0400 Subject: [PATCH] fixed load/save of new group ids and backward compatibility with FriendList --- libretroshare/src/pqi/p3peermgr.cc | 19 ++++- libretroshare/src/serialiser/rsconfigitems.cc | 77 +++++++++++++++---- libretroshare/src/serialiser/rsconfigitems.h | 7 +- retroshare-gui/src/gui/common/FriendList.cpp | 12 ++- retroshare-gui/src/gui/common/GroupDefs.cpp | 2 +- retroshare-gui/src/gui/groups/CreateGroup.cpp | 9 ++- retroshare-gui/src/gui/groups/CreateGroup.ui | 38 +++++---- 7 files changed, 124 insertions(+), 40 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index c54019100..c12692d28 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -2065,7 +2065,10 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) /* save groups */ for ( std::map::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) - saveData.push_back(new RsNodeGroupItem(groupIt->second)); // no delete + { + RsNodeGroupItem *itm = new RsNodeGroupItem(groupIt->second); + saveData.push_back(itm) ; + } return true; } @@ -2311,9 +2314,13 @@ bool p3PeerMgrIMPL::loadList(std::list& load) if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAVORITES)) ginfo.id = RS_GROUP_ID_FAVORITES ; if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_OTHERS )) ginfo.id = RS_GROUP_ID_OTHERS ; - groupList[ginfo.id] = ginfo ; - - std::cerr << "(II) Creating new group for old format local group \"" << gitem->name << "\". Id=" << ginfo.id << std::endl; + if(!ginfo.id.isNull()) + { + groupList[ginfo.id] = ginfo ; + std::cerr << "(II) Creating new group for old format local group \"" << gitem->name << "\". Id=" << ginfo.id << std::endl; + } + else + std::cerr << "(EE) no group corresponding to old format group with ID=\"" << gitem->id << "\"" << std::endl; continue; } @@ -2335,6 +2342,7 @@ bool p3PeerMgrIMPL::loadList(std::list& load) info.name = gitem2->name ; info.flag = gitem2->flag ; + std::cerr << "(II) Loaded group in new format. ID = " << info.id << std::endl; groupList[info.id] = info ; continue; @@ -2483,6 +2491,8 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo) groupItem.flag &= ~RS_GROUP_FLAG_STANDARD; groupList[groupInfo.id] = groupItem; + + std::cerr << "(II) Added new group with ID " << groupInfo.id << ", name=\"" << groupInfo.name << "\"" << std::endl; } RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD); @@ -2586,6 +2596,7 @@ bool p3PeerMgrIMPL::getGroupInfoByName(const std::string& groupName, RsGroupInfo return true ; } + std::cerr << "(EE) getGroupInfoByName: no known group for name " << groupName << std::endl; return false ; } bool p3PeerMgrIMPL::getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo &groupInfo) diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index db0aa5dcf..20430aae3 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -750,7 +750,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i) { RsPeerStunItem *psi; RsPeerNetItem *pni; - RsPeerGroupItem_deprecated *pgi; + RsNodeGroupItem *pgi; RsPeerServicePermissionItem *pri; RsPeerBandwidthLimitsItem *pblitem; @@ -762,7 +762,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i) { return sizeStun(psi); } - else if (NULL != (pgi = dynamic_cast(i))) + else if (NULL != (pgi = dynamic_cast(i))) { return sizeGroup(pgi); } @@ -783,7 +783,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi { RsPeerNetItem *pni; RsPeerStunItem *psi; - RsPeerGroupItem_deprecated *pgi; + RsNodeGroupItem *pgi; RsPeerServicePermissionItem *pri; RsPeerBandwidthLimitsItem *pblitem; @@ -795,7 +795,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi { return serialiseStun(psi, data, pktsize); } - else if (NULL != (pgi = dynamic_cast(i))) + else if (NULL != (pgi = dynamic_cast(i))) { return serialiseGroup(pgi, data, pktsize); } @@ -833,8 +833,10 @@ RsItem *RsPeerConfigSerialiser::deserialise(void *data, uint32_t *pktsize) case RS_PKT_SUBTYPE_PEER_STUN: return deserialiseStun(data, pktsize); case RS_PKT_SUBTYPE_PEER_GROUP_deprecated: - return deserialiseGroup(data, pktsize); - case RS_PKT_SUBTYPE_PEER_PERMISSIONS: + return deserialiseGroup_deprecated(data, pktsize); + case RS_PKT_SUBTYPE_NODE_GROUP: + return deserialiseGroup(data, pktsize); + case RS_PKT_SUBTYPE_PEER_PERMISSIONS: return deserialisePermissions(data, pktsize); case RS_PKT_SUBTYPE_PEER_BANDLIMITS: return deserialisePeerBandwidthLimits(data, pktsize); @@ -1469,20 +1471,67 @@ std::ostream &RsPeerGroupItem_deprecated::print(std::ostream &out, uint16_t inde return out; } +RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup_deprecated(void *data, uint32_t *size) +{ + /* get the type and size */ + uint32_t rstype = getRsItemId(data); + uint32_t rssize = getRsItemSize(data); + + uint32_t offset = 0; + + if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || + (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || + (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || + (RS_PKT_SUBTYPE_PEER_GROUP_deprecated != getRsItemSubType(rstype))) + { + return NULL; /* wrong type */ + } + + if (*size < rssize) /* check size */ + return NULL; /* not enough data */ + + /* set the packet length */ + *size = rssize; + + bool ok = true; + + RsPeerGroupItem_deprecated *item = new RsPeerGroupItem_deprecated(); + item->clear(); + + /* skip the header */ + offset += 8; + + /* get mandatory parts first */ + uint32_t version; + ok &= getRawUInt32(data, rssize, &offset, &version); + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, item->id); + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name); + ok &= getRawUInt32(data, rssize, &offset, &(item->flag)); + ok &= item->pgpList.GetTlv(data, rssize, &offset); + + if (offset != rssize) + { + /* error */ + delete item; + return NULL; + } + + return item; +} /*************************************************************************/ -uint32_t RsPeerConfigSerialiser::sizeGroup(RsPeerGroupItem_deprecated *i) +uint32_t RsPeerConfigSerialiser::sizeGroup(RsNodeGroupItem *i) { uint32_t s = 8; /* header */ s += 4; /* version */ - s += GetTlvStringSize(i->id); + s += RsNodeGroupId::serial_size(); s += GetTlvStringSize(i->name); s += 4; /* flag */ s += i->pgpList.TlvSize(); return s; } -bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem_deprecated *item, void *data, uint32_t *size) +bool RsPeerConfigSerialiser::serialiseGroup(RsNodeGroupItem *item, void *data, uint32_t *size) { uint32_t tlvsize = RsPeerConfigSerialiser::sizeGroup(item); uint32_t offset = 0; @@ -1508,7 +1557,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem_deprecated *item, vo /* add mandatory parts first */ ok &= setRawUInt32(data, tlvsize, &offset, 0); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_KEY, item->id); + ok &= item->id.serialise(data, tlvsize, offset); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name); ok &= setRawUInt32(data, tlvsize, &offset, item->flag); ok &= item->pgpList.SetTlv(data, tlvsize, &offset); @@ -1524,7 +1573,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem_deprecated *item, vo return ok; } -RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size) +RsNodeGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size) { /* get the type and size */ uint32_t rstype = getRsItemId(data); @@ -1535,7 +1584,7 @@ RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup(void *data, if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_PEER_GROUP_deprecated != getRsItemSubType(rstype))) + (RS_PKT_SUBTYPE_NODE_GROUP != getRsItemSubType(rstype))) { return NULL; /* wrong type */ } @@ -1548,7 +1597,7 @@ RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup(void *data, bool ok = true; - RsPeerGroupItem_deprecated *item = new RsPeerGroupItem_deprecated(); + RsNodeGroupItem *item = new RsNodeGroupItem(); item->clear(); /* skip the header */ @@ -1557,7 +1606,7 @@ RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup(void *data, /* get mandatory parts first */ uint32_t version; ok &= getRawUInt32(data, rssize, &offset, &version); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, item->id); + ok &= item->id.deserialise(data, rssize, offset); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name); ok &= getRawUInt32(data, rssize, &offset, &(item->flag)); ok &= item->pgpList.GetTlv(data, rssize, &offset); diff --git a/libretroshare/src/serialiser/rsconfigitems.h b/libretroshare/src/serialiser/rsconfigitems.h index 33ee08891..3d3d50a97 100644 --- a/libretroshare/src/serialiser/rsconfigitems.h +++ b/libretroshare/src/serialiser/rsconfigitems.h @@ -222,9 +222,10 @@ virtual uint32_t sizeStun(RsPeerStunItem *); virtual bool serialiseStun (RsPeerStunItem *item, void *data, uint32_t *size); virtual RsPeerStunItem * deserialiseStun(void *data, uint32_t *size); -virtual uint32_t sizeGroup(RsPeerGroupItem_deprecated *); -virtual bool serialiseGroup (RsPeerGroupItem_deprecated *item, void *data, uint32_t *size); -virtual RsPeerGroupItem_deprecated * deserialiseGroup(void *data, uint32_t *size); +virtual uint32_t sizeGroup(RsNodeGroupItem *); +virtual bool serialiseGroup (RsNodeGroupItem *item, void *data, uint32_t *size); +virtual RsNodeGroupItem *deserialiseGroup(void *data, uint32_t *size); +virtual RsPeerGroupItem_deprecated * deserialiseGroup_deprecated(void *data, uint32_t *size); virtual uint32_t sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *); virtual bool serialisePeerBandwidthLimits (RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size); diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index 6f0b8d05b..47b5c67ed 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -217,7 +217,17 @@ void FriendList::processSettings(bool load) int arrayIndex = Settings->beginReadArray("Groups"); for (int index = 0; index < arrayIndex; ++index) { Settings->setArrayIndex(index); - addGroupToExpand(RsNodeGroupId(Settings->value("open").toString().toStdString())); + + std::string gids = Settings->value("open").toString().toStdString(); + + RsGroupInfo ginfo ; + + if(rsPeers->getGroupInfoByName(gids,ginfo)) // backward compatibility + addGroupToExpand(ginfo.id) ; + else if(rsPeers->getGroupInfo(RsNodeGroupId(gids),ginfo)) // backward compatibility + addGroupToExpand(ginfo.id) ; + else + std::cerr << "(EE) Cannot find group info for openned group \"" << gids << "\"" << std::endl; } Settings->endArray(); } else { diff --git a/retroshare-gui/src/gui/common/GroupDefs.cpp b/retroshare-gui/src/gui/common/GroupDefs.cpp index 2b493124e..8a5e85ecd 100644 --- a/retroshare-gui/src/gui/common/GroupDefs.cpp +++ b/retroshare-gui/src/gui/common/GroupDefs.cpp @@ -51,7 +51,7 @@ const QString GroupDefs::name(const RsGroupInfo &groupInfo) return qApp->translate("GroupDefs", "Favorites"); } - std::cerr << "GroupDefs::name: Unknown group id requested " << groupInfo.id; + std::cerr << "GroupDefs::name: Unknown group id requested " << groupInfo.id << std::endl; return ""; } diff --git a/retroshare-gui/src/gui/groups/CreateGroup.cpp b/retroshare-gui/src/gui/groups/CreateGroup.cpp index 3fef40542..913b86a38 100644 --- a/retroshare-gui/src/gui/groups/CreateGroup.cpp +++ b/retroshare-gui/src/gui/groups/CreateGroup.cpp @@ -45,6 +45,11 @@ CreateGroup::CreateGroup(const RsNodeGroupId &groupId, QWidget *parent) mGroupId = groupId; + if(!mGroupId.isNull()) + ui.groupId_LE->setText(QString::fromStdString(mGroupId.toStdString())) ; + else + ui.groupId_LE->setText(tr("To be defined")) ; + /* Initialize friends list */ ui.friendList->setHeaderText(tr("Friends")); ui.friendList->setModus(FriendSelectionWidget::MODUS_CHECK); @@ -104,9 +109,9 @@ CreateGroup::~CreateGroup() void CreateGroup::groupNameChanged(QString text) { if (text.isEmpty() || mUsedGroupNames.contains(misc::removeNewLine(text))) { - ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } else { - ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } } diff --git a/retroshare-gui/src/gui/groups/CreateGroup.ui b/retroshare-gui/src/gui/groups/CreateGroup.ui index 3eb4bc2fd..7abcd5a4e 100644 --- a/retroshare-gui/src/gui/groups/CreateGroup.ui +++ b/retroshare-gui/src/gui/groups/CreateGroup.ui @@ -6,8 +6,8 @@ 0 0 - 386 - 298 + 575 + 485 @@ -23,9 +23,6 @@ 0 - - - @@ -36,27 +33,35 @@ - - - 6 - - - 0 - - + + - Group Name + Group Name: - + Enter a name for your group + + + + Group ID: + + + + + + + true + + + @@ -79,6 +84,9 @@ + + +