summaryrefslogtreecommitdiff
path: root/include/modules.h
diff options
context:
space:
mode:
authorrburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864>2009-02-09 21:01:05 +0000
committerrburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864>2009-02-09 21:01:05 +0000
commitd7d01bdc5c667a1fafd95241282b58e03b4caa5b (patch)
treef1482d8734da609923c6d8af6bc8fcb0fc187534 /include/modules.h
parentd49b3a25fda5f597491e73640dd1e76babc240eb (diff)
Squashed commit: merge next (1.9.1) back to trunk.
SVN users, NOTE: THIS WILL NOT BUILD, NOR SHOULD YOU RUN IT YET. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1953 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'include/modules.h')
-rw-r--r--include/modules.h162
1 files changed, 103 insertions, 59 deletions
diff --git a/include/modules.h b/include/modules.h
index 5c4eaa67c..eb0b8c4a6 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -20,30 +20,24 @@
/* Cross OS compatibility macros */
#ifdef _WIN32
-typedef HMODULE ano_module_t;
-
-#define ano_modopen(file) LoadLibrary(file)
-/* ano_moderr in modules.c */
-#define ano_modsym(file, symbol) (HMODULE)GetProcAddress(file, symbol)
-#define ano_modclose(file) FreeLibrary(file) ? 0 : 1
-#define ano_modclearerr() SetLastError(0)
-#define MODULE_EXT ".so"
-
+ typedef HMODULE ano_module_t;
+
+ #define dlopen(file, unused) LoadLibrary(file)
+ MDE const char *dlerror();
+ #define dlsym(file, symbol) (HMODULE)GetProcAddress(file, symbol)
+ #define dlclose(file) FreeLibrary(file) ? 0 : 1
+ #define ano_modclearerr() SetLastError(0)
+ #define MODULE_EXT ".so"
#else
-typedef void * ano_module_t;
-
-#define ano_modopen(file) dlopen(file, RTLD_LAZY)
-#define ano_moderr() dlerror()
-#define ano_modsym(file, symbol) dlsym(file, symbol)
-#define ano_modclose(file) dlclose(file)
-/* We call dlerror() here because it clears the module error after being
- * called. This previously read 'errno = 0', but that didn't work on
- * all POSIX-compliant architectures. This way the error is guaranteed
- * to be cleared, POSIX-wise. -GD
- */
-#define ano_modclearerr() dlerror()
-#define MODULE_EXT ".so"
+ typedef void * ano_module_t;
+ /* We call dlerror() here because it clears the module error after being
+ * called. This previously read 'errno = 0', but that didn't work on
+ * all POSIX-compliant architectures. This way the error is guaranteed
+ * to be cleared, POSIX-wise. -GD
+ */
+ #define ano_modclearerr() dlerror()
+ #define MODULE_EXT ".so"
#endif
@@ -51,8 +45,13 @@ typedef void * ano_module_t;
#define CMD_HASH(x) (((x)[0]&31)<<5 | ((x)[1]&31)) /* Will gen a hash from a string :) */
#define MAX_CMD_HASH 1024
-#define MOD_STOP 1
-#define MOD_CONT 0
+/** The return value from commands.
+ */
+enum CommandReturn
+{
+ MOD_CONT,
+ MOD_STOP
+};
#define HOSTSERV HS_cmdTable /* using HOSTSERV etc. looks nicer than HS_cmdTable for modules */
#define BOTSERV BS_cmdTable
@@ -122,7 +121,6 @@ typedef enum { MOD_OP_LOAD, MOD_OP_UNLOAD } ModuleOperation;
/*************************************************************************/
/* Structure for information about a *Serv command. */
-typedef struct Command_ Command;
struct CommandHash;
typedef struct ModuleLang_ ModuleLang;
typedef struct ModuleHash_ ModuleHash;
@@ -148,6 +146,86 @@ struct ModuleLang_ {
char **argv;
};
+/** Every services command is a class, inheriting from Command.
+ */
+class Command
+{
+ public:
+ size_t MaxParams;
+ size_t MinParams;
+ std::string name;
+
+ /** Create a new command.
+ * @param min_params The minimum number of parameters the parser will require to execute this command
+ * @param max_params The maximum number of parameters the parser will create, after max_params, all will be combined into the last argument.
+ * NOTE: If max_params is not set (default), there is no limit to the max number of params.
+ */
+ Command(const std::string &sname, size_t min_params, size_t max_params = 0) : MaxParams(max_params), MinParams(min_params), name(sname)
+ {
+ this->has_priv = NULL;
+ this->help_param1 = NULL;
+ this->help_param2 = NULL;
+ this->help_param3 = NULL;
+ this->help_param4 = NULL;
+ this->core = 0;
+ this->next = NULL;
+ this->mod_name = NULL;
+ this->service = NULL;
+ this->all_help = NULL;
+ this->regular_help = NULL;
+ this->oper_help = NULL;
+ this->admin_help = NULL;
+ this->root_help = NULL;
+ }
+
+ ~Command()
+ {
+ this->has_priv = NULL;
+ if (this->mod_name) {
+ delete [] this->mod_name;
+ }
+ if (this->service) {
+ delete [] this->service;
+ }
+ this->next = NULL;
+ }
+
+ /** Execute this command.
+ * @param u The user executing the command.
+ */
+ virtual CommandReturn Execute(User *u, std::vector<std::string> &) { return MOD_CONT; }
+
+ /** Requested when the user is requesting help on this command. Help on this command should be sent to the user.
+ * @param u The user requesting help
+ * @param subcommand The subcommand the user is requesting help on, or an empty string. (e.g. /ns help set foo bar lol gives a subcommand of "FOO BAR LOL")
+ * @return true if help was provided to the user, false otherwise.
+ */
+ virtual bool OnHelp(User *u, const std::string &subcommand) { return false; }
+
+ /** Requested when the user provides bad syntax to this command (not enough params, etc).
+ * @param u The user executing the command.
+ */
+ virtual void OnBadSyntax(User *u) { }
+
+ int (*has_priv)(User *u); /* Returns 1 if user may use command, else 0 */
+
+ char *help_param1;
+ char *help_param2;
+ char *help_param3;
+ char *help_param4;
+
+ /* Module related stuff */
+ int core; /* Can this command be deleted? */
+ char *mod_name; /* Name of the module who owns us, NULL for core's */
+ char *service; /* Service we provide this command for */
+ int (*all_help)(User *u);
+ int (*regular_help)(User *u);
+ int (*oper_help)(User *u);
+ int (*admin_help)(User *u);
+ int (*root_help)(User *u);
+
+ Command *next; /* Next command responsible for the same command */
+};
/** Every module in Anope is actually a class.
*/
class CoreExport Module
@@ -398,38 +476,6 @@ struct ModuleHash_ {
ModuleHash *next;
};
-struct Command_ {
- char *name;
- int (*routine)(User *u);
- int (*has_priv)(User *u); /* Returns 1 if user may use command, else 0 */
-
- /* Regrettably, these are hard-coded to correspond to current privilege
- * levels (v4.0). Suggestions for better ways to do this are
- * appreciated.
- */
- int helpmsg_all; /* Displayed to all users; -1 = no message */
- int helpmsg_reg; /* Displayed to regular users only */
- int helpmsg_oper; /* Displayed to Services operators only */
- int helpmsg_admin; /* Displayed to Services admins only */
- int helpmsg_root; /* Displayed to Services root only */
- char *help_param1;
- char *help_param2;
- char *help_param3;
- char *help_param4;
-
- /* Module related stuff */
- int core; /* Can this command be deleted? */
- char *mod_name; /* Name of the module who owns us, NULL for core's */
- char *service; /* Service we provide this command for */
- int (*all_help)(User *u);
- int (*regular_help)(User *u);
- int (*oper_help)(User *u);
- int (*admin_help)(User *u);
- int (*root_help)(User *u);
-
- Command *next; /* Next command responsible for the same command */
-};
-
struct CommandHash {
char *name; /* Name of the command */
Command *c; /* Actual command */
@@ -494,8 +540,6 @@ extern MDE char *mod_current_buffer;
/*************************************************************************/
/*************************************************************************/
/* Command Managment Functions */
-MDE Command *createCommand(const char *name,int (*func)(User *u),int (*has_priv)(User *u),int help_all, int help_reg, int help_oper, int help_admin,int help_root);
-MDE int destroyCommand(Command *c); /* destroy a command */
Command *findCommand(CommandHash *cmdTable[], const char *name); /* Find a command */
/*************************************************************************/