summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-08 01:00:16 +0000
committerRobin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-08 01:00:16 +0000
commitd5162d6e45aa484b918f4e2f97f5fcfb49b537e0 (patch)
tree6707b1f62d38a2e1912d024c8bdec66f65463329 /src
parent7ac7c564f5115af12f771db5b510b757b1dcc322 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/main.c2
-rw-r--r--src/modules.c229
-rw-r--r--src/operserv.c29
-rw-r--r--src/timeout.c25
4 files changed, 107 insertions, 178 deletions
diff --git a/src/main.c b/src/main.c
index ab658e090..e29249311 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
diff --git a/src/modules.c b/src/modules.c
index 2988b9f52..7d0bc3f17 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -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;
@@ -1290,6 +1236,43 @@ int delCommand(CommandHash * cmdTable[], Command * c, const char *mod_name)
}
/**
+ * 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
* @param name the name of the command to look for
diff --git a/src/operserv.c b/src/operserv.c
index c39790418..470a96008 100644
--- a/src/operserv.c
+++ b/src/operserv.c
@@ -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
**/
diff --git a/src/timeout.c b/src/timeout.c
index 544d05435..94280c1d9 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -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)