static int Open(vlc_object_t *object) { access_t *access = (access_t*)object; if (!strchr(access->psz_location, '|')) return VLC_EGENERIC; char *base = strdup(access->psz_location); if (!base) return VLC_EGENERIC; char *name = strchr(base, '|'); *name++ = '\0'; decode_URI(base); stream_t *s = stream_UrlNew(access, base); if (!s) goto error; int count; rar_file_t **files; if (RarProbe(s) || RarParse(s, &count, &files) || count <= 0) goto error; rar_file_t *file = NULL; for (int i = 0; i < count; i++) { if (!file && !strcmp(files[i]->name, name)) file = files[i]; else RarFileDelete(files[i]); } free(files); if (!file) goto error; access_sys_t *sys = access->p_sys = malloc(sizeof(*sys)); sys->s = s; sys->file = file; access->pf_read = Read; access->pf_block = NULL; access->pf_control = Control; access->pf_seek = Seek; access_InitFields(access); access->info.i_size = file->size; rar_file_chunk_t dummy = { .mrl = base, }; sys->chunk = &dummy; Seek(access, 0); free(base); return VLC_SUCCESS; error: if (s) stream_Delete(s); free(base); return VLC_EGENERIC; }
/** * Decodes an encoded URI component. See also decode_URI(). * \return decoded string allocated on the heap, or NULL on error. */ char *decode_URI_duplicate (const char *str) { char *buf = strdup (str); if (decode_URI (buf) == NULL) { free (buf); buf = NULL; } return buf; }
/***************************************************************************** * String transformations *****************************************************************************/ static int vlclua_decode_uri( lua_State *L ) { int i_top = lua_gettop( L ); int i; for( i = 1; i <= i_top; i++ ) { const char *psz_cstring = luaL_checkstring( L, 1 ); char *psz_string = strdup( psz_cstring ); lua_remove( L, 1 ); /* remove elements to prevent being limited by * the stack's size (this function will work with * up to (stack size - 1) arguments */ decode_URI( psz_string ); lua_pushstring( L, psz_string ); free( psz_string ); } return i_top; }
void InputManager::UpdateName() { assert( p_input ); /* Update text, name and nowplaying */ QString name; /* Try to get the nowplaying */ char *format = var_InheritString( p_intf, "input-title-format" ); char *formatted = NULL; if (format != NULL) { formatted = str_format_meta( p_input, format ); free( format ); if( formatted != NULL ) { name = qfu(formatted); free( formatted ); } } /* If we have Nothing */ if( name.simplified().isEmpty() ) { char *uri = input_item_GetURI( input_GetItem( p_input ) ); char *file = uri ? strrchr( uri, '/' ) : NULL; if( file != NULL ) { decode_URI( ++file ); name = qfu(file); } else name = qfu(uri); free( uri ); } name = name.trimmed(); if( oldName != name ) { emit nameChanged( name ); oldName = name; } }
/** * Decode encoded URI component. See also decode_URI(). * \return decoded duplicated string */ char *decode_URI_duplicate( const char *psz ) { char *psz_dup = strdup( psz ); decode_URI( psz_dup ); return psz_dup; }
void input_item_SetURI( input_item_t *p_i, const char *psz_uri ) { assert( psz_uri ); #ifndef NDEBUG if( !strstr( psz_uri, "://" ) || strchr( psz_uri, ' ' ) || strchr( psz_uri, '"' ) ) fprintf( stderr, "Warning: %s(\"%s\"): file path instead of URL.\n", __func__, psz_uri ); #endif vlc_mutex_lock( &p_i->lock ); free( p_i->psz_uri ); p_i->psz_uri = strdup( psz_uri ); p_i->i_type = GuessType( p_i ); if( p_i->psz_name ) ; else if( p_i->i_type == ITEM_TYPE_FILE || p_i->i_type == ITEM_TYPE_DIRECTORY ) { const char *psz_filename = strrchr( p_i->psz_uri, '/' ); if( psz_filename && *psz_filename == '/' ) psz_filename++; if( psz_filename && *psz_filename ) p_i->psz_name = strdup( psz_filename ); /* Make the name more readable */ if( p_i->psz_name ) { decode_URI( p_i->psz_name ); EnsureUTF8( p_i->psz_name ); } } else { /* Strip login and password from title */ int r; vlc_url_t url; vlc_UrlParse( &url, psz_uri, 0 ); if( url.psz_protocol ) { if( url.i_port > 0 ) r=asprintf( &p_i->psz_name, "%s://%s:%d%s", url.psz_protocol, url.psz_host, url.i_port, url.psz_path ? url.psz_path : "" ); else r=asprintf( &p_i->psz_name, "%s://%s%s", url.psz_protocol, url.psz_host ? url.psz_host : "", url.psz_path ? url.psz_path : "" ); } else { if( url.i_port > 0 ) r=asprintf( &p_i->psz_name, "%s:%d%s", url.psz_host, url.i_port, url.psz_path ? url.psz_path : "" ); else r=asprintf( &p_i->psz_name, "%s%s", url.psz_host, url.psz_path ? url.psz_path : "" ); } vlc_UrlClean( &url ); if( -1==r ) p_i->psz_name=NULL; /* recover from undefined value */ } vlc_mutex_unlock( &p_i->lock ); }
int RarAccessOpen(vlc_object_t *object) { access_t *access = (access_t*)object; const char *name = strchr(access->psz_location, '|'); if (name == NULL) return VLC_EGENERIC; char *base = strndup(access->psz_location, name - access->psz_location); if (unlikely(base == NULL)) return VLC_ENOMEM; name++; decode_URI(base); stream_t *s = stream_UrlNew(access, base); if (!s || RarProbe(s)) goto error; struct { int filescount; rar_file_t **files; unsigned int i_nbvols; } newscheme = { 0, NULL, 0 }, oldscheme = { 0, NULL, 0 }, *p_scheme; if (RarParse(s, &newscheme.filescount, &newscheme.files, &newscheme.i_nbvols, false) || newscheme.filescount < 1 || newscheme.i_nbvols < 2 ) { /* We might want to lookup old naming scheme, could be a part1.rar,part1.r00 */ stream_Seek(s, 0); RarParse(s, &oldscheme.filescount, &oldscheme.files, &oldscheme.i_nbvols, true); } if (oldscheme.filescount >= newscheme.filescount && oldscheme.i_nbvols > newscheme.i_nbvols) { for (int i = 0; i < newscheme.filescount; i++) RarFileDelete(newscheme.files[i]); free(newscheme.files); p_scheme = &oldscheme; msg_Dbg(s, "using rar old naming for %d files nbvols %u", p_scheme->filescount, oldscheme.i_nbvols); } else if (newscheme.filescount) { for (int i = 0; i < oldscheme.filescount; i++) RarFileDelete(oldscheme.files[i]); free(oldscheme.files); p_scheme = &newscheme; msg_Dbg(s, "using rar new naming for %d files nbvols %u", p_scheme->filescount, oldscheme.i_nbvols); } else { msg_Info(s, "Invalid or unsupported RAR archive"); for (int i = 0; i < oldscheme.filescount; i++) RarFileDelete(oldscheme.files[i]); free(oldscheme.files); for (int i = 0; i < newscheme.filescount; i++) RarFileDelete(newscheme.files[i]); free(newscheme.files); goto error; } rar_file_t *file = NULL; for (int i = 0; i < p_scheme->filescount; i++) { if (!file && !strcmp(p_scheme->files[i]->name, name)) file = p_scheme->files[i]; else RarFileDelete(p_scheme->files[i]); } free(p_scheme->files); if (!file) goto error; access_sys_t *sys = access->p_sys = malloc(sizeof(*sys)); sys->s = s; sys->file = file; access->pf_read = Read; access->pf_block = NULL; access->pf_control = Control; access->pf_seek = Seek; access_InitFields(access); rar_file_chunk_t dummy = { .mrl = base, }; sys->chunk = &dummy; Seek(access, 0); free(base); return VLC_SUCCESS; error: if (s) stream_Delete(s); free(base); return VLC_EGENERIC; }
int AccessOpen(vlc_object_t *p_object) { access_t *p_access = (access_t*)p_object; const char *sep = strchr(p_access->psz_location, ARCHIVE_SEP_CHAR); if (sep == NULL) return VLC_EGENERIC; char *psz_base = strdup(p_access->psz_location); if (unlikely(psz_base == NULL)) return VLC_ENOMEM; char *psz_name = psz_base + (sep - p_access->psz_location); *(psz_name++) = '\0'; if (decode_URI(psz_base) == NULL) { free(psz_base); return VLC_EGENERIC; } access_sys_t *p_sys = p_access->p_sys = calloc(1, sizeof(access_sys_t)); p_sys->p_archive = archive_read_new(); if (!p_sys->p_archive) { msg_Err(p_access, "can't create libarchive instance: %s", archive_error_string(p_sys->p_archive)); free(psz_base); goto error; } EnableArchiveFormats(p_sys->p_archive); /* Set up the switch callback for multiple volumes handling */ archive_read_set_switch_callback(p_sys->p_archive, SwitchCallback); /* !Warn: sucks because libarchive can't guess format without reading 1st header * and it can't tell either if volumes are missing neither set following * volumes after the first Open(). * We need to know volumes uri in advance then :/ */ /* Try to list existing volumes */ char **ppsz_files = NULL; unsigned int i_files = 0; FindVolumes(p_access, p_sys->p_archive, psz_base, &ppsz_files, &i_files); p_sys->i_callback_data = 1 + i_files; p_sys->p_callback_data = malloc(sizeof(callback_data_t) * p_sys->i_callback_data); if (!p_sys->p_callback_data) { for(unsigned int i=0; i<i_files; i++) free(ppsz_files[i]); free(ppsz_files); free(psz_base); AccessClose(p_object); return VLC_ENOMEM; } /* set up our callback struct for our main uri */ p_sys->p_callback_data[0].psz_uri = psz_base; p_sys->p_callback_data[0].p_access = p_access; archive_read_append_callback_data(p_sys->p_archive, &p_sys->p_callback_data[0]); /* and register other volumes */ for(unsigned int i=0; i<i_files; i++) { p_sys->p_callback_data[1+i].psz_uri = ppsz_files[i]; p_sys->p_callback_data[1+i].p_access = p_access; archive_read_append_callback_data(p_sys->p_archive, &p_sys->p_callback_data[1+i]); } free(ppsz_files); if (archive_read_open2(p_sys->p_archive, &p_sys->p_callback_data[0], OpenCallback, ReadCallback, SkipCallback, CloseCallback) != ARCHIVE_OK) { msg_Err(p_access, "can't open archive: %s", archive_error_string(p_sys->p_archive)); AccessClose(p_object); return VLC_EGENERIC; } bool b_present = false; while(archive_read_next_header(p_sys->p_archive, &p_sys->p_entry) == ARCHIVE_OK) { if (!strcmp(archive_entry_pathname(p_sys->p_entry), psz_name)) { b_present = true; break; } msg_Dbg(p_access, "skipping entry %s != %s", archive_entry_pathname(p_sys->p_entry), psz_name); } if (!b_present) { msg_Err(p_access, "entry '%s' not found in archive", psz_name); /* entry not found */ goto error; } msg_Dbg(p_access, "reading entry %s %"PRId64, archive_entry_pathname(p_sys->p_entry), archive_entry_size(p_sys->p_entry)); /* try to guess if it is seekable or not (does not depend on backend) */ p_sys->b_seekable = (archive_seek_data(p_sys->p_archive, 0, SEEK_SET) >= 0); p_access->pf_read = Read; p_access->pf_block = NULL; /* libarchive's zerocopy keeps owning block :/ */ p_access->pf_control = Control; p_access->pf_seek = Seek; access_InitFields(p_access); return VLC_SUCCESS; error: AccessClose(p_object); return VLC_EGENERIC; }
/** * Parses clipinfo parameter * @param psz_clipinfo: string containing the clipinfo parameter along with quotes * @param ppsz_artist: Buffer to store artist name * @param ppsz_title: Buffer to store title * @param ppsz_album: Buffer to store album * @param ppsz_genre: Buffer to store genre * @param ppsz_year: Buffer to store year * @param ppsz_cdnum: Buffer to store cdnum * @param ppsz_comments: Buffer to store comments */ static void ParseClipInfo( const char *psz_clipinfo, char **ppsz_artist, char **ppsz_title, char **ppsz_album, char **ppsz_genre, char **ppsz_year, char **ppsz_cdnum, char **ppsz_comments ) { char *psz_option_next, *psz_option_start, *psz_param, *psz_value, *psz_suboption; char *psz_temp_clipinfo = strdup( psz_clipinfo ); psz_option_start = strchr( psz_temp_clipinfo, '"' ); if( !psz_option_start ) { free( psz_temp_clipinfo ); return; } psz_option_start++; psz_option_next = psz_option_start; while( 1 ) /* Process each sub option */ { /* Get the sub option */ psz_option_start = psz_option_next; psz_option_next = strchr( psz_option_start, '|' ); if( psz_option_next ) *psz_option_next = '\0'; else psz_option_next = strchr( psz_option_start, '"' ); if( psz_option_next ) *psz_option_next = '\0'; else psz_option_next = strchr( psz_option_start, '\0' ); if( psz_option_next == psz_option_start ) break; psz_suboption = strdup( psz_option_start ); if( !psz_suboption ) break; /* Parse out param and value */ psz_param = psz_suboption; if( strchr( psz_suboption, '=' ) ) { psz_value = strchr( psz_suboption, '=' ) + 1; *( strchr( psz_suboption, '=' ) ) = '\0'; } else break; /* Put into args */ if( !strcmp( psz_param, "artist name" ) ) *ppsz_artist = decode_URI( psz_value ); else if( !strcmp( psz_param, "title" ) ) *ppsz_title = decode_URI( psz_value ); else if( !strcmp( psz_param, "album name" ) ) *ppsz_album = decode_URI( psz_value ); else if( !strcmp( psz_param, "genre" ) ) *ppsz_genre = decode_URI( psz_value ); else if( !strcmp( psz_param, "year" ) ) *ppsz_year = decode_URI( psz_value ); else if( !strcmp( psz_param, "cdnum" ) ) *ppsz_cdnum = decode_URI( psz_value ); else if( !strcmp( psz_param, "comments" ) ) *ppsz_comments = decode_URI( psz_value ); free( psz_suboption ); psz_option_next++; } free( psz_temp_clipinfo ); }
/** * Main demux callback function * @param p_demux: this demux object */ static int Demux( demux_t *p_demux ) { char *psz_line; char *psz_artist = NULL, *psz_album = NULL, *psz_genre = NULL, *psz_year = NULL; char *psz_author = NULL, *psz_title = NULL, *psz_copyright = NULL, *psz_cdnum = NULL, *psz_comments = NULL; int i_parsed_duration = 0; mtime_t i_duration = -1; const char **ppsz_options = NULL; int i_options = 0, i_start = 0, i_stop = 0; bool b_cleanup = false; input_item_t *p_input; input_item_t *p_current_input = GetCurrentItem(p_demux); psz_line = stream_ReadLine( p_demux->s ); while( psz_line ) { char *psz_parse = psz_line; /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++; if( *psz_parse == '#' ) { /* Ignore comments */ } else if( *psz_parse ) { char *psz_mrl, *psz_option_next, *psz_option; char *psz_param, *psz_value; /* Get the MRL from the file. Note that this might contain parameters of form ?param1=value1¶m2=value2 in a RAM file */ psz_mrl = ProcessMRL( psz_parse, p_demux->p_sys->psz_prefix ); b_cleanup = true; if ( !psz_mrl ) goto error; /* We have the MRL, now we have to check for options and parse them from MRL */ psz_option = strchr( psz_mrl, '?' ); /* Look for start of options */ if( psz_option ) { /* Remove options from MRL because VLC can't get the file otherwise */ *psz_option = '\0'; psz_option++; psz_option_next = psz_option; while( 1 ) /* Process each option */ { /* Look for end of first option which maybe a & or \0 */ psz_option = psz_option_next; psz_option_next = strchr( psz_option, '&' ); if( psz_option_next ) { *psz_option_next = '\0'; psz_option_next++; } else psz_option_next = strchr( psz_option, '\0' ); /* Quit if options are over */ if( psz_option_next == psz_option ) break; /* Parse out param and value */ psz_param = psz_option; psz_value = strchr( psz_option, '=' ); if( psz_value == NULL ) break; *psz_value = '\0'; psz_value++; /* Take action based on parameter value in the below if else structure */ /* TODO: Remove any quotes surrounding values if required */ if( !strcmp( psz_param, "clipinfo" ) ) { ParseClipInfo( psz_value, &psz_artist, &psz_title, &psz_album, &psz_genre, &psz_year, &psz_cdnum, &psz_comments ); /* clipinfo has various sub parameters, which is parsed by this function */ } else if( !strcmp( psz_param, "author" ) ) psz_author = decode_URI(psz_value); else if( !strcmp( psz_param, "start" ) ) { i_start = ParseTime( psz_value, strlen( psz_value ) ); char *temp; if( i_start ) { if( asprintf( &temp, ":start-time=%d", i_start ) != -1 ) INSERT_ELEM( ppsz_options, i_options, i_options, temp ); } } else if( !strcmp( psz_param, "end" ) ) { i_stop = ParseTime( psz_value, strlen( psz_value ) ); char *temp; if( i_stop ) { if( asprintf( &temp, ":stop-time=%d", i_stop ) != -1 ) INSERT_ELEM( ppsz_options, i_options, i_options, temp ); } } else if( !strcmp( psz_param, "title" ) ) psz_title = decode_URI(psz_value); else if( !strcmp( psz_param, "copyright" ) ) psz_copyright = decode_URI(psz_value); else { /* TODO: insert option anyway? Currently ignores*/ /* INSERT_ELEM( ppsz_options, i_options, i_options, psz_option ); */ } } } /* Create the input item and pump in all the options into playlist item */ p_input = input_item_NewExt( p_demux, psz_mrl, psz_title, i_options, ppsz_options, 0, i_duration ); if( !EMPTY_STR( psz_artist ) ) input_item_SetArtist( p_input, psz_artist ); if( !EMPTY_STR( psz_author ) ) input_item_SetPublisher( p_input, psz_author ); if( !EMPTY_STR( psz_title ) ) input_item_SetTitle( p_input, psz_title ); if( !EMPTY_STR( psz_copyright ) ) input_item_SetCopyright( p_input, psz_copyright ); if( !EMPTY_STR( psz_album ) ) input_item_SetAlbum( p_input, psz_album ); if( !EMPTY_STR( psz_genre ) ) input_item_SetGenre( p_input, psz_genre ); if( !EMPTY_STR( psz_year ) ) input_item_SetDate( p_input, psz_copyright ); if( !EMPTY_STR( psz_cdnum ) ) input_item_SetTrackNum( p_input, psz_cdnum ); if( !EMPTY_STR( psz_comments ) ) input_item_SetDescription( p_input, psz_comments ); input_item_AddSubItem( p_current_input, p_input ); vlc_gc_decref( p_input ); free( psz_mrl ); } error: /* Fetch another line */ free( psz_line ); psz_line = stream_ReadLine( p_demux->s ); if( !psz_line ) b_cleanup = true; if( b_cleanup ) { /* Cleanup state */ while( i_options-- ) free( (char*)ppsz_options[i_options] ); FREENULL( ppsz_options ); FREENULL( psz_artist ); FREENULL( psz_title ); FREENULL( psz_author ); FREENULL( psz_copyright ); FREENULL( psz_album ); FREENULL( psz_genre ); FREENULL( psz_year ); FREENULL( psz_cdnum ); FREENULL( psz_comments ); i_options = 0; i_parsed_duration = 0; i_duration = -1; i_start = 0; i_stop = 0; b_cleanup = false; } } vlc_gc_decref(p_current_input); var_Destroy( p_demux, "m3u-extvlcopt" ); return 0; /* Needed for correct operation of go back */ }
static LRESULT HandleCadMessage(intf_thread_t* p_intf, HWND hwnd, WPARAM wParam, LPARAM lParam) { intf_sys_t* const p_sys = p_intf->p_sys; switch (lParam) { case IPC_PLAY: { playlist_Play(pl_Get(p_intf->p_libvlc)); return 1; } case IPC_PLAYPAUSE: { playlist_t* p_playlist = pl_Get(p_intf->p_libvlc); const bool playing = playlist_Status(p_playlist) == PLAYLIST_RUNNING; playlist_Control(p_playlist, playing ? PLAYLIST_PAUSE : PLAYLIST_PLAY, pl_Unlocked); return 1; } case IPC_PAUSE: { playlist_Pause(pl_Get(p_intf->p_libvlc)); return 1; } case IPC_STOP: { playlist_Stop(pl_Get(p_intf->p_libvlc)); return 1; } case IPC_NEXT: { playlist_Next(pl_Get(p_intf->p_libvlc)); return 1; } case IPC_PREVIOUS: { playlist_Prev(pl_Get(p_intf->p_libvlc)); return 1; } case IPC_SET_VOLUME: { playlist_VolumeSet(pl_Get(p_intf->p_libvlc), (int)wParam / 100.0f); return 1; } case IPC_GET_VOLUME: { // VLC can return a volume larger than 100% so we need to cap it to 100 here. const float volume = playlist_VolumeGet(pl_Get(p_intf->p_libvlc)) * 100.0f; return (LRESULT)min(volume, 100.0f); } case IPC_GET_DURATION: { unsigned int duration = 0; if (p_sys->p_input) { input_item_t* const p_item = input_GetItem(p_sys->p_input); duration = (unsigned int)(input_item_GetDuration(p_item) / 1000000); } return duration; } case IPC_GET_POSITION: { int pos = 0; if (p_sys->p_input) { pos = (int)(var_GetTime(p_sys->p_input, "time") / CLOCK_FREQ); } return pos; } case IPC_SET_POSITION: { if (p_sys->p_input) { var_SetTime(p_sys->p_input, "time", (int64_t)wParam * CLOCK_FREQ); } return 0; } case IPC_GET_SHUFFLE: { return (int)var_GetBool(pl_Get(p_intf->p_libvlc), "random"); } case IPC_SET_SHUFFLE: { return (int)var_SetBool(pl_Get(p_intf->p_libvlc), "random", (bool)wParam); } case IPC_GET_REPEAT: { return (int)var_GetBool(pl_Get(p_intf->p_libvlc), "repeat"); } case IPC_SET_REPEAT: { return (int)var_SetBool(pl_Get(p_intf->p_libvlc), "repeat", (bool)wParam); } case IPC_SET_RATING: { // VLC does not support ratings so send back 0. PostMessage(p_sys->cad_window, WM_USER, 0, IPC_RATING_CHANGED_NOTIFICATION); return 0; } case IPC_SET_CALLBACK_HWND: { p_sys->cad_window = (HWND)wParam; return 1; } case IPC_SHOW_WINDOW: { // TODO. return 0; } case IPC_GET_STATE: { const int status = playlist_Status(pl_Get(p_intf->p_libvlc)); return status == PLAYLIST_RUNNING ? 1 : status == PLAYLIST_PAUSED ? 2 : 0; } case IPC_SHUTDOWN_NOTIFICATION: { p_sys->cad_window = NULL; return 1; } case IPC_CLOSE: { libvlc_Quit(p_intf->p_libvlc); return 1; } case IPC_GET_CURRENT_TRACK: { if (!p_sys->p_input) return 0; input_item_t* p_item = input_GetItem(p_sys->p_input); char buffer[DATA_MAX_LENGTH]; int buffer_len = 0; // If the i sstarts with file://, we assume that it is a local file and detailed // metadata is available. Otherwise, we assume it to be a network stream (i.e. radio) // with limited info (only a title). char* const file = decode_URI(input_item_GetURI(p_item)); if (strncmp(file, "file://", 7) == 0) { char* const title = input_item_GetTitleFbName(p_item); char* const artist = input_item_GetArtist(p_item); char* const album = input_item_GetAlbum(p_item); char* const cover = decode_URI(input_item_GetArtworkURL(p_item)); const unsigned int duration = input_item_GetDuration(p_item) / 1000000U; buffer_len = _snprintf( buffer, ARRAYSIZE(buffer), "%s\t%s\t%s\t\t\t\t\t%u\t%s\t\t%s\t\t\t\t\t\t\t", title ? title : "", artist ? artist : "", album ? album : "", duration, file ? &file[8] : "", cover ? &cover[8] : ""); // Skip the "file://" part. free(title); free(artist); free(album); free(cover); } else if (char* now_playing = input_item_GetNowPlaying(p_item)) { char* artist = NULL; char* title = now_playing; char* pos = strstr(now_playing, " - "); if (pos) { pos[0] = '\0'; artist = title; title = pos + 3; // Skip the " - " } buffer_len = _snprintf( buffer, ARRAYSIZE(buffer), "%s\t%s\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", title ? title : "", artist ? artist : ""); free(now_playing); } free(file); if (buffer_len) { wchar_t buffer_w[DATA_MAX_LENGTH]; const int buffer_w_len = MultiByteToWideChar( CP_UTF8, 0, buffer, buffer_len + 1, buffer_w, ARRAYSIZE(buffer_w)); COPYDATASTRUCT cds; cds.dwData = IPC_CURRENT_TRACK_NOTIFICATION; cds.lpData = &buffer_w; cds.cbData = buffer_w_len * sizeof(buffer_w[0]); SendMessage( p_sys->cad_window, WM_COPYDATA, IPC_CURRENT_TRACK_NOTIFICATION, (LPARAM)&cds); } return 1; } } return 0; }
/***************************************************************************** * ItemChange: Playlist item change callback *****************************************************************************/ static int ItemChange( vlc_object_t *p_this, const char *psz_var, vlc_value_t oldval, vlc_value_t newval, void *param ) { VLC_UNUSED(psz_var); VLC_UNUSED(oldval); VLC_UNUSED(newval); char psz_tmp[MAX_LENGTH]; char psz_notify[MAX_LENGTH]; char *psz_title = NULL; char *psz_artist = NULL; char *psz_album = NULL; char *psz_arturl = NULL; input_thread_t *p_input = playlist_CurrentInput( (playlist_t*) p_this ); intf_thread_t *p_intf = param; intf_sys_t *p_sys = p_intf->p_sys; if( !p_input ) return VLC_SUCCESS; if( p_input->b_dead ) { /* Not playing anything ... */ vlc_object_release( p_input ); return VLC_SUCCESS; } /* Wait a tad so the meta has been fetched * FIXME that's awfully wrong */ msleep( 1000*4 ); /* Playing something ... */ input_item_t *p_input_item = input_GetItem( p_input ); psz_artist = input_item_GetArtist( p_input_item ); psz_album = input_item_GetAlbum( p_input_item ); psz_title = input_item_GetTitleFbName( p_input_item ); if( EMPTY_STR( psz_title ) ) { /* Not enough metadata ... */ free( psz_title ); free( psz_artist ); free( psz_album ); vlc_object_release( p_input ); return VLC_SUCCESS; } if( EMPTY_STR( psz_artist ) ) { free( psz_artist ); psz_artist = NULL; } if( EMPTY_STR( psz_album ) ) { free( psz_album ); psz_album = NULL; } if( psz_artist && psz_album ) snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>\n%s\n[%s]", psz_title, psz_artist, psz_album ); else if( psz_artist ) snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>\n%s", psz_title, psz_artist ); else snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>", psz_title ); free( psz_title ); free( psz_artist ); free( psz_album ); GdkPixbuf *pix = NULL; psz_arturl = input_item_GetArtURL( p_input_item ); vlc_object_release( p_input ); if( psz_arturl && !strncmp( psz_arturl, "file://", 7 ) && decode_URI( psz_arturl + 7 ) ) { /* scale the art to show it in notify popup */ GError *p_error = NULL; pix = gdk_pixbuf_new_from_file_at_scale( &psz_arturl[7], 72, 72, TRUE, &p_error ); } else /* else we show state-of-the art logo */ { GError *p_error = NULL; char *psz_pixbuf; if( asprintf( &psz_pixbuf, "%s/vlc48x48.png", config_GetDataDir() ) >= 0 ) { pix = gdk_pixbuf_new_from_file( psz_pixbuf, &p_error ); free( psz_pixbuf ); } } free( psz_arturl ); /* we need to replace '&' with '&' because '&' is a keyword of * notification-daemon parser */ const int i_len = strlen( psz_tmp ); int i_notify = 0; for( int i = 0; i < i_len && i_notify < ( MAX_LENGTH - 5 ); i++ ) { /* we use MAX_LENGTH - 5 because if the last char of psz_tmp is '&' * we will need 5 more characters: 'amp;\0' . * however that's unlikely to happen because the last char is '\0' */ if( psz_tmp[i] != '&' ) { psz_notify[i_notify] = psz_tmp[i]; } else { snprintf( &psz_notify[i_notify], 6, "&" ); i_notify += 4; } i_notify++; } psz_notify[i_notify] = '\0'; vlc_mutex_lock( &p_sys->lock ); Notify( p_this, psz_notify, pix, p_intf ); vlc_mutex_unlock( &p_sys->lock ); return VLC_SUCCESS; }
void input_item_SetURI( input_item_t *p_i, const char *psz_uri ) { vlc_mutex_lock( &p_i->lock ); #ifndef NDEBUG if( !strstr( psz_uri, "://" ) || strstr( psz_uri, " " ) || strstr( psz_uri, "\"" ) ) fprintf( stderr, "input_item_SetURI() was likely called with a path. FIXME\n" ); #endif free( p_i->psz_uri ); p_i->psz_uri = strdup( psz_uri ); p_i->i_type = GuessType( p_i ); if( p_i->psz_name ) ; else if( p_i->i_type == ITEM_TYPE_FILE || p_i->i_type == ITEM_TYPE_DIRECTORY ) { const char *psz_filename = strrchr( p_i->psz_uri, '/' ); if( psz_filename && *psz_filename == '/' ) psz_filename++; if( psz_filename && *psz_filename ) p_i->psz_name = strdup( psz_filename ); /* Make the name more readable */ if( p_i->psz_name ) decode_URI( p_i->psz_name ); } else { /* Strip login and password from title */ int r; vlc_url_t url; vlc_UrlParse( &url, psz_uri, 0 ); if( url.psz_protocol ) { if( url.i_port > 0 ) r=asprintf( &p_i->psz_name, "%s://%s:%d%s", url.psz_protocol, url.psz_host, url.i_port, url.psz_path ? url.psz_path : "" ); else r=asprintf( &p_i->psz_name, "%s://%s%s", url.psz_protocol, url.psz_host ? url.psz_host : "", url.psz_path ? url.psz_path : "" ); } else { if( url.i_port > 0 ) r=asprintf( &p_i->psz_name, "%s:%d%s", url.psz_host, url.i_port, url.psz_path ? url.psz_path : "" ); else r=asprintf( &p_i->psz_name, "%s%s", url.psz_host, url.psz_path ? url.psz_path : "" ); } vlc_UrlClean( &url ); if( -1==r ) p_i->psz_name=NULL; /* recover from undefined value */ } vlc_mutex_unlock( &p_i->lock ); }
void EvaluateRPN( intf_thread_t *p_intf, mvar_t *vars, rpn_stack_t *st, char *exp ) { intf_sys_t *p_sys = p_intf->p_sys; while( exp != NULL && *exp != '\0' ) { char *p, *s; /* skip space */ while( *exp == ' ' ) { exp++; } if( *exp == '\'' ) { /* extract string */ p = FirstWord( exp, exp ); SSPush( st, exp ); exp = p; continue; } /* extract token */ p = FirstWord( exp, exp ); s = exp; if( p == NULL ) { exp += strlen( exp ); } else { exp = p; } if( *s == '\0' ) { break; } /* 1. Integer function */ if( !strcmp( s, "!" ) ) { SSPushN( st, ~SSPopN( st, vars ) ); } else if( !strcmp( s, "^" ) ) { SSPushN( st, SSPopN( st, vars ) ^ SSPopN( st, vars ) ); } else if( !strcmp( s, "&" ) ) { SSPushN( st, SSPopN( st, vars ) & SSPopN( st, vars ) ); } else if( !strcmp( s, "|" ) ) { SSPushN( st, SSPopN( st, vars ) | SSPopN( st, vars ) ); } else if( !strcmp( s, "+" ) ) { SSPushN( st, SSPopN( st, vars ) + SSPopN( st, vars ) ); } else if( !strcmp( s, "-" ) ) { int j = SSPopN( st, vars ); int i = SSPopN( st, vars ); SSPushN( st, i - j ); } else if( !strcmp( s, "*" ) ) { SSPushN( st, SSPopN( st, vars ) * SSPopN( st, vars ) ); } else if( !strcmp( s, "/" ) ) { int i, j; j = SSPopN( st, vars ); i = SSPopN( st, vars ); SSPushN( st, j != 0 ? i / j : 0 ); } else if( !strcmp( s, "%" ) ) { int i, j; j = SSPopN( st, vars ); i = SSPopN( st, vars ); SSPushN( st, j != 0 ? i % j : 0 ); } /* 2. integer tests */ else if( !strcmp( s, "=" ) ) { SSPushN( st, SSPopN( st, vars ) == SSPopN( st, vars ) ? -1 : 0 ); } else if( !strcmp( s, "!=" ) ) { SSPushN( st, SSPopN( st, vars ) != SSPopN( st, vars ) ? -1 : 0 ); } else if( !strcmp( s, "<" ) ) { int j = SSPopN( st, vars ); int i = SSPopN( st, vars ); SSPushN( st, i < j ? -1 : 0 ); } else if( !strcmp( s, ">" ) ) { int j = SSPopN( st, vars ); int i = SSPopN( st, vars ); SSPushN( st, i > j ? -1 : 0 ); } else if( !strcmp( s, "<=" ) ) { int j = SSPopN( st, vars ); int i = SSPopN( st, vars ); SSPushN( st, i <= j ? -1 : 0 ); } else if( !strcmp( s, ">=" ) ) { int j = SSPopN( st, vars ); int i = SSPopN( st, vars ); SSPushN( st, i >= j ? -1 : 0 ); } /* 3. string functions */ else if( !strcmp( s, "strcat" ) ) { char *s2 = SSPop( st ); char *s1 = SSPop( st ); char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 ); strcpy( str, s1 ); strcat( str, s2 ); SSPush( st, str ); free( s1 ); free( s2 ); free( str ); } else if( !strcmp( s, "strcmp" ) ) { char *s2 = SSPop( st ); char *s1 = SSPop( st ); SSPushN( st, strcmp( s1, s2 ) ); free( s1 ); free( s2 ); } else if( !strcmp( s, "strncmp" ) ) { int n = SSPopN( st, vars ); char *s2 = SSPop( st ); char *s1 = SSPop( st ); SSPushN( st, strncmp( s1, s2 , n ) ); free( s1 ); free( s2 ); } else if( !strcmp( s, "strsub" ) ) { int n = SSPopN( st, vars ); int m = SSPopN( st, vars ); int i_len; char *s = SSPop( st ); char *str; if( n >= m ) { i_len = n - m + 1; } else { i_len = 0; } str = malloc( i_len + 1 ); memcpy( str, s + m - 1, i_len ); str[ i_len ] = '\0'; SSPush( st, str ); free( s ); free( str ); } else if( !strcmp( s, "strlen" ) ) { char *str = SSPop( st ); SSPushN( st, strlen( str ) ); free( str ); } else if( !strcmp( s, "str_replace" ) ) { char *psz_to = SSPop( st ); char *psz_from = SSPop( st ); char *psz_in = SSPop( st ); char *psz_in_current = psz_in; char *psz_out = malloc( strlen(psz_in) * strlen(psz_to) + 1 ); char *psz_out_current = psz_out; while( (p = strstr( psz_in_current, psz_from )) != NULL ) { memcpy( psz_out_current, psz_in_current, p - psz_in_current ); psz_out_current += p - psz_in_current; strcpy( psz_out_current, psz_to ); psz_out_current += strlen(psz_to); psz_in_current = p + strlen(psz_from); } strcpy( psz_out_current, psz_in_current ); psz_out_current += strlen(psz_in_current); *psz_out_current = '\0'; SSPush( st, psz_out ); free( psz_to ); free( psz_from ); free( psz_in ); free( psz_out ); } else if( !strcmp( s, "url_extract" ) ) { const char *url = mvar_GetValue( vars, "url_value" ); char *name = SSPop( st ); char *value = ExtractURIString( url, name ); if( value != NULL ) { decode_URI( value ); SSPush( st, value ); free( value ); } else SSPush( st, "" ); free( name ); } else if( !strcmp( s, "url_encode" ) ) { char *url = SSPop( st ); char *value = vlc_UrlEncode( url ); free( url ); SSPush( st, value ); free( value ); } else if( !strcmp( s, "xml_encode" ) || !strcmp( s, "htmlspecialchars" ) ) { char *url = SSPop( st ); char *value = convert_xml_special_chars( url ); free( url ); SSPush( st, value ); free( value ); } else if( !strcmp( s, "addslashes" ) ) { char *psz_src = SSPop( st ); char *psz_dest; char *str = psz_src; p = psz_dest = malloc( strlen( str ) * 2 + 1 ); while( *str != '\0' ) { if( *str == '"' || *str == '\'' || *str == '\\' ) { *p++ = '\\'; } *p++ = *str; str++; } *p = '\0'; SSPush( st, psz_dest ); free( psz_src ); free( psz_dest ); } else if( !strcmp( s, "stripslashes" ) ) { char *psz_src = SSPop( st ); char *psz_dest; char *str = psz_src; p = psz_dest = strdup( psz_src ); while( *str ) { if( *str == '\\' && *(str + 1) ) { str++; } *p++ = *str++; } *p = '\0'; SSPush( st, psz_dest ); free( psz_src ); free( psz_dest ); } else if( !strcmp( s, "realpath" ) ) { char *psz_src = SSPop( st ); char *psz_dir = RealPath( psz_src ); SSPush( st, psz_dir ); free( psz_src ); free( psz_dir ); } /* 4. stack functions */ else if( !strcmp( s, "dup" ) ) { char *str = SSPop( st ); SSPush( st, str ); SSPush( st, str ); free( str ); } else if( !strcmp( s, "drop" ) ) { char *str = SSPop( st ); free( str ); } else if( !strcmp( s, "swap" ) ) { char *s1 = SSPop( st ); char *s2 = SSPop( st ); SSPush( st, s1 ); SSPush( st, s2 ); free( s1 ); free( s2 ); } else if( !strcmp( s, "flush" ) ) { SSClean( st ); SSInit( st ); } else if( !strcmp( s, "store" ) ) { char *value = SSPop( st ); char *name = SSPop( st ); mvar_PushNewVar( vars, name, value ); free( name ); free( value ); } else if( !strcmp( s, "value" ) ) { char *name = SSPop( st ); const char *value = mvar_GetValue( vars, name ); SSPush( st, value ); free( name ); } /* 5. player control */ else if( !strcmp( s, "vlc_play" ) ) { int i_id = SSPopN( st, vars ); int i_ret; playlist_Lock( p_sys->p_playlist ); i_ret = playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, NULL, playlist_ItemGetById( p_sys->p_playlist, i_id ) ); playlist_Unlock( p_sys->p_playlist ); msg_Dbg( p_intf, "requested playlist item: %i", i_id ); SSPushN( st, i_ret ); } else if( !strcmp( s, "vlc_stop" ) ) { playlist_Control( p_sys->p_playlist, PLAYLIST_STOP, pl_Unlocked ); msg_Dbg( p_intf, "requested playlist stop" ); } else if( !strcmp( s, "vlc_pause" ) ) { playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE, pl_Unlocked ); msg_Dbg( p_intf, "requested playlist pause" ); } else if( !strcmp( s, "vlc_next" ) ) { playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, pl_Unlocked, 1 ); msg_Dbg( p_intf, "requested playlist next" ); } else if( !strcmp( s, "vlc_previous" ) ) { playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, pl_Unlocked, -1 ); msg_Dbg( p_intf, "requested playlist previous" ); } else if( !strcmp( s, "vlc_seek" ) ) { char *psz_value = SSPop( st ); HandleSeek( p_intf, psz_value ); msg_Dbg( p_intf, "requested playlist seek: %s", psz_value ); free( psz_value ); } else if( !strcmp( s, "vlc_var_type" ) || !strcmp( s, "vlc_config_type" ) ) { vlc_object_t *p_object; const char *psz_type = NULL; int i_type = 0; if( !strcmp( s, "vlc_var_type" ) ) { char *psz_object = SSPop( st ); char *psz_variable = SSPop( st ); bool b_need_release; p_object = GetVLCObject( p_intf, psz_object, &b_need_release ); if( p_object != NULL ) i_type = var_Type( p_object, psz_variable ); free( psz_variable ); free( psz_object ); if( b_need_release && p_object != NULL ) vlc_object_release( p_object ); } else { char *psz_variable = SSPop( st ); p_object = VLC_OBJECT(p_intf); i_type = config_GetType( p_object, psz_variable ); free( psz_variable ); } if( p_object != NULL ) { switch( i_type & VLC_VAR_TYPE ) { case VLC_VAR_BOOL: psz_type = "VLC_VAR_BOOL"; break; case VLC_VAR_INTEGER: psz_type = "VLC_VAR_INTEGER"; break; case VLC_VAR_HOTKEY: psz_type = "VLC_VAR_HOTKEY"; break; case VLC_VAR_STRING: psz_type = "VLC_VAR_STRING"; break; case VLC_VAR_MODULE: psz_type = "VLC_VAR_MODULE"; break; case VLC_VAR_FILE: psz_type = "VLC_VAR_FILE"; break; case VLC_VAR_DIRECTORY: psz_type = "VLC_VAR_DIRECTORY"; break; case VLC_VAR_VARIABLE: psz_type = "VLC_VAR_VARIABLE"; break; case VLC_VAR_FLOAT: psz_type = "VLC_VAR_FLOAT"; break; default: psz_type = "UNDEFINED"; } } else psz_type = "INVALID"; SSPush( st, psz_type ); } else if( !strcmp( s, "vlc_var_set" ) ) { char *psz_object = SSPop( st ); char *psz_variable = SSPop( st ); bool b_need_release; vlc_object_t *p_object = GetVLCObject( p_intf, psz_object, &b_need_release ); if( p_object != NULL ) { bool b_error = false; char *psz_value = NULL; vlc_value_t val; int i_type; i_type = var_Type( p_object, psz_variable ); switch( i_type & VLC_VAR_TYPE ) { case VLC_VAR_BOOL: val.b_bool = SSPopN( st, vars ); msg_Dbg( p_intf, "requested %s var change: %s->%d", psz_object, psz_variable, val.b_bool ); break; case VLC_VAR_INTEGER: case VLC_VAR_HOTKEY: val.i_int = SSPopN( st, vars ); msg_Dbg( p_intf, "requested %s var change: %s->%d", psz_object, psz_variable, val.i_int ); break; case VLC_VAR_STRING: case VLC_VAR_MODULE: case VLC_VAR_FILE: case VLC_VAR_DIRECTORY: case VLC_VAR_VARIABLE: val.psz_string = psz_value = SSPop( st ); msg_Dbg( p_intf, "requested %s var change: %s->%s", psz_object, psz_variable, psz_value ); break; case VLC_VAR_FLOAT: psz_value = SSPop( st ); val.f_float = atof( psz_value ); msg_Dbg( p_intf, "requested %s var change: %s->%f", psz_object, psz_variable, val.f_float ); break; default: SSPopN( st, vars ); msg_Warn( p_intf, "invalid %s variable type %d (%s)", psz_object, i_type & VLC_VAR_TYPE, psz_variable ); b_error = true; } if( !b_error ) var_Set( p_object, psz_variable, val ); if( psz_value != NULL ) free( psz_value ); } else msg_Warn( p_intf, "vlc_var_set called without an object" ); free( psz_variable ); free( psz_object ); if( b_need_release && p_object != NULL ) vlc_object_release( p_object ); } else if( !strcmp( s, "vlc_var_get" ) ) { char *psz_object = SSPop( st ); char *psz_variable = SSPop( st ); bool b_need_release; vlc_object_t *p_object = GetVLCObject( p_intf, psz_object, &b_need_release ); if( p_object != NULL ) { vlc_value_t val; int i_type; i_type = var_Type( p_object, psz_variable ); var_Get( p_object, psz_variable, &val ); switch( i_type & VLC_VAR_TYPE ) { case VLC_VAR_BOOL: SSPushN( st, val.b_bool ); break; case VLC_VAR_INTEGER: case VLC_VAR_HOTKEY: SSPushN( st, val.i_int ); break; case VLC_VAR_STRING: case VLC_VAR_MODULE: case VLC_VAR_FILE: case VLC_VAR_DIRECTORY: case VLC_VAR_VARIABLE: SSPush( st, val.psz_string ); free( val.psz_string ); break; case VLC_VAR_FLOAT: { char psz_value[20]; lldiv_t value = lldiv( val.f_float * 1000000, 1000000 ); snprintf( psz_value, sizeof(psz_value), "%lld.%06u", value.quot, (unsigned int)value.rem ); SSPush( st, psz_value ); break; } default: msg_Warn( p_intf, "invalid %s variable type %d (%s)", psz_object, i_type & VLC_VAR_TYPE, psz_variable ); SSPush( st, "" ); } } else { msg_Warn( p_intf, "vlc_var_get called without an object" ); SSPush( st, "" ); } free( psz_variable ); free( psz_object ); if( b_need_release && p_object != NULL ) vlc_object_release( p_object ); } else if( !strcmp( s, "vlc_object_exists" ) ) { char *psz_object = SSPop( st ); bool b_need_release; vlc_object_t *p_object = GetVLCObject( p_intf, psz_object, &b_need_release ); if( b_need_release && p_object != NULL ) vlc_object_release( p_object ); if( p_object != NULL ) SSPush( st, "1" ); else SSPush( st, "0" ); } else if( !strcmp( s, "vlc_config_set" ) ) { char *psz_variable = SSPop( st ); int i_type = config_GetType( p_intf, psz_variable ); switch( i_type & VLC_VAR_TYPE ) { case VLC_VAR_BOOL: case VLC_VAR_INTEGER: config_PutInt( p_intf, psz_variable, SSPopN( st, vars ) ); break; case VLC_VAR_STRING: case VLC_VAR_MODULE: case VLC_VAR_FILE: case VLC_VAR_DIRECTORY: { char *psz_string = SSPop( st ); config_PutPsz( p_intf, psz_variable, psz_string ); free( psz_string ); break; } case VLC_VAR_FLOAT: { char *psz_string = SSPop( st ); config_PutFloat( p_intf, psz_variable, atof(psz_string) ); free( psz_string ); break; } default: msg_Warn( p_intf, "vlc_config_set called on unknown var (%s)", psz_variable ); } free( psz_variable ); } else if( !strcmp( s, "vlc_config_get" ) ) { char *psz_variable = SSPop( st ); int i_type = config_GetType( p_intf, psz_variable ); switch( i_type & VLC_VAR_TYPE ) { case VLC_VAR_BOOL: case VLC_VAR_INTEGER: SSPushN( st, config_GetInt( p_intf, psz_variable ) ); break; case VLC_VAR_STRING: case VLC_VAR_MODULE: case VLC_VAR_FILE: case VLC_VAR_DIRECTORY: { char *psz_string = config_GetPsz( p_intf, psz_variable ); SSPush( st, psz_string ); free( psz_string ); break; } case VLC_VAR_FLOAT: { char psz_string[20]; lldiv_t value = lldiv( config_GetFloat( p_intf, psz_variable ) * 1000000, 1000000 ); snprintf( psz_string, sizeof(psz_string), "%lld.%06u", value.quot, (unsigned int)value.rem ); SSPush( st, psz_string ); break; } default: msg_Warn( p_intf, "vlc_config_get called on unknown var (%s)", psz_variable ); SSPush( st, "" ); } free( psz_variable ); } else if( !strcmp( s, "vlc_config_save" ) ) { char *psz_module = SSPop( st ); int i_result; if( !*psz_module ) { free( psz_module ); psz_module = NULL; } i_result = config_SaveConfigFile( p_intf, psz_module ); if( psz_module != NULL ) free( psz_module ); SSPushN( st, i_result ); } else if( !strcmp( s, "vlc_config_reset" ) ) { config_ResetAll( p_intf ); } /* 6. playlist functions */ else if( !strcmp( s, "playlist_add" ) ) { char *psz_name = SSPop( st ); char *mrl = SSPop( st ); input_item_t *p_input; int i_ret; p_input = MRLParse( p_intf, mrl, psz_name ); char *psz_uri = input_item_GetURI( p_input ); if( !p_input || !psz_uri || !*psz_uri ) { i_ret = VLC_EGENERIC; msg_Dbg( p_intf, "invalid requested mrl: %s", mrl ); } else { i_ret = playlist_AddInput( p_sys->p_playlist, p_input, PLAYLIST_APPEND, PLAYLIST_END, true, pl_Unlocked ); if( i_ret == VLC_SUCCESS ) { playlist_item_t *p_item; msg_Dbg( p_intf, "requested mrl add: %s", mrl ); playlist_Lock( p_sys->p_playlist ); p_item = playlist_ItemGetByInput( p_sys->p_playlist, p_input ); if( p_item ) i_ret = p_item->i_id; playlist_Unlock( p_sys->p_playlist ); } else msg_Warn( p_intf, "adding mrl %s failed", mrl ); vlc_gc_decref( p_input ); } free( psz_uri ); SSPushN( st, i_ret ); free( mrl ); free( psz_name ); } else if( !strcmp( s, "playlist_empty" ) ) { playlist_Clear( p_sys->p_playlist, pl_Unlocked ); msg_Dbg( p_intf, "requested playlist empty" ); } else if( !strcmp( s, "playlist_delete" ) ) { int i_id = SSPopN( st, vars ); playlist_Lock( p_sys->p_playlist ); playlist_item_t *p_item = playlist_ItemGetById( p_sys->p_playlist, i_id ); if( p_item ) { playlist_DeleteFromInput( p_sys->p_playlist, p_item->p_input, pl_Locked ); msg_Dbg( p_intf, "requested playlist delete: %d", i_id ); } else { msg_Dbg( p_intf, "couldn't find playlist item to delete (%d)", i_id ); } playlist_Unlock( p_sys->p_playlist ); } else if( !strcmp( s, "playlist_move" ) ) { /*int i_newpos =*/ SSPopN( st, vars ); /*int i_pos =*/ SSPopN( st, vars ); /* FIXME FIXME TODO TODO XXX XXX do not release before fixing this if ( i_pos < i_newpos ) { playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 ); } else { playlist_Move( p_sys->p_playlist, i_pos, i_newpos ); } msg_Dbg( p_intf, "requested to move playlist item %d to %d", i_pos, i_newpos); FIXME FIXME TODO TODO XXX XXX */ msg_Err( p_intf, "moving using indexes is obsolete. We need to update this function" ); } else if( !strcmp( s, "playlist_sort" ) ) { int i_order = SSPopN( st, vars ); int i_sort = SSPopN( st, vars ); i_order = i_order % 2; i_sort = i_sort % 9; /* FIXME FIXME TODO TODO XXX XXX do not release before fixing this playlist_RecursiveNodeSort( p_sys->p_playlist, p_sys->p_playlist->p_general, i_sort, i_order ); msg_Dbg( p_intf, "requested sort playlist by : %d in order : %d", i_sort, i_order ); FIXME FIXME TODO TODO XXX XXX */ msg_Err( p_intf, "this needs to be fixed to use the new playlist framework" ); } else if( !strcmp( s, "services_discovery_add" ) ) { char *psz_sd = SSPop( st ); playlist_ServicesDiscoveryAdd( p_sys->p_playlist, psz_sd ); free( psz_sd ); } else if( !strcmp( s, "services_discovery_remove" ) ) { char *psz_sd = SSPop( st ); playlist_ServicesDiscoveryRemove( p_sys->p_playlist, psz_sd ); free( psz_sd ); } else if( !strcmp( s, "services_discovery_is_loaded" ) ) { char *psz_sd = SSPop( st ); SSPushN( st, playlist_IsServicesDiscoveryLoaded( p_sys->p_playlist, psz_sd ) ); free( psz_sd ); } else if( !strcmp( s, "vlc_volume_set" ) ) { char *psz_vol = SSPop( st ); int i_value; audio_volume_t i_volume; aout_VolumeGet( p_intf, &i_volume ); if( psz_vol[0] == '+' ) { i_value = atoi( psz_vol ); if( (i_volume + i_value) > AOUT_VOLUME_MAX ) aout_VolumeSet( p_intf, AOUT_VOLUME_MAX ); else aout_VolumeSet( p_intf, i_volume + i_value ); } else if( psz_vol[0] == '-' ) { i_value = atoi( psz_vol ); if( (i_volume + i_value) < AOUT_VOLUME_MIN ) aout_VolumeSet( p_intf, AOUT_VOLUME_MIN ); else aout_VolumeSet( p_intf, i_volume + i_value ); } else if( strstr( psz_vol, "%") != NULL ) { i_value = atoi( psz_vol ); if( i_value < 0 ) i_value = 0; if( i_value > 400 ) i_value = 400; aout_VolumeSet( p_intf, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/400+AOUT_VOLUME_MIN); } else { i_value = atoi( psz_vol ); if( i_value > AOUT_VOLUME_MAX ) i_value = AOUT_VOLUME_MAX; if( i_value < AOUT_VOLUME_MIN ) i_value = AOUT_VOLUME_MIN; aout_VolumeSet( p_intf, i_value ); } aout_VolumeGet( p_intf, &i_volume ); free( psz_vol ); } else if( !strcmp( s, "vlc_get_meta" ) ) { char *psz_meta = SSPop( st ); char *psz_val = NULL; if( p_sys->p_input && input_GetItem(p_sys->p_input) ) { #define p_item input_GetItem( p_sys->p_input ) if( !strcmp( psz_meta, "ARTIST" ) ) { psz_val = input_item_GetArtist( p_item ); } else if( !strcmp( psz_meta, "TITLE" ) ) { psz_val = input_item_GetTitle( p_item ); if( !psz_val ) psz_val = input_item_GetName( p_item ); } else if( !strcmp( psz_meta, "ALBUM" ) ) { psz_val = input_item_GetAlbum( p_item ); } else if( !strcmp( psz_meta, "GENRE" ) ) { psz_val = input_item_GetGenre( p_item ); } else if( !strcmp( psz_meta, "COPYRIGHT" ) ) { psz_val = input_item_GetCopyright( p_item ); } else if( !strcmp( psz_meta, "TRACK_NUMBER" ) ) { psz_val = input_item_GetTrackNum( p_item ); } else if( !strcmp( psz_meta, "DESCRIPTION" ) ) { psz_val = input_item_GetDescription( p_item ); } else if( !strcmp( psz_meta, "RATING" ) ) { psz_val = input_item_GetRating( p_item ); } else if( !strcmp( psz_meta, "DATE" ) ) { psz_val = input_item_GetDate( p_item ); } else if( !strcmp( psz_meta, "URL" ) ) { psz_val = input_item_GetURL( p_item ); } else if( !strcmp( psz_meta, "LANGUAGE" ) ) { psz_val = input_item_GetLanguage( p_item ); } else if( !strcmp( psz_meta, "NOW_PLAYING" ) ) { psz_val = input_item_GetNowPlaying( p_item ); } else if( !strcmp( psz_meta, "PUBLISHER" ) ) { psz_val = input_item_GetPublisher( p_item ); } else if( !strcmp( psz_meta, "ENCODED_BY" ) ) { psz_val = input_item_GetEncodedBy( p_item ); } else if( !strcmp( psz_meta, "ART_URL" ) ) { psz_val = input_item_GetEncodedBy( p_item ); } else if( !strcmp( psz_meta, "TRACK_ID" ) ) { psz_val = input_item_GetTrackID( p_item ); } #undef p_item } if( psz_val == NULL ) psz_val = strdup( "" ); SSPush( st, psz_val ); free( psz_meta ); free( psz_val ); } #ifdef ENABLE_VLM else if( !strcmp( s, "vlm_command" ) || !strcmp( s, "vlm_cmd" ) ) { char *psz_elt; char *psz_cmd = strdup( "" ); char *psz_error; vlm_message_t *vlm_answer; /* make sure that we have a vlm object */ if( p_intf->p_sys->p_vlm == NULL ) p_intf->p_sys->p_vlm = vlm_New( p_intf ); /* vlm command uses the ';' delimiter * (else we can't know when to stop) */ while( strcmp( psz_elt = SSPop( st ), "" ) && strcmp( psz_elt, ";" ) ) { char* psz_buf; if( asprintf( &psz_buf, "%s %s", psz_cmd, psz_elt ) == -1 ) psz_buf = NULL; free( psz_cmd ); free( psz_elt ); psz_cmd = psz_buf; } msg_Dbg( p_intf, "executing vlm command: %s", psz_cmd ); vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz_cmd, &vlm_answer ); if( vlm_answer->psz_value == NULL ) { psz_error = strdup( "" ); } else { if( asprintf( &psz_error , "%s : %s" , vlm_answer->psz_name, vlm_answer->psz_value ) == -1 ) psz_error = NULL; } mvar_AppendNewVar( vars, "vlm_error", psz_error ); /* this is kind of a duplicate but we need to have the message * without the command name for the "export" command */ mvar_AppendNewVar( vars, "vlm_value", vlm_answer->psz_value ); vlm_MessageDelete( vlm_answer ); free( psz_cmd ); free( psz_error ); } #endif /* ENABLE_VLM */ else if( !strcmp( s, "snapshot" ) ) { if( p_sys->p_input ) { vout_thread_t *p_vout = input_GetVout( p_sys->p_input ); if( p_vout ) { var_TriggerCallback( p_vout, "video-snapshot" ); vlc_object_release( p_vout ); msg_Dbg( p_intf, "requested snapshot" ); } } break; } else { SSPush( st, s ); } } }