summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-08-02 17:03:30 +0200
committerwm4 <wm4@nowhere>2013-08-02 17:05:26 +0200
commit44d6ac06aed7c13cbace543920e706023551c3c2 (patch)
treef2b352e856c7b4286f873b1cd2f5a9a6465774b2 /stream/stream.c
parentf8589c98891b11eea249c998b1dc2fac50c99b46 (diff)
downloadmpv-44d6ac06aed7c13cbace543920e706023551c3c2.tar.bz2
mpv-44d6ac06aed7c13cbace543920e706023551c3c2.tar.xz
stream: parse URL escapes for file://
So for example "file:///file%20name.mkv" will open "file name.mkv". I'm not sure whether we want/need this. The old code didn't do it. Also, it's not really clear whether this is handled correctly. It seems the corresponding freedesktop.org "standard" allows a (useless) hostname part, which we should skip in theory. The number of slashes is not really clear either. We can open relative filenames (by removing one of the slashes from the example above), which is perhaps an unneeded feature. How does this even work with Windows paths? This issues can probably be corrected later. The URL unescape code is based on code from m_option.c removed with a recent commit.
Diffstat (limited to 'stream/stream.c')
-rw-r--r--stream/stream.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/stream/stream.c b/stream/stream.c
index a4d9238d46..4160e7267e 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -116,6 +116,37 @@ static const stream_info_t *const auto_open_streams[] = {
static int stream_seek_unbuffered(stream_t *s, int64_t newpos);
+static int from_hex(unsigned char c)
+{
+ if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+ if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ return -1;
+}
+
+// Replace escape sequences in an URL (or a part of an URL)
+void mp_url_unescape_inplace(char *buf)
+{
+ int len = strlen(buf);
+ int o = 0;
+ for (int i = 0; i < len; i++) {
+ unsigned char c = buf[i];
+ if (c == '%' && i + 2 < len) { //must have 2 more chars
+ int c1 = from_hex(buf[i + 1]);
+ int c2 = from_hex(buf[i + 2]);
+ if (c1 >= 0 && c2 >= 0) {
+ c = c1 * 16 + c2;
+ i = i + 2; //only skip next 2 chars if valid esc
+ }
+ }
+ buf[o++] = c;
+ }
+ buf[o++] = '\0';
+}
+
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][0]; n++) {