]> jfr.im git - solanum.git/blobdiff - ircd/modules.c
ircd: further cleanup of YES/NO
[solanum.git] / ircd / modules.c
index 4501c1ff57b7c1db239b22ca8e31803c5b48f3ff..09fc4a9853a4c87d4ab25a46b11cf6b68e8d8310 100644 (file)
@@ -58,6 +58,8 @@ static const char *core_module_table[] = {
        NULL
 };
 
+#define MOD_WARN_DELTA (90 * 86400)    /* time in seconds, 86400 seconds in a day */
+
 #define MODS_INCREMENT 10
 int num_mods = 0;
 int max_mods = MODS_INCREMENT;
@@ -243,7 +245,7 @@ load_all_modules(int warn)
                if((len > 3) && !strcmp(ldirent->d_name+len-3, ".la"))
                {
                        (void) snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name);
-                       (void) load_a_module(module_fq_name, warn, 0);
+                       (void) load_a_module(module_fq_name, warn, MAPI_ORIGIN_CORE, 0);
                }
 
        }
@@ -268,7 +270,7 @@ load_core_modules(int warn)
                snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH,
                            core_module_table[i], ".la");
 
-               if(load_a_module(module_name, warn, 1) == -1)
+               if(load_a_module(module_name, warn, MAPI_ORIGIN_CORE, 1) == -1)
                {
                        ilog(L_MAIN,
                             "Error loading core module %s%s: terminating ircd",
@@ -285,7 +287,7 @@ load_core_modules(int warn)
  * side effects -
  */
 int
-load_one_module(const char *path, int coremodule)
+load_one_module(const char *path, int origin, int coremodule)
 {
        char modpath[PATH_MAX];
        rb_dlink_node *pathst;
@@ -296,6 +298,12 @@ load_one_module(const char *path, int coremodule)
        if (server_state_foreground == 1)
                inotice("loading module %s ...", path);
 
+       if(coremodule != 0)
+       {
+               coremodule = 1;
+               origin = MAPI_ORIGIN_CORE;
+       }
+
        RB_DLINK_FOREACH(pathst, mod_paths.head)
        {
                mpath = pathst->data;
@@ -308,10 +316,7 @@ load_one_module(const char *path, int coremodule)
                                if(S_ISREG(statbuf.st_mode))
                                {
                                        /* Regular files only please */
-                                       if(coremodule)
-                                               return load_a_module(modpath, 1, 1);
-                                       else
-                                               return load_a_module(modpath, 1, 0);
+                                       return load_a_module(modpath, 1, origin, coremodule);
                                }
                        }
 
@@ -362,6 +367,7 @@ static int
 do_modload(struct Client *source_p, const char *module)
 {
        char *m_bn = rb_basename(module);
+       int origin;
 
        if(findmodule_byname(m_bn) != -1)
        {
@@ -370,7 +376,8 @@ do_modload(struct Client *source_p, const char *module)
                return 0;
        }
 
-       load_one_module(module, 0);
+       origin = strcmp(module, m_bn) == 0 ? MAPI_ORIGIN_CORE : MAPI_ORIGIN_EXTENSION;
+       load_one_module(module, origin, 0);
 
        rb_free(m_bn);
 
@@ -500,7 +507,7 @@ do_modreload(struct Client *source_p, const char *module)
                return 0;
        }
 
-       if((load_one_module(m_bn, check_core) == -1) && check_core)
+       if((load_one_module(m_bn, modlist[modindex]->origin, check_core) == -1) && check_core)
        {
                sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                     "Error reloading core module: %s: terminating ircd", m_bn);
@@ -554,6 +561,20 @@ do_modlist(struct Client *source_p, const char *pattern)
 
        for (i = 0; i < num_mods; i++)
        {
+               const char *origin;
+               switch (modlist[i]->origin)
+               {
+               case MAPI_ORIGIN_EXTENSION:
+                       origin = "extension";
+                       break;
+               case MAPI_ORIGIN_CORE:
+                       origin = "builtin";
+                       break;
+               default:
+                       origin = "unknown";
+                       break;
+               }
+
                if(pattern)
                {
                        if(match(pattern, modlist[i]->name))
@@ -561,16 +582,16 @@ do_modlist(struct Client *source_p, const char *pattern)
                                sendto_one(source_p, form_str(RPL_MODLIST),
                                           me.name, source_p->name,
                                           modlist[i]->name,
-                                          (unsigned long)(uintptr_t)modlist[i]->address,
-                                          modlist[i]->version, modlist[i]->description, modlist[i]->core ? " (core)" : "");
+                                          (unsigned long)(uintptr_t)modlist[i]->address, origin,
+                                          modlist[i]->core ? " (core)" : "", modlist[i]->version, modlist[i]->description);
                        }
                }
                else
                {
                        sendto_one(source_p, form_str(RPL_MODLIST),
                                   me.name, source_p->name, modlist[i]->name,
-                                  (unsigned long)(uintptr_t)modlist[i]->address,
-                                  modlist[i]->version, modlist[i]->description, modlist[i]->core ? " (core)" : "");
+                                  (unsigned long)(uintptr_t)modlist[i]->address, origin,
+                                  modlist[i]->core ? " (core)" : "", modlist[i]->version, modlist[i]->description);
                }
        }
 
@@ -727,7 +748,7 @@ unload_one_module(const char *name, int warn)
                                {
                                        struct CapabilityIndex *idx;
 
-                                       switch(m->cap_index)
+                                       switch (m->cap_index)
                                        {
                                        case MAPI_CAP_CLIENT:
                                                idx = cli_capindex;
@@ -777,21 +798,19 @@ unload_one_module(const char *name, int warn)
        return 0;
 }
 
-
 /*
  * load_a_module()
  *
- * inputs      - path name of module, int to notice, int of core
+ * inputs      - path name of module, int to notice, int of origin, int of core
  * output      - -1 if error 0 if success
  * side effects - loads a module if successful
  */
 int
-load_a_module(const char *path, int warn, int core)
+load_a_module(const char *path, int warn, int origin, int core)
 {
        lt_dlhandle tmpptr;
        char *mod_basename;
        const char *ver, *description = NULL;
-       int origin = 0;
 
        int *mapi_version;
 
@@ -879,7 +898,7 @@ load_a_module(const char *path, int warn, int core)
                        if(mheader->mapi_register && (mheader->mapi_register() == -1))
                        {
                                ilog(L_MAIN, "Module %s indicated failure during load.",
-                                    mod_basename);
+                                       mod_basename);
                                sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                                     "Module %s indicated failure during load.",
                                                     mod_basename);
@@ -887,6 +906,27 @@ load_a_module(const char *path, int warn, int core)
                                rb_free(mod_basename);
                                return -1;
                        }
+
+                       /* Basic date code checks
+                        *
+                        * Don't make them fatal, but do complain about differences within a certain time frame.
+                        * Later on if there are major API changes we can add fatal checks.
+                        * -- Elizafox
+                        */
+                       if(mheader->mapi_datecode != datecode && mheader->mapi_datecode > 0)
+                       {
+                               long int delta = datecode - mheader->mapi_datecode;
+                               if (delta > MOD_WARN_DELTA)
+                               {
+                                       delta /= 86400;
+                                       iwarn("Module %s build date is out of sync with ircd build date by %ld days, expect problems",
+                                               mod_basename, delta);
+                                       sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                                               "Module %s build date is out of sync with ircd build date by %ld days, expect problems",
+                                               mod_basename, delta);
+                               }
+                       }
+
                        if(mheader->mapi_command_list)
                        {
                                struct Message **m;
@@ -911,7 +951,6 @@ load_a_module(const char *path, int warn, int core)
                        /* New in MAPI v2 - version replacement */
                        ver = mheader->mapi_module_version ? mheader->mapi_module_version : ircd_version;
                        description = mheader->mapi_module_description;
-                       origin = mheader->mapi_origin;
 
                        if(mheader->mapi_cap_list)
                        {
@@ -921,7 +960,7 @@ load_a_module(const char *path, int warn, int core)
                                        struct CapabilityIndex *idx;
                                        int result;
 
-                                       switch(m->cap_index)
+                                       switch (m->cap_index)
                                        {
                                        case MAPI_CAP_CLIENT:
                                                idx = cli_capindex;
@@ -981,11 +1020,8 @@ load_a_module(const char *path, int warn, int core)
        {
                const char *o;
 
-               switch(origin)
+               switch (origin)
                {
-               case MAPI_ORIGIN_EXTERNAL:
-                       o = "external";
-                       break;
                case MAPI_ORIGIN_EXTENSION:
                        o = "extension";
                        break;