]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
MetaData rework
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Sep 2009 00:45:37 +0000 (00:45 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Sep 2009 00:45:37 +0000 (00:45 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11607 e03df62e-2008-0410-955e-edbf42e46eb7

26 files changed:
include/modules.h
include/protocol.h
src/modules.cpp
src/modules/extra/m_ssl_gnutls.cpp
src/modules/extra/m_ssl_openssl.cpp
src/modules/m_callerid.cpp
src/modules/m_cban.cpp
src/modules/m_cgiirc.cpp
src/modules/m_check.cpp
src/modules/m_cloaking.cpp
src/modules/m_customtitle.cpp
src/modules/m_filter.cpp
src/modules/m_namesx.cpp
src/modules/m_sasl.cpp
src/modules/m_services_account.cpp
src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/main.h
src/modules/m_spanningtree/metadata.cpp
src/modules/m_spanningtree/netburst.cpp
src/modules/m_spanningtree/protocolinterface.cpp
src/modules/m_spanningtree/protocolinterface.h
src/modules/m_sslinfo.cpp
src/modules/m_svshold.cpp
src/modules/m_swhois.cpp
src/modules/m_taxonomy.cpp
src/modules/m_uhnames.cpp

index 84895177be6f2eea19bcc7533c86ca5339d95c21..e67f287c889d973542a671781135cd371089489f 100644 (file)
@@ -449,7 +449,7 @@ enum Implementation
        I_OnSendSnotice, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnWhois,
        I_OnUserPreInvite, I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreNick,
        I_OnUserMessage, I_OnUserNotice, I_OnMode, I_OnGetServerDescription, I_OnSyncUser,
-       I_OnSyncChannel, I_OnSyncChannelMetaData, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnWallops,
+       I_OnSyncChannel, I_OnDecodeMetaData, I_OnWallops,
        I_OnChangeHost, I_OnChangeName, I_OnAddLine, I_OnDelLine, I_OnExpireLine, I_OnCleanup,
        I_OnUserPostNick, I_OnAccessCheck, I_On005Numeric, I_OnKill, I_OnRemoteKill, I_OnLoadModule,
        I_OnUnloadModule, I_OnBackgroundTimer, I_OnPreCommand, I_OnCheckReady, I_OnCheckInvite,
@@ -458,7 +458,7 @@ enum Implementation
        I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnGlobalOper, I_OnPostConnect, I_OnAddBan,
        I_OnDelBan, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead,
        I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete,
-       I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnUserList, I_OnPostCommand, I_OnPostJoin,
+       I_OnPostOper, I_OnSyncNetwork, I_OnSetAway, I_OnUserList, I_OnPostCommand, I_OnPostJoin,
        I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect, I_OnGarbageCollect, I_OnBufferFlushed,
        I_OnText, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric, I_OnHookUserIO,
        I_OnHostCycle, I_OnPreRehash, I_OnModuleRehash,
@@ -853,9 +853,7 @@ class CoreExport Module : public Extensible
         * the linking protocol. This currently is m_spanningtree.so. A pointer to this module
         * is given in Module* proto, so that you may call its methods such as ProtoSendMode
         * (see below). This function will be called for every user visible on your side
-        * of the burst, allowing you to for example set modes, etc. Do not use this call to
-        * synchronize data which you have stored using class Extensible -- There is a specialist
-        * function OnSyncUserMetaData and OnSyncChannelMetaData for this!
+        * of the burst, allowing you to for example set modes, etc.
         *
         * For a good example of how to use this function, please see src/modules/m_chanprotect.cpp
         *
@@ -865,36 +863,6 @@ class CoreExport Module : public Extensible
         */
        virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque);
 
-       /* Allows modules to syncronize metadata related to channels over the network during a netburst.
-        * Whenever the linking module wants to send out data, but doesnt know what the data
-        * represents (e.g. it is Extensible metadata, added to a User or Channel by a module) then
-        * this method is called.You should use the ProtoSendMetaData function after you've
-        * correctly decided how the data should be represented, to send the metadata on its way if it belongs
-        * to your module. For a good example of how to use this method, see src/modules/m_swhois.cpp.
-        * @param chan The channel whos metadata is being syncronized
-        * @param proto A pointer to the module handling network protocol
-        * @param opaque An opaque pointer set by the protocol module, should not be modified!
-        * @param extname The extensions name which is being searched for
-        * @param displayable If this value is true, the data is going to be displayed to a user,
-        * and not sent across the network. Use this to determine wether or not to show sensitive data.
-        */
-       virtual void OnSyncChannelMetaData(Channel* chan, Module* proto,void* opaque, const std::string &extname, bool displayable = false);
-
-       /* Allows modules to syncronize metadata related to users over the network during a netburst.
-        * Whenever the linking module wants to send out data, but doesnt know what the data
-        * represents (e.g. it is Extensible metadata, added to a User or Channel by a module) then
-        * this method is called. You should use the ProtoSendMetaData function after you've
-        * correctly decided how the data should be represented, to send the metadata on its way if
-        * if it belongs to your module.
-        * @param user The user whos metadata is being syncronized
-        * @param proto A pointer to the module handling network protocol
-        * @param opaque An opaque pointer set by the protocol module, should not be modified!
-        * @param extname The extensions name which is being searched for
-        * @param displayable If this value is true, the data is going to be displayed to a user,
-        * and not sent across the network. Use this to determine wether or not to show sensitive data.
-        */
-       virtual void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable = false);
-
        /* Allows modules to syncronize metadata not related to users or channels, over the network during a netburst.
         * Whenever the linking module wants to send out data, but doesnt know what the data
         * represents (e.g. it is Extensible metadata, added to a User or Channel by a module) then
@@ -906,7 +874,7 @@ class CoreExport Module : public Extensible
         * @param displayable If this value is true, the data is going to be displayed to a user,
         * and not sent across the network. Use this to determine wether or not to show sensitive data.
         */
-       virtual void OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable = false);
+       virtual void OnSyncNetwork(Module* proto, void* opaque);
 
        /** Allows module data, sent via ProtoSendMetaData, to be decoded again by a receiving module.
         * Please see src/modules/m_swhois.cpp for a working example of how to use this method call.
@@ -915,7 +883,7 @@ class CoreExport Module : public Extensible
         * @param extname The extension name which is being sent
         * @param extdata The extension data, encoded at the other end by an identical module through OnSyncChannelMetaData or OnSyncUserMetaData
         */
-       virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata);
+       virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata);
 
        /** Implemented by modules which provide the ability to link servers.
         * These modules will implement this method, which allows transparent sending of servermodes
@@ -947,7 +915,14 @@ class CoreExport Module : public Extensible
         * @param extname The extension name to send metadata for
         * @param extdata Encoded data for this extension name, which will be encoded at the oppsite end by an identical module using OnDecodeMetaData
         */
-       virtual void ProtoSendMetaData(void* opaque, TargetTypeFlags target_type, void* target, const std::string &extname, const std::string &extdata);
+       virtual void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata);
+
+       /**
+        * Implemented by all modules that implement ProtoSendMetaData.
+        * Translates the item into a string format suitable for sending to other servers.
+        * Currently, this just translates nicks to their UID and channels to their name
+        */
+       virtual std::string ProtoTranslate(Extensible* item);
 
        /** Called after every WALLOPS command.
         * @param user The user sending the WALLOPS
index fdfb89aab1a125e443d630b1798e49d668a7ac9e..bd437c76f03082ac7f60137a7efbe9abe5fee9a7 100644 (file)
@@ -52,11 +52,10 @@ class ProtocolInterface : public Extensible
 
        /** Send metadata for an object to other linked servers.
         * @param target The object to send metadata for.
-        * @param type The type of metadata to send (TYPE_USER, TYPE_CHANNEL, etc)
         * @param key The 'key' of the data, e.g. "swhois" for swhois desc on a user
         * @param data The string representation of the data
         */
-       virtual void SendMetaData(void* target, TargetTypeFlags type, const std::string &key, const std::string &data) { }
+       virtual void SendMetaData(Extensible* target, const std::string &key, const std::string &data) { }
 
        /** Send a topic change for a channel
         * @param channel The channel to change the topic for.
index 21db883c4589ee769f52913d923d9ada1fcb5a05..ad7efdb06d70f1f670c9e4b47bdf6867d3862f98 100644 (file)
@@ -172,12 +172,11 @@ void              Module::OnPostLocalTopicChange(User*, Channel*, const std::string&) { }
 void           Module::OnGetServerDescription(const std::string&, std::string&) { }
 void           Module::OnSyncUser(User*, Module*, void*) { }
 void           Module::OnSyncChannel(Channel*, Module*, void*) { }
+void           Module::OnSyncNetwork(Module*, void*) { }
 void           Module::ProtoSendMode(void*, TargetTypeFlags, void*, const std::vector<std::string>&, const std::vector<TranslateType>&) { }
-void           Module::OnSyncChannelMetaData(Channel*, Module*, void*, const std::string&, bool) { }
-void           Module::OnSyncUserMetaData(User*, Module*, void*, const std::string&, bool) { }
-void           Module::OnSyncOtherMetaData(Module*, void*, bool) { }
-void           Module::OnDecodeMetaData(int, void*, const std::string&, const std::string&) { }
-void           Module::ProtoSendMetaData(void*, TargetTypeFlags, void*, const std::string&, const std::string&) { }
+void           Module::OnDecodeMetaData(Extensible*, const std::string&, const std::string&) { }
+void           Module::ProtoSendMetaData(void*, Extensible*, const std::string&, const std::string&) { }
+std::string    Module::ProtoTranslate(Extensible*) { return "?"; }
 void           Module::OnWallops(User*, const std::string&) { }
 void           Module::OnChangeHost(User*, const std::string&) { }
 void           Module::OnChangeName(User*, const std::string&) { }
index 665a6723f733d44c635c4308eb56b8ca8ae97861..a769bd12bfae55aadb200b1b2ce5775974e7c3ab 100644 (file)
@@ -697,9 +697,9 @@ class ModuleSSLGnuTLS : public Module
                                user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\"", user->nick.c_str(), cipher.c_str());
                        }
 
-                       ServerInstance->PI->SendMetaData(user, TYPE_USER, "ssl", "ON");
+                       ServerInstance->PI->SendMetaData(user, "ssl", "ON");
                        if (certdata)
-                               ServerInstance->PI->SendMetaData(user, TYPE_USER, "ssl_cert", certdata->GetMetaLine().c_str());
+                               ServerInstance->PI->SendMetaData(user, "ssl_cert", certdata->GetMetaLine().c_str());
                }
        }
 
index 447f359404dc62908477c1530c47f67f377f71ea..9bce0d05efc5ca0242abd66209d0690cf6ed00cd 100644 (file)
@@ -777,9 +777,9 @@ class ModuleSSLOpenSSL : public Module
                        if (sessions[user->GetFd()].sess)
                                user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\"", user->nick.c_str(), SSL_get_cipher(sessions[user->GetFd()].sess));
 
-                       ServerInstance->PI->SendMetaData(user, TYPE_USER, "ssl", "ON");
+                       ServerInstance->PI->SendMetaData(user, "ssl", "ON");
                        if (certdata)
-                               ServerInstance->PI->SendMetaData(user, TYPE_USER, "ssl_cert", certdata->GetMetaLine().c_str());
+                               ServerInstance->PI->SendMetaData(user, "ssl_cert", certdata->GetMetaLine().c_str());
                }
        }
 
index 1b9492ce14ecdbacd0cf33e0176982acc124c691..29ba7fd6022f2c113a1e7365519f35df5012115f 100644 (file)
@@ -56,14 +56,14 @@ class callerid_data : public classbase
                }
        }
 
-       std::string ToString(bool displayable) const
+       std::string ToString(Module* proto) const
        {
                std::ostringstream oss;
                oss << lastnotify;
                for (std::set<User*>::const_iterator i = accepting.begin(); i != accepting.end(); ++i)
                {
                        // Encode UIDs.
-                       oss << "," << (displayable ? (*i)->nick : (*i)->uuid);
+                       oss << "," << proto->ProtoTranslate(*i);
                }
                oss << std::ends;
                return oss.str();
@@ -430,24 +430,21 @@ public:
                RemoveData(u);
        }
 
-       virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string& extname, bool displayable)
+       virtual void OnSyncUser(User* user, Module* proto, void* opaque)
        {
-               if (extname == "callerid_data")
+               callerid_data* dat = GetData(user, false);
+               if (dat)
                {
-                       callerid_data* dat = GetData(user, false);
-                       if (dat)
-                       {
-                               std::string str = dat->ToString(displayable);
-                               proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, str);
-                       }
+                       std::string str = dat->ToString(proto);
+                       proto->ProtoSendMetaData(opaque, user, "callerid_data", str);
                }
        }
 
-       virtual void OnDecodeMetaData(int target_type, void* target, const std::string& extname, const std::string& extdata)
+       virtual void OnDecodeMetaData(Extensible* target, const std::string& extname, const std::string& extdata)
        {
-               if (target_type == TYPE_USER && extname == "callerid_data")
+               User* u = dynamic_cast<User*>(target);
+               if (u && extname == "callerid_data")
                {
-                       User* u = (User*)target;
                        callerid_data* dat = new callerid_data(extdata, ServerInstance);
                        u->Extend("callerid_data", dat);
                }
index 4b0319d87aab55c92e21eedf84840c6dff4d68db..11bd32c8a03cdf484c975a0701a855829f50087f 100644 (file)
@@ -165,8 +165,8 @@ class ModuleCBan : public Module
                ServerInstance->XLines->RegisterFactory(&f);
 
                ServerInstance->AddCommand(&mycommand);
-               Implementation eventlist[] = { I_OnUserPreJoin, I_OnSyncOtherMetaData, I_OnDecodeMetaData, I_OnStats };
-               ServerInstance->Modules->Attach(eventlist, this, 4);
+               Implementation eventlist[] = { I_OnUserPreJoin, I_OnStats };
+               ServerInstance->Modules->Attach(eventlist, this, 2);
        }
 
        virtual ~ModuleCBan()
index 8b7a77941d666c935fe02abccd12f309a9bc87bf..3e00f498d9ed2dd621a853647dd3974706636580 100644 (file)
@@ -143,7 +143,7 @@ public:
                OnRehash(NULL);
                ServerInstance->AddCommand(&cmd);
 
-               Implementation eventlist[] = { I_OnRehash, I_OnUserRegister, I_OnCleanup, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUserDisconnect, I_OnUserConnect };
+               Implementation eventlist[] = { I_OnRehash, I_OnUserRegister, I_OnCleanup, I_OnSyncUser, I_OnDecodeMetaData, I_OnUserDisconnect, I_OnUserConnect };
                ServerInstance->Modules->Attach(eventlist, this, 7);
        }
 
@@ -224,29 +224,22 @@ public:
                }
        }
 
-       virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
+       virtual void OnSyncUser(User* user, Module* proto, void* opaque)
        {
-               if((extname == "cgiirc_realhost") || (extname == "cgiirc_realip"))
-               {
-                       std::string* data;
-
-                       if(user->GetExt(extname, data))
-                       {
-                               proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, *data);
-                       }
-               }
+               std::string* data;
+               if (user->GetExt("cgiirc_realhost", data))
+                       proto->ProtoSendMetaData(opaque, user, "cgiirc_realhost", *data);
+               if (user->GetExt("cgiirc_realip", data))
+                       proto->ProtoSendMetaData(opaque, user, "cgiirc_realip", *data);
        }
 
-       virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
+       virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata)
        {
-               if(target_type == TYPE_USER)
+               User* dest = dynamic_cast<User*>(target);
+               std::string* bleh;
+               if(dest && ((extname == "cgiirc_realhost") || (extname == "cgiirc_realip")) && (!dest->GetExt(extname, bleh)))
                {
-                       User* dest = (User*)target;
-                       std::string* bleh;
-                       if(((extname == "cgiirc_realhost") || (extname == "cgiirc_realip")) && (!dest->GetExt(extname, bleh)))
-                       {
-                               dest->Extend(extname, new std::string(extdata));
-                       }
+                       dest->Extend(extname, new std::string(extdata));
                }
        }
 
index 3b79081adabab01a6f00e009243cae6e69c818fe..42be6a350971343e852e5ea32452ed00c43b873c 100644 (file)
@@ -99,18 +99,7 @@ class CommandCheck : public Command
 
                        ServerInstance->DumpText(user,checkstr + " onchans ", dump);
 
-                       std::deque<std::string> extlist;
-                       targuser->GetExtList(extlist);
-                       std::stringstream dumpkeys;
-                       for(std::deque<std::string>::iterator i = extlist.begin(); i != extlist.end(); i++)
-                       {
-                               md_sent = false;
-                               FOREACH_MOD_I(ServerInstance,I_OnSyncUserMetaData,OnSyncUserMetaData(targuser,Parent,(void*)user,*i, true));
-                               if (!md_sent)
-                                       dumpkeys << " " << *i;
-                       }
-                       if (!dumpkeys.str().empty())
-                               ServerInstance->DumpText(user,checkstr + " metadata ", dumpkeys);
+                       FOREACH_MOD_I(ServerInstance,I_OnSyncUser,OnSyncUser(targuser,Parent,(void*)user));
                }
                else if (targchan)
                {
@@ -143,18 +132,7 @@ class CommandCheck : public Command
                                user->WriteServ(checkstr + " member " + tmpbuf);
                        }
 
-                       std::deque<std::string> extlist;
-                       targchan->GetExtList(extlist);
-                       std::stringstream dumpkeys;
-                       for(std::deque<std::string>::iterator i = extlist.begin(); i != extlist.end(); i++)
-                       {
-                               md_sent = false;
-                               FOREACH_MOD_I(ServerInstance,I_OnSyncChannelMetaData,OnSyncChannelMetaData(targchan,Parent,(void*)user,*i, true));
-                               if (!md_sent)
-                                       dumpkeys << " " << *i;
-                       }
-                       if (!dumpkeys.str().empty())
-                               ServerInstance->DumpText(user,checkstr + " metadata ", dumpkeys);
+                       FOREACH_MOD_I(ServerInstance,I_OnSyncChannel,OnSyncChannel(targchan,Parent,(void*)user));
                }
                else
                {
@@ -206,12 +184,23 @@ class ModuleCheck : public Module
                return Version("$Id$", VF_VENDOR, API_VERSION);
        }
 
-       virtual void ProtoSendMetaData(void* opaque, TargetTypeFlags type, void* target, const std::string& name, const std::string& value)
+       virtual void ProtoSendMetaData(void* opaque, Extensible* target, const std::string& name, const std::string& value)
        {
                User* user = static_cast<User*>(opaque);
                user->WriteServ("304 " + std::string(user->nick) + " :CHECK meta:" + name + " " + value);
                mycommand.md_sent = true;
        }
+
+       virtual std::string ProtoTranslate(Extensible* item)
+       {
+               User* u = dynamic_cast<User*>(item);
+               Channel* c = dynamic_cast<Channel*>(item);
+               if (u)
+                       return u->nick;
+               if (c)
+                       return c->name;
+               return "?";
+       }
 };
 
 MODULE_INIT(ModuleCheck)
index a236300f18404bf623e7ad73a12b738862dd4530..458d833dfab28258c9f992d802765860a6166089 100644 (file)
@@ -282,20 +282,17 @@ class ModuleCloaking : public Module
 
                ServerInstance->Modules->UseInterface("HashRequest");
 
-               Implementation eventlist[] = { I_OnRehash, I_OnUserDisconnect, I_OnCleanup, I_OnCheckBan, I_OnUserConnect, I_OnSyncUserMetaData, I_OnCleanup };
+               Implementation eventlist[] = { I_OnRehash, I_OnUserDisconnect, I_OnCleanup, I_OnCheckBan, I_OnUserConnect, I_OnSyncUser, I_OnCleanup };
                ServerInstance->Modules->Attach(eventlist, this, 6);
 
                CloakExistingUsers();
        }
 
-       void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable)
+       void OnSyncUser(User* user, Module* proto,void* opaque)
        {
-               if ((displayable) && (extname == "cloaked_host"))
-               {
-                       std::string* cloak;
-                       if (user->GetExt("cloaked_host", cloak))
-                               proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, *cloak);
-               }
+               std::string* cloak;
+               if (user->GetExt("cloaked_host", cloak) && proto->ProtoTranslate(NULL) == "?")
+                       proto->ProtoSendMetaData(opaque, user, "cloaked_host", *cloak);
        }
 
        void CloakExistingUsers()
index 35992d505bd3ba0d5d283793d2077e70128f2622..499886535d1b075a2eaf524d44dab7fa04905729 100644 (file)
@@ -71,7 +71,7 @@ class CommandTitle : public Command
                                text = new std::string(title);
                                user->Extend("ctitle", text);
 
-                               ServerInstance->PI->SendMetaData(user, TYPE_USER, "ctitle", *text);
+                               ServerInstance->PI->SendMetaData(user, "ctitle", *text);
 
                                if (!vhost.empty())
                                        user->ChangeDisplayedHost(vhost.c_str());
@@ -96,7 +96,7 @@ class ModuleCustomTitle : public Module
        ModuleCustomTitle(InspIRCd* Me) : Module(Me), cmd(Me)
        {
                ServerInstance->AddCommand(&cmd);
-               Implementation eventlist[] = { I_OnDecodeMetaData, I_OnWhoisLine, I_OnSyncUserMetaData, I_OnUserQuit, I_OnCleanup };
+               Implementation eventlist[] = { I_OnDecodeMetaData, I_OnWhoisLine, I_OnSyncUser, I_OnUserQuit, I_OnCleanup };
                ServerInstance->Modules->Attach(eventlist, this, 5);
        }
 
@@ -123,20 +123,12 @@ class ModuleCustomTitle : public Module
        // this method is called. We should use the ProtoSendMetaData function after we've
        // corrected decided how the data should look, to send the metadata on its way if
        // it is ours.
-       virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
+       virtual void OnSyncUser(User* user, Module* proto, void* opaque)
        {
-               // check if the linking module wants to know about OUR metadata
-               if (extname == "ctitle")
-               {
-                       // check if this user has an ctitle field to send
-                       std::string* ctitle;
-                       if (user->GetExt("ctitle", ctitle))
-                       {
-                               // call this function in the linking module, let it format the data how it
-                               // sees fit, and send it on its way. We dont need or want to know how.
-                               proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*ctitle);
-                       }
-               }
+               // check if this user has an ctitle field to send
+               std::string* ctitle;
+               if (user->GetExt("ctitle", ctitle))
+                       proto->ProtoSendMetaData(opaque,user,"ctitle",*ctitle);
        }
 
        // when a user quits, tidy up their metadata
@@ -172,12 +164,12 @@ class ModuleCustomTitle : public Module
        // In our case we're only sending a single string around, so we just construct a std::string.
        // Some modules will probably get much more complex and format more detailed structs and classes
        // in a textual way for sending over the link.
-       virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
+       virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata)
        {
+               User* dest = dynamic_cast<User*>(target);
                // check if its our metadata key, and its associated with a user
-               if ((target_type == TYPE_USER) && (extname == "ctitle"))
+               if (dest && (extname == "ctitle"))
                {
-                       User* dest = (User*)target;
                        std::string* text;
                        if (dest->GetExt("ctitle", text))
                        {
index 9c4788f4664f8afd3314b1a836215529bbb4cd48..6490e4c8636a04e26227ab09b7d17341e7e0d93f 100644 (file)
@@ -134,8 +134,8 @@ protected:
        virtual Version GetVersion();
        std::string EncodeFilter(FilterResult* filter);
        FilterResult DecodeFilter(const std::string &data);
-       virtual void OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable = false);
-       virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata);
+       virtual void OnSyncNetwork(Module* proto, void* opaque);
+       virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata);
        virtual int OnStats(char symbol, User* user, string_list &results) = 0;
        virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line);
        bool AppliesToMe(User* user, FilterResult* filter, int flags);
@@ -240,7 +240,7 @@ FilterBase::FilterBase(InspIRCd* Me, const std::string &source) : Module(Me), fi
 {
        Me->Modules->UseInterface("RegularExpression");
        ServerInstance->AddCommand(&filtcommand);
-       Implementation eventlist[] = { I_OnPreCommand, I_OnStats, I_OnSyncOtherMetaData, I_OnDecodeMetaData, I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash, I_OnLoadModule };
+       Implementation eventlist[] = { I_OnPreCommand, I_OnStats, I_OnSyncNetwork, I_OnDecodeMetaData, I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash, I_OnLoadModule };
        ServerInstance->Modules->Attach(eventlist, this, 8);
 }
 
@@ -510,19 +510,19 @@ FilterResult FilterBase::DecodeFilter(const std::string &data)
        return res;
 }
 
-void FilterBase::OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable)
+void FilterBase::OnSyncNetwork(Module* proto, void* opaque)
 {
        this->SyncFilters(proto, opaque);
 }
 
 void FilterBase::SendFilter(Module* proto, void* opaque, FilterResult* iter)
 {
-       proto->ProtoSendMetaData(opaque, TYPE_OTHER, NULL, "filter", EncodeFilter(iter));
+       proto->ProtoSendMetaData(opaque, NULL, "filter", EncodeFilter(iter));
 }
 
-void FilterBase::OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
+void FilterBase::OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata)
 {
-       if ((target_type == TYPE_OTHER) && (extname == "filter"))
+       if ((target == NULL) && (extname == "filter"))
        {
                FilterResult data = DecodeFilter(extdata);
                this->AddFilter(data.freeform, data.action, data.reason, data.gline_time, data.flags);
index 794cd5b46b4b6b07a1df73a994abfb62beb34425..377c9b1f003866b4d8e57dac04274ecbe06762dd 100644 (file)
@@ -23,7 +23,7 @@ class ModuleNamesX : public Module
        ModuleNamesX(InspIRCd* Me)
                : Module(Me)
        {
-               Implementation eventlist[] = { I_OnSyncUserMetaData, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent };
+               Implementation eventlist[] = { I_OnSyncUser, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent };
                ServerInstance->Modules->Attach(eventlist, this, 5);
        }
 
@@ -32,10 +32,10 @@ class ModuleNamesX : public Module
        {
        }
 
-       void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable)
+       void OnSyncUser(User* user, Module* proto,void* opaque)
        {
-               if ((displayable) && (extname == "NAMESX"))
-                       proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "Enabled");
+               if (proto->ProtoTranslate(NULL) == "?" && user->GetExt("NAMESX"))
+                       proto->ProtoSendMetaData(opaque, user, "NAMESX", "Enabled");
        }
 
        virtual Version GetVersion()
index b205f91c1d334fc00117bb8cb470dd26828add09..08f1363741fa8ab4e3509d68dfb8428b87de6fd7 100644 (file)
@@ -272,7 +272,7 @@ class ModuleSASL : public Module
                std::string* str = NULL;
 
                if (user->GetExt("accountname", str))
-                       ServerInstance->PI->SendMetaData(user, TYPE_USER, "accountname", *str);
+                       ServerInstance->PI->SendMetaData(user, "accountname", *str);
 
                return;
        }
index d6cf0b1e772960b6a77fa3ef7d122e2f357eb1dc..30baccadf0db10aaa6b008af4386875d8cb6d145 100644 (file)
@@ -115,7 +115,7 @@ class ModuleServicesAccount : public Module
                        throw ModuleException("Some other module has claimed our modes!");
 
                Implementation eventlist[] = { I_OnWhois, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreJoin, I_OnCheckBan,
-                       I_OnSyncUserMetaData, I_OnUserQuit, I_OnCleanup, I_OnDecodeMetaData, I_On005Numeric, I_OnUserPostNick };
+                       I_OnSyncUser, I_OnUserQuit, I_OnCleanup, I_OnDecodeMetaData, I_On005Numeric, I_OnUserPostNick };
 
                ServerInstance->Modules->Attach(eventlist, this, 10);
        }
@@ -254,23 +254,19 @@ class ModuleServicesAccount : public Module
        // this method is called. We should use the ProtoSendMetaData function after we've
        // corrected decided how the data should look, to send the metadata on its way if
        // it is ours.
-       virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
+       virtual void OnSyncUser(User* user, Module* proto, void* opaque)
        {
-               // check if the linking module wants to know about OUR metadata
-               if (extname == "accountname")
+               // check if this user has an swhois field to send
+               std::string* account;
+               user->GetExt("accountname", account);
+               if (account)
                {
-                       // check if this user has an swhois field to send
-                       std::string* account;
-                       user->GetExt("accountname", account);
-                       if (account)
-                       {
-                               // remove any accidental leading/trailing spaces
-                               trim(*account);
+                       // remove any accidental leading/trailing spaces
+                       trim(*account);
 
-                               // call this function in the linking module, let it format the data how it
-                               // sees fit, and send it on its way. We dont need or want to know how.
-                               proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*account);
-                       }
+                       // call this function in the linking module, let it format the data how it
+                       // sees fit, and send it on its way. We dont need or want to know how.
+                       proto->ProtoSendMetaData(opaque,user,"accountname",*account);
                }
        }
 
@@ -309,13 +305,12 @@ class ModuleServicesAccount : public Module
        // In our case we're only sending a single string around, so we just construct a std::string.
        // Some modules will probably get much more complex and format more detailed structs and classes
        // in a textual way for sending over the link.
-       virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
+       virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata)
        {
+               User* dest = dynamic_cast<User*>(target);
                // check if its our metadata key, and its associated with a user
-               if ((target_type == TYPE_USER) && (extname == "accountname"))
+               if (dest && (extname == "accountname"))
                {
-                       User* dest = (User*)target;
-
                        std::string* account;
                        if (dest->GetExt("accountname", account)) {
                                // remove old account so that we can set new (or leave unset)
index c402b145a7afd76955f76bc5da68878d722502c7..2ecbd8a88709f261bdec25cab12a75976d56011a 100644 (file)
@@ -899,26 +899,28 @@ void ModuleSpanningTree::ProtoSendMode(void* opaque, TargetTypeFlags target_type
        }
 }
 
-void ModuleSpanningTree::ProtoSendMetaData(void* opaque, TargetTypeFlags target_type, void* target, const std::string &extname, const std::string &extdata)
-{
-       TreeSocket* s = (TreeSocket*)opaque;
-       if (target)
-       {
-               if (target_type == TYPE_USER)
-               {
-                       User* u = (User*)target;
-                       s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata);
-               }
-               else if (target_type == TYPE_CHANNEL)
-               {
-                       Channel* c = (Channel*)target;
-                       s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+extname+" :"+extdata);
-               }
-       }
-       if (target_type == TYPE_OTHER)
-       {
+void ModuleSpanningTree::ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata)
+{
+       TreeSocket* s = static_cast<TreeSocket*>(opaque);
+       User* u = dynamic_cast<User*>(target);
+       Channel* c = dynamic_cast<Channel*>(target);
+       if (u)
+               s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata);
+       else if (c)
+               s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+extname+" :"+extdata);
+       else if (!target)
                s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA * "+extname+" :"+extdata);
-       }
+}
+
+std::string ModuleSpanningTree::ProtoTranslate(Extensible* item)
+{
+       User* u = dynamic_cast<User*>(item);
+       Channel* c = dynamic_cast<Channel*>(item);
+       if (u)
+               return u->uuid;
+       if (c)
+               return c->name;
+       return "*";
 }
 
 void ModuleSpanningTree::OnEvent(Event* event)
index 15d59701d373673f70dbdab2bf7e11eddae85704..54524c720659a661f8c8553300e60f6beaf02d47 100644 (file)
@@ -185,7 +185,8 @@ class ModuleSpanningTree : public Module
        virtual int OnStats(char statschar, User* user, string_list &results);
        virtual int OnSetAway(User* user, const std::string &awaymsg);
        virtual void ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::vector<std::string> &modeline, const std::vector<TranslateType> &translate);
-       virtual void ProtoSendMetaData(void* opaque, TargetTypeFlags target_type, void* target, const std::string &extname, const std::string &extdata);
+       virtual void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata);
+       virtual std::string ProtoTranslate(Extensible* item);
        virtual void OnEvent(Event* event);
        virtual void OnLoadModule(Module* mod,const std::string &name);
        virtual void OnUnloadModule(Module* mod,const std::string &name);
index eece14b0c08cd98a4a102396b31757f77eb5744e..f012568f9db23e0dd92789258c953b45d8d982db 100644 (file)
@@ -32,14 +32,14 @@ bool TreeSocket::MetaData(const std::string &prefix, parameterlist &params)
        {
                if (params[0] == "*")
                {
-                       FOREACH_MOD_I(this->ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_OTHER,NULL,params[1],params[2]));
+                       FOREACH_MOD_I(this->ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(NULL,params[1],params[2]));
                }
                else if (*(params[0].c_str()) == '#')
                {
                        Channel* c = this->ServerInstance->FindChan(params[0]);
                        if (c)
                        {
-                               FOREACH_MOD_I(this->ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_CHANNEL,c,params[1],params[2]));
+                               FOREACH_MOD_I(this->ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(c,params[1],params[2]));
                        }
                }
                else if (*(params[0].c_str()) != '#')
@@ -47,7 +47,7 @@ bool TreeSocket::MetaData(const std::string &prefix, parameterlist &params)
                        User* u = this->ServerInstance->FindNick(params[0]);
                        if (u)
                        {
-                               FOREACH_MOD_I(this->ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_USER,u,params[1],params[2]));
+                               FOREACH_MOD_I(this->ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(u,params[1],params[2]));
                        }
                }
        }
index 1601cd6e653d61386d597f944794af909d62bd6e..eda627e3fad721481d5537bfce3668de40c31611 100644 (file)
@@ -46,7 +46,7 @@ void TreeSocket::DoBurst(TreeServer* s)
        /* Send everything else (channel modes, xlines etc) */
        this->SendChannelModes(s);
        this->SendXLines(s);
-       FOREACH_MOD_I(this->ServerInstance,I_OnSyncOtherMetaData,OnSyncOtherMetaData((Module*)Utils->Creator,(void*)this));
+       FOREACH_MOD_I(this->ServerInstance,I_OnSyncNetwork,OnSyncNetwork((Module*)Utils->Creator,(void*)this));
        this->WriteLine(endburst);
        this->ServerInstance->SNO->WriteToSnoMask('l',"Finished bursting to \2"+name+"\2.");
 }
@@ -219,12 +219,6 @@ void TreeSocket::SendChannelModes(TreeServer* Current)
                        this->WriteLine(data);
                }
                FOREACH_MOD_I(this->ServerInstance,I_OnSyncChannel,OnSyncChannel(c->second,(Module*)Utils->Creator,(void*)this));
-               list.clear();
-               c->second->GetExtList(list);
-               for (unsigned int j = 0; j < list.size(); j++)
-               {
-                       FOREACH_MOD_I(this->ServerInstance,I_OnSyncChannelMetaData,OnSyncChannelMetaData(c->second,(Module*)Utils->Creator,(void*)this,list[j]));
-               }
        }
 }
 
@@ -232,7 +226,6 @@ void TreeSocket::SendChannelModes(TreeServer* Current)
 void TreeSocket::SendUsers(TreeServer* Current)
 {
        char data[MAXBUF];
-       std::deque<std::string> list;
        std::string dataline;
        for (user_hash::iterator u = this->ServerInstance->Users->clientlist->begin(); u != this->ServerInstance->Users->clientlist->end(); u++)
        {
@@ -267,12 +260,6 @@ void TreeSocket::SendUsers(TreeServer* Current)
                        }
 
                        FOREACH_MOD_I(this->ServerInstance,I_OnSyncUser,OnSyncUser(u->second,(Module*)Utils->Creator,(void*)this));
-                       list.clear();
-                       u->second->GetExtList(list);
-                       for (unsigned int j = 0; j < list.size(); j++)
-                       {
-                               FOREACH_MOD_I(this->ServerInstance,I_OnSyncUserMetaData,OnSyncUserMetaData(u->second,(Module*)Utils->Creator,(void*)this,list[j]));
-                       }
                }
        }
 }
index 989e8b3e41a9c5de4db1f996255a1661eb67f2a4..804a451ca96cb6e2bae57a73f51c64a6de84564a 100644 (file)
@@ -31,25 +31,19 @@ void SpanningTreeProtocolInterface::SendEncapsulatedData(parameterlist &encap)
        Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
 }
 
-void SpanningTreeProtocolInterface::SendMetaData(void* target, TargetTypeFlags type, const std::string &key, const std::string &data)
+void SpanningTreeProtocolInterface::SendMetaData(Extensible* target, const std::string &key, const std::string &data)
 {
        parameterlist params;
 
-       switch (type)
-       {
-               case TYPE_USER:
-                       params.push_back(((User*)target)->uuid);
-                       break;
-               case TYPE_CHANNEL:
-                       params.push_back(((Channel*)target)->name);
-                       break;
-               case TYPE_SERVER:
-                       params.push_back("*");
-                       break;
-               default:
-                       throw CoreException("I don't know how to handle TYPE_OTHER.");
-                       break;
-       }
+       User* u = dynamic_cast<User*>(target);
+       Channel* c = dynamic_cast<Channel*>(target);
+       if (u)
+               params.push_back(u->uuid);
+       else if (c)
+               params.push_back(c->name);
+       else
+               params.push_back("*");
+
        params.push_back(key);
        params.push_back(":" + data);
 
index 84da6d8cf082819b2095f21a3a14b46fbb0552ff..047d490b6260761fc34e91f1a863d6e8dccc6194 100644 (file)
@@ -14,7 +14,7 @@ class SpanningTreeProtocolInterface : public ProtocolInterface
        virtual ~SpanningTreeProtocolInterface() { }
 
        virtual void SendEncapsulatedData(parameterlist &encap);
-       virtual void SendMetaData(void* target, TargetTypeFlags type, const std::string &key, const std::string &data);
+       virtual void SendMetaData(Extensible* target, const std::string &key, const std::string &data);
        virtual void SendTopic(Channel* channel, std::string &topic);
        virtual void SendMode(const std::string &target, const parameterlist &modedata, const std::vector<TranslateType> &types);
        virtual void SendModeNotice(const std::string &modes, const std::string &text);
index 01509653c20f41c8245f2eeea84ca5773c89c354..185df53757aaedc7a2a28510cecc61184b1ef6ed 100644 (file)
@@ -70,7 +70,7 @@ class ModuleSSLInfo : public Module
        {
                ServerInstance->AddCommand(&cmd);
 
-               Implementation eventlist[] = { I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnWhois, I_OnPreCommand };
+               Implementation eventlist[] = { I_OnSyncUser, I_OnDecodeMetaData, I_OnWhois, I_OnPreCommand };
                ServerInstance->Modules->Attach(eventlist, this, 4);
        }
 
@@ -92,44 +92,30 @@ class ModuleSSLInfo : public Module
                }
        }
 
-       virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
+       virtual void OnSyncUser(User* user, Module* proto, void* opaque)
        {
-               // check if the linking module wants to know about OUR metadata
-               if (extname == "ssl")
-               {
-                       // check if this user has an ssl field to send
-                       if (!user->GetExt(extname))
-                               return;
-
-                       // call this function in the linking module, let it format the data how it
-                       // sees fit, and send it on its way. We dont need or want to know how.
-                       proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, displayable ? "Enabled" : "ON");
-               }
-               else if (extname == "ssl_cert")
-               {
-                       ssl_cert* cert;
-                       if (!user->GetExt("ssl_cert", cert))
-                               return;
-
-                       proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, cert->GetMetaLine().c_str());
-               }
+               if (user->GetExt("ssl"))
+                       proto->ProtoSendMetaData(opaque, user, "ssl", "ON");
+               
+               ssl_cert* cert;
+               if (user->GetExt("ssl_cert", cert))
+                       proto->ProtoSendMetaData(opaque, user, "ssl_cert", cert->GetMetaLine().c_str());
        }
 
-       virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
+       virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata)
        {
+               User* dest = dynamic_cast<User*>(target);
                // check if its our metadata key, and its associated with a user
-               if ((target_type == TYPE_USER) && (extname == "ssl"))
+               if (dest && (extname == "ssl"))
                {
-                       User* dest = static_cast<User*>(target);
                        // if they dont already have an ssl flag, accept the remote server's
                        if (!dest->GetExt(extname))
                        {
                                dest->Extend(extname);
                        }
                }
-               else if ((target_type == TYPE_USER) && (extname == "ssl_cert"))
+               else if (dest && (extname == "ssl_cert"))
                {
-                       User* dest = static_cast<User*>(target);
                        if (dest->GetExt(extname))
                                return;
 
@@ -173,9 +159,9 @@ class ModuleSSLInfo : public Module
 
        virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
-               irc::string cmd = command.c_str();
+               irc::string pcmd = command.c_str();
 
-               if ((cmd == "OPER") && (validated))
+               if ((pcmd == "OPER") && (validated))
                {
                        ConfigReader cf(ServerInstance);
                        char TheHost[MAXBUF];
index ada7fbc68a1f4a64ed3a6785b391953238e9e99e..276fef038cab386c6695a06b738eb8ce689d5e11 100644 (file)
@@ -151,8 +151,8 @@ class ModuleSVSHold : public Module
        {
                ServerInstance->XLines->RegisterFactory(&s);
                ServerInstance->AddCommand(&cmd);
-               Implementation eventlist[] = { I_OnUserPreNick, I_OnSyncOtherMetaData, I_OnDecodeMetaData, I_OnStats };
-               ServerInstance->Modules->Attach(eventlist, this, 4);
+               Implementation eventlist[] = { I_OnUserPreNick, I_OnStats };
+               ServerInstance->Modules->Attach(eventlist, this, 2);
        }
 
 
index 5a253069e0013ccf0f3b4ff74801bccc42ee29b5..9939a83a2c281e626d3d14c479d88e6ea8db76c9 100644 (file)
@@ -64,7 +64,7 @@ class CommandSwhois : public Command
                 * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
                 * -- Brain
                 */
-               ServerInstance->PI->SendMetaData(dest, TYPE_USER, "swhois", *text);
+               ServerInstance->PI->SendMetaData(dest, "swhois", *text);
 
                // If it's an empty swhois, unset it (not ideal, but ok)
                if (text->empty())
@@ -90,7 +90,7 @@ class ModuleSWhois : public Module
 
                Conf = new ConfigReader(ServerInstance);
                ServerInstance->AddCommand(&cmd);
-               Implementation eventlist[] = { I_OnDecodeMetaData, I_OnWhoisLine, I_OnSyncUserMetaData, I_OnUserQuit, I_OnCleanup, I_OnRehash, I_OnPostCommand };
+               Implementation eventlist[] = { I_OnDecodeMetaData, I_OnWhoisLine, I_OnSyncUser, I_OnUserQuit, I_OnCleanup, I_OnRehash, I_OnPostCommand };
                ServerInstance->Modules->Attach(eventlist, this, 7);
        }
 
@@ -124,20 +124,12 @@ class ModuleSWhois : public Module
        // this method is called. We should use the ProtoSendMetaData function after we've
        // corrected decided how the data should look, to send the metadata on its way if
        // it is ours.
-       virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
+       virtual void OnSyncUser(User* user, Module* proto, void* opaque)
        {
-               // check if the linking module wants to know about OUR metadata
-               if (extname == "swhois")
-               {
-                       // check if this user has an swhois field to send
-                       std::string* swhois;
-                       if (user->GetExt("swhois", swhois))
-                       {
-                               // call this function in the linking module, let it format the data how it
-                               // sees fit, and send it on its way. We dont need or want to know how.
-                               proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*swhois);
-                       }
-               }
+               // check if this user has an swhois field to send
+               std::string* swhois;
+               if (user->GetExt("swhois", swhois))
+                       proto->ProtoSendMetaData(opaque,user,"swhois",*swhois);
        }
 
        // when a user quits, tidy up their metadata
@@ -154,15 +146,13 @@ class ModuleSWhois : public Module
        // if the module is unloaded, tidy up all our dangling metadata
        virtual void OnCleanup(int target_type, void* item)
        {
-               if (target_type == TYPE_USER)
+               if (target_type != TYPE_USER) return;
+               User* user = static_cast<User*>(item);
+               std::string* swhois;
+               if (user && user->GetExt("swhois", swhois))
                {
-                       User* user = (User*)item;
-                       std::string* swhois;
-                       if (user->GetExt("swhois", swhois))
-                       {
-                               user->Shrink("swhois");
-                               delete swhois;
-                       }
+                       user->Shrink("swhois");
+                       delete swhois;
                }
        }
 
@@ -173,27 +163,26 @@ class ModuleSWhois : public Module
        // In our case we're only sending a single string around, so we just construct a std::string.
        // Some modules will probably get much more complex and format more detailed structs and classes
        // in a textual way for sending over the link.
-       virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
+       virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata)
        {
+               User* dest = dynamic_cast<User*>(target);
                // check if its our metadata key, and its associated with a user
-               if ((target_type == TYPE_USER) && (extname == "swhois"))
-               {
-                       User* dest = (User*)target;
+               if (extname != "swhois" || !dest)
+                       return;
 
-                       // if they already have an swhois field, trash it and replace it with the remote one.
-                       std::string* text;
-                       if (dest->GetExt("swhois", text))
-                       {
-                               dest->Shrink("swhois");
-                               delete text;
-                       }
+               // if they already have an swhois field, trash it and replace it with the remote one.
+               std::string* text;
+               if (dest->GetExt("swhois", text))
+               {
+                       dest->Shrink("swhois");
+                       delete text;
+               }
 
-                       if (extdata.empty())
-                               return; // XXX does the command parser even allow sending blank mdata? it needs to here! -- w00t
+               if (extdata.empty())
+                       return;
 
-                       text = new std::string(extdata);
-                       dest->Extend("swhois", text);
-               }
+               text = new std::string(extdata);
+               dest->Extend("swhois", text);
        }
 
        virtual void OnPostCommand(const std::string &command, const std::vector<std::string> &params, User *user, CmdResult result, const std::string &original_line)
@@ -240,7 +229,7 @@ class ModuleSWhois : public Module
 
                std::string *text = new std::string(swhois);
                user->Extend("swhois", text);
-               ServerInstance->PI->SendMetaData(user, TYPE_USER, "swhois", *text);
+               ServerInstance->PI->SendMetaData(user, "swhois", *text);
        }
 
        virtual ~ModuleSWhois()
index 6f06b36605558828af65c0b7f0468d25dbacedb8..83ee05749211f4a0a6f8bb11982ca6c6da353636 100644 (file)
 class CommandTaxonomy : public Command
 {
        Module* Creator;
-       bool& claimed;
  public:
        /* Command 'taxonomy', takes no parameters and needs no special modes */
-       CommandTaxonomy (InspIRCd* Instance, Module* maker, bool &claim) : Command(Instance,"TAXONOMY", "o", 1), Creator(maker), claimed(claim)
+       CommandTaxonomy (InspIRCd* Instance, Module* maker) : Command(Instance,"TAXONOMY", "o", 1), Creator(maker)
        {
                this->source = "m_taxonomy.so";
                syntax = "<nickname>";
@@ -37,15 +36,7 @@ class CommandTaxonomy : public Command
                        std::deque<std::string> list;
                        dest->GetExtList(list);
                        user->WriteNumeric(304, "" + std::string(user->nick) + ":TAXONOMY ITEMS " + std::string(dest->nick) + " " +ConvToStr(list.size()));
-                       for (unsigned int j = 0; j < list.size(); j++)
-                       {
-                               claimed = false;
-                               FOREACH_MOD(I_OnSyncUserMetaData, OnSyncUserMetaData(dest, Creator, user, list[j], true));
-                               if (!claimed)
-                               {
-                                       user->WriteNumeric(304, "" + std::string(user->nick) + ":TAXONOMY METADATA " + list[j] + " = <unknown>");
-                               }
-                       }
+                       FOREACH_MOD(I_OnSyncUser, OnSyncUser(dest, Creator, user));
                        user->WriteNumeric(304, "" + std::string(user->nick) + ":TAXONOMY END");
                }
                return CMD_LOCALONLY;
@@ -55,24 +46,19 @@ class CommandTaxonomy : public Command
 class ModuleTaxonomy : public Module
 {
        CommandTaxonomy cmd;
-       bool claimed;
  public:
        ModuleTaxonomy(InspIRCd* Me)
-               : Module(Me), cmd(Me, this, claimed)
+               : Module(Me), cmd(Me, this)
        {
                ServerInstance->AddCommand(&cmd);
        }
 
 
-       void ProtoSendMetaData(void* opaque, TargetTypeFlags target_type, void* target, const std::string &extname, const std::string &extdata)
+       void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata)
        {
-               if (target_type == TYPE_USER)
-               {
-                       User* spoolto = (User*)opaque;
-                       std::string taxstr = "304 " + std::string(spoolto->nick) + ":TAXONOMY METADATA "+extname+" = "+extdata;
-                       spoolto->WriteServ(taxstr);
-                       claimed = true;
-               }
+               User* spoolto = (User*)opaque;
+               std::string taxstr = "304 " + std::string(spoolto->nick) + ":TAXONOMY METADATA "+extname+" = "+extdata;
+               spoolto->WriteServ(taxstr);
        }
 
        virtual ~ModuleTaxonomy()
@@ -83,6 +69,17 @@ class ModuleTaxonomy : public Module
        {
                return Version("$Id$", VF_VENDOR, API_VERSION);
        }
+
+       virtual std::string ProtoTranslate(Extensible* item)
+       {
+               User* u = dynamic_cast<User*>(item);
+               Channel* c = dynamic_cast<Channel*>(item);
+               if (u)
+                       return u->nick;
+               if (c)
+                       return c->name;
+               return "?";
+       }
 };
 
 MODULE_INIT(ModuleTaxonomy)
index e9038e57a628abab3de7eb4878538fac3c5aacb8..70036d5a2da2e92b78bfc91530ea95b9749ed298 100644 (file)
@@ -24,7 +24,7 @@ class ModuleUHNames : public Module
        ModuleUHNames(InspIRCd* Me)
                : Module(Me)
        {
-               Implementation eventlist[] = { I_OnEvent, I_OnSyncUserMetaData, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric };
+               Implementation eventlist[] = { I_OnEvent, I_OnSyncUser, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, 5);
        }
 
@@ -32,10 +32,10 @@ class ModuleUHNames : public Module
        {
        }
 
-       void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable)
+       void OnSyncUser(User* user, Module* proto,void* opaque)
        {
-               if ((displayable) && (extname == "UHNAMES"))
-                       proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "Enabled");
+               if (proto->ProtoTranslate(NULL) == "?" && user->GetExt("UHNAMES"))
+                       proto->ProtoSendMetaData(opaque, user, "UHNAMES", "Enabled");
        }
 
        virtual Version GetVersion()