Exemplo n.º 1
0
void setCookies(const KURL& url, const KURL& policyURL, const String& value)
{
#if USE(CFNETWORK)
    if (!ResourceHandle::cookieStorage())
        return;

    RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL());
    RetainPtr<CFURLRef> policyURLCF(AdoptCF, policyURL.createCFURL());

    // <http://bugzilla.opendarwin.org/show_bug.cgi?id=6531>, <rdar://4409034>
    // cookiesWithResponseHeaderFields doesn't parse cookies without a value
    String cookieString = value.contains('=') ? value : value + "=";

    RetainPtr<CFStringRef> cookieStringCF(AdoptCF, cookieString.createCFString());
    RetainPtr<CFDictionaryRef> headerFieldsCF(AdoptCF, CFDictionaryCreate(kCFAllocatorDefault, (const void**)&s_setCookieKeyCF, 
        (const void**)&cookieStringCF, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));

    RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieCreateWithResponseHeaderFields(kCFAllocatorDefault,
        headerFieldsCF.get(), urlCF.get()));

    CFHTTPCookieStorageSetCookies(ResourceHandle::cookieStorage(), cookiesCF.get(), urlCF.get(), policyURLCF.get());
#else
    // FIXME: Deal with the policy URL.
    DeprecatedString str = url.url();
    str.append((UChar)'\0');
    DeprecatedString val = value.deprecatedString();
    val.append((UChar)'\0');
    InternetSetCookie((UChar*)str.unicode(), 0, (UChar*)val.unicode());
#endif
}
Exemplo n.º 2
0
bool QConfFileSettingsPrivate::writePlistFile(const QString &fileName,
                                              const ParsedSettingsMap &map) const
{
    QVarLengthArray<QCFType<CFStringRef> > cfkeys(map.size());
    QVarLengthArray<QCFType<CFPropertyListRef> > cfvalues(map.size());
    int i = 0;
    ParsedSettingsMap::const_iterator j;
    for (j = map.constBegin(); j != map.constEnd(); ++j) {
        cfkeys[i] = macKey(j.key());
        cfvalues[i] = macValue(j.value());
        ++i;
    }

    QCFType<CFDictionaryRef> propertyList =
            CFDictionaryCreate(kCFAllocatorDefault,
                               reinterpret_cast<const void **>(cfkeys.data()),
                               reinterpret_cast<const void **>(cfvalues.data()),
                               CFIndex(map.size()),
                               &kCFTypeDictionaryKeyCallBacks,
                               &kCFTypeDictionaryValueCallBacks);

    QCFType<CFDataRef> xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, propertyList);

    SInt32 code;
    return CFURLWriteDataAndPropertiesToResource(urlFromFileName(fileName), xmlData, 0, &code);
}
Exemplo n.º 3
0
CF_PRIVATE CFErrorRef _CFErrorFromStreamError(CFAllocatorRef alloc, CFStreamError *streamError) {
    CFErrorRef result;
    Boolean canUpCall;
    
    __CFLock(&(CFNetworkSupport.lock));
    if (!__CFBitIsSet(CFNetworkSupport.flags, kTriedToLoad)) initializeCFNetworkSupport();
    canUpCall = (CFNetworkSupport._CFErrorCreateWithStreamError != NULL);
    __CFUnlock(&(CFNetworkSupport.lock));

    if (canUpCall) {
        result = CFNETWORK_CALL(_CFErrorCreateWithStreamError, (alloc, streamError));
    } else {
        if (streamError->domain == kCFStreamErrorDomainPOSIX) {
            return CFErrorCreate(alloc, kCFErrorDomainPOSIX, streamError->error, NULL);
        } else if (streamError->domain == kCFStreamErrorDomainMacOSStatus) {
            return CFErrorCreate(alloc, kCFErrorDomainOSStatus, streamError->error, NULL);
        } else {
            CFStringRef key = CFSTR("CFStreamErrorDomainKey");
            CFNumberRef value = CFNumberCreate(alloc, kCFNumberCFIndexType, &streamError->domain);
            CFDictionaryRef dict = CFDictionaryCreate(alloc, (const void **)(&key), (const void **)(&value), 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
            result = CFErrorCreate(alloc, CFSTR("BogusCFStreamErrorCompatibilityDomain"), streamError->error, dict);
            CFRelease(value);
            CFRelease(dict);
        }
    }
    return result;
}
void SendSkypeCommand(CFStringRef command)
{
	if (delegate == NULL)
	{
		printf("Can't send message, no delegate set\n");
		return;
	}
	if (command == NULL)
		return;
	if (!client_id)
	{
		printf("Can't send message, not connected\n");
		return;
	}

	CFRetain(command);

	CFNumberRef id_number = CFNumberCreate(NULL, kCFNumberIntType, &client_id);
	CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
	const void *keys[] = {(void *)CFSTR("SKYPE_API_COMMAND"), (void *)CFSTR("SKYPE_API_CLIENT_ID")};
	const void *values[] = {command, id_number};
	CFDictionaryRef userInfo = CFDictionaryCreate(NULL, keys, values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);	
	
	//send message
	CFNotificationCenterPostNotification(
		center,
		CFSTR("SKSkypeAPICommand"),
		NULL,
		userInfo,
		FALSE);
	
	CFRelease(command);
	CFRelease(id_number);
	CFRelease(userInfo);
}
Exemplo n.º 5
0
bool
OSXKeyState::getGroups(GroupList& groups) const
{
	CFIndex n;
	bool gotLayouts = false;

	// get number of layouts
	CFStringRef keys[] = { kTISPropertyInputSourceCategory };
	CFStringRef values[] = { kTISCategoryKeyboardInputSource };
	CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 1, NULL, NULL);
	CFArrayRef kbds = TISCreateInputSourceList(dict, false);
	n = CFArrayGetCount(kbds);
	gotLayouts = (n != 0);

	if (!gotLayouts) {
		LOG((CLOG_DEBUG1 "can't get keyboard layouts"));
		return false;
	}

	// get each layout
	groups.clear();
	for (CFIndex i = 0; i < n; ++i) {
		bool addToGroups = true;
		TISInputSourceRef keyboardLayout = 
			(TISInputSourceRef)CFArrayGetValueAtIndex(kbds, i);

		if (addToGroups)
    		groups.push_back(keyboardLayout);
	}
	return true;
}
Exemplo n.º 6
0
inline int __JSONParserAppendMapEnd(void *context) {
  int success = 0;
  __JSONRef json = (__JSONRef)context;
  __JSONStackEntryRef entry = __JSONStackPop(json->stack);
  if (entry) {
    if (entry->keysIndex == entry->valuesIndex) {
      CFTypeRef *keys = __JSONStackEntryCreateKeys(entry, json->elements);
      if (keys) {
        CFTypeRef *values = __JSONStackEntryCreateValues(entry, json->elements);
        if (values) {
          json->elements[entry->index] = CFDictionaryCreate(json->allocator, keys, values, entry->keysIndex, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
          CFAllocatorDeallocate(entry->allocator, values);
          success = 1;
        }
        CFAllocatorDeallocate(entry->allocator, keys);
      }
    } else {
      // TODO: The number of keys and values does not match
    }
    __JSONStackEntryRelease(entry);
  } else {
    // TODO: Container on the stack can't be NULL (too deep?)
  }
  return success;
}
static CFErrorRef GTMCFLaunchCreateUnlocalizedError(CFIndex code,
                                                    CFStringRef format, ...) {
  CFDictionaryRef user_info = NULL;
  if (format) {
    va_list args;
    va_start(args, format);
    CFStringRef string
      = CFStringCreateWithFormatAndArguments(kCFAllocatorDefault,
                                             NULL,
                                             format,
                                             args);
    user_info = CFDictionaryCreate(kCFAllocatorDefault,
                                   (const void **)&kCFErrorDescriptionKey,
                                   (const void **)&string,
                                   1,
                                   &kCFTypeDictionaryKeyCallBacks,
                                   &kCFTypeDictionaryValueCallBacks);
    CFRelease(string);
    va_end(args);
  }
  CFErrorRef error = CFErrorCreate(kCFAllocatorDefault,
                                   kCFErrorDomainPOSIX,
                                   code,
                                   user_info);
  if (user_info) {
    CFRelease(user_info);
  }
  return error;
}
Exemplo n.º 8
0
void SocketStreamHandle::createStreams()
{
    if (m_connectionType == Unknown)
        chooseProxy();

    // If it's still unknown, then we're resolving a PAC file asynchronously.
    if (m_connectionType == Unknown)
        return;

    RetainPtr<CFStringRef> host(AdoptCF, m_url.host().createCFString());

    // Creating streams to final destination, not to proxy.
    CFReadStreamRef readStream = 0;
    CFWriteStreamRef writeStream = 0;
    CFStreamCreatePairWithSocketToHost(0, host.get(), m_url.port(), &readStream, &writeStream);

    m_readStream.adoptCF(readStream);
    m_writeStream.adoptCF(writeStream);

    switch (m_connectionType) {
    case Unknown:
        ASSERT_NOT_REACHED();
        break;
    case Direct:
        break;
    case SOCKSProxy: {
        // FIXME: SOCKS5 doesn't do challenge-response, should we try to apply credentials from Keychain right away?
        // But SOCKS5 credentials don't work at the time of this writing anyway, see <rdar://6776698>.
        const void* proxyKeys[] = { kCFStreamPropertySOCKSProxyHost, kCFStreamPropertySOCKSProxyPort };
        const void* proxyValues[] = { m_proxyHost.get(), m_proxyPort.get() };
        RetainPtr<CFDictionaryRef> connectDictionary(AdoptCF, CFDictionaryCreate(0, proxyKeys, proxyValues, WTF_ARRAY_LENGTH(proxyKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
        CFReadStreamSetProperty(m_readStream.get(), kCFStreamPropertySOCKSProxy, connectDictionary.get());
        break;
    }
    case CONNECTProxy:
        wkSetCONNECTProxyForStream(m_readStream.get(), m_proxyHost.get(), m_proxyPort.get());
        break;
    }

    if (shouldUseSSL()) {
        const void* keys[] = { kCFStreamSSLPeerName, kCFStreamSSLLevel };
        const void* values[] = { host.get(), kCFStreamSocketSecurityLevelNegotiatedSSL };
        RetainPtr<CFDictionaryRef> settings(AdoptCF, CFDictionaryCreate(0, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
        CFReadStreamSetProperty(m_readStream.get(), kCFStreamPropertySSLSettings, settings.get());
        CFWriteStreamSetProperty(m_writeStream.get(), kCFStreamPropertySSLSettings, settings.get());
    }
}
Exemplo n.º 9
0
CFArrayRef CFNetworkCopyProxiesForURL(CFURLRef url, CFDictionaryRef proxySettings) {
    CFDictionaryRef noSettings = CFDictionaryCreate(NULL,
        (CFTypeRef*)&kCFProxyTypeKey, (CFTypeRef*)&kCFProxyTypeNone, 1,
        &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    CFArrayRef proxies = CFArrayCreate(NULL, (CFTypeRef*)&noSettings, 1, &kCFTypeArrayCallBacks);
    CFRelease(noSettings);
    return proxies;
}
Exemplo n.º 10
0
static CFDictionaryRef createPixelBufferOptionsDictionary(QTPixelBuffer::Type contextType)
{
    const void* key = kQTVisualContextPixelBufferAttributesKey;
    const void* value = QTPixelBuffer::createPixelBufferAttributesDictionary(contextType);
    CFDictionaryRef pixelBufferOptions = CFDictionaryCreate(kCFAllocatorDefault, &key, &value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    CFRelease(value);
    return pixelBufferOptions;
}
Exemplo n.º 11
0
Arquivo: client.c Projeto: aosm/bootp
static CFDictionaryRef
IPv6ConfigDictCreate(const char * ifname, 
		     int argc, char * argv[], const char * cmd,
		     const char * method_name,
		     CFStringRef config_method)
{
    CFDictionaryRef		dict;
    CFMutableDictionaryRef	ipv6_dict;
    CFStringRef			ipv6_key;

    ipv6_dict = CFDictionaryCreateMutable(NULL, 0,
					  &kCFTypeDictionaryKeyCallBacks,
					  &kCFTypeDictionaryValueCallBacks);
    CFDictionarySetValue(ipv6_dict, kSCPropNetIPv6ConfigMethod,
			 config_method);
    if (config_method == kSCValNetIPv6ConfigMethodManual) {
	struct in6_addr		ip_address;
	int			prefix_length;

	if (argc != 2) {
	    fprintf(stderr, "usage: ipconfig %s %s "
		    "%s6 <ipv6-address> <prefix-length>\n", 
		    cmd, ifname, method_name);
	    goto failed;
	}
	if (inet_pton(AF_INET6, argv[0], &ip_address) != 1) {
	    fprintf(stderr, "Invalid IPv6 address %s\n", argv[0]);
	    goto failed;
	}
	my_CFDictionarySetIPv6AddressAsArrayValue(ipv6_dict,
						  kSCPropNetIPv6Addresses,
						  &ip_address);
	prefix_length = (int)strtol(argv[1], NULL, 0);
	if (prefix_length < 0 || prefix_length > 128) {
	    fprintf(stderr, "Invalid prefix_length %s\n", argv[1]);
	    goto failed;
	}
	my_CFDictionarySetIntegerAsArrayValue(ipv6_dict,
					      kSCPropNetIPv6PrefixLength,
					      prefix_length);
    }
    else if (argc != 0) {
	fprintf(stderr, "too many arguments for method\n");
	goto failed;
    }
    ipv6_key = kSCEntNetIPv6;
    dict = CFDictionaryCreate(NULL,
			      (const void * *)&ipv6_key,
			      (const void * *)&ipv6_dict, 1,
			      &kCFTypeDictionaryKeyCallBacks,
			      &kCFTypeDictionaryValueCallBacks);
    CFRelease(ipv6_dict);
    return (dict);

 failed:
    my_CFRelease(&ipv6_dict);
    return (NULL);
}
Exemplo n.º 12
0
static RetainPtr<CFDictionaryRef> createImageSourceOptions(SubsamplingLevel subsamplingLevel)
{
    if (!subsamplingLevel) {
        const unsigned numOptions = 3;
        const void* keys[numOptions] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32, kCGImageSourceSkipMetadata };
        const void* values[numOptions] = { kCFBooleanTrue, kCFBooleanTrue, kCFBooleanTrue };
        return CFDictionaryCreate(nullptr, keys, values, numOptions, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    }

    short constrainedSubsamplingLevel = std::min<short>(3, std::max<short>(0, subsamplingLevel));
    int subsampleInt = 1 << constrainedSubsamplingLevel; // [0..3] => [1, 2, 4, 8]

    RetainPtr<CFNumberRef> subsampleNumber = adoptCF(CFNumberCreate(nullptr,  kCFNumberIntType,  &subsampleInt));
    const CFIndex numOptions = 4;
    const void* keys[numOptions] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32, kCGImageSourceSkipMetadata, kCGImageSourceSubsampleFactor };
    const void* values[numOptions] = { kCFBooleanTrue, kCFBooleanTrue, kCFBooleanTrue, subsampleNumber.get() };
    return adoptCF(CFDictionaryCreate(nullptr, keys, values, numOptions, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
}
Exemplo n.º 13
0
void send_server_event ( const eEventCode in_event_code, const char *in_name, const char *in_addr )
{
	CFTypeRef keys[2];
	CFTypeRef values[2];
	CFStringRef cfstr_addr = NULL;
	CFStringRef cfstr_event = NULL;

	if ( !strlen(g_client_addr) || (strcmp(g_client_addr, in_addr) != 0) ) {
		strlcpy(g_client_addr, in_addr, sizeof g_client_addr);
		g_bad_recip_cntr = 0;
	}

	if ( g_bad_recip_cntr++ < 4 )
		return;
	else
		sleep( g_bad_recip_cntr >= 10 ? 10 : g_bad_recip_cntr );

	/* create a port to the event server */
	if ( gEventPort == NULL )
		gEventPort = XSEventPortCreate(nil);

	keys[0] = CFSTR("eventType");
	keys[1] = CFSTR("host_address");

	/* set event code string */
	switch ( in_event_code ) {
		case eBadRecipient:
			cfstr_event = CFStringCreateWithCString(NULL, "smtp.receive.badrecipient", kCFStringEncodingMacRoman);
			break;
		case eAuthFailure:
			cfstr_event = CFStringCreateWithCString(NULL, "auth.failure", kCFStringEncodingMacRoman);
			break;
		case eAuthSuccess:
			cfstr_event = CFStringCreateWithCString(NULL, "auth.success", kCFStringEncodingMacRoman);
			break;
		default:
			msg_warn("Warning: unknown sever event: %d", in_event_code);
			return;
	}

	cfstr_addr = CFStringCreateWithCString(NULL, in_addr, kCFStringEncodingMacRoman);

	values[0] = cfstr_event;
	values[1] = cfstr_addr;

     CFDictionaryRef dict_event = CFDictionaryCreate(NULL, keys, values, 
                                               sizeof(keys) / sizeof(keys[0]), 
                                               &kCFTypeDictionaryKeyCallBacks, 
                                               &kCFTypeDictionaryValueCallBacks); 
	
	/* send the event */
	(void)XSEventPortPostEvent(gEventPort, cfstr_event, dict_event);

	CFRelease(cfstr_addr);
	CFRelease(cfstr_event);
	CFRelease(dict_event);
} /* send_server_event */
Exemplo n.º 14
0
CFDictionaryRef
AppleVTDecoder::CreateDecoderExtensions()
{
  AutoCFRelease<CFDataRef> avc_data =
    CFDataCreate(kCFAllocatorDefault,
                 mExtraData->Elements(),
                 mExtraData->Length());

  const void* atomsKey[] = { CFSTR("avcC") };
  const void* atomsValue[] = { avc_data };
  static_assert(ArrayLength(atomsKey) == ArrayLength(atomsValue),
                "Non matching keys/values array size");

  AutoCFRelease<CFDictionaryRef> atoms =
    CFDictionaryCreate(kCFAllocatorDefault,
                       atomsKey,
                       atomsValue,
                       ArrayLength(atomsKey),
                       &kCFTypeDictionaryKeyCallBacks,
                       &kCFTypeDictionaryValueCallBacks);

  const void* extensionKeys[] =
    { kCVImageBufferChromaLocationBottomFieldKey,
      kCVImageBufferChromaLocationTopFieldKey,
      AppleCMLinker::skPropExtensionAtoms,
      AppleCMLinker::skPropFullRangeVideo /* Not defined in 10.6 */ };

  const void* extensionValues[] =
    { kCVImageBufferChromaLocation_Left,
      kCVImageBufferChromaLocation_Left,
      atoms,
      kCFBooleanTrue };
  static_assert(ArrayLength(extensionKeys) == ArrayLength(extensionValues),
                "Non matching keys/values array size");

  return CFDictionaryCreate(kCFAllocatorDefault,
                            extensionKeys,
                            extensionValues,
                            AppleCMLinker::skPropFullRangeVideo ?
                              ArrayLength(extensionKeys) :
                              ArrayLength(extensionKeys) - 1,
                            &kCFTypeDictionaryKeyCallBacks,
                            &kCFTypeDictionaryValueCallBacks);
}
Exemplo n.º 15
0
extern pascal OSStatus CFQDictionaryCreateWithArrayOfKeysAndValues(CFArrayRef keys, 
																   CFArrayRef values, 
																   CFDictionaryRef *result)
	// See comment in header.
{
	OSStatus    err;
	CFIndex 	count;
	CFTypeRef * keysBuffer;
	CFTypeRef * valuesBuffer;
	
	assert(keys != NULL);
	assert(values != NULL);
	assert( CFArrayGetCount(keys) == CFArrayGetCount(values) );
	assert( result != NULL);
	assert(*result == NULL);
	
	keysBuffer   = NULL;
	valuesBuffer = NULL;

	// Check that the arrays are of a like size.
		
	err = noErr;
	count = CFArrayGetCount(keys);
	if ( count != CFArrayGetCount(values) ) {
		err = paramErr;
	}
	
	// Allocate a buffer for both keys and values.
	
	if (err == noErr) {
		err = CFQAllocate(sizeof(CFTypeRef) * count, (void **) &keysBuffer);
	}
	if (err == noErr) {
		err = CFQAllocate(sizeof(CFTypeRef) * count, (void **) &valuesBuffer);
	}
	
	// Get the keys and values into their buffers, and create a 
	// dictionary based on the buffer.
	
	if (err == noErr) {
		CFArrayGetValues(keys,   CFRangeMake(0, count), keysBuffer);
		CFArrayGetValues(values, CFRangeMake(0, count), valuesBuffer);
		
		*result = CFDictionaryCreate(NULL, keysBuffer, valuesBuffer, count, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
		if (*result == NULL) {
			err = coreFoundationUnknownErr;
		}
	}
	
	// Clean up.
	
	CFQDeallocate(keysBuffer);
	CFQDeallocate(valuesBuffer);
	
	return err;
}
Exemplo n.º 16
0
/* Create and identity and try to retrieve it. */
static void AddIdentityToKeychain(void)
{
    SecCertificateRef cert = NULL;
    SecKeyRef privKey = NULL;
    //SecIdentityRef identity = NULL;

    isnt(cert = SecCertificateCreateWithBytes(NULL, _c1, sizeof(_c1)),
            NULL, "create certificate");

#if TARGET_OS_IPHONE
    privKey = SecKeyCreateRSAPrivateKey(NULL, _k1, sizeof(_k1),
                                        kSecKeyEncodingPkcs1);
#else
#warning TODO
    privKey = NULL;
#endif

    isnt(privKey, NULL, "create private key");

    const void *certkeys[] = {
        kSecValueRef
    };
    const void *certvalues[] = {
        cert
    };
    CFDictionaryRef certDict = CFDictionaryCreate(NULL, certkeys, certvalues,
            array_size(certkeys), NULL, NULL);
    ok_status(SecItemAdd(certDict, NULL), "add certificate");
    CFReleaseNull(certDict);
    CFReleaseNull(cert);

    const void *privkeys[] = {
        kSecValueRef
    };
    const void *privvalues[] = {
        privKey
    };
    CFDictionaryRef privDict = CFDictionaryCreate(NULL, privkeys, privvalues,
            array_size(privkeys), NULL, NULL);
    ok_status(SecItemAdd(privDict, NULL), "add private key");
    CFReleaseNull(privDict);
    CFReleaseNull(privKey);
}
Exemplo n.º 17
0
/* ------------------------------------------------------------------------------------
 get the EAP dictionary from the options
 ------------------------------------------------------------------------------------ */
static void
EAPAKAGetOptions (void)
{
	if (eapOptions)
		return;
	
	// no option, use empty dictionary
	if (!eapOptions)
		eapOptions = CFDictionaryCreate(0, 0, 0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}
Exemplo n.º 18
0
/* Returns a shared empty dictionary (unless the allocator is not kCFAllocatorSystemDefault, in which case returns a newly allocated one).
*/
static CFDictionaryRef _CFErrorCreateEmptyDictionary(CFAllocatorRef allocator) {
    if (allocator == NULL) allocator = __CFGetDefaultAllocator();
    if (_CFAllocatorIsSystemDefault(allocator)) {
        static CFDictionaryRef emptyErrorDictionary = NULL;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            emptyErrorDictionary = CFDictionaryCreate(allocator, NULL, NULL, 0, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
        });
        return (CFDictionaryRef)CFRetain(emptyErrorDictionary);
    } else {
Exemplo n.º 19
0
KeyedDecoder::KeyedDecoder(const uint8_t* data, size_t size)
{
    auto cfData = adoptCF(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, data, size, kCFAllocatorNull));

    if (auto rootDictionary = adoptCF(dynamic_cf_cast<CFDictionaryRef>(CFPropertyListCreateWithData(kCFAllocatorDefault, cfData.get(), kCFPropertyListImmutable, nullptr, nullptr))))
        m_rootDictionary = std::move(rootDictionary);
    else
        m_rootDictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, nullptr, nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
    m_dictionaryStack.append(m_rootDictionary.get());
}
Exemplo n.º 20
0
SDMMD_AMConnectionRef SDMMD__CreateTemporaryServConn(uint32_t socket, SSL *ssl) {
	SDMMD_AMConnectionRef handle = NULL;
	CFStringRef closeInvalid = CFSTR("CloseOnInvalidate");
	CFDictionaryRef dict = CFDictionaryCreate(kCFAllocatorDefault, (const void**)&closeInvalid, (const void**)&kCFBooleanFalse, 0x1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
	if (dict) {
		handle = SDMMD_AMDServiceConnectionCreate(socket, ssl, dict);
		CFSafeRelease(dict);
	}
	return handle;
}
int main()
{
    IOReturn            ret = 0;
    IOPMAssertionID     _id = 0;
    CFDictionaryRef     _props = 0;
    CFStringRef         keys[10];
    CFTypeRef           vals[10];
    int                 val = 0;
    
    ret = PMTestInitialize("PMAssertions", "com.apple.iokit.powertesting");
    if(kIOReturnSuccess != ret)
    {
        fprintf(stderr,"PMTestInitialize failed with IOReturn error code 0x%08x\n", ret);
        exit(-1);
    }
    
    
    keys[0] =       kIOPMAssertionTypeKey;
    vals[0] =       kIOPMAssertionTypePreventUserIdleSystemSleep;
    
    keys[1] =       kIOPMAssertionHumanReadableReasonKey;
    vals[1] =       CFSTR("I did this because I had to.");
    
    val =           500; // seconds
    keys[2] =       kIOPMAssertionTimeoutKey;
    vals[2] =       CFNumberCreate(0, kCFNumberIntType, &val);
    
    keys[3] =       kIOPMAssertionLocalizationBundlePathKey;
    vals[3] =       CFSTR("/System/Library/CoreServices/powerd.bundle");
    
    _props = CFDictionaryCreate(0, (const void **)keys, (const void **)vals, 4, 
                                &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    
    ret = IOPMAssertionCreateWithProperties(_props, &_id);
    
    CFRelease(_props);
    CFRelease(vals[0]);
    CFRelease(vals[2]);

    if (kIOReturnSuccess != ret) {
        PMTestFail("IOPMAssertionCreateWithProperties returns non-success 0x%08x\n", ret);
        exit(1);
    }

    ret = IOPMAssertionRelease(_id);
    
    if (kIOReturnSuccess != ret) {
        PMTestFail("IOPMAssertionRelease returns non-success 0x%08x\n", ret);
        exit(1);
    }
    
    PMTestPass("Successfully created and released via IOPMAssertionCrateWithProperties\n");
    
    return 0;
}
static CFDictionaryRef createConnectionProperties(bool shouldUseCredentialStorage, CFDictionaryRef clientProperties)
{
    static const CFStringRef webKitPrivateSessionCF = CFSTR("WebKitPrivateSession");
    static const CFStringRef _kCFURLConnectionSessionID = CFSTR("_kCFURLConnectionSessionID");
    static const CFStringRef kCFURLConnectionSocketStreamProperties = CFSTR("kCFURLConnectionSocketStreamProperties");

    CFDictionaryRef sessionID = shouldUseCredentialStorage ?
        CFDictionaryCreate(0, 0, 0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) :
        CFDictionaryCreate(0, (const void**)&_kCFURLConnectionSessionID, (const void**)&webKitPrivateSessionCF, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

    CFMutableDictionaryRef propertiesDictionary;
    if (clientProperties)
        propertiesDictionary = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, clientProperties);
    else
        propertiesDictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    CFDictionaryAddValue(propertiesDictionary, (const void*)kCFURLConnectionSocketStreamProperties, (const void*)sessionID);

    CFRelease(sessionID);
    return propertiesDictionary;
}
Exemplo n.º 23
0
/* Returns a shared empty dictionary (unless the allocator is not kCFAllocatorSystemDefault, in which case returns a newly allocated one).
*/
static CFDictionaryRef _CFErrorCreateEmptyDictionary(CFAllocatorRef allocator) {
    if (allocator == NULL) allocator = __CFGetDefaultAllocator();
    if (_CFAllocatorIsSystemDefault(allocator)) {
        static CFDictionaryRef emptyErrorDictionary = NULL;
        if (emptyErrorDictionary == NULL) {
            CFDictionaryRef tmp = CFDictionaryCreate(allocator, NULL, NULL, 0, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
            __CFSpinLock(&_CFErrorSpinlock);
            if (emptyErrorDictionary == NULL) {
                emptyErrorDictionary = tmp;
                __CFSpinUnlock(&_CFErrorSpinlock);
            } else {
                __CFSpinUnlock(&_CFErrorSpinlock);
                CFRelease(tmp);
            }
        }
        return (CFDictionaryRef)CFRetain(emptyErrorDictionary);
    } else {
        return CFDictionaryCreate(allocator, NULL, NULL, 0, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    }
}
Exemplo n.º 24
0
OSStatus
MoonVDADecoder::CreateDecoder (SInt32 inHeight, SInt32 inWidth, OSType inSourceFormat, CFDataRef inAVCCData)
{
	OSStatus status;

	CFMutableDictionaryRef decoderConfiguration = NULL;
	CFMutableDictionaryRef destinationImageBufferAttributes = NULL;
	CFDictionaryRef emptyDictionary;

	CFNumberRef height = NULL;
	CFNumberRef width= NULL;
	CFNumberRef sourceFormat = NULL;
	CFNumberRef pixelFormat = NULL;

	// source must be H.264
	if (inSourceFormat != 'avc1') {
		fprintf (stderr, "Source format is not H.264!\n");
		return paramErr;
	}

	// the avcC data chunk from the bitstream must be present
	if (inAVCCData == NULL) {
		fprintf (stderr, "avc1 decoder configuration data cannot be NULL!\n");
		return paramErr;
	}

	decoderConfiguration = CFDictionaryCreateMutable (kCFAllocatorDefault, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

	height = CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &inHeight);
	width = CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &inWidth);
	sourceFormat = CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &inSourceFormat);

	CFDictionarySetValue (decoderConfiguration, kVDADecoderConfiguration_Height, height);
	CFDictionarySetValue (decoderConfiguration, kVDADecoderConfiguration_Width, width);
	CFDictionarySetValue (decoderConfiguration, kVDADecoderConfiguration_SourceFormat, sourceFormat);
	CFDictionarySetValue (decoderConfiguration, kVDADecoderConfiguration_avcCData, inAVCCData);

	destinationImageBufferAttributes = CFDictionaryCreateMutable (kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

	OSType cvPixelFormatType = kCVPixelFormatType_422YpCbCr8;
	pixelFormat = CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &cvPixelFormatType);
	emptyDictionary = CFDictionaryCreate (kCFAllocatorDefault, NULL, NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

	CFDictionarySetValue (destinationImageBufferAttributes, kCVPixelBufferPixelFormatTypeKey, pixelFormat);
	CFDictionarySetValue (destinationImageBufferAttributes, kCVPixelBufferIOSurfacePropertiesKey, emptyDictionary);

	status = VDADecoderCreate (decoderConfiguration, destinationImageBufferAttributes, (VDADecoderOutputCallback*) VDADecoderCallback, this, (VDADecoder*) &decoder);

	if (decoderConfiguration) CFRelease (decoderConfiguration);
	if (destinationImageBufferAttributes) CFRelease (destinationImageBufferAttributes);
	if (emptyDictionary) CFRelease (emptyDictionary);

	return status;
}
Exemplo n.º 25
0
static int OSX_Mouse_Thread(void *ctx)
{
	if (!ctx)
		return 0;
	struct osx_mouse_data *mdata = static_cast<struct osx_mouse_data *>(ctx);
	
	IOHIDManagerRef hid_manager = IOHIDManagerCreate(kCFAllocatorSystemDefault, kIOHIDOptionsTypeNone);
	if (!hid_manager) {
		SDL_DestroyMutex(mdata->mouse_mutex);
		delete mdata;
		return 0;
	}
	
	if (IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
		CFRelease(hid_manager);
		SDL_DestroyMutex(mdata->mouse_mutex);
		delete mdata;
		return 0;
	}
	
	IOHIDManagerRegisterInputValueCallback(hid_manager, input_callback, mdata);
	IOHIDManagerScheduleWithRunLoop(hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
		
	uint32_t page = kHIDPage_GenericDesktop;
	uint32_t usage = kHIDUsage_GD_Mouse;
	CFDictionaryRef dict = NULL;
	CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
	CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
	const void *keys[2] = { CFSTR(kIOHIDDeviceUsagePageKey), CFSTR(kIOHIDDeviceUsageKey) };
	const void *vals[2] = { pageNumRef, usageNumRef };

	if (pageNumRef && usageNumRef)
		dict = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
	if (pageNumRef)
		CFRelease(pageNumRef);
	if (usageNumRef)
		CFRelease(usageNumRef);
	IOHIDManagerSetDeviceMatching(hid_manager, dict);
	if (dict)
		CFRelease(dict);

	while (!mdata->should_exit) {
		CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, false);
	}

	IOHIDManagerUnscheduleFromRunLoop(hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
	IOHIDManagerClose(hid_manager, kIOHIDOptionsTypeNone);
	
	CFRelease(hid_manager);
	SDL_DestroyMutex(mdata->mouse_mutex);
	delete mdata;
	return 0;
}
Exemplo n.º 26
0
static CFDictionaryRef imageSourceOptions()
{
    static CFDictionaryRef options;
    
    if (!options) {
        const void* keys[2] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32 };
        const void* values[2] = { kCFBooleanTrue, kCFBooleanTrue };
        options = CFDictionaryCreate(NULL, keys, values, 2, 
            &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    }
    return options;
}
Exemplo n.º 27
0
/* Note that there are two entry points for creating CFErrors. This one does it with individual keys and values which are used to create the userInfo dictionary.
*/
CFErrorRef CFErrorCreateWithUserInfoKeysAndValues(CFAllocatorRef allocator, CFStringRef domain, CFIndex code, const void *const *userInfoKeys, const void *const *userInfoValues, CFIndex numUserInfoValues) {
    __CFGenericValidateType(domain, CFStringGetTypeID());

    CFErrorRef err = (CFErrorRef)_CFRuntimeCreateInstance(allocator, __kCFErrorTypeID, sizeof(struct __CFError) - sizeof(CFRuntimeBase), NULL);
    if (NULL == err) return NULL;

    err->domain = CFStringCreateCopy(allocator, domain);
    err->code = code;
    err->userInfo = CFDictionaryCreate(allocator, (const void **)userInfoKeys, (const void **)userInfoValues, numUserInfoValues, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

    return err;
}
CFDictionaryRef
AppleVDADecoder::CreateOutputConfiguration()
{
  // Construct IOSurface Properties
  const void* IOSurfaceKeys[] = { MacIOSurfaceLib::kPropIsGlobal };
  const void* IOSurfaceValues[] = { kCFBooleanTrue };
  static_assert(ArrayLength(IOSurfaceKeys) == ArrayLength(IOSurfaceValues),
                "Non matching keys/values array size");

  // Contruct output configuration.
  AutoCFRelease<CFDictionaryRef> IOSurfaceProperties =
    CFDictionaryCreate(kCFAllocatorDefault,
                       IOSurfaceKeys,
                       IOSurfaceValues,
                       ArrayLength(IOSurfaceKeys),
                       &kCFTypeDictionaryKeyCallBacks,
                       &kCFTypeDictionaryValueCallBacks);

  SInt32 PixelFormatTypeValue = kCVPixelFormatType_32BGRA;
  AutoCFRelease<CFNumberRef> PixelFormatTypeNumber =
    CFNumberCreate(kCFAllocatorDefault,
                   kCFNumberSInt32Type,
                   &PixelFormatTypeValue);

  const void* outputKeys[] = { kCVPixelBufferIOSurfacePropertiesKey,
                               kCVPixelBufferPixelFormatTypeKey,
                               kCVPixelBufferOpenGLCompatibilityKey };
  const void* outputValues[] = { IOSurfaceProperties,
                                 PixelFormatTypeNumber,
                                 kCFBooleanTrue };
  static_assert(ArrayLength(outputKeys) == ArrayLength(outputValues),
                "Non matching keys/values array size");

  return CFDictionaryCreate(kCFAllocatorDefault,
                            outputKeys,
                            outputValues,
                            ArrayLength(outputKeys),
                            &kCFTypeDictionaryKeyCallBacks,
                            &kCFTypeDictionaryValueCallBacks);
}
Exemplo n.º 29
0
/* Helper to create a dictionary according to the given pts. */
static CFDictionaryRef vda_dictionary_with_pts(int64_t i_pts)
{
    CFStringRef key = CFSTR("FF_VDA_DECODER_PTS_KEY");
    CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &i_pts);
    CFDictionaryRef user_info = CFDictionaryCreate(kCFAllocatorDefault,
                                                   (const void **)&key,
                                                   (const void **)&value,
                                                   1,
                                                   &kCFTypeDictionaryKeyCallBacks,
                                                   &kCFTypeDictionaryValueCallBacks);
    CFRelease(value);
    return user_info;
}
Exemplo n.º 30
0
//
// Make CFDictionaries from stuff
//
CFDictionaryRef makeCFDictionary(unsigned count, ...)
{
	CFTypeRef keys[count], values[count];
	va_list args;
	va_start(args, count);
	for (unsigned n = 0; n < count; n++) {
		keys[n] = va_arg(args, CFTypeRef);
		values[n] = va_arg(args, CFTypeRef);
	}
	va_end(args);
	return CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, count,
		&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}