本文整理汇总了C++中CFGetTypeID函数的典型用法代码示例。如果您正苦于以下问题:C++ CFGetTypeID函数的具体用法?C++ CFGetTypeID怎么用?C++ CFGetTypeID使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CFGetTypeID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDeviceMatched
static 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;
}
示例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 void
PlatformCallback(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);
}
示例3: ModemOrSerialDeviceToDictProc
static 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;
}
示例4: SetKeyLabelAndTag
static 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);
}
示例5: findFirstEncryptionPublicKeyOnToken
int 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;
}
示例6: HIDGetElementsCFArrayHandler
static void
HIDGetElementsCFArrayHandler(const void *value, void *parameter)
{
if (CFGetTypeID(value) == CFDictionaryGetTypeID())
HIDAddElement((CFTypeRef) value, (recDevice *) parameter);
}
示例7: SecKeyGenerateSymmetric
SecKeyRef
SecKeyGenerateSymmetric(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))
//.........这里部分代码省略.........
示例8: DoSetPermissions
OSStatus 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) ;
//.........这里部分代码省略.........
示例9: q_toVariant
static 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();
}
示例10: propertyListExample
void 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);
}
示例11: MyGetModemPath
static 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;
}
示例12: disk_read
static 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));
//.........这里部分代码省略.........
示例13: ASSERT
bool 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;
}
示例14: dsauth_chap
static 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));
//.........这里部分代码省略.........
示例15: _SCCopyDescription
CFStringRef
_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;
//.........这里部分代码省略.........