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

playlist/*: convert to C++

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