diff options
Diffstat (limited to 'src/modules.c')
-rw-r--r-- | src/modules.c | 2414 |
1 files changed, 1207 insertions, 1207 deletions
diff --git a/src/modules.c b/src/modules.c index 36ffc2ed5..aa8f09b29 100644 --- a/src/modules.c +++ b/src/modules.c @@ -56,23 +56,23 @@ ModuleCallBack *moduleCallBackHead = NULL; char *ModuleGetErrStr(int status) { - const char *module_err_str[] = { - "Module, Okay - No Error", /* MOD_ERR_OK */ - "Module Error, Allocating memory", /* MOD_ERR_MEMORY */ - "Module Error, Not enough parameters", /* MOD_ERR_PARAMS */ - "Module Error, Already loaded", /* MOD_ERR_EXISTS */ - "Module Error, File does not exist", /* MOD_ERR_NOEXIST */ - "Module Error, No User", /* MOD_ERR_NOUSER */ - "Module Error, Error during load time or module returned MOD_STOP", /* MOD_ERR_NOLOAD */ - "Module Error, Unable to unload", /* MOD_ERR_NOUNLOAD */ - "Module Error, Incorrect syntax", /* MOD_ERR_SYNTAX */ - "Module Error, Unable to delete", /* MOD_ERR_NODELETE */ - "Module Error, Unknown Error occuried", /* MOD_ERR_UNKOWN */ - "Module Error, File I/O Error", /* MOD_ERR_FILE_IO */ - "Module Error, No Service found for request", /* MOD_ERR_NOSERVICE */ - "Module Error, No module name for request" /* MOD_ERR_NO_MOD_NAME */ - }; - return (char *) module_err_str[status]; + const char *module_err_str[] = { + "Module, Okay - No Error", /* MOD_ERR_OK */ + "Module Error, Allocating memory", /* MOD_ERR_MEMORY */ + "Module Error, Not enough parameters", /* MOD_ERR_PARAMS */ + "Module Error, Already loaded", /* MOD_ERR_EXISTS */ + "Module Error, File does not exist", /* MOD_ERR_NOEXIST */ + "Module Error, No User", /* MOD_ERR_NOUSER */ + "Module Error, Error during load time or module returned MOD_STOP", /* MOD_ERR_NOLOAD */ + "Module Error, Unable to unload", /* MOD_ERR_NOUNLOAD */ + "Module Error, Incorrect syntax", /* MOD_ERR_SYNTAX */ + "Module Error, Unable to delete", /* MOD_ERR_NODELETE */ + "Module Error, Unknown Error occuried", /* MOD_ERR_UNKOWN */ + "Module Error, File I/O Error", /* MOD_ERR_FILE_IO */ + "Module Error, No Service found for request", /* MOD_ERR_NOSERVICE */ + "Module Error, No module name for request" /* MOD_ERR_NO_MOD_NAME */ + }; + return (char *) module_err_str[status]; } @@ -89,14 +89,14 @@ char *ModuleGetErrStr(int status) */ static int displayCommand(Command * c) { - Command *cmd = NULL; - int i = 0; - alog("Displaying command list for %s", c->name); - for (cmd = c; cmd; cmd = cmd->next) { - alog("%d: 0x%p", ++i, (void *) cmd); - } - alog("end"); - return 0; + Command *cmd = NULL; + int i = 0; + alog("Displaying command list for %s", c->name); + for (cmd = c; cmd; cmd = cmd->next) { + alog("%d: 0x%p", ++i, (void *) cmd); + } + alog("end"); + return 0; } /** @@ -108,21 +108,21 @@ static int displayCommand(Command * c) */ static int displayCommandFromHash(CommandHash * cmdTable[], const char *name) { - CommandHash *current = NULL; - int index = 0; - index = CMD_HASH(name); - if (debug > 1) { - alog("debug: trying to display command %s", name); - } - for (current = cmdTable[index]; current; current = current->next) { - if (stricmp(name, current->name) == 0) { - displayCommand(current->c); - } - } - if (debug > 1) { - alog("debug: done displaying command %s", name); - } - return 0; + CommandHash *current = NULL; + int index = 0; + index = CMD_HASH(name); + if (debug > 1) { + alog("debug: trying to display command %s", name); + } + for (current = cmdTable[index]; current; current = current->next) { + if (stricmp(name, current->name) == 0) { + displayCommand(current->c); + } + } + if (debug > 1) { + alog("debug: done displaying command %s", name); + } + return 0; } /** @@ -133,14 +133,14 @@ static int displayCommandFromHash(CommandHash * cmdTable[], const char *name) */ static int displayMessage(Message * m) { - Message *msg = NULL; - int i = 0; - alog("Displaying message list for %s", m->name); - for (msg = m; msg; msg = msg->next) { - alog("%d: 0x%p", ++i, (void *) msg); - } - alog("end"); - return 0; + Message *msg = NULL; + int i = 0; + alog("Displaying message list for %s", m->name); + for (msg = m; msg; msg = msg->next) { + alog("%d: 0x%p", ++i, (void *) msg); + } + alog("end"); + return 0; } /** @@ -151,21 +151,21 @@ static int displayMessage(Message * m) */ static int displayMessageFromHash(const char *name) { - MessageHash *current = NULL; - int index = 0; - index = CMD_HASH(name); - if (debug > 1) { - alog("debug: trying to display message %s", name); - } - for (current = IRCD[index]; current; current = current->next) { - if (stricmp(name, current->name) == 0) { - displayMessage(current->m); - } - } - if (debug > 1) { - alog("debug: done displaying message %s", name); - } - return 0; + MessageHash *current = NULL; + int index = 0; + index = CMD_HASH(name); + if (debug > 1) { + alog("debug: trying to display message %s", name); + } + for (current = IRCD[index]; current; current = current->next) { + if (stricmp(name, current->name) == 0) { + displayMessage(current->m); + } + } + if (debug > 1) { + alog("debug: done displaying message %s", name); + } + return 0; } /************************************************/ @@ -174,14 +174,14 @@ static int displayMessageFromHash(const char *name) * **/ int encryption_module_init(void) { - int ret = 0; + int ret = 0; - alog("Loading Encryption Module: [%s]", EncModule); - ret = ModuleManager::LoadModule(EncModule, NULL); + alog("Loading Encryption Module: [%s]", EncModule); + ret = ModuleManager::LoadModule(EncModule, NULL); if (ret == MOD_ERR_OK) findModule(EncModule)->SetType(ENCRYPTION); - mod_current_module = NULL; - return ret; + mod_current_module = NULL; + return ret; } /** @@ -189,10 +189,10 @@ int encryption_module_init(void) { **/ int protocol_module_init(void) { - int ret = 0; + int ret = 0; - alog("Loading IRCD Protocol Module: [%s]", IRCDModule); - ret = ModuleManager::LoadModule(IRCDModule, NULL); + alog("Loading IRCD Protocol Module: [%s]", IRCDModule); + ret = ModuleManager::LoadModule(IRCDModule, NULL); if (ret == MOD_ERR_OK) { @@ -207,14 +207,14 @@ int protocol_module_init(void) } /* We can assume the ircd supports TS6 here */ - if (UseTS6 && !Numeric) { - alog("UseTS6 requires the setting of Numeric to be enabled."); - ret = -1; - } + if (UseTS6 && !Numeric) { + alog("UseTS6 requires the setting of Numeric to be enabled."); + ret = -1; + } } mod_current_module = NULL; - return ret; + return ret; } /** @@ -247,33 +247,33 @@ void modules_unload_all(bool fini, bool unload_proto) next = mh->next; if (unload_proto || (mh->m->type != PROTOCOL)) { mod_current_module = mh->m; - mod_current_module_name = mh->m->name.c_str(); - mod_current_module_name = NULL; + mod_current_module_name = mh->m->name.c_str(); + mod_current_module_name = NULL; - delete mh->m; - } - mh = next; + delete mh->m; + } + mh = next; } } } void Module::InsertLanguage(int langNumber, int ac, const char **av) { - int i; + int i; if (debug) alog("debug: %s Adding %d texts for language %d", this->name.c_str(), ac, langNumber); - if (this->lang[langNumber].argc > 0) { - moduleDeleteLanguage(langNumber); - } + if (this->lang[langNumber].argc > 0) { + moduleDeleteLanguage(langNumber); + } - this->lang[langNumber].argc = ac; - this->lang[langNumber].argv = - (char **)malloc(sizeof(char *) * ac); - for (i = 0; i < ac; i++) { - this->lang[langNumber].argv[i] = sstrdup(av[i]); - } + this->lang[langNumber].argc = ac; + this->lang[langNumber].argv = + (char **)malloc(sizeof(char *) * ac); + for (i = 0; i < ac; i++) { + this->lang[langNumber].argv[i] = sstrdup(av[i]); + } } /** @@ -283,19 +283,19 @@ void Module::InsertLanguage(int langNumber, int ac, const char **av) */ Module *findModule(const char *name) { - int idx; - ModuleHash *current = NULL; - if (!name) { - return NULL; - } - idx = CMD_HASH(name); - - for (current = MODULE_HASH[idx]; current; current = current->next) { - if (stricmp(name, current->name) == 0) { - return current->m; - } - } - return NULL; + int idx; + ModuleHash *current = NULL; + if (!name) { + return NULL; + } + idx = CMD_HASH(name); + + for (current = MODULE_HASH[idx]; current; current = current->next) { + if (stricmp(name, current->name) == 0) { + return current->m; + } + } + return NULL; } @@ -315,39 +315,39 @@ Module *findModule(const char *name) * @return a "ready to use" Command struct will be returned */ 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) + int (*has_priv) (User * u), int help_all, + int help_reg, int help_oper, int help_admin, + int help_root) { - Command *c; - if (!name || !*name) { - return NULL; - } - - if ((c = (Command *)malloc(sizeof(Command))) == NULL) { - fatal("Out of memory!"); - } - c->name = sstrdup(name); - c->routine = func; - c->has_priv = has_priv; - c->helpmsg_all = help_all; - c->helpmsg_reg = help_reg; - c->helpmsg_oper = help_oper; - c->helpmsg_admin = help_admin; - c->helpmsg_root = help_root; - c->help_param1 = NULL; - c->help_param2 = NULL; - c->help_param3 = NULL; - c->help_param4 = NULL; - c->next = NULL; - c->mod_name = NULL; - c->service = NULL; - c->all_help = NULL; - c->regular_help = NULL; - c->oper_help = NULL; - c->admin_help = NULL; - c->root_help = NULL; - return c; + Command *c; + if (!name || !*name) { + return NULL; + } + + if ((c = (Command *)malloc(sizeof(Command))) == NULL) { + fatal("Out of memory!"); + } + c->name = sstrdup(name); + c->routine = func; + c->has_priv = has_priv; + c->helpmsg_all = help_all; + c->helpmsg_reg = help_reg; + c->helpmsg_oper = help_oper; + c->helpmsg_admin = help_admin; + c->helpmsg_root = help_root; + c->help_param1 = NULL; + c->help_param2 = NULL; + c->help_param3 = NULL; + c->help_param4 = NULL; + c->next = NULL; + c->mod_name = NULL; + c->service = NULL; + c->all_help = NULL; + c->regular_help = NULL; + c->oper_help = NULL; + c->admin_help = NULL; + c->root_help = NULL; + return c; } /** @@ -357,43 +357,43 @@ Command *createCommand(const char *name, int (*func) (User * u), */ int destroyCommand(Command * c) { - if (!c) { - return MOD_ERR_PARAMS; - } - if (c->core == 1) { - return MOD_ERR_UNKNOWN; - } - if (c->name) { - free(c->name); - } - c->routine = NULL; - c->has_priv = NULL; - c->helpmsg_all = -1; - c->helpmsg_reg = -1; - c->helpmsg_oper = -1; - c->helpmsg_admin = -1; - c->helpmsg_root = -1; - if (c->help_param1) { - free(c->help_param1); - } - if (c->help_param2) { - free(c->help_param2); - } - if (c->help_param3) { - free(c->help_param3); - } - if (c->help_param4) { - free(c->help_param4); - } - if (c->mod_name) { - free(c->mod_name); - } - if (c->service) { - free(c->service); - } - c->next = NULL; - free(c); - return MOD_ERR_OK; + if (!c) { + return MOD_ERR_PARAMS; + } + if (c->core == 1) { + return MOD_ERR_UNKNOWN; + } + if (c->name) { + free(c->name); + } + c->routine = NULL; + c->has_priv = NULL; + c->helpmsg_all = -1; + c->helpmsg_reg = -1; + c->helpmsg_oper = -1; + c->helpmsg_admin = -1; + c->helpmsg_root = -1; + if (c->help_param1) { + free(c->help_param1); + } + if (c->help_param2) { + free(c->help_param2); + } + if (c->help_param3) { + free(c->help_param3); + } + if (c->help_param4) { + free(c->help_param4); + } + if (c->mod_name) { + free(c->mod_name); + } + if (c->service) { + free(c->service); + } + c->next = NULL; + free(c); + return MOD_ERR_OK; } /** Add a command to a command table. Only for internal use. @@ -407,135 +407,135 @@ int destroyCommand(Command * c) */ static int internal_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; + /* 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; } int Module::AddCommand(CommandHash * cmdTable[], Command * c, int pos) { - int status; - - if (!cmdTable || !c) { - return MOD_ERR_PARAMS; - } - c->core = 0; - if (!c->mod_name) { - c->mod_name = sstrdup(this->name.c_str()); - } - - - if (cmdTable == HOSTSERV) { - if (s_HostServ) { - c->service = sstrdup(s_HostServ); - } else { - return MOD_ERR_NOSERVICE; - } - } else if (cmdTable == BOTSERV) { - if (s_BotServ) { - c->service = sstrdup(s_BotServ); - } else { - return MOD_ERR_NOSERVICE; - } - } else if (cmdTable == MEMOSERV) { - if (s_MemoServ) { - c->service = sstrdup(s_MemoServ); - } else { - return MOD_ERR_NOSERVICE; - } - } else if (cmdTable == CHANSERV) { - if (s_ChanServ) { - c->service = sstrdup(s_ChanServ); - } else { - return MOD_ERR_NOSERVICE; - } - } else if (cmdTable == NICKSERV) { - if (s_NickServ) { - c->service = sstrdup(s_NickServ); - } else { - return MOD_ERR_NOSERVICE; - } - } else if (cmdTable == HELPSERV) { - if (s_HelpServ) { - c->service = sstrdup(s_HelpServ); - } else { - return MOD_ERR_NOSERVICE; - } - } else if (cmdTable == OPERSERV) { - if (s_OperServ) { - c->service = sstrdup(s_OperServ); - } else { - return MOD_ERR_NOSERVICE; - } - } else - c->service = sstrdup("Unknown"); - - if (debug >= 2) - displayCommandFromHash(cmdTable, c->name); - status = internal_addCommand(cmdTable, c, pos); - if (debug >= 2) - displayCommandFromHash(cmdTable, c->name); - if (status != MOD_ERR_OK) { - alog("ERROR! [%d]", status); - } - return status; + int status; + + if (!cmdTable || !c) { + return MOD_ERR_PARAMS; + } + c->core = 0; + if (!c->mod_name) { + c->mod_name = sstrdup(this->name.c_str()); + } + + + if (cmdTable == HOSTSERV) { + if (s_HostServ) { + c->service = sstrdup(s_HostServ); + } else { + return MOD_ERR_NOSERVICE; + } + } else if (cmdTable == BOTSERV) { + if (s_BotServ) { + c->service = sstrdup(s_BotServ); + } else { + return MOD_ERR_NOSERVICE; + } + } else if (cmdTable == MEMOSERV) { + if (s_MemoServ) { + c->service = sstrdup(s_MemoServ); + } else { + return MOD_ERR_NOSERVICE; + } + } else if (cmdTable == CHANSERV) { + if (s_ChanServ) { + c->service = sstrdup(s_ChanServ); + } else { + return MOD_ERR_NOSERVICE; + } + } else if (cmdTable == NICKSERV) { + if (s_NickServ) { + c->service = sstrdup(s_NickServ); + } else { + return MOD_ERR_NOSERVICE; + } + } else if (cmdTable == HELPSERV) { + if (s_HelpServ) { + c->service = sstrdup(s_HelpServ); + } else { + return MOD_ERR_NOSERVICE; + } + } else if (cmdTable == OPERSERV) { + if (s_OperServ) { + c->service = sstrdup(s_OperServ); + } else { + return MOD_ERR_NOSERVICE; + } + } else + c->service = sstrdup("Unknown"); + + if (debug >= 2) + displayCommandFromHash(cmdTable, c->name); + status = internal_addCommand(cmdTable, c, pos); + if (debug >= 2) + displayCommandFromHash(cmdTable, c->name); + if (status != MOD_ERR_OK) { + alog("ERROR! [%d]", status); + } + return status; } @@ -547,65 +547,65 @@ int Module::AddCommand(CommandHash * cmdTable[], Command * c, int pos) */ static int internal_delCommand(CommandHash * cmdTable[], Command * c, const char *mod_name) { - int index = 0; - CommandHash *current = NULL; - CommandHash *lastHash = NULL; - Command *tail = NULL, *last = NULL; - - if (!c || !cmdTable) { - return MOD_ERR_PARAMS; - } - - index = CMD_HASH(c->name); - for (current = cmdTable[index]; current; current = current->next) { - if (stricmp(c->name, current->name) == 0) { - if (!lastHash) { - tail = current->c; - if (tail->next) { - while (tail) { - if (mod_name && tail->mod_name - && (stricmp(mod_name, tail->mod_name) == 0)) { - if (last) { - last->next = tail->next; - } else { - current->c = tail->next; - } - return MOD_ERR_OK; - } - last = tail; - tail = tail->next; - } - } else { - cmdTable[index] = current->next; - free(current->name); - return MOD_ERR_OK; - } - } else { - tail = current->c; - if (tail->next) { - while (tail) { - if (mod_name && tail->mod_name - && (stricmp(mod_name, tail->mod_name) == 0)) { - if (last) { - last->next = tail->next; - } else { - current->c = tail->next; - } - return MOD_ERR_OK; - } - last = tail; - tail = tail->next; - } - } else { - lastHash->next = current->next; - free(current->name); - return MOD_ERR_OK; - } - } - } - lastHash = current; - } - return MOD_ERR_NOEXIST; + int index = 0; + CommandHash *current = NULL; + CommandHash *lastHash = NULL; + Command *tail = NULL, *last = NULL; + + if (!c || !cmdTable) { + return MOD_ERR_PARAMS; + } + + index = CMD_HASH(c->name); + for (current = cmdTable[index]; current; current = current->next) { + if (stricmp(c->name, current->name) == 0) { + if (!lastHash) { + tail = current->c; + if (tail->next) { + while (tail) { + if (mod_name && tail->mod_name + && (stricmp(mod_name, tail->mod_name) == 0)) { + if (last) { + last->next = tail->next; + } else { + current->c = tail->next; + } + return MOD_ERR_OK; + } + last = tail; + tail = tail->next; + } + } else { + cmdTable[index] = current->next; + free(current->name); + return MOD_ERR_OK; + } + } else { + tail = current->c; + if (tail->next) { + while (tail) { + if (mod_name && tail->mod_name + && (stricmp(mod_name, tail->mod_name) == 0)) { + if (last) { + last->next = tail->next; + } else { + current->c = tail->next; + } + return MOD_ERR_OK; + } + last = tail; + tail = tail->next; + } + } else { + lastHash->next = current->next; + free(current->name); + return MOD_ERR_OK; + } + } + } + lastHash = current; + } + return MOD_ERR_NOEXIST; } /** @@ -616,29 +616,29 @@ static int internal_delCommand(CommandHash * cmdTable[], Command * c, const char */ int Module::DelCommand(CommandHash * cmdTable[], const char *dname) { - Command *c = NULL; - Command *cmd = NULL; - int status = 0; - - c = findCommand(cmdTable, dname); - if (!c) { - return MOD_ERR_NOEXIST; - } - - - for (cmd = c; cmd; cmd = cmd->next) { - if (cmd->mod_name - && cmd->mod_name == this->name) { - if (debug >= 2) { - displayCommandFromHash(cmdTable, dname); - } - status = internal_delCommand(cmdTable, cmd, this->name.c_str()); - if (debug >= 2) { - displayCommandFromHash(cmdTable, dname); - } - } - } - return status; + Command *c = NULL; + Command *cmd = NULL; + int status = 0; + + c = findCommand(cmdTable, dname); + if (!c) { + return MOD_ERR_NOEXIST; + } + + + for (cmd = c; cmd; cmd = cmd->next) { + if (cmd->mod_name + && cmd->mod_name == this->name) { + if (debug >= 2) { + displayCommandFromHash(cmdTable, dname); + } + status = internal_delCommand(cmdTable, cmd, this->name.c_str()); + if (debug >= 2) { + displayCommandFromHash(cmdTable, dname); + } + } + } + return status; } /** @@ -649,20 +649,20 @@ int Module::DelCommand(CommandHash * cmdTable[], const char *dname) */ Command *findCommand(CommandHash * cmdTable[], const char *name) { - int idx; - CommandHash *current = NULL; - if (!cmdTable || !name) { - return NULL; - } - - idx = CMD_HASH(name); - - for (current = cmdTable[idx]; current; current = current->next) { - if (stricmp(name, current->name) == 0) { - return current->c; - } - } - return NULL; + int idx; + CommandHash *current = NULL; + if (!cmdTable || !name) { + return NULL; + } + + idx = CMD_HASH(name); + + for (current = cmdTable[idx]; current; current = current->next) { + if (stricmp(name, current->name) == 0) { + return current->c; + } + } + return NULL; } /******************************************************************************* @@ -676,20 +676,20 @@ Command *findCommand(CommandHash * cmdTable[], const char *name) * @return a new Message object **/ Message *createMessage(const char *name, - int (*func) (const char *source, int ac, const char **av)) + int (*func) (const char *source, int ac, const char **av)) { - Message *m = NULL; - if (!name || !func) { - return NULL; - } - if ((m = (Message *)malloc(sizeof(Message))) == NULL) { - fatal("Out of memory!"); - } - m->name = sstrdup(name); - m->func = func; - m->mod_name = NULL; - m->next = NULL; - return m; + Message *m = NULL; + if (!name || !func) { + return NULL; + } + if ((m = (Message *)malloc(sizeof(Message))) == NULL) { + fatal("Out of memory!"); + } + m->name = sstrdup(name); + m->func = func; + m->mod_name = NULL; + m->next = NULL; + return m; } /** @@ -701,19 +701,19 @@ Message *createMessage(const char *name, **/ Message *findMessage(MessageHash * msgTable[], const char *name) { - int idx; - MessageHash *current = NULL; - if (!msgTable || !name) { - return NULL; - } - idx = CMD_HASH(name); - - for (current = msgTable[idx]; current; current = current->next) { + int idx; + MessageHash *current = NULL; + if (!msgTable || !name) { + return NULL; + } + idx = CMD_HASH(name); + + for (current = msgTable[idx]; current; current = current->next) { if (stricmp(name, current->name) == 0) { return current->m; } - } - return NULL; + } + return NULL; } /** @@ -726,58 +726,58 @@ Message *findMessage(MessageHash * msgTable[], const char *name) int addMessage(MessageHash * msgTable[], Message * m, int pos) { - /* We can assume both param's have been checked by this point.. */ - int index = 0; - MessageHash *current = NULL; - MessageHash *newHash = NULL; - MessageHash *lastHash = NULL; - Message *tail = NULL; - int match = 0; - - if (!msgTable || !m || (pos < 0 || pos > 2)) { - return MOD_ERR_PARAMS; - } - - index = CMD_HASH(m->name); - - for (current = msgTable[index]; current; current = current->next) { - match = stricmp(m->name, current->name); - if (match == 0) { /* the msg exist's we are a addHead */ - if (pos == 1) { - m->next = current->m; - current->m = m; - if (debug) - alog("debug: existing msg: (0x%p), new msg (0x%p)", - (void *) m->next, (void *) m); - return MOD_ERR_OK; - } else if (pos == 2) { - tail = current->m; - while (tail->next) - tail = tail->next; - if (debug) - alog("debug: existing msg: (0x%p), new msg (0x%p)", - (void *) tail, (void *) m); - tail->next = m; - m->next = NULL; - return MOD_ERR_OK; - } else - return MOD_ERR_EXISTS; - } - lastHash = current; - } - - if ((newHash = (MessageHash *)malloc(sizeof(MessageHash))) == NULL) { - fatal("Out of memory"); - } - newHash->next = NULL; - newHash->name = sstrdup(m->name); - newHash->m = m; - - if (lastHash == NULL) - msgTable[index] = newHash; - else - lastHash->next = newHash; - return MOD_ERR_OK; + /* We can assume both param's have been checked by this point.. */ + int index = 0; + MessageHash *current = NULL; + MessageHash *newHash = NULL; + MessageHash *lastHash = NULL; + Message *tail = NULL; + int match = 0; + + if (!msgTable || !m || (pos < 0 || pos > 2)) { + return MOD_ERR_PARAMS; + } + + index = CMD_HASH(m->name); + + for (current = msgTable[index]; current; current = current->next) { + match = stricmp(m->name, current->name); + if (match == 0) { /* the msg exist's we are a addHead */ + if (pos == 1) { + m->next = current->m; + current->m = m; + if (debug) + alog("debug: existing msg: (0x%p), new msg (0x%p)", + (void *) m->next, (void *) m); + return MOD_ERR_OK; + } else if (pos == 2) { + tail = current->m; + while (tail->next) + tail = tail->next; + if (debug) + alog("debug: existing msg: (0x%p), new msg (0x%p)", + (void *) tail, (void *) m); + tail->next = m; + m->next = NULL; + return MOD_ERR_OK; + } else + return MOD_ERR_EXISTS; + } + lastHash = current; + } + + if ((newHash = (MessageHash *)malloc(sizeof(MessageHash))) == NULL) { + fatal("Out of memory"); + } + newHash->next = NULL; + newHash->name = sstrdup(m->name); + newHash->m = m; + + if (lastHash == NULL) + msgTable[index] = newHash; + else + lastHash->next = newHash; + return MOD_ERR_OK; } /** @@ -788,11 +788,11 @@ int addMessage(MessageHash * msgTable[], Message * m, int pos) **/ int addCoreMessage(MessageHash * msgTable[], Message * m) { - if (!msgTable || !m) { - return MOD_ERR_PARAMS; - } - m->core = 1; - return addMessage(msgTable, m, 0); + if (!msgTable || !m) { + return MOD_ERR_PARAMS; + } + m->core = 1; + return addMessage(msgTable, m, 0); } /** @@ -803,30 +803,30 @@ int addCoreMessage(MessageHash * msgTable[], Message * m) **/ int moduleAddMessage(Message * m, int pos) { - int status; - - if (!m) { - return MOD_ERR_PARAMS; - } - - /* ok, this appears to be a module adding a message from outside of AnopeInit, try to look up its module struct for it */ - if ((mod_current_module_name) && (!mod_current_module)) { - mod_current_module = findModule(mod_current_module_name); - } - - if (!mod_current_module) { - return MOD_ERR_UNKNOWN; - } /* shouldnt happen */ - m->core = 0; - if (!m->mod_name) { - m->mod_name = sstrdup(mod_current_module->name.c_str()); - } - - status = addMessage(IRCD, m, pos); - if (debug) { - displayMessageFromHash(m->name); - } - return status; + int status; + + if (!m) { + return MOD_ERR_PARAMS; + } + + /* ok, this appears to be a module adding a message from outside of AnopeInit, try to look up its module struct for it */ + if ((mod_current_module_name) && (!mod_current_module)) { + mod_current_module = findModule(mod_current_module_name); + } + + if (!mod_current_module) { + return MOD_ERR_UNKNOWN; + } /* shouldnt happen */ + m->core = 0; + if (!m->mod_name) { + m->mod_name = sstrdup(mod_current_module->name.c_str()); + } + + status = addMessage(IRCD, m, pos); + if (debug) { + displayMessageFromHash(m->name); + } + return status; } /** @@ -836,22 +836,22 @@ int moduleAddMessage(Message * m, int pos) **/ int moduleDelMessage(const char *name) { - Message *m; - int status; - - if (!mod_current_module) { - return MOD_ERR_UNKNOWN; - } - m = findMessage(IRCD, name); - if (!m) { - return MOD_ERR_NOEXIST; - } - - status = delMessage(IRCD, m, mod_current_module->name.c_str()); - if (debug) { - displayMessageFromHash(m->name); - } - return status; + Message *m; + int status; + + if (!mod_current_module) { + return MOD_ERR_UNKNOWN; + } + m = findMessage(IRCD, name); + if (!m) { + return MOD_ERR_NOEXIST; + } + + status = delMessage(IRCD, m, mod_current_module->name.c_str()); + if (debug) { + displayMessageFromHash(m->name); + } + return status; } /** @@ -863,66 +863,66 @@ int moduleDelMessage(const char *name) **/ int delMessage(MessageHash * msgTable[], Message * m, const char *mod_name) { - int index = 0; - MessageHash *current = NULL; - MessageHash *lastHash = NULL; - Message *tail = NULL, *last = NULL; - - if (!m || !msgTable) { - return MOD_ERR_PARAMS; - } - - index = CMD_HASH(m->name); - - for (current = msgTable[index]; current; current = current->next) { - if (stricmp(m->name, current->name) == 0) { - if (!lastHash) { - tail = current->m; - if (tail->next) { - while (tail) { - if (mod_name && tail->mod_name - && (stricmp(mod_name, tail->mod_name) == 0)) { - if (last) { - last->next = tail->next; - } else { - current->m = tail->next; - } - return MOD_ERR_OK; - } - last = tail; - tail = tail->next; - } - } else { - msgTable[index] = current->next; - free(current->name); - return MOD_ERR_OK; - } - } else { - tail = current->m; - if (tail->next) { - while (tail) { - if (mod_name && tail->mod_name - && (stricmp(mod_name, tail->mod_name) == 0)) { - if (last) { - last->next = tail->next; - } else { - current->m = tail->next; - } - return MOD_ERR_OK; - } - last = tail; - tail = tail->next; - } - } else { - lastHash->next = current->next; - free(current->name); - return MOD_ERR_OK; - } - } - } - lastHash = current; - } - return MOD_ERR_NOEXIST; + int index = 0; + MessageHash *current = NULL; + MessageHash *lastHash = NULL; + Message *tail = NULL, *last = NULL; + + if (!m || !msgTable) { + return MOD_ERR_PARAMS; + } + + index = CMD_HASH(m->name); + + for (current = msgTable[index]; current; current = current->next) { + if (stricmp(m->name, current->name) == 0) { + if (!lastHash) { + tail = current->m; + if (tail->next) { + while (tail) { + if (mod_name && tail->mod_name + && (stricmp(mod_name, tail->mod_name) == 0)) { + if (last) { + last->next = tail->next; + } else { + current->m = tail->next; + } + return MOD_ERR_OK; + } + last = tail; + tail = tail->next; + } + } else { + msgTable[index] = current->next; + free(current->name); + return MOD_ERR_OK; + } + } else { + tail = current->m; + if (tail->next) { + while (tail) { + if (mod_name && tail->mod_name + && (stricmp(mod_name, tail->mod_name) == 0)) { + if (last) { + last->next = tail->next; + } else { + current->m = tail->next; + } + return MOD_ERR_OK; + } + last = tail; + tail = tail->next; + } + } else { + lastHash->next = current->next; + free(current->name); + return MOD_ERR_OK; + } + } + } + lastHash = current; + } + return MOD_ERR_NOEXIST; } /** @@ -932,18 +932,18 @@ int delMessage(MessageHash * msgTable[], Message * m, const char *mod_name) **/ int destroyMessage(Message * m) { - if (!m) { - return MOD_ERR_PARAMS; - } - if (m->name) { - free(m->name); - } - m->func = NULL; - if (m->mod_name) { - free(m->mod_name); - } - m->next = NULL; - return MOD_ERR_OK; + if (!m) { + return MOD_ERR_PARAMS; + } + if (m->name) { + free(m->name); + } + m->func = NULL; + if (m->mod_name) { + free(m->mod_name); + } + m->next = NULL; + return MOD_ERR_OK; } /******************************************************************************* @@ -961,54 +961,54 @@ int destroyMessage(Message * m) * @see moduleDelCallBack **/ int moduleAddCallback(const char *name, time_t when, - int (*func) (int argc, char *argv[]), int argc, - char **argv) + int (*func) (int argc, char *argv[]), int argc, + char **argv) { - ModuleCallBack *newcb, *tmp, *prev; - int i; - newcb = (ModuleCallBack *)malloc(sizeof(ModuleCallBack)); - if (!newcb) - return MOD_ERR_MEMORY; - - if (name) - newcb->name = sstrdup(name); - else - newcb->name = NULL; - newcb->when = when; - if (mod_current_module_name) { - newcb->owner_name = sstrdup(mod_current_module_name); - } else { - newcb->owner_name = NULL; - } - newcb->func = func; - newcb->argc = argc; - newcb->argv = (char **)malloc(sizeof(char *) * argc); - for (i = 0; i < argc; i++) { - newcb->argv[i] = sstrdup(argv[i]); - } - newcb->next = NULL; - - if (moduleCallBackHead == NULL) { - moduleCallBackHead = newcb; - } else { /* find place in list */ - tmp = moduleCallBackHead; - prev = tmp; - if (newcb->when < tmp->when) { - newcb->next = tmp; - moduleCallBackHead = newcb; - } else { - while (tmp && newcb->when >= tmp->when) { - prev = tmp; - tmp = tmp->next; - } - prev->next = newcb; - newcb->next = tmp; - } - } - if (debug) - alog("debug: added module CallBack: [%s] due to execute at %ld", - newcb->name ? newcb->name : "?", (long int) newcb->when); - return MOD_ERR_OK; + ModuleCallBack *newcb, *tmp, *prev; + int i; + newcb = (ModuleCallBack *)malloc(sizeof(ModuleCallBack)); + if (!newcb) + return MOD_ERR_MEMORY; + + if (name) + newcb->name = sstrdup(name); + else + newcb->name = NULL; + newcb->when = when; + if (mod_current_module_name) { + newcb->owner_name = sstrdup(mod_current_module_name); + } else { + newcb->owner_name = NULL; + } + newcb->func = func; + newcb->argc = argc; + newcb->argv = (char **)malloc(sizeof(char *) * argc); + for (i = 0; i < argc; i++) { + newcb->argv[i] = sstrdup(argv[i]); + } + newcb->next = NULL; + + if (moduleCallBackHead == NULL) { + moduleCallBackHead = newcb; + } else { /* find place in list */ + tmp = moduleCallBackHead; + prev = tmp; + if (newcb->when < tmp->when) { + newcb->next = tmp; + moduleCallBackHead = newcb; + } else { + while (tmp && newcb->when >= tmp->when) { + prev = tmp; + tmp = tmp->next; + } + prev->next = newcb; + newcb->next = tmp; + } + } + if (debug) + alog("debug: added module CallBack: [%s] due to execute at %ld", + newcb->name ? newcb->name : "?", (long int) newcb->when); + return MOD_ERR_OK; } /** @@ -1016,7 +1016,7 @@ int moduleAddCallback(const char *name, time_t when, **/ void moduleCallBackRun(void) { - ModuleCallBack *tmp; + ModuleCallBack *tmp; while ((tmp = moduleCallBackHead) && (tmp->when <= time(NULL))) { if (debug) @@ -1036,26 +1036,26 @@ void moduleCallBackRun(void) **/ void moduleCallBackDeleteEntry(ModuleCallBack * prev) { - ModuleCallBack *tmp = NULL; - int i; - if (prev == NULL) { - tmp = moduleCallBackHead; - moduleCallBackHead = tmp->next; - } else { - tmp = prev->next; - prev->next = tmp->next; - } - if (tmp->name) - free(tmp->name); - if (tmp->owner_name) - free(tmp->owner_name); - tmp->func = NULL; - for (i = 0; i < tmp->argc; i++) { - free(tmp->argv[i]); - } - tmp->argc = 0; - tmp->next = NULL; - free(tmp); + ModuleCallBack *tmp = NULL; + int i; + if (prev == NULL) { + tmp = moduleCallBackHead; + moduleCallBackHead = tmp->next; + } else { + tmp = prev->next; + prev->next = tmp->next; + } + if (tmp->name) + free(tmp->name); + if (tmp->owner_name) + free(tmp->owner_name); + tmp->func = NULL; + for (i = 0; i < tmp->argc; i++) { + free(tmp->argv[i]); + } + tmp->argc = 0; + tmp->next = NULL; + free(tmp); } /** @@ -1066,24 +1066,24 @@ void moduleCallBackDeleteEntry(ModuleCallBack * prev) **/ static ModuleCallBack *moduleCallBackFindEntry(const char *mod_name, bool * found) { - ModuleCallBack *prev = NULL, *current = NULL; - *found = false; - current = moduleCallBackHead; - while (current != NULL) { - if (current->owner_name - && (strcmp(mod_name, current->owner_name) == 0)) { - *found = true; - break; - } else { - prev = current; - current = current->next; - } - } - if (current == moduleCallBackHead) { - return NULL; - } else { - return prev; - } + ModuleCallBack *prev = NULL, *current = NULL; + *found = false; + current = moduleCallBackHead; + while (current != NULL) { + if (current->owner_name + && (strcmp(mod_name, current->owner_name) == 0)) { + *found = true; + break; + } else { + prev = current; + current = current->next; + } + } + if (current == moduleCallBackHead) { + return NULL; + } else { + return prev; + } } /** @@ -1092,38 +1092,38 @@ static ModuleCallBack *moduleCallBackFindEntry(const char *mod_name, bool * foun **/ void moduleDelCallback(char *name) { - ModuleCallBack *current = NULL; - ModuleCallBack *prev = NULL, *tmp = NULL; - int del = 0; - if (!mod_current_module_name) { - return; - } - if (!name) { - return; - } - current = moduleCallBackHead; - while (current) { - if ((current->owner_name) && (current->name)) { - if ((strcmp(mod_current_module_name, current->owner_name) == 0) - && (strcmp(current->name, name) == 0)) { - if (debug) { - alog("debug: removing CallBack %s for module %s", name, - mod_current_module_name); - } - tmp = current->next; /* get a pointer to the next record, as once we delete this record, we'll lose it :) */ - moduleCallBackDeleteEntry(prev); /* delete this record */ - del = 1; /* set the record deleted flag */ - } - } - if (del == 1) { /* if a record was deleted */ - current = tmp; /* use the value we stored in temp */ - tmp = NULL; /* clear it for next time */ - del = 0; /* reset the flag */ - } else { - prev = current; /* just carry on as normal */ - current = current->next; - } - } + ModuleCallBack *current = NULL; + ModuleCallBack *prev = NULL, *tmp = NULL; + int del = 0; + if (!mod_current_module_name) { + return; + } + if (!name) { + return; + } + current = moduleCallBackHead; + while (current) { + if ((current->owner_name) && (current->name)) { + if ((strcmp(mod_current_module_name, current->owner_name) == 0) + && (strcmp(current->name, name) == 0)) { + if (debug) { + alog("debug: removing CallBack %s for module %s", name, + mod_current_module_name); + } + tmp = current->next; /* get a pointer to the next record, as once we delete this record, we'll lose it :) */ + moduleCallBackDeleteEntry(prev); /* delete this record */ + del = 1; /* set the record deleted flag */ + } + } + if (del == 1) { /* if a record was deleted */ + current = tmp; /* use the value we stored in temp */ + tmp = NULL; /* clear it for next time */ + del = 0; /* reset the flag */ + } else { + prev = current; /* just carry on as normal */ + current = current->next; + } + } } /** @@ -1133,17 +1133,17 @@ void moduleDelCallback(char *name) **/ void moduleCallBackPrepForUnload(const char *mod_name) { - bool found = false; - ModuleCallBack *tmp = NULL; - - tmp = moduleCallBackFindEntry(mod_name, &found); - while (found) { - if (debug) { - alog("debug: removing CallBack for module %s", mod_name); - } - moduleCallBackDeleteEntry(tmp); - tmp = moduleCallBackFindEntry(mod_name, &found); - } + bool found = false; + ModuleCallBack *tmp = NULL; + + tmp = moduleCallBackFindEntry(mod_name, &found); + while (found) { + if (debug) { + alog("debug: removing CallBack for module %s", mod_name); + } + moduleCallBackDeleteEntry(tmp); + tmp = moduleCallBackFindEntry(mod_name, &found); + } } /** @@ -1153,14 +1153,14 @@ void moduleCallBackPrepForUnload(const char *mod_name) **/ char *moduleGetLastBuffer(void) { - char *tmp = NULL; - if (mod_current_buffer) { - tmp = strchr(mod_current_buffer, ' '); - if (tmp) { - tmp++; - } - } - return tmp; + char *tmp = NULL; + if (mod_current_buffer) { + tmp = strchr(mod_current_buffer, ' '); + if (tmp) { + tmp++; + } + } + return tmp; } /******************************************************************************* @@ -1173,11 +1173,11 @@ char *moduleGetLastBuffer(void) **/ int moduleAddRootHelp(Command * c, int (*func) (User * u)) { - if (c) { - c->root_help = func; - return MOD_STOP; - } - return MOD_CONT; + if (c) { + c->root_help = func; + return MOD_STOP; + } + return MOD_CONT; } /** @@ -1187,11 +1187,11 @@ int moduleAddRootHelp(Command * c, int (*func) (User * u)) **/ int moduleAddAdminHelp(Command * c, int (*func) (User * u)) { - if (c) { - c->admin_help = func; - return MOD_STOP; - } - return MOD_CONT; + if (c) { + c->admin_help = func; + return MOD_STOP; + } + return MOD_CONT; } /** @@ -1201,11 +1201,11 @@ int moduleAddAdminHelp(Command * c, int (*func) (User * u)) **/ int moduleAddOperHelp(Command * c, int (*func) (User * u)) { - if (c) { - c->oper_help = func; - return MOD_STOP; - } - return MOD_CONT; + if (c) { + c->oper_help = func; + return MOD_STOP; + } + return MOD_CONT; } /** @@ -1215,11 +1215,11 @@ int moduleAddOperHelp(Command * c, int (*func) (User * u)) **/ int moduleAddRegHelp(Command * c, int (*func) (User * u)) { - if (c) { - c->regular_help = func; - return MOD_STOP; - } - return MOD_CONT; + if (c) { + c->regular_help = func; + return MOD_STOP; + } + return MOD_CONT; } /** @@ -1229,11 +1229,11 @@ int moduleAddRegHelp(Command * c, int (*func) (User * u)) **/ int moduleAddHelp(Command * c, int (*func) (User * u)) { - if (c) { - c->all_help = func; - return MOD_STOP; - } - return MOD_CONT; + if (c) { + c->all_help = func; + return MOD_STOP; + } + return MOD_CONT; } /** @@ -1243,9 +1243,9 @@ int moduleAddHelp(Command * c, int (*func) (User * u)) **/ void moduleSetNickHelp(void (*func) (User * u)) { - if (mod_current_module) { - mod_current_module->nickHelp = func; - } + if (mod_current_module) { + mod_current_module->nickHelp = func; + } } /** @@ -1255,9 +1255,9 @@ void moduleSetNickHelp(void (*func) (User * u)) **/ void moduleSetChanHelp(void (*func) (User * u)) { - if (mod_current_module) { - mod_current_module->chanHelp = func; - } + if (mod_current_module) { + mod_current_module->chanHelp = func; + } } /** @@ -1267,9 +1267,9 @@ void moduleSetChanHelp(void (*func) (User * u)) **/ void moduleSetMemoHelp(void (*func) (User * u)) { - if (mod_current_module) { - mod_current_module->memoHelp = func; - } + if (mod_current_module) { + mod_current_module->memoHelp = func; + } } /** @@ -1279,9 +1279,9 @@ void moduleSetMemoHelp(void (*func) (User * u)) **/ void moduleSetBotHelp(void (*func) (User * u)) { - if (mod_current_module) { - mod_current_module->botHelp = func; - } + if (mod_current_module) { + mod_current_module->botHelp = func; + } } /** @@ -1291,9 +1291,9 @@ void moduleSetBotHelp(void (*func) (User * u)) **/ void moduleSetOperHelp(void (*func) (User * u)) { - if (mod_current_module) { - mod_current_module->operHelp = func; - } + if (mod_current_module) { + mod_current_module->operHelp = func; + } } /** @@ -1303,9 +1303,9 @@ void moduleSetOperHelp(void (*func) (User * u)) **/ void moduleSetHostHelp(void (*func) (User * u)) { - if (mod_current_module) { - mod_current_module->hostHelp = func; - } + if (mod_current_module) { + mod_current_module->hostHelp = func; + } } /** @@ -1315,9 +1315,9 @@ void moduleSetHostHelp(void (*func) (User * u)) **/ void moduleSetHelpHelp(void (*func) (User * u)) { - if (mod_current_module) { - mod_current_module->helpHelp = func; - } + if (mod_current_module) { + mod_current_module->helpHelp = func; + } } /** @@ -1327,33 +1327,33 @@ void moduleSetHelpHelp(void (*func) (User * u)) **/ void moduleDisplayHelp(int service, User * u) { - int idx; - ModuleHash *current = NULL; + int idx; + ModuleHash *current = NULL; Module *calling_module = mod_current_module; const char *calling_module_name = mod_current_module_name; - for (idx = 0; idx != MAX_CMD_HASH; idx++) { - for (current = MODULE_HASH[idx]; current; current = current->next) { + for (idx = 0; idx != MAX_CMD_HASH; idx++) { + for (current = MODULE_HASH[idx]; current; current = current->next) { mod_current_module_name = current->name; mod_current_module = current->m; - if ((service == 1) && current->m->nickHelp) { - current->m->nickHelp(u); - } else if ((service == 2) && current->m->chanHelp) { - current->m->chanHelp(u); - } else if ((service == 3) && current->m->memoHelp) { - current->m->memoHelp(u); - } else if ((service == 4) && current->m->botHelp) { - current->m->botHelp(u); - } else if ((service == 5) && current->m->operHelp) { - current->m->operHelp(u); - } else if ((service == 6) && current->m->hostHelp) { - current->m->hostHelp(u); - } else if ((service == 7) && current->m->helpHelp) { - current->m->helpHelp(u); - } - } - } + if ((service == 1) && current->m->nickHelp) { + current->m->nickHelp(u); + } else if ((service == 2) && current->m->chanHelp) { + current->m->chanHelp(u); + } else if ((service == 3) && current->m->memoHelp) { + current->m->memoHelp(u); + } else if ((service == 4) && current->m->botHelp) { + current->m->botHelp(u); + } else if ((service == 5) && current->m->operHelp) { + current->m->operHelp(u); + } else if ((service == 6) && current->m->hostHelp) { + current->m->hostHelp(u); + } else if ((service == 7) && current->m->helpHelp) { + current->m->helpHelp(u); + } + } + } mod_current_module = calling_module; mod_current_module_name = calling_module_name; @@ -1369,33 +1369,33 @@ void moduleDisplayHelp(int service, User * u) **/ int moduleAddData(ModuleData ** md, const char *key, char *value) { - ModuleData *newData = NULL; + ModuleData *newData = NULL; - if (mod_current_module_name == NULL) { - alog("moduleAddData() called with mod_current_module_name being NULL"); - if (debug) - do_backtrace(0); - } + if (mod_current_module_name == NULL) { + alog("moduleAddData() called with mod_current_module_name being NULL"); + if (debug) + do_backtrace(0); + } - if (!key || !value) { - alog("A module (%s) tried to use ModuleAddData() with one or more NULL arguments... returning", mod_current_module_name); - return MOD_ERR_PARAMS; - } + if (!key || !value) { + alog("A module (%s) tried to use ModuleAddData() with one or more NULL arguments... returning", mod_current_module_name); + return MOD_ERR_PARAMS; + } - moduleDelData(md, key); /* Remove any existing module data for this module with the same key */ + moduleDelData(md, key); /* Remove any existing module data for this module with the same key */ - newData = (ModuleData *)malloc(sizeof(ModuleData)); - if (!newData) { - return MOD_ERR_MEMORY; - } + newData = (ModuleData *)malloc(sizeof(ModuleData)); + if (!newData) { + return MOD_ERR_MEMORY; + } - newData->moduleName = sstrdup(mod_current_module_name); - newData->key = sstrdup(key); - newData->value = sstrdup(value); - newData->next = *md; - *md = newData; + newData->moduleName = sstrdup(mod_current_module_name); + newData->key = sstrdup(key); + newData->value = sstrdup(value); + newData->next = *md; + *md = newData; - return MOD_ERR_OK; + return MOD_ERR_OK; } /** @@ -1407,31 +1407,31 @@ int moduleAddData(ModuleData ** md, const char *key, char *value) **/ char *moduleGetData(ModuleData ** md, const char *key) { - /* See comment in moduleAddData... -GD */ - char *mod_name = sstrdup(mod_current_module_name); - ModuleData *current = *md; - - if (mod_current_module_name == NULL) { - alog("moduleGetData() called with mod_current_module_name being NULL"); - if (debug) - do_backtrace(0); - } - - if (debug) { - alog("debug: moduleGetData %p : key %s", (void *) md, key); - alog("debug: Current Module %s", mod_name); - } - - while (current) { - if ((stricmp(current->moduleName, mod_name) == 0) - && (stricmp(current->key, key) == 0)) { - free(mod_name); - return sstrdup(current->value); - } - current = current->next; - } - free(mod_name); - return NULL; + /* See comment in moduleAddData... -GD */ + char *mod_name = sstrdup(mod_current_module_name); + ModuleData *current = *md; + + if (mod_current_module_name == NULL) { + alog("moduleGetData() called with mod_current_module_name being NULL"); + if (debug) + do_backtrace(0); + } + + if (debug) { + alog("debug: moduleGetData %p : key %s", (void *) md, key); + alog("debug: Current Module %s", mod_name); + } + + while (current) { + if ((stricmp(current->moduleName, mod_name) == 0) + && (stricmp(current->key, key) == 0)) { + free(mod_name); + return sstrdup(current->value); + } + current = current->next; + } + free(mod_name); + return NULL; } /** @@ -1442,40 +1442,40 @@ char *moduleGetData(ModuleData ** md, const char *key) **/ void moduleDelData(ModuleData ** md, const char *key) { - /* See comment in moduleAddData... -GD */ - char *mod_name = sstrdup(mod_current_module_name); - ModuleData *current = *md; - ModuleData *prev = NULL; - ModuleData *next = NULL; - - if (mod_current_module_name == NULL) { - alog("moduleDelData() called with mod_current_module_name being NULL"); - if (debug) - do_backtrace(0); - } - - if (key) { - while (current) { - next = current->next; - if ((stricmp(current->moduleName, mod_name) == 0) - && (stricmp(current->key, key) == 0)) { - if (prev) { - prev->next = current->next; - } else { - *md = current->next; - } - free(current->moduleName); - free(current->key); - free(current->value); - current->next = NULL; - free(current); - } else { - prev = current; - } - current = next; - } - } - free(mod_name); + /* See comment in moduleAddData... -GD */ + char *mod_name = sstrdup(mod_current_module_name); + ModuleData *current = *md; + ModuleData *prev = NULL; + ModuleData *next = NULL; + + if (mod_current_module_name == NULL) { + alog("moduleDelData() called with mod_current_module_name being NULL"); + if (debug) + do_backtrace(0); + } + + if (key) { + while (current) { + next = current->next; + if ((stricmp(current->moduleName, mod_name) == 0) + && (stricmp(current->key, key) == 0)) { + if (prev) { + prev->next = current->next; + } else { + *md = current->next; + } + free(current->moduleName); + free(current->key); + free(current->value); + current->next = NULL; + free(current); + } else { + prev = current; + } + current = next; + } + } + free(mod_name); } /** @@ -1486,37 +1486,37 @@ void moduleDelData(ModuleData ** md, const char *key) **/ void moduleDelAllData(ModuleData ** md) { - /* See comment in moduleAddData... -GD */ - char *mod_name = sstrdup(mod_current_module_name); - ModuleData *current = *md; - ModuleData *prev = NULL; - ModuleData *next = NULL; - - if (mod_current_module_name == NULL) { - alog("moduleDelAllData() called with mod_current_module_name being NULL"); - if (debug) - do_backtrace(0); - } - - while (current) { - next = current->next; - if ((stricmp(current->moduleName, mod_name) == 0)) { - if (prev) { - prev->next = current->next; - } else { - *md = current->next; - } - free(current->moduleName); - free(current->key); - free(current->value); - current->next = NULL; - free(current); - } else { - prev = current; - } - current = next; - } - free(mod_name); + /* See comment in moduleAddData... -GD */ + char *mod_name = sstrdup(mod_current_module_name); + ModuleData *current = *md; + ModuleData *prev = NULL; + ModuleData *next = NULL; + + if (mod_current_module_name == NULL) { + alog("moduleDelAllData() called with mod_current_module_name being NULL"); + if (debug) + do_backtrace(0); + } + + while (current) { + next = current->next; + if ((stricmp(current->moduleName, mod_name) == 0)) { + if (prev) { + prev->next = current->next; + } else { + *md = current->next; + } + free(current->moduleName); + free(current->key); + free(current->value); + current->next = NULL; + free(current); + } else { + prev = current; + } + current = next; + } + free(mod_name); } /** @@ -1525,52 +1525,52 @@ void moduleDelAllData(ModuleData ** md) **/ void moduleDelAllDataMod(Module * m) { - bool freeme = false; - int i, j; - User *user; - NickAlias *na; - NickCore *nc; - ChannelInfo *ci; - - if (!mod_current_module_name) { - mod_current_module_name = sstrdup(m->name.c_str()); - freeme = true; - } - - for (i = 0; i < 1024; i++) { - /* Remove the users */ - for (user = userlist[i]; user; user = user->next) { - moduleDelAllData(&user->moduleData); - } - /* Remove the nick Cores */ - for (nc = nclists[i]; nc; nc = nc->next) { - moduleDelAllData(&nc->moduleData); - /* Remove any memo data for this nick core */ - for (j = 0; j < nc->memos.memocount; j++) { - moduleCleanStruct(&nc->memos.memos[j].moduleData); - } - } - /* Remove the nick Aliases */ - for (na = nalists[i]; na; na = na->next) { - moduleDelAllData(&na->moduleData); - } - } - - for (i = 0; i < 256; i++) { - /* Remove any chan info data */ - for (ci = chanlists[i]; ci; ci = ci->next) { - moduleDelAllData(&ci->moduleData); - /* Remove any memo data for this nick core */ - for (j = 0; j < ci->memos.memocount; j++) { - moduleCleanStruct(&ci->memos.memos[j].moduleData); - } - } - } - - if (freeme) { - free((void *)mod_current_module_name); - mod_current_module_name = NULL; - } + bool freeme = false; + int i, j; + User *user; + NickAlias *na; + NickCore *nc; + ChannelInfo *ci; + + if (!mod_current_module_name) { + mod_current_module_name = sstrdup(m->name.c_str()); + freeme = true; + } + + for (i = 0; i < 1024; i++) { + /* Remove the users */ + for (user = userlist[i]; user; user = user->next) { + moduleDelAllData(&user->moduleData); + } + /* Remove the nick Cores */ + for (nc = nclists[i]; nc; nc = nc->next) { + moduleDelAllData(&nc->moduleData); + /* Remove any memo data for this nick core */ + for (j = 0; j < nc->memos.memocount; j++) { + moduleCleanStruct(&nc->memos.memos[j].moduleData); + } + } + /* Remove the nick Aliases */ + for (na = nalists[i]; na; na = na->next) { + moduleDelAllData(&na->moduleData); + } + } + + for (i = 0; i < 256; i++) { + /* Remove any chan info data */ + for (ci = chanlists[i]; ci; ci = ci->next) { + moduleDelAllData(&ci->moduleData); + /* Remove any memo data for this nick core */ + for (j = 0; j < ci->memos.memocount; j++) { + moduleCleanStruct(&ci->memos.memos[j].moduleData); + } + } + } + + if (freeme) { + free((void *)mod_current_module_name); + mod_current_module_name = NULL; + } } /** @@ -1580,19 +1580,19 @@ void moduleDelAllDataMod(Module * m) **/ void moduleCleanStruct(ModuleData ** moduleData) { - ModuleData *current = *moduleData; - ModuleData *next = NULL; - - while (current) { - next = current->next; - free(current->moduleName); - free(current->key); - free(current->value); - current->next = NULL; - free(current); - current = next; - } - *moduleData = NULL; + ModuleData *current = *moduleData; + ModuleData *next = NULL; + + while (current) { + next = current->next; + free(current->moduleName); + free(current->key); + free(current->value); + current->next = NULL; + free(current); + current = next; + } + *moduleData = NULL; } /** @@ -1606,48 +1606,48 @@ void moduleCleanStruct(ModuleData ** moduleData) **/ bool moduleMinVersion(int major, int minor, int patch, int build) { - bool ret = false; - if (VERSION_MAJOR > major) { /* Def. new */ - ret = true; - } else if (VERSION_MAJOR == major) { /* Might be newer */ - if (minor == -1) { - return true; - } /* They dont care about minor */ - if (VERSION_MINOR > minor) { /* Def. newer */ - ret = true; - } else if (VERSION_MINOR == minor) { /* Might be newer */ - if (patch == -1) { - return true; - } /* They dont care about patch */ - if (VERSION_PATCH > patch) { - ret = true; - } else if (VERSION_PATCH == patch) { + bool ret = false; + if (VERSION_MAJOR > major) { /* Def. new */ + ret = true; + } else if (VERSION_MAJOR == major) { /* Might be newer */ + if (minor == -1) { + return true; + } /* They dont care about minor */ + if (VERSION_MINOR > minor) { /* Def. newer */ + ret = true; + } else if (VERSION_MINOR == minor) { /* Might be newer */ + if (patch == -1) { + return true; + } /* They dont care about patch */ + if (VERSION_PATCH > patch) { + ret = true; + } else if (VERSION_PATCH == patch) { #if 0 // XXX - if (build == -1) { - return true; - } /* They dont care about build */ - if (VERSION_BUILD >= build) { - ret = true; - } + if (build == -1) { + return true; + } /* They dont care about build */ + if (VERSION_BUILD >= build) { + ret = true; + } #endif - } - } - } - return ret; + } + } + } + return ret; } #ifdef _WIN32 const char *ano_moderr(void) { - static char errbuf[513]; - DWORD err = GetLastError(); - if (err == 0) - return NULL; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, errbuf, 512, - NULL); - return errbuf; + static char errbuf[513]; + DWORD err = GetLastError(); + if (err == 0) + return NULL; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, errbuf, 512, + NULL); + return errbuf; } #endif @@ -1655,39 +1655,39 @@ const char *ano_moderr(void) * Allow ircd protocol files to update the protect level info tables. **/ void updateProtectDetails(const char *level_info_protect_word, - const char *level_info_protectme_word, - const char *fant_protect_add, const char *fant_protect_del, - const char *level_protect_word, const char *protect_set_mode, - const char *protect_unset_mode) + const char *level_info_protectme_word, + const char *fant_protect_add, const char *fant_protect_del, + const char *level_protect_word, const char *protect_set_mode, + const char *protect_unset_mode) { - int i = 0; - CSModeUtil ptr; - LevelInfo l_ptr; - - ptr = csmodeutils[i]; - while (ptr.name) { - if (strcmp(ptr.name, "PROTECT") == 0) { - csmodeutils[i].bsname = sstrdup(fant_protect_add); - csmodeutils[i].mode = sstrdup(protect_set_mode); - } else if (strcmp(ptr.name, "DEPROTECT") == 0) { - csmodeutils[i].bsname = sstrdup(fant_protect_del); - csmodeutils[i].mode = sstrdup(protect_unset_mode); - } - ptr = csmodeutils[++i]; - } - - i = 0; - l_ptr = levelinfo[i]; - while (l_ptr.what != -1) { - if (l_ptr.what == CA_PROTECT) { - levelinfo[i].name = sstrdup(level_info_protect_word); - } else if (l_ptr.what == CA_PROTECTME) { - levelinfo[i].name = sstrdup(level_info_protectme_word); - } else if (l_ptr.what == CA_AUTOPROTECT) { - levelinfo[i].name = sstrdup(level_protect_word); - } - l_ptr = levelinfo[++i]; - } + int i = 0; + CSModeUtil ptr; + LevelInfo l_ptr; + + ptr = csmodeutils[i]; + while (ptr.name) { + if (strcmp(ptr.name, "PROTECT") == 0) { + csmodeutils[i].bsname = sstrdup(fant_protect_add); + csmodeutils[i].mode = sstrdup(protect_set_mode); + } else if (strcmp(ptr.name, "DEPROTECT") == 0) { + csmodeutils[i].bsname = sstrdup(fant_protect_del); + csmodeutils[i].mode = sstrdup(protect_unset_mode); + } + ptr = csmodeutils[++i]; + } + + i = 0; + l_ptr = levelinfo[i]; + while (l_ptr.what != -1) { + if (l_ptr.what == CA_PROTECT) { + levelinfo[i].name = sstrdup(level_info_protect_word); + } else if (l_ptr.what == CA_PROTECTME) { + levelinfo[i].name = sstrdup(level_info_protectme_word); + } else if (l_ptr.what == CA_AUTOPROTECT) { + levelinfo[i].name = sstrdup(level_protect_word); + } + l_ptr = levelinfo[++i]; + } } /** @@ -1697,90 +1697,90 @@ void updateProtectDetails(const char *level_info_protect_word, **/ int moduleGetConfigDirective(Directive * d) { - FILE *config; - char *dir = NULL; - char buf[1024]; + FILE *config; + char *dir = NULL; + char buf[1024]; char *directive; - int linenum = 0; - int ac = 0; - char *av[MAXPARAMS]; + int linenum = 0; + int ac = 0; + char *av[MAXPARAMS]; char *str = NULL; - char *s = NULL; + char *s = NULL; char *t = NULL; - int retval = 1; - - config = fopen(SERVICES_CONF, "r"); - if (!config) { - alog("Can't open %s", SERVICES_CONF); - return 0; - } - while (fgets(buf, sizeof(buf), config)) { - linenum++; - if (*buf == '#' || *buf == '\r' || *buf == '\n') { - continue; + int retval = 1; + + config = fopen(SERVICES_CONF, "r"); + if (!config) { + alog("Can't open %s", SERVICES_CONF); + return 0; + } + while (fgets(buf, sizeof(buf), config)) { + linenum++; + if (*buf == '#' || *buf == '\r' || *buf == '\n') { + continue; + } + dir = myStrGetOnlyToken(buf, '\t', 0); + if (dir) { + str = myStrGetTokenRemainder(buf, '\t', 1); + } else { + dir = myStrGetOnlyToken(buf, ' ', 0); + if (dir || (dir = myStrGetOnlyToken(buf, '\n', 0))) { + str = myStrGetTokenRemainder(buf, ' ', 1); + } else { + continue; + } } - dir = myStrGetOnlyToken(buf, '\t', 0); - if (dir) { - str = myStrGetTokenRemainder(buf, '\t', 1); - } else { - dir = myStrGetOnlyToken(buf, ' ', 0); - if (dir || (dir = myStrGetOnlyToken(buf, '\n', 0))) { - str = myStrGetTokenRemainder(buf, ' ', 1); - } else { - continue; - } - } if (dir) { directive = normalizeBuffer(dir); } else { continue; } - if (stricmp(directive, d->name) == 0) { - if (str) { + if (stricmp(directive, d->name) == 0) { + if (str) { s = str; - while (isspace(*s)) - s++; - while (*s) { - if (ac >= MAXPARAMS) { - alog("module error: too many config. params"); - break; - } - t = s; - if (*s == '"') { - t++; - s++; - while (*s && *s != '"') { - if (*s == '\\' && s[1] != 0) - s++; - s++; - } - if (!*s) - alog("module error: Warning: unterminated double-quoted string"); - else - *s++ = 0; - } else { - s += strcspn(s, " \t\r\n"); - if (*s) - *s++ = 0; - } - av[ac++] = t; - while (isspace(*s)) - s++; - } - } - retval = parse_directive(d, directive, ac, av, linenum, 0, s); - } + while (isspace(*s)) + s++; + while (*s) { + if (ac >= MAXPARAMS) { + alog("module error: too many config. params"); + break; + } + t = s; + if (*s == '"') { + t++; + s++; + while (*s && *s != '"') { + if (*s == '\\' && s[1] != 0) + s++; + s++; + } + if (!*s) + alog("module error: Warning: unterminated double-quoted string"); + else + *s++ = 0; + } else { + s += strcspn(s, " \t\r\n"); + if (*s) + *s++ = 0; + } + av[ac++] = t; + while (isspace(*s)) + s++; + } + } + retval = parse_directive(d, directive, ac, av, linenum, 0, s); + } if (directive) { free(directive); } - } - if (dir) - free(dir); - if (str) - free(str); - fclose(config); - return retval; + } + if (dir) + free(dir); + if (str) + free(str); + fclose(config); + return retval; } /** @@ -1792,47 +1792,47 @@ int moduleGetConfigDirective(Directive * d) **/ void moduleNoticeLang(char *source, User * u, int number, ...) { - va_list va; - char buffer[4096], outbuf[4096]; - char *fmt = NULL; - int lang = NSDefLanguage; - char *s, *t, *buf; - - if ((mod_current_module_name) && (!mod_current_module || mod_current_module_name != mod_current_module->name)) { - mod_current_module = findModule(mod_current_module_name); - } - - /* Find the users lang, and use it if we can */ - if (u && u->na && u->na->nc) { - lang = u->na->nc->language; - } - - /* If the users lang isnt supported, drop back to English */ - if (mod_current_module->lang[lang].argc == 0) { - lang = LANG_EN_US; - } - - /* If the requested lang string exists for the language */ - if (mod_current_module->lang[lang].argc > number) { - fmt = mod_current_module->lang[lang].argv[number]; - - buf = sstrdup(fmt); - va_start(va, number); - vsnprintf(buffer, 4095, buf, va); - va_end(va); - s = buffer; - while (*s) { - t = s; - s += strcspn(s, "\n"); - if (*s) - *s++ = '\0'; - strscpy(outbuf, t, sizeof(outbuf)); - notice_user(source, u, "%s", outbuf); - } + va_list va; + char buffer[4096], outbuf[4096]; + char *fmt = NULL; + int lang = NSDefLanguage; + char *s, *t, *buf; + + if ((mod_current_module_name) && (!mod_current_module || mod_current_module_name != mod_current_module->name)) { + mod_current_module = findModule(mod_current_module_name); + } + + /* Find the users lang, and use it if we can */ + if (u && u->na && u->na->nc) { + lang = u->na->nc->language; + } + + /* If the users lang isnt supported, drop back to English */ + if (mod_current_module->lang[lang].argc == 0) { + lang = LANG_EN_US; + } + + /* If the requested lang string exists for the language */ + if (mod_current_module->lang[lang].argc > number) { + fmt = mod_current_module->lang[lang].argv[number]; + + buf = sstrdup(fmt); + va_start(va, number); + vsnprintf(buffer, 4095, buf, va); + va_end(va); + s = buffer; + while (*s) { + t = s; + s += strcspn(s, "\n"); + if (*s) + *s++ = '\0'; + strscpy(outbuf, t, sizeof(outbuf)); + notice_user(source, u, "%s", outbuf); + } free(buf); - } else { - alog("%s: INVALID language string call, language: [%d], String [%d]", mod_current_module->name.c_str(), lang, number); - } + } else { + alog("%s: INVALID language string call, language: [%d], String [%d]", mod_current_module->name.c_str(), lang, number); + } } /** @@ -1843,30 +1843,30 @@ void moduleNoticeLang(char *source, User * u, int number, ...) **/ const char *moduleGetLangString(User * u, int number) { - int lang = NSDefLanguage; + int lang = NSDefLanguage; - if ((mod_current_module_name) && (!mod_current_module || mod_current_module_name != mod_current_module->name)) - mod_current_module = findModule(mod_current_module_name); + if ((mod_current_module_name) && (!mod_current_module || mod_current_module_name != mod_current_module->name)) + mod_current_module = findModule(mod_current_module_name); - /* Find the users lang, and use it if we can */ - if (u && u->na && u->na->nc) - lang = u->na->nc->language; + /* Find the users lang, and use it if we can */ + if (u && u->na && u->na->nc) + lang = u->na->nc->language; - /* If the users lang isnt supported, drop back to English */ - if (mod_current_module->lang[lang].argc == 0) - lang = LANG_EN_US; + /* If the users lang isnt supported, drop back to English */ + if (mod_current_module->lang[lang].argc == 0) + lang = LANG_EN_US; - /* If the requested lang string exists for the language */ - if (mod_current_module->lang[lang].argc > number) { - return mod_current_module->lang[lang].argv[number]; + /* If the requested lang string exists for the language */ + if (mod_current_module->lang[lang].argc > number) { + return mod_current_module->lang[lang].argv[number]; /* Return an empty string otherwise, because we might be used without * the return value being checked. If we would return NULL, bad things * would happen! */ } else { - alog("%s: INVALID language string call, language: [%d], String [%d]", mod_current_module->name.c_str(), lang, number); + alog("%s: INVALID language string call, language: [%d], String [%d]", mod_current_module->name.c_str(), lang, number); return ""; - } + } } /** @@ -1875,37 +1875,37 @@ const char *moduleGetLangString(User * u, int number) **/ void moduleDeleteLanguage(int langNumber) { - int idx = 0; - if ((mod_current_module_name) && (!mod_current_module || mod_current_module_name != mod_current_module->name)) { - mod_current_module = findModule(mod_current_module_name); - } - for (idx = 0; idx > mod_current_module->lang[langNumber].argc; idx++) { - free(mod_current_module->lang[langNumber].argv[idx]); - } - mod_current_module->lang[langNumber].argc = 0; + int idx = 0; + if ((mod_current_module_name) && (!mod_current_module || mod_current_module_name != mod_current_module->name)) { + mod_current_module = findModule(mod_current_module_name); + } + for (idx = 0; idx > mod_current_module->lang[langNumber].argc; idx++) { + free(mod_current_module->lang[langNumber].argv[idx]); + } + mod_current_module->lang[langNumber].argc = 0; } void ModuleRunTimeDirCleanUp(void) { #ifndef _WIN32 - DIR *dirp; - struct dirent *dp; + DIR *dirp; + struct dirent *dp; #else - BOOL fFinished; - HANDLE hList; - TCHAR szDir[MAX_PATH + 1]; - TCHAR szSubDir[MAX_PATH + 1]; - WIN32_FIND_DATA FileData; - char buffer[_MAX_PATH]; + BOOL fFinished; + HANDLE hList; + TCHAR szDir[MAX_PATH + 1]; + TCHAR szSubDir[MAX_PATH + 1]; + WIN32_FIND_DATA FileData; + char buffer[_MAX_PATH]; #endif - char dirbuf[BUFSIZE]; - char filebuf[BUFSIZE]; + char dirbuf[BUFSIZE]; + char filebuf[BUFSIZE]; #ifndef _WIN32 - snprintf(dirbuf, BUFSIZE, "%s/modules/runtime", services_dir); + snprintf(dirbuf, BUFSIZE, "%s/modules/runtime", services_dir); #else - snprintf(dirbuf, BUFSIZE, "\\%s", "modules/runtime"); + snprintf(dirbuf, BUFSIZE, "\\%s", "modules/runtime"); #endif if (debug) { @@ -1913,52 +1913,52 @@ void ModuleRunTimeDirCleanUp(void) } #ifndef _WIN32 - if ((dirp = opendir(dirbuf)) == NULL) { + if ((dirp = opendir(dirbuf)) == NULL) { if (debug) { - alog("debug: cannot open directory (%s)", dirbuf); + alog("debug: cannot open directory (%s)", dirbuf); + } + return; + } + while ((dp = readdir(dirp)) != NULL) { + if (dp->d_ino == 0) { + continue; } - return; - } - while ((dp = readdir(dirp)) != NULL) { - if (dp->d_ino == 0) { - continue; - } - if (!stricmp(dp->d_name, ".") || !stricmp(dp->d_name, "..")) { - continue; - } - snprintf(filebuf, BUFSIZE, "%s/%s", dirbuf, dp->d_name); + if (!stricmp(dp->d_name, ".") || !stricmp(dp->d_name, "..")) { + continue; + } + snprintf(filebuf, BUFSIZE, "%s/%s", dirbuf, dp->d_name); unlink(filebuf); - } - closedir(dirp); + } + closedir(dirp); #else - /* Get the current working directory: */ - if (_getcwd(buffer, _MAX_PATH) == NULL) { + /* Get the current working directory: */ + if (_getcwd(buffer, _MAX_PATH) == NULL) { if (debug) { - alog("debug: Unable to set Current working directory"); + alog("debug: Unable to set Current working directory"); } - } - snprintf(szDir, sizeof(szDir), "%s\\%s\\*", buffer, dirbuf); - - hList = FindFirstFile(szDir, &FileData); - if (hList != INVALID_HANDLE_VALUE) { - fFinished = FALSE; - while (!fFinished) { - if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - snprintf(filebuf, BUFSIZE, "%s/%s", dirbuf, FileData.cFileName); + } + snprintf(szDir, sizeof(szDir), "%s\\%s\\*", buffer, dirbuf); + + hList = FindFirstFile(szDir, &FileData); + if (hList != INVALID_HANDLE_VALUE) { + fFinished = FALSE; + while (!fFinished) { + if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + snprintf(filebuf, BUFSIZE, "%s/%s", dirbuf, FileData.cFileName); DeleteFile(filebuf); - } - if (!FindNextFile(hList, &FileData)) { - if (GetLastError() == ERROR_NO_MORE_FILES) { - fFinished = TRUE; - } - } - } - } else { + } + if (!FindNextFile(hList, &FileData)) { + if (GetLastError() == ERROR_NO_MORE_FILES) { + fFinished = TRUE; + } + } + } + } else { if (debug) { - alog("debug: Invalid File Handle. GetLastError reports %d\n", GetLastError()); + alog("debug: Invalid File Handle. GetLastError reports %d\n", GetLastError()); } - } - FindClose(hList); + } + FindClose(hList); #endif if (debug) { alog("debug: Module run time directory has been cleaned out"); |