Commit 257a0dee authored by Max Kellermann's avatar Max Kellermann

playlist/*: convert to C++

parent e995cd92
...@@ -96,14 +96,6 @@ mpd_headers = \ ...@@ -96,14 +96,6 @@ mpd_headers = \
src/page.h \ src/page.h \
src/Playlist.hxx \ src/Playlist.hxx \
src/playlist_error.h \ src/playlist_error.h \
src/playlist_plugin.h \
src/playlist/extm3u_playlist_plugin.h \
src/playlist/m3u_playlist_plugin.h \
src/playlist/pls_playlist_plugin.h \
src/playlist/xspf_playlist_plugin.h \
src/playlist/asx_playlist_plugin.h \
src/playlist/rss_playlist_plugin.h \
src/playlist/cue_playlist_plugin.h \
src/poison.h \ src/poison.h \
src/riff.h \ src/riff.h \
src/aiff.h \ src/aiff.h \
...@@ -919,13 +911,21 @@ endif ...@@ -919,13 +911,21 @@ endif
# #
libplaylist_plugins_a_SOURCES = \ libplaylist_plugins_a_SOURCES = \
src/playlist/extm3u_playlist_plugin.c \ src/PlaylistPlugin.hxx \
src/playlist/m3u_playlist_plugin.c \ src/playlist/ExtM3uPlaylistPlugin.cxx \
src/playlist/pls_playlist_plugin.c \ src/playlist/ExtM3uPlaylistPlugin.hxx \
src/playlist/xspf_playlist_plugin.c \ src/playlist/M3uPlaylistPlugin.cxx \
src/playlist/asx_playlist_plugin.c \ src/playlist/M3uPlaylistPlugin.hxx \
src/playlist/rss_playlist_plugin.c \ src/playlist/PlsPlaylistPlugin.cxx \
src/playlist/cue_playlist_plugin.c \ src/playlist/PlsPlaylistPlugin.hxx \
src/playlist/XspfPlaylistPlugin.cxx \
src/playlist/XspfPlaylistPlugin.hxx \
src/playlist/AsxPlaylistPlugin.cxx \
src/playlist/AsxPlaylistPlugin.hxx \
src/playlist/RssPlaylistPlugin.cxx \
src/playlist/RssPlaylistPlugin.hxx \
src/playlist/CuePlaylistPlugin.cxx \
src/playlist/CuePlaylistPlugin.hxx \
src/playlist/EmbeddedCuePlaylistPlugin.cxx \ src/playlist/EmbeddedCuePlaylistPlugin.cxx \
src/playlist/EmbeddedCuePlaylistPlugin.hxx \ src/playlist/EmbeddedCuePlaylistPlugin.hxx \
src/PlaylistRegistry.cxx src/PlaylistRegistry.hxx src/PlaylistRegistry.cxx src/PlaylistRegistry.hxx
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "InputRegistry.hxx" #include "InputRegistry.hxx"
#include "InputPlugin.hxx" #include "InputPlugin.hxx"
#include "PlaylistRegistry.hxx" #include "PlaylistRegistry.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "mpd_error.h" #include "mpd_error.h"
#include "glib_compat.h" #include "glib_compat.h"
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,12 +17,11 @@ ...@@ -17,12 +17,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_PLAYLIST_PLUGIN_H #ifndef MPD_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_PLUGIN_H #define MPD_PLAYLIST_PLUGIN_HXX
#include <glib.h> #include <glib.h>
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
struct config_param; struct config_param;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "PlaylistSong.hxx" #include "PlaylistSong.hxx"
#include "Playlist.hxx" #include "Playlist.hxx"
#include "PlaylistRegistry.hxx" #include "PlaylistRegistry.hxx"
#include "PlaylistPlugin.hxx"
#include "QueuePrint.hxx" #include "QueuePrint.hxx"
#include "SongPrint.hxx" #include "SongPrint.hxx"
#include "DatabaseGlue.hxx" #include "DatabaseGlue.hxx"
...@@ -32,7 +33,6 @@ ...@@ -32,7 +33,6 @@
#include "input_stream.h" #include "input_stream.h"
extern "C" { extern "C" {
#include "playlist_plugin.h"
#include "song.h" #include "song.h"
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "config.h" #include "config.h"
#include "PlaylistQueue.hxx" #include "PlaylistQueue.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "PlaylistAny.hxx" #include "PlaylistAny.hxx"
#include "PlaylistSong.hxx" #include "PlaylistSong.hxx"
#include "Playlist.hxx" #include "Playlist.hxx"
......
...@@ -19,17 +19,17 @@ ...@@ -19,17 +19,17 @@
#include "config.h" #include "config.h"
#include "PlaylistRegistry.hxx" #include "PlaylistRegistry.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "playlist/extm3u_playlist_plugin.h" #include "playlist/ExtM3uPlaylistPlugin.hxx"
#include "playlist/m3u_playlist_plugin.h" #include "playlist/M3uPlaylistPlugin.hxx"
#include "playlist/xspf_playlist_plugin.h" #include "playlist/XspfPlaylistPlugin.hxx"
#include "playlist/LastFMPlaylistPlugin.hxx" #include "playlist/LastFMPlaylistPlugin.hxx"
#include "playlist/DespotifyPlaylistPlugin.hxx" #include "playlist/DespotifyPlaylistPlugin.hxx"
#include "playlist/SoundCloudPlaylistPlugin.hxx" #include "playlist/SoundCloudPlaylistPlugin.hxx"
#include "playlist/pls_playlist_plugin.h" #include "playlist/PlsPlaylistPlugin.hxx"
#include "playlist/asx_playlist_plugin.h" #include "playlist/AsxPlaylistPlugin.hxx"
#include "playlist/rss_playlist_plugin.h" #include "playlist/RssPlaylistPlugin.hxx"
#include "playlist/cue_playlist_plugin.h" #include "playlist/CuePlaylistPlugin.hxx"
#include "playlist/EmbeddedCuePlaylistPlugin.hxx" #include "playlist/EmbeddedCuePlaylistPlugin.hxx"
#include "input_stream.h" #include "input_stream.h"
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
*/ */
#include "config.h" #include "config.h"
#include "playlist/asx_playlist_plugin.h" #include "AsxPlaylistPlugin.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "input_stream.h" #include "input_stream.h"
#include "song.h" #include "song.h"
#include "tag.h" #include "tag.h"
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
/** /**
* This is the state object for the GLib XML parser. * This is the state object for the GLib XML parser.
*/ */
struct asx_parser { struct AsxParser {
/** /**
* The list of songs (in reverse order because that's faster * The list of songs (in reverse order because that's faster
* while adding). * while adding).
...@@ -61,6 +61,11 @@ struct asx_parser { ...@@ -61,6 +61,11 @@ struct asx_parser {
* element. * element.
*/ */
struct song *song; struct song *song;
AsxParser()
:songs(nullptr),
state(ROOT) {}
}; };
static const gchar * static const gchar *
...@@ -81,19 +86,19 @@ asx_start_element(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -81,19 +86,19 @@ asx_start_element(G_GNUC_UNUSED GMarkupParseContext *context,
const gchar **attribute_values, const gchar **attribute_values,
gpointer user_data, G_GNUC_UNUSED GError **error) gpointer user_data, G_GNUC_UNUSED GError **error)
{ {
struct asx_parser *parser = user_data; AsxParser *parser = (AsxParser *)user_data;
switch (parser->state) { switch (parser->state) {
case ROOT: case AsxParser::ROOT:
if (g_ascii_strcasecmp(element_name, "entry") == 0) { if (g_ascii_strcasecmp(element_name, "entry") == 0) {
parser->state = ENTRY; parser->state = AsxParser::ENTRY;
parser->song = song_remote_new("asx:"); parser->song = song_remote_new("asx:");
parser->tag = TAG_NUM_OF_ITEM_TYPES; parser->tag = TAG_NUM_OF_ITEM_TYPES;
} }
break; break;
case ENTRY: case AsxParser::ENTRY:
if (g_ascii_strcasecmp(element_name, "ref") == 0) { if (g_ascii_strcasecmp(element_name, "ref") == 0) {
const gchar *href = get_attribute(attribute_names, const gchar *href = get_attribute(attribute_names,
attribute_values, attribute_values,
...@@ -130,13 +135,13 @@ asx_end_element(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -130,13 +135,13 @@ asx_end_element(G_GNUC_UNUSED GMarkupParseContext *context,
const gchar *element_name, const gchar *element_name,
gpointer user_data, G_GNUC_UNUSED GError **error) gpointer user_data, G_GNUC_UNUSED GError **error)
{ {
struct asx_parser *parser = user_data; AsxParser *parser = (AsxParser *)user_data;
switch (parser->state) { switch (parser->state) {
case ROOT: case AsxParser::ROOT:
break; break;
case ENTRY: case AsxParser::ENTRY:
if (g_ascii_strcasecmp(element_name, "entry") == 0) { if (g_ascii_strcasecmp(element_name, "entry") == 0) {
if (strcmp(parser->song->uri, "asx:") != 0) if (strcmp(parser->song->uri, "asx:") != 0)
parser->songs = g_slist_prepend(parser->songs, parser->songs = g_slist_prepend(parser->songs,
...@@ -144,7 +149,7 @@ asx_end_element(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -144,7 +149,7 @@ asx_end_element(G_GNUC_UNUSED GMarkupParseContext *context,
else else
song_free(parser->song); song_free(parser->song);
parser->state = ROOT; parser->state = AsxParser::ROOT;
} else } else
parser->tag = TAG_NUM_OF_ITEM_TYPES; parser->tag = TAG_NUM_OF_ITEM_TYPES;
...@@ -157,13 +162,13 @@ asx_text(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -157,13 +162,13 @@ asx_text(G_GNUC_UNUSED GMarkupParseContext *context,
const gchar *text, gsize text_len, const gchar *text, gsize text_len,
gpointer user_data, G_GNUC_UNUSED GError **error) gpointer user_data, G_GNUC_UNUSED GError **error)
{ {
struct asx_parser *parser = user_data; AsxParser *parser = (AsxParser *)user_data;
switch (parser->state) { switch (parser->state) {
case ROOT: case AsxParser::ROOT:
break; break;
case ENTRY: case AsxParser::ENTRY:
if (parser->tag != TAG_NUM_OF_ITEM_TYPES) { if (parser->tag != TAG_NUM_OF_ITEM_TYPES) {
if (parser->song->tag == NULL) if (parser->song->tag == NULL)
parser->song->tag = tag_new(); parser->song->tag = tag_new();
...@@ -176,15 +181,17 @@ asx_text(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -176,15 +181,17 @@ asx_text(G_GNUC_UNUSED GMarkupParseContext *context,
} }
static const GMarkupParser asx_parser = { static const GMarkupParser asx_parser = {
.start_element = asx_start_element, asx_start_element,
.end_element = asx_end_element, asx_end_element,
.text = asx_text, asx_text,
nullptr,
nullptr,
}; };
static void static void
song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
{ {
struct song *song = data; struct song *song = (struct song *)data;
song_free(song); song_free(song);
} }
...@@ -192,9 +199,9 @@ song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) ...@@ -192,9 +199,9 @@ song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
static void static void
asx_parser_destroy(gpointer data) asx_parser_destroy(gpointer data)
{ {
struct asx_parser *parser = data; AsxParser *parser = (AsxParser *)data;
if (parser->state >= ENTRY) if (parser->state >= AsxParser::ENTRY)
song_free(parser->song); song_free(parser->song);
g_slist_foreach(parser->songs, song_free_callback, NULL); g_slist_foreach(parser->songs, song_free_callback, NULL);
...@@ -206,7 +213,7 @@ asx_parser_destroy(gpointer data) ...@@ -206,7 +213,7 @@ asx_parser_destroy(gpointer data)
* *
*/ */
struct asx_playlist { struct AsxPlaylist {
struct playlist_provider base; struct playlist_provider base;
GSList *songs; GSList *songs;
...@@ -215,11 +222,8 @@ struct asx_playlist { ...@@ -215,11 +222,8 @@ struct asx_playlist {
static struct playlist_provider * static struct playlist_provider *
asx_open_stream(struct input_stream *is) asx_open_stream(struct input_stream *is)
{ {
struct asx_parser parser = { AsxParser parser;
.songs = NULL, AsxPlaylist *playlist;
.state = ROOT,
};
struct asx_playlist *playlist;
GMarkupParseContext *context; GMarkupParseContext *context;
char buffer[1024]; char buffer[1024];
size_t nbytes; size_t nbytes;
...@@ -264,9 +268,9 @@ asx_open_stream(struct input_stream *is) ...@@ -264,9 +268,9 @@ asx_open_stream(struct input_stream *is)
return NULL; return NULL;
} }
/* create a #asx_playlist object from the parsed song list */ /* create a #AsxPlaylist object from the parsed song list */
playlist = g_new(struct asx_playlist, 1); playlist = g_new(AsxPlaylist, 1);
playlist_provider_init(&playlist->base, &asx_playlist_plugin); playlist_provider_init(&playlist->base, &asx_playlist_plugin);
playlist->songs = g_slist_reverse(parser.songs); playlist->songs = g_slist_reverse(parser.songs);
parser.songs = NULL; parser.songs = NULL;
...@@ -279,7 +283,7 @@ asx_open_stream(struct input_stream *is) ...@@ -279,7 +283,7 @@ asx_open_stream(struct input_stream *is)
static void static void
asx_close(struct playlist_provider *_playlist) asx_close(struct playlist_provider *_playlist)
{ {
struct asx_playlist *playlist = (struct asx_playlist *)_playlist; AsxPlaylist *playlist = (AsxPlaylist *)_playlist;
g_slist_foreach(playlist->songs, song_free_callback, NULL); g_slist_foreach(playlist->songs, song_free_callback, NULL);
g_slist_free(playlist->songs); g_slist_free(playlist->songs);
...@@ -289,13 +293,12 @@ asx_close(struct playlist_provider *_playlist) ...@@ -289,13 +293,12 @@ asx_close(struct playlist_provider *_playlist)
static struct song * static struct song *
asx_read(struct playlist_provider *_playlist) asx_read(struct playlist_provider *_playlist)
{ {
struct asx_playlist *playlist = (struct asx_playlist *)_playlist; AsxPlaylist *playlist = (AsxPlaylist *)_playlist;
struct song *song;
if (playlist->songs == NULL) if (playlist->songs == NULL)
return NULL; return NULL;
song = playlist->songs->data; struct song *song = (struct song *)playlist->songs->data;
playlist->songs = g_slist_remove(playlist->songs, song); playlist->songs = g_slist_remove(playlist->songs, song);
return song; return song;
...@@ -312,12 +315,16 @@ static const char *const asx_mime_types[] = { ...@@ -312,12 +315,16 @@ static const char *const asx_mime_types[] = {
}; };
const struct playlist_plugin asx_playlist_plugin = { const struct playlist_plugin asx_playlist_plugin = {
.name = "asx", "asx",
.open_stream = asx_open_stream, nullptr,
.close = asx_close, nullptr,
.read = asx_read, nullptr,
asx_open_stream,
asx_close,
asx_read,
.suffixes = asx_suffixes, nullptr,
.mime_types = asx_mime_types, asx_suffixes,
asx_mime_types,
}; };
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_PLAYLIST_ASX_PLAYLIST_PLUGIN_H #ifndef MPD_ASX_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_ASX_PLAYLIST_PLUGIN_H #define MPD_ASX_PLAYLIST_PLUGIN_HXX
extern const struct playlist_plugin asx_playlist_plugin; extern const struct playlist_plugin asx_playlist_plugin;
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,13 +18,16 @@ ...@@ -18,13 +18,16 @@
*/ */
#include "config.h" #include "config.h"
#include "playlist/cue_playlist_plugin.h" #include "CuePlaylistPlugin.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "tag.h" #include "tag.h"
#include "song.h" #include "song.h"
#include "cue/cue_parser.h"
#include "input_stream.h" #include "input_stream.h"
extern "C" {
#include "text_input_stream.h" #include "text_input_stream.h"
#include "cue/cue_parser.h"
}
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
...@@ -33,7 +36,7 @@ ...@@ -33,7 +36,7 @@
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "cue" #define G_LOG_DOMAIN "cue"
struct cue_playlist { struct CuePlaylist {
struct playlist_provider base; struct playlist_provider base;
struct input_stream *is; struct input_stream *is;
...@@ -44,21 +47,20 @@ struct cue_playlist { ...@@ -44,21 +47,20 @@ struct cue_playlist {
static struct playlist_provider * static struct playlist_provider *
cue_playlist_open_stream(struct input_stream *is) cue_playlist_open_stream(struct input_stream *is)
{ {
struct cue_playlist *playlist = g_new(struct cue_playlist, 1); CuePlaylist *playlist = g_new(CuePlaylist, 1);
playlist_provider_init(&playlist->base, &cue_playlist_plugin); playlist_provider_init(&playlist->base, &cue_playlist_plugin);
playlist->is = is; playlist->is = is;
playlist->tis = text_input_stream_new(is); playlist->tis = text_input_stream_new(is);
playlist->parser = cue_parser_new(); playlist->parser = cue_parser_new();
return &playlist->base; return &playlist->base;
} }
static void static void
cue_playlist_close(struct playlist_provider *_playlist) cue_playlist_close(struct playlist_provider *_playlist)
{ {
struct cue_playlist *playlist = (struct cue_playlist *)_playlist; CuePlaylist *playlist = (CuePlaylist *)_playlist;
cue_parser_free(playlist->parser); cue_parser_free(playlist->parser);
text_input_stream_free(playlist->tis); text_input_stream_free(playlist->tis);
...@@ -68,7 +70,7 @@ cue_playlist_close(struct playlist_provider *_playlist) ...@@ -68,7 +70,7 @@ cue_playlist_close(struct playlist_provider *_playlist)
static struct song * static struct song *
cue_playlist_read(struct playlist_provider *_playlist) cue_playlist_read(struct playlist_provider *_playlist)
{ {
struct cue_playlist *playlist = (struct cue_playlist *)_playlist; CuePlaylist *playlist = (CuePlaylist *)_playlist;
struct song *song = cue_parser_get(playlist->parser); struct song *song = cue_parser_get(playlist->parser);
if (song != NULL) if (song != NULL)
...@@ -97,12 +99,16 @@ static const char *const cue_playlist_mime_types[] = { ...@@ -97,12 +99,16 @@ static const char *const cue_playlist_mime_types[] = {
}; };
const struct playlist_plugin cue_playlist_plugin = { const struct playlist_plugin cue_playlist_plugin = {
.name = "cue", "cue",
.open_stream = cue_playlist_open_stream, nullptr,
.close = cue_playlist_close, nullptr,
.read = cue_playlist_read, nullptr,
cue_playlist_open_stream,
cue_playlist_close,
cue_playlist_read,
.suffixes = cue_playlist_suffixes, nullptr,
.mime_types = cue_playlist_mime_types, cue_playlist_suffixes,
cue_playlist_mime_types,
}; };
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_PLAYLIST_CUE_PLAYLIST_PLUGIN_H #ifndef MPD_CUE_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_CUE_PLAYLIST_PLUGIN_H #define MPD_CUE_PLAYLIST_PLUGIN_HXX
extern const struct playlist_plugin cue_playlist_plugin; extern const struct playlist_plugin cue_playlist_plugin;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "config.h" #include "config.h"
#include "DespotifyPlaylistPlugin.hxx" #include "DespotifyPlaylistPlugin.hxx"
#include "DespotifyUtils.hxx" #include "DespotifyUtils.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "PlaylistRegistry.hxx" #include "PlaylistRegistry.hxx"
#include "conf.h" #include "conf.h"
#include "uri.h" #include "uri.h"
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "config.h" #include "config.h"
#include "EmbeddedCuePlaylistPlugin.hxx" #include "EmbeddedCuePlaylistPlugin.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "tag.h" #include "tag.h"
#include "tag_handler.h" #include "tag_handler.h"
#include "song.h" #include "song.h"
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,20 +18,22 @@ ...@@ -18,20 +18,22 @@
*/ */
#include "config.h" #include "config.h"
#include "playlist/extm3u_playlist_plugin.h" #include "ExtM3uPlaylistPlugin.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "text_input_stream.h"
#include "uri.h"
#include "song.h" #include "song.h"
#include "tag.h" #include "tag.h"
#include "string_util.h" #include "string_util.h"
extern "C" {
#include "text_input_stream.h"
}
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
struct extm3u_playlist { struct ExtM3uPlaylist {
struct playlist_provider base; struct playlist_provider base;
struct text_input_stream *tis; struct text_input_stream *tis;
...@@ -40,13 +42,10 @@ struct extm3u_playlist { ...@@ -40,13 +42,10 @@ struct extm3u_playlist {
static struct playlist_provider * static struct playlist_provider *
extm3u_open_stream(struct input_stream *is) extm3u_open_stream(struct input_stream *is)
{ {
struct extm3u_playlist *playlist; ExtM3uPlaylist *playlist = g_new(ExtM3uPlaylist, 1);
const char *line;
playlist = g_new(struct extm3u_playlist, 1);
playlist->tis = text_input_stream_new(is); playlist->tis = text_input_stream_new(is);
line = text_input_stream_read(playlist->tis); const char *line = text_input_stream_read(playlist->tis);
if (line == NULL || strcmp(line, "#EXTM3U") != 0) { if (line == NULL || strcmp(line, "#EXTM3U") != 0) {
/* no EXTM3U header: fall back to the plain m3u /* no EXTM3U header: fall back to the plain m3u
plugin */ plugin */
...@@ -62,7 +61,7 @@ extm3u_open_stream(struct input_stream *is) ...@@ -62,7 +61,7 @@ extm3u_open_stream(struct input_stream *is)
static void static void
extm3u_close(struct playlist_provider *_playlist) extm3u_close(struct playlist_provider *_playlist)
{ {
struct extm3u_playlist *playlist = (struct extm3u_playlist *)_playlist; ExtM3uPlaylist *playlist = (ExtM3uPlaylist *)_playlist;
text_input_stream_free(playlist->tis); text_input_stream_free(playlist->tis);
g_free(playlist); g_free(playlist);
...@@ -111,7 +110,7 @@ extm3u_parse_tag(const char *line) ...@@ -111,7 +110,7 @@ extm3u_parse_tag(const char *line)
static struct song * static struct song *
extm3u_read(struct playlist_provider *_playlist) extm3u_read(struct playlist_provider *_playlist)
{ {
struct extm3u_playlist *playlist = (struct extm3u_playlist *)_playlist; ExtM3uPlaylist *playlist = (ExtM3uPlaylist *)_playlist;
struct tag *tag = NULL; struct tag *tag = NULL;
const char *line; const char *line;
struct song *song; struct song *song;
...@@ -151,12 +150,16 @@ static const char *const extm3u_mime_types[] = { ...@@ -151,12 +150,16 @@ static const char *const extm3u_mime_types[] = {
}; };
const struct playlist_plugin extm3u_playlist_plugin = { const struct playlist_plugin extm3u_playlist_plugin = {
.name = "extm3u", "extm3u",
.open_stream = extm3u_open_stream, nullptr,
.close = extm3u_close, nullptr,
.read = extm3u_read, nullptr,
extm3u_open_stream,
.suffixes = extm3u_suffixes, extm3u_close,
.mime_types = extm3u_mime_types, extm3u_read,
nullptr,
extm3u_suffixes,
extm3u_mime_types,
}; };
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_PLAYLIST_EXTM3U_PLAYLIST_PLUGIN_H #ifndef MPD_EXTM3U_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_EXTM3U_PLAYLIST_PLUGIN_H #define MPD_EXTM3U_PLAYLIST_PLUGIN_HXX
extern const struct playlist_plugin extm3u_playlist_plugin; extern const struct playlist_plugin extm3u_playlist_plugin;
......
...@@ -19,10 +19,9 @@ ...@@ -19,10 +19,9 @@
#include "config.h" #include "config.h"
#include "LastFMPlaylistPlugin.hxx" #include "LastFMPlaylistPlugin.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "PlaylistRegistry.hxx" #include "PlaylistRegistry.hxx"
#include "conf.h" #include "conf.h"
#include "uri.h"
#include "song.h" #include "song.h"
#include "input_stream.h" #include "input_stream.h"
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,15 +18,17 @@ ...@@ -18,15 +18,17 @@
*/ */
#include "config.h" #include "config.h"
#include "playlist/m3u_playlist_plugin.h" #include "M3uPlaylistPlugin.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "text_input_stream.h"
#include "uri.h"
#include "song.h" #include "song.h"
extern "C" {
#include "text_input_stream.h"
}
#include <glib.h> #include <glib.h>
struct m3u_playlist { struct M3uPlaylist {
struct playlist_provider base; struct playlist_provider base;
struct text_input_stream *tis; struct text_input_stream *tis;
...@@ -35,7 +37,7 @@ struct m3u_playlist { ...@@ -35,7 +37,7 @@ struct m3u_playlist {
static struct playlist_provider * static struct playlist_provider *
m3u_open_stream(struct input_stream *is) m3u_open_stream(struct input_stream *is)
{ {
struct m3u_playlist *playlist = g_new(struct m3u_playlist, 1); M3uPlaylist *playlist = g_new(M3uPlaylist, 1);
playlist_provider_init(&playlist->base, &m3u_playlist_plugin); playlist_provider_init(&playlist->base, &m3u_playlist_plugin);
playlist->tis = text_input_stream_new(is); playlist->tis = text_input_stream_new(is);
...@@ -46,7 +48,7 @@ m3u_open_stream(struct input_stream *is) ...@@ -46,7 +48,7 @@ m3u_open_stream(struct input_stream *is)
static void static void
m3u_close(struct playlist_provider *_playlist) m3u_close(struct playlist_provider *_playlist)
{ {
struct m3u_playlist *playlist = (struct m3u_playlist *)_playlist; M3uPlaylist *playlist = (M3uPlaylist *)_playlist;
text_input_stream_free(playlist->tis); text_input_stream_free(playlist->tis);
g_free(playlist); g_free(playlist);
...@@ -55,7 +57,7 @@ m3u_close(struct playlist_provider *_playlist) ...@@ -55,7 +57,7 @@ m3u_close(struct playlist_provider *_playlist)
static struct song * static struct song *
m3u_read(struct playlist_provider *_playlist) m3u_read(struct playlist_provider *_playlist)
{ {
struct m3u_playlist *playlist = (struct m3u_playlist *)_playlist; M3uPlaylist *playlist = (M3uPlaylist *)_playlist;
const char *line; const char *line;
do { do {
...@@ -81,12 +83,16 @@ static const char *const m3u_mime_types[] = { ...@@ -81,12 +83,16 @@ static const char *const m3u_mime_types[] = {
}; };
const struct playlist_plugin m3u_playlist_plugin = { const struct playlist_plugin m3u_playlist_plugin = {
.name = "m3u", "m3u",
.open_stream = m3u_open_stream, nullptr,
.close = m3u_close, nullptr,
.read = m3u_read, nullptr,
m3u_open_stream,
m3u_close,
m3u_read,
.suffixes = m3u_suffixes, nullptr,
.mime_types = m3u_mime_types, m3u_suffixes,
m3u_mime_types,
}; };
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_PLAYLIST_M3U_PLAYLIST_PLUGIN_H #ifndef MPD_M3U_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_M3U_PLAYLIST_PLUGIN_H #define MPD_M3U_PLAYLIST_PLUGIN_HXX
extern const struct playlist_plugin m3u_playlist_plugin; extern const struct playlist_plugin m3u_playlist_plugin;
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,21 +18,22 @@ ...@@ -18,21 +18,22 @@
*/ */
#include "config.h" #include "config.h"
#include "playlist/pls_playlist_plugin.h" #include "PlsPlaylistPlugin.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "input_stream.h" #include "input_stream.h"
#include "uri.h" #include "uri.h"
#include "song.h" #include "song.h"
#include "tag.h" #include "tag.h"
#include <glib.h> #include <glib.h>
struct pls_playlist { struct PlsPlaylist {
struct playlist_provider base; struct playlist_provider base;
GSList *songs; GSList *songs;
}; };
static void pls_parser(GKeyFile *keyfile, struct pls_playlist *playlist) static void pls_parser(GKeyFile *keyfile, PlsPlaylist *playlist)
{ {
gchar *key; gchar *key;
gchar *value; gchar *value;
...@@ -111,7 +112,7 @@ pls_open_stream(struct input_stream *is) ...@@ -111,7 +112,7 @@ pls_open_stream(struct input_stream *is)
char buffer[1024]; char buffer[1024];
bool success; bool success;
GKeyFile *keyfile; GKeyFile *keyfile;
struct pls_playlist *playlist; PlsPlaylist *playlist;
GString *kf_data = g_string_new(""); GString *kf_data = g_string_new("");
do { do {
...@@ -152,7 +153,7 @@ pls_open_stream(struct input_stream *is) ...@@ -152,7 +153,7 @@ pls_open_stream(struct input_stream *is)
return NULL; return NULL;
} }
playlist = g_new(struct pls_playlist, 1); playlist = g_new(PlsPlaylist, 1);
playlist_provider_init(&playlist->base, &pls_playlist_plugin); playlist_provider_init(&playlist->base, &pls_playlist_plugin);
playlist->songs = NULL; playlist->songs = NULL;
...@@ -166,7 +167,7 @@ pls_open_stream(struct input_stream *is) ...@@ -166,7 +167,7 @@ pls_open_stream(struct input_stream *is)
static void static void
song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
{ {
struct song *song = data; struct song *song = (struct song *)data;
song_free(song); song_free(song);
} }
...@@ -174,7 +175,7 @@ song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) ...@@ -174,7 +175,7 @@ song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
static void static void
pls_close(struct playlist_provider *_playlist) pls_close(struct playlist_provider *_playlist)
{ {
struct pls_playlist *playlist = (struct pls_playlist *)_playlist; PlsPlaylist *playlist = (PlsPlaylist *)_playlist;
g_slist_foreach(playlist->songs, song_free_callback, NULL); g_slist_foreach(playlist->songs, song_free_callback, NULL);
g_slist_free(playlist->songs); g_slist_free(playlist->songs);
...@@ -186,13 +187,12 @@ pls_close(struct playlist_provider *_playlist) ...@@ -186,13 +187,12 @@ pls_close(struct playlist_provider *_playlist)
static struct song * static struct song *
pls_read(struct playlist_provider *_playlist) pls_read(struct playlist_provider *_playlist)
{ {
struct pls_playlist *playlist = (struct pls_playlist *)_playlist; PlsPlaylist *playlist = (PlsPlaylist *)_playlist;
struct song *song;
if (playlist->songs == NULL) if (playlist->songs == NULL)
return NULL; return NULL;
song = playlist->songs->data; struct song *song = (struct song *)playlist->songs->data;
playlist->songs = g_slist_remove(playlist->songs, song); playlist->songs = g_slist_remove(playlist->songs, song);
return song; return song;
...@@ -209,12 +209,16 @@ static const char *const pls_mime_types[] = { ...@@ -209,12 +209,16 @@ static const char *const pls_mime_types[] = {
}; };
const struct playlist_plugin pls_playlist_plugin = { const struct playlist_plugin pls_playlist_plugin = {
.name = "pls", "pls",
.open_stream = pls_open_stream, nullptr,
.close = pls_close, nullptr,
.read = pls_read, nullptr,
pls_open_stream,
pls_close,
pls_read,
.suffixes = pls_suffixes, nullptr,
.mime_types = pls_mime_types, pls_suffixes,
pls_mime_types,
}; };
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_PLAYLIST_PLS_PLAYLIST_PLUGIN_H #ifndef MPD_PLS_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_PLS_PLAYLIST_PLUGIN_H #define MPD_PLS_PLAYLIST_PLUGIN_HXX
extern const struct playlist_plugin pls_playlist_plugin; extern const struct playlist_plugin pls_playlist_plugin;
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
*/ */
#include "config.h" #include "config.h"
#include "playlist/rss_playlist_plugin.h" #include "RssPlaylistPlugin.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "input_stream.h" #include "input_stream.h"
#include "song.h" #include "song.h"
#include "tag.h" #include "tag.h"
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
/** /**
* This is the state object for the GLib XML parser. * This is the state object for the GLib XML parser.
*/ */
struct rss_parser { struct RssParser {
/** /**
* The list of songs (in reverse order because that's faster * The list of songs (in reverse order because that's faster
* while adding). * while adding).
...@@ -61,6 +61,9 @@ struct rss_parser { ...@@ -61,6 +61,9 @@ struct rss_parser {
* element. * element.
*/ */
struct song *song; struct song *song;
RssParser()
:songs(nullptr), state(ROOT) {}
}; };
static const gchar * static const gchar *
...@@ -81,19 +84,19 @@ rss_start_element(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -81,19 +84,19 @@ rss_start_element(G_GNUC_UNUSED GMarkupParseContext *context,
const gchar **attribute_values, const gchar **attribute_values,
gpointer user_data, G_GNUC_UNUSED GError **error) gpointer user_data, G_GNUC_UNUSED GError **error)
{ {
struct rss_parser *parser = user_data; RssParser *parser = (RssParser *)user_data;
switch (parser->state) { switch (parser->state) {
case ROOT: case RssParser::ROOT:
if (g_ascii_strcasecmp(element_name, "item") == 0) { if (g_ascii_strcasecmp(element_name, "item") == 0) {
parser->state = ITEM; parser->state = RssParser::ITEM;
parser->song = song_remote_new("rss:"); parser->song = song_remote_new("rss:");
parser->tag = TAG_NUM_OF_ITEM_TYPES; parser->tag = TAG_NUM_OF_ITEM_TYPES;
} }
break; break;
case ITEM: case RssParser::ITEM:
if (g_ascii_strcasecmp(element_name, "enclosure") == 0) { if (g_ascii_strcasecmp(element_name, "enclosure") == 0) {
const gchar *href = get_attribute(attribute_names, const gchar *href = get_attribute(attribute_names,
attribute_values, attribute_values,
...@@ -128,13 +131,13 @@ rss_end_element(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -128,13 +131,13 @@ rss_end_element(G_GNUC_UNUSED GMarkupParseContext *context,
const gchar *element_name, const gchar *element_name,
gpointer user_data, G_GNUC_UNUSED GError **error) gpointer user_data, G_GNUC_UNUSED GError **error)
{ {
struct rss_parser *parser = user_data; RssParser *parser = (RssParser *)user_data;
switch (parser->state) { switch (parser->state) {
case ROOT: case RssParser::ROOT:
break; break;
case ITEM: case RssParser::ITEM:
if (g_ascii_strcasecmp(element_name, "item") == 0) { if (g_ascii_strcasecmp(element_name, "item") == 0) {
if (strcmp(parser->song->uri, "rss:") != 0) if (strcmp(parser->song->uri, "rss:") != 0)
parser->songs = g_slist_prepend(parser->songs, parser->songs = g_slist_prepend(parser->songs,
...@@ -142,7 +145,7 @@ rss_end_element(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -142,7 +145,7 @@ rss_end_element(G_GNUC_UNUSED GMarkupParseContext *context,
else else
song_free(parser->song); song_free(parser->song);
parser->state = ROOT; parser->state = RssParser::ROOT;
} else } else
parser->tag = TAG_NUM_OF_ITEM_TYPES; parser->tag = TAG_NUM_OF_ITEM_TYPES;
...@@ -155,13 +158,13 @@ rss_text(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -155,13 +158,13 @@ rss_text(G_GNUC_UNUSED GMarkupParseContext *context,
const gchar *text, gsize text_len, const gchar *text, gsize text_len,
gpointer user_data, G_GNUC_UNUSED GError **error) gpointer user_data, G_GNUC_UNUSED GError **error)
{ {
struct rss_parser *parser = user_data; RssParser *parser = (RssParser *)user_data;
switch (parser->state) { switch (parser->state) {
case ROOT: case RssParser::ROOT:
break; break;
case ITEM: case RssParser::ITEM:
if (parser->tag != TAG_NUM_OF_ITEM_TYPES) { if (parser->tag != TAG_NUM_OF_ITEM_TYPES) {
if (parser->song->tag == NULL) if (parser->song->tag == NULL)
parser->song->tag = tag_new(); parser->song->tag = tag_new();
...@@ -174,15 +177,17 @@ rss_text(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -174,15 +177,17 @@ rss_text(G_GNUC_UNUSED GMarkupParseContext *context,
} }
static const GMarkupParser rss_parser = { static const GMarkupParser rss_parser = {
.start_element = rss_start_element, rss_start_element,
.end_element = rss_end_element, rss_end_element,
.text = rss_text, rss_text,
nullptr,
nullptr,
}; };
static void static void
song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
{ {
struct song *song = data; struct song *song = (struct song *)data;
song_free(song); song_free(song);
} }
...@@ -190,9 +195,9 @@ song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) ...@@ -190,9 +195,9 @@ song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
static void static void
rss_parser_destroy(gpointer data) rss_parser_destroy(gpointer data)
{ {
struct rss_parser *parser = data; RssParser *parser = (RssParser *)data;
if (parser->state >= ITEM) if (parser->state >= RssParser::ITEM)
song_free(parser->song); song_free(parser->song);
g_slist_foreach(parser->songs, song_free_callback, NULL); g_slist_foreach(parser->songs, song_free_callback, NULL);
...@@ -204,7 +209,7 @@ rss_parser_destroy(gpointer data) ...@@ -204,7 +209,7 @@ rss_parser_destroy(gpointer data)
* *
*/ */
struct rss_playlist { struct RssPlaylist {
struct playlist_provider base; struct playlist_provider base;
GSList *songs; GSList *songs;
...@@ -213,11 +218,8 @@ struct rss_playlist { ...@@ -213,11 +218,8 @@ struct rss_playlist {
static struct playlist_provider * static struct playlist_provider *
rss_open_stream(struct input_stream *is) rss_open_stream(struct input_stream *is)
{ {
struct rss_parser parser = { RssParser parser;
.songs = NULL, RssPlaylist *playlist;
.state = ROOT,
};
struct rss_playlist *playlist;
GMarkupParseContext *context; GMarkupParseContext *context;
char buffer[1024]; char buffer[1024];
size_t nbytes; size_t nbytes;
...@@ -264,7 +266,7 @@ rss_open_stream(struct input_stream *is) ...@@ -264,7 +266,7 @@ rss_open_stream(struct input_stream *is)
/* create a #rss_playlist object from the parsed song list */ /* create a #rss_playlist object from the parsed song list */
playlist = g_new(struct rss_playlist, 1); playlist = g_new(RssPlaylist, 1);
playlist_provider_init(&playlist->base, &rss_playlist_plugin); playlist_provider_init(&playlist->base, &rss_playlist_plugin);
playlist->songs = g_slist_reverse(parser.songs); playlist->songs = g_slist_reverse(parser.songs);
parser.songs = NULL; parser.songs = NULL;
...@@ -277,7 +279,7 @@ rss_open_stream(struct input_stream *is) ...@@ -277,7 +279,7 @@ rss_open_stream(struct input_stream *is)
static void static void
rss_close(struct playlist_provider *_playlist) rss_close(struct playlist_provider *_playlist)
{ {
struct rss_playlist *playlist = (struct rss_playlist *)_playlist; RssPlaylist *playlist = (RssPlaylist *)_playlist;
g_slist_foreach(playlist->songs, song_free_callback, NULL); g_slist_foreach(playlist->songs, song_free_callback, NULL);
g_slist_free(playlist->songs); g_slist_free(playlist->songs);
...@@ -287,13 +289,12 @@ rss_close(struct playlist_provider *_playlist) ...@@ -287,13 +289,12 @@ rss_close(struct playlist_provider *_playlist)
static struct song * static struct song *
rss_read(struct playlist_provider *_playlist) rss_read(struct playlist_provider *_playlist)
{ {
struct rss_playlist *playlist = (struct rss_playlist *)_playlist; RssPlaylist *playlist = (RssPlaylist *)_playlist;
struct song *song;
if (playlist->songs == NULL) if (playlist->songs == NULL)
return NULL; return NULL;
song = playlist->songs->data; struct song *song = (struct song *)playlist->songs->data;
playlist->songs = g_slist_remove(playlist->songs, song); playlist->songs = g_slist_remove(playlist->songs, song);
return song; return song;
...@@ -311,12 +312,16 @@ static const char *const rss_mime_types[] = { ...@@ -311,12 +312,16 @@ static const char *const rss_mime_types[] = {
}; };
const struct playlist_plugin rss_playlist_plugin = { const struct playlist_plugin rss_playlist_plugin = {
.name = "rss", "rss",
.open_stream = rss_open_stream, nullptr,
.close = rss_close, nullptr,
.read = rss_read, nullptr,
rss_open_stream,
rss_close,
rss_read,
.suffixes = rss_suffixes, nullptr,
.mime_types = rss_mime_types, rss_suffixes,
rss_mime_types,
}; };
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_PLAYLIST_RSS_PLAYLIST_PLUGIN_H #ifndef MPD_RSS_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_RSS_PLAYLIST_PLUGIN_H #define MPD_RSS_PLAYLIST_PLUGIN_HXX
extern const struct playlist_plugin rss_playlist_plugin; extern const struct playlist_plugin rss_playlist_plugin;
......
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
#include "config.h" #include "config.h"
#include "SoundCloudPlaylistPlugin.hxx" #include "SoundCloudPlaylistPlugin.hxx"
#include "PlaylistPlugin.hxx"
#include "conf.h" #include "conf.h"
#include "input_stream.h" #include "input_stream.h"
#include "playlist_plugin.h"
#include "song.h" #include "song.h"
#include "tag.h" #include "tag.h"
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
*/ */
#include "config.h" #include "config.h"
#include "playlist/xspf_playlist_plugin.h" #include "XspfPlaylistPlugin.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
#include "input_stream.h" #include "input_stream.h"
#include "uri.h" #include "uri.h"
#include "song.h" #include "song.h"
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
/** /**
* This is the state object for the GLib XML parser. * This is the state object for the GLib XML parser.
*/ */
struct xspf_parser { struct XspfParser {
/** /**
* The list of songs (in reverse order because that's faster * The list of songs (in reverse order because that's faster
* while adding). * while adding).
...@@ -63,6 +63,9 @@ struct xspf_parser { ...@@ -63,6 +63,9 @@ struct xspf_parser {
* element. * element.
*/ */
struct song *song; struct song *song;
XspfParser()
:songs(nullptr), state(ROOT) {}
}; };
static void static void
...@@ -72,33 +75,33 @@ xspf_start_element(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -72,33 +75,33 @@ xspf_start_element(G_GNUC_UNUSED GMarkupParseContext *context,
G_GNUC_UNUSED const gchar **attribute_values, G_GNUC_UNUSED const gchar **attribute_values,
gpointer user_data, G_GNUC_UNUSED GError **error) gpointer user_data, G_GNUC_UNUSED GError **error)
{ {
struct xspf_parser *parser = user_data; XspfParser *parser = (XspfParser *)user_data;
switch (parser->state) { switch (parser->state) {
case ROOT: case XspfParser::ROOT:
if (strcmp(element_name, "playlist") == 0) if (strcmp(element_name, "playlist") == 0)
parser->state = PLAYLIST; parser->state = XspfParser::PLAYLIST;
break; break;
case PLAYLIST: case XspfParser::PLAYLIST:
if (strcmp(element_name, "trackList") == 0) if (strcmp(element_name, "trackList") == 0)
parser->state = TRACKLIST; parser->state = XspfParser::TRACKLIST;
break; break;
case TRACKLIST: case XspfParser::TRACKLIST:
if (strcmp(element_name, "track") == 0) { if (strcmp(element_name, "track") == 0) {
parser->state = TRACK; parser->state = XspfParser::TRACK;
parser->song = NULL; parser->song = NULL;
parser->tag = TAG_NUM_OF_ITEM_TYPES; parser->tag = TAG_NUM_OF_ITEM_TYPES;
} }
break; break;
case TRACK: case XspfParser::TRACK:
if (strcmp(element_name, "location") == 0) if (strcmp(element_name, "location") == 0)
parser->state = LOCATION; parser->state = XspfParser::LOCATION;
else if (strcmp(element_name, "title") == 0) else if (strcmp(element_name, "title") == 0)
parser->tag = TAG_TITLE; parser->tag = TAG_TITLE;
else if (strcmp(element_name, "creator") == 0) else if (strcmp(element_name, "creator") == 0)
...@@ -114,7 +117,7 @@ xspf_start_element(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -114,7 +117,7 @@ xspf_start_element(G_GNUC_UNUSED GMarkupParseContext *context,
break; break;
case LOCATION: case XspfParser::LOCATION:
break; break;
} }
} }
...@@ -124,38 +127,38 @@ xspf_end_element(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -124,38 +127,38 @@ xspf_end_element(G_GNUC_UNUSED GMarkupParseContext *context,
const gchar *element_name, const gchar *element_name,
gpointer user_data, G_GNUC_UNUSED GError **error) gpointer user_data, G_GNUC_UNUSED GError **error)
{ {
struct xspf_parser *parser = user_data; XspfParser *parser = (XspfParser *)user_data;
switch (parser->state) { switch (parser->state) {
case ROOT: case XspfParser::ROOT:
break; break;
case PLAYLIST: case XspfParser::PLAYLIST:
if (strcmp(element_name, "playlist") == 0) if (strcmp(element_name, "playlist") == 0)
parser->state = ROOT; parser->state = XspfParser::ROOT;
break; break;
case TRACKLIST: case XspfParser::TRACKLIST:
if (strcmp(element_name, "tracklist") == 0) if (strcmp(element_name, "tracklist") == 0)
parser->state = PLAYLIST; parser->state = XspfParser::PLAYLIST;
break; break;
case TRACK: case XspfParser::TRACK:
if (strcmp(element_name, "track") == 0) { if (strcmp(element_name, "track") == 0) {
if (parser->song != NULL) if (parser->song != NULL)
parser->songs = g_slist_prepend(parser->songs, parser->songs = g_slist_prepend(parser->songs,
parser->song); parser->song);
parser->state = TRACKLIST; parser->state = XspfParser::TRACKLIST;
} else } else
parser->tag = TAG_NUM_OF_ITEM_TYPES; parser->tag = TAG_NUM_OF_ITEM_TYPES;
break; break;
case LOCATION: case XspfParser::LOCATION:
parser->state = TRACK; parser->state = XspfParser::TRACK;
break; break;
} }
} }
...@@ -165,15 +168,15 @@ xspf_text(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -165,15 +168,15 @@ xspf_text(G_GNUC_UNUSED GMarkupParseContext *context,
const gchar *text, gsize text_len, const gchar *text, gsize text_len,
gpointer user_data, G_GNUC_UNUSED GError **error) gpointer user_data, G_GNUC_UNUSED GError **error)
{ {
struct xspf_parser *parser = user_data; XspfParser *parser = (XspfParser *)user_data;
switch (parser->state) { switch (parser->state) {
case ROOT: case XspfParser::ROOT:
case PLAYLIST: case XspfParser::PLAYLIST:
case TRACKLIST: case XspfParser::TRACKLIST:
break; break;
case TRACK: case XspfParser::TRACK:
if (parser->song != NULL && if (parser->song != NULL &&
parser->tag != TAG_NUM_OF_ITEM_TYPES) { parser->tag != TAG_NUM_OF_ITEM_TYPES) {
if (parser->song->tag == NULL) if (parser->song->tag == NULL)
...@@ -184,7 +187,7 @@ xspf_text(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -184,7 +187,7 @@ xspf_text(G_GNUC_UNUSED GMarkupParseContext *context,
break; break;
case LOCATION: case XspfParser::LOCATION:
if (parser->song == NULL) { if (parser->song == NULL) {
char *uri = g_strndup(text, text_len); char *uri = g_strndup(text, text_len);
parser->song = song_remote_new(uri); parser->song = song_remote_new(uri);
...@@ -196,15 +199,17 @@ xspf_text(G_GNUC_UNUSED GMarkupParseContext *context, ...@@ -196,15 +199,17 @@ xspf_text(G_GNUC_UNUSED GMarkupParseContext *context,
} }
static const GMarkupParser xspf_parser = { static const GMarkupParser xspf_parser = {
.start_element = xspf_start_element, xspf_start_element,
.end_element = xspf_end_element, xspf_end_element,
.text = xspf_text, xspf_text,
nullptr,
nullptr,
}; };
static void static void
song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
{ {
struct song *song = data; struct song *song = (struct song *)data;
song_free(song); song_free(song);
} }
...@@ -212,9 +217,9 @@ song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) ...@@ -212,9 +217,9 @@ song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
static void static void
xspf_parser_destroy(gpointer data) xspf_parser_destroy(gpointer data)
{ {
struct xspf_parser *parser = data; XspfParser *parser = (XspfParser *)data;
if (parser->state >= TRACK && parser->song != NULL) if (parser->state >= XspfParser::TRACK && parser->song != NULL)
song_free(parser->song); song_free(parser->song);
g_slist_foreach(parser->songs, song_free_callback, NULL); g_slist_foreach(parser->songs, song_free_callback, NULL);
...@@ -226,7 +231,7 @@ xspf_parser_destroy(gpointer data) ...@@ -226,7 +231,7 @@ xspf_parser_destroy(gpointer data)
* *
*/ */
struct xspf_playlist { struct XspfPlaylist {
struct playlist_provider base; struct playlist_provider base;
GSList *songs; GSList *songs;
...@@ -235,11 +240,8 @@ struct xspf_playlist { ...@@ -235,11 +240,8 @@ struct xspf_playlist {
static struct playlist_provider * static struct playlist_provider *
xspf_open_stream(struct input_stream *is) xspf_open_stream(struct input_stream *is)
{ {
struct xspf_parser parser = { XspfParser parser;
.songs = NULL, XspfPlaylist *playlist;
.state = ROOT,
};
struct xspf_playlist *playlist;
GMarkupParseContext *context; GMarkupParseContext *context;
char buffer[1024]; char buffer[1024];
size_t nbytes; size_t nbytes;
...@@ -286,7 +288,7 @@ xspf_open_stream(struct input_stream *is) ...@@ -286,7 +288,7 @@ xspf_open_stream(struct input_stream *is)
/* create a #xspf_playlist object from the parsed song list */ /* create a #xspf_playlist object from the parsed song list */
playlist = g_new(struct xspf_playlist, 1); playlist = g_new(XspfPlaylist, 1);
playlist_provider_init(&playlist->base, &xspf_playlist_plugin); playlist_provider_init(&playlist->base, &xspf_playlist_plugin);
playlist->songs = g_slist_reverse(parser.songs); playlist->songs = g_slist_reverse(parser.songs);
parser.songs = NULL; parser.songs = NULL;
...@@ -299,7 +301,7 @@ xspf_open_stream(struct input_stream *is) ...@@ -299,7 +301,7 @@ xspf_open_stream(struct input_stream *is)
static void static void
xspf_close(struct playlist_provider *_playlist) xspf_close(struct playlist_provider *_playlist)
{ {
struct xspf_playlist *playlist = (struct xspf_playlist *)_playlist; XspfPlaylist *playlist = (XspfPlaylist *)_playlist;
g_slist_foreach(playlist->songs, song_free_callback, NULL); g_slist_foreach(playlist->songs, song_free_callback, NULL);
g_slist_free(playlist->songs); g_slist_free(playlist->songs);
...@@ -309,13 +311,12 @@ xspf_close(struct playlist_provider *_playlist) ...@@ -309,13 +311,12 @@ xspf_close(struct playlist_provider *_playlist)
static struct song * static struct song *
xspf_read(struct playlist_provider *_playlist) xspf_read(struct playlist_provider *_playlist)
{ {
struct xspf_playlist *playlist = (struct xspf_playlist *)_playlist; XspfPlaylist *playlist = (XspfPlaylist *)_playlist;
struct song *song;
if (playlist->songs == NULL) if (playlist->songs == NULL)
return NULL; return NULL;
song = playlist->songs->data; struct song *song = (struct song *)playlist->songs->data;
playlist->songs = g_slist_remove(playlist->songs, song); playlist->songs = g_slist_remove(playlist->songs, song);
return song; return song;
...@@ -332,12 +333,16 @@ static const char *const xspf_mime_types[] = { ...@@ -332,12 +333,16 @@ static const char *const xspf_mime_types[] = {
}; };
const struct playlist_plugin xspf_playlist_plugin = { const struct playlist_plugin xspf_playlist_plugin = {
.name = "xspf", "xspf",
.open_stream = xspf_open_stream, nullptr,
.close = xspf_close, nullptr,
.read = xspf_read, nullptr,
xspf_open_stream,
xspf_close,
xspf_read,
.suffixes = xspf_suffixes, nullptr,
.mime_types = xspf_mime_types, xspf_suffixes,
xspf_mime_types,
}; };
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_PLAYLIST_XSPF_PLAYLIST_PLUGIN_H #ifndef MPD_XSPF_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_XSPF_PLAYLIST_PLUGIN_H #define MPD_XSPF_PLAYLIST_PLUGIN_HXX
extern const struct playlist_plugin xspf_playlist_plugin; extern const struct playlist_plugin xspf_playlist_plugin;
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "InputInit.hxx" #include "InputInit.hxx"
#include "IOThread.hxx" #include "IOThread.hxx"
#include "PlaylistRegistry.hxx" #include "PlaylistRegistry.hxx"
#include "playlist_plugin.h" #include "PlaylistPlugin.hxx"
extern "C" { extern "C" {
#include "decoder_list.h" #include "decoder_list.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment