/* +------------------------------------+ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * * InspIRCd: (C) 2002-2008 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. * * --------------------------------------------------- */ /* $Core: libIRCDcommand_parse */ #include "inspircd.h" #include "wildcard.h" #include "xline.h" #include "socketengine.h" #include "socket.h" #include "command_parse.h" #include "exitcodes.h" /* Directory Searching for Unix-Only */ #ifndef WIN32 #include #include #endif int InspIRCd::PassCompare(Extensible* ex, const std::string &data, const std::string &input, const std::string &hashtype) { int MOD_RESULT = 0; FOREACH_RESULT_I(this,I_OnPassCompare,OnPassCompare(ex, data, input, hashtype)) if (MOD_RESULT == 1) return 0; if (MOD_RESULT == -1) return 1; return data != input; // this seems back to front, but returns 0 if they *match*, 1 else } /* LoopCall is used to call a command classes handler repeatedly based on the contents of a comma seperated list. * There are two overriden versions of this method, one of which takes two potential lists and the other takes one. * We need a version which takes two potential lists for JOIN, because a JOIN may contain two lists of items at once, * the channel names and their keys as follows: * JOIN #chan1,#chan2,#chan3 key1,,key3 * Therefore, we need to deal with both lists concurrently. The first instance of this method does that by creating * two instances of irc::commasepstream and reading them both together until the first runs out of tokens. * The second version is much simpler and just has the one stream to read, and is used in NAMES, WHOIS, PRIVMSG etc. * Both will only parse until they reach ServerInstance->Config->MaxTargets number of targets, to stop abuse via spam. */ int CommandParser::LoopCall(User* user, Command* CommandObj, const std::vector& parameters, unsigned int splithere, unsigned int extra) { if (splithere >= parameters.size()) return 0; /* First check if we have more than one item in the list, if we don't we return zero here and the handler * which called us just carries on as it was. */ if (parameters[splithere].find(',') == std::string::npos) return 0; /** Some lame ircds will weed out dupes using some shitty O(n^2) algorithm. * By using std::map (thanks for the idea w00t) we can cut this down a ton. * ...VOOODOOOO! */ std::map dupes; /* Create two lists, one for channel names, one for keys */ irc::commasepstream items1(parameters[splithere]); irc::commasepstream items2(parameters[extra]); std::string extrastuff; std::string item; unsigned int max = 0; /* Attempt to iterate these lists and call the command objech * which called us, for every parameter pair until there are * no more left to parse. */ while (items1.GetToken(item) && (max++ < ServerInstance->Config->MaxTargets)) { if (dupes.find(item.c_str()) == dupes.end()) { std::vector new_parameters; for (unsigned int t = 0; (t < parameters.size()) && (t < MAXPARAMETERS); t++) new_parameters.push_back(parameters[t]); if (!items2.GetToken(extrastuff)) extrastuff = ""; new_parameters[splithere] = item.c_str(); new_parameters[extra] = extrastuff.c_str(); CommandObj->Handle(new_parameters, user); dupes[item.c_str()] = true; } } return 1; } int CommandParser::LoopCall(User* user, Command* CommandObj, const std::vector& parameters, unsigned int splithere) { if (splithere >= parameters.size()) return 0; /* First check if we have more than one item in the list, if we don't we return zero here and the handler * which called us just carries on as it was. */ if (parameters[splithere].find(',') == std::string::npos) return 0; std::map dupes; /* Only one commasepstream here */ irc::commasepstream items1(parameters[splithere]); std::string item; unsigned int max = 0; /* Parse the commasepstream until there are no tokens remaining. * Each token we parse out, call the command handler that called us * with it */ while (items1.GetToken(item) && (max++ < ServerInstance->Config->MaxTargets)) { if (dupes.find(item.c_str()) == dupes.end()) { std::vector new_parameters; for (unsigned int t = 0; (t < parameters.size()) && (t < MAXPARAMETERS); t++) new_parameters.push_back(parameters[t]); new_parameters[splithere] = item.c_str(); /* Execute the command handler. */ CommandObj->Handle(new_parameters, user); dupes[item.c_str()] = true; } } /* By returning 1 we tell our caller that nothing is to be done, * as all the previous calls handled the data. This makes the parent * return without doing any processing. */ return 1; } bool CommandParser::IsValidCommand(const std::string &commandname, unsigned int pcnt, User * user) { Commandtable::iterator n = cmdlist.find(commandname); if (n != cmdlist.end()) { if ((pcnt >= n->second->min_params) && (n->second->source != "")) { if (IS_LOCAL(user) && n->second->flags_needed) { if (user->IsModeSet(n->second->flags_needed)) { return (user->HasPermission(commandname)); } } else { return true; } } } return false; } Command* CommandParser::GetHandler(const std::string &commandname) { Commandtable::iterator n = cmdlist.find(commandname); if (n != cmdlist.end()) return n->second; return NULL; } // calls a handler function for a command CmdResult CommandParser::CallHandler(const std::string &commandname, const std::vector& parameters, User *user) { Commandtable::iterator n = cmdlist.find(commandname); if (n != cmdlist.end()) { if (parameters.size() >= n->second->min_params) { bool bOkay = false; if (IS_LOCAL(user) && n->second->flags_needed) { /* if user is local, and flags are needed .. */ if (user->IsModeSet(n->second->flags_needed)) { /* if user has the flags, and now has the permissions, go ahead */ if (user->HasPermission(commandname)) bOkay = true; } } else { /* remote or no flags required anyway */ bOkay = true; } if (bOkay) { return n->second->Handle(parameters,user); } } } return CMD_INVALID; } void CommandParser::DoLines(User* current, bool one_only) { // while there are complete lines to process... unsigned int floodlines = 0; while (current->BufferIsReady()) { if (current->MyClass) { if (ServerInstance->Time() > current->reset_due) { current->reset_due = ServerInstance->Time() + current->MyClass->GetThreshold(); current->lines_in = 0; } if (++current->lines_in > current->MyClass->GetFlood() && current->MyClass->GetFlood()) { ServerInstance->FloodQuitUser(current); return; } if ((++floodlines > current->MyClass->GetFlood()) && (current->MyClass->GetFlood() != 0)) { ServerInstance->FloodQuitUser(current); return; } } // use GetBuffer to copy single lines into the sanitized string std::string single_line = current->GetBuffer(); current->bytes_in += single_line.length(); current->cmds_in++; if (single_line.length() > MAXBUF - 2) // MAXBUF is 514 to allow for neccessary line terminators single_line.resize(MAXBUF - 2); // So to trim to 512 here, we use MAXBUF - 2 // ProcessBuffer returns false if the user has gone over penalty if (!ServerInstance->Parser->ProcessBuffer(single_line, current) || one_only) break; } } bool CommandParser::ProcessCommand(User *user, std::string &cmd) { std::vector command_p; ir
/*       +------------------------------------+
 *       | Inspire Internet Relay Chat Daemon |
 *       +------------------------------------+
 *
 *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
 * See: http://wiki.inspircd.org/Credits
 *
 * This program is free but copyrighted software; see
 *	  the file COPYING for details.
 *
 * ---------------------------------------------------
 */

/* $ModDesc: Provides a spanning tree server link protocol */

#include "inspircd.h"
#include "commands/cmd_whois.h"
#include "commands/cmd_stats.h"
#include "socket.h"
#include "xline.h"
#include "transport.h"

#include "m_spanningtree/main.h"
#include "m_spanningtree/utils.h"
#include "m_spanningtree/treeserver.h"
#include "m_spanningtree/treesocket.h"

/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */

void ModuleSpanningTree::OnPostCommand(const std::string &command, const std::vector<std::string>& parameters, User *user, CmdResult result, const std::string &original_line)
{
	if ((result == CMD_SUCCESS) && (ServerInstance->IsValidModuleCommand(command, parameters.size(), user)))
	{
		/* Safe, we know its non-null because IsValidModuleCommand returned true */
		Command* thiscmd = ServerInstance