本文整理匯總了C++中CFArrayGetCount函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFArrayGetCount函數的具體用法?C++ CFArrayGetCount怎麽用?C++ CFArrayGetCount使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFArrayGetCount函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: DoStatPaths
OSStatus DoStatPaths(COMMAND_PROC_ARGUMENTS) {
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 CFArrayRef
CFArrayRef infos = CFDictionaryGetValue(request, CFSTR(kInfos)) ;
assert(infos != NULL) ;
assert(CFGetTypeID(infos) == CFArrayGetTypeID()) ;
CFIndex nFiles = CFArrayGetCount(infos) ;
CFIndex i ;
int nSucceeded = 0 ;
CFMutableDictionaryRef statDatas = CFDictionaryCreateMutable(
NULL,
nFiles,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks
) ;
CFMutableDictionaryRef errorCodes = CFDictionaryCreateMutable(
NULL,
nFiles,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks
) ;
for (i=0; i<nFiles; i++) {
CFStringRef path = CFArrayGetValueAtIndex(infos, i) ;
assert(CFGetTypeID(path) == CFStringGetTypeID()) ;
int errorCode = 0 ;
char pathC[SSY_UNIX_PATH_UTILS_MAX_PATH_CHARS] ;
if (errorCode == 0) {
Boolean ok = CFStringGetCString(
path,
pathC,
SSY_UNIX_PATH_UTILS_MAX_PATH_CHARS,
kCFStringEncodingASCII
) ;
if (!ok) {
errorCode = SSYAuthorizedTasksPathTooLong ;
}
}
if (errorCode == 0) {
struct stat aStat ;
int result = stat(pathC, &aStat) ;
if (result == 0) {
CFDataRef statData = CFDataCreate (
kCFAllocatorDefault,
(UInt8*)&aStat,
sizeof(aStat)
) ;
CFDictionaryAddValue(statDatas, path, statData) ;
CFQRelease(statData) ;
}
else {
errorCode = errno ;
}
}
if (errorCode == 0) {
nSucceeded++ ;
}
else {
CFNumberRef errorNumber = CFNumberCreate(
kCFAllocatorDefault,
kCFNumberIntType,
&errorCode
) ;
CFDictionaryAddValue(errorCodes, path, errorNumber) ;
CFQRelease(errorNumber) ;
}
}
CFDictionaryAddValue(response, CFSTR(kStatDatas), statDatas) ;
CFRelease(statDatas) ;
CFDictionaryAddValue(response, CFSTR(kErrorCodes), errorCodes) ;
CFRelease(errorCodes) ;
asl_log(
asl,
aslMsg,
ASL_LEVEL_DEBUG,
"DoStatPaths did good %d/%d requested files",
nSucceeded,
(int)nFiles
) ;
// Return the number of file copy operations that failed
retval = nFiles - nSucceeded ;
return retval ;
}
示例2: CGFontCopyTableTags
bool
ScaledFontMac::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton)
{
// We'll reconstruct a TTF font from the tables we can get from the CGFont
CFArrayRef tags = CGFontCopyTableTags(mFont);
CFIndex count = CFArrayGetCount(tags);
TableRecord *records = new TableRecord[count];
uint32_t offset = 0;
offset += sizeof(uint32_t)*3;
offset += sizeof(uint32_t)*4*count;
bool CFF = false;
for (CFIndex i = 0; i<count; i++) {
uint32_t tag = (uint32_t)(uintptr_t)CFArrayGetValueAtIndex(tags, i);
if (tag == 0x43464620) // 'CFF '
CFF = true;
CFDataRef data = CGFontCopyTableForTag(mFont, tag);
records[i].tag = tag;
records[i].offset = offset;
records[i].data = data;
records[i].length = CFDataGetLength(data);
bool skipChecksumAdjust = (tag == 0x68656164); // 'head'
records[i].checkSum = CalcTableChecksum(reinterpret_cast<const uint32_t*>(CFDataGetBytePtr(data)),
records[i].length, skipChecksumAdjust);
offset += records[i].length;
// 32 bit align the tables
offset = (offset + 3) & ~3;
}
CFRelease(tags);
struct writeBuf buf(offset);
// write header/offset table
if (CFF) {
buf.writeElement(CFSwapInt32HostToBig(0x4f54544f));
} else {
buf.writeElement(CFSwapInt32HostToBig(0x00010000));
}
buf.writeElement(CFSwapInt16HostToBig(count));
buf.writeElement(CFSwapInt16HostToBig((1<<maxPow2LessThan(count))*16));
buf.writeElement(CFSwapInt16HostToBig(maxPow2LessThan(count)));
buf.writeElement(CFSwapInt16HostToBig(count*16-((1<<maxPow2LessThan(count))*16)));
// write table record entries
for (CFIndex i = 0; i<count; i++) {
buf.writeElement(CFSwapInt32HostToBig(records[i].tag));
buf.writeElement(CFSwapInt32HostToBig(records[i].checkSum));
buf.writeElement(CFSwapInt32HostToBig(records[i].offset));
buf.writeElement(CFSwapInt32HostToBig(records[i].length));
}
// write tables
int checkSumAdjustmentOffset = 0;
for (CFIndex i = 0; i<count; i++) {
if (records[i].tag == 0x68656164) {
checkSumAdjustmentOffset = buf.offset + 2*4;
}
buf.writeMem(CFDataGetBytePtr(records[i].data), CFDataGetLength(records[i].data));
buf.align();
CFRelease(records[i].data);
}
delete[] records;
// clear the checksumAdjust field before checksumming the whole font
memset(&buf.data[checkSumAdjustmentOffset], 0, sizeof(uint32_t));
uint32_t fontChecksum = CFSwapInt32HostToBig(0xb1b0afba - CalcTableChecksum(reinterpret_cast<const uint32_t*>(buf.data), offset));
// set checkSumAdjust to the computed checksum
memcpy(&buf.data[checkSumAdjustmentOffset], &fontChecksum, sizeof(fontChecksum));
// we always use an index of 0
aDataCallback(buf.data, buf.offset, 0, mSize, aBaton);
return true;
}
示例3: mongoc_secure_transport_setup_certificate
bool
mongoc_secure_transport_setup_certificate (
mongoc_stream_tls_secure_transport_t *secure_transport,
mongoc_ssl_opt_t *opt)
{
bool success;
CFArrayRef items;
SecIdentityRef id;
SecKeyRef key = NULL;
SecCertificateRef cert = NULL;
SecExternalItemType type = kSecItemTypeCertificate;
if (!opt->pem_file) {
TRACE ("%s",
"No private key provided, the server won't be able to verify us");
return false;
}
success = _mongoc_secure_transport_import_pem (
opt->pem_file, opt->pem_pwd, &items, &type);
if (!success) {
MONGOC_ERROR ("Can't find certificate in: '%s'", opt->pem_file);
return false;
}
if (type != kSecItemTypeAggregate) {
MONGOC_ERROR ("Cannot work with keys of type \"%d\". Please file a JIRA",
type);
CFRelease (items);
return false;
}
for (CFIndex i = 0; i < CFArrayGetCount (items); ++i) {
CFTypeID item_id = CFGetTypeID (CFArrayGetValueAtIndex (items, i));
if (item_id == SecCertificateGetTypeID ()) {
cert = (SecCertificateRef) CFArrayGetValueAtIndex (items, i);
} else if (item_id == SecKeyGetTypeID ()) {
key = (SecKeyRef) CFArrayGetValueAtIndex (items, i);
}
}
if (!cert || !key) {
MONGOC_ERROR ("Couldn't find valid private key");
CFRelease (items);
return false;
}
id = SecIdentityCreate (kCFAllocatorDefault, cert, key);
secure_transport->my_cert =
CFArrayCreateMutable (kCFAllocatorDefault, 2, &kCFTypeArrayCallBacks);
CFArrayAppendValue (secure_transport->my_cert, id);
CFArrayAppendValue (secure_transport->my_cert, cert);
CFRelease (id);
/*
* Secure Transport assumes the following:
* * The certificate references remain valid for the lifetime of the
* session.
* * The identity specified in certRefs[0] is capable of signing.
*/
success = !SSLSetCertificate (secure_transport->ssl_ctx_ref,
secure_transport->my_cert);
TRACE ("Setting client certificate %s", success ? "succeeded" : "failed");
CFRelease (items);
return true;
}
示例4: pango_core_text_family_list_faces
static void
pango_core_text_family_list_faces (PangoFontFamily *family,
PangoFontFace ***faces,
int *n_faces)
{
PangoCoreTextFamily *ctfamily = PANGO_CORE_TEXT_FAMILY (family);
if (ctfamily->n_faces < 0)
{
GList *l;
GList *faces = NULL;
GList *synthetic_faces = NULL;
GHashTable *italic_faces;
const char *real_family = get_real_family (ctfamily->family_name);
CTFontCollectionRef collection;
CFArrayRef ctfaces;
CFArrayRef font_descriptors;
CFDictionaryRef attributes;
CFIndex i, count;
CFTypeRef keys[] = {
(CFTypeRef) kCTFontFamilyNameAttribute
};
CFStringRef values[] = {
CFStringCreateWithCString (kCFAllocatorDefault,
real_family,
kCFStringEncodingUTF8)
};
CTFontDescriptorRef descriptors[1];
attributes = CFDictionaryCreate (kCFAllocatorDefault,
(const void **)keys,
(const void **)values,
1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
descriptors[0] = CTFontDescriptorCreateWithAttributes (attributes);
font_descriptors = CFArrayCreate (kCFAllocatorDefault,
(const void **)descriptors,
1,
&kCFTypeArrayCallBacks);
collection = CTFontCollectionCreateWithFontDescriptors (font_descriptors,
NULL);
ctfaces = CTFontCollectionCreateMatchingFontDescriptors (collection);
italic_faces = g_hash_table_new (g_direct_hash, g_direct_equal);
count = CFArrayGetCount (ctfaces);
for (i = 0; i < count; i++)
{
PangoCoreTextFace *face;
CTFontDescriptorRef desc = CFArrayGetValueAtIndex (ctfaces, i);
face = pango_core_text_face_from_ct_font_descriptor (desc);
face->family = ctfamily;
faces = g_list_prepend (faces, face);
if (face->traits & kCTFontItalicTrait
|| pango_core_text_face_is_oblique (face))
g_hash_table_insert (italic_faces,
GINT_TO_POINTER ((gint)face->weight),
face);
}
CFRelease (font_descriptors);
CFRelease (attributes);
CFRelease (ctfaces);
/* For all fonts for which a non-synthetic italic variant does
* not exist on the system, we create synthesized versions here.
*/
for (l = faces; l; l = l->next)
{
PangoCoreTextFace *face = l->data;
if (!g_hash_table_lookup (italic_faces,
GINT_TO_POINTER ((gint)face->weight)))
{
PangoCoreTextFace *italic_face;
italic_face = g_object_new (PANGO_TYPE_CORE_TEXT_FACE, NULL);
italic_face->family = ctfamily;
italic_face->postscript_name = g_strdup (face->postscript_name);
italic_face->weight = face->weight;
italic_face->traits = face->traits | kCTFontItalicTrait;
italic_face->synthetic_italic = TRUE;
italic_face->coverage = pango_coverage_ref (face->coverage);
/* Try to create a sensible face name. */
if (strcasecmp (face->style_name, "regular") == 0)
italic_face->style_name = g_strdup ("Oblique");
else
italic_face->style_name = g_strdup_printf ("%s Oblique",
face->style_name);
//.........這裏部分代碼省略.........
示例5: __CFArrayValidateRange
CF_INLINE void __CFArrayValidateRange(CFArrayRef array, CFRange range, const char *func) {
CFAssert3(0 <= range.location && range.location <= CFArrayGetCount(array), __kCFLogAssertion, "%s(): range.location index (%ld) out of bounds (0, %ld)", func, range.location, CFArrayGetCount(array));
CFAssert2(0 <= range.length, __kCFLogAssertion, "%s(): range.length (%ld) cannot be less than zero", func, range.length);
CFAssert3(range.location + range.length <= CFArrayGetCount(array), __kCFLogAssertion, "%s(): ending index (%ld) out of bounds (0, %ld)", func, range.location + range.length, CFArrayGetCount(array));
}
示例6: SCREENReadNormalizedGammaTable
//.........這裏部分代碼省略.........
screenNumber = -1 * screenNumber;
}
else {
PsychCopyInScreenNumberArg(1, TRUE, &screenNumber);
}
if ((PSYCH_SYSTEM == PSYCH_LINUX) && (physicalDisplay > -1)) {
// Affect one specific display output for given screen:
outputId = physicalDisplay;
}
else {
// Other OS'es, and Linux with default setting: Affect all outputs
// for a screen.
outputId = -1;
}
// Retrieve gamma table:
PsychReadNormalizedGammaTable(screenNumber, outputId, &numEntries, &redTable, &greenTable, &blueTable);
// Copy it out to runtime:
PsychAllocOutDoubleMatArg(1, FALSE, numEntries, 3, 0, &gammaTable);
for(i=0;i<numEntries;i++){
gammaTable[PsychIndexElementFrom3DArray(numEntries, 3, 0, i, 0, 0)]=(double)redTable[i];
gammaTable[PsychIndexElementFrom3DArray(numEntries, 3, 0, i, 1, 0)]=(double)greenTable[i];
gammaTable[PsychIndexElementFrom3DArray(numEntries, 3, 0, i, 2, 0)]=(double)blueTable[i];
}
// Copy out optional DAC resolution value:
PsychCopyOutDoubleArg(2, FALSE, (double) PsychGetDacBitsFromDisplay(screenNumber));
// We default to the assumption that the real size of the hardware LUT is identical to
// the size of the returned LUT:
reallutsize = numEntries;
#if PSYCH_SYSTEM == PSYCH_OSX
// On OS-X we query the real LUT size from the OS and return that value:
CGDirectDisplayID displayID;
CFMutableDictionaryRef properties;
CFNumberRef cfGammaLength;
SInt32 lutslotcount;
io_service_t displayService;
kern_return_t kr;
CFMutableArrayRef framebufferTimings0 = 0;
CFDataRef framebufferTimings1 = 0;
IODetailedTimingInformationV2 *framebufferTiming = NULL;
// Retrieve display handle for screen:
PsychGetCGDisplayIDFromScreenNumber(&displayID, screenNumber);
// Retrieve low-level IOKit service port for this display:
displayService = CGDisplayIOServicePort(displayID);
// Obtain the properties from that service
kr = IORegistryEntryCreateCFProperties(displayService, &properties, NULL, 0);
if((kr == kIOReturnSuccess) && ((cfGammaLength = (CFNumberRef) CFDictionaryGetValue(properties, CFSTR(kIOFBGammaCountKey)))!=NULL))
{
CFNumberGetValue(cfGammaLength, kCFNumberSInt32Type, &lutslotcount);
CFRelease(properties);
reallutsize = (int) lutslotcount;
}
else {
// Failed!
if (PsychPrefStateGet_Verbosity()>1) printf("PTB-WARNING: Failed to query real size of video LUT for screen %i! Will return safe default of %i slots.\n", screenNumber, reallutsize);
}
if (PsychPrefStateGet_Verbosity()>9) {
CGDisplayModeRef currentMode;
CFNumberRef n;
int modeId;
currentMode = CGDisplayCopyDisplayMode(displayID);
modeId = (int) CGDisplayModeGetIODisplayModeID(currentMode);
CGDisplayModeRelease(currentMode);
printf("Current mode has id %i\n\n", modeId);
kr = IORegistryEntryCreateCFProperties(displayService, &properties, NULL, 0);
if((kr == kIOReturnSuccess) && ((framebufferTimings0 = (CFMutableArrayRef) CFDictionaryGetValue(properties, CFSTR(kIOFBDetailedTimingsKey) ) )!=NULL))
{
for (i=0; i<CFArrayGetCount(framebufferTimings0); i++) {
if ((framebufferTimings1 = CFArrayGetValueAtIndex(framebufferTimings0, i)) != NULL) {
if ((framebufferTiming = (IODetailedTimingInformationV2*) CFDataGetBytePtr(framebufferTimings1)) != NULL) {
printf("[%i] : VActive = %li, VBL = %li, VSYNC = %li, VSYNCWIDTH = %li , VBORDERBOT = %li, VTOTAL = %li \n", i, framebufferTiming->verticalActive, framebufferTiming->verticalBlanking, framebufferTiming->verticalSyncOffset, framebufferTiming->verticalSyncPulseWidth, framebufferTiming->verticalBorderBottom, framebufferTiming->verticalActive + framebufferTiming->verticalBlanking);
}
}
}
CFRelease(properties);
}
else {
// Failed!
if (PsychPrefStateGet_Verbosity()>1) printf("PTB-WARNING: Failed to query STUFF for screen %i --> %p!\n", screenNumber, properties);
}
}
#endif
// Copy out optional real LUT size (number of slots):
PsychCopyOutDoubleArg(3, FALSE, (double) reallutsize);
return(PsychError_none);
}
示例7: convertWebResourceDataToString
static void convertWebResourceDataToString(CFMutableDictionaryRef resource)
{
CFMutableStringRef mimeType = (CFMutableStringRef)CFDictionaryGetValue(resource, CFSTR("WebResourceMIMEType"));
CFStringLowercase(mimeType, CFLocaleGetSystem());
convertMIMEType(mimeType);
CFArrayRef supportedMIMETypes = supportedNonImageMIMETypes();
if (CFStringHasPrefix(mimeType, CFSTR("text/")) || CFArrayContainsValue(supportedMIMETypes, CFRangeMake(0, CFArrayGetCount(supportedMIMETypes)), mimeType)) {
CFStringRef textEncodingName = static_cast<CFStringRef>(CFDictionaryGetValue(resource, CFSTR("WebResourceTextEncodingName")));
CFStringEncoding stringEncoding;
if (textEncodingName && CFStringGetLength(textEncodingName))
stringEncoding = CFStringConvertIANACharSetNameToEncoding(textEncodingName);
else
stringEncoding = kCFStringEncodingUTF8;
CFDataRef data = static_cast<CFDataRef>(CFDictionaryGetValue(resource, CFSTR("WebResourceData")));
RetainPtr<CFStringRef> dataAsString = adoptCF(CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, data, stringEncoding));
if (dataAsString)
CFDictionarySetValue(resource, CFSTR("WebResourceData"), dataAsString.get());
}
}
示例8: SetFallbackFont
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback)
{
const char *str;
bool result = false;
callback->FindMissingGlyphs(&str);
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
if (MacOSVersionIsAtLeast(10, 5, 0)) {
/* Determine fallback font using CoreText. This uses the language isocode
* to find a suitable font. CoreText is available from 10.5 onwards. */
char lang[16];
if (strcmp(language_isocode, "zh_TW") == 0) {
/* Traditional Chinese */
strecpy(lang, "zh-Hant", lastof(lang));
} else if (strcmp(language_isocode, "zh_CN") == 0) {
/* Simplified Chinese */
strecpy(lang, "zh-Hans", lastof(lang));
} else if (strncmp(language_isocode, "ur", 2) == 0) {
/* The urdu alphabet is variant of persian. As OS X has no default
* font that advertises an urdu language code, search for persian
* support instead. */
strecpy(lang, "fa", lastof(lang));
} else {
/* Just copy the first part of the isocode. */
strecpy(lang, language_isocode, lastof(lang));
char *sep = strchr(lang, '_');
if (sep != NULL) *sep = '\0';
}
CFStringRef lang_code;
lang_code = CFStringCreateWithCString(kCFAllocatorDefault, lang, kCFStringEncodingUTF8);
/* Create a font iterator and iterate over all fonts that
* are available to the application. */
ATSFontIterator itr;
ATSFontRef font;
ATSFontIteratorCreate(kATSFontContextLocal, NULL, NULL, kATSOptionFlagsUnRestrictedScope, &itr);
while (!result && ATSFontIteratorNext(itr, &font) == noErr) {
/* Get CoreText font handle. */
CTFontRef font_ref = CTFontCreateWithPlatformFont(font, 0.0, NULL, NULL);
CFArrayRef langs = CTFontCopySupportedLanguages(font_ref);
if (langs != NULL) {
/* Font has a list of supported languages. */
for (CFIndex i = 0; i < CFArrayGetCount(langs); i++) {
CFStringRef lang = (CFStringRef)CFArrayGetValueAtIndex(langs, i);
if (CFStringCompare(lang, lang_code, kCFCompareAnchored) == kCFCompareEqualTo) {
/* Lang code is supported by font, get full font name. */
CFStringRef font_name = CTFontCopyFullName(font_ref);
char name[128];
CFStringGetCString(font_name, name, lengthof(name), kCFStringEncodingUTF8);
CFRelease(font_name);
/* Skip some inappropriate or ugly looking fonts that have better alternatives. */
if (strncmp(name, "Courier", 7) == 0 || strncmp(name, "Apple Symbols", 13) == 0 ||
strncmp(name, ".Aqua", 5) == 0 || strncmp(name, "LastResort", 10) == 0 ||
strncmp(name, "GB18030 Bitmap", 14) == 0) continue;
/* Save result. */
callback->SetFontNames(settings, name);
DEBUG(freetype, 2, "CT-Font for %s: %s", language_isocode, name);
result = true;
break;
}
}
CFRelease(langs);
}
CFRelease(font_ref);
}
ATSFontIteratorRelease(&itr);
CFRelease(lang_code);
} else
#endif
{
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) && !__LP64__
/* Determine fallback font using ATSUI. This uses a string sample with
* missing characters. This is not failure-proof, but a better way like
* using the isocode as in the CoreText code path is not available.
* ATSUI was deprecated with 10.6 and is only partially available in
* 64-bit mode. */
/* Remove all control characters in the range from SCC_CONTROL_START to
* SCC_CONTROL_END as well as all ASCII < 0x20 from the string as it will
* mess with the automatic font detection */
char buff[256]; // This length is enough to find a suitable replacement font
strecpy(buff, str, lastof(buff));
str_validate(buff, lastof(buff), SVS_ALLOW_NEWLINE);
/* Extract a UniChar representation of the sample string. */
CFStringRef cf_str = CFStringCreateWithCString(kCFAllocatorDefault, buff, kCFStringEncodingUTF8);
if (cf_str == NULL) {
/* Something went wrong. Corrupt/invalid sample string? */
return false;
}
CFIndex str_len = CFStringGetLength(cf_str);
UniChar string[str_len];
CFStringGetCharacters(cf_str, CFRangeMake(0, str_len), string);
/* Create a default text style with the default font. */
ATSUStyle style;
ATSUCreateStyle(&style);
//.........這裏部分代碼省略.........
示例9: keychain_iter_start
static int
keychain_iter_start(hx509_context context,
hx509_certs certs, void *data, void **cursor)
{
#ifndef __APPLE_TARGET_EMBEDDED__
struct ks_keychain *ctx = data;
#endif
struct iter *iter;
iter = calloc(1, sizeof(*iter));
if (iter == NULL) {
hx509_set_error_string(context, 0, ENOMEM, "out of memory");
return ENOMEM;
}
#ifndef __APPLE_TARGET_EMBEDDED__
if (ctx->anchors) {
CFArrayRef anchors;
int ret;
int i;
ret = hx509_certs_init(context, "MEMORY:ks-file-create",
0, NULL, &iter->certs);
if (ret) {
free(iter);
return ret;
}
ret = SecTrustCopyAnchorCertificates(&anchors);
if (ret != 0) {
hx509_certs_free(&iter->certs);
free(iter);
hx509_set_error_string(context, 0, ENOMEM,
"Can't get trust anchors from Keychain");
return ENOMEM;
}
for (i = 0; i < CFArrayGetCount(anchors); i++) {
SecCertificateRef cr;
hx509_cert cert;
CFDataRef dataref;
cr = (SecCertificateRef)CFArrayGetValueAtIndex(anchors, i);
dataref = SecCertificateCopyData(cr);
if (dataref == NULL)
continue;
ret = hx509_cert_init_data(context, CFDataGetBytePtr(dataref), CFDataGetLength(dataref), &cert);
CFRelease(dataref);
if (ret)
continue;
ret = hx509_certs_add(context, iter->certs, cert);
hx509_cert_free(cert);
}
CFRelease(anchors);
if (ret != 0) {
hx509_certs_free(&iter->certs);
free(iter);
hx509_set_error_string(context, 0, ret,
"Failed to add cert");
return ret;
}
}
if (iter->certs) {
int ret;
ret = hx509_certs_start_seq(context, iter->certs, &iter->cursor);
if (ret) {
hx509_certs_free(&iter->certs);
free(iter);
return ret;
}
} else
#endif
{
OSStatus ret;
const void *keys[] = {
kSecClass,
kSecReturnRef,
kSecMatchLimit
};
const void *values[] = {
kSecClassCertificate,
kCFBooleanTrue,
kSecMatchLimitAll
};
CFDictionaryRef secQuery;
secQuery = CFDictionaryCreate(NULL, keys, values,
sizeof(keys) / sizeof(*keys),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
ret = SecItemCopyMatching(secQuery, (CFTypeRef *)&iter->search);
CFRelease(secQuery);
if (ret) {
free(iter);
return ENOMEM;
//.........這裏部分代碼省略.........
示例10: createXMLStringFromWebArchiveData
CFStringRef createXMLStringFromWebArchiveData(CFDataRef webArchiveData)
{
CFErrorRef error = 0;
CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
RetainPtr<CFMutableDictionaryRef> propertyList = adoptCF((CFMutableDictionaryRef)CFPropertyListCreateWithData(kCFAllocatorDefault, webArchiveData, kCFPropertyListMutableContainersAndLeaves, &format, &error));
if (!propertyList) {
if (error)
return CFErrorCopyDescription(error);
return static_cast<CFStringRef>(CFRetain(CFSTR("An unknown error occurred converting data to property list.")));
}
RetainPtr<CFMutableArrayRef> resources = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks));
CFArrayAppendValue(resources.get(), propertyList.get());
while (CFArrayGetCount(resources.get())) {
RetainPtr<CFMutableDictionaryRef> resourcePropertyList = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(resources.get(), 0);
CFArrayRemoveValueAtIndex(resources.get(), 0);
CFMutableDictionaryRef mainResource = (CFMutableDictionaryRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebMainResource"));
normalizeWebResourceURL((CFMutableStringRef)CFDictionaryGetValue(mainResource, CFSTR("WebResourceURL")));
convertWebResourceDataToString(mainResource);
// Add subframeArchives to list for processing
CFMutableArrayRef subframeArchives = (CFMutableArrayRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebSubframeArchives")); // WebSubframeArchivesKey in WebArchive.m
if (subframeArchives)
CFArrayAppendArray(resources.get(), subframeArchives, CFRangeMake(0, CFArrayGetCount(subframeArchives)));
CFMutableArrayRef subresources = (CFMutableArrayRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebSubresources")); // WebSubresourcesKey in WebArchive.m
if (!subresources)
continue;
CFIndex subresourcesCount = CFArrayGetCount(subresources);
for (CFIndex i = 0; i < subresourcesCount; ++i) {
CFMutableDictionaryRef subresourcePropertyList = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(subresources, i);
normalizeWebResourceURL((CFMutableStringRef)CFDictionaryGetValue(subresourcePropertyList, CFSTR("WebResourceURL")));
convertWebResourceResponseToDictionary(subresourcePropertyList);
convertWebResourceDataToString(subresourcePropertyList);
}
// Sort the subresources so they're always in a predictable order for the dump
CFArraySortValues(subresources, CFRangeMake(0, CFArrayGetCount(subresources)), compareResourceURLs, 0);
}
error = 0;
RetainPtr<CFDataRef> xmlData = adoptCF(CFPropertyListCreateData(kCFAllocatorDefault, propertyList.get(), kCFPropertyListXMLFormat_v1_0, 0, &error));
if (!xmlData) {
if (error)
return CFErrorCopyDescription(error);
return static_cast<CFStringRef>(CFRetain(CFSTR("An unknown error occurred converting property list to data.")));
}
RetainPtr<CFStringRef> xmlString = adoptCF(CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, xmlData.get(), kCFStringEncodingUTF8));
RetainPtr<CFMutableStringRef> string = adoptCF(CFStringCreateMutableCopy(kCFAllocatorDefault, 0, xmlString.get()));
// Replace "Apple Computer" with "Apple" in the DTD declaration.
CFStringFindAndReplace(string.get(), CFSTR("-//Apple Computer//"), CFSTR("-//Apple//"), CFRangeMake(0, CFStringGetLength(string.get())), 0);
return string.leakRef();
}
示例11: keychain_query
static int
keychain_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 */
//.........這裏部分代碼省略.........
示例12: qtValue
static QVariant qtValue(CFPropertyListRef cfvalue)
{
if (!cfvalue)
return QVariant();
CFTypeID typeId = CFGetTypeID(cfvalue);
/*
Sorted grossly from most to least frequent type.
*/
if (typeId == CFStringGetTypeID()) {
return QSettingsPrivate::stringToVariant(QCFString::toQString(static_cast<CFStringRef>(cfvalue)));
} else if (typeId == CFNumberGetTypeID()) {
CFNumberRef cfnumber = static_cast<CFNumberRef>(cfvalue);
if (CFNumberIsFloatType(cfnumber)) {
double d;
CFNumberGetValue(cfnumber, kCFNumberDoubleType, &d);
return d;
} else {
int i;
qint64 ll;
if (CFNumberGetValue(cfnumber, kCFNumberIntType, &i))
return i;
CFNumberGetValue(cfnumber, kCFNumberLongLongType, &ll);
return ll;
}
} else if (typeId == CFArrayGetTypeID()) {
CFArrayRef cfarray = static_cast<CFArrayRef>(cfvalue);
QList<QVariant> list;
CFIndex size = CFArrayGetCount(cfarray);
bool metNonString = false;
for (CFIndex i = 0; i < size; ++i) {
QVariant value = qtValue(CFArrayGetValueAtIndex(cfarray, i));
if (value.type() != QVariant::String)
metNonString = true;
list << value;
}
if (metNonString)
return list;
else
return QVariant(list).toStringList();
} else if (typeId == CFBooleanGetTypeID()) {
return (bool)CFBooleanGetValue(static_cast<CFBooleanRef>(cfvalue));
} else if (typeId == CFDataGetTypeID()) {
CFDataRef cfdata = static_cast<CFDataRef>(cfvalue);
return QByteArray(reinterpret_cast<const char *>(CFDataGetBytePtr(cfdata)),
CFDataGetLength(cfdata));
} else if (typeId == CFDictionaryGetTypeID()) {
CFDictionaryRef cfdict = static_cast<CFDictionaryRef>(cfvalue);
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 = QCFString::toQString(static_cast<CFStringRef>(keys[i]));
if (CFGetTypeID(values[i]) == arrayTypeId) {
CFArrayRef cfarray = static_cast<CFArrayRef>(values[i]);
CFIndex arraySize = CFArrayGetCount(cfarray);
for (CFIndex j = arraySize - 1; j >= 0; --j)
map.insert(key, qtValue(CFArrayGetValueAtIndex(cfarray, j)));
} else {
map.insert(key, qtValue(values[i]));
}
}
return map;
} else if (typeId == CFDateGetTypeID()) {
QDateTime dt;
dt.setTime_t((uint)kCFAbsoluteTimeIntervalSince1970);
return dt.addSecs((int)CFDateGetAbsoluteTime(static_cast<CFDateRef>(cfvalue)));
}
return QVariant();
}
示例13: GetDataFromPasteboard
// Sorry for the very long code, all nicer OS X APIs are coded in Objective C and not C!
// Also it does very thorough error handling
bool GetDataFromPasteboard( PasteboardRef inPasteboard, char* flavorText /* out */, const int bufSize )
{
OSStatus err = noErr;
PasteboardSyncFlags syncFlags;
ItemCount itemCount;
syncFlags = PasteboardSynchronize( inPasteboard );
//require_action( syncFlags & kPasteboardModified, PasteboardOutOfSync,
// err = badPasteboardSyncErr );
err = PasteboardGetItemCount( inPasteboard, &itemCount );
require_noerr( err, CantGetPasteboardItemCount );
for (UInt32 itemIndex = 1; itemIndex <= itemCount; itemIndex++)
{
PasteboardItemID itemID;
CFArrayRef flavorTypeArray;
CFIndex flavorCount;
err = PasteboardGetItemIdentifier( inPasteboard, itemIndex, &itemID );
require_noerr( err, CantGetPasteboardItemIdentifier );
err = PasteboardCopyItemFlavors( inPasteboard, itemID, &flavorTypeArray );
require_noerr( err, CantCopyPasteboardItemFlavors );
flavorCount = CFArrayGetCount( flavorTypeArray );
for (CFIndex flavorIndex = 0; flavorIndex < flavorCount; flavorIndex++)
{
CFStringRef flavorType;
CFDataRef flavorData;
CFIndex flavorDataSize;
flavorType = (CFStringRef)CFArrayGetValueAtIndex(flavorTypeArray, flavorIndex);
// we're only interested by text...
if (UTTypeConformsTo(flavorType, CFSTR("public.utf8-plain-text")))
{
err = PasteboardCopyItemFlavorData( inPasteboard, itemID,
flavorType, &flavorData );
require_noerr( err, CantCopyFlavorData );
flavorDataSize = CFDataGetLength( flavorData );
flavorDataSize = (flavorDataSize<254) ? flavorDataSize : 254;
if (flavorDataSize+2 > bufSize)
{
fprintf(stderr, "Cannot copy clipboard, contents is too big!\n");
return false;
}
for (short dataIndex = 0; dataIndex <= flavorDataSize; dataIndex++)
{
char byte = *(CFDataGetBytePtr( flavorData ) + dataIndex);
flavorText[dataIndex] = byte;
}
flavorText[flavorDataSize] = '\0';
flavorText[flavorDataSize+1] = '\n';
CFRelease (flavorData);
return true;
}
continue;
CantCopyFlavorData: fprintf(stderr, "Cannot copy clipboard, CantCopyFlavorData!\n");
}
CFRelease (flavorTypeArray);
continue;
CantCopyPasteboardItemFlavors: fprintf(stderr, "Cannot copy clipboard, CantCopyPasteboardItemFlavors!\n"); continue;
CantGetPasteboardItemIdentifier: fprintf(stderr, "Cannot copy clipboard, CantGetPasteboardItemIdentifier!\n"); continue;
}
fprintf(stderr, "Cannot copy clipboard, found no acceptable flavour!\n");
return false;
CantGetPasteboardItemCount: fprintf(stderr, "Cannot copy clipboard, CantGetPasteboardItemCount!\n"); return false;
//PasteboardOutOfSync: fprintf(stderr, "Cannot copy clipboard, PasteboardOutOfSync!\n"); return false;
}
示例14: HIDDumpDeviceInfo
//.........這裏部分代碼省略.........
printf( " productID: 0x%04lX, ", productID );
#else
if ( HIDGetProductNameFromVendorProductID( vendorID, productID, cstring ) ) {
printf( " productID: 0x%04lX (\"%s\"), ", productID, cstring );
} else {
printf( " productID: 0x%04lX, ", productID );
}
#endif
}
uint32_t usagePage = IOHIDDevice_GetUsagePage( inIOHIDDeviceRef );
uint32_t usage = IOHIDDevice_GetUsage( inIOHIDDeviceRef );
if ( !usagePage || !usage ) {
usagePage = IOHIDDevice_GetPrimaryUsagePage( inIOHIDDeviceRef );
usage = IOHIDDevice_GetPrimaryUsage( inIOHIDDeviceRef );
}
printf( "usage: 0x%04lX:0x%04lX, ", (long unsigned int) usagePage, (long unsigned int) usage );
#if 1
tCFStringRef = HIDCopyUsageName( usagePage, usage );
if ( tCFStringRef ) {
verify( CFStringGetCString( tCFStringRef, cstring, sizeof( cstring ), kCFStringEncodingUTF8 ) );
printf( "\"%s\", ", cstring );
CFRelease( tCFStringRef );
}
#endif
#if 1
tCFStringRef = IOHIDDevice_GetTransport( inIOHIDDeviceRef );
if ( tCFStringRef ) {
verify( CFStringGetCString( tCFStringRef, cstring, sizeof( cstring ), kCFStringEncodingUTF8 ) );
printf( "Transport: \"%s\", ", cstring );
}
long vendorIDSource = IOHIDDevice_GetVendorIDSource( inIOHIDDeviceRef );
if ( vendorIDSource ) {
printf( "VendorIDSource: %ld, ", vendorIDSource );
}
long version = IOHIDDevice_GetVersionNumber( inIOHIDDeviceRef );
if ( version ) {
printf( "version: %ld, ", version );
}
tCFStringRef = IOHIDDevice_GetSerialNumber( inIOHIDDeviceRef );
if ( tCFStringRef ) {
verify( CFStringGetCString( tCFStringRef, cstring, sizeof( cstring ), kCFStringEncodingUTF8 ) );
printf( "SerialNumber: \"%s\", ", cstring );
}
long country = IOHIDDevice_GetCountryCode( inIOHIDDeviceRef );
if ( country ) {
printf( "CountryCode: %ld, ", country );
}
long locationID = IOHIDDevice_GetLocationID( inIOHIDDeviceRef );
if ( locationID ) {
printf( "locationID: 0x%08lX, ", locationID );
}
#if 0
CFArrayRef pairs = IOHIDDevice_GetUsagePairs( inIOHIDDeviceRef );
if ( pairs ) {
CFIndex idx, cnt = CFArrayGetCount(pairs);
for ( idx = 0; idx < cnt; idx++ ) {
const void * pair = CFArrayGetValueAtIndex(pairs, idx);
CFShow( pair );
}
}
#endif
long maxInputReportSize = IOHIDDevice_GetMaxInputReportSize( inIOHIDDeviceRef );
if ( maxInputReportSize ) {
printf( "MaxInputReportSize: %ld, ", maxInputReportSize );
}
long maxOutputReportSize = IOHIDDevice_GetMaxOutputReportSize( inIOHIDDeviceRef );
if ( maxOutputReportSize ) {
printf( "MaxOutputReportSize: %ld, ", maxOutputReportSize );
}
long maxFeatureReportSize = IOHIDDevice_GetMaxFeatureReportSize( inIOHIDDeviceRef );
if ( maxFeatureReportSize ) {
printf( "MaxFeatureReportSize: %ld, ", maxOutputReportSize );
}
long reportInterval = IOHIDDevice_GetReportInterval( inIOHIDDeviceRef );
if ( reportInterval ) {
printf( "ReportInterval: %ld, ", reportInterval );
}
IOHIDQueueRef queueRef = IOHIDDevice_GetQueue( inIOHIDDeviceRef );
if ( queueRef ) {
printf( "queue: %p, ", queueRef);
}
IOHIDTransactionRef transactionRef = IOHIDDevice_GetTransaction( inIOHIDDeviceRef );
if ( transactionRef ) {
printf( "transaction: %p, ", transactionRef);
}
#endif
printf( "}\n" );
fflush( stdout );
} // HIDDumpDeviceInfo
示例15: PasteboardCreate
char *osd_get_clipboard_text(void)
{
char *result = NULL; /* core expects a malloced C string of uft8 data */
PasteboardRef pasteboard_ref;
OSStatus err;
PasteboardSyncFlags sync_flags;
PasteboardItemID item_id;
CFIndex flavor_count;
CFArrayRef flavor_type_array;
CFIndex flavor_index;
ItemCount item_count;
UInt32 item_index;
Boolean success = false;
err = PasteboardCreate(kPasteboardClipboard, &pasteboard_ref);
if (!err)
{
sync_flags = PasteboardSynchronize( pasteboard_ref );
err = PasteboardGetItemCount(pasteboard_ref, &item_count );
for (item_index=1; item_index<=item_count; item_index++)
{
err = PasteboardGetItemIdentifier(pasteboard_ref, item_index, &item_id);
if (!err)
{
err = PasteboardCopyItemFlavors(pasteboard_ref, item_id, &flavor_type_array);
if (!err)
{
flavor_count = CFArrayGetCount(flavor_type_array);
for (flavor_index = 0; flavor_index < flavor_count; flavor_index++)
{
CFStringRef flavor_type;
CFDataRef flavor_data;
CFStringEncoding encoding;
CFStringRef string_ref;
CFDataRef data_ref;
CFIndex length;
CFRange range;
flavor_type = (CFStringRef)CFArrayGetValueAtIndex(flavor_type_array, flavor_index);
if (UTTypeConformsTo (flavor_type, kUTTypeUTF16PlainText))
encoding = kCFStringEncodingUTF16;
else if (UTTypeConformsTo (flavor_type, kUTTypeUTF8PlainText))
encoding = kCFStringEncodingUTF8;
else if (UTTypeConformsTo (flavor_type, kUTTypePlainText))
encoding = kCFStringEncodingMacRoman;
else
continue;
err = PasteboardCopyItemFlavorData(pasteboard_ref, item_id, flavor_type, &flavor_data);
if( !err )
{
string_ref = CFStringCreateFromExternalRepresentation (kCFAllocatorDefault, flavor_data, encoding);
data_ref = CFStringCreateExternalRepresentation (kCFAllocatorDefault, string_ref, kCFStringEncodingUTF8, '?');
length = CFDataGetLength (data_ref);
range = CFRangeMake (0,length);
result = (char *)osd_malloc_array (length+1);
if (result != NULL)
{
CFDataGetBytes (data_ref, range, (unsigned char *)result);
result[length] = 0;
success = true;
break;
}
CFRelease(data_ref);
CFRelease(string_ref);
CFRelease(flavor_data);
}
}
CFRelease(flavor_type_array);
}
}
if (success)
break;
}
CFRelease(pasteboard_ref);
}
return result;
}