Пример #1
0
/*! Looks up the session identifier associated with a particular target name.
 *  @param targetIQN the IQN name of the target (e.q., iqn.2015-01.com.example)
 *  @return sessionId the session identifier. */
SID iSCSIKernelGetSessionIdForTargetIQN(CFStringRef targetIQN)
{
    if(!targetIQN)
        return kiSCSIInvalidSessionId;
    
    const UInt32 expOutputCnt = 1;
    UInt64 output[expOutputCnt];
    UInt32 outputCnt = expOutputCnt;

    kern_return_t result = IOConnectCallMethod(
        connection,
        kiSCSIGetSessionIdForTargetIQN,0,0,
        (const void*)CFStringGetCStringPtr(targetIQN,kCFStringEncodingASCII),
        CFStringGetLength(targetIQN)+1,
        output,&outputCnt,0,0);
    
    if(result == kIOReturnSuccess && outputCnt == expOutputCnt)
        return (SID)output[0];
    
    return kiSCSIInvalidSessionId;
}
Пример #2
0
int stransport_error(OSStatus ret)
{
	CFStringRef message;

	if (ret == noErr || ret == errSSLClosedGraceful) {
		giterr_clear();
		return 0;
	}

#if !TARGET_OS_IPHONE
	message = SecCopyErrorMessageString(ret, NULL);
	GITERR_CHECK_ALLOC(message);

	giterr_set(GITERR_NET, "SecureTransport error: %s", CFStringGetCStringPtr(message, kCFStringEncodingUTF8));
	CFRelease(message);
#else
    giterr_set(GITERR_NET, "SecureTransport error: OSStatus %d", (unsigned int)ret);
#endif

	return -1;
}
Пример #3
0
OSErr AEDescCreateUTF8Text(CFStringRef string, AEDesc* outDescPtr)
{
	OSErr err = noErr;
	CFStringEncoding kEncoding = kCFStringEncodingUTF8;
	DescType resultType = typeUTF8Text;
	const char *constBuff = CFStringGetCStringPtr(string, kEncoding);
	if (constBuff == NULL) {
		char *buffer;
		CFIndex charLen = CFStringGetLength(string);
		CFIndex maxLen = CFStringGetMaximumSizeForEncoding(charLen, kEncoding)+1; // +1 is for null termination.
		buffer = malloc(sizeof(char)*maxLen);
		CFStringGetCString(string, buffer, maxLen, kEncoding);
		err = AECreateDesc(resultType, buffer, strlen(buffer), outDescPtr);
		free(buffer);
	}
	else {
		err=AECreateDesc(resultType, constBuff, strlen(constBuff), outDescPtr);
	}
	
	return err;
}
Пример #4
0
bool outOfSpace(CFStringRef pathName)
{
	Boolean			validKey;
	unsigned int	minMeg;
	struct statfs	fileSys;
	
	minMeg = CFPreferencesGetAppIntegerValue(MINMEG_PREF_KEY,PREF_DOMAIN,&validKey);
	if (!validKey)
	{
		minMeg = DEFAULT_MEG;
		CFPreferencesSetAppValue(MINMEG_PREF_KEY,CFNumberCreate(kCFAllocatorDefault,kCFNumberIntType,&minMeg),PREF_DOMAIN);
	}

	if (statfs(CFStringGetCStringPtr(pathName,CFStringGetFastestEncoding(pathName)),&fileSys))
		return false;

	if ((fileSys.f_bsize/1024)*(fileSys.f_bavail/1024) < minMeg)
		return true;
		
	return false;
}
Пример #5
0
//! Get the serial number for a HID device
QString pjrc_rawhid::getserial(int num) {
    Q_UNUSED(num);

    QMutexLocker locker(m_readMutex);
    Q_UNUSED(locker);

    if (!device_open || unplugged)
        return "";

    CFTypeRef serialnum = IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDSerialNumberKey));
    if(serialnum && CFGetTypeID(serialnum) == CFStringGetTypeID())
    {
        //Note: I'm not sure it will always succeed if encoded as MacRoman but that
        //is a superset of UTF8 so I think this is fine
        CFStringRef str = (CFStringRef)serialnum;
        const char * buf = CFStringGetCStringPtr(str, kCFStringEncodingMacRoman);
        return QString(buf);
    }

    return QString("Error");
}
vector<string> DeckLinkController::getDeviceNameList()  {
	vector<string> nameList;
	int deviceIndex = 0;
	
	while (deviceIndex < deviceList.size()) {
		CFStringRef cfStrName;
		
		// Get the name of this device
		if (deviceList[deviceIndex]->GetDisplayName(&cfStrName) == S_OK) {
			nameList.push_back(string(CFStringGetCStringPtr(cfStrName, kCFStringEncodingMacRoman)));
			CFRelease(cfStrName);
		}
		else {
			nameList.push_back("DeckLink");
		}
		
		deviceIndex++;
	}
	
	return nameList;
}
Пример #7
0
/* new in 10.6 */
SecPolicyRef
SecPolicyCreateSSL(Boolean server, CFStringRef hostname)
{
    // return a SecPolicyRef object for the SSL policy, given hostname and client options
    SecPolicyRef policy = nil;
    SecPolicySearchRef policySearch = nil;
    OSStatus status = SecPolicySearchCreate(CSSM_CERT_X_509v3, &CSSMOID_APPLE_TP_SSL, NULL, &policySearch);
    if (!status) {
        status = SecPolicySearchCopyNext(policySearch, &policy);
    }
    if (!status && policy) {
        // set options for client-side or server-side policy evaluation
		char *strbuf = NULL;
		const char *hostnamestr = NULL;
		if (hostname) {
			CFIndex strbuflen = 0;
			hostnamestr = CFStringGetCStringPtr(hostname, kCFStringEncodingUTF8);
			if (hostnamestr == NULL) {
				strbuflen = CFStringGetLength(hostname)*6;
				strbuf = (char *)malloc(strbuflen+1);
				if (CFStringGetCString(hostname, strbuf, strbuflen, kCFStringEncodingUTF8)) {
					hostnamestr = strbuf;
				}
			}
		}
        uint32 hostnamelen = (hostnamestr) ? strlen(hostnamestr) : 0;
        uint32 flags = (!server) ? CSSM_APPLE_TP_SSL_CLIENT : 0;
        CSSM_APPLE_TP_SSL_OPTIONS opts = {CSSM_APPLE_TP_SSL_OPTS_VERSION, hostnamelen, hostnamestr, flags};
        CSSM_DATA data = {sizeof(opts), (uint8*)&opts};
        SecPolicySetValue(policy, &data);
		
		if (strbuf) {
			free(strbuf);
		}
    }
	if (policySearch) {
		CFRelease(policySearch);
	}
    return policy;
}
Пример #8
0
void mount_developer_image(AMDeviceRef device) {
    CFStringRef ds_path = copy_device_support_path(device);
    CFStringRef image_path = copy_developer_disk_image_path(device);
    CFStringRef sig_path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@.signature"), image_path);
    CFRelease(ds_path);

    if (verbose) {
        printf("Device support path: ");
        fflush(stdout);
        CFShow(ds_path);
        printf("Developer disk image: ");
        fflush(stdout);
        CFShow(image_path);
    }

    FILE* sig = fopen(CFStringGetCStringPtr(sig_path, kCFStringEncodingMacRoman), "rb");
    void *sig_buf = malloc(128);
    assert(fread(sig_buf, 1, 128, sig) == 128);
    fclose(sig);
    CFDataRef sig_data = CFDataCreateWithBytesNoCopy(NULL, sig_buf, 128, NULL);
    CFRelease(sig_path);

    CFTypeRef keys[] = { CFSTR("ImageSignature"), CFSTR("ImageType") };
    CFTypeRef values[] = { sig_data, CFSTR("Developer") };
    CFDictionaryRef options = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    CFRelease(sig_data);

    int result = AMDeviceMountImage(device, image_path, options, &mount_callback, 0);
    if (result == 0) {
        printf("[ 95%%] Developer disk image mounted successfully\n");
    } else if (result == 0xe8000076 /* already mounted */) {
        printf("[ 95%%] Developer disk image already mounted\n");
    } else {
        printf("[ !! ] Unable to mount developer disk image. (%x)\n", result);
        exit(1);
    }

    CFRelease(image_path);
    CFRelease(options);
}
/* return AD realm if it exists */
const char *get_ad_realm ( struct auth_request *auth_request )
{
	const char *out_realm = NULL;

	SCDynamicStoreRef store = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("dovecot.digest.auth"), NULL, NULL);
	if ( store ) {
		CFDictionaryRef dict = SCDynamicStoreCopyValue(store, CFSTR("com.apple.opendirectoryd.ActiveDirectory"));
		if (dict) {
			CFStringRef domain = CFDictionaryGetValue(dict, CFSTR("DomainNameFlat"));
			if (domain) {
				const char *ad_realm = CFStringGetCStringPtr(domain, kCFStringEncodingUTF8);
				if (ad_realm) {
					auth_request_log_info(auth_request, "digest-md5", "ad realm: %s", ad_realm);
					out_realm = t_strdup(ad_realm);
				}
			}
			CFRelease(dict);
		}
		CFRelease(store);
	}
	return( out_realm );
}
Пример #10
0
static FILE* ios_open_from_bundle(const char path[], const char* perm) {
    // Get a reference to the main bundle
    CFBundleRef mainBundle = CFBundleGetMainBundle();

    // Get a reference to the file's URL
    CFStringRef pathRef = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8);
    CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle, pathRef, NULL, NULL);
    if (!imageURL) {
        return nullptr;
    }

    // Convert the URL reference into a string reference
    CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL, kCFURLPOSIXPathStyle);

    // Get the system encoding method
    CFStringEncoding encodingMethod = CFStringGetSystemEncoding();

    // Convert the string reference into a C string
    const char *finalPath = CFStringGetCStringPtr(imagePath, encodingMethod);

    return fopen(finalPath, perm);
}
Пример #11
0
/**
 * Get the location for global or user-local support files.
 * @return NULL if it could not be determined
 */
char *Bgetsupportdir(int global)
{
    char *dir = NULL;
    
#ifdef __APPLE__
	FSRef ref;
	CFStringRef str;
	CFURLRef base;
	const char *s;
	
	if (FSFindFolder(global ? kLocalDomain : kUserDomain,
					 kApplicationSupportFolderType,
					 kDontCreateFolder, &ref) < 0) return NULL;

	base = CFURLCreateFromFSRef(NULL, &ref);
	if (!base) {
        return NULL;
    }
    
	str = CFURLCopyFileSystemPath(base, kCFURLPOSIXPathStyle);
	CFRelease(base);
	if (!str) {
        return NULL;
    }
    
	s = CFStringGetCStringPtr(str, CFStringGetSystemEncoding());
	if (s) {
        dir = strdup(s);
    }
	CFRelease(str);

#else
    if (!global) {
        dir = Bgethomedir();
    }
#endif
    
	return dir;
}
Пример #12
0
const void *subsurface_get_conf(char *name, pref_type_t type)
{
	CFStringRef dict_entry;

	/* if no settings exist, we return the value for FALSE */
	if (!propertyList)
		return NULL;

	switch (type) {
	case PREF_BOOL:
		dict_entry = CFDictionaryGetValue(propertyList, CFSTR_VAR(name));
		if (dict_entry && ! CFStringCompare(CFSTR("1"), dict_entry, 0))
			return (void *) 1;
		else
			return NULL;
	case PREF_STRING:
		return CFStringGetCStringPtr(CFDictionaryGetValue(propertyList,
						CFSTR_VAR(name)), kCFStringEncodingMacRoman);
	}
	/* we shouldn't get here, but having this line makes the compiler happy */
	return NULL;
}
static IOReturn
PrintSpeedForDisc ( io_object_t opticalMedia )
{
	
	IOReturn				error 		= kIOReturnError;
	CFMutableDictionaryRef	properties 	= NULL;
	CFStringRef				bsdNode		= NULL;
	const char *			bsdName		= NULL;
	
	error = IORegistryEntryCreateCFProperties ( opticalMedia,
												&properties,
												kCFAllocatorDefault,
												kNilOptions );
	require ( ( error == kIOReturnSuccess ), ErrorExit );
	
	bsdNode = ( CFStringRef ) CFDictionaryGetValue ( properties, CFSTR ( kIOBSDNameKey ) );
	require ( ( bsdNode != NULL ), ReleaseProperties );
	
	bsdName = CFStringGetCStringPtr ( bsdNode, CFStringGetSystemEncoding ( ) );
	require ( ( bsdName != NULL ), ReleaseProperties );
	
	error = PrintSpeedForBSDNode ( bsdName );
	require ( ( error == kIOReturnSuccess ), ReleaseProperties );
	
	
ReleaseProperties:
	
	
	require_quiet ( ( properties != NULL ), ErrorExit );
	CFRelease ( properties );
	properties = NULL;
	
	
ErrorExit:
	
	
	return error;
	
}
Пример #14
0
static char *
cfstring2cstring(CFStringRef string)
{
    CFIndex len;
    char *str;

    str = (char *) CFStringGetCStringPtr(string, kCFStringEncodingUTF8);
    if (str)
        return strdup(str);

    len = CFStringGetLength(string);
    len = 1 + CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8);
    str = malloc(len);
    if (str == NULL)
        return NULL;

    if (!CFStringGetCString (string, str, len, kCFStringEncodingUTF8)) {
        free (str);
        return NULL;
    }
    return str;
}
Пример #15
0
ST_FUNC ST_Error ST_ID3v1_setYearStr(ST_ID3v1 *tag, CFStringRef s) {
    char *prev = tag->year;
    const char *str;
    char tmp[5];

    /* Make sure they aren't doing anything screwy */
    if(!tag || tag->base.type != ST_TagType_ID3v1)
        return ST_Error_InvalidArgument;
    else if(CFStringGetLength(s) != 4)
        return ST_Error_InvalidArgument;

    if(!s) {
        free(tag->year);
        tag->year = NULL;
        return ST_Error_None;
    }

    /* Grab the ISO-8859-1 representation of the string */
    if(!(str = CFStringGetCStringPtr(s, kCFStringEncodingISOLatin1))) {
        if(!CFStringGetCString(s, tmp, 5, kCFStringEncodingISOLatin1))
            return ST_Error_InvalidEncoding;

        str = tmp;
    }

    /* One last sanity check... */
    if(strlen(str) != 4 || (!is_8859digit(str[0]) || !is_8859digit(str[1]) ||
                            !is_8859digit(str[2]) || !is_8859digit(str[3])))
        return ST_Error_InvalidArgument;

    /* Copy it in */
    if((tag->year = strdup(str))) {
        free(prev);
        return ST_Error_None;
    }

    tag->year = prev;
    return ST_Error_errno;
}
static CFDataRef
digestString(CFStringRef str)
{
	CFDataRef retval = NULL;
 	CFErrorRef error = NULL;
    
    CFDataRef inputString = CFStringCreateExternalRepresentation(kCFAllocatorDefault, str, kCFStringEncodingUTF8, 0xff);
    
    SecTransformRef	digestTrans = SecDigestTransformCreate(kSecDigestSHA2, 256, &error);
    if(error == NULL) {
        SecTransformSetAttribute(digestTrans, kSecTransformInputAttributeName, inputString, &error);
        if(error == NULL) {
        	retval = SecTransformExecute(digestTrans, &error);
            if(retval == NULL) {
                secDebug(ASL_LEVEL_ERR, "Couldn't create digest %s\n", CFStringGetCStringPtr(CFErrorCopyFailureReason(error), kCFStringEncodingUTF8));
            }
        }
        CFRelease(digestTrans);
    }
    CFRelease(inputString);
    return retval;
}
Пример #17
0
QString ScPaths::bundleDir(void) const
{
	// On MacOS/X, override the compile-time settings with a location
// obtained from the system.
#ifdef Q_WS_MAC
	// Set up the various app paths to look inside the app bundle
	CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
	CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
										   kCFURLPOSIXPathStyle);
	const char *pathPtr = CFStringGetCStringPtr(macPath,
										   CFStringGetSystemEncoding());

	// make sure we get the Scribus.app directory, not some subdir

	// strip trailing '/':
	char *p = const_cast<char*>(pathPtr + strlen(pathPtr) - 1);
	while (*p == '/')
		--p;
	++p;
	*p = '\0';
	if (strcmp("/bin", p-4) == 0) {
		p -= 4;
		*p = '\0';
	}
	if (strcmp("/MacOS", p-6) == 0) {
		p -= 6;
		*p = '\0';
	}
	if (strcmp("/Contents", p-9) == 0) {
		p -= 9;
		*p = '\0';
	}
	CFRelease(pluginRef);
	CFRelease(macPath);
	return QString("%1").arg(pathPtr);
#endif
	return QString::null;
}
Пример #18
0
static ST_Error setCFString(ST_ID3v1 *tag, char **ptr, CFStringRef s) {
    char *prev = *ptr;
    const char *str;
    char tmp[31];

    /* Make sure they aren't doing anything screwy */
    if(!tag || tag->base.type != ST_TagType_ID3v1)
        return ST_Error_InvalidArgument;
    else if(CFStringGetLength(s) > 30)
        return ST_Error_InvalidArgument;

    if(!s) {
        free(prev);
        *ptr = NULL;
        return ST_Error_None;
    }

    /* Grab the ISO-8859-1 representation of the string */
    if(!(str = CFStringGetCStringPtr(s, kCFStringEncodingISOLatin1))) {
        if(!CFStringGetCString(s, tmp, 31, kCFStringEncodingISOLatin1))
            return ST_Error_InvalidEncoding;

        str = tmp;
    }

    /* One last sanity check... */
    if(strlen(str) > 30)
        return ST_Error_InvalidArgument;

    /* Copy it in */
    if((*ptr = strdup(str))) {
        free(prev);
        return ST_Error_None;
    }

    *ptr = prev;
    return ST_Error_errno;
}
Пример #19
0
char *cfStringToChar(CFStringRef inStr)
{
    // Caller must free
    char *result = NULL;
    const char *str = NULL;

	if (!inStr)
        return strdup("");     // return a null string

	// quick path first
	if ((str = CFStringGetCStringPtr(inStr, kCFStringEncodingUTF8))) {
        result = strdup(str);
	} else {
        // need to extract into buffer
        CFIndex length = CFStringGetLength(inStr);  // in 16-bit character units
        CFIndex bytesToAllocate = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
        result = malloc(bytesToAllocate);
        if (!CFStringGetCString(inStr, result, bytesToAllocate, kCFStringEncodingUTF8))
            result[0] = 0;
    }
    
	return result;
}
Пример #20
0
/**
 * Creates a VuoText value from a @c CFStringRef.
 */
VuoText VuoText_makeFromMacString(CFStringRef cfString)
{
	// http://stackoverflow.com/questions/1609565/whats-the-cfstring-equiv-of-nsstrings-utf8string

	const char *useUTF8StringPtr = NULL;
	char *freeUTF8StringPtr = NULL;

	if ((useUTF8StringPtr = CFStringGetCStringPtr(cfString, kCFStringEncodingUTF8)) == NULL)
	{
		CFIndex stringLength = CFStringGetLength(cfString);
		CFIndex maxBytes = 4 * stringLength + 1;
		freeUTF8StringPtr = malloc(maxBytes);
		CFStringGetCString(cfString, freeUTF8StringPtr, maxBytes, kCFStringEncodingUTF8);
		useUTF8StringPtr = freeUTF8StringPtr;
	}

	VuoText text = VuoText_make(useUTF8StringPtr);

	if (freeUTF8StringPtr != NULL)
		free(freeUTF8StringPtr);

	return text;
}
Пример #21
0
const char * MYCFStringGetUTF8String(CFStringRef aString, 
                                     char **buffer) {
  if (aString == NULL) {
    return NULL;
  }
  
  const char *cstr = CFStringGetCStringPtr(aString, 
                                           kCFStringEncodingUTF8);
  if (cstr == NULL) {
    CFIndex length = CFStringGetLength(aString);
    CFIndex maxSize =
    CFStringGetMaximumSizeForEncoding(length,
                                      kCFStringEncodingUTF8) + 1; // +1 for NULL
    if (maxSize > malloc_size(buffer)) {
      *buffer = realloc(*buffer, maxSize);
    }
    if (CFStringGetCString(aString, *buffer, maxSize,
                           kCFStringEncodingUTF8)) {
      cstr = *buffer;
    }
  }
  return cstr;
}
PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(SharedBuffer* data)
{
    LOG(Archives, "LegacyWebArchive - Creating from raw data");
    
    RefPtr<LegacyWebArchive> archive = create();
        
    ASSERT(data);
    if (!data)
        return 0;
        
    RetainPtr<CFDataRef> cfData(AdoptCF, data->createCFData());
    if (!cfData)
        return 0;
        
    CFStringRef errorString = 0;
    
    RetainPtr<CFDictionaryRef> plist(AdoptCF, static_cast<CFDictionaryRef>(CFPropertyListCreateFromXMLData(0, cfData.get(), kCFPropertyListImmutable, &errorString)));
    if (!plist) {
#ifndef NDEBUG
        const char* cError = errorString ? CFStringGetCStringPtr(errorString, kCFStringEncodingUTF8) : "unknown error";
        LOG(Archives, "LegacyWebArchive - Error parsing PropertyList from archive data - %s", cError);
#endif
        if (errorString)
            CFRelease(errorString);
        return 0;
    }
    
    if (CFGetTypeID(plist.get()) != CFDictionaryGetTypeID()) {
        LOG(Archives, "LegacyWebArchive - Archive property list is not the expected CFDictionary, aborting invalid WebArchive");
        return 0;
    }
    
    if (!archive->extract(plist.get()))
        return 0;

    return archive.release();
}
Пример #23
0
char *Bgethomedir(void)
{
#ifdef _WIN32
	TCHAR appdata[MAX_PATH];

	if (SUCCEEDED(SHGetSpecialFolderPathA(NULL, appdata, CSIDL_APPDATA, FALSE)))
		return strdup(appdata);
	return NULL;
#elif defined __APPLE__
    
#if LOWANG_IOS
    const char* Sys_GetResourceDir(void);
	return strdup(Sys_GetResourceDir());
#else
    
	FSRef ref;
	CFStringRef str;
	CFURLRef base;
	char *s;

	if (FSFindFolder(kUserDomain, kVolumeRootFolderType, kDontCreateFolder, &ref) < 0) return NULL;
	base = CFURLCreateFromFSRef(NULL, &ref);
	if (!base) return NULL;
	str = CFURLCopyFileSystemPath(base, kCFURLPOSIXPathStyle);
	CFRelease(base);
	if (!str) return NULL;
	s = (char*)CFStringGetCStringPtr(str,CFStringGetSystemEncoding());
	if (s) s = strdup(s);
	CFRelease(str);
	return s;
#endif
#else
	char *e = getenv("HOME");
	if (!e) return NULL;
	return strdup(e);
#endif
}
static void listServices()
{
    IOHIDEventSystemClientRef eventSystem = IOHIDEventSystemClientCreateWithType(kCFAllocatorDefault, kIOHIDEventSystemClientTypeAdmin, NULL);
    CFArrayRef  services = NULL;
    CFIndex     index;
    
    require(eventSystem, exit);
    
    services = _IOHIDEventSystemClientCopyServiceDescriptions(eventSystem);
    require(services, exit);
    
    for ( index=0; index<CFArrayGetCount(services); index++ ) {
        CFStringRef serviceDebugDesc = (CFStringRef)CFArrayGetValueAtIndex(services, index);
        printf("%s\n", CFStringGetCStringPtr(serviceDebugDesc, CFStringGetSystemEncoding()));
    }
    
    
exit:
    if ( services )
        CFRelease(services);
    
    if (eventSystem)
        CFRelease(eventSystem);
}
static void servicesAddedCallback(void * target, void * refcon, void * sender, CFArrayRef services)
{
    CFIndex index, count;
    
    for(index=0, count = CFArrayGetCount(services); index<count; index++) {
        IOHIDServiceRef service = (IOHIDServiceRef)CFArrayGetValueAtIndex(services, index);
        CFStringRef string;
        
        IOHIDNotificationRef notification = IOHIDServiceCreateRemovalNotification(service, serviceRemovalCallback, NULL, NULL);
        if ( notification ) {
            CFDictionaryAddValue(__serviceNotifications, service, notification);
            CFRelease(notification);
        }
        
        printf("SERVICE %s:\n", (char *)kServiceAdded);
        
        string = CFCopyDescription(service);
        if ( string ) {
            printf("%s\n", CFStringGetCStringPtr(string, kCFStringEncodingMacRoman));
            CFRelease(string);
        }
    }
    
}
Пример #26
0
static PyObject*
cfstring_to_pystring(CFStringRef ref)
{
    const char* s;

    s = CFStringGetCStringPtr(ref, kCFStringEncodingUTF8);
    if (s) {
        return PyUnicode_DecodeUTF8(
                        s, strlen(s), NULL);

    } else {
        CFIndex len = CFStringGetLength(ref);
        Boolean ok;
        PyObject* result;
        char* buf;

        buf = PyMem_Malloc(len*4);
        if (buf == NULL) {
            PyErr_NoMemory();
            return NULL;
        }

        ok = CFStringGetCString(ref,
                        buf, len * 4,
                        kCFStringEncodingUTF8);
        if (!ok) {
            PyMem_Free(buf);
            return NULL;
        } else {
            result = PyUnicode_DecodeUTF8(
                            buf, strlen(buf), NULL);
            PyMem_Free(buf);
        }
        return result;
    }
}
Пример #27
0
void CCoreAudioHardware::GetOutputDeviceName(std::string& name)
{
    name = "Default";
    AudioDeviceID deviceId = GetDefaultOutputDevice();

    if (deviceId)
    {
        AudioObjectPropertyAddress  propertyAddress;
        propertyAddress.mScope    = kAudioObjectPropertyScopeGlobal;
        propertyAddress.mElement  = kAudioObjectPropertyElementMaster;
        propertyAddress.mSelector = kAudioObjectPropertyName;

        CFStringRef theDeviceName = NULL;
        UInt32 propertySize = sizeof(CFStringRef);
        OSStatus ret = AudioObjectGetPropertyData(deviceId, &propertyAddress, 0, NULL, &propertySize, &theDeviceName);
        if (ret != noErr)
            return;

        const char *cstr = CFStringGetCStringPtr(theDeviceName, kCFStringEncodingUTF8);
        if (cstr)
            name = cstr;
        CFRelease(theDeviceName);
    }
}
Пример #28
0
char *Bgetsupportdir(int global)
{
#ifndef __APPLE__
	return Bgethomedir();
#else
	FSRef ref;
	CFStringRef str;
	CFURLRef base;
	char *s;
	
	if (FSFindFolder(global ? kLocalDomain : kUserDomain,
					 kApplicationSupportFolderType,
					 kDontCreateFolder, &ref) < 0) return NULL;
	base = CFURLCreateFromFSRef(NULL, &ref);
	if (!base) return NULL;
	str = CFURLCopyFileSystemPath(base, kCFURLPOSIXPathStyle);
	CFRelease(base);
	if (!str) return NULL;
	s = (char*)CFStringGetCStringPtr(str,CFStringGetSystemEncoding());
	if (s) s = strdup(s);
	CFRelease(str);
	return s;
#endif
}
Пример #29
0
pid_t StartServer()
{
	pid_t pid = fork();

	if(pid == 0)
	{
		CFBundleRef bundle = CFBundleGetMainBundle();
		CFURLRef url = CFBundleCopyExecutableURL(bundle);

		CFStringRef urlString = CFURLCopyPath(url);

		const char *file = CFStringGetCStringPtr(urlString, kCFStringEncodingUTF8);
		const char *args[] = { file, "--start", NULL };

		execv(file, (char *const *)args);

		// Should not be reached, but let's exit gracefully anyway
		CFRelease(url);
		CFRelease(urlString);
		exit(EXIT_FAILURE);
	}

	return pid;
}
Пример #30
0
  QSettings mySettings;

  // For non static builds on mac and win (static builds are not supported)
  // we need to be sure we can find the qt image
  // plugins. In mac be sure to look in the
  // application bundle...
#ifdef Q_OS_WIN
  QCoreApplication::addLibraryPath( QApplication::applicationDirPath()
                                    + QDir::separator() + "qtplugins" );
#endif
#ifdef Q_OS_MACX
  //qDebug("Adding qt image plugins to plugin search path...");
  CFURLRef myBundleRef = CFBundleCopyBundleURL( CFBundleGetMainBundle() );
  CFStringRef myMacPath = CFURLCopyFileSystemPath( myBundleRef, kCFURLPOSIXPathStyle );
  const char *mypPathPtr = CFStringGetCStringPtr( myMacPath, CFStringGetSystemEncoding() );
  CFRelease( myBundleRef );
  CFRelease( myMacPath );
  QString myPath( mypPathPtr );
  // if we are not in a bundle assume that the app is built
  // as a non bundle app and that image plugins will be
  // in system Qt frameworks. If the app is a bundle
  // lets try to set the qt plugin search path...
  QFileInfo myInfo( myPath );
  if ( myInfo.isBundle() )
  {
    // First clear the plugin search paths so we can be sure
    // only plugins from the bundle are being used
    QStringList myPathList;
    QCoreApplication::setLibraryPaths( myPathList );
    // Now set the paths inside the bundle