From: <mme...@gr...> - 2007-08-18 22:49:42
|
# HG changeset patch # User Matt Messier <mme...@gr...> # Date 1187472657 14400 # Node ID 7fd3df5d67d667238737563dafa4b72b641263df # Parent f9523c276598519f9e148162e450f4e5d63ce429 Added a new "layout" mechanism for locating fonts, plugins, etc. New xine-utils functions for getting and creating cache/config directories. New xine-utils functions for getting font and plugin directories. Added a configure option --with-layout to specify the layout type, which may be one of macosx-framework, macosx-library, and xdg. If not specified, the appropriate layout for the platform and other build options will be chosen. New xine-utils functions for creating directories. The functions are based on old input_cdda code, but it's been cleaned up a bunch. Removed the old functions from input_cdda in favor of these new ones. diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 configure.ac --- a/configure.ac Sat Aug 18 17:30:57 2007 -0400 +++ b/configure.ac Sat Aug 18 17:28:09 2007 -0400 @@ -228,23 +228,6 @@ AC_CHECK_LIB([c], [dlopen], [DYNAMIC_LD_ AC_LANG_POP([C])], [AC_MSG_ERROR([dynamic linker needed])])]) AC_SUBST([DYNAMIC_LD_LIBS]) -AC_ARG_WITH([external-libxdg-basedir], - [AS_HELP_STRING([--with-external-libxdg-basedir], [use external copy of libxdg-basedir])]) - -if test x"$with_external_libxdg_basedir" = x"yes"; then - PKG_CHECK_MODULES([XDG_BASEDIR], [libxdg-basedir >= 0.1.3]) -else - XDG_BASEDIR_CPPFLAGS='-I$(top_srcdir)/contrib/libxdg-basedir' - XDG_BASEDIR_LIBS='$(top_builddir)/contrib/libxdg-basedir/libxdg-basedir.la' - XDG_BASEDIR_DEPS='$(top_builddir)/contrib/libxdg-basedir/libxdg-basedir.la' -fi - -AC_SUBST([XDG_BASEDIR_CPPFLAGS]) -AC_SUBST([XDG_BASEDIR_LIBS]) -AC_SUBST([XDG_BASEDIR_DEPS]) - -AM_CONDITIONAL([EXTERNAL_LIBXDG_BASEDIR], [test x"$with_external_libxdg_basedir" = x"yes"]) - dnl Test for socket and network support library AC_CHECK_LIB([socket], [socket], [NET_LIBS="-lsocket $NET_LIBS"]) AC_CHECK_LIB([nsl], [gethostbyname], [NET_LIBS="-lnsl $NET_LIBS"]) @@ -339,6 +322,9 @@ if test x"$with_fontconfig" = x"yes"; th fi fi +dnl Check for the layout to use. Layout is where caches, plugins, etc. are +dnl located in the filesystem. +XINE_LAYOUT dnl ----------------------- dnl checks for header files diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 contrib/libxdg-basedir/Makefile.am --- a/contrib/libxdg-basedir/Makefile.am Sat Aug 18 17:30:57 2007 -0400 +++ b/contrib/libxdg-basedir/Makefile.am Sat Aug 18 17:28:09 2007 -0400 @@ -1,5 +1,7 @@ if !EXTERNAL_LIBXDG_BASEDIR +if XINE_LAYOUT_XDG if !EXTERNAL_LIBXDG_BASEDIR noinst_LTLIBRARIES = libxdg-basedir.la +endif endif AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/input/Makefile.am --- a/src/input/Makefile.am Sat Aug 18 17:30:57 2007 -0400 +++ b/src/input/Makefile.am Sat Aug 18 17:28:09 2007 -0400 @@ -106,17 +106,13 @@ xineplug_inp_pnm_la_LIBADD = $(XINE_LIB) xineplug_inp_pnm_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) xineplug_inp_dvb_la_SOURCES = input_dvb.c net_buf_ctrl.c -xineplug_inp_dvb_la_DEPS = $(XDG_BASEDIR_DEPS) -xineplug_inp_dvb_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) $(XDG_BASEDIR_LIBS) -xineplug_inp_dvb_la_CPPFLAGS = $(AM_CPPFLAGS) $(XDG_BASEDIR_CPPFLAGS) +xineplug_inp_dvb_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) xineplug_inp_rtsp_la_SOURCES = input_rtsp.c net_buf_ctrl.c xineplug_inp_rtsp_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) libreal/libreal.la librtsp/librtsp.la xineplug_inp_cdda_la_SOURCES = input_cdda.c media_helper.c sha1.c sha1.h base64.c base64.h -xineplug_inp_cdda_la_DEPS = $(XDG_BASEDIR_DEPS) -xineplug_inp_cdda_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) $(XDG_BASEDIR_LIBS) $(MEDIA_HELPER_LIBS) -xineplug_inp_cdda_la_CPPFLAGS = $(AM_CPPFLAGS) $(XDG_BASEDIR_CPPFLAGS) +xineplug_inp_cdda_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) $(MEDIA_HELPER_LIBS) xineplug_inp_v4l_la_SOURCES = input_v4l.c xineplug_inp_v4l_la_LIBADD = $(ALSA_LIBS) $(XINE_LIB) $(LTLIBINTL) diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/input/input_cdda.c --- a/src/input/input_cdda.c Sat Aug 18 17:30:57 2007 -0400 +++ b/src/input/input_cdda.c Sat Aug 18 17:28:09 2007 -0400 @@ -57,8 +57,6 @@ #include <signal.h> #include <netinet/in.h> #include <sys/socket.h> - -#include <basedir.h> #define LOG_MODULE "input_cdda" #define LOG_VERBOSE @@ -1335,96 +1333,6 @@ static int _cdda_is_cd_changed(cdda_inpu } /* - * create a directory, in safe mode - */ -static void _cdda_mkdir_safe(xine_t *xine, char *path) { - - if(path == NULL) - return; - -#ifndef WIN32 - { - struct stat pstat; - - if((stat(path, &pstat)) < 0) { - /* file or directory no exist, create it */ - if(mkdir(path, 0755) < 0) { - xprintf(xine, XINE_VERBOSITY_DEBUG, - "input_cdda: mkdir(%s) failed: %s.\n", path, strerror(errno)); - return; - } - } - else { - /* Check of found file is a directory file */ - if(!S_ISDIR(pstat.st_mode)) { - xprintf(xine, XINE_VERBOSITY_DEBUG, "input_cdda: %s is not a directory.\n", path); - } - } - } -#else - { - HANDLE hList; - TCHAR szDir[MAX_PATH+3]; - WIN32_FIND_DATA FileData; - - // Get the proper directory path - sprintf(szDir, "%s\\*", path); - - // Get the first file - hList = FindFirstFile(szDir, &FileData); - if (hList == INVALID_HANDLE_VALUE) - { - if(_mkdir(path) != 0) { - xprintf(xine, XINE_VERBOSITY_DEBUG, "input_cdda: mkdir(%s) failed.\n", path); - return; - } - } - - FindClose(hList); - } -#endif /* WIN32 */ -} - -/* - * Make recursive directory creation - */ -static void _cdda_mkdir_recursive_safe(xine_t *xine, char *path) { - char *p, *pp; - char buf[XINE_PATH_MAX + XINE_NAME_MAX + 1]; - char buf2[XINE_PATH_MAX + XINE_NAME_MAX + 1]; - - if(path == NULL) - return; - - memset(&buf, 0, sizeof(buf)); - memset(&buf2, 0, sizeof(buf2)); - - snprintf(buf, sizeof(buf), "%s", path); - pp = buf; - while((p = xine_strsep(&pp, "/")) != NULL) { - if(p && strlen(p)) { - -#ifdef WIN32 - if (*buf2 != '\0') { -#endif - - int size = strlen(buf2); - snprintf(buf2 + size, sizeof(buf2) - size, "/%s", p); - -#ifdef WIN32 - } - else { - snprintf(buf2, sizeof(buf2), "%s", p); - } - -#endif /* WIN32 */ - - _cdda_mkdir_safe(xine, buf2); - } - } -} - -/* * Read from socket, fill char *s, return size length. */ static int _cdda_cddb_socket_read(cdda_input_plugin_t *this, char *str, int size) { @@ -1525,15 +1433,13 @@ static int _cdda_load_cached_cddb_infos( static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) { char *cdir = NULL; DIR *dir; - - const char *const xdg_cache_home = xdgCacheHome(this->stream->xine->basedir_handle); - - if(this == NULL) + const char *cache_directory; + + if(!this || !this->stream || !(cache_directory = xine_get_cache_directory(this->stream->xine, 0))) return 0; - cdir = alloca(strlen(xdg_cache_home) + sizeof("/"PACKAGE"/cddb")); - strcpy(cdir, xdg_cache_home); - strcat(cdir, "/"PACKAGE"/cddb"); + cdir = alloca(strlen(cache_directory) + sizeof("/cddb")); + strcat(strcpy(cdir, cache_directory), "/cddb"); if((dir = opendir(cdir)) != NULL) { struct dirent *pdir; @@ -1661,18 +1567,17 @@ static void _cdda_save_cached_cddb_infos FILE *fd; char *cfile; - const char *const xdg_cache_home = xdgCacheHome(this->stream->xine->basedir_handle); + const char *const cache_directory = xine_get_cache_directory(this->stream->xine, 1); if((this == NULL) || (filecontent == NULL)) return; /* the filename is always 8 characters */ - cfile = alloca(strlen(xdg_cache_home) + sizeof("/"PACKAGE"/cddb") + 9); - strcpy(cfile, xdg_cache_home); - strcat(cfile, "/"PACKAGE"/cddb"); + cfile = alloca(strlen(cache_directory) + sizeof("/cddb") + 9); + strcat(strcpy(cfile, cache_directory), "/cddb"); /* Ensure the cache directory exists */ - _cdda_mkdir_recursive_safe(this->stream->xine, cfile); + xine_mkdir_recursive_safe(this->stream->xine, cfile); sprintf(cfile, "%s/%08lx", cfile, this->cddb.disc_id); diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/input/input_dvb.c --- a/src/input/input_dvb.c Sat Aug 18 17:30:57 2007 -0400 +++ b/src/input/input_dvb.c Sat Aug 18 17:28:09 2007 -0400 @@ -100,9 +100,6 @@ #endif #include <ctype.h> -/* XDG */ -#include <basedir.h> - #include <linux/dvb/dmx.h> #include <linux/dvb/frontend.h> @@ -895,7 +892,10 @@ static channel_t *load_channels(xine_t * int i; struct stat st; - snprintf(filename, BUFSIZE, "%s/"PACKAGE"/channels.conf", xdgConfigHome(xine->basedir_handle)); + const char *config_directory = xine_get_config_directory(xine, 0); + if (!config_directory) + return NULL; + snprintf(filename, BUFSIZE, "%s/channels.conf", config_directory); f = fopen(filename, "r"); if (!f) { @@ -3211,10 +3211,15 @@ static char **dvb_class_get_autoplay_lis class->mrls[0]="Sorry, no channels.conf found."; class->mrls[1]="Please run the scan utility from the DVB"; class->mrls[2]="drivers apps package and place the file in"; - if (!placefile) - asprintf (&placefile, "%s/"PACKAGE"/", xdgConfigHome(class->xine->basedir_handle)); - class->mrls[3]=placefile; - *num_files=4; + if (!placefile) { + const char *config_directory = xine_get_config_directory(class->xine, 0); + if (config_directory) { + asprintf (&placefile, "%s/", config_directory); + class->mrls[3]=placefile; + } + else + class->mrls[3]="<internal error: unable to determine config directory>"; + *num_files=4; return class->mrls; } diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/libw32dll/Makefile.am --- a/src/libw32dll/Makefile.am Sat Aug 18 17:30:57 2007 -0400 +++ b/src/libw32dll/Makefile.am Sat Aug 18 17:28:09 2007 -0400 @@ -18,13 +18,11 @@ endif endif xineplug_decode_w32dll_la_SOURCES = w32codec.c -xineplug_decode_w32dll_la_DEPS = $(XDG_BASEDIR_DEPS) xineplug_decode_w32dll_la_LIBADD = \ $(top_builddir)/src/libw32dll/wine/libwine.la \ $(top_builddir)/src/libw32dll/DirectShow/libds_filter.la \ $(top_builddir)/src/libw32dll/dmo/libdmo_filter.la \ - $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) -lm $(KSTAT_LIBS) $(XDG_BASEDIR_LIBS) -xineplug_decode_w32dll_la_CPPFLAGS = $(AM_CPPFLAGS) $(XDG_BASEDIR_CPPFLAGS) + $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) -lm $(KSTAT_LIBS) xineplug_decode_qt_la_SOURCES = qt_decoder.c xineplug_decode_qt_la_LIBADD = \ diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/libw32dll/wine/Makefile.am --- a/src/libw32dll/wine/Makefile.am Sat Aug 18 17:30:57 2007 -0400 +++ b/src/libw32dll/wine/Makefile.am Sat Aug 18 17:28:09 2007 -0400 @@ -64,4 +64,3 @@ libwine_la_SOURCES = \ win32.c \ stubs.s \ wrapper.S -libwine_la_CPPFLAGS = $(AM_CPPFLAGS) $(XDG_BASEDIR_CPPFLAGS) diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/libw32dll/wine/registry.c --- a/src/libw32dll/wine/registry.c Sat Aug 18 17:30:57 2007 -0400 +++ b/src/libw32dll/wine/registry.c Sat Aug 18 17:28:09 2007 -0400 @@ -19,7 +19,6 @@ #ifdef XINE_MAJOR #include "xineutils.h" -#include <basedir.h> #endif //#undef TRACE @@ -303,22 +302,25 @@ static struct reg_value* insert_reg_valu static void init_registry(void) { - xdgHandle tmph = xdgAllocHandle(); - const char *const xdg_cache_home = xdgCacheHome(tmph); + const char *const cache_directory = xine_get_cache_directory(NULL, 0); TRACE("Initializing registry\n"); // can't be free-ed - it's static and probably thread // unsafe structure which is stored in glibc - localregpathname = malloc(strlen(xdg_cache_home) + sizeof("/"PACKAGE"/win32registry")); - strcpy(localregpathname, xdg_cache_home); - strcat(localregpathname, "/"PACKAGE"/win32registry"); + if (!cache_directory) + { + localregpathname = strdup("/tmp/win32registry"); + } + else + { + localregpathname = malloc(strlen(cache_directory) + sizeof("/win32registry")); + strcat(strcpy(localregpathname, cache_directory), "/win32registry"); + } open_registry(); insert_handle(HKEY_LOCAL_MACHINE, "HKLM"); insert_handle(HKEY_CURRENT_USER, "HKCU"); - - xdgFreeHandle(tmph); } #if 0 diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/xine-engine/Makefile.am --- a/src/xine-engine/Makefile.am Sat Aug 18 17:30:57 2007 -0400 +++ b/src/xine-engine/Makefile.am Sat Aug 18 17:28:09 2007 -0400 @@ -2,7 +2,7 @@ include $(top_srcdir)/lib/Makefile.commo include $(top_srcdir)/lib/Makefile.common AM_CFLAGS = $(DEFAULT_OCFLAGS) $(X_CFLAGS) $(FT2_CFLAGS) $(FONTCONFIG_CFLAGS) $(VISIBILITY_FLAG) -AM_CPPFLAGS = $(XDG_BASEDIR_CPPFLAGS) $(ZLIB_CPPFLAGS) -DXINE_LIBRARY_COMPILE +AM_CPPFLAGS = $(ZLIB_CPPFLAGS) -DXINE_LIBRARY_COMPILE XINEUTILS_LIB = $(top_builddir)/src/xine-utils/libxineutils.la diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/xine-engine/load_plugins.c --- a/src/xine-engine/load_plugins.c Sat Aug 18 17:30:57 2007 -0400 +++ b/src/xine-engine/load_plugins.c Sat Aug 18 17:28:09 2007 -0400 @@ -42,15 +42,6 @@ #include <stdio.h> #include <ctype.h> #include <signal.h> -#ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> -#endif - -#include <basedir.h> - -#ifdef HAVE_COREFOUNDATION -#include <CoreFoundation/CoreFoundation.h> -#endif #define LOG_MODULE "load_plugins" #define LOG_VERBOSE @@ -555,7 +546,7 @@ void xine_register_plugins(xine_t *self, * ***************************************************************************/ -static void collect_plugins(xine_t *this, char *path){ +static void collect_plugins(xine_t *this, const char *path){ DIR *dir; @@ -610,9 +601,6 @@ static void collect_plugins(xine_t *this if(!strstr(str, ".dll") #else if(!strstr(str, ".so") -#endif -#ifdef HOST_OS_DARWIN - && !strcasestr(str, ".xineplugin") #endif ) break; @@ -1072,55 +1060,21 @@ static void load_plugin_list(FILE *fp, x /** * @brief Returns the complete filename for the plugins' cache file - * @param this Instance pointer, used for logging and libxdg-basedir. + * @param this Instance pointer, used for logging and layout. * @param createdir If not zero, create the directory structure in which * the file has to reside. * @return If createdir was not zero, returns NULL if the directory hasn't * been created; otherwise always returns a new string with the * name of the cachefile. - * @internal - * - * @see XDG Base Directory specification: - * http://standards.freedesktop.org/basedir-spec/latest/index.html */ static char *catalog_filename(xine_t *this, int createdir) { - const char *const xdg_cache_home = xdgCacheHome(this->basedir_handle); + const char *const cache_directory = xine_get_cache_directory(this, createdir); char *cachefile = NULL; - cachefile = xine_xmalloc( strlen(xdg_cache_home) + sizeof("/"PACKAGE"/plugins.cache") ); - strcpy(cachefile, xdg_cache_home); - - /* If we're going to create the directory structure, we concatenate - * piece by piece the path, so that we can try to create all the - * directories. - * If we don't need to create anything, we just concatenate the - * whole path at once. - */ - if ( createdir ) { - int result = 0; - - result = mkdir( cachefile, 0700 ); - if ( result != 0 && errno != EEXIST ) { - /** @todo Convert this to use xine's log facility */ - fprintf(stderr, _("Unable to create %s directory: %s\n"), cachefile, strerror(errno)); - free(cachefile); - return NULL; - } - - strcat(cachefile, "/"PACKAGE); - result = mkdir( cachefile, 0700 ); - if ( result != 0 && errno != EEXIST ) { - /** @todo Convert this to use xine's log facility */ - fprintf(stderr, _("Unable to create %s directory: %s\n"), cachefile, strerror(errno)); - free(cachefile); - return NULL; - } - - strcat(cachefile, "/plugins.cache"); - - } else - strcat(cachefile, "/"PACKAGE"/plugins.cache"); - + if (cache_directory) { + cachefile = xine_xmalloc( strlen(cache_directory) + sizeof("/plugins.cache") ); + strcat(strcpy(cachefile, cache_directory), "/plugins.cache"); + } return cachefile; } @@ -1156,53 +1110,19 @@ static void load_cached_catalog (xine_t char *const cachefile = catalog_filename(this, 0); /* It can't return NULL without creating directories */ - if( (fp = fopen(cachefile,"r")) != NULL ) { + if( cachefile && (fp = fopen(cachefile,"r")) != NULL ) { load_plugin_list (fp, this->plugin_catalog->cache_list); fclose(fp); } free(cachefile); } - -#ifdef XINE_MACOSX_FRAMEWORK -static char *get_framework_plugin_path(void) -{ - char *pluginpath = NULL; - CFURLRef resourcesURL = NULL; - CFBundleRef frameworkBundle; - - /* So there's this internal function in CoreFoundation called - * CFURLCreateStringWithFileSystemPath() that does EXACTLY what we want - * to do here, but for reasons that are beyond my understanding, it's not - * exposed. Instead, we're left with no choice but to use the following - * horrible, horrible bit of code. - */ - if ((frameworkBundle = CFBundleGetBundleWithIdentifier(CFSTR("de.xinehq.xine-lib"))) != NULL && - (resourcesURL = CFBundleCopyResourcesDirectoryURL(frameworkBundle)) != NULL && - (pluginpath = (char *)xine_xmalloc(MAXPATHLEN + 1)) != NULL && - CFURLGetFileSystemRepresentation(resourcesURL, true, (UInt8 *)pluginpath, MAXPATHLEN + 1)) - { - if (strlen(pluginpath) <= MAXPATHLEN - 8) { - strcat(pluginpath, "/PlugIns"); - CFRelease(resourcesURL); - return pluginpath; - } - } - free(pluginpath); - if (resourcesURL) { - CFRelease(resourcesURL); - } - return NULL; -} -#endif /* * initialize catalog, load all plugins into new catalog */ void _x_scan_plugins (xine_t *this) { - - char *homedir, *plugindir, *pluginpath; - int i,j; - int lenpluginpath; + const char * const *plugin_paths; + const char * const *plugin_path; lprintf("_x_scan_plugins()\n"); @@ -1212,53 +1132,16 @@ void _x_scan_plugins (xine_t *this) { _x_abort(); } - homedir = strdup(xine_get_homedir()); this->plugin_catalog = _new_catalog(); load_cached_catalog (this); - if ((pluginpath = getenv("XINE_PLUGIN_PATH")) != NULL) { - pluginpath = strdup(pluginpath); - } else { - const char *str1, *str2; - int len; - - str1 = "~/.xine/plugins"; -#ifdef XINE_MACOSX_FRAMEWORK - str2 = get_framework_plugin_path(); -#else - str2 = XINE_PLUGINDIR; -#endif - len = strlen(str1) + strlen(str2) + 2; - pluginpath = xine_xmalloc(len); - snprintf(pluginpath, len, "%s" XINE_PATH_SEPARATOR_STRING "%s", str1, str2); -#ifdef XINE_MACOSX_FRAMEWORK - free((char *)str2); -#endif - } - plugindir = xine_xmalloc(strlen(pluginpath)+strlen(homedir)+2); - j=0; - lenpluginpath = strlen(pluginpath); - for (i=0; i <= lenpluginpath; ++i){ - switch (pluginpath[i]){ - case XINE_PATH_SEPARATOR_CHAR: - case '\0': - plugindir[j] = '\0'; - collect_plugins(this, plugindir); - j = 0; - break; - case '~': - if (j == 0){ - strcpy(plugindir, homedir); - j = strlen(plugindir); - break; - } - default: - plugindir[j++] = pluginpath[i]; - } - } - free(plugindir); - free(pluginpath); - free(homedir); + plugin_paths = xine_get_plugin_directories(this); + if (plugin_paths) { + for (plugin_path = plugin_paths; *plugin_path && **plugin_path; plugin_path++) { + collect_plugins(this, *plugin_path); + } + xine_free_directory_list(this, plugin_paths); + } save_catalog (this); diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/xine-engine/osd.c --- a/src/xine-engine/osd.c Sat Aug 18 17:30:57 2007 -0400 +++ b/src/xine-engine/osd.c Sat Aug 18 17:28:09 2007 -0400 @@ -35,18 +35,9 @@ #include <dirent.h> #endif #include <errno.h> -#ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> -#endif #ifdef HAVE_ICONV # include <iconv.h> -#endif - -#include <basedir.h> - -#ifdef HAVE_COREFOUNDATION -#include <CoreFoundation/CoreFoundation.h> #endif #define LOG_MODULE "osd" @@ -875,37 +866,40 @@ static int osd_lookup_fontconfig( osd_ob # endif /* HAVE_FONTCONFIG */ /** - * @brief Look up a font file using XDG data directories. + * @brief Look up a font file using the build-time xine layout. * @param osd The OSD object to load the font for. * @param fontname Name (absolute or relative) of the font to look up. * * @return If the lookup was done correctly, a non-zero value is returned. * - * @see XDG Base Directory specification: - * http://standards.freedesktop.org/basedir-spec/latest/index.html - */ -static int osd_lookup_xdg( osd_object_t *osd, const char *const fontname ) { - const char *const *data_dirs = xdgSearchableDataDirectories(osd->renderer->stream->xine->basedir_handle); + */ +static int osd_lookup_xine( osd_object_t *osd, const char *const fontname ) { + const char *const *data_dirs = xine_get_font_directories(osd->renderer->stream->xine); + const char *const *data_dir; /* try load font from current directory or from an absolute path */ - if ( FT_New_Face(osd->ft2->library, fontname, 0, &osd->ft2->face) == FT_Err_Ok ) + if ( FT_New_Face(osd->ft2->library, fontname, 0, &osd->ft2->face) == FT_Err_Ok ) { + xine_free_directory_list(osd->renderer->stream->xine, data_dirs); return 1; - - if ( data_dirs ) - while( (*data_dirs) && *(*data_dirs) ) { + } + + if ( data_dirs ) { + for ( data_dir = data_dirs; (*data_dir) && *(*data_dir); data_dir++ ) { FT_Error fte = FT_Err_Ok; char *fontpath = NULL; - asprintf(&fontpath, "%s/"PACKAGE"/fonts/%s", *data_dirs, fontname); + asprintf(&fontpath, "%s/%s", *data_dir, fontname); fte = FT_New_Face(osd->ft2->library, fontpath, 0, &osd->ft2->face); free(fontpath); - if ( fte == FT_Err_Ok ) + if ( fte == FT_Err_Ok ) { + xine_free_directory_list(osd->renderer->stream->xine, data_dirs); return 1; - - data_dirs++; - } + } + } + xine_free_directory_list(osd->renderer->stream->xine, data_dirs); + } xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG, _("osd: error loading font %s with in XDG data directories.\n"), fontname); @@ -929,7 +923,7 @@ static int osd_set_font_freetype2( osd_o if ( osd_lookup_fontconfig(osd, fontname, size) ) break; #endif - if ( osd_lookup_xdg(osd, fontname) ) + if ( osd_lookup_xine(osd, fontname) ) break; free(osd->ft2); @@ -1434,7 +1428,7 @@ static int osd_get_text_size(osd_object_ return 1; } -static void osd_preload_fonts (osd_renderer_t *this, char *path) { +static void osd_preload_fonts (osd_renderer_t *this, const char *path) { DIR *dir; char *s, *p; @@ -1635,47 +1629,14 @@ osd_renderer_t *_x_osd_renderer_init( xi * load available fonts */ { -#ifndef XINE_MACOSX_FRAMEWORK - const char *const *data_dirs = xdgSearchableDataDirectories(stream->xine->basedir_handle); - if ( data_dirs ) - while( (*data_dirs) && *(*data_dirs) ) { - /* sizeof("") takes care of the final NUL byte */ - char *fontpath = xine_xmalloc( strlen(*data_dirs) + sizeof("/"PACKAGE"/fonts/") ); - strcpy(fontpath, *data_dirs); - strcat(fontpath, "/"PACKAGE"/fonts/"); - - osd_preload_fonts(this, fontpath); - - free(fontpath); - - data_dirs++; - } -#else - char *fontpath = NULL; - CFURLRef resourcesURL = NULL; - CFBundleRef frameworkBundle; - - /* So there's this internal function in CoreFoundation called - * CFURLCreateStringWithFileSystemPath() that does EXACTLY what we want - * to do here, but for reasons that are beyond my understanding, it's not - * exposed. Instead, we're left with no choice but to use the following - * horrible, horrible bit of code. - */ - if ((frameworkBundle = CFBundleGetBundleWithIdentifier(CFSTR("de.xinehq.xine-lib"))) != NULL && - (resourcesURL = CFBundleCopyResourcesDirectoryURL(frameworkBundle)) != NULL && - (fontpath = (char *)xine_xmalloc(MAXPATHLEN + 1)) != NULL && - CFURLGetFileSystemRepresentation(resourcesURL, true, (UInt8 *)fontpath, MAXPATHLEN + 1)) - { - if (strlen(fontpath) <= MAXPATHLEN - 6) { - strcat(fontpath, "/Fonts"); - osd_preload_fonts(this, fontpath); - } - } - free(fontpath); - if (resourcesURL) { - CFRelease(resourcesURL); - } -#endif + const char *const *data_dirs = xine_get_font_directories(stream->xine); + const char *const *data_dir; + if ( data_dirs ) { + for( data_dir = data_dirs; *(data_dir) && *(*data_dir); data_dir++ ) { + osd_preload_fonts(this, *data_dirs); + } + xine_free_directory_list(stream->xine, data_dirs); + } } this->textpalette = this->stream->xine->config->register_enum (this->stream->xine->config, diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/xine-engine/xine.c --- a/src/xine-engine/xine.c Sat Aug 18 17:30:57 2007 -0400 +++ b/src/xine-engine/xine.c Sat Aug 18 17:28:09 2007 -0400 @@ -46,8 +46,6 @@ #ifdef HAVE_SETLOCALE #include <locale.h> #endif - -#include <basedir.h> #define LOG_MODULE "xine" #define LOG_VERBOSE @@ -1534,7 +1532,9 @@ void xine_exit (xine_t *this) { WSACleanup(); #endif +#if defined(XINE_LAYOUT_XDG) xdgFreeHandle(this->basedir_handle); +#endif free (this); } @@ -1664,8 +1664,10 @@ void xine_init (xine_t *this) { static const char *const demux_strategies[] = {"default", "reverse", "content", "extension", NULL}; +#if defined(XINE_LAYOUT_XDG) /* First of all, initialise libxdg-basedir as it's used by plugins. */ this->basedir_handle = xdgAllocHandle(); +#endif /* initialize color conversion tables and functions */ init_yuv_conversion(); diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/xine-engine/xine_internal.h --- a/src/xine-engine/xine_internal.h Sat Aug 18 17:30:57 2007 -0400 +++ b/src/xine-engine/xine_internal.h Sat Aug 18 17:28:09 2007 -0400 @@ -116,8 +116,10 @@ struct xine_s { metronom_clock_t *clock; +#ifdef XINE_LAYOUT_XDG /** Handle for libxdg-basedir functions. It's actually an xdgHandle. */ void * basedir_handle; +#endif #ifdef XINE_ENGINE_INTERNAL xine_ticket_t *port_ticket; diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/xine-utils/Makefile.am --- a/src/xine-utils/Makefile.am Sat Aug 18 17:30:57 2007 -0400 +++ b/src/xine-utils/Makefile.am Sat Aug 18 17:28:09 2007 -0400 @@ -1,7 +1,7 @@ include $(top_srcdir)/misc/Makefile.comm include $(top_srcdir)/misc/Makefile.common AM_CFLAGS = $(DEFAULT_OCFLAGS) $(X_CFLAGS) $(VISIBILITY_FLAG) -AM_CPPFLAGS = -DXINE_LIBRARY_COMPILE +AM_CPPFLAGS = -DXINE_LIBRARY_COMPILE $(XDG_BASEDIR_CPPFLAGS) EXTRA_DIST = ppcasm_string.S ppc_asm.tmpl @@ -44,4 +44,5 @@ libxineutils_la_SOURCES = $(pppc_files) array.c \ sorted_array.c \ pool.c \ + paths.c \ ring_buffer.c diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/xine-utils/xineutils.h --- a/src/xine-utils/xineutils.h Sat Aug 18 17:30:57 2007 -0400 +++ b/src/xine-utils/xineutils.h Sat Aug 18 17:28:09 2007 -0400 @@ -648,6 +648,29 @@ const char *xine_get_fontdir(void) XINE_ const char *xine_get_fontdir(void) XINE_PROTECTED; const char *xine_get_localedir(void) XINE_PROTECTED; #endif + +/* safely create a directory */ +int xine_mkdir_safe (xine_t *xine, const char *path) XINE_PROTECTED; + +/* safely create a directory recursively */ +int xine_mkdir_recursive_safe (xine_t *xine, const char *path) XINE_PROTECTED; + +/* get the directory where cache files may be found and should be stored */ +const char *xine_get_cache_directory (xine_t *xine, int create) XINE_PROTECTED; + +/* get the directory where config files may be found and should be stored */ +const char *xine_get_config_directory (xine_t *xine, int create) XINE_PROTECTED; + +/* get a list of directories where fonts for osd can be found */ +const char * const *xine_get_font_directories (xine_t *xine) XINE_PROTECTED; + +/* get a list of directories where plugins can be found */ +const char * const *xine_get_plugin_directories (xine_t *xine) XINE_PROTECTED; + +/* free a list of directories returned from either + _x_get_font_directories() or _x_get_plugin_directories(). */ +void xine_free_directory_list(xine_t *xine, const char * const *directories) XINE_PROTECTED; + /* * Clean a string (remove spaces and '=' at the begin, diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 m4/layout.m4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m4/layout.m4 Sat Aug 18 17:28:09 2007 -0400 @@ -0,0 +1,58 @@ +AC_DEFUN([XINE_LAYOUT], [ + AC_ARG_WITH([layout], + [AS_HELP_STRING([--with-layout=LAYOUT], [enable an alternate layout from the default])]) + + test -z "$with_layout" && with_layout="default" + test "$with_layout" = "yes" && with_layout="default" + test "$with_layout" = "no" && with_layout="default" + + if test "$with_layout" = "default" ; then + case "$host_os" in + darwin*) + with_layout="macosx" + test x"$with_macosx_framework" != x"no" && with_layout="macosx-framework" + ;; + *) + with_layout="xdg" + ;; + esac + fi + + with_external_libxdg_basedir=no + + case "$with_layout" in + macosx-framework) + AC_DEFINE([XINE_LAYOUT_MACOSX_FRAMEWORK], 1, [Define this if using the Mac OS X framework layout]) + if test x"$ac_cv_framework_CoreFoundation" != x"yes" ; then + AC_MSG_ERROR([The Mac OS X framework layout requires CoreFoundation to be available.]) + fi + ;; + macosx) + AC_DEFINE([XINE_LAYOUT_MACOSX_LIBRARY], 1, [Define this if using the Mac OS X library layout]) + if test x"$ac_cv_framework_CoreFoundation" != x"yes" ; then + AC_MSG_ERROR([The Mac OS X library layout requires CoreFoundation to be available.]) + fi + ;; + xdg) + AC_DEFINE([XINE_LAYOUT_XDG], 1, [Define this if using the XDG layout]) + AC_ARG_WITH([external-libxdg-basedir], + [AS_HELP_STRING([--with-external-libxdg-basedir], [use external copy of libxdg-basedir])]) + if test x"$with_external_libxdg_basedir" = x"yes"; then + PKG_CHECK_MODULES([XDG_BASEDIR], [libxdg-basedir >= 0.1.3]) + else + XDG_BASEDIR_CPPFLAGS='-I$(top_srcdir)/contrib/libxdg-basedir' + XDG_BASEDIR_LIBS='$(top_builddir)/contrib/libxdg-basedir/libxdg-basedir.la' + XDG_BASEDIR_DEPS='$(top_builddir)/contrib/libxdg-basedir/libxdg-basedir.la' + fi + AC_SUBST([XDG_BASEDIR_CPPFLAGS]) + AC_SUBST([XDG_BASEDIR_LIBS]) + AC_SUBST([XDG_BASEDIR_DEPS]) + ;; + *) + AC_MSG_ERROR([Invalid layout for --with-layout; valid layouts are framework, macosx, and xdg]) + ;; + esac + + AM_CONDITIONAL([XINE_LAYOUT_XDG], [test x"$with_layout" = x"xdg"]) + AM_CONDITIONAL([EXTERNAL_LIBXDG_BASEDIR], [test x"$with_external_libxdg_basedir" = x"yes"]) +]) diff -r 7fd3df5d67d667238737563dafa4b72b641263df -r f9523c276598519f9e148162e450f4e5d63ce429 src/xine-utils/paths.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/xine-utils/paths.c Sat Aug 18 17:28:09 2007 -0400 @@ -0,0 +1,567 @@ +/* + * Copyright (C) 2000-2005 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * + * functions for obtaining platform-specific path information + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#define XINE_ENABLE_EXPERIMENTAL_FEATURES 1 +#define XINE_ENGINE_INTERNAL + +#include "xine_internal.h" +#include "xineutils.h" + +#include <sys/stat.h> +#ifdef HAVE_SYS_PARAM_H +#include <sys/param.h> +#endif + +#if !(defined(XINE_LAYOUT_MACOSX_FRAMEWORK) || defined(XINE_LAYOUT_MACOSX_LIBRARY) || defined(XINE_LAYOUT_XDG)) +#define XINE_LAYOUT_DEFAULT 1 +#else +#undef XINE_LAYOUT_DEFAULT +#endif + +#if defined(XINE_LAYOUT_MACOSX_FRAMEWORK) || defined(XINE_LAYOUT_MACOSX_LIBRARY) + +/* cache and config directories are always the same on Mac OS X, regardless + * of whether running as a framework or as a library. The font and plugin + * directories differ, though. For a framework, the fonts and plugins are + * embedded in the framework. For a library, the fonts and plugins are + * located in standard locations and where the library is installed. + */ + +#define FULL_PACKAGE "de.xinehq." PACKAGE + +/* No need to test for CoreFoundation -- layout.m4 will not allow either of + * these layouts if CoreFoundation is not available. */ +#include <CoreFoundation/CoreFoundation.h> + +static const char * +macosx_get_cache_directory(xine_t *xine) +{ + char *cache_directory; + const char *homedir; + + if ((homedir = xine_get_homedir()) != NULL) { + /* sizeof(string_literal) includes the null byte. */ + cache_directory = (char *)xine_xmalloc(strlen(homedir) + sizeof("/Library/Caches/" FULL_PACKAGE)); + if (cache_directory) { + return strcat(strcpy(cache_directory, homedir), "/Library/Caches/" FULL_PACKAGE); + } + } + return NULL; +} + +static const char * +macosx_get_config_directory(xine_t *xine) +{ + char *config_directory; + const char *homedir; + + if ((homedir = xine_get_homedir()) != NULL) { + /* sizeof(string_literal) includes the null byte. */ + config_directory = (char *)xine_xmalloc(strlen(homedir) + sizeof("/Library/Preferences/" FULL_PACKAGE)); + if (config_directory) { + return strcat(strcpy(config_directory, homedir), "/Library/Preferences/" FULL_PACKAGE); + } + } + return NULL; +} + +#endif + +#if defined(XINE_LAYOUT_MACOSX_FRAMEWORK) +static const char * const * +macosx_get_font_directories(xine_t *xine) +{ + char **directories; + CFURLRef resourcesURL = NULL; + CFBundleRef frameworkBundle; + + if ((directories = (char **)xine_xmalloc(sizeof(char *) * 2)) != NULL) { + /* So there's this internal function in CoreFoundation called + * CFURLCreateStringWithFileSystemPath() that does EXACTLY what we want + * to do here, but for reasons that are beyond my understanding, it's not + * exposed. Instead, we're left with no choice but to use the following + * horrible, horrible bit of code. + */ + directories[0] = directories[1] = NULL; + if ((frameworkBundle = CFBundleGetBundleWithIdentifier(CFSTR(FULL_PACKAGE))) != NULL && + (resourcesURL = CFBundleCopyResourcesDirectoryURL(frameworkBundle)) != NULL && + (directories[0] = (char *)xine_xmalloc(MAXPATHLEN + 1)) != NULL && + CFURLGetFileSystemRepresentation(resourcesURL, true, (UInt8 *)directories[0], MAXPATHLEN + 1)) + { + if (strlen(directories[0]) <= MAXPATHLEN - 6) { + strcat(directories[0], "/Fonts"); + } + } + if (resourcesURL) { + CFRelease(resourcesURL); + } + if (!directories[0]) { + free(directories); + directories = NULL; [... 315 lines omitted ...] + return -1; + } + + /* Copy the original path so that xine_strsep() can alter it. */ + pp = strcpy(buf, path); + + /* Loop with xine_strsep() to build the path. Add '/' each time except for + * the first, unless *path == '/'. buf and buf2 are the same size, so using + * strcpy here is safe. */ + for (len = 0; (p = xine_strsep(&pp, "/")) != NULL; len += (strlen(p))) { + if (p && *p) { + if (len || *path == '/') { + *(buf2 + len++) = '/'; + } + strcpy(buf2 + len, p); + if ((rc = xine_mkdir_safe(xine, buf2)) < 0) { + return rc; + } + } + } + + return 0; +} + +const char * +xine_get_cache_directory(xine_t *xine, int create) +{ + static const char *cache_directory = NULL; + + if (!cache_directory) { + if (!(cache_directory = getenv("XINE_CACHE_PATH")) || !*cache_directory) { +#if defined(XINE_LAYOUT_MACOSX_FRAMEWORK) || defined(XINE_LAYOUT_MACOSX_LIBRARY) + cache_directory = macosx_get_cache_directory(xine); +#elif defined(XINE_LAYOUT_XDG) + cache_directory = xdg_get_cache_directory(xine); +#else + cache_directory = get_cache_directory(xine); +#endif + } + } + if (cache_directory && create) { + if (xine_mkdir_recursive_safe(xine, cache_directory) < 0) { + return NULL; + } + } + return cache_directory; +} + +const char * +xine_get_config_directory(xine_t *xine, int create) +{ + static const char *config_directory = NULL; + + if (!config_directory) { + if (!(config_directory = getenv("XINE_CONFIG_PATH")) || !*config_directory) { +#if defined(XINE_LAYOUT_MACOSX_FRAMEWORK) || defined(XINE_LAYOUT_MACOSX_LIBRARY) + config_directory = macosx_get_config_directory(xine); +#elif defined(XINE_LAYOUT_XDG) + config_directory = xdg_get_config_directory(xine); +#else + config_directory = get_config_directory(xine); +#endif + } + } + if (config_directory && create) { + if (xine_mkdir_recursive_safe(xine, config_directory) < 0) { + return NULL; + } + } + return config_directory; +} + +const char * const * +xine_get_font_directories(xine_t *xine) +{ + char *fontpath; + const char * const *directories; + + if ((fontpath = getenv("XINE_FONT_PATH")) != NULL && *fontpath) { + directories = explode_path_list(fontpath); + if (directories && *directories) { + return directories; + } + xine_free_directory_list(xine, directories); + } +#if defined(XINE_LAYOUT_MACOSX_FRAMEWORK) + return macosx_get_font_directories(xine); +#elif defined(XINE_LAYOUT_XDG) + return xdg_get_font_directories(xine); +#else + return get_font_directories(xine); +#endif +} + +const char * const * +xine_get_plugin_directories(xine_t *xine) +{ + char *pluginpath; + const char * const *directories; + + if ((pluginpath = getenv("XINE_PLUGIN_PATH")) != NULL && *pluginpath) { + directories = explode_path_list(pluginpath); + if (directories && *directories) { + return directories; + } + xine_free_directory_list(xine, directories); + } + /* Only XINE_LAYOUT_MACOSX_FRAMEWORK has special plugin magic */ +#if defined(XINE_LAYOUT_MACOSX_FRAMEWORK) + return macosx_get_plugin_directories(xine); +#else + return get_plugin_directories(xine); +#endif +} + +void +xine_free_directory_list(xine_t *xine, const char * const *directories) +{ + int i; + char *directory; + + if (directories) { + for (i = 0; (directory = (char *)(directories[i])) != NULL; i++) { + free(directory); + } + free((void *)directories); + } +} |