コード例 #1
0
ファイル: CRESTRequest.c プロジェクト: n3b/CRESTService
static void parseParams(CFMutableDictionaryRef params, CFStringRef query)
{
	assert( params && query );

	CFArrayRef parts = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, query, amp);
	int i = 0;

	while( i < CFArrayGetCount(parts) )
	{
		CFArrayRef components = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault,
				CFArrayGetValueAtIndex(parts, i), eq);

		// only if k & v present, and len of k > 0
		if( 2 == CFArrayGetCount(components) && CFStringGetLength(CFArrayGetValueAtIndex(components, 0)) )
		{
			// retain count == 2
			CFStringRef val = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
					CFArrayGetValueAtIndex(components, 1), emp, kCFStringEncodingUTF8);
			CFDictionarySetValue(params, CFArrayGetValueAtIndex(components, 0), val);
			CFRelease(val);
		}

		CFRelease(components);
		i++;
	}

	CFRelease(parts);
}
コード例 #2
0
ファイル: fswatch.c プロジェクト: bclennox/fswatch
//set up fsevents and callback
int main(int argc, char **argv) {

  if(argc != 3) {
    fprintf(stderr, "You must specify a directory to watch and a command to execute on change\n");
    exit(1);
  }

  to_run = argv[2];

  CFStringRef mypath = CFStringCreateWithCString(NULL, argv[1], kCFStringEncodingUTF8); 
  CFArrayRef pathsToWatch = CFStringCreateArrayBySeparatingStrings (NULL, mypath, CFSTR(":"));

  void *callbackInfo = NULL; 
  FSEventStreamRef stream; 
  CFAbsoluteTime latency = 1.0;

  stream = FSEventStreamCreate(NULL,
    &callback,
    callbackInfo,
    pathsToWatch,
    kFSEventStreamEventIdSinceNow,
    latency,
    kFSEventStreamCreateFlagNone
  ); 

  FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 
  FSEventStreamStart(stream);
  CFRunLoopRun();

}
コード例 #3
0
ファイル: SCNetworkSet.c プロジェクト: carriercomm/osx-2
SCNetworkSetRef
SCNetworkSetCopyCurrent(SCPreferencesRef prefs)
{
	CFArrayRef		components;
	CFStringRef		currentID;
	SCNetworkSetPrivateRef	setPrivate	= NULL;

	currentID = SCPreferencesGetValue(prefs, kSCPrefCurrentSet);
	if (!isA_CFString(currentID)) {
		return NULL;
	}

	components = CFStringCreateArrayBySeparatingStrings(NULL, currentID, CFSTR("/"));
	if (CFArrayGetCount(components) == 3) {
		CFStringRef	setID;
		CFStringRef	path;

		setID = CFArrayGetValueAtIndex(components, 2);
		path = SCPreferencesPathKeyCreateSet(NULL, setID);
		if (CFEqual(path, currentID)) {
			setPrivate = __SCNetworkSetCreatePrivate(NULL, prefs, setID);
			assert(setPrivate != NULL);

			// mark set as "old" (already established)
			setPrivate->established = TRUE;
		} else {
			SC_log(LOG_NOTICE, "SCNetworkSetCopyCurrent(): preferences are non-conformant");
		}
		CFRelease(path);
	}
	CFRelease(components);

	return (SCNetworkSetRef)setPrivate;
}
コード例 #4
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);
		}
	}
}
コード例 #5
0
CFMutableArrayRef get_device_product_version_parts(AMDeviceRef device) {
    CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion"));
    CFArrayRef parts = CFStringCreateArrayBySeparatingStrings(NULL, version, CFSTR("."));
    CFMutableArrayRef result = CFArrayCreateMutableCopy(NULL, CFArrayGetCount(parts), parts);
    CFRelease(version);
    CFRelease(parts);
    return result;
}
コード例 #6
0
ファイル: fswatch.c プロジェクト: pieper/fswatch
//set up fsevents and callback
int main(int argc, char **argv) {

  if(argc < 3) {
    fprintf(stderr, "usage: %s directory command [argument ...]\n", argv[0]);
    exit(1);
  }

  int n_args = argc - 2;

  // find total length of argument to bash -c, including spaces
  int n_bash_arg_chars = 0;
  for(int i=2; i<argc; ++i) {
    n_bash_arg_chars += strlen(argv[i]) + 1;
  }

  // build the space-separated string argument
  char bash_arg[n_bash_arg_chars];
  int i_chars = 0;
  for(int i=2; i<argc; ++i) {
    memcpy(&bash_arg[i_chars], argv[i], strlen(argv[i]) * sizeof(char));
    i_chars += strlen(argv[i]);
    bash_arg[i_chars++] = ' ';
  }
  bash_arg[i_chars - 1] = 0;

  // update the global bash command to be run
  bash_command[2] = bash_arg;

  CFStringRef mypath = CFStringCreateWithCString(NULL, argv[1], kCFStringEncodingUTF8); 
  CFArrayRef pathsToWatch = CFStringCreateArrayBySeparatingStrings (NULL, mypath, CFSTR(":"));

  void *callbackInfo = NULL; 
  FSEventStreamRef stream; 
  CFAbsoluteTime latency = 0;

  stream = FSEventStreamCreate(NULL,
    &callback,
    callbackInfo,
    pathsToWatch,
    kFSEventStreamEventIdSinceNow,
    latency,
    kFSEventStreamCreateFlagNone
  ); 

  FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 
  FSEventStreamStart(stream);
  CFRunLoopRun();

}
コード例 #7
0
/*
 * Opens a configuration file and returns a CFArrayRef consisting
 * of a CFStringRef for each line.
 */
CFArrayRef
configRead(const char *path)
{
	int			fd;
	struct stat		statBuf;
	CFMutableDataRef	data;
	CFStringRef		str;
	CFArrayRef		config	= NULL;

	fd = open(path, O_RDONLY, 0644);
	if (fd < 0) {
		goto done;
	}
	if (fstat(fd, &statBuf) < 0) {
		goto done;
	}
	if ((statBuf.st_mode & S_IFMT) != S_IFREG) {
		goto done;
	}

	data = CFDataCreateMutable(NULL, statBuf.st_size);
	CFDataSetLength(data, statBuf.st_size);
	if(read(fd, (void *)CFDataGetMutableBytePtr(data), statBuf.st_size) != statBuf.st_size) {
		CFRelease(data);
		goto done;
	}

	str = CFStringCreateFromExternalRepresentation(NULL, data, kCFStringEncodingMacRoman);
	CFRelease(data);

	config = CFStringCreateArrayBySeparatingStrings(NULL, str, CFSTR("\n"));
	CFRelease(str);

    done:

	if (fd >= 0) {
		close(fd);
	}
	if (config == NULL) {
		CFMutableArrayRef	emptyConfig;

		/* pretend that we found an empty file */
		emptyConfig = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
		CFArrayAppendValue(emptyConfig, CFSTR(""));
		config = (CFArrayRef)emptyConfig;
	}
	return config;
}
コード例 #8
0
static bool OnLionOrLater()
{
  if (sOnLionOrLater < 0) {
    SInt32 major = 0, minor = 0;

    CFURLRef url =
      CFURLCreateWithString(kCFAllocatorDefault,
                            CFSTR("file:///System/Library/CoreServices/SystemVersion.plist"),
                            NULL);
    CFReadStreamRef stream =
      CFReadStreamCreateWithFile(kCFAllocatorDefault, url);
    CFReadStreamOpen(stream);
    CFDictionaryRef sysVersionPlist = (CFDictionaryRef)
      CFPropertyListCreateWithStream(kCFAllocatorDefault,
                                     stream, 0, kCFPropertyListImmutable,
                                     NULL, NULL);
    CFReadStreamClose(stream);
    CFRelease(stream);
    CFRelease(url);

    CFStringRef versionString = (CFStringRef)
      CFDictionaryGetValue(sysVersionPlist, CFSTR("ProductVersion"));
    CFArrayRef versions =
      CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault,
                                             versionString, CFSTR("."));
    CFIndex count = CFArrayGetCount(versions);
    if (count > 0) {
      CFStringRef component = (CFStringRef) CFArrayGetValueAtIndex(versions, 0);
      major = CFStringGetIntValue(component);
      if (count > 1) {
        component = (CFStringRef) CFArrayGetValueAtIndex(versions, 1);
        minor = CFStringGetIntValue(component);
      }
    }
    CFRelease(sysVersionPlist);
    CFRelease(versions);

    if (major < 10) {
      sOnLionOrLater = 0;
    } else {
      int version = 0x1000 + (minor << 4);
      sOnLionOrLater = version >= MAC_OS_X_VERSION_10_7_HEX ? 1 : 0;
    }
  }

  return sOnLionOrLater > 0 ? true : false;
}
コード例 #9
0
ファイル: parse_url.c プロジェクト: aosm/smb
static CFArrayRef CreateWrkgrpUserArrayFromCFStringRef(CFStringRef inString, CFStringRef separatorString)
{
	CFArrayRef	userArray = NULL;

	userArray = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, inString, separatorString);
	/* 
	 * If there are two array entries then we have a workgoup and username otherwise if we just have one item then its a 
	 * username. Any other number could be an error, but since we have no idea what they are trying to do we just treat
	 * it as a username.
	 */
	if (userArray && (CFArrayGetCount(userArray) != 2)) {
		CFRelease(userArray);
		userArray = NULL;
	}
	return userArray;
	
}
コード例 #10
0
ファイル: FWUtilGlobals.cpp プロジェクト: arnelh/Examples
ostream & operator<<(ostream & outs, const FWUtilBlockIndenter & indenter)
{
	CFArrayRef	linesArray = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, indenter.mString, CFSTR("\n")) ;
	
	if ( ( linesArray ) && ( CFArrayGetCount( linesArray ) > 0 ) )
	{
		outs << indenter.mIndenter << (CFStringRef) CFArrayGetValueAtIndex(linesArray, 0) ;
	
		for( CFIndex index = 1, count = CFArrayGetCount( linesArray ); index < count; ++index )
		{
			outs << endl << indenter.mIndenter << (CFStringRef) CFArrayGetValueAtIndex(linesArray, index) ;
		}
		
		CFRelease( linesArray ) ;
	}
	
	return outs ;
}
コード例 #11
0
bool
MDSPrefs::readPathFromEnv()
{
    static const char *kPluginPathEnv = "MDSPATH";
    static const CFStringRef kSeparator = CFSTR(":");

    char *envValue = getenv(kPluginPathEnv);
    if (envValue) {
        CFStringRef path = CFStringCreateWithCString(NULL, envValue, kCFStringEncodingUTF8);

        mPluginFolders = CFStringCreateArrayBySeparatingStrings(NULL, path, kSeparator);
        
        CFRelease(path);
        return true;
    }
    
    return false;
}
コード例 #12
0
ファイル: cert_data.c プロジェクト: xnuxer/vpnconnect
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;
}
コード例 #13
0
ファイル: SCNetworkSet.c プロジェクト: carriercomm/osx-2
static CFStringRef
copy_next_name(CFStringRef name)
{
	CFArrayRef		components;
	CFIndex			n;
	CFMutableArrayRef	newComponents;
	SInt32			suffix	= 2;

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

	components = CFStringCreateArrayBySeparatingStrings(NULL, name, CFSTR(" "));
	if (components != NULL) {
		newComponents = CFArrayCreateMutableCopy(NULL, 0, components);
		CFRelease(components);
	} else {
		newComponents = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
		CFArrayAppendValue(newComponents, name);
	}

	n = CFArrayGetCount(newComponents);
	if (n > 1) {
		CFStringRef	str;

		str = CFArrayGetValueAtIndex(newComponents, n - 1);
		suffix = CFStringGetIntValue(str);
		if (suffix++ > 0) {
			CFArrayRemoveValueAtIndex(newComponents, n - 1);
		} else {
			suffix = 2;
		}
	}

	name = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), (int)suffix);
	CFArrayAppendValue(newComponents, name);
	CFRelease(name);

	name = CFStringCreateByCombiningStrings(NULL, newComponents, CFSTR(" "));
	CFRelease(newComponents);

	return name;
}
コード例 #14
0
ファイル: SCNetworkSet.c プロジェクト: carriercomm/osx-2
SCNetworkSetRef
SCNetworkSetCreate(SCPreferencesRef prefs)
{
	CFArrayRef		components;
	CFDictionaryRef		entity;
	Boolean			ok;
	CFStringRef		path;
	CFStringRef		prefix;
	CFStringRef		setID;
	SCNetworkSetPrivateRef	setPrivate;

	prefix = SCPreferencesPathKeyCreateSets(NULL);
	path = __SCPreferencesPathCreateUniqueChild_WithMoreSCFCompatibility(prefs, prefix);
	if (path == NULL) path = SCPreferencesPathCreateUniqueChild(prefs, prefix);
	CFRelease(prefix);
	if (path == NULL) {
		return NULL;
	}

	components = CFStringCreateArrayBySeparatingStrings(NULL, path, CFSTR("/"));
	setID = CFArrayGetValueAtIndex(components, 2);
	setPrivate = __SCNetworkSetCreatePrivate(NULL, prefs, setID);
	assert(setPrivate != NULL);
	CFRelease(components);

	// mark set as "new" (not yet established)
	setPrivate->established = FALSE;

	// establish the set in the preferences
	entity = CFDictionaryCreate(NULL,
				    NULL, NULL, 0,
				    &kCFTypeDictionaryKeyCallBacks,
				    &kCFTypeDictionaryValueCallBacks);
	ok = SCPreferencesPathSetValue(prefs, path, entity);
	CFRelease(path);
	CFRelease(entity);
	if (!ok) {
		CFRelease(setPrivate);
		setPrivate = NULL;
	}

	return (SCNetworkSetRef)setPrivate;
}
コード例 #15
0
/* ------------------------------------------------------------------------------------------------------

SetNumberValueFromHeader: read FITS header and set number value to attribute name.

------------------------------------------------------------------------------------------------------ */
void SetNumberValueFromFITSHeader(const char* filename, 
				CFMutableDictionaryRef attributes, 
				const char* importerAttrName, 
				char* keyword, 
				Boolean isCoordinates)
{
	CFStringRef headerValue = getCleanedHeaderValue(filename, keyword);
	
	if (headerValue != NULL) {
		double number;
		CFRange r = CFStringFind(headerValue, CFSTR(":"), 0);		
		
		if ((isCoordinates == true) && (r.location != kCFNotFound)) {
			double sign = 1.;
			CFArrayRef dmsArray = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, headerValue, CFSTR(":"));

			if (CFArrayGetCount(dmsArray) == 3) {			
				if (CFStringGetDoubleValue(CFArrayGetValueAtIndex(dmsArray, 0)) < 0) {
					sign = -1;
				}
									
				// Work for either DMS or HMS, since the input format is kept. It is not a transformation, just a flattening.
				number = sign * ( fabs(CFStringGetDoubleValue(CFArrayGetValueAtIndex(dmsArray, 0))) +
									   CFStringGetDoubleValue(CFArrayGetValueAtIndex(dmsArray, 1)) / 60 +
									   CFStringGetDoubleValue(CFArrayGetValueAtIndex(dmsArray, 2)) / 3600 );

			}

			CFRelease(dmsArray);
		}
		else {
			number = CFStringGetDoubleValue(headerValue);			
		}

		CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &number);
		CFStringRef cfImporterAttrName = CFStringCreateWithCString(kCFAllocatorDefault, importerAttrName, kCFStringEncodingUTF8);
		CFDictionaryAddValue(attributes, cfImporterAttrName, value);
		CFRelease(value);
		CFRelease(cfImporterAttrName);

		CFRelease(headerValue);
	}
}
コード例 #16
0
ファイル: combo.cpp プロジェクト: arcanelab/mda-VST-plug-ins
OSStatus Combo::GetParameterValueStrings(AudioUnitScope inScope, AudioUnitParameterID inParameterID, CFArrayRef *outStrings)
{
	if (inScope != kAudioUnitScope_Global)
		return kAudioUnitErr_InvalidScope;

	switch (inParameterID)
	{
		case _MODEL:
			if (outStrings != NULL)
			{
				*outStrings = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, 
								CFSTR("Direct|Speaker Sim|Radio|MB Close|MB Distant|4x12 Centre|4x12 Edge"), CFSTR("|"));	
				if (*outStrings == NULL)
					return coreFoundationUnknownErr;
			}
			return noErr;

	}
	return kAudioUnitErr_InvalidPropertyValue;
}
コード例 #17
0
//--------------------------------------------------------------------------------
OSStatus SubSynth::GetParameterValueStrings(AudioUnitScope inScope, AudioUnitParameterID inParameterID, CFArrayRef * outStrings)
{
	if (inScope != kAudioUnitScope_Global)
		return kAudioUnitErr_InvalidScope;

	switch (inParameterID)
	{
		case kParam_Type:
			if (outStrings != NULL)
			{
				*outStrings = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, 
								CFSTR("distort|divide|invert|key osc."), CFSTR("|"));
				if (*outStrings == NULL)
					return coreFoundationUnknownErr;
			}
			return noErr;
	}

	return kAudioUnitErr_InvalidPropertyValue;
}
コード例 #18
0
ファイル: dubdelay.cpp プロジェクト: eriser/mda-vst-code
//--------------------------------------------------------------------------------
OSStatus DubDelay::GetParameterValueStrings(AudioUnitScope inScope, AudioUnitParameterID inParameterID, CFArrayRef * outStrings)
{
	if (inScope != kAudioUnitScope_Global)
		return kAudioUnitErr_InvalidScope;

	switch (inParameterID)
	{
		case kParam_FeedbackMode:
			if (outStrings != NULL)
			{
				*outStrings = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, 
								CFSTR("limit|saturate"), CFSTR("|"));
				if (*outStrings == NULL)
					return coreFoundationUnknownErr;
			}
			return noErr;
	}

	return kAudioUnitErr_InvalidPropertyValue;
}
コード例 #19
0
ファイル: xcodeproj_ext.c プロジェクト: Ashton-W/Xcodeproj
/* Generates a UUID. The original version is truncated, so this is not 100%
 * guaranteed to be unique. However, the `PBXObject#generate_uuid` method
 * checks that the UUID does not exist yet, in the project, before using it.
 *
 * @note Meant for internal use only.
 *
 * @return [String] A 24 characters long UUID.
 */
static VALUE
generate_uuid(void) {
  CFUUIDRef uuid = CFUUIDCreate(NULL);
  CFStringRef strRef = CFUUIDCreateString(NULL, uuid);
  CFRelease(uuid);

  CFArrayRef components = CFStringCreateArrayBySeparatingStrings(NULL, strRef, CFSTR("-"));
  CFRelease(strRef);
  strRef = CFStringCreateByCombiningStrings(NULL, components, CFSTR(""));
  CFRelease(components);

  UniChar buffer[24];
  CFStringGetCharacters(strRef, CFRangeMake(0, 24), buffer);
  CFStringRef strRef2 = CFStringCreateWithCharacters(NULL, buffer, 24);

  VALUE str = cfstr_to_str(strRef2);
  CFRelease(strRef);
  CFRelease(strRef2);
  return str;
}
コード例 #20
0
ファイル: cert_data.c プロジェクト: xnuxer/vpnconnect
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;
}
コード例 #21
0
ファイル: folderwatcher_mac.cpp プロジェクト: 24killen/client
void FolderWatcherPrivate::startWatching()
{
    qDebug() << "FolderWatcherPrivate::startWatching()" << _folder;
    CFStringRef folderCF = CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(_folder.unicode()),
                                                        _folder.length());
    CFArrayRef pathsToWatch = CFStringCreateArrayBySeparatingStrings (NULL, folderCF, CFSTR(":"));

    FSEventStreamContext ctx =  {0, this, NULL, NULL, NULL};

    // TODO: Add kFSEventStreamCreateFlagFileEvents ?

    _stream = FSEventStreamCreate(NULL,
                                 &callback,
                                 &ctx,
                                 pathsToWatch,
                                 kFSEventStreamEventIdSinceNow,
                                 0, // latency
                                 kFSEventStreamCreateFlagUseCFTypes|kFSEventStreamCreateFlagFileEvents|kFSEventStreamCreateFlagIgnoreSelf
                                 );

    CFRelease(pathsToWatch);
    FSEventStreamScheduleWithRunLoop(_stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    FSEventStreamStart(_stream);
}
コード例 #22
0
static void
split(const void * key, const void * value, void * context)
{
	CFArrayRef		components;
	CFStringRef		entity_id;
	CFStringRef		service_id;
	CFMutableDictionaryRef	state_dict;

	components = CFStringCreateArrayBySeparatingStrings(NULL, (CFStringRef)key, CFSTR("/"));
	service_id = CFArrayGetValueAtIndex(components, 3);
	entity_id  = CFArrayGetValueAtIndex(components, 4);
	state_dict = (CFMutableDictionaryRef)CFDictionaryGetValue(context, service_id);
	if (state_dict != NULL) {
		state_dict = CFDictionaryCreateMutableCopy(NULL, 0, state_dict);
	} else {
		state_dict = CFDictionaryCreateMutable(NULL,
						       0,
						       &kCFTypeDictionaryKeyCallBacks,
						       &kCFTypeDictionaryValueCallBacks);
	}

	if (CFEqual(entity_id, kSCEntNetIPv4) ||
	    CFEqual(entity_id, kSCEntNetIPv6)) {
		CFStringRef	interface;

		interface = CFDictionaryGetValue((CFDictionaryRef)value, kSCPropInterfaceName);
		if (interface != NULL) {
			CFDictionaryRef		proxy;
			CFMutableDictionaryRef	new_proxy;

			proxy = CFDictionaryGetValue(state_dict, kSCEntNetProxies);
			if (proxy != NULL) {
				new_proxy = CFDictionaryCreateMutableCopy(NULL, 0, proxy);
			} else {
				new_proxy = CFDictionaryCreateMutable(NULL,
								0,
								&kCFTypeDictionaryKeyCallBacks,
								&kCFTypeDictionaryValueCallBacks);
			}
			CFDictionarySetValue(new_proxy, kSCPropInterfaceName, interface);
			CFDictionarySetValue(state_dict, kSCEntNetProxies, new_proxy);
			CFRelease(new_proxy);
		}
	} else if (CFEqual(entity_id, kSCEntNetProxies)) {
		CFDictionaryRef	proxy;

		proxy = CFDictionaryGetValue(state_dict, kSCEntNetProxies);
		if (proxy != NULL) {
			CFStringRef		domain;
			CFMutableDictionaryRef	new_proxy;

			// if we already have some Setup: or State: proxy content
			domain = CFArrayGetValueAtIndex(components, 0);
			if (CFEqual(domain, kSCDynamicStoreDomainState)) {
				// if we've already seen the Setup: key
				new_proxy = CFDictionaryCreateMutableCopy(NULL, 0, (CFDictionaryRef)value);
				CFDictionaryApplyFunction(proxy, mergeDict, new_proxy);
			} else {
				// if we've already seen the State: key
				new_proxy = CFDictionaryCreateMutableCopy(NULL, 0, proxy);
				CFDictionaryApplyFunction((CFDictionaryRef)value, mergeDict, new_proxy);
			}
			CFDictionarySetValue(state_dict, kSCEntNetProxies, new_proxy);
			CFRelease(new_proxy);
		} else {
			CFDictionarySetValue(state_dict, kSCEntNetProxies, (CFDictionaryRef)value);
		}
	} else {
		CFDictionarySetValue(state_dict, entity_id, (CFDictionaryRef)value);
	}

	CFDictionarySetValue((CFMutableDictionaryRef)context, service_id, state_dict);
	CFRelease(state_dict);
	CFRelease(components);

	return;
}
コード例 #23
0
static CFComparisonResult
compareDomain(const void *val1, const void *val2, void *context)
{
	CFDictionaryRef		proxy1	= (CFDictionaryRef)val1;
	CFDictionaryRef		proxy2	= (CFDictionaryRef)val2;
	CFStringRef		domain1;
	CFStringRef		domain2;
	CFArrayRef		labels1	= NULL;
	CFArrayRef		labels2	= NULL;
	CFIndex			n1;
	CFIndex			n2;
	CFComparisonResult	result;
	Boolean			rev1;
	Boolean			rev2;

	// "default" domains sort before "supplemental" domains
	domain1 = CFDictionaryGetValue(proxy1, kSCPropNetProxiesSupplementalMatchDomain);
	domain2 = CFDictionaryGetValue(proxy2, kSCPropNetProxiesSupplementalMatchDomain);
	if (domain1 == NULL) {
		if (domain2 == NULL) {
			return kCFCompareEqualTo;
		}
		return kCFCompareLessThan;
	} else if (domain2 == NULL) {
		return kCFCompareGreaterThan;
	}

	// forward (A, AAAA) domains sort before reverse (PTR) domains
	rev1 = CFStringHasSuffix(domain1, CFSTR(".arpa"));
	rev2 = CFStringHasSuffix(domain2, CFSTR(".arpa"));
	if (rev1 != rev2) {
		if (rev1) {
			return kCFCompareGreaterThan;
		} else {
			return kCFCompareLessThan;
		}
	}

	labels1 = CFStringCreateArrayBySeparatingStrings(NULL, domain1, CFSTR("."));
	n1 = CFArrayGetCount(labels1);

	labels2 = CFStringCreateArrayBySeparatingStrings(NULL, domain2, CFSTR("."));
	n2 = CFArrayGetCount(labels2);

	while ((n1 > 0) && (n2 > 0)) {
		CFStringRef	label1	= CFArrayGetValueAtIndex(labels1, --n1);
		CFStringRef	label2	= CFArrayGetValueAtIndex(labels2, --n2);

		// compare domain labels
		result = CFStringCompare(label1, label2, kCFCompareCaseInsensitive);
		if (result != kCFCompareEqualTo) {
			goto done;
		}
	}

	// longer labels (corp.apple.com) sort before shorter labels (apple.com)
	if (n1 > n2) {
		result = kCFCompareLessThan;
		goto done;
	} else if (n1 < n2) {
		result = kCFCompareGreaterThan;
		goto done;
	}

	// sort by search order
	result = compareBySearchOrder(val1, val2, context);

    done :

	if (labels1 != NULL) CFRelease(labels1);
	if (labels2 != NULL) CFRelease(labels2);
	return result;
}
コード例 #24
0
static int
fuse_system_get_version(int *major, int *minor, int *bugfix)
{
    int ret = 0;

    CFStringRef plist_path = CFSTR(SYSTEM_VERSION_PATH);

    CFURLRef plist_url = CFURLCreateWithFileSystemPath(
            kCFAllocatorDefault, plist_path, kCFURLPOSIXPathStyle, false);
    CFReadStreamRef plist_stream = CFReadStreamCreateWithFile(
            kCFAllocatorDefault, plist_url);

    CFRelease(plist_url);
    if (!plist_stream) {
        return 1;
    }
    if (!CFReadStreamOpen(plist_stream)) {
        CFRelease(plist_stream);
        return 1;
    }

    CFPropertyListRef plist = CFPropertyListCreateWithStream(
            kCFAllocatorDefault, plist_stream, 0, kCFPropertyListImmutable,
            NULL, NULL);

    CFReadStreamClose(plist_stream);
    CFRelease(plist_stream);
    if (!plist) {
        return 1;
    }

    CFStringRef version = CFDictionaryGetValue(plist, CFSTR("ProductVersion"));
    if (!version) {
        ret = 1;
        goto out_plist;
    }

    CFArrayRef components = CFStringCreateArrayBySeparatingStrings(
            kCFAllocatorDefault, version, CFSTR("."));
    if (!components) {
        ret = 1;
        goto out_plist;
    }

    CFIndex count = CFArrayGetCount(components);

#define component_get(components, count, index) \
        ((index) < (count) \
         ? CFStringGetIntValue(CFArrayGetValueAtIndex((components), (index))) \
         : 0)

    if (major) {
        *major = component_get(components, count, 0);
    }
    if (minor) {
        *minor = component_get(components, count, 1);
    }
    if (bugfix) {
        *bugfix = component_get(components, count, 2);
    }

#undef component_get

    CFRelease(components);

out_plist:
    CFRelease(plist);

    return ret;
}
コード例 #25
0
ファイル: main.c プロジェクト: GingerLi/SDMMobileDevice
int main(int argc, const char * argv[]) {
	SDMMobileDevice;
	
	char *udid = NULL;
	
	char *service = NULL;
	
	char *help = NULL;
	
	char *domain = NULL;
	char *key = NULL;
	
	char *bundle = NULL;
	
	char *diagArg = NULL;
	
	bool searchArgs = true;
	
	char *installPath = NULL;
	
	int c;
	while (searchArgs) {
		int option_index = 0x0;
		c = getopt_long (argc, (char * const *)argv, "lh:d:ais:q:p:t:c:",long_options, &option_index);
		if (c == -1) {
			break;
		}
		switch (c) {
			case 'h': {
				if (optarg) {
					help = optarg;
				}
				optionsEnable[OptionsHelp] = true;
				searchArgs = false;
				break;
			};
			case 'l': {
				optionsEnable[OptionsList] = true;
				searchArgs = false;
				break;
			};
			case 'd': {
				if (optarg && !optionsEnable[OptionsDevice]) {
					optionsEnable[OptionsDevice] = true;
					udid = optarg;
				}
				break;
			}
			case 's': {
				if (optarg && !optionsEnable[OptionsAttach]) {
					service = optarg;
					optionsEnable[OptionsAttach] = true;
				}
				else {
					printf("please specify a service name to attach");
				}
				break;
			};
			case 'q': {
				if (optarg && !optionsEnable[OptionsQuery]) {
					CFStringRef argValue = CFStringCreateWithCString(kCFAllocatorDefault, optarg, kCFStringEncodingUTF8);
					CFArrayRef argsArray = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, argValue, CFSTR("="));
					CFIndex argsCounter = CFArrayGetCount(argsArray);
					if (argsCounter >= 0x1) {
						domain = (char*)SDMCFStringGetString(CFArrayGetValueAtIndex(argsArray, 0x0));
						if (strncmp(domain, "all", sizeof(char)*0x3) == 0x0) {
							Safe(free, domain);
							domain = calloc(0x1, sizeof(char)*(strlen(kAllDomains)+0x1));
							memcpy(domain, kAllDomains, strlen(kAllDomains));
						}
						optionsEnable[OptionsQuery] = true;
					}
					if (argsCounter == 0x2) {
						key = (char*)SDMCFStringGetString(CFArrayGetValueAtIndex(argsArray, 0x1));
					}
					else {
						key = calloc(0x1, sizeof(char)*(strlen(kAllKeys)+0x1));
						memcpy(key, kAllKeys, strlen(kAllKeys));
					}
					CFSafeRelease(argsArray);
					CFSafeRelease(argValue);
				}
				break;
			};
			case 'a': {
				optionsEnable[OptionsApps] = true;
				break;
			};
			case 'i': {
				optionsEnable[OptionsInfo] = true;
				break;
			};
			case 'r': {
				if (optarg && !optionsEnable[OptionsRun]) {
					bundle = optarg;
					optionsEnable[OptionsRun] = true;
				}
				break;
			};
			case 'p': {
				if (optarg && !optionsEnable[OptionsDiag]) {
					diagArg = optarg;
					optionsEnable[OptionsDiag] = true;
				}
				break;
			};
			case 'x': {
				optionsEnable[OptionsDev] = true;
				break;
			}
			case 't': {
				if (optarg) {
					optionsEnable[OptionsInstall] = true;
					installPath = optarg;
				}
				break;
			}
			case 'c': {
				if (optarg) {
					optionsEnable[OptionsConfig] = true;
					installPath = optarg;
				}
				break;
			}
			default: {
				printf("--help for help");
				break;
			};
		}
	}
	if (optionsEnable[OptionsHelp]) {
		if (!help) {
			printf("%s [service|query] : list available services or queries\n",helpArg);
			printf("%s : list attached devices\n",listArg);
			printf("%s [UDID] : specify a device\n",deviceArg);
			printf("%s [service] : attach to [service]\n",attachArg);
			printf("%s <domain>=<key> : query value for <key> in <domain>, specify 'null' for global domain\n",queryArg);
			printf("%s : display installed apps\n",appsArg);
			printf("%s : display info of a device\n",infoArg);
			printf("%s [bundle id] : run an application with specified [bundle id]\n",runArg);
			printf("%s [sleep|reboot|shutdown] : perform diag power operations on a device\n",powerArg);
			printf("%s : setup device for development\n",devArg);
			printf("%s [.app path] : install specificed .app to a device\n",installArg);
			printf("%s [.mobileconfig path] : install specificed .mobileconfig to a device\n",profileArg);
		}
		else {
			if (strncmp(help, "service", strlen("service")) == 0x0) {
				printf(" shorthand : service identifier\n--------------------------------\n");
				for (uint32_t i = 0x0; i < SDM_MD_Service_Count; i++) {
					printf("%10s : %s\n",SDMMDServiceIdentifiers[i].shorthand, SDMMDServiceIdentifiers[i].identifier);
				}
			}
			if (strncmp(help, "query", strlen("query")) == 0x0) {
				for (uint32_t i = 0x0; i < SDM_MD_Domain_Count; i++) {
					printf("Domain: %s\n",SDMMDKnownDomain[i].domain);
					for (uint32_t j = 0x0; j < SDMMDKnownDomain[i].keyCount; j++) {
						printf("\t%s\n",SDMMDKnownDomain[i].keys[j]);
					}
					printf("\n\n");
				}
			}
		}
	}
	if (optionsEnable[OptionsList]) {
		ListConnectedDevices();
	}
	if (optionsEnable[OptionsDevice]) {
		if (optionsEnable[OptionsInfo]) {
			
		}
		else if (optionsEnable[OptionsApps]) {
			LookupAppsOnDevice(udid);
		}
		else if (optionsEnable[OptionsAttach]) {
			PerformService(udid, service);
		}
		else if (optionsEnable[OptionsQuery]) {
			PerformQuery(udid, domain, key);
		}
		else if (optionsEnable[OptionsRun]) {
			RunAppOnDeviceWithIdentifier(udid, bundle);
		}
		else if (optionsEnable[OptionsDiag]) {
			if (diagArg) {
				if (strncmp(diagArg, "sleep", strlen("sleep")) == 0x0) {
					SendSleepToDevice(udid);
				} else if (strncmp(diagArg, "reboot", strlen("reboot")) == 0x0) {
					SendRebootToDevice(udid);
				} else if (strncmp(diagArg, "shutdown", strlen("shutdown")) == 0x0) {
					SendShutdownToDevice(udid);
				}
			}
		}
		else if (optionsEnable[OptionsDev]) {
			SetupDeviceForDevelopment(udid);
		}
		else if (optionsEnable[OptionsInstall]) {
			InstallAppToDevice(udid, installPath);
		}
		else if (optionsEnable[OptionsConfig]) {
			InstallProfileToDevice(udid, installPath);
		}
	}
	Safe(free, domain);
	Safe(free, key);
	
    return 0;
}
コード例 #26
0
ファイル: parse_url.c プロジェクト: aosm/smb
/*
 * Given a c-style string create a CFURL. We assume the c-style string is in  
 * URL or UNC format. Anything else will give unexpected behavior.
 * NOTE: The library code doesn't care if the scheme exist or not in the URL, 
 * but we attempt to create a URL with a scheme, just for correctness sake.
 *
 * Note: If its a URL, then do not escape it out again since it should already
 * be escaped out properly.
 */
CFURLRef CreateSMBURL(const char *url)
{
	CFURLRef ct_url = NULL;
	CFStringRef urlString = CFStringCreateWithCString(NULL, 
                                                      url, 
                                                      kCFStringEncodingUTF8);
    CFStringRef escapedUrlString;
    int UNCformat = 0;
    
    escapedUrlString = NULL;
	
	/* 
	 * We have a UNC path that we need to convert into a SMB URL. Currently we 
	 * just replace the backslashes with slashes
	 */
   if (urlString && (*url == '\\') && (*(url + 1) == '\\')) {
       CFArrayRef urlArray = CFStringCreateArrayBySeparatingStrings(NULL, 
                                                                    urlString, 
                                                                    CFSTR("\\"));

	   CFRelease(urlString);
	   urlString = NULL;
	   if (urlArray) {
		   urlString = CFStringCreateByCombiningStrings(NULL, 
                                                        urlArray, 
                                                        CFSTR("/"));
		   CFRelease(urlArray);
	   }
       UNCformat = 1;
    }
    
	/* Something failed just get out */
	if (!urlString) {
		return NULL;
    }
    
	DebugLogCFString(urlString, "urlString ", __FUNCTION__, __LINE__);

	/* 
	 * No scheme, add one if we can, but not required by the library code. 
	 * NOTE: If no scheme, then expect the string to start with double slashes.
	 */
	if ((!CFStringHasPrefix(urlString, CFSTR("smb://"))) && 
		(!CFStringHasPrefix(urlString, CFSTR("cifs://")))) {
		CFMutableStringRef urlStringM = CFStringCreateMutableCopy(NULL, 
                                                                  1024, 
                                                                  CFSTR("smb:"));

		if (urlStringM) {
			CFStringAppend(urlStringM, urlString);
			CFRelease(urlString);
			urlString = urlStringM;
		}
	}
    
    /* Something failed just get out */
    if (urlString == NULL) {
        return (NULL);
    }
   
    if (UNCformat == 1) {
        /* For UNC format strings, escape out any non-URL characters */
        escapedUrlString = CFURLCreateStringByAddingPercentEscapes(NULL, 
                                                                   urlString, 
                                                                   NULL, 
                                                                   NULL, 
                                                                   kCFStringEncodingUTF8);
        CFRelease(urlString);	/* Can release it now */
        
        /* Something failed just get out */
        if (escapedUrlString == NULL) {
            return (NULL);
        }

        /* now create the URL */
        ct_url = CFURLCreateWithString(kCFAllocatorDefault, 
                                       escapedUrlString, 
                                       NULL);
        
        CFRelease(escapedUrlString);	/* We create it now release it */
    }
    else {
        /* 
         * For URL format strings, it should already be escaped. 
         * Just create the URL.
         */
        ct_url = CFURLCreateWithString(kCFAllocatorDefault, 
                                       urlString, 
                                       NULL);
        
        CFRelease(urlString);	/* Can release it now */
    }
	
	return ct_url;
}
コード例 #27
0
ファイル: parse_url.c プロジェクト: aosm/smb
/*
 * We need to separate the share name and any path component from the URL.
 *	URL "smb://*****:*****@server" no share name or path.
 *	URL "smb://*****:*****@server/"no share name or path.
 *	URL "smb://*****:*****@server/share" just a share name.
 *	URL "smb://*****:*****@server/share/path" share name and path.
 *
 * The Share name and Path name will not begin with a slash.
 *		smb://server/ntfs  share = ntfs path = NULL
 *		smb://ntfs/dir1/dir2  share = ntfs path = dir1/dir2
 *		smb://server/OPEN%2fSPACE/dir1   share = OPEN%2fSPACE path = dir1
 */
static int GetShareAndPathFromURL(CFURLRef url, CFStringRef *out_share, CFStringRef *out_path)
{
	Boolean isAbsolute;
	CFArrayRef userArray = NULL;
	CFMutableArrayRef userArrayM = NULL;
	CFStringRef share = CFURLCopyStrictPath(url, &isAbsolute);
	CFStringRef path = NULL;
	
	*out_share = NULL;
	*out_path = NULL;
	/* We have an empty share treat it like no share */
	if (share && (CFStringGetLength(share) == 0)) {
		CFRelease(share);	
		share = NULL;
	}
	/* Since there is no share name we have nothing left to do. */
	if (!share)
		return 0;
	
	userArray = CFStringCreateArrayBySeparatingStrings(NULL, share, CFSTR("/"));
	if (userArray && (CFArrayGetCount(userArray) > 1))
		userArrayM = CFArrayCreateMutableCopy(NULL, CFArrayGetCount(userArray), userArray);
	
	if (userArray)
		CFRelease(userArray);
	
	if (userArrayM) {
		CFMutableStringRef newshare;	/* Just in case something goes wrong */
		
		newshare = CFStringCreateMutableCopy(NULL, 0, (CFStringRef)CFArrayGetValueAtIndex(userArrayM, 0));
		if (newshare) {
			CFStringTrim(newshare, CFSTR("/"));	/* Remove any trailing slashes */
			CreateStringByReplacingPercentEscapesUTF8((CFStringRef *) &newshare, CFSTR("/"));
		}
		CFArrayRemoveValueAtIndex(userArrayM, 0);			
			/* Now remove any trailing slashes */
		path = CFStringCreateByCombiningStrings(NULL, userArrayM, CFSTR("/"));
		if (path && (CFStringGetLength(path) == 0)) {
			CFRelease(path);	/* Empty path remove it */
			path = NULL;
		}
		if (path) {
			CFMutableStringRef newpath = CFStringCreateMutableCopy(NULL, 0, path);
			if (newpath) {
				CFStringTrim(newpath, CFSTR("/")); 	/* Remove any trailing slashes */
				CFRelease(path);
				path = newpath;							
			}
		}
		if (path) {
			CreateStringByReplacingPercentEscapesUTF8(&path, CFSTR("/"));
			LogCFString(path, "Path", __FUNCTION__, __LINE__);			
		}

		CFRelease(userArrayM);
		/* Something went wrong use the original value */
		if (newshare) {
			CFRelease(share);
			share = newshare;
		}
	} else
		CreateStringByReplacingPercentEscapesUTF8(&share, CFSTR("/"));

	/* 
	 * The above routines will not un-precent escape out slashes. We only allow for the cases
	 * where the share name is a single slash. Slashes are treated as delemiters in the path name.
	 * So if the share name has a single 0x2f then make it a slash. This means you can't have
	 * a share name whos name is 0x2f, not likley to happen.
	 */
	if (share && ( kCFCompareEqualTo == CFStringCompare (share, CFSTR("0x2f"), kCFCompareCaseInsensitive) )) {
		CFRelease(share);
		share = CFStringCreateCopy(NULL, CFSTR("/"));		
	}

	
	if (share && (CFStringGetLength(share) >= SMB_MAXSHARENAMELEN)) {
		CFRelease(share);
		if (path)
			CFRelease(path);
		return ENAMETOOLONG;
	}
	
	*out_share = share;
	*out_path = path;
	return 0;
}
コード例 #28
0
void HTTP_Stream::parseICYStream(UInt8 *buf, CFIndex bufSize)
{
    CFIndex offset = 0;
    if (!m_icyHeadersRead) {
        // TODO: fail after n tries?
        
        for (; offset < bufSize; offset++) {
            if (m_icyHeaderCR && buf[offset] == '\n') {
                m_icyHeaderLines.push_back(std::string(""));
                
                size_t n = m_icyHeaderLines.size();
                
                /* If the last two lines were empty, we have reached
                 the end of the headers */
                if (n >= 2) {                    
                    if (m_icyHeaderLines[n-2].empty() &&
                        m_icyHeaderLines[n-1].empty()) {
                        m_icyHeadersRead = true;
                        break;
                    }
                }
                
                continue;
            }
            
            if (buf[offset] == '\r') {
                m_icyHeaderCR = true;
                continue;
            } else {
                m_icyHeaderCR = false;
            }
            
            size_t numberOfLines = m_icyHeaderLines.size();
            
            if (numberOfLines == 0) {
                continue;
            }
            m_icyHeaderLines[numberOfLines - 1].push_back(buf[offset]);
        }
    } else if (!m_icyHeadersParsed) {
        const char *icyContentTypeHeader = "content-type:";
        const char *icyMetaDataHeader = "icy-metaint:";
        size_t icyContenTypeHeaderLength = strlen(icyContentTypeHeader);
        size_t icyMetaDataHeaderLength = strlen(icyMetaDataHeader);
        
        for (std::vector<std::string>::iterator h = m_icyHeaderLines.begin(); h != m_icyHeaderLines.end(); ++h) {
            if (h->compare(0, icyContenTypeHeaderLength, icyContentTypeHeader) == 0) {
                m_contentType = h->substr(icyContenTypeHeaderLength, h->length() - icyContenTypeHeaderLength);
            }
            
            if (h->compare(0, icyMetaDataHeaderLength, icyMetaDataHeader) == 0) {
                m_icyMetaDataInterval = atoi(h->substr(icyMetaDataHeaderLength, h->length() - icyMetaDataHeaderLength).c_str());
            }
        }
        
        m_icyHeadersParsed = true;
        offset++;
        
        if (m_delegate) {
            m_delegate->streamIsReadyRead();
        }
    }
    
    if (!m_icyReadBuffer) {
        m_icyReadBuffer = new UInt8[STREAM_BUFSIZ];
    }
    
    UInt32 i=0;
    
    for (; offset < bufSize; offset++) {
        // is this a metadata byte?
        if (m_metaDataBytesRemaining > 0) {
            m_metaDataBytesRemaining--;
            
            if (m_metaDataBytesRemaining == 0) {
                m_dataByteReadCount = 0;
                
                if (m_delegate && !m_icyMetaData.empty()) {
                    std::map<CFStringRef,CFStringRef> metadataMap;
                    
                    CFStringRef metaData = createMetaDataStringWithMostReasonableEncoding(&m_icyMetaData[0],
                                                                                          m_icyMetaData.size());
                    
                    if (!metaData) {
                        // Metadata encoding failed, cannot parse.
                        m_icyMetaData.clear();
                        continue;
                    }
                    
                    CFArrayRef tokens = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault,
                                                                               metaData,
                                                                               CFSTR(";"));
                    
                    for (CFIndex i=0, max=CFArrayGetCount(tokens); i < max; i++) {
                        CFStringRef token = (CFStringRef) CFArrayGetValueAtIndex(tokens, i);
                        
                        CFRange foundRange;
                        
                        if (CFStringFindWithOptions(token,
                                                    CFSTR("='"),
                                                    CFRangeMake(0, CFStringGetLength(token)),
                                                    NULL,
                                                    &foundRange) == true) {
                            
                            CFRange keyRange = CFRangeMake(0, foundRange.location);
                            
                            CFStringRef metadaKey = CFStringCreateWithSubstring(kCFAllocatorDefault,
                                                                                token,
                                                                                keyRange);
                            
                            CFRange valueRange = CFRangeMake(foundRange.location + 2, CFStringGetLength(token) - keyRange.length - 3);
                            
                            CFStringRef metadaValue = CFStringCreateWithSubstring(kCFAllocatorDefault,
                                                                                  token,
                                                                                  valueRange);
                            
                            metadataMap[metadaKey] = metadaValue;
                        }
                    }
                    
                    CFRelease(tokens);
                    CFRelease(metaData);
                    
                    m_delegate->streamMetaDataAvailable(metadataMap);
                }
                m_icyMetaData.clear();
                continue;
            }
            
            m_icyMetaData.push_back(buf[offset]);
            continue;
        }
        
        // is this the interval byte?
        if (m_icyMetaDataInterval > 0 && m_dataByteReadCount == m_icyMetaDataInterval) {
            m_metaDataBytesRemaining = buf[offset] * 16;
            
            if (m_metaDataBytesRemaining == 0) {
                m_dataByteReadCount = 0;
            }
            continue;
        }
        
        // a data byte
        m_dataByteReadCount++;
        m_icyReadBuffer[i++] = buf[offset];
    }
    
    if (m_delegate && i > 0) {
        m_delegate->streamHasBytesAvailable(m_icyReadBuffer, i);
    }
}
コード例 #29
0
ファイル: parse_url.c プロジェクト: aosm/smb
/*
 * See if this is a BTMM address
 */
int isBTMMAddress(CFStringRef serverNameRef)
{
    boolean_t	foundBTMM;
    CFStringRef btmmRef;
    CFStringRef serverNameQual;
    CFIndex serverNameLen, btmmCount, serverCount, btmmIndex, srvIndex;
    CFArrayRef btmmArrRef, serverArrRef;
    CFStringRef btmmTmpRef, serverTmpRef;
    CFComparisonResult res;
    
    foundBTMM = TRUE;
    btmmRef = NULL;
    serverNameQual = NULL;
    btmmArrRef = NULL;
    serverArrRef = NULL;
	
	if (serverNameRef == NULL) {
		smb_log_info("%s: serverNameRef is NULL!", ASL_LEVEL_DEBUG, __FUNCTION__);
		foundBTMM = FALSE;
        goto out;
	}
	
    serverNameLen = CFStringGetLength(serverNameRef);
	if (serverNameLen == 0) {
		smb_log_info("%s: serverNameRef len is 0!", ASL_LEVEL_DEBUG, __FUNCTION__);
		foundBTMM = FALSE;
        goto out;
	}
    
    /*  Create a copy of the server name, add a trailing '.' */
    /*  if it doesn't already have one. */
    if (CFStringGetCharacterAtIndex(serverNameRef, serverNameLen - 1) == (UniChar)'.') {
        serverNameQual = CFStringCreateCopy(kCFAllocatorDefault, serverNameRef);
    } else {
        serverNameQual = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@."), serverNameRef);
    }
    
    if (serverNameQual == NULL) {
		foundBTMM = FALSE;
        goto out;
    }
    
    /* Fetch BTMM domain from DynamicStore */
    btmmRef = _CSBackToMyMacCopyDomain();
    if (btmmRef == NULL) {
		foundBTMM = FALSE;
        goto out;
    }
    
    /* Split them into component string arrays */
    btmmArrRef = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, btmmRef, CFSTR("."));
    btmmCount = CFArrayGetCount(btmmArrRef);
    
    serverArrRef = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, serverNameQual, CFSTR("."));
    serverCount = CFArrayGetCount(serverArrRef);
    
    if (btmmCount == 0 || serverCount == 0) {
		foundBTMM = FALSE;
        goto out;
    }
    
    if (btmmCount > serverCount) {
        /* Not a BTMM domain */
		foundBTMM = FALSE;
        goto out;
    }
    
    for (btmmIndex = btmmCount - 1, srvIndex = serverCount - 1; btmmIndex >= 0; btmmIndex--, srvIndex--) {
        btmmTmpRef = CFArrayGetValueAtIndex(btmmArrRef, btmmIndex);
        serverTmpRef = CFArrayGetValueAtIndex(serverArrRef, srvIndex);
        
        res = CFStringCompare(btmmTmpRef, serverTmpRef, kCFCompareCaseInsensitive);
        if (res != kCFCompareEqualTo) {
            /* Not a BTMM domain */
            foundBTMM = FALSE;
            break;
        }
    }
        
	if (foundBTMM == TRUE) {
        smb_log_info("%s: found a btmm address", ASL_LEVEL_DEBUG, __FUNCTION__);
	}

out:
    
    // Clean up mem
    if (btmmArrRef != NULL) {
        CFRelease(btmmArrRef);
    }
    if (serverArrRef != NULL) {
        CFRelease(serverArrRef);
    }
    if (btmmRef != NULL) {
        CFRelease(btmmRef);
    }
    if (serverNameQual !=NULL) {
        CFRelease(serverNameQual);
    }
    
	return (foundBTMM);
}
コード例 #30
0
ファイル: SCNetworkSet.c プロジェクト: carriercomm/osx-2
CFArrayRef /* of SCNetworkServiceRef's */
SCNetworkSetCopyServices(SCNetworkSetRef set)
{
	CFMutableArrayRef       array;
	CFDictionaryRef		dict;
	CFIndex			n;
	CFStringRef		path;
	SCNetworkSetPrivateRef	setPrivate	= (SCNetworkSetPrivateRef)set;

	if (!isA_SCNetworkSet(set)) {
		_SCErrorSet(kSCStatusInvalidArgument);
		return NULL;
	}

	path = SCPreferencesPathKeyCreateSetNetworkService(NULL, setPrivate->setID, NULL);
	dict = SCPreferencesPathGetValue(setPrivate->prefs, path);
	CFRelease(path);
	if ((dict != NULL) && !isA_CFDictionary(dict)) {
		return NULL;
	}

	array = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);

	n = (dict != NULL) ? CFDictionaryGetCount(dict) : 0;
	if (n > 0) {
		CFIndex		i;
		const void *    keys_q[N_QUICK];
		const void **   keys	= keys_q;

		if (n > (CFIndex)(sizeof(keys_q) / sizeof(CFTypeRef))) {
			keys = CFAllocatorAllocate(NULL, n * sizeof(CFTypeRef), 0);
		}
		CFDictionaryGetKeysAndValues(dict, keys, NULL);
		for (i = 0; i < n; i++) {
			CFArrayRef	components;
			CFStringRef	link;

			path = SCPreferencesPathKeyCreateSetNetworkServiceEntity(NULL,
										 setPrivate->setID,
										 (CFStringRef)keys[i],
										 NULL);
			link = SCPreferencesPathGetLink(setPrivate->prefs, path);
			CFRelease(path);
			if (link == NULL) {
				SC_log(LOG_INFO, "service \"%@\" for set \"%@\" is not a link",
				       keys[i],
				       setPrivate->setID);
				continue;	 // if the service is not a link
			}

			components = CFStringCreateArrayBySeparatingStrings(NULL, link, CFSTR("/"));
			if (CFArrayGetCount(components) == 3) {
				CFStringRef serviceID;

				serviceID = CFArrayGetValueAtIndex(components, 2);
				path = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL,		// allocator
										      serviceID,	// service
										      NULL);		// entity
				if (CFEqual(path, link)) {
					SCNetworkServicePrivateRef	servicePrivate;

					servicePrivate = __SCNetworkServiceCreatePrivate(NULL,
											 setPrivate->prefs,
											 serviceID,
											 NULL);
					CFArrayAppendValue(array, (SCNetworkServiceRef)servicePrivate);
					CFRelease(servicePrivate);
				}
				CFRelease(path);
			}
			CFRelease(components);
		}
		if (keys != keys_q) {
			CFAllocatorDeallocate(NULL, keys);
		}
	}

	return array;
}