X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fcommand_parse.h;h=2c883be203b696458ea4c6366af404c907161355;hb=e6d000042ea75d4e0485bec9564b47163a3ca414;hp=40c3425fbe3dfc0e139f57c13d10e61152aa4d4a;hpb=ecd5b4082a7ef4ae89116761c77285ed77b7a794;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/command_parse.h b/include/command_parse.h index 40c3425fb..2c883be20 100644 --- a/include/command_parse.h +++ b/include/command_parse.h @@ -2,12 +2,9 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits * - * Written by Craig Edwards, Craig McLure, and others. * This program is free but copyrighted software; see * the file COPYING for details. * @@ -22,8 +19,12 @@ #include "ctables.h" #include "typedefs.h" +/** Required forward declaration + */ class InspIRCd; +/** A list of dll/so files containing the command handlers for the core + */ typedef std::map SharedObjectList; /** This class handles command management and parsing. @@ -31,13 +32,17 @@ typedef std::map SharedObjectList; * call command handlers by name, and chop up comma seperated * parameters into multiple calls. */ -class CommandParser : public classbase +class CoreExport CommandParser : public classbase { private: /** The creator of this class */ InspIRCd* ServerInstance; + /** Parameter buffer + */ + std::vector para; + /** Process a parameter string into a list of items * @param command_p The output list of items * @param parameters The input string @@ -51,10 +56,6 @@ class CommandParser : public classbase */ void ProcessCommand(userrec *user, std::string &cmd); - /** Insert the default RFC1459 commands into the command hash. - */ - void SetupCommandTable(); - /** Finds the init_command symbol in a .so file * @param v A function pointer to be initialized * @param h A valid shared object handle @@ -68,8 +69,15 @@ class CommandParser : public classbase /** Load a command from a shared object on disk. * @param name The shared object to load (without path) + * @return NULL on success, pointer to dlerrr() error message on failure + */ + const char* LoadCommand(const char* name); + + /** Removes a command if the sources match. Used as a helper for + * safe hash_map delete while iter in RemoveCommands(const char* source). */ - void LoadCommand(const char* name); + void RemoveCommand(nspace::hash_map::iterator safei, const char* source); + public: /** Command list, a hash_map of command names to command_t* @@ -84,7 +92,7 @@ class CommandParser : public classbase * @return True if the command was reloaded, false if it could not be found * or another error occured */ - bool ReloadCommand(const char* cmd); + bool ReloadCommand(const char* cmd, userrec* user); /** Default constructor. * @param Instance The creator of this class @@ -104,6 +112,12 @@ class CommandParser : public classbase */ CmdResult CallHandler(const std::string &commandname,const char** parameters, int pcnt, userrec *user); + /** Get the handler function for a command. + * @param commandname The command required. Always use uppercase for this parameter. + * @return a pointer to the command handler, or NULL + */ + command_t* GetHandler(const std::string &commandname); + /** This function returns true if a command is valid with the given number of parameters and user. * @param commandname The command name to check * @param pcnt The parameter count @@ -180,6 +194,21 @@ class CommandParser : public classbase * @return True if the command was added */ bool CreateCommand(command_t *f, void* so_handle = NULL); + + /** Insert the default RFC1459 commands into the command hash. + * Ignore any already loaded commands. + * @param user User to spool errors to, or if NULL, when an error occurs spool the errors to + * stdout then exit with EXIT_STATUS_HANDLER. + */ + void SetupCommandTable(userrec* user); + + /** Translate nicknames in a string into UIDs, based on the TranslationType given. + * @param to The translation type to use for the process. + * @param source The input string + * @param dest The output string, it is safe to pass source and dest as the same variable only for translation type TR_TEXT. + * @return returns the number of substitutions made. Will always be 0 or 1 for TR_TEXT and 0..n for other types. + */ + int TranslateUIDs(TranslateType to, const std::string &source, std::string &dest); }; /** Command handler class for the RELOAD command. @@ -196,6 +225,32 @@ class cmd_reload : public command_t CmdResult Handle(const char** parameters, int pcnt, userrec *user); }; - +/** A lookup table of values for multiplier characters used by + * InspIRCd::Duration(). In this lookup table, the indexes for + * the ascii values 'm' and 'M' have the value '60', the indexes + * for the ascii values 'D' and 'd' have a value of '86400', etc. + */ +const int duration_multi[] = +{ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 86400, 1, 1, 1, 3600, + 1, 1, 1, 1, 60, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 604800, 1, 31536000, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 86400, 1, 1, 1, 3600, 1, 1, 1, 1, 60, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 604800, 1, 31536000, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 +}; #endif +