void *CFBundleGetFunctionPointerForName(CFBundleRef bundle, CFStringRef funcName) {
    void *tvp = NULL;
    // Load if necessary
    if (!bundle->_isLoaded) {
        if (!CFBundleLoadExecutable(bundle)) return NULL;
    }
    
    switch (bundle->_binaryType) {
#if defined(BINARY_SUPPORT_DYLD)
        case __CFBundleDYLDBundleBinary:
        case __CFBundleDYLDFrameworkBinary:
        case __CFBundleDYLDExecutableBinary:
#if defined(BINARY_SUPPORT_DLFCN)
            if (bundle->_handleCookie) return _CFBundleDlfcnGetSymbolByName(bundle, funcName);
#else /* BINARY_SUPPORT_DLFCN */
            return _CFBundleDYLDGetSymbolByName(bundle, funcName);
#endif /* BINARY_SUPPORT_DLFCN */
            break;
#endif /* BINARY_SUPPORT_DYLD */
#if defined(BINARY_SUPPORT_DLL)
        case __CFBundleDLLBinary:
            tvp = _CFBundleDLLGetSymbolByName(bundle, funcName);
            break;
#endif /* BINARY_SUPPORT_DLL */
        default:
#if defined(BINARY_SUPPORT_DLFCN)
            if (bundle->_handleCookie) return _CFBundleDlfcnGetSymbolByName(bundle, funcName);
#endif /* BINARY_SUPPORT_DLFCN */
            break;
    }
    return tvp;
}
void *_CFBundleGetCFMFunctionPointerForName(CFBundleRef bundle, CFStringRef funcName) {
    void *fp = NULL;
    // Load if necessary
    if (!bundle->_isLoaded) {
        if (!CFBundleLoadExecutable(bundle)) return NULL;
    }
#if defined (BINARY_SUPPORT_DYLD) || defined (BINARY_SUPPORT_DLFCN)
    switch (bundle->_binaryType) {
#if defined(BINARY_SUPPORT_DYLD)
        case __CFBundleDYLDBundleBinary:
        case __CFBundleDYLDFrameworkBinary:
        case __CFBundleDYLDExecutableBinary:
#if defined(BINARY_SUPPORT_DLFCN)
            if (bundle->_handleCookie) fp = _CFBundleDlfcnGetSymbolByNameWithSearch(bundle, funcName, true);
#else /* BINARY_SUPPORT_DLFCN */
            fp = _CFBundleDYLDGetSymbolByNameWithSearch(bundle, funcName, true);
#endif /* BINARY_SUPPORT_DLFCN */
            break;
#endif /* BINARY_SUPPORT_DYLD */
        default:
#if defined(BINARY_SUPPORT_DLFCN)
            if (bundle->_handleCookie) fp = _CFBundleDlfcnGetSymbolByNameWithSearch(bundle, funcName, true);
#endif /* BINARY_SUPPORT_DLFCN */
            break;
    }
#endif /* BINARY_SUPPORT_DYLD || BINARY_SUPPORT_DLFCN */
    return fp;
}
Пример #3
0
CFBundleRef LoadBundle(const char *tpath)
{
	OSErr theErr;
	CFBundleRef theBundle = NULL;
	FSSpec fspec;
	if ((theErr = MCS_path2FSSpec(tpath, &fspec)) != noErr)
		return NULL;
	FSRef theRef;
	CFURLRef theBundleURL;
	theErr = FSpMakeFSRef(&fspec, &theRef);
	theBundleURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &theRef);
	if (theBundleURL != NULL)
	{
		/* Turn the CFURL into a bundle reference */
		theBundle = CFBundleCreate(kCFAllocatorSystemDefault, theBundleURL);
		CFRelease(theBundleURL);
	}
	if (theErr != noErr || theBundle == NULL)
		return NULL;
	Boolean isLoaded = CFBundleLoadExecutable(theBundle);
	if (!isLoaded)
	{
		CFRelease(theBundle);
		return NULL;
	}
	return theBundle;
}
void *CFBundleGetDataPointerForName(CFBundleRef bundle, CFStringRef symbolName) {
    void *dp = NULL;
    // Load if necessary
    if (!bundle->_isLoaded && !CFBundleLoadExecutable(bundle)) return NULL;
    
    switch (bundle->_binaryType) {
#if defined(BINARY_SUPPORT_DYLD)
        case __CFBundleDYLDBundleBinary:
        case __CFBundleDYLDFrameworkBinary:
        case __CFBundleDYLDExecutableBinary:
#if defined(BINARY_SUPPORT_DLFCN)
            if (bundle->_handleCookie) dp = _CFBundleDlfcnGetSymbolByName(bundle, symbolName);
#else /* BINARY_SUPPORT_DLFCN */
            dp = _CFBundleDYLDGetSymbolByName(bundle, symbolName);
#endif /* BINARY_SUPPORT_DLFCN */
            break;
#endif /* BINARY_SUPPORT_DYLD */
#if defined(BINARY_SUPPORT_DLL)
        case __CFBundleDLLBinary:
            /* MF:!!! Handle this someday */
            break;
#endif /* BINARY_SUPPORT_DLL */
        default:
#if defined(BINARY_SUPPORT_DLFCN)
            if (bundle->_handleCookie) dp = _CFBundleDlfcnGetSymbolByName(bundle, symbolName);
#endif /* BINARY_SUPPORT_DLFCN */
            break;
    }
    return dp;
}
Пример #5
0
OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef
*bundlePtr)
{
    OSStatus    err;
    FSRef       frameworksFolderRef;
    CFURLRef    baseURL;
    CFURLRef    bundleURL;

    if ( bundlePtr == nil ) return( -1 );

    *bundlePtr = nil;
 
    baseURL = nil;
    bundleURL = nil;
 
    err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true,
&frameworksFolderRef);
    if (err == noErr) {
        baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault,
&frameworksFolderRef);
        if (baseURL == nil) {
            err = coreFoundationUnknownErr;
        }
    }
    if (err == noErr) {
        bundleURL =
CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL,
framework, false);
        if (bundleURL == nil) {
            err = coreFoundationUnknownErr;
        }
    }
    if (err == noErr) {
        *bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
        if (*bundlePtr == nil) {
            err = coreFoundationUnknownErr;
        }
    }
    if (err == noErr) {
        if ( ! CFBundleLoadExecutable( *bundlePtr ) ) {
            err = coreFoundationUnknownErr;
        }
    }

    // Clean up.
    if (err != noErr && *bundlePtr != nil) {
        CFRelease(*bundlePtr);
        *bundlePtr = nil;
    }
    if (bundleURL != nil) {
        CFRelease(bundleURL);
    }

    if (baseURL != nil) {
        CFRelease(baseURL);
    }

    return err;
}
Пример #6
0
extern pascal OSStatus CFQBundleCreateFromFrameworkName(CFStringRef frameworkName, 
														CFBundleRef *bundlePtr)
	// See comment in header.
{
	OSStatus 	err;
	FSRef 		frameworksFolderRef;
	CFURLRef	baseURL;
	CFURLRef	bundleURL;
	
	assert(frameworkName != NULL);
	assert( bundlePtr != NULL);
	assert(*bundlePtr == NULL);
	
	*bundlePtr = NULL;
	
	baseURL = NULL;
	bundleURL = NULL;
	
	// Find the frameworks folder and create a URL for it.
	
	err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef);
	if (err == noErr) {
		baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
		err = CFQError(baseURL);
	}
	
	// Append the name of the framework to the URL.
	
	if (err == noErr) {
		bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, frameworkName, false);
		err = CFQError(bundleURL);
	}
	
	// Create a bundle based on that URL and load the bundle into memory.
	
	if (err == noErr) {
		*bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
		err = CFQError(*bundlePtr);
	}
	if (err == noErr) {
	    err = CFQErrorBoolean( CFBundleLoadExecutable( *bundlePtr ) );
	}

	// Clean up.
	
	if (err != noErr) {
		CFQRelease(*bundlePtr);
		*bundlePtr = NULL;
	}
	CFQRelease(bundleURL);
	CFQRelease(baseURL);
	
	assert( (err == noErr) == (*bundlePtr != NULL) );
	
	return err;
}
Пример #7
0
OSStatus LoadFrameworkBundle(SInt16 folderLocation,CFStringRef framework, CFBundleRef *bundlePtr)
{
	OSStatus 	err;
	FSRef 		frameworksFolderRef;
	CFURLRef	baseURL;
	CFURLRef	bundleURL;
	
	*bundlePtr = nil;
	
	baseURL = nil;
	bundleURL = nil;
	
	err = FSFindFolder(folderLocation, kFrameworksFolderType, true, &frameworksFolderRef);
	if (err == noErr) {
		baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
		if (baseURL == nil) {
			err = coreFoundationUnknownErr;
		}
	}
	if (err == noErr) {
		bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework, false);
		if (bundleURL == nil) {
			err = coreFoundationUnknownErr;
		}
	}
	if (err == noErr) {
		*bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
		if (*bundlePtr == nil) {
			err = coreFoundationUnknownErr;
		}
	}
	if (err == noErr) {
	    if ( ! CFBundleLoadExecutable( *bundlePtr ) ) {
			err = coreFoundationUnknownErr;
	    }
	}

	// Clean up.
	
	if (err != noErr && *bundlePtr != nil) {
		CFRelease(*bundlePtr);
		*bundlePtr = nil;
	}
	if (bundleURL != nil) {
		CFRelease(bundleURL);
	}	
	if (baseURL != nil) {
		CFRelease(baseURL);
	}	

	#ifdef JMMDEBUG
	fprintf(stderr,"\nsystem location %i error %i",folderLocation,err);
	#endif
	
	return err;
}
Пример #8
0
/*
 * QuartzLoadDisplayBundle
 *  Try to load the appropriate bundle containing the back end display code.
 */
Bool QuartzLoadDisplayBundle(
    const char *dpyBundleName)
{
    CFBundleRef mainBundle;
    CFStringRef bundleName;
    CFURLRef    bundleURL;
    CFBundleRef dpyBundle;
    QuartzModeBundleInitPtr bundleInit;

    // Get the main bundle for the application
    mainBundle = CFBundleGetMainBundle();

    // Make CFString from bundle name
    bundleName = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
                                                 dpyBundleName,
                                                 kCFStringEncodingASCII,
                                                 kCFAllocatorNull);

    // Look for the appropriate bundle in the main bundle
    bundleURL = CFBundleCopyResourceURL(mainBundle, bundleName,
                                        NULL, NULL);
    if (!bundleURL) {
        ErrorF("Could not find display mode bundle %s.\n", dpyBundleName);
        return FALSE;
    }

    // Make a bundle instance using the URLRef
    dpyBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);

    if (!CFBundleLoadExecutable(dpyBundle)) {
        ErrorF("Could not load display mode bundle %s.\n", dpyBundleName);
        return FALSE;
    }

    // Lookup the bundle initialization function
    bundleInit = (void *)
            CFBundleGetFunctionPointerForName(dpyBundle,
                                              CFSTR("QuartzModeBundleInit"));
    if (!bundleInit) {
        ErrorF("Could not initialize display mode bundle %s.\n",
               dpyBundleName);
        return FALSE;
    }
    if (!bundleInit())
        return FALSE;

    // Release the CF objects
    CFRelease(bundleName);
    CFRelease(bundleURL);

    return TRUE;
}
Пример #9
0
void CFPlugInSetLoadOnDemand(CFPlugInRef plugIn, Boolean flag) {
    if (__CFBundleGetPlugInData(plugIn)->_isPlugIn) {
        __CFBundleGetPlugInData(plugIn)->_loadOnDemand = flag;
        if (__CFBundleGetPlugInData(plugIn)->_loadOnDemand && !__CFBundleGetPlugInData(plugIn)->_isDoingDynamicRegistration && __CFBundleGetPlugInData(plugIn)->_instanceCount == 0) {
            /* Unload now if we can/should. */
            /* If we are doing dynamic registration currently, do not unload.  The unloading will happen when dynamic registration is done, if necessary. */
            CFBundleUnloadExecutable(plugIn);
        } else if (!__CFBundleGetPlugInData(plugIn)->_loadOnDemand) {
            /* Make sure we're loaded now. */
            CFBundleLoadExecutable(plugIn);
        }
    }
}
Пример #10
0
bool PluginPackage::load()
{
    if (m_isLoaded) {
        m_loadCount++;
        return true;
    }

    WTF::RetainPtr<CFStringRef> path(AdoptCF, m_path.createCFString());
    WTF::RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path.get(),
                                                                        kCFURLPOSIXPathStyle, false));
    m_module = CFBundleCreate(NULL, url.get());
    if (!m_module || !CFBundleLoadExecutable(m_module)) {
        LOG(Plugins, "%s not loaded", m_path.utf8().data());
        return false;
    }

    m_isLoaded = true;

    NP_GetEntryPointsFuncPtr NP_GetEntryPoints = 0;
    NP_InitializeFuncPtr NP_Initialize;
    NPError npErr;

    NP_Initialize = (NP_InitializeFuncPtr)CFBundleGetFunctionPointerForName(m_module, CFSTR("NP_Initialize"));
    NP_GetEntryPoints = (NP_GetEntryPointsFuncPtr)CFBundleGetFunctionPointerForName(m_module, CFSTR("NP_GetEntryPoints"));
    m_NPP_Shutdown = (NPP_ShutdownProcPtr)CFBundleGetFunctionPointerForName(m_module, CFSTR("NP_Shutdown"));

    if (!NP_Initialize || !NP_GetEntryPoints || !m_NPP_Shutdown)
        goto abort;

    memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs));
    m_pluginFuncs.size = sizeof(m_pluginFuncs);

    initializeBrowserFuncs();

    npErr = NP_Initialize(&m_browserFuncs);
    LOG_NPERROR(npErr);
    if (npErr != NPERR_NO_ERROR)
        goto abort;

    npErr = NP_GetEntryPoints(&m_pluginFuncs);
    LOG_NPERROR(npErr);
    if (npErr != NPERR_NO_ERROR)
        goto abort;

    m_loadCount++;
    return true;

abort:
    unloadWithoutShutdown();
    return false;
}
Пример #11
0
/*
 * LoadGlxBundle
 *  The Quartz mode X server needs to dynamically load the appropriate
 *  bundle before initializing GLX.
 */
static void LoadGlxBundle(void)
{
    CFBundleRef mainBundle;
    CFStringRef bundleName;
    CFURLRef    bundleURL;
    CFBundleRef glxBundle;

    // Get the main bundle for the application
    mainBundle = CFBundleGetMainBundle();

    // Choose the bundle to load
    ErrorF("Loading GLX bundle ");
    if (quartzUseAGL) {
        bundleName = CFSTR("glxAGL.bundle");
        ErrorF("glxAGL.bundle (using Apple's OpenGL)\n");
    } else {
        bundleName = CFSTR("glxMesa.bundle");
        ErrorF("glxMesa.bundle (using Mesa)\n");
    }

    // Look for the appropriate GLX bundle in the main bundle by name
    bundleURL = CFBundleCopyResourceURL(mainBundle, bundleName,
                                        NULL, NULL);
    if (!bundleURL) {
        FatalError("Could not find GLX bundle.");
    }

    // Make a bundle instance using the URLRef
    glxBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);

    if (!CFBundleLoadExecutable(glxBundle)) {
        FatalError("Could not load GLX bundle.");
    }

    // Find the GLX init functions
    GlxExtensionInit = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxExtensionInit"));

    GlxWrapInitVisuals = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxWrapInitVisuals"));

    if (!GlxExtensionInit || !GlxWrapInitVisuals) {
        FatalError("Could not initialize GLX bundle.");
    }

    // Release the CF objects
    CFRelease(mainBundle);
    CFRelease(bundleURL);
}
Пример #12
0
OSCodeFragment::OSCodeFragment(const char* inPath)
: fFragmentP(NULL)
{
#if defined(HPUX) || defined(HPUX10)
    shl_t handle;
    fFragmentP = shl_load(inPath, BIND_IMMEDIATE|BIND_VERBOSE|BIND_NOSTART, 0L);
#elif defined(OSF1) ||\
    (defined(__FreeBSD_version) && (__FreeBSD_version >= 220000))
    fFragmentP = dlopen((char *)inPath, RTLD_NOW | RTLD_GLOBAL);
#elif defined(__FreeBSD__)
    fFragmentP = dlopen(inPath, RTLD_NOW);
#elif defined(__sgi__) 
    fFragmentP = dlopen(inPath, RTLD_NOW); // not sure this should be either RTLD_NOW or RTLD_LAZY
#elif defined(__Win32__)
    fFragmentP = ::LoadLibrary(inPath);
#elif defined(__MacOSX__)
    CFStringRef theString = CFStringCreateWithCString( kCFAllocatorDefault, inPath, kCFStringEncodingASCII);

        //
        // In MacOSX, our "fragments" are CF bundles, which are really
        // directories, so our paths are paths to a directory
        CFURLRef    bundleURL = CFURLCreateWithFileSystemPath(  kCFAllocatorDefault,
                                                            theString,
                                                            kCFURLPOSIXPathStyle,
                                                            true);

    //
    // I figure CF is safe about having NULL passed
    // into its functions (if fBundle failed to get created).
    // So, I won't worry about error checking myself
    fFragmentP = CFBundleCreate( kCFAllocatorDefault, bundleURL );
    Boolean success = false;
    if (fFragmentP != NULL)
        success = CFBundleLoadExecutable( fFragmentP );
    if (!success && fFragmentP != NULL)
    {
        CFRelease( fFragmentP );
        fFragmentP = NULL;
    }
    
    CFRelease(bundleURL);
    CFRelease(theString);
    
#else
    fFragmentP = dlopen(inPath, RTLD_NOW | RTLD_GLOBAL);
    //fprintf (stderr, "%s\n", dlerror());

#endif
}
Пример #13
0
CFragConnectionID LoadLibViaPathInDomain(char *libName,SInt16 domain) {
 	CFragConnectionID	libHandle = 0;
    CFURLRef 			theURLRef;
    CFBundleRef			theBundle;
    OSStatus			err;
    CFStringRef 		libNameCFString;
	FSRef 				frameworksFolderRef;
	CFURLRef	baseURL;

 
    err = FSFindFolder(domain, kInternetPlugInFolderType, false,&frameworksFolderRef);
    
    if (err != noErr) {
		return nil;
    }
    
    baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault,&frameworksFolderRef);
    if (baseURL == nil) {
        return nil;
    }
    
	libNameCFString = CFStringCreateWithCString(kCFAllocatorDefault,libName,kCFStringEncodingMacRoman);
    if (libNameCFString == nil) {
		CFRelease(baseURL);
    	return nil;
    }
    theURLRef = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL,libNameCFString, false);
	CFRelease(libNameCFString);
	CFRelease(baseURL);
    if (theURLRef == nil) {
        return nil;
    }
         
    theBundle = CFBundleCreate(kCFAllocatorSystemDefault,theURLRef);
    CFRelease(theURLRef);
    
    if (theBundle == nil) {
        return nil;
    }
    
    if (!CFBundleLoadExecutable(theBundle)) {
        CFRelease(theBundle);
        return nil;
    }
    
    libHandle = (CFragConnectionID) theBundle;

	return libHandle;
}
Пример #14
0
// Utility routine to get a bundle from the system folder by file name....typically used to find OpenGL to get extension functions.
int load_bundle_by_filename (const char * in_filename, CFBundleRef * io_bundle_ref)
{
    OSStatus		err = noErr;
	FSRef			framework_fs;
    CFURLRef		framework_url = NULL;
	CFURLRef		bundle_url = NULL;
	CFStringRef		bundle_name = NULL;
	CFBundleRef		bundle_ref = NULL;
	
	bundle_name = CFStringCreateWithCString(kCFAllocatorDefault, in_filename, kCFStringEncodingUTF8);
    if (bundle_name == NULL) {
		err = paramErr;
    	goto bail; }
	
	err = FSFindFolder(kSystemDomain, kFrameworksFolderType, false, &framework_fs);
    if (noErr != err) {
		err = dirNFErr;
    	goto bail; }
	
    // create URL to folder
    framework_url = CFURLCreateFromFSRef (kCFAllocatorDefault, &framework_fs);
	if(framework_url == NULL) {
		err = ioErr;
		goto bail; }
	
	bundle_url = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorDefault, bundle_name, kCFURLPOSIXPathStyle, false, framework_url);
	if(bundle_url == NULL) {
		err = fnfErr;
		goto bail; }
	
    bundle_ref = CFBundleCreate (kCFAllocatorDefault, bundle_url);
	if(bundle_ref == NULL) {
		err = permErr;
		goto bail; }
	
    if (!CFBundleLoadExecutable (bundle_ref)) {
        err = bdNamErr;
		goto bail;
    }
	
	if (io_bundle_ref) { *io_bundle_ref = bundle_ref; bundle_ref = NULL; }
bail:
		if(bundle_ref)		CFRelease(bundle_ref);
	if(bundle_name)		CFRelease(bundle_name);
	if(bundle_url)		CFRelease(bundle_url);
	if(framework_url)	CFRelease(framework_url);
	
    return err;
}
Пример #15
0
    CFBundleRef mac_loadExeBundle(const char *name) 
    {
        CFBundleRef baseBundle = CFBundleGetBundleWithIdentifier(CFSTR("org.demi3d.Demi"));
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFStringRef nameRef = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
        CFURLRef bundleURL = 0; //URL of bundle to load
        CFBundleRef bundle = 0; //bundle to load

        //cut off .bundle if present
        if (CFStringHasSuffix(nameRef, CFSTR(".bundle"))) 
        {
            CFStringRef nameTempRef = nameRef;
            int end = CFStringGetLength(nameTempRef) - CFStringGetLength(CFSTR(".bundle"));
            nameRef = CFStringCreateWithSubstring(NULL, nameTempRef, CFRangeMake(0, end));
            CFRelease(nameTempRef);
        }

        //assume relative to Resources/ directory of Main bundle
        bundleURL = CFBundleCopyResourceURL(mainBundle, nameRef, CFSTR("bundle"), NULL);
        if (bundleURL)
        {
            bundle = CFBundleCreate(NULL, bundleURL);
            CFRelease(bundleURL);
        }

        //otherwise, try Resources/ directory of Ogre Framework bundle
        if (!bundle) 
        {
            bundleURL = CFBundleCopyResourceURL(baseBundle, nameRef, CFSTR("bundle"), NULL);
            if (bundleURL)
            {
                bundle = CFBundleCreate(NULL, bundleURL);
                CFRelease(bundleURL);
            }
        }
        CFRelease(nameRef);

        if (bundle)
        {
            if (CFBundleLoadExecutable(bundle)) 
                return bundle;
            else
                CFRelease(bundle);
        }

        return 0;
    }
Пример #16
0
/*
 * / Load a module (if needed)
 */
int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
{

	CFStringRef bundlePath;
	CFURLRef bundleURL;
	CFBundleRef bundle;

	*pvLHandle = 0;

	/*
	 * @@@ kCFStringEncodingMacRoman might be wrong on non US systems.
	 */

	bundlePath = CFStringCreateWithCString(NULL, pcLibrary,
		kCFStringEncodingMacRoman);
	if (bundlePath == NULL)
		return SCARD_E_NO_MEMORY;

	bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath,
		kCFURLPOSIXPathStyle, TRUE);
	CFRelease(bundlePath);
	if (bundleURL == NULL)
		return SCARD_E_NO_MEMORY;

	bundle = CFBundleCreate(NULL, bundleURL);
	CFRelease(bundleURL);
	if (bundle == NULL)
	{
		Log1(PCSC_LOG_ERROR, "CFBundleCreate");
		return SCARD_F_UNKNOWN_ERROR;
	}

	if (!CFBundleLoadExecutable(bundle))
	{
		Log1(PCSC_LOG_ERROR, "CFBundleLoadExecutable");
		CFRelease(bundle);
		return SCARD_F_UNKNOWN_ERROR;
	}

	*pvLHandle = (void *) bundle;

	return SCARD_S_SUCCESS;
}
Пример #17
0
	bool loadLibrary (const char* fileName)
	{
	#if _WIN32
		module = LoadLibrary (fileName);
	#elif TARGET_API_MAC_CARBON
		CFStringRef fileNameString = CFStringCreateWithCString (NULL, fileName, kCFStringEncodingUTF8);
		if (fileNameString == 0)
			return false;
		CFURLRef url = CFURLCreateWithFileSystemPath (NULL, fileNameString, kCFURLPOSIXPathStyle, false);
		CFRelease (fileNameString);
		if (url == 0)
			return false;
		module = CFBundleCreate (NULL, url);
		CFRelease (url);
		if (module && CFBundleLoadExecutable ((CFBundleRef)module) == false)
			return false;
	#endif
		return module != 0;
	}
Пример #18
0
bool InjectedBundle::load(APIObject* initializationUserData)
{
    if (m_sandboxExtension) {
        if (!m_sandboxExtension->consume()) {
            fprintf(stderr, "InjectedBundle::load failed - Could not consume bundle sandbox extension for [%s].\n", m_path.utf8().data());
            return false;
        }

        m_sandboxExtension = 0;
    }
    
    RetainPtr<CFStringRef> injectedBundlePathStr(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(m_path.characters()), m_path.length()));
    if (!injectedBundlePathStr) {
        fprintf(stderr, "InjectedBundle::load failed - Could not create the path string.\n");
        return false;
    }
    
    RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(0, injectedBundlePathStr.get(), kCFURLPOSIXPathStyle, false));
    if (!bundleURL) {
        fprintf(stderr, "InjectedBundle::load failed - Could not create the url from the path string.\n");
        return false;
    }

    m_platformBundle = CFBundleCreate(0, bundleURL.get());
    if (!m_platformBundle) {
        fprintf(stderr, "InjectedBundle::load failed - Could not create the bundle.\n");
        return false;
    }
        
    if (!CFBundleLoadExecutable(m_platformBundle)) {
        fprintf(stderr, "InjectedBundle::load failed - Could not load the executable from the bundle.\n");
        return false;
    }

    WKBundleInitializeFunctionPtr initializeFunction = reinterpret_cast<WKBundleInitializeFunctionPtr>(CFBundleGetFunctionPointerForName(m_platformBundle, CFSTR("WKBundleInitialize")));
    if (!initializeFunction) {
        fprintf(stderr, "InjectedBundle::load failed - Could not find the initialize function in the bundle executable.\n");
        return false;
    }

    initializeFunction(toAPI(this), toAPI(initializationUserData));
    return true;
}
static CFBundleRef
_glitz_agl_get_bundle (const char *name)
{
    CFBundleRef bundle = 0;
    FSRefParam ref_param;
    char framework_name[256];

    framework_name[0] = strlen (name);
    strcpy (&framework_name[1], name);

    memset (&ref_param, 0, sizeof (ref_param));

    if (FindFolder (kSystemDomain,
		    kFrameworksFolderType,
		    kDontCreateFolder,
		    &ref_param.ioVRefNum,
		    &ref_param.ioDirID) == noErr) {
	FSRef ref;

	memset (&ref, 0, sizeof (ref));

	ref_param.ioNamePtr = (unsigned char *) framework_name;
	ref_param.newRef = &ref;

	if (PBMakeFSRefSync (&ref_param) == noErr) {
	    CFURLRef url;

	    url = CFURLCreateFromFSRef (kCFAllocatorDefault, &ref);
	    if (url) {
		bundle = CFBundleCreate (kCFAllocatorDefault, url);
		CFRelease (url);

		if (!CFBundleLoadExecutable (bundle)) {
		    CFRelease (bundle);
		    return (CFBundleRef) 0;
		}
	    }
	}
    }

    return bundle;
}
Пример #20
0
static void InitializeIO()
{
    if (sfwRefCount++) {
        return;
    }
    // race condition, infinitesimal risk

    FSRef theRef;
    if (FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, false, &theRef)
            == noErr) {
        CFURLRef fw = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &theRef);
        if (fw) {
            CFURLRef bd = CFURLCreateCopyAppendingPathComponent
                          (kCFAllocatorSystemDefault, fw, CFSTR("System.framework"), false);
            CFRelease(fw);
            if (bd) {
                systemFramework = CFBundleCreate(kCFAllocatorSystemDefault, bd);
                CFRelease(bd);
            }
        }
        if (!systemFramework || !CFBundleLoadExecutable(systemFramework)) {
            return;
        }
#define F(x) CFBundleGetFunctionPointerForName(systemFramework, CFSTR(#x))
        my_fopen = (FILE * (*)(const char *, const char *))F(fopen);
        my_fclose = (int(*)(FILE *))F(fclose);
        my_ftell = (long(*)(FILE *))F(ftell);
        my_fseek = (int(*)(FILE *, long, int))F(fseek);
        my_fread = (t4_u32(*)(void *ptr, t4_u32, t4_u32, FILE *))F(fread);
        my_fwrite = (t4_u32(*)(const void *ptr, t4_u32, t4_u32, FILE *))F(fwrite);
        my_ferror = (int(*)(FILE *))F(ferror);
        my_fflush = (int(*)(FILE *))F(fflush);
        my_fileno = (int(*)(FILE *))F(fileno);
        my_mmap = (char *(*)(char *, t4_u32, int, int, int, long long))F(mmap);
        my_munmap = (int(*)(char *, t4_u32))F(munmap);
#undef F
        d4_assert(my_fopen && my_fclose && my_ftell && my_fseek && my_fread &&
                  my_fwrite && my_ferror && my_fflush && my_fileno && my_mmap && my_munmap);
    }
}
Пример #21
0
	short InstallConsole(short fd)
	{
	#pragma unused (fd)
		OSErr theErr;
		short theResult;
		
		theResult = -1;
		
		/* Start with no bundle */
		__msl_os_x.isLoaded = false;
		__msl_os_x.theBundle = NULL;
		__msl_os_x.theRead = NULL;
		__msl_os_x.theWrite = NULL;
		
		/* Create a bundle reference based on its name */
		theErr = __msl_CreateFrameworkBundleFromName(CFSTR("System.framework"),
			&__msl_os_x.theBundle);
		
		if ((theErr == noErr) && (__msl_os_x.theBundle != NULL))
		{
			theResult = 0;
			
			__msl_os_x.isLoaded = CFBundleLoadExecutable(__msl_os_x.theBundle);
			
			if (__msl_os_x.isLoaded)
			{
				/* Lookup the functions in the bundle by name */
				__msl_os_x.theRead = (ReadPtr)
					CFBundleGetFunctionPointerForName(__msl_os_x.theBundle, CFSTR("read"));
				__msl_os_x.theWrite = (WritePtr)
					CFBundleGetFunctionPointerForName(__msl_os_x.theBundle, CFSTR("write"));
			}
		}
		
		return theResult;
	}
Пример #22
0
/*
 * LoadGlxBundle
 *  The Quartz mode X server needs to dynamically load the appropriate
 *  bundle before initializing GLX.
 */
static void LoadGlxBundle(void)
{
    CFBundleRef mainBundle;
    CFStringRef bundleName;
    CFURLRef    bundleURL;
    CFBundleRef glxBundle;

    // Get the main bundle for the application
    mainBundle = CFBundleGetMainBundle();

    // Choose the bundle to load
    ErrorF("Loading GLX bundle ");
    if (/*quartzUseAGL*/0) {
        bundleName = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
                                                     quartzOpenGLBundle,
                                                     kCFStringEncodingASCII,
                                                     kCFAllocatorNull);
        ErrorF("%s (using Apple's OpenGL)\n", quartzOpenGLBundle);
    } else {
        bundleName = CFSTR("glxMesa.bundle");
        CFRetain(bundleName);			// so we can release later
        ErrorF("glxMesa.bundle (using Mesa)\n");
    }

    // Look for the appropriate GLX bundle in the main bundle by name
    bundleURL = CFBundleCopyResourceURL(mainBundle, bundleName,
                                        NULL, NULL);
    if (!bundleURL) {
        FatalError("Could not find GLX bundle.");
    }

    // Make a bundle instance using the URLRef
    glxBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);

    if (!CFBundleLoadExecutable(glxBundle)) {
        FatalError("Could not load GLX bundle.");
    }

    // Find the GLX init functions


    __DarwinglXMesaProvider = (void *) CFBundleGetDataPointerForName(
			       glxBundle, CFSTR("__glXMesaProvider"));

    GlxPushProvider = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxPushProvider"));

    GlxExtensionInit = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxExtensionInit"));

    GlxWrapInitVisuals = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxWrapInitVisuals"));

    if (!GlxExtensionInit || !GlxWrapInitVisuals) {
        FatalError("Could not initialize GLX bundle.");
    }

    // Release the CF objects
    CFRelease(bundleName);
    CFRelease(bundleURL);
}
Пример #23
0
static CFBundleRef findMe()
{
    CFURLRef    bundleURL;
    CFBundleRef myBundle;
    Boolean didLoad = false;
    // Make a CFURLRef from the CFString representation of the 
    // bundle's path. See the Core Foundation URL Services chapter 
    // for details.
    bundleURL = CFURLCreateWithFileSystemPath( 
                    kCFAllocatorDefault, 
                    CFSTR("/System/Library/Extensions/DVFamily.bundle"),
                    kCFURLPOSIXPathStyle,
                    true );
    
    printf("Bundle URL: %p\n", bundleURL);
    // Make a bundle instance using the URLRef.
    myBundle = CFBundleCreate( kCFAllocatorDefault, bundleURL );
    printf("Bundle: %p\n", myBundle);

    // Try to load the executable from my bundle.
    didLoad = CFBundleLoadExecutable( myBundle );
    printf("loaded? %d\n", didLoad);
    
    sDVFuncs.fDVCountDevices = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVCountDevices") );
    sDVFuncs.fDVGetIndDevice = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVGetIndDevice") );
    sDVFuncs.fDVSetDeviceName = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVSetDeviceName") );
    sDVFuncs.fDVGetDeviceName = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVGetDeviceName") );
    sDVFuncs.fDVOpenDriver = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVOpenDriver") );
    sDVFuncs.fDVCloseDriver = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVCloseDriver") );

// AVC Stuff
    sDVFuncs.fDVDoAVCTransaction = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVDoAVCTransaction") );

    sDVFuncs.fDVIsEnabled = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVIsEnabled") );
    sDVFuncs.fDVGetDeviceStandard = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVGetDeviceStandard") );

// Isoch I/O
    sDVFuncs.fDVEnableRead = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVEnableRead") );
    sDVFuncs.fDVDisableRead = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVDisableRead") );
    sDVFuncs.fDVReadFrame = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVReadFrame") );
    sDVFuncs.fDVReleaseFrame = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVReleaseFrame") );
    sDVFuncs.fDVEnableWrite = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVEnableWrite") );
    sDVFuncs.fDVDisableWrite = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVDisableWrite") );
    sDVFuncs.fDVGetEmptyFrame = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVGetEmptyFrame") );
    sDVFuncs.fDVWriteFrame = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVWriteFrame") );

// Notifications
    sDVFuncs.fDVNewNotification = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVNewNotification") );
    sDVFuncs.fDVNotifyMeWhen = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVNotifyMeWhen") );
    sDVFuncs.fDVCancelNotification = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVCancelNotification") );
    sDVFuncs.fDVDisposeNotification = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVDisposeNotification") );

    // Any CF objects returned from functions with "create" or 
    // "copy" in their names must be released by us!
    CFRelease( bundleURL );
    return myBundle;
}
Пример #24
0
// ---------------------------------------------------------------------------
// Constructeur
// ------------
bStdExtLib::bStdExtLib(CFBundleRef bndl,
                       bGenericMacMapApp* gapp){
_bTrace_("bStdExtLib::bStdExtLib",false);
char	path[PATH_MAX];
UInt32	lsign=_kNULLSign_;

	_status=_bStdExtLibNoErr_;
	_bndl=bndl;
	_family=_kNULLSign_;
	_creator=_kNULLSign_;
	_version=NULL;
	_name=NULL;
	_sign=_kNULLSign_;
	_mmvers=NULL;
	_init=NULL;
	_destroy=NULL;
	_inst=NULL;
	
	for(;;){
		CFBundleGetPackageInfo(_bndl,&_family,&_creator);
		_version=(CFStringRef)CFBundleGetValueForInfoDictionaryKey(_bndl,CFSTR("CFBundleVersion"));
		_name=(CFStringRef)CFBundleGetValueForInfoDictionaryKey(_bndl,CFSTR("CFBundleName"));
				
CFStringRef	cfs;
		
		cfs=(CFStringRef)CFBundleGetValueForInfoDictionaryKey(_bndl,CFSTR("MacMapLibSign"));
		_sign=(cfs)?(*((int*)CFStringGetCStringPtr(cfs,0))):_kNULLSign_;
		_mmvers=(CFStringRef)CFBundleGetValueForInfoDictionaryKey(_bndl,CFSTR("MacMapMinVers"));

CFURLRef	url=CFBundleCopyBundleURL(_bndl);

		cfs=CFURLCopyFileSystemPath(url,kCFURLPOSIXPathStyle);
		CFStringGetCString(cfs,path,PATH_MAX,kCFStringEncodingUTF8);
		CFRelease(cfs);
		
		if(_family==_kNULLSign_){
			_status=_bStdExtLibNoFamilyErr_;
			break;
		}
		if(_creator==_kNULLSign_){
			_status=_bStdExtLibNoCreatorErr_;
			break;
		}
		if(_version==NULL){
			_status=_bStdExtLibNoVersErr_;
			break;
		}
		if(_name==NULL){
			break;
		}
		if(_sign==_kNULLSign_){
			_status=_bStdExtLibNoSignatureErr_;
			break;
		}
		if(_mmvers==NULL){
			_status=_bStdExtLibNoMacMapVersErr_;
			break;
		}
		if(CFBundleIsExecutableLoaded(_bndl)){
			_status=_bStdExtLibBundleAlreadyLoadedErr_;
			break;
		}
		if(!CFBundleLoadExecutable(_bndl)){
			_status=_bStdExtLibBundleLoadErr_;
			break;
		}
		
		_init=(initPtr)CFBundleGetFunctionPointerForName(bndl,CFSTR("init"));
		if(!_init){
			_status=_bStdExtLibNoInitProcErr_;
			break;
		}
		_destroy=(destroyPtr)CFBundleGetFunctionPointerForName(bndl,CFSTR("destroy"));
		if(!_destroy){
			_status=_bStdExtLibNoDestroyProcErr_;
			break;
		}
		_init(&_inst,gapp,_bndl);
		if(!_inst){
			_status=_bStdExtLibNoInstanceErr_;
			break;
		}
		break;
	}
	
	if(_status){
		_status+=_bStdExtLibRootErr_;
_te_("bStdExtLib::bStdExtLib returns "+_status);
	}
	else{
char	c[256];
		name(c);
        (void)bSplashWd::instance(false,gapp)->set_progress(c);
// DEBUG<
        MacRoman2UTF8(c,256);
		lsign=_sign;
#ifdef __LITTLE_ENDIAN__
        LBSwapWord(&lsign,sizeof(int));
#endif
_tm_(c+" "+(unsigned int*)(&_family)+"\t"+(unsigned int*)(&lsign)+" loaded");
// DEBUG>
	}
	
}
Пример #25
0
// hdll, pluginmain and audiomaster are set here
// must be NULL beforehand!
bool VSTPlugin::NewPlugin(const char *plugname)
{
    FLEXT_ASSERT(!pluginmain && !audiomaster);

    dllname = plugname;

#if FLEXT_OS == FLEXT_OS_WIN
    hdll = LoadLibraryEx(dllname.c_str(),NULL,0 /*DONT_RESOLVE_DLL_REFERENCES*/);
/*
    char buf[255],*c;
    strcpy(buf,dllname.c_str());
    for(c = buf; *c; ++c) 
        if(*c == '/') 
            *c = '\\';
    char *sl = strrchr(buf,'\\');
    if(sl) *sl = 0;
    SetCurrentDirectory(buf);
    hdll = LoadLibrary(dllname.c_str());
*/
    if(hdll) pluginmain = (PVSTMAIN)GetProcAddress(hdll,"main");
    audiomaster = Master;  

#elif FLEXT_OS == FLEXT_OS_MAC

#if 1
	CFStringRef fileNameString = CFStringCreateWithCString(NULL, fileName, kCFStringEncodingUTF8);
	if(fileNameString == 0) goto bail;
	CFURLRef url = CFURLCreateWithFileSystemPath(NULL, fileNameString, kCFURLPOSIXPathStyle, false);
	CFRelease(fileNameString);
	if(url == 0) goto bail;
	hdll = CFBundleCreate(NULL, url);
	CFRelease (url);
	if(hdll && !CFBundleLoadExecutable(hdll)) goto bail;

    PVSTMAIN mainaddr = PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("VSTPluginMain"));
	if(!mainaddr)
		mainaddr = (PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("main_macho"));
#ifdef __CFM__
    pluginmain = (PVSTMAIN)NewMachOFromCFM(mainaddr);
    audiomaster = NewCFMFromMachO(Master);
#else
    pluginmain = (PVSTMAIN)mainaddr;
    audiomaster = Master;
#endif

#else
    short   resFileID;
    FSSpec  spec;
    OSErr err;

    err = FSPathMakeFSSpec(dllname.c_str(),&spec,NULL);
    resFileID = FSpOpenResFile(&spec, fsRdPerm);
    short cResCB = Count1Resources('aEff');

    for(int i = 0; i < cResCB; i++) {
        Handle             codeH;
        CFragConnectionID  connID;
        Ptr                mainAddr;
        Str255             errName;
        Str255             fragName;
        char               fragNameCStr[256];
        short              resID;
        OSType             resType;

        codeH = Get1IndResource('aEff', short(i+1));
        if(!codeH) continue;

        GetResInfo(codeH, &resID, &resType, fragName);
        DetachResource(codeH);
        HLock(codeH);

        err = GetMemFragment(*codeH,
                             GetHandleSize(codeH),
                             fragName,
                             kPrivateCFragCopy,
                             &connID, (Ptr *) & mainAddr, errName);

        if(!err) {
           #ifdef __CFM__
           pluginmain = (PVSTMAIN)NewMachOFromCFM(mainAddr);
           #else
           pluginmain = (PVSTMAIN)mainAddr;
           #endif
        }
    }
    CloseResFile(resFileID);

    audiomaster = 
#ifdef __CFM__
        NewCFMFromMachO(Master);
#else
        Master;
#endif

#endif

#else
#error Platform not supported
#endif    

bail:
    if(pluginmain && audiomaster)
        return true;
    else {
        FreePlugin();
        return false;
    }
}
Пример #26
0
CFragConnectionID LoadLibViaPath(char *libName, char *pluginDirPath) {
        char				tempDirPath[DOCUMENT_NAME_SIZE+1];
		char				cFileName[DOCUMENT_NAME_SIZE+1];
		CFragConnectionID   libHandle = 0;
		CFStringRef			filePath;
        CFURLRef 			theURLRef;
        CFBundleRef			theBundle;
        OSStatus			err;
        
		strncpy(tempDirPath,pluginDirPath,DOCUMENT_NAME_SIZE);
        if (tempDirPath[strlen(tempDirPath)-1] != DELIMITERInt)
            strcat(tempDirPath,DELIMITER);
            
        if ((strlen(tempDirPath) + strlen(libName) + 7) > DOCUMENT_NAME_SIZE)
            return nil;
        
        strcat(tempDirPath,libName);
        strcat(tempDirPath,".bundle");  
        //Watch out for the bundle suffix, not a normal thing in squeak plugins

		/* copy the file name into a null-terminated C string */
		sqFilenameFromStringOpen(cFileName, (int) &tempDirPath, strlen(tempDirPath));
		#ifdef JMMDEBUG
		fprintf(stderr,"\nLoadLibViaPath file %s",cFileName);
		#endif
        filePath   = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)cFileName,strlen(cFileName),kCFStringEncodingUTF8,false);
    
        theURLRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,filePath,kCFURLPOSIXPathStyle,false);
		CFRelease(filePath);
        if (theURLRef == nil) {
			#ifdef JMMDEBUG
			fprintf(stderr,"\ntheURLRef was nil so bail");
			#endif
            return nil;
		}

        theBundle = CFBundleCreate(NULL,theURLRef);
        CFRelease(theURLRef);
        
        if (theBundle == nil) {
            CFStringRef libNameCFString;
			#ifdef JMMDEBUG
			fprintf(stderr,"\nbundle was nil, trying to load from other system locations");
			#endif

           libNameCFString = CFStringCreateWithCString(kCFAllocatorDefault,libName,gCurrentVMEncoding);
            err = LoadFrameworkBundle(kUserDomain,libNameCFString, &theBundle);
			if (err != noErr)
				err = LoadFrameworkBundle(kNetworkDomain,libNameCFString, &theBundle);
			if (err != noErr)
				err = LoadFrameworkBundle(kLocalDomain,libNameCFString, &theBundle);
			if (err != noErr)
				err = LoadFrameworkBundle(kSystemDomain,libNameCFString, &theBundle);
				
            CFRelease(libNameCFString);
            if (err != noErr) {
				#ifdef JMMDEBUG
				fprintf(stderr,"\nno bundle so bail, last error %i",err);
				#endif
                return nil;
			}
        }  
        
        if (theBundle == nil) {
			#ifdef JMMDEBUG
			fprintf(stderr,"\nno bundle so bail");
			#endif
            return nil;
		}
            
        if (!CFBundleLoadExecutable(theBundle)) {
			#ifdef JMMDEBUG
			fprintf(stderr,"\nBundle found but failed CFBundleLoadExecutable");
			#endif
            CFRelease(theBundle);
            return nil;
        }
        libHandle = (CFragConnectionID) theBundle;

	#ifdef JMMDEBUG
		fprintf(stderr,"\nFound Bundle %i",libHandle);
	#endif
	return libHandle;
}
Пример #27
0
void CVST2KSPIModule::DoScanDirectory(const std::string& sPathName)
{
	// Scan the system for plug-ins
	CAutoDelete<IFileSearch> pFileSearch(IFileSearch::Create());
	pFileSearch->Init(sPathName.c_str());
	
	tchar pszName[256];
	tbool bDirectory;
	while (pFileSearch->GetNext(pszName, bDirectory)) {
		std::string sPlugInPath = sPathName;

		std::string sName(pszName);

#ifdef WIN32
		if (bDirectory) {
#else	// WIN32
		std::string sEnding = sName.substr(sName.size() - 4);
		if (sEnding != ".vst" && sEnding != ".VST" && sName.size() > 4) {
#endif	
			sPlugInPath += sName;
			sPlugInPath += ":";
			DoScanDirectory(sPlugInPath);
			continue;
		}

		std::string sPathName = sPlugInPath + sName;

#ifdef WIN32
		// Load the plug-in to get info
		{
			HMODULE hDLL;

			std::string sEnding = sName.substr(sName.size() - 4);
			if (sEnding != ".dll" && sEnding != ".DLL" && sEnding != ".Dll" && sName.size() > 4) {
				continue;
			}

			// Load plug-in
			std::string s2 = sPathName;
			ModifyPathName(s2);
			hDLL = LoadLibrary(s2.c_str());
			if (hDLL == NULL) {
				continue;
			}
			
			VSTMainFunc mainFunc = (VSTMainFunc)(void*)GetProcAddress(hDLL, "VSTPluginMain");
			//			VSTMainFunc mainFunc = (VSTMainFunc)CFBundleGetFunctionPointerForName(BundleRef, CFSTR("main") );
			if (mainFunc == NULL) {
				continue;
			}
			
			AEffect* pEffect = NULL;
			try {
				pEffect = mainFunc(audioMasterCallbackModule);
				// Note: Call setSampleRate and setBlockSize also (part of initialization sequence).
				pEffect->dispatcher(pEffect, effOpen, 0, 0, 0, 0.0);
				
				// We don't really need the name now, but we want to just try something to see if it crashes. Would be better to get some info about VST version and required host VST version.
				char pszProductName[1042];
				pEffect->dispatcher(pEffect, effGetEffectName, 0, 0, pszProductName, 0.0);
			}
			catch(...) {
				// Plug-in crashed
				//				CFBundleUnloadExecutable(BundleRef);
				//				CFRelease(BundleRef);
				continue;
			}
			
			// Effect appears ok, put it in list
			msEffectPathNames.push_back(sPathName);
			
			// Unload it
			pEffect->dispatcher(pEffect, effClose, 0, 0, 0, 0.0);
			//			CFBundleUnloadExecutable(BundleRef);
			//			CFRelease(BundleRef);
		}
#else	// WIN32
		// Load the plug-in to get info
		{
			CFBundleRef BundleRef;
			
			// Make a CFURLRef from the CFString representation of the bundle's path.
			tchar pszPathName[1024];
			strcpy(pszPathName, sPathName.c_str());
			ToUnix(pszPathName);
			CFURLRef bundleURL = CFURLCreateWithFileSystemPath( 
															   kCFAllocatorDefault, 
															   __CFStringMakeConstantString(pszPathName),
															   kCFURLPOSIXPathStyle,
															   true );
			if ( !bundleURL ) continue;
			
			// Make a bundle instance using the URLRef.
			BundleRef = CFBundleCreate( kCFAllocatorDefault, bundleURL );
			
			// We don't need the URL anymore
			CFRelease( bundleURL );	
			
			if ( !BundleRef ) {
				continue;
			}
			
			if ( !CFBundleLoadExecutable( BundleRef ) )
			{
				CFRelease( BundleRef );
				BundleRef = NULL;
				continue;
			}
			
			VSTMainFunc mainFunc = (VSTMainFunc)CFBundleGetFunctionPointerForName(BundleRef, CFSTR("VSTPluginMain") );
			//			VSTMainFunc mainFunc = (VSTMainFunc)CFBundleGetFunctionPointerForName(BundleRef, CFSTR("main") );
			if (mainFunc == NULL) {
				continue;
			}
			
			AEffect* pEffect = NULL;
			try {
				pEffect = mainFunc(audioMasterCallbackModule);
				// Note: Call setSampleRate and setBlockSize also (part of initialization sequence).
				pEffect->dispatcher(pEffect, effOpen, 0, 0, 0, 0.0);
				
				// We don't really need the name now, but we want to just try something to see if it crashes. Would be better to get some info about VST version and required host VST version.
				char pszProductName[1042];
				pEffect->dispatcher(pEffect, effGetEffectName, 0, 0, pszProductName, 0.0);
			}
			catch(...) {
				// Plug-in crashed
				//				CFBundleUnloadExecutable(BundleRef);
				//				CFRelease(BundleRef);
				continue;
			}
			
			// Effect appears ok, put it in list
			msEffectPathNames.push_back(sPathName);
			
			// Unload it
			pEffect->dispatcher(pEffect, effClose, 0, 0, 0, 0.0);
			//			CFBundleUnloadExecutable(BundleRef);
			//			CFRelease(BundleRef);
		}
#endif	// WIN32 / else
	}
}

void CVST2KSPIModule::Init()
{
/*	short sVolRef;
	long lDirID;
	tchar pszPlugInPath[1024];
	::FindFolder(kOnSystemDisk, kVolumeRootFolderType, kDontCreateFolder, &sVolRef, &lDirID);
	PathNameFromDirID(lDirID, sVolRef, (char*)pszPlugInPath);
	std::string sPlugInPath(pszPlugInPath);
	sPlugInPath += std::string("Library:Audio:Plug-Ins:VST:");*/
	// Note: This is hardcoded, and needs to change
#ifdef WIN32
	std::string sPlugInPath(":C:VSTPlugIns:");
	DoScanDirectory(sPlugInPath);
#else	// WIN32
//	std::string sPlugInPath(":Macintosh HD:Library:Audio:Plug-Ins:VST:");
	tchar pszPath[1024];
	IFile::GetSystemDirectory(IFile::SystemDirLibrary, pszPath);
	strcat(pszPath, "Audio:Plug-Ins:VST:");
	std::string sPlugInPath(pszPath);
	DoScanDirectory(sPlugInPath);

	IFile::GetSystemDirectory(IFile::SystemDirUser, pszPath);
	strcat(pszPath, "Library:Audio:Plug-Ins:VST:");
	sPlugInPath = std::string(pszPath);
	DoScanDirectory(sPlugInPath);
#endif	// WIN32 / else
}
Пример #28
0
CVST2KSPIPlugIn::CVST2KSPIPlugIn(CVST2KSPIModule* pModule, const std::string& sEffectPathName)
	: CBasePlugIn(dynamic_cast<CBaseModule*>(pModule), giAudioMaxBufferSize, dynamic_cast<CBaseDSPEngine*>(new CEcho()), 0, COMPANY_NAME, PRODUCT_NAME),
	mbUpdateGUISettings(true),
	mbBypass(false), mbShowDemoExpiredDialog(false),
	mbRegistered(false),
	miNoiseMode(0), miNoiseCounter(0),
	msEffectPathName(sEffectPathName),
	mpVSTEffect(NULL)
{
	dynamic_cast<CEcho*>(mpDSPEngine)->SetChannels(2);

	mpDezipper->SetCallback(dynamic_cast<IBaseDezipperCallback*>(this));

	mbCanProcess = true;

	muiTimeWhenStarted = ITime::GetTimeMS();

	miRandom = 0x123456;

#ifdef WIN32
	{
		HMODULE hDLL;

		// Load plug-in
		std::string s2 = msEffectPathName;
		ModifyPathName(s2);
		hDLL = LoadLibrary(s2.c_str());
		if (hDLL == NULL) {
		}
			
		VSTMainFunc mainFunc = (VSTMainFunc)(void*)GetProcAddress(hDLL, "VSTPluginMain");
		if (mainFunc == NULL) {
		}

		try {
			mpVSTEffect = mainFunc(audioMasterCallbackPlugIn);
			mpVSTEffect->dispatcher(mpVSTEffect, effOpen, 0, 0, 0, 0.0);
			mpVSTEffect->dispatcher(mpVSTEffect, effSetSampleRate, 0, 0, 0, 44100.0f);
			mpVSTEffect->dispatcher(mpVSTEffect, effSetBlockSize, 0, 32, 0, 0.0);
		}
		catch(...) {
			// Plug-in crashed
			mpVSTEffect = NULL;
		}
	}
#else	// WIN32
	{
		CFBundleRef BundleRef;

		// Make a CFURLRef from the CFString representation of the bundle's path.
		tchar pszPathName[1024];
		strcpy(pszPathName, msEffectPathName.c_str());
		ToUnix(pszPathName);
		CFURLRef bundleURL = CFURLCreateWithFileSystemPath( 
			kCFAllocatorDefault, 
			__CFStringMakeConstantString(pszPathName),
			kCFURLPOSIXPathStyle,
			true );
		if ( !bundleURL ) {
		}

		// Make a bundle instance using the URLRef.
		BundleRef = CFBundleCreate( kCFAllocatorDefault, bundleURL );

		// We don't need the URL anymore
		CFRelease( bundleURL );	

		if ( !BundleRef ) {
		}

		if ( !CFBundleLoadExecutable( BundleRef ) )
		{
			CFRelease( BundleRef );
			BundleRef = NULL;
		}

		VSTMainFunc mainFunc = (VSTMainFunc)CFBundleGetFunctionPointerForName( 
					BundleRef, CFSTR("VSTPluginMain") );
		if (mainFunc == NULL) {
		}

		try {
			mpVSTEffect = mainFunc(audioMasterCallbackPlugIn);
			mpVSTEffect->dispatcher(mpVSTEffect, effOpen, 0, 0, 0, 0.0);
			mpVSTEffect->dispatcher(mpVSTEffect, effSetSampleRate, 0, 0, 0, 44100.0f);
			mpVSTEffect->dispatcher(mpVSTEffect, effSetBlockSize, 0, 32, 0, 0.0);
		}
		catch(...) {
			// Plug-in crashed
			mpVSTEffect = NULL;
		}
	}
#endif	// WIN32 / else
}
Пример #29
0
//
// Load management for a loadable bundle
//
void LoadableBundle::load()
{
	if (!CFBundleLoadExecutable(cfBundle()))
		CFError::throwMe();
    secdebug("bundle", "%p (%s) loaded", this, path().c_str());
}
Пример #30
0
/*ARGSUSED2*/
long KRB5_CALLCONV
krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct errinfo *ep)
{
    long err = 0;
    struct stat statbuf;
    struct plugin_file_handle *htmp = NULL;
    int got_plugin = 0;

    if (!err) {
        if (stat (filepath, &statbuf) < 0) {
            Tprintf ("stat(%s): %s\n", filepath, strerror (errno));
            err = errno;
        }
    }

    if (!err) {
        htmp = calloc (1, sizeof (*htmp)); /* calloc initializes ptrs to NULL */
        if (htmp == NULL) { err = errno; }
    }

#if USE_DLOPEN
    if (!err && (statbuf.st_mode & S_IFMT) == S_IFREG) {
        void *handle = NULL;
#ifdef RTLD_GROUP
#define PLUGIN_DLOPEN_FLAGS (RTLD_NOW | RTLD_LOCAL | RTLD_GROUP)
#else
#define PLUGIN_DLOPEN_FLAGS (RTLD_NOW | RTLD_LOCAL)
#endif

        if (!err) {
            handle = dlopen(filepath, PLUGIN_DLOPEN_FLAGS);
            if (handle == NULL) {
                const char *e = dlerror();
                Tprintf ("dlopen(%s): %s\n", filepath, e);
                err = ENOENT; /* XXX */
		krb5int_set_error (ep, err, "%s", e);
            }
        }

        if (!err) {
            got_plugin = 1;
            htmp->dlhandle = handle;
            handle = NULL;
        }

        if (handle != NULL) { dlclose (handle); }
    }
#endif

#if USE_CFBUNDLE
    if (!err && (statbuf.st_mode & S_IFMT) == S_IFDIR) {
        CFStringRef pluginPath = NULL;
        CFURLRef pluginURL = NULL;
        CFBundleRef pluginBundle = NULL;

        if (!err) {
            pluginPath = CFStringCreateWithCString (kCFAllocatorDefault, filepath, 
                                                    kCFStringEncodingASCII);
            if (pluginPath == NULL) { err = ENOMEM; }
        }
        
        if (!err) {
            pluginURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, pluginPath, 
                                                       kCFURLPOSIXPathStyle, true);
            if (pluginURL == NULL) { err = ENOMEM; }
        }
        
        if (!err) {
            pluginBundle = CFBundleCreate (kCFAllocatorDefault, pluginURL);
            if (pluginBundle == NULL) { err = ENOENT; } /* XXX need better error */
        }
        
        if (!err) {
            if (!CFBundleIsExecutableLoaded (pluginBundle)) {
                int loaded = CFBundleLoadExecutable (pluginBundle);
                if (!loaded) { err = ENOENT; }  /* XXX need better error */
            }
        }
        
        if (!err) {
            got_plugin = 1;
            htmp->bundle = pluginBundle;
            pluginBundle = NULL;  /* htmp->bundle takes ownership */
        }

        if (pluginBundle != NULL) { CFRelease (pluginBundle); }
        if (pluginURL    != NULL) { CFRelease (pluginURL); }
        if (pluginPath   != NULL) { CFRelease (pluginPath); }
    }
#endif
        
    if (!err && !got_plugin) {
        err = ENOENT;  /* no plugin or no way to load plugins */
    }
    
    if (!err) {
        *h = htmp;
        htmp = NULL;  /* h takes ownership */
    }
    
    if (htmp != NULL) { free (htmp); }
    
    return err;
}