这篇教程C++ CFGetTypeID函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CFGetTypeID函数的典型用法代码示例。如果您正苦于以下问题:C++ CFGetTypeID函数的具体用法?C++ CFGetTypeID怎么用?C++ CFGetTypeID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CFGetTypeID函数的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: onDeviceMatchedstatic void onDeviceMatched(void * context, IOReturn result, void * sender, IOHIDDeviceRef device) { CFArrayRef elements; CFIndex elementIndex; IOHIDElementRef element; CFStringRef cfProductName; struct Gamepad_device * deviceRecord; struct Gamepad_devicePrivate * hidDeviceRecord; IOHIDElementType type; char * description; struct Gamepad_queuedEvent queuedEvent; deviceRecord = malloc(sizeof(struct Gamepad_device)); deviceRecord->deviceID = nextDeviceID++; deviceRecord->vendorID = IOHIDDeviceGetVendorID(device); deviceRecord->productID = IOHIDDeviceGetProductID(device); deviceRecord->numAxes = 0; deviceRecord->numButtons = 0; devices = realloc(devices, sizeof(struct Gamepad_device *) * (numDevices + 1)); devices[numDevices++] = deviceRecord; hidDeviceRecord = malloc(sizeof(struct Gamepad_devicePrivate)); hidDeviceRecord->deviceRef = device; hidDeviceRecord->axisElements = NULL; hidDeviceRecord->buttonElements = NULL; deviceRecord->privateData = hidDeviceRecord; cfProductName = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); if (cfProductName == NULL || CFGetTypeID(cfProductName) != CFStringGetTypeID()) { description = malloc(strlen("[Unknown]" + 1)); strcpy(description, "[Unknown]"); } else { CFIndex length; CFStringGetBytes(cfProductName, CFRangeMake(0, CFStringGetLength(cfProductName)), kCFStringEncodingUTF8, '?', false, NULL, 100, &length); description = malloc(length + 1); CFStringGetBytes(cfProductName, CFRangeMake(0, CFStringGetLength(cfProductName)), kCFStringEncodingUTF8, '?', false, (UInt8 *) description, length + 1, NULL); description[length] = '/x00'; } deviceRecord->description = description; elements = IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone); for (elementIndex = 0; elementIndex < CFArrayGetCount(elements); elementIndex++) { element = (IOHIDElementRef) CFArrayGetValueAtIndex(elements, elementIndex); type = IOHIDElementGetType(element); // All of the axis elements I've ever detected have been kIOHIDElementTypeInput_Misc. kIOHIDElementTypeInput_Axis is only included for good faith... if (type == kIOHIDElementTypeInput_Misc || type == kIOHIDElementTypeInput_Axis) { hidDeviceRecord->axisElements = realloc(hidDeviceRecord->axisElements, sizeof(struct HIDGamepadAxis) * (deviceRecord->numAxes + 1)); hidDeviceRecord->axisElements[deviceRecord->numAxes].cookie = IOHIDElementGetCookie(element); hidDeviceRecord->axisElements[deviceRecord->numAxes].logicalMin = IOHIDElementGetLogicalMin(element); hidDeviceRecord->axisElements[deviceRecord->numAxes].logicalMax = IOHIDElementGetLogicalMax(element); hidDeviceRecord->axisElements[deviceRecord->numAxes].hasNullState = !!IOHIDElementHasNullState(element); hidDeviceRecord->axisElements[deviceRecord->numAxes].isHatSwitch = IOHIDElementGetUsage(element) == kHIDUsage_GD_Hatswitch; hidDeviceRecord->axisElements[deviceRecord->numAxes].isHatSwitchSecondAxis = false; deviceRecord->numAxes++; if (hidDeviceRecord->axisElements[deviceRecord->numAxes - 1].isHatSwitch) { hidDeviceRecord->axisElements = realloc(hidDeviceRecord->axisElements, sizeof(struct HIDGamepadAxis) * (deviceRecord->numAxes + 1)); hidDeviceRecord->axisElements[deviceRecord->numAxes].isHatSwitchSecondAxis = true; deviceRecord->numAxes++; } } else if (type == kIOHIDElementTypeInput_Button) { hidDeviceRecord->buttonElements = realloc(hidDeviceRecord->buttonElements, sizeof(struct HIDGamepadButton) * (deviceRecord->numButtons + 1)); hidDeviceRecord->buttonElements[deviceRecord->numButtons].cookie = IOHIDElementGetCookie(element); deviceRecord->numButtons++; } } CFRelease(elements); deviceRecord->axisStates = calloc(sizeof(float), deviceRecord->numAxes); deviceRecord->buttonStates = calloc(sizeof(bool), deviceRecord->numButtons); IOHIDDeviceRegisterInputValueCallback(device, onDeviceValueChanged, deviceRecord); queuedEvent.deviceID = deviceRecord->deviceID; queuedEvent.eventType = GAMEPAD_EVENT_DEVICE_ATTACHED; queuedEvent.eventData = deviceRecord; if (deviceEventCount >= deviceEventQueueSize) { deviceEventQueueSize = deviceEventQueueSize == 0 ? 1 : deviceEventQueueSize * 2; deviceEventQueue = realloc(deviceEventQueue, sizeof(struct Gamepad_queuedEvent) * deviceEventQueueSize); } deviceEventQueue[deviceEventCount++] = queuedEvent;}
开发者ID:boristyukin,项目名称:giderosplugins,代码行数:88,
示例2: PlatformCallback// Callback passed to the VideoToolbox decoder for returning data.// This needs to be static because the API takes a C-style pair of// function and userdata pointers. This validates parameters and// forwards the decoded image back to an object method.static voidPlatformCallback(void* decompressionOutputRefCon, CFDictionaryRef frameInfo, OSStatus status, VDADecodeInfoFlags infoFlags, CVImageBufferRef image){ LOG("AppleVDADecoder[%s] status %d flags %d retainCount %ld", __func__, status, infoFlags, CFGetRetainCount(frameInfo)); // Validate our arguments. // According to Apple's TN2267 // The output callback is still called for all flushed frames, // but no image buffers will be returned. // FIXME: Distinguish between errors and empty flushed frames. if (status != noErr || !image) { NS_WARNING("AppleVDADecoder decoder returned no data"); return; } MOZ_ASSERT(CFGetTypeID(image) == CVPixelBufferGetTypeID(), "AppleVDADecoder returned an unexpected image type"); if (infoFlags & kVDADecodeInfo_FrameDropped) { NS_WARNING(" ...frame dropped..."); return; } AppleVDADecoder* decoder = static_cast<AppleVDADecoder*>(decompressionOutputRefCon); AutoCFRelease<CFNumberRef> ptsref = (CFNumberRef)CFDictionaryGetValue(frameInfo, CFSTR("FRAME_PTS")); AutoCFRelease<CFNumberRef> dtsref = (CFNumberRef)CFDictionaryGetValue(frameInfo, CFSTR("FRAME_DTS")); AutoCFRelease<CFNumberRef> durref = (CFNumberRef)CFDictionaryGetValue(frameInfo, CFSTR("FRAME_DURATION")); AutoCFRelease<CFNumberRef> boref = (CFNumberRef)CFDictionaryGetValue(frameInfo, CFSTR("FRAME_OFFSET")); AutoCFRelease<CFNumberRef> kfref = (CFNumberRef)CFDictionaryGetValue(frameInfo, CFSTR("FRAME_KEYFRAME")); Microseconds dts; Microseconds pts; Microseconds duration; int64_t byte_offset; char is_sync_point; CFNumberGetValue(ptsref, kCFNumberSInt64Type, &pts); CFNumberGetValue(dtsref, kCFNumberSInt64Type, &dts); CFNumberGetValue(durref, kCFNumberSInt64Type, &duration); CFNumberGetValue(boref, kCFNumberSInt64Type, &byte_offset); CFNumberGetValue(kfref, kCFNumberSInt8Type, &is_sync_point); nsAutoPtr<AppleVDADecoder::AppleFrameRef> frameRef( new AppleVDADecoder::AppleFrameRef(dts, pts, duration, byte_offset, is_sync_point == 1)); // Forward the data back to an object method which can access // the correct MP4Reader callback. decoder->OutputFrame(image, frameRef);}
开发者ID:msliu,项目名称:gecko-dev,代码行数:69,
示例3: ModemOrSerialDeviceToDictProcstatic kern_return_t ModemOrSerialDeviceToDictProc(void *contextPtr, io_object_t interface, CFMutableDictionaryRef interfaceInfo) // This routine is called (via function pointer) by AddMatchingDevicesToArray // to add modem/serial-specific information for the modem/serial-like device // (which includes internal modems, built-in serial ports, USB serial adapters, // USB modems, and IrDA) specified by interface to the interfaceInfo dictionary.{ #pragma unused(contextPtr) kern_return_t err; kern_return_t junk; CFMutableDictionaryRef interfaceDict; CFStringRef baseName; CFNumberRef supportsHold; assert(interface != 0 ); assert(interfaceInfo != NULL); interfaceDict = NULL; supportsHold = false; err = IORegistryEntryCreateCFProperties(interface, &interfaceDict, NULL, kNilOptions ); // Get IOTTYBaseName // Yetch. We specifically exclude ports named "irda" because otherwise the IrDA // ports on the original iMac (rev's A through D) show up as serial ports. Given // that only the rev A actually had an IrDA port, and Mac OS X doesn't even support // it, these ports definitely shouldn't be listed. if (err == 0 && CFDictionaryGetValueIfPresent(interfaceDict, CFSTR(kIOTTYBaseNameKey), (const void **) &baseName ) && ! CFEqual(baseName, CFSTR("irda")) ) { junk = CFQDictionarySetNumber(interfaceInfo, kSortOrderKey, kSerialSortOrder); assert(junk == 0); // kSCPropNetInterfaceDeviceName CFDictionarySetValue(interfaceInfo, kSCPropNetInterfaceDeviceName, CFDictionaryGetValue(interfaceDict, CFSTR(kIOTTYDeviceKey))); // kSCPropNetInterfaceHardware CFDictionarySetValue(interfaceInfo, kSCPropNetInterfaceHardware, kSCEntNetModem); // kSCPropNetInterfaceType CFDictionarySetValue(interfaceInfo, kSCPropNetInterfaceType, kSCValNetInterfaceTypePPP); // kSCPropNetInterfaceSubType CFDictionarySetValue(interfaceInfo, kSCPropNetInterfaceSubType, kSCValNetInterfaceSubTypePPPSerial); // "HardwareVariant" // A special hack for IrDA, modelled directly on the code from the // control panel. if ( CFStringHasPrefix(baseName, kMoreSCValNetInterfaceHardwareVariantIrDACOMM) ) { junk = CFQDictionarySetNumber(interfaceInfo, kSortOrderKey, kIrDASerialSortOrder); assert(junk == 0); CFDictionarySetValue(interfaceInfo, kMoreSCPropNetInterfaceHardwareVariant, kMoreSCValNetInterfaceHardwareVariantIrDACOMM); } // kSCPropNetInterfaceSupportsModemOnHold supportsHold = (CFNumberRef) IORegistryEntrySearchCFProperty(interface, kIOServicePlane, CFSTR("V92Modem"), NULL, kIORegistryIterateRecursively | kIORegistryIterateParents); if (supportsHold != NULL) { assert( CFGetTypeID(supportsHold) == CFNumberGetTypeID() ); CFDictionarySetValue(interfaceInfo, kSCPropNetInterfaceSupportsModemOnHold, supportsHold); } // kSCPropUserDefinedName set up by caller. } CFQRelease(interfaceDict); CFQRelease(supportsHold); return err;}
开发者ID:fruitsamples,项目名称:MoreIsBetter,代码行数:83,
示例4: SetKeyLabelAndTagstatic OSStatus SetKeyLabelAndTag(SecKeyRef keyRef, CFTypeRef label, CFDataRef tag){ int numToModify = 0; if (label != NULL) { numToModify += 1; } if (tag != NULL) { numToModify += 1; } if (numToModify == 0) { return noErr; } SecKeychainAttributeList attrList; SecKeychainAttribute attributes[numToModify]; int i = 0; if (label != NULL) { if (CFStringGetTypeID() == CFGetTypeID(label)) { CFStringRef label_string = static_cast<CFStringRef>(label); attributes[i].tag = kSecKeyPrintName; attributes[i].data = (void*) CFStringGetCStringPtr(label_string, kCFStringEncodingUTF8); if (NULL == attributes[i].data) { CFIndex buffer_length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(label_string), kCFStringEncodingUTF8); attributes[i].data = alloca((size_t)buffer_length); if (NULL == attributes[i].data) { UnixError::throwMe(ENOMEM); } if (!CFStringGetCString(label_string, static_cast<char *>(attributes[i].data), buffer_length, kCFStringEncodingUTF8)) { MacOSError::throwMe(paramErr); } } attributes[i].length = strlen(static_cast<char *>(attributes[i].data)); } else if (CFDataGetTypeID() == CFGetTypeID(label)) { // 10.6 bug compatibility CFDataRef label_data = static_cast<CFDataRef>(label); attributes[i].tag = kSecKeyLabel; attributes[i].data = (void*) CFDataGetBytePtr(label_data); attributes[i].length = CFDataGetLength(label_data); } else { MacOSError::throwMe(paramErr); } i++; } if (tag != NULL) { attributes[i].tag = kSecKeyApplicationTag; attributes[i].data = (void*) CFDataGetBytePtr(tag); attributes[i].length = CFDataGetLength(tag); i++; } attrList.count = numToModify; attrList.attr = attributes; return SecKeychainItemModifyAttributesAndData((SecKeychainItemRef) keyRef, &attrList, 0, NULL);}
开发者ID:Apple-FOSS-Mirror,项目名称:libsecurity_keychain,代码行数:65,
示例5: findFirstEncryptionPublicKeyOnTokenint findFirstEncryptionPublicKeyOnToken(SecKeyRef *publicKey, SecKeychainRef *keychainRef, CFDataRef *label){ if (!publicKey || !keychainRef) return paramErr; OSStatus status = noErr; CFArrayRef identityArray = NULL; SecKeyRef tmpKeyRef = NULL; SecCertificateRef certificate = NULL; SecKeychainRef tmpKeychainRef = NULL; try { status = findEncryptionIdentities((CFTypeRef *)&identityArray); if (status) MacOSError::throwMe(status); if (!identityArray || (CFGetTypeID(identityArray)!=CFArrayGetTypeID()) || (CFArrayGetCount(identityArray)==0)) MacOSError::throwMe(paramErr); CFTypeRef tmpref = CFArrayGetValueAtIndex(identityArray, 0); if (CFGetTypeID(tmpref)!=SecIdentityGetTypeID()) MacOSError::throwMe(paramErr); status = SecIdentityCopyCertificate(SecIdentityRef(tmpref), &certificate); if (status) MacOSError::throwMe(status); if (!certificate) MacOSError::throwMe(errKCItemNotFound); status = findCertificatePublicKeyHash(certificate, label); if (status) MacOSError::throwMe(status); status = SecKeychainItemCopyKeychain(SecKeychainItemRef(certificate), &tmpKeychainRef); if (status) MacOSError::throwMe(status); status = SecCertificateCopyPublicKey(certificate, &tmpKeyRef); if (status) MacOSError::throwMe(status); // Found an encryption key *publicKey = tmpKeyRef; *keychainRef = tmpKeychainRef; } catch (const MacOSError &err) { status = err.osStatus(); cssmPerror("findFirstEncryptionPublicKeyOnToken", status); } catch (...) { fprintf(stderr, "findFirstEncryptionPublicKeyOnToken: unknown exception/n"); status = errKCItemNotFound; } if (status) { if (identityArray) CFRelease(identityArray); if (certificate) CFRelease(certificate); } if (identityArray) CFRelease(identityArray); if (certificate) CFRelease(certificate); return status;}
开发者ID:Apple-FOSS-Mirror,项目名称:security_systemkeychain,代码行数:75,
示例6: HIDGetElementsCFArrayHandlerstatic voidHIDGetElementsCFArrayHandler(const void *value, void *parameter){ if (CFGetTypeID(value) == CFDictionaryGetTypeID()) HIDAddElement((CFTypeRef) value, (recDevice *) parameter);}
开发者ID:CrypticGator,项目名称:hackterm,代码行数:6,
示例7: SecKeyGenerateSymmetricSecKeyRefSecKeyGenerateSymmetric(CFDictionaryRef parameters, CFErrorRef *error){ OSStatus result = paramErr; // default result for an early exit SecKeyRef key = NULL; SecKeychainRef keychain = NULL; SecAccessRef access; CFStringRef label; CFStringRef appLabel; CFStringRef appTag; CFStringRef dateLabel = NULL; CSSM_ALGORITHMS algorithm; uint32 keySizeInBits; CSSM_KEYUSE keyUsage; uint32 keyAttr = CSSM_KEYATTR_RETURN_DEFAULT; CSSM_KEYCLASS keyClass; CFTypeRef value; Boolean isPermanent; Boolean isExtractable; // verify keychain parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecUseKeychain, (const void **)&keychain)) keychain = NULL; else if (SecKeychainGetTypeID() != CFGetTypeID(keychain)) { keychain = NULL; goto errorExit; } else CFRetain(keychain); // verify permanent parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrIsPermanent, (const void **)&value)) isPermanent = false; else if (!value || (CFBooleanGetTypeID() != CFGetTypeID(value))) goto errorExit; else isPermanent = CFEqual(kCFBooleanTrue, value); if (isPermanent) { if (keychain == NULL) { // no keychain was specified, so use the default keychain result = SecKeychainCopyDefault(&keychain); } keyAttr |= CSSM_KEYATTR_PERMANENT; } // verify extractable parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrIsExtractable, (const void **)&value)) isExtractable = true; // default to extractable if value not specified else if (!value || (CFBooleanGetTypeID() != CFGetTypeID(value))) goto errorExit; else isExtractable = CFEqual(kCFBooleanTrue, value); if (isExtractable) keyAttr |= CSSM_KEYATTR_EXTRACTABLE; // verify access parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrAccess, (const void **)&access)) access = NULL; else if (SecAccessGetTypeID() != CFGetTypeID(access)) goto errorExit; // verify label parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrLabel, (const void **)&label)) label = (dateLabel = utilCopyDefaultKeyLabel()); // no label provided, so use default else if (CFStringGetTypeID() != CFGetTypeID(label)) goto errorExit; // verify application label parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrApplicationLabel, (const void **)&appLabel)) appLabel = (dateLabel) ? dateLabel : (dateLabel = utilCopyDefaultKeyLabel()); else if (CFStringGetTypeID() != CFGetTypeID(appLabel)) goto errorExit; // verify application tag parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrApplicationTag, (const void **)&appTag)) appTag = NULL; else if (CFStringGetTypeID() != CFGetTypeID(appTag)) goto errorExit; utilGetKeyParametersFromCFDict(parameters, &algorithm, &keySizeInBits, &keyUsage, &keyClass); if (!keychain) { // the generated key will not be stored in any keychain result = SecKeyGenerate(keychain, algorithm, keySizeInBits, 0, keyUsage, keyAttr, access, &key); } else { // we can set the label attributes on the generated key if it's a keychain item size_t labelBufLen = (label) ? (size_t)CFStringGetMaximumSizeForEncoding(CFStringGetLength(label), kCFStringEncodingUTF8) + 1 : 0; char *labelBuf = (char *)malloc(labelBufLen); size_t appLabelBufLen = (appLabel) ? (size_t)CFStringGetMaximumSizeForEncoding(CFStringGetLength(appLabel), kCFStringEncodingUTF8) + 1 : 0; char *appLabelBuf = (char *)malloc(appLabelBufLen); size_t appTagBufLen = (appTag) ? (size_t)CFStringGetMaximumSizeForEncoding(CFStringGetLength(appTag), kCFStringEncodingUTF8) + 1 : 0; char *appTagBuf = (char *)malloc(appTagBufLen); if (label && !CFStringGetCString(label, labelBuf, labelBufLen-1, kCFStringEncodingUTF8)) labelBuf[0]=0; if (appLabel && !CFStringGetCString(appLabel, appLabelBuf, appLabelBufLen-1, kCFStringEncodingUTF8)) appLabelBuf[0]=0; if (appTag && !CFStringGetCString(appTag, appTagBuf, appTagBufLen-1, kCFStringEncodingUTF8))//.........这里部分代码省略.........
开发者ID:Apple-FOSS-Mirror,项目名称:libsecurity_keychain,代码行数:101,
示例8: DoSetPermissionsOSStatus DoSetPermissions(COMMAND_PROC_ARGUMENTS) {#pragma unused (auth)#pragma unused (userData) OSStatus retval = noErr; // Pre-conditions // userData may be NULL assert(request != NULL); assert(response != NULL); // asl may be NULL // aslMsg may be NULL // Get Info from arguments and assert that it's a CFDictionaryRef CFDictionaryRef infos = CFDictionaryGetValue(request, CFSTR(kInfos)) ; assert(infos != NULL) ; assert(CFGetTypeID(infos) == CFDictionaryGetTypeID()) ; CFIndex nPaths = CFDictionaryGetCount(infos) ; CFMutableDictionaryRef errorDescriptions = CFDictionaryCreateMutable( NULL, nPaths, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks ) ; CFMutableDictionaryRef originalModes = CFDictionaryCreateMutable( NULL, nPaths, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks ) ; CFIndex i ; int nSucceeded = 0 ; const void ** paths = (const void **)malloc( nPaths * sizeof(const void *)) ; const void ** modeNums = (const void **)malloc( nPaths * sizeof(const void *)) ; if ((paths != NULL) && (modeNums != NULL)) { CFDictionaryGetKeysAndValues( infos, paths, modeNums ) ; for (i=0; i<nPaths; i++) { // Process each path Boolean ok = true ; int retval ; // Get path, assert that it's a string anc convert to a C string CFStringRef path = paths[i] ; assert(CFGetTypeID(path) == CFStringGetTypeID()) ; char pathC[MAX_PATH_CHARS] ; if (ok) { ok = CFStringGetCString( path, pathC, MAX_PATH_CHARS, kCFStringEncodingASCII ) ; if (!ok) { CFDictionaryAddValue(errorDescriptions, path, CFSTR("Name too long")) ; } } // Read current permissions for path, wrap as CFNumber and add to results dictionary if (ok) { struct stat rawStats ; retval = stat(pathC, &rawStats) ; ok = (retval == 0) ; if (ok) { // rawStats.st_mode is of type mode_t which is an unsigned short. // Unfortunately, the available kCFNumberTypes don't have unsigned short. // And I have found that if I give CFNumberCreate an unsigned short and // tell it that it's an available kCFNumberType, which has more bits, // the undefined bits get encoded as garbage, changing the value. // First assigning the unsigned short to an int fixes it. int originalMode = rawStats.st_mode ; CFNumberRef fileModeCF = CFNumberCreate( NULL, kCFNumberIntType, &originalMode ) ; CFDictionaryAddValue( originalModes, path, fileModeCF) ; CFRelease(fileModeCF) ; } else { CFStringRef errString = CFStringCreateWithFormat( NULL, NULL, CFSTR("stat64 failed. errno: %d"), errno ) ; CFDictionaryAddValue(errorDescriptions, path, errString) ; CFQRelease(errString) ;//.........这里部分代码省略.........
开发者ID:dibowei,项目名称:CocoaPrivilegedHelper,代码行数:101,
示例9: q_toVariantstatic QVariant q_toVariant(const CFTypeRef &obj){ const CFTypeID typeId = CFGetTypeID(obj); if (typeId == CFStringGetTypeID()) return QVariant(q_toString(static_cast<const CFStringRef>(obj))); if (typeId == CFNumberGetTypeID()) { const CFNumberRef num = static_cast<const CFNumberRef>(obj); const CFNumberType type = CFNumberGetType(num); switch (type) { case kCFNumberSInt8Type: return qVariantFromValue(convertCFNumber<char>(num, type)); case kCFNumberSInt16Type: return qVariantFromValue(convertCFNumber<qint16>(num, type)); case kCFNumberSInt32Type: return qVariantFromValue(convertCFNumber<qint32>(num, type)); case kCFNumberSInt64Type: return qVariantFromValue(convertCFNumber<qint64>(num, type)); case kCFNumberCharType: return qVariantFromValue(convertCFNumber<uchar>(num, type)); case kCFNumberShortType: return qVariantFromValue(convertCFNumber<short>(num, type)); case kCFNumberIntType: return qVariantFromValue(convertCFNumber<int>(num, type)); case kCFNumberLongType: return qVariantFromValue(convertCFNumber<long>(num, type)); case kCFNumberLongLongType: return qVariantFromValue(convertCFNumber<long long>(num, type)); case kCFNumberFloatType: return qVariantFromValue(convertCFNumber<float>(num, type)); case kCFNumberDoubleType: return qVariantFromValue(convertCFNumber<double>(num, type)); default: if (CFNumberIsFloatType(num)) return qVariantFromValue(convertCFNumber<double>(num, kCFNumberDoubleType)); return qVariantFromValue(convertCFNumber<quint64>(num, kCFNumberLongLongType)); } } if (typeId == CFDateGetTypeID()) { QDateTime dt; dt.setTime_t(uint(kCFAbsoluteTimeIntervalSince1970)); return dt.addSecs(int(CFDateGetAbsoluteTime(static_cast<const CFDateRef>(obj)))); } if (typeId == CFDataGetTypeID()) { const CFDataRef cfdata = static_cast<const CFDataRef>(obj); return QByteArray(reinterpret_cast<const char *>(CFDataGetBytePtr(cfdata)), CFDataGetLength(cfdata)); } if (typeId == CFBooleanGetTypeID()) return QVariant(bool(CFBooleanGetValue(static_cast<const CFBooleanRef>(obj)))); if (typeId == CFArrayGetTypeID()) { const CFArrayRef cfarray = static_cast<const CFArrayRef>(obj); QList<QVariant> list; CFIndex size = CFArrayGetCount(cfarray); bool metNonString = false; for (CFIndex i = 0; i < size; ++i) { QVariant value = q_toVariant(CFArrayGetValueAtIndex(cfarray, i)); if (value.type() != QVariant::String) metNonString = true; list << value; } if (metNonString) return list; else return QVariant(list).toStringList(); } if (typeId == CFDictionaryGetTypeID()) { const CFDictionaryRef cfdict = static_cast<const CFDictionaryRef>(obj); const CFTypeID arrayTypeId = CFArrayGetTypeID(); int size = int(CFDictionaryGetCount(cfdict)); QVarLengthArray<CFPropertyListRef> keys(size); QVarLengthArray<CFPropertyListRef> values(size); CFDictionaryGetKeysAndValues(cfdict, keys.data(), values.data()); QMultiMap<QString, QVariant> map; for (int i = 0; i < size; ++i) { QString key = q_toString(static_cast<const CFStringRef>(keys[i])); if (CFGetTypeID(values[i]) == arrayTypeId) { const CFArrayRef cfarray = static_cast<const CFArrayRef>(values[i]); CFIndex arraySize = CFArrayGetCount(cfarray); for (CFIndex j = arraySize - 1; j >= 0; --j) map.insert(key, q_toVariant(CFArrayGetValueAtIndex(cfarray, j))); } else { map.insert(key, q_toVariant(values[i])); } } return map; } return QVariant();}
开发者ID:gustavosbarreto,项目名称:libqsolid,代码行数:98,
示例10: propertyListExamplevoid propertyListExample (void) { CFMutableDictionaryRef dict; CFNumberRef num; CFArrayRef array; CFDataRef data; #define NumKids 2 CFStringRef kidsNames[] = { CFSTR ("John"), CFSTR ("Kyra") }; #define NumPets 0 int yearOfBirth = 1965; #define NumBytesInPic 10 const unsigned char pic[ NumBytesInPic ] = { 0x3c, 0x42, 0x81, 0xa5, 0x81, 0xa5, 0x99, 0x81, 0x42, 0x3c }; CFDataRef xmlPropertyListData; CFStringRef xmlAsString; // Create and populate a pretty standard mutable dictionary: CFString keys, CF type values. // To be written out as a "propertyList", the tree of CF types can contain only: // CFDictionary, CFArray, CFString, CFData, CFNumber, and CFDate. // In addition, the keys of the dictionaries should be CFStrings. dict = CFDictionaryCreateMutable (NULL, 0, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks ); CFDictionarySetValue (dict, CFSTR ("Name"), CFSTR ("John Doe")); CFDictionarySetValue (dict, CFSTR ("City of Birth"), CFSTR ("Springfield")); num = CFNumberCreate (NULL, kCFNumberIntType, &yearOfBirth); CFDictionarySetValue (dict, CFSTR ("Year Of Birth"), num); CFRelease (num); array = CFArrayCreate (NULL, (const void **)kidsNames, NumKids, &kCFTypeArrayCallBacks); CFDictionarySetValue (dict, CFSTR ("Kids Names"), array); CFRelease (array); array = CFArrayCreate (NULL, NULL, 0, &kCFTypeArrayCallBacks); CFDictionarySetValue (dict, CFSTR ("Pets Names"), array ); CFRelease (array); data = CFDataCreate (NULL, pic, NumBytesInPic); CFDictionarySetValue (dict, CFSTR ("Picture"), data); CFRelease (data); // We now have a dictionary which contains everything we want to know about // John Doe; let's show it first: CFShow (CFSTR ("John Doe info dictionary: ")); CFShow (dict); // Now create a "property list", which is a flattened, XML version of the // dictionary: xmlPropertyListData = CFPropertyListCreateXMLData (NULL, dict); // The return value is a CFData containing the XML file; show the data CFShow (CFSTR ("Shown as XML property list (bytes): ")); CFShow (xmlPropertyListData); // Given CFDatas are shown as ASCII versions of their hex contents, we can also // attempt to show the contents of the XML, assuming it was encoded in UTF8 // (This is the case for XML property lists generated by CoreFoundation currently) xmlAsString = CFStringCreateFromExternalRepresentation (NULL, xmlPropertyListData, kCFStringEncodingUTF8); CFShow (CFSTR ("The XML property list contents: ")); CFShow (xmlAsString); writePropertyListToFile (xmlPropertyListData); CFRelease (dict); CFRelease (xmlAsString); CFRelease (xmlPropertyListData); CFStringRef name = CFSTR("Brent"); if (CFBundleRef bundle = CFBundleGetMainBundle ()) if (CFTypeRef bundleExecutable = CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleExecutableKey)) if (CFGetTypeID(bundleExecutable) == CFStringGetTypeID()) name = reinterpret_cast<CFStringRef>(bundleExecutable); int value = 1; CFNumberRef numRef = CFNumberCreate(0, kCFNumberSInt8Type, &value); CFShow (CFSTR ("The number was: ")); CFShow (numRef); CFRelease (numRef);}
开发者ID:AbhinavBansal,项目名称:opencflite,代码行数:82,
示例11: MyGetModemPathstatic kern_return_t MyGetModemPath(io_iterator_t serialPortIterator, char *deviceFilePath, CFIndex maxPathSize){ io_object_t modemService; kern_return_t kernResult = KERN_FAILURE; Boolean modemFound = false; // Initialize the returned path *deviceFilePath = '/0'; // Iterate across all modems found. In this example, we exit after // finding the first modem. while ((!modemFound) && (modemService = IOIteratorNext(serialPortIterator))) { CFTypeRef deviceFilePathAsCFType; CFStringRef deviceFilePathAsCFString; // Get the callout device's path (/dev/cu.xxxxx). // The callout device should almost always be // used. You would use the dialin device (/dev/tty.xxxxx) when // monitoring a serial port for // incoming calls, for example, a fax listener. deviceFilePathAsCFType = IORegistryEntryCreateCFProperty(modemService, CFSTR(kIOCalloutDeviceKey), kCFAllocatorDefault, 0); if (CFGetTypeID(deviceFilePathAsCFType) == CFStringGetTypeID()) { deviceFilePathAsCFString = (CFStringRef)deviceFilePathAsCFType; } else { // panic! } if (deviceFilePathAsCFString) { Boolean result; // Convert the path from a CFString to a NULL-terminated C string // for use with the POSIX open() call. result = CFStringGetCString(deviceFilePathAsCFString, deviceFilePath, maxPathSize, kCFStringEncodingASCII); CFRelease(deviceFilePathAsCFString); if (result) { printf("BSD path: %s", deviceFilePath); modemFound = true; kernResult = KERN_SUCCESS; } } printf("/n"); // Release the io_service_t now that we are done with it. (void) IOObjectRelease(modemService); } return kernResult;}
开发者ID:bschreck,项目名称:gesture-drone,代码行数:62,
示例12: disk_readstatic int disk_read (void){#if HAVE_IOKIT_IOKITLIB_H io_registry_entry_t disk; io_registry_entry_t disk_child; io_iterator_t disk_list; CFDictionaryRef props_dict; CFDictionaryRef stats_dict; CFDictionaryRef child_dict; CFStringRef tmp_cf_string_ref; kern_return_t status; signed long long read_ops; signed long long read_byt; signed long long read_tme; signed long long write_ops; signed long long write_byt; signed long long write_tme; int disk_major; int disk_minor; char disk_name[DATA_MAX_NAME_LEN]; char disk_name_bsd[DATA_MAX_NAME_LEN]; /* Get the list of all disk objects. */ if (IOServiceGetMatchingServices (io_master_port, IOServiceMatching (kIOBlockStorageDriverClass), &disk_list) != kIOReturnSuccess) { ERROR ("disk plugin: IOServiceGetMatchingServices failed."); return (-1); } while ((disk = IOIteratorNext (disk_list)) != 0) { props_dict = NULL; stats_dict = NULL; child_dict = NULL; /* `disk_child' must be released */ if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child)) != kIOReturnSuccess) { /* This fails for example for DVD/CD drives.. */ DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status); IOObjectRelease (disk); continue; } /* We create `props_dict' => we need to release it later */ if (IORegistryEntryCreateCFProperties (disk, (CFMutableDictionaryRef *) &props_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) { ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed."); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; } if (props_dict == NULL) { DEBUG ("IORegistryEntryCreateCFProperties (disk) failed."); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; } /* tmp_cf_string_ref doesn't need to be released. */ tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict, CFSTR(kIOBSDNameKey)); if (!tmp_cf_string_ref) { DEBUG ("disk plugin: CFDictionaryGetValue(" "kIOBSDNameKey) failed."); CFRelease (props_dict); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; } assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ()); memset (disk_name_bsd, 0, sizeof (disk_name_bsd)); CFStringGetCString (tmp_cf_string_ref, disk_name_bsd, sizeof (disk_name_bsd), kCFStringEncodingUTF8); if (disk_name_bsd[0] == 0) { ERROR ("disk plugin: CFStringGetCString() failed."); CFRelease (props_dict); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; } DEBUG ("disk plugin: disk_name_bsd = /"%s/"", disk_name_bsd); stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict, CFSTR (kIOBlockStorageDriverStatisticsKey));//.........这里部分代码省略.........
开发者ID:zach14c,项目名称:collectd,代码行数:101,
示例13: ASSERTbool LegacyWebArchive::extract(CFDictionaryRef dictionary){ ASSERT(dictionary); if (!dictionary) { LOG(Archives, "LegacyWebArchive - Null root CFDictionary, aborting invalid WebArchive"); return false; } CFDictionaryRef mainResourceDict = static_cast<CFDictionaryRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveMainResourceKey)); if (!mainResourceDict) { LOG(Archives, "LegacyWebArchive - No main resource in archive, aborting invalid WebArchive"); return false; } if (CFGetTypeID(mainResourceDict) != CFDictionaryGetTypeID()) { LOG(Archives, "LegacyWebArchive - Main resource is not the expected CFDictionary, aborting invalid WebArchive"); return false; } setMainResource(createResource(mainResourceDict)); if (!mainResource()) { LOG(Archives, "LegacyWebArchive - Failed to parse main resource from CFDictionary or main resource does not exist, aborting invalid WebArchive"); return false; } CFArrayRef subresourceArray = static_cast<CFArrayRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveSubresourcesKey)); if (subresourceArray && CFGetTypeID(subresourceArray) != CFArrayGetTypeID()) { LOG(Archives, "LegacyWebArchive - Subresources is not the expected Array, aborting invalid WebArchive"); return false; } if (subresourceArray) { CFIndex count = CFArrayGetCount(subresourceArray); for (CFIndex i = 0; i < count; ++i) { CFDictionaryRef subresourceDict = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(subresourceArray, i)); if (CFGetTypeID(subresourceDict) != CFDictionaryGetTypeID()) { LOG(Archives, "LegacyWebArchive - Subresource is not expected CFDictionary, aborting invalid WebArchive"); return false; } addSubresource(createResource(subresourceDict)); } } CFArrayRef subframeArray = static_cast<CFArrayRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveSubframeArchivesKey)); if (subframeArray && CFGetTypeID(subframeArray) != CFArrayGetTypeID()) { LOG(Archives, "LegacyWebArchive - Subframe archives is not the expected Array, aborting invalid WebArchive"); return false; } if (subframeArray) { CFIndex count = CFArrayGetCount(subframeArray); for (CFIndex i = 0; i < count; ++i) { CFDictionaryRef subframeDict = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(subframeArray, i)); if (CFGetTypeID(subframeDict) != CFDictionaryGetTypeID()) { LOG(Archives, "LegacyWebArchive - Subframe array is not expected CFDictionary, aborting invalid WebArchive"); return false; } RefPtr<LegacyWebArchive> subframeArchive = create(); if (subframeArchive->extract(subframeDict)) addSubframeArchive(subframeArchive.release()); else LOG(Archives, "LegacyWebArchive - Invalid subframe archive skipped"); } } return true;}
开发者ID:DreamOnTheGo,项目名称:src,代码行数:67,
示例14: dsauth_chapstatic int dsauth_chap(u_char *name, u_char *ourname, int id, struct chap_digest_type *digest, unsigned char *challenge, unsigned char *response, unsigned char *message, int message_space){ tDirReference dirRef; tDirNodeReference userNode = 0; tDataNodePtr authTypeDataNodePtr = 0; tDataBufferPtr authDataBufPtr = 0; tDataBufferPtr responseDataBufPtr = 0; tAttributeValueEntryPtr recordNameAttr = 0; tAttributeValueEntryPtr authAuthorityAttr = 0; tDirStatus dsResult = eDSNoErr; int authResult = 0; char *ptr; MS_Chap2Response *resp; u_int32_t userShortNameSize; u_int32_t userNameSize = strlen((char*)name); u_int32_t authDataSize; int challenge_len, response_len; CFMutableDictionaryRef serviceInfo = 0; CFMutableDictionaryRef eventDetail; CFDictionaryRef interface; CFStringRef subtypeRef; CFStringRef addrRef; challenge_len = *challenge++; /* skip length, is 16 */ response_len = *response++; // currently only support MS-CHAPv2 if (digest->code != CHAP_MICROSOFT_V2 || response_len != MS_CHAP2_RESPONSE_LEN || challenge_len != CHALLENGE_SIZE) return 0; resp = (MS_Chap2Response*)response; if ((dsResult = dsOpenDirService(&dirRef)) == eDSNoErr) { if ((authTypeDataNodePtr = dsDataNodeAllocateString(dirRef, kDSStdAuthMSCHAP2)) == 0) { error("DSAuth plugin: Could not allocate data buffer/n"); goto cleanup; } // setup service info interface = CFDictionaryGetValue(systemOptions, kRASEntInterface); if (interface && CFGetTypeID(interface) == CFDictionaryGetTypeID()) { subtypeRef = CFDictionaryGetValue(interface, kRASPropInterfaceSubType); if (subtypeRef && CFGetTypeID(subtypeRef) == CFStringGetTypeID()) { serviceInfo = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (serviceInfo) { eventDetail = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (eventDetail) { addrRef = CFStringCreateWithCString(0, remoteaddress, kCFStringEncodingUTF8); if (addrRef) { CFDictionaryAddValue(eventDetail, CFSTR("ClientIP"), addrRef); CFRelease(addrRef); } if (CFStringCompare(subtypeRef, kRASValInterfaceSubTypeL2TP, 0) == kCFCompareEqualTo) { CFDictionaryAddValue(eventDetail, CFSTR("HostPort"), CFSTR("1701")); CFDictionaryAddValue(eventDetail, CFSTR("ProtocolName"), CFSTR("L2TP")); CFDictionaryAddValue(eventDetail, CFSTR("ProtocolVersion"), CFSTR("2")); } else if (CFStringCompare(subtypeRef, kRASValInterfaceSubTypePPTP, 0) == kCFCompareEqualTo) { CFDictionaryAddValue(eventDetail, CFSTR("HostPort"), CFSTR("1723")); CFDictionaryAddValue(eventDetail, CFSTR("ProtocolName"), CFSTR("PPTP")); CFDictionaryAddValue(eventDetail, CFSTR("ProtocolVersion"), CFSTR("1")); } else CFDictionaryAddValue(eventDetail, CFSTR("ProtocolName"), subtypeRef); CFDictionaryAddValue(eventDetail, CFSTR("ServiceName"), CFSTR("VPN")); // add eventDetail to serviceInfo dict CFDictionaryAddValue(serviceInfo, CFSTR("ServiceInformation"), eventDetail); CFRelease(eventDetail); // allocate response buffer with service info if (dsServiceInformationAllocate(serviceInfo, BUF_LEN, &responseDataBufPtr) != eDSNoErr) { error("DSAuth plugin: Unable to allocate service info buffer/n"); goto cleanup; } } else { error("DSAuth plugin: Unable to allocate eventDetail dictionary/n"); goto cleanup; } } else { error("DSAuth plugin: Unable to allocate serviceInfo dictionary/n"); goto cleanup; } } else { error("DSAuth plugin: No Interface subtype found/n"); goto cleanup; } } else { error("DSAuth plugin: No Interface dictionary found/n"); goto cleanup; } if (dsauth_find_user_node(dirRef, (char*)name, &userNode, &recordNameAttr, &authAuthorityAttr) == 0) { userShortNameSize = recordNameAttr->fAttributeValueData.fBufferLength; authDataSize = userNameSize + userShortNameSize + NT_RESPONSE_SIZE + (2 * CHALLENGE_SIZE) + (5 * sizeof(u_int32_t)); //.........这里部分代码省略.........
开发者ID:TARRANUM,项目名称:ppp,代码行数:101,
示例15: _SCCopyDescriptionCFStringRef_SCCopyDescription(CFTypeRef cf, CFDictionaryRef formatOptions){#ifdef ENABLE_SC_FORMATTING CFMutableDictionaryRef nFormatOptions; CFStringRef prefix1; CFStringRef prefix2; CFTypeID type = CFGetTypeID(cf); if (!formatOptions || !CFDictionaryGetValueIfPresent(formatOptions, CFSTR("PREFIX1"), (const void **)&prefix1)) { prefix1 = CFSTR(""); } if (type == CFStringGetTypeID()) { return CFStringCreateWithFormat(NULL, formatOptions, CFSTR("%@%@"), prefix1, cf); } if (type == CFBooleanGetTypeID()) { return CFStringCreateWithFormat(NULL, formatOptions, CFSTR("%@%s"), prefix1, CFBooleanGetValue(cf) ? "TRUE" : "FALSE"); } if (type == CFDataGetTypeID()) { const uint8_t *data; CFIndex dataLen; CFIndex i; CFMutableStringRef str; str = CFStringCreateMutable(NULL, 0); CFStringAppendFormat(str, formatOptions, CFSTR("%@<data> 0x"), prefix1); data = CFDataGetBytePtr(cf); dataLen = CFDataGetLength(cf); for (i = 0; i < dataLen; i++) { CFStringAppendFormat(str, NULL, CFSTR("%02x"), data[i]); } return str; } if (type == CFNumberGetTypeID()) { return CFStringCreateWithFormat(NULL, formatOptions, CFSTR("%@%@"), prefix1, cf); } if (type == CFDateGetTypeID()) { CFCalendarRef calendar; CFStringRef str; CFTimeZoneRef tz; int MM, DD, YYYY, hh, mm, ss; calendar = CFCalendarCreateWithIdentifier(NULL, kCFGregorianCalendar); tz = CFTimeZoneCopySystem(); CFCalendarSetTimeZone(calendar, tz); CFRelease(tz); CFCalendarDecomposeAbsoluteTime(calendar, CFDateGetAbsoluteTime(cf), "MdyHms", &MM, &DD, &YYYY, &hh, &mm, &ss); CFRelease(calendar); str = CFStringCreateWithFormat(NULL, formatOptions, CFSTR("%@%02d/%02d/%04d %02d:%02d:%02d"), prefix1, MM, DD, YYYY, hh, mm, ss); return str; } if ((formatOptions == NULL) || !CFDictionaryGetValueIfPresent(formatOptions, CFSTR("PREFIX2"), (const void **)&prefix2)) { prefix2 = prefix1; } if (formatOptions != NULL) { nFormatOptions = CFDictionaryCreateMutableCopy(NULL, 0, formatOptions); } else { nFormatOptions = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } assert(nFormatOptions != NULL);#define N_QUICK 32 if (type == CFArrayGetTypeID()) { const void * elements_q[N_QUICK]; const void ** elements = elements_q;//.........这里部分代码省略.........
开发者ID:010001111,项目名称:darling,代码行数:101,
示例16: keychain_querystatic intkeychain_query(hx509_context context, hx509_certs certs, void *data, const hx509_query *query, hx509_cert *retcert){ CFArrayRef identities = NULL; hx509_cert cert = NULL; CFIndex n, count; int ret; int kdcLookupHack = 0; /* * First to course filtering using security framework .... */#define FASTER_FLAGS (HX509_QUERY_MATCH_PERSISTENT|HX509_QUERY_PRIVATE_KEY) if ((query->match & FASTER_FLAGS) == 0) return HX509_UNIMPLEMENTED_OPERATION; CFMutableDictionaryRef secQuery = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); /* * XXX this is so broken, SecItem doesn't find the kdc certificte, * and kdc certificates happend to be searched by friendly name, * so find that and mundge on the structure. */ if ((query->match & HX509_QUERY_MATCH_FRIENDLY_NAME) && (query->match & HX509_QUERY_PRIVATE_KEY) && strcmp(query->friendlyname, "O=System Identity,CN=com.apple.kerberos.kdc") == 0) { ((hx509_query *)query)->match &= ~HX509_QUERY_PRIVATE_KEY; kdcLookupHack = 1; } if (kdcLookupHack || (query->match & HX509_QUERY_MATCH_PERSISTENT)) { CFDictionaryAddValue(secQuery, kSecClass, kSecClassCertificate); } else CFDictionaryAddValue(secQuery, kSecClass, kSecClassIdentity); CFDictionaryAddValue(secQuery, kSecReturnRef, kCFBooleanTrue); CFDictionaryAddValue(secQuery, kSecMatchLimit, kSecMatchLimitAll); if (query->match & HX509_QUERY_MATCH_PERSISTENT) { CFDataRef refdata = CFDataCreateWithBytesNoCopy(NULL, query->persistent->data, query->persistent->length, kCFAllocatorNull); CFDictionaryAddValue(secQuery, kSecValuePersistentRef, refdata); CFRelease(refdata); } OSStatus status = SecItemCopyMatching(secQuery, (CFTypeRef *)&identities); CFRelease(secQuery); if (status || identities == NULL) { hx509_clear_error_string(context); return HX509_CERT_NOT_FOUND; } heim_assert(CFArrayGetTypeID() == CFGetTypeID(identities), "return value not an array"); /* * ... now do hx509 filtering */ count = CFArrayGetCount(identities); for (n = 0; n < count; n++) { CFTypeRef secitem = (CFTypeRef)CFArrayGetValueAtIndex(identities, n);#ifndef __APPLE_TARGET_EMBEDDED__ if (query->match & HX509_QUERY_MATCH_PERSISTENT) { SecIdentityRef other = NULL; OSStatus osret; osret = SecIdentityCreateWithCertificate(NULL, (SecCertificateRef)secitem, &other); if (osret == noErr) { ret = hx509_cert_init_SecFramework(context, (void *)other, &cert); CFRelease(other); if (ret) continue; } else { ret = hx509_cert_init_SecFramework(context, (void *)secitem, &cert); if (ret) continue; } } else#endif { ret = hx509_cert_init_SecFramework(context, (void *)secitem, &cert); if (ret) continue; } if (_hx509_query_match_cert(context, query, cert)) {#ifndef __APPLE_TARGET_EMBEDDED__ /* certtool/keychain doesn't glue togheter the cert with keys for system keys *///.........这里部分代码省略.........
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:101,
示例17: GetKeyParametersstatic OSStatus GetKeyParameters(CFDictionaryRef parameters, int keySize, bool isPublic, CSSM_KEYUSE &keyUse, uint32 &attrs, CFTypeRef &labelRef, CFDataRef &applicationTagRef){ // establish default values labelRef = NULL; bool isPermanent = false; applicationTagRef = NULL; CFTypeRef effectiveKeySize = NULL; bool canDecrypt = isPublic ? false : true; bool canEncrypt = !canDecrypt; bool canDerive = true; bool canSign = isPublic ? false : true; bool canVerify = !canSign; bool canUnwrap = isPublic ? false : true; attrs = CSSM_KEYATTR_EXTRACTABLE; keyUse = 0; void* attributePointers[] = {&labelRef, &isPermanent, &applicationTagRef, &effectiveKeySize, &canEncrypt, &canDecrypt, &canDerive, &canSign, &canVerify, &canUnwrap}; // look for modifiers in the general dictionary OSStatus result = ScanDictionaryForParameters(parameters, attributePointers); if (result != noErr) { return result; } // see if we have anything which modifies the defaults CFTypeRef key; if (isPublic) { key = kSecPublicKeyAttrs; } else { key = kSecPrivateKeyAttrs; } CFTypeRef dType = CFDictionaryGetValue(parameters, key); if (dType != NULL) { // this had better be a dictionary if (CFGetTypeID(dType) != CFDictionaryGetTypeID()) { return errSecParam; } // pull any additional parameters out of this dictionary result = ScanDictionaryForParameters(parameters, attributePointers); if (result != noErr) { return result; } } // figure out the key usage keyUse = 0; if (canDecrypt) { keyUse |= CSSM_KEYUSE_DECRYPT; } if (canEncrypt) { keyUse |= CSSM_KEYUSE_ENCRYPT; } if (canDerive) { keyUse |= CSSM_KEYUSE_DERIVE; } if (canSign) { keyUse |= CSSM_KEYUSE_SIGN; } if (canVerify) { keyUse |= CSSM_KEYUSE_VERIFY; } if (canUnwrap) { keyUse |= CSSM_KEYUSE_UNWRAP; } // public key is always extractable; // private key is extractable by default unless explicitly set to false CFTypeRef value = NULL; if (!isPublic && CFDictionaryGetValueIfPresent(parameters, kSecAttrIsExtractable, (const void **)&value) && value) { Boolean keyIsExtractable = CFEqual(kCFBooleanTrue, value); if (!keyIsExtractable) attrs = 0; } attrs |= CSSM_KEYATTR_PERMANENT; return noErr;}
开发者ID:Apple-FOSS-Mirror,项目名称:libsecurity_keychain,代码行数:100,
示例18: DAMountWithArguments//.........这里部分代码省略......... CFRetain( mountpoint ); } /* * Scan the mount map list. */ count = CFArrayGetCount( gDAMountMapList1 ); for ( index = 0; index < count; index++ ) { map = CFArrayGetValueAtIndex( gDAMountMapList1, index ); if ( map ) { CFTypeRef id; CFStringRef kind; id = CFDictionaryGetValue( map, kDAMountMapProbeIDKey ); kind = CFDictionaryGetValue( map, kDAMountMapProbeKindKey ); if ( kind ) { /* * Determine whether the volume kind matches. */ if ( CFEqual( kind, DAFileSystemGetKind( filesystem ) ) == FALSE ) { continue; } } if ( CFGetTypeID( id ) == CFUUIDGetTypeID( ) ) { /* * Determine whether the volume UUID matches. */ if ( DADiskCompareDescription( disk, kDADiskDescriptionVolumeUUIDKey, id ) == kCFCompareEqualTo ) { break; } } else if ( CFGetTypeID( id ) == CFStringGetTypeID( ) ) { /* * Determine whether the volume name matches. */ if ( DADiskCompareDescription( disk, kDADiskDescriptionVolumeNameKey, id ) == kCFCompareEqualTo ) { break; } } else if ( CFGetTypeID( id ) == CFDictionaryGetTypeID( ) ) { boolean_t match = FALSE; /* * Determine whether the device description matches. */ IOServiceMatchPropertyTable( DADiskGetIOMedia( disk ), id, &match ); if ( match )
开发者ID:carriercomm,项目名称:osx-2,代码行数:67,
示例19: 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; } // Set the run loop reference: the_correct_runloop = CFRunLoopGetCurrent(); 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;}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:84,
示例20: hu_XMLSearchForProductNameByVendorProductID/************************************************************************* * * hu_XMLSearchForProductNameByVendorProductID( inVendorID, inProductID, outCStr ) * * Purpose: Find an product string in the <HID_device_usage_strings.plist> resource ( XML ) file * * Inputs: inVendorID - the elements vendor ID * inProductID - the elements product ID * outCStr - address where result will be returned * * Returns: Boolean - if successful */static Boolean hu_XMLSearchForProductNameByVendorProductID(long inVendorID, long inProductID, char *outCStr) { Boolean results = FALSE; if ( !gUsageCFPropertyListRef ) { gUsageCFPropertyListRef = hu_XMLLoad( CFSTR( "HID_device_usage_strings"), CFSTR("plist") ); } if ( gUsageCFPropertyListRef ) { if ( CFDictionaryGetTypeID() == CFGetTypeID(gUsageCFPropertyListRef) ) { // first we make our vendor ID key CFStringRef vendorKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), inVendorID); if ( vendorKeyCFStringRef ) { // and use it to look up our vendor dictionary CFDictionaryRef vendorCFDictionaryRef; if ( CFDictionaryGetValueIfPresent(gUsageCFPropertyListRef, vendorKeyCFStringRef, (const void **) &vendorCFDictionaryRef) ) { // pull our vendor name our of that dictionary CFStringRef vendorCFStringRef = NULL; if ( CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, kNameKeyCFStringRef, (const void **) &vendorCFStringRef) ) {#if FAKE_MISSING_NAMES CFRetain(vendorCFStringRef); // so we can CFRelease it later } else { vendorCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "V: %@"), vendorKeyCFStringRef);#endif } // now we make our product ID key CFStringRef productKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%ld"), inProductID); if ( productKeyCFStringRef ) { // and use that key to look up our product dictionary in the vendor dictionary CFDictionaryRef productCFDictionaryRef; if ( CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, productKeyCFStringRef, (const void **) &productCFDictionaryRef) ) { // pull our product name our of the product dictionary CFStringRef productCFStringRef = NULL; if ( CFDictionaryGetValueIfPresent(productCFDictionaryRef, kNameKeyCFStringRef, (const void **) &productCFStringRef) ) {#if FAKE_MISSING_NAMES CFRetain(productCFStringRef); // so we can CFRelease it later } else { productCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "P: %@"), kNameKeyCFStringRef);#endif } CFStringRef fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%@ %@"), vendorCFStringRef, productCFStringRef); if ( fullCFStringRef ) { // CFShow( fullCFStringRef ); results = CFStringGetCString(fullCFStringRef, outCStr, CFStringGetLength( fullCFStringRef) * sizeof(UniChar) + 1, kCFStringEncodingUTF8); CFRelease(fullCFStringRef); } #if FAKE_MISSING_NAMES if ( productCFStringRef ) { CFRelease(productCFStringRef); } #endif } CFRelease(productKeyCFStringRef); } #if FAKE_MISSING_NAMES if ( vendorCFStringRef ) { CFRelease(vendorCFStringRef); } #endif } CFRelease(vendorKeyCFStringRef); } } //.........这里部分代码省略.........
开发者ID:CarlKenner,项目名称:gz3doom,代码行数:101,
示例21: gst_core_media_buffer_newGstBuffer *gst_core_media_buffer_new (GstCoreMediaCtx * ctx, CMSampleBufferRef sample_buf){ GstCVApi *cv = ctx->cv; GstCMApi *cm = ctx->cm; CVImageBufferRef image_buf; CVPixelBufferRef pixel_buf; CMBlockBufferRef block_buf; Byte *data = NULL; UInt32 size; OSStatus status; GstBuffer *buf; GstCoreMediaMeta *meta; image_buf = cm->CMSampleBufferGetImageBuffer (sample_buf); pixel_buf = NULL; block_buf = cm->CMSampleBufferGetDataBuffer (sample_buf); if (image_buf != NULL && CFGetTypeID (image_buf) == cv->CVPixelBufferGetTypeID ()) { pixel_buf = (CVPixelBufferRef) image_buf; if (cv->CVPixelBufferLockBaseAddress (pixel_buf, kCVPixelBufferLock_ReadOnly) != kCVReturnSuccess) { goto error; } if (cv->CVPixelBufferIsPlanar (pixel_buf)) { gint plane_count, plane_idx; data = cv->CVPixelBufferGetBaseAddressOfPlane (pixel_buf, 0); size = 0; plane_count = cv->CVPixelBufferGetPlaneCount (pixel_buf); for (plane_idx = 0; plane_idx != plane_count; plane_idx++) { size += cv->CVPixelBufferGetBytesPerRowOfPlane (pixel_buf, plane_idx) * cv->CVPixelBufferGetHeightOfPlane (pixel_buf, plane_idx); } } else { data = cv->CVPixelBufferGetBaseAddress (pixel_buf); size = cv->CVPixelBufferGetBytesPerRow (pixel_buf) * cv->CVPixelBufferGetHeight (pixel_buf); } } else if (block_buf != NULL) { status = cm->CMBlockBufferGetDataPointer (block_buf, 0, 0, 0, &data); if (status != noErr) goto error; size = cm->CMBlockBufferGetDataLength (block_buf); } else { goto error; } buf = gst_buffer_new (); meta = (GstCoreMediaMeta *) gst_buffer_add_meta (buf, gst_core_media_meta_get_info (), NULL); meta->ctx = g_object_ref (ctx); meta->sample_buf = cm->FigSampleBufferRetain (sample_buf); meta->image_buf = image_buf; meta->pixel_buf = pixel_buf; meta->block_buf = block_buf; gst_buffer_append_memory (buf, gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, data, size, 0, size, NULL, NULL)); return buf;error: return NULL;}
开发者ID:lubing521,项目名称:gst-embedded-builder,代码行数:71,
示例22: hu_XMLSearchForElementNameByUsage/************************************************************************* * * hu_XMLSearchForElementNameByUsage( inVendorID, inProductID, inUsagePage, inUsage, outCStr ) * * Purpose: Find an element string in the <HID_device_usage_strings.plist> resource( XML ) file * * Inputs: inVendorID - the elements vendor ID * inProductID - the elements product ID * inUsagePage - the elements usage page * inUsage - the elements usage * outCStr - address where result will be returned * * Returns: Boolean - if successful */static Boolean hu_XMLSearchForElementNameByUsage(long inVendorID, long inProductID, long inUsagePage, long inUsage, char *outCStr) { Boolean results = FALSE; if ( !gUsageCFPropertyListRef ) { gUsageCFPropertyListRef = hu_XMLLoad( CFSTR( "HID_device_usage_strings"), CFSTR("plist") ); } if ( gUsageCFPropertyListRef ) { if ( CFDictionaryGetTypeID() == CFGetTypeID(gUsageCFPropertyListRef) ) { CFStringRef vendorKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), inVendorID); if ( vendorKeyCFStringRef ) { CFDictionaryRef vendorCFDictionaryRef; if ( CFDictionaryGetValueIfPresent(gUsageCFPropertyListRef, vendorKeyCFStringRef, (const void **) &vendorCFDictionaryRef) ) { CFStringRef vendorCFStringRef = NULL; if ( CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, kNameKeyCFStringRef, (const void **) &vendorCFStringRef) ) { vendorCFStringRef = CFStringCreateCopy(kCFAllocatorDefault, vendorCFStringRef); } else { vendorCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("v: %ld"), inVendorID); // CFShow( vendorCFStringRef ); } CFStringRef productKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%ld"), inProductID); CFDictionaryRef productCFDictionaryRef; if ( CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, productKeyCFStringRef, (const void **) &productCFDictionaryRef) ) { CFStringRef fullCFStringRef = NULL; CFStringRef productCFStringRef; if ( CFDictionaryGetValueIfPresent(productCFDictionaryRef, kNameKeyCFStringRef, (const void **) &productCFStringRef) ) { // CFShow( productCFStringRef ); } CFStringRef usageKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%ld:%ld"), inUsagePage, inUsage); CFStringRef usageCFStringRef; if ( CFDictionaryGetValueIfPresent(productCFDictionaryRef, usageKeyCFStringRef, (const void **) &usageCFStringRef) ) {#if VERBOSE_ELEMENT_NAMES fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%@ %@ %@"), vendorCFStringRef, productCFStringRef, usageCFStringRef);#else fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@"), usageCFStringRef);#endif // VERBOSE_ELEMENT_NAMES // CFShow( usageCFStringRef ); } #if FAKE_MISSING_NAMES else { fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%@ %@ # %@"), vendorCFStringRef, productCFStringRef, usageKeyCFStringRef); }#endif // FAKE_MISSING_NAMES if ( fullCFStringRef ) { // CFShow( fullCFStringRef ); results = CFStringGetCString(fullCFStringRef, outCStr, CFStringGetLength( fullCFStringRef) * sizeof(UniChar) + 1, kCFStringEncodingUTF8); CFRelease(fullCFStringRef); } CFRelease(usageKeyCFStringRef); } if ( vendorCFStringRef ) { CFRelease(vendorCFStringRef); } CFRelease(productKeyCFStringRef); } CFRelease(vendorKeyCFStringRef); }//.........这里部分代码省略.........
开发者ID:CarlKenner,项目名称:gz3doom,代码行数:101,
示例23: find_led_cookiesvoidfind_led_cookies(IOHIDDeviceInterface122** handle){ IOHIDElementCookie cookie; CFTypeRef object; long number; long usage; long usagePage; CFArrayRef elements; CFDictionaryRef element; IOReturn result; if (!handle || !(*handle)) { return; } result = (*handle)->copyMatchingElements(handle, NULL, &elements); if (result != kIOReturnSuccess) { fprintf(stderr, "Failed to copy cookies./n"); exit(1); } CFIndex i; for (i = 0; i < CFArrayGetCount(elements); i++) { element = CFArrayGetValueAtIndex(elements, i); object = (CFDictionaryGetValue(element, CFSTR(kIOHIDElementCookieKey))); if (object == 0 || CFGetTypeID(object) != CFNumberGetTypeID()) { continue; } if (!CFNumberGetValue((CFNumberRef) object, kCFNumberLongType, &number)) { continue; } cookie = (IOHIDElementCookie)number; object = CFDictionaryGetValue(element, CFSTR(kIOHIDElementUsageKey)); if (object == 0 || CFGetTypeID(object) != CFNumberGetTypeID()) { continue; } if (!CFNumberGetValue((CFNumberRef)object, kCFNumberLongType, &number)) { continue; } usage = number; object = CFDictionaryGetValue(element,CFSTR(kIOHIDElementUsagePageKey)); if (object == 0 || CFGetTypeID(object) != CFNumberGetTypeID()) { continue; } if (!CFNumberGetValue((CFNumberRef)object, kCFNumberLongType, &number)) { continue; } usagePage = number; if (usagePage == kHIDPage_LEDs) { switch (usage) { case kHIDUsage_LED_NumLock: numlock_cookie = cookie; break; case kHIDUsage_LED_CapsLock: capslock_cookie = cookie; break; default: break; } } } return;}
开发者ID:bharath2020,项目名称:mikeash.com-svn,代码行数:78,
示例24: hu_AddVendorProductToCFDict/************************************************************************* * * hu_AddVendorProductToCFDict( inCFMutableDictionaryRef, inVendorID, inVendorCFStringRef, inProductID, inProductCFStringRef ) * * Purpose: add a vendor & product to a dictionary * * Inputs: inCFMutableDictionaryRef - the dictionary * inVendorID - the elements vendor ID * inProductID - the elements product ID * inProductCFStringRef - the string to be added * * Returns: Boolean - if successful */static Boolean hu_AddVendorProductToCFDict(CFMutableDictionaryRef inCFMutableDictionaryRef, long inVendorID, CFStringRef inVendorCFStringRef, long inProductID, CFStringRef inProductCFStringRef) { Boolean results = FALSE; if ( inCFMutableDictionaryRef && ( CFDictionaryGetTypeID() == CFGetTypeID(inCFMutableDictionaryRef) ) ) { CFMutableDictionaryRef vendorCFMutableDictionaryRef; CFStringRef vendorKeyCFStringRef; CFMutableDictionaryRef productCFMutableDictionaryRef; CFStringRef productKeyCFStringRef; // if the vendor dictionary doesn't exist vendorKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), inVendorID); if ( CFDictionaryGetValueIfPresent(inCFMutableDictionaryRef, vendorKeyCFStringRef, (const void **) &vendorCFMutableDictionaryRef) ) { // copy it. vendorCFMutableDictionaryRef = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, vendorCFMutableDictionaryRef); } else { // ...otherwise... // create it. vendorCFMutableDictionaryRef = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); results = TRUE; } // if the vendor name key doesn't exist if ( !CFDictionaryContainsKey(vendorCFMutableDictionaryRef, kNameKeyCFStringRef) ) { // create it. CFDictionaryAddValue(vendorCFMutableDictionaryRef, kNameKeyCFStringRef, inVendorCFStringRef); results = TRUE; } // if the product key exists in the vendor dictionary productKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), inProductID); if ( CFDictionaryGetValueIfPresent(vendorCFMutableDictionaryRef, productKeyCFStringRef, (const void **) &productCFMutableDictionaryRef) ) { // copy it. productCFMutableDictionaryRef = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, productCFMutableDictionaryRef); } else { // ...otherwise... // create it. productCFMutableDictionaryRef = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); results = TRUE; } // if the product name key doesn't exist if ( !CFDictionaryContainsKey(productCFMutableDictionaryRef, kNameKeyCFStringRef) ) { // create it. CFDictionaryAddValue(productCFMutableDictionaryRef, kNameKeyCFStringRef, inProductCFStringRef); results = TRUE; } if ( vendorCFMutableDictionaryRef ) { if ( productCFMutableDictionaryRef ) { if ( results ) { CFDictionarySetValue(vendorCFMutableDictionaryRef, productKeyCFStringRef, productCFMutableDictionaryRef); } CFRelease(productCFMutableDictionaryRef); } if ( results ) { CFDictionarySetValue(inCFMutableDictionaryRef, vendorKeyCFStringRef, vendorCFMutableDictionaryRef); } CFRelease(vendorCFMutableDictionaryRef); } if ( productKeyCFStringRef ) { CFRelease(productKeyCFStringRef); } if ( vendorKeyCFStringRef ) { CFRelease(vendorKeyCFStringRef); } } return (results);} // hu_AddVendorProductToCFDict
开发者ID:CarlKenner,项目名称:gz3doom,代码行数:93,
示例25: cdio_get_devices// Returns a pointer to an array of strings with the device namesstd::vector<std::string> cdio_get_devices(){ io_object_t next_media; mach_port_t master_port; kern_return_t kern_result; io_iterator_t media_iterator; CFMutableDictionaryRef classes_to_match; std::vector<std::string> drives; kern_result = IOMasterPort(MACH_PORT_NULL, &master_port); if (kern_result != KERN_SUCCESS) return drives; classes_to_match = IOServiceMatching(kIOCDMediaClass); if (classes_to_match == nullptr) return drives; CFDictionarySetValue(classes_to_match, CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); kern_result = IOServiceGetMatchingServices(master_port, classes_to_match, &media_iterator); if (kern_result != KERN_SUCCESS) return drives; next_media = IOIteratorNext(media_iterator); if (next_media != 0) { CFTypeRef str_bsd_path; do { str_bsd_path = IORegistryEntryCreateCFProperty(next_media, CFSTR(kIOBSDNameKey), kCFAllocatorDefault, 0); if (str_bsd_path == nullptr) { IOObjectRelease(next_media); continue; } if (CFGetTypeID(str_bsd_path) == CFStringGetTypeID()) { size_t buf_size = CFStringGetLength((CFStringRef)str_bsd_path) * 4 + 1; char* buf = new char[buf_size]; if (CFStringGetCString((CFStringRef)str_bsd_path, buf, buf_size, kCFStringEncodingUTF8)) { // Below, by appending 'r' to the BSD node name, we indicate // a raw disk. Raw disks receive I/O requests directly and // don't go through a buffer cache. drives.push_back(std::string(_PATH_DEV "r") + buf); } delete[] buf; } CFRelease(str_bsd_path); IOObjectRelease(next_media); } while ((next_media = IOIteratorNext(media_iterator)) != 0); } IOObjectRelease(media_iterator); return drives;}
开发者ID:gamax92,项目名称:Ishiiruka,代码行数:65,
示例26: disk_readstatic int disk_read (void){#if HAVE_IOKIT_IOKITLIB_H io_registry_entry_t disk; io_registry_entry_t disk_child; io_iterator_t disk_list; CFMutableDictionaryRef props_dict, child_dict; CFDictionaryRef stats_dict; CFStringRef tmp_cf_string_ref; kern_return_t status; signed long long read_ops, read_byt, read_tme; signed long long write_ops, write_byt, write_tme; int disk_major, disk_minor; char disk_name[DATA_MAX_NAME_LEN]; char child_disk_name_bsd[DATA_MAX_NAME_LEN], props_disk_name_bsd[DATA_MAX_NAME_LEN]; /* Get the list of all disk objects. */ if (IOServiceGetMatchingServices (io_master_port, IOServiceMatching (kIOBlockStorageDriverClass), &disk_list) != kIOReturnSuccess) { ERROR ("disk plugin: IOServiceGetMatchingServices failed."); return (-1); } while ((disk = IOIteratorNext (disk_list)) != 0) { props_dict = NULL; stats_dict = NULL; child_dict = NULL; /* get child of disk entry and corresponding property dictionary */ if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child)) != kIOReturnSuccess) { /* This fails for example for DVD/CD drives, which we want to ignore anyway */ DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status); IOObjectRelease (disk); continue; } if (IORegistryEntryCreateCFProperties (disk_child, (CFMutableDictionaryRef *) &child_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || child_dict == NULL) { ERROR ("disk plugin: IORegistryEntryCreateCFProperties (disk_child) failed."); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; } /* extract name and major/minor numbers */ memset (child_disk_name_bsd, 0, sizeof (child_disk_name_bsd)); tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (child_dict, CFSTR(kIOBSDNameKey)); if (tmp_cf_string_ref) { assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ()); CFStringGetCString (tmp_cf_string_ref, child_disk_name_bsd, sizeof (child_disk_name_bsd), kCFStringEncodingUTF8); } disk_major = (int) dict_get_value (child_dict, kIOBSDMajorKey); disk_minor = (int) dict_get_value (child_dict, kIOBSDMinorKey); DEBUG ("disk plugin: child_disk_name_bsd=/"%s/" major=%d minor=%d", child_disk_name_bsd, disk_major, disk_minor); CFRelease (child_dict); IOObjectRelease (disk_child); /* get property dictionary of the disk entry itself */ if (IORegistryEntryCreateCFProperties (disk, (CFMutableDictionaryRef *) &props_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || props_dict == NULL) { ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed."); IOObjectRelease (disk); continue; } /* extract name and stats dictionary */ memset (props_disk_name_bsd, 0, sizeof (props_disk_name_bsd)); tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict, CFSTR(kIOBSDNameKey)); if (tmp_cf_string_ref) { assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ()); CFStringGetCString (tmp_cf_string_ref, props_disk_name_bsd, sizeof (props_disk_name_bsd), kCFStringEncodingUTF8); } stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict, CFSTR (kIOBlockStorageDriverStatisticsKey)); if (stats_dict == NULL) { ERROR ("disk plugin: CFDictionaryGetValue (%s) failed.", kIOBlockStorageDriverStatisticsKey); CFRelease (props_dict); IOObjectRelease (disk); continue; } DEBUG ("disk plugin: props_disk_name_bsd=/"%s/"", props_disk_name_bsd); /* choose name */ if (use_bsd_name) { if (child_disk_name_bsd[0] != 0) sstrncpy (disk_name, child_disk_name_bsd, sizeof (disk_name)); else if (props_disk_name_bsd[0] != 0) sstrncpy (disk_name, props_disk_name_bsd, sizeof (disk_name)); else { ERROR ("disk plugin: can't find bsd disk name."); ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor); } } else ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor); /* extract the stats */ read_ops = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsReadsKey); read_byt = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesReadKey); read_tme = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalReadTimeKey); write_ops = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsWritesKey); write_byt = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesWrittenKey); write_tme = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalWriteTimeKey);//.........这里部分代码省略.........
开发者ID:Mindera,项目名称:collectd,代码行数:101,
注:本文中的CFGetTypeID函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ CFNumberCreate函数代码示例 C++ CFGetAllocator函数代码示例 |