diff options
author | phintuka <phintuka> | 2007-06-18 08:53:31 +0000 |
---|---|---|
committer | phintuka <phintuka> | 2007-06-18 08:53:31 +0000 |
commit | 855b2542c52027476dd0dec4e707543cf2dd579d (patch) | |
tree | 03151d588cb182abf9f3db5520ae9024c704ca5b /tools/playlist.c | |
parent | cd3736a815f0048c5e6b63bc8459c02ba9d4bcdb (diff) | |
download | xineliboutput-855b2542c52027476dd0dec4e707543cf2dd579d.tar.gz xineliboutput-855b2542c52027476dd0dec4e707543cf2dd579d.tar.bz2 |
Added EscapeMrl()
Diffstat (limited to 'tools/playlist.c')
-rw-r--r-- | tools/playlist.c | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/tools/playlist.c b/tools/playlist.c index 7e66548d..c1625ecd 100644 --- a/tools/playlist.c +++ b/tools/playlist.c @@ -4,7 +4,7 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: playlist.c,v 1.5 2007-01-04 13:49:10 phintuka Exp $ + * $Id: playlist.c,v 1.6 2007-06-18 08:53:31 phintuka Exp $ * */ @@ -825,5 +825,64 @@ bool cPlaylist::Read(const char *PlaylistFile, bool Recursive) return Result; } +cString cPlaylist::EscapeMrl(const char *mrl) +{ + static const uint8_t hex[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; + const uint8_t *fn = (const uint8_t*)mrl; + int size = strlen(mrl) + 16; + uint8_t *buf = (uint8_t*)malloc(size); + int i = 0, found = 0; + LOGDBG("cPlaylist::EscapeMrl('%s')", fn); + + // Wait for first '/' (do not escape mrl start dvd:/, http://a@b/, ...) + if (*fn == '/') + found = 3; + + while (*fn) { + if(size-7 < i) + buf = (uint8_t *)realloc(buf, (size=size+16)); + switch (*fn) { + case 1 ... ' ': + case 127 ... 255: + case '#': + case '%': + case ':': + case ';': + case '\'': + case '\"': + case '(': + case ')': + if (found > 2) { + buf[i++] = '%'; + buf[i++] = hex[(*fn & 0xf0)>>4]; + buf[i++] = hex[(*fn & 0x0f)]; + break; + } + default: + // file:/... -> only one '/' before escaping + // http://.../ --> three '/' before escaping + if(!found && (fn[0] == ':' && fn[1] == '/')) { + if(fn[2] == '/') { + // ex. http://user:pass@host/... --> wait for third '/' + buf[i++] = *fn++; + buf[i++] = *fn++; + found += 2; + } else { + // ex. file:/local_file + buf[i++] = *fn++; + found += 3; + } + } else if(*fn == '/') { + found++; + } + buf[i++] = *fn; + break; + } + fn++; + } + buf[i] = 0; + LOGDBG(" --> '%s'", buf); + return cString((const char*)buf, true); +} |