-
- Module* newmod = NULL;
- ircd_module* newhandle = NULL;
-
- try
- {
- /* This will throw a CoreException if there's a problem loading
- * the module file or getting a pointer to the init_module symbol.
- */
- newhandle = new ircd_module(modfile, "init_module");
- newmod = newhandle->CallInit();
-
- if (newmod)
- {
- newmod->ModuleSourceFile = filename_str;
- Version v = newmod->GetVersion();
-
- if (v.API != API_VERSION)
- {
- DetachAll(newmod);
- delete newmod;
- delete newhandle;
- LastModuleError = "Unable to load " + filename_str + ": Incorrect module API version: " + ConvToStr(v.API) + " (our version: " + ConvToStr(API_VERSION) + ")";
- ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
- return false;
- }
- else
- {
- ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (API version %d, Module version %s)%s", filename, v.API, v.version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
- }
-
- Modules[filename_str] = std::make_pair(newhandle, newmod);
- }
- else
- {
- delete newhandle;
- LastModuleError = "Unable to load " + filename_str + ": Probably missing init_module() entrypoint, but dlsym() didn't notice a problem";
- ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
- return false;
- }
- }
- /** XXX: Is there anything we can do about this mess? -- Brain */
- catch (LoadModuleException& modexcept)
- {
- DetachAll(newmod);
- if (newmod)
- delete newmod;
- if (newhandle)
- delete newhandle;
- LastModuleError = "Unable to load " + filename_str + ": Error when loading: " + modexcept.GetReason();
- ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
- return false;
- }
- catch (FindSymbolException& modexcept)
- {
- DetachAll(newmod);
- if (newmod)
- delete newmod;
- if (newhandle)
- delete newhandle;
- LastModuleError = "Unable to load " + filename_str + ": Error finding symbol: " + modexcept.GetReason();
- ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
- return false;
- }
- catch (CoreException& modexcept)
- {
- DetachAll(newmod);
- if (newmod)
- delete newmod;
- if (newhandle)
- delete newhandle;
- LastModuleError = "Unable to load " + filename_str + ": " + modexcept.GetReason();
- ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
- return false;
- }
-
- this->ModCount++;
- FOREACH_MOD(I_OnLoadModule,OnLoadModule(newmod, filename_str));
-
- /* We give every module a chance to re-prioritize when we introduce a new one,
- * not just the one thats loading, as the new module could affect the preference
- * of others
- */
- for(int tries = 0; tries < 20; tries++)
- {
- prioritizationState = tries > 0 ? PRIO_STATE_LAST : PRIO_STATE_FIRST;
- for (std::map<std::string, std::pair<ircd_module*, Module*> >::iterator n = Modules.begin(); n != Modules.end(); ++n)
- n->second.second->Prioritize();
-
- if (prioritizationState == PRIO_STATE_LAST)
- break;
- if (tries == 19)
- ServerInstance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected while loading " + filename_str);
- }
-
- ServerInstance->BuildISupport();