本文整理汇总了C++中CFDataGetLength函数的典型用法代码示例。如果您正苦于以下问题:C++ CFDataGetLength函数的具体用法?C++ CFDataGetLength怎么用?C++ CFDataGetLength使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CFDataGetLength函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printEntry
static void printEntry(const void *key, const void *value, void *context)
{
struct indent_ctxt * ctxt = context;
#if 1
// IOKit pretty
CFDataRef data;
indent(false, ctxt->depth, ctxt->stackOfBits);
printf(" ");
printCFString( (CFStringRef)key );
printf(" = ");
data = IOCFSerialize((CFStringRef)value, kNilOptions);
if( data) {
if( 10000 > CFDataGetLength(data))
printf(CFDataGetBytePtr(data));
else
printf("<is BIG>");
CFRelease(data);
} else
printf("<IOCFSerialize failed>");
printf("\n");
#else
// CF ugly
CFStringRef keyStr = (CFStringRef) key;
CFStringRef valueStr = CFCopyDescription((CFTypeRef) val);
CFStringRef outStr;
indent(false, ctxt->depth, ctxt->stackOfBits);
outStr = CFStringCreateWithFormat(kCFAllocatorDefault, 0,
CFSTR(" %@ = %@\n"), keyStr, valueStr);
assert(outStr);
printCFString(outStr);
CFRelease(valueStr);
CFRelease(outStr);
#endif
}
示例2: schan_imp_get_session_peer_certificate
SECURITY_STATUS schan_imp_get_session_peer_certificate(schan_imp_session session,
PCCERT_CONTEXT *cert)
{
struct mac_session* s = (struct mac_session*)session;
SECURITY_STATUS ret = SEC_E_INTERNAL_ERROR;
CFArrayRef certs;
OSStatus status;
TRACE("(%p/%p, %p)\n", s, s->context, cert);
status = SSLCopyPeerCertificates(s->context, &certs);
if (status == noErr && certs)
{
SecCertificateRef mac_cert;
CFDataRef data;
if (CFArrayGetCount(certs) &&
(mac_cert = (SecCertificateRef)CFArrayGetValueAtIndex(certs, 0)) &&
(SecKeychainItemExport(mac_cert, kSecFormatX509Cert, 0, NULL, &data) == noErr))
{
*cert = CertCreateCertificateContext(X509_ASN_ENCODING,
CFDataGetBytePtr(data), CFDataGetLength(data));
if (*cert)
ret = SEC_E_OK;
else
{
ret = GetLastError();
WARN("CertCreateCertificateContext failed: %x\n", ret);
}
CFRelease(data);
}
else
WARN("Couldn't extract certificate data\n");
CFRelease(certs);
}
else
WARN("SSLCopyPeerCertificates failed: %ld\n", (long)status);
return ret;
}
示例3: dataRead
static CFIndex dataRead(CFReadStreamRef stream, UInt8 *buffer, CFIndex bufferLength, CFStreamError *error, Boolean *atEOF, void *info) {
_CFReadDataStreamContext *dataCtxt = (_CFReadDataStreamContext *)info;
const UInt8 *bytePtr = CFDataGetBytePtr(dataCtxt->data);
CFIndex length = CFDataGetLength(dataCtxt->data);
CFIndex bytesToCopy = bytePtr + length - dataCtxt->loc;
if (bytesToCopy > bufferLength) {
bytesToCopy = bufferLength;
}
if (bytesToCopy < 0) {
bytesToCopy = 0;
}
if (bytesToCopy != 0) {
memmove(buffer, dataCtxt->loc, bytesToCopy);
dataCtxt->loc += bytesToCopy;
}
error->error = 0;
*atEOF = (dataCtxt->loc < bytePtr + length) ? FALSE : TRUE;
if (dataCtxt->scheduled && !*atEOF) {
CFReadStreamSignalEvent(stream, kCFStreamEventHasBytesAvailable, NULL);
}
return bytesToCopy;
}
示例4: PasteboardCreate
GHOST_TUns8* GHOST_SystemCarbon::getClipboard(bool selection) const
{
PasteboardRef inPasteboard;
PasteboardItemID itemID;
CFDataRef flavorData;
OSStatus err = noErr;
GHOST_TUns8 * temp_buff;
CFRange range;
OSStatus syncFlags;
err = PasteboardCreate(kPasteboardClipboard, &inPasteboard);
if(err != noErr) { return NULL;}
syncFlags = PasteboardSynchronize( inPasteboard );
/* as we always get in a new string, we can safely ignore sync flags if not an error*/
if(syncFlags <0) { return NULL;}
err = PasteboardGetItemIdentifier( inPasteboard, 1, &itemID );
if(err != noErr) { return NULL;}
err = PasteboardCopyItemFlavorData( inPasteboard, itemID, CFSTR("public.utf8-plain-text"), &flavorData);
if(err != noErr) { return NULL;}
range = CFRangeMake(0, CFDataGetLength(flavorData));
temp_buff = (GHOST_TUns8*) malloc(range.length+1);
CFDataGetBytes(flavorData, range, (UInt8*)temp_buff);
temp_buff[range.length] = '\0';
if(temp_buff) {
return temp_buff;
} else {
return NULL;
}
}
示例5: metadata_realm_encryption_key
std::vector<char> metadata_realm_encryption_key()
{
const size_t key_size = 64;
const std::string service = "io.realm.sync.keychain";
const std::string account = "metadata";
auto search_dictionary = build_search_dictionary(account, service, none);
CFDataRef retained_key_data;
if (OSStatus status = SecItemCopyMatching(search_dictionary.get(), (CFTypeRef *)&retained_key_data)) {
if (status != errSecItemNotFound) {
throw KeychainAccessException(status);
}
// Key was not found. Generate a new key, store it, and return it.
std::vector<char> key(key_size);
arc4random_buf(key.data(), key_size);
auto key_data = adoptCF(CFDataCreate(nullptr, reinterpret_cast<const UInt8 *>(key.data()), key_size));
if (!key_data) {
throw std::bad_alloc();
}
CFDictionaryAddValue(search_dictionary.get(), kSecValueData, key_data.get());
if (OSStatus status = SecItemAdd(search_dictionary.get(), nullptr)) {
throw KeychainAccessException(status);
}
return key;
}
CFPtr<CFDataRef> key_data = adoptCF(retained_key_data);
// Key was previously stored. Extract it.
if (key_size != CFDataGetLength(key_data.get())) {
throw std::runtime_error("Password stored in keychain was not expected size.");
}
auto key_bytes = reinterpret_cast<const char *>(CFDataGetBytePtr(key_data.get()));
return std::vector<char>(key_bytes, key_bytes + key_size);
}
示例6: __DAQueueResponse
static void __DAQueueResponse( DASessionRef session,
void * address,
void * context,
_DACallbackKind kind,
DADiskRef disk,
CFTypeRef response,
SInt32 responseID )
{
CFDataRef _response = NULL;
if ( response ) _response = _DASerialize( kCFAllocatorDefault, response );
_DAServerSessionQueueResponse( _DASessionGetID( session ),
( uintptr_t ) address,
( uintptr_t ) context,
( int32_t ) kind,
( caddr_t ) _DADiskGetID( disk ),
( vm_address_t ) ( _response ? CFDataGetBytePtr( _response ) : 0 ),
( mach_msg_type_number_t ) ( _response ? CFDataGetLength( _response ) : 0 ),
( int32_t ) responseID );
if ( _response ) CFRelease( _response );
}
示例7: img3_flash_NOR_image
int img3_flash_NOR_image(io_connect_t norServiceConnection, CFDataRef imageData, int isLLB) {
restored_log("%s: flashing %s data\n", "img3_flash_NOR_image", (isLLB ? "LLB" : "NOR"));
size_t imgLen = CFDataGetLength(imageData);
void *mappedImage = mmap(NULL, imgLen, PROT_READ | PROT_WRITE, MAP_SHARED, -1, 0);
if(mappedImage == MAP_FAILED) {
int err = errno;
restored_log("mmap (size = %d) failed: %s\n", imgLen, strerror(err));
return err;
}
const void *imageDataPtr = CFDataGetBytePtr(imageData);
bcopy(imageDataPtr, mappedImage, imgLen);
kern_return_t result;
if((result = IOConnectCallStructMethod(norServiceConnection, 0, mappedImage, imgLen, NULL, 0)) != KERN_SUCCESS) {
restored_log("IOConnectCallStructMethod failed: 0x%x\n", result);
}
munmap(mappedImage, imgLen);
return result;
}
示例8: dumpLogicalVolumeExtents
static void
dumpLogicalVolumeExtents(CFMutableDictionaryRef lv)
{
CFStringRef lvUUID = CFDictionaryGetValue(lv, CFSTR(kAppleLVMVolumeUUIDKey));
if (!lvUUID) { printf("\ninternal error, no uuid in lv dict\n"); return; };
CFDataRef extentData = (CFDataRef)AppleLVMGetVolumeExtents(lvUUID);
if (!extentData) { printf("\nno extent data found?\n"); return; };
AppleRAIDExtentOnDisk * extentList = (AppleRAIDExtentOnDisk *)CFDataGetBytePtr(extentData);
UInt64 extentCount = CFDataGetLength(extentData) / sizeof(AppleRAIDExtentOnDisk);
if (!extentCount || !extentList) { printf("\nextent data empty?\n"); return; };
printf("\textent list:\n");
UInt32 i;
for (i = 0; i < extentCount; i++) {
printf(" %20llu - %12llu (%llu)\n",
extentList[i].extentByteOffset,
extentList[i].extentByteOffset + extentList[i].extentByteCount - 1,
extentList[i].extentByteCount);
}
}
示例9: TSICTStringCreateDataFromIntermediateRepresentation
static inline CFDataRef TSICTStringCreateDataFromIntermediateRepresentation(TStringIRep* rep)
{
CFIndex len = CFDataGetLength(rep->data);
CFMutableDataRef buffer = CFDataCreateMutableCopy(kCFAllocatorDefault, (len + 12), rep->data);
UInt8* bufferBytes = CFDataGetMutableBytePtr(buffer);
size_t prefixLength = strlen(rep->length) + 1;
CFDataReplaceBytes(buffer, BeginningRange, (const UInt8*)rep->length, (CFIndex)prefixLength);
if (rep->format == kTSITStringFormatTNetstring) {
const UInt8 ftag = (UInt8)TNetstringTypes[rep->type];
CFDataAppendBytes(buffer, &ftag, 1);
bufferBytes[(prefixLength - 1)] = TNetstringSeparator;
} else if (rep->format == kTSITStringFormatOTNetstring) {
const UInt8 ftag = (UInt8)OTNetstringTypes[rep->type];
bufferBytes[(prefixLength - 1)] = ftag;
}
CFDataRef dataRep = CFDataCreateCopy(kCFAllocatorDefault, buffer);
CFRelease(buffer);
return dataRep;
}
示例10: mailstream_low_cfstream_get_fd
static int mailstream_low_cfstream_get_fd(mailstream_low * s)
{
#if HAVE_CFNETWORK
struct mailstream_cfstream_data * cfstream_data = NULL;
CFDataRef native_handle_data = NULL;
CFSocketNativeHandle native_handle_value = -1;
CFIndex native_data_len = 0;
CFIndex native_value_len = 0;
if (!s)
return -1;
cfstream_data = (struct mailstream_cfstream_data *) s->data;
if (!cfstream_data->readStream)
return -1;
native_handle_data = (CFDataRef)CFReadStreamCopyProperty(cfstream_data->readStream, kCFStreamPropertySocketNativeHandle);
if (!native_handle_data)
return -1;
native_data_len = CFDataGetLength(native_handle_data);
native_value_len = (CFIndex)sizeof(native_handle_value);
if (native_data_len != native_value_len) {
CFRelease(native_handle_data);
return -1;
}
CFDataGetBytes(native_handle_data, CFRangeMake(0, MIN(native_data_len, native_value_len)), (UInt8 *)&native_handle_value);
CFRelease(native_handle_data);
return native_handle_value;
#else
return -1;
#endif
}
示例11: start_paste
void start_paste(widget_list *widget)
{
OSStatus err = noErr;
PasteboardRef gClipboard;
PasteboardItemID itemID;
CFDataRef flavorData;
char* flavorText;
err = PasteboardCreate( kPasteboardClipboard, &gClipboard );
//require_noerr( err, CantCreateClipboard );
err = PasteboardGetItemIdentifier( gClipboard, 1, &itemID );
err = PasteboardCopyItemFlavorData( gClipboard, itemID, CFSTR("com.apple.traditional-mac-plain-text"), &flavorData );
int flavorDataSize = CFDataGetLength(flavorData);
flavorText=(char*)malloc(flavorDataSize+1);
short dataIndex;
for(dataIndex = 0; dataIndex <= flavorDataSize; dataIndex++ )
{
char byte = *(CFDataGetBytePtr( flavorData ) + dataIndex);
flavorText[dataIndex] = (byte>32) ? byte : ' ';
}
flavorText[flavorDataSize] = '\0';
CFRelease(flavorData);
if (widget == NULL)
{
do_paste (flavorText);
}
else
{
do_paste_to_text_field(widget, flavorText);
}
free(flavorText);
CFRelease( gClipboard );
}
示例12: iSCSIDaemonCreateCFPropertiesForSession
/*! Creates a dictionary of session parameters for the session associated with
* the specified target, if one exists.
* @param handle a handle to a daemon connection.
* @param target the target to check for associated sessions to generate
* a dictionary of session parameters.
* @return a dictionary of session properties. */
CFDictionaryRef iSCSIDaemonCreateCFPropertiesForSession(iSCSIDaemonHandle handle,
iSCSITargetRef target)
{
// Validate inputs
if(handle < 0 || !target)
return NULL;
CFDictionaryRef properties = NULL;
CFDataRef targetData = iSCSITargetCreateData(target);
// Send command to daemon
iSCSIDMsgCreateCFPropertiesForSessionCmd cmd = iSCSIDMsgCreateCFPropertiesForSessionCmdInit;
cmd.targetLength = (UInt32)CFDataGetLength(targetData);
errno_t error = iSCSIDaemonSendMsg(handle,(iSCSIDMsgGeneric *)&cmd,
targetData,NULL);
CFRelease(targetData);
iSCSIDMsgCreateCFPropertiesForSessionRsp rsp;
if(!error)
error = iSCSIDaemonRecvMsg(handle,(iSCSIDMsgGeneric*)&rsp,NULL);
if(!error) {
CFDataRef data = NULL;
error = iSCSIDaemonRecvMsg(handle,0,&data,rsp.dataLength,NULL);
if(!error && data) {
CFPropertyListFormat format;
properties = CFPropertyListCreateWithData(kCFAllocatorDefault,data,0,&format,NULL);
CFRelease(data);
}
}
return properties;
}
示例13: IOPMSleepSystemWithOptions
/* Private call for Apple Internal use only */
IOReturn IOPMSleepSystemWithOptions ( io_connect_t fb, CFDictionaryRef options )
{
uint64_t rtn = 0;
size_t len = sizeof(uint32_t);
kern_return_t err;
CFDataRef serializedOptions = NULL;
if( !options ) {
return IOPMSleepSystem( fb );
}
serializedOptions = IOCFSerialize( options, 0 );
if (!serializedOptions)
{
return kIOReturnInternalError;
}
/* kPMSleepSystemOptions
* in: serialized CFDictionary of options
* out: IOReturn code returned from sleepSystem
*/
err = IOConnectCallStructMethod(
fb,
kPMSleepSystemOptions,
CFDataGetBytePtr(serializedOptions), /* inputStruct */
CFDataGetLength(serializedOptions), /* inputStructCnt */
&rtn, /* outputStruct */
&len); /* outputStructCnt */
CFRelease(serializedOptions);
if (kIOReturnSuccess != err)
return err;
else
return (IOReturn) rtn;
}
示例14: CFNetDiagnosticDiagnoseProblemInteractively
CFNetDiagnosticStatus CFNetDiagnosticDiagnoseProblemInteractively(CFNetDiagnosticRef details) {
SInt32 retval = 0;
mach_port_t port = MACH_PORT_NULL;
CFDataRef msgData = NULL;
kern_return_t err;
//build message
CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers(kCFAllocatorDefault, kCFAllocatorDefault);
CFWriteStreamOpen(stream);
CFIndex len = CFPropertyListWriteToStream(details, stream, kCFPropertyListBinaryFormat_v1_0, NULL);
CFWriteStreamClose(stream);
if(len > 0) {
msgData = CFWriteStreamCopyProperty(stream, kCFStreamPropertyDataWritten);
}
CFRelease(stream);
if(msgData) {
err = bootstrap_look_up(bootstrap_port, *((name_t*)(&_CFNetDiagnosticMachPortName)), &port);
if (err == KERN_SUCCESS) {
err = _CFNetDiagnosticClient_passDescriptor( port,
_CFNetDiagnosticMachProtocolVersion,
(vm_address_t)CFDataGetBytePtr(msgData),
CFDataGetLength(msgData));
if (err == KERN_SUCCESS) {
//FIXME Yay!!!
}
}
CFRelease(msgData);
}
return (CFNetDiagnosticStatus)retval;
}
示例15: SDMMD_MB2SendFileStream
sdmmd_return_t SDMMD_MB2SendFileStream(SDMMD_AMConnectionRef conn, CFStringRef path, CFDataRef file) {
sdmmd_return_t result = kAMDSuccess;
CFDataRef file_path = CFStringCreateExternalRepresentation(kCFAllocatorDefault, path, kCFStringEncodingUTF8, 0);
result = SDMMD_ServiceSend(SDMMD_TranslateConnectionToSocket(conn), file_path);
CFSafeRelease(file_path);
CheckErrorAndReturn(result);
char data_chunk[1] = { 0x0C };
CFMutableDataRef data_separator = CFDataCreateMutable(kCFAllocatorDefault, 0);
CFDataAppendBytes(data_separator, (const UInt8 *)data_chunk, sizeof(uint8_t));
CFDataAppendBytes(data_separator, CFDataGetBytePtr(file), CFDataGetLength(file));
result = SDMMD_ServiceSend(SDMMD_TranslateConnectionToSocket(conn), data_separator);
CFSafeRelease(data_separator);
CheckErrorAndReturn(result);
char zero_chunk[1] = { 0x0 };
CFDataRef data_end = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)zero_chunk, sizeof(uint8_t));
result = SDMMD_ServiceSend(SDMMD_TranslateConnectionToSocket(conn), data_end);
CFSafeRelease(data_end);
CheckErrorAndReturn(result);
ExitLabelAndReturn(result);
}