这篇教程C++ CFDataGetBytePtr函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CFDataGetBytePtr函数的典型用法代码示例。如果您正苦于以下问题:C++ CFDataGetBytePtr函数的具体用法?C++ CFDataGetBytePtr怎么用?C++ CFDataGetBytePtr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CFDataGetBytePtr函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: isom_write_avccbool PrivateDecoderVDA::Init(const QString &decoder, PlayerFlags flags, AVCodecContext *avctx){ if ((decoder != "vda") || (avctx->codec_id != CODEC_ID_H264) || !(flags & kDecodeAllowEXT) || !avctx) return false; m_lib = VDALibrary::GetVDALibrary(); if (!m_lib) return false; uint8_t *extradata = avctx->extradata; int extrasize = avctx->extradata_size; if (!extradata || extrasize < 7) return false; CFDataRef avc_cdata = NULL; if (extradata[0] != 1) { if (extradata[0] == 0 && extradata[1] == 0 && extradata[2] == 0 && extradata[3] == 1) { // video content is from x264 or from bytestream h264 (AnnexB format) // NAL reformating to bitstream format needed AVIOContext *pb; if (avio_open_dyn_buf(&pb) < 0) { return false; } m_annexb = true; isom_write_avcc(pb, extradata, extrasize); // unhook from ffmpeg's extradata extradata = NULL; // extract the avcC atom data into extradata then write it into avcCData for VDADecoder extrasize = avio_close_dyn_buf(pb, &extradata); // CFDataCreate makes a copy of extradata contents avc_cdata = CFDataCreate(kCFAllocatorDefault, (const uint8_t*)extradata, extrasize); // done with the converted extradata, we MUST free using av_free av_free(extradata); } else { LOG(VB_GENERAL, LOG_ERR, LOC + "Invalid avcC atom data"); return false; } } else { if (extradata[4] == 0xFE) { // video content is from so silly encoder that think 3 byte NAL sizes // are valid, setup to convert 3 byte NAL sizes to 4 byte. extradata[4] = 0xFF; m_convert_3byteTo4byteNALSize = true; } // CFDataCreate makes a copy of extradata contents avc_cdata = CFDataCreate(kCFAllocatorDefault, (const uint8_t*)extradata, extrasize); } OSType format = 'avc1'; // check the avcC atom's sps for number of reference frames and // bail if interlaced, VDA does not handle interlaced h264. uint32_t avcc_len = CFDataGetLength(avc_cdata); if (avcc_len < 8) { // avcc atoms with length less than 8 are borked. CFRelease(avc_cdata); return false; } bool interlaced = false; uint8_t *spc = (uint8_t*)CFDataGetBytePtr(avc_cdata) + 6; uint32_t sps_size = VDA_RB16(spc); if (sps_size) { H264Parser *h264_parser = new H264Parser(); h264_parser->parse_SPS(spc+3, sps_size-1, interlaced, m_max_ref_frames); delete h264_parser; } else { m_max_ref_frames = avctx->refs; } if (interlaced) { LOG(VB_GENERAL, LOG_ERR, LOC + "Possible interlaced content. Aborting"); CFRelease(avc_cdata); return false; } if (m_max_ref_frames == 0) { m_max_ref_frames = 2; } if (avctx->profile == FF_PROFILE_H264_MAIN && avctx->level == 32 &&//.........这里部分代码省略.........
开发者ID:stunami,项目名称:mythtv,代码行数:101,
示例2: _ServerCreateAndRegisterNetService/* static */ Boolean_ServerCreateAndRegisterNetService(Server* server) { do { UInt32 port = server->_port; Boolean didSet, didRegister; CFNetServiceClientContext netSvcCtxt = {0, server, (CFAllocatorRetainCallBack)&CFRetain, (CFAllocatorReleaseCallBack)&CFRelease, (CFAllocatorCopyDescriptionCallBack)&CFCopyDescription}; // If the port was unspecified, get the port from the socket. if (port == 0) { // Get the local address CFDataRef addr = CFSocketCopyAddress(server->_sockets[0]); struct sockaddr_in* nativeAddr = (struct sockaddr_in*)CFDataGetBytePtr(addr); CFRelease(addr); port = ntohs(nativeAddr->sin_port); } // Create the service for registration. server->_service = CFNetServiceCreate(CFGetAllocator((_CFServerRef)server), _kCFServerEmptyString, server->_type, server->_name, port); // Require the service for the socket. if (server->_service == NULL) break; // Try setting the client on the service. didSet = CFNetServiceSetClient(server->_service, (CFNetServiceClientCallBack)&_NetServiceCallBack, &netSvcCtxt); // Check to make sure it set before registering. if (!didSet) break; // Schedule the service on the run loop. CFNetServiceScheduleWithRunLoop(server->_service, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); // Start the registration. didRegister = CFNetServiceRegisterWithOptions(server->_service, 0, NULL); // If registration failed, die. if (!didRegister) break; return TRUE; } while (0); // Failed to set up the service, so clean up anything that succeeded. _ServerReleaseNetService(server); return FALSE;}
开发者ID:annp,项目名称:CFNetwork,代码行数:63,
示例3: getActiveModifiersKeyButton COSXKeyState::mapKeyFromEvent(CKeyIDs& ids, KeyModifierMask* maskOut, CGEventRef event) const{ ids.clear(); // map modifier key if (maskOut != NULL) { KeyModifierMask activeMask = getActiveModifiers(); activeMask &= ~KeyModifierAltGr; *maskOut = activeMask; } // get virtual key UInt32 vkCode = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode); // handle up events UInt32 eventKind = CGEventGetType(event); if (eventKind == kCGEventKeyUp) { // the id isn't used. we just need the same button we used on // the key press. note that we don't use or reset the dead key // state; up events should not affect the dead key state. ids.push_back(kKeyNone); return mapVirtualKeyToKeyButton(vkCode); } // check for special keys CVirtualKeyMap::const_iterator i = m_virtualKeyMap.find(vkCode); if (i != m_virtualKeyMap.end()) { m_deadKeyState = 0; ids.push_back(i->second); return mapVirtualKeyToKeyButton(vkCode); } // get keyboard info#if defined(MAC_OS_X_VERSION_10_5) TISInputSourceRef currentKeyboardLayout = TISCopyCurrentKeyboardLayoutInputSource(); #else KeyboardLayoutRef currentKeyboardLayout; OSStatus status = KLGetCurrentKeyboardLayout(¤tKeyboardLayout);#endif if (currentKeyboardLayout == NULL) { return kKeyNone; } // get the event modifiers and remove the command and control // keys. note if we used them though. // UCKeyTranslate expects old-style Carbon modifiers, so convert. UInt32 modifiers; modifiers = mapModifiersToCarbon(CGEventGetFlags(event)); static const UInt32 s_commandModifiers = cmdKey | controlKey | rightControlKey; bool isCommand = ((modifiers & s_commandModifiers) != 0); modifiers &= ~s_commandModifiers; // if we've used a command key then we want the glyph produced without // the option key (i.e. the base glyph). //if (isCommand) { modifiers &= ~optionKey; //} // choose action UInt16 action; if(eventKind==kCGEventKeyDown) { action = kUCKeyActionDown; } else if(CGEventGetIntegerValueField(event, kCGKeyboardEventAutorepeat)==1) { action = kUCKeyActionAutoKey; } else { return 0; } // translate via uchr resource#if defined(MAC_OS_X_VERSION_10_5) CFDataRef ref = (CFDataRef) TISGetInputSourceProperty(currentKeyboardLayout, kTISPropertyUnicodeKeyLayoutData); const UCKeyboardLayout* layout = (const UCKeyboardLayout*) CFDataGetBytePtr(ref); const bool layoutValid = (layout != NULL);#else const void* resource; int err = KLGetKeyboardLayoutProperty(currentKeyboardLayout, kKLuchrData, &resource); const bool layoutValid = (err == noErr); const UCKeyboardLayout* layout = (const UCKeyboardLayout*)resource;#endif if (layoutValid) { // translate key UniCharCount count; UniChar chars[2]; LOG((CLOG_DEBUG2 "modifiers: %08x", modifiers & 0xffu)); OSStatus status = UCKeyTranslate(layout, vkCode & 0xffu, action, (modifiers >> 8) & 0xffu, LMGetKbdType(), 0, &m_deadKeyState, sizeof(chars) / sizeof(chars[0]), &count, chars); // get the characters if (status == 0) {//.........这里部分代码省略.........
开发者ID:CarloWood,项目名称:synergy,代码行数:101,
示例4: RTDECLRTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf){ AssertPtrReturn(pszBuf, VERR_INVALID_POINTER); AssertReturn(cbBuf > 0, VERR_INVALID_PARAMETER); *pszBuf = '/0'; AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER); CFStringRef PropStringRef = NULL; switch (enmString) { case RTSYSDMISTR_PRODUCT_NAME: PropStringRef = CFSTR(PROP_PRODUCT_NAME); break; case RTSYSDMISTR_PRODUCT_VERSION: PropStringRef = CFSTR(PROP_PRODUCT_VERSION); break; case RTSYSDMISTR_PRODUCT_SERIAL: PropStringRef = CFSTR(PROP_PRODUCT_SERIAL); break; case RTSYSDMISTR_PRODUCT_UUID: PropStringRef = CFSTR(PROP_PRODUCT_UUID); break; case RTSYSDMISTR_MANUFACTURER: PropStringRef = CFSTR(PROP_MANUFACTURER); break; default: return VERR_NOT_SUPPORTED; } mach_port_t MasterPort; kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &MasterPort); if (kr != kIOReturnSuccess) { if (kr == KERN_NO_ACCESS) return VERR_ACCESS_DENIED; return RTErrConvertFromDarwinIO(kr); } CFDictionaryRef ClassToMatch = IOServiceMatching(IOCLASS_PLATFORMEXPERTDEVICE); if (!ClassToMatch) return VERR_NOT_SUPPORTED; /* IOServiceGetMatchingServices will always consume ClassToMatch. */ io_iterator_t Iterator; kr = IOServiceGetMatchingServices(MasterPort, ClassToMatch, &Iterator); if (kr != kIOReturnSuccess) return RTErrConvertFromDarwinIO(kr); int rc = VERR_NOT_SUPPORTED; io_service_t ServiceObject; while ((ServiceObject = IOIteratorNext(Iterator))) { if ( enmString == RTSYSDMISTR_PRODUCT_NAME || enmString == RTSYSDMISTR_PRODUCT_VERSION || enmString == RTSYSDMISTR_MANUFACTURER ) { CFDataRef DataRef = (CFDataRef)IORegistryEntryCreateCFProperty(ServiceObject, PropStringRef, kCFAllocatorDefault, kNilOptions); if (DataRef) { size_t cbData = CFDataGetLength(DataRef); const char *pchData = (const char *)CFDataGetBytePtr(DataRef); rc = RTStrCopyEx(pszBuf, cbBuf, pchData, cbData); CFRelease(DataRef); break; } } else { CFStringRef StringRef = (CFStringRef)IORegistryEntryCreateCFProperty(ServiceObject, PropStringRef, kCFAllocatorDefault, kNilOptions); if (StringRef) { Boolean fRc = CFStringGetCString(StringRef, pszBuf, cbBuf, kCFStringEncodingUTF8); if (fRc) rc = VINF_SUCCESS; else { CFIndex cwc = CFStringGetLength(StringRef); size_t cbTmp = cwc + 1; char *pszTmp = (char *)RTMemTmpAlloc(cbTmp); int cTries = 1; while ( pszTmp && (fRc = CFStringGetCString(StringRef, pszTmp, cbTmp, kCFStringEncodingUTF8)) == FALSE && cTries++ < 4) { RTMemTmpFree(pszTmp); cbTmp *= 2; pszTmp = (char *)RTMemTmpAlloc(cbTmp); } if (fRc) rc = RTStrCopy(pszBuf, cbBuf, pszTmp); else if (!pszTmp) rc = VERR_NO_TMP_MEMORY; else rc = VERR_ACCESS_DENIED; RTMemFree(pszTmp); } CFRelease(StringRef); break; } } } IOObjectRelease(ServiceObject); IOObjectRelease(Iterator); return rc;}
开发者ID:jeppeter,项目名称:vbox,代码行数:99,
示例5: GetFormatCountbool wxDataObject::GetFromPasteboard( void * pb ){ PasteboardRef pasteboard = (PasteboardRef) pb; size_t formatcount = GetFormatCount(wxDataObject::Set); wxDataFormat *array = new wxDataFormat[ formatcount ]; GetAllFormats(array, wxDataObject::Set); ItemCount itemCount = 0; wxString filenamesPassed; bool transferred = false; bool pastelocationset = false; // we synchronize here once again, so we don't mind which flags get returned PasteboardSynchronize( pasteboard ); OSStatus err = PasteboardGetItemCount( pasteboard, &itemCount ); if ( err == noErr ) { for (size_t i = 0; !transferred && i < formatcount; i++) { // go through the data in our order of preference wxDataFormat dataFormat = array[ i ]; for( UInt32 itemIndex = 1; itemIndex <= itemCount && transferred == false ; itemIndex++ ) { PasteboardItemID itemID = 0; CFArrayRef flavorTypeArray = NULL; CFIndex flavorCount = 0; err = PasteboardGetItemIdentifier( pasteboard, itemIndex, &itemID ); if ( err != noErr ) continue; err = PasteboardCopyItemFlavors( pasteboard, itemID, &flavorTypeArray ); if ( err != noErr ) continue; flavorCount = CFArrayGetCount( flavorTypeArray ); for( CFIndex flavorIndex = 0; !transferred && flavorIndex < flavorCount ; flavorIndex++ ) { CFStringRef flavorType; CFDataRef flavorData; CFIndex flavorDataSize; flavorType = (CFStringRef)CFArrayGetValueAtIndex( flavorTypeArray, flavorIndex ); wxDataFormat flavorFormat( (wxDataFormat::NativeFormat) flavorType ); if ( dataFormat == flavorFormat ) { if ( UTTypeConformsTo( (CFStringRef)flavorType, kPasteboardTypeFileURLPromise) ) { if ( !pastelocationset ) { wxString tempdir = wxFileName::GetTempDir() + wxFILE_SEP_PATH + "wxtemp.XXXXXX"; char* result = mkdtemp((char*)tempdir.fn_str().data()); if (!result) continue; wxCFRef<CFURLRef> dest(CFURLCreateFromFileSystemRepresentation(NULL,(const UInt8*)result,strlen(result),true)); PasteboardSetPasteLocation(pasteboard, dest); pastelocationset = true; } } else if ( flavorFormat.GetType() != wxDF_PRIVATE ) { // indicate the expected format for the type, benefiting from native conversions eg utf8 -> utf16 flavorType = (CFStringRef) wxDataFormat( flavorFormat.GetType()).GetFormatId(); } err = PasteboardCopyItemFlavorData( pasteboard, itemID, flavorType , &flavorData ); if ( err == noErr ) { flavorDataSize = CFDataGetLength( flavorData ); if (dataFormat.GetType() == wxDF_FILENAME ) { // revert the translation and decomposition to arrive at a proper utf8 string again CFURLRef url = CFURLCreateWithBytes( kCFAllocatorDefault, CFDataGetBytePtr( flavorData ), flavorDataSize, kCFStringEncodingUTF8, NULL ); CFStringRef cfString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle ); CFRelease( url ); CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString); CFRelease( cfString ); CFStringNormalize(cfMutableString,kCFStringNormalizationFormC); wxString path = wxCFStringRef(cfMutableString).AsString(); if (!path.empty()) filenamesPassed += path + wxT("/n"); } else { // because some data implementation expect trailing a trailing NUL, we add some headroom void *buf = malloc( flavorDataSize + 4 ); if ( buf ) { memset( buf, 0, flavorDataSize + 4 ); memcpy( buf, CFDataGetBytePtr( flavorData ), flavorDataSize );//.........这里部分代码省略.........
开发者ID:0ryuO,项目名称:dolphin-avsync,代码行数:101,
示例6: S_setstatic intS_set(mach_port_t server, int argc, char * argv[]){ CFDataRef data = NULL; CFDictionaryRef dict = NULL; const char * method_name; if_name_t if_name; kern_return_t kret; ipconfig_status_t status = ipconfig_status_success_e; void * xml_data_ptr = NULL; int xml_data_len = 0; strlcpy(if_name, argv[0], sizeof(if_name)); method_name = argv[1]; argv += 2; argc -= 2; if (strcasecmp(method_name, "NONE") == 0) { /* nothing to do, NONE implies NULL method data */ } else if (strcasecmp(method_name, "NONE-V6") == 0 || strcasecmp(method_name, "NONE-V4") == 0) { CFDictionaryRef empty_dict; CFStringRef ip_key; /* NONE-V{4,6} is represented as an empty IPv{4,6} dictionary */ empty_dict = CFDictionaryCreate(NULL, NULL, NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (strcasecmp(method_name, "NONE-V6") == 0) { ip_key = kSCEntNetIPv6; } else { ip_key = kSCEntNetIPv4; } dict = CFDictionaryCreate(NULL, (const void * *)&ip_key, (const void * *)&empty_dict, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFRelease(empty_dict); } else { dict = ConfigDictCreate(if_name, argc, argv, command_name, method_name, TRUE); if (dict == NULL) { return (1); } } if (dict != NULL) { data = CFPropertyListCreateData(NULL, dict, kCFPropertyListBinaryFormat_v1_0, 0, NULL); if (data == NULL) { CFRelease(dict); fprintf(stderr, "failed to allocate memory/n"); return (1); } xml_data_ptr = (void *)CFDataGetBytePtr(data); xml_data_len = (int)CFDataGetLength(data); } kret = ipconfig_set(server, if_name, xml_data_ptr, xml_data_len, &status); my_CFRelease(&dict); my_CFRelease(&data); if (kret != KERN_SUCCESS) { mach_error("ipconfig_set failed", kret); return (1); } if (status != ipconfig_status_success_e) { fprintf(stderr, "ipconfig_set %s %s failed: %s/n", if_name, method_name, ipconfig_status_string(status)); return (1); } return (0);}
开发者ID:aosm,项目名称:bootp,代码行数:79,
示例7: _inputStreamAtEOF__private_extern__ Boolean _inputStreamAtEOF(_CFXMLInputStream *stream) { if (!(stream->flags & STREAM_OPEN)) return false; if (stream->currentChar) return false; if (stream->currentByte - CFDataGetBytePtr(stream->data) < CFDataGetLength(stream->data)) return false; return true;}
开发者ID:Apple-FOSS-Mirror,项目名称:CF,代码行数:6,
示例8: determineEncoding/* Utility functions used in parsing */static Boolean determineEncoding(_CFXMLInputStream *stream) { const uint8_t *bytes = (uint8_t *)CFDataGetBytePtr(stream->data); UInt32 length = CFDataGetLength(stream->data); const uint8_t *idx = 0L, *end = 0L; const uint8_t *base = 0L; char quote = ' '; Boolean useUTF8 = false; // Check for the byte order mark first if (length > 2) { // This clause checks for the unicode byte order mark, or a Unicode sequence lacking the BOM; technically an error, but this check is recommended by the XML spec if ((*bytes == 0xFF && *(bytes+1) == 0xFE) ||*(bytes+1) == 0x00) {#if __BIG_ENDIAN__ stream->flags |= ENCODING_IS_UNICODE_SWAPPED;#else stream->flags |= ENCODING_IS_UNICODE_NATURAL;#endif if (*bytes == 0xFF) { stream->currentByte = bytes + 2; } stream->encoding = kCFStringEncodingUnicode; return true; } else if ((*bytes == 0xFE && *(bytes+1) == 0xFF) || *bytes == 0x00) {#if __BIG_ENDIAN__ stream->flags |= ENCODING_IS_UNICODE_NATURAL;#else stream->flags |= ENCODING_IS_UNICODE_SWAPPED;#endif if (*bytes == 0xFE) { stream->currentByte = bytes + 2; } stream->encoding = kCFStringEncodingUnicode; return true; } else if(*bytes == 0xEF && *(bytes+1) == 0xBB && *(bytes+2) == 0xBF) { if(*bytes == 0xEF) { stream->currentByte = bytes + 3; } stream->encoding = kCFStringEncodingUTF8; stream->flags |= ENCODING_MATCHES_ASCII; return true; } } // Scan for the <?xml.... ?> opening if (length < 5 || strncmp((char const *) bytes, "<?xml", 5) != 0) { useUTF8 = true; } if (!useUTF8) { idx = bytes + 5; end = bytes + length; // Found "<?xml"; now we scan for "encoding" while (idx < end) { uint8_t ch = *idx; const uint8_t *scan; if ( ch == '?' || ch == '>') { useUTF8 = true; break; } idx ++; scan = idx; if (ch == 'e' && *scan++ == 'n' && *scan++ == 'c' && *scan++ == 'o' && *scan++ == 'd' && *scan++ == 'i' && *scan++ == 'n' && *scan++ == 'g' && *scan++ == '=') { idx = scan; break; } } if (!useUTF8 && idx >= end) { useUTF8 = true; } } if (!useUTF8) { // Found "encoding="; see if we've got an honest-to-goodness encoding name quote = *idx; if (quote != '/'' && quote != '/"') { useUTF8 = true; } } if (!useUTF8) { base = idx + 1; // Move past the quote character idx ++; while (idx < end && *idx != quote) idx ++; if (idx >= end) { useUTF8 = true; } } if (!useUTF8) { UInt32 len = idx - base; if (len == 5 && (*base == 'u' || *base == 'U') && (base[1] == 't' || base[1] == 'T') && (base[2] == 'f' || base[2] == 'F') && (base[3] == '-') && (base[4] == '8')) { useUTF8 = true; } else { CFStringRef encodingName = CFStringCreateWithBytes(stream->allocator, base, len, kCFStringEncodingISOLatin1, false); stream->encoding = CFStringConvertIANACharSetNameToEncoding(encodingName); CFRelease(encodingName); } } if (useUTF8) { stream->encoding = kCFStringEncodingUTF8; stream->flags |= ENCODING_MATCHES_ASCII; return true; } else if (stream->encoding == kCFStringEncodingInvalidId) { return false;//.........这里部分代码省略.........
开发者ID:Apple-FOSS-Mirror,项目名称:CF,代码行数:101,
示例9: CFDataCreateCopyCFDataRefCFDataCreateCopy (CFAllocatorRef allocator, CFDataRef d){ return CFDataCreate_internal (allocator, CFDataGetBytePtr(d), CFDataGetLength(d), NULL, true);}
开发者ID:Ibadinov,项目名称:gnustep-corebase,代码行数:6,
示例10: createMkext1ForArchCFDataRef createMkext1ForArch(const NXArchInfo * arch, CFArrayRef archiveKexts, boolean_t compress){ CFMutableDataRef result = NULL; CFMutableDictionaryRef kextsByIdentifier = NULL; Mkext1Context context; mkext1_header * mkextHeader = NULL; // do not free const uint8_t * adler_point = 0; CFIndex count, i; result = CFDataCreateMutable(kCFAllocatorDefault, /* capaacity */ 0); if (!result || !createCFMutableDictionary(&kextsByIdentifier)) { OSKextLogMemError(); goto finish; } /* mkext1 can only contain 1 kext for a given bundle identifier, so we * have to pick out the most recent versions. */ count = CFArrayGetCount(archiveKexts); for (i = 0; i < count; i++) { OSKextRef theKext = (OSKextRef)CFArrayGetValueAtIndex(archiveKexts, i); CFStringRef bundleIdentifier = OSKextGetIdentifier(theKext); OSKextRef savedKext = (OSKextRef)CFDictionaryGetValue(kextsByIdentifier, bundleIdentifier); OSKextVersion thisVersion, savedVersion; if (!OSKextSupportsArchitecture(theKext, arch)) { continue; } if (!savedKext) { CFDictionarySetValue(kextsByIdentifier, bundleIdentifier, theKext); continue; } thisVersion = OSKextGetVersion(theKext); savedVersion = OSKextGetVersion(savedKext); if (thisVersion > savedVersion) { CFDictionarySetValue(kextsByIdentifier, bundleIdentifier, theKext); } } /* Add room for the mkext header and kext descriptors. */ CFDataSetLength(result, sizeof(mkext1_header) + CFDictionaryGetCount(kextsByIdentifier) * sizeof(mkext_kext)); context.mkext = result; context.kextIndex = 0; context.compressOffset = (uint32_t)CFDataGetLength(result); context.arch = arch; context.fatal = false; context.compress = compress; CFDictionaryApplyFunction(kextsByIdentifier, addToMkext1, &context); if (context.fatal) { SAFE_RELEASE_NULL(result); goto finish; } mkextHeader = (mkext1_header *)CFDataGetBytePtr(result); mkextHeader->magic = OSSwapHostToBigInt32(MKEXT_MAGIC); mkextHeader->signature = OSSwapHostToBigInt32(MKEXT_SIGN); mkextHeader->version = OSSwapHostToBigInt32(0x01008000); // 'vers' 1.0.0 mkextHeader->numkexts = OSSwapHostToBigInt32(CFDictionaryGetCount(kextsByIdentifier)); mkextHeader->cputype = OSSwapHostToBigInt32(arch->cputype); mkextHeader->cpusubtype = OSSwapHostToBigInt32(arch->cpusubtype); mkextHeader->length = OSSwapHostToBigInt32(CFDataGetLength(result)); adler_point = (UInt8 *)&mkextHeader->version; mkextHeader->adler32 = OSSwapHostToBigInt32(local_adler32( (UInt8 *)&mkextHeader->version, (int)(CFDataGetLength(result) - (adler_point - (uint8_t *)mkextHeader)))); OSKextLog(/* kext */ NULL, kOSKextLogProgressLevel | kOSKextLogArchiveFlag, "Created mkext for %s containing %lu kexts.", arch->name, CFDictionaryGetCount(kextsByIdentifier));finish: SAFE_RELEASE(kextsByIdentifier); return result;}
开发者ID:Annovae,项目名称:kext_tools,代码行数:86,
示例11: keychain_iter_startstatic intkeychain_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;//.........这里部分代码省略.........
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:101,
示例12: 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,
示例13: RunAppOnDeviceWithIdentifiervoid RunAppOnDeviceWithIdentifier(char *udid, char *identifier, bool waitForDebugger){ SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid); if (device) { sdmmd_return_t result = SDMMD_AMDeviceConnect(device); if (SDM_MD_CallSuccessful(result)) { result = SDMMD_AMDeviceStartSession(device); if (SDM_MD_CallSuccessful(result)) { CFDictionaryRef response; CFArrayRef lookupValues = SDMMD_ApplicationLookupDictionary(); CFMutableDictionaryRef optionsDict = SDMMD_create_dict(); CFDictionarySetValue(optionsDict, CFSTR("ReturnAttributes"), lookupValues); result = SDMMD_AMDeviceLookupApplications(device, optionsDict, &response); if (SDM_MD_CallSuccessful(result)) { CFStringRef bundleIdentifier = CFStringCreateWithCString(kCFAllocatorDefault, identifier, kCFStringEncodingUTF8); CFDictionaryRef details = NULL; if (CFDictionaryContainsKey(response, bundleIdentifier)) { details = CFDictionaryGetValue(response, bundleIdentifier); } CFSafeRelease(bundleIdentifier); if (details) { SDMMD_AMDeviceStopSession(device); SDMMD_AMDeviceDisconnect(device); SDMMD_AMDebugConnectionRef dconn = SDMMD_AMDebugConnectionCreateForDevice(device); sdmmd_return_t result = SDMMD_AMDebugConnectionStart(dconn); bool launchSuccess = false; if (SDM_MD_CallSuccessful(result)) { // setting max packet size CFMutableArrayRef maxPacketArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks); CFArrayAppendValue(maxPacketArgs, CFSTR("1024")); DebuggerCommandRef maxPacket = SDMMD_CreateDebuggingCommand(kDebugQSetMaxPacketSize, NULL, maxPacketArgs); CFSafeRelease(maxPacketArgs); CFDataRef maxPacketResponse = NULL; result = SDMMD_DebuggingSend(dconn, maxPacket, &maxPacketResponse); CFSafeRelease(maxPacketResponse); SDMMD_DebuggingCommandRelease(maxPacket); // setting the working directory CFStringRef path = CFDictionaryGetValue(details, CFSTR("Path")); CFStringRef container = CFDictionaryGetValue(details, CFSTR("Container")); if (!container) { CFURLRef pathURL = CFURLCreateWithString(kCFAllocatorDefault, path, NULL); CFURLRef containerURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, pathURL); container = CFURLGetString(containerURL); CFSafeRelease(pathURL); } CFMutableArrayRef containerPathArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks); CFArrayAppendValue(containerPathArgs, container); DebuggerCommandRef containerPath = SDMMD_CreateDebuggingCommand(kDebugQSetWorkingDir, NULL, containerPathArgs); CFSafeRelease(containerPathArgs); CFDataRef containerPathResponse = NULL; result = SDMMD_DebuggingSend(dconn, containerPath, &containerPathResponse); CFSafeRelease(containerPathResponse); SDMMD_DebuggingCommandRelease(containerPath); // setting launch args CFStringRef commandFormat = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("A%d,0,"), (uint32_t)CFStringGetLength(path) * 0x2); CFMutableArrayRef setLaunchArgsArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks); CFArrayAppendValue(setLaunchArgsArgs, path); DebuggerCommandRef setLaunchArgs = SDMMD_CreateDebuggingCommand(kDebugCUSTOMCOMMAND, commandFormat, setLaunchArgsArgs); CFSafeRelease(setLaunchArgsArgs); CFSafeRelease(commandFormat); CFDataRef setLaunchArgsResponse = NULL; result = SDMMD_DebuggingSend(dconn, setLaunchArgs, &setLaunchArgsResponse); CFSafeRelease(setLaunchArgsResponse); SDMMD_DebuggingCommandRelease(setLaunchArgs); // Check for launch success CFMutableArrayRef launchSuccessArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks); DebuggerCommandRef launchSuccessCommand = SDMMD_CreateDebuggingCommand(kDebugqLaunchSuccess, NULL, launchSuccessArgs); CFSafeRelease(launchSuccessArgs); CFDataRef launchSuccessResponse = NULL; result = SDMMD_DebuggingSend(dconn, launchSuccessCommand, &launchSuccessResponse); if (launchSuccessResponse) { char *launchSuccessResponseAsString = (char *)CFDataGetBytePtr(launchSuccessResponse); launchSuccess = !strncmp(launchSuccessResponseAsString, "OK", 2); if (!launchSuccess) { printf("Launch failure: %s/n", launchSuccessResponseAsString); } } CFSafeRelease(launchSuccessResponse); SDMMD_DebuggingCommandRelease(launchSuccessCommand); if (launchSuccess) { printf("Launch success/n"); if (!waitForDebugger) { printf("Continuing with execution.../n"); // setting thread to attach//.........这里部分代码省略.........
开发者ID:K0smas,项目名称:SDMMobileDevice,代码行数:101,
示例14: ct_font_descriptor_get_coveragestatic PangoCoverage *ct_font_descriptor_get_coverage (CTFontDescriptorRef desc){ CFCharacterSetRef charset; CFIndex i, length; CFDataRef bitmap; const UInt8 *ptr, *plane_ptr; const UInt32 plane_size = 8192; PangoCoverage *coverage; coverage = pango_coverage_new (); charset = CTFontDescriptorCopyAttribute (desc, kCTFontCharacterSetAttribute); if (!charset) /* Return an empty coverage */ return coverage; bitmap = CFCharacterSetCreateBitmapRepresentation (kCFAllocatorDefault, charset); ptr = CFDataGetBytePtr (bitmap); /* First handle the BMP plane. */ length = MIN (CFDataGetLength (bitmap), plane_size); /* FIXME: can and should this be done more efficiently? */ for (i = 0; i < length; i++) { int j; for (j = 0; j < 8; j++) if ((ptr[i] & (1 << j)) == (1 << j)) pango_coverage_set (coverage, i * 8 + j, PANGO_COVERAGE_EXACT); } /* Next, handle the other planes. The plane number is encoded first as * a single byte. In the following 8192 bytes that plane's coverage bitmap * is stored. */ plane_ptr = ptr + plane_size; while (plane_ptr - ptr < CFDataGetLength (bitmap)) { const UInt8 plane_number = *plane_ptr; plane_ptr++; for (i = 0; i < plane_size; i++) { int j; for (j = 0; j < 8; j++) if ((plane_ptr[i] & (1 << j)) == (1 << j)) pango_coverage_set (coverage, (plane_number * plane_size + i) * 8 + j, PANGO_COVERAGE_EXACT); } plane_ptr += plane_size; } CFRelease (bitmap); CFRelease (charset); return coverage;}
开发者ID:ImageMagick,项目名称:pango,代码行数:62,
示例15: _inputStreamReturnCharacter__private_extern__ Boolean _inputStreamReturnCharacter(_CFXMLInputStream *stream, UniChar ch) { Boolean decrementLineNum = false; if (ch == '/n') { decrementLineNum = true; } else if (ch == '/r') { UniChar nextChar; if (!_inputStreamPeekCharacter(stream, &nextChar) || nextChar != '/n') { decrementLineNum = true; } } if (!(stream->flags & STREAM_OPEN)) { return false; } else if (stream->currentChar) { if (stream->currentChar != stream->charBuffer) { stream->currentChar --; } else { // Yuck; we're unlucky and are returning a character _before_ the first character in charBuffer if (stream->bufferLength >= stream->bufferCapacity) { growCharacterBuffer(stream); } memmove(stream->charBuffer + 1, stream->charBuffer, stream->bufferLength * sizeof(UniChar)); *stream->charBuffer = ch; stream->bufferLength ++; if (stream->mark) { stream->mark ++; } if (stream->parserMark) { stream->parserMark ++; } } } else if ((stream->mark || stream->parserMark) && stream->bufferLength) { // We've been collecting characters in charBuffer; the only reason stream->currentChar is NULL is that we've processed the last character thusfar translated from data. That last character is the one being returned. stream->currentChar = stream->charBuffer + stream->bufferLength - 1; } else if (stream->charBuffer) { // We have processed all the meaningful characters from charBuffer and have no reason to preserve them. We use charBuffer to hold this one character that has been returned to us. *stream->charBuffer = ch; stream->currentChar = stream->charBuffer; stream->bufferLength = 1; if (stream->mark) { stream->mark ++; } if (stream->parserMark) { stream->parserMark ++; } } else if (stream->currentByte > CFDataGetBytePtr(stream->data)) { // We have no character buffer available, so that means one of two things - either we've never needed a character buffer because all the characters could come directly out of the byte stream, or we've not yet processed the first character. The former means we can just back up the byte pointer; the latter means Bad Things have happened. if (stream->flags & ENCODING_MATCHES_ASCII) { stream->currentByte --; } else { // Must be Unicode stream->currentByte -= 2; } } else { return false; } stream->charIndex --; if (decrementLineNum) { stream->lineNum --; } return true;}
开发者ID:Apple-FOSS-Mirror,项目名称:CF,代码行数:61,
示例16: S_bsdp_optionstatic intS_bsdp_option(mach_port_t server, int argc, char * argv[]){ CFDictionaryRef chosen = NULL; void * data = NULL; int data_len; struct dhcp * dhcp; int length; dhcpol_t options; CFDataRef response = NULL; int ret = 1; int tag = 0; dhcpol_t vendor_options; int vendor_tag = 0; if (getuid() != 0) { return (EX_NOPERM); } chosen = myIORegistryEntryCopyValue("IODeviceTree:/chosen"); if (chosen == NULL) { goto done; } response = CFDictionaryGetValue(chosen, CFSTR("bsdp-response")); if (isA_CFData(response) == NULL) { response = CFDictionaryGetValue(chosen, CFSTR("bootp-response")); if (isA_CFData(response) == NULL) { goto done; } } /* ALIGN: CFDataGetBytePtr is aligned to at least sizeof(uint64) */ dhcp = (struct dhcp *)(void *)CFDataGetBytePtr(response); length = (int)CFDataGetLength(response); if (dhcpol_parse_packet(&options, dhcp, length, NULL) == FALSE) { goto done; } if (strcmp(argv[0], SHADOW_MOUNT_PATH_COMMAND) == 0) { tag = dhcptag_vendor_specific_e; vendor_tag = bsdptag_shadow_mount_path_e; } else if (strcmp(argv[0], SHADOW_FILE_PATH_COMMAND) == 0) { tag = dhcptag_vendor_specific_e; vendor_tag = bsdptag_shadow_file_path_e; } else if (strcmp(argv[0], MACHINE_NAME_COMMAND) == 0) { tag = dhcptag_vendor_specific_e; vendor_tag = bsdptag_machine_name_e; } else { tag = atoi(argv[0]); if (argc == 2) { vendor_tag = atoi(argv[1]); } } if (tag == dhcptag_vendor_specific_e && vendor_tag != 0) { if (dhcpol_parse_vendor(&vendor_options, &options, NULL) == FALSE) { goto done; } data = dhcpol_option_copy(&vendor_options, vendor_tag, &data_len); if (data != NULL) { dhcptype_print(bsdptag_type(vendor_tag), data, data_len); ret = 0; } dhcpol_free(&vendor_options); } else { const dhcptag_info_t * entry; entry = dhcptag_info(tag); if (entry == NULL) { goto done; } data = dhcpol_option_copy(&options, tag, &data_len); if (data != NULL) { dhcptype_print(entry->type, data, data_len); ret = 0; } } done: if (data != NULL) { free(data); } if (chosen != NULL) { CFRelease(chosen); } return (ret);}
开发者ID:aosm,项目名称:bootp,代码行数:88,
示例17: TISCopyCurrentKeyboardLayoutInputSourceOP_STATUS UKeyTranslate::GetUnicharFromVirtualKey(UInt32 virtualKeyCode, uni_char &outUniChar, UInt8 modifierKeyState){#ifdef SIXTY_FOUR_BIT UInt32 deadKeyState = 0; OP_STATUS result = OpStatus::ERR; TISInputSourceRef kbInputSourceRef = TISCopyCurrentKeyboardLayoutInputSource(); CFDataRef uchrDataRef = (CFDataRef)TISGetInputSourceProperty(kbInputSourceRef, kTISPropertyUnicodeKeyLayoutData); Boolean existsUchr = ((uchrDataRef != NULL) && (CFDataGetBytePtr(uchrDataRef) != NULL) && (CFDataGetLength(uchrDataRef) != 0)); if (existsUchr) { UniCharCount actualLength = 0; UniChar outChar[2] = {0,0}; OSStatus status = UCKeyTranslate((const UCKeyboardLayout *)CFDataGetBytePtr(uchrDataRef), virtualKeyCode, kUCKeyActionDown, modifierKeyState, LMGetKbdType(), kNilOptions, &deadKeyState, 2, &actualLength, outChar); if (status == noErr && actualLength && outChar[0] != kFunctionKeyCharCode) { outUniChar = outChar[0]; result = OpStatus::OK; } } CFRelease(kbInputSourceRef); return result;#else // !SIXTY_FOUR_BIT static KeyboardLayoutRef lastKbdLayout = 0; static const UCKeyboardLayout* ucharData = NULL; static const void* charData = NULL; KeyboardLayoutRef currentKbdLayout = 0; if (noErr != KLGetCurrentKeyboardLayout(¤tKbdLayout) || !currentKbdLayout) { return OpStatus::ERR; } short keyCode; OSStatus error = noErr; UInt32 deadKeyState = 0; OP_STATUS result = OpStatus::ERR; keyCode = virtualKeyCode; if (!ucharData || (currentKbdLayout != lastKbdLayout)) { // Don't fetch this unless we have to: Because of the KeyScript issue handled below this may in some cases return 0 // KeyScript is an EXPENSIVE call, so by caching ucharData as long as possible we minimise the number of times // we need to call it. error = KLGetKeyboardLayoutProperty(currentKbdLayout, kKLuchrData, (const void**)&ucharData); } if (!ucharData) { static Boolean try_again = true; if (try_again && (smRoman == GetScriptManagerVariable(smKeyScript))) { // This is required for roman scripts in order to get something from KLGetCurrentKeyboardLayout KeyScript(smRoman | smKeyForceKeyScriptMask); error = KLGetKeyboardLayoutProperty(currentKbdLayout, kKLuchrData, (const void**)&ucharData); if (error || !ucharData) try_again = false; } } if ((error == noErr) && (ucharData != 0)) { UniCharCount actualLength = 0; UniChar outChar[2] = {0,0}; charData = NULL; error = UCKeyTranslate(ucharData, (unsigned short)keyCode, kUCKeyActionDown, modifierKeyState, LMGetKbdType(), 0, &deadKeyState, 2, &actualLength, outChar); if (error == noErr && actualLength && outChar[0] != kFunctionKeyCharCode) { outUniChar = outChar[0]; result = OpStatus::OK;#ifdef DEBUG_UNI_KEYSTROKES// if (outUniChar & 0xff00)// fprintf(stderr, "UKC:%x/n", outChar[0]);#endif }#ifdef DEBUG_UNI_KEYSTROKES else { fprintf(stderr, "UKCe:%li-%x-%lu-%x/n", error, outChar[0], virtualKeyCode, modifierKeyState); } if (actualLength != 1) fprintf(stderr, "UKCl:%lu-%x-%x-%lu-%x/n", actualLength, outChar[0], outChar[1], virtualKeyCode, modifierKeyState);#endif } else {#ifdef DEBUG_UNI_KEYSTROKES fprintf(stderr, "KLP:%li/n", error);#endif error = noErr; if (!charData || (currentKbdLayout != lastKbdLayout)) { error = KLGetKeyboardLayoutProperty(currentKbdLayout, kKLKCHRData, &charData); }//.........这里部分代码省略.........
开发者ID:prestocore,项目名称:browser,代码行数:101,
示例18: S_add_or_set_servicestatic intS_add_or_set_service(mach_port_t server, int argc, char * argv[], bool add){ CFDataRef data = NULL; CFDictionaryRef dict; char * method_name; if_name_t if_name; kern_return_t kret; inline_data_t service_id; unsigned int service_id_len; ipconfig_status_t status = ipconfig_status_success_e; void * xml_data_ptr = NULL; int xml_data_len = 0; strlcpy(if_name, argv[0], sizeof(if_name)); method_name = argv[1]; argv += 2; argc -= 2; dict = ConfigDictCreate(if_name, argc, argv, command_name, method_name, FALSE); if (dict == NULL) { return (1); } data = CFPropertyListCreateData(NULL, dict, kCFPropertyListBinaryFormat_v1_0, 0, NULL); if (data == NULL) { CFRelease(dict); fprintf(stderr, "failed to allocate memory/n"); return (1); } xml_data_ptr = (void *)CFDataGetBytePtr(data); xml_data_len = (int)CFDataGetLength(data); if (add) { kret = ipconfig_add_service(server, if_name, xml_data_ptr, xml_data_len, service_id, &service_id_len, &status); } else { kret = ipconfig_set_service(server, if_name, xml_data_ptr, xml_data_len, service_id, &service_id_len, &status); } CFRelease(dict); CFRelease(data); if (kret != KERN_SUCCESS) { fprintf(stderr, "ipconfig_%s_service failed, %s/n", add ? "add" : "set", mach_error_string(kret)); return (1); } if (status != ipconfig_status_success_e) { fprintf(stderr, "ipconfig_%s_service %s %s failed: %s/n", add ? "add" : "set", if_name, method_name, ipconfig_status_string(status)); return (1); } printf("%.*s/n", service_id_len, service_id); return (0);}
开发者ID:aosm,项目名称:bootp,代码行数:61,
示例19: sendMessagesstatic void sendMessages(int howMany, SecOTRSessionRef *bobSession, SecOTRSessionRef *aliceSession, bool serialize){ for(int count = howMany; count > 0; --count) { const char* aliceToBob = "aliceToBob"; CFDataRef rawAliceToBob = CFDataCreate(kCFAllocatorDefault, (const uint8_t*)aliceToBob, (CFIndex) strlen(aliceToBob)); CFMutableDataRef protectedAliceToBob = CFDataCreateMutable(kCFAllocatorDefault, 0); CFMutableDataRef bobDecode = CFDataCreateMutable(kCFAllocatorDefault, 0); ok_status(SecOTRSSignAndProtectMessage(*aliceSession, rawAliceToBob, protectedAliceToBob), "encode message"); ok_status(SecOTRSVerifyAndExposeMessage(*bobSession, protectedAliceToBob, bobDecode), "Decode message"); if (serialize) { serializeAndDeserialize(bobSession); serializeAndDeserialize(aliceSession); } ok(CFDataGetLength(rawAliceToBob) == CFDataGetLength(bobDecode) && 0 == memcmp(CFDataGetBytePtr(rawAliceToBob), CFDataGetBytePtr(bobDecode), (size_t)CFDataGetLength(rawAliceToBob)), "Didn't match!"); CFReleaseNull(rawAliceToBob); CFReleaseNull(protectedAliceToBob); CFReleaseNull(bobDecode); const char* bobToAlice = "i liked your silly message from me to you"; CFDataRef rawBobToAlice = CFDataCreate(kCFAllocatorDefault, (const uint8_t*)bobToAlice, (CFIndex) strlen(bobToAlice)); CFMutableDataRef protectedBobToAlice = CFDataCreateMutable(kCFAllocatorDefault, 0); CFMutableDataRef aliceDecode = CFDataCreateMutable(kCFAllocatorDefault, 0); ok_status(SecOTRSSignAndProtectMessage(*aliceSession, rawBobToAlice, protectedBobToAlice), "encode reply"); ok_status(SecOTRSVerifyAndExposeMessage(*bobSession, protectedBobToAlice, aliceDecode), "decode reply"); if (serialize) { serializeAndDeserialize(bobSession); serializeAndDeserialize(aliceSession); } ok(CFDataGetLength(rawBobToAlice) == CFDataGetLength(aliceDecode) && 0 == memcmp(CFDataGetBytePtr(rawBobToAlice), CFDataGetBytePtr(aliceDecode), (size_t)CFDataGetLength(rawBobToAlice)), "reply matched"); CFReleaseNull(rawAliceToBob); CFReleaseNull(rawBobToAlice); CFReleaseNull(protectedBobToAlice); CFReleaseNull(protectedAliceToBob); CFReleaseNull(aliceDecode); rawAliceToBob = CFDataCreate(kCFAllocatorDefault, (const uint8_t*)aliceToBob, (CFIndex) strlen(aliceToBob)); protectedAliceToBob = CFDataCreateMutable(kCFAllocatorDefault, 0); bobDecode = CFDataCreateMutable(kCFAllocatorDefault, 0); ok_status(SecOTRSSignAndProtectMessage(*aliceSession, rawAliceToBob, protectedAliceToBob), "encode message"); ok_status(SecOTRSVerifyAndExposeMessage(*bobSession, protectedAliceToBob, bobDecode), "Decode message"); if (serialize) { serializeAndDeserialize(bobSession); serializeAndDeserialize(aliceSession); } ok(CFDataGetLength(rawAliceToBob) == CFDataGetLength(bobDecode) && 0 == memcmp(CFDataGetBytePtr(rawAliceToBob), CFDataGetBytePtr(bobDecode), (size_t)CFDataGetLength(rawAliceToBob)), "Didn't match!"); CFReleaseNull(rawAliceToBob); CFReleaseNull(protectedAliceToBob); CFReleaseNull(bobDecode); bobToAlice = "i liked your silly message from me to you"; rawBobToAlice = CFDataCreate(kCFAllocatorDefault, (const uint8_t*)bobToAlice, (CFIndex) strlen(bobToAlice)); protectedBobToAlice = CFDataCreateMutable(kCFAllocatorDefault, 0); aliceDecode = CFDataCreateMutable(kCFAllocatorDefault, 0); ok_status(SecOTRSSignAndProtectMessage(*aliceSession, rawBobToAlice, protectedBobToAlice), "encode reply"); ok_status(SecOTRSVerifyAndExposeMessage(*bobSession, protectedBobToAlice, aliceDecode), "decode reply"); if (serialize) { serializeAndDeserialize(bobSession); serializeAndDeserialize(aliceSession); } ok(CFDataGetLength(rawBobToAlice) == CFDataGetLength(aliceDecode) && 0 == memcmp(CFDataGetBytePtr(rawBobToAlice), CFDataGetBytePtr(aliceDecode), (size_t)CFDataGetLength(rawBobToAlice)), "reply matched"); CFReleaseNull(rawAliceToBob); CFReleaseNull(rawBobToAlice); CFReleaseNull(protectedBobToAlice); CFReleaseNull(protectedAliceToBob); CFReleaseNull(aliceDecode); CFStringRef stateString = CFCopyDescription(*bobSession); ok(stateString, "getting state from bob"); CFReleaseNull(stateString); stateString = CFCopyDescription(*aliceSession); ok(stateString, "getting state from alice"); CFReleaseNull(stateString); }}
开发者ID:darlinghq,项目名称:darling-security,代码行数:98,
示例20: QVariantQVariantQMacPasteboard::retrieveData(const QString &format, QVariant::Type) const{ if (!paste) return QVariant(); sync(); ItemCount cnt = 0; if(PasteboardGetItemCount(paste, &cnt) || !cnt) return QByteArray();#ifdef DEBUG_PASTEBOARD qDebug("Pasteboard: retrieveData [%s]", qPrintable(format));#endif const QList<QMacPasteboardMime *> mimes = QMacPasteboardMime::all(mime_type); for(int mime = 0; mime < mimes.size(); ++mime) { QMacPasteboardMime *c = mimes.at(mime); QString c_flavor = c->flavorFor(format); if(!c_flavor.isEmpty()) { // Handle text/plain a little differently. Try handling Unicode first. bool checkForUtf16 = (c_flavor == QLatin1String("com.apple.traditional-mac-plain-text") || c_flavor == QLatin1String("public.utf8-plain-text")); if (checkForUtf16 || c_flavor == QLatin1String("public.utf16-plain-text")) { // Try to get the NSStringPboardType from NSPasteboard, newlines are mapped // correctly (as '/n') in this data. The 'public.utf16-plain-text' type // usually maps newlines to '/r' instead. QString str = qt_mac_get_pasteboardString(paste); if (!str.isEmpty()) return str; } if (checkForUtf16 && hasFlavor(QLatin1String("public.utf16-plain-text"))) c_flavor = QLatin1String("public.utf16-plain-text"); QVariant ret; QList<QByteArray> retList; for(uint index = 1; index <= cnt; ++index) { PasteboardItemID id; if(PasteboardGetItemIdentifier(paste, index, &id) != noErr) continue; QCFType<CFArrayRef> types; if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr) continue; const int type_count = CFArrayGetCount(types); for(int i = 0; i < type_count; ++i) { CFStringRef flavor = static_cast<CFStringRef>(CFArrayGetValueAtIndex(types, i)); if(c_flavor == QCFString::toQString(flavor)) { QCFType<CFDataRef> macBuffer; if(PasteboardCopyItemFlavorData(paste, id, flavor, &macBuffer) == noErr) { QByteArray buffer((const char *)CFDataGetBytePtr(macBuffer), CFDataGetLength(macBuffer)); if(!buffer.isEmpty()) {#ifdef DEBUG_PASTEBOARD qDebug(" - %s [%s] (%s)", qPrintable(format), qPrintable(QCFString::toQString(flavor)), qPrintable(c->convertorName()));#endif buffer.detach(); //detach since we release the macBuffer retList.append(buffer); break; //skip to next element } } } else {#ifdef DEBUG_PASTEBOARD qDebug(" - NoMatch %s [%s] (%s)", qPrintable(c_flavor), qPrintable(QCFString::toQString(flavor)), qPrintable(c->convertorName()));#endif } } } if (!retList.isEmpty()) { ret = c->convertToMime(format, retList, c_flavor); return ret; } } } return QVariant();}
开发者ID:jbartolozzi,项目名称:CIS462_HW1,代码行数:77,
示例21: _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,
示例22: qtValuestatic 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 (CFNumberGetType(cfnumber) == kCFNumberIntType) { 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();}
开发者ID:tanaxiusi,项目名称:Qt5.7.0-my-modified-version,代码行数:79,
示例23: StartDebuggingAndDetachvoid StartDebuggingAndDetach(char *udid, char *app_path) { SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid); if (device) { CFStringRef bundleId = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8 *)app_path, strlen(app_path), kCFStringEncodingUTF8, false); CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, bundleId, kCFURLPOSIXPathStyle, false); CFURLRef disk_app_url = CFURLCopyAbsoluteURL(relative_url); CFStringRef bundle_identifier = copy_disk_app_identifier(disk_app_url); SDMMD_AMDebugConnectionRef debug = SDMMD_AMDebugConnectionCreateForDevice(device); SDMMD_AMDebugConnectionStart(debug); uintptr_t socket = SDMMD_AMDServiceConnectionGetSocket(debug->connection); CFSocketContext context = { 0, (void*)socket, NULL, NULL, NULL }; CFSocketRef fdvendor = CFSocketCreate(NULL, AF_UNIX, 0, 0, kCFSocketAcceptCallBack, &socket_callback, &context); int yes = 1; setsockopt(CFSocketGetNative(fdvendor), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); struct sockaddr_un address; memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; strcpy(address.sun_path, SDM_LLDB_SOCKET); address.sun_len = SUN_LEN(&address); CFDataRef address_data = CFDataCreate(NULL, (const UInt8 *)&address, sizeof(address)); unlink(SDM_LLDB_SOCKET); CFSocketSetAddress(fdvendor, address_data); CFRelease(address_data); CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, fdvendor, 0), kCFRunLoopCommonModes); SDMMD_AMDeviceRef device = SDMMD_AMDServiceConnectionGetDevice(debug->connection); CFMutableStringRef cmds = CFStringCreateMutableCopy(NULL, 0, LLDB_PREP_CMDS); CFRange range = { 0, CFStringGetLength(cmds) }; CFURLRef device_app_url = copy_device_app_url(device, bundle_identifier); CFStringRef device_app_path = CFURLCopyFileSystemPath(device_app_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{DEVICE_PATH}"), device_app_path, range, 0); range.length = CFStringGetLength(cmds); CFStringRef disk_app_path = CFURLCopyFileSystemPath(disk_app_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{APP_PATH}"), disk_app_path, range, 0); range.length = CFStringGetLength(cmds); CFURLRef device_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, device_app_url); CFStringRef device_container_path = CFURLCopyFileSystemPath(device_container_url, kCFURLPOSIXPathStyle); CFMutableStringRef dcp_noprivate = CFStringCreateMutableCopy(NULL, 0, device_container_path); range.length = CFStringGetLength(dcp_noprivate); CFStringFindAndReplace(dcp_noprivate, CFSTR("/private/var/"), CFSTR("/var/"), range, 0); range.length = CFStringGetLength(cmds); CFStringFindAndReplace(cmds, CFSTR("{device_container}"), dcp_noprivate, range, 0); range.length = CFStringGetLength(cmds); CFURLRef disk_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, disk_app_url); CFStringRef disk_container_path = CFURLCopyFileSystemPath(disk_container_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{disk_container}"), disk_container_path, range, 0); CFDataRef cmds_data = CFStringCreateExternalRepresentation(NULL, cmds, kCFStringEncodingASCII, 0); FILE *out = fopen(PREP_CMDS_PATH, "w"); fwrite(CFDataGetBytePtr(cmds_data), CFDataGetLength(cmds_data), 1, out); fclose(out); CFSafeRelease(cmds); CFSafeRelease(bundle_identifier); CFSafeRelease(device_app_url); CFSafeRelease(device_app_path); CFSafeRelease(disk_app_path); CFSafeRelease(device_container_url); CFSafeRelease(device_container_path); CFSafeRelease(dcp_noprivate); CFSafeRelease(disk_container_url); CFSafeRelease(disk_container_path); CFSafeRelease(cmds_data); signal(SIGHUP, exit); pid_t parent = getpid(); int pid = fork(); if (pid == 0) { system("xcrun -sdk iphoneos lldb /tmp/sdmmd-lldb-prep"); kill(parent, SIGHUP); _exit(0); } CFRunLoopRun(); }}
开发者ID:bigfei,项目名称:SDMMobileDevice,代码行数:88,
示例24: _CFServerStart/* extern */ Boolean_CFServerStart(_CFServerRef server, CFStringRef name, CFStringRef type, UInt32 port) { Server* s = (Server*)server; CFDataRef address = NULL; do { unsigned i; CFRunLoopRef rl = CFRunLoopGetCurrent(); CFAllocatorRef alloc = CFGetAllocator(server); struct sockaddr_in addr4; struct sockaddr_in6 addr6; // Make sure the port is valid (0 - 65535). if ((port & 0xFFFF0000U) != 0) break; // NULL means to use the machine name. if (name == NULL) name = _kCFServerEmptyString; for (i = 0; i < (sizeof(s->_sockets) / sizeof(s->_sockets[0])); i++) { // Create the run loop source for putting on the run loop. CFRunLoopSourceRef src = CFSocketCreateRunLoopSource(alloc, s->_sockets[i], 0); if (src == NULL) break; // Add the run loop source to the current run loop and default mode. CFRunLoopAddSource(rl, src, kCFRunLoopCommonModes); CFRelease(src); } memset(&addr4, 0, sizeof(addr4)); // Put the local port and address into the native address.#if !defined(__WIN32__) addr4.sin_len = sizeof(addr4);#endif addr4.sin_family = AF_INET; addr4.sin_port = htons((UInt16)port); addr4.sin_addr.s_addr = htonl(INADDR_ANY); // Wrap the native address structure for CFSocketCreate. address = CFDataCreateWithBytesNoCopy(alloc, (const UInt8*)&addr4, sizeof(addr4), kCFAllocatorNull); // If it failed to create the address data, bail. if (address == NULL) break; // Set the local binding which causes the socket to start listening. if (CFSocketSetAddress(s->_sockets[0], address) != kCFSocketSuccess) break; CFRelease(address); address = CFSocketCopyAddress(s->_sockets[0]); memcpy(&addr4, CFDataGetBytePtr(address), CFDataGetLength(address)); port = ntohs(addr4.sin_port); CFRelease(address); memset(&addr6, 0, sizeof(addr6)); // Put the local port and address into the native address. addr6.sin6_family = AF_INET6;#ifndef __WIN32__ addr6.sin6_port = htons((UInt16)port); addr6.sin6_len = sizeof(addr6); memcpy(&(addr6.sin6_addr), &in6addr_any, sizeof(addr6.sin6_addr));#else#ifndef __MINGW32__ // real MS headers have this IN6ADDR_SETANY(addr6); addr6.sin6_port = htons((UInt16)port);#else addr6.sin6_port = htons((UInt16)port); // mingw's w32 headers have this INIT macro instead, for some odd reason struct sockaddr_in6 in6addr_any = IN6ADDR_ANY_INIT; memcpy(&(addr6.sin6_addr), &in6addr_any, sizeof(addr6.sin6_addr));#endif#endif // Wrap the native address structure for CFSocketCreate. address = CFDataCreateWithBytesNoCopy(alloc, (const UInt8*)&addr6, sizeof(addr6), kCFAllocatorNull); // Set the local binding which causes the socket to start listening. if (CFSocketSetAddress(s->_sockets[1], address) != kCFSocketSuccess) break; // Save the name, service type and port. s->_name = CFRetain(name); s->_type = type ? CFRetain(type) : NULL; s->_port = port;#if defined(__MACH__) // Attempt to register the service on the network. //.........这里部分代码省略.........
开发者ID:annp,项目名称:CFNetwork,代码行数:101,
示例25: 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,
示例26: PJ_DEF/* Resolve IPv4/IPv6 address */PJ_DEF(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *nodename, unsigned *count, pj_addrinfo ai[]){#if defined(PJ_SOCK_HAS_GETADDRINFO) && PJ_SOCK_HAS_GETADDRINFO!=0 char nodecopy[PJ_MAX_HOSTNAME]; pj_bool_t has_addr = PJ_FALSE; unsigned i;#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0 CFStringRef hostname; CFHostRef hostRef; pj_status_t status = PJ_SUCCESS;#else int rc; struct addrinfo hint, *res, *orig_res;#endif PJ_ASSERT_RETURN(nodename && count && *count && ai, PJ_EINVAL); PJ_ASSERT_RETURN(nodename->ptr && nodename->slen, PJ_EINVAL); PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6 || af==PJ_AF_UNSPEC, PJ_EINVAL); /* Check if nodename is IP address */ pj_bzero(&ai[0], sizeof(ai[0])); if ((af==PJ_AF_INET || af==PJ_AF_UNSPEC) && pj_inet_pton(PJ_AF_INET, nodename, &ai[0].ai_addr.ipv4.sin_addr) == PJ_SUCCESS) { af = PJ_AF_INET; has_addr = PJ_TRUE; } else if ((af==PJ_AF_INET6 || af==PJ_AF_UNSPEC) && pj_inet_pton(PJ_AF_INET6, nodename, &ai[0].ai_addr.ipv6.sin6_addr) == PJ_SUCCESS) { af = PJ_AF_INET6; has_addr = PJ_TRUE; } if (has_addr) { pj_str_t tmp; tmp.ptr = ai[0].ai_canonname; pj_strncpy_with_null(&tmp, nodename, PJ_MAX_HOSTNAME); ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; *count = 1; return PJ_SUCCESS; } /* Copy node name to null terminated string. */ if (nodename->slen >= PJ_MAX_HOSTNAME) return PJ_ENAMETOOLONG; pj_memcpy(nodecopy, nodename->ptr, nodename->slen); nodecopy[nodename->slen] = '/0';#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0 hostname = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, nodecopy, kCFStringEncodingASCII, kCFAllocatorNull); hostRef = CFHostCreateWithName(kCFAllocatorDefault, hostname); if (CFHostStartInfoResolution(hostRef, kCFHostAddresses, nil)) { CFArrayRef addrRef = CFHostGetAddressing(hostRef, nil); i = 0; if (addrRef != nil) { CFIndex idx, naddr; naddr = CFArrayGetCount(addrRef); for (idx = 0; idx < naddr && i < *count; idx++) { struct sockaddr *addr; addr = (struct sockaddr *) CFDataGetBytePtr(CFArrayGetValueAtIndex(addrRef, idx)); /* This should not happen. */ pj_assert(addr); /* Ignore unwanted address families */ if (af!=PJ_AF_UNSPEC && addr->sa_family != af) continue; /* Store canonical name */ pj_ansi_strcpy(ai[i].ai_canonname, nodecopy); /* Store address */ PJ_ASSERT_ON_FAIL(sizeof(*addr) <= sizeof(pj_sockaddr), continue); pj_memcpy(&ai[i].ai_addr, addr, sizeof(*addr)); PJ_SOCKADDR_RESET_LEN(&ai[i].ai_addr); i++; } } *count = i; } else {
开发者ID:AbhaySingh,项目名称:pjproject,代码行数:94,
示例27: SCREENReadNormalizedGammaTable//.........这里部分代码省略......... } 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); if (PsychPrefStateGet_Verbosity()>5) printf("PTB-DEBUG: Screen %i has framebuffer address %p./n", screenNumber, CGDisplayBaseAddress(displayID)); // 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) { CFDictionaryRef currentMode; CFNumberRef n; int modeId; currentMode = CGDisplayCurrentMode(displayID); n=CFDictionaryGetValue(currentMode, kCGDisplayMode); CFNumberGetValue(n, kCFNumberIntType, &modeId); 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);}
开发者ID:Epixoft,项目名称:Psychtoolbox-3,代码行数:101,
示例28: writeDictToFileRecursivestatic bool writeDictToFileRecursive(CFDictionaryRef dict, int level, FILE *fp){ for (int i = 0; i < level; i++) fwrite("/t", 1, 1, fp); fwrite("<dict>/n", 1, 7, fp); CFIndex len = CFDictionaryGetCount(dict); if (len == 0) { for (int i = 0; i < level; i++) fwrite("/t", 1, 1, fp); fwrite("</dict>/n", 1, 8, fp); return true; } CFStringRef *keys = (CFStringRef*)malloc(len * sizeof(CFStringRef)); CFTypeRef *values = (CFTypeRef*)malloc(len * sizeof(CFTypeRef)); CFDictionaryGetKeysAndValues(dict, (const void**)keys, (const void**)values); for (CFIndex ci = 0; ci < len; ci++) { for (int i = 0; i <= level; i++) fwrite("/t", 1, 1, fp); fwrite("<key>", 1, 5, fp); CFIndex cflen = CFStringGetLength(keys[ci]); if (cflen > 0) { char buf[cflen+1]; if (CFStringGetCString(keys[ci], buf, cflen+1, kCFStringEncodingUTF8) == false) { free(keys); free(values); return false; } fwrite(buf, 1, cflen, fp); } fwrite("</key>/n", 1, 7, fp); CFTypeID valtype = CFGetTypeID(values[ci]); if (valtype == CFStringGetTypeID()) { for (int i = 0; i <= level; i++) fwrite("/t", 1, 1, fp); fwrite("<string>", 1, 8, fp); cflen = CFStringGetLength((CFStringRef)values[ci]); if (cflen > 0) { char buf[cflen+1]; if (CFStringGetCString((CFStringRef)values[ci], buf, cflen+1, kCFStringEncodingUTF8) == false) { free(keys); free(values); return false; } fwrite(buf, 1, cflen, fp); } fwrite("</string>/n", 1, 10, fp); } else if (valtype == CFDictionaryGetTypeID()) { if (!writeDictToFileRecursive((CFDictionaryRef)values[ci], level+1, fp)) { free(keys); free(values); return false; } } else if (valtype == CFDataGetTypeID()) { for (int i = 0; i <= level; i++) fwrite("/t", 1, 1, fp); fwrite("<data>/n", 1, 7, fp); CFIndex datalen = CFDataGetLength((CFDataRef)values[ci]); if (datalen > 0) { int encodedlen = Base64encode_len((int)datalen); char encodeddata[encodedlen]; Base64encode(encodeddata, (const char*)CFDataGetBytePtr((CFDataRef)values[ci]), (int)datalen); encodedlen = strlen(encodeddata); int count = 0; while (count < encodedlen) { for (int i = 0; i <= level; i++) fwrite("/t", 1, 1, fp); if ( (encodedlen-count) > 60 ) { fwrite(encodeddata+count, 1, 60, fp); count += 60; } else { fwrite(encodeddata+count, 1, encodedlen-count, fp); count = encodedlen; } fwrite("/n", 1, 1, fp); }//.........这里部分代码省略.........
开发者ID:Alioune18,项目名称:independence,代码行数:101,
示例29: print_line/* TODO: Use the shared version of this function in print_cert.c. */static void print_line(CFStringRef line) { UInt8 buf[256]; CFRange range = { .location = 0 }; range.length = CFStringGetLength(line); while (range.length > 0) { CFIndex bytesUsed = 0; CFIndex converted = CFStringGetBytes(line, range, kCFStringEncodingUTF8, 0, false, buf, sizeof(buf), &bytesUsed); fwrite(buf, 1, bytesUsed, stdout); range.length -= converted; range.location += converted; } fputc('/n', stdout);}static void printPlist(CFArrayRef plist, CFIndex indent, CFIndex maxWidth) { CFIndex count = CFArrayGetCount(plist); CFIndex ix; for (ix = 0; ix < count ; ++ix) { CFDictionaryRef prop = (CFDictionaryRef)CFArrayGetValueAtIndex(plist, ix); CFStringRef pType = (CFStringRef)CFDictionaryGetValue(prop, kSecPropertyKeyType); CFStringRef label = (CFStringRef)CFDictionaryGetValue(prop, kSecPropertyKeyLabel); CFStringRef llabel = (CFStringRef)CFDictionaryGetValue(prop, kSecPropertyKeyLocalizedLabel); CFTypeRef value = (CFTypeRef)CFDictionaryGetValue(prop, kSecPropertyKeyValue); bool isSection = CFEqual(pType, kSecPropertyTypeSection); CFMutableStringRef line = CFStringCreateMutable(NULL, 0); CFIndex jx = 0; for (jx = 0; jx < indent; ++jx) { CFStringAppend(line, CFSTR(" ")); } if (llabel) { CFStringAppend(line, llabel); if (!isSection) { for (jx = CFStringGetLength(llabel) + indent * 4; jx < maxWidth; ++jx) { CFStringAppend(line, CFSTR(" ")); } CFStringAppend(line, CFSTR(" : ")); } } if (CFEqual(pType, kSecPropertyTypeWarning)) { CFStringAppend(line, CFSTR("*WARNING* ")); CFStringAppend(line, (CFStringRef)value); } else if (CFEqual(pType, kSecPropertyTypeError)) { CFStringAppend(line, CFSTR("*ERROR* ")); CFStringAppend(line, (CFStringRef)value); } else if (CFEqual(pType, kSecPropertyTypeSuccess)) { CFStringAppend(line, CFSTR("*OK* ")); CFStringAppend(line, (CFStringRef)value); } else if (CFEqual(pType, kSecPropertyTypeTitle)) { CFStringAppend(line, CFSTR("*")); CFStringAppend(line, (CFStringRef)value); CFStringAppend(line, CFSTR("*")); } else if (CFEqual(pType, kSecPropertyTypeSection)) { } else if (CFEqual(pType, kSecPropertyTypeData)) { CFDataRef data = (CFDataRef)value; CFIndex length = CFDataGetLength(data); if (length > 20) CFStringAppendFormat(line, NULL, CFSTR("[%" PRIdCFIndex " bytes] "), length); const UInt8 *bytes = CFDataGetBytePtr(data); for (jx = 0; jx < length; ++jx) { if (jx == 0) CFStringAppendFormat(line, NULL, CFSTR("%02X"), bytes[jx]); else if (jx < 15 || length <= 20) CFStringAppendFormat(line, NULL, CFSTR(" %02X"), bytes[jx]); else { CFStringAppend(line, CFSTR(" ...")); break; } } } else if (CFEqual(pType, kSecPropertyTypeString)) { CFStringAppend(line, (CFStringRef)value); } else if (CFEqual(pType, kSecPropertyTypeDate)) { CFLocaleRef lc = CFLocaleCopyCurrent(); CFDateFormatterRef df = CFDateFormatterCreate(NULL, lc, kCFDateFormatterFullStyle, kCFDateFormatterFullStyle); //CFTimeZoneRef tz = CFTimeZoneCreateWithName(NULL, CFSTR("GMT"), false); //CFDateFormatterSetProperty(df, kCFDateFormatterTimeZone, tz); //CFRelease(tz); CFDateRef date = (CFDateRef)value; CFStringRef ds = CFDateFormatterCreateStringWithDate(NULL, df, date); CFStringAppend(line, ds); CFRelease(ds); CFRelease(df); CFRelease(lc); } else if (CFEqual(pType, kSecPropertyTypeURL)) { CFURLRef url = (CFURLRef)value; CFStringAppend(line, CFSTR("<")); CFStringAppend(line, CFURLGetString(url)); CFStringAppend(line, CFSTR(">")); } else { CFStringAppendFormat(line, NULL, CFSTR("*unknown type %@* = %@"),//.........这里部分代码省略.........
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:101,
注:本文中的CFDataGetBytePtr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ CFDataGetBytes函数代码示例 C++ CFDataCreateWithBytesNoCopy函数代码示例 |