static CFComparisonResult __DAFileSystemProbeListCompare( const void * value1, const void * value2, void * context ) { CFNumberRef order1 = CFDictionaryGetValue( value1, CFSTR( kFSProbeOrderKey ) ); CFNumberRef order2 = CFDictionaryGetValue( value2, CFSTR( kFSProbeOrderKey ) ); if ( order1 == NULL ) return kCFCompareGreaterThan; if ( order2 == NULL ) return kCFCompareLessThan; return CFNumberCompare( order1, order2, NULL ); }
/* * Do dictionary lookup, convert possible CFNumber to uint32. * Does not alter val if valid number is not found. */ static void rsaLookupVal( Dictionary &prefs, CFStringRef key, uint32 &val) { CFNumberRef cfVal = (CFNumberRef)prefs.getValue(key); if(cfVal == NULL) { return; } if(CFGetTypeID(cfVal) != CFNumberGetTypeID()) { return; } /* ensure the number is positive, not relying on gcc 64-bit arithmetic */ SInt32 s32 = 0; CFNumberRef cfLimit = CFNumberCreate(NULL, kCFNumberSInt32Type, &s32); CFComparisonResult result = CFNumberCompare(cfVal, cfLimit, NULL); CFRelease(cfLimit); if(result == kCFCompareLessThan) { /* negative value in preference */ return; } /* ensure the number fits in 31 bits (the useful size of a SInt32 for us) */ s32 = 0x7fffffff; cfLimit = CFNumberCreate(NULL, kCFNumberSInt32Type, &s32); result = CFNumberCompare(cfVal, cfLimit, NULL); CFRelease(cfLimit); if(result == kCFCompareGreaterThan) { /* too large; discard it */ return; } SInt64 s64; if(!CFNumberGetValue(cfVal, kCFNumberSInt64Type, &s64)) { /* impossible, right? We already range checked */ return; } val = (uint32)s64; }
CFComparisonResult compareNumbers( const void * val1, const void * val2, void * context) { CFComparisonResult result = CFNumberCompare((CFNumberRef)val1, (CFNumberRef)val2, context); if (result == kCFCompareLessThan) { result = kCFCompareGreaterThan; } else if (result == kCFCompareGreaterThan) { result = kCFCompareLessThan; } return result; }
QuartzToggler::QuartzToggler() : originalMode(NULL), activeDspys(NULL), widgetScreen(0), isFull(false) { CGDisplayCount dspyCnt = 0; CGGetActiveDisplayList(0, 0, &dspyCnt); activeDspys = new CGDirectDisplayID[dspyCnt]; CGGetActiveDisplayList(dspyCnt, activeDspys, &dspyCnt); infoVector.resize(dspyCnt); fullResIndex.resize(dspyCnt); fullRateIndex.resize(dspyCnt); for (CGDisplayCount i = 0; i < dspyCnt; ++i) { CGDirectDisplayID display = activeDspys[i]; CFDictionaryRef currentMode = CGDisplayCurrentMode(display); CFArrayRef modesArray = CGDisplayAvailableModes(display); CFIndex numModes = CFArrayGetCount(modesArray); CFNumberRef bpp = static_cast<CFNumberRef>(CFDictionaryGetValue(currentMode, kCGDisplayBitsPerPixel)); for (CFIndex j = 0; j < numModes; ++j) { CFDictionaryRef mode = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(modesArray, j)); if (CFNumberCompare(bpp, static_cast<CFNumberRef>(CFDictionaryGetValue(mode, kCGDisplayBitsPerPixel)), NULL) == kCFCompareEqualTo) { addMode(mode, infoVector[i], NULL, NULL); } } } originalMode = CGDisplayCurrentMode(activeDspys[widgetScreen]); for (CGDisplayCount i = 0; i < dspyCnt; ++i) { unsigned resIndex = 0; unsigned rateIndex = 0; addMode(CGDisplayCurrentMode(activeDspys[i]), infoVector[i], &resIndex, &rateIndex); fullResIndex[i] = resIndex; fullRateIndex[i] = rateIndex; } }
Boolean equalValues(CFStringRef number, CFNumberRef expected, CFNumberFormatterStyle style, CFNumberFormatterOptionFlags option) { //CFStringRef enLocaleIdentifier = CFSTR("en_US"); //CFLocaleRef curLocale = CFLocaleCreate(NULL, enLocaleIdentifier); CFLocaleRef curLocale = CFLocaleCopyCurrent(); CFStringRef identifier = CFLocaleGetIdentifier(curLocale); CFNumberFormatterRef fmt; CFNumberRef val; show(CFSTR("Make a Number from : %@"), number); fmt = CFNumberFormatterCreate (0, curLocale, style); val = CFNumberFormatterCreateNumberFromString(0, fmt, number, 0, option); show(CFSTR("val=%@, should be=%@\n"), val, expected); if (!val) return false; return (0 == CFNumberCompare(val, expected, 0)); }
UString UserObjectImp::toString(ExecState *exec) const { UString result; JSUserObject* jsObjPtr = KJSValueToJSObject(toObject(exec), exec); CFTypeRef cfValue = jsObjPtr ? jsObjPtr->CopyCFValue() : 0; if (cfValue) { CFTypeID cfType = CFGetTypeID(cfValue); if (cfValue == GetCFNull()) { // } else if (cfType == CFBooleanGetTypeID()) { if (cfValue == kCFBooleanTrue) { result = "true"; } else { result = "false"; } } else if (cfType == CFStringGetTypeID()) { result = CFStringToUString((CFStringRef)cfValue); } else if (cfType == CFNumberGetTypeID()) { if (cfValue == kCFNumberNaN) { result = "Nan"; } else if (CFNumberCompare(kCFNumberPositiveInfinity, (CFNumberRef)cfValue, 0) == 0) { result = "Infinity"; } else if (CFNumberCompare(kCFNumberNegativeInfinity, (CFNumberRef)cfValue, 0) == 0) { result = "-Infinity"; } else { CFStringRef cfNumStr; double d = 0; CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d); if (CFNumberIsFloatType((CFNumberRef)cfValue)) { cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%f"), d); } else { cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%.0f"), d); } result = CFStringToUString(cfNumStr); ReleaseCFType(cfNumStr); } } else if (cfType == CFArrayGetTypeID()) { // } else if (cfType == CFDictionaryGetTypeID()) { // } else if (cfType == CFSetGetTypeID()) { // } else if (cfType == CFURLGetTypeID()) { CFURLRef absURL = CFURLCopyAbsoluteURL((CFURLRef)cfValue); if (absURL) { CFStringRef cfStr = CFURLGetString(absURL); if (cfStr) { result = CFStringToUString(cfStr); } ReleaseCFType(absURL); } } } ReleaseCFType(cfValue); if (jsObjPtr) jsObjPtr->Release(); return result; }
CFStringRef FSCopyFormatNameForFSType(CFStringRef fsType, int16_t fsSubtype, bool localized, bool encrypted) { CFTypeRef formatName; CFStringRef formatNameTableKey; CFIndex indx; if (NULL == fsType) return NULL; // Create a key for cache localized name table (i.e. "0hfs0") formatNameTableKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d%@%d"), (localized ? 1 : 0), fsType, fsSubtype); // Use OSSpinLock to protect the table accessed from multiple threads OSSpinLockLock(&__FSLocalizedNameTableLock); formatName = (void*)((NULL == __FSLocalizedNameTable) ? NULL : CFDictionaryGetValue(__FSLocalizedNameTable, (const void *)formatNameTableKey)); OSSpinLockUnlock(&__FSLocalizedNameTableLock); if (NULL == formatName) { // not in the cache CFBundleRef bundle = NULL; CFURLRef bundleURL; CFStringRef fsTypeName; static CFArrayRef searchPaths = NULL; /* Construct a bundle path URL from the fsType argument and create a CFBundle. We search (using CFCopySearchPathForDirectoriesInDomains) /Network/Library/Filesystems, /Library/Filesystems, and /System/Library/Filesystems. */ // Create CFURL for /System/Library/Filesystems and cache it if (NULL == searchPaths) { CFArrayRef tmpPaths = CFCopySearchPathForDirectoriesInDomains(kCFLibraryDirectory, kCFSystemDomainMask | kCFNetworkDomainMask | kCFLocalDomainMask, true); CFMutableArrayRef tmpStrings; CFIndex i; if (NULL == tmpPaths) return NULL; // No directories to search?!?! tmpStrings = CFArrayCreateMutable(NULL, CFArrayGetCount(tmpPaths), NULL); if (tmpStrings == NULL) goto done; for (i = 0; i < CFArrayGetCount(tmpPaths); i++) { CFStringRef tStr; CFURLRef tURL; char path[PATH_MAX + 1]; CFTypeRef tobject = CFArrayGetValueAtIndex(tmpPaths, i); if (CFGetTypeID(tobject) == CFURLGetTypeID()) { if (false == CFURLGetFileSystemRepresentation( tobject, false, (UInt8*)path, sizeof(path))) { goto done; } } else if (CFGetTypeID(tobject) == CFStringGetTypeID()) { CFStringGetCString(tobject, path, sizeof(path), kCFStringEncodingUTF8); } else { goto done; } strlcat(path, "/Filesystems", sizeof(path)); tStr = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8); if (tStr == NULL) goto done; tURL = CFURLCreateWithFileSystemPath(NULL, tStr, kCFURLPOSIXPathStyle, true); if (tURL) { CFArrayAppendValue(tmpStrings, tURL); } CFRelease(tStr); } searchPaths = CFArrayCreateCopy(NULL, tmpStrings); done: CFRelease(tmpStrings); CFRelease(tmpPaths); if (searchPaths == NULL) return NULL; } for (indx = 0; indx < CFArrayGetCount(searchPaths); indx++) { CFURLRef libRef = CFArrayGetValueAtIndex(searchPaths, indx); fsTypeName = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@.fs"), fsType); bundleURL = CFURLCreateWithFileSystemPathRelativeToBase(NULL, fsTypeName, kCFURLPOSIXPathStyle, true, libRef); bundle = CFBundleCreate(NULL, bundleURL); CFRelease(fsTypeName); CFRelease(bundleURL); if (NULL != bundle) { break; } } if (NULL != bundle) { // the bundle exists at path CFDictionaryRef localPersonalities = NULL; // Access the Info dictionary in the bundle CFDictionaryRef bundleDict = CFBundleGetInfoDictionary(bundle); // Get localized FSPersonalities only if we want localized name if (localized == true) { localPersonalities = CFBundleGetValueForInfoDictionaryKey(bundle, KEY_FS_PERSONALITIES); //NSLog(CFSTR("localPersonalities = %@\n"), localPersonalities); } /* Get global FSPersonalities. We need to access this since FSSubType exists only * in global FSPersonalities */ CFDictionaryRef globalPersonalities = CFDictionaryGetValue(bundleDict, (const void *) KEY_FS_PERSONALITIES); //NSLog(CFSTR("globalPersonalities = %@\n"), globalPersonalities); CFIndex numPersonalities; if (((NULL != localPersonalities) || (localized == false)) && // localPersonalities or we don't want localizations (NULL != globalPersonalities) && ((numPersonalities = CFDictionaryGetCount(globalPersonalities)) > 0)) { // read all FSPersonalities keys and values CFDictionaryRef valuesBuffer[MAX_FS_SUBTYPES]; CFStringRef keysBuffer[MAX_FS_SUBTYPES]; CFDictionaryRef *values = ((numPersonalities > MAX_FS_SUBTYPES) ? (CFDictionaryRef *)malloc(sizeof(CFDictionaryRef) * numPersonalities) : valuesBuffer); CFStringRef *keys = ((numPersonalities > MAX_FS_SUBTYPES) ? (CFStringRef *)malloc(sizeof(CFStringRef) * numPersonalities) : keysBuffer); CFDictionaryGetKeysAndValues(globalPersonalities, (const void **)keys, (const void **)values); // create CFNumberRef for the FSSubType CFNumberRef subTypeID = CFNumberCreate(NULL, kCFNumberSInt16Type, (const void *)&fsSubtype); CFStringRef FSNameKey = NULL; // search for valid FSSubType - we will use its key from global FSPersonalties to // access FSName from localized FSPersonalities CFIndex index; CFNumberRef readSubTypeID; for (index = 0; index < numPersonalities; index++) { if ((true == CFDictionaryGetValueIfPresent(values[index], (const void *)KEY_FS_SUBTYPE, (const void **)&readSubTypeID)) && (CFNumberCompare(subTypeID, readSubTypeID, NULL) == 0)) { FSNameKey = keys[index]; break; } } CFRelease(subTypeID); /* If a personality hasn't been found, use the last value in the dictionary (note the content of CFDictionary is unordered so choosing the last doesn't produce consistent result) */ if (NULL == FSNameKey) { FSNameKey = keys[numPersonalities - 1]; // is selecting the last entry right ? } // Get FSName from the FSPersonalities entry CFDictionaryRef FSNameDict; if (localized == true) { FSNameDict = CFDictionaryGetValue(localPersonalities, FSNameKey); } else { FSNameDict = CFDictionaryGetValue(globalPersonalities, FSNameKey); } if (NULL != FSNameDict) { CFStringRef tempName = CFDictionaryGetValue(FSNameDict, (const void *)KEY_FS_NAME); CFStringRef encrName = CFDictionaryGetValue(FSNameDict, CFSTR(kFSCoreStorageEncryptNameKey)); if (tempName) { if (encrName) { formatName = (void*)CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (formatName != NULL) { (void)CFDictionarySetValue((void*)formatName, tempName, encrName); } } else { formatName = tempName; } } } if (values != valuesBuffer) free(values); if (keys != keysBuffer) free(keys); } } // If all failed, return "Unknown format (f_fstypename)" as the last resort if (NULL == formatName) { static CFStringRef unknownTypeString = NULL; CFStringRef unknownFSNameString = NULL; // This should use the framework bundle this code resides. CarbonCore ??? */ if (NULL == unknownTypeString) unknownTypeString = CFCopyLocalizedString(UNKNOWN_FS_NAME, "This string is displayed when localized file system name cannot be determined."); unknownFSNameString = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)"), unknownTypeString, fsType); formatName = (void*)unknownFSNameString; } // Cache the result OSSpinLockLock(&__FSLocalizedNameTableLock); if (NULL == __FSLocalizedNameTable) __FSLocalizedNameTable = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); // NSLog(CFSTR("Setting value %@ for key %@\n"), formatName, formatNameTableKey); CFDictionarySetValue(__FSLocalizedNameTable, (const void *)formatNameTableKey, (const void *)formatName); OSSpinLockUnlock(&__FSLocalizedNameTableLock); // NSLog(CFSTR("Localized Name Table = %@\n"), __FSLocalizedNameTable); if (NULL != bundle) CFRelease(bundle); // it has to be released here since formatName might be owned by the bundle } CFRelease(formatNameTableKey); if (CFGetTypeID(formatName) == CFStringGetTypeID()) { return CFRetain(formatName); } else if (CFGetTypeID(formatName) == CFDictionaryGetTypeID()) { // Dictionary with the (possibly localized) name as the key, and the encrypted name as the value // If we want the encrypted name, we return the value, else we return the key size_t numEntries = CFDictionaryGetCount((void*)formatName); void *keyNames[numEntries]; void *values[numEntries]; CFDictionaryGetKeysAndValues((void*)formatName, (const void**)&keyNames, (const void**)&values); if (encrypted) return CFRetain(values[0]); else return CFRetain(keyNames[0]); } return CFRetain(formatName); }
static Boolean __CFNumberEqual(CFTypeRef cf1, CFTypeRef cf2) { return CFNumberCompare((CFNumberRef)cf1, (CFNumberRef)cf2, 0) == kCFCompareEqualTo; }