summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-08-25 22:58:29 +0200
committerwm4 <wm4@nowhere>2013-08-26 10:09:46 +0200
commit3fc3bf70f972f4e68258193f0f9c70ee6b85be5e (patch)
tree7c953cee512669da24d83c1b6ffefce74f3ddc53 /stream/stream.c
parent74b846e2f7d95e4dea2fdae4b1301a2c83f2acd3 (diff)
downloadmpv-3fc3bf70f972f4e68258193f0f9c70ee6b85be5e.tar.bz2
mpv-3fc3bf70f972f4e68258193f0f9c70ee6b85be5e.tar.xz
stream: add uncompressed rar support
Apparently, it is popular to store large files in uncompressed rar archives. Extracting files is not practical, and some media players suport playing directly from uncompressed rar (at least VLC and some DirectShow components). Storing or accessing files this way is completely idiotic, but it is a common practice, and the ones subjected to this practice can't do much to change this (at least that's what I assume/hope). Also, it's a feature request, so we say yes. This code is mostly taken from VLC (commit f6e7240 from their git tree). We also copy the way this is done: opening a rar file by itself yields a playlist, which contains URLs to the actual entries in the rar file. Compressed entries are simply skipped.
Diffstat (limited to 'stream/stream.c')
-rw-r--r--stream/stream.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 474e46d96a..ebd582de73 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -75,6 +75,8 @@ extern const stream_info_t stream_info_file;
extern const stream_info_t stream_info_ifo;
extern const stream_info_t stream_info_dvd;
extern const stream_info_t stream_info_bluray;
+extern const stream_info_t stream_info_rar_filter;
+extern const stream_info_t stream_info_rar_entry;
static const stream_info_t *const stream_list[] = {
#ifdef CONFIG_VCD
@@ -111,6 +113,8 @@ static const stream_info_t *const stream_list[] = {
&stream_info_memory,
&stream_info_null,
&stream_info_mf,
+ &stream_info_rar_filter,
+ &stream_info_rar_entry,
&stream_info_file,
NULL
};
@@ -148,6 +152,36 @@ void mp_url_unescape_inplace(char *buf)
buf[o++] = '\0';
}
+// Escape according to http://tools.ietf.org/html/rfc3986#section-2.1
+// Only unreserved characters are not escaped.
+// The argument ok (if not NULL) is as follows:
+// ok[0] != '~': additional characters that are not escaped
+// ok[0] == '~': do not escape anything but these characters
+// (can't override the unreserved characters, which are
+// never escaped, and '%', which is always escaped)
+char *mp_url_escape(void *talloc_ctx, const char *s, const char *ok)
+{
+ int len = strlen(s);
+ char *buf = talloc_array(talloc_ctx, char, len * 3 + 1);
+ int o = 0;
+ for (int i = 0; i < len; i++) {
+ unsigned char c = s[i];
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') || strchr("-._~", c) ||
+ (ok && ((ok[0] != '~') == !!strchr(ok, c)) && c != '%'))
+ {
+ buf[o++] = c;
+ } else {
+ const char hex[] = "0123456789ABCDEF";
+ buf[o++] = '%';
+ buf[o++] = hex[c / 16];
+ buf[o++] = hex[c % 16];
+ }
+ }
+ buf[o++] = '\0';
+ return buf;
+}
+
static const char *find_url_opt(struct stream *s, const char *opt)
{
for (int n = 0; s->info->url_options && s->info->url_options[n]; n++) {