]> jfr.im git - solanum.git/blobdiff - src/modules.c
Merge pull request #53 from ShadowNinja/clarify_U+R
[solanum.git] / src / modules.c
index 78a795b7e45297a403f0989af8ce50539825c541..97dd1075fa21a24f221662370ae96d575538b1c6 100644 (file)
@@ -28,7 +28,7 @@
 
 
 #include "modules.h"
-#include "s_log.h"
+#include "logger.h"
 #include "ircd.h"
 #include "client.h"
 #include "send.h"
 #include "numeric.h"
 #include "parse.h"
 #include "ircd_defs.h"
-#include "irc_string.h"
-#include "sprintf_irc.h"
+#include "match.h"
 
 
 
 /* -TimeMr14C:
  * I have moved the dl* function definitions and
  * the two functions (load_a_module / unload_a_module) to the
- * file dynlink.c 
+ * file dynlink.c
  * And also made the necessary changes to those functions
  * to comply with shl_load and friends.
- * In this file, to keep consistency with the makefile, 
+ * In this file, to keep consistency with the makefile,
  * I added the ability to load *.sl files, too.
  * 27/02/2002
  */
@@ -58,6 +57,7 @@
 struct module **modlist = NULL;
 
 static const char *core_module_table[] = {
+       "m_ban",
        "m_die",
        "m_error",
        "m_join",
@@ -69,7 +69,6 @@ static const char *core_module_table[] = {
        "m_part",
        "m_quit",
        "m_server",
-       "m_sjoin",
        "m_squit",
        NULL
 };
@@ -111,8 +110,6 @@ struct Message modrestart_msgtab = {
        {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_modrestart, 0}}
 };
 
-extern struct Message error_msgtab;
-
 void
 modules_init(void)
 {
@@ -133,17 +130,17 @@ modules_init(void)
  * output      - none
  * side effects - returns a module path from path
  */
-static struct module_path *
+static char *
 mod_find_path(const char *path)
 {
        rb_dlink_node *ptr;
-       struct module_path *mpath;
+       char *mpath;
 
        RB_DLINK_FOREACH(ptr, mod_paths.head)
        {
                mpath = ptr->data;
 
-               if(!strcmp(path, mpath->path))
+               if(!strcmp(path, mpath))
                        return mpath;
        }
 
@@ -153,20 +150,18 @@ mod_find_path(const char *path)
 /* mod_add_path
  *
  * input       - path
- * ouput       - 
+ * ouput       -
  * side effects - adds path to list
  */
 void
 mod_add_path(const char *path)
 {
-       struct module_path *pathst;
+       char *pathst;
 
        if(mod_find_path(path))
                return;
 
-       pathst = MyMalloc(sizeof(struct module_path));
-
-       strcpy(pathst->path, path);
+       pathst = rb_strdup(path);
        rb_dlinkAddAlloc(pathst, &mod_paths);
 }
 
@@ -183,35 +178,14 @@ mod_clear_paths(void)
 
        RB_DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head)
        {
-               MyFree(ptr->data);
-               free_rb_dlink_node(ptr);
+               rb_free(ptr->data);
+               rb_free_rb_dlink_node(ptr);
        }
 
        mod_paths.head = mod_paths.tail = NULL;
        mod_paths.length = 0;
 }
 
-/* irc_basename
- *
- * input       -
- * output      -
- * side effects -
- */
-char *
-irc_basename(const char *path)
-{
-       char *mod_basename = MyMalloc(strlen(path) + 1);
-       const char *s;
-
-       if(!(s = strrchr(path, '/')))
-               s = path;
-       else
-               s++;
-
-       (void) strcpy(mod_basename, s);
-       return mod_basename;
-}
-
 /* findmodule_byname
  *
  * input        -
@@ -248,7 +222,7 @@ load_all_modules(int warn)
 
        modules_init();
 
-       modlist = (struct module **) MyMalloc(sizeof(struct module) * (MODS_INCREMENT));
+       modlist = (struct module **) rb_malloc(sizeof(struct module *) * (MODS_INCREMENT));
 
        max_mods = MODS_INCREMENT;
 
@@ -282,7 +256,7 @@ load_all_modules(int warn)
 void
 load_core_modules(int warn)
 {
-       char module_name[MAXPATHLEN];
+       char module_name[PATH_MAX];
        int i;
 
 
@@ -310,20 +284,20 @@ load_core_modules(int warn)
 int
 load_one_module(const char *path, int coremodule)
 {
-       char modpath[MAXPATHLEN];
+       char modpath[PATH_MAX];
        rb_dlink_node *pathst;
-       struct module_path *mpath;
+       const char *mpath;
 
        struct stat statbuf;
 
        if (server_state_foreground == 1)
-               inotice("loading module %s ...", path); 
+               inotice("loading module %s ...", path);
 
        RB_DLINK_FOREACH(pathst, mod_paths.head)
        {
                mpath = pathst->data;
 
-               rb_snprintf(modpath, sizeof(modpath), "%s/%s", mpath->path, path);
+               rb_snprintf(modpath, sizeof(modpath), "%s/%s", mpath, path);
                if((strstr(modpath, "../") == NULL) && (strstr(modpath, "/..") == NULL))
                {
                        if(stat(modpath, &statbuf) == 0)
@@ -359,18 +333,18 @@ mo_modload(struct Client *client_p, struct Client *source_p, int parc, const cha
                return 0;
        }
 
-       m_bn = irc_basename(parv[1]);
+       m_bn = rb_basename(parv[1]);
 
        if(findmodule_byname(m_bn) != -1)
        {
                sendto_one_notice(source_p, ":Module %s is already loaded", m_bn);
-               MyFree(m_bn);
+               rb_free(m_bn);
                return 0;
        }
 
        load_one_module(parv[1], 0);
 
-       MyFree(m_bn);
+       rb_free(m_bn);
 
        return 0;
 }
@@ -390,19 +364,19 @@ mo_modunload(struct Client *client_p, struct Client *source_p, int parc, const c
                return 0;
        }
 
-       m_bn = irc_basename(parv[1]);
+       m_bn = rb_basename(parv[1]);
 
        if((modindex = findmodule_byname(m_bn)) == -1)
        {
                sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
-               MyFree(m_bn);
+               rb_free(m_bn);
                return 0;
        }
 
        if(modlist[modindex]->core == 1)
        {
                sendto_one_notice(source_p, ":Module %s is a core module and may not be unloaded", m_bn);
-               MyFree(m_bn);
+               rb_free(m_bn);
                return 0;
        }
 
@@ -411,7 +385,7 @@ mo_modunload(struct Client *client_p, struct Client *source_p, int parc, const c
                sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
        }
 
-       MyFree(m_bn);
+       rb_free(m_bn);
        return 0;
 }
 
@@ -430,12 +404,12 @@ mo_modreload(struct Client *client_p, struct Client *source_p, int parc, const c
                return 0;
        }
 
-       m_bn = irc_basename(parv[1]);
+       m_bn = rb_basename(parv[1]);
 
        if((modindex = findmodule_byname(m_bn)) == -1)
        {
                sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
-               MyFree(m_bn);
+               rb_free(m_bn);
                return 0;
        }
 
@@ -444,19 +418,19 @@ mo_modreload(struct Client *client_p, struct Client *source_p, int parc, const c
        if(unload_one_module(m_bn, 1) == -1)
        {
                sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
-               MyFree(m_bn);
+               rb_free(m_bn);
                return 0;
        }
 
-       if((load_one_module(parv[1], check_core) == -1) && check_core)
+       if((load_one_module(m_bn, check_core) == -1) && check_core)
        {
                sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                    "Error reloading core module: %s: terminating ircd", parv[1]);
-               ilog(L_MAIN, "Error loading core module %s: terminating ircd", parv[1]);
+                                    "Error reloading core module: %s: terminating ircd", m_bn);
+               ilog(L_MAIN, "Error loading core module %s: terminating ircd", m_bn);
                exit(0);
        }
 
-       MyFree(m_bn);
+       rb_free(m_bn);
        return 0;
 }
 
@@ -482,7 +456,7 @@ mo_modlist(struct Client *client_p, struct Client *source_p, int parc, const cha
                                sendto_one(source_p, form_str(RPL_MODLIST),
                                           me.name, source_p->name,
                                           modlist[i]->name,
-                                          modlist[i]->address,
+                                          (unsigned long)(uintptr_t)modlist[i]->address,
                                           modlist[i]->version, modlist[i]->core ? "(core)" : "");
                        }
                }
@@ -490,7 +464,8 @@ mo_modlist(struct Client *client_p, struct Client *source_p, int parc, const cha
                {
                        sendto_one(source_p, form_str(RPL_MODLIST),
                                   me.name, source_p->name, modlist[i]->name,
-                                  modlist[i]->address, modlist[i]->version,
+                                  (unsigned long)(uintptr_t)modlist[i]->address,
+                                  modlist[i]->version,
                                   modlist[i]->core ? "(core)" : "");
                }
        }
@@ -535,6 +510,10 @@ mo_modrestart(struct Client *client_p, struct Client *source_p, int parc, const
 #define RTLD_NOW RTLD_LAZY     /* openbsd deficiency */
 #endif
 
+#ifndef RTLD_LOCAL
+#define RTLD_LOCAL 0
+#endif
+
 #ifdef CHARYBDIS_PROFILE
 # ifndef RTLD_PROFILE
 #  warning libdl may not support profiling, sucks. :(
@@ -712,9 +691,9 @@ unload_one_module(const char *name, int warn)
        /*
         ** XXX - The type system in C does not allow direct conversion between
         ** data and function pointers, but as it happens, most C compilers will
-        ** safely do this, however it is a theoretical overlow to cast as we 
-        ** must do here.  I have library functions to take care of this, but 
-        ** despite being more "correct" for the C language, this is more 
+        ** safely do this, however it is a theoretical overlow to cast as we
+        ** must do here.  I have library functions to take care of this, but
+        ** despite being more "correct" for the C language, this is more
         ** practical.  Removing the abuse of the ability to cast ANY pointer
         ** to and from an integer value here will break some compilers.
         **          -jmallett
@@ -757,9 +736,9 @@ unload_one_module(const char *name, int warn)
 
        dlclose(modlist[modindex]->address);
 
-       MyFree(modlist[modindex]->name);
-       memcpy(&modlist[modindex], &modlist[modindex + 1],
-              sizeof(struct module) * ((num_mods - 1) - modindex));
+       rb_free(modlist[modindex]->name);
+       memmove(&modlist[modindex], &modlist[modindex + 1],
+              sizeof(struct module *) * ((num_mods - 1) - modindex));
 
        if(num_mods != 0)
                num_mods--;
@@ -791,12 +770,12 @@ load_a_module(const char *path, int warn, int core)
 
        int *mapi_version;
 
-       mod_basename = irc_basename(path);
+       mod_basename = rb_basename(path);
 
 #ifdef CHARYBDIS_PROFILE
-       tmpptr = dlopen(path, RTLD_NOW | RTLD_PROFILE);
+       tmpptr = dlopen(path, RTLD_NOW | RTLD_LOCAL | RTLD_PROFILE);
 #else
-       tmpptr = dlopen(path, RTLD_NOW);
+       tmpptr = dlopen(path, RTLD_NOW | RTLD_LOCAL);
 #endif
 
        if(tmpptr == NULL)
@@ -806,7 +785,7 @@ load_a_module(const char *path, int warn, int core)
                sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                     "Error loading module %s: %s", mod_basename, err);
                ilog(L_MAIN, "Error loading module %s: %s", mod_basename, err);
-               MyFree(mod_basename);
+               rb_free(mod_basename);
                return -1;
        }
 
@@ -827,7 +806,7 @@ load_a_module(const char *path, int warn, int core)
                                     mod_basename);
                ilog(L_MAIN, "Data format error: module %s has no MAPI header.", mod_basename);
                (void) dlclose(tmpptr);
-               MyFree(mod_basename);
+               rb_free(mod_basename);
                return -1;
        }
 
@@ -844,7 +823,7 @@ load_a_module(const char *path, int warn, int core)
                                                     "Module %s indicated failure during load.",
                                                     mod_basename);
                                dlclose(tmpptr);
-                               MyFree(mod_basename);
+                               rb_free(mod_basename);
                                return -1;
                        }
                        if(mheader->mapi_command_list)
@@ -879,7 +858,7 @@ load_a_module(const char *path, int warn, int core)
                                     "Module %s has unknown/unsupported MAPI version %d.",
                                     mod_basename, *mapi_version);
                dlclose(tmpptr);
-               MyFree(mod_basename);
+               rb_free(mod_basename);
                return -1;
        }
 
@@ -888,11 +867,11 @@ load_a_module(const char *path, int warn, int core)
 
        increase_modlist();
 
-       modlist[num_mods] = MyMalloc(sizeof(struct module));
+       modlist[num_mods] = rb_malloc(sizeof(struct module));
        modlist[num_mods]->address = tmpptr;
        modlist[num_mods]->version = ver;
        modlist[num_mods]->core = core;
-       DupString(modlist[num_mods]->name, mod_basename);
+       modlist[num_mods]->name = rb_strdup(mod_basename);
        modlist[num_mods]->mapi_header = mapi_version;
        modlist[num_mods]->mapi_version = MAPI_VERSION(*mapi_version);
        num_mods++;
@@ -906,7 +885,7 @@ load_a_module(const char *path, int warn, int core)
                ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d] loaded at 0x%lx",
                     mod_basename, ver, MAPI_VERSION(*mapi_version), (unsigned long) tmpptr);
        }
-       MyFree(mod_basename);
+       rb_free(mod_basename);
        return 0;
 }
 
@@ -925,11 +904,11 @@ increase_modlist(void)
        if((num_mods + 1) < max_mods)
                return;
 
-       new_modlist = (struct module **) MyMalloc(sizeof(struct module) *
+       new_modlist = (struct module **) rb_malloc(sizeof(struct module *) *
                                                  (max_mods + MODS_INCREMENT));
-       memcpy((void *) new_modlist, (void *) modlist, sizeof(struct module) * num_mods);
+       memcpy((void *) new_modlist, (void *) modlist, sizeof(struct module *) * num_mods);
 
-       MyFree(modlist);
+       rb_free(modlist);
        modlist = new_modlist;
        max_mods += MODS_INCREMENT;
 }