Exemplo n.º 1
0
void 		CAComponent::SetCompNames () const
{
	if (!mCompName) {
	
		CFStringRef compName;
		OSStatus result = AudioComponentCopyName (Comp(), &compName);
		if (result) return;
		
		const_cast<CAComponent*>(this)->mCompName = compName;
		if (compName)
		{
			CFArrayRef splitStrArray = CFStringCreateArrayBySeparatingStrings(NULL, compName, CFSTR(":"));
			
			// we need to retain these values so the strings are not lost when the array is released
			const_cast<CAComponent*>(this)->mManuName = (CFStringRef)CFArrayGetValueAtIndex(splitStrArray, 0);
            CFRetain(this->mManuName);
			if (CFArrayGetCount(splitStrArray) > 1)
			{
				CFStringRef str = (CFStringRef)CFArrayGetValueAtIndex(splitStrArray, 1);
				
				CFMutableStringRef mstr = CFStringCreateMutableCopy (NULL, CFStringGetLength(str), str);

				// this needs to trim out white space:
				
				CFStringTrimWhitespace (mstr);
			
				const_cast<CAComponent*>(this)->mAUName = mstr;
			} else
				const_cast<CAComponent*>(this)->mAUName = NULL;
			
			CFRelease(splitStrArray);
		}
	}
}
Exemplo n.º 2
0
static int run(CFArrayRef argv) {
	if (CFArrayGetCount(argv) > 1)  return -1;
	CFStringRef build = DBGetCurrentBuild();
	CFStringRef project = NULL;
	CFDictionaryRef projectEnv = NULL;
	CFDictionaryRef globalEnv = DBCopyPropDictionary(build, NULL, CFSTR("environment"));
	if (CFArrayGetCount(argv) == 1) {
		project = CFArrayGetValueAtIndex(argv, 0);
		projectEnv = DBCopyPropDictionary(build, project, CFSTR("environment"));
	}
	
	CFMutableDictionaryRef env = NULL;
	
	if (globalEnv && projectEnv) {
		env = (CFMutableDictionaryRef)mergeDictionaries(projectEnv, globalEnv);
	} else if (globalEnv) {
		env = (CFMutableDictionaryRef)globalEnv;
	} else if (projectEnv) {
		env = (CFMutableDictionaryRef)projectEnv;
	} else {
		return 0;
	}

	// Auto-generate some variables based on RC_ARCHS and RC_NONARCH_CFLAGS
	// RC_CFLAGS=$RC_NONARCH_CFLAGS -arch ${arch}
	// RC_${arch}=YES
	CFStringRef str = CFDictionaryGetValue(env, CFSTR("RC_NONARCH_CFLAGS"));
	if (!str) str = CFSTR("");
	CFMutableStringRef cflags = CFStringCreateMutableCopy(NULL, 0, str);
	str = CFDictionaryGetValue(env, CFSTR("RC_ARCHS"));
	if (str) {
		CFMutableStringRef trimmed = CFStringCreateMutableCopy(NULL, 0, str);
		CFStringTrimWhitespace(trimmed);
		CFArrayRef archs = tokenizeString(trimmed);
		CFIndex i, count = CFArrayGetCount(archs);
		for (i = 0; i < count; ++i) {
			CFStringRef arch = CFArrayGetValueAtIndex(archs, i);
			// -arch ${arch}
			CFStringAppendFormat(cflags, NULL, CFSTR(" -arch %@"), arch);
			
			// RC_${arch}=YES
			CFStringRef name = CFStringCreateWithFormat(NULL, NULL, CFSTR("RC_%@"), arch);
			CFDictionarySetValue(env, name, CFSTR("YES"));
			CFRelease(name);
		}
		CFRelease(trimmed);
	}
	CFDictionarySetValue(env, CFSTR("RC_CFLAGS"), cflags);
	
	// print variables to stdout
	CFArrayRef keys = dictionaryGetSortedKeys(env);
	CFIndex i, count = CFArrayGetCount(keys);
	for (i = 0; i < count; ++i) {
		CFStringRef name = CFArrayGetValueAtIndex(keys, i);
		CFStringRef value = CFDictionaryGetValue(env, name);
		cfprintf(stdout, "%@=%@\n", name, value);
	}
	return 0;
}
Exemplo n.º 3
0
CFStringRef stringFromRange(const char *cstring, CFRange range)
{
  CFStringRef str = CFStringCreateWithBytes (NULL, (uint8*)&cstring[range.location], range.length, kCFStringEncodingUTF8, false);
  CFMutableStringRef mutableStr = CFStringCreateMutableCopy(NULL, 0, str);
  CFStringTrimWhitespace(mutableStr);
  CFRelease(str);
  return mutableStr;
}
static void secNormalize(CFMutableStringRef theString, CFLocaleRef theLocale)
{
	CFRange theRange;
	
	CFStringFold(theString, kCFCompareCaseInsensitive | kCFCompareDiacriticInsensitive | kCFCompareWidthInsensitive, theLocale);
	CFStringNormalize(theString, kCFStringNormalizationFormKC);
	CFStringTrimWhitespace(theString);
	while(CFStringFindCharacterFromSet(theString, CFCharacterSetGetPredefined(kCFCharacterSetWhitespace), CFRangeMake(0, CFStringGetLength(theString)), kCFCompareBackwards, &theRange))
		CFStringDelete(theString, theRange);
}
Exemplo n.º 5
0
static CFStringRef CFStringFromCGPath(CGPathRef path)
{
    if (!path)
        return 0;

    CFMutableStringRef string = CFStringCreateMutable(NULL, 0);
    CGPathApply(path, string, CGPathToCFStringApplierFunction);
    CFStringTrimWhitespace(string);


    return string;
}
Exemplo n.º 6
0
int parseNameComponent(CFStringRef dn, CFStringRef *pName, CFStringRef *pValue)
{
  CFArrayRef nameStrings = CFStringCreateArrayBySeparatingStrings(NULL, dn, kCertNameEquals);

  *pName = *pValue = NULL;

  if (CFArrayGetCount(nameStrings) != 2)
    return 0;

  CFMutableStringRef str;

  str = CFStringCreateMutableCopy(NULL, 0, CFArrayGetValueAtIndex(nameStrings, 0));
  CFStringTrimWhitespace(str);
  *pName = str;

  str = CFStringCreateMutableCopy(NULL, 0, CFArrayGetValueAtIndex(nameStrings, 1));
  CFStringTrimWhitespace(str);
  *pValue = str;

  CFRelease(nameStrings);
  return 1;
}
/* ------------------------------------------------------------------------------------------------------

getCleanedHeaderValue: read FITS header and return striped CFStringRef value.

------------------------------------------------------------------------------------------------------ */
CFStringRef getCleanedHeaderValue(const char* filename, char* keyword) {
	char *headerValue = NULL;
	headerValue = qfits_query_hdr((const char*)filename, keyword);
//	printf("For keyword %s, headerValue is: %s\n", keyword, headerValue);
	
	if (headerValue != NULL) {
		CFStringRef cfvalue = CFStringCreateWithCString(kCFAllocatorDefault, headerValue, kCFStringEncodingUTF8);
		CFIndex length = CFStringGetLength(cfvalue);
		CFMutableStringRef cfmvalue = CFStringCreateMutable(kCFAllocatorDefault, length);
		CFStringAppend(cfmvalue, cfvalue);		
		CFRelease(cfvalue);
		CFStringTrim(cfmvalue, CFSTR("'"));
		CFStringTrimWhitespace(cfmvalue);
		return cfmvalue;
	} else {
		return NULL;
	}
}
Exemplo n.º 8
0
int parseCertName(CFStringRef nameDesc, CFMutableArrayRef names)
{
  CFArrayRef nameStrings = CFStringCreateArrayBySeparatingStrings(NULL, nameDesc, kCertNameFwdSlash);
  int count = CFArrayGetCount(nameStrings);
  int i;
  int ret = 1;

  CertNameRef pCertName = createCertName();

  for(i = 0;i < count;i++)
    {
      CFMutableStringRef dn = CFStringCreateMutableCopy(NULL, 0, CFArrayGetValueAtIndex(nameStrings, i));
      CFStringTrimWhitespace(dn);

      CFStringRef name, value;

      if (!parseNameComponent(dn, &name, &value))
        ret = 0;

      if (!name || !value)
        {
          if (name)
            CFRelease(name);

          if (value)
            CFRelease(value);
          if (name && !value)
            ret = 0;

          CFRelease(dn);
          continue;
        }

      if (!appendCertField(pCertName, name, value))
        ret = 0;
      CFRelease(name);
      CFRelease(value);
      CFRelease(dn);
    }

  CFArrayAppendValue(names, pCertName);
  CFRelease(nameStrings);
  return ret;
}
Exemplo n.º 9
0
CFStringRef
SMBCreateNetBIOSName(CFStringRef proposedName)
{
    CFMutableStringRef  composedName;
    CFStringEncoding    codepage;
    CFIndex		    nconverted = 0;
    CFIndex		    nused = 0;

    uint8_t		    name_buffer[NetBIOS_NAME_LEN];

    if (proposedName == NULL) {
        return NULL;
    }

    codepage = getPrefsCodePage();

    composedName = CFStringCreateMutableCopy(kCFAllocatorDefault,
                   0, proposedName);
    if (!composedName) {
        return NULL;
    }
    CFStringTrimWhitespace(composedName);
    CFStringUppercase(composedName, CFLocaleGetSystem());

    nconverted = CFStringGetBytes(composedName,
                                  CFRangeMake(0,
                                          MIN((CFIndex)sizeof(name_buffer), CFStringGetLength(composedName))),
                                  codepage, 0 /* loss byte */, false /* no BOM */,
                                  name_buffer, sizeof(name_buffer), &nused);

    /* We expect the conversion above to always succeed, given that we
     * tried to remove anything that might not convert to a code page.
     */
    if (nconverted == 0) {
        char buf[256];

        buf[0] = '\0';
        CFStringGetCString(composedName, buf, sizeof(buf), kCFStringEncodingUTF8);
        SMBLogInfo("failed to compose a NetBIOS name string from '%s'",
                   ASL_LEVEL_DEBUG, buf);

        CFRelease(composedName);
        return NULL;
    }

    CFRelease(composedName);

    /* Null terminate for the benefit of CFStringCreate. Be careful to be
     * no more that 15 bytes, since the last byte is reserved for the name
     * type.
     */
    name_buffer[MIN(nused, (CFIndex)sizeof(name_buffer) - 1)] = '\0';

    composedName = CFStringCreateMutable(kCFAllocatorDefault,
                                         NetBIOS_NAME_LEN);
    if (composedName == NULL) {
        return NULL;
    }

    CFStringAppendCString(composedName, (const char *)name_buffer, codepage);
    return composedName;
}
Exemplo n.º 10
0
Boolean GetMetadataForFile(void* thisInterface, 
			   CFMutableDictionaryRef attributes, 
			   CFStringRef contentTypeUTI,
			   CFStringRef pathToFile)
{
    Boolean success = false;

	CFDictionaryRef	tempDictRef;
	CFStringRef		tempTitleRef;
	CFArrayRef		tempContentRef;

	// load the document at the specified location	
	CFURLRef		pathToFileURL;
	pathToFileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, pathToFile, kCFURLPOSIXPathStyle, false);
	tempDictRef = (CFDictionaryRef)CreatePropertiesFromXMLFile(pathToFileURL);
    CFRelease(pathToFileURL);

    if (tempDictRef)
    {
		CFStringRef	tempBrdNameRef;
		CFStringRef	tempDatNumberRef;
		CFNumberRef	tempLengthRef;
		CFDateRef	tempCreatedDateRef;
		CFDateRef	tempModifiedDateRef;

		CFDictionarySetValue(attributes, kMDItemCreator, CFSTR("BathyScaphe"));

		// set the kMDItemTitle attribute to the Title
		tempTitleRef = CFDictionaryGetValue(tempDictRef, CFSTR("Title"));
		if (tempTitleRef != NULL) {
			CFDictionarySetValue(attributes, kMDItemTitle, tempTitleRef);
			CFDictionarySetValue(attributes, kMDItemDisplayName, tempTitleRef);
		}
		
		tempBrdNameRef = CFDictionaryGetValue(tempDictRef, CFSTR("BoardName"));
		if (tempBrdNameRef != NULL)
			CFDictionarySetValue(attributes, CFSTR("jp_tsawada2_bathyscaphe_thread_BoardName"), tempBrdNameRef);

		tempDatNumberRef = CFDictionaryGetValue(tempDictRef, CFSTR("dat"));
		if (tempDatNumberRef != NULL)
			CFDictionarySetValue(attributes, CFSTR("jp_tsawada2_bathyscaphe_thread_DatNumber"), tempDatNumberRef);

		tempLengthRef = CFDictionaryGetValue(tempDictRef, CFSTR("Length"));
		if (tempLengthRef != NULL)
			CFDictionarySetValue(attributes, CFSTR("jp_tsawada2_bathyscaphe_thread_DatSize"), tempLengthRef);

		tempCreatedDateRef = CFDictionaryGetValue(tempDictRef, CFSTR("CreatedDate"));
		if (tempCreatedDateRef != NULL)
			CFDictionarySetValue(attributes, kMDItemContentCreationDate, tempCreatedDateRef);

		tempModifiedDateRef = CFDictionaryGetValue(tempDictRef, CFSTR("ModifiedDate"));
		if (tempModifiedDateRef != NULL)
			CFDictionarySetValue(attributes, kMDItemContentModificationDate, tempModifiedDateRef);

		tempContentRef = CFDictionaryGetValue(tempDictRef, CFSTR("Contents"));
		if (tempContentRef) {
			CFIndex	i, count_;
			CFNumberRef	countRef_;
			CFMutableStringRef	cont_ = CFStringCreateMutable(kCFAllocatorDefault, 0);
			CFMutableArrayRef	nameArray_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
			CFDictionaryRef	obj;
			CFNumberRef		statusStr;

			count_ = CFArrayGetCount(tempContentRef);

			countRef_ = CFNumberCreate(kCFAllocatorDefault, kCFNumberCFIndexType, &count_);
			CFDictionarySetValue(attributes, CFSTR("jp_tsawada2_bathyscaphe_thread_ResCount"), countRef_);
			CFRelease(countRef_);
			
			for (i=0; i<count_; i++) {
				obj = CFArrayGetValueAtIndex(tempContentRef, i);

				if (obj == NULL) continue;
				statusStr = CFDictionaryGetValue(obj, CFSTR("Status"));
				if (isNotAbonedRes(statusStr)) {
					CFStringRef	msg_;
					CFStringRef	name_;

					msg_ = CFDictionaryGetValue(obj, CFSTR("Message"));
					if (msg_) {
						CFStringAppend(cont_, msg_);
					}

					name_ = CFDictionaryGetValue(obj, CFSTR("Name"));
					if (name_) {
						Boolean already_ = CFArrayContainsValue(nameArray_, CFRangeMake(0, CFArrayGetCount(nameArray_)), name_);
						if (already_ == false) CFArrayAppendValue(nameArray_, name_);
					}
				}
			}

			CFStringFindAndReplace(cont_, CFSTR(" <br> "), CFSTR(""), CFRangeMake(0, CFStringGetLength(cont_)), 0);
			CFStringTrimWhitespace(cont_);
																	
			CFIndex	len;
			CFRange	searchRange;
			CFRange	resultRange;
			CFRange	gtRange;

			len = CFStringGetLength(cont_);
			searchRange = CFRangeMake(0, len);

			while (1) {
				Boolean	found_ = CFStringFindWithOptions(cont_, CFSTR("<a "), searchRange, kCFCompareCaseInsensitive, &resultRange);
				if (found_ == false) break;
				// Start searching next to "<"
				searchRange.location = resultRange.location + resultRange.length;
				searchRange.length = (len - searchRange.location);

				found_ = CFStringFindWithOptions(cont_, CFSTR("</a>"), searchRange, kCFCompareCaseInsensitive, &gtRange);
				if (found_ == false) break;
				resultRange.length = gtRange.location + gtRange.length - resultRange.location;
				CFStringDelete(cont_, resultRange);

				searchRange.length -= resultRange.length;
				len -= resultRange.length;
				
				if (searchRange.location >= len) break;
			}

			CFDictionarySetValue(attributes, kMDItemTextContent, cont_);
			CFDictionarySetValue(attributes, kMDItemContributors, nameArray_);
			
			CFRelease(cont_);
			CFRelease(nameArray_);
		}
		// release the loaded document
		CFRelease(tempDictRef);
		// return YES so that the attributes are imported
		success = true;
    }
    return success;
}