示例#1
0
bool ModuleManager::Load(const std::string& name, bool defer)
{
    modmap::iterator it = modlist->find(name);
    if (it == modlist->end())
        return false;
    Module* mod = NULL;

    ServiceList newservices;
    if (!defer)
        this->NewServices = &newservices;

    try
    {
        mod = (*it->second->init)();
        mod->ModuleSourceFile = name;
        mod->ModuleDLLManager = NULL;
        mod->dying = false;
        Modules[name] = mod;
        this->NewServices = NULL;
        if (defer)
        {
            ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s", name.c_str());
            return true;
        }
        else
        {
            ConfigStatus confstatus;

            AttachAll(mod);
            AddServices(newservices);
            mod->init();
            mod->ReadConfig(confstatus);
        }
    }
    catch (CoreException& modexcept)
    {
        this->NewServices = NULL;

        if (mod)
            DoSafeUnload(mod);
        ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Unable to load " + name + ": " + modexcept.GetReason());
        return false;
    }

    FOREACH_MOD(OnLoadModule, (mod));
    PrioritizeHooks();
    ServerInstance->ISupport.Build();
    return true;
}
示例#2
0
void ModuleManager::LoadAll()
{
	std::map<std::string, ServiceList> servicemap;
	LoadCoreModules(servicemap);

	ConfigTagList tags = ServerInstance->Config->ConfTags("module");
	for (ConfigIter i = tags.first; i != tags.second; ++i)
	{
		ConfigTag* tag = i->second;
		std::string name = tag->getString("name");
		this->NewServices = &servicemap[name];
		std::cout << "[" << con_green << "*" << con_reset << "] Loading module:\t" << con_green << name << con_reset << std::endl;

		if (!this->Load(name, true))
		{
			ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
			std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
			ServerInstance->Exit(EXIT_STATUS_MODULE);
		}
	}

	ConfigStatus confstatus;

	for (ModuleMap::const_iterator i = Modules.begin(); i != Modules.end(); ++i)
	{
		Module* mod = i->second;
		try
		{
			ServerInstance->Logs->Log("MODULE", LOG_DEBUG, "Initializing %s", i->first.c_str());
			AttachAll(mod);
			AddServices(servicemap[i->first]);
			mod->init();
			mod->ReadConfig(confstatus);
		}
		catch (CoreException& modexcept)
		{
			LastModuleError = "Unable to initialize " + mod->ModuleSourceFile + ": " + modexcept.GetReason();
			ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
			std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << LastModuleError << std::endl << std::endl;
			ServerInstance->Exit(EXIT_STATUS_MODULE);
		}
	}

	this->NewServices = NULL;

	if (!PrioritizeHooks())
		ServerInstance->Exit(EXIT_STATUS_MODULE);
}
示例#3
0
void AttachAll(HWND hWnd)
{
	UINT uId = (UINT) GetProp(hWnd, gszSubclassProp);
	ATLASSERT(uId == 0);
	if(uId == 0)
	{
		SetProp(hWnd, gszSubclassProp, (HANDLE) guIdSubclass);
		SetWindowSubclass(hWnd, SubclassProc, guIdSubclass, NULL);
	}

	// Subclass all of the children
	hWnd = ::GetWindow(hWnd, GW_CHILD);
	while(hWnd) {
		AttachAll(hWnd);
		hWnd = ::GetWindow(hWnd, GW_HWNDNEXT);
	}
}
示例#4
0
BOOL CIEDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	m_WB.Create( NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, IDC_IE );

	m_WB.put_RegisterAsBrowser( TRUE );
	m_WB.put_RegisterAsDropTarget( TRUE );

	// We want to subclass all the child windows so we can detect focus changes.
	// This will enable us to notify FF of a change in element focus because it gets confused.
	AttachAll(m_hWnd);

	if( m_URL && *m_URL )	{
		COleVariant url(m_URL);
		m_WB.Navigate2( &url, NULL, NULL, NULL, NULL );
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
示例#5
0
bool ModuleManager::Load(const std::string& modname, bool defer)
{
    /* Don't allow people to specify paths for modules, it doesn't work as expected */
    if (modname.find('/') != std::string::npos)
    {
        LastModuleError = "You can't load modules with a path: " + modname;
        return false;
    }

    const std::string filename = ExpandModName(modname);
    const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename);

    if (!FileSystem::FileExists(moduleFile))
    {
        LastModuleError = "Module file could not be found: " + filename;
        ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
        return false;
    }

    if (Modules.find(filename) != Modules.end())
    {
        LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!";
        ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
        return false;
    }

    Module* newmod = NULL;
    DLLManager* newhandle = new DLLManager(moduleFile.c_str());
    ServiceList newservices;
    if (!defer)
        this->NewServices = &newservices;

    try
    {
        newmod = newhandle->CallInit();
        this->NewServices = NULL;

        if (newmod)
        {
            newmod->ModuleSourceFile = filename;
            newmod->ModuleDLLManager = newhandle;
            newmod->dying = false;
            Modules[filename] = newmod;
            std::string version = newhandle->GetVersion();
            if (defer)
            {
                ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)",
                                          filename.c_str(), version.c_str());
            }
            else
            {
                ConfigStatus confstatus;

                AttachAll(newmod);
                AddServices(newservices);
                newmod->init();
                newmod->ReadConfig(confstatus);

                Version v = newmod->GetVersion();
                ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s",
                                          filename.c_str(), version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
            }
        }
        else
        {
            LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError();
            ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
            delete newhandle;
            return false;
        }
    }
    catch (CoreException& modexcept)
    {
        this->NewServices = NULL;

        // failure in module constructor
        if (newmod)
        {
            DoSafeUnload(newmod);
            ServerInstance->GlobalCulls.AddItem(newhandle);
        }
        else
            delete newhandle;
        LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason();
        ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
        return false;
    }

    if (defer)
        return true;

    FOREACH_MOD(OnLoadModule, (newmod));
    PrioritizeHooks();
    ServerInstance->ISupport.Build();
    return true;
}
示例#6
0
LRESULT CALLBACK SubclassProc(
    HWND hWnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam,
    UINT_PTR uIdSubclass,
    DWORD_PTR dwRefData
)
{
	switch(uMsg)
	{
	case WM_NCDESTROY:
		{
			UINT uId = (UINT) GetProp(hWnd, gszSubclassProp);
			if(uId != 0)
			{
				RemoveProp(hWnd, gszSubclassProp);
				RemoveWindowSubclass(hWnd, SubclassProc, guIdSubclass);
			}
		}
		break;

	case WM_PARENTNOTIFY:
		if(LOWORD(wParam) == WM_CREATE)
		{
			bool bSubclass = true;

			// We stop at "Internet Explorer_Server
			TCHAR szClassName[MAX_PATH];
			if ( GetClassName( hWnd, szClassName, ARRAYSIZE(szClassName) ) > 0 )
			{
				if ( _tcscmp(szClassName, _T("Internet Explorer_Server")) == 0 )
				{
					bSubclass = false;
				}
			}

			if(bSubclass)
			{
				HWND hWndChild = (HWND) lParam;
				UINT uId = (UINT) GetProp(hWndChild, gszSubclassProp);
				ATLASSERT(uId == 0);
				if(uId == 0)
				{
					AttachAll(hWndChild);
				}
			}
		}
		break;

	case WM_KEYDOWN:
	case WM_SYSKEYDOWN:
		{
			CWebBrowserCtrl* wb = WebBrowserFromHandle(hWnd);
			if(wb)
			{
				if( (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN) &&
					( HIBYTE(GetKeyState(VK_CONTROL)) || // Ctrl is pressed
					  HIBYTE(GetKeyState(VK_MENU)) || // Alt is pressed
					  ((wParam >= VK_F1) && (wParam <= VK_F24)) // Function-Keys is pressed
					)
				  )
				{
					// Redirect to browser
					::PostMessage( ::GetParent(::GetParent(::GetParent(::GetParent(wb->m_hWnd)))), uMsg, wParam, lParam );
				}
			}
		}
		break;
	}

	return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
示例#7
0
bool ModuleManager::Load(const std::string& filename, bool defer)
{
	/* Don't allow people to specify paths for modules, it doesn't work as expected */
	if (filename.find('/') != std::string::npos)
		return false;

	const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename);

	if (!ServerConfig::FileExists(moduleFile.c_str()))
	{
		LastModuleError = "Module file could not be found: " + filename;
		ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
		return false;
	}

	if (Modules.find(filename) != Modules.end())
	{
		LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!";
		ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
		return false;
	}

	Module* newmod = NULL;
	DLLManager* newhandle = new DLLManager(moduleFile.c_str());

	try
	{
		newmod = newhandle->CallInit();

		if (newmod)
		{
			newmod->ModuleSourceFile = filename;
			newmod->ModuleDLLManager = newhandle;
			newmod->dying = false;
			Modules[filename] = newmod;
			std::string version = newhandle->GetVersion();
			if (defer)
			{
				ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)",
					filename.c_str(), version.c_str());
			}
			else
			{
				AttachAll(newmod);
				newmod->init();

				Version v = newmod->GetVersion();
				ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s",
					filename.c_str(), version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
			}
		}
		else
		{
			LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError();
			ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
			delete newhandle;
			return false;
		}
	}
	catch (CoreException& modexcept)
	{
		// failure in module constructor
		if (newmod)
		{
			DoSafeUnload(newmod);
			ServerInstance->GlobalCulls.AddItem(newhandle);
		}
		else
			delete newhandle;
		LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason();
		ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
		return false;
	}

	this->ModCount++;
	if (defer)
		return true;

	FOREACH_MOD(OnLoadModule, (newmod));
	/* 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, Module*>::iterator n = Modules.begin(); n != Modules.end(); ++n)
			n->second->Prioritize();

		if (prioritizationState == PRIO_STATE_LAST)
			break;
		if (tries == 19)
			ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Hook priority dependency loop detected while loading " + filename);
	}

	ServerInstance->ISupport.Build();
	return true;
}
示例#8
0
/* We must load the modules AFTER initializing the socket engine, now */
void ModuleManager::LoadAll()
{
	ModCount = 0;

	std::cout << std::endl << "Loading core commands";
	fflush(stdout);

	DIR* library = opendir(ServerInstance->Config->Paths.Module.c_str());
	if (library)
	{
		dirent* entry = NULL;
		while (0 != (entry = readdir(library)))
		{
			if (InspIRCd::Match(entry->d_name, "cmd_*.so", ascii_case_insensitive_map))
			{
				std::cout << ".";
				fflush(stdout);

				if (!Load(entry->d_name, true))
				{
					ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
					std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
					ServerInstance->Exit(EXIT_STATUS_MODULE);
				}
			}
		}
		closedir(library);
		std::cout << std::endl;
	}

	ConfigTagList tags = ServerInstance->Config->ConfTags("module");
	for(ConfigIter i = tags.first; i != tags.second; ++i)
	{
		ConfigTag* tag = i->second;
		std::string name = tag->getString("name");
		std::cout << "[" << con_green << "*" << con_reset << "] Loading module:\t" << con_green << name << con_reset << std::endl;

		if (!this->Load(name, true))
		{
			ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
			std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
			ServerInstance->Exit(EXIT_STATUS_MODULE);
		}
	}

	for(std::map<std::string, Module*>::iterator i = Modules.begin(); i != Modules.end(); i++)
	{
		Module* mod = i->second;
		try
		{
			ServerInstance->Logs->Log("MODULE", LOG_DEBUG, "Initializing %s", i->first.c_str());
			AttachAll(mod);
			mod->init();
		}
		catch (CoreException& modexcept)
		{
			LastModuleError = "Unable to initialize " + mod->ModuleSourceFile + ": " + modexcept.GetReason();
			ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
			std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << LastModuleError << std::endl << std::endl;
			ServerInstance->Exit(EXIT_STATUS_MODULE);
		}
	}

	/* 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, Module*>::iterator n = Modules.begin(); n != Modules.end(); ++n)
			n->second->Prioritize();

		if (prioritizationState == PRIO_STATE_LAST)
			break;
		if (tries == 19)
		{
			ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Hook priority dependency loop detected");
			ServerInstance->Exit(EXIT_STATUS_MODULE);
		}
	}
}