void MacOSUnicodeConverter::lowerCase(XMLCh* const toLowerCase)
{
#if TARGET_API_MAC_CARBON

   // If we're targeting carbon, use the CFString conversion to uppercase
   int len = XMLString::stringLen(toLowerCase);
   CFMutableStringRef cfString = CFStringCreateMutableWithExternalCharactersNoCopy(
        kCFAllocatorDefault,
        (UniChar*)toLowerCase,
        len,		// length
        len,		// capacity
        kCFAllocatorNull);
   CFStringLowercase(cfString, NULL);
   CFRelease(cfString);

#elif (__GNUC__ >= 3 && _GLIBCPP_USE_WCHAR_T)

	// Use this if there's a reasonable c library available.
	// Metrowerks does this reasonably
	wchar_t c;
	for (XMLCh* p = (XMLCh*)toLowerCase; ((c = *p) != 0); )
		*p++ = std::towlower(c);

#else
	#error Sorry, no support for lowerCase
#endif
}
__private_extern__ CFStringRef _CFPreferencesGetByHostIdentifierString(void) {
    static CFStringRef __byHostIdentifierString = NULL;

    if (!__byHostIdentifierString) {
        CFStringRef hostID = _CFGetHostUUIDString();
        if (hostID) {
            if (CFStringHasPrefix(hostID, CFSTR("00000000-0000-1000-8000-"))) {
                // If the host UUID is prefixed by "00000000-0000-1000-8000-" then the UUID returned is the "compatible" type. The last field of the string will be the MAC address of the primary ethernet interface of the computer. We use this for compatibility with existing by-host preferences.
                CFStringRef lastField = CFStringCreateWithSubstring(kCFAllocatorSystemDefault, hostID, CFRangeMake(24, 12));
                CFMutableStringRef tmpstr = CFStringCreateMutableCopy(kCFAllocatorSystemDefault, 0, lastField);
                CFStringLowercase(tmpstr, NULL);
                CFStringRef downcasedField = CFStringCreateCopy(kCFAllocatorSystemDefault, tmpstr);
                
                if (!OSAtomicCompareAndSwapPtrBarrier(NULL, (void *)downcasedField, (void *)&__byHostIdentifierString)) {
                    CFRelease(downcasedField);
                }
                
                CFRelease(tmpstr);
                CFRelease(lastField);
            } else {
                // The host UUID is a full UUID, and we should just use that. This doesn't involve any additional string creation, so we should just be able to do the assignment.
                __byHostIdentifierString = hostID;
            }
        } else {
            __byHostIdentifierString = CFSTR("UnknownHostID");
        }
    }
    
    return __byHostIdentifierString;
}
Ejemplo n.º 3
0
void
GetServiceTypeToLookup(CFMutableStringRef * serviceString, UInt16 * serviceMenuItem)
{
    ControlID 		controlID = { kNSLSample, kServicesTypePopup };
    ControlRef		control;
    CFStringRef		outString;
    MenuRef		menu;
    SInt16		value;
    OSStatus		err;
    
    err = GetControlByID(gMainWindow, &controlID, &control);
    if (err == noErr)
    {
        value = GetControlValue(control);
        if (serviceString)
        {
            menu = GetControlPopupMenuHandle(control);
            if (menu)
            {
                CopyMenuItemTextAsCFString(menu, value, &outString);
                if (serviceString)
                {
                    *serviceString = CFStringCreateMutableCopy(NULL, CFStringGetLength(outString), outString);
                    CFStringLowercase(*serviceString, NULL);
                }
                if (outString) CFRelease(outString);
            }
        }
        
        if (serviceMenuItem) *serviceMenuItem = value;
    }
}
Ejemplo n.º 4
0
Boolean APSetKey(CFStringRef key)
{
    hash = CFSTR("");
    blacklist = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
    
    // Create a new key
    rsaKey = RSA_new();
    
    // Public exponent is always 3
    BN_hex2bn(&rsaKey->e, "3");
    
    CFMutableStringRef mutableKey = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, key);
    if (!mutableKey)
        return FALSE;
    
    CFIndex maximumCStringLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(mutableKey), kCFStringEncodingMacRoman) + 1;
    char *keyCStringBuffer = malloc(maximumCStringLength);
    
    // Determine if we have a hex or decimal key
    CFStringLowercase(mutableKey, NULL);
    if (CFStringHasPrefix(mutableKey, CFSTR("0x"))) {
        CFStringTrim(mutableKey, CFSTR("0x"));
        CFStringGetCString(mutableKey, keyCStringBuffer, maximumCStringLength, kCFStringEncodingMacRoman);
        BN_hex2bn(&rsaKey->n, keyCStringBuffer);
    }
    else {
        CFStringGetCString(mutableKey, keyCStringBuffer, maximumCStringLength, kCFStringEncodingMacRoman);
        BN_dec2bn(&rsaKey->n, keyCStringBuffer);
    }
    CFRelease(mutableKey);
    free(keyCStringBuffer);
    
    return TRUE;
}
Ejemplo n.º 5
0
rktio_char16_t *rktio_recase_utf16(rktio_t *rktio, rktio_bool_t to_up, rktio_char16_t *s1, intptr_t l1, intptr_t *olen)
{
#ifdef MACOS_UNICODE_SUPPORT
  CFMutableStringRef mstr;
  CFStringRef str;
  CFRange rng;
  rktio_char16_t *result;
  intptr_t len;

  str = CFStringCreateWithBytes(NULL, (unsigned char *)s1, (l1 * sizeof(rktio_char16_t)), kCFStringEncodingUnicode, FALSE);
  mstr = CFStringCreateMutableCopy(NULL, 0, str);
  CFRelease(str);

  if (to_up)
    CFStringUppercase(mstr, NULL);
  else
    CFStringLowercase(mstr, NULL);

  len = CFStringGetLength(mstr);

  result = malloc((len + 1) * sizeof(rktio_char16_t));

  rng = CFRangeMake(0, len);
  CFStringGetCharacters(mstr, rng, (UniChar *)result);
  CFRelease(mstr);

  result[len] = 0;

  if (olen)
    *olen = len;

  return result;
#elif defined(RKTIO_SYSTEM_WINDOWS)
  rktio_char16_t *result;
  
  result = malloc((l1 + 1) * sizeof(rktio_char16_t));
  memcpy(result, s1, l1 * sizeof(rktio_char16_t));
  result[l1] = 0;
  
  if (to_up)
    CharUpperBuffW((wchar_t *)result, l1);
  else
    CharLowerBuffW((wchar_t *)result, l1);

  if (olen)
    *olen = l1;

  return result;
#else
  return NULL;
#endif
}
Ejemplo n.º 6
0
Tcl_UniChar Tcl_UniCharToLower(Tcl_UniChar c)
{
    if (c < 0x7f)
	return tolower(c);
    CFMutableStringRef str = CFStringCreateMutableWithExternalCharactersNoCopy(kCFAllocatorDefault,&c, 1,0, kCFAllocatorNull);
    CFStringLowercase(str,NULL);
    Tcl_UniChar retval = c;
    if (CFStringGetLength(str)) { // make sure one exists
	retval = CFStringGetCharacterAtIndex(str, 0);
    }
    CFRelease(str);
    return retval;
}
Ejemplo n.º 7
0
/*++
Function:
  PAL_towlower

See MSDN

--*/
wchar_16
__cdecl
PAL_towlower( wchar_16 c )
{
#if HAVE_COREFOUNDATION
    PERF_ENTRY(towlower);
    ENTRY("towlower (c=%d)\n", c);
    if (!PAL_iswlower(c))
    {
        CFMutableStringRef cfString = CFStringCreateMutable(
                                            kCFAllocatorDefault, 1);
        if (cfString != NULL)
        {
            CFStringAppendCharacters(cfString, (const UniChar*)&c, 1);
            CFStringLowercase(cfString, NULL);
            c = CFStringGetCharacterAtIndex(cfString, 0);
            CFRelease(cfString);
        }
    }
    LOGEXIT("towlower returns int %d\n", c );
    PERF_EXIT(towlower);
    return c;
#else   /* HAVE_COREFOUNDATION */
    UnicodeDataRec dataRec;
    
    PERF_ENTRY(towlower);
    ENTRY("towlower (c=%d)\n", c);
    
    if (!GetUnicodeData(c, &dataRec))
    {
        TRACE( "Unable to retrieve unicode data for the character %c.\n", c );
        LOGEXIT("towlower returns int %d\n", c );
        PERF_EXIT(towlower);
        return c;
    }

    if ( (dataRec.C1_TYPE_FLAGS & C1_LOWER) || (dataRec.nOpposingCase ==  0 ))
    {
        LOGEXIT("towlower returns int %d\n", c );
        PERF_EXIT(towlower);
        return c;
    }
    else
    {
        LOGEXIT("towlower returns int %d\n", dataRec.nOpposingCase );
        PERF_EXIT(towlower);
        return dataRec.nOpposingCase;
    }
#endif  /* HAVE_COREFOUNDATION */
}
Ejemplo n.º 8
0
wchar_t
towlower (wchar_t wc)
{
    CFMutableStringRef strRef = CFStringCreateMutable (NULL, 0);
    UniChar c = (UniChar) wc;
    wchar_t wcs;

    CFStringAppendCharacters (strRef, &c, 1);
    CFStringLowercase (strRef, NULL);
    wcs = CFStringGetCharacterAtIndex (strRef, 0);
    CFRelease (strRef);

    return wcs;
}
static void convertWebResourceDataToString(CFMutableDictionaryRef resource)
{
    CFMutableStringRef mimeType = (CFMutableStringRef)CFDictionaryGetValue(resource, CFSTR("WebResourceMIMEType"));
    CFStringLowercase(mimeType, CFLocaleGetSystem());
    convertMIMEType(mimeType);

    CFArrayRef supportedMIMETypes = supportedNonImageMIMETypes();
    if (CFStringHasPrefix(mimeType, CFSTR("text/")) || CFArrayContainsValue(supportedMIMETypes, CFRangeMake(0, CFArrayGetCount(supportedMIMETypes)), mimeType)) {
        CFStringRef textEncodingName = static_cast<CFStringRef>(CFDictionaryGetValue(resource, CFSTR("WebResourceTextEncodingName")));
        CFStringEncoding stringEncoding;
        if (textEncodingName && CFStringGetLength(textEncodingName))
            stringEncoding = CFStringConvertIANACharSetNameToEncoding(textEncodingName);
        else
            stringEncoding = kCFStringEncodingUTF8;

        CFDataRef data = static_cast<CFDataRef>(CFDictionaryGetValue(resource, CFSTR("WebResourceData")));
        RetainPtr<CFStringRef> dataAsString = adoptCF(CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, data, stringEncoding));
        if (dataAsString)
            CFDictionarySetValue(resource, CFSTR("WebResourceData"), dataAsString.get());
    }
}
Ejemplo n.º 10
0
void stringManipulation(void) {
   
   CFMutableStringRef strChange;
   CFStringRef strOuter, find, replace, find2, replace2, find3, replace3, bigger, smaller, result;
   CFComparisonResult comp;
   CFLocaleRef curLocale;
   Boolean isHyphenationSupported = false;
   
   show(CFSTR("------------------String Manipulations---------------"));

   // Create a simple immutable string from a Pascal string and convert it to Unicode
   strOuter = CFStringCreateWithCString(NULL, "Hello Cruel World", kCFStringEncodingASCII);
   strChange = CFStringCreateMutableCopy(NULL, CFStringGetLength(strOuter), strOuter);
   find = CFStringCreateWithCString(NULL, "Cruel", kCFStringEncodingASCII);
   replace = CFStringCreateWithCString(NULL, "Cool", kCFStringEncodingASCII);
   find2 = CFStringCreateWithCString(NULL, "Keep", kCFStringEncodingASCII);
   replace2 = CFStringCreateWithCString(NULL, "Be", kCFStringEncodingASCII);
   find3 = CFStringCreateWithCString(NULL, "Change.", kCFStringEncodingASCII);
   replace3 = CFStringCreateWithCString(NULL, "Ball.", kCFStringEncodingASCII);

   bigger  = CFStringCreateWithCString(NULL, "version 2.5", kCFStringEncodingASCII);
   smaller = CFStringCreateWithCString(NULL, "version 2.0", kCFStringEncodingASCII);

   show(CFSTR("String Outer       : %@"), strOuter);
   show(CFSTR("String Find        : %@"), find);
   show(CFSTR("String Replace     : %@"), replace);
   
   CFStringFindAndReplace(strChange, find, replace, CFRangeMake(0, CFStringGetLength(strChange)), 0);
   
   show(CFSTR("Replaced           : %@"), strChange);
   
   CFStringAppendCString(strChange, "!  Keep the change.", kCFStringEncodingASCII);
   
   show(CFSTR("Appended           : %@"), strChange);
   
   curLocale = CFLocaleCopyCurrent ();

   isHyphenationSupported = CFStringIsHyphenationAvailableForLocale(curLocale);
   show(CFSTR("Is Hyphenation supported for this locale? %@"), ((isHyphenationSupported) ? CFSTR ("Yes") : CFSTR("No")));

   CFStringUppercase(strChange, curLocale);
   
   show(CFSTR("Upper Cased        : %@"), strChange);
   
   CFStringLowercase(strChange, curLocale);
   
   show(CFSTR("Lower Cased        : %@"), strChange);
   
   CFStringCapitalize(strChange, curLocale);
   
   show(CFSTR("Capitalized        : %@"), strChange);

   CFStringUppercase(strChange, curLocale);
   
   show(CFSTR("Up Cased (again)   : %@"), strChange);

   CFStringFindAndReplace(strChange, find2, replace2, CFRangeMake(0, CFStringGetLength(strChange)), 0);

   show(CFSTR("Replaced?          : %@"), strChange);
   
   CFStringFindAndReplace(strChange, find2, replace2, CFRangeMake(0, CFStringGetLength(strChange)), kCFCompareCaseInsensitive);
   
   show(CFSTR("Case insensitive   : %@"), strChange);
   
   CFStringCapitalize(strChange, curLocale);
   
   show(CFSTR("Capitalized        : %@"), strChange);

   CFStringFindAndReplace(strChange, replace2, find2, CFRangeMake(0, CFStringGetLength(strChange)), kCFCompareAnchored);
   
   show(CFSTR("Should Be Unchanged: %@"), strChange);

   CFStringFindAndReplace(strChange, find3, replace3, CFRangeMake(0, CFStringGetLength(strChange)), kCFCompareAnchored|kCFCompareBackwards);
   
   show(CFSTR("Should Be Changed  : %@"), strChange);
   
   show(CFSTR("Which is bigger %@ or %@?"), bigger, smaller);
   
   comp = CFStringCompare(bigger, smaller, 0);   
   result = (comp == kCFCompareGreaterThan) ? bigger : smaller;   
   show(CFSTR("Base Compare Says  : %@"), result);

   comp = CFStringCompare(bigger, smaller, kCFCompareNumerically);
   result = (comp == kCFCompareGreaterThan) ? bigger : smaller;   
   show(CFSTR("Numerical Compare  : %@"), result);

   CFRelease(curLocale);
   CFRelease(replace);
   CFRelease(find);
   CFRelease(replace2);   
   CFRelease(find2);
   CFRelease(replace3);   
   CFRelease(find3);
   CFRelease(bigger);   
   CFRelease(smaller);
   CFRelease(strChange);
}
Ejemplo n.º 11
0
static kern_return_t CopyUserVisibleNameForModemOrSerialPort(io_object_t interface, 
															 CFMutableDictionaryRef interfaceInfo,
															 CFStringRef *userVisibleName)
	// Given a serial device (interface) and a dictionary of 
	// information about the device (interfaceInfo), guess at the 
	// user-visible name for the device.
	// 
	// I'm somewhat unhappy with this code (both its length and its style) 
	// but there really isn't a better solution right now.  Apple 
	// is actively working on a better way to do this.
{
	kern_return_t 	err;
	kern_return_t 	junk;
	CFStringRef   	serialType;
	Boolean			isModem;
	CFStringRef		baseName;
	CFStringRef		productName;
	
	assert(interface        != 0  );
	assert(interfaceInfo    != NULL);
	assert( userVisibleName != NULL);
	assert(*userVisibleName == NULL);

	serialType = NULL;
	baseName = NULL;
	productName = NULL;
	
	// Determine whether the device is a modem.
	
	err = 0;
	serialType = (CFStringRef) IORegistryEntryCreateCFProperty(interface, CFSTR(kIOSerialBSDTypeKey), NULL, kNilOptions);
	if (serialType == NULL) {
		err = -1;
	}
	if (err == 0) {
		isModem = CFEqual(serialType, CFSTR(kIOSerialBSDModemType));
		if (isModem) {
			junk = CFQDictionarySetNumber(interfaceInfo, kSortOrderKey, kModemSortOrder);
			assert(junk == 0);
		}
	}

	// Get the "IOTTYBaseName" property and derive the user-visible name from that.
	
	if (err == 0) {
		baseName = (CFStringRef) IORegistryEntryCreateCFProperty(interface, CFSTR(kIOTTYBaseNameKey), NULL, kNilOptions);
		if (baseName == NULL) {
			err = -1;
		}
	}
	if (err == noErr) {
		// See whether the device has a "Product Name" property anywhere in its 
		// parent chain.

		productName = (CFStringRef) IORegistryEntrySearchCFProperty(interface, kIOServicePlane,
                            						  CFSTR(kIOPropertyProductNameKey), 
                            						  NULL, 
                            						  kIORegistryIterateRecursively | kIORegistryIterateParents);
	}
	if (err == 0) {
	    if ( isModem && CFEqualString(baseName, CFSTR("modem")) ) {

			junk = CFQDictionarySetNumber(interfaceInfo, kSortOrderKey, kInternalModemSortOrder);
			assert(junk == 0);
	    	
	        *userVisibleName = kMoreSCPortLabelModemInternal;
		    CFRetain(*userVisibleName);
	    } else if ( CFEqualString(baseName, CFSTR("modem"))) {
	        *userVisibleName = kMoreSCPortLabelModemPort;
		    CFRetain(*userVisibleName);
	    } else if ( CFEqualString(baseName, CFSTR("printer"))) {
	        *userVisibleName = kMoreSCPortLabelPrinterPort;
		    CFRetain(*userVisibleName);
	    } else if ( CFEqualString(baseName, CFSTR("modem-printer"))) {
	        *userVisibleName = kMoreSCPortLabelModemPrinterPort;
		    CFRetain(*userVisibleName);
	    } else if ( CFEqualString(baseName, CFSTR("IrDA-IrCOMM"))) {
	        *userVisibleName = kMoreSCPortLabelModemIrDA;
		    CFRetain(*userVisibleName);
	    } else if ( CFEqualString(baseName, CFSTR("usbmodem")) || (productName != NULL) ) {

			// It may not be a modem (it may just be a USB serial device), so 
			// we only override the default sort order (serial) if the we 
			// know it's a modem.
			
			if (isModem) {
				junk = CFQDictionarySetNumber(interfaceInfo, kSortOrderKey, kUSBModemSortOrder);
				assert(junk == 0);
			}
			
			if (productName != NULL) {
				// Serial or modem USB device with "Product Name" key.
				*userVisibleName = productName;
			} else {
				// productName is NULL so baseName must be "usbmodem".
		        *userVisibleName = kMoreSCPortLabelModemUSB;
			}
		    CFRetain(*userVisibleName);
			
	    } else {
			CFStringRef 		baseNameProperty;
			CFMutableStringRef	ttyBase;
			
			ttyBase = NULL;
			baseNameProperty = (CFStringRef) IORegistryEntryCreateCFProperty(interface, CFSTR(kIOTTYBaseNameKey), NULL, kNilOptions);
			if (baseNameProperty != NULL) {
				ttyBase = CFStringCreateMutableCopy(NULL, 0, baseNameProperty);
			}
			if (ttyBase == NULL) {
				CFDictionarySetValue(interfaceInfo, CFSTR(kIOTTYBaseNameKey), CFSTR("unknown"));
			} else {
				CFStringLowercase(ttyBase, NULL);
				CFDictionarySetValue(interfaceInfo, CFSTR(kIOTTYBaseNameKey), ttyBase);
			}
			CFQRelease(ttyBase);
			CFQRelease(baseNameProperty);

	    	// This string is pretty unlikely, but it does match what the 
	    	// Network preferences panel creates in Mac OS X 10.1.x for 
	    	// unknown devices, such as a Keyspan serial adapter.

	    	*userVisibleName = kMoreSCPortLabelSerial;
		    CFRetain(*userVisibleName);
	    }
	}

	CFQRelease(serialType);
	CFQRelease(baseName);
	CFQRelease(productName);
	
	assert( (err == 0) == (*userVisibleName != NULL) );
	
	return err;
}
Ejemplo n.º 12
0
Boolean APSetKey(CFStringRef key)
{
    hash = CFSTR("");
    blacklist = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
    
    CFMutableStringRef mutableKey = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, key);
    CFStringRef preparedKey = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, key);
    CFLocaleRef currentLocale = CFLocaleCopyCurrent();
    CFStringLowercase(mutableKey, currentLocale);
    CFRelease(currentLocale);
    
    if (CFStringHasPrefix(mutableKey, CFSTR("0x")) && CFStringGetLength(mutableKey) > 2)
    {
        CFStringDelete(mutableKey, CFRangeMake(0, 2));
    }
    if (CFStringGetLength(mutableKey) == 1024/8*2)
    {
        CFRelease(preparedKey);
        preparedKey = APPEMKeyCreateFromHexKey(mutableKey);
    }
    CFRelease(mutableKey);
    
    
    SecItemImportExportKeyParameters params = {0};
    params.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
    params.flags = kSecKeyNoAccessControl;
    SecExternalItemType itemType = kSecItemTypePublicKey;
    SecExternalFormat externalFormat = kSecFormatPEMSequence;
    CFArrayRef tempArray = NULL;
    OSStatus oserr = noErr;
    
    // Set the key as extractable. Looking through the source code in SecImportExportUtils.cpp
    // it looks like this isn't handled, yet it seems to be documented to me. One day the code
    // may catch up, so I'm leaving this here to show the intention.
    CFNumberRef attributeFlags[1];
    uint32 flag0value = CSSM_KEYATTR_EXTRACTABLE;
    CFNumberRef flag0 = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &flag0value);
    attributeFlags[0] = flag0;
    CFArrayRef keyAttributes = CFArrayCreate(kCFAllocatorDefault, (const void **)attributeFlags, 1, &kCFTypeArrayCallBacks);
    CFRelease(flag0);
    params.keyAttributes = keyAttributes;
    
    CFDataRef keyData = CFStringCreateExternalRepresentation(kCFAllocatorDefault, preparedKey, kCFStringEncodingUTF8, 0);
    CFRelease(preparedKey);
    
    oserr = SecItemImport(keyData,
                          NULL,
                          &externalFormat,
                          &itemType,
                          0,
                          &params,
                          NULL,
                          &tempArray);
    CFRelease(keyAttributes);
    CFRelease(keyData);
    
    if (oserr != noErr) {
        CFStringRef errorString = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("Unable to import key. Error %d"), oserr);
        CFShow(errorString);
        CFRelease(errorString);
        return FALSE;
    }
    
    publicKeyRef = (SecKeyRef)CFArrayGetValueAtIndex(tempArray, 0);
    CFRetain(publicKeyRef);
    CFRelease(tempArray);
    
    return TRUE;
}