/************************************************************************ * LoadCryptFile: Try to parse key_uri and keyfile-location from file ************************************************************************/ static int LoadCryptFile( sout_access_out_t *p_access ) { sout_access_out_sys_t *p_sys = p_access->p_sys; FILE *stream = vlc_fopen( p_sys->psz_keyfile, "rt" ); char *key_file=NULL,*key_uri=NULL; if( unlikely( stream == NULL ) ) { msg_Err( p_access, "Unable to open keyloadfile %s: %s", p_sys->psz_keyfile, vlc_strerror_c(errno) ); return VLC_EGENERIC; } //First read key_uri ssize_t len = getline( &key_uri, &(size_t){0}, stream ); if( unlikely( len == -1 ) ) { msg_Err( p_access, "Cannot read %s: %s", p_sys->psz_keyfile, vlc_strerror_c(errno) ); clearerr( stream ); fclose( stream ); free( key_uri ); return VLC_EGENERIC; } //Strip the newline from uri, maybe scanf would be better? key_uri[len-1]='\0'; len = getline( &key_file, &(size_t){0}, stream ); if( unlikely( len == -1 ) ) { msg_Err( p_access, "Cannot read %s: %s", p_sys->psz_keyfile, vlc_strerror_c(errno) ); clearerr( stream ); fclose( stream ); free( key_uri ); free( key_file ); return VLC_EGENERIC; } // Strip the last newline from filename key_file[len-1]='\0'; fclose( stream ); int returncode = VLC_SUCCESS; if( !p_sys->key_uri || strcmp( p_sys->key_uri, key_uri ) ) { if( p_sys->key_uri ) { free( p_sys->key_uri ); p_sys->key_uri = NULL; } p_sys->key_uri = strdup( key_uri ); returncode = CryptSetup( p_access, key_file ); } free( key_file ); free( key_uri ); return returncode; }
/***************************************************************************** * OpenDecoder: Open the decoder *****************************************************************************/ static int OpenDecoderCommon( vlc_object_t *p_this, bool b_force_dump ) { decoder_t *p_dec = (decoder_t*)p_this; char psz_file[10 + 3 * sizeof (p_dec)]; snprintf( psz_file, sizeof( psz_file), "stream.%p", p_dec ); if( !b_force_dump ) b_force_dump = var_InheritBool( p_dec, "dummy-save-es" ); if( b_force_dump ) { FILE *stream = vlc_fopen( psz_file, "wb" ); if( stream == NULL ) { msg_Err( p_dec, "cannot create `%s'", psz_file ); return VLC_EGENERIC; } msg_Dbg( p_dec, "dumping stream to file `%s'", psz_file ); p_dec->p_sys = (void *)stream; } else p_dec->p_sys = NULL; /* Set callbacks */ p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **)) DecodeBlock; p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **)) DecodeBlock; p_dec->pf_decode_sub = (subpicture_t *(*)(decoder_t *, block_t **)) DecodeBlock; es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in ); return VLC_SUCCESS; }
static char *MarqueeReadFile( filter_t *obj, const char *path ) { FILE *stream = vlc_fopen( path, "rt" ); if( stream == NULL ) { msg_Err( obj, "cannot open %s: %m", path ); return NULL; } char *line = NULL; size_t p = 0; // sunqueen add ssize_t len = getline( &line, &p/*&(size_t){ 0 }*/, stream ); // sunqueen modify if( len == -1 ) { msg_Err( obj, "cannot read %s: %m", path ); clearerr( stream ); line = NULL; } fclose( stream ); if( len >= 1 && line[len - 1] == '\n' ) line[--len] = '\0'; return line; }
int playlist_FindArtInCacheUsingItemUID( input_item_t *p_item ) { char *uid = input_item_GetInfo( p_item, "uid", "md5" ); if ( ! *uid ) { free( uid ); return VLC_EGENERIC; } /* we have an input item uid set */ bool b_done = false; char *psz_byuiddir = GetDirByItemUIDs( uid ); char *psz_byuidfile = GetFileByItemUID( psz_byuiddir, "arturl" ); free( psz_byuiddir ); if( psz_byuidfile ) { FILE *fd = vlc_fopen( psz_byuidfile, "rb" ); if ( fd ) { char sz_cachefile[2049]; /* read the cache hash url */ if ( fgets( sz_cachefile, 2048, fd ) != NULL ) { input_item_SetArtURL( p_item, sz_cachefile ); b_done = true; } fclose( fd ); } free( psz_byuidfile ); } free( uid ); if ( b_done ) return VLC_SUCCESS; return VLC_EGENERIC; }
static voidpf ZCALLBACK open_vlc( voidpf opaque, const char *filename, int mode) { (void)mode; intf_thread_t *pIntf = (intf_thread_t *)opaque; FILE *stream = vlc_fopen( filename, "rb" ); if( stream == NULL ) msg_Dbg( pIntf, "vlc_fopen failed for %s", filename ); return stream; }
static int InstallFile( addons_storage_t *p_this, const char *psz_downloadlink, const char *psz_dest ) { stream_t *p_stream; FILE *p_destfile; char buffer[1<<10]; int i_read = 0; p_stream = stream_UrlNew( p_this, psz_downloadlink ); if( !p_stream ) { msg_Err( p_this, "Failed to access Addon download url %s", psz_downloadlink ); return VLC_EGENERIC; } char *psz_path = strdup( psz_dest ); if ( !psz_path ) { stream_Delete( p_stream ); return VLC_ENOMEM; } char *psz_buf = strrchr( psz_path, DIR_SEP_CHAR ); if( psz_buf ) { *++psz_buf = '\0'; /* ensure directory exists */ if( !EMPTY_STR( psz_path ) ) recursive_mkdir( VLC_OBJECT(p_this), psz_path ); free( psz_path ); } p_destfile = vlc_fopen( psz_dest, "w" ); if( !p_destfile ) { msg_Err( p_this, "Failed to open Addon storage file %s", psz_dest ); stream_Delete( p_stream ); return VLC_EGENERIC; } while ( ( i_read = stream_Read( p_stream, &buffer, 1<<10 ) ) > 0 ) { if ( fwrite( &buffer, i_read, 1, p_destfile ) < 1 ) { msg_Err( p_this, "Failed to write to Addon file" ); fclose( p_destfile ); stream_Delete( p_stream ); return VLC_EGENERIC; } } fclose( p_destfile ); stream_Delete( p_stream ); return VLC_SUCCESS; }
int playlist_Export( playlist_t * p_playlist, const char *psz_filename, bool b_playlist, const char *psz_type ) { playlist_export_t *p_export = vlc_custom_create( p_playlist, sizeof( *p_export ), "playlist export" ); if( unlikely(p_export == NULL) ) return VLC_ENOMEM; msg_Dbg( p_export, "saving %s to file %s", b_playlist ? "playlist" : "media library", psz_filename ); int ret = VLC_EGENERIC; /* Prepare the playlist_export_t structure */ p_export->base_url = vlc_path2uri( psz_filename, NULL ); p_export->p_file = vlc_fopen( psz_filename, "wt" ); if( p_export->p_file == NULL ) { msg_Err( p_export, "could not create playlist file %s: %s", psz_filename, vlc_strerror_c(errno) ); goto out; } module_t *p_module; /* And call the module ! All work is done now */ playlist_Lock( p_playlist ); p_export->p_root = b_playlist ? p_playlist->p_playing : p_playlist->p_media_library; p_module = module_need( p_export, "playlist export", psz_type, true ); playlist_Unlock( p_playlist ); if( p_module != NULL ) { module_unneed( p_export, p_module ); if( !ferror( p_export->p_file ) ) ret = VLC_SUCCESS; else msg_Err( p_playlist, "could not write playlist file: %s", vlc_strerror_c(errno) ); } else msg_Err( p_playlist, "could not export playlist" ); fclose( p_export->p_file ); out: free( p_export->base_url ); vlc_object_release( p_export ); return ret; }
int playlist_Export( playlist_t * p_playlist, const char *psz_filename, playlist_item_t *p_export_root, const char *psz_type ) { if( p_export_root == NULL ) return VLC_EGENERIC; playlist_export_t *p_export = vlc_custom_create( p_playlist, sizeof( *p_export ), "playlist export" ); if( unlikely(p_export == NULL) ) return VLC_ENOMEM; msg_Dbg( p_export, "saving %s to file %s", p_export_root->p_input->psz_name, psz_filename ); int ret = VLC_EGENERIC; /* Prepare the playlist_export_t structure */ p_export->p_root = p_export_root; p_export->psz_filename = psz_filename; p_export->p_file = vlc_fopen( psz_filename, "wt" ); if( p_export->p_file == NULL ) { msg_Err( p_export, "could not create playlist file %s: %s", psz_filename, vlc_strerror_c(errno) ); goto out; } module_t *p_module; /* And call the module ! All work is done now */ playlist_Lock( p_playlist ); p_module = module_need( p_export, "playlist export", psz_type, true ); playlist_Unlock( p_playlist ); if( p_module != NULL ) { module_unneed( p_export, p_module ); if( !ferror( p_export->p_file ) ) ret = VLC_SUCCESS; else msg_Err( p_playlist, "could not write playlist file: %s", vlc_strerror_c(errno) ); } else msg_Err( p_playlist, "could not export playlist" ); fclose( p_export->p_file ); out: vlc_object_release( p_export ); return ret; }
/* hash a binary file */ static int hash_from_binary_file( const char *psz_file, gcry_md_hd_t hd ) { uint8_t buffer[4096]; size_t i_read; FILE *f = vlc_fopen( psz_file, "r" ); if( !f ) return -1; while( ( i_read = fread( buffer, 1, sizeof(buffer), f ) ) > 0 ) gcry_md_write( hd, buffer, i_read ); fclose( f ); return 0; }
/***************************************************************************** * Open file relative to base directory for reading. *****************************************************************************/ static FILE *OpenRelativeFile( access_t *p_access, const char *psz_file ) { /* build path and add extension */ char *psz_path; if( asprintf( &psz_path, "%s" DIR_SEP "%s%s", p_access->psz_filepath, psz_file, p_access->p_sys->b_ts_format ? "" : ".vdr" ) == -1 ) return NULL; FILE *file = vlc_fopen( psz_path, "rb" ); if( !file ) msg_Warn( p_access, "Failed to open %s: %m", psz_path ); free( psz_path ); return file; }
/** * Saves a module cache to disk, and release cache data from memory. */ void CacheSave (vlc_object_t *p_this, const char *dir, module_cache_t *entries, size_t n) { char *filename = NULL, *tmpname = NULL; if (asprintf (&filename, "%s"DIR_SEP CACHE_NAME, dir ) == -1) goto out; if (asprintf (&tmpname, "%s.%"PRIu32, filename, (uint32_t)getpid ()) == -1) goto out; msg_Dbg (p_this, "saving plugins cache %s", filename); FILE *file = vlc_fopen (tmpname, "wb"); if (file == NULL) { if (errno != EACCES && errno != ENOENT) msg_Warn (p_this, "cannot create %s: %s", tmpname, vlc_strerror_c(errno)); goto out; } if (CacheSaveBank (file, entries, n)) { msg_Warn (p_this, "cannot write %s: %s", tmpname, vlc_strerror_c(errno)); clearerr (file); fclose (file); vlc_unlink (tmpname); goto out; } #if !defined( _WIN32 ) && !defined( __OS2__ ) vlc_rename (tmpname, filename); /* atomically replace old cache */ fclose (file); #else vlc_unlink (filename); fclose (file); vlc_rename (tmpname, filename); #endif out: free (filename); free (tmpname); for (size_t i = 0; i < n; i++) free (entries[i].path); free (entries); }
/**************************************************************************** * Helpers ****************************************************************************/ static int Start( stream_t *s, const char *psz_extension ) { stream_sys_t *p_sys = s->p_sys; char *psz_file; FILE *f; /* */ if( !psz_extension ) psz_extension = "dat"; /* Retreive path */ char *psz_path = var_CreateGetNonEmptyString( s, "input-record-path" ); if( !psz_path ) psz_path = config_GetUserDir( VLC_DOWNLOAD_DIR ); if( !psz_path ) return VLC_ENOMEM; /* Create file name * TODO allow prefix configuration */ psz_file = input_CreateFilename( VLC_OBJECT(s), psz_path, INPUT_RECORD_PREFIX, psz_extension ); free( psz_path ); if( !psz_file ) return VLC_ENOMEM; f = vlc_fopen( psz_file, "wb" ); if( !f ) { free( psz_file ); return VLC_EGENERIC; } /* signal new record file */ var_SetString( s->p_libvlc, "record-file", psz_file ); msg_Dbg( s, "Recording into %s", psz_file ); free( psz_file ); /* */ p_sys->f = f; p_sys->b_error = false; return VLC_SUCCESS; }
int playlist_Export( playlist_t * p_playlist, const char *psz_filename, playlist_item_t *p_export_root, const char *psz_type ) { if( p_export_root == NULL ) return VLC_EGENERIC; playlist_export_t *p_export = vlc_custom_create( p_playlist, sizeof( *p_export ), VLC_OBJECT_GENERIC, "playlist export" ); if( !p_export ) return VLC_ENOMEM; vlc_object_attach( p_export, p_playlist ); msg_Dbg( p_export, "saving %s to file %s", p_export_root->p_input->psz_name, psz_filename ); int ret = VLC_EGENERIC; /* Prepare the playlist_export_t structure */ p_export->p_root = p_export_root; p_export->psz_filename = psz_filename; p_export->p_file = vlc_fopen( psz_filename, "wt" ); if( p_export->p_file == NULL ) msg_Err( p_export, "could not create playlist file %s (%m)", psz_filename ); else { module_t *p_module; /* And call the module ! All work is done now */ playlist_Lock( p_playlist ); p_module = module_need( p_export, "playlist export", psz_type, true ); playlist_Unlock( p_playlist ); if( p_module == NULL ) msg_Err( p_playlist, "could not export playlist" ); else { module_unneed( p_export, p_module ); ret = VLC_SUCCESS; } fclose( p_export->p_file ); } vlc_object_release( p_export ); return ret; }
/***************************************************************************** * SavePluginsCache: saves the plugins cache to a file *****************************************************************************/ void CacheSave (vlc_object_t *p_this, const char *dir, module_cache_t *const *pp_cache, size_t n) { char *filename, *tmpname; if (asprintf (&filename, "%s"DIR_SEP CACHE_NAME, dir ) == -1) return; if (asprintf (&tmpname, "%s.%"PRIu32, filename, (uint32_t)getpid ()) == -1) { free (filename); return; } msg_Dbg (p_this, "saving plugins cache %s", filename); FILE *file = vlc_fopen (tmpname, "wb"); if (file == NULL) { if (errno != EACCES && errno != ENOENT) msg_Warn (p_this, "cannot create %s (%m)", tmpname); goto out; } if (CacheSaveBank (file, pp_cache, n)) { msg_Warn (p_this, "cannot write %s (%m)", tmpname); clearerr (file); fclose (file); vlc_unlink (tmpname); goto out; } #if !defined( WIN32 ) && !defined( __OS2__ ) vlc_rename (tmpname, filename); /* atomically replace old cache */ fclose (file); #else vlc_unlink (filename); fclose (file); vlc_rename (tmpname, filename); #endif out: free (filename); free (tmpname); }
/***************************************************************************** * Open: *****************************************************************************/ static int Open( vlc_object_t *p_this ) { sout_stream_t *p_stream = (sout_stream_t*)p_this; sout_stream_sys_t *p_sys; char *outputFile; p_sys = calloc( 1, sizeof( sout_stream_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options, p_stream->p_cfg ); outputFile = var_InheritString( p_stream, SOUT_CFG_PREFIX "output" ); if( outputFile ) { p_sys->output = vlc_fopen( outputFile, "wt" ); if( !p_sys->output ) { msg_Err( p_stream, "Unable to open file '%s' for writing", outputFile ); free( p_sys ); free( outputFile ); return VLC_EGENERIC; } else { fprintf( p_sys->output,"#prefix\ttrack\ttype\tsegment_number\tdts_difference\tlength\tmd5\n"); } free( outputFile ); } p_sys->prefix = var_InheritString( p_stream, SOUT_CFG_PREFIX "prefix" ); p_stream->p_sys = p_sys; p_stream->pf_add = Add; p_stream->pf_del = Del; p_stream->pf_send = Send; return VLC_SUCCESS; }
static int ImageWriteUrl( image_handler_t *p_image, picture_t *p_pic, video_format_t *p_fmt_in, video_format_t *p_fmt_out, const char *psz_url ) { block_t *p_block; FILE *file; if( !p_fmt_out->i_chroma ) { /* Try to guess format from file name */ p_fmt_out->i_chroma = image_Ext2Fourcc( psz_url ); } file = vlc_fopen( psz_url, "wb" ); if( !file ) { msg_Err( p_image->p_parent, "%s: %s", psz_url, vlc_strerror_c(errno) ); return VLC_EGENERIC; } p_block = ImageWrite( p_image, p_pic, p_fmt_in, p_fmt_out ); int err = 0; if( p_block ) { if( fwrite( p_block->p_buffer, p_block->i_buffer, 1, file ) != 1 ) err = errno; block_Release( p_block ); } if( fclose( file ) && !err ) err = errno; if( err ) { errno = err; msg_Err( p_image->p_parent, "%s: %s", psz_url, vlc_strerror_c(errno) ); } return err ? VLC_EGENERIC : VLC_SUCCESS; }
int HttpCallback( httpd_file_sys_t *p_args, httpd_file_t *p_file, uint8_t *_p_request, uint8_t **_pp_data, int *pi_data ) { VLC_UNUSED(p_file); char *p_request = (char *)_p_request; char **pp_data = (char **)_pp_data; FILE *f; if( ( f = vlc_fopen( p_args->file, "r" ) ) == NULL ) { Callback404( p_args, pp_data, pi_data ); return VLC_SUCCESS; } if( !p_args->b_html ) { FileLoad( f, pp_data, pi_data ); } else { int i_buffer; char *p_buffer; /* first we load in a temporary buffer */ FileLoad( f, &p_buffer, &i_buffer ); ParseExecute( p_args, p_buffer, i_buffer, p_request, pp_data, pi_data ); free( p_buffer ); } fclose( f ); return VLC_SUCCESS; }
static char *MarqueeReadFile( filter_t *obj, const char *path ) { FILE *stream = vlc_fopen( path, "rt" ); if( stream == NULL ) { msg_Err( obj, "cannot open %s: %s", path, vlc_strerror_c(errno) ); return NULL; } char *line = NULL; ssize_t len = getline( &line, &(size_t){ 0 }, stream ); if( len == -1 ) { msg_Err( obj, "cannot read %s: %s", path, vlc_strerror_c(errno) ); clearerr( stream ); line = NULL; } fclose( stream ); if( len >= 1 && line[len - 1] == '\n' ) line[--len] = '\0'; return line; }
/** * Loads a plugins cache file. * * This function will load the plugin cache if present and valid. This cache * will in turn be queried by AllocateAllPlugins() to see if it needs to * actually load the dynamically loadable module. * This allows us to only fully load plugins when they are actually used. */ size_t CacheLoad( vlc_object_t *p_this, const char *dir, module_cache_t **r ) { char *psz_filename; FILE *file; int i_size, i_read; char p_cachestring[sizeof(CACHE_STRING)]; size_t i_cache; int32_t i_marker; assert( dir != NULL ); *r = NULL; if( asprintf( &psz_filename, "%s"DIR_SEP CACHE_NAME, dir ) == -1 ) return 0; msg_Dbg( p_this, "loading plugins cache file %s", psz_filename ); file = vlc_fopen( psz_filename, "rb" ); if( !file ) { msg_Warn( p_this, "cannot read %s: %s", psz_filename, vlc_strerror_c(errno) ); free( psz_filename ); return 0; } free( psz_filename ); /* Check the file is a plugins cache */ i_size = sizeof(CACHE_STRING) - 1; i_read = fread( p_cachestring, 1, i_size, file ); if( i_read != i_size || memcmp( p_cachestring, CACHE_STRING, i_size ) ) { msg_Warn( p_this, "This doesn't look like a valid plugins cache" ); fclose( file ); return 0; } #ifdef DISTRO_VERSION /* Check for distribution specific version */ char p_distrostring[sizeof( DISTRO_VERSION )]; i_size = sizeof( DISTRO_VERSION ) - 1; i_read = fread( p_distrostring, 1, i_size, file ); if( i_read != i_size || memcmp( p_distrostring, DISTRO_VERSION, i_size ) ) { msg_Warn( p_this, "This doesn't look like a valid plugins cache" ); fclose( file ); return 0; } #endif /* Check Sub-version number */ i_read = fread( &i_marker, 1, sizeof(i_marker), file ); if( i_read != sizeof(i_marker) || i_marker != CACHE_SUBVERSION_NUM ) { msg_Warn( p_this, "This doesn't look like a valid plugins cache " "(corrupted header)" ); fclose( file ); return 0; } /* Check header marker */ i_read = fread( &i_marker, 1, sizeof(i_marker), file ); if( i_read != sizeof(i_marker) || i_marker != ftell( file ) - (int)sizeof(i_marker) ) { msg_Warn( p_this, "This doesn't look like a valid plugins cache " "(corrupted header)" ); fclose( file ); return 0; } if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) ) { msg_Warn( p_this, "This doesn't look like a valid plugins cache " "(file too short)" ); fclose( file ); return 0; } module_cache_t *cache = NULL; for (size_t count = 0; count < i_cache;) { module_t *module; int i_submodules; module = vlc_module_create (NULL); /* Load additional infos */ LOAD_STRING(module->psz_shortname); LOAD_STRING(module->psz_longname); LOAD_STRING(module->psz_help); LOAD_IMMEDIATE(module->i_shortcuts); if (module->i_shortcuts > MODULE_SHORTCUT_MAX) goto error; else { module->pp_shortcuts = xmalloc (sizeof (*module->pp_shortcuts) * module->i_shortcuts); for (unsigned j = 0; j < module->i_shortcuts; j++) LOAD_STRING(module->pp_shortcuts[j]); } LOAD_STRING(module->psz_capability); LOAD_IMMEDIATE(module->i_score); LOAD_IMMEDIATE(module->b_unloadable); /* Config stuff */ if (CacheLoadModuleConfig (module, file) != VLC_SUCCESS) goto error; LOAD_STRING(module->domain); if (module->domain != NULL) vlc_bindtextdomain (module->domain); LOAD_IMMEDIATE( i_submodules ); while( i_submodules-- ) { module_t *submodule = vlc_module_create (module); free (submodule->pp_shortcuts); LOAD_STRING(submodule->psz_shortname); LOAD_STRING(submodule->psz_longname); LOAD_IMMEDIATE(submodule->i_shortcuts); if (submodule->i_shortcuts > MODULE_SHORTCUT_MAX) goto error; else { submodule->pp_shortcuts = xmalloc (sizeof (*submodule->pp_shortcuts) * submodule->i_shortcuts); for (unsigned j = 0; j < submodule->i_shortcuts; j++) LOAD_STRING(submodule->pp_shortcuts[j]); } LOAD_STRING(submodule->psz_capability); LOAD_IMMEDIATE(submodule->i_score); } char *path; struct stat st; /* Load common info */ LOAD_STRING(path); if (path == NULL) goto error; LOAD_IMMEDIATE(st.st_mtime); LOAD_IMMEDIATE(st.st_size); CacheAdd (&cache, &count, path, &st, module); free (path); /* TODO: deal with errors */ } fclose( file ); *r = cache; return i_cache; error: msg_Warn( p_this, "plugins cache not loaded (corrupted)" ); /* TODO: cleanup */ fclose( file ); return 0; }
/** * Initialize a libvlc instance * This function initializes a previously allocated libvlc instance: * - CPU detection * - gettext initialization * - message queue, module bank and playlist initialization * - configuration and commandline parsing */ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, const char *ppsz_argv[] ) { libvlc_priv_t *priv = libvlc_priv (p_libvlc); char * psz_modules = NULL; char * psz_parser = NULL; char * psz_control = NULL; playlist_t *p_playlist = NULL; char *psz_val; /* System specific initialization code */ system_Init(); /* Initialize the module bank and load the configuration of the * main module. We need to do this at this stage to be able to display * a short help if required by the user. (short help == main module * options) */ module_InitBank (); /* Get command line options that affect module loading. */ if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) ) { module_EndBank (false); return VLC_EGENERIC; } priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" ); /* Find verbosity from VLC_VERBOSE environment variable */ { char *env = getenv( "VLC_VERBOSE" ); if( env != NULL ) priv->i_verbose = atoi( env ); } /* Announce who we are (TODO: only first instance?) */ msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE ); msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE ); msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset ); msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE ); /* Load the builtins and plugins into the module_bank. * We have to do it before config_Load*() because this also gets the * list of configuration options exported by each module and loads their * default values. */ size_t module_count = module_LoadPlugins (p_libvlc); /* * Override default configuration with config file settings */ if( !var_InheritBool( p_libvlc, "ignore-config" ) ) { if( var_InheritBool( p_libvlc, "reset-config" ) ) config_SaveConfigFile( p_libvlc ); /* Save default config */ else config_LoadConfigFile( p_libvlc ); } /* * Override configuration with command line settings */ int vlc_optind; if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) ) { #ifdef WIN32 MessageBox (NULL, TEXT("The command line options could not be parsed.\n" "Make sure they are valid."), TEXT("VLC media player"), MB_OK|MB_ICONERROR); #endif module_EndBank (true); return VLC_EGENERIC; } priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" ); /* * Support for gettext */ #if defined( ENABLE_NLS ) \ && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) vlc_bindtextdomain (PACKAGE_NAME); #endif /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */ msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") ); if (config_PrintHelp (VLC_OBJECT(p_libvlc))) { module_EndBank (true); return VLC_EEXITSUCCESS; } if( module_count <= 1 ) { msg_Err( p_libvlc, "No plugins found! Check your VLC installation."); module_EndBank (true); return VLC_ENOITEM; } #ifdef HAVE_DAEMON /* Check for daemon mode */ if( var_InheritBool( p_libvlc, "daemon" ) ) { char *psz_pidfile = NULL; if( daemon( 1, 0) != 0 ) { msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" ); module_EndBank (true); return VLC_EEXIT; } b_daemon = true; /* lets check if we need to write the pidfile */ psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" ); if( psz_pidfile != NULL ) { FILE *pidfile; pid_t i_pid = getpid (); msg_Dbg( p_libvlc, "PID is %d, writing it to %s", i_pid, psz_pidfile ); pidfile = vlc_fopen( psz_pidfile,"w" ); if( pidfile != NULL ) { utf8_fprintf( pidfile, "%d", (int)i_pid ); fclose( pidfile ); } else { msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)", psz_pidfile ); } } free( psz_pidfile ); } #endif /* FIXME: could be replaced by using Unix sockets */ #ifdef HAVE_DBUS #define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append" #define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc" #define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2" #define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList" dbus_threads_init_default(); if( var_InheritBool( p_libvlc, "one-instance" ) || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" ) && var_InheritBool( p_libvlc, "started-from-file" ) ) ) { /* Initialise D-Bus interface, check for other instances */ DBusConnection *p_conn = NULL; DBusError dbus_error; dbus_error_init( &dbus_error ); /* connect to the session bus */ p_conn = dbus_bus_get( DBUS_BUS_SESSION, &dbus_error ); if( !p_conn ) { msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s", dbus_error.message ); dbus_error_free( &dbus_error ); } else { /* check if VLC is available on the bus * if not: D-Bus control is not enabled on the other * instance and we can't pass MRLs to it */ if( !dbus_bus_name_has_owner( p_conn, MPRIS_BUS_NAME, &dbus_error ) ) { if( dbus_error_is_set( &dbus_error ) ) { msg_Err( p_libvlc, "D-Bus error: %s", dbus_error.message ); dbus_error_free( &dbus_error ); } else msg_Dbg( p_libvlc, "No Media Player is running. " "Continuing normally." ); } else { int i_input; DBusMessage* p_dbus_msg = NULL; DBusMessageIter dbus_args; DBusPendingCall* p_dbus_pending = NULL; dbus_bool_t b_play; msg_Warn( p_libvlc, "Another Media Player is running. Exiting"); for( i_input = vlc_optind; i_input < i_argc;i_input++ ) { /* Skip input options, we can't pass them through D-Bus */ if( ppsz_argv[i_input][0] == ':' ) { msg_Warn( p_libvlc, "Ignoring option %s", ppsz_argv[i_input] ); continue; } /* We need to resolve relative paths in this instance */ char *psz_mrl; if( strstr( psz_mrl, "://" ) ) psz_mrl = strdup( ppsz_argv[i_input] ); else psz_mrl = vlc_path2uri( ppsz_argv[i_input], NULL ); const char *psz_after_track = MPRIS_APPEND; if( psz_mrl == NULL ) continue; msg_Dbg( p_libvlc, "Adds %s to the running Media Player", psz_mrl ); p_dbus_msg = dbus_message_new_method_call( MPRIS_BUS_NAME, MPRIS_OBJECT_PATH, MPRIS_TRACKLIST_INTERFACE, "AddTrack" ); if ( NULL == p_dbus_msg ) { msg_Err( p_libvlc, "D-Bus problem" ); free( psz_mrl ); system_End( ); exit( 1 ); } /* append MRLs */ dbus_message_iter_init_append( p_dbus_msg, &dbus_args ); if ( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_STRING, &psz_mrl ) ) { dbus_message_unref( p_dbus_msg ); free( psz_mrl ); system_End( ); exit( 1 ); } free( psz_mrl ); if( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_OBJECT_PATH, &psz_after_track ) ) { dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } b_play = TRUE; if( var_InheritBool( p_libvlc, "playlist-enqueue" ) ) b_play = FALSE; if ( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_BOOLEAN, &b_play ) ) { dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } /* send message and get a handle for a reply */ if ( !dbus_connection_send_with_reply ( p_conn, p_dbus_msg, &p_dbus_pending, -1 ) ) { msg_Err( p_libvlc, "D-Bus problem" ); dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } if ( NULL == p_dbus_pending ) { msg_Err( p_libvlc, "D-Bus problem" ); dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } dbus_connection_flush( p_conn ); dbus_message_unref( p_dbus_msg ); /* block until we receive a reply */ dbus_pending_call_block( p_dbus_pending ); dbus_pending_call_unref( p_dbus_pending ); } /* processes all command line MRLs */ /* bye bye */ system_End( ); exit( 0 ); } } /* we unreference the connection when we've finished with it */ if( p_conn ) dbus_connection_unref( p_conn ); } #undef MPRIS_APPEND #undef MPRIS_BUS_NAME #undef MPRIS_OBJECT_PATH #undef MPRIS_TRACKLIST_INTERFACE #endif // HAVE_DBUS /* * Message queue options */ /* Last chance to set the verbosity. Once we start interfaces and other * threads, verbosity becomes read-only. */ var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); if( var_InheritBool( p_libvlc, "quiet" ) ) { var_SetInteger( p_libvlc, "verbose", -1 ); priv->i_verbose = -1; } vlc_threads_setup( p_libvlc ); if( priv->b_color ) priv->b_color = var_InheritBool( p_libvlc, "color" ); vlc_CPU_dump( VLC_OBJECT(p_libvlc) ); vlc_object_set_name( p_libvlc, "main" ); priv->b_stats = var_InheritBool( p_libvlc, "stats" ); /* * Initialize hotkey handling */ priv->actions = vlc_InitActions( p_libvlc ); /* Create a variable for showing the fullscreen interface */ var_Create( p_libvlc, "intf-toggle-fscontrol", VLC_VAR_BOOL ); var_SetBool( p_libvlc, "intf-toggle-fscontrol", true ); /* Create a variable for the Boss Key */ var_Create( p_libvlc, "intf-boss", VLC_VAR_VOID ); /* Create a variable for showing the main interface */ var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL ); /* Create a variable for showing the right click menu */ var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL ); /* variables for signalling creation of new files */ var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING ); var_Create( p_libvlc, "record-file", VLC_VAR_STRING ); /* some default internal settings */ var_Create( p_libvlc, "window", VLC_VAR_STRING ); var_Create( p_libvlc, "user-agent", VLC_VAR_STRING ); var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" ); /* Initialize playlist and get commandline files */ p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) ); if( !p_playlist ) { msg_Err( p_libvlc, "playlist initialization failed" ); module_EndBank (true); return VLC_EGENERIC; } /* System specific configuration */ system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); #if defined(MEDIA_LIBRARY) /* Get the ML */ if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) ) { priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL ); if( !priv->p_ml ) { msg_Err( p_libvlc, "ML initialization failed" ); return VLC_EGENERIC; } } else { priv->p_ml = NULL; } #endif /* Add service discovery modules */ psz_modules = var_InheritString( p_libvlc, "services-discovery" ); if( psz_modules ) { char *p = psz_modules, *m; while( ( m = strsep( &p, " :," ) ) != NULL ) playlist_ServicesDiscoveryAdd( p_playlist, m ); free( psz_modules ); } #ifdef ENABLE_VLM /* Initialize VLM if vlm-conf is specified */ psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" ); if( psz_parser ) { priv->p_vlm = vlm_New( p_libvlc ); if( !priv->p_vlm ) msg_Err( p_libvlc, "VLM initialization failed" ); } free( psz_parser ); #endif /* * Load background interfaces */ psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" ); psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" ); if( psz_modules && psz_control ) { char* psz_tmp; if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 ) { free( psz_modules ); psz_modules = psz_tmp; } } else if( psz_control ) { free( psz_modules ); psz_modules = strdup( psz_control ); } psz_parser = psz_modules; while ( psz_parser && *psz_parser ) { char *psz_module, *psz_temp; psz_module = psz_parser; psz_parser = strchr( psz_module, ':' ); if ( psz_parser ) { *psz_parser = '\0'; psz_parser++; } if( asprintf( &psz_temp, "%s,none", psz_module ) != -1) { intf_Create( p_libvlc, psz_temp ); free( psz_temp ); } } free( psz_modules ); free( psz_control ); /* * Always load the hotkeys interface if it exists */ intf_Create( p_libvlc, "hotkeys,none" ); if( var_InheritBool( p_libvlc, "file-logging" ) #ifdef HAVE_SYSLOG_H && !var_InheritBool( p_libvlc, "syslog" ) #endif ) { intf_Create( p_libvlc, "logger,none" ); } #ifdef HAVE_SYSLOG_H if( var_InheritBool( p_libvlc, "syslog" ) ) { char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" ); var_SetString( p_libvlc, "logmode", "syslog" ); intf_Create( p_libvlc, "logger,none" ); if( logmode ) { var_SetString( p_libvlc, "logmode", logmode ); free( logmode ); } var_Destroy( p_libvlc, "logmode" ); } #endif if( var_InheritBool( p_libvlc, "network-synchronisation") ) { intf_Create( p_libvlc, "netsync,none" ); } #ifdef __APPLE__ var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS ); #endif #if defined (WIN32) || defined (__OS2__) var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER ); #endif /* * Get input filenames given as commandline arguments. * We assume that the remaining parameters are filenames * and their input options. */ GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); /* * Get --open argument */ psz_val = var_InheritString( p_libvlc, "open" ); if ( psz_val != NULL ) { playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0, -1, 0, NULL, 0, true, pl_Unlocked ); free( psz_val ); } return VLC_SUCCESS; }
/***************************************************************************** * Simple parser open function *****************************************************************************/ int osd_parser_simpleOpen( vlc_object_t *p_this ) { osd_menu_t *p_menu = (osd_menu_t *) p_this; osd_button_t *p_current = NULL; /* button currently processed */ osd_button_t *p_prev = NULL; /* previous processed button */ FILE *fd = NULL; int result = 0; if( !p_menu ) return VLC_ENOOBJ; msg_Dbg( p_this, "opening osdmenu definition file %s", p_menu->psz_file ); fd = vlc_fopen( p_menu->psz_file, "r" ); if( !fd ) { msg_Err( p_this, "failed to open osdmenu definition file %s", p_menu->psz_file ); return VLC_EGENERIC; } /* Read first line */ if( !feof( fd ) ) { char action[25] = ""; char cmd[25] = ""; char path[PATH_MAX] = ""; char *psz_path = NULL; size_t i_len = 0; long pos = 0; result = fscanf(fd, "%24s %255s", action, path ); /* override images path ? */ psz_path = var_InheritString( p_this, "osdmenu-file-path" ); if( psz_path ) { /* psz_path is not null and therefor path cannot be NULL * it might be null terminated. */ strncpy( path, psz_path, PATH_MAX ); free( psz_path ); psz_path = NULL; } /* NULL terminate before asking the length of path[] */ path[PATH_MAX-1] = '\0'; i_len = strlen(path); /* Protect against buffer overflow: * max index is PATH_MAX-1 and we increment by 1 after * so PATH_MAX-2 is the bigest we can have */ if( i_len > PATH_MAX - 2 ) i_len = PATH_MAX - 2; #if defined(WIN32) || defined(UNDER_CE) || defined(__OS2__) if( (i_len > 0) && path[i_len] != '\\' ) path[i_len] = '\\'; #else if( (i_len > 0) && path[i_len] != '/' ) path[i_len] = '/'; #endif path[i_len+1] = '\0'; if( result == 0 || result == EOF ) goto error; msg_Dbg( p_this, "osdmenu dir %s", path ); if( i_len == 0 ) p_menu = osd_MenuNew( p_menu, NULL, 0, 0 ); else p_menu = osd_MenuNew( p_menu, path, 0, 0 ); /* Peek for 'style' argument */ pos = ftell( fd ); if( pos < 0 ) goto error; result = fscanf(fd, "%24s %24s", cmd, action ); if( result == 0 || result == EOF ) goto error; msg_Dbg( p_this, "osdmenu %s %s", cmd, action ); if( strncmp( cmd, "style", 5 ) == 0 ) { if( strncmp( action, "default", 7) == 0 ) { p_menu->i_style = OSD_MENU_STYLE_SIMPLE; } else if( strncmp( action, "concat", 6) == 0 ) { p_menu->i_style = OSD_MENU_STYLE_CONCAT; } } else { result = fseek( fd, pos, SEEK_SET ); if( result < 0 ) goto error; } } if( !p_menu ) goto error; /* read successive lines */ while( !feof( fd ) ) { osd_state_t *p_state_current = NULL; /* button state currently processed */ osd_state_t *p_state_prev = NULL; /* previous state processed button */ char cmd[25] = ""; char action[25] = ""; char state[25] = ""; char file[256] = ""; char path[PATH_MAX] = ""; int i_x = 0; int i_y = 0; result = fscanf( fd, "%24s %24s (%d,%d)", cmd, action, &i_x, &i_y ); if( result == 0 ) goto error; if( strncmp( &cmd[0], "action", 6 ) != 0 ) break; msg_Dbg( p_this, " + %s hotkey=%s (%d,%d)", cmd, action, i_x, i_y ); p_prev = p_current; p_current = osd_ButtonNew( action, i_x, i_y ); if( !p_current ) goto error; if( p_prev ) p_prev->p_next = p_current; else p_menu->p_button = p_current; p_current->p_prev = p_prev; /* parse all states */ while( !feof( fd ) ) { char type[25] = ""; result = fscanf( fd, "\t%24s", state ); if( result == 0 ) goto error; /* FIXME: We only parse one level deep now */ if( strncmp( state, "action", 6 ) == 0 ) { osd_button_t *p_up = NULL; result = fscanf( fd, "%24s (%d,%d)", action, &i_x, &i_y ); if( result == 0 ) goto error; /* create new button */ p_up = osd_ButtonNew( action, i_x, i_y ); if( !p_up ) goto error; /* Link to list */ p_up->p_down = p_current; p_current->p_up = p_up; msg_Dbg( p_this, " + (menu up) hotkey=%s (%d,%d)", action, i_x, i_y ); /* Parse type state */ result = fscanf( fd, "\t%24s %24s", cmd, type ); if( result == 0 ) goto error; if( strncmp( cmd, "type", 4 ) == 0 ) { if( strncmp( type, "volume", 6 ) == 0 ) { p_menu->p_state->p_volume = p_up; msg_Dbg( p_this, " + type=%s", type ); } } /* Parse range state */ result = fscanf( fd, "\t%24s", state ); if( result == 0 ) goto error; /* Parse the range state */ if( strncmp( state, "range", 5 ) == 0 ) { osd_state_t *p_range_current = NULL; /* range state currently processed */ osd_state_t *p_range_prev = NULL; /* previous state processed range */ int i_index = 0; p_up->b_range = true; result = fscanf( fd, "\t%24s", action ); if( result == 0 ) goto error; result = fscanf( fd, "\t%d", &i_index ); if( result == 0 ) goto error; msg_Dbg( p_this, " + (menu up) hotkey down %s, file=%s%s", action, p_menu->psz_path, file ); free( p_up->psz_action_down ); p_up->psz_action_down = strdup( action ); /* Parse range contstruction : * range <hotkey> * <state1> <file1> * * <stateN> <fileN> * end */ while( !feof( fd ) ) { result = fscanf( fd, "\t%255s", file ); if( result == 0 ) goto error; if( strncmp( file, "end", 3 ) == 0 ) break; p_range_prev = p_range_current; if( p_menu->psz_path ) { size_t i_path_size = strlen( p_menu->psz_path ); size_t i_file_size = strlen( file ); if( (i_path_size + i_file_size >= PATH_MAX) || (i_path_size >= PATH_MAX) ) goto error; strncpy( path, p_menu->psz_path, i_path_size ); strncpy( &path[i_path_size], file, PATH_MAX - (i_path_size + i_file_size) ); path[ i_path_size + i_file_size ] = '\0'; p_range_current = osd_StateNew( p_menu, path, "pressed" ); } else /* absolute paths are used. */ p_range_current = osd_StateNew( p_menu, file, "pressed" ); if( !p_range_current ) goto error; if( !p_range_current->p_pic ) { osd_StatesFree( p_menu, p_range_current ); goto error; } p_range_current->i_x = i_x; p_range_current->i_y = i_y; /* increment the number of ranges for this button */ p_up->i_ranges++; if( p_range_prev ) p_range_prev->p_next = p_range_current; else p_up->p_states = p_range_current; p_range_current->p_prev = p_range_prev; msg_Dbg( p_this, " |- range=%d, file=%s%s", p_up->i_ranges, p_menu->psz_path, file ); } if( i_index > 0 ) { osd_state_t *p_range = NULL; /* Find the default index for state range */ p_range = p_up->p_states; while( (--i_index > 0) && p_range->p_next ) { osd_state_t *p_temp = NULL; p_temp = p_range->p_next; p_range = p_temp; } p_up->p_current_state = p_range; } else p_up->p_current_state = p_up->p_states; } result = fscanf( fd, "\t%24s", state ); if( result == 0 ) goto error; if( strncmp( state, "end", 3 ) != 0 ) goto error; /* Continue at the beginning of the while() */ continue; } /* Parse the range state */ if( strncmp( state, "range", 5 ) == 0 ) { osd_state_t *p_range_current = NULL; /* range state currently processed */ osd_state_t *p_range_prev = NULL; /* previous state processed range */ int i_index = 0; p_current->b_range = true; result = fscanf( fd, "\t%24s", action ); if( result == 0 ) goto error; result = fscanf( fd, "\t%d", &i_index ); if( result == 0 ) goto error; msg_Dbg( p_this, " + hotkey down %s, file=%s%s", action, p_menu->psz_path, file ); free( p_current->psz_action_down ); p_current->psz_action_down = strdup( action ); /* Parse range contstruction : * range <hotkey> * <state1> <file1> * * <stateN> <fileN> * end */ while( !feof( fd ) ) { result = fscanf( fd, "\t%255s", file ); if( result == 0 ) goto error; if( strncmp( file, "end", 3 ) == 0 ) break; p_range_prev = p_range_current; if( p_menu->psz_path ) { size_t i_path_size = strlen( p_menu->psz_path ); size_t i_file_size = strlen( file ); if( (i_path_size + i_file_size >= PATH_MAX) || (i_path_size >= PATH_MAX) ) goto error; strncpy( path, p_menu->psz_path, i_path_size ); strncpy( &path[i_path_size], file, PATH_MAX - (i_path_size + i_file_size) ); path[ i_path_size + i_file_size ] = '\0'; p_range_current = osd_StateNew( p_menu, path, "pressed" ); } else /* absolute paths are used. */ p_range_current = osd_StateNew( p_menu, file, "pressed" ); if( !p_range_current ) goto error; if( !p_range_current->p_pic ) { osd_StatesFree( p_menu, p_range_current ); goto error; } p_range_current->i_x = i_x; p_range_current->i_y = i_y; /* increment the number of ranges for this button */ p_current->i_ranges++; if( p_range_prev ) p_range_prev->p_next = p_range_current; else p_current->p_states = p_range_current; p_range_current->p_prev = p_range_prev; msg_Dbg( p_this, " |- range=%d, file=%s%s", p_current->i_ranges, p_menu->psz_path, file ); } if( i_index > 0 ) { osd_state_t *p_range = NULL; /* Find the default index for state range */ p_range = p_current->p_states; while( (--i_index > 0) && p_range->p_next ) { osd_state_t *p_temp = NULL; p_temp = p_range->p_next; p_range = p_temp; } p_current->p_current_state = p_range; } else p_current->p_current_state = p_current->p_states; /* Continue at the beginning of the while() */ continue; } if( strncmp( state, "end", 3 ) == 0 ) break; result = fscanf( fd, "\t%255s", file ); if( result == 0 ) goto error; p_state_prev = p_state_current; if( ( strncmp( ppsz_button_states[0], state, strlen(ppsz_button_states[0]) ) != 0 ) && ( strncmp( ppsz_button_states[1], state, strlen(ppsz_button_states[1]) ) != 0 ) && ( strncmp( ppsz_button_states[2], state, strlen(ppsz_button_states[2]) ) != 0 ) ) { msg_Err( p_this, "invalid button state %s for button %s " "expected %u: unselect, select or pressed)", state, action, (unsigned)strlen(state)); goto error; } if( p_menu->psz_path ) { size_t i_path_size = strlen( p_menu->psz_path ); size_t i_file_size = strlen( file ); if( (i_path_size + i_file_size >= PATH_MAX) || (i_path_size >= PATH_MAX) ) goto error; strncpy( path, p_menu->psz_path, i_path_size ); strncpy( &path[i_path_size], file, PATH_MAX - (i_path_size + i_file_size) ); path[ i_path_size + i_file_size ] = '\0'; p_state_current = osd_StateNew( p_menu, path, state ); } else /* absolute paths are used. */ p_state_current = osd_StateNew( p_menu, file, state ); if( !p_state_current ) goto error; if( !p_state_current->p_pic ) { osd_StatesFree( p_menu, p_state_current ); goto error; } p_state_current->i_x = i_x; p_state_current->i_y = i_y; if( p_state_prev ) p_state_prev->p_next = p_state_current; else p_current->p_states = p_state_current; p_state_current->p_prev = p_state_prev; msg_Dbg( p_this, " |- state=%s, file=%s%s", state, p_menu->psz_path, file ); } p_current->p_current_state = p_current->p_states; } /* Find the last button and store its pointer. * The OSD menu behaves like a roundrobin list. */ p_current = p_menu->p_button; while( p_current && p_current->p_next ) { osd_button_t *p_temp = NULL; p_temp = p_current->p_next; p_current = p_temp; } p_menu->p_last_button = p_current; fclose( fd ); return VLC_SUCCESS; error: msg_Err( p_this, "parsing file failed (returned %d)", result ); if( p_menu ) osd_MenuFree( p_menu ); fclose( fd ); return VLC_EGENERIC; }
/**************************************************************************** * OpenVCDImage: try to open a vcd image from a .cue file ****************************************************************************/ static int OpenVCDImage( vlc_object_t * p_this, const char *psz_dev, vcddev_t *p_vcddev ) { int i_ret = -1; char *p_pos; char *psz_vcdfile = NULL; char *psz_cuefile = NULL; FILE *cuefile = NULL; int *p_sectors = NULL; char line[1024]; bool b_found = false; /* Check if we are dealing with a .cue file */ p_pos = strrchr( psz_dev, '.' ); if( p_pos && !strcmp( p_pos, ".cue" ) ) { /* psz_dev must be the cue file. Let's assume there's a .bin * file with the same filename */ if( asprintf( &psz_vcdfile, "%.*s.bin", (int)(p_pos - psz_dev), psz_dev ) < 0 ) psz_vcdfile = NULL; psz_cuefile = strdup( psz_dev ); } else if( p_pos ) { /* psz_dev must be the actual vcd file. Let's assume there's a .cue * file with the same filename */ if( asprintf( &psz_cuefile, "%.*s.cue", (int)(p_pos - psz_dev), psz_dev ) < 0 ) psz_cuefile = NULL; psz_vcdfile = strdup( psz_dev ); } else { if( asprintf( &psz_cuefile, "%s.cue", psz_dev ) == -1 ) psz_cuefile = NULL; /* If we need to look up the .cue file, then we don't have to look * for the vcd */ psz_vcdfile = strdup( psz_dev ); } if( psz_cuefile == NULL || psz_vcdfile == NULL ) goto error; /* Open the cue file and try to parse it */ msg_Dbg( p_this,"trying .cue file: %s", psz_cuefile ); cuefile = vlc_fopen( psz_cuefile, "rt" ); if( cuefile == NULL ) { msg_Dbg( p_this, "could not find .cue file" ); goto error; } msg_Dbg( p_this,"guessing vcd image file: %s", psz_vcdfile ); p_vcddev->i_vcdimage_handle = vlc_open( psz_vcdfile, O_RDONLY | O_NONBLOCK | O_BINARY ); while( fgets( line, 1024, cuefile ) && !b_found ) { /* We have a cue file, but no valid vcd file yet */ char filename[1024]; char type[16]; int i_temp = sscanf( line, "FILE \"%1023[^\"]\" %15s", filename, type ); switch( i_temp ) { case 2: msg_Dbg( p_this, "the cue file says the data file is %s", type ); if( strcasecmp( type, "BINARY" ) ) goto error; /* Error if not binary, otherwise treat as case 1 */ case 1: if( p_vcddev->i_vcdimage_handle == -1 ) { msg_Dbg( p_this, "we could not find the data file, but we found a new path" ); free( psz_vcdfile); if( *filename != '/' && ((p_pos = strrchr( psz_cuefile, '/' )) || (p_pos = strrchr( psz_cuefile, '\\' ) )) ) { psz_vcdfile = malloc( strlen(filename) + (p_pos - psz_cuefile + 1) + 1 ); strncpy( psz_vcdfile, psz_cuefile, (p_pos - psz_cuefile + 1) ); strcpy( psz_vcdfile + (p_pos - psz_cuefile + 1), filename ); } else psz_vcdfile = strdup( filename ); msg_Dbg( p_this,"using vcd image file: %s", psz_vcdfile ); p_vcddev->i_vcdimage_handle = vlc_open( psz_vcdfile, O_RDONLY | O_NONBLOCK | O_BINARY ); } b_found = true; default: break; } } if( p_vcddev->i_vcdimage_handle == -1) goto error; /* Try to parse the i_tracks and p_sectors info so we can just forget * about the cuefile */ size_t i_tracks = 0; while( fgets( line, 1024, cuefile ) && i_tracks < INT_MAX-1 ) { /* look for a TRACK line */ char psz_dummy[10]; if( !sscanf( line, "%9s", psz_dummy ) || strcmp(psz_dummy, "TRACK") ) continue; /* look for an INDEX line */ while( fgets( line, 1024, cuefile ) ) { int i_num, i_min, i_sec, i_frame; if( (sscanf( line, "%*9s %2u %2u:%2u:%2u", &i_num, &i_min, &i_sec, &i_frame ) != 4) || (i_num != 1) ) continue; int *buf = realloc (p_sectors, (i_tracks + 1) * sizeof (*buf)); if (buf == NULL) goto error; p_sectors = buf; p_sectors[i_tracks] = MSF_TO_LBA(i_min, i_sec, i_frame); msg_Dbg( p_this, "vcd track %i begins at sector:%i", (int)i_tracks, (int)p_sectors[i_tracks] ); i_tracks++; break; } } /* fill in the last entry */ int *buf = realloc (p_sectors, (i_tracks + 1) * sizeof (*buf)); if (buf == NULL) goto error; p_sectors = buf; p_sectors[i_tracks] = lseek(p_vcddev->i_vcdimage_handle, 0, SEEK_END) / VCD_SECTOR_SIZE; msg_Dbg( p_this, "vcd track %i, begins at sector:%i", (int)i_tracks, (int)p_sectors[i_tracks] ); p_vcddev->i_tracks = ++i_tracks; p_vcddev->p_sectors = p_sectors; p_sectors = NULL; i_ret = 0; error: if( cuefile ) fclose( cuefile ); free( p_sectors ); free( psz_cuefile ); free( psz_vcdfile ); return i_ret; }
static int WriteCatalog( addons_storage_t *p_storage, addon_entry_t **pp_entries, int i_entries ) { addon_entry_t *p_entry; char *psz_file; char *psz_file_tmp; char *psz_tempstring; char *psz_userdir = config_GetUserDir( VLC_DATA_DIR ); if ( !psz_userdir ) return VLC_ENOMEM; if ( asprintf( &psz_file, "%s%s", psz_userdir, ADDONS_CATALOG ) < 1 ) { free( psz_userdir ); return VLC_ENOMEM; } free( psz_userdir ); if ( asprintf( &psz_file_tmp, "%s.tmp%"PRIu32, psz_file, (uint32_t)getpid() ) < 1 ) { free( psz_file ); return VLC_ENOMEM; } char *psz_path = strdup( psz_file ); if ( !psz_path ) { free( psz_file ); free( psz_file_tmp ); return VLC_ENOMEM; } char *psz_buf = strrchr( psz_path, DIR_SEP_CHAR ); if( psz_buf ) { *++psz_buf = '\0'; /* ensure directory exists */ if( !EMPTY_STR( psz_path ) ) recursive_mkdir( VLC_OBJECT(p_storage), psz_path ); } free( psz_path ); FILE *p_catalog = vlc_fopen( psz_file_tmp, "wt" ); if ( !p_catalog ) { free( psz_file ); free( psz_file_tmp ); return VLC_EGENERIC; } /* write XML header */ fprintf( p_catalog, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); fprintf( p_catalog, "<videolan xmlns=\"http://videolan.org/ns/vlc/addons/1.0\">\n" ); fprintf( p_catalog, "\t<addons>\n" ); for ( int i=0; i<i_entries; i++ ) { p_entry = pp_entries[i]; vlc_mutex_lock( &p_entry->lock ); psz_tempstring = NULL; if ( ( p_entry->e_state != ADDON_INSTALLED ) || !( p_entry->e_flags & ADDON_MANAGEABLE ) ) { vlc_mutex_unlock( &p_entry->lock ); continue; } if ( p_entry->psz_source_module ) psz_tempstring = vlc_xml_encode( p_entry->psz_source_module ); char *psz_uuid = addons_uuid_to_psz( ( const addon_uuid_t * ) & p_entry->uuid ); fprintf( p_catalog, "\t\t<addon source=\"%s\" type=\"%s\" id=\"%s\" " "downloads=\"%ld\" score=\"%d\"", ( psz_tempstring ) ? psz_tempstring : "", getTypePsz( p_entry->e_type ), psz_uuid, p_entry->i_downloads, p_entry->i_score ); free( psz_uuid ); free( psz_tempstring ); WRITE_WITH_ENTITIES( " version=\"%s\"", p_entry->psz_version ) fprintf( p_catalog, ">\n" ); WRITE_WITH_ENTITIES( "\t\t\t<name>%s</name>\n", p_entry->psz_name ) WRITE_WITH_ENTITIES( "\t\t\t<summary>%s</summary>\n", p_entry->psz_summary ) if ( p_entry->psz_description ) { psz_tempstring = p_entry->psz_description; /* FIXME: do real escaping */ while( ( psz_tempstring = strstr( psz_tempstring, "]]>" ) ) ) *psz_tempstring = ' '; fprintf( p_catalog, "\t\t\t<description><![CDATA[%s]]></description>\n", p_entry->psz_description ); } WRITE_WITH_ENTITIES( "\t\t\t<image>%s</image>\n", p_entry->psz_image_data ) WRITE_WITH_ENTITIES( "\t\t\t<archive>%s</archive>\n", p_entry->psz_archive_uri ) fprintf( p_catalog, "\t\t\t<authorship>\n" ); WRITE_WITH_ENTITIES( "\t\t\t\t<creator>%s</creator>\n", p_entry->psz_author ) WRITE_WITH_ENTITIES( "\t\t\t\t<sourceurl>%s</sourceurl>\n", p_entry->psz_source_uri ) fprintf( p_catalog, "\t\t\t</authorship>\n" ); FOREACH_ARRAY( addon_file_t *p_file, p_entry->files ) psz_tempstring = vlc_xml_encode( p_file->psz_filename ); fprintf( p_catalog, "\t\t\t<resource type=\"%s\">%s</resource>\n", getTypePsz( p_file->e_filetype ), psz_tempstring ); free( psz_tempstring ); FOREACH_END(); fprintf( p_catalog, "\t\t</addon>\n" ); vlc_mutex_unlock( &p_entry->lock ); } fprintf( p_catalog, "\t</addons>\n" ); fprintf( p_catalog, "</videolan>\n" ); fclose( p_catalog ); int i_ret = vlc_rename( psz_file_tmp, psz_file ); free( psz_file ); free( psz_file_tmp ); if( i_ret == -1 ) { msg_Err( p_storage, "could not rename temp catalog: %s", vlc_strerror_c(errno) ); return VLC_EGENERIC; } return VLC_SUCCESS; }
/***************************************************************************** * Open: initialize and create stuff *****************************************************************************/ static int Open( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_sys_t *p_sys; char *psz_mode; CONSOLE_INTRO_MSG; msg_Info( p_intf, "using logger." ); /* Allocate instance and initialize some members */ p_sys = p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) ); if( p_sys == NULL ) return VLC_ENOMEM; p_sys->msg.p_intf = p_intf; p_sys->msg.i_mode = MODE_TEXT; psz_mode = var_InheritString( p_intf, "logmode" ); if( psz_mode ) { if( !strcmp( psz_mode, "text" ) ) ; else if( !strcmp( psz_mode, "html" ) ) { p_sys->msg.i_mode = MODE_HTML; } #ifdef HAVE_SYSLOG_H else if( !strcmp( psz_mode, "syslog" ) ) { p_sys->msg.i_mode = MODE_SYSLOG; } #endif else { msg_Warn( p_intf, "invalid log mode `%s', using `text'", psz_mode ); p_sys->msg.i_mode = MODE_TEXT; } free( psz_mode ); } else { msg_Warn( p_intf, "no log mode specified, using `text'" ); } if( p_sys->msg.i_mode != MODE_SYSLOG ) { char *psz_file = var_InheritString( p_intf, "logfile" ); if( !psz_file ) { #ifdef __APPLE__ char *home = config_GetUserDir(VLC_DOCUMENTS_DIR); if( home == NULL || asprintf( &psz_file, "%s/"LOG_DIR"/%s", home, (p_sys->msg.i_mode == MODE_HTML) ? LOG_FILE_HTML : LOG_FILE_TEXT ) == -1 ) psz_file = NULL; free(home); #else switch( p_sys->msg.i_mode ) { case MODE_HTML: psz_file = strdup( LOG_FILE_HTML ); break; case MODE_TEXT: default: psz_file = strdup( LOG_FILE_TEXT ); break; } #endif msg_Warn( p_intf, "no log filename provided, using `%s'", psz_file ); } /* Open the log file and remove any buffering for the stream */ msg_Dbg( p_intf, "opening logfile `%s'", psz_file ); p_sys->msg.p_file = vlc_fopen( psz_file, "at" ); if( p_sys->msg.p_file == NULL ) { msg_Err( p_intf, "error opening logfile `%s'", psz_file ); free( p_sys ); free( psz_file ); return -1; } setvbuf( p_sys->msg.p_file, NULL, _IONBF, 0 ); free( psz_file ); switch( p_sys->msg.i_mode ) { case MODE_HTML: fputs( HTML_HEADER, p_sys->msg.p_file ); break; case MODE_TEXT: default: fputs( TEXT_HEADER, p_sys->msg.p_file ); break; } } else { p_sys->msg.p_file = NULL; #ifdef HAVE_SYSLOG_H int i_facility; char *psz_facility = var_InheritString( p_intf, "syslog-facility" ); if( psz_facility ) { bool b_valid = 0; for( size_t i = 0; i < fac_entries; ++i ) { if( !strcmp( psz_facility, fac_name[i] ) ) { i_facility = fac_number[i]; b_valid = 1; break; } } if( !b_valid ) { msg_Warn( p_intf, "invalid syslog facility `%s', using `%s'", psz_facility, fac_name[0] ); i_facility = fac_number[0]; } free( psz_facility ); } else { msg_Warn( p_intf, "no syslog facility specified, using `%s'", fac_name[0] ); i_facility = fac_number[0]; } openlog( "vlc", LOG_PID|LOG_NDELAY, i_facility ); #endif } p_sys->p_sub = msg_Subscribe( p_intf->p_libvlc, Overflow, &p_sys->msg ); return 0; }
int vout_snapshot_SaveImage(char **name, int *sequential, const block_t *image, vout_thread_t *p_vout, const vout_snapshot_save_cfg_t *cfg) { /* */ char *filename; DIR *pathdir = vlc_opendir(cfg->path); input_thread_t *input = (input_thread_t*)p_vout->p->input; if (pathdir != NULL) { /* The use specified a directory path */ closedir(pathdir); /* */ char *prefix = NULL; if (cfg->prefix_fmt) prefix = str_format(input, cfg->prefix_fmt); if (prefix) filename_sanitize(prefix); else { prefix = strdup("vlcsnap-"); if (!prefix) goto error; } if (cfg->is_sequential) { for (int num = cfg->sequence; ; num++) { struct stat st; if (asprintf(&filename, "%s" DIR_SEP "%s%05d.%s", cfg->path, prefix, num, cfg->format) < 0) { free(prefix); goto error; } if (vlc_stat(filename, &st)) { *sequential = num; break; } free(filename); } } else { struct timespec ts; struct tm curtime; char buffer[128]; timespec_get(&ts, TIME_UTC); if (localtime_r(&ts.tv_sec, &curtime) == NULL) gmtime_r(&ts.tv_sec, &curtime); if (strftime(buffer, sizeof(buffer), "%Y-%m-%d-%Hh%Mm%Ss", &curtime) == 0) strcpy(buffer, "error"); if (asprintf(&filename, "%s" DIR_SEP "%s%s%03lu.%s", cfg->path, prefix, buffer, ts.tv_nsec / 1000000, cfg->format) < 0) filename = NULL; } free(prefix); } else { /* The user specified a full path name (including file name) */ filename = str_format(input, cfg->path); path_sanitize(filename); } if (!filename) goto error; /* Save the snapshot */ FILE *file = vlc_fopen(filename, "wb"); if (!file) { msg_Err(p_vout, "Failed to open '%s'", filename); free(filename); goto error; } if (fwrite(image->p_buffer, image->i_buffer, 1, file) != 1) { msg_Err(p_vout, "Failed to write to '%s'", filename); fclose(file); free(filename); goto error; } fclose(file); /* */ if (name) *name = filename; else free(filename); return VLC_SUCCESS; error: msg_Err(p_vout, "could not save snapshot"); return VLC_EGENERIC; }
/***************************************************************************** * Open: initialize and create stuff *****************************************************************************/ static int Open( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_sys_t *p_sys; CONSOLE_INTRO_MSG; msg_Info( p_intf, "using logger." ); /* Allocate instance and initialize some members */ p_sys = p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) ); if( p_sys == NULL ) return VLC_ENOMEM; p_sys->p_file = NULL; vlc_log_cb cb = TextPrint; const char *filename = LOG_FILE_TEXT, *header = TEXT_HEADER; p_sys->footer = TEXT_FOOTER; char *mode = var_InheritString( p_intf, "logmode" ); if( mode != NULL ) { if( !strcmp( mode, "html" ) ) { p_sys->footer = HTML_FOOTER; header = HTML_HEADER; cb = HtmlPrint; } #ifdef HAVE_SYSLOG_H else if( !strcmp( mode, "syslog" ) ) cb = SyslogPrint; #endif #ifdef __ANDROID__ else if( !strcmp( mode, "android" ) ) cb = AndroidPrint; #endif else if( strcmp( mode, "text" ) ) msg_Warn( p_intf, "invalid log mode `%s', using `text'", mode ); free( mode ); } #ifdef HAVE_SYSLOG_H if( cb == SyslogPrint ) { int i_facility; char *psz_facility = var_InheritString( p_intf, "syslog-facility" ); if( psz_facility ) { bool b_valid = 0; for( size_t i = 0; i < fac_entries; ++i ) { if( !strcmp( psz_facility, fac_name[i] ) ) { i_facility = fac_number[i]; b_valid = 1; break; } } if( !b_valid ) { msg_Warn( p_intf, "invalid syslog facility `%s', using `%s'", psz_facility, fac_name[0] ); i_facility = fac_number[0]; } free( psz_facility ); } else { msg_Warn( p_intf, "no syslog facility specified, using `%s'", fac_name[0] ); i_facility = fac_number[0]; } char *psz_syslog_ident = var_InheritString( p_intf, "syslog-ident" ); if (unlikely(psz_syslog_ident == NULL)) { free( p_sys ); return VLC_ENOMEM; } p_sys->ident = psz_syslog_ident; openlog( p_sys->ident, LOG_PID|LOG_NDELAY, i_facility ); p_sys->p_file = NULL; } else #endif #ifdef __ANDROID__ if( cb == AndroidPrint ) { /* nothing to do */ } else #endif { char *psz_file = var_InheritString( p_intf, "logfile" ); if( !psz_file ) { #ifdef __APPLE__ # define LOG_DIR "Library/Logs" char *home = config_GetUserDir(VLC_HOME_DIR); if( home == NULL || asprintf( &psz_file, "%s/"LOG_DIR"/%s", home, filename ) == -1 ) psz_file = NULL; free(home); filename = psz_file; #endif msg_Warn( p_intf, "no log filename provided, using `%s'", filename ); } else filename = psz_file; /* Open the log file and remove any buffering for the stream */ msg_Dbg( p_intf, "opening logfile `%s'", filename ); p_sys->p_file = vlc_fopen( filename, "at" ); if( p_sys->p_file == NULL ) { msg_Err( p_intf, "error opening logfile `%s': %m", filename ); free( psz_file ); free( p_sys ); return VLC_EGENERIC; } free( psz_file ); setvbuf( p_sys->p_file, NULL, _IONBF, 0 ); fputs( header, p_sys->p_file ); } vlc_LogSet( p_intf->p_libvlc, cb, p_intf ); return VLC_SUCCESS; }
static int Retrieve( addons_finder_t *p_finder, addon_entry_t *p_entry ) { if ( !p_entry->psz_archive_uri ) return VLC_EGENERIC; /* get archive and parse manifest */ stream_t *p_stream; if ( p_entry->psz_archive_uri[0] == '/' ) { /* Relative path */ char *psz_uri; if ( ! asprintf( &psz_uri, ADDONS_REPO_SCHEMEHOST"%s", p_entry->psz_archive_uri ) ) return VLC_ENOMEM; p_stream = stream_UrlNew( p_finder, psz_uri ); free( psz_uri ); } else { p_stream = stream_UrlNew( p_finder, p_entry->psz_archive_uri ); } msg_Dbg( p_finder, "downloading archive %s", p_entry->psz_archive_uri ); if ( !p_stream ) return VLC_EGENERIC; /* In case of pf_ reuse */ if ( p_finder->p_sys->psz_tempfile ) { vlc_unlink( p_finder->p_sys->psz_tempfile ); FREENULL( p_finder->p_sys->psz_tempfile ); } p_finder->p_sys->psz_tempfile = tempnam( NULL, "vlp" ); if ( !p_finder->p_sys->psz_tempfile ) { msg_Err( p_finder, "Can't create temp storage file" ); stream_Delete( p_stream ); return VLC_EGENERIC; } FILE *p_destfile = vlc_fopen( p_finder->p_sys->psz_tempfile, "w" ); if( !p_destfile ) { msg_Err( p_finder, "Failed to open addon temp storage file" ); FREENULL(p_finder->p_sys->psz_tempfile); stream_Delete( p_stream ); return VLC_EGENERIC; } char buffer[1<<10]; int i_read = 0; while ( ( i_read = stream_Read( p_stream, &buffer, 1<<10 ) ) ) { if ( fwrite( &buffer, i_read, 1, p_destfile ) < 1 ) { msg_Err( p_finder, "Failed to write to Addon file" ); fclose( p_destfile ); stream_Delete( p_stream ); return VLC_EGENERIC; } } fclose( p_destfile ); stream_Delete( p_stream ); msg_Dbg( p_finder, "Reading manifest from %s", p_finder->p_sys->psz_tempfile ); char *psz_manifest; if ( asprintf( &psz_manifest, "unzip://%s!/manifest.xml", p_finder->p_sys->psz_tempfile ) < 1 ) return VLC_ENOMEM; p_stream = stream_UrlNew( p_finder, psz_manifest ); free( psz_manifest ); int i_ret = ( ParseManifest( p_finder, p_entry, p_finder->p_sys->psz_tempfile, p_stream ) > 0 ) ? VLC_SUCCESS : VLC_EGENERIC; stream_Delete( p_stream ); return i_ret; }
int playlist_SaveArt( vlc_object_t *obj, input_item_t *p_item, const void *data, size_t length, const char *psz_type ) { char *psz_filename = ArtCacheName( p_item, psz_type ); if( !psz_filename ) return VLC_EGENERIC; char *psz_uri = vlc_path2uri( psz_filename, "file" ); if( !psz_uri ) { free( psz_filename ); return VLC_EGENERIC; } /* Check if we already dumped it */ struct stat s; if( !vlc_stat( psz_filename, &s ) ) { input_item_SetArtURL( p_item, psz_uri ); free( psz_filename ); free( psz_uri ); return VLC_SUCCESS; } /* Dump it otherwise */ FILE *f = vlc_fopen( psz_filename, "wb" ); if( f ) { if( fwrite( data, 1, length, f ) != length ) { msg_Err( obj, "%s: %s", psz_filename, vlc_strerror_c(errno) ); } else { msg_Dbg( obj, "album art saved to %s", psz_filename ); input_item_SetArtURL( p_item, psz_uri ); } fclose( f ); } free( psz_uri ); /* save uid info */ char *uid = input_item_GetInfo( p_item, "uid", "md5" ); if ( ! *uid ) { free( uid ); goto end; } char *psz_byuiddir = GetDirByItemUIDs( uid ); char *psz_byuidfile = GetFileByItemUID( psz_byuiddir, "arturl" ); ArtCacheCreateDir( psz_byuiddir ); free( psz_byuiddir ); if ( psz_byuidfile ) { f = vlc_fopen( psz_byuidfile, "wb" ); if ( f ) { if( fputs( "file://", f ) < 0 || fputs( psz_filename, f ) < 0 ) msg_Err( obj, "Error writing %s: %s", psz_byuidfile, vlc_strerror_c(errno) ); fclose( f ); } free( psz_byuidfile ); } free( uid ); /* !save uid info */ end: free( psz_filename ); return VLC_SUCCESS; }
static FILE *config_OpenConfigFile( vlc_object_t *p_obj ) { char *psz_filename = config_GetConfigFile( p_obj ); if( psz_filename == NULL ) return NULL; msg_Dbg( p_obj, "opening config file (%s)", psz_filename ); FILE *p_stream = vlc_fopen( psz_filename, "rt" ); if( p_stream == NULL && errno != ENOENT ) { msg_Err( p_obj, "cannot open config file (%s): %m", psz_filename ); } #if !( defined(WIN32) || defined(__APPLE__) ) else if( p_stream == NULL && errno == ENOENT ) { /* This is the fallback for pre XDG Base Directory * Specification configs */ char *home = config_GetUserDir(VLC_HOME_DIR); char *psz_old; if( home != NULL && asprintf( &psz_old, "%s/.vlc/" CONFIG_FILE, home ) != -1 ) { p_stream = vlc_fopen( psz_old, "rt" ); if( p_stream ) { /* Old config file found. We want to write it at the * new location now. */ msg_Info( p_obj->p_libvlc, "Found old config file at %s. " "VLC will now use %s.", psz_old, psz_filename ); char *psz_readme; if( asprintf(&psz_readme,"%s/.vlc/README", home ) != -1 ) { FILE *p_readme = vlc_fopen( psz_readme, "wt" ); if( p_readme ) { fprintf( p_readme, "The VLC media player " "configuration folder has moved to comply\n" "with the XDG Base Directory Specification " "version 0.6. Your\nconfiguration has been " "copied to the new location:\n%s\nYou can " "delete this directory and all its contents.", psz_filename); fclose( p_readme ); } free( psz_readme ); } /* Remove the old configuration file so that --reset-config * can work properly. Fortunately, Linux allows removing * open files - with most filesystems. */ unlink( psz_old ); } free( psz_old ); } free( home ); } #endif free( psz_filename ); return p_stream; }
/** * Initialize a libvlc instance * This function initializes a previously allocated libvlc instance: * - CPU detection * - gettext initialization * - message queue, module bank and playlist initialization * - configuration and commandline parsing */ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, const char *ppsz_argv[] ) { libvlc_priv_t *priv = libvlc_priv (p_libvlc); char * psz_modules = NULL; char * psz_parser = NULL; char * psz_control = NULL; char *psz_val; /* System specific initialization code */ system_Init(); vlc_LogPreinit(p_libvlc); /* Initialize the module bank and load the configuration of the * core module. We need to do this at this stage to be able to display * a short help if required by the user. (short help == core module * options) */ module_InitBank (); /* Get command line options that affect module loading. */ if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) ) { module_EndBank (false); return VLC_EGENERIC; } vlc_threads_setup (p_libvlc); /* Load the builtins and plugins into the module_bank. * We have to do it before config_Load*() because this also gets the * list of configuration options exported by each module and loads their * default values. */ size_t module_count = module_LoadPlugins (p_libvlc); /* * Override default configuration with config file settings */ if( !var_InheritBool( p_libvlc, "ignore-config" ) ) { if( var_InheritBool( p_libvlc, "reset-config" ) ) config_SaveConfigFile( p_libvlc ); /* Save default config */ else config_LoadConfigFile( p_libvlc ); } /* * Override configuration with command line settings */ int vlc_optind; if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) ) { vlc_LogDeinit (p_libvlc); module_EndBank (true); return VLC_EGENERIC; } vlc_LogInit(p_libvlc); /* * Support for gettext */ #if defined( ENABLE_NLS ) \ && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) vlc_bindtextdomain (PACKAGE_NAME); #endif /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */ msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") ); if (config_PrintHelp (VLC_OBJECT(p_libvlc))) { module_EndBank (true); exit(0); } if( module_count <= 1 ) { msg_Err( p_libvlc, "No plugins found! Check your VLC installation."); vlc_LogDeinit (p_libvlc); module_EndBank (true); return VLC_ENOMOD; } #ifdef HAVE_DAEMON /* Check for daemon mode */ if( var_InheritBool( p_libvlc, "daemon" ) ) { if( daemon( 1, 0) != 0 ) { msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" ); vlc_LogDeinit (p_libvlc); module_EndBank (true); return VLC_ENOMEM; } /* lets check if we need to write the pidfile */ char *pidfile = var_InheritString( p_libvlc, "pidfile" ); if( pidfile != NULL ) { FILE *stream = vlc_fopen( pidfile, "w" ); if( stream != NULL ) { fprintf( stream, "%d", (int)getpid() ); fclose( stream ); msg_Dbg( p_libvlc, "written PID file %s", pidfile ); } else msg_Err( p_libvlc, "cannot write PID file %s: %s", pidfile, vlc_strerror_c(errno) ); free( pidfile ); } } else { var_Create( p_libvlc, "pidfile", VLC_VAR_STRING ); var_SetString( p_libvlc, "pidfile", "" ); } #endif /* FIXME: could be replaced by using Unix sockets */ #ifdef HAVE_DBUS #define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append" #define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc" #define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2" #define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList" if( var_InheritBool( p_libvlc, "one-instance" ) || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" ) && var_InheritBool( p_libvlc, "started-from-file" ) ) ) { for( int i = vlc_optind; i < i_argc; i++ ) if( ppsz_argv[i][0] == ':' ) { msg_Err( p_libvlc, "item option %s incompatible with single instance", ppsz_argv[i] ); goto dbus_out; } /* Initialise D-Bus interface, check for other instances */ dbus_threads_init_default(); DBusError err; dbus_error_init( &err ); /* connect to the session bus */ DBusConnection *conn = dbus_bus_get( DBUS_BUS_SESSION, &err ); if( conn == NULL ) { msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s", err.message ); dbus_error_free( &err ); goto dbus_out; } /* check if VLC is available on the bus * if not: D-Bus control is not enabled on the other * instance and we can't pass MRLs to it */ /* FIXME: This check is totally brain-dead and buggy. */ if( !dbus_bus_name_has_owner( conn, MPRIS_BUS_NAME, &err ) ) { dbus_connection_unref( conn ); if( dbus_error_is_set( &err ) ) { msg_Err( p_libvlc, "D-Bus error: %s", err.message ); } else msg_Dbg( p_libvlc, "No media player running. Continuing normally." ); dbus_error_free( &err ); goto dbus_out; } const dbus_bool_t play = !var_InheritBool( p_libvlc, "playlist-enqueue" ); msg_Warn( p_libvlc, "media player running. Exiting..."); for( int i = vlc_optind; i < i_argc; i++ ) { DBusMessage *msg = dbus_message_new_method_call( MPRIS_BUS_NAME, MPRIS_OBJECT_PATH, MPRIS_TRACKLIST_INTERFACE, "AddTrack" ); if( unlikely(msg == NULL) ) continue; /* We need to resolve relative paths in this instance */ char *mrl; if( strstr( ppsz_argv[i], "://" ) ) mrl = strdup( ppsz_argv[i] ); else mrl = vlc_path2uri( ppsz_argv[i], NULL ); if( mrl == NULL ) { dbus_message_unref( msg ); continue; } const char *after_track = MPRIS_APPEND; /* append MRLs */ if( !dbus_message_append_args( msg, DBUS_TYPE_STRING, &mrl, DBUS_TYPE_OBJECT_PATH, &after_track, DBUS_TYPE_BOOLEAN, &play, DBUS_TYPE_INVALID ) ) { dbus_message_unref( msg ); msg = NULL; free( mrl ); continue; } msg_Dbg( p_libvlc, "Adds %s to the running media player", mrl ); free( mrl ); /* send message and get a handle for a reply */ DBusMessage *reply = dbus_connection_send_with_reply_and_block( conn, msg, -1, &err ); dbus_message_unref( msg ); if( reply == NULL ) { msg_Err( p_libvlc, "D-Bus error: %s", err.message ); continue; } dbus_message_unref( reply ); } /* we unreference the connection when we've finished with it */ dbus_connection_unref( conn ); exit( 0 ); } #undef MPRIS_APPEND #undef MPRIS_BUS_NAME #undef MPRIS_OBJECT_PATH #undef MPRIS_TRACKLIST_INTERFACE dbus_out: #endif // HAVE_DBUS vlc_CPU_dump( VLC_OBJECT(p_libvlc) ); priv->b_stats = var_InheritBool( p_libvlc, "stats" ); /* * Initialize hotkey handling */ priv->actions = vlc_InitActions( p_libvlc ); /* * Meta data handling */ priv->parser = playlist_preparser_New(VLC_OBJECT(p_libvlc)); /* Create a variable for showing the fullscreen interface */ var_Create( p_libvlc, "intf-toggle-fscontrol", VLC_VAR_BOOL ); var_SetBool( p_libvlc, "intf-toggle-fscontrol", true ); /* Create a variable for the Boss Key */ var_Create( p_libvlc, "intf-boss", VLC_VAR_VOID ); /* Create a variable for showing the main interface */ var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL ); /* Create a variable for showing the right click menu */ var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL ); /* variables for signalling creation of new files */ var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING ); var_Create( p_libvlc, "record-file", VLC_VAR_STRING ); /* some default internal settings */ var_Create( p_libvlc, "window", VLC_VAR_STRING ); /* NOTE: Because the playlist and interfaces start before this function * returns control to the application (DESIGN BUG!), all these variables * must be created (in place of libvlc_new()) and set to VLC defaults * (in place of VLC main()) *here*. */ var_Create( p_libvlc, "user-agent", VLC_VAR_STRING ); var_SetString( p_libvlc, "user-agent", "VLC media player (LibVLC "VERSION")" ); var_Create( p_libvlc, "http-user-agent", VLC_VAR_STRING ); var_SetString( p_libvlc, "http-user-agent", "VLC/"PACKAGE_VERSION" LibVLC/"PACKAGE_VERSION ); var_Create( p_libvlc, "app-icon-name", VLC_VAR_STRING ); var_SetString( p_libvlc, "app-icon-name", PACKAGE_NAME ); var_Create( p_libvlc, "app-id", VLC_VAR_STRING ); var_SetString( p_libvlc, "app-id", "org.VideoLAN.VLC" ); var_Create( p_libvlc, "app-version", VLC_VAR_STRING ); var_SetString( p_libvlc, "app-version", PACKAGE_VERSION ); /* System specific configuration */ system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); #ifdef ENABLE_VLM /* Initialize VLM if vlm-conf is specified */ psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" ); if( psz_parser ) { priv->p_vlm = vlm_New( p_libvlc ); if( !priv->p_vlm ) msg_Err( p_libvlc, "VLM initialization failed" ); } free( psz_parser ); #endif /* * Load background interfaces */ psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" ); psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" ); if( psz_modules && psz_control ) { char* psz_tmp; if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 ) { free( psz_modules ); psz_modules = psz_tmp; } } else if( psz_control ) { free( psz_modules ); psz_modules = strdup( psz_control ); } psz_parser = psz_modules; while ( psz_parser && *psz_parser ) { char *psz_module, *psz_temp; psz_module = psz_parser; psz_parser = strchr( psz_module, ':' ); if ( psz_parser ) { *psz_parser = '\0'; psz_parser++; } if( asprintf( &psz_temp, "%s,none", psz_module ) != -1) { libvlc_InternalAddIntf( p_libvlc, psz_temp ); free( psz_temp ); } } free( psz_modules ); free( psz_control ); if( var_InheritBool( p_libvlc, "network-synchronisation") ) libvlc_InternalAddIntf( p_libvlc, "netsync,none" ); #ifdef __APPLE__ var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS ); #endif /* * Get input filenames given as commandline arguments. * We assume that the remaining parameters are filenames * and their input options. */ GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); /* * Get --open argument */ psz_val = var_InheritString( p_libvlc, "open" ); if ( psz_val != NULL ) { intf_InsertItem( p_libvlc, psz_val, 0, NULL, 0 ); free( psz_val ); } return VLC_SUCCESS; }