mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
save/load public msg invites. Small bug fixes.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6358 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
cc6555b93f
commit
a8d4c02a6e
@ -1382,6 +1382,26 @@ void RsMsgTagType::clear()
|
||||
}
|
||||
|
||||
|
||||
void RsPublicMsgInviteConfigItem::clear()
|
||||
{
|
||||
hash.clear() ;
|
||||
time_stamp = 0 ;
|
||||
}
|
||||
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;
|
||||
}
|
||||
void RsMsgTags::clear()
|
||||
{
|
||||
msgId = 0;
|
||||
@ -1580,7 +1600,15 @@ RsMsgItem *RsMsgSerialiser::deserialiseMsgItem(void *data, uint32_t *pktsize)
|
||||
|
||||
return item;
|
||||
}
|
||||
uint32_t RsMsgSerialiser::sizePublicMsgInviteConfigItem(RsPublicMsgInviteConfigItem* item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += GetTlvStringSize(item->hash);
|
||||
s += 4; /* time_stamp */
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsMsgSerialiser::sizeTagItem(RsMsgTagType* item)
|
||||
{
|
||||
@ -1593,6 +1621,44 @@ uint32_t RsMsgSerialiser::sizeTagItem(RsMsgTagType* item)
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsMsgSerialiser::serialisePublicMsgInviteConfigItem(RsPublicMsgInviteConfigItem *item, void *data, uint32_t* pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizePublicMsgInviteConfigItem(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 << "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, item->hash);
|
||||
ok &= setRawUInt32(data,tlvsize,&offset, item->time_stamp);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool RsMsgSerialiser::serialiseTagItem(RsMsgTagType *item, void *data, uint32_t* pktsize)
|
||||
{
|
||||
@ -1632,6 +1698,59 @@ bool RsMsgSerialiser::serialiseTagItem(RsMsgTagType *item, void *data, uint32_t*
|
||||
|
||||
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)
|
||||
{
|
||||
@ -2110,7 +2229,7 @@ bool RsMsgSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
RsMsgParentId* msp;
|
||||
RsMsgTagType *mtt;
|
||||
RsMsgTags *mts;
|
||||
|
||||
RsPublicMsgInviteConfigItem *mtu;
|
||||
|
||||
if (NULL != (mi = dynamic_cast<RsMsgItem *>(i)))
|
||||
{
|
||||
@ -2132,6 +2251,10 @@ bool RsMsgSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
return serialiseMsgTagItem(mts, data, pktsize);
|
||||
}
|
||||
else if (NULL != (mtu = dynamic_cast<RsPublicMsgInviteConfigItem *>(i)))
|
||||
{
|
||||
return serialisePublicMsgInviteConfigItem(mtu, data, pktsize);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -2165,6 +2288,9 @@ RsItem* RsMsgSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
case RS_PKT_SUBTYPE_MSG_TAG_TYPE:
|
||||
return deserialiseTagItem(data, pktsize);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_MSG_INVITE:
|
||||
return deserialisePublicMsgInviteConfigItem(data, pktsize);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_MSG_TAGS:
|
||||
return deserialiseMsgTagItem(data, pktsize);
|
||||
break;
|
||||
|
@ -71,7 +71,7 @@ const uint8_t RS_PKT_SUBTYPE_MSG_TAG_TYPE = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_TAGS = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_SRC_TAG = 0x05;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_PARENT_TAG = 0x06;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_ENCRYPTED = 0x07;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_INVITE = 0x07;
|
||||
|
||||
typedef uint64_t ChatLobbyId ;
|
||||
typedef uint64_t ChatLobbyMsgId ;
|
||||
@ -444,36 +444,6 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsTlvFileSet attachment;
|
||||
};
|
||||
|
||||
// // Encrypted messages encapsulate a whole RsMsgItem into the binary data. The signature is optional.
|
||||
// // There is no To or CC peers since the whole communiation addresses are obfuscated in the encrypted
|
||||
// // layer, and because of public key encryption, the email can only have one destination peer.
|
||||
// //
|
||||
// class RsEncryptedMsgItem: public RsItem
|
||||
// {
|
||||
// public:
|
||||
// RsEncryptedMsgItem()
|
||||
// :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG, RS_PKT_SUBTYPE_MSG_ENCRYPTED)
|
||||
// {
|
||||
// setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ;
|
||||
// }
|
||||
//
|
||||
// // RsEncryptedMsgItem(uint16_t type)
|
||||
// // :RsItem(RS_PKT_VERSION_SERVICE, type, RS_PKT_SUBTYPE_DEFAULT)
|
||||
// // {
|
||||
// // setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ;
|
||||
// // }
|
||||
//
|
||||
// virtual ~RsEncryptedMsgItem();
|
||||
// virtual void clear();
|
||||
// std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
//
|
||||
// uint32_t msgId;
|
||||
// unsigned char *encrypted_bin_data ;
|
||||
// uint32_t encrypted_bin_size ;
|
||||
// unsigned char *signature_bin_data ;
|
||||
// uint32_t signature_bin_size ;
|
||||
// };
|
||||
|
||||
class RsMsgTagType : public RsItem
|
||||
{
|
||||
public:
|
||||
@ -530,6 +500,24 @@ public:
|
||||
std::string srcId;
|
||||
|
||||
};
|
||||
class RsPublicMsgInviteConfigItem : public RsItem
|
||||
{
|
||||
|
||||
public:
|
||||
RsPublicMsgInviteConfigItem()
|
||||
: RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG,
|
||||
RS_PKT_SUBTYPE_MSG_INVITE)
|
||||
{ return;}
|
||||
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual ~RsPublicMsgInviteConfigItem() {}
|
||||
virtual void clear();
|
||||
|
||||
std::string hash ;
|
||||
time_t time_stamp ;
|
||||
};
|
||||
|
||||
|
||||
class RsMsgParentId : public RsItem
|
||||
{
|
||||
@ -591,9 +579,9 @@ class RsMsgSerialiser: public RsSerialType
|
||||
virtual bool serialiseMsgParentIdItem (RsMsgParentId *item, void *data, uint32_t *size);
|
||||
virtual RsMsgParentId *deserialiseMsgParentIdItem(void *data, uint32_t *size);
|
||||
|
||||
// virtual uint32_t sizeEncryptedMsgItem(RsEncryptedMsgItem *) ;
|
||||
// virtual bool serialiseEncryptedMsgItem(RsEncryptedMsgItem *item, void *data, uint32_t *size);
|
||||
// virtual RsEncryptedMsgItem *deserialiseEncryptedMsgItem(void *data, uint32_t *size);
|
||||
virtual uint32_t sizePublicMsgInviteConfigItem(RsPublicMsgInviteConfigItem *) ;
|
||||
virtual bool serialisePublicMsgInviteConfigItem(RsPublicMsgInviteConfigItem *item, void *data, uint32_t *size);
|
||||
virtual RsPublicMsgInviteConfigItem *deserialisePublicMsgInviteConfigItem(void *data, uint32_t *size);
|
||||
|
||||
bool m_bConfiguration; // is set to true for saving configuration (enables serialising msgId)
|
||||
};
|
||||
|
@ -383,6 +383,14 @@ bool p3MsgService::saveList(bool& cleanup, std::list<RsItem*>& itemList)
|
||||
for(mit4 = mParentId.begin(); mit4 != mParentId.end(); mit4++)
|
||||
itemList.push_back(mit4->second);
|
||||
|
||||
for(std::map<std::string,DistantMessengingInvite>::const_iterator it(_messenging_invites.begin());it!=_messenging_invites.end();++it)
|
||||
{
|
||||
RsPublicMsgInviteConfigItem *item = new RsPublicMsgInviteConfigItem ;
|
||||
item->hash = it->first ;
|
||||
item->time_stamp = it->second.time_of_validity ;
|
||||
|
||||
itemList.push_back(item) ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -447,6 +455,7 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
|
||||
RsMsgTags* mti;
|
||||
RsMsgSrcId* msi;
|
||||
RsMsgParentId* msp;
|
||||
RsPublicMsgInviteConfigItem* msv;
|
||||
|
||||
std::list<RsMsgItem*> items;
|
||||
std::list<RsItem*>::iterator it;
|
||||
@ -468,18 +477,18 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
|
||||
items.push_back(mitem);
|
||||
}
|
||||
else if(NULL != (mtt = dynamic_cast<RsMsgTagType *>(*it)))
|
||||
{
|
||||
// delete standard tags as they are now save in config
|
||||
if(mTags.end() == (tagIt = mTags.find(mtt->tagId)))
|
||||
{
|
||||
mTags.insert(std::pair<uint32_t, RsMsgTagType* >(mtt->tagId, mtt));
|
||||
}
|
||||
else
|
||||
{
|
||||
delete mTags[mtt->tagId];
|
||||
mTags.erase(tagIt);
|
||||
mTags.insert(std::pair<uint32_t, RsMsgTagType* >(mtt->tagId, mtt));
|
||||
}
|
||||
{
|
||||
// delete standard tags as they are now save in config
|
||||
if(mTags.end() == (tagIt = mTags.find(mtt->tagId)))
|
||||
{
|
||||
mTags.insert(std::pair<uint32_t, RsMsgTagType* >(mtt->tagId, mtt));
|
||||
}
|
||||
else
|
||||
{
|
||||
delete mTags[mtt->tagId];
|
||||
mTags.erase(tagIt);
|
||||
mTags.insert(std::pair<uint32_t, RsMsgTagType* >(mtt->tagId, mtt));
|
||||
}
|
||||
|
||||
}
|
||||
else if(NULL != (mti = dynamic_cast<RsMsgTags *>(*it)))
|
||||
@ -495,6 +504,10 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
|
||||
{
|
||||
mParentId.insert(std::pair<uint32_t, RsMsgParentId*>(msp->msgId, msp));
|
||||
}
|
||||
else if(NULL != (msv = dynamic_cast<RsPublicMsgInviteConfigItem *>(*it)))
|
||||
{
|
||||
_messenging_invites[msv->hash].time_of_validity = msv->time_stamp ;
|
||||
}
|
||||
}
|
||||
|
||||
// sort items into lists
|
||||
@ -1702,6 +1715,8 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
||||
}
|
||||
delete item ;
|
||||
|
||||
IndicateConfigChanged() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
@ -1724,6 +1739,8 @@ bool p3MsgService::createDistantOfflineMessengingInvite(time_t time_of_validity,
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
_messenging_invites[hash] = invite ;
|
||||
}
|
||||
IndicateConfigChanged() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool p3MsgService::getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites)
|
||||
|
@ -122,7 +122,6 @@ void CreateMsgLinkDialog::update()
|
||||
}
|
||||
|
||||
std::vector<DistantOfflineMessengingInvite> invites2 ;
|
||||
|
||||
rsMsgs->getDistantOfflineMessengingInvites(invites2) ;
|
||||
|
||||
for(uint32_t i=0;i<invites2.size();++i)
|
||||
@ -134,7 +133,7 @@ void CreateMsgLinkDialog::update()
|
||||
else
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
item->setData(Qt::DisplayRole,tr("Private chat invite to ")+QString::fromStdString(invites2[i].issuer_pgp_id)) ;
|
||||
item->setData(Qt::DisplayRole,tr("Public message link")) ;
|
||||
item->setData(Qt::UserRole,link.toString()) ;
|
||||
|
||||
_existing_links_LW->insertItem(0,item) ;
|
||||
|
@ -17,7 +17,14 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QListWidget" name="_existing_links_LW"/>
|
||||
<widget class="QListWidget" name="_existing_links_LW">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
@ -182,6 +189,13 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="_create_link_PB">
|
||||
<property name="text">
|
||||
<string>Create!</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
@ -196,27 +210,6 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="_create_link_PB">
|
||||
<property name="text">
|
||||
<string>Create!</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Link:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -1490,6 +1490,8 @@ void MessagesDialog::decryptSelectedMsg()
|
||||
|
||||
//setMsgAsReadUnread(currentIndex.row(), true);
|
||||
updateMessageSummaryList();
|
||||
insertMessages();
|
||||
insertMsgTxtAndFiles();
|
||||
}
|
||||
|
||||
bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid)
|
||||
|
Loading…
Reference in New Issue
Block a user