1
0
mirror of https://github.com/anope/anope.git synced 2026-06-28 05:36:38 +02:00

Fix various scary stuff to do with API.

git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1584 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
Robin Burchell w00t@inspircd.org
2008-11-08 01:00:16 +00:00
parent 7ac7c564f5
commit d5162d6e45
8 changed files with 107 additions and 196 deletions
-4
View File
@@ -36,10 +36,6 @@
/* Define this to enable OperServ's svs commands (superadmin only). */
#define USE_OSSVS
/* Define this to enable OperServ's debugging commands (Services root
* only). These commands are undocumented; "use the source, Luke!" */
/* #define DEBUG_COMMANDS */
/******************* END OF USER-CONFIGURABLE SECTION ********************/
/* Size of input buffer (note: this is different from BUFSIZ)
-3
View File
@@ -319,10 +319,7 @@ MDE int moduleGetConfigDirective(Directive *h);
/* 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 */
MDE int addCoreCommand(CommandHash *cmdTable[], Command *c); /* Add a command to a command table */
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos);
MDE int addCommand(CommandHash *cmdTable[], Command *c,int pos);
MDE int delCommand(CommandHash *cmdTable[], Command *c, const char *mod_name); /* Del a command from a cmd table */
MDE int moduleDelCommand(CommandHash *cmdTable[], const char *name); /* Del a command from a cmd table */
Command *findCommand(CommandHash *cmdTable[], const char *name); /* Find a command */
-5
View File
@@ -41,10 +41,5 @@ extern Timeout *add_timeout(int delay, void (*code)(Timeout *), int repeat);
/* Remove a timeout from the list (if it's there). */
extern void del_timeout(Timeout *t);
#ifdef DEBUG_COMMANDS
/* Send the list of timeouts to the given user. */
extern int send_timeout_list(User *u);
#endif
#endif /* TIMEOUT_H */
-6
View File
@@ -52,12 +52,6 @@ cat >version.h <<EOF
#define VERSION_STRING "$VERSION"
#define VERSION_STRING_DOTTED "$VERSIONDOTTED"
#ifdef DEBUG_COMMANDS
# define VER_DEBUG "D"
#else
# define VER_DEBUG
#endif
#if defined(_WIN32)
# if _MSC_VER >= 1400
# define VER_OS "W"
+1 -1
View File
@@ -79,7 +79,7 @@ const char version_number_dotted[] = VERSION_STRING_DOTTED;
const char version_build[] =
"build #" BUILD ", compiled " __DATE__ " " __TIME__;
/* the space is needed cause if you build with nothing it will complain */
const char version_flags[] = " " VER_DEBUG VER_OS VER_MYSQL VER_MODULE;
const char version_flags[] = " " VER_OS VER_MYSQL VER_MODULE;
extern char *mod_current_buffer;
+106 -123
View File
@@ -1006,20 +1006,77 @@ int destroyCommand(Command * c)
return MOD_ERR_OK;
}
/**
* Add a CORE command ot the given command hash
* @param cmdTable the command table to add the command to
/** Add a command to a command table. Only for internal use.
* only add if were unique, pos = 0;
* if we want it at the "head" of that command, pos = 1
* at the tail, pos = 2
* @param cmdTable the table to add the command to
* @param c the command to add
* @return MOD_ERR_OK on success
* @param pos the position in the cmd call stack to add the command
* @return MOD_ERR_OK will be returned on success.
*/
int addCoreCommand(CommandHash * cmdTable[], Command * c)
static int internal_addCommand(CommandHash * cmdTable[], Command * c, int pos)
{
if (!cmdTable || !c) {
/* We can assume both param's have been checked by this point.. */
int index = 0;
CommandHash *current = NULL;
CommandHash *newHash = NULL;
CommandHash *lastHash = NULL;
Command *tail = NULL;
if (!cmdTable || !c || (pos < 0 || pos > 2)) {
return MOD_ERR_PARAMS;
}
c->core = 1;
c->next = NULL;
return addCommand(cmdTable, c, 0);
if (mod_current_module_name && !c->mod_name)
return MOD_ERR_NO_MOD_NAME;
index = CMD_HASH(c->name);
for (current = cmdTable[index]; current; current = current->next) {
if ((c->service) && (current->c) && (current->c->service)
&& (!strcmp(c->service, current->c->service) == 0)) {
continue;
}
if ((stricmp(c->name, current->name) == 0)) { /* the cmd exist's we are a addHead */
if (pos == 1) {
c->next = current->c;
current->c = c;
if (debug)
alog("debug: existing cmd: (0x%p), new cmd (0x%p)",
(void *) c->next, (void *) c);
return MOD_ERR_OK;
} else if (pos == 2) {
tail = current->c;
while (tail->next)
tail = tail->next;
if (debug)
alog("debug: existing cmd: (0x%p), new cmd (0x%p)",
(void *) tail, (void *) c);
tail->next = c;
c->next = NULL;
return MOD_ERR_OK;
} else
return MOD_ERR_EXISTS;
}
lastHash = current;
}
if ((newHash = (CommandHash *)malloc(sizeof(CommandHash))) == NULL) {
fatal("Out of memory");
}
newHash->next = NULL;
newHash->name = sstrdup(c->name);
newHash->c = c;
if (lastHash == NULL)
cmdTable[index] = newHash;
else
lastHash->next = newHash;
return MOD_ERR_OK;
}
/**
@@ -1099,7 +1156,7 @@ int moduleAddCommand(CommandHash * cmdTable[], Command * c, int pos)
if (debug >= 2)
displayCommandFromHash(cmdTable, c->name);
status = addCommand(cmdTable, c, pos);
status = internal_addCommand(cmdTable, c, pos);
if (debug >= 2)
displayCommandFromHash(cmdTable, c->name);
if (status != MOD_ERR_OK) {
@@ -1108,125 +1165,14 @@ int moduleAddCommand(CommandHash * cmdTable[], Command * c, int pos)
return status;
}
/**
* Delete a command from the service given.
* @param cmdTable the cmdTable for the services to remove the command from
* @param name the name of the command to delete from the service
* @return returns MOD_ERR_OK on success
*/
int moduleDelCommand(CommandHash * cmdTable[], const char *name)
{
Command *c = NULL;
Command *cmd = NULL;
int status = 0;
if (!mod_current_module) {
return MOD_ERR_UNKNOWN;
}
c = findCommand(cmdTable, name);
if (!c) {
return MOD_ERR_NOEXIST;
}
for (cmd = c; cmd; cmd = cmd->next) {
if (cmd->mod_name
&& cmd->mod_name == mod_current_module->name) {
if (debug >= 2) {
displayCommandFromHash(cmdTable, name);
}
status = delCommand(cmdTable, cmd, mod_current_module->name.c_str());
if (debug >= 2) {
displayCommandFromHash(cmdTable, name);
}
}
}
return status;
}
/**
* Add a command to a command table.
* only add if were unique, pos = 0;
* if we want it at the "head" of that command, pos = 1
* at the tail, pos = 2
* @param cmdTable the table to add the command to
* @param c the command to add
* @param pos the position in the cmd call stack to add the command
* @return MOD_ERR_OK will be returned on success.
*/
int addCommand(CommandHash * cmdTable[], Command * c, int pos)
{
/* We can assume both param's have been checked by this point.. */
int index = 0;
CommandHash *current = NULL;
CommandHash *newHash = NULL;
CommandHash *lastHash = NULL;
Command *tail = NULL;
if (!cmdTable || !c || (pos < 0 || pos > 2)) {
return MOD_ERR_PARAMS;
}
if (mod_current_module_name && !c->mod_name)
return MOD_ERR_NO_MOD_NAME;
index = CMD_HASH(c->name);
for (current = cmdTable[index]; current; current = current->next) {
if ((c->service) && (current->c) && (current->c->service)
&& (!strcmp(c->service, current->c->service) == 0)) {
continue;
}
if ((stricmp(c->name, current->name) == 0)) { /* the cmd exist's we are a addHead */
if (pos == 1) {
c->next = current->c;
current->c = c;
if (debug)
alog("debug: existing cmd: (0x%p), new cmd (0x%p)",
(void *) c->next, (void *) c);
return MOD_ERR_OK;
} else if (pos == 2) {
tail = current->c;
while (tail->next)
tail = tail->next;
if (debug)
alog("debug: existing cmd: (0x%p), new cmd (0x%p)",
(void *) tail, (void *) c);
tail->next = c;
c->next = NULL;
return MOD_ERR_OK;
} else
return MOD_ERR_EXISTS;
}
lastHash = current;
}
if ((newHash = (CommandHash *)malloc(sizeof(CommandHash))) == NULL) {
fatal("Out of memory");
}
newHash->next = NULL;
newHash->name = sstrdup(c->name);
newHash->c = c;
if (lastHash == NULL)
cmdTable[index] = newHash;
else
lastHash->next = newHash;
return MOD_ERR_OK;
}
/**
* Remove a command from the command hash.
/** Remove a command from the command hash. Only for internal use.
* @param cmdTable the command table to remove the command from
* @param c the command to remove
* @param mod_name the name of the module who owns the command
* @return MOD_ERR_OK will be returned on success
*/
int delCommand(CommandHash * cmdTable[], Command * c, const char *mod_name)
static int internal_delCommand(CommandHash * cmdTable[], Command * c, const char *mod_name)
{
int index = 0;
CommandHash *current = NULL;
@@ -1289,6 +1235,43 @@ int delCommand(CommandHash * cmdTable[], Command * c, const char *mod_name)
return MOD_ERR_NOEXIST;
}
/**
* Delete a command from the service given.
* @param cmdTable the cmdTable for the services to remove the command from
* @param name the name of the command to delete from the service
* @return returns MOD_ERR_OK on success
*/
int moduleDelCommand(CommandHash * cmdTable[], const char *name)
{
Command *c = NULL;
Command *cmd = NULL;
int status = 0;
if (!mod_current_module) {
return MOD_ERR_UNKNOWN;
}
c = findCommand(cmdTable, name);
if (!c) {
return MOD_ERR_NOEXIST;
}
for (cmd = c; cmd; cmd = cmd->next) {
if (cmd->mod_name
&& cmd->mod_name == mod_current_module->name) {
if (debug >= 2) {
displayCommandFromHash(cmdTable, name);
}
status = internal_delCommand(cmdTable, cmd, mod_current_module->name.c_str());
if (debug >= 2) {
displayCommandFromHash(cmdTable, name);
}
}
}
return status;
}
/**
* Search the command table gieven for a command.
* @param cmdTable the name of the command table to search
-29
View File
@@ -55,10 +55,6 @@ ChannelInfo DefConModesCI; /* ChannelInfo containg params for locked modes
*/
#ifdef DEBUG_COMMANDS
static int do_matchwild(User * u);
#endif
void moduleAddOperServCmds(void);
/*************************************************************************/
@@ -78,16 +74,7 @@ SListOpts szopts = { 0, NULL, &is_szline_entry_equal, &free_szline_entry };
/*************************************************************************/
/* *INDENT-OFF* */
void moduleAddOperServCmds(void) {
#ifdef DEBUG_COMMANDS
Command *c;
#endif
modules_core_init(OperServCoreNumber, OperServCoreModules);
#ifdef DEBUG_COMMANDS
c = createCommand("LISTTIMERS", send_timeout_list, is_services_root, -1,-1,-1,-1,-1); addCoreCommand(OPERSERV,c);
c = createCommand("MATCHWILD", do_matchwild, is_services_root, -1,-1,-1,-1,-1); addCoreCommand(OPERSERV,c);
#endif
}
/* *INDENT-ON* */
@@ -1496,22 +1483,6 @@ static void free_operlist_entry(SList * slist, void *item)
/*************************************************************************/
#ifdef DEBUG_COMMANDS
static int do_matchwild(User * u)
{
char *pat = strtok(NULL, " ");
char *str = strtok(NULL, " ");
if (pat && str)
notice_user(s_OperServ, u, "%d", match_wild(pat, str));
else
notice_user(s_OperServ, u, "Syntax error.");
return MOD_CONT;
}
#endif /* DEBUG_COMMANDS */
/*************************************************************************/
/**
* Returns 1 if the passed level is part of the CURRENT defcon, else 0 is returned
**/
-25
View File
@@ -19,31 +19,6 @@ static Timeout *timeouts = NULL;
/*************************************************************************/
#ifdef DEBUG_COMMANDS
/* Send the timeout list to the given user. */
int send_timeout_list(User * u)
{
Timeout *to, *last;
ircdproto->SendMessage(s_OperServ, u->nick, "Now: %ld", (long int) time(NULL));
for (to = timeouts, last = NULL; to; last = to, to = to->next) {
ircdproto->SendMessage(s_OperServ, u->nick, "0x%p: %ld: 0x%p (0x%p)",
(void *) to, (long int) to->timeout, (void *) to->code,
(void *) to->data);
if (to->prev != last)
ircdproto->SendMessage(s_OperServ, u->nick,
" to->prev incorrect! expected=0x%p seen=0x%p",
(void *) last, (void *) to->prev);
}
return MOD_CONT;
}
#endif /* DEBUG_COMMANDS */
/*************************************************************************/
/* Check the timeout list for any pending actions. */
void check_timeouts(void)