# HG changeset patch # User William Pitcock # Date 1190657343 18000 # Node ID 71698fb39d2979c6332d2fe77e6fb4bf468c2392 # Parent 6bc14eddc4c30a3c0c5f641c8ca4fb388eb9bcf0 xspf: decruftify and Mk2 diff -r 6bc14eddc4c3 -r 71698fb39d29 src/xspf/Makefile --- a/src/xspf/Makefile Mon Sep 24 13:06:11 2007 -0500 +++ b/src/xspf/Makefile Mon Sep 24 13:09:03 2007 -0500 @@ -1,18 +1,12 @@ -include ../../mk/rules.mk -include ../../mk/init.mk +PLUGIN = xspf$(PLUGIN_SUFFIX) +plugindir = audacious/$(CONTAINER_PLUGIN_DIR) -OBJECTIVE_LIBS = libxspf$(SHARED_SUFFIX) - -LIBDIR = $(plugindir)/$(CONTAINER_PLUGIN_DIR) - -SOURCES = xspf.c +SRCS = xspf.c -OBJECTS = ${SOURCES:.c=.o} - -CFLAGS += $(PICFLAGS) $(GTK_CFLAGS) $(GLIB_CFLAGS) $(PANGO_CFLAGS) $(ARCH_DEFINES) $(XML_CPPFLAGS) -I../../intl -I../.. -Wall +include ../../buildsys.mk +include ../../extra.mk -CXXFLAGS = $(CFLAGS) - -LIBADD = $(GTK_LIBS) $(GLIB_LIBS) $(PANGO_LIBS) $(XML_LIBS) - -include ../../mk/objective.mk +CFLAGS += $(PLUGIN_CFLAGS) +CPPFLAGS += $(PLUGIN_CPPFLAGS) $(MOWGLI_CFLAGS) $(DBUS_CFLAGS) $(GTK_CFLAGS) $(GLIB_CFLAGS) $(PANGO_CFLAGS) $(ARCH_DEFINES) $(XML_CPPFLAGS) \ + -I../../intl -I../.. -Wall +LIBS += $(GTK_LIBS) $(GLIB_LIBS) $(PANGO_LIBS) $(XML_LIBS) diff -r 6bc14eddc4c3 -r 71698fb39d29 src/xspf/base64.c --- a/src/xspf/base64.c Mon Sep 24 13:06:11 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -/** - * \file base64.c - * \brief base-64 conversion routines. - * - * \author Eric S. Raymond . - * - * For license terms, see the file COPYING. - * - * This base 64 encoding is defined in RFC2045 section 6.8, - * "Base64 Content-Transfer-Encoding", but lines must not be broken in the - * scheme used here. - */ -#include - - -static const char base64digits[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -#define BAD -1 -static const char base64val[] = { - BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, - BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, - BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD, 62, BAD,BAD,BAD, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,BAD,BAD, BAD,BAD,BAD,BAD, - BAD, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,BAD, BAD,BAD,BAD,BAD, - BAD, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,BAD, BAD,BAD,BAD,BAD -}; -#define DECODE64(c) (isascii(c) ? base64val[c] : BAD) - -/** - * \brief Raw bytes in quasi-big-endian order to base 64 string (NUL-terminated) - * - * \param[out] out A pointer to a char to hold the converted string - * \param[in] in String to convert - * \param[in] inlen Length of the string to be converted - */ -void to64frombits(unsigned char *out, const unsigned char *in, int inlen) -{ - for (; inlen >= 3; inlen -= 3) - { - *out++ = base64digits[in[0] >> 2]; - *out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)]; - *out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; - *out++ = base64digits[in[2] & 0x3f]; - in += 3; - } - - if (inlen > 0) - { - unsigned char fragment; - - *out++ = base64digits[in[0] >> 2]; - fragment = (in[0] << 4) & 0x30; - - if (inlen > 1) - fragment |= in[1] >> 4; - - *out++ = base64digits[fragment]; - *out++ = (inlen < 2) ? '=' : base64digits[(in[1] << 2) & 0x3c]; - *out++ = '='; - } - - *out = '\0'; -} - -/** - * \brief base 64 to raw bytes in quasi-big-endian order, returning count of bytes - * - * \param[out] out Where to save the converted string - * \param[in] in String to convert - * \return Number of converted bytes. - */ -int from64tobits(char *out, const char *in) -{ - int len = 0; - register unsigned char digit1, digit2, digit3, digit4; - - if (in[0] == '+' && in[1] == ' ') - in += 2; - if (*in == '\r') - return(0); - - do { - digit1 = in[0]; - if (DECODE64(digit1) == BAD) - return(-1); - digit2 = in[1]; - if (DECODE64(digit2) == BAD) - return(-1); - digit3 = in[2]; - if (digit3 != '=' && DECODE64(digit3) == BAD) - return(-1); - digit4 = in[3]; - if (digit4 != '=' && DECODE64(digit4) == BAD) - return(-1); - in += 4; - *out++ = (DECODE64(digit1) << 2) | (DECODE64(digit2) >> 4); - ++len; - if (digit3 != '=') - { - *out++ = ((DECODE64(digit2) << 4) & 0xf0) | (DECODE64(digit3) >> 2); - ++len; - if (digit4 != '=') - { - *out++ = ((DECODE64(digit3) << 6) & 0xc0) | DECODE64(digit4); - ++len; - } - } - } while (*in && *in != '\r' && digit4 != '='); - - return (len); -} diff -r 6bc14eddc4c3 -r 71698fb39d29 src/xspf/base64.h --- a/src/xspf/base64.h Mon Sep 24 13:06:11 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -/** - * \file base64.h - * \brief This file has all base64.c declarations - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * See COPYING for details. - */ - -#ifndef BASE64_H_ -#define BASE64_H_ - -void to64frombits(unsigned char*,const unsigned char*,int); -int from64tobits(char*,const char*); - -#endif /* BASE64_H_ */ diff -r 6bc14eddc4c3 -r 71698fb39d29 src/xspf/urlencode.c --- a/src/xspf/urlencode.c Mon Sep 24 13:06:11 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,159 +0,0 @@ -/* the original code was taken from wget-1.10.2 */ - -#include -#include -#include -#include -#include -#include "urlencode.h" - -enum { - /* rfc1738 reserved chars + "$" and ",". */ - urlchr_reserved = 1, - - /* rfc1738 unsafe chars, plus non-printables. */ - urlchr_unsafe = 2 -}; - -#define urlchr_test(c, mask) (urlchr_table[(unsigned char)(c)] & (mask)) -#define URL_RESERVED_CHAR(c) urlchr_test(c, urlchr_reserved) -#define URL_UNSAFE_CHAR(c) urlchr_test(c, urlchr_unsafe) -#define XNUM_TO_DIGIT(x) ("0123456789ABCDEF"[x] + 0) -#define ISXDIGIT(x) (isxdigit((unsigned char)(x))) -#define X2DIGITS_TO_NUM(h1, h2) ((XDIGIT_TO_NUM (h1) << 4) + XDIGIT_TO_NUM (h2)) -#define XDIGIT_TO_NUM(h) ((h) < 'A' ? (h) - '0' : toupper (h) - 'A' + 10) - -/* Shorthands for the table: */ -#define R urlchr_reserved -#define U urlchr_unsafe -#define RU R|U - -static const unsigned char urlchr_table[256] = -{ - U, U, U, U, U, U, U, U, /* NUL SOH STX ETX EOT ENQ ACK BEL */ - U, U, U, U, U, U, U, U, /* BS HT LF VT FF CR SO SI */ - U, U, U, U, U, U, U, U, /* DLE DC1 DC2 DC3 DC4 NAK SYN ETB */ - U, U, U, U, U, U, U, U, /* CAN EM SUB ESC FS GS RS US */ - U, 0, U, RU, R, U, R, 0, /* SP ! " # $ % & ' */ - 0, 0, 0, R, R, 0, 0, R, /* ( ) * + , - . / */ - 0, 0, 0, 0, 0, 0, 0, 0, /* 0 1 2 3 4 5 6 7 */ - 0, 0, RU, R, U, R, U, R, /* 8 9 : ; < = > ? */ - RU, 0, 0, 0, 0, 0, 0, 0, /* @ A B C D E F G */ - 0, 0, 0, 0, 0, 0, 0, 0, /* H I J K L M N O */ - 0, 0, 0, 0, 0, 0, 0, 0, /* P Q R S T U V W */ - 0, 0, 0, RU, U, RU, U, 0, /* X Y Z [ \ ] ^ _ */ - U, 0, 0, 0, 0, 0, 0, 0, /* ` a b c d e f g */ - 0, 0, 0, 0, 0, 0, 0, 0, /* h i j k l m n o */ - 0, 0, 0, 0, 0, 0, 0, 0, /* p q r s t u v w */ - 0, 0, 0, U, U, U, 0, U, /* x y z { | } ~ DEL */ - - U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, - U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, - U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, - U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, - - U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, - U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, - U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, - U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, -}; -#undef R -#undef U -#undef RU - -/* URL-unescape the string S. - - This is done by transforming the sequences "%HH" to the character - represented by the hexadecimal digits HH. If % is not followed by - two hexadecimal digits, it is inserted literally. - - The transformation is done in place. If you need the original - string intact, make a copy before calling this function. */ - -char * -xspf_url_decode (const char *s) -{ - char *copy = strdup(s); - char *t = copy; /* t - tortoise */ - char *h = copy; /* h - hare */ - - for (; *h; h++, t++) - { - if (*h != '%') - { - copychar: - *t = *h; - } - else - { - char c; - /* Do nothing if '%' is not followed by two hex digits. */ - if (!h[1] || !h[2] || !(ISXDIGIT (h[1]) && ISXDIGIT (h[2]))) - goto copychar; - c = X2DIGITS_TO_NUM (h[1], h[2]); - /* Don't unescape %00 because there is no way to insert it - into a C string without effectively truncating it. */ - if (c == '\0') - goto copychar; - *t = c; - h += 2; - } - } - *t = '\0'; - return copy; -} - -/* The core of url_escape_* functions. Escapes the characters that - match the provided mask in urlchr_table. - - If ALLOW_PASSTHROUGH is non-zero, a string with no unsafe chars - will be returned unchanged. If ALLOW_PASSTHROUGH is zero, a - freshly allocated string will be returned in all cases. */ - -static char * -url_escape_1 (const char *s, unsigned char mask, int allow_passthrough) -{ - const char *p1; - char *p2, *newstr; - int newlen; - int addition = 0; - - for (p1 = s; *p1; p1++) - if (urlchr_test (*p1, mask)) - addition += 2; /* Two more characters (hex digits) */ - - if (!addition) - return allow_passthrough ? (char *)s : strdup (s); - - newlen = (p1 - s) + addition; - newstr = (char *)malloc (newlen + 1); - - p1 = s; - p2 = newstr; - while (*p1) - { - /* Quote the characters that match the test mask. */ - if (urlchr_test (*p1, mask)) - { - unsigned char c = *p1++; - *p2++ = '%'; - *p2++ = XNUM_TO_DIGIT (c >> 4); - *p2++ = XNUM_TO_DIGIT (c & 0xf); - } - else - *p2++ = *p1++; - } - g_return_val_if_fail (p2 - newstr == newlen, NULL); - *p2 = '\0'; - - return newstr; -} - -/* URL-escape the unsafe characters (see urlchr_table) in a given - string, returning a freshly allocated string. */ - -char * -xspf_url_encode (const char *s) -{ - return url_escape_1 (s, urlchr_unsafe, 0); -} diff -r 6bc14eddc4c3 -r 71698fb39d29 src/xspf/urlencode.h --- a/src/xspf/urlencode.h Mon Sep 24 13:06:11 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -/* prototypes */ - -char *xspf_url_decode(const char *url); -char *xspf_url_encode(const char *path);