From 276bbd193ed9dc53f44a4f564401d577d8e31424 Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 10 May 2007 20:53:31 +0000 Subject: Add m_taxonomy and api minor tweak to make it work, enable some modules for it. I have higher aims for this module, namely a neat fix for feature request in bug #285 git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6967 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/modules.h | 14 ++-- src/modules.cpp | 6 +- src/modules/extra/m_ssl_gnutls.cpp | 4 +- src/modules/extra/m_ssl_openssl.cpp | 4 +- src/modules/m_cban.cpp | 2 +- src/modules/m_cgiirc.cpp | 2 +- src/modules/m_filter.h | 4 +- src/modules/m_namesx.cpp | 8 ++- src/modules/m_services_account.cpp | 2 +- src/modules/m_ssl_dummy.cpp | 4 +- src/modules/m_svshold.cpp | 2 +- src/modules/m_swhois.cpp | 2 +- src/modules/m_taxonomy.cpp | 123 ++++++++++++++++++++++++++++++++++++ src/modules/m_uhnames.cpp | 8 ++- 14 files changed, 163 insertions(+), 22 deletions(-) create mode 100644 src/modules/m_taxonomy.cpp diff --git a/include/modules.h b/include/modules.h index 78bb103fa..fe921a540 100644 --- a/include/modules.h +++ b/include/modules.h @@ -75,7 +75,7 @@ enum MessageType { * ipv4 servers, so this value will be ten times as * high on ipv6 servers. */ -#define NATIVE_API_VERSION 11021 +#define NATIVE_API_VERSION 11022 #ifdef IPV6 #define API_VERSION (NATIVE_API_VERSION * 10) #else @@ -791,8 +791,10 @@ class Module : public Extensible * @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(chanrec* chan, Module* proto,void* opaque, const std::string &extname); + virtual void OnSyncChannelMetaData(chanrec* 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 @@ -804,8 +806,10 @@ class Module : public Extensible * @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(userrec* user, Module* proto,void* opaque, const std::string &extname); + virtual void OnSyncUserMetaData(userrec* 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 @@ -815,8 +819,10 @@ class Module : public Extensible * if it belongs to your module. * @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 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); + virtual void OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable = false); /** 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. diff --git a/src/modules.cpp b/src/modules.cpp index f4b2b294f..0acc3683c 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -164,9 +164,9 @@ void Module::OnGetServerDescription(const std::string &servername,std::string & void Module::OnSyncUser(userrec* user, Module* proto, void* opaque) { }; void Module::OnSyncChannel(chanrec* chan, Module* proto, void* opaque) { }; void Module::ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline) { }; -void Module::OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, const std::string &extname) { }; -void Module::OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, const std::string &extname) { }; -void Module::OnSyncOtherMetaData(Module* proto, void* opaque) { }; +void Module::OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, const std::string &extname, bool displayable) { }; +void Module::OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, const std::string &extname, bool displayable) { }; +void Module::OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable) { }; void Module::OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata) { }; void Module::ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata) { }; void Module::OnWallops(userrec* user, const std::string &text) { }; diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index def9abdd2..0e923df41 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -559,7 +559,7 @@ class ModuleSSLGnuTLS : public Module } } - virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname) + virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable) { // check if the linking module wants to know about OUR metadata if(extname == "ssl") @@ -569,7 +569,7 @@ class ModuleSSLGnuTLS : public Module { // 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, "ON"); + proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, displayable ? "Enabled" : "ON"); } } } diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index ee672b798..53c595365 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -644,7 +644,7 @@ class ModuleSSLOpenSSL : public Module } } - virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname) + virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable) { // check if the linking module wants to know about OUR metadata if (extname == "ssl") @@ -654,7 +654,7 @@ class ModuleSSLOpenSSL : public Module { // 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, "ON"); + proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, displayable ? "Enabled" : "ON"); } } } diff --git a/src/modules/m_cban.cpp b/src/modules/m_cban.cpp index 32cd40d83..5491f5e3a 100644 --- a/src/modules/m_cban.cpp +++ b/src/modules/m_cban.cpp @@ -172,7 +172,7 @@ class ModuleCBan : public Module return 0; } - virtual void OnSyncOtherMetaData(Module* proto, void* opaque) + virtual void OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable) { for(cbanlist::iterator iter = cbans.begin(); iter != cbans.end(); iter++) { diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp index 04a56b1fa..b3cc24839 100644 --- a/src/modules/m_cgiirc.cpp +++ b/src/modules/m_cgiirc.cpp @@ -209,7 +209,7 @@ public: } } - virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname) + virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable) { if((extname == "cgiirc_realhost") || (extname == "cgiirc_realip")) { diff --git a/src/modules/m_filter.h b/src/modules/m_filter.h index b31a03271..5797cc310 100644 --- a/src/modules/m_filter.h +++ b/src/modules/m_filter.h @@ -54,7 +54,7 @@ class FilterBase : public Module virtual Version GetVersion(); std::string EncodeFilter(FilterResult* filter); FilterResult DecodeFilter(const std::string &data); - virtual void OnSyncOtherMetaData(Module* proto, void* opaque); + 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 int OnStats(char symbol, userrec* user, string_list &results) = 0; virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line); @@ -343,7 +343,7 @@ FilterResult FilterBase::DecodeFilter(const std::string &data) return res; } -void FilterBase::OnSyncOtherMetaData(Module* proto, void* opaque) +void FilterBase::OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable) { this->SyncFilters(proto, opaque); } diff --git a/src/modules/m_namesx.cpp b/src/modules/m_namesx.cpp index dd2b32e7b..db8270cb9 100644 --- a/src/modules/m_namesx.cpp +++ b/src/modules/m_namesx.cpp @@ -31,13 +31,19 @@ class ModuleNamesX : public Module void Implements(char* List) { - List[I_OnPreCommand] = List[I_OnUserList] = List[I_On005Numeric] = 1; + List[I_OnSyncUserMetaData] = List[I_OnPreCommand] = List[I_OnUserList] = List[I_On005Numeric] = 1; } virtual ~ModuleNamesX() { } + void OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, const std::string &extname, bool displayable) + { + if ((displayable) && (extname == "NAMESX")) + proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "Enabled"); + } + virtual Version GetVersion() { return Version(1,1,0,1,VF_VENDOR,API_VERSION); diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp index 04d5751ec..6defa1e2e 100644 --- a/src/modules/m_services_account.cpp +++ b/src/modules/m_services_account.cpp @@ -225,7 +225,7 @@ 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(userrec* user, Module* proto, void* opaque, const std::string &extname) + virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable) { // check if the linking module wants to know about OUR metadata if (extname == "accountname") diff --git a/src/modules/m_ssl_dummy.cpp b/src/modules/m_ssl_dummy.cpp index 69e4da3e1..6f1ee4789 100644 --- a/src/modules/m_ssl_dummy.cpp +++ b/src/modules/m_ssl_dummy.cpp @@ -52,7 +52,7 @@ class ModuleSSLDummy : public Module } } - virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname) + virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable) { // check if the linking module wants to know about OUR metadata if(extname == "ssl") @@ -62,7 +62,7 @@ class ModuleSSLDummy : public Module { // 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, "ON"); + proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, displayable ? "Enabled" : "ON"); } } } diff --git a/src/modules/m_svshold.cpp b/src/modules/m_svshold.cpp index ad1ec8085..abef3d713 100644 --- a/src/modules/m_svshold.cpp +++ b/src/modules/m_svshold.cpp @@ -194,7 +194,7 @@ class ModuleSVSHold : public Module return 0; } - virtual void OnSyncOtherMetaData(Module* proto, void* opaque) + virtual void OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable) { for(SVSHoldMap::iterator iter = HoldMap.begin(); iter != HoldMap.end(); iter++) { diff --git a/src/modules/m_swhois.cpp b/src/modules/m_swhois.cpp index 3dcdb10f2..a79b1d10a 100644 --- a/src/modules/m_swhois.cpp +++ b/src/modules/m_swhois.cpp @@ -123,7 +123,7 @@ 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(userrec* user, Module* proto, void* opaque, const std::string &extname) + virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable) { // check if the linking module wants to know about OUR metadata if (extname == "swhois") diff --git a/src/modules/m_taxonomy.cpp b/src/modules/m_taxonomy.cpp new file mode 100644 index 000000000..c573e7761 --- /dev/null +++ b/src/modules/m_taxonomy.cpp @@ -0,0 +1,123 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +#include +#include "users.h" +#include "channels.h" +#include "modules.h" +#include "inspircd.h" + +/* $ModDesc: Provides the /TAXONOMY command, used to view all metadata attached to a user */ + +/** Handle /WOOT + */ +class cmd_taxonomy : public command_t +{ + Module* Creator; + bool& claimed; + public: + /* Command 'taxonomy', takes no parameters and needs no special modes */ + cmd_taxonomy (InspIRCd* Instance, Module* maker, bool &claim) : command_t(Instance,"TAXONOMY", 'o', 1), Creator(maker), claimed(claim) + { + this->source = "m_taxonomy.so"; + } + + CmdResult Handle (const char** parameters, int pcnt, userrec *user) + { + userrec* dest = ServerInstance->FindNick(parameters[0]); + if (dest) + { + std::deque list; + list.clear(); + user->GetExtList(list); + user->WriteServ("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(user, Creator, dest, list[j], true)); + if (!claimed) + { + user->WriteServ("304 " + std::string(user->nick) + ":TAXONOMY METADATA " + list[j] + " = "); + } + } + user->WriteServ("304 " + std::string(user->nick) + ":TAXONOMY END"); + } + return CMD_FAILURE; + } +}; + +class ModuleTaxonomy : public Module +{ + cmd_taxonomy* newcommand; + bool claimed; + public: + ModuleTaxonomy(InspIRCd* Me) + : Module::Module(Me) + { + + // Create a new command + newcommand = new cmd_taxonomy(ServerInstance, this, claimed); + ServerInstance->AddCommand(newcommand); + } + + void Implements(char* List) + { + List[I_ProtoSendMetaData] = 1; + } + + void ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata) + { + if (target_type == TYPE_USER) + { + userrec* spool = (userrec*)opaque; + std::string taxstr = "304 " + std::string(spool->nick) + ":TAXONOMY METADATA "+extname+" = "+extdata; + spool->WriteServ(taxstr); + claimed = true; + } + } + + virtual ~ModuleTaxonomy() + { + } + + virtual Version GetVersion() + { + return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION); + } +}; + + +class ModuleTaxonomyFactory : public ModuleFactory +{ + public: + ModuleTaxonomyFactory() + { + } + + ~ModuleTaxonomyFactory() + { + } + + virtual Module * CreateModule(InspIRCd* Me) + { + return new ModuleTaxonomy(Me); + } + +}; + + +extern "C" void * init_module( void ) +{ + return new ModuleTaxonomyFactory; +} + diff --git a/src/modules/m_uhnames.cpp b/src/modules/m_uhnames.cpp index b0981d58d..3663ab4ca 100644 --- a/src/modules/m_uhnames.cpp +++ b/src/modules/m_uhnames.cpp @@ -32,13 +32,19 @@ class ModuleUHNames : public Module void Implements(char* List) { - List[I_OnPreCommand] = List[I_OnUserList] = List[I_On005Numeric] = 1; + List[I_OnSyncUserMetaData] = List[I_OnPreCommand] = List[I_OnUserList] = List[I_On005Numeric] = 1; } virtual ~ModuleUHNames() { } + void OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, const std::string &extname, bool displayable) + { + if ((displayable) && (extname == "UHNAMES")) + proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "Enabled"); + } + virtual Version GetVersion() { return Version(1,1,0,1,VF_VENDOR,API_VERSION); -- cgit v1.2.3