Пример #1
0
bool ImageSource::frameHasAlphaAtIndex(size_t index)
{
    if (!m_decoder)
        return false; // FIXME: why doesn't this return true?

    if (!frameIsCompleteAtIndex(index))
        return true;

    CFStringRef imageType = CGImageSourceGetType(m_decoder);

    // Return false if there is no image type or the image type is JPEG, because
    // JPEG does not support alpha transparency.
    if (!imageType || CFEqual(imageType, CFSTR("public.jpeg")))
        return false;

    // FIXME: Could return false for other non-transparent image formats.
    // FIXME: Could maybe return false for a GIF Frame if we have enough info in the GIF properties dictionary
    // to determine whether or not a transparent color was defined.
    return true;
}
Пример #2
0
// -----------------------------------------------------------------------------
//	FLACMDImporterPluginFactory
// -----------------------------------------------------------------------------
//	Implementation of the factory function for this type.
//
void *MetadataImporterPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID)
{

#pragma unused(allocator)

    MetadataImporterPluginType *result;
    CFUUIDRef                 uuid;

    /* If correct type is being requested, allocate an
     * instance of TestType and return the IUnknown interface.
     */
    if (CFEqual(typeID,kMDImporterTypeID)) {
        uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID));
        result = AllocMetadataImporterPluginType(uuid);
        CFRelease(uuid);
        return result;
    }
    /* If the requested type is incorrect, return NULL. */
    return NULL;
}
Пример #3
0
static void
updateStore(const void *key, const void *value, void *context)
{
	CFDictionaryRef dict;
	CFDictionaryRef newDict = (CFDictionaryRef)value;
	CFDictionaryRef	oldIFs	= (CFDictionaryRef)context;

	dict = CFDictionaryGetValue(oldIFs, key);

	if (!dict || !CFEqual(dict, newDict)) {
		if (CFDictionaryGetCount(newDict) > 0) {
			cache_SCDynamicStoreSetValue(store, key, newDict);
		} else if (dict) {
			cache_SCDynamicStoreRemoveValue(store, key);
		}
		network_changed = TRUE;
	}

	return;
}
Пример #4
0
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl)
{
    // loop through the list of startup items and try to find the bitcoin app
    CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, NULL);
    for(int i = 0; i < CFArrayGetCount(listSnapshot); i++) {
        LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(listSnapshot, i);
        UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
        CFURLRef currentItemURL = NULL;
        LSSharedFileListItemResolve(item, resolutionFlags, &currentItemURL, NULL);
        if(currentItemURL && CFEqual(currentItemURL, findUrl)) {
            // found
            CFRelease(currentItemURL);
            return item;
        }
        if(currentItemURL) {
            CFRelease(currentItemURL);
        }
    }
    return NULL;
}
HRESULT IOHIDTransactionClass::queryInterface(REFIID iid, void ** ppv)
{
    CFUUIDRef uuid = CFUUIDCreateFromUUIDBytes(NULL, iid);
    HRESULT res = S_OK;

    if (CFEqual(uuid, kIOHIDDeviceTransactionInterfaceID))
    {
        *ppv = getInterfaceMap();
        addRef();
    }
    else {
        res = fOwningDevice->queryInterface(iid, ppv);
    }

    if (!*ppv)
        res = E_NOINTERFACE;

    CFRelease(uuid);
    return res;
}
Пример #6
0
static Boolean SecKeyEqual(CFTypeRef cf1, CFTypeRef cf2)
{
    SecKeyRef key1 = (SecKeyRef)cf1;
    SecKeyRef key2 = (SecKeyRef)cf2;
    if (key1 == key2)
        return true;
    if (!key2 || key1->key_class != key2->key_class)
        return false;
    if (key1->key_class->extraBytes)
        return !memcmp(key1->key, key2->key, key1->key_class->extraBytes);
    
    /* TODO: Won't work when we get reference keys. */
    CFDictionaryRef d1, d2;
    d1 = SecKeyCopyAttributeDictionary(key1);
    d2 = SecKeyCopyAttributeDictionary(key2);
    Boolean result = CFEqual(d1, d2);
    CFReleaseSafe(d1);
    CFReleaseSafe(d2);
    return result;
}
static CFPropertyListRef dataCopyProperty(struct _CFStream *stream, CFStringRef propertyName, void *info) {
    _CFWriteDataStreamContext *dataStream = (_CFWriteDataStreamContext *)info;
    CFIndex size = 0;
    _CFStreamByteBuffer *buf;
    CFAllocatorRef alloc;
    UInt8 *bytes, *currByte;
    if (!CFEqual(propertyName, kCFStreamPropertyDataWritten)) return NULL;
    if (dataStream->bufferAllocator == kCFAllocatorNull)  return NULL;
    alloc = dataStream->bufferAllocator;
    for (buf = dataStream->firstBuf; buf != NULL; buf = buf->next) {
        size += buf->length;
    }
    bytes = (UInt8 *)CFAllocatorAllocate(alloc, size, 0);
    currByte = bytes;
    for (buf = dataStream->firstBuf; buf != NULL; buf = buf->next) {
        memmove(currByte, buf->bytes, buf->length);
        currByte += buf->length;
    }
    return CFDataCreateWithBytesNoCopy(alloc, bytes, size, alloc);
}
Пример #8
0
static RetainPtr<CGImageRef> imageWithColorSpace(CGImageRef originalImage, ColorSpace colorSpace)
{
    CGColorSpaceRef originalColorSpace = CGImageGetColorSpace(originalImage);

    // If the image already has a (non-device) color space, we don't want to
    // override it, so return.
    if (!originalColorSpace || !CFEqual(originalColorSpace, deviceRGBColorSpaceRef()))
        return originalImage;

    switch (colorSpace) {
    case DeviceColorSpace:
        return originalImage;
    case sRGBColorSpace:
        return RetainPtr<CGImageRef>(AdoptCF, CGImageCreateCopyWithColorSpace(originalImage, 
            sRGBColorSpaceRef()));
    }

    ASSERT_NOT_REACHED();
    return originalImage;
}
static void writeXMLValue(CFTypeRef context, void *xmlDomain, CFStringRef key, CFTypeRef value) {
    _CFXMLPreferencesDomain *domain = (_CFXMLPreferencesDomain *)xmlDomain;
    const void *existing = NULL;

    __CFLock(&domain->_lock);
    if (domain->_domainDict == NULL) {
        _loadXMLDomainIfStale((CFURLRef )context, domain);
    }

	// check to see if the value is the same
	// if (1) the key is present AND value is !NULL and equal to existing, do nothing, or
	// if (2) the key is not present AND value is NULL, do nothing
	// these things are no-ops, and should not dirty the domain
    if (CFDictionaryGetValueIfPresent(domain->_domainDict, key, &existing)) {
	if (NULL != value && (existing == value || CFEqual(existing, value))) {
	    __CFUnlock(&domain->_lock);
	    return;
	}
    } else {
	if (NULL == value) {
	    __CFUnlock(&domain->_lock);
	    return;
	}
    }

	// We must append first so key gets another retain (in case we're
	// about to remove it from the dictionary, and that's the sole reference)
    // This should be a set not an array.
    if (!CFArrayContainsValue(domain->_dirtyKeys, CFRangeMake(0, CFArrayGetCount(domain->_dirtyKeys)), key)) {
	CFArrayAppendValue(domain->_dirtyKeys, key);
    }
    if (value) {
        // Must copy for two reasons - we don't want mutable objects in the cache, and we don't want objects allocated from a different allocator in the cache.
        CFTypeRef newValue = CFPropertyListCreateDeepCopy(__CFPreferencesAllocator(), value, kCFPropertyListImmutable);
        CFDictionarySetValue(domain->_domainDict, key, newValue);
        CFRelease(newValue);
    } else {
        CFDictionaryRemoveValue(domain->_domainDict, key);
    }
    __CFUnlock(&domain->_lock);
}
Пример #10
0
NativeImagePtr ImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel, DecodingMode decodingMode) const
{
    LOG(Images, "ImageDecoder %p createFrameImageAtIndex %lu", this, index);

    RetainPtr<CFDictionaryRef> options = imageSourceOptions(subsamplingLevel, decodingMode);
    RetainPtr<CGImageRef> image;

    if (decodingMode == DecodingMode::OnDemand)
        image = adoptCF(CGImageSourceCreateImageAtIndex(m_nativeDecoder.get(), index, options.get()));
    else
        image = adoptCF(CGImageSourceCreateThumbnailAtIndex(m_nativeDecoder.get(), index, options.get()));
    
#if PLATFORM(IOS)
    // <rdar://problem/7371198> - CoreGraphics changed the default caching behaviour in iOS 4.0 to kCGImageCachingTransient
    // which caused a performance regression for us since the images had to be resampled/recreated every time we called
    // CGContextDrawImage. We now tell CG to cache the drawn images. See also <rdar://problem/14366755> -
    // CoreGraphics needs to un-deprecate kCGImageCachingTemporary since it's still not the default.
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
    CGImageSetCachingFlags(image.get(), kCGImageCachingTemporary);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
#endif // PLATFORM(IOS)
    
    CFStringRef imageUTI = CGImageSourceGetType(m_nativeDecoder.get());
    static const CFStringRef xbmUTI = CFSTR("public.xbitmap-image");
    
    if (!imageUTI)
        return image;
    
    if (!CFEqual(imageUTI, xbmUTI))
        return image;
    
    // If it is an xbm image, mask out all the white areas to render them transparent.
    const CGFloat maskingColors[6] = {255, 255,  255, 255, 255, 255};
    RetainPtr<CGImageRef> maskedImage = adoptCF(CGImageCreateWithMaskingColors(image.get(), maskingColors));
    return maskedImage ? maskedImage : image;
}
Пример #11
0
/*
 * Function: EAPOLClientConfigurationGetSystemProfile
 *
 * Purpose:
 *   Return the profile configured for System mode on the
 *   specified BSD network interface (e.g. "en0", "en1").
 *
 * Returns:
 *   NULL if no such profile is defined, non-NULL profile
 *   otherwise.
 */
EAPOLClientProfileRef
EAPOLClientConfigurationGetSystemProfile(EAPOLClientConfigurationRef cfg,
					 CFStringRef if_name)
{
    CFDictionaryRef		dict;
    SCNetworkInterfaceRef 	net_if = NULL;
    EAPOLClientProfileRef	profile = NULL;
    CFStringRef			profileID;

    dict = get_eapol_configuration(get_sc_prefs(cfg), if_name, &net_if);
    if (dict != NULL
	&& !CFEqual(SCNetworkInterfaceGetInterfaceType(net_if),
		    kSCNetworkInterfaceTypeIEEE80211)) {
	profileID = CFDictionaryGetValue(dict, kSystemProfileID);
	if (isA_CFString(profileID) != NULL) {
	    profile = EAPOLClientConfigurationGetProfileWithID(cfg, profileID);
	}
    }
    my_CFRelease(&net_if);
    return (profile);
}
Пример #12
0
/*
	druDeviceContainsErasableMedia
	
	Returns TRUE if the device contains blank media.
*/
int
druDeviceContainsErasableMedia(DRDeviceRef device)
{
	CFDictionaryRef		deviceStatus = DRDeviceCopyStatus(device);
	CFStringRef			mediaState = CFDictionaryGetValue(deviceStatus,kDRDeviceMediaStateKey);
	int					result = 0;
	
	/* Check to see if there's media in the device */
	if (mediaState != NULL && CFEqual(mediaState,kDRDeviceMediaStateMediaPresent))
	{
		CFDictionaryRef	mediaInfo = CFDictionaryGetValue(deviceStatus,kDRDeviceMediaInfoKey);
		CFBooleanRef	erasable = CFDictionaryGetValue(mediaInfo,kDRDeviceMediaIsErasableKey);
		
		/* There's media, but is it blank and writable? */
		if (erasable != NULL && CFBooleanGetValue(erasable))
			result = 1;
	}
	
	CFRelease(deviceStatus);
	return result;
}
Пример #13
0
static CFArrayRef SecCAIssuerRequestCacheCopyParents(SecCertificateRef cert,
    CFArrayRef issuers) {
    CFIndex ix = 0, ex = CFArrayGetCount(issuers);
    for (;ix < ex; ++ix) {
        CFURLRef issuer = CFArrayGetValueAtIndex(issuers, ix);
        CFStringRef scheme = CFURLCopyScheme(issuer);
        if (scheme) {
            if (CFEqual(CFSTR("http"), scheme)) {
                CFArrayRef parents = SecCAIssuerConvertToParents(cert,
                    SecCAIssuerCacheCopyMatching(issuer));
                if (parents) {
                    secdebug("caissuer", "cache hit, for %@ no request issued", issuer);
		    CFRelease(scheme);
                    return parents;
                }
            }
            CFRelease(scheme);
        }
    }
    return NULL;
}
Пример #14
0
/*
	druMediaIsReserved
	
	Returns TRUE if the device contains blank media.
*/
int
druMediaIsReserved(DRDeviceRef device)
{
	CFDictionaryRef		deviceStatus = DRDeviceCopyStatus(device);
	CFStringRef			mediaState = CFDictionaryGetValue(deviceStatus,kDRDeviceMediaStateKey);
	int					result = 0;
	
	/* Check to see if there's media in the device */
	if (mediaState != NULL && CFEqual(mediaState,kDRDeviceMediaStateMediaPresent))
	{
		CFDictionaryRef	mediaInfo = CFDictionaryGetValue(deviceStatus,kDRDeviceMediaInfoKey);
		CFBooleanRef	reserved = CFDictionaryGetValue(mediaInfo,kDRDeviceMediaIsReservedKey);
		
		/* There's media, but do we have the reservation? */
		if (reserved != NULL && CFBooleanGetValue(reserved))
			result = 1;
	}
	
	CFRelease(deviceStatus);
	return result;
}
Пример #15
0
void RemoveEventFromArray(CFMutableArrayRef array, CFNumberRef launchdToken)
{
	CFIndex i;
	CFIndex count = CFArrayGetCount(array);
	// Loop thru looking for us.
	for (i = 0; i < count; )
	{
		CFDictionaryRef eventDict = CFArrayGetValueAtIndex(array, i);
		CFNumberRef token = CFDictionaryGetValue(eventDict, sLaunchdTokenKey);
		
		if (CFEqual(token, launchdToken)) // This is the same event?
		{
			CFArrayRemoveValueAtIndex(array, i);	// Remove the event,
			break; // The token should only exist once, so it make no sense to continue.
		}
		else
		{
			++i; // If it's not us, advance.
		}
	}	
}
Пример #16
0
CF_EXPORT CFURLRef CFCopyHomeDirectoryURLForUser(CFStringRef uName) {
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
    if (!uName) {
        uid_t euid;
        __CFGetUGIDs(&euid, NULL);
        struct passwd *upwd = getpwuid(euid ? euid : getuid());
        return _CFCopyHomeDirURLForUser(upwd, true);
    } else {
        struct passwd *upwd = NULL;
        char buf[128], *user;
        SInt32 len = CFStringGetLength(uName), size = CFStringGetMaximumSizeForEncoding(len, kCFPlatformInterfaceStringEncoding);
        CFIndex usedSize;
        if (size < 127) {
            user = buf;
        } else {
            user = CFAllocatorAllocate(kCFAllocatorSystemDefault, size+1, 0);
        }
        if (CFStringGetBytes(uName, CFRangeMake(0, len), kCFPlatformInterfaceStringEncoding, 0, true, (uint8_t *)user, size, &usedSize) == len) {
            user[usedSize] = '\0';
            upwd = getpwnam(user);
        }
        if (buf != user) {
            CFAllocatorDeallocate(kCFAllocatorSystemDefault, user);
        }
        return _CFCopyHomeDirURLForUser(upwd, false);
    }
#elif DEPLOYMENT_TARGET_WINDOWS
    // This code can only get the directory for the current user
    CFStringRef userName = uName ? CFCopyUserName() : NULL;
    if (uName && !CFEqual(uName, userName)) {
        CFLog(kCFLogLevelError, CFSTR("CFCopyHomeDirectoryURLForUser(): Unable to get home directory for other user"));
        if (userName) CFRelease(userName);
        return NULL;
    }
    if (userName) CFRelease(userName);
    return CFCopyHomeDirectoryURL();
#else
#error Dont know how to compute users home directories on this platform
#endif
}
Пример #17
0
AFPUserRef
AFPUserList_lookup(AFPUserListRef users, CFStringRef afp_user)
{
    int		i;
    int		n;

    n = CFArrayGetCount(users->list);
    for (i = 0; i < n; i++) {
	CFStringRef	name;
	AFPUserRef	user;
	ODRecordRef	record;

	user = (AFPUserRef)CFArrayGetValueAtIndex(users->list, i);
	record = (ODRecordRef)CFDictionaryGetValue(user, kAFPUserODRecord);
	name = ODRecordGetRecordName(record);
	if (CFEqual(name, afp_user)) {
		return (user);
	}
    }

    return (NULL);
}
Пример #18
0
static void
updateStore(const void *key, const void *value, void *context)
{
	CFDictionaryRef dict;
	CFDictionaryRef newDict = (CFDictionaryRef)value;
	CFDictionaryRef	oldIFs	= (CFDictionaryRef)context;

	dict = CFDictionaryGetValue(oldIFs, key);

	if (!dict || !CFEqual(dict, newDict)) {
		if (CFDictionaryGetCount(newDict) > 0) {
			SC_log(LOG_DEBUG, "Update interface configuration: %@: %@", key, newDict);
			cache_SCDynamicStoreSetValue(store, key, newDict);
		} else if (dict) {
			SC_log(LOG_DEBUG, "Update interface configuration: %@: <removed>", key);
			cache_SCDynamicStoreRemoveValue(store, key);
		}
		network_changed = TRUE;
	}

	return;
}
HRESULT STDMETHODCALLTYPE IBMDSwitcherDiscovery::QueryInterface(REFIID riid, LPVOID *ppv)
{
  if (!ppv)
    return E_POINTER;
  
  if (riid == IID_IBMDSwitcherDiscovery)
  {
    *ppv = static_cast<IBMDSwitcherDiscovery*>(this);
    AddRef();
    return S_OK;
  }

  if (CFEqual(CFUUIDCreateFromUUIDBytes(NULL,riid), IUnknownUUID))
  {
    *ppv = static_cast<IUnknown*>(this);
    AddRef();
    return S_OK;
  }

  *ppv = NULL;
  return E_NOINTERFACE;
}
Пример #20
0
// -----------------------------------------------------------------------------
//  QuickLookGeneratorPluginFactory
// -----------------------------------------------------------------------------
void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID)
{
    QuickLookGeneratorPluginType *result;
    CFUUIDRef                 uuid;

        /* If correct type is being requested, allocate an
         * instance of kQLGeneratorTypeID and return the IUnknown interface.
         */
    if (CFEqual(typeID,kQLGeneratorTypeID)){
        uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID));
        result = AllocQuickLookGeneratorPluginType(uuid);
        CFRelease(uuid);
        return result;
    }
	
	allocator = NULL;
        /* If the requested type is incorrect, return NULL. */
	
	/* Fixes a warning at compile time */
	allocator = NULL;
    return NULL;
}
Пример #21
0
__private_extern__ bool
GetPMSettingBool(CFStringRef which)
{
    CFDictionaryRef     current_settings; 
    CFNumberRef         n;
    int                 nint = 0;
    CFStringRef         pwrSrc;
    
    if (!energySettings || !which) 
        return false;

    if (CFEqual(which, CFSTR(kIOPMDarkWakeBackgroundTaskKey))) {
        /* Overrides for DWBT support */
        if (gSilentRunningOverride == kPMSROverrideEnable)
            return true;
        if (gSilentRunningOverride == kPMSROverrideDisable)
            return false;
    }
    
    if (_getPowerSource() == kBatteryPowered)
       pwrSrc = CFSTR(kIOPMBatteryPowerKey);
    else
       pwrSrc = CFSTR(kIOPMACPowerKey);
    // Don't use 'currentPowerSource' here as that gets updated
    // little slowly after this function is called to get a setting
    // on new power source.
    current_settings = (CFDictionaryRef)isA_CFDictionary(
                         CFDictionaryGetValue(energySettings, pwrSrc));

    if (current_settings) {
        n = CFDictionaryGetValue(current_settings, which);
        if (n) {
            CFNumberGetValue(n, kCFNumberIntType, &nint);
        }
        return (0 != nint);
    }
    return false;
}
static void test_persistent2(struct test_persistent_s *p)
{
    CFTypeRef results = NULL;
    CFTypeRef results2 = NULL;

    ok_status(!SecItemCopyMatching(p->query, &results),
        "don't find internet password by attributes");
    ok(!results, "no results");

    ok_status(!SecItemCopyMatching(p->query2, &results2),
        "don't find internet password by persistent ref anymore");
    ok(!results2, "no results");

    SKIP:{
        ok_status(SecItemCopyMatching(p->query4, &results2), "find non updated internet password by persistent ref");
        skip("non updated internet password by persistent ref NOT FOUND!", 2, results2);
        ok(results2, "non updated internet password not found");
        CFStringRef server = CFDictionaryGetValue(results2, kSecAttrServer);
        ok(CFEqual(server, CFSTR("zuigt.nl")), "verify second items attribute was not modified by update");
        CFReleaseNull(results2);
    }

    is_status(SecItemCopyMatching(p->query3, &results2), errSecItemNotFound,
        "don't find deleted internet password by persistent ref");
    CFReleaseNull(results2);
    ok_status(SecItemCopyMatching(p->query4, &results2),
        "find non deleted internet password by persistent ref");
    CFReleaseNull(results2);

    ok_status(SecItemDelete(p->query4),"Deleted internet password by persistent ref");

    CFRelease(p->query);
    CFRelease(p->query2);
    CFRelease(p->query3);
    CFRelease(p->query4);
    CFReleaseNull(p->persist[0]);
    CFReleaseNull(p->persist[1]);
}
/* IOPSCopyInternalBatteriesArray
 *
 * Argument: 
 *	CFTypeRef power_sources: The return value from IOPSCoyPowerSourcesInfo()
 * Return value:
 * 	CFArrayRef: all the batteries we found
 *			NULL if none are found
 */
CFArrayRef
IOPSCopyInternalBatteriesArray(CFTypeRef power_sources)
{
    CFArrayRef			array = isA_CFArray(IOPSCopyPowerSourcesList(power_sources));
    CFMutableArrayRef   ret_arr;
    CFTypeRef			name = NULL;
    CFDictionaryRef		ps;
    CFStringRef			transport_type;
    int				    i, count;

    if(!array) return NULL;
    count = CFArrayGetCount(array);
    name = NULL;

    ret_arr = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
    if(!ret_arr) goto exit;

    for(i=0; i<count; i++) {
        name = CFArrayGetValueAtIndex(array, i);
        ps = isA_CFDictionary(IOPSGetPowerSourceDescription(power_sources, name));
        if(ps) {
            transport_type = isA_CFString(CFDictionaryGetValue(ps, CFSTR(kIOPSTransportTypeKey)));
            if(transport_type && CFEqual(transport_type, CFSTR(kIOPSInternalType)))
            {
                CFArrayAppendValue(ret_arr, name);
            }
        }
    }

    if(0 == CFArrayGetCount(ret_arr)) {
        CFRelease(ret_arr);
        ret_arr = NULL;
    }

exit:
    CFRelease(array);
    return ret_arr;
}
Пример #24
0
/* =============================================================================

    Name:	PrintDialogPDEPluginFactory()

    Description:
		This is the factory function which should be the only entry point of
		this plugin. This factory function creates the "base class" for the system.
		The factory functions name (ie "PrintDialogPDEPluginFactory") needs to be
		listed in the Info.plist to associate the factory function name
		with the factory function UUID. For example, this is how this function
		is associated with the UUID in the Info.plist file.

		CFPlugInFactories =
		{
       	 	"DFC01D58-0C4A-11D5-BB77-003065500EB8" = "PrintDialogPDEPluginFactory";
    	};

    Input Parameters:
        allocator	- the allocator function used by CoreFoundation
        reqTypeID	- requested instance type.

    Output Parameters:
        None.

    Return Value:


 * ========================================================================== */
void* PrintDialogPDEPluginFactory( CFAllocatorRef allocator, CFUUIDRef reqTypeID )
{
    CFUUIDRef			myInstID;
    IUnknownInstance*	instance = NULL;

    // There is not much we can do with errors - just return NULL.
    myInstID = CFUUIDCreateFromString(kCFAllocatorDefault, kAppPrintDialogTypeIDStr);
    // If the requested type matches our plugin type (it should!)
    // have a plugin instance created which will query us for
    // interfaces:
    if (myInstID && CFEqual(reqTypeID, myInstID))
    {
        CFUUIDRef myFactoryID = CFUUIDCreateFromString(kCFAllocatorDefault, kPrintDialogPDEIntfFactoryIDStr);
        if(myFactoryID) {
            // allocate and clear our instance structure
            instance = (IUnknownInstance*) calloc(1, sizeof(IUnknownInstance));
            if (instance != NULL)
            {
                // Assign all members:
                instance->vtable = &instance->vtableStorage;

                instance->vtableStorage.QueryInterface = IUnknownQueryInterface;
                instance->vtableStorage.AddRef = IUnknownAddRef;
                instance->vtableStorage.Release = IUnknownRelease;

                instance->factoryID = myFactoryID;
                instance->refCount = 1;

                // Register the newly created instance
                CFPlugInAddInstanceForFactory(myFactoryID);
            }
        }
    }
    if(myInstID)
        CFRelease(myInstID);

    return ((void*) instance);
}
Пример #25
0
/*****************************************************************************
 * HandleStateEventsForService
 * - 
 * This method handles the toggling the state of a while exists event to 
 * reflect the network. 
 *****************************************************************************/
void HandleStateEventsForService(BonjourUserEventsPlugin* plugin, NetBrowserInfo* browser, CFStringRef serviceName, Boolean didAppear)
{
	CFArrayRef events = (CFArrayRef)CFDictionaryGetValue(plugin->_whileServiceExist, browser); // Get the _whileServiceExist events that are interested in this browser.
	CFIndex i;
	CFIndex count;
	
	if (!events)  // Somehow we have a orphan browser...
		return;
	
	count = CFArrayGetCount(events);
	
	// Go thru the events and run filters, notifity if they pass.
	for (i = 0; i < count; ++i)
	{
		CFDictionaryRef eventDict = (CFDictionaryRef)CFArrayGetValueAtIndex(events, i);
		CFStringRef eventServiceName = (CFStringRef)CFDictionaryGetValue(eventDict, sServiceNameKey);
		CFNumberRef token = (CFNumberRef) CFDictionaryGetValue(eventDict, sLaunchdTokenKey);
		
		// Currently we only filter on service name, that makes this as simple as... 
		if (!eventServiceName || CFEqual(serviceName, eventServiceName))
			UserEventAgentSetLaunchEventState(plugin->_pluginContext, token, didAppear);
	}
}
Пример #26
0
void SFB::Audio::AttachedPicture::SetValue(CFStringRef key, CFTypeRef value)
{
	if(nullptr == key)
		return;

	if(nullptr == value) {
		if(CFDictionaryContainsKey(mMetadata, key))
			CFDictionarySetValue(mChangedMetadata, key, kCFNull);
		else
			CFDictionaryRemoveValue(mChangedMetadata, key);
	}
	else {
		if(CFDictionaryContainsKey(mChangedMetadata, key)) {
			CFTypeRef savedValue = CFDictionaryGetValue(mMetadata, key);
			if(nullptr != savedValue && CFEqual(savedValue, value))
				CFDictionaryRemoveValue(mChangedMetadata, key);
			else
				CFDictionarySetValue(mChangedMetadata, key, value);
		}
		else
			CFDictionarySetValue(mChangedMetadata, key, value);
	}
}
Пример #27
0
    // Implementation of the factory function for this type.
    void *MyFactory(CFAllocatorRef allocator, CFUUIDRef typeID) {
        // If correct type is being requested, allocate an
        // instance of TestType and return the IUnknown interface.

        if (CFEqual(typeID, kAudioHardwarePlugInTypeID)) {
#if PRINTDEBUG
            printf("JAS: MyFactory kAudioHardwarePlugInTypeID\n");
#endif

#ifdef kAudioHardwarePlugInInterface2ID

            MyType *result = _allocMyType( kAudioHardwarePlugInInterface2ID );
#else

            MyType *result = _allocMyType( kAudioHardwarePlugInInterfaceID );
#endif

            return result;
        } else {
            // If the requested type is incorrect, return NULL.
            return NULL;
        }
    }
Пример #28
0
/* extern */ Boolean
_SchedulesRemoveRunLoopAndMode(CFMutableArrayRef schedules, CFRunLoopRef runLoop, CFStringRef runLoopMode) {

	/* Get the number of items in schedules and create a range for searching */
    CFIndex count = CFArrayGetCount(schedules);
    CFRange range = CFRangeMake(0, count);

	/* Go through the list looking for this schedule */
    while (range.length) {

		/* Find the run loop in the list */
        CFIndex i = CFArrayGetFirstIndexOfValue(schedules, range, runLoop);

		/* If the loop wasn't found, then this pair was never added. */
        if (i == kCFNotFound)
            break;

		/* If the mode is the same, this is already scheduled here so bail */
        if (CFEqual(CFArrayGetValueAtIndex(schedules, i + 1), runLoopMode)) {

			/* Remove the schedule from the list */
            range.location = i;
            range.length = 2;
            CFArrayReplaceValues(schedules, range, NULL, 0);

			/* Did remove the schedule from the list */
			return TRUE;
		}

		/* Continue looking from here */
		range.location = i + 2;
		range.length = count - range.location;
    }

	/* Did not remove the schedule from the list */
	return FALSE;
}
Пример #29
0
static void
__SCDynamicStoreInitialize(void)
{
	CFBundleRef	bundle;

	/* register with CoreFoundation */
	__kSCDynamicStoreTypeID = _CFRuntimeRegisterClass(&__SCDynamicStoreClass);

	/* add handler to cleanup after fork() */
	(void) pthread_atfork(NULL, NULL, childForkHandler);

	/* get the application/executable/bundle name */
	bundle = CFBundleGetMainBundle();
	if (bundle != NULL) {
		_sc_bundleID = CFBundleGetIdentifier(bundle);
		if (_sc_bundleID != NULL) {
			CFRetain(_sc_bundleID);
		} else {
			CFURLRef	url;

			url = CFBundleCopyExecutableURL(bundle);
			if (url != NULL) {
				_sc_bundleID = CFURLCopyPath(url);
				CFRelease(url);
			}
		}

		if (_sc_bundleID != NULL) {
			if (CFEqual(_sc_bundleID, CFSTR("/"))) {
				CFRelease(_sc_bundleID);
				_sc_bundleID = CFStringCreateWithFormat(NULL, NULL, CFSTR("(%d)"), getpid());
			}
		}
	}

	return;
}
/*
 * Map a filename and/or a BIFileType to a UTI string.
 */
static CFStringRef BIGetUTI(
	CFURLRef url,
	BIFileType fileType)
{
	switch(fileType) {
		case BI_FT_JPEG:
		case BI_FT_JPEG_Lossless:
			return kUTTypeJPEG;
		case BI_FT_TIFF:
			return kUTTypeTIFF;
		case BI_FT_JPEG2000:
		case BI_FT_JPEG2000_Lossless:
			return kUTTypeJPEG2000;
		case BI_FT_Default:
			/* figure it out from file extension */
			break;
		default:
			fprintf(stderr, "***BIGetUTI internal error\n");
			return NULL;
	}
	
	CFStringRef fileExt = CFURLCopyPathExtension(url);
	if(fileExt == NULL) {
		fprintf(stderr, "***BIGetUTI(BI_FT_Default) - no extension available\n");
		return NULL;
	}
	
	for(unsigned mapDex=0; mapDex<NUM_UTI_MAPS; mapDex++) {
		const UTIMap *map = &utiMap[mapDex];
		if(CFEqual(fileExt, map->exten)) {
			return map->uti;
		}
	}

	fprintf(stderr, "***BIGetUTI(BI_FT_Default) - unknown extension\n");
	return NULL;
}