static CFStringRef copy_localized_string(CFBundleRef bundle, CFStringRef ethernet_str, CFStringRef airport_str, CFTypeRef ssid) { CFStringRef str = NULL; if (ssid != NULL) { CFStringRef format; format = CFBundleCopyLocalizedString(bundle, airport_str, airport_str, NULL); if (format != NULL) { str = CFStringCreateWithFormat(NULL, NULL, format, ssid); CFRelease(format); } } else { str = CFBundleCopyLocalizedString(bundle, ethernet_str, ethernet_str, NULL); } if (str == NULL) { str = CFRetain(ethernet_str); } return (str); }
/* ----------------------------------------------------------------------------- plugin entry point, called by pppd ----------------------------------------------------------------------------- */ int start(CFBundleRef ref) { CFStringRef strref; CFURLRef urlref; bundle = ref; CFRetain(bundle); url = CFBundleCopyBundleURL(bundle); // hookup our handlers old_check_options = the_channel->check_options; the_channel->check_options = serial_check_options; old_connect = the_channel->connect; the_channel->connect = serial_connect; old_process_extra_options = the_channel->process_extra_options; the_channel->process_extra_options = serial_process_extra_options; add_notifier(&connect_fail_notify, serial_connect_notifier, 0); add_notifier(&lcp_lowerdown_notify, serial_lcpdown_notifier, 0); cancelstrref = CFBundleCopyLocalizedString(bundle, CFSTR("Cancel"), CFSTR("Cancel"), NULL); if (cancelstrref == 0) return 1; CFStringGetCString(cancelstrref, (char*)cancelstr, sizeof(cancelstr), kCFStringEncodingUTF8); icstrref = CFBundleCopyLocalizedString(bundle, CFSTR("Network Connection"), CFSTR("Network Connection"), NULL); if (icstrref == 0) return 1; CFStringGetCString(icstrref, (char*)icstr, sizeof(icstr), kCFStringEncodingUTF8); urlref = CFBundleCopyResourceURL(bundle, CFSTR("NetworkConnect.icns"), NULL, NULL); if (urlref == 0 || ((strref = CFURLGetString(urlref)) == 0)) { if (urlref) CFRelease(urlref); return 1; } CFStringGetCString(strref, (char*)iconstr, sizeof(iconstr), kCFStringEncodingUTF8); iconstrref = CFStringCreateCopy(NULL, strref); CFRelease(urlref); urlref = CFBundleCopyBuiltInPlugInsURL(bundle); if (urlref == 0 || ((CFURLGetFileSystemRepresentation(urlref, TRUE, pathccl, sizeof(pathccl))) == FALSE)) { if (urlref) CFRelease(urlref); return 1; } strlcat((char*)pathccl, SUFFIX_CCLENGINE, sizeof(pathccl)); CFRelease(urlref); // add the socket specific options add_options(serial_options); return 0; }
REString localized(const char * s) { REString resString; if (s && _localizedTableName && _localizedBundle) { CFStringRef key = CFStringCreateWithCString(NULL, s ,kCFStringEncodingUTF8); if (key) { CFStringRef loc = CFBundleCopyLocalizedString(_localizedBundle, key, key, _localizedTableName); if (loc) { const size_t buffSize = 512 * sizeof(wchar_t); char buff[buffSize] = { 0 }; if (CFStringGetCString(loc, buff, buffSize, kCFStringEncodingUTF8)) { resString = buff; } CFRelease(loc); } CFRelease(key); } } if (resString.isEmpty()) resString = s; return resString; }
static_inline const char * _intlize(const char *msg, int base, char *str, size_t len) { char domain[12 +20]; CFStringRef cfstring = CFStringCreateWithCString(kCFAllocatorSystemDefault, msg, kCFStringEncodingUTF8); CFStringRef cfdomain; CFBundleRef OpenAFSBundle = CFBundleGetBundleWithIdentifier(CFSTR("org.openafs.filesystems.afs")); if (!str) { CFRelease(cfstring); return msg; } snprintf(domain, sizeof(domain), "heim_com_err%d", base); cfdomain = CFStringCreateWithCString(kCFAllocatorSystemDefault, domain, kCFStringEncodingUTF8); if (OpenAFSBundle != NULL) { CFStringRef cflocal; cflocal = CFBundleCopyLocalizedString(OpenAFSBundle, cfstring, cfstring, cfdomain); CFStringGetCString(cflocal, str, len, kCFStringEncodingUTF8); CFRelease(cflocal); } else { CFStringGetCString(cfstring, str, len, kCFStringEncodingUTF8); } CFRelease(cfstring); CFRelease(cfdomain); return str; }
// --------------------------------------------------------------------------- // // ----------- void strget(const char* msg_id, char* string){ CFBundleRef bndl=CFBundleGetBundleWithIdentifier(CFSTR("com.cbconseil.macmapsuite.framework")); CFStringRef cfid=CFStringCreateWithCString(kCFAllocatorDefault,msg_id,kCFStringEncodingMacRoman); CFStringRef msg=CFBundleCopyLocalizedString(bndl,cfid,CFSTR("MESSAGES"),NULL); string[0]=0; CFRelease(cfid); if(!msg){ return; } CFStringGetCString(msg,string,256,kCFStringEncodingMacRoman); CFRelease(msg); }
static CFStringRef _CFCopyLocalizedVersionKey(CFBundleRef *bundlePtr, CFStringRef nonLocalized) { CFStringRef localized = NULL; CFBundleRef locBundle = bundlePtr ? *bundlePtr : NULL; if (!locBundle) { CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, CFSTR("/System/Library/CoreServices/SystemVersion.bundle"), kCFURLPOSIXPathStyle, false); if (url) { locBundle = CFBundleCreate(kCFAllocatorSystemDefault, url); CFRelease(url); } } if (locBundle) { localized = CFBundleCopyLocalizedString(locBundle, nonLocalized, nonLocalized, CFSTR("SystemVersion")); if (bundlePtr) *bundlePtr = locBundle; else CFRelease(locBundle); } return localized ? localized : (CFStringRef)CFRetain(nonLocalized); }
/* Built-in callback for POSIX domain. Note that we will pick up localizations from ErrnoErrors.strings in /System/Library/CoreServices/CoreTypes.bundle, if the file happens to be there. */ static CFTypeRef _CFErrorPOSIXCallBack(CFErrorRef err, CFStringRef key) { if (!CFEqual(key, kCFErrorDescriptionKey) && !CFEqual(key, kCFErrorLocalizedFailureReasonKey)) return NULL; const char *errCStr = strerror(CFErrorGetCode(err)); CFStringRef errStr = (errCStr && strlen(errCStr)) ? CFStringCreateWithCString(kCFAllocatorSystemDefault, errCStr, kCFStringEncodingUTF8) : NULL; if (!errStr) return NULL; if (CFEqual(key, kCFErrorDescriptionKey)) return errStr; // If all we wanted was the non-localized description, we're done #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS // We need a kCFErrorLocalizedFailureReasonKey, so look up a possible localization for the error message // Look for the bundle in /System/Library/CoreServices/CoreTypes.bundle CFArrayRef paths = CFCopySearchPathForDirectoriesInDomains(kCFLibraryDirectory, kCFSystemDomainMask, false); if (paths) { if (CFArrayGetCount(paths) > 0) { CFStringRef path = CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("%@/CoreServices/CoreTypes.bundle"), CFArrayGetValueAtIndex(paths, 0)); CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, path, kCFURLPOSIXPathStyle, false /* not a directory */); if (url) { CFBundleRef bundle = CFBundleCreate(kCFAllocatorSystemDefault, url); if (bundle) { // We only want to return a result if there was a localization CFStringRef localizedErrStr = CFBundleCopyLocalizedString(bundle, errStr, errStr, CFSTR("ErrnoErrors")); if (localizedErrStr == errStr) { CFRelease(localizedErrStr); CFRelease(errStr); errStr = NULL; } else { CFRelease(errStr); errStr = localizedErrStr; } CFRelease(bundle); } CFRelease(url); } CFRelease(path); } CFRelease(paths); } #endif return errStr; }
CFStringRef SCNetworkSetGetName(SCNetworkSetRef set) { CFBundleRef bundle; CFDictionaryRef entity; CFStringRef path; SCNetworkSetPrivateRef setPrivate = (SCNetworkSetPrivateRef)set; if (!isA_SCNetworkSet(set)) { _SCErrorSet(kSCStatusInvalidArgument); return NULL; } if (setPrivate->name != NULL) { return setPrivate->name; } path = SCPreferencesPathKeyCreateSet(NULL, setPrivate->setID); entity = SCPreferencesPathGetValue(setPrivate->prefs, path); CFRelease(path); if (isA_CFDictionary(entity)) { CFStringRef name; name = CFDictionaryGetValue(entity, kSCPropUserDefinedName); if (isA_CFString(name)) { setPrivate->name = CFRetain(name); } } bundle = _SC_CFBundleGet(); if (bundle != NULL) { if (setPrivate->name != NULL) { CFStringRef non_localized; non_localized = _SC_CFBundleCopyNonLocalizedString(bundle, CFSTR("DEFAULT_SET_NAME"), CFSTR("Automatic"), NULL); if (non_localized != NULL) { if (CFEqual(setPrivate->name, non_localized)) { CFStringRef localized; // if "Automatic", return localized name localized = CFBundleCopyLocalizedString(bundle, CFSTR("DEFAULT_SET_NAME"), CFSTR("Automatic"), NULL); if (localized != NULL) { CFRelease(setPrivate->name); setPrivate->name = localized; } } CFRelease(non_localized); } } } return setPrivate->name; }
Boolean SCNetworkSetSetName(SCNetworkSetRef set, CFStringRef name) { CFBundleRef bundle = NULL; CFDictionaryRef entity; CFStringRef localized = NULL; CFStringRef non_localized = NULL; Boolean ok = FALSE; CFStringRef path; SCNetworkSetPrivateRef setPrivate = (SCNetworkSetPrivateRef)set; if (!isA_SCNetworkSet(set)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } if ((name != NULL) && !isA_CFString(name)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } // if known, compare against localized name if (name != NULL) { bundle = _SC_CFBundleGet(); if (bundle != NULL) { non_localized = _SC_CFBundleCopyNonLocalizedString(bundle, CFSTR("DEFAULT_SET_NAME"), CFSTR("Automatic"), NULL); if (non_localized != NULL) { if (CFEqual(name, non_localized)) { localized = CFBundleCopyLocalizedString(bundle, CFSTR("DEFAULT_SET_NAME"), CFSTR("Automatic"), NULL); if (localized != NULL) { name = localized; } } } } } #define PREVENT_DUPLICATE_SET_NAMES #ifdef PREVENT_DUPLICATE_SET_NAMES if (name != NULL) { CFArrayRef sets; // ensure that each set is uniquely named sets = SCNetworkSetCopyAll(setPrivate->prefs); if (sets != NULL) { CFIndex i; CFIndex n; n = CFArrayGetCount(sets); for (i = 0; i < n; i++) { CFStringRef otherID; CFStringRef otherName; SCNetworkSetRef set = CFArrayGetValueAtIndex(sets, i); otherID = SCNetworkSetGetSetID(set); if (CFEqual(setPrivate->setID, otherID)) { continue; // skip current set } otherName = SCNetworkSetGetName(set); if ((otherName != NULL) && CFEqual(name, otherName)) { // if "name" not unique CFRelease(sets); _SCErrorSet(kSCStatusKeyExists); goto done; } } CFRelease(sets); } } #endif /* PREVENT_DUPLICATE_SET_NAMES */ // if known, store non-localized name if ((name != NULL) && (bundle != NULL) && (non_localized != NULL)) { if (localized == NULL) { localized = CFBundleCopyLocalizedString(bundle, CFSTR("DEFAULT_SET_NAME"), CFSTR("Automatic"), NULL); } if (localized != NULL) { if (CFEqual(name, localized)) { name = non_localized; } } } // update the "name" path = SCPreferencesPathKeyCreateSet(NULL, setPrivate->setID); entity = SCPreferencesPathGetValue(setPrivate->prefs, path); if (isA_CFDictionary(entity) || ((entity == NULL) && (name != NULL))) { CFMutableDictionaryRef newEntity; if (entity != NULL) { newEntity = CFDictionaryCreateMutableCopy(NULL, 0, entity); } else { newEntity = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } if (name != NULL) { CFDictionarySetValue(newEntity, kSCPropUserDefinedName, name); } else { CFDictionaryRemoveValue(newEntity, kSCPropUserDefinedName); } ok = SCPreferencesPathSetValue(setPrivate->prefs, path, newEntity); CFRelease(newEntity); } CFRelease(path); done : if (localized != NULL) CFRelease(localized); if (non_localized != NULL) CFRelease(non_localized); return ok; }
static void _INXCancelStringInit() { CFBundleRef UIKitBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.UIKit")); if (UIKitBundle != NULL) _INXCancelString = CFBundleCopyLocalizedString(UIKitBundle, CFSTR("Cancel"), NULL, NULL); }
static Boolean establishNewPreferences() { CFBundleRef bundle; SCNetworkSetRef current = NULL; CFStringRef new_model; Boolean ok = FALSE; int sc_status = kSCStatusFailed; SCNetworkSetRef set = NULL; CFStringRef setName = NULL; Boolean updated = FALSE; while (TRUE) { ok = SCPreferencesLock(prefs, TRUE); if (ok) { break; } sc_status = SCError(); if (sc_status == kSCStatusStale) { SCPreferencesSynchronize(prefs); } else { SCLog(TRUE, LOG_ERR, CFSTR("Could not acquire network configuration lock: %s"), SCErrorString(sc_status)); return FALSE; } } /* Ensure that the preferences has the new model */ new_model = _SC_hw_model(FALSE); /* Need to regenerate the new configuration for new model */ if (new_model != NULL) { CFStringRef old_model; old_model = SCPreferencesGetValue(prefs, MODEL); if ((old_model != NULL) && !_SC_CFEqual(old_model, new_model)) { CFIndex count; CFIndex index; CFArrayRef keys; keys = SCPreferencesCopyKeyList(prefs); count = (keys != NULL) ? CFArrayGetCount(keys) : 0; // if new hardware for (index = 0; index < count; index++) { CFStringRef existing_key; existing_key = CFArrayGetValueAtIndex(keys, index); if (isA_CFString(existing_key) != NULL) { CFStringRef new_key; CFPropertyListRef value; /* If it already contains a Model or if it already contains a MODEL:KEY key skip it*/ if (CFEqual(existing_key, MODEL) || CFStringFind(existing_key, CFSTR(":"), 0).location != kCFNotFound) { continue; } value = SCPreferencesGetValue(prefs, existing_key); /* Create a new key as OLD_MODEL:OLD_KEY */ new_key = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@:%@"), old_model, existing_key); SCPreferencesSetValue(prefs, new_key, value); if (!CFEqual(existing_key, kSCPrefSystem)) { /* preserve existing host names */ SCPreferencesRemoveValue(prefs, existing_key); } CFRelease(new_key); } } if (keys != NULL) { CFRelease(keys); } } /* Set the new model */ SCPreferencesSetValue(prefs, MODEL, new_model); } current = SCNetworkSetCopyCurrent(prefs); if (current != NULL) { set = current; } if (set == NULL) { set = SCNetworkSetCreate(prefs); if (set == NULL) { ok = FALSE; sc_status = SCError(); goto done; } bundle = _SC_CFBundleGet(); if (bundle != NULL) { setName = CFBundleCopyLocalizedString(bundle, CFSTR("DEFAULT_SET_NAME"), CFSTR("Automatic"), NULL); } ok = SCNetworkSetSetName(set, (setName != NULL) ? setName : CFSTR("Automatic")); if (!ok) { sc_status = SCError(); goto done; } ok = SCNetworkSetSetCurrent(set); if (!ok) { sc_status = SCError(); goto done; } } ok = SCNetworkSetEstablishDefaultConfiguration(set); if (!ok) { sc_status = SCError(); goto done; } done : if (ok) { ok = SCPreferencesCommitChanges(prefs); if (ok) { SCLog(TRUE, LOG_NOTICE, CFSTR("New network configuration saved")); updated = TRUE; } else { sc_status = SCError(); if (sc_status == EROFS) { /* a read-only fileysstem is OK */ ok = TRUE; /* ... but we don't want to synchronize */ rofs = TRUE; } } /* apply (committed or temporary/read-only) changes */ (void) SCPreferencesApplyChanges(prefs); } else if ((current == NULL) && (set != NULL)) { (void) SCNetworkSetRemove(set); } if (!ok) { SCLog(TRUE, LOG_ERR, CFSTR("Could not establish network configuration: %s"), SCErrorString(sc_status)); } (void)SCPreferencesUnlock(prefs); if (setName != NULL) CFRelease(setName); if (set != NULL) CFRelease(set); return updated; }