]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add the msgid tag to all outgoing messages.
authorPeter Powell <petpow@saberuk.com>
Fri, 7 Jun 2019 12:32:56 +0000 (13:32 +0100)
committerPeter Powell <petpow@saberuk.com>
Fri, 7 Jun 2019 19:22:43 +0000 (20:22 +0100)
src/modules/m_ircv3_msgid.cpp

index 4d34455b94b1f2c8747e1470114ef1e721badca7..00854a19cbda5266631c16189aa65886b75885c8 100644 (file)
 #include "modules/cap.h"
 #include "modules/ctctags.h"
 
+class MsgIdGenerator
+{
+       uint64_t counter;
+       std::string strid;
+       const std::string::size_type baselen;
+
+ public:
+       MsgIdGenerator()
+               : counter(0)
+               , strid(InspIRCd::Format("%s~%lu~", ServerInstance->Config->GetSID().c_str(), ServerInstance->startup_time))
+               , baselen(strid.length())
+       {
+       }
+
+       const std::string& GetNext()
+       {
+               strid.erase(baselen);
+               strid.append(ConvToStr(counter++));
+               return strid;
+       }
+};
+
 class MsgIdTag : public ClientProtocol::MessageTagProvider
 {
  private:
        Cap::Reference ctctagcap;
 
  public:
+       MsgIdGenerator generator;
+
        MsgIdTag(Module* mod)
                : ClientProtocol::MessageTagProvider(mod)
                , ctctagcap(mod, "message-tags")
        {
        }
 
+       void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE
+       {
+               const ClientProtocol::TagMap& tags = msg.GetTags();
+               if (tags.find("msgid") == tags.end())
+                       msg.AddTag("msgid", this, generator.GetNext());
+       }
+
        ModResult OnProcessTag(User* user, const std::string& tagname, std::string& tagvalue) CXX11_OVERRIDE
        {
                if (!irc::equals(tagname, "msgid"))
@@ -49,35 +80,12 @@ class MsgIdTag : public ClientProtocol::MessageTagProvider
        }
 };
 
-class MsgIdGenerator
-{
-       uint64_t counter;
-       std::string strid;
-       const std::string::size_type baselen;
-
- public:
-       MsgIdGenerator()
-               : counter(0)
-               , strid(InspIRCd::Format("%s~%lu~", ServerInstance->Config->GetSID().c_str(), ServerInstance->startup_time))
-               , baselen(strid.length())
-       {
-       }
-
-       const std::string& GetNext()
-       {
-               strid.erase(baselen);
-               strid.append(ConvToStr(counter++));
-               return strid;
-       }
-};
-
 class ModuleMsgId
        : public Module
        , public CTCTags::EventListener
 {
  private:
        MsgIdTag tag;
-       MsgIdGenerator generator;
 
        ModResult CopyMessageId(const ClientProtocol::TagMap& tags_in, ClientProtocol::TagMap& tags_out)
        {
@@ -87,11 +95,7 @@ class ModuleMsgId
                        // If the remote server has sent a message identifier we should use that as
                        // identifiers need to be the same on all sides of the network.
                        tags_out.insert(*iter);
-                       return MOD_RES_PASSTHRU;
                }
-
-               // Otherwise, we can just create a new message identifier.
-               tags_out.insert(std::make_pair("msgid", ClientProtocol::MessageTagData(&tag, generator.GetNext())));
                return MOD_RES_PASSTHRU;
        }