void _glfwChangeToResourcesDirectory( void ) { CFBundleRef mainBundle = CFBundleGetMainBundle(); if( mainBundle == NULL ) { UNBUNDLED; } CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL( mainBundle ); char resourcesPath[ _GLFW_MAX_PATH_LENGTH ]; CFStringRef lastComponent = CFURLCopyLastPathComponent( resourcesURL ); if( kCFCompareEqualTo != CFStringCompare( CFSTR( "Resources" ), lastComponent, 0 ) ) { UNBUNDLED; } CFRelease( lastComponent ); if( !CFURLGetFileSystemRepresentation( resourcesURL, TRUE, (UInt8*)resourcesPath, _GLFW_MAX_PATH_LENGTH ) ) { CFRelease( resourcesURL ); UNBUNDLED; } CFRelease( resourcesURL ); #ifndef MMDAGENT if( chdir( resourcesPath ) != 0 ) { UNBUNDLED; } #endif /* !MMDAGENT */ }
__private_extern__ void _CFBundleInitPlugIn(CFBundleRef bundle) { CFArrayCallBacks _pluginFactoryArrayCallbacks = {0, NULL, NULL, NULL, NULL}; Boolean doDynamicReg = false; CFDictionaryRef infoDict; CFDictionaryRef factoryDict; CFDictionaryRef typeDict; CFStringRef tempStr; infoDict = CFBundleGetInfoDictionary(bundle); if (!infoDict) return; factoryDict = (CFDictionaryRef)CFDictionaryGetValue(infoDict, kCFPlugInFactoriesKey); if (factoryDict && CFGetTypeID(factoryDict) != CFDictionaryGetTypeID()) factoryDict = NULL; tempStr = (CFStringRef)CFDictionaryGetValue(infoDict, kCFPlugInDynamicRegistrationKey); if (tempStr && CFGetTypeID(tempStr) == CFStringGetTypeID() && CFStringCompare(tempStr, CFSTR("YES"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) doDynamicReg = true; if (!factoryDict && !doDynamicReg) return; // This is not a plug-in. /* loadOnDemand is true by default if the plugIn does not do dynamic registration. It is false, by default if it does do dynamic registration. The dynamic register function can set this. */ __CFBundleGetPlugInData(bundle)->_isPlugIn = true; __CFBundleGetPlugInData(bundle)->_loadOnDemand = true; __CFBundleGetPlugInData(bundle)->_isDoingDynamicRegistration = false; __CFBundleGetPlugInData(bundle)->_instanceCount = 0; __CFBundleGetPlugInData(bundle)->_factories = CFArrayCreateMutable(CFGetAllocator(bundle), 0, &_pluginFactoryArrayCallbacks); /* Now do the registration */ /* First do static registrations, if any. */ if (factoryDict) CFDictionaryApplyFunction(factoryDict, _registerFactory, bundle); typeDict = (CFDictionaryRef)CFDictionaryGetValue(infoDict, kCFPlugInTypesKey); if (typeDict && CFGetTypeID(typeDict) != CFDictionaryGetTypeID()) typeDict = NULL; if (typeDict) CFDictionaryApplyFunction(typeDict, _registerType, bundle); /* Now set key for dynamic registration if necessary */ if (doDynamicReg) { CFDictionarySetValue((CFMutableDictionaryRef)infoDict, CFSTR("CFPlugInNeedsDynamicRegistration"), CFSTR("YES")); if (CFBundleIsExecutableLoaded(bundle)) _CFBundlePlugInLoaded(bundle); } }
/* new in 10.7 */ SecPolicyRef SecPolicyCreateWithOID(CFTypeRef policyOID) { //%%% FIXME: allow policyOID to be a CFDataRef or a CFStringRef for an arbitrary OID // for now, we only accept the policy constants that are defined in SecPolicy.h CFStringRef oidStr = (CFStringRef)policyOID; CSSM_OID *oidPtr = NULL; SecPolicyRef policy = NULL; const void* oidmap[] = { kSecPolicyAppleX509Basic, &CSSMOID_APPLE_X509_BASIC, kSecPolicyAppleSSL, &CSSMOID_APPLE_TP_SSL, kSecPolicyAppleSMIME, &CSSMOID_APPLE_TP_SMIME, kSecPolicyAppleEAP, &CSSMOID_APPLE_TP_EAP, kSecPolicyAppleIPsec, &CSSMOID_APPLE_TP_IP_SEC, kSecPolicyAppleiChat, &CSSMOID_APPLE_TP_ICHAT, kSecPolicyApplePKINITClient, &CSSMOID_APPLE_TP_PKINIT_CLIENT, kSecPolicyApplePKINITServer, &CSSMOID_APPLE_TP_PKINIT_SERVER, kSecPolicyAppleCodeSigning, &CSSMOID_APPLE_TP_CODE_SIGNING, kSecPolicyMacAppStoreReceipt, &CSSMOID_APPLE_TP_MACAPPSTORE_RECEIPT, kSecPolicyAppleIDValidation, &CSSMOID_APPLE_TP_APPLEID_SHARING }; unsigned int i, oidmaplen = sizeof(oidmap) / sizeof(oidmap[0]); for (i=0; i<oidmaplen*2; i+=2) { CFStringRef str = (CFStringRef)oidmap[i]; if (CFStringCompare(str, oidStr, 0) == kCFCompareEqualTo) { oidPtr = (CSSM_OID*)oidmap[i+1]; break; } } if (oidPtr) { SecPolicySearchRef policySearch = NULL; OSStatus status = SecPolicySearchCreate(CSSM_CERT_X_509v3, oidPtr, NULL, &policySearch); if (!status && policySearch) { status = SecPolicySearchCopyNext(policySearch, &policy); CFRelease(policySearch); } } return policy; }
bool CScreensaver::Host_is_running_on_batteries() { CFDictionaryRef pSource = NULL; CFStringRef psState; int i; bool retval = false; CFTypeRef blob = IOPSCopyPowerSourcesInfo(); CFArrayRef list = IOPSCopyPowerSourcesList(blob); for (i=0; i<CFArrayGetCount(list); i++) { pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(list, i)); if(!pSource) break; psState = (CFStringRef)CFDictionaryGetValue(pSource, CFSTR(kIOPSPowerSourceStateKey)); if(!CFStringCompare(psState,CFSTR(kIOPSBatteryPowerValue),0)) retval = true; } CFRelease(blob); CFRelease(list); return retval; }
Notificator::Notificator(const QString &programName, QSystemTrayIcon *trayicon, QWidget *parent): QObject(parent), parent(parent), programName(programName), mode(None), trayIcon(trayicon) #ifdef USE_DBUS ,interface(0) #endif { if(trayicon && trayicon->supportsMessages()) { mode = QSystemTray; } #ifdef USE_DBUS interface = new QDBusInterface("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications"); if(interface->isValid()) { mode = Freedesktop; } #endif #ifdef Q_OS_MAC // Check if Growl is installed (based on Qt's tray icon implementation) CFURLRef cfurl; OSStatus status = LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator, CFSTR("growlTicket"), kLSRolesAll, 0, &cfurl); if (status != kLSApplicationNotFoundErr) { CFBundleRef bundle = CFBundleCreate(0, cfurl); if (CFStringCompare(CFBundleGetIdentifier(bundle), CFSTR("com.Growl.GrowlHelperApp"), kCFCompareCaseInsensitive | kCFCompareBackwards) == kCFCompareEqualTo) { if (CFStringHasSuffix(CFURLGetString(cfurl), CFSTR("/Growl.app/"))) mode = Growl13; else mode = Growl12; } CFRelease(cfurl); CFRelease(bundle); } #endif }
const void *subsurface_get_conf(char *name, pref_type_t type) { CFStringRef dict_entry; /* if no settings exist, we return the value for FALSE */ if (!propertyList) return NULL; switch (type) { case PREF_BOOL: dict_entry = CFDictionaryGetValue(propertyList, CFSTR_VAR(name)); if (dict_entry && ! CFStringCompare(CFSTR("1"), dict_entry, 0)) return (void *) 1; else return NULL; case PREF_STRING: return CFStringGetCStringPtr(CFDictionaryGetValue(propertyList, CFSTR_VAR(name)), kCFStringEncodingMacRoman); } /* we shouldn't get here, but having this line makes the compiler happy */ return NULL; }
kim_error kim_os_string_compare (kim_string in_string, kim_string in_compare_to_string, kim_boolean in_case_insensitive, kim_comparison *out_comparison) { kim_error err = KIM_NO_ERROR; CFStringRef cfstring = NULL; CFStringRef compare_to_cfstring = NULL; if (!err && !in_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_compare_to_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_comparison ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_string_get_cfstring (in_string, &cfstring); } if (!err) { err = kim_os_string_get_cfstring (in_compare_to_string, &compare_to_cfstring); } if (!err) { CFOptionFlags options = (in_case_insensitive ? 1 : kCFCompareCaseInsensitive); /* Returned CFComparisonResult is compatible with kim_comparison_t */ *out_comparison = CFStringCompare (cfstring, compare_to_cfstring, options); } if (cfstring ) { CFRelease (cfstring); } if (compare_to_cfstring) { CFRelease (compare_to_cfstring); } return check_error (err); }
CFStringRef CreateDisplayNameForURL(CFURLRef url) { assert(nullptr != url); CFStringRef displayName = nullptr; #if !TARGET_OS_IPHONE CFStringRef scheme = CFURLCopyScheme(url); if(scheme) { bool isFileURL = (kCFCompareEqualTo == CFStringCompare(CFSTR("file"), scheme, kCFCompareCaseInsensitive)); CFRelease(scheme), scheme = nullptr; if(isFileURL) { OSStatus result = LSCopyDisplayNameForURL(url, &displayName); if(noErr != result) { LOGGER_WARNING("org.sbooth.AudioEngine", "LSCopyDisplayNameForURL failed: " << result); displayName = CFURLCopyLastPathComponent(url); } } else { displayName = CFURLGetString(url); CFRetain(displayName); } } // If scheme is nullptr the URL is probably invalid, but can still be logged else { displayName = CFURLGetString(url); CFRetain(displayName); } #else displayName = CFURLGetString(url); CFRetain(displayName); #endif return displayName; }
int od_record_check_shell(ODRecordRef record) { int retval = PAM_PERM_DENIED; CFStringRef cfstr = NULL; if (NULL == record) { openpam_log(PAM_LOG_DEBUG, "NULL argument passed"); retval = PAM_SERVICE_ERR; goto cleanup; } retval = od_record_attribute_create_cfstring(record, kODAttributeTypeUserShell, &cfstr); if (PAM_SUCCESS != retval) { openpam_log(PAM_LOG_DEBUG, "od_record_attribute_create_cfstring() failed"); goto cleanup; } if (NULL == cfstr) { retval = PAM_SUCCESS; goto cleanup; } if (CFStringCompare(cfstr, CFSTR("/usr/bin/false"), 0) == kCFCompareEqualTo) { openpam_log(PAM_LOG_DEBUG, "user shell is /bin/false"); retval = PAM_PERM_DENIED; } cleanup: if (PAM_SUCCESS != retval) openpam_log(PAM_LOG_ERROR, "failed: %d", retval); if (NULL != cfstr) { CFRelease(cfstr); } return retval; }
OSStatus SecureDownloadCopyTicketLocation (CFURLRef url, CFURLRef *ticketLocation) { API_BEGIN Required (ticketLocation); Required (url); // copy the resource specifier CFStringRef resourceSpecifier = CFURLCopyResourceSpecifier (url); if (resourceSpecifier == NULL) { CFError::throwMe (); } // make a new URL from the resource specifier *ticketLocation = CFURLCreateWithString (NULL, resourceSpecifier, NULL); if (*ticketLocation == NULL) { CFError::throwMe (); } // check the scheme to make sure that it isn't a file url CFStringRef scheme = CFURLCopyScheme (*ticketLocation); if (scheme != NULL) { CFComparisonResult equal = CFStringCompare (scheme, CFSTR("file"), kCFCompareCaseInsensitive); CFRelease (scheme); if (equal == kCFCompareEqualTo) { CFRelease (*ticketLocation); *ticketLocation = NULL; MacOSError::throwMe (errSecureDownloadInvalidDownload); } } CFRelease (resourceSpecifier); API_END }
Boolean IOURLCreateDataAndPropertiesFromResource(CFAllocatorRef alloc, CFURLRef url, CFDataRef *fetchedData, CFDictionaryRef *fetchedProperties, CFArrayRef desiredProperties, SInt32 *errorCode) { CFStringRef scheme = CFURLCopyScheme(url); if (!scheme) { if (errorCode) *errorCode = kIOURLImproperArgumentsError; if (fetchedData) *fetchedData = NULL; if (fetchedProperties) *fetchedProperties = NULL; return FALSE; } else { Boolean result; if (CFStringCompare(scheme, CFSTR("file"), 0) == kCFCompareEqualTo) { result = _IOFileURLCreateDataAndPropertiesFromResource(alloc, url, fetchedData, desiredProperties, fetchedProperties, errorCode); } else { if (fetchedData) *fetchedData = NULL; if (fetchedProperties) *fetchedProperties = NULL; if (errorCode) *errorCode = kIOURLUnknownSchemeError; result = FALSE; } CFRelease(scheme); return result; } }
kern_return_t test_apple_Sessioned_AMDeviceCopyValue(struct am_device *apple, CFTypeRef *value) { kern_return_t apple_return = kAMDUndefinedError; CFTypeRef apple_value = NULL; kern_return_t result = AMDeviceConnect(apple); if (SDM_MD_CallSuccessful(result)) { result = AMDeviceStartSession(apple); if (SDM_MD_CallSuccessful(result)) { apple_value = AMDeviceCopyValue(apple, CFSTR(kInternationalDomain), CFSTR(kLanguage)); if (apple_value == NULL || CFStringCompare(apple_value, CFSTR("GetProhibited"), 0) == kCFCompareEqualTo) { printf("\t\tappleMD_AMDeviceCopyValue (w/ Session): GetProhibited\n"); apple_return = kAMDGetProhibitedError; CFSafeRelease(apple_value); } else { *value = apple_value; apple_return = kAMDSuccess; } AMDeviceStopSession(apple); } AMDeviceDisconnect(apple); } return apple_return; }
static inline Boolean CFNotificationObserverEqual(CFNotificationObserver *observer1, CFNotificationObserver *observer2) { if (observer1 == observer2) { return true; } if (observer1->observer != observer2->observer) { return false; } if (observer1->callBack != observer2->callBack) { return false; } if (CFStringCompare(observer1->name, observer2->name, 0) != kCFCompareEqualTo) { return false; } if (observer1->object != observer2->object) { return false; } return true; }
CFTypeRef _mongoc_secure_transport_dict_get (CFArrayRef values, CFStringRef label) { if (!values || CFGetTypeID (values) != CFArrayGetTypeID ()) { return NULL; } for (CFIndex i = 0; i < CFArrayGetCount (values); ++i) { CFStringRef item_label; CFDictionaryRef item = CFArrayGetValueAtIndex (values, i); if (CFGetTypeID (item) != CFDictionaryGetTypeID ()) { continue; } item_label = CFDictionaryGetValue (item, kSecPropertyKeyLabel); if (item_label && CFStringCompare (item_label, label, 0) == kCFCompareEqualTo) { return CFDictionaryGetValue (item, kSecPropertyKeyValue); } } return NULL; }
CFMutableDictionaryRef CAuthAuthority::GetValueForTagAsCFDict( const char *inTagStr ) { CFMutableDictionaryRef theDict = NULL; CFMutableDictionaryRef aDict = NULL; CFIndex arrayCount = 0; CFIndex index = 0; CFStringRef tagValueString = NULL; CFStringRef searchTagValueString = NULL; if ( mValueArray == NULL ) return NULL; searchTagValueString = CFStringCreateWithCString( kCFAllocatorDefault, inTagStr, kCFStringEncodingUTF8 ); if ( searchTagValueString == NULL ) return NULL; arrayCount = CFArrayGetCount( mValueArray ); for ( index = 0; index < arrayCount; index++ ) { aDict = (CFMutableDictionaryRef) CFArrayGetValueAtIndex( mValueArray, index ); if ( aDict != NULL ) { tagValueString = (CFStringRef) CFDictionaryGetValue( aDict, CFSTR("tag") ); if ( tagValueString != NULL && CFStringCompare(tagValueString, searchTagValueString, kCFCompareCaseInsensitive) == kCFCompareEqualTo ) { theDict = aDict; break; } } } CFRelease( searchTagValueString ); return theDict; }
/*! Applies a callback function all IOMedia objects of a particular target. * @param target search children of this node for IOMedia objects. * @param callback the callback function to call on each IOMedia object. * @param context a user-defined parameter to pass to the callback function. */ void iSCSIIORegistryIOMediaApplyFunction(io_object_t target, iSCSIIOMediaCallback callback, void * context) { io_object_t entry = IO_OBJECT_NULL; io_iterator_t iterator = IO_OBJECT_NULL; IORegistryEntryGetChildIterator(target,kIOServicePlane,&iterator); // Iterate over all children of the target object while((entry = IOIteratorNext(iterator)) != IO_OBJECT_NULL) { // Recursively call this function for each child of the target iSCSIIORegistryIOMediaApplyFunction(entry,callback,context); // Find the IOMedia's root provider class (IOBlockStorageDriver) and // get the first child. This ensures that we grab the IOMedia object // for the disk itself and not each individual partition CFStringRef providerClass = IORegistryEntryCreateCFProperty(entry,CFSTR(kIOClassKey),kCFAllocatorDefault,0); if(providerClass && CFStringCompare(providerClass,CFSTR(kIOBlockStorageDriverClass),0) == kCFCompareEqualTo) { // Apply callback function to the child (the child is the the // IOMedia object that pertains to the whole disk) io_object_t child; IORegistryEntryGetChildEntry(entry,kIOServicePlane,&child); callback(child,context); IOObjectRelease(child); } if(providerClass) CFRelease(providerClass); IOObjectRelease(entry); } IOObjectRelease(iterator); }
void QMacSettingsPrivate::sync() { for (int i = 0; i < numDomains; ++i) { for (int j = 0; j < numHostNames; ++j) { Boolean ok = CFPreferencesSynchronize(domains[i].applicationOrSuiteId, domains[i].userName, hostNames[j]); // only report failures for the primary file (the one we write to) if (!ok && i == 0 && hostNames[j] == hostName && status == QSettings::NoError) { #if 1 if (QSysInfo::macVersion() < QSysInfo::MV_10_7) { // work around what seems to be a bug in CFPreferences: // don't report an error if there are no preferences for the application QCFType<CFArrayRef> appIds = CFPreferencesCopyApplicationList(domains[i].userName, hostNames[j]); // iterate through all the applications and see if we're there CFIndex size = CFArrayGetCount(appIds); for (CFIndex k = 0; k < size; ++k) { const void *cfvalue = CFArrayGetValueAtIndex(appIds, k); if (CFGetTypeID(cfvalue) == CFStringGetTypeID()) { if (CFStringCompare(static_cast<CFStringRef>(cfvalue), domains[i].applicationOrSuiteId, kCFCompareCaseInsensitive) == kCFCompareEqualTo) { setStatus(QSettings::AccessError); break; } } } } else #endif { setStatus(QSettings::AccessError); } } } } }
int GetBoolPreference(const char * name, int defaut) { int retour = defaut; CFStringRef nom = CFStringCreateWithCString (NULL,name,CFStringGetSystemEncoding()); if (nom != NULL) { CFStringRef value = (CFStringRef)CFPreferencesCopyAppValue(nom,kCFPreferencesCurrentApplication); if (value != NULL) { if (CFGetTypeID(value) == CFStringGetTypeID ()) { retour = (CFStringCompare(value, CFSTR("YES"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) ? 1 : 0; } CFRelease(value); } CFRelease(nom); } return retour; }
bool AudioDecoder::HandlesMIMEType(CFStringRef mimeType) { if(NULL == mimeType) return false; CFArrayRef supportedMIMETypes = CreateSupportedMIMETypes(); if(NULL == supportedMIMETypes) return false; bool mimeTypeIsSupported = false; CFIndex numberOfSupportedMIMETypes = CFArrayGetCount(supportedMIMETypes); for(CFIndex currentIndex = 0; currentIndex < numberOfSupportedMIMETypes; ++currentIndex) { CFStringRef currentMIMEType = static_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedMIMETypes, currentIndex)); if(kCFCompareEqualTo == CFStringCompare(mimeType, currentMIMEType, kCFCompareCaseInsensitive)) { mimeTypeIsSupported = true; break; } } CFRelease(supportedMIMETypes), supportedMIMETypes = NULL; return mimeTypeIsSupported; }
Boolean IOURLWriteDataAndPropertiesToResource(CFURLRef url, CFDataRef data, CFDictionaryRef propertyDict, SInt32 *errorCode) { CFStringRef scheme = CFURLCopyScheme(url); if (!scheme) { if (errorCode) *errorCode = kIOURLImproperArgumentsError; return FALSE; } else if (CFStringCompare(scheme, CFSTR("file"), 0) == kCFCompareEqualTo) { Boolean success = TRUE; CFRelease(scheme); if (errorCode) *errorCode = 0; if (data) { char cPath[CFMaxPathSize]; if (!CFURLGetFileSystemRepresentation(url, TRUE, cPath, CFMaxPathSize)) { if (errorCode) *errorCode = kIOURLImproperArgumentsError; success = FALSE; } else if (CFURLHasDirectoryPath(url)) { // Create a directory success = !mkdir(cPath, 0777); if (!success && errorCode) *errorCode = kIOURLUnknownError; } else { // Write data SInt32 length = CFDataGetLength(data); const void *bytes = (0 == length) ? (const void *)"" : CFDataGetBytePtr(data); success = _IOWriteBytesToFile(cPath, bytes, length); if (!success && errorCode) *errorCode = kIOURLUnknownError; } } if (propertyDict) { if (!_IOFileURLWritePropertiesToResource(url, propertyDict, errorCode)) success = FALSE; } return success; } else { if (errorCode) *errorCode = kIOURLUnknownSchemeError; return FALSE; } }
bool AudioDecoder::HandlesFilesWithExtension(CFStringRef extension) { if(NULL == extension) return false; CFArrayRef supportedExtensions = CreateSupportedFileExtensions(); if(NULL == supportedExtensions) return false; bool extensionIsSupported = false; CFIndex numberOfSupportedExtensions = CFArrayGetCount(supportedExtensions); for(CFIndex currentIndex = 0; currentIndex < numberOfSupportedExtensions; ++currentIndex) { CFStringRef currentExtension = static_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedExtensions, currentIndex)); if(kCFCompareEqualTo == CFStringCompare(extension, currentExtension, kCFCompareCaseInsensitive)) { extensionIsSupported = true; break; } } CFRelease(supportedExtensions), supportedExtensions = NULL; return extensionIsSupported; }
kim_error kim_os_string_compare_to_cfstring (kim_string in_string, CFStringRef in_compare_to_cfstring, kim_comparison *out_comparison) { kim_error err = KIM_NO_ERROR; CFStringRef cfstring = NULL; if (!err && !in_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_compare_to_cfstring) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_comparison ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_string_get_cfstring (in_string, &cfstring); } if (!err) { /* Returned CFComparisonResult is compatible with kim_comparison_t */ *out_comparison = CFStringCompare (cfstring, in_compare_to_cfstring, 0); } if (cfstring) { CFRelease (cfstring); } return check_error (err); }
bool application_is_open(CFStringRef appName, ProcessSerialNumber *psn) { OSStatus status; ProcessSerialNumber currentProcessPSN = {kNoProcess, kNoProcess}; status = GetNextProcess(¤tProcessPSN); while (status == noErr) { CFStringRef processName = NULL; status = CopyProcessName(¤tProcessPSN, &processName); if (status != noErr) die("CopyProcessName failed"); if (NULL == processName) die("CopyProcessName succeeded, but the process name is NULL!"); if (kCFCompareEqualTo == CFStringCompare(processName, appName, 0)) { memcpy(psn, ¤tProcessPSN, sizeof(*psn)); return TRUE; } status = GetNextProcess(¤tProcessPSN); } return FALSE; }
/*! Finds the target object (IOSCSIParallelInterfaceDevice) in the IO registry that * corresponds to the specified target. * @param targetIQN the name of the target. * @return the IO registry object of the IOSCSITargetDevice for this session. */ io_object_t iSCSIIORegistryGetTargetEntry(CFStringRef targetIQN) { if(!targetIQN) return IO_OBJECT_NULL; io_service_t service; if(!(service = iSCSIIORegistryGetiSCSIHBAEntry())) return IO_OBJECT_NULL; // Iterate over the targets and find the specified target by name io_iterator_t iterator = IO_OBJECT_NULL; IORegistryEntryGetChildIterator(service,kIOServicePlane,&iterator); io_object_t entry; while((entry = IOIteratorNext(iterator)) != IO_OBJECT_NULL) { CFDictionaryRef protocolDict = IORegistryEntryCreateCFProperty( entry,CFSTR(kIOPropertyProtocolCharacteristicsKey),kCFAllocatorDefault,0); if(protocolDict) { CFStringRef IQN = CFDictionaryGetValue(protocolDict,CFSTR(kIOPropertyiSCSIQualifiedNameKey)); if(CFStringCompare(IQN,targetIQN,0) == kCFCompareEqualTo) { CFRelease(protocolDict); IOObjectRelease(iterator); return entry; } CFRelease(protocolDict); } IOObjectRelease(entry); } IOObjectRelease(iterator); return IO_OBJECT_NULL; }
size_t bitDepth(CGDisplayModeRef mode) { size_t depth = 0; CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode); // my numerical representation for kIO16BitFloatPixels and kIO32bitFloatPixels // are made up and possibly non-sensical if (kCFCompareEqualTo == CFStringCompare(pixelEncoding, CFSTR(kIO32BitFloatPixels), kCFCompareCaseInsensitive)) { depth = 96; } else if (kCFCompareEqualTo == CFStringCompare(pixelEncoding, CFSTR(kIO64BitDirectPixels), kCFCompareCaseInsensitive)) { depth = 64; } else if (kCFCompareEqualTo == CFStringCompare(pixelEncoding, CFSTR(kIO16BitFloatPixels), kCFCompareCaseInsensitive)) { depth = 48; } else if (kCFCompareEqualTo == CFStringCompare(pixelEncoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive)) { depth = 32; } else if (kCFCompareEqualTo == CFStringCompare(pixelEncoding, CFSTR(kIO30BitDirectPixels), kCFCompareCaseInsensitive)) { depth = 30; } else if (kCFCompareEqualTo == CFStringCompare(pixelEncoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive)) { depth = 16; } else if (kCFCompareEqualTo == CFStringCompare(pixelEncoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive)) { depth = 8; } CFRelease(pixelEncoding); return depth; }
void stringManipulation(void) { CFMutableStringRef strChange; CFStringRef strOuter, find, replace, find2, replace2, find3, replace3, bigger, smaller, result; CFComparisonResult comp; CFLocaleRef curLocale; Boolean isHyphenationSupported = false; show(CFSTR("------------------String Manipulations---------------")); // Create a simple immutable string from a Pascal string and convert it to Unicode strOuter = CFStringCreateWithCString(NULL, "Hello Cruel World", kCFStringEncodingASCII); strChange = CFStringCreateMutableCopy(NULL, CFStringGetLength(strOuter), strOuter); find = CFStringCreateWithCString(NULL, "Cruel", kCFStringEncodingASCII); replace = CFStringCreateWithCString(NULL, "Cool", kCFStringEncodingASCII); find2 = CFStringCreateWithCString(NULL, "Keep", kCFStringEncodingASCII); replace2 = CFStringCreateWithCString(NULL, "Be", kCFStringEncodingASCII); find3 = CFStringCreateWithCString(NULL, "Change.", kCFStringEncodingASCII); replace3 = CFStringCreateWithCString(NULL, "Ball.", kCFStringEncodingASCII); bigger = CFStringCreateWithCString(NULL, "version 2.5", kCFStringEncodingASCII); smaller = CFStringCreateWithCString(NULL, "version 2.0", kCFStringEncodingASCII); show(CFSTR("String Outer : %@"), strOuter); show(CFSTR("String Find : %@"), find); show(CFSTR("String Replace : %@"), replace); CFStringFindAndReplace(strChange, find, replace, CFRangeMake(0, CFStringGetLength(strChange)), 0); show(CFSTR("Replaced : %@"), strChange); CFStringAppendCString(strChange, "! Keep the change.", kCFStringEncodingASCII); show(CFSTR("Appended : %@"), strChange); curLocale = CFLocaleCopyCurrent (); isHyphenationSupported = CFStringIsHyphenationAvailableForLocale(curLocale); show(CFSTR("Is Hyphenation supported for this locale? %@"), ((isHyphenationSupported) ? CFSTR ("Yes") : CFSTR("No"))); CFStringUppercase(strChange, curLocale); show(CFSTR("Upper Cased : %@"), strChange); CFStringLowercase(strChange, curLocale); show(CFSTR("Lower Cased : %@"), strChange); CFStringCapitalize(strChange, curLocale); show(CFSTR("Capitalized : %@"), strChange); CFStringUppercase(strChange, curLocale); show(CFSTR("Up Cased (again) : %@"), strChange); CFStringFindAndReplace(strChange, find2, replace2, CFRangeMake(0, CFStringGetLength(strChange)), 0); show(CFSTR("Replaced? : %@"), strChange); CFStringFindAndReplace(strChange, find2, replace2, CFRangeMake(0, CFStringGetLength(strChange)), kCFCompareCaseInsensitive); show(CFSTR("Case insensitive : %@"), strChange); CFStringCapitalize(strChange, curLocale); show(CFSTR("Capitalized : %@"), strChange); CFStringFindAndReplace(strChange, replace2, find2, CFRangeMake(0, CFStringGetLength(strChange)), kCFCompareAnchored); show(CFSTR("Should Be Unchanged: %@"), strChange); CFStringFindAndReplace(strChange, find3, replace3, CFRangeMake(0, CFStringGetLength(strChange)), kCFCompareAnchored|kCFCompareBackwards); show(CFSTR("Should Be Changed : %@"), strChange); show(CFSTR("Which is bigger %@ or %@?"), bigger, smaller); comp = CFStringCompare(bigger, smaller, 0); result = (comp == kCFCompareGreaterThan) ? bigger : smaller; show(CFSTR("Base Compare Says : %@"), result); comp = CFStringCompare(bigger, smaller, kCFCompareNumerically); result = (comp == kCFCompareGreaterThan) ? bigger : smaller; show(CFSTR("Numerical Compare : %@"), result); CFRelease(curLocale); CFRelease(replace); CFRelease(find); CFRelease(replace2); CFRelease(find2); CFRelease(replace3); CFRelease(find3); CFRelease(bigger); CFRelease(smaller); CFRelease(strChange); }
CFDictionaryRef createDockDescriptionForURL(CFURLRef url) { if (!url) { NSLog(CFSTR("%@"), CFSTR("in copyDockDescriptionForURL in CFGrowlAdditions: Cannot copy Dock description for a NULL URL")); return NULL; } //return NULL for non-file: URLs. CFStringRef scheme = CFURLCopyScheme(url); Boolean isFileURL = (CFStringCompare(scheme, CFSTR("file"), kCFCompareCaseInsensitive) == kCFCompareEqualTo); CFRelease(scheme); if (!isFileURL) return NULL; CFDictionaryRef dict = NULL; CFStringRef path = NULL; CFDataRef aliasData = NULL; FSRef fsref; if (CFURLGetFSRef(url, &fsref)) { AliasHandle alias = NULL; OSStatus err = FSNewAlias(/*fromFile*/ NULL, &fsref, &alias); if (err != noErr) { NSLog(CFSTR("in copyDockDescriptionForURL in CFGrowlAdditions: FSNewAlias for %@ returned %li"), url, (long)err); } else { HLock((Handle)alias); err = FSCopyAliasInfo(alias, /*targetName*/ NULL, /*volumeName*/ NULL, (CFStringRef *)&path, /*whichInfo*/ NULL, /*info*/ NULL); if (err != noErr) { NSLog(CFSTR("in copyDockDescriptionForURL in CFGrowlAdditions: FSCopyAliasInfo for %@ returned %li"), url, (long)err); } aliasData = CFDataCreate(kCFAllocatorDefault, (UInt8 *)*alias, GetHandleSize((Handle)alias)); HUnlock((Handle)alias); DisposeHandle((Handle)alias); } } if (!path) { path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); } if (path || aliasData) { CFMutableDictionaryRef temp = CFDictionaryCreateMutable(kCFAllocatorDefault, /*capacity*/ 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (path) { CFDictionarySetValue(temp, _CFURLStringKey, path); CFRelease(path); int pathStyle = kCFURLPOSIXPathStyle; CFNumberRef pathStyleNum = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pathStyle); CFDictionarySetValue(temp, _CFURLStringTypeKey, pathStyleNum); CFRelease(pathStyleNum); } if (aliasData) { CFDictionarySetValue(temp, _CFURLAliasDataKey, aliasData); CFRelease(aliasData); } dict = temp; } return dict; }
void HostPowerServiceDarwin::checkBatteryCriticalLevel(bool *pfCriticalChanged) { CFTypeRef pBlob = IOPSCopyPowerSourcesInfo(); CFArrayRef pSources = IOPSCopyPowerSourcesList(pBlob); CFDictionaryRef pSource = NULL; const void *psValue; bool result; int powerSource = POWER_SOURCE_OUTLET; bool critical = false; if (CFArrayGetCount(pSources) > 0) { for (int i = 0; i < CFArrayGetCount(pSources); ++i) { pSource = IOPSGetPowerSourceDescription(pBlob, CFArrayGetValueAtIndex(pSources, i)); /* If the source is empty skip over to the next one. */ if (!pSource) continue; /* Skip all power sources which are currently not present like a * second battery. */ if (CFDictionaryGetValue(pSource, CFSTR(kIOPSIsPresentKey)) == kCFBooleanFalse) continue; /* Only internal power types are of interest. */ result = CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSTransportTypeKey), &psValue); if (result && CFStringCompare((CFStringRef)psValue, CFSTR(kIOPSInternalType), 0) == kCFCompareEqualTo) { /* First check which power source we are connect on. */ result = CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSPowerSourceStateKey), &psValue); if (result && CFStringCompare((CFStringRef)psValue, CFSTR(kIOPSACPowerValue), 0) == kCFCompareEqualTo) powerSource = POWER_SOURCE_OUTLET; else if (result && CFStringCompare((CFStringRef)psValue, CFSTR(kIOPSBatteryPowerValue), 0) == kCFCompareEqualTo) powerSource = POWER_SOURCE_BATTERY; int curCapacity = 0; int maxCapacity = 1; float remCapacity = 0.0f; /* Fetch the current capacity value of the power source */ result = CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSCurrentCapacityKey), &psValue); if (result) CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &curCapacity); /* Fetch the maximum capacity value of the power source */ result = CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSMaxCapacityKey), &psValue); if (result) CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &maxCapacity); /* Calculate the remaining capacity in percent */ remCapacity = ((float)curCapacity/(float)maxCapacity * 100.0); /* Check for critical. 5 percent is default. */ int criticalValue = 5; result = CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSDeadWarnLevelKey), &psValue); if (result) CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &criticalValue); critical = (remCapacity < criticalValue); /* We have to take action only if we are on battery, the * previous state wasn't critical, the state has changed & the * user requested that info. */ if (powerSource == POWER_SOURCE_BATTERY && mCritical == false && mCritical != critical && pfCriticalChanged) *pfCriticalChanged = true; Log(("checkBatteryCriticalLevel: Remains: %d.%d%% Critical: %d Critical State Changed: %d\n", (int)remCapacity, (int)(remCapacity * 10) % 10, critical, pfCriticalChanged?*pfCriticalChanged:-1)); } } } /* Save the new state */ mCritical = critical; CFRelease(pBlob); CFRelease(pSources); }
CFStreamError _CFStreamErrorFromCFError(CFErrorRef err) { CFStreamError error = { 0, 0 }; error.error = CFErrorGetCode(err); CFStringRef domain = CFErrorGetDomain(err); if (CFStringCompare(domain, CFStreamErrorDomainPOSIX, 0)) { error.domain = kCFStreamErrorDomainPOSIX; } else if (CFStringCompare(domain, CFStreamErrorDomainFTP, 0)) { error.domain = kCFStreamErrorDomainFTP; } else if (CFStringCompare(domain, CFStreamErrorDomainNetDB, 0)) { error.domain = kCFStreamErrorDomainNetDB; } else if (CFStringCompare(domain, CFStreamErrorDomainSystemConfiguration, 0)) { error.domain = kCFStreamErrorDomainSystemConfiguration; } else if (CFStringCompare(domain, CFStreamErrorDomainHTTP, 0)) { error.domain = kCFStreamErrorDomainHTTP; } else if (CFStringCompare(domain, CFStreamErrorDomainMach, 0)) { error.domain = kCFStreamErrorDomainMach; } else if (CFStringCompare(domain, CFStreamErrorDomainNetServices, 0)) { error.domain = kCFStreamErrorDomainNetServices; } else if (CFStringCompare(domain, CFStreamErrorDomainSOCKS, 0)) { error.domain = kCFStreamErrorDomainSOCKS; } else if (CFStringCompare(domain, CFStreamErrorDomainSSL, 0)) { error.domain = kCFStreamErrorDomainSSL; } else if (CFStringCompare(domain, CFStreamErrorDomainMacOSStatus, 0)) { error.domain = kCFStreamErrorDomainMacOSStatus; } else if (CFStringCompare(domain, CFStreamErrorDomainCustom, 0)) { error.domain = kCFStreamErrorDomainCustom; } return error; }
static CFComparisonResult compareDomain(const void *val1, const void *val2, void *context) { CFDictionaryRef proxy1 = (CFDictionaryRef)val1; CFDictionaryRef proxy2 = (CFDictionaryRef)val2; CFStringRef domain1; CFStringRef domain2; CFArrayRef labels1 = NULL; CFArrayRef labels2 = NULL; CFIndex n1; CFIndex n2; CFComparisonResult result; Boolean rev1; Boolean rev2; // "default" domains sort before "supplemental" domains domain1 = CFDictionaryGetValue(proxy1, kSCPropNetProxiesSupplementalMatchDomain); domain2 = CFDictionaryGetValue(proxy2, kSCPropNetProxiesSupplementalMatchDomain); if (domain1 == NULL) { if (domain2 == NULL) { return kCFCompareEqualTo; } return kCFCompareLessThan; } else if (domain2 == NULL) { return kCFCompareGreaterThan; } // forward (A, AAAA) domains sort before reverse (PTR) domains rev1 = CFStringHasSuffix(domain1, CFSTR(".arpa")); rev2 = CFStringHasSuffix(domain2, CFSTR(".arpa")); if (rev1 != rev2) { if (rev1) { return kCFCompareGreaterThan; } else { return kCFCompareLessThan; } } labels1 = CFStringCreateArrayBySeparatingStrings(NULL, domain1, CFSTR(".")); n1 = CFArrayGetCount(labels1); labels2 = CFStringCreateArrayBySeparatingStrings(NULL, domain2, CFSTR(".")); n2 = CFArrayGetCount(labels2); while ((n1 > 0) && (n2 > 0)) { CFStringRef label1 = CFArrayGetValueAtIndex(labels1, --n1); CFStringRef label2 = CFArrayGetValueAtIndex(labels2, --n2); // compare domain labels result = CFStringCompare(label1, label2, kCFCompareCaseInsensitive); if (result != kCFCompareEqualTo) { goto done; } } // longer labels (corp.apple.com) sort before shorter labels (apple.com) if (n1 > n2) { result = kCFCompareLessThan; goto done; } else if (n1 < n2) { result = kCFCompareGreaterThan; goto done; } // sort by search order result = compareBySearchOrder(val1, val2, context); done : if (labels1 != NULL) CFRelease(labels1); if (labels2 != NULL) CFRelease(labels2); return result; }