diff -r 44b86f49c5d8 -r 4bfb3f26c519 metamod/mlist.cpp --- a/metamod/mlist.cpp Tue Mar 08 10:09:50 2005 +0000 +++ b/metamod/mlist.cpp Tue Jul 12 22:18:15 2005 +0000 @@ -62,6 +62,25 @@ endlist=0; } +// Find a plugin based on the plugin handle. +// meta_errno values: +// - ME_ARGUMENT invalid pindex +// - ME_NOTFOUND couldn't find a matching plugin +MPlugin *MPluginList::find(DLHANDLE handle) +{ + int i; + + if(!handle) + RETURN_ERRNO(NULL, ME_ARGUMENT); + for(i=0; i < endlist; i++) { + if(plist[i].status < PL_VALID) + continue; + if(plist[i].handle == handle) + return(&plist[i]); + } + RETURN_ERRNO(NULL, ME_NOTFOUND); +} + // Find a plugin based on the plugin index #. // meta_errno values: // - ME_ARGUMENT invalid pindex @@ -221,6 +240,63 @@ RETURN_ERRNO(NULL, ME_NOTFOUND); } +MPlugin * MPluginList::plugin_addload(plid_t plid, const char *fname, PLUG_LOADTIME now) +{ + MPlugin pl_temp; + MPlugin *pl_found, *pl_added, *pl_loader; + + if ( !(pl_loader=find(plid)) ) + { + META_DEBUG(1, ("Couldn't find plugin that gave this loading request!")); + RETURN_ERRNO(NULL, ME_BADREQ); + } + + memset(&pl_temp, 0, sizeof(pl_temp)); + + if (!pl_temp.plugin_parseline(fname, pl_loader->index)) + { + RETURN_ERRNO(NULL, ME_NOTFOUND); + } + + if (pl_temp.resolve() != mTRUE) + { + META_DEBUG(1, ("Couldn't resolve given path into a file: %s", pl_temp.file)); + RETURN_ERRNO(NULL, ME_NOTFOUND); + } + + if ( (pl_found=find(pl_temp.pathname)) ) + { + META_DEBUG(1, ("Plugin '%s' already in current list; file=%s desc='%s'", + pl_temp.file, pl_found->file, pl_found->desc)); + RETURN_ERRNO(NULL, ME_ALREADY); + } + + if (!(pl_added=add(&pl_temp))) + { + META_DEBUG(1, ("Couldn't add plugin '%s' to list; see log", pl_temp.desc)); + return NULL; + } + + pl_added->action = PA_LOAD; + if (!pl_added->load(now)) + { + if (meta_errno==ME_NOTALLOWED || meta_errno==ME_DELAYED) + { + META_DEBUG(1, ("Plugin '%s' couldn't attach; only allowed %s", + pl_added->desc, pl_added->str_loadable(SL_ALLOWED))); + pl_added->clear(); + } else if (pl_added->status == PL_OPENED) { + META_DEBUG(1, ("Opened plugin '%s', but failed to attach; see log", pl_added->desc)); + } else { + META_DEBUG(1, ("Couldn't load plugin '%s'; see log", pl_added->desc)); + } + return NULL; + } + + META_DEBUG(1, ("Loaded plugin '%s' successfully", pl_added->desc)); + meta_errno = ME_NOERROR; + return pl_added; +} // Add a plugin to the list. // meta_errno values: @@ -597,7 +673,7 @@ if(iplug->source==PS_INI && iplug->status >= PL_RUNNING) { META_DEBUG(1, ("Unloading plugin '%s'", iplug->desc)); iplug->action=PA_UNLOAD; - if(iplug->unload(now, PNL_INI_DELETED)) + if(iplug->unload(now, PNL_INI_DELETED, PNL_INI_DELETED)) nunloaded++; else if(meta_errno==ME_DELAYED) ndelayed++;