Example #1
0
File: bs.c Project: MSch/MacRuby
static inline const char *
_bs_main_bundle_bs_path(void)
{
  static bool done = false;
  static char *path = NULL;
  /* XXX not thread-safe */
  if (!done) {
    CFBundleRef bundle;

    done = true;
    bundle = CFBundleGetMainBundle();
    if (bundle != NULL) {
      CFURLRef url;

      url = CFBundleCopyResourceURL(bundle, CFSTR("BridgeSupport"), 
                                    NULL, NULL);
      if (url != NULL) {
        CFStringRef str = CFURLCopyPath(url);
        path = (char *)malloc(sizeof(char) * PATH_MAX);
	ASSERT_ALLOC(path);
        CFStringGetFileSystemRepresentation(str, path, PATH_MAX);
        CFRelease(str);
        CFRelease(url);
      }
    }
  }
  return path;
}
// Asssumes caller already knows the directory doesn't exist.
static Boolean _createDirectory(CFURLRef dirURL, Boolean worldReadable) {
    CFAllocatorRef alloc = __CFPreferencesAllocator();
    CFURLRef parentURL = CFURLCreateCopyDeletingLastPathComponent(alloc, dirURL);
    CFBooleanRef val = (CFBooleanRef) CFURLCreatePropertyFromResource(alloc, parentURL, kCFURLFileExists, NULL);
    Boolean parentExists = (val && CFBooleanGetValue(val));
    SInt32 mode;
    Boolean result;
    if (val) CFRelease(val);
    if (!parentExists) {
        CFStringRef path = CFURLCopyPath(parentURL);
        if (!CFEqual(path, CFSTR("/"))) {
            _createDirectory(parentURL, worldReadable);
            val = (CFBooleanRef) CFURLCreatePropertyFromResource(alloc, parentURL, kCFURLFileExists, NULL);
            parentExists = (val && CFBooleanGetValue(val));
            if (val) CFRelease(val);
        }
        CFRelease(path);
    }
    if (parentURL) CFRelease(parentURL);
    if (!parentExists) return false;

#if TARGET_OS_OSX || TARGET_OS_LINUX
    mode = worldReadable ? S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH : S_IRWXU;
#else
    mode = 0666;
#endif

    result = CFURLWriteDataAndPropertiesToResource(dirURL, (CFDataRef)dirURL, URLPropertyDictForPOSIXMode(mode), NULL);
    URLPropertyDictRelease();
    return result;
}
Example #3
0
const char *
sys_runtime_dir(void)
{
	if (_nix_runtime_dir[0] == 0x0) {
	#if defined(_IOS)
		CFURLRef url = CFCopyHomeDirectoryURL();
		CFStringRef path = CFURLCopyPath(url);
		
		memset(_nix_tmp_buff, 0x0, PATH_MAX);
		CFStringGetCString(path, _nix_tmp_buff, PATH_MAX, kCFStringEncodingUTF8);
		
		CFRelease(path);
		CFRelease(url);
		
		snprintf(_nix_cache_dir, PATH_MAX, "%s/run", _nix_tmp_buff);
	#elif defined(__ANDROID__)
	#else
		snprintf(_nix_runtime_dir, PATH_MAX, "/var/run/%s", _miwa_sys_name);
	#endif
	
		if (sys_directory_exists(_nix_runtime_dir) < 0)
			sys_create_directory(_nix_runtime_dir);
	}

	return _nix_runtime_dir;
}
Example #4
0
	FILE* fopen (const char *filename, const char *mode) {
		
		#ifdef HX_MACOS
		FILE *result = ::fopen (filename, "rb");
		if (!result) {
			CFStringRef str = CFStringCreateWithCString (NULL, filename, kCFStringEncodingUTF8);
			CFURLRef path = CFBundleCopyResourceURL (CFBundleGetMainBundle (), str, NULL, NULL);
			CFRelease (str);
			if (path) {
				str = CFURLCopyPath (path);
				CFIndex maxSize = CFStringGetMaximumSizeForEncoding (CFStringGetLength (str), kCFStringEncodingUTF8);
				char *buffer = (char *)malloc (maxSize);
				if (CFStringGetCString (str, buffer, maxSize, kCFStringEncodingUTF8)) {
					result = ::fopen (buffer,"rb");
					free (buffer);
				}
				CFRelease (str);
				CFRelease (path);
			}
		}
		return result;
		#else
		return ::fopen (filename, mode);
		#endif
		
	}
Example #5
0
void fill_pathname_application_path(char *buf, size_t size)
{
   size_t i;
   (void)i;
   if (!size)
      return;

#ifdef _WIN32
   DWORD ret = GetModuleFileName(GetModuleHandle(NULL), buf, size - 1);
   buf[ret] = '\0';
#elif defined(__APPLE__)
   CFBundleRef bundle = CFBundleGetMainBundle();
   if (bundle)
   {
      CFURLRef bundle_url = CFBundleCopyBundleURL(bundle);
      CFStringRef bundle_path = CFURLCopyPath(bundle_url);
      CFStringGetCString(bundle_path, buf, size, kCFStringEncodingUTF8);
      CFRelease(bundle_path);
      CFRelease(bundle_url);
      
      rarch_assert(strlcat(buf, "nobin", size) < size);
      return;
   }
#elif defined(__HAIKU__)
   image_info info;
   int32 cookie = 0;

   while (get_next_image_info(0, &cookie, &info) == B_OK)
   {
      if (info.type == B_APP_IMAGE)
      {
         strlcpy(buf, info.name, size);
         return;
      }
   }
#else
   *buf = '\0';
   pid_t pid = getpid(); 
   char link_path[PATH_MAX];
   /* Linux, BSD and Solaris paths. Not standardized. */
   static const char *exts[] = { "exe", "file", "path/a.out" };
   for (i = 0; i < ARRAY_SIZE(exts); i++)
   {
      snprintf(link_path, sizeof(link_path), "/proc/%u/%s",
            (unsigned)pid, exts[i]);
      ssize_t ret = readlink(link_path, buf, size - 1);
      if (ret >= 0)
      {
         buf[ret] = '\0';
         return;
      }
   }
   
   RARCH_ERR("Cannot resolve application path! This should not happen.\n");
#endif
}
Example #6
0
// function provides some Mac OS X specific source code to load files from the resources of the application bundle.
char * resPath(char **argv, char* name, char* type ) 
{
	static char resource[1024];
	CFURLRef cfBundleURL = CFBundleCopyResourceURL( CFBundleGetMainBundle(),    
	CFStringCreateWithCString(kCFAllocatorDefault,name, kCFStringEncodingISOLatin1), 
	CFStringCreateWithCString(kCFAllocatorDefault,type,kCFStringEncodingISOLatin1), 
	NULL);
	CFStringGetCString( CFURLCopyPath(cfBundleURL),
		resource,1023,kCFStringEncodingISOLatin1);
   return resource;
}
Example #7
0
CRESTRequestRef CRESTRequestCreateWithBytes(UInt8 const *bytes, ssize_t len)
{
	CFURLRef url;
	CRESTRequestRef request;
	CFHTTPMessageRef message;

	message	= CFHTTPMessageCreateEmpty(kCFAllocatorDefault, true);
	request = calloc(1, sizeof(struct CRESTRequest));
	assert(request);
	bool isAppended = CFHTTPMessageAppendBytes(message, bytes, (CFIndex) len);
	bool isComplete = CFHTTPMessageIsHeaderComplete(message);

	if( ! ( isAppended && isComplete ) )
	{
		CFRelease(message);
		CRESTRequestDealloc(request);
		return NULL;
	}

	url = CFHTTPMessageCopyRequestURL(message);

	CFMutableDictionaryRef params = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks,
			&kCFTypeDictionaryValueCallBacks);

	CFStringRef query = CFURLCopyQueryString(url, NULL);
	if( query )
	{
		parseParams(params, query);
		CFRelease(query);
	}

	CFDataRef bodyData = CFHTTPMessageCopyBody(message);
	if( CFDataGetLength(bodyData) )
	{
		CFStringRef bodyString = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, bodyData,
				kCFStringEncodingUTF8);
		parseParams(params, bodyString);
		CFRelease(bodyString);
	}
	CFRelease(bodyData);

	request->method = CFHTTPMessageCopyRequestMethod(message);
	request->path = CFURLCopyPath(url);
	request->params = (CFDictionaryRef) params;

	CFRelease(url);
	CFRelease(message);

	return request;
}
Example #8
0
static CFIndex CFURLEnumeratorPushURL(CFURLEnumeratorRef enumerator, CFURLRef url, CFErrorRef *error) {
    char path[PATH_MAX] = { 0 };
    CFStringRef urlPath = CFURLCopyPath(url);
    Boolean success = CFStringGetFileSystemRepresentation(urlPath, path, PATH_MAX);
    
    if (!success) {
        cocoaError(error, -1, url, urlPath);
        CFRelease(urlPath);
        return kCFNotFound;
    }

    DIR *dir = opendir(path);
    if (dir == NULL) {
        posixError(error, url, urlPath);
        CFRelease(urlPath);
        return kCFNotFound;
    }

    CFMutableArrayRef fileInfos = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);

    struct dirent *current = NULL;
    while ((current = readdir(dir)) != NULL) {
        if (strcmp(current->d_name, ".") == 0 || strcmp(current->d_name, "..") == 0) {
            continue;
        }
        CFMutableDictionaryRef fileInfo = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
        CFStringRef fileName = CFStringCreateWithBytes(kCFAllocatorDefault, current->d_name, strlen(current->d_name), kCFStringEncodingUTF8, false);
        CFDictionarySetValue(fileInfo, fileInfoNameKey, fileName);
        CFDictionarySetValue(fileInfo, fileInfoIsDirKey, current->d_type == DT_DIR ? kCFBooleanTrue : kCFBooleanFalse);
        CFArrayAppendValue(fileInfos, fileInfo);
        CFRelease(fileName);
        CFRelease(fileInfo);
    }

    CFArraySortValues(fileInfos, CFRangeMake(0, CFArrayGetCount(fileInfos)), _compareFileInfo, nil);
    CFArrayAppendValue(enumerator->urlStack, url);
    CFArrayAppendValue(enumerator->dirFileInfos, fileInfos);
    CFRelease(urlPath);
    CFRelease(fileInfos);
    closedir(dir);
    return CFArrayGetCount(enumerator->urlStack);
}
Example #9
0
 CF::String URL::GetPath( void )
 {
     CF::String  str;
     CFStringRef cfStr;
     
     if( this->_cfObject == NULL )
     {
         return str;
     }
     
     cfStr = CFURLCopyPath( this->_cfObject );
     
     if( cfStr != NULL )
     {
         str = cfStr;
         
         CFRelease( cfStr );
     }
     
     return str;
 }
Example #10
0
static void
__SCDynamicStoreInitialize(void)
{
	CFBundleRef	bundle;

	/* register with CoreFoundation */
	__kSCDynamicStoreTypeID = _CFRuntimeRegisterClass(&__SCDynamicStoreClass);

	/* add handler to cleanup after fork() */
	(void) pthread_atfork(NULL, NULL, childForkHandler);

	/* get the application/executable/bundle name */
	bundle = CFBundleGetMainBundle();
	if (bundle != NULL) {
		_sc_bundleID = CFBundleGetIdentifier(bundle);
		if (_sc_bundleID != NULL) {
			CFRetain(_sc_bundleID);
		} else {
			CFURLRef	url;

			url = CFBundleCopyExecutableURL(bundle);
			if (url != NULL) {
				_sc_bundleID = CFURLCopyPath(url);
				CFRelease(url);
			}
		}

		if (_sc_bundleID != NULL) {
			if (CFEqual(_sc_bundleID, CFSTR("/"))) {
				CFRelease(_sc_bundleID);
				_sc_bundleID = CFStringCreateWithFormat(NULL, NULL, CFSTR("(%d)"), getpid());
			}
		}
	}

	return;
}
Example #11
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;
}
Example #12
0
static const char *			/* O - Locale string */
appleLangDefault(void)
{
  int			i;		/* Looping var */
  CFBundleRef		bundle;		/* Main bundle (if any) */
  CFArrayRef		bundleList;	/* List of localizations in bundle */
  CFPropertyListRef 	localizationList = NULL;
					/* List of localization data */
  CFStringRef		languageName;	/* Current name */
  CFStringRef		localeName;	/* Canonical from of name */
  char			*lang;		/* LANG environment variable */
  _cups_globals_t	*cg = _cupsGlobals();
  					/* Pointer to library globals */


  DEBUG_puts("2appleLangDefault()");

 /*
  * Only do the lookup and translation the first time.
  */

  if (!cg->language[0])
  {
    if (getenv("SOFTWARE") != NULL && (lang = getenv("LANG")) != NULL)
    {
      DEBUG_printf(("3appleLangDefault: Using LANG=%s", lang));
      strlcpy(cg->language, lang, sizeof(cg->language));
      return (cg->language);
    }
    else if ((bundle = CFBundleGetMainBundle()) != NULL &&
             (bundleList = CFBundleCopyBundleLocalizations(bundle)) != NULL)
    {
      CFURLRef resources = CFBundleCopyResourcesDirectoryURL(bundle);

      DEBUG_puts("3appleLangDefault: Getting localizationList from bundle.");

      if (resources)
      {
        CFStringRef	cfpath = CFURLCopyPath(resources);
	char		path[1024];

        if (cfpath)
	{
	 /*
	  * See if we have an Info.plist file in the bundle...
	  */

	  CFStringGetCString(cfpath, path, sizeof(path), kCFStringEncodingUTF8);
	  DEBUG_printf(("3appleLangDefault: Got a resource URL (\"%s\")", path));
	  strlcat(path, "Contents/Info.plist", sizeof(path));

          if (!access(path, R_OK))
	    localizationList = CFBundleCopyPreferredLocalizationsFromArray(bundleList);
	  else
	    DEBUG_puts("3appleLangDefault: No Info.plist, ignoring resource URL...");

	  CFRelease(cfpath);
	}

	CFRelease(resources);
      }
      else
        DEBUG_puts("3appleLangDefault: No resource URL.");

      CFRelease(bundleList);
    }

    if (!localizationList)
    {
      DEBUG_puts("3appleLangDefault: Getting localizationList from preferences.");

      localizationList =
	  CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),
				    kCFPreferencesCurrentApplication);
    }

    if (localizationList)
    {
#ifdef DEBUG
      if (CFGetTypeID(localizationList) == CFArrayGetTypeID())
        DEBUG_printf(("3appleLangDefault: Got localizationList, %d entries.",
                      (int)CFArrayGetCount(localizationList)));
      else
        DEBUG_puts("3appleLangDefault: Got localizationList but not an array.");
#endif /* DEBUG */

      if (CFGetTypeID(localizationList) == CFArrayGetTypeID() &&
	  CFArrayGetCount(localizationList) > 0)
      {
	languageName = CFArrayGetValueAtIndex(localizationList, 0);

	if (languageName &&
	    CFGetTypeID(languageName) == CFStringGetTypeID())
	{
	  localeName = CFLocaleCreateCanonicalLocaleIdentifierFromString(
			   kCFAllocatorDefault, languageName);

	  if (localeName)
	  {
	    CFStringGetCString(localeName, cg->language, sizeof(cg->language),
			       kCFStringEncodingASCII);
	    CFRelease(localeName);

	    DEBUG_printf(("3appleLangDefault: cg->language=\"%s\"",
			  cg->language));

	   /*
	    * Map new language identifiers to locales...
	    */

	    for (i = 0;
		 i < (int)(sizeof(apple_language_locale) /
		           sizeof(apple_language_locale[0]));
		 i ++)
	    {
	      if (!strcmp(cg->language, apple_language_locale[i].language))
	      {
		DEBUG_printf(("3appleLangDefault: mapping \"%s\" to \"%s\"...",
			      cg->language, apple_language_locale[i].locale));
		strlcpy(cg->language, apple_language_locale[i].locale,
			sizeof(cg->language));
		break;
	      }
	    }

	   /*
	    * Convert language subtag into region subtag...
	    */

	    if (cg->language[2] == '-')
	      cg->language[2] = '_';

	    if (!strchr(cg->language, '.'))
	      strlcat(cg->language, ".UTF-8", sizeof(cg->language));
	  }
	  else
	    DEBUG_puts("3appleLangDefault: Unable to get localeName.");
	}
      }

      CFRelease(localizationList);
    }

   /*
    * If we didn't find the language, default to en_US...
    */

    if (!cg->language[0])
    {
      DEBUG_puts("3appleLangDefault: Defaulting to en_US.");
      strlcpy(cg->language, "en_US.UTF-8", sizeof(cg->language));
    }
  }
  else
    DEBUG_printf(("3appleLangDefault: Using previous locale \"%s\".", cg->language));

 /*
  * Return the cached locale...
  */

  return (cg->language);
}
Example #13
0
static void frontend_apple_get_environment_settings(int *argc, char *argv[],
      void *args, void *params_data)
{
   char bundle_path_buf[PATH_MAX_LENGTH], home_dir_buf[PATH_MAX_LENGTH],
        support_path_buf[PATH_MAX_LENGTH];
   CFURLRef bundle_url;
   CFStringRef bundle_path;
   CFBundleRef bundle = CFBundleGetMainBundle();
    
   (void)support_path_buf;

   if (!bundle)
      return;

   bundle_url  = CFBundleCopyBundleURL(bundle);
   bundle_path = CFURLCopyPath(bundle_url);
    
   CFStringGetCString(bundle_path, bundle_path_buf, sizeof(bundle_path_buf), kCFStringEncodingUTF8);
   (void)home_dir_buf;
   
#ifdef IOS
    CFSearchPathForDirectoriesInDomains(CFDocumentDirectory, CFUserDomainMask, 1, home_dir_buf, sizeof(home_dir_buf));
   
   fill_pathname_join(g_defaults.system_dir, home_dir_buf, ".RetroArch", sizeof(g_defaults.system_dir));
   fill_pathname_join(g_defaults.core_dir, bundle_path_buf, "modules", sizeof(g_defaults.core_dir));
   fill_pathname_join(g_defaults.core_info_dir, bundle_path_buf, "info", sizeof(g_defaults.core_info_dir));
   fill_pathname_join(g_defaults.shader_dir, bundle_path_buf, "shaders_glsl", sizeof(g_defaults.shader_dir));
    fill_pathname_join(g_defaults.overlay_dir, bundle_path_buf, "overlays", sizeof(g_defaults.overlay_dir));

   strlcpy(g_defaults.menu_config_dir, g_defaults.system_dir, sizeof(g_defaults.menu_config_dir));
   fill_pathname_join(g_defaults.config_path, g_defaults.menu_config_dir, "retroarch.cfg", sizeof(g_defaults.config_path));

   strlcpy(g_defaults.sram_dir, g_defaults.system_dir, sizeof(g_defaults.sram_dir));
   strlcpy(g_defaults.savestate_dir, g_defaults.system_dir, sizeof(g_defaults.savestate_dir));

   path_mkdir(bundle_path_buf);

   if (access(bundle_path_buf, 0755) != 0)
      RARCH_ERR("Failed to create or access base directory: %s\n", bundle_path_buf);
   else
   {
      path_mkdir(g_defaults.system_dir);

      if (access(g_defaults.system_dir, 0755) != 0)
         RARCH_ERR("Failed to create or access system directory: %s.\n", g_defaults.system_dir);
   }
#elif defined(OSX)
    CFSearchPathForDirectoriesInDomains(CFApplicationSupportDirectory, CFUserDomainMask, 1, support_path_buf, sizeof(support_path_buf));
    
    fill_pathname_join(g_defaults.core_dir, "~/Library/Application Support/RetroArch", "cores", sizeof(g_defaults.core_dir));
    fill_pathname_join(g_defaults.core_info_dir, "~/Library/Application Support/RetroArch", "info", sizeof(g_defaults.core_info_dir));
    /* TODO/FIXME - we might need to update all these paths too and put them all in ~/Library/Application Support, but that would
     * require copying all the resource files that are bundled in the app bundle over first to this new directory.
     *
     * Ideas: There's some overlap here with how the Android APK has to extract all its resource files over to the actual sandboxed
     * app dir, maybe try to create something standardized for both platforms (OSX/Android) */
    fill_pathname_join(g_defaults.overlay_dir, bundle_path_buf, "Contents/Resources/overlays", sizeof(g_defaults.overlay_dir));
    fill_pathname_join(g_defaults.autoconfig_dir, bundle_path_buf, "Contents/Resources/autoconfig/apple", sizeof(g_defaults.autoconfig_dir));
    fill_pathname_join(g_defaults.assets_dir, bundle_path_buf, "Contents/Resources/assets", sizeof(g_defaults.assets_dir));
    fill_pathname_join(g_defaults.shader_dir, bundle_path_buf, "Contents/Resources/shaders", sizeof(g_defaults.shader_dir));
    fill_pathname_join(g_defaults.audio_filter_dir, bundle_path_buf, "Contents/Resources/audio_filters", sizeof(g_defaults.audio_filter_dir));
    fill_pathname_join(g_defaults.video_filter_dir, bundle_path_buf, "Contents/Resources/video_filters", sizeof(g_defaults.video_filter_dir));
    fill_pathname_join(g_defaults.menu_config_dir, support_path_buf, "RetroArch", sizeof(g_defaults.menu_config_dir));
    fill_pathname_join(g_defaults.config_path, g_defaults.menu_config_dir, "retroarch.cfg", sizeof(g_defaults.config_path));
#endif

   CFRelease(bundle_path);
   CFRelease(bundle_url);
}
Example #14
0
/*
 * Creates a vector of driver bundle info structures from the hot-plug driver
 * directory.
 *
 * Returns NULL on error and a pointer to an allocated HPDriver vector on
 * success.  The caller must free the HPDriver with a call to
 * HPDriversRelease().
 */
static HPDriverVector HPDriversGetFromDirectory(const char *driverBundlePath)
{
#ifdef DEBUG_HOTPLUG
	Log2(PCSC_LOG_DEBUG, "Entering HPDriversGetFromDirectory: %s",
		driverBundlePath);
#endif

	int readersNumber = 0;
	HPDriverVector bundleVector = NULL;
	CFArrayRef bundleArray;
	CFStringRef driverBundlePathString =
		CFStringCreateWithCString(kCFAllocatorDefault,
		driverBundlePath,
		kCFStringEncodingMacRoman);
	CFURLRef pluginUrl = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
		driverBundlePathString,
		kCFURLPOSIXPathStyle, TRUE);

	CFRelease(driverBundlePathString);
	if (!pluginUrl)
	{
		Log1(PCSC_LOG_ERROR, "error getting plugin directory URL");
		return NULL;
	}
	bundleArray = CFBundleCreateBundlesFromDirectory(kCFAllocatorDefault,
		pluginUrl, NULL);
	if (!bundleArray)
	{
		Log1(PCSC_LOG_ERROR, "error getting plugin directory bundles");
		return NULL;
	}
	CFRelease(pluginUrl);

	size_t bundleArraySize = CFArrayGetCount(bundleArray);
	size_t i;

	/* get the number of readers (including aliases) */
	for (i = 0; i < bundleArraySize; i++)
	{
		CFBundleRef currBundle =
			(CFBundleRef) CFArrayGetValueAtIndex(bundleArray, i);
		CFDictionaryRef dict = CFBundleGetInfoDictionary(currBundle);

		const void * blobValue = CFDictionaryGetValue(dict,
			CFSTR(PCSCLITE_HP_MANUKEY_NAME));

		if (!blobValue)
		{
			Log1(PCSC_LOG_ERROR, "error getting vendor ID from bundle");
			return NULL;
		}

		if (CFGetTypeID(blobValue) == CFArrayGetTypeID())
		{
			/* alias found, each reader count as 1 */
			CFArrayRef propertyArray = blobValue;
			readersNumber += CFArrayGetCount(propertyArray);
		}
		else
			/* No alias, only one reader supported */
			readersNumber++;
	}
#ifdef DEBUG_HOTPLUG
	Log2(PCSC_LOG_DEBUG, "Total of %d readers supported", readersNumber);
#endif

	/* The last entry is an end marker (m_vendorId = 0)
	 * see checks in HPDriversMatchUSBDevices:503
	 *  and HPDriverVectorRelease:376 */
	readersNumber++;

	bundleVector = calloc(readersNumber, sizeof(HPDriver));
	if (!bundleVector)
	{
		Log1(PCSC_LOG_ERROR, "memory allocation failure");
		return NULL;
	}

	HPDriver *driverBundle = bundleVector;
	for (i = 0; i < bundleArraySize; i++)
	{
		CFBundleRef currBundle =
			(CFBundleRef) CFArrayGetValueAtIndex(bundleArray, i);
		CFDictionaryRef dict = CFBundleGetInfoDictionary(currBundle);

		CFURLRef bundleUrl = CFBundleCopyBundleURL(currBundle);
		CFStringRef bundlePath = CFURLCopyPath(bundleUrl);

		driverBundle->m_libPath = strdup(CFStringGetCStringPtr(bundlePath,
				CFStringGetSystemEncoding()));

		const void * blobValue = CFDictionaryGetValue(dict,
			CFSTR(PCSCLITE_HP_MANUKEY_NAME));

		if (!blobValue)
		{
			Log1(PCSC_LOG_ERROR, "error getting vendor ID from bundle");
			return bundleVector;
		}

		if (CFGetTypeID(blobValue) == CFArrayGetTypeID())
		{
			CFArrayRef vendorArray = blobValue;
			CFArrayRef productArray;
			CFArrayRef friendlyNameArray;
			char *libPath = driverBundle->m_libPath;

#ifdef DEBUG_HOTPLUG
			Log2(PCSC_LOG_DEBUG, "Driver with aliases: %s", libPath);
#endif
			/* get list of ProductID */
			productArray = CFDictionaryGetValue(dict,
				 CFSTR(PCSCLITE_HP_PRODKEY_NAME));
			if (!productArray)
			{
				Log1(PCSC_LOG_ERROR, "error getting product ID from bundle");
				return bundleVector;
			}

			/* get list of FriendlyName */
			friendlyNameArray = CFDictionaryGetValue(dict,
				 CFSTR(PCSCLITE_HP_NAMEKEY_NAME));
			if (!friendlyNameArray)
			{
				Log1(PCSC_LOG_ERROR, "error getting product ID from bundle");
				return bundleVector;
			}

			int reader_nb = CFArrayGetCount(vendorArray);

			if (reader_nb != CFArrayGetCount(productArray))
			{
				Log3(PCSC_LOG_ERROR,
					"Malformed Info.plist: %d vendors and %ld products",
					reader_nb, CFArrayGetCount(productArray));
				return bundleVector;
			}

			if (reader_nb != CFArrayGetCount(friendlyNameArray))
			{
				Log3(PCSC_LOG_ERROR,
					"Malformed Info.plist: %d vendors and %ld friendlynames",
					reader_nb, CFArrayGetCount(friendlyNameArray));
				return bundleVector;
			}

			int j;
			for (j=0; j<reader_nb; j++)
			{
				CFStringRef strValue = CFArrayGetValueAtIndex(vendorArray, j);

				driverBundle->m_vendorId = strtoul(CFStringGetCStringPtr(strValue,
					CFStringGetSystemEncoding()), NULL, 16);

				strValue = CFArrayGetValueAtIndex(productArray, j);
				driverBundle->m_productId = strtoul(CFStringGetCStringPtr(strValue,
					CFStringGetSystemEncoding()), NULL, 16);

				strValue = CFArrayGetValueAtIndex(friendlyNameArray, j);
				const char *cstr = CFStringGetCStringPtr(strValue,
					CFStringGetSystemEncoding());

				driverBundle->m_friendlyName = strdup(cstr);
				if (!driverBundle->m_libPath)
					driverBundle->m_libPath = strdup(libPath);

#ifdef DEBUG_HOTPLUG
				Log2(PCSC_LOG_DEBUG, "VendorID: 0x%04X",
					driverBundle->m_vendorId);
				Log2(PCSC_LOG_DEBUG, "ProductID: 0x%04X",
					driverBundle->m_productId);
				Log2(PCSC_LOG_DEBUG, "Friendly name: %s",
					driverBundle->m_friendlyName);
				Log2(PCSC_LOG_DEBUG, "Driver: %s", driverBundle->m_libPath);
#endif

				/* go to next bundle in the vector */
				driverBundle++;
			}
		}
		else
		{
			CFStringRef strValue = blobValue;

#ifdef DEBUG_HOTPLUG
			Log3(PCSC_LOG_DEBUG, "Driver without alias: %s %s",
				driverBundle->m_friendlyName, driverBundle->m_libPath);
#endif

			driverBundle->m_vendorId = strtoul(CFStringGetCStringPtr(strValue,
					CFStringGetSystemEncoding()), NULL, 16);

			strValue = (CFStringRef) CFDictionaryGetValue(dict,
				CFSTR(PCSCLITE_HP_PRODKEY_NAME));
			if (!strValue)
			{
				Log1(PCSC_LOG_ERROR, "error getting product ID from bundle");
				return bundleVector;
			}
			driverBundle->m_productId = strtoul(CFStringGetCStringPtr(strValue,
				CFStringGetSystemEncoding()), NULL, 16);

			strValue = (CFStringRef) CFDictionaryGetValue(dict,
				CFSTR(PCSCLITE_HP_NAMEKEY_NAME));
			if (!strValue)
			{
				Log1(PCSC_LOG_ERROR, "error getting product friendly name from bundle");
				driverBundle->m_friendlyName = strdup("unnamed device");
			}
			else
			{
				const char *cstr = CFStringGetCStringPtr(strValue,
					CFStringGetSystemEncoding());

				driverBundle->m_friendlyName = strdup(cstr);
			}
#ifdef DEBUG_HOTPLUG
			Log2(PCSC_LOG_DEBUG, "VendorID: 0x%04X", driverBundle->m_vendorId);
			Log2(PCSC_LOG_DEBUG, "ProductID: 0x%04X", driverBundle->m_productId);
			Log2(PCSC_LOG_DEBUG, "Friendly name: %s", driverBundle->m_friendlyName);
			Log2(PCSC_LOG_DEBUG, "Driver: %s", driverBundle->m_libPath);
#endif

			/* go to next bundle in the vector */
			driverBundle++;
		}
	}
	CFRelease(bundleArray);
	return bundleVector;
}
Example #15
0
int convertMain (int argc, char * const argv[])
{
#if TARGET_OS_WIN32
  	QTLicenseRef aacEncoderLicenseRef = nil;
  	QTLicenseRef amrEncoderLicenseRef = nil;
	OSErr localerr;
#endif
	int result = 0;
	CFURLRef inputFileURL = NULL;
	CFURLRef outputFileURL = NULL;
    
#if TARGET_OS_WIN32
	InitializeQTML(0L);
	{
		OSErr localerr;
		const char *licenseDesc = "AAC Encode License Verification";
		const char *amrLicenseDesc = "AMR Encode License Verification";
        
		localerr = QTRequestLicensedTechnology("com.apple.quicktimeplayer","com.apple.aacencoder",
                                               (void *)licenseDesc,strlen(licenseDesc),&aacEncoderLicenseRef);
		localerr = QTRequestLicensedTechnology("com.apple.quicktimeplayer","1D07EB75-3D5E-4DA6-B749-D497C92B06D8",
                                               (void *)amrLicenseDesc,strlen(amrLicenseDesc),&amrEncoderLicenseRef);
	}
#endif
	
	try {
		OSType format = 0;
		Float64 sampleRate = 0;
		AudioFileTypeID outputFileType = kAudioFileCAFType;
 	  	UInt32 outputBitRate = 0;
		UInt32 outputBitDepth = 0;
		
		ParseArgs (argc, argv, format, sampleRate, outputFileType, inputFileURL, outputFileURL, outputBitDepth, outputBitRate);
        
        //	printf ("args:%4.4s, sample rate:%.1f, outputFileType: %4.4s\n", (char*)&format, sampleRate, (char*)&outputFileType);
        
		CAStreamBasicDescription inputFormat;
		CAStreamBasicDescription outputFormat;
		ConstructOutputFormatFromArgs (inputFileURL, outputFileType, format, sampleRate, inputFormat, outputBitDepth, outputFormat);
		
		printf ("Source File format:\n\t"); inputFormat.Print();
		printf ("Dest File format:\n\t"); outputFormat.Print();
		
		result = ConvertFile (inputFileURL, inputFormat, outputFileURL, outputFileType, outputFormat, outputBitRate);
        
		CFStringRef path = CFURLCopyPath(outputFileURL);
		printf("done: "); fflush(stdout); CFShow(path);
		if (path) CFRelease(path);
        
	} catch (CAXException e) {
		char buf[256];
		fprintf(stderr, "Error in: %s\nException thrown: %s\n", e.mOperation, e.FormatError(buf));
		result = 1;
	} catch (...) {
		fprintf(stderr, "Unspecified exception\n");
		result = 1;
	}
	if (inputFileURL) CFRelease(inputFileURL);
	if (outputFileURL) CFRelease(outputFileURL);
	
#if TARGET_OS_WIN32
	TerminateQTML();
 	if (aacEncoderLicenseRef)
	{
		localerr = QTReleaseLicensedTechnology(aacEncoderLicenseRef);
		aacEncoderLicenseRef = nil;
	}
	if(amrEncoderLicenseRef)
	{
		localerr = QTReleaseLicensedTechnology(amrEncoderLicenseRef);
		amrEncoderLicenseRef = nil;
	}
#endif
	return result;
}
Example #16
0
SCPreferencesRef
SCPreferencesCreateWithOptions(CFAllocatorRef	allocator,
			       CFStringRef	name,
			       CFStringRef	prefsID,
			       AuthorizationRef	authorization,
			       CFDictionaryRef	options)
{
	CFDataRef			authorizationData	= NULL;
	SCPreferencesPrivateRef		prefsPrivate;

	if (options != NULL) {
		if (!isA_CFDictionary(options)) {
			_SCErrorSet(kSCStatusInvalidArgument);
			return NULL;
		}
	}

	if (authorization != NULL) {
		CFMutableDictionaryRef	authorizationDict;
		CFBundleRef		bundle;
		CFStringRef		bundleID	= NULL;

		authorizationDict =  CFDictionaryCreateMutable(NULL,
							       0,
							       &kCFTypeDictionaryKeyCallBacks,
							       &kCFTypeDictionaryValueCallBacks);
#if	!TARGET_OS_IPHONE
		if (authorization != kSCPreferencesUseEntitlementAuthorization) {
			CFDataRef			data;
			AuthorizationExternalForm	extForm;
			OSStatus			os_status;

			os_status = AuthorizationMakeExternalForm(authorization, &extForm);
			if (os_status != errAuthorizationSuccess) {
				SCLog(TRUE, LOG_INFO, CFSTR("_SCHelperOpen AuthorizationMakeExternalForm() failed"));
				_SCErrorSet(kSCStatusInvalidArgument);
				CFRelease(authorizationDict);
				return NULL;
			}

			data = CFDataCreate(NULL, (const UInt8 *)extForm.bytes, sizeof(extForm.bytes));
			CFDictionaryAddValue(authorizationDict,
					     kSCHelperAuthAuthorization,
					     data);
			CFRelease(data);
		}
#endif

		/* get the application/executable/bundle name */
		bundle = CFBundleGetMainBundle();
		if (bundle != NULL) {
			bundleID = CFBundleGetIdentifier(bundle);
			if (bundleID != NULL) {
				CFRetain(bundleID);
			} else {
				CFURLRef	url;

				url = CFBundleCopyExecutableURL(bundle);
				if (url != NULL) {
					bundleID = CFURLCopyPath(url);
					CFRelease(url);
				}
			}

			if (bundleID != NULL) {
				if (CFEqual(bundleID, CFSTR("/"))) {
					CFRelease(bundleID);
					bundleID = NULL;
				}
			}
		}
		if (bundleID == NULL) {
			bundleID = CFStringCreateWithFormat(NULL, NULL, CFSTR("Unknown(%d)"), getpid());
		}
		CFDictionaryAddValue(authorizationDict,
				     kSCHelperAuthCallerInfo,
				     bundleID);
		CFRelease(bundleID);

		if (authorizationDict != NULL) {
			_SCSerialize((CFPropertyListRef)authorizationDict,
				     &authorizationData,
				     NULL,
				     NULL);
			CFRelease(authorizationDict);
		}
	}

	prefsPrivate = __SCPreferencesCreate(allocator, name, prefsID, authorizationData, options);
	if (authorizationData != NULL) CFRelease(authorizationData);

	return (SCPreferencesRef)prefsPrivate;
}
Example #17
0
/* ioLoadModule:
	Load a module from disk.
	WARNING: this always loads a *new* module. Don't even attempt to find a loaded one.
	WARNING: never primitiveFail() within, just return 0
*/
void* ioLoadModule(char *pluginName) {
	char pluginDirPath[DOCUMENT_NAME_SIZE+1];
	CFragConnectionID libHandle;
#ifndef BROWSERPLUGIN
    #if !defined ( __APPLE__ ) && !defined ( __MACH__ )
	Ptr mainAddr;
	Str255 errorMsg,tempPluginName;
	OSErr err;
#endif
#endif    
    	/* first, look in the "<Squeak VM directory>Plugins" directory for the library */
        getVMPathWithEncoding(pluginDirPath,gCurrentVMEncoding);
	
#ifdef BROWSERPLUGIN
        createBrowserPluginPath(pluginDirPath);
#else
	strcat(pluginDirPath, "Plugins");
#endif 	
    
    libHandle = LoadLibViaPath(pluginName, pluginDirPath);
	if (libHandle != nil) return (void *) libHandle;

#ifndef BROWSERPLUGIN
	/* second, look directly in Squeak VM directory for the library */
	getVMPathWithEncoding(pluginDirPath,gCurrentVMEncoding);
	libHandle = LoadLibViaPath(pluginName, pluginDirPath);
	if (libHandle != nil) return (void*) libHandle;
    
    #if !defined ( __APPLE__ ) && !defined ( __MACH__ )
        /* Lastly look for it as a shared import library */
        
        CopyCStringToPascal(pluginName,tempPluginName);
        err = GetSharedLibrary(tempPluginName, kAnyCFragArch, kLoadCFrag, &libHandle, &mainAddr, errorMsg);
            if (err == noErr) 
                err = GetSharedLibrary(tempPluginName, kAnyCFragArch, kFindCFrag, &libHandle, &mainAddr, errorMsg);
            if (libHandle != nil) return (void*) libHandle;
    #else
		{
            CFBundleRef mainBundle;
            CFURLRef	bundleURL,bundleURL2,resourceURL;
			CFStringRef filePath,resourcePathString;
			
            mainBundle = CFBundleGetMainBundle();   
			bundleURL = CFBundleCopyBundleURL(mainBundle);
			resourceURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
			resourcePathString = CFURLCopyPath(resourceURL);
			CFRelease(resourceURL);

			bundleURL2 = CFURLCreateCopyAppendingPathComponent( kCFAllocatorSystemDefault, bundleURL, resourcePathString, false );
			CFRelease(bundleURL);
	#ifdef MACINTOSHUSEUNIXFILENAMES
			filePath = CFURLCopyFileSystemPath (bundleURL2, kCFURLPOSIXPathStyle);
	#else
			filePath = CFURLCopyFileSystemPath (bundleURL2, kCFURLHFSPathStyle);
	#endif
			CFRelease(bundleURL2);
			
			CFStringGetCString (filePath,pluginDirPath,DOCUMENT_NAME_SIZE, gCurrentVMEncoding);
			CFRelease(filePath);
			
			libHandle = LoadLibViaPath(pluginName, pluginDirPath);
			if (libHandle != nil) return (void *) libHandle;
 		}
	#endif
    #endif 
	
	return nil;
}
Example #18
0
void fill_pathname_application_path(char *s, size_t len)
{
   size_t i;
#ifdef __APPLE__
  CFBundleRef bundle = CFBundleGetMainBundle();
#endif
#ifdef _WIN32
   DWORD ret;
   wchar_t ws[PATH_MAX_LENGTH] = {0};
#endif
#ifdef __HAIKU__
   image_info info;
   int32_t cookie = 0;
#endif
   (void)i;

   if (!len)
      return;

#ifdef _WIN32
   ret    = GetModuleFileName(GetModuleHandle(NULL), s, len - 1);
   s[ret] = '\0';
#elif defined(__APPLE__)
   if (bundle)
   {
      CFURLRef bundle_url = CFBundleCopyBundleURL(bundle);
      CFStringRef bundle_path = CFURLCopyPath(bundle_url);
      CFStringGetCString(bundle_path, s, len, kCFStringEncodingUTF8);
      CFRelease(bundle_path);
      CFRelease(bundle_url);
      
      retro_assert(strlcat(s, "nobin", len) < len);
      return;
   }
#elif defined(__HAIKU__)
   while (get_next_image_info(0, &cookie, &info) == B_OK)
   {
      if (info.type == B_APP_IMAGE)
      {
         strlcpy(s, info.name, len);
         return;
      }
   }
#else
   {
      pid_t pid;
      static const char *exts[] = { "exe", "file", "path/a.out" };
      char link_path[255];

      link_path[0] = *s = '\0';
      pid       = getpid(); 

      /* Linux, BSD and Solaris paths. Not standardized. */
      for (i = 0; i < ARRAY_SIZE(exts); i++)
      {
         ssize_t ret;

         snprintf(link_path, sizeof(link_path), "/proc/%u/%s",
               (unsigned)pid, exts[i]);
         ret = readlink(link_path, s, len - 1);

         if (ret >= 0)
         {
            s[ret] = '\0';
            return;
         }
      }
   }
   
   RARCH_ERR("Cannot resolve application path! This should not happen.\n");
#endif
}