static int LoadLuaConfig(LuaModule *luamodule) { int count = 0; FcitxStringHashSet *sset = FcitxXDGGetFiles("lua", NULL, ".lua"); FcitxStringHashSet *str; for (str = sset; str != NULL;) { FcitxStringHashSet *tmp = str->hh.next; char *path; FILE *f = FcitxXDGGetFileWithPrefix("lua", str->name, "r", &path); if (f && path) { if (LoadExtension(luamodule, path)) { FcitxLog(INFO, "lua load extension file:%s", path); ++count; } else { FcitxLog(ERROR, "LoadExtension() failed"); } } if (f) { fclose(f); } if (path) { free(path); } HASH_DEL(sset, str); free(str->name); free(str); str = tmp; } return count; }
/*ARGSUSED*/ void InitExtensions(int argc, char *argv[]) { int i; ExtensionModule *ext; static Bool listInitialised = FALSE; if (!listInitialised) { /* Add built-in extensions to the list. */ for (i = 0; staticExtensions[i].name; i++) LoadExtension(&staticExtensions[i], TRUE); /* Sort the extensions according the init dependencies. */ LoaderSortExtensions(); listInitialised = TRUE; } for (i = 0; ExtensionModuleList[i].name != NULL; i++) { ext = &ExtensionModuleList[i]; if (ext->initFunc != NULL && (ext->disablePtr == NULL || !*ext->disablePtr)) { (ext->initFunc) (); } } }
IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size_t maxlength) { /* Remove platform extension if it's there. Compat hack. */ const char *ext = libsys->GetFileExtension(file); if (strcmp(ext, PLATFORM_LIB_EXT) == 0) { char path2[PLATFORM_MAX_PATH]; smcore.Format(path2, sizeof(path2), "%s", file); path2[strlen(file) - strlen(PLATFORM_LIB_EXT) - 1] = '\0'; return LoadExtension(path2, error, maxlength); } IExtension *pAlready; if ((pAlready=FindExtensionByFile(file)) != NULL) { return pAlready; } CExtension *pExt = new CLocalExtension(file); if (!pExt->Load(error, maxlength) || !pExt->IsLoaded()) { pExt->Unload(); delete pExt; return NULL; } /* :TODO: do QueryRunning check if the map is loaded */ m_Libs.push_back(pExt); return pExt; }
static pointer glxSetup(pointer module, pointer opts, int *errmaj, int *errmin) { static Bool setupDone = FALSE; pointer GLcore = NULL; #ifdef GLX_USE_SGI_SI char GLcoreName[] = "GL"; #else char GLcoreName[] = "GLcore"; #endif if (!setupDone) { setupDone = TRUE; GLcore = LoadSubModule(module, GLcoreName, NULL, NULL, NULL, NULL, errmaj, errmin); if (!GLcore) { if (errmaj) *errmaj = LDR_NOSUBENT; } else { LoaderReqSymLists(glcoreSymbols, NULL); LoadExtension(&GLXExt, FALSE); /* Wrap the init visuals routine in micmap.c */ GlxWrapInitVisuals(&miInitVisualsProc); /* Make sure this gets wrapped each time InitVisualWrap is called */ miHookInitVisuals(NULL, GlxWrapInitVisuals); } } else { if (errmaj) *errmaj = LDR_ONCEONLY; } /* Need a non-NULL return value to indicate success */ return GLcore; }
static pointer glxSetup(pointer module, pointer opts, int *errmaj, int *errmin) { static Bool setupDone = FALSE; __GLXprovider *provider; if (setupDone) { if (errmaj) *errmaj = LDR_ONCEONLY; return NULL; } setupDone = TRUE; xf86Msg(xf86Info.aiglxFrom, "AIGLX %s\n", xf86Info.aiglx ? "enabled" : "disabled"); if (xf86Info.aiglx) { provider = LoaderSymbol("__glXDRIProvider"); if (provider) GlxPushProvider(provider); provider = LoaderSymbol("__glXDRI2Provider"); if (provider) GlxPushProvider(provider); } LoadExtension(&GLXExt, FALSE); return module; }
static pointer extmodSetup(pointer module, pointer opts, int *errmaj, int *errmin) { int i; /* XXX the option stuff here is largely a sample/test case */ for (i = 0; extensionModules[i].name != NULL; i++) { if (opts) { char *s; s = (char *)xalloc(strlen(extensionModules[i].name) + 5); if (s) { pointer o; strcpy(s, "omit"); strcat(s, extensionModules[i].name); o = xf86FindOption(opts, s); xfree(s); if (o) { xf86MarkOptionUsed(o); continue; } } } LoadExtension(&extensionModules[i], FALSE); } /* Need a non-NULL return */ return (pointer)1; }
static pointer xieSetup(pointer module, pointer opts, int *errmaj, int *errmin) { LoadExtension(&XieExt, FALSE); /* Need a non-NULL return value to indicate success */ return (pointer)1; }
static void ephyrExtensionInit(void) { int i; for (i = 0; i < ARRAY_SIZE(ephyrExtensions); i++) LoadExtension(&ephyrExtensions[i], TRUE); }
static void AddStaticExtensions(void) { static Bool listInitialised = FALSE; int i; if (listInitialised) return; listInitialised = TRUE; /* Add built-in extensions to the list. */ for (i = 0; i < ARRAY_SIZE(staticExtensions); i++) LoadExtension(&staticExtensions[i], TRUE); }
static pointer extmodSetup(pointer module, pointer opts, int *errmaj, int *errmin) { int i; /* XXX the option stuff here is largely a sample/test case */ for (i = 0; extensionModules[i].name != NULL; i++) { if (opts) { char *s; s = (char *)xalloc(strlen(extensionModules[i].name) + 5); if (s) { pointer o; strcpy(s, "omit"); strcat(s, extensionModules[i].name); o = xf86FindOption(opts, s); xfree(s); if (o) { xf86MarkOptionUsed(o); continue; } } } #ifdef XSELINUX if (! strcmp(SELINUX_EXTENSION_NAME, extensionModules[i].name)) { pointer o; selinuxEnforcingState = SELINUX_MODE_DEFAULT; if ((o = xf86FindOption(opts, "SELinux mode disabled"))) { xf86MarkOptionUsed(o); selinuxEnforcingState = SELINUX_MODE_DISABLED; } if ((o = xf86FindOption(opts, "SELinux mode permissive"))) { xf86MarkOptionUsed(o); selinuxEnforcingState = SELINUX_MODE_PERMISSIVE; } if ((o = xf86FindOption(opts, "SELinux mode enforcing"))) { xf86MarkOptionUsed(o); selinuxEnforcingState = SELINUX_MODE_ENFORCING; } } #endif LoadExtension(&extensionModules[i], FALSE); } /* Need a non-NULL return */ return (pointer)1; }
/* * XwinExtensionInit * Initialises Xwin-specific extensions. */ static void XwinExtensionInit(void) { int i; #ifdef XWIN_GLX_WINDOWS if (g_fNativeGl) { /* install the native GL provider */ glxWinPushNativeProvider(); } #endif for (i = 0; i < ARRAY_SIZE(xwinExtensions); i++) LoadExtension(&xwinExtensions[i], TRUE); }
static pointer driSetup(pointer module, pointer opts, int *errmaj, int *errmin) { static Bool setupDone = FALSE; if (!setupDone) { setupDone = TRUE; LoadExtension(&XF86DRIExt, FALSE); } else { if (errmaj) *errmaj = LDR_ONCEONLY; } drmSetServerInfo(&DRIDRMServerInfo); /* Need a non-NULL return value to indicate success */ return 1; }
void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command) { int argcount = smcore.Argc(command); if (argcount >= 3) { const char *cmd = smcore.Arg(command, 2); if (strcmp(cmd, "list") == 0) { List<CExtension *>::iterator iter; CExtension *pExt; unsigned int num = 1; switch (m_Libs.size()) { case 1: { rootmenu->ConsolePrint("[SM] Displaying 1 extension:"); break; } case 0: { rootmenu->ConsolePrint("[SM] No extensions are loaded."); break; } default: { rootmenu->ConsolePrint("[SM] Displaying %d extensions:", m_Libs.size()); break; } } for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++,num++) { pExt = (*iter); if (pExt->IsLoaded()) { char error[255]; if (!pExt->IsRunning(error, sizeof(error))) { rootmenu->ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), error); } else { IExtensionInterface *pAPI = pExt->GetAPI(); const char *name = pAPI->GetExtensionName(); const char *version = pAPI->GetExtensionVerString(); const char *descr = pAPI->GetExtensionDescription(); rootmenu->ConsolePrint("[%02d] %s (%s): %s", num, name, version, descr); } } else { rootmenu->ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str()); } } return; } else if (strcmp(cmd, "load") == 0) { if (argcount < 4) { rootmenu->ConsolePrint("[SM] Usage: sm exts load <file>"); return; } const char *filename = smcore.Arg(command, 3); char path[PLATFORM_MAX_PATH]; char error[256]; smcore.Format(path, sizeof(path), "%s%s%s", filename, !strstr(filename, ".ext") ? ".ext" : "", !strstr(filename, "." PLATFORM_LIB_EXT) ? "." PLATFORM_LIB_EXT : ""); if (FindExtensionByFile(path) != NULL) { rootmenu->ConsolePrint("[SM] Extension %s is already loaded.", path); return; } if (LoadExtension(path, error, sizeof(error))) { rootmenu->ConsolePrint("[SM] Loaded extension %s successfully.", path); } else { rootmenu->ConsolePrint("[SM] Extension %s failed to load: %s", path, error); } return; } else if (strcmp(cmd, "info") == 0) { if (argcount < 4) { rootmenu->ConsolePrint("[SM] Usage: sm exts info <#>"); return; } const char *sId = smcore.Arg(command, 3); unsigned int id = atoi(sId); if (id <= 0) { rootmenu->ConsolePrint("[SM] Usage: sm exts info <#>"); return; } if (m_Libs.size() == 0) { rootmenu->ConsolePrint("[SM] No extensions are loaded."); return; } if (id > m_Libs.size()) { rootmenu->ConsolePrint("[SM] No extension was found with id %d.", id); return; } List<CExtension *>::iterator iter = m_Libs.begin(); CExtension *pExt = NULL; while (iter != m_Libs.end()) { if (--id == 0) { pExt = (*iter); break; } iter++; } /* This should never happen */ if (!pExt) { rootmenu->ConsolePrint("[SM] No extension was found with id %d.", id); return; } if (!pExt->IsLoaded()) { rootmenu->ConsolePrint(" File: %s", pExt->GetFilename()); rootmenu->ConsolePrint(" Loaded: No (%s)", pExt->m_Error.c_str()); } else { char error[255]; if (!pExt->IsRunning(error, sizeof(error))) { rootmenu->ConsolePrint(" File: %s", pExt->GetFilename()); rootmenu->ConsolePrint(" Loaded: Yes"); rootmenu->ConsolePrint(" Running: No (%s)", error); } else { IExtensionInterface *pAPI = pExt->GetAPI(); rootmenu->ConsolePrint(" File: %s", pExt->GetFilename()); rootmenu->ConsolePrint(" Loaded: Yes (version %s)", pAPI->GetExtensionVerString()); rootmenu->ConsolePrint(" Name: %s (%s)", pAPI->GetExtensionName(), pAPI->GetExtensionDescription()); rootmenu->ConsolePrint(" Author: %s (%s)", pAPI->GetExtensionAuthor(), pAPI->GetExtensionURL()); rootmenu->ConsolePrint(" Binary info: API version %d (compiled %s)", pAPI->GetExtensionVersion(), pAPI->GetExtensionDateString()); if (pExt->IsExternal()) { rootmenu->ConsolePrint(" Method: Loaded by Metamod:Source, attached to SourceMod"); } else if (pAPI->IsMetamodExtension()) { rootmenu->ConsolePrint(" Method: Loaded by SourceMod, attached to Metamod:Source"); } else { rootmenu->ConsolePrint(" Method: Loaded by SourceMod"); } } } return; } else if (strcmp(cmd, "unload") == 0) { if (argcount < 4) { rootmenu->ConsolePrint("[SM] Usage: sm exts unload <#> [code]"); return; } const char *arg = smcore.Arg(command, 3); unsigned int num = atoi(arg); CExtension *pExt = FindByOrder(num); if (!pExt) { rootmenu->ConsolePrint("[SM] Extension number %d was not found.", num); return; } if (argcount > 4 && pExt->unload_code) { const char *unload = smcore.Arg(command, 4); if (pExt->unload_code == (unsigned)atoi(unload)) { char filename[PLATFORM_MAX_PATH]; snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename()); UnloadExtension(pExt); rootmenu->ConsolePrint("[SM] Extension %s is now unloaded.", filename); } else { rootmenu->ConsolePrint("[SM] Please try again, the correct unload code is \"%d\"", pExt->unload_code); } return; } if (!pExt->IsLoaded() || (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size())) { char filename[PLATFORM_MAX_PATH]; snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename()); UnloadExtension(pExt); rootmenu->ConsolePrint("[SM] Extension %s is now unloaded.", filename); return; } else { List<CPlugin *> plugins; if (pExt->m_ChildDeps.size()) { rootmenu->ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename()); List<CExtension *>::iterator iter; CExtension *pOther; /* Get list of all extensions */ for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) { List<IfaceInfo>::iterator i_iter; pOther = (*iter); if (!pOther->IsLoaded() || pOther == pExt) { continue; } /* Get their dependencies */ for (i_iter=pOther->m_Deps.begin(); i_iter!=pOther->m_Deps.end(); i_iter++) { /* Is this dependency to us? */ if ((*i_iter).owner != pExt) { continue; } /* Will our dependent care? */ if (!pExt->GetAPI()->QueryInterfaceDrop((*i_iter).iface)) { rootmenu->ConsolePrint(" -> %s", pExt->GetFilename()); /* Add to plugin unload list */ List<CPlugin *>::iterator p_iter; for (p_iter=pOther->m_Dependents.begin(); p_iter!=pOther->m_Dependents.end(); p_iter++) { if (plugins.find((*p_iter)) == plugins.end()) { plugins.push_back((*p_iter)); } } } } } } if (pExt->m_Dependents.size()) { rootmenu->ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename()); List<CPlugin *>::iterator iter; CPlugin *pPlugin; for (iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++) { pPlugin = (*iter); if (plugins.find(pPlugin) == plugins.end()) { plugins.push_back(pPlugin); } } for (iter = plugins.begin(); iter != plugins.end(); iter++) { pPlugin = (*iter); rootmenu->ConsolePrint(" -> %s", pPlugin->GetFilename()); } } srand(static_cast<int>(time(NULL))); pExt->unload_code = (rand() % 877) + 123; //123 to 999 rootmenu->ConsolePrint("[SM] To verify unloading %s, please use the following: ", pExt->GetFilename()); rootmenu->ConsolePrint("[SM] sm exts unload %d %d", num, pExt->unload_code); return; } } else if (strcmp(cmd, "reload") == 0) { if (argcount < 4) { rootmenu->ConsolePrint("[SM] Usage: sm exts reload <#>"); return; } const char *arg = smcore.Arg(command, 3); unsigned int num = atoi(arg); CExtension *pExt = FindByOrder(num); if (!pExt) { rootmenu->ConsolePrint("[SM] Extension number %d was not found.", num); return; } if (pExt->IsLoaded()) { char filename[PLATFORM_MAX_PATH]; char error[255]; snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename()); if (pExt->Reload(error, sizeof(error))) { rootmenu->ConsolePrint("[SM] Extension %s is now reloaded.", filename); } else { rootmenu->ConsolePrint("[SM] Extension %s failed to reload: %s", filename, error); } return; } else { rootmenu->ConsolePrint("[SM] Extension %s is not loaded.", pExt->GetFilename()); return; } } } rootmenu->ConsolePrint("SourceMod Extensions Menu:"); rootmenu->DrawGenericOption("info", "Extra extension information"); rootmenu->DrawGenericOption("list", "List extensions"); rootmenu->DrawGenericOption("load", "Load an extension"); rootmenu->DrawGenericOption("reload", "Reload an extension"); rootmenu->DrawGenericOption("unload", "Unload an extension"); }
void ExtensionsLoader::LoadAllExtensions(const gd::String & directory, gd::Platform & platform, bool forgiving) { std::cout << "Loading extensions for " << platform.GetName() << "... "; gd::String suffix = ""; #if defined(WINDOWS) suffix += "w"; #endif #if defined(GD_IDE_ONLY) suffix += "e"; #endif #if defined(__GNUC__) //For compilers with posix support struct dirent *lecture; DIR *rep; rep = opendir( directory.c_str() ); int l = 0; if ( rep == NULL ) { cout << "Unable to open Extensions ("<< directory <<") directory." << endl; return; } std::vector<gd::String> librariesLoaded; while ( (lecture = readdir( rep )) ) { gd::String lec = lecture->d_name; //Load all extensions, except the legacy ones finishing by *Automatism.xgd* from GD3.x if ( lec != "." && lec != ".." && lec.find(".xgd"+suffix, lec.length()-4-suffix.length()) != string::npos && lec.find("Automatism.xgd"+suffix) == string::npos) { //Use a log file, in IDE only #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI) { wxFile errorDetectFile(wxFileName::GetTempDir()+"/ExtensionBeingLoaded.log", wxFile::write); errorDetectFile.Write(directory+"/"+lec); } #endif LoadExtension(directory+"/"+lec, platform, forgiving); //Everything is ok : Delete the log file #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI) wxRemoveFile(wxFileName::GetTempDir()+"/ExtensionBeingLoaded.log"); #endif librariesLoaded.push_back(directory+"/"+lec); l++; } } closedir( rep ); #elif defined(_MSC_VER) WIN32_FIND_DATA f; gd::String dirPart = "/*.xgd"; gd::String dirComplete = directory + dirPart + suffix; HANDLE h = FindFirstFile(dirComplete.c_str(), &f); if(h != INVALID_HANDLE_VALUE) { do { //Use a log file, in IDE only #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI) { wxFile errorDetectFile(wxFileName::GetTempDir()+"/ExtensionBeingLoaded.log", wxFile::write); errorDetectFile.Write(f.cFileName); } #endif LoadExtension(f.cFileName, platform, forgiving); //Everything is ok : Delete the log file #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI) wxRemoveFile(wxFileName::GetTempDir()+"/ExtensionBeingLoaded.log"); #endif } while(FindNextFile(h, &f)); } #else #warning Compiler not supported (but might support one style of directory listing, update defines if necessary) for dynamic libraries loading #endif std::cout << " done. " << std::endl; }
void InitOutput(ScreenInfo *scrInfo, int argc, char **argv) { int i; int NumFormats = 0; vncPrintBanner(); #if XORG >= 113 #ifdef GLXEXT if (serverGeneration == 1) #if XORG >= 116 LoadExtensionList(&glxExt, 1, TRUE); #else LoadExtension(&glxExt, TRUE); #endif #endif #endif /* initialize pixmap formats */ /* must have a pixmap depth to match every screen depth */ for (i = 0; i < vfbNumScreens; i++) { vfbPixmapDepths[vfbScreens[i].fb.depth] = TRUE; } /* RENDER needs a good set of pixmaps. */ if (Render) { vfbPixmapDepths[1] = TRUE; vfbPixmapDepths[4] = TRUE; vfbPixmapDepths[8] = TRUE; /* vfbPixmapDepths[15] = TRUE; */ vfbPixmapDepths[16] = TRUE; vfbPixmapDepths[24] = TRUE; vfbPixmapDepths[32] = TRUE; } for (i = 1; i <= 32; i++) { if (vfbPixmapDepths[i]) { if (NumFormats >= MAXFORMATS) FatalError ("MAXFORMATS is too small for this server\n"); scrInfo->formats[NumFormats].depth = i; scrInfo->formats[NumFormats].bitsPerPixel = vfbBitsPerPixel(i); scrInfo->formats[NumFormats].scanlinePad = BITMAP_SCANLINE_PAD; NumFormats++; } } scrInfo->imageByteOrder = IMAGE_BYTE_ORDER; scrInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; scrInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD; scrInfo->bitmapBitOrder = BITMAP_BIT_ORDER; scrInfo->numPixmapFormats = NumFormats; /* initialize screens */ for (i = 0; i < vfbNumScreens; i++) { if (-1 == AddScreen(vfbScreenInit, argc, argv)) { FatalError("Couldn't add screen %d", i); } } if (!AddCallback(&ClientStateCallback, vfbClientStateChange, 0)) { FatalError("AddCallback failed\n"); } } /* end InitOutput */
void CScriptEnvTest::SetUp() { InitEngine(); LoadExtension(); }