Change ChatroomInfo to contain more information
Change-Id: Ie91ced5dd9be51c8d59a0c5d881967658a58fd15
diff --git a/src/chatroom-info.cpp b/src/chatroom-info.cpp
index 2b23719..f6b81e3 100644
--- a/src/chatroom-info.cpp
+++ b/src/chatroom-info.cpp
@@ -27,27 +27,62 @@
{
size_t totalLength = 0;
- //Chatroom := CHATROOM-TYPE TLV-LENGTH
- // TrustModel
- // Participant+
+ // ChatroomInfo := CHATROOM-INFO-TYPE TLV-LENGTH
+ // ChatroomName
+ // TrustModel
+ // ChatroomPrefix
+ // ManagerPrefix
+ // Participants
+ //
+ // ChatroomName := CHATROOM-NAME-TYPE TLV-LENGTH
+ // NameComponent
+ //
+ // TrustModel := TRUST-MODEL-TYPE TLV-LENGTH
+ // nonNegativeInteger
+ //
+ // ChatroomPrefix := CHATROOM-PREFIX-TYPE TLV-LENGTH
+ // Name
+ //
+ // ManagerPrefix := MANAGER-PREFIX-TYPE TLV-LENGTH
+ // Name
+ //
+ // Participants := PARTICIPANTS-TYPE TLV-LENGTH
+ // Name+
- //Participants
- for (std::vector<Name>::const_reverse_iterator it = m_participants.rbegin();
+ // Participants
+ size_t participantsLength = 0;
+ for (std::list<Name>::const_reverse_iterator it = m_participants.rbegin();
it != m_participants.rend(); ++it) {
- size_t entryLength = 0;
-
- entryLength += it->wireEncode(block);
- entryLength += block.prependVarNumber(entryLength);
- entryLength += block.prependVarNumber(tlv::PARTICIPANT);
- totalLength += entryLength;
+ participantsLength += it->wireEncode(block);
}
+ participantsLength += block.prependVarNumber(participantsLength);
+ participantsLength += block.prependVarNumber(tlv::Participants);
+ totalLength += participantsLength;
- //TrustModel
- totalLength += prependNonNegativeIntegerBlock(block, tlv::TRUSTMODEL, m_trustModel);
+ // Manager Prefix
+ size_t managerLength = m_manager.wireEncode(block);
+ totalLength += managerLength;
+ totalLength += block.prependVarNumber(managerLength);
+ totalLength += block.prependVarNumber(tlv::ManagerPrefix);
- //type = TYPE_CHATROOM;
+ // Chatroom Sync Prefix
+ size_t chatroomSyncPrefixLength = m_syncPrefix.wireEncode(block);
+ totalLength += chatroomSyncPrefixLength;
+ totalLength += block.prependVarNumber(chatroomSyncPrefixLength);
+ totalLength += block.prependVarNumber(tlv::ChatroomPrefix);
+
+ // Trust Model
+ totalLength += prependNonNegativeIntegerBlock(block, tlv::TrustModel, m_trustModel);
+
+ // Chatroom Name
+ size_t chatroomNameLength = m_chatroomName.wireEncode(block);
+ totalLength += chatroomNameLength;
+ totalLength += block.prependVarNumber(chatroomNameLength);
+ totalLength += block.prependVarNumber(tlv::ChatroomName);
+
+ // Chatroom Info
totalLength += block.prependVarNumber(totalLength);
- totalLength += block.prependVarNumber(tlv::CHATROOM);
+ totalLength += block.prependVarNumber(tlv::ChatroomInfo);
return totalLength;
}
@@ -75,37 +110,102 @@
m_participants.clear();
- //Chatroom := CHATROOM-TYPE TLV-LENGTH
- // TrustModel
- // Participant+
+ // ChatroomInfo := CHATROOM-INFO-TYPE TLV-LENGTH
+ // ChatroomName
+ // TrustModel
+ // ChatroomPrefix
+ // ManagerPrefix
+ // Participants
+ //
+ // ChatroomName := CHATROOM-NAME-TYPE TLV-LENGTH
+ // NameComponent
+ //
+ // TrustModel := TRUST-MODEL-TYPE TLV-LENGTH
+ // nonNegativeInteger
+ //
+ // ChatroomPrefix := CHATROOM-PREFIX-TYPE TLV-LENGTH
+ // Name
+ //
+ // ManagerPrefix := MANAGER-PREFIX-TYPE TLV-LENGTH
+ // Name
+ //
+ // Participants := PARTICIPANTS-TYPE TLV-LENGTH
+ // Name+
- if (m_wire.type() != tlv::CHATROOM)
+ if (m_wire.type() != tlv::ChatroomInfo)
throw Error("Unexpected TLV number when decoding chatroom packet");
+ // Chatroom Info
Block::element_const_iterator i = m_wire.elements_begin();
- //TrustModel
- if (i == m_wire.elements_end() || i->type() != tlv::TRUSTMODEL)
+ if (i == m_wire.elements_end() || i->type() != tlv::ChatroomName)
+ throw Error("Missing Chatroom Name Info");
+ m_chatroomName.wireDecode(i->blockFromValue());
+
+ ++i;
+
+ // Trust Model
+ if (i == m_wire.elements_end() || i->type() != tlv::TrustModel)
throw Error("Missing TrustModel");
m_trustModel =
static_cast<TrustModel>(readNonNegativeInteger(*i));
++i;
- //Participants
- for (; i != m_wire.elements_end() && i->type() == tlv::PARTICIPANT; ++i) {
- Name name;
- name.wireDecode(i->blockFromValue());
- m_participants.push_back(name);
+ // Chatroom Sync Prefix
+ if (i == m_wire.elements_end() || i->type() != tlv::ChatroomPrefix)
+ throw Error("Missing Chatroom Prefix");
+ m_syncPrefix.wireDecode(i->blockFromValue());
+
+ ++i;
+
+ // Manager Prefix
+ if (i == m_wire.elements_end() || i->type() != tlv::ManagerPrefix)
+ throw Error("Missing Manager Prefix");
+ m_manager.wireDecode(i->blockFromValue());
+ ++i;
+
+ // Participants
+ if (i == m_wire.elements_end() || i->type() != tlv::Participants)
+ throw Error("Missing Participant");
+
+ Block temp = *i;
+ temp.parse();
+
+ Block::element_const_iterator j = temp.elements_begin();
+
+ while (j != temp.elements_end() && j->type() == tlv::Name) {
+ m_participants.push_back(Name(*j));
+ ++j;
}
+ if (j != temp.elements_end())
+ throw Error("Unexpected element");
+
if (m_participants.empty())
throw Error("Missing Participant");
+
+ ++i;
+
if (i != m_wire.elements_end()) {
throw Error("Unexpected element");
}
}
void
+ChatroomInfo::setName(const Name::Component& name)
+{
+ m_wire.reset();
+ m_chatroomName = name;
+}
+
+void
+ChatroomInfo::setTrustModel(const TrustModel trustModel)
+{
+ m_wire.reset();
+ m_trustModel = trustModel;
+}
+
+void
ChatroomInfo::addParticipant(const Name& participant)
{
m_wire.reset();
@@ -113,24 +213,24 @@
}
void
-ChatroomInfo::addContact(const Name& contact)
+ChatroomInfo::removeParticipant(const Name& participant)
{
m_wire.reset();
- m_contacts.push_back(contact);
+ m_participants.remove(participant);
}
void
-ChatroomInfo::setName(const Name::Component& name)
+ChatroomInfo::setSyncPrefix(const Name& prefix)
{
m_wire.reset();
- m_name = name;
+ m_syncPrefix = prefix;
}
void
-ChatroomInfo::setTrustModel(const TrustModel trustModel)
+ChatroomInfo::setManager(const Name& manager)
{
m_wire.reset();
- m_trustModel = trustModel;
+ m_manager = manager;
}
-} //namespace chronos
+} // namespace chronos