+class SilenceExtItem : public SimpleExtItem<SilenceList>
+{
+ public:
+ unsigned int maxsilence;
+
+ SilenceExtItem(Module* Creator)
+ : SimpleExtItem<SilenceList>("silence_list", ExtensionItem::EXT_USER, Creator)
+ {
+ }
+
+ void FromInternal(Extensible* container, const std::string& value) CXX11_OVERRIDE
+ {
+ LocalUser* user = IS_LOCAL(static_cast<User*>(container));
+ if (!user)
+ return;
+
+ // Remove the old list and create a new one.
+ unset(user);
+ SilenceList* list = new SilenceList();
+
+ irc::spacesepstream ts(value);
+ while (!ts.StreamEnd())
+ {
+ // Check we have space for another entry.
+ if (list->size() >= maxsilence)
+ {
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Oversized silence list received for %s: %s",
+ user->uuid.c_str(), value.c_str());
+ delete list;
+ return;
+ }
+
+ // Extract the mask and the flags.
+ std::string mask;
+ std::string flagstr;
+ if (!ts.GetToken(mask) || !ts.GetToken(flagstr))
+ {
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Malformed silence list received for %s: %s",
+ user->uuid.c_str(), value.c_str());
+ delete list;
+ return;
+ }
+
+ // Try to parse the flags.
+ uint32_t flags;
+ if (!SilenceEntry::FlagsToBits(flagstr, flags))
+ {
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Malformed silence flags received for %s: %s",
+ user->uuid.c_str(), flagstr.c_str());
+ delete list;
+ return;
+ }
+
+ // Store the silence entry.
+ list->insert(SilenceEntry(flags, mask));
+ }
+
+ // The value was well formed.
+ set(user, list);
+ }
+
+ std::string ToInternal(const Extensible* container, void* item) const CXX11_OVERRIDE
+ {
+ SilenceList* list = static_cast<SilenceList*>(item);
+ std::string buf;
+ for (SilenceList::const_iterator iter = list->begin(); iter != list->end(); ++iter)
+ {
+ if (iter != list->begin())
+ buf.push_back(' ');
+
+ buf.append(iter->mask);
+ buf.push_back(' ');
+ buf.append(SilenceEntry::BitsToFlags(iter->flags));
+ }
+ return buf;
+ }
+};
+