static CFStringRef __CFArrayCopyDescription(CFTypeRef cf) {
    CFArrayRef array = (CFArrayRef)cf;
    CFMutableStringRef result;
    const CFArrayCallBacks *cb;
    CFAllocatorRef allocator;
    CFIndex idx, cnt;
    cnt = __CFArrayGetCount(array);
    allocator = CFGetAllocator(array);
    result = CFStringCreateMutable(allocator, 0);
    switch (__CFArrayGetType(array)) {
    case __kCFArrayImmutable:
	CFStringAppendFormat(result, NULL, CFSTR("<CFArray %p [%p]>{type = immutable, count = %lu, values = (%s"), cf, allocator, (unsigned long)cnt, cnt ? "\n" : "");
	break;
    case __kCFArrayDeque:
	CFStringAppendFormat(result, NULL, CFSTR("<CFArray %p [%p]>{type = mutable-small, count = %lu, values = (%s"), cf, allocator, (unsigned long)cnt, cnt ? "\n" : "");
	break;
    }
    cb = __CFArrayGetCallBacks(array);
    for (idx = 0; idx < cnt; idx++) {
	CFStringRef desc = NULL;
	const void *val = __CFArrayGetBucketAtIndex(array, idx)->_item;
	if (NULL != cb->copyDescription) {
	    desc = (CFStringRef)INVOKE_CALLBACK1(cb->copyDescription, val);
	}
	if (NULL != desc) {
	    CFStringAppendFormat(result, NULL, CFSTR("\t%lu : %@\n"), (unsigned long)idx, desc);
	    CFRelease(desc);
	} else {
	    CFStringAppendFormat(result, NULL, CFSTR("\t%lu : <%p>\n"), (unsigned long)idx, val);
	}
    }
    CFStringAppend(result, CFSTR(")}"));
    return result;
}
static CFStringRef
rlsCopyDescription(const void *info)
{
	CFMutableStringRef		result;
	SCDynamicStoreRef		store		= (SCDynamicStoreRef)info;
	SCDynamicStorePrivateRef	storePrivate	= (SCDynamicStorePrivateRef)store;

	result = CFStringCreateMutable(NULL, 0);
	CFStringAppendFormat(result, NULL, CFSTR("<SCDynamicStore RLS> {"));
	CFStringAppendFormat(result, NULL, CFSTR("store = %p"), store);
	if (storePrivate->notifyStatus == Using_NotifierInformViaRunLoop) {
		CFStringRef	description	= NULL;

		CFStringAppendFormat(result, NULL, CFSTR(", callout = %p"), storePrivate->rlsFunction);

		if ((storePrivate->rlsContext.info != NULL) && (storePrivate->rlsContext.copyDescription != NULL)) {
			description = (*storePrivate->rlsContext.copyDescription)(storePrivate->rlsContext.info);
		}
		if (description == NULL) {
			description = CFStringCreateWithFormat(NULL, NULL, CFSTR("<SCDynamicStore context %p>"), storePrivate->rlsContext.info);
		}
		if (description == NULL) {
			description = CFRetain(CFSTR("<no description>"));
		}
		CFStringAppendFormat(result, NULL, CFSTR(", context = %@"), description);
		CFRelease(description);
	}
	CFStringAppendFormat(result, NULL, CFSTR("}"));

	return result;
}
Exemple #3
0
__private_extern__
void
ipv6_duplicated_address(const char * if_name, const struct in6_addr * addr,
			int hw_len, const void * hw_addr)
{
	uint8_t	*		hw_addr_bytes = (uint8_t *)hw_addr;
	int			i;
	CFStringRef		if_name_cf;
	CFMutableStringRef	key;
	char			ntopbuf[INET6_ADDRSTRLEN];
	CFStringRef		prefix;

	if_name_cf = CFStringCreateWithCString(NULL, if_name,
					       kCFStringEncodingASCII);
	prefix = SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL,
							       kSCDynamicStoreDomainState,
							       if_name_cf,
							       kSCEntNetIPv6DuplicatedAddress);
	ntopbuf[0] = '\0';
	(void)inet_ntop(AF_INET6, addr, ntopbuf, sizeof(ntopbuf));
	key = CFStringCreateMutableCopy(NULL, 0, prefix);
	CFStringAppendFormat(key, NULL, CFSTR("/%s"), ntopbuf);
	for (i = 0; i < hw_len; i++) {
	    CFStringAppendFormat(key, NULL, CFSTR("%s%02x"),
				 (i == 0) ? "/" : ":", hw_addr_bytes[i]);
	}
	cache_SCDynamicStoreNotifyValue(store, key);
	CFRelease(key);
	CFRelease(prefix);
	CFRelease(if_name_cf);
}
Exemple #4
0
static CFStringRef __CFSetCopyDescription(CFTypeRef cf) {
    CFSetRef set = (CFSetRef)cf;
    const CFSetCallBacks *cb;
    const struct __CFSetBucket *buckets;
    CFIndex idx, nbuckets;
    CFMutableStringRef result;
    cb = __CFSetGetCallBacks(set);
    buckets = set->_buckets;
    nbuckets = set->_bucketsNum;
    result = CFStringCreateMutable(kCFAllocatorSystemDefault, 0);
    CFStringAppendFormat(result, NULL, CFSTR("<CFSet %p [%p]>{count = %u, capacity = %u, values = (\n"), set, CFGetAllocator(set), set->_count, set->_capacity);
    for (idx = 0; idx < nbuckets; idx++) {
	if (__CFSetBucketIsOccupied(set, &buckets[idx])) {
	    CFStringRef desc = NULL;
	    if (NULL != cb->copyDescription) {
		desc = (CFStringRef)INVOKE_CALLBACK2(((CFStringRef (*)(const void *, void *))cb->copyDescription), buckets[idx]._key, set->_context);
	    }
	    if (NULL != desc) {
		CFStringAppendFormat(result, NULL, CFSTR("\t%u : %@\n"), idx, desc, NULL);
		CFRelease(desc);
	    } else {
		CFStringAppendFormat(result, NULL, CFSTR("\t%u : <%p>\n"), idx, buckets[idx]._key, NULL);
	    }
	}
    }
    CFStringAppend(result, CFSTR(")}"));
    return result;
}
Exemple #5
0
static VALUE
format_message(VALUE exc)
{
    CFMutableStringRef result = CFStringCreateMutable(NULL, 0);
    VALUE message = rb_vm_call(exc, sel_registerName("message"), 0, NULL);
    VALUE bt = rb_vm_call(exc, sel_registerName("backtrace"), 0, NULL);

    message = rb_check_string_type(message);
    const char *msg = message == Qnil ? "" : RSTRING_PTR(message);

    const long count = (bt != Qnil ? RARRAY_LEN(bt) : 0);
    if (count > 0) {
	for (long i = 0; i < count; i++) {
	    const char *bte = RSTRING_PTR(RARRAY_AT(bt, i));
	    if (i == 0) {
		CFStringAppendFormat(result, NULL, CFSTR("%s: %s (%s)\n"),
		    bte, msg, rb_class2name(*(VALUE *)exc));
	    }
	    else {
		CFStringAppendFormat(result, NULL, CFSTR("\tfrom %s\n"), bte);
	    }
	}
    }
    else {
	CFStringAppendFormat(result, NULL, CFSTR("%s (%s)\n"),
	    msg, rb_class2name(*(VALUE *)exc));
    }
    CFMakeCollectable(result);
    return (VALUE)result;
}
Exemple #6
0
static CFStringRef __CFBinaryHeapCopyDescription(CFTypeRef cf) {
    CFBinaryHeapRef heap = (CFBinaryHeapRef)cf;
    CFMutableStringRef result;
    CFIndex idx;
    CFIndex cnt;
    const void **list, *buffer[256];
    cnt = __CFBinaryHeapCount(heap);
    result = CFStringCreateMutable(CFGetAllocator(heap), 0);
    CFStringAppendFormat(result, NULL, CFSTR("<CFBinaryHeap %p [%p]>{count = %lu, capacity = %lu, objects = (\n"), cf, CFGetAllocator(heap), (unsigned long)cnt, (unsigned long)__CFBinaryHeapCapacity(heap));
    list = (cnt <= 128) ? (const void **)buffer : (const void **)CFAllocatorAllocate(kCFAllocatorSystemDefault, cnt * sizeof(void *), 0); // GC OK
    if (__CFOASafe && list != buffer) __CFSetLastAllocationEventName(list, "CFBinaryHeap (temp)");
    CFBinaryHeapGetValues(heap, list);
    for (idx = 0; idx < cnt; idx++) {
	CFStringRef desc = NULL;
	const void *item = list[idx];
	if (NULL != heap->_callbacks.copyDescription) {
	    desc = heap->_callbacks.copyDescription(item);
	}
	if (NULL != desc) {
	    CFStringAppendFormat(result, NULL, CFSTR("\t%lu : %@\n"), (unsigned long)idx, desc);
	    CFRelease(desc);
	} else {
	    CFStringAppendFormat(result, NULL, CFSTR("\t%lu : <%p>\n"), (unsigned long)idx, item);
	}
    }
    CFStringAppend(result, CFSTR(")}"));
    if (list != buffer) CFAllocatorDeallocate(CFGetAllocator(heap), list); // GC OK
    return result;
}
static CFStringRef __CFDataCopyDescription(CFTypeRef cf) {
    CFDataRef data = (CFDataRef)cf;
    CFMutableStringRef result;
    CFIndex idx;
    CFIndex len;
    const uint8_t *bytes;
    len = __CFDataLength(data);
    bytes = CFDataGetBytePtr(data);
    result = CFStringCreateMutable(CFGetAllocator(data), 0);
    CFStringAppendFormat(result, NULL, CFSTR("<CFData %p [%p]>{length = %u, capacity = %u, bytes = 0x"), cf, CFGetAllocator(data), len, __CFDataCapacity(data));
    if (24 < len) {
        for (idx = 0; idx < 16; idx += 4) {
	    CFStringAppendFormat(result, NULL, CFSTR("%02x%02x%02x%02x"), bytes[idx], bytes[idx + 1], bytes[idx + 2], bytes[idx + 3]);
	}
        CFStringAppend(result, CFSTR(" ... "));
        for (idx = len - 8; idx < len; idx += 4) {
	    CFStringAppendFormat(result, NULL, CFSTR("%02x%02x%02x%02x"), bytes[idx], bytes[idx + 1], bytes[idx + 2], bytes[idx + 3]);
	}
    } else {
        for (idx = 0; idx < len; idx++) {
	    CFStringAppendFormat(result, NULL, CFSTR("%02x"), bytes[idx]);
	}
    }
    CFStringAppend(result, CFSTR("}"));
    return result;
}
Exemple #8
0
static void CGPathToCFStringApplierFunction(void* info, const CGPathElement *element)
{
    CFMutableStringRef string = (CFMutableStringRef)info;
    CFStringRef typeString = CFSTR("");
    CGPoint* points = element->points;
    switch (element->type) {
    case kCGPathElementMoveToPoint:
        CFStringAppendFormat(string, 0, CFSTR("M%.2f,%.2f "), points[0].x, points[0].y);
        break;
    case kCGPathElementAddLineToPoint:
        CFStringAppendFormat(string, 0, CFSTR("L%.2f,%.2f "), points[0].x, points[0].y);
        break;
    case kCGPathElementAddQuadCurveToPoint:
        CFStringAppendFormat(string, 0, CFSTR("Q%.2f,%.2f,%.2f,%.2f "),
                points[0].x, points[0].y, points[1].x, points[1].y);
        break;
    case kCGPathElementAddCurveToPoint:
        CFStringAppendFormat(string, 0, CFSTR("C%.2f,%.2f,%.2f,%.2f,%.2f,%.2f "),
                points[0].x, points[0].y, points[1].x, points[1].y,
                points[2].x, points[2].y);
        break;
    case kCGPathElementCloseSubpath:
        typeString = CFSTR("X"); break;
    }
}
Exemple #9
0
/* The "debug" description, used by CFCopyDescription and -[NSObject description].
 */
CFStringRef _CFErrorCreateDebugDescription(CFErrorRef err) {
    CFMutableStringRef result = CFStringCreateMutable(
        kCFAllocatorSystemDefault, 0);
    CFStringAppendFormat(
        result, NULL,
        CFSTR("Error Domain=%@ Code=%d"),
        CFErrorGetDomain(err), (int)CFErrorGetCode(err));

    CFDictionaryRef userInfo = _CFErrorGetUserInfo(err);
    if (userInfo) {
        CFStringAppendFormat(result, NULL, CFSTR(" UserInfo=%p"), userInfo);
    }

    CFStringRef desc = CFErrorCopyDescription(err);
    if (desc) {
        CFStringAppendFormat(result, NULL, CFSTR(" \"%@\""), desc);
        CFRelease(desc);
    }

    CFStringRef debugDesc = _CFErrorCopyUserInfoKey(err, kCFErrorDebugDescriptionKey);
    if (debugDesc) {
        if (CFStringGetLength(debugDesc) > 0) {
            CFStringAppendFormat(result, NULL, CFSTR(" (%@)"), debugDesc);
        }
        CFRelease(debugDesc);
    }

    return result;
}
Exemple #10
0
CFStringRef SOSInterestListCopyDescription(CFArrayRef interests)
{
    CFMutableStringRef description = CFStringCreateMutable(kCFAllocatorDefault, 0);
    CFStringAppendFormat(description, NULL, CFSTR("<Interest: "));
    
    CFArrayForEach(interests, ^(const void* string) {
        if (isString(string))
            CFStringAppendFormat(description, NULL, CFSTR(" '%@'"), string);
    });
Exemple #11
0
/* The "debug" description, used by CFCopyDescription and -[NSObject description].
*/
static void userInfoKeyValueShow(const void *key, const void *value, void *context) {
    CFStringRef desc;
    if (CFEqual(key, kCFErrorUnderlyingErrorKey) && (desc = CFErrorCopyDescription((CFErrorRef)value))) {	// We check desc, see <rdar://problem/8415727>
	CFStringAppendFormat((CFMutableStringRef)context, NULL, CFSTR("%@=%p \"%@\", "), key, value, desc); 
	CFRelease(desc);
    } else {
	CFStringAppendFormat((CFMutableStringRef)context, NULL, CFSTR("%@=%@, "), key, value); 
    }
}
Exemple #12
0
static CFStringRef
__SCPreferencesCopyDescription(CFTypeRef cf) {
	CFAllocatorRef		allocator	= CFGetAllocator(cf);
	SCPreferencesPrivateRef prefsPrivate	= (SCPreferencesPrivateRef)cf;
	CFMutableStringRef	result;

	result = CFStringCreateMutable(allocator, 0);
	CFStringAppendFormat(result, NULL, CFSTR("<SCPreferences %p [%p]> {"), cf, allocator);
	CFStringAppendFormat(result, NULL, CFSTR("name = %@"), prefsPrivate->name);
	CFStringAppendFormat(result, NULL, CFSTR(", id = %@"), prefsPrivate->prefsID);
	CFStringAppendFormat(result, NULL, CFSTR(", path = %s"),
			     prefsPrivate->newPath ? prefsPrivate->newPath : prefsPrivate->path);
	if (prefsPrivate->accessed) {
		CFStringAppendFormat(result, NULL, CFSTR(", accessed"));
	}
	if (prefsPrivate->changed) {
		CFStringAppendFormat(result, NULL, CFSTR(", changed"));
	}
	if (prefsPrivate->locked) {
		CFStringAppendFormat(result, NULL, CFSTR(", locked"));
	}
	if (prefsPrivate->helper_port != MACH_PORT_NULL) {
		CFStringAppendFormat(result, NULL, CFSTR(", helper port = 0x%x"), prefsPrivate->helper_port);
	}
	CFStringAppendFormat(result, NULL, CFSTR("}"));

	return result;
}
static CFStringRef __ACSharedArtImageSourceCopyFormat(CFTypeRef cf, CFDictionaryRef format)
{
	ACSharedArtImageSourceRef isrc = (ACSharedArtImageSourceRef) cf;
	CFMutableStringRef description = CFStringCreateMutable(kCFAllocatorDefault,0);
	CFStringAppendFormat(description,NULL,CFSTR("Type: %d EntryCount: %d\n"),isrc->header->type,isrc->header->entryCount);
	for (int i = 0; i < isrc->header->entryCount; i++)
	{
		struct __ACSharedArtImageHeaderDataInfo dataInfoAtIndex = isrc->header->data_info[i];
		CFStringAppendFormat(description,NULL,CFSTR("\tImage %d Size: %dx%d Length: %d @ %d \n"),i,dataInfoAtIndex.width,dataInfoAtIndex.height,
							 dataInfoAtIndex.length,dataInfoAtIndex.relativeOffset);
	}
	return (CFStringRef) description;
}
// Start OTR negotiation if we haven't already done so.
SOSCoderStatus
SOSCoderStart(SOSCoderRef coder, CFErrorRef *error) {
    CFMutableStringRef action = CFStringCreateMutable(kCFAllocatorDefault, 0);
    CFStringRef beginState = NULL;
    SOSCoderStatus result = kSOSCoderFailure;
    CFMutableDataRef startPacket = NULL;

    require_action_quiet(coder->sessRef, coderFailure, CFStringAppend(action, CFSTR("*** no otr session ***")));
    beginState = CFCopyDescription(coder->sessRef);
    require_action_quiet(!coder->waitingForDataPacket, negotiatingOut, CFStringAppend(action, CFSTR("waiting for peer to send first data packet")));
    require_action_quiet(!SecOTRSGetIsReadyForMessages(coder->sessRef), coderFailure, CFStringAppend(action, CFSTR("otr session ready"));
                         result = kSOSCoderDataReturned);
    require_action_quiet(SecOTRSGetIsIdle(coder->sessRef), negotiatingOut, CFStringAppend(action, CFSTR("otr negotiating already")));
    require_action_quiet(startPacket = CFDataCreateMutable(kCFAllocatorDefault, 0), coderFailure, SOSCreateError(kSOSErrorAllocationFailure, CFSTR("alloc failed"), NULL, error));
    require_quiet(SOSOTRSAppendStartPacket(coder->sessRef, startPacket, error), coderFailure);
    CFRetainAssign(coder->pendingResponse, startPacket);

negotiatingOut:
    result = kSOSCoderNegotiating;
coderFailure:
    // Uber state log
    if (result == kSOSCoderFailure && error && *error)
        CFStringAppendFormat(action, NULL, CFSTR(" %@"), *error);
    secnotice("coder", "%@ %s %@ %@ returned %s", beginState,
              SecOTRPacketTypeString(startPacket), action, coder->sessRef, SOSCoderString(result));
    CFReleaseNull(startPacket);
    CFReleaseSafe(beginState);
    CFRelease(action);

    return result;

}
static CFStringRef
__SCBondStatusCopyDescription(CFTypeRef cf)
{
	CFAllocatorRef		allocator	= CFGetAllocator(cf);
	CFMutableStringRef	result;
	SCBondStatusPrivateRef	statusPrivate	= (SCBondStatusPrivateRef)cf;

	result = CFStringCreateMutable(allocator, 0);
	CFStringAppendFormat(result, NULL, CFSTR("<SCBondStatus %p [%p]> {"), cf, allocator);
	CFStringAppendFormat(result, NULL, CFSTR(" bond = %@"), statusPrivate->bond);
	CFStringAppendFormat(result, NULL, CFSTR(", interface = %@"), statusPrivate->status_bond);
	CFStringAppendFormat(result, NULL, CFSTR(", members = %@"),   statusPrivate->status_interfaces);
	CFStringAppendFormat(result, NULL, CFSTR(" }"));

	return result;
}
Exemple #16
0
static int run(CFArrayRef argv) {
	if (CFArrayGetCount(argv) > 1)  return -1;
	CFStringRef build = DBGetCurrentBuild();
	CFStringRef project = NULL;
	CFDictionaryRef projectEnv = NULL;
	CFDictionaryRef globalEnv = DBCopyPropDictionary(build, NULL, CFSTR("environment"));
	if (CFArrayGetCount(argv) == 1) {
		project = CFArrayGetValueAtIndex(argv, 0);
		projectEnv = DBCopyPropDictionary(build, project, CFSTR("environment"));
	}
	
	CFMutableDictionaryRef env = NULL;
	
	if (globalEnv && projectEnv) {
		env = (CFMutableDictionaryRef)mergeDictionaries(projectEnv, globalEnv);
	} else if (globalEnv) {
		env = (CFMutableDictionaryRef)globalEnv;
	} else if (projectEnv) {
		env = (CFMutableDictionaryRef)projectEnv;
	} else {
		return 0;
	}

	// Auto-generate some variables based on RC_ARCHS and RC_NONARCH_CFLAGS
	// RC_CFLAGS=$RC_NONARCH_CFLAGS -arch ${arch}
	// RC_${arch}=YES
	CFStringRef str = CFDictionaryGetValue(env, CFSTR("RC_NONARCH_CFLAGS"));
	if (!str) str = CFSTR("");
	CFMutableStringRef cflags = CFStringCreateMutableCopy(NULL, 0, str);
	str = CFDictionaryGetValue(env, CFSTR("RC_ARCHS"));
	if (str) {
		CFMutableStringRef trimmed = CFStringCreateMutableCopy(NULL, 0, str);
		CFStringTrimWhitespace(trimmed);
		CFArrayRef archs = tokenizeString(trimmed);
		CFIndex i, count = CFArrayGetCount(archs);
		for (i = 0; i < count; ++i) {
			CFStringRef arch = CFArrayGetValueAtIndex(archs, i);
			// -arch ${arch}
			CFStringAppendFormat(cflags, NULL, CFSTR(" -arch %@"), arch);
			
			// RC_${arch}=YES
			CFStringRef name = CFStringCreateWithFormat(NULL, NULL, CFSTR("RC_%@"), arch);
			CFDictionarySetValue(env, name, CFSTR("YES"));
			CFRelease(name);
		}
		CFRelease(trimmed);
	}
	CFDictionarySetValue(env, CFSTR("RC_CFLAGS"), cflags);
	
	// print variables to stdout
	CFArrayRef keys = dictionaryGetSortedKeys(env);
	CFIndex i, count = CFArrayGetCount(keys);
	for (i = 0; i < count; ++i) {
		CFStringRef name = CFArrayGetValueAtIndex(keys, i);
		CFStringRef value = CFDictionaryGetValue(env, name);
		cfprintf(stdout, "%@=%@\n", name, value);
	}
	return 0;
}
Exemple #17
0
static void appendElementProlog(CFMutableStringRef str, CFXMLTreeRef tree) {
    const CFXMLElementInfo *data = (CFXMLElementInfo *)CFXMLNodeGetInfoPtr(CFXMLTreeGetNode(tree));
    CFStringAppendFormat(str, NULL, CFSTR("<%@"), CFXMLNodeGetString(CFXMLTreeGetNode(tree)));
    if (data->attributeOrder) {
        CFIndex i, c = CFArrayGetCount(data->attributeOrder);
        for (i = 0; i < c; i ++) {
            CFStringRef attr = (CFStringRef)CFArrayGetValueAtIndex(data->attributeOrder, i);
            CFStringRef value = (CFStringRef)CFDictionaryGetValue(data->attributes, attr);
            CFStringAppendFormat(str, NULL, CFSTR(" %@="), attr);
            appendQuotedString(str, value);
        }
    }
    if (data->isEmpty) {
        CFStringAppendCString(str, "/>", kCFStringEncodingASCII);
    } else {
        CFStringAppendCString(str, ">", kCFStringEncodingASCII);
    }
}
Exemple #18
0
CFStringRef _CFErrorCreateDebugDescription(CFErrorRef err) {
    CFStringRef desc = CFErrorCopyDescription(err);
    CFStringRef debugDesc = _CFErrorCopyUserInfoKey(err, kCFErrorDebugDescriptionKey);
    CFDictionaryRef userInfo = _CFErrorGetUserInfo(err);
    CFMutableStringRef result = CFStringCreateMutable(kCFAllocatorSystemDefault, 0);
    CFStringAppendFormat(result, NULL, CFSTR("Error Domain=%@ Code=%d"), CFErrorGetDomain(err), (long)CFErrorGetCode(err));
    CFStringAppendFormat(result, NULL, CFSTR(" \"%@\""), desc);
    if (debugDesc && CFStringGetLength(debugDesc) > 0) CFStringAppendFormat(result, NULL, CFSTR(" (%@)"), debugDesc);
    if (userInfo) {
        CFStringAppendFormat(result, NULL, CFSTR(" UserInfo=%p {"), userInfo);
	CFDictionaryApplyFunction(userInfo, userInfoKeyValueShow, (void *)result);
	CFIndex commaLength = (CFStringHasSuffix(result, CFSTR(", "))) ? 2 : 0;
	CFStringReplace(result, CFRangeMake(CFStringGetLength(result)-commaLength, commaLength), CFSTR("}"));
    }
    if (debugDesc) CFRelease(debugDesc);
    if (desc) CFRelease(desc);
    return result;
}
Exemple #19
0
static CFStringRef
__SCNetworkSetCopyDescription(CFTypeRef cf)
{
	CFAllocatorRef		allocator	= CFGetAllocator(cf);
	CFMutableStringRef      result;
	SCNetworkSetPrivateRef	setPrivate	= (SCNetworkSetPrivateRef)cf;

	result = CFStringCreateMutable(allocator, 0);
	CFStringAppendFormat(result, NULL, CFSTR("<SCNetworkSet %p [%p]> {"), cf, allocator);
	CFStringAppendFormat(result, NULL, CFSTR("id = %@"), setPrivate->setID);
	CFStringAppendFormat(result, NULL, CFSTR(", prefs = %p"), setPrivate->prefs);
	if (setPrivate->name != NULL) {
		CFStringAppendFormat(result, NULL, CFSTR(", name = %@"), setPrivate->name);
	}
	CFStringAppendFormat(result, NULL, CFSTR("}"));

	return result;
}
Exemple #20
0
/**
 * Determines the network proxy server to use (if any).
 * @param url absolute URL for which to get the proxy server (not used)
 * @return proxy URL, NULL if no proxy or error
 */
char *vlc_getProxyUrl(const char *url)
{
    VLC_UNUSED(url);
    CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
    char *proxy_url = NULL;

    if (proxies) {
        CFNumberRef cfn_httpProxyOn =
            (CFNumberRef)CFDictionaryGetValue(proxies,
                                              kSCPropNetProxiesHTTPEnable);
        if (cfn_httpProxyOn) {
            int i_httpProxyOn;
            CFNumberGetValue(cfn_httpProxyOn, kCFNumberIntType, &i_httpProxyOn);
            CFRelease(cfn_httpProxyOn);

            if (i_httpProxyOn == 1) // http proxy is on
            {
                CFStringRef httpProxy =
                    (CFStringRef)CFDictionaryGetValue(proxies,
                                                      kSCPropNetProxiesHTTPProxy);

                if (httpProxy) {
                    CFNumberRef cfn_httpProxyPort =
                        (CFNumberRef)CFDictionaryGetValue(proxies,
                                                        kSCPropNetProxiesHTTPPort);
                    int i_httpProxyPort;
                    CFNumberGetValue(cfn_httpProxyPort,
                                     kCFNumberIntType,
                                     &i_httpProxyPort);
                    CFRelease(cfn_httpProxyPort);

                    CFMutableStringRef outputURL =
                        CFStringCreateMutableCopy(kCFAllocatorDefault,
                                                  0,
                                                  httpProxy);
                    if (i_httpProxyPort > 0)
                        CFStringAppendFormat(outputURL,
                                             NULL,
                                             CFSTR(":%i"),
                                             i_httpProxyPort);

                    char buffer[4096];
                    if (CFStringGetCString(outputURL, buffer, sizeof(buffer),
                        kCFStringEncodingUTF8))
                        proxy_url = strdup(buffer);

                    CFRelease(outputURL);
                }
                CFRelease(httpProxy);
            }
        }
        CFRelease(proxies);
    }

    return proxy_url;
}
Exemple #21
0
/*
void addUUID(CFMutableDictionaryRef dest, CFStringRef key, EFI_GUID *uuid)
{
    assert(dest);
    CFStringRef strValue = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
                                                    CFSTR("%08tX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"),
                                                    uuid->Data1, uuid->Data2, uuid->Data3,
                                                    uuid->Data4[0], uuid->Data4[1],
                                                    uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6], uuid->Data4[7]);
    assert(strValue);
    CFDictionaryAddValue( dest, key, strValue );
    CFRelease(strValue);
}*/
void addUUID(CFMutableDictionaryRef dest, CFStringRef key, UInt8 *uuid)
{
  SInt64 i = 0;
  CFMutableStringRef strValue = CFStringCreateMutable (kCFAllocatorDefault, 0);
  
  for (i = 0; i < 4; i++) {
    CFStringAppendFormat(strValue, NULL, CFSTR("%02x"), *uuid++);
  }
  for (i = 0; i < 3; i++) {
    CFStringAppendFormat(strValue, NULL, CFSTR("-%02x"), *uuid++);
    CFStringAppendFormat(strValue, NULL, CFSTR("%02x"), *uuid++);
  }
  CFStringAppendFormat(strValue, NULL, CFSTR("-"));
  for (i = 0; i < 6; i++) {
    CFStringAppendFormat(strValue, NULL, CFSTR("%02x"), *uuid++);
  }
  CFDictionaryAddValue( dest, key, strValue );
  CFRelease(strValue);
}
Exemple #22
0
void addIntArray(CFMutableDictionaryRef dest, CFStringRef key, UInt8 *Value, SInt64 num)
{
    SInt64 i = 0;
    CFMutableStringRef strValue = CFStringCreateMutable (kCFAllocatorDefault, 0);

    for (i = 0; i < num; i++) {
        CFStringAppendFormat(strValue, NULL, CFSTR("%02x"), Value[i]);
    }
    CFDictionaryAddValue( dest, key, strValue );
    CFRelease(strValue);
}
STATIC CFStringRef
__EAPOLClientItemIDCopyDebugDesc(CFTypeRef cf)
{
    CFAllocatorRef		allocator = CFGetAllocator(cf);
    EAPOLClientItemIDRef	itemID = (EAPOLClientItemIDRef)cf;
    CFStringRef			profileID;
    CFMutableStringRef		result;
    CFStringRef			ssid_str;

    result = CFStringCreateMutable(allocator, 0);
    CFStringAppendFormat(result, NULL, 
			 CFSTR("<EAPOLClientItemID %p [%p]> {"), cf, allocator);
    switch (itemID->type) {
    case kEAPOLClientItemIDTypeWLANSSID:
	ssid_str = my_CFStringCreateWithData(itemID->u.ssid);
	CFStringAppendFormat(result, NULL, CFSTR("WLAN SSID = %@"),
			     ssid_str);
	CFRelease(ssid_str);
	break;
    case kEAPOLClientItemIDTypeWLANDomain:
	CFStringAppendFormat(result, NULL, CFSTR("WLAN domain = %@"),
			     itemID->u.domain);
	break;
    case kEAPOLClientItemIDTypeProfileID:
	CFStringAppendFormat(result, NULL, CFSTR("ProfileID = %@"),
			     itemID->u.profileID);
	break;
    case kEAPOLClientItemIDTypeProfile:
	profileID = EAPOLClientProfileGetID(itemID->u.profile);
	CFStringAppendFormat(result, NULL, CFSTR("Profile = %@"),
			     profileID);
	break;
    case kEAPOLClientItemIDTypeDefault:
	CFStringAppend(result, CFSTR("Default"));
	break;
    default:
	break;
    }
    CFStringAppend(result, CFSTR("}"));
    return result;
}
Exemple #24
0
static CFStringRef __CFNumberCopyDescription(CFTypeRef cf) {
    CFNumberRef number = (CFNumberRef)cf;
    CFNumberType type = __CFNumberGetType(number);
    CFMutableStringRef mstr = CFStringCreateMutable(kCFAllocatorSystemDefault, 0);
    CFStringAppendFormat(mstr, NULL, CFSTR("<CFNumber %p [%p]>{value = "), cf, CFGetAllocator(cf));
    if (__CFNumberTypeTable[type].floatBit) {
        Float64 d;
        __CFNumberGetValue(number, kCFNumberFloat64Type, &d);
        if (isnan(d)) {
            CFStringAppend(mstr, CFSTR("nan"));
        } else if (isinf(d)) {
            CFStringAppend(mstr, (0.0 < d) ? CFSTR("+infinity") : CFSTR("-infinity"));
        } else if (0.0 == d) {
            CFStringAppend(mstr, (copysign(1.0, d) < 0.0) ? CFSTR("-0.0") : CFSTR("+0.0"));
        } else {
            CFStringAppendFormat(mstr, NULL, CFSTR("%+.*f"), (__CFNumberTypeTable[type].storageBit ? 20 : 10), d);
        }
        const char* typeName = "unknown float";
        switch (type) {
            case kCFNumberFloat32Type: typeName = "kCFNumberFloat32Type"; break;
            case kCFNumberFloat64Type: typeName = "kCFNumberFloat64Type"; break;
        }
        CFStringAppendFormat(mstr, NULL, CFSTR(", type = %s}"), typeName);
    } else {
        CFSInt128Struct i;
        __CFNumberGetValue(number, kCFNumberSInt128Type, &i);
        char buffer[128];
        __CFSInt128Format(buffer, &i, true);
        const char* typeName = "unknown integer";
        switch (type) {
            case kCFNumberSInt8Type: typeName = "kCFNumberSInt8Type"; break;
            case kCFNumberSInt16Type: typeName = "kCFNumberSInt16Type"; break;
            case kCFNumberSInt32Type: typeName = "kCFNumberSInt32Type"; break;
            case kCFNumberSInt64Type: typeName = "kCFNumberSInt64Type"; break;
            case kCFNumberSInt128Type: typeName = "kCFNumberSInt128Type"; break;
        }
        CFStringAppendFormat(mstr, NULL, CFSTR("%s, type = %s}"), buffer, typeName);
    }
    return mstr;
}
Exemple #25
0
static CFStringRef CGColorSpaceCopyDebugDescription(CFTypeRef ref) {
    CGColorSpace* colorSpace=_CGColorSpaceFromTypeRef(ref);
    CFAllocatorRef allocator=CFGetAllocator(ref);
    CFMutableStringRef description=CFStringCreateMutable(allocator,0);
    CFStringRef typeName=CGColorSpaceFormatType(colorSpace->type);
    CFStringAppendFormat(
        description,
        NULL,
        CFSTR("<CGColorSpace %p> (%@)"),
        colorSpace,typeName);
    CFRelease(typeName);
    return description;
}
static CFStringRef SOSRecoveryKeyBagCopyFormatDescription(CFTypeRef aObj, CFDictionaryRef formatOptions) {
    SOSRecoveryKeyBagRef rb = (SOSRecoveryKeyBagRef) aObj;
    CFStringRef gcString = SOSGenerationCountCopyDescription(rb->generation);
    CFStringRef rkbID = SOSCopyIDOfDataBufferWithLength(rb->recoveryKeyBag, 8, NULL);

    CFMutableStringRef description = CFStringCreateMutable(kCFAllocatorDefault, 0);
    
    CFStringAppendFormat(description, NULL, CFSTR("<SOSRecoveryKeyBag@%p DSID: %@ version: %d  gencount: %@  RecoveryKeyID: %@ "), rb, rb->accountDSID, (int) rb->rkbVersion, gcString, rkbID);
    CFStringAppend(description, CFSTR(">"));
    
    CFReleaseNull(gcString);
    CFReleaseNull(rkbID);
    return description;
}
STATIC CFStringRef
__EAPOLClientConfigurationCopyDebugDesc(CFTypeRef cf)
{
    CFAllocatorRef		allocator = CFGetAllocator(cf);
    EAPOLClientConfigurationRef	cfg = (EAPOLClientConfigurationRef)cf;
    CFMutableStringRef		result;

    result = CFStringCreateMutable(allocator, 0);
    if (cfg->auth_ext_p == NULL) {
	CFStringAppendFormat(result, NULL,
			     CFSTR("<EAPOLClientConfiguration %p [%p]> {"),
			     cf, allocator);
    }
    else {
	CFStringAppendFormat(result, NULL,
			     CFSTR("<EAPOLClientConfiguration %p [%p] auth> {"),
			     cf, allocator);
    }
    CFStringAppendFormat(result, NULL, CFSTR("profiles = %@"), cfg->profiles);
    CFStringAppendFormat(result, NULL, CFSTR("ssids = %@"), cfg->ssids);
    CFStringAppend(result, CFSTR("}"));
    return (result);
}
Exemple #28
0
/* FIXME: There are other versions of this in SecCertifcate.c and SecCertificateP.c */
static CFStringRef SecDERItemCopyOIDDecimalRepresentation(CFAllocatorRef allocator, const CSSM_OID *oid)
{
	if (oid->Length == 0)
        return CFSTR("<NULL>");

	if (oid->Length > MAX_OID_SIZE)
        return CFSTR("Oid too long");

    CFMutableStringRef result = CFStringCreateMutable(allocator, 0);

	// The first two levels are encoded into one byte, since the root levelq
	// has only 3 nodes (40*x + y).  However if x = joint-iso-itu-t(2) then
	// y may be > 39, so we have to add special-case handling for this.
	uint32_t x = oid->Data[0] / 40;
	uint32_t y = oid->Data[0] % 40;
	if (x > 2)
	{
		// Handle special case for large y if x = 2
		y += (x - 2) * 40;
		x = 2;
	}
    CFStringAppendFormat(result, NULL, CFSTR("%u.%u"), x, y);

	uint32_t value = 0;
	for (x = 1; x < oid->Length; ++x)
	{
		value = (value << 7) | (oid->Data[x] & 0x7F);
        /* @@@ value may not span more than 4 bytes. */
        /* A max number of 20 values is allowed. */
		if (!(oid->Data[x] & 0x80))
		{
            CFStringAppendFormat(result, NULL, CFSTR(".%lu"), (unsigned long)value);
			value = 0;
		}
	}
	return result;
}
CFStringRef createVersionDescription(const struct Version v) {
    /*the struct Version structure contains two u_int16_ts, two u_int8_ts, and one u_int32_t.
     *the maximum number of decimal digits in an u_int32_t is 10 (UINT_MAX=4294967295).
     *the maximum number of decimal digits in an u_int16_t is 5 (USHRT_MAX=65535).
     *the maximum number of decimal digits in an u_int8_t  is 3 (UCHAR_MAX=255).
     *the maximum length of a release type name (see releaseTypeNames above)
     *	is 5 (" SVN " including spaces).
     *thus, the maximum length of a version description is:
     *	5 + 5 + 3 + 5 + 10 = 28.
     */
    CFMutableStringRef str = CFStringCreateMutable(kCFAllocatorDefault, /*capacity*/ 28);
    CFStringAppendFormat(str, /*formatOptions*/ NULL, CFSTR("%hu.%hu"), v.major, v.minor);
    if (v.incremental) {
        CFStringAppendFormat(str, /*formatOptions*/ NULL, CFSTR(".%hhu"), v.incremental);
    }
    if (v.releaseType != releaseType_release) {
        if (v.releaseType >= numberOfReleaseTypes) {
            CFRelease(str);
            return nil;
        }
        CFStringAppendFormat(str, /*formatOptions*/ NULL, CFSTR("%@%u"), releaseTypeNames[v.releaseType], v.development);
    }
    return str;
}
Exemple #30
0
void stringWithExternalContentsExample(void) {
#define BufferSize 1000
    CFMutableStringRef mutStr;
    UniChar *myBuffer;

    show(CFSTR("------------------External Contents Examples---------------"));

    // Allocate a contents store that is empty (but has space for BufferSize chars)...
    myBuffer = (UniChar*)malloc(BufferSize * sizeof(UniChar));

    // Now create a mutable CFString which uses this buffer
    // The 0 and BufferSize indicate the length and capacity (in UniChars)
    // The kCFAllocatorNull indicates how the CFString should reallocate or free this buffer (in this case, do nothing)

    mutStr = CFStringCreateMutableWithExternalCharactersNoCopy(NULL, myBuffer, 0, BufferSize, kCFAllocatorNull);
    CFStringAppend(mutStr, CFSTR("Appended string... "));
    CFStringAppend(mutStr, CFSTR("More stuff... "));
#if defined(__APPLE__)
    CFStringAppendPascalString(mutStr, "\pA pascal string. ", kCFStringEncodingASCII);
#else
    CFStringAppendCString(mutStr, "A C string. ", kCFStringEncodingASCII);
#endif
    CFStringAppendFormat(mutStr, NULL, CFSTR("%d %4.2f %@..."), 42, -3.14, CFSTR("Hello"));
    
    show(CFSTR("String: %@"), mutStr);

    CFRelease(mutStr);
    free(myBuffer);

    // Now create a similar string, but give CFString the ability to reallocate or free the buffer
    // The last "NULL" argument specifies that the default allocator should be used
    // Here we provide an initial buffer of 32 characters, but if it grows beyond this, it's OK
    // (unlike the previous example, where if the string grew beyond 1000, it's an error)

    myBuffer = (UniChar*)CFAllocatorAllocate(CFAllocatorGetDefault(), 32 * sizeof(UniChar), 0);
    mutStr = CFStringCreateMutableWithExternalCharactersNoCopy(NULL, myBuffer, 0, 32, NULL);

    CFStringAppend(mutStr, CFSTR("Appended string... "));
    CFStringAppend(mutStr, CFSTR("Appended string... "));
    CFStringAppend(mutStr, CFSTR("Appended string... "));
    CFStringAppend(mutStr, CFSTR("Appended string... "));
    CFStringAppend(mutStr, CFSTR("Appended string... "));

    show(CFSTR("String: %@"), mutStr);

    CFRelease(mutStr);
    // Here we don't free the buffer, as CFString does that
}