mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00:00
mpv has a very weak and very annoying policy that determines whether a playlist should be used or not. For example, if you play a remote playlist, you usually don't want it to be able to read local filesystem entries. (Although for a media player the impact is small I guess.) It's weak and annoying as in that it does not prevent certain cases which could be interpreted as bad in some cases, such as allowing playlists on the local filesystem to reference remote URLs. It probably barely makes sense, but we just want to exclude some other "definitely not a good idea" things, all while playlists generally just work, so whatever. The policy is: - from the command line anything is played - local playlists can reference anything except "unsafe" streams ("unsafe" means special stream inputs like libavfilter graphs) - remote playlists can reference only remote URLs - things like "memory://" and archives are "transparent" to this This commit does... something. It replaces the weird stream flags with a slightly clearer "origin" value, which is now consequently passed down and used everywhere. It fixes some deviations from the described policy. I wanted to force archives to reference only content within them, but this would probably have been more complicated (or required different abstractions), and I'm too lazy to figure it out, so archives are now "transparent" (playlists within archives behave the same outside). There may be a lot of bugs in this. This is unfortunately a very noisy commit because: - every stream open call now needs to pass the origin - so does every demuxer open call (=> params param. gets mandatory) - most stream were changed to provide the "origin" value - the origin value needed to be passed along in a lot of places - I was too lazy to split the commit Fixes: #7274
102 lines
2.9 KiB
C
102 lines
2.9 KiB
C
/*
|
|
* This file is part of mpv.
|
|
*
|
|
* mpv is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* mpv is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <archive.h>
|
|
#include <archive_entry.h>
|
|
|
|
#include "common/common.h"
|
|
#include "common/playlist.h"
|
|
#include "stream/stream.h"
|
|
#include "misc/natural_sort.h"
|
|
#include "demux.h"
|
|
|
|
#include "stream/stream_libarchive.h"
|
|
|
|
static int cmp_filename(const void *a, const void *b)
|
|
{
|
|
return mp_natural_sort_cmp(*(char **)a, *(char **)b);
|
|
}
|
|
|
|
static int open_file(struct demuxer *demuxer, enum demux_check check)
|
|
{
|
|
if (!demuxer->access_references)
|
|
return -1;
|
|
|
|
int flags = 0;
|
|
int probe_size = STREAM_BUFFER_SIZE;
|
|
if (check <= DEMUX_CHECK_REQUEST) {
|
|
flags |= MP_ARCHIVE_FLAG_UNSAFE;
|
|
probe_size *= 100;
|
|
}
|
|
|
|
void *probe = ta_alloc_size(NULL, probe_size);
|
|
if (!probe)
|
|
return -1;
|
|
int probe_got = stream_read_peek(demuxer->stream, probe, probe_size);
|
|
struct stream *probe_stream =
|
|
stream_memory_open(demuxer->global, probe, probe_got);
|
|
struct mp_archive *mpa = mp_archive_new(mp_null_log, probe_stream, flags);
|
|
bool ok = !!mpa;
|
|
free_stream(probe_stream);
|
|
mp_archive_free(mpa);
|
|
ta_free(probe);
|
|
if (!ok)
|
|
return -1;
|
|
|
|
mpa = mp_archive_new(demuxer->log, demuxer->stream, flags);
|
|
if (!mpa)
|
|
return -1;
|
|
|
|
struct playlist *pl = talloc_zero(demuxer, struct playlist);
|
|
demuxer->playlist = pl;
|
|
|
|
char *prefix = mp_url_escape(mpa, demuxer->stream->url, "~|");
|
|
|
|
char **files = NULL;
|
|
int num_files = 0;
|
|
|
|
while (mp_archive_next_entry(mpa)) {
|
|
// stream_libarchive.c does the real work
|
|
char *f = talloc_asprintf(mpa, "archive://%s|/%s", prefix,
|
|
mpa->entry_filename);
|
|
MP_TARRAY_APPEND(mpa, files, num_files, f);
|
|
}
|
|
|
|
if (files)
|
|
qsort(files, num_files, sizeof(files[0]), cmp_filename);
|
|
|
|
for (int n = 0; n < num_files; n++)
|
|
playlist_add_file(pl, files[n]);
|
|
|
|
for (struct playlist_entry *e = pl->first; e; e = e->next)
|
|
e->stream_flags = demuxer->stream_origin;
|
|
|
|
demuxer->filetype = "archive";
|
|
demuxer->fully_read = true;
|
|
|
|
mp_archive_free(mpa);
|
|
demux_close_stream(demuxer);
|
|
|
|
return 0;
|
|
}
|
|
|
|
const struct demuxer_desc demuxer_desc_libarchive = {
|
|
.name = "libarchive",
|
|
.desc = "libarchive wrapper",
|
|
.open = open_file,
|
|
};
|