本文整理匯總了C++中CFDictionarySetValue函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFDictionarySetValue函數的具體用法?C++ CFDictionarySetValue怎麽用?C++ CFDictionarySetValue使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFDictionarySetValue函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: IOHIDManagerCreate
// open - open 1 or more devices
//
// Inputs:
// max = maximum number of devices to open
// vid = Vendor ID, or -1 if any
// pid = Product ID, or -1 if any
// usage_page = top level usage page, or -1 if any
// usage = top level usage number, or -1 if any
// Output:
// actual number of devices opened
//
int pjrc_rawhid::open(int max, int vid, int pid, int usage_page, int usage)
{
static IOHIDManagerRef hid_manager=NULL;
CFMutableDictionaryRef dict;
CFNumberRef num;
IOReturn ret;
hid_t *p;
int count=0;
if (first_hid) free_all_hid();
//printf("pjrc_rawhid_open, max=%d\n", max);
if (max < 1) return 0;
// Start the HID Manager
// http://developer.apple.com/technotes/tn2007/tn2187.html
if (!hid_manager) {
hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (hid_manager == NULL || CFGetTypeID(hid_manager) != IOHIDManagerGetTypeID()) {
if (hid_manager) CFRelease(hid_manager);
return 0;
}
}
if (vid > 0 || pid > 0 || usage_page > 0 || usage > 0) {
// Tell the HID Manager what type of devices we want
dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (!dict) return 0;
if (vid > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &vid);
CFDictionarySetValue(dict, CFSTR(kIOHIDVendorIDKey), num);
CFRelease(num);
}
if (pid > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pid);
CFDictionarySetValue(dict, CFSTR(kIOHIDProductIDKey), num);
CFRelease(num);
}
if (usage_page > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage_page);
CFDictionarySetValue(dict, CFSTR(kIOHIDPrimaryUsagePageKey), num);
CFRelease(num);
}
if (usage > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
CFDictionarySetValue(dict, CFSTR(kIOHIDPrimaryUsageKey), num);
CFRelease(num);
}
IOHIDManagerSetDeviceMatching(hid_manager, dict);
CFRelease(dict);
} else {
IOHIDManagerSetDeviceMatching(hid_manager, NULL);
}
// set up a callbacks for device attach & detach
IOHIDManagerScheduleWithRunLoop(hid_manager, CFRunLoopGetCurrent(),
kCFRunLoopDefaultMode);
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, attach_callback, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, detach_callback, NULL);
ret = IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone);
if (ret != kIOReturnSuccess) {
printf("Could not start IOHIDManager");
IOHIDManagerUnscheduleFromRunLoop(hid_manager,
CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
CFRelease(hid_manager);
return 0;
}
printf("run loop\n");
// let it do the callback for all devices
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) == kCFRunLoopRunHandledSource) ;
// count up how many were added by the callback
for (p = first_hid; p; p = p->next) count++;
return count;
}
示例2: add_supplemental
static void
add_supplemental(CFMutableArrayRef proxies, CFDictionaryRef proxy, uint32_t defaultOrder)
{
CFArrayRef domains;
CFIndex i;
CFIndex n_domains;
CFArrayRef orders;
domains = CFDictionaryGetValue(proxy, kSCPropNetProxiesSupplementalMatchDomains);
n_domains = isA_CFArray(domains) ? CFArrayGetCount(domains) : 0;
if (n_domains == 0) {
return;
}
orders = CFDictionaryGetValue(proxy, kSCPropNetProxiesSupplementalMatchOrders);
if (orders != NULL) {
if (!isA_CFArray(orders) || (n_domains != CFArrayGetCount(orders))) {
return;
}
}
/*
* yes, this is a "supplemental" proxy configuration, expand
* the match domains and add each to the proxies list.
*/
for (i = 0; i < n_domains; i++) {
CFStringRef match_domain;
CFNumberRef match_order;
CFMutableDictionaryRef match_proxy;
match_domain = CFArrayGetValueAtIndex(domains, i);
if (!isA_CFString(match_domain)) {
continue;
}
match_proxy = CFDictionaryCreateMutableCopy(NULL, 0, proxy);
// set supplemental proxy match "domain"
match_domain = _SC_trimDomain(match_domain);
if (match_domain != NULL) {
CFDictionarySetValue(match_proxy, kSCPropNetProxiesSupplementalMatchDomain, match_domain);
CFRelease(match_domain);
} else {
CFDictionaryRemoveValue(match_proxy, kSCPropNetProxiesSupplementalMatchDomain);
}
// set supplemental proxy match "order"
match_order = (orders != NULL) ? CFArrayGetValueAtIndex(orders, i) : NULL;
if (isA_CFNumber(match_order)) {
CFDictionarySetValue(match_proxy, PROXY_MATCH_ORDER_KEY, match_order);
} else {
CFNumberRef num;
num = CFNumberCreate(NULL, kCFNumberIntType, &defaultOrder);
CFDictionarySetValue(match_proxy, PROXY_MATCH_ORDER_KEY, num);
CFRelease(num);
defaultOrder++; // if multiple domains, maintain ordering
}
// remove keys we don't want in a supplemental proxy
CFDictionaryRemoveValue(match_proxy, kSCPropNetProxiesSupplementalMatchDomains);
CFDictionaryRemoveValue(match_proxy, kSCPropNetProxiesSupplementalMatchOrders);
CFDictionaryRemoveValue(match_proxy, kSCPropInterfaceName);
add_proxy(proxies, match_proxy);
CFRelease(match_proxy);
}
return;
}
示例3: __addKeysAndValues
static void __addKeysAndValues(const void *key, const void *value, void *context) {
CFDictionarySetValue((CFMutableDictionaryRef)context, key, value);
}
示例4: add_supplemental_proxies
static void
add_supplemental_proxies(CFMutableArrayRef proxies, CFDictionaryRef services, CFArrayRef service_order)
{
const void * keys_q[N_QUICK];
const void ** keys = keys_q;
CFIndex i;
CFIndex n_order;
CFIndex n_services;
const void * vals_q[N_QUICK];
const void ** vals = vals_q;
n_services = isA_CFDictionary(services) ? CFDictionaryGetCount(services) : 0;
if (n_services == 0) {
return; // if no services
}
if (n_services > (CFIndex)(sizeof(keys_q) / sizeof(CFTypeRef))) {
keys = CFAllocatorAllocate(NULL, n_services * sizeof(CFTypeRef), 0);
vals = CFAllocatorAllocate(NULL, n_services * sizeof(CFTypeRef), 0);
}
n_order = isA_CFArray(service_order) ? CFArrayGetCount(service_order) : 0;
CFDictionaryGetKeysAndValues(services, keys, vals);
for (i = 0; i < n_services; i++) {
uint32_t defaultOrder;
CFDictionaryRef proxy;
CFMutableDictionaryRef proxyWithDNS = NULL;
CFDictionaryRef service = (CFDictionaryRef)vals[i];
if (!isA_CFDictionary(service)) {
continue;
}
proxy = CFDictionaryGetValue(service, kSCEntNetProxies);
if (!isA_CFDictionary(proxy)) {
continue;
}
if ((G_supplemental_proxies_follow_dns != NULL) && CFBooleanGetValue(G_supplemental_proxies_follow_dns)) {
CFDictionaryRef dns;
CFArrayRef matchDomains;
CFArrayRef matchOrders;
if (!CFDictionaryContainsKey(proxy, kSCPropNetProxiesSupplementalMatchDomains) &&
CFDictionaryGetValueIfPresent(service, kSCEntNetDNS, (const void **)&dns) &&
isA_CFDictionary(dns) &&
CFDictionaryGetValueIfPresent(dns, kSCPropNetDNSSupplementalMatchDomains, (const void **)&matchDomains) &&
isA_CFArray(matchDomains)) {
proxyWithDNS = CFDictionaryCreateMutableCopy(NULL, 0, proxy);
CFDictionarySetValue(proxyWithDNS, kSCPropNetProxiesSupplementalMatchDomains, matchDomains);
if (CFDictionaryGetValueIfPresent(dns, kSCPropNetDNSSupplementalMatchOrders, (const void **)&matchOrders) &&
isA_CFArray(matchOrders)) {
CFDictionarySetValue(proxyWithDNS, kSCPropNetProxiesSupplementalMatchOrders, matchOrders);
} else {
CFDictionaryRemoveValue(proxyWithDNS, kSCPropNetProxiesSupplementalMatchOrders);
}
proxy = proxyWithDNS;
}
}
defaultOrder = DEFAULT_MATCH_ORDER
- (DEFAULT_MATCH_ORDER / 2)
+ ((DEFAULT_MATCH_ORDER / 1000) * i);
if ((n_order > 0) &&
!CFArrayContainsValue(service_order, CFRangeMake(0, n_order), keys[i])) {
// push out services not specified in service order
defaultOrder += (DEFAULT_MATCH_ORDER / 1000) * n_services;
}
add_supplemental(proxies, proxy, defaultOrder);
if (proxyWithDNS != NULL) CFRelease(proxyWithDNS);
}
if (keys != keys_q) {
CFAllocatorDeallocate(NULL, keys);
CFAllocatorDeallocate(NULL, vals);
}
return;
}
示例5: copy_scoped_proxies
static CFDictionaryRef
copy_scoped_proxies(CFDictionaryRef services, CFArrayRef order)
{
CFIndex i;
CFIndex n_order;
CFMutableDictionaryRef scoped = NULL;
// iterate over services
n_order = isA_CFArray(order) ? CFArrayGetCount(order) : 0;
for (i = 0; i < n_order; i++) {
char if_name[IF_NAMESIZE];
CFStringRef interface;
CFMutableDictionaryRef newProxy;
CFDictionaryRef proxy;
CFDictionaryRef service;
CFStringRef serviceID;
serviceID = CFArrayGetValueAtIndex(order, i);
service = CFDictionaryGetValue(services, serviceID);
if (!isA_CFDictionary(service)) {
// if no service
continue;
}
proxy = CFDictionaryGetValue(service, kSCEntNetProxies);
if (!isA_CFDictionary(proxy)) {
// if no proxy
continue;
}
interface = CFDictionaryGetValue(proxy, kSCPropInterfaceName);
if (interface == NULL) {
// if no [scoped] interface
continue;
}
if ((scoped != NULL) &&
CFDictionaryContainsKey(scoped, interface)) {
// if we've already processed this [scoped] interface
continue;
}
if ((_SC_cfstring_to_cstring(interface,
if_name,
sizeof(if_name),
kCFStringEncodingASCII) == NULL) ||
((if_nametoindex(if_name)) == 0)) {
// if interface index not available
continue;
}
// add [scoped] proxy entry
// ... and remove keys we don't want in a [scoped] proxy
CFRetain(interface);
newProxy = CFDictionaryCreateMutableCopy(NULL, 0, proxy);
CFDictionaryRemoveValue(newProxy, kSCPropNetProxiesSupplementalMatchDomains);
CFDictionaryRemoveValue(newProxy, kSCPropNetProxiesSupplementalMatchOrders);
CFDictionaryRemoveValue(newProxy, kSCPropInterfaceName);
if (scoped == NULL) {
scoped = CFDictionaryCreateMutable(NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
}
CFDictionarySetValue(scoped, interface, newProxy);
CFRelease(newProxy);
CFRelease(interface);
}
return scoped;
}
示例6: stream
bool SFB::Audio::MP3Metadata::_ReadMetadata(CFErrorRef *error)
{
UInt8 buf [PATH_MAX];
if(!CFURLGetFileSystemRepresentation(mURL, false, buf, PATH_MAX))
return false;
std::unique_ptr<TagLib::FileStream> stream(new TagLib::FileStream((const char *)buf, true));
if(!stream->isOpen()) {
if(error) {
SFB::CFString description(CFCopyLocalizedString(CFSTR("The file “%@” could not be opened for reading."), ""));
SFB::CFString failureReason(CFCopyLocalizedString(CFSTR("Input/output error"), ""));
SFB::CFString recoverySuggestion(CFCopyLocalizedString(CFSTR("The file may have been renamed, moved, deleted, or you may not have appropriate permissions."), ""));
*error = CreateErrorForURL(Metadata::ErrorDomain, Metadata::InputOutputError, description, mURL, failureReason, recoverySuggestion);
}
return false;
}
TagLib::MPEG::File file(stream.get(), TagLib::ID3v2::FrameFactory::instance());
if(!file.isValid()) {
if(nullptr != error) {
SFB::CFString description(CFCopyLocalizedString(CFSTR("The file “%@” is not a valid MPEG file."), ""));
SFB::CFString failureReason(CFCopyLocalizedString(CFSTR("Not an MPEG file"), ""));
SFB::CFString recoverySuggestion(CFCopyLocalizedString(CFSTR("The file's extension may not match the file's type."), ""));
*error = CreateErrorForURL(Metadata::ErrorDomain, Metadata::InputOutputError, description, mURL, failureReason, recoverySuggestion);
}
return false;
}
CFDictionarySetValue(mMetadata, kFormatNameKey, CFSTR("MP3"));
if(file.audioProperties()) {
auto properties = file.audioProperties();
AddAudioPropertiesToDictionary(mMetadata, properties);
// TODO: Is this too much information?
#if 0
switch(properties->version()) {
case TagLib::MPEG::Header::Version1:
switch(properties->layer()) {
case 1: CFDictionarySetValue(mMetadata, kFormatNameKey, CFSTR("MPEG-1 Layer I")); break;
case 2: CFDictionarySetValue(mMetadata, kFormatNameKey, CFSTR("MPEG-1 Layer II")); break;
case 3: CFDictionarySetValue(mMetadata, kFormatNameKey, CFSTR("MPEG-1 Layer III")); break;
}
break;
case TagLib::MPEG::Header::Version2:
switch(properties->layer()) {
case 1: CFDictionarySetValue(mMetadata, kFormatNameKey, CFSTR("MPEG-2 Layer I")); break;
case 2: CFDictionarySetValue(mMetadata, kFormatNameKey, CFSTR("MPEG-2 Layer II")); break;
case 3: CFDictionarySetValue(mMetadata, kFormatNameKey, CFSTR("MPEG-2 Layer III")); break;
}
break;
case TagLib::MPEG::Header::Version2_5:
switch(properties->layer()) {
case 1: CFDictionarySetValue(mMetadata, kFormatNameKey, CFSTR("MPEG-2.5 Layer I")); break;
case 2: CFDictionarySetValue(mMetadata, kFormatNameKey, CFSTR("MPEG-2.5 Layer II")); break;
case 3: CFDictionarySetValue(mMetadata, kFormatNameKey, CFSTR("MPEG-2.5 Layer III")); break;
}
break;
}
#endif
if(properties->xingHeader() && properties->xingHeader()->totalFrames())
AddIntToDictionary(mMetadata, kTotalFramesKey, (int)properties->xingHeader()->totalFrames());
}
if(file.APETag())
AddAPETagToDictionary(mMetadata, mPictures, file.APETag());
if(file.ID3v1Tag())
AddID3v1TagToDictionary(mMetadata, file.ID3v1Tag());
if(file.ID3v2Tag())
AddID3v2TagToDictionary(mMetadata, mPictures, file.ID3v2Tag());
return true;
}
示例7: drives_available
drives_s* drives_available(){
CFMutableDictionaryRef main_dict = NULL;
CFMutableDictionaryRef sec_dict = NULL;
io_iterator_t itt = IO_OBJECT_NULL;
io_name_t cls_name;
io_service_t sd = IO_OBJECT_NULL;
IOCFPlugInInterface **plg_in_intf = NULL;
SCSITaskDeviceInterface **dev_intf = NULL;
MMCDeviceInterface **mmc_intf = NULL;
SInt32 score = 0;
int count;
int ret = 1;
drive_s* d = 0;
drives_s* dd = 0;
if((main_dict = CFDictionaryCreateMutable(kCFAllocatorDefault,0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks)) != NULL){
if((sec_dict = CFDictionaryCreateMutable(kCFAllocatorDefault,0,&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)) != NULL){
CFDictionarySetValue(sec_dict,CFSTR(kIOPropertySCSITaskDeviceCategory),CFSTR(kIOPropertySCSITaskAuthoringDevice));
CFDictionarySetValue(main_dict,CFSTR(kIOPropertyMatchKey),sec_dict);
CFRelease(sec_dict);
}
}
if(IOServiceGetMatchingServices(kIOMasterPortDefault,main_dict,&itt)){
printf("no matching services\n");
return 0;
}
count = 0;
while((sd = IOIteratorNext(itt))) {
if(!IOObjectGetClass(sd,cls_name)){
if(!IOCreatePlugInInterfaceForService(sd,kIOMMCDeviceUserClientTypeID,kIOCFPlugInInterfaceID,&plg_in_intf,&score) &&
!(*plg_in_intf)->QueryInterface(plg_in_intf,CFUUIDGetUUIDBytes(kIOMMCDeviceInterfaceID),(LPVOID*)&mmc_intf))
{
dev_intf = (*mmc_intf)->GetSCSITaskDeviceInterface(mmc_intf);
if(dev_intf){
drive_data_s dd;
dd.mmc_intf = mmc_intf;
dd.plg_in_intf = plg_in_intf;
dd.itt = itt;
dd.dev_intf = dev_intf;
if(drive_type((int)&dd) == T_CDROM){
inquiry_s* inq;
count++;
d = (drive_s*)realloc(d,count*sizeof(drive_s));
inq = drive_inquiry((int)&dd);
memcpy(&d[count-1].name,inq->p_id,sizeof(inq->p_id));
d[count-1].id = count;
free(inq);
}
}
}
if(IOObjectRelease(sd)) ret = 0;
}
if(mmc_intf != NULL)(*mmc_intf)->Release(mmc_intf);
if(plg_in_intf != NULL)IODestroyPlugInInterface(plg_in_intf);
}
IOObjectRelease(itt);
dd = (drives_s*)malloc(sizeof(drives_s));
if(dd){
dd->drives = d;
dd->number = count;
}else{
free(d);
return 0;
}
if(ret)
return dd;
else return 0;
}
示例8: cert_load_defaults
static value cert_load_defaults(){
#if defined(NEKO_WINDOWS)
value v;
HCERTSTORE store;
PCCERT_CONTEXT cert;
mbedtls_x509_crt *chain = (mbedtls_x509_crt *)alloc(sizeof(mbedtls_x509_crt));
mbedtls_x509_crt_init( chain );
if( store = CertOpenSystemStore(0, (LPCSTR)"Root") ){
cert = NULL;
while( cert = CertEnumCertificatesInStore(store, cert) )
mbedtls_x509_crt_parse_der( chain, (unsigned char *)cert->pbCertEncoded, cert->cbCertEncoded );
CertCloseStore(store, 0);
}
v = alloc_abstract(k_cert, chain);
val_gc(v,free_cert);
return v;
#elif defined(NEKO_MAC)
CFMutableDictionaryRef search;
CFArrayRef result;
SecKeychainRef keychain;
SecCertificateRef item;
CFDataRef dat;
value v;
mbedtls_x509_crt *chain = NULL;
// Load keychain
if( SecKeychainOpen("/System/Library/Keychains/SystemRootCertificates.keychain",&keychain) != errSecSuccess )
return val_null;
// Search for certificates
search = CFDictionaryCreateMutable( NULL, 0, NULL, NULL );
CFDictionarySetValue( search, kSecClass, kSecClassCertificate );
CFDictionarySetValue( search, kSecMatchLimit, kSecMatchLimitAll );
CFDictionarySetValue( search, kSecReturnRef, kCFBooleanTrue );
CFDictionarySetValue( search, kSecMatchSearchList, CFArrayCreate(NULL, (const void **)&keychain, 1, NULL) );
if( SecItemCopyMatching( search, (CFTypeRef *)&result ) == errSecSuccess ){
CFIndex n = CFArrayGetCount( result );
for( CFIndex i = 0; i < n; i++ ){
item = (SecCertificateRef)CFArrayGetValueAtIndex( result, i );
// Get certificate in DER format
dat = SecCertificateCopyData( item );
if( dat ){
if( chain == NULL ){
chain = (mbedtls_x509_crt *)alloc(sizeof(mbedtls_x509_crt));
mbedtls_x509_crt_init( chain );
}
mbedtls_x509_crt_parse_der( chain, (unsigned char *)CFDataGetBytePtr(dat), CFDataGetLength(dat) );
CFRelease( dat );
}
}
}
CFRelease(keychain);
if( chain != NULL ){
v = alloc_abstract(k_cert, chain);
val_gc(v,free_cert);
return v;
}else{
return val_null;
}
#else
return val_null;
#endif
}
示例9: copy_cdsa_certificate
static CFArrayRef /* O - Array of certificates */
copy_cdsa_certificate(
cupsd_client_t *con) /* I - Client connection */
{
OSStatus err; /* Error info */
SecKeychainRef keychain = NULL;/* Keychain reference */
SecIdentitySearchRef search = NULL; /* Search reference */
SecIdentityRef identity = NULL;/* Identity */
CFArrayRef certificates = NULL;
/* Certificate array */
SecPolicyRef policy = NULL; /* Policy ref */
CFStringRef servername = NULL;
/* Server name */
CFMutableDictionaryRef query = NULL; /* Query qualifiers */
CFArrayRef list = NULL; /* Keychain list */
# if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
char localname[1024];/* Local hostname */
# endif /* HAVE_DNSSD || HAVE_AVAHI */
cupsdLogMessage(CUPSD_LOG_DEBUG,
"copy_cdsa_certificate: Looking for certs for \"%s\".",
con->servername);
if ((err = SecKeychainOpen(ServerCertificate, &keychain)))
{
cupsdLogMessage(CUPSD_LOG_ERROR, "Cannot open keychain \"%s\" - %s (%d)",
ServerCertificate, cssmErrorString(err), (int)err);
goto cleanup;
}
servername = CFStringCreateWithCString(kCFAllocatorDefault, con->servername,
kCFStringEncodingUTF8);
policy = SecPolicyCreateSSL(1, servername);
if (servername)
CFRelease(servername);
if (!policy)
{
cupsdLogMessage(CUPSD_LOG_ERROR, "Cannot create ssl policy reference");
goto cleanup;
}
if (!(query = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)))
{
cupsdLogMessage(CUPSD_LOG_ERROR, "Cannot create query dictionary");
goto cleanup;
}
list = CFArrayCreate(kCFAllocatorDefault, (const void **)&keychain, 1,
&kCFTypeArrayCallBacks);
CFDictionaryAddValue(query, kSecClass, kSecClassIdentity);
CFDictionaryAddValue(query, kSecMatchPolicy, policy);
CFDictionaryAddValue(query, kSecReturnRef, kCFBooleanTrue);
CFDictionaryAddValue(query, kSecMatchLimit, kSecMatchLimitOne);
CFDictionaryAddValue(query, kSecMatchSearchList, list);
CFRelease(list);
err = SecItemCopyMatching(query, (CFTypeRef *)&identity);
# if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
if (err && DNSSDHostName)
{
/*
* Search for the connection server name failed; try the DNS-SD .local
* hostname instead...
*/
snprintf(localname, sizeof(localname), "%s.local", DNSSDHostName);
cupsdLogMessage(CUPSD_LOG_DEBUG,
"copy_cdsa_certificate: Looking for certs for \"%s\".",
localname);
servername = CFStringCreateWithCString(kCFAllocatorDefault, localname,
kCFStringEncodingUTF8);
CFRelease(policy);
policy = SecPolicyCreateSSL(1, servername);
if (servername)
CFRelease(servername);
if (!policy)
{
cupsdLogMessage(CUPSD_LOG_ERROR, "Cannot create ssl policy reference");
goto cleanup;
}
CFDictionarySetValue(query, kSecMatchPolicy, policy);
err = SecItemCopyMatching(query, (CFTypeRef *)&identity);
}
//.........這裏部分代碼省略.........
示例10: Q_ASSERT
/**
* @brief open - open 1 or more devices
* @param[in] max maximum number of devices to open
* @param[in] vid Vendor ID, or -1 if any
* @param[in] pid Product ID, or -1 if any
* @param[in] usage_page top level usage page, or -1 if any
* @param[in] usage top level usage number, or -1 if any
* @returns actual number of devices opened
*/
int pjrc_rawhid::open(int max, int vid, int pid, int usage_page, int usage)
{
CFMutableDictionaryRef dict;
CFNumberRef num;
IOReturn ret;
Q_ASSERT(hid_manager == NULL);
Q_ASSERT(device_open == false);
attach_count = 0;
// Start the HID Manager
hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (hid_manager == NULL || CFGetTypeID(hid_manager) != IOHIDManagerGetTypeID()) {
if (hid_manager) CFRelease(hid_manager);
return 0;
}
if (vid > 0 || pid > 0 || usage_page > 0 || usage > 0) {
// Tell the HID Manager what type of devices we want
dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (!dict) return 0;
if (vid > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &vid);
CFDictionarySetValue(dict, CFSTR(kIOHIDVendorIDKey), num);
CFRelease(num);
}
if (pid > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pid);
CFDictionarySetValue(dict, CFSTR(kIOHIDProductIDKey), num);
CFRelease(num);
}
if (usage_page > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage_page);
CFDictionarySetValue(dict, CFSTR(kIOHIDPrimaryUsagePageKey), num);
CFRelease(num);
}
if (usage > 0) {
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
CFDictionarySetValue(dict, CFSTR(kIOHIDPrimaryUsageKey), num);
CFRelease(num);
}
IOHIDManagerSetDeviceMatching(hid_manager, dict);
CFRelease(dict);
} else {
IOHIDManagerSetDeviceMatching(hid_manager, NULL);
}
// Set the run loop reference before configuring the attach callback
the_correct_runloop = CFRunLoopGetCurrent();
// set up a callbacks for device attach & detach
IOHIDManagerScheduleWithRunLoop(hid_manager, CFRunLoopGetCurrent(),
kCFRunLoopDefaultMode);
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, pjrc_rawhid::attach_callback, this);
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, pjrc_rawhid::dettach_callback, this);
ret = IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone);
if (ret != kIOReturnSuccess) {
IOHIDManagerUnscheduleFromRunLoop(hid_manager,
CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
CFRelease(hid_manager);
return 0;
}
// let it do the callback for all devices
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) == kCFRunLoopRunHandledSource) ;
// count up how many were added by the callback
return attach_count;
}
示例11: IOServiceMatching
brick_t *find_usb_devices (
void *usb,
int32_t vendor, int32_t product,
int32_t configuration, int32_t interface,
brick_type_t type) {
usb_handle_t *h = (usb_handle_t *) usb;
CFMutableDictionaryRef matching;
kern_return_t kr;
io_iterator_t devices;
io_service_t device;
brick_t *bricks = NULL;
int count;
if (configuration) {
matching = IOServiceMatching (kIOUSBInterfaceClassName);
} else {
matching = IOServiceMatching (kIOUSBDeviceClassName);
}
if (!matching) {
return NULL;
}
CFDictionarySetValue (matching, CFSTR (kUSBVendorID),
CFNumberCreate (kCFAllocatorDefault,
kCFNumberSInt32Type, &vendor));
CFDictionarySetValue (matching, CFSTR (kUSBProductID),
CFNumberCreate (kCFAllocatorDefault,
kCFNumberSInt32Type, &product));
if (configuration) {
CFDictionarySetValue (matching, CFSTR (kUSBConfigurationValue),
CFNumberCreate (kCFAllocatorDefault,
kCFNumberSInt32Type, &configuration));
CFDictionarySetValue (matching, CFSTR (kUSBInterfaceNumber),
CFNumberCreate (kCFAllocatorDefault,
kCFNumberSInt32Type, &interface));
}
kr = IOServiceGetMatchingServices (h->port, matching, &devices);
if (kr) {
fprintf (stderr, "IOService matching error = %08x\n", kr);
return NULL;
}
count = 0;
while ((device = IOIteratorNext (devices)))
count++;
if (count > 0) {
int i = 0;
IOIteratorReset (devices);
bricks = malloc ((sizeof (brick_t)) * (count + 1));
memset ((void *) bricks, 0, (sizeof (brick_t )) * (count + 1));
while ((device = IOIteratorNext (devices))) {
IOUSBInterfaceInterface182 **intf = NULL;
IOUSBDeviceInterface **dev = NULL;
IOCFPlugInInterface **plugInInterface = NULL;
brick_t *b = &(bricks[i]);
HRESULT result;
SInt32 score;
if (configuration) {
kr = IOCreatePlugInInterfaceForService (
device, kIOUSBInterfaceUserClientTypeID, kIOCFPlugInInterfaceID,
&plugInInterface, &score
);
} else {
kr = IOCreatePlugInInterfaceForService (
device, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID,
&plugInInterface, &score
);
}
if (kr || !plugInInterface) {
continue;
}
if (configuration) {
result = (*plugInInterface)->QueryInterface (
plugInInterface,
CFUUIDGetUUIDBytes (kIOUSBInterfaceInterfaceID182),
(LPVOID *) &intf
);
} else {
result = (*plugInInterface)->QueryInterface (
plugInInterface,
CFUUIDGetUUIDBytes (kIOUSBDeviceInterfaceID),
(LPVOID *) &dev
);
}
(*plugInInterface)->Release (plugInInterface);
if (result || !(dev || intf)) {
continue;
}
//.........這裏部分代碼省略.........
示例12: mailstream_cfstream_set_ssl_enabled
int mailstream_cfstream_set_ssl_enabled(mailstream * s, int ssl_enabled)
{
#if HAVE_CFNETWORK
struct mailstream_cfstream_data * cfstream_data;
int r;
cfstream_data = (struct mailstream_cfstream_data *) s->low->data;
cfstream_data->ssl_enabled = ssl_enabled;
if (ssl_enabled) {
CFMutableDictionaryRef settings;
settings = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
switch (cfstream_data->ssl_level) {
case MAILSTREAM_CFSTREAM_SSL_LEVEL_NONE:
CFDictionarySetValue(settings, kCFStreamSSLLevel, kCFStreamSocketSecurityLevelNone);
break;
case MAILSTREAM_CFSTREAM_SSL_LEVEL_SSLv2:
CFDictionarySetValue(settings, kCFStreamSSLLevel, kCFStreamSocketSecurityLevelSSLv2);
break;
case MAILSTREAM_CFSTREAM_SSL_LEVEL_SSLv3:
CFDictionarySetValue(settings, kCFStreamSSLLevel, kCFStreamSocketSecurityLevelSSLv3);
break;
case MAILSTREAM_CFSTREAM_SSL_LEVEL_TLSv1:
CFDictionarySetValue(settings, kCFStreamSSLLevel, kCFStreamSocketSecurityLevelTLSv1);
break;
case MAILSTREAM_CFSTREAM_SSL_LEVEL_NEGOCIATED_SSL:
CFDictionarySetValue(settings, kCFStreamSSLLevel, kCFStreamSocketSecurityLevelNegotiatedSSL);
break;
}
if ((cfstream_data->ssl_certificate_verification_mask & MAILSTREAM_CFSTREAM_SSL_ALLOWS_EXPIRED_CERTIFICATES) != 0) {
CFDictionarySetValue(settings, kCFStreamSSLAllowsExpiredCertificates, kCFBooleanTrue);
}
if ((cfstream_data->ssl_certificate_verification_mask & MAILSTREAM_CFSTREAM_SSL_ALLOWS_EXPIRED_ROOTS) != 0) {
CFDictionarySetValue(settings, kCFStreamSSLAllowsExpiredRoots, kCFBooleanTrue);
}
if ((cfstream_data->ssl_certificate_verification_mask & MAILSTREAM_CFSTREAM_SSL_ALLOWS_ANY_ROOT) != 0) {
CFDictionarySetValue(settings, kCFStreamSSLAllowsAnyRoot, kCFBooleanTrue);
}
if ((cfstream_data->ssl_certificate_verification_mask & MAILSTREAM_CFSTREAM_SSL_DISABLE_VALIDATES_CERTIFICATE_CHAIN) != 0) {
CFDictionarySetValue(settings, kCFStreamSSLValidatesCertificateChain, kCFBooleanFalse);
}
CFReadStreamSetProperty(cfstream_data->readStream, kCFStreamPropertySSLSettings, settings);
CFWriteStreamSetProperty(cfstream_data->writeStream, kCFStreamPropertySSLSettings, settings);
CFRelease(settings);
}
else {
CFMutableDictionaryRef settings;
settings = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(settings, kCFStreamSSLLevel, kCFStreamSocketSecurityLevelNone);
CFReadStreamSetProperty(cfstream_data->readStream, kCFStreamPropertySSLSettings, settings);
CFWriteStreamSetProperty(cfstream_data->writeStream, kCFStreamPropertySSLSettings, settings);
CFRelease(settings);
//fprintf(stderr, "is not ssl\n");
}
// We need to investigate more about how to establish a STARTTLS connection.
// For now, wait until we get the certificate chain.
while (1) {
r = wait_runloop(s->low, STATE_WAIT_SSL);
if (r != WAIT_RUNLOOP_EXIT_NO_ERROR) {
return -1;
}
if (cfstream_data->writeSSLResult < 0)
return -1;
if (cfstream_data->readSSLResult < 0)
return -1;
SecTrustRef secTrust = (SecTrustRef)CFReadStreamCopyProperty(cfstream_data->readStream, kCFStreamPropertySSLPeerTrust);
if (secTrust == NULL) {
// No trust, wait more.
continue;
}
CFIndex count = SecTrustGetCertificateCount(secTrust);
CFRelease(secTrust);
if (count == 0) {
// No certificates, wait more.
continue;
}
break;
}
return 0;
#else
return -1;
#endif
}
示例13: CFDictionaryRemoveAllValues
bool FLACMetadata::ReadMetadata(CFErrorRef *error)
{
// Start from scratch
CFDictionaryRemoveAllValues(mMetadata);
CFDictionaryRemoveAllValues(mChangedMetadata);
UInt8 buf [PATH_MAX];
if(!CFURLGetFileSystemRepresentation(mURL, false, buf, PATH_MAX))
return false;
auto stream = new TagLib::FileStream(reinterpret_cast<const char *>(buf), true);
TagLib::FLAC::File file(stream, TagLib::ID3v2::FrameFactory::instance());
if(!file.isValid()) {
if(nullptr != error) {
CFStringRef description = CFCopyLocalizedString(CFSTR("The file “%@” is not a valid FLAC file."), "");
CFStringRef failureReason = CFCopyLocalizedString(CFSTR("Not a FLAC file"), "");
CFStringRef recoverySuggestion = CFCopyLocalizedString(CFSTR("The file's extension may not match the file's type."), "");
*error = CreateErrorForURL(AudioMetadataErrorDomain, AudioMetadataInputOutputError, description, mURL, failureReason, recoverySuggestion);
CFRelease(description), description = nullptr;
CFRelease(failureReason), failureReason = nullptr;
CFRelease(recoverySuggestion), recoverySuggestion = nullptr;
}
return false;
}
CFDictionarySetValue(mMetadata, kPropertiesFormatNameKey, CFSTR("FLAC"));
if(file.audioProperties()) {
auto properties = file.audioProperties();
AddAudioPropertiesToDictionary(mMetadata, properties);
if(properties->sampleWidth())
AddIntToDictionary(mMetadata, kPropertiesBitsPerChannelKey, properties->sampleWidth());
if(properties->sampleFrames())
AddLongLongToDictionary(mMetadata, kPropertiesTotalFramesKey, properties->sampleFrames());
}
// Add all tags that are present
if(file.ID3v1Tag())
AddID3v1TagToDictionary(mMetadata, file.ID3v1Tag());
if(file.ID3v2Tag()) {
std::vector<AttachedPicture *> pictures;
AddID3v2TagToDictionary(mMetadata, pictures, file.ID3v2Tag());
for(auto picture : pictures)
AddSavedPicture(picture);
}
if(file.xiphComment()) {
std::vector<AttachedPicture *> pictures;
AddXiphCommentToDictionary(mMetadata, pictures, file.xiphComment());
for(auto picture : pictures)
AddSavedPicture(picture);
}
// Add album art
for(auto iter : file.pictureList()) {
CFDataRef data = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(iter->data().data()), iter->data().size());
CFStringRef description = nullptr;
if(!iter->description().isNull())
description = CFStringCreateWithCString(kCFAllocatorDefault, iter->description().toCString(true), kCFStringEncodingUTF8);
AttachedPicture *picture = new AttachedPicture(data, static_cast<AttachedPicture::Type>(iter->type()), description);
AddSavedPicture(picture);
if(data)
CFRelease(data), data = nullptr;
if(description)
CFRelease(description), description = nullptr;
}
return true;
}
示例14: emit_item
static int emit_item(pkcs12_context * context, NSS_Attribute **attrs,
CFStringRef item_key, CFTypeRef item_value)
{
int result = -1;
/* parse attrs into friendlyName, localKeyId; ignoring generic attrs */
CFMutableDictionaryRef attr_dict = CFDictionaryCreateMutable(kCFAllocatorDefault,
0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
require(attr_dict, out);
unsigned numAttrs = nssArraySize((const void **)attrs);
unsigned int dex;
for(dex = 0; dex < numAttrs; dex++) {
NSS_Attribute *attr = attrs[dex];
unsigned numValues = nssArraySize((const void**)attr->attrValue);
DERItem type = { attr->attrType.Data, attr->attrType.Length };
if(DEROidCompare(&type, &oidFriendlyName)) {
/*
* BMP string (UniCode). Spec says only one legal value.
*/
require(numValues == 1, out);
SecAsn1Item friendly_name_asn1;
require_noerr(decode_item(context, attr->attrValue[0],
kSecAsn1BMPStringTemplate, &friendly_name_asn1), out);
CFStringRef friendly_name = CFStringCreateWithBytes(kCFAllocatorDefault,
friendly_name_asn1.Data, friendly_name_asn1.Length,
kCFStringEncodingUnicode, true);
if (friendly_name) {
CFDictionarySetValue(attr_dict, kSecImportItemLabel, friendly_name);
CFRelease(friendly_name);
}
}
else if(DEROidCompare(&type, &oidLocalKeyId)) {
/*
* Octet string. Spec says only one legal value.
*/
require(numValues == 1, out);
SecAsn1Item local_key_id;
require_noerr(decode_item(context, attr->attrValue[0],
kSecAsn1OctetStringTemplate, &local_key_id), out);
CFDataRef keyid = CFDataCreate(kCFAllocatorDefault, local_key_id.Data, local_key_id.Length);
if (keyid) {
CFDictionarySetValue(attr_dict, kSecImportItemKeyID, keyid);
CFRelease(keyid);
}
}
}
CFTypeRef key = CFDictionaryGetValue(attr_dict, kSecImportItemKeyID);
if (!key)
key = CFDictionaryGetValue(attr_dict, kSecImportItemLabel);
if (!key)
key = item_value;
CFMutableDictionaryRef item = (CFMutableDictionaryRef)CFDictionaryGetValue(context->items, key);
if (item) {
CFDictionarySetValue(item, item_key, item_value);
} else {
CFDictionarySetValue(attr_dict, item_key, item_value);
CFDictionarySetValue(context->items, key, attr_dict);
}
result = 0;
out:
CFReleaseSafe(attr_dict);
return result;
}
示例15: apple_init_profile
static void
apple_init_profile(
ppd_file_t *ppd, /* I - PPD file */
cups_array_t *languages, /* I - Languages in the PPD file */
CFMutableDictionaryRef profile, /* I - Profile dictionary */
unsigned id, /* I - Profile ID */
const char *name, /* I - Profile name */
const char *text, /* I - Profile UI text */
const char *iccfile) /* I - ICC filename */
{
CFURLRef url; /* URL for profile filename */
CFMutableDictionaryRef dict; /* Dictionary for name */
char *language; /* Current language */
ppd_attr_t *attr; /* Profile attribute */
CFStringRef cflang, /* Language string */
cftext; /* Localized text */
(void)id;
/*
* Build the profile name dictionary...
*/
dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
if (!dict)
{
cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to initialize profile \"%s\".",
iccfile);
return;
}
cftext = CFStringCreateWithCString(kCFAllocatorDefault, text,
kCFStringEncodingUTF8);
if (cftext)
{
CFDictionarySetValue(dict, CFSTR("en_US"), cftext);
CFRelease(cftext);
}
if (languages)
{
/*
* Find localized names for the color profiles...
*/
cupsArraySave(ppd->sorted_attrs);
for (language = (char *)cupsArrayFirst(languages);
language;
language = (char *)cupsArrayNext(languages))
{
if (iccfile)
{
if ((attr = _ppdLocalizedAttr(ppd, "cupsICCProfile", name,
language)) == NULL)
attr = _ppdLocalizedAttr(ppd, "APTiogaProfile", name, language);
}
else
attr = _ppdLocalizedAttr(ppd, "ColorModel", name, language);
if (attr && attr->text[0])
{
cflang = CFStringCreateWithCString(kCFAllocatorDefault, language,
kCFStringEncodingUTF8);
cftext = CFStringCreateWithCString(kCFAllocatorDefault, attr->text,
kCFStringEncodingUTF8);
if (cflang && cftext)
CFDictionarySetValue(dict, cflang, cftext);
if (cflang)
CFRelease(cflang);
if (cftext)
CFRelease(cftext);
}
}
cupsArrayRestore(ppd->sorted_attrs);
}
/*
* Fill in the profile data...
*/
if (iccfile && *iccfile)
{
url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)iccfile, (CFIndex)strlen(iccfile), false);
if (url)
{
CFDictionarySetValue(profile, kColorSyncDeviceProfileURL, url);
CFRelease(url);
}
}
//.........這裏部分代碼省略.........