diff options
author | Alexey Yakovenko <waker@users.sourceforge.net> | 2014-06-22 21:55:26 +0200 |
---|---|---|
committer | Alexey Yakovenko <waker@users.sourceforge.net> | 2014-06-22 21:56:20 +0200 |
commit | 51993c5f565db1984c3b2b6de6fc0bf70d710f98 (patch) | |
tree | 8c12ae6edf3073e303b05f9ab407d12f6185f93f | |
parent | 42589a768d7c83e06724299c9f5b317748ad0334 (diff) |
added uri support to plt_insert_file_int, improved pls parser
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | escape.c | 172 | ||||
-rw-r--r-- | escape.h | 29 | ||||
-rw-r--r-- | playlist.c | 11 | ||||
-rw-r--r-- | plugins/artwork/escape.h | 34 | ||||
-rw-r--r-- | plugins/m3u/m3u.c | 7 |
6 files changed, 237 insertions, 19 deletions
diff --git a/Makefile.am b/Makefile.am index c0432f5d..10ad52fe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,7 +39,8 @@ deadbeef_SOURCES =\ replaygain.c replaygain.h\ fft.c fft.h\ handler.c handler.h\ - strdupa.h + strdupa.h\ + escape.c escape.h # ConvertUTF/ConvertUTF.c ConvertUTF/ConvertUTF.h diff --git a/escape.c b/escape.c new file mode 100644 index 00000000..3a113d6e --- /dev/null +++ b/escape.c @@ -0,0 +1,172 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* Escape and unescape URL encoding in strings. The functions return a new + * allocated string or NULL if an error occurred. */ + +#include <ctype.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/* Portable character check (remember EBCDIC). Do not use isalnum() because + its behavior is altered by the current locale. + See http://tools.ietf.org/html/rfc3986#section-2.3 +*/ +static int Curl_isunreserved(unsigned char in) +{ + switch (in) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': + case '-': case '.': case '_': case '~': + return 1; + default: + break; + } + return 0; +} + +char *uri_escape(const char *string, int inlength) +{ + size_t alloc = (inlength?(size_t)inlength:strlen(string))+1; + char *ns; + char *testing_ptr = NULL; + unsigned char in; /* we need to treat the characters unsigned */ + size_t newlen = alloc; + int strindex=0; + size_t length; + + ns = malloc(alloc); + if(!ns) + return NULL; + + length = alloc-1; + while(length--) { + in = *string; + + if (Curl_isunreserved(in)) { + /* just copy this */ + ns[strindex++]=in; + } + else { + /* encode it */ + newlen += 2; /* the size grows with two, since this'll become a %XX */ + if(newlen > alloc) { + alloc *= 2; + testing_ptr = realloc(ns, alloc); + if(!testing_ptr) { + free( ns ); + return NULL; + } + else { + ns = testing_ptr; + } + } + + snprintf(&ns[strindex], 4, "%%%02X", in); + + strindex+=3; + } + string++; + } + ns[strindex]=0; /* terminate it */ + return ns; +} + +#define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x))) +#define CURL_MASK_UCHAR 0xFF + +/* +** unsigned long to unsigned char +*/ + +unsigned char curlx_ultouc(unsigned long ulnum) +{ +#ifdef __INTEL_COMPILER +# pragma warning(push) +# pragma warning(disable:810) /* conversion may lose significant bits */ +#endif + + return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR); + +#ifdef __INTEL_COMPILER +# pragma warning(pop) +#endif +} + +char *uri_unescape(const char *string, int length) +{ + int alloc = (length?length:(int)strlen(string))+1; + char *ns = malloc(alloc); + unsigned char in; + int strindex=0; + unsigned long hex; + + if( !ns ) + return NULL; + + while(--alloc > 0) { + in = *string; + if(('%' == in) && ISXDIGIT(string[1]) && ISXDIGIT(string[2])) { + /* this is two hexadecimal digits following a '%' */ + char hexstr[3]; + char *ptr; + hexstr[0] = string[1]; + hexstr[1] = string[2]; + hexstr[2] = 0; + + hex = strtoul(hexstr, &ptr, 16); + + in = curlx_ultouc(hex); /* this long is never bigger than 255 anyway */ + +#ifdef CURL_DOES_CONVERSIONS +/* escape sequences are always in ASCII so convert them on non-ASCII hosts */ + if(!handle || + (Curl_convert_from_network(handle, &in, 1) != CURLE_OK)) { + /* Curl_convert_from_network calls failf if unsuccessful */ + free(ns); + return NULL; + } +#endif /* CURL_DOES_CONVERSIONS */ + + string+=2; + alloc-=2; + } + + ns[strindex++] = in; + string++; + } + ns[strindex]=0; /* terminate it */ + + return ns; +} diff --git a/escape.h b/escape.h new file mode 100644 index 00000000..7d3be795 --- /dev/null +++ b/escape.h @@ -0,0 +1,29 @@ +/* + DeaDBeeF -- the music player + Copyright (C) 2009-2014 Alexey Yakovenko and other contributors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ +#ifndef __ESCAPE_H +#define __ESCAPE_H + +char *uri_escape(const char *string, int inlength); +char *uri_unescape(const char *string, int inlength); + +#endif @@ -61,6 +61,7 @@ #include "metacache.h" #include "volume.h" #include "pltmeta.h" +#include "escape.h" // disable custom title function, until we have new title formatting (0.7) #define DISABLE_CUSTOM_TITLE @@ -87,8 +88,8 @@ #error writing playlists in format <1.2 is not supported #endif -//#define trace(...) { fprintf(stderr, __VA_ARGS__); } -#define trace(fmt,...) +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(fmt,...) #define SKIP_BLANK_CUE_TRACKS 0 #define MAX_CUE_TRACKS 99 @@ -1377,7 +1378,13 @@ plt_insert_file_int (int visibility, playlist_t *playlist, playItem_t *after, co } } else { + char *escaped = uri_unescape (fname, strlen (fname)); + if (escaped) { + fname = strdupa (escaped); + free (escaped); + } fname += 7; + printf ("escaped filename: %s\n", fname); } // detect decoder diff --git a/plugins/artwork/escape.h b/plugins/artwork/escape.h index a8086a89..bd76f4d4 100644 --- a/plugins/artwork/escape.h +++ b/plugins/artwork/escape.h @@ -1,20 +1,24 @@ /* - DeaDBeeF - ultimate music player for GNU/Linux systems with X11 - Copyright (C) 2009-2013 Alexey Yakovenko <waker@users.sourceforge.net> + DeaDBeeF -- the music player + Copyright (C) 2009-2014 Alexey Yakovenko and other contributors - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. */ #ifndef __ESCAPE_H #define __ESCAPE_H diff --git a/plugins/m3u/m3u.c b/plugins/m3u/m3u.c index 9c1372a9..56602c4c 100644 --- a/plugins/m3u/m3u.c +++ b/plugins/m3u/m3u.c @@ -247,6 +247,7 @@ pls_insert_file (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, c const char *slash = NULL; if (strrchr (uri, '/')) { + trace ("pls: inserting from uri: %s\n", uri); it = deadbeef->plt_insert_file2 (0, plt, after, uri, pabort, cb, user_data); } @@ -258,7 +259,7 @@ pls_insert_file (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, c char fullpath[slash - fname + l + 2]; memcpy (fullpath, fname, slash - fname + 1); strcpy (fullpath + (slash - fname + 1), uri); - trace ("pls_insert_file: adding file %s\n", fullpath); + trace ("pls: inserting from calculated relative path: %s\n", fullpath); it = deadbeef->plt_insert_file2 (0, plt, after, fullpath, pabort, cb, user_data); } if (it) { @@ -437,6 +438,10 @@ load_pls (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, int *pab } else { trace ("pls: skipping unrecognized entry in pls file: %s\n", p); + e = p; + while (e < end && *e >= 0x20) { + e++; + } } while (e < end && *e < 0x20) { e++; |