Пример #1
0
CFStringRef CFLocaleCopyDisplayNameForPropertyValue(CFLocaleRef displayLocale, CFStringRef key, CFStringRef value) {
    CF_OBJC_FUNCDISPATCH2(CFLocaleGetTypeID(), CFStringRef, displayLocale, "_copyDisplayNameForKey:value:", key, value);
    CFIndex idx, slot = -1;
    for (idx = 0; idx < __kCFLocaleKeyTableCount; idx++) {
	if (__CFLocaleKeyTable[idx].key == key) {
	    slot = idx;
	    break;
	}
    }
    if (-1 == slot && NULL != key) {
	for (idx = 0; idx < __kCFLocaleKeyTableCount; idx++) {
	    if (CFEqual(__CFLocaleKeyTable[idx].key, key)) {
		slot = idx;
		break;
	    }
	}
    }
    if (-1 == slot || !value) {
	return NULL;
    }
    // Get the locale ID as a C string
    char localeID[ULOC_FULLNAME_CAPACITY+ULOC_KEYWORD_AND_VALUES_CAPACITY];
    char cValue[ULOC_FULLNAME_CAPACITY+ULOC_KEYWORD_AND_VALUES_CAPACITY];
    if (CFStringGetCString(displayLocale->_identifier, localeID, sizeof(localeID)/sizeof(localeID[0]), kCFStringEncodingASCII) && CFStringGetCString(value, cValue, sizeof(cValue)/sizeof(char), kCFStringEncodingASCII)) {
        CFStringRef result;
        if ((NULL == displayLocale->_prefs) && __CFLocaleKeyTable[slot].name(localeID, cValue, &result)) {
            return result;
        }

        // We could not find a result using the requested language. Fall back through all preferred languages.
        CFArrayRef langPref;
	if (displayLocale->_prefs) {
	    langPref = (CFArrayRef)CFDictionaryGetValue(displayLocale->_prefs, CFSTR("AppleLanguages"));
	    if (langPref) CFRetain(langPref);
	} else {
	    langPref = (CFArrayRef)CFPreferencesCopyAppValue(CFSTR("AppleLanguages"), kCFPreferencesCurrentApplication);
	}
        if (langPref != NULL) {
            CFIndex count = CFArrayGetCount(langPref);
            CFIndex i;
            bool success = false;
            for (i = 0; i < count && !success; ++i) {
                CFStringRef language = (CFStringRef)CFArrayGetValueAtIndex(langPref, i);
                CFStringRef cleanLanguage = CFLocaleCreateCanonicalLanguageIdentifierFromString(kCFAllocatorSystemDefault, language);
                if (CFStringGetCString(cleanLanguage, localeID, sizeof(localeID)/sizeof(localeID[0]), kCFStringEncodingASCII)) {
                    success = __CFLocaleKeyTable[slot].name(localeID, cValue, &result);
		}
                CFRelease(cleanLanguage);
            }
	    CFRelease(langPref);
            if (success)
                return result;
        }
    }
    return NULL;
}
Пример #2
0
int useWhitelist() {
    CFArrayRef    prefCFArrayRef = CFPreferencesCopyAppValue( CFStringCreateWithCString(NULL, "whitelist", kCFStringEncodingASCII), kAppCFStr);

    if (NULL == prefCFArrayRef)
        return 0;

    CFRelease(prefCFArrayRef);
    return 1;

}
Пример #3
0
//============================================================================
//		NTargetPreferences::HasKey : Does a key exist?
//----------------------------------------------------------------------------
bool NTargetPreferences::HasKey(const NString &theKey)
{	NCFObject		cfObject;
	bool			hasKey;



	// Check the key
	hasKey = cfObject.SetObject(CFPreferencesCopyAppValue(ToCF(theKey), kCFPreferencesCurrentApplication));
	
	return(hasKey);
}
Пример #4
0
static void
init_log(void)
{
    static dispatch_once_t once = 0;
    dispatch_once(&once, ^{
	    CFBooleanRef b;
	    b = CFPreferencesCopyAppValue(CFSTR("EnableDebugging"),
					  CFSTR("com.apple.MITKerberosShim"));
	    if (b && CFGetTypeID(b) == CFBooleanGetTypeID())
		do_log = CFBooleanGetValue(b);
    });
Пример #5
0
void LoadPrefs (void)
{
	CFMutableStringRef	mref;
	CFStringRef			sref;
	CFDataRef			data;

	for (unsigned int i = 0; i < kPrefListSize; i++)
	{
		mref = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, CFSTR("Preferences_"));
		if (mref)
		{
			sref = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8 *) &(prefList[i].itemName), sizeof(OSType), kCFStringEncodingMacRoman, false);
			if (sref)
			{
				CFStringAppend(mref, sref);

				data = (CFDataRef) CFPreferencesCopyAppValue(mref, kCFPreferencesCurrentApplication);
				if (data)
				{
					if (CFDataGetLength(data) == prefList[i].size)
						CFDataGetBytes(data, CFRangeMake(0, prefList[i].size), (UInt8 *) prefList[i].itemPointer);
					CFRelease(data);
				}

				CFRelease(sref);
			}

			CFRelease(mref);
		}
	}

	mref = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, CFSTR("Preferences_SaveFolder"));
	if (mref)
	{
		sref = (CFStringRef) CFPreferencesCopyAppValue(mref, kCFPreferencesCurrentApplication);
		if (sref)
			saveFolderPath = sref;

		CFRelease(mref);
	}
}
Пример #6
0
//============================================================================
//		NTargetPreferences::GetValue : Get a value.
//----------------------------------------------------------------------------
NVariant NTargetPreferences::GetValue(const NString &theKey)
{	NVariant		theValue;
	NCFObject		cfValue;



	// Get the value
	if (cfValue.SetObject(CFPreferencesCopyAppValue(ToCF(theKey), kCFPreferencesCurrentApplication)))
		theValue = NMacTarget::ConvertCFToObject(cfValue);
	
	return(theValue);
}
Пример #7
0
/*    eats it */
static int get_mac_x11_prop(char *keystr) {
    CFPropertyListRef ret;
    CFStringRef key, appID;
    int val;

    appID = CFStringCreateWithBytes(NULL,(uint8 *) "com.apple.x11",strlen("com.apple.x11"), kCFStringEncodingISOLatin1, 0);
    key   = CFStringCreateWithBytes(NULL,(uint8 *) keystr,strlen(keystr), kCFStringEncodingISOLatin1, 0);
    ret = CFPreferencesCopyAppValue(key,appID);
    if ( ret==NULL ) {
	/* Sigh. Apple uses a different preference file under 10.5.6 I really */
	/*  wish they'd stop making stupid, unnecessary changes */
	appID = CFStringCreateWithBytes(NULL,(uint8 *) "org.x.X11",strlen("org.x.X11"), kCFStringEncodingISOLatin1, 0);
	ret = CFPreferencesCopyAppValue(key,appID);
    }
    if ( ret==NULL )
return( -1 );
    if ( CFGetTypeID(ret)!=CFBooleanGetTypeID())
return( -2 );
    val = CFBooleanGetValue(ret);
    CFRelease(ret);
return( val );
}
Пример #8
0
std::string
Moose::applicationPath()
{
    CFStringRef path = (CFStringRef) CFPreferencesCopyAppValue(
            CFSTR( "Path" ),
            CFSTR( MOOSE_PREFS_PLIST ) );

    if ( path == NULL )
        return "/Applications/Last.fm.app/Contents/MacOS/Last.fm";

    std::string s = CFStringToStdString( path );
    CFRelease( path );
    return s;
}
Пример #9
0
static void MacQTOpenVideoComponent(ComponentInstance *rci)
{	
	OSStatus			err;
	ComponentInstance	ci;
	
	ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
	CheckError((ci == nil), 01);
	
	CFDataRef	data;

	data = (CFDataRef) CFPreferencesCopyAppValue(CFSTR("QTVideoSetting"), kCFPreferencesCurrentApplication);
	if (data)
	{
		CFIndex	len;
		Handle	hdl;
		
		len = CFDataGetLength(data);
		hdl = NewHandleClear((Size) len);
		if (MemError() == noErr)
		{	
			HLock(hdl);
			CFDataGetBytes(data, CFRangeMake(0, len), (unsigned char *) *hdl);
			err = SCSetInfo(ci, scSettingsStateType, &hdl);
		
			DisposeHandle(hdl);
		}

		CFRelease(data);
	}
	else
	{
		SCSpatialSettings	ss;
		SCTemporalSettings	ts;
		
		ss.codecType       = kAnimationCodecType;
		ss.codec           = 0;
		ss.depth           = 16;
		ss.spatialQuality  = codecMaxQuality;
		err = SCSetInfo(ci, scSpatialSettingsType, &ss);
		
		ts.frameRate       = FixRatio(Memory.ROMFramesPerSecond, 1);
		ts.keyFrameRate    = Memory.ROMFramesPerSecond;
		ts.temporalQuality = codecMaxQuality;
		err = SCSetInfo(ci, scTemporalSettingsType, &ts);
	}

	*rci = ci;
}
CF_EXPORT Boolean CFPreferencesAppBooleanValue(CFStringRef key, CFStringRef appName, Boolean *keyExistsAndHasValidFormat) {
    CFPropertyListRef value;
    Boolean result, valid;
    CFTypeID typeID = 0;
    CFAssert1(appName != NULL, __kCFLogAssertion, "%s(): Cannot access application preferences with a NULL application name", __PRETTY_FUNCTION__);
    CFAssert1(key != NULL, __kCFLogAssertion, "%s(): Cannot access preferences with a NULL key", __PRETTY_FUNCTION__);

    if (!keyExistsAndHasValidFormat) {
        keyExistsAndHasValidFormat = &valid;
    }
    value = CFPreferencesCopyAppValue(key, appName);
    if (!value) {
        *keyExistsAndHasValidFormat = false;
        return false;
    }
    typeID = CFGetTypeID(value);
    if (typeID == CFStringGetTypeID()) {
        if (CFStringCompare((CFStringRef)value, CFSTR("true"), kCFCompareCaseInsensitive) == kCFCompareEqualTo || CFStringCompare((CFStringRef)value, CFSTR("YES"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
            *keyExistsAndHasValidFormat = true;
            result = true;
        } else if (CFStringCompare((CFStringRef)value, CFSTR("false"), kCFCompareCaseInsensitive) == kCFCompareEqualTo || CFStringCompare((CFStringRef)value, CFSTR("NO"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
            *keyExistsAndHasValidFormat = true;
            result = false;
        } else {
            *keyExistsAndHasValidFormat = false;
            result = false;
        }
    } else if (typeID == CFNumberGetTypeID()) {
        if (CFNumberIsFloatType((CFNumberRef)value)) {
            *keyExistsAndHasValidFormat = false;
            result = false;
        } else {
            int i;
            *keyExistsAndHasValidFormat = true;
            CFNumberGetValue((CFNumberRef)value, kCFNumberIntType, &i);
            result = (i == 0) ? false : true;
        }
    } else if (typeID == CFBooleanGetTypeID()) {
        result = (value == kCFBooleanTrue);
        *keyExistsAndHasValidFormat = true;
    } else {
        // Unknown type
        result = false;
        *keyExistsAndHasValidFormat = false;
    }
    CFRelease(value);
    return result;
}
Пример #11
0
/**
 * Retrieve the stored data specified by the given 'app' and data 'name'.  Requires
 * 'buffer' be pre-allocated and contains enough space to hold the data.  Pass in
 * the size of 'buffer' with 'buffersize'.
 *
 * @returns 0 on success, -1 on error
 */
int RudeRegistryCF::QueryByte(const TCHAR *app, const TCHAR *name, void *buffer, int *buffersize)
{
	CFStringRef key = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
	CFPropertyListRef value = CFPreferencesCopyAppValue(key, kCFPreferencesCurrentApplication);
	
	if(value == 0)
		return -1;
	
	if(CFDataGetLength((CFDataRef) value) != *buffersize)
		return -1;
	
	CFRange range = CFRangeMake(0, *buffersize);
	CFDataGetBytes((CFDataRef) value, range, (UInt8 *) buffer);

	return 0;
}
Пример #12
0
bool
Moose::launchWithMediaPlayer()
{
    CFBooleanRef v = (CFBooleanRef) CFPreferencesCopyAppValue( 
            CFSTR( "LaunchWithMediaPlayer" ), 
            CFSTR( MOOSE_PREFS_PLIST ) );

    if (v)
    {
        bool b = CFBooleanGetValue( v );
        CFRelease( v );
        return b;
    }
    else
        return true;
}
Пример #13
0
static char *command_from_prefs(const char *key, const char *default_value) {
    char *command = NULL;
    
    CFStringRef cfKey;
    CFPropertyListRef PlistRef;

    if(!key)
        return NULL;

    cfKey = CFStringCreateWithCString(NULL, key, kCFStringEncodingASCII);

    if(!cfKey)
        return NULL;

    PlistRef = CFPreferencesCopyAppValue(cfKey, kCFPreferencesCurrentApplication);
    
    if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
        CFStringRef cfDefaultValue = CFStringCreateWithCString(NULL, default_value, kCFStringEncodingASCII);
        int len = strlen(default_value) + 1;

        if(!cfDefaultValue)
            goto command_from_prefs_out;

        CFPreferencesSetAppValue(cfKey, cfDefaultValue, kCFPreferencesCurrentApplication);
        CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
        CFRelease(cfDefaultValue);
        
        command = (char *)malloc(len * sizeof(char));
        if(!command)
            goto command_from_prefs_out;
        strcpy(command, default_value);
    } else {
        int len = CFStringGetLength((CFStringRef)PlistRef) + 1;
        command = (char *)malloc(len * sizeof(char));
        if(!command)
            goto command_from_prefs_out;
        CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
    }

command_from_prefs_out:
    if (PlistRef)
        CFRelease(PlistRef);
    if(cfKey)
        CFRelease(cfKey);
    return command;
}
Boolean HIDRestoreElementPref( CFStringRef inKeyCFStringRef,
							  CFStringRef inAppCFStringRef,
							  IOHIDDeviceRef* outIOHIDDeviceRef,
							  IOHIDElementRef *outIOHIDElementRef )
{
	Boolean found = FALSE;
	
	if ( inKeyCFStringRef && inAppCFStringRef && outIOHIDDeviceRef && outIOHIDElementRef ) {
		CFPropertyListRef prefCFPropertyListRef = CFPreferencesCopyAppValue( inKeyCFStringRef, inAppCFStringRef );
		
		if ( prefCFPropertyListRef ) {
			if ( CFStringGetTypeID( ) == CFGetTypeID( prefCFPropertyListRef ) ) {
				char buffer[256];
				
				if ( CFStringGetCString( ( CFStringRef ) prefCFPropertyListRef, buffer, sizeof( buffer ),
										kCFStringEncodingUTF8 ) ) {
					recSaveHID searchInfo;
					
					int count = sscanf( buffer,
									   "d:{v:%d, p:%d, l:%d, p:%d, u:%d}, e:{p:%d, u:%d, c:%ld}",
									   &searchInfo.device.vendorID,
									   &searchInfo.device.productID,
									   &searchInfo.device.locID,
									   &searchInfo.device.usagePage,
									   &searchInfo.device.usage,
									   &searchInfo.element.usagePage,
									   &searchInfo.element.usage,
									   ( long* ) &searchInfo.element.cookie );
					
					if ( 8 == count ) { // if we found all eight parameters…
						// and can find a device & element that matches these…
						if ( HIDFindDeviceAndElement( &searchInfo, outIOHIDDeviceRef, outIOHIDElementRef ) ) {
							found = TRUE;
						}
					}
				}
			} else {
				// We found the entry with this key but it's the wrong type; delete it.
				CFPreferencesSetAppValue( inKeyCFStringRef, NULL, inAppCFStringRef );
				( void ) CFPreferencesAppSynchronize( inAppCFStringRef );
			}
			CFRelease( prefCFPropertyListRef );
		}
	}
	return found;
}   // HIDRestoreElementPref
Пример #15
0
static void
_rd_prefs_load_recent_files(rd_recent_file_t *r, int num_files, CFStringRef app)
{
    assert(r != NULL);
    assert(app != NULL);

    CFArrayRef the_array = CFPreferencesCopyAppValue(CFSTR("recent_files"), app);
    if (the_array == NULL) {
        return;
    }
    
    CFIndex array_count = CFArrayGetCount(the_array);        
    int i;
    for (i = 0; i < num_files; i++) {
        rd_recent_file_t *f = &r[i];
        if (i >= array_count) {
            bzero(f, sizeof(*f));
        } else {
            const void *f_val    = CFArrayGetValueAtIndex(the_array, i);
            if (CFGetTypeID(f_val) == CFStringGetTypeID()) {
                // string.  set the time to now.
                if (CFStringGetCString(f_val, f->path, sizeof(f->path), kCFStringEncodingUTF8)) {
                    // success 
                    f->path[sizeof(f->path) - 1] = '\0';
                    f->last_atime = (unsigned long) time(NULL);
                }
            } else if (CFGetTypeID(f_val) == CFDictionaryGetTypeID()) {
                CFStringRef f_name  = CFDictionaryGetValue(f_val, CFSTR("name"));
                CFNumberRef f_atime = CFDictionaryGetValue(f_val, CFSTR("atime"));
                
                if (CFStringGetCString(f_name, f->path, sizeof(f->path), kCFStringEncodingUTF8)) {
                    // success
                    f->path[sizeof(f->path) - 1] = '\0';
                
                    if (CFNumberGetValue(f_atime, kCFNumberLongType, (long*) &f->last_atime)) {
                        // success
                    } else {
                        f->last_atime = (unsigned long) time(NULL);
                    }
                }
            }
        }
    }
    
    CFRelease(the_array);
}
Пример #16
0
void extmgr_mntopts (const char *device, int *mopts, int *eopts, int *nomount)
{
   CFPropertyListRef mediaRoot;
   CFDictionaryRef media;
   CFStringRef uuid;
   CFBooleanRef boolVal;
   
   *nomount = 0;
   
   mediaRoot = CFPreferencesCopyAppValue(EXT_PREF_KEY_MEDIA, EXT_PREF_ID);
   if (mediaRoot && CFDictionaryGetTypeID() == CFGetTypeID(mediaRoot)) {
      uuid = extsuper_uuid(device);
      if (uuid) {
         media = CFDictionaryGetValue(mediaRoot, uuid);
         if (media && CFDictionaryGetTypeID() == CFGetTypeID(media)) {
            boolVal = CFDictionaryGetValue(media, EXT_PREF_KEY_NOAUTO);
            if (boolVal && CFBooleanGetValue(boolVal)) {
               *nomount = 1;
               goto out;
            }
            
            boolVal = CFDictionaryGetValue(media, EXT_PREF_KEY_RDONLY);
            if (boolVal && CFBooleanGetValue(boolVal)) {
               *mopts |= MNT_RDONLY;
            }
            
            boolVal = CFDictionaryGetValue(media, EXT_PREF_KEY_NOPERMS);
            if (boolVal && CFBooleanGetValue(boolVal)) {
               *mopts |= MNT_IGNORE_OWNERSHIP;
            }
            
            /* Ext2/3 specific */
            
            boolVal = CFDictionaryGetValue(media, EXT_PREF_KEY_DIRINDEX);
            if (boolVal && CFBooleanGetValue(boolVal)) {
               *eopts |= EXT2_MNT_INDEX;
            }
         }
out:
         CFRelease(uuid);
      }
   }
   if (mediaRoot)
      CFRelease(mediaRoot);
}
Пример #17
0
static Boolean getPrefDouble(CFStringRef key, CFStringRef app, double *val)
{
    CFPropertyListRef prefRef;
    Boolean ok;
    double ret;

    ok = false;
    prefRef = CFPreferencesCopyAppValue(key, app);
    if ( prefRef ) {
        if ( CFGetTypeID(prefRef) == CFNumberGetTypeID() && CFNumberIsFloatType(prefRef) ) {
            ok = CFNumberGetValue(prefRef, kCFNumberDoubleType, &ret);
            if ( ok && val )
                *val = ret;
        }
        CFRelease(prefRef);
    }
    return ok;
}
Пример #18
0
static bool enableAssembler(ExecutableAllocator& executableAllocator)
{
    if (!executableAllocator.isValid() || !Options::useJIT())
        return false;

#if USE(CF)
    RetainPtr<CFStringRef> canUseJITKey(AdoptCF, CFStringCreateWithCString(0 , "JavaScriptCoreUseJIT", kCFStringEncodingMacRoman));
    RetainPtr<CFBooleanRef> canUseJIT(AdoptCF, (CFBooleanRef)CFPreferencesCopyAppValue(canUseJITKey.get(), kCFPreferencesCurrentApplication));
    if (canUseJIT)
        return kCFBooleanTrue == canUseJIT.get();
#endif

#if USE(CF) || OS(UNIX)
    char* canUseJITString = getenv("JavaScriptCoreUseJIT");
    return !canUseJITString || atoi(canUseJITString);
#else
    return true;
#endif
}
Boolean HIDRestoreElementPref (CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice * ppDevice, pRecElement * ppElement)
{
	Boolean found = false;

	if ((NULL != keyCFStringRef) && (NULL != appCFStringRef) && (NULL != ppDevice) && (NULL != ppElement))
	{
		CFPropertyListRef prefCFPropertyListRef = CFPreferencesCopyAppValue(keyCFStringRef, appCFStringRef);

		if (NULL != prefCFPropertyListRef)
		{
			if (CFStringGetTypeID() == CFGetTypeID(prefCFPropertyListRef))
			{
				char buffer[256];

				if (CFStringGetCString((CFStringRef) prefCFPropertyListRef, buffer, sizeof(buffer), kCFStringEncodingASCII))
				{
					recDevice	searchDevice;
					recElement	searchElement;
					int count = sscanf(buffer, "d:{v:%ld, p:%ld, l:%ld, p:%ld, u:%ld}, e:{t:%ld, p:%ld, u:%ld, c:%ld}", 
						&searchDevice.vendorID, &searchDevice.productID, &searchDevice.locID, &searchDevice.usagePage, &searchDevice.usage, 
						&searchElement.type, &searchElement.usagePage, &searchElement.usage, (long*) &searchElement.cookie);

					if (9 == count)	// if we found all nine parametersÉ
					{	// and can find a device & element that matches theseÉ
						if (HIDFindActionDeviceAndElement(&searchDevice, &searchElement,ppDevice, ppElement))
						{
							found = true;
						}
					}
				}
			}
			else
			{
				// We found the entry with this key but it's the wrong type; delete it.
				CFPreferencesSetAppValue(keyCFStringRef, NULL, appCFStringRef);
				(void) CFPreferencesAppSynchronize(appCFStringRef);
			}
			CFRelease(prefCFPropertyListRef);
		}
	}
	return found;
}
void SearchPopupMenuWin::loadRecentSearches(const AtomicString& name, Vector<String>& searchItems)
{
    if (name.isEmpty())
        return;

#if USE(CF)
    searchItems.clear();
    RetainPtr<CFArrayRef> items(AdoptCF, reinterpret_cast<CFArrayRef>(CFPreferencesCopyAppValue(autosaveKey(name).get(), kCFPreferencesCurrentApplication)));

    if (!items || CFGetTypeID(items.get()) != CFArrayGetTypeID())
        return;

    size_t size = CFArrayGetCount(items.get());
    for (size_t i = 0; i < size; ++i) {
        CFStringRef item = (CFStringRef)CFArrayGetValueAtIndex(items.get(), i);
        if (CFGetTypeID(item) == CFStringGetTypeID())
            searchItems.append(item);
    }
#endif
}
__private_extern__ CFIndex CFPreferencesAppIntegerValue(CFStringRef key, CFStringRef appName, Boolean *keyExistsAndHasValidFormat) {
    CFPropertyListRef value;
    CFIndex result;
    CFTypeID typeID = 0;
    Boolean valid;
    CFAssert1(appName != NULL, __kCFLogAssertion, "%s(): Cannot access application preferences with a NULL application name", __PRETTY_FUNCTION__);
    CFAssert1(key != NULL, __kCFLogAssertion, "%s(): Cannot access preferences with a NULL key", __PRETTY_FUNCTION__);

    value = CFPreferencesCopyAppValue(key, appName);
    if (!keyExistsAndHasValidFormat) {
        keyExistsAndHasValidFormat = &valid;
    }
    if (!value) {
        *keyExistsAndHasValidFormat = false;
        return 0;
    }
    typeID = CFGetTypeID(value);
    if (typeID == CFStringGetTypeID()) {
        SInt32 charIndex = 0;
        SInt32 intVal;
        CFStringInlineBuffer buf;
        Boolean success;
        CFStringInitInlineBuffer((CFStringRef)value, &buf, CFRangeMake(0, CFStringGetLength((CFStringRef)value)));
        success = __CFStringScanInteger(&buf, NULL, &charIndex, false, &intVal);
        *keyExistsAndHasValidFormat = (success && charIndex == CFStringGetLength((CFStringRef)value));
        result = (*keyExistsAndHasValidFormat) ? intVal : 0;
    } else if (typeID == CFNumberGetTypeID()) {
        *keyExistsAndHasValidFormat = !CFNumberIsFloatType((CFNumberRef)value);
        if (*keyExistsAndHasValidFormat) {
            CFNumberGetValue((CFNumberRef)value, kCFNumberCFIndexType, &result);
        } else {
            result = 0;
        }
    } else {
        // Unknown type
        result = 0;
        *keyExistsAndHasValidFormat = false;
    }
    CFRelease(value);
    return result;
}
Пример #22
0
static void GetAlways()
{
#if TARGET_API_MAC_CARBON
	CFStringRef prefs_id = CFStringCreateWithCString(NULL, SUPERPNG_PREFS_ID, kCFStringEncodingASCII);
	
	CFStringRef always_id = CFStringCreateWithCString(NULL, SUPERPNG_PREFS_ALWAYS, kCFStringEncodingASCII);

	CFPropertyListRef always_val = CFPreferencesCopyAppValue(always_id, prefs_id);
	
	if(always_val)
	{
		g_always = CFBooleanGetValue((CFBooleanRef)always_val);
		
		CFRelease(always_val);
	}
	
	CFRelease(always_id);
	
	CFRelease(prefs_id);
#endif
}
Пример #23
0
void InitMultiCart (void)
{
	CFStringRef	keyRef, pathRef;
	char		key[32];

	multiCartPath[0] = multiCartPath[1] = NULL;

	for (int i = 0; i < 2; i++)
	{
		sprintf(key, "MultiCartPath_%02d", i);
		keyRef = CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringGetSystemEncoding());
		if (keyRef)
		{
			pathRef = (CFStringRef) CFPreferencesCopyAppValue(keyRef, kCFPreferencesCurrentApplication);
			if (pathRef)
				multiCartPath[i] = pathRef;

			CFRelease(keyRef);
		}
	}
}
Пример #24
0
const void *subsurface_get_conf(char *name, pref_type_t type)
{
    Boolean boolpref;
    CFPropertyListRef strpref;

    switch (type) {
    case PREF_BOOL:
        boolpref = CFPreferencesGetAppBooleanValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES, FALSE);
        if (boolpref)
            return (void *) 1;
        else
            return NULL;
    case PREF_STRING:
        strpref = CFPreferencesCopyAppValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES);
        if (!strpref)
            return NULL;
        return strdup(CFStringGetCStringPtr(strpref, kCFStringEncodingMacRoman));
    }
    /* we shouldn't get here, but having this line makes the compiler happy */
    return NULL;
}
Пример #25
0
static int				/* O - 1 if set, 0 otherwise */
cups_apple_get_string(
    CFStringRef key,			/* I - Key (name) */
    char        *value,			/* O - String value */
    size_t      valsize)		/* I - Size of value buffer */
{
  CFStringRef	sval;			/* String value */


  if ((sval = CFPreferencesCopyAppValue(key, kCUPSPrintingPrefs)) != NULL)
  {
    Boolean result = CFStringGetCString(sval, value, (CFIndex)valsize, kCFStringEncodingUTF8);

    CFRelease(sval);

    if (result)
      return (1);
  }

  return (0);
}
Пример #26
0
int isKeychainListed(char *keychainPath, char *listName) {




    CFArrayRef    prefCFArrayRef = CFPreferencesCopyAppValue( CFStringCreateWithCString(NULL, listName, kCFStringEncodingASCII), kAppCFStr);
    CFIndex       blacklist,index;
    int           blacklisted = 0;

    if (NULL == prefCFArrayRef)
        return 0;

    blacklist = CFArrayGetCount(prefCFArrayRef);

    for (index = 0;index < blacklist;index++) {
        CFStringRef    keychainCFString;
        char*        keychainStrPtr;




        keychainCFString = CFArrayGetValueAtIndex(prefCFArrayRef,index);
        if (NULL == keychainCFString)
            break;

        keychainStrPtr = Copy_CFStringRefToCString(keychainCFString);

        if(strcmp(keychainPath,keychainStrPtr) == 0) {
            blacklisted = 1;
            DisposePtr(keychainStrPtr);
            break;
        }
        DisposePtr(keychainStrPtr);

    }

    CFRelease(prefCFArrayRef);

    return blacklisted;
}
Пример #27
0
static void
_rd_prefs_load_singleton_string(const char *key, char *val, size_t sizeof_val, CFStringRef app)
{
    assert(key != NULL);
    assert(val != NULL);
    
    bzero(val, sizeof_val);
    
    CFStringRef k = CFStringCreateWithCString(kCFAllocatorSystemDefault, key, kCFStringEncodingASCII);
    if (k == NULL) {
        return;
    }
    
    CFStringRef v = (CFStringRef) CFPreferencesCopyAppValue(k, app);
    if (v != NULL) {
        if (CFStringGetCString(v, val, sizeof_val, kCFStringEncodingUTF8)) {
            // success
        }
        
        CFRelease(v);
    }    
}
Пример #28
0
static bool enableAssembler(ExecutableAllocator& executableAllocator)
{
    if (!executableAllocator.isValid() || !Options::useJIT)
        return false;

#if USE(CF)
    CFStringRef canUseJITKey = CFStringCreateWithCString(0 , "JavaScriptCoreUseJIT", kCFStringEncodingMacRoman);
    CFBooleanRef canUseJIT = (CFBooleanRef)CFPreferencesCopyAppValue(canUseJITKey, kCFPreferencesCurrentApplication);
    if (canUseJIT) {
        return kCFBooleanTrue == canUseJIT;
        CFRelease(canUseJIT);
    }
    CFRelease(canUseJITKey);
#endif

#if USE(CF) || OS(UNIX)
    char* canUseJITString = getenv("JavaScriptCoreUseJIT");
    return !canUseJITString || atoi(canUseJITString);
#else
    return true;
#endif
}
Пример #29
0
static char *
get_admin_account(void)
{
    CFPropertyListRef   pref = NULL;
    char *              account = NULL;
    int                 accountLength = 1024;

    pref = CFPreferencesCopyAppValue (CFSTR("DomainAdmin"), SAMBA_APP_ID);
    if (pref != 0) {
        if (CFGetTypeID(pref) == CFStringGetTypeID()) {
            account = calloc(1, accountLength);
            if (!CFStringGetCString((CFStringRef)pref, account,
                        accountLength, kCFStringEncodingUTF8)) {
                free(account);
                account = NULL;
            }
        }

        CFRelease(pref);
    }

    return account;
}
Пример #30
0
/**
 * If the value could not be loaded, the value in *val is not changed
 */
static void
_rd_prefs_load_singleton_int(const char *key, int *val, CFStringRef app)
{
    assert(key != NULL);
    assert(val != NULL);
    
    CFStringRef k = CFStringCreateWithCString(kCFAllocatorSystemDefault, key, kCFStringEncodingASCII);
    if (k == NULL) {
        return;
    }

    CFNumberRef n = CFPreferencesCopyAppValue(k, app);
    if (n != NULL) {
        int temp = 0;
        if (!CFNumberGetValue(n, kCFNumberIntType, &temp)) {
            // Oh well
        } else {
            *val = temp;
        }
        
        CFRelease(n);
    }
}