当前位置: 首页>>代码示例>>C++>>正文


C++ CFStringGetCString函数代码示例

本文整理汇总了C++中CFStringGetCString函数的典型用法代码示例。如果您正苦于以下问题:C++ CFStringGetCString函数的具体用法?C++ CFStringGetCString怎么用?C++ CFStringGetCString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CFStringGetCString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DoSetPermissions

OSStatus DoSetPermissions(COMMAND_PROC_ARGUMENTS) {
#pragma unused (auth)
#pragma unused (userData)
	OSStatus retval = noErr;
	
	// Pre-conditions
    
    // userData may be NULL
	assert(request != NULL);
	assert(response != NULL);
    // asl may be NULL
    // aslMsg may be NULL
	
	// Get Info from arguments and assert that it's a CFDictionaryRef
	CFDictionaryRef infos = CFDictionaryGetValue(request, CFSTR(kInfos)) ;
	assert(infos != NULL) ;
	assert(CFGetTypeID(infos) == CFDictionaryGetTypeID()) ;
	
	CFIndex nPaths = CFDictionaryGetCount(infos) ;
	
	CFMutableDictionaryRef errorDescriptions = CFDictionaryCreateMutable(
																NULL,
																nPaths,
																&kCFTypeDictionaryKeyCallBacks,
																&kCFTypeDictionaryValueCallBacks
																) ;
	CFMutableDictionaryRef originalModes = CFDictionaryCreateMutable(
																	 NULL,
																	 nPaths,
																	 &kCFTypeDictionaryKeyCallBacks,
																	 &kCFTypeDictionaryValueCallBacks
																	 ) ;
	
	CFIndex i ;
	int nSucceeded = 0 ;
	
	const void ** paths = (const void **)malloc( nPaths * sizeof(const void *)) ;
	const void ** modeNums = (const void **)malloc( nPaths * sizeof(const void *)) ;
	if ((paths != NULL) && (modeNums != NULL)) {
		CFDictionaryGetKeysAndValues(
									 infos,
									 paths,
									 modeNums
									 )
		;
		
		for (i=0; i<nPaths; i++) {
			// Process each path
			Boolean ok = true ;
			int retval ;
			
			// Get path, assert that it's a string anc convert to a C string
			CFStringRef path = paths[i] ;
			assert(CFGetTypeID(path) == CFStringGetTypeID()) ;
			char pathC[MAX_PATH_CHARS] ;
			if (ok) {
				ok = CFStringGetCString(
										path,
										pathC,
										MAX_PATH_CHARS,
										kCFStringEncodingASCII
										) ;
				if (!ok) {
					CFDictionaryAddValue(errorDescriptions, path, CFSTR("Name too long")) ;
				}
			}
			
			// Read current permissions for path, wrap as CFNumber and add to results dictionary
			if (ok) {
				struct stat rawStats ;
				retval = stat(pathC, &rawStats) ;
				ok = (retval == 0) ;
				if (ok) {
					// rawStats.st_mode is of type mode_t which is an unsigned short.
					// Unfortunately, the available kCFNumberTypes don't have unsigned short.
					// And I have found that if I give CFNumberCreate an unsigned short and
					// tell it that it's an available kCFNumberType, which has more bits,
					// the undefined bits get encoded as garbage, changing the value.
					// First assigning the unsigned short to an int fixes it.
					int originalMode = rawStats.st_mode ;
					CFNumberRef fileModeCF =  CFNumberCreate(
															 NULL,
															 kCFNumberIntType,
															 &originalMode
															 ) ;
					CFDictionaryAddValue(
										 originalModes,
										 path,
										 fileModeCF) ;
					CFRelease(fileModeCF) ;
				}
				else {
					CFStringRef errString = CFStringCreateWithFormat(
																	 NULL,
																	 NULL,
																	 CFSTR("stat64 failed.  errno: %d"),
																	 errno
																	 ) ;
					CFDictionaryAddValue(errorDescriptions, path, errString) ;
					CFQRelease(errString) ;
//.........这里部分代码省略.........
开发者ID:dibowei,项目名称:CocoaPrivilegedHelper,代码行数:101,代码来源:HelperToolTaskDoSetPermissions.c

示例2: sizeof


//.........这里部分代码省略.........
        str = "T/F";
        break;
    case kAudioUnitParameterUnit_Percent:
    case kAudioUnitParameterUnit_EqualPowerCrossfade:
        str = "%";
        break;
    case kAudioUnitParameterUnit_Seconds:
        str = "Secs";
        break;
    case kAudioUnitParameterUnit_SampleFrames:
        str = "Samps";
        break;
    case kAudioUnitParameterUnit_Phase:
    case kAudioUnitParameterUnit_Degrees:
        str = "Degr.";
        break;
    case kAudioUnitParameterUnit_Hertz:
        str = "Hz";
        break;
    case kAudioUnitParameterUnit_Cents:
    case kAudioUnitParameterUnit_AbsoluteCents:
        str = "Cents";
        break;
    case kAudioUnitParameterUnit_RelativeSemiTones:
        str = "S-T";
        break;
    case kAudioUnitParameterUnit_MIDINoteNumber:
    case kAudioUnitParameterUnit_MIDIController:
        str = "MIDI";
        //these are inclusive, so add one value here
        mNumIndexedParams = short(mParamInfo.maxValue+1 - mParamInfo.minValue);
        break;
    case kAudioUnitParameterUnit_Decibels:
        str = "dB";
        break;
    case kAudioUnitParameterUnit_MixerFaderCurve1:
    case kAudioUnitParameterUnit_LinearGain:
        str = "Gain";
        break;
    case kAudioUnitParameterUnit_Pan:
        str = "L/R";
        break;
    case kAudioUnitParameterUnit_Meters:
        str = "Mtrs";
        break;
    case kAudioUnitParameterUnit_Octaves:
        str = "8ve";
        break;
    case kAudioUnitParameterUnit_BPM:
        str = "BPM";
        break;
    case kAudioUnitParameterUnit_Beats:
        str = "Beats";
        break;
    case kAudioUnitParameterUnit_Milliseconds:
        str = "msecs";
        break;
    case kAudioUnitParameterUnit_Ratio:
        str = "Ratio";
        break;
    case kAudioUnitParameterUnit_Indexed:
    {
        propertySize = sizeof(mNamedParams);
        err = AudioUnitGetProperty (au,
                                    kAudioUnitProperty_ParameterValueStrings,
                                    scope,
                                    param,
                                    &mNamedParams,
                                    &propertySize);
        if (!err && mNamedParams) {
            mNumIndexedParams = CFArrayGetCount(mNamedParams);
        } else {
            //these are inclusive, so add one value here
            mNumIndexedParams = short(mParamInfo.maxValue+1 - mParamInfo.minValue);
        }
        str = NULL;
    }
    break;
    case kAudioUnitParameterUnit_CustomUnit:
    {
        CFStringRef unitName = mParamInfo.unitName;
        static char paramStr[256];
        CFStringGetCString (unitName, paramStr, 256, kCFStringEncodingUTF8);
        if (mParamInfo.flags & kAudioUnitParameterFlag_CFNameRelease)
            CFRelease (unitName);
        str = paramStr;
        break;
    }
    case kAudioUnitParameterUnit_Generic:
    case kAudioUnitParameterUnit_Rate:
    default:
        str = NULL;
        break;
    }

    if (str)
        mParamTag = CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8);
    else
        mParamTag = NULL;
}
开发者ID:kuolei,项目名称:CocoaSampleCode,代码行数:101,代码来源:CAAUParameter.cpp

示例3: vprintf_stderr_common

static void vprintf_stderr_common(const char* format, va_list args)
{
#if USE(CF) && !OS(WINDOWS)
    if (strstr(format, "%@")) {
        CFStringRef cfFormat = CFStringCreateWithCString(NULL, format, kCFStringEncodingUTF8);

#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
        CFStringRef str = CFStringCreateWithFormatAndArguments(NULL, NULL, cfFormat, args);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
        CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8);
        char* buffer = (char*)malloc(length + 1);

        CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);

#if USE(APPLE_SYSTEM_LOG)
        asl_log(0, 0, ASL_LEVEL_NOTICE, "%s", buffer);
#endif
        fputs(buffer, stderr);

        free(buffer);
        CFRelease(str);
        CFRelease(cfFormat);
        return;
    }

#if USE(APPLE_SYSTEM_LOG)
    va_list copyOfArgs;
    va_copy(copyOfArgs, args);
    asl_vlog(0, 0, ASL_LEVEL_NOTICE, format, copyOfArgs);
    va_end(copyOfArgs);
#endif

    // Fall through to write to stderr in the same manner as other platforms.

#elif PLATFORM(BLACKBERRY)
    BBLOGV(BlackBerry::Platform::LogLevelCritical, format, args);
#elif HAVE(ISDEBUGGERPRESENT)
    if (IsDebuggerPresent()) {
        size_t size = 1024;

        do {
            char* buffer = (char*)malloc(size);

            if (buffer == NULL)
                break;

            if (_vsnprintf(buffer, size, format, args) != -1) {
#if OS(WINCE)
                // WinCE only supports wide chars
                wchar_t* wideBuffer = (wchar_t*)malloc(size * sizeof(wchar_t));
                if (wideBuffer == NULL)
                    break;
                for (unsigned int i = 0; i < size; ++i) {
                    if (!(wideBuffer[i] = buffer[i]))
                        break;
                }
                OutputDebugStringW(wideBuffer);
                free(wideBuffer);
#else
                OutputDebugStringA(buffer);
#endif
                free(buffer);
                break;
            }

            free(buffer);
            size *= 2;
        } while (size > 1024);
    }
#endif
#if !PLATFORM(BLACKBERRY)
    vfprintf(stderr, format, args);
#endif
}
开发者ID:CUITCHE,项目名称:JavaScriptCore-iOS,代码行数:79,代码来源:Assertions.cpp

示例4: cdio_get_devices

// Returns a pointer to an array of strings with the device names
std::vector<std::string> cdio_get_devices()
{
    io_object_t   next_media;
    mach_port_t   master_port;
    kern_return_t kern_result;
    io_iterator_t media_iterator;
    CFMutableDictionaryRef classes_to_match;
    std::vector<std::string> drives;

    kern_result = IOMasterPort(MACH_PORT_NULL, &master_port);
    if (kern_result != KERN_SUCCESS)
        return drives;

    classes_to_match = IOServiceMatching(kIOCDMediaClass);
    if (classes_to_match == nullptr)
        return drives;

    CFDictionarySetValue(classes_to_match,
                         CFSTR(kIOMediaEjectableKey), kCFBooleanTrue);

    kern_result = IOServiceGetMatchingServices(master_port,
                  classes_to_match, &media_iterator);
    if (kern_result != KERN_SUCCESS)
        return drives;

    next_media = IOIteratorNext(media_iterator);
    if (next_media != 0)
    {
        CFTypeRef str_bsd_path;

        do
        {
            str_bsd_path =
                IORegistryEntryCreateCFProperty(next_media,
                                                CFSTR(kIOBSDNameKey), kCFAllocatorDefault,
                                                0);
            if (str_bsd_path == nullptr)
            {
                IOObjectRelease(next_media);
                continue;
            }

            if (CFGetTypeID(str_bsd_path) == CFStringGetTypeID())
            {
                size_t buf_size = CFStringGetLength((CFStringRef)str_bsd_path) * 4 + 1;
                char* buf = new char[buf_size];

                if (CFStringGetCString((CFStringRef)str_bsd_path, buf, buf_size, kCFStringEncodingUTF8))
                {
                    // Below, by appending 'r' to the BSD node name, we indicate
                    // a raw disk. Raw disks receive I/O requests directly and
                    // don't go through a buffer cache.
                    drives.push_back(std::string(_PATH_DEV "r") + buf);
                }

                delete[] buf;
            }
            CFRelease(str_bsd_path);
            IOObjectRelease(next_media);
        } while ((next_media = IOIteratorNext(media_iterator)) != 0);
    }
    IOObjectRelease(media_iterator);
    return drives;
}
开发者ID:gamax92,项目名称:Ishiiruka,代码行数:65,代码来源:CDUtils.cpp

示例5: CFStringCreateWithCString

nuiHTTPResponse* nuiHTTPRequest::SendRequest()
{
  char* pUrl = mUrl.Export();
	
  CFStringRef originalURLString = CFStringCreateWithCString(kCFAllocatorDefault, pUrl, kCFStringEncodingUTF8);
	
  CFStringRef preprocessedString =
  CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, originalURLString, CFSTR(""), kCFStringEncodingUTF8);
  CFStringRef urlString =
  CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, preprocessedString, NULL, NULL, kCFStringEncodingUTF8);
	
  free(pUrl);
  CFURLRef url = CFURLCreateWithString(kCFAllocatorDefault, urlString, NULL);
  CFRelease(urlString);
  
  char* pMeth = mMethod.Export(); 
  CFStringRef method = CFStringCreateWithCString(kCFAllocatorDefault, pMeth, kCFStringEncodingUTF8);
  free(pMeth);
  
  CFHTTPMessageRef req = CFHTTPMessageCreateRequest(kCFAllocatorDefault, method, url, kCFHTTPVersion1_1);
  
  CFStringRef userAgentField = CFSTR("User-Agent");
  CFStringRef userAgentName = CFSTR("nuiHTTP/2.0");
  CFHTTPMessageSetHeaderFieldValue(req, userAgentField, userAgentName);
  CFRelease(userAgentField);
  CFRelease(userAgentName);
  
  nuiHTTPHeaderMap::const_iterator end = mHeaders.end();
  for (nuiHTTPHeaderMap::const_iterator it = mHeaders.begin(); it != end; ++it)
  {
    char* pName = it->first.Export();
    char* pVal = it->second.Export();
    CFStringRef fieldName = CFStringCreateWithCString(kCFAllocatorDefault, pName, kCFStringEncodingUTF8);
    CFStringRef fieldValue = CFStringCreateWithCString(kCFAllocatorDefault, pVal, kCFStringEncodingUTF8);
    
    CFHTTPMessageSetHeaderFieldValue(req, fieldName, fieldValue);
    
    CFRelease(fieldName);
    CFRelease(fieldValue);
    delete pName;
    delete pVal;
  }
  
  CFDataRef body = NULL;
  if (mBody.size())
  {
    body = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, (UInt8*)&mBody[0], mBody.size(), kCFAllocatorNull);
    CFHTTPMessageSetBody(req, body);
  }
  
  CFReadStreamRef readStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, req);
  CFReadStreamOpen(readStream);
  
  std::vector<char> buf;
  CFIndex pos = 0;
  CFIndex size = 0;
  bool cont = true;
  do
  {
    buf.resize(pos + 1024);
    size = CFReadStreamRead(readStream, (UInt8*)&buf[pos], 1024);
    if (size == -1)
    {
      return NULL;
    }
    else if (size == 0)
    {
      if (CFReadStreamGetStatus(readStream) == kCFStreamStatusAtEnd)
        cont = false;
      else
        nglThread::MsSleep(10);
    }
    
    pos += size;
  }
  while (cont);
  
  CFHTTPMessageRef responseHeader = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader);
  
  CFStringRef statusLine = CFHTTPMessageCopyResponseStatusLine(responseHeader);
  CFIndex strSize = CFStringGetLength(statusLine)+1;
  char* pStatus = new char[strSize];
  CFStringGetCString(statusLine, pStatus, strSize, kCFStringEncodingUTF8);
  nglString status(pStatus);
  
  UInt32 statusCode = CFHTTPMessageGetResponseStatusCode(responseHeader);
  
  nuiHTTPResponse* pResponse = new nuiHTTPResponse(statusCode, status);
  pResponse->SetBody(&buf[0], pos);
  
  delete[] pStatus;
  
  CFDictionaryRef dict = CFHTTPMessageCopyAllHeaderFields(responseHeader);
  CFIndex valueCount = CFDictionaryGetCount(dict);
  const CFStringRef* pNames = new CFStringRef[valueCount];
  const CFStringRef* pValues = new CFStringRef[valueCount];
  CFDictionaryGetKeysAndValues(dict, (const void**)pNames, (const void**)pValues);
  for (CFIndex i = 0; i< valueCount; i++)
  {
    strSize = CFStringGetLength(pNames[i])+1;
//.........这里部分代码省略.........
开发者ID:YetToCome,项目名称:nui3,代码行数:101,代码来源:nuiHTTP_CoreFoundation.cpp

示例6: HIDDumpElementInfo


//.........这里部分代码省略.........
						break;
					}
						
					case kIOHIDElementCollectionTypeUsageModifier:
					{
						printf("type: Usage Modifier Collection, ");
						break;
					}
						
					default:
					{
						printf("type: %p Collection, ", (void *) tIOHIDElementCollectionType);
						break;
					}
				} // switch
				
				break;
			}
				
			default:
			{
				printf("type: %p, ", (void *) tIOHIDElementType);
				break;
			}
		}     /* switch */
		
		uint32_t usagePage = IOHIDElementGetUsagePage(inIOHIDElementRef);
		uint32_t usage     = IOHIDElementGetUsage(inIOHIDElementRef);
		printf("usage: 0x%04lX:0x%04lX, ", (long unsigned int) usagePage, (long unsigned int) usage);

		CFStringRef tCFStringRef = HIDCopyUsageName(usagePage, usage);
		if (tCFStringRef) {
			char usageString[256] = "";
			(void) CFStringGetCString(tCFStringRef, usageString, sizeof(usageString), kCFStringEncodingUTF8);
			printf("\"%s\", ", usageString);
			CFRelease(tCFStringRef);
		}

		CFStringRef nameCFStringRef = IOHIDElementGetName(inIOHIDElementRef);
		char        buffer[256];
		if ( nameCFStringRef && CFStringGetCString(nameCFStringRef, buffer, sizeof(buffer), kCFStringEncodingUTF8) ) {
			printf("name: %s, ", buffer);
		}
		
		uint32_t reportID    = IOHIDElementGetReportID(inIOHIDElementRef);
		uint32_t reportSize  = IOHIDElementGetReportSize(inIOHIDElementRef);
		uint32_t reportCount = IOHIDElementGetReportCount(inIOHIDElementRef);
		printf("report: { ID: %lu, Size: %lu, Count: %lu }, ",
		       (long unsigned int) reportID, (long unsigned int) reportSize, (long unsigned int) reportCount);
		
		uint32_t unit    = IOHIDElementGetUnit(inIOHIDElementRef);
		uint32_t unitExp = IOHIDElementGetUnitExponent(inIOHIDElementRef);
		if (unit || unitExp) {
			printf("unit: %lu * 10^%lu, ", (long unsigned int) unit, (long unsigned int) unitExp);
		}
		
		CFIndex logicalMin = IOHIDElementGetLogicalMin(inIOHIDElementRef);
		CFIndex logicalMax = IOHIDElementGetLogicalMax(inIOHIDElementRef);
		if (logicalMin != logicalMax) {
			printf("logical: {min: %ld, max: %ld}, ", logicalMin, logicalMax);
		}
		
		CFIndex physicalMin = IOHIDElementGetPhysicalMin(inIOHIDElementRef);
		CFIndex physicalMax = IOHIDElementGetPhysicalMax(inIOHIDElementRef);
		if (physicalMin != physicalMax) {
			printf("physical: {min: %ld, max: %ld}, ", physicalMin, physicalMax);
开发者ID:Vincent7,项目名称:CocoaSampleCode,代码行数:67,代码来源:HID_Utilities.c

示例7: setGourceDefaults


//.........这里部分代码省略.........
        user_image_dir = entry->getString();

        //append slash
        if(user_image_dir[user_image_dir.size()-1] != '/') {
            user_image_dir += std::string("/");
        }

        //get jpg and png images in dir
        DIR *dp;
        struct dirent *dirp;

        user_image_map.clear();

        if((dp = opendir(gGourceSettings.user_image_dir.c_str())) != 0) {

            while ((dirp = readdir(dp)) != 0) {
                std::string dirfile = std::string(dirp->d_name);

                size_t extpos = 0;

                if(   (extpos=dirfile.rfind(".jpg"))  == std::string::npos
                && (extpos=dirfile.rfind(".jpeg")) == std::string::npos
                && (extpos=dirfile.rfind(".png"))  == std::string::npos) continue;


                std::string image_path = gGourceSettings.user_image_dir + dirfile;
                std::string name       = dirfile.substr(0,extpos);

#ifdef __APPLE__
                CFMutableStringRef help = CFStringCreateMutable(kCFAllocatorDefault, 0);
                CFStringAppendCString(help, name.c_str(), kCFStringEncodingUTF8);
                CFStringNormalize(help, kCFStringNormalizationFormC);
                char data[4096];
                CFStringGetCString(help,
                                   data,
                                   sizeof(data),
                                   kCFStringEncodingUTF8);
                name = data;
#endif

                debugLog("%s => %s", name.c_str(), image_path.c_str());

                user_image_map[name] = image_path;
            }

            closedir(dp);
        }
    }

    if((entry = gource_settings->getEntry("caption-file")) != 0) {

        if(!entry->hasValue()) conffile.entryException(entry, "specify caption file (filename)");

        caption_file = entry->getString();
    }

    if((entry = gource_settings->getEntry("caption-duration")) != 0) {

        if(!entry->hasValue()) conffile.entryException(entry, "specify caption duration (seconds)");

        caption_duration = entry->getFloat();

        if(caption_duration <= 0.0f) {
            conffile.invalidValueException(entry);
        }
    }
开发者ID:Frencil,项目名称:Gource,代码行数:67,代码来源:gource_settings.cpp

示例8: process_prefs

// ----------------------------------------------------------------------------
//	process_prefs
// ----------------------------------------------------------------------------
int process_prefs(struct vpn_params *params)
{

    char 			pathStr[MAXPATHLEN];
    SCPreferencesRef 		prefs = 0;
    CFPropertyListRef		servers_list;
    
    char 			text[512] = "";
  
    // open the prefs file
    prefs = SCPreferencesCreate(0, CFSTR("vpnd"), kRASServerPrefsFileName);
    if (prefs == NULL) {
        CFStringGetCString(kRASServerPrefsFileName, pathStr, MAXPATHLEN, kCFStringEncodingMacRoman);
        snprintf(text, sizeof(text), "Unable to read vpnd prefs file '%s'\n", pathStr);
        goto fail;
    }
    // get servers list from the plist
    servers_list = SCPreferencesGetValue(prefs, kRASServers);
    if (servers_list == NULL) {
        snprintf(text, sizeof(text), "Could not get servers dictionary\n");
        goto fail;
    }
    // retrieve the information for the given Server ID
    params->serverIDRef = CFStringCreateWithCString(0, params->server_id, kCFStringEncodingMacRoman);
    if (params->serverIDRef == NULL) {
        snprintf(text, sizeof(text), "Could not create CFString for server ID\n");
        goto fail;
    }
    params->serverRef = CFDictionaryGetValue(servers_list, params->serverIDRef);
    if (params->serverRef == NULL || isDictionary(params->serverRef) == 0) {
        snprintf(text, sizeof(text), "Server ID '%.64s' invalid\n", params->server_id);
        params->serverRef = 0;
        goto fail;
    }
    CFRetain(params->serverRef);
    CFRelease(prefs);
    prefs = 0;    
    
    // process the dictionaries
    if (process_server_prefs(params))
        goto fail;
    if (process_interface_prefs(params))
        goto fail;
	
	switch (params->server_type) {
		case SERVER_TYPE_PPP:
			if (ppp_process_prefs(params)) {
				snprintf(text, sizeof(text), "Error while reading PPP preferences\n");
				goto fail;
			}
			break;
		case SERVER_TYPE_IPSEC:
			if (ipsec_process_prefs(params)) {
				snprintf(text, sizeof(text), "Error while reading IPSec preferences\n");
				goto fail;
			}
			break;
	}

    return 0;

fail:
    vpnlog(LOG_ERR, text[0] ? text : "Error while reading preferences\n");
    if (params->serverIDRef) {
        CFRelease(params->serverIDRef);
        params->serverIDRef = 0;
    }
    if (params->serverRef) {
        CFRelease(params->serverRef);
        params->serverRef = 0;
    }
    if (prefs)
        CFRelease(prefs);
    return -1;
}
开发者ID:Deanzou,项目名称:ppp,代码行数:78,代码来源:vpnoptions.c

示例9:

CF_PRIVATE void *_CFBundleDLLGetSymbolByName(CFBundleRef bundle, CFStringRef symbolName) {
    void *result = NULL;
    char buff[1024];
    if (CFStringGetCString(symbolName, buff, 1024, kCFStringEncodingWindowsLatin1)) result = GetProcAddress(bundle->_hModule, buff);
    return result;
}
开发者ID:parkera,项目名称:swift-corelibs-foundation,代码行数:6,代码来源:CFBundle_Binary.c

示例10: disk_read

static int disk_read (void)
{
#if HAVE_IOKIT_IOKITLIB_H
	io_registry_entry_t	disk;
	io_registry_entry_t	disk_child;
	io_iterator_t		disk_list;
	CFDictionaryRef		props_dict;
	CFDictionaryRef		stats_dict;
	CFDictionaryRef		child_dict;
	CFStringRef		tmp_cf_string_ref;
	kern_return_t		status;

	signed long long read_ops;
	signed long long read_byt;
	signed long long read_tme;
	signed long long write_ops;
	signed long long write_byt;
	signed long long write_tme;

	int  disk_major;
	int  disk_minor;
	char disk_name[DATA_MAX_NAME_LEN];
	char disk_name_bsd[DATA_MAX_NAME_LEN];

	/* Get the list of all disk objects. */
	if (IOServiceGetMatchingServices (io_master_port,
				IOServiceMatching (kIOBlockStorageDriverClass),
				&disk_list) != kIOReturnSuccess)
	{
		ERROR ("disk plugin: IOServiceGetMatchingServices failed.");
		return (-1);
	}

	while ((disk = IOIteratorNext (disk_list)) != 0)
	{
		props_dict = NULL;
		stats_dict = NULL;
		child_dict = NULL;

		/* `disk_child' must be released */
		if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child))
			       	!= kIOReturnSuccess)
		{
			/* This fails for example for DVD/CD drives.. */
			DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status);
			IOObjectRelease (disk);
			continue;
		}

		/* We create `props_dict' => we need to release it later */
		if (IORegistryEntryCreateCFProperties (disk,
					(CFMutableDictionaryRef *) &props_dict,
					kCFAllocatorDefault,
					kNilOptions)
				!= kIOReturnSuccess)
		{
			ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
			IOObjectRelease (disk_child);
			IOObjectRelease (disk);
			continue;
		}

		if (props_dict == NULL)
		{
			DEBUG ("IORegistryEntryCreateCFProperties (disk) failed.");
			IOObjectRelease (disk_child);
			IOObjectRelease (disk);
			continue;
		}

		/* tmp_cf_string_ref doesn't need to be released. */
		tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict,
				CFSTR(kIOBSDNameKey));
		if (!tmp_cf_string_ref)
		{
			DEBUG ("disk plugin: CFDictionaryGetValue("
					"kIOBSDNameKey) failed.");
			CFRelease (props_dict);
			IOObjectRelease (disk_child);
			IOObjectRelease (disk);
			continue;
		}
		assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());

		memset (disk_name_bsd, 0, sizeof (disk_name_bsd));
		CFStringGetCString (tmp_cf_string_ref,
				disk_name_bsd, sizeof (disk_name_bsd),
				kCFStringEncodingUTF8);
		if (disk_name_bsd[0] == 0)
		{
			ERROR ("disk plugin: CFStringGetCString() failed.");
			CFRelease (props_dict);
			IOObjectRelease (disk_child);
			IOObjectRelease (disk);
			continue;
		}
		DEBUG ("disk plugin: disk_name_bsd = \"%s\"", disk_name_bsd);

		stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict,
				CFSTR (kIOBlockStorageDriverStatisticsKey));
//.........这里部分代码省略.........
开发者ID:zach14c,项目名称:collectd,代码行数:101,代码来源:disk.c

示例11: sizeof


//.........这里部分代码省略.........

	dwRetVal = GetNetworkParams( fixedInfo, &ulOutBufLen );
	uint8_t buf2[ulOutBufLen];
	if(ERROR_BUFFER_OVERFLOW == dwRetVal)
	{
		fixedInfo = (FIXED_INFO *)buf2;
	}

	if ((dwRetVal = GetNetworkParams( fixedInfo, &ulOutBufLen )) != 0)
		LOG_ERROR("Call to GetNetworkParams failed. Return Value: %08lx\n", dwRetVal);
	else
	{
		m_DnsServers.push_back(IPv4Address(fixedInfo->DnsServerList.IpAddress.String));
		int i = 1;
		LOG_DEBUG("Default DNS server IP #%d: %s\n", i++, fixedInfo->DnsServerList.IpAddress.String );

		pIPAddr = fixedInfo->DnsServerList.Next;
		while ( pIPAddr )
		{
			m_DnsServers.push_back(IPv4Address(pIPAddr->IpAddress.String));
			LOG_DEBUG("Default DNS server IP #%d: %s\n", i++, pIPAddr->IpAddress.String);
			pIPAddr = pIPAddr -> Next;
		}
	}
#elif LINUX
	std::string command = "nmcli dev list | grep IP4.DNS";
	std::string dnsServersInfo = executeShellCommand(command);
	if (dnsServersInfo == "")
	{
		LOG_DEBUG("Error retrieving DNS server list: call to nmcli gave no output");
		return;
	}

	std::istringstream stream(dnsServersInfo);
	std::string line;
	int i = 1;
	while(std::getline(stream, line))
	{
		std::istringstream lineStream(line);
		std::string headline;
		std::string dnsIP;
		lineStream >> headline;
		lineStream >> dnsIP;
		IPv4Address dnsIPAddr(dnsIP);
		if (!dnsIPAddr.isValid())
			continue;

		if (std::find(m_DnsServers.begin(), m_DnsServers.end(), dnsIPAddr) == m_DnsServers.end())
		{
			m_DnsServers.push_back(dnsIPAddr);
			LOG_DEBUG("Default DNS server IP #%d: %s\n", i++, dnsIPAddr.toString().c_str());
		}
	}
#elif MAC_OS_X

	SCDynamicStoreRef dynRef = SCDynamicStoreCreate(kCFAllocatorSystemDefault, CFSTR("iked"), NULL, NULL);
	if (dynRef == NULL)
	{
		LOG_DEBUG("Couldn't set DNS server list: failed to retrieve SCDynamicStore");
		return;
	}

	CFDictionaryRef dnsDict = (CFDictionaryRef)SCDynamicStoreCopyValue(dynRef,CFSTR("State:/Network/Global/DNS"));

	if (dnsDict == NULL)
	{
		LOG_DEBUG("Couldn't set DNS server list: failed to get DNS dictionary");
		CFRelease(dynRef);
		return;
	}

	CFArrayRef serverAddresses = (CFArrayRef)CFDictionaryGetValue(dnsDict, CFSTR("ServerAddresses"));

	if (serverAddresses == NULL)
	{
		LOG_DEBUG("Couldn't set DNS server list: server addresses array is null");
		CFRelease(dynRef);
		CFRelease(dnsDict);
		return;
	}

	CFIndex count = CFArrayGetCount(serverAddresses);
	for (CFIndex i = 0; i < count; i++)
	{
		CFStringRef serverAddress = (CFStringRef)CFArrayGetValueAtIndex(serverAddresses, i);

		if (serverAddress == NULL)
			continue;

		uint8_t buf[20];
		char* serverAddressCString = (char*)buf;
		CFStringGetCString(serverAddress, serverAddressCString, 20, kCFStringEncodingUTF8);
		m_DnsServers.push_back(IPv4Address(serverAddressCString));
		LOG_DEBUG("Default DNS server IP #%d: %s\n", (int)(i+1), serverAddressCString);
	}

	CFRelease(dynRef);
	CFRelease(dnsDict);
#endif
}
开发者ID:HaochuanXJTU,项目名称:PcapPlusPlus,代码行数:101,代码来源:PcapLiveDeviceList.cpp

示例12: get_device_infos

//http://iphonedevwiki.net/index.php/Lockdownd
void get_device_infos(CFMutableDictionaryRef out) {
    CC_SHA1_CTX sha1ctx;
    uint8_t udid[20];
    char udid1[100];
    CFStringRef serial;
    CFStringRef imei;
    CFStringRef macwifi;
    CFStringRef macbt;
    
    CFStringRef hw = copy_hardware_model(); 
    if (hw != NULL)
    {
        CFDictionaryAddValue(out, CFSTR("hwModel"), hw);
        CFRelease(hw);
    }
    
    serial = copy_device_serial_number();
    imei = copy_device_imei();
    macwifi = copy_wifi_mac_address();
    macbt = copy_bluetooth_mac_address();
    
    CFMutableStringRef udidInput = CFStringCreateMutable(kCFAllocatorDefault, 0);
    if (serial != NULL)
    {
        CFStringAppend(udidInput, serial);
        CFDictionaryAddValue(out, CFSTR("serialNumber"), serial);
        CFRelease(serial);
    }
    
    uint64_t _ecid = 0;
    CFNumberRef ecid = copyNumberFromChosen(CFSTR("unique-chip-id"));
    if (ecid != NULL)
    {
        CFDictionaryAddValue(out, CFSTR("ECID"), ecid);
    }
    
    if (ecid != NULL && useNewUDID(hw))
    {
        CFNumberGetValue(ecid, kCFNumberSInt64Type, &_ecid);
        CFStringAppendFormat(udidInput, NULL, CFSTR("%llu"), _ecid);
    }
    else if (imei != NULL)
    {
        CFStringAppend(udidInput, imei);
        CFDictionaryAddValue(out, CFSTR("imei"), imei);
        CFRelease(imei);
    }
    if (macwifi != NULL)
    {
        CFStringAppend(udidInput, macwifi);
        CFDictionaryAddValue(out, CFSTR("wifiMac"), macwifi);
        CFRelease(macwifi);
    }
    if (macbt != NULL)
    {
        CFStringAppend(udidInput, macbt);
        CFDictionaryAddValue(out, CFSTR("btMac"), macbt);
        CFRelease(macbt);
    }
    
    CFStringGetCString(udidInput, udid1, 99, kCFStringEncodingASCII);
    
    CC_SHA1_Init(&sha1ctx);
    CC_SHA1_Update(&sha1ctx, udid1, CFStringGetLength(udidInput));
    CC_SHA1_Final(udid, &sha1ctx);
    
    CFRelease(udidInput);
    addHexaString(out, CFSTR("udid"), udid, 20);

}
开发者ID:0bj3ct1veC,项目名称:iphone-dataprotection,代码行数:71,代码来源:registry.c

示例13: GetScrapByName

//-----------------------------------------------------------------------------
const char* Platform::getClipboard()
{
    // mac clipboards can contain multiple items,
    //  and each item can be in several differnt flavors,
    //  such as unicode or plaintext or pdf, etc.
    // scan through the clipboard, and return the 1st piece of actual text.
    ScrapRef    clip;
    char        *retBuf = "";
    OSStatus    err = noErr;
    char        *dataBuf = "";

    // get a local ref to the system clipboard
    GetScrapByName( kScrapClipboardScrap, kScrapGetNamedScrap, &clip );


    // First try to get unicode data, then try to get plain text data.
    Size dataSize = 0;
    bool plaintext = false;
    err = GetScrapFlavorSize(clip, kScrapFlavorTypeUnicode, &dataSize);
    if( err != noErr || dataSize <= 0)
    {
        Con::errorf("some error getting unicode clip");
        plaintext = true;
        err = GetScrapFlavorSize(clip, kScrapFlavorTypeText, &dataSize);
    }

    // kick out if we don't have any data.
    if( err != noErr || dataSize <= 0)
    {
        Con::errorf("no data, kicking out. size = %i",dataSize);
        return "";
    }

    if( err == noErr && dataSize > 0 )
    {
        // ok, we've got something! allocate a buffer and copy it in.
        char buf[dataSize+1];
        dMemset(buf, 0, dataSize+1);
        dataBuf = buf;
        // plain text needs no conversion.
        // unicode data needs to be converted to normalized utf-8 format.
        if(plaintext)
        {
            GetScrapFlavorData(clip, kScrapFlavorTypeText, &dataSize, &buf);
            retBuf = Con::getReturnBuffer(dataSize + 1);
            dMemcpy(retBuf,buf,dataSize);
        }
        else
        {
            GetScrapFlavorData(clip, kScrapFlavorTypeUnicode, &dataSize, &buf);

            // normalize
            CFStringRef cfBuf = CFStringCreateWithBytes(NULL, (const UInt8*)buf, dataSize, kCFStringEncodingUnicode, false);
            CFMutableStringRef normBuf = CFStringCreateMutableCopy(NULL, 0, cfBuf);
            CFStringNormalize(normBuf, kCFStringNormalizationFormC);

            // convert to utf-8
            U32 normBufLen = CFStringGetLength(normBuf);
            U32 retBufLen = CFStringGetMaximumSizeForEncoding(normBufLen,kCFStringEncodingUTF8) + 1; // +1 for the null terminator
            retBuf = Con::getReturnBuffer(retBufLen);
            CFStringGetCString( normBuf, retBuf, retBufLen, kCFStringEncodingUTF8);
            dataSize = retBufLen;
        }

        // manually null terminate, just in case.
        retBuf[dataSize] = 0;
    }

    // return the data, or the empty string if we did not find any data.
    return retBuf;
}
开发者ID:Bloodknight,项目名称:T3D-MIT-GMK-Port,代码行数:72,代码来源:macCarbInput.cpp

示例14: vprintf_stderr_common

static void vprintf_stderr_common(const char* format, va_list args)
{
#if USE(CF) && !OS(WINDOWS)
    if (strstr(format, "%@")) {
        CFStringRef cfFormat = CFStringCreateWithCString(NULL, format, kCFStringEncodingUTF8);

#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
        CFStringRef str = CFStringCreateWithFormatAndArguments(NULL, NULL, cfFormat, args);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
        CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8);
        char* buffer = (char*)malloc(length + 1);

        CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);

#if USE(APPLE_SYSTEM_LOG)
        asl_log(0, 0, ASL_LEVEL_NOTICE, "%s", buffer);
#endif
        fputs(buffer, stderr);

        free(buffer);
        CFRelease(str);
        CFRelease(cfFormat);
        return;
    }

#if USE(APPLE_SYSTEM_LOG)
    va_list copyOfArgs;
    va_copy(copyOfArgs, args);
    asl_vlog(0, 0, ASL_LEVEL_NOTICE, format, copyOfArgs);
    va_end(copyOfArgs);
#endif

    // Fall through to write to stderr in the same manner as other platforms.

#elif HAVE(ISDEBUGGERPRESENT)
    if (IsDebuggerPresent()) {
        size_t size = 1024;

        do {
            char* buffer = (char*)malloc(size);

            if (buffer == NULL)
                break;

            if (vsnprintf(buffer, size, format, args) != -1) {
                OutputDebugStringA(buffer);
                free(buffer);
                break;
            }

            free(buffer);
            size *= 2;
        } while (size > 1024);
    }
#endif
    vfprintf(stderr, format, args);
}
开发者ID:emutavchi,项目名称:WebKitForWayland,代码行数:62,代码来源:Assertions.cpp

示例15: hu_XMLSearchForProductNameByVendorProductID

/*************************************************************************
 *
 * hu_XMLSearchForProductNameByVendorProductID( inVendorID, inProductID, outCStr )
 *
 * Purpose: Find an product string in the <HID_device_usage_strings.plist> resource ( XML ) file
 *
 * Inputs: inVendorID - the elements vendor ID
 *			inProductID - the elements product ID
 *			outCStr		- address where result will be returned
 *
 * Returns: Boolean		- if successful
 */
static Boolean hu_XMLSearchForProductNameByVendorProductID(long inVendorID, long inProductID, char *outCStr) {
	Boolean results = FALSE;
	if ( !gUsageCFPropertyListRef ) {
		gUsageCFPropertyListRef =
		hu_XMLLoad(                                 CFSTR(
														  "HID_device_usage_strings"), CFSTR("plist") );
	}
	if ( gUsageCFPropertyListRef ) {
		if (
		    CFDictionaryGetTypeID() == CFGetTypeID(gUsageCFPropertyListRef) )
		{
			// first we make our vendor ID key
			CFStringRef vendorKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), inVendorID);
			if ( vendorKeyCFStringRef ) {
				// and use it to look up our vendor dictionary
				CFDictionaryRef vendorCFDictionaryRef;
				if (     CFDictionaryGetValueIfPresent(gUsageCFPropertyListRef, vendorKeyCFStringRef,
				                                       (const void **) &vendorCFDictionaryRef) )
				{
					// pull our vendor name our of that dictionary
					CFStringRef vendorCFStringRef = NULL;
					if ( CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, kNameKeyCFStringRef,
					                                   (const void **) &vendorCFStringRef) )
					{
#if FAKE_MISSING_NAMES
						CFRetain(vendorCFStringRef);    // so we can CFRelease it later
					} else {
						vendorCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR(
																									  "V: %@"), vendorKeyCFStringRef);
#endif
					}
					
					// now we make our product ID key
					CFStringRef productKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR(
																												  "%ld"), inProductID);
					if ( productKeyCFStringRef ) {
						// and use that key to look up our product dictionary in the vendor dictionary
						CFDictionaryRef productCFDictionaryRef;
						if (     CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, productKeyCFStringRef,
						                                       (const void **) &productCFDictionaryRef) )
						{
							// pull our product name our of the product dictionary
							CFStringRef productCFStringRef = NULL;
							if ( CFDictionaryGetValueIfPresent(productCFDictionaryRef, kNameKeyCFStringRef,
							                                   (const void **) &productCFStringRef) )
							{
#if FAKE_MISSING_NAMES
								CFRetain(productCFStringRef);   // so we can CFRelease it later
							} else {
								productCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR(
																											   "P: %@"), kNameKeyCFStringRef);
#endif
							}
							
							CFStringRef fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR(
																													"%@ %@"), vendorCFStringRef,
							                                                       productCFStringRef);
							if ( fullCFStringRef ) {
								// CFShow( fullCFStringRef );
								results =
								CFStringGetCString(fullCFStringRef, outCStr, CFStringGetLength(
																							   fullCFStringRef) * sizeof(UniChar) + 1, kCFStringEncodingUTF8);
								CFRelease(fullCFStringRef);
							}
							
#if FAKE_MISSING_NAMES
							if ( productCFStringRef ) {
								CFRelease(productCFStringRef);
							}
							
#endif
						}
						
						CFRelease(productKeyCFStringRef);
					}
					
#if FAKE_MISSING_NAMES
					if ( vendorCFStringRef ) {
						CFRelease(vendorCFStringRef);
					}
					
#endif
				}
				
				CFRelease(vendorKeyCFStringRef);
			}
		}
		
//.........这里部分代码省略.........
开发者ID:CarlKenner,项目名称:gz3doom,代码行数:101,代码来源:HID_Name_Lookup.c


注:本文中的CFStringGetCString函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。