From 718fd97612c298b7eac47289c1803a2a19d9a859 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 30 Jan 2013 09:08:50 +0100 Subject: icy_server: convert to C++ --- Makefile.am | 3 +- src/IcyMetaDataServer.cxx | 139 +++++++++++++++++++++++++++++++++++++++ src/IcyMetaDataServer.hxx | 33 ++++++++++ src/icy_server.c | 137 -------------------------------------- src/icy_server.h | 42 ------------ src/output/HttpdClient.cxx | 2 +- src/output/HttpdOutputPlugin.cxx | 2 +- 7 files changed, 175 insertions(+), 183 deletions(-) create mode 100644 src/IcyMetaDataServer.cxx create mode 100644 src/IcyMetaDataServer.hxx delete mode 100644 src/icy_server.c delete mode 100644 src/icy_server.h diff --git a/Makefile.am b/Makefile.am index 3a1c72a9e..c14ff2ed8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -81,7 +81,6 @@ mpd_headers = \ src/decoder/pcm_decoder_plugin.h \ src/input_stream.h \ src/text_input_stream.h \ - src/icy_server.h \ src/ls.h \ src/mixer_api.h \ src/mixer_control.h \ @@ -889,7 +888,7 @@ endif if ENABLE_HTTPD_OUTPUT liboutput_plugins_a_SOURCES += \ - src/icy_server.c \ + src/IcyMetaDataServer.cxx src/IcyMetaDataServer.hxx \ src/output/HttpdInternal.hxx \ src/output/HttpdClient.cxx src/output/HttpdClient.hxx \ src/output/HttpdOutputPlugin.cxx src/output/HttpdOutputPlugin.hxx diff --git a/src/IcyMetaDataServer.cxx b/src/IcyMetaDataServer.cxx new file mode 100644 index 000000000..e7bd0acf4 --- /dev/null +++ b/src/IcyMetaDataServer.cxx @@ -0,0 +1,139 @@ +/* + * 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 + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "IcyMetaDataServer.hxx" +#include "page.h" +#include "tag.h" + +#include + +#include + +#undef G_LOG_DOMAIN +#define G_LOG_DOMAIN "icy_server" + +char* +icy_server_metadata_header(const char *name, + const char *genre, const char *url, + const char *content_type, int metaint) +{ + return g_strdup_printf("ICY 200 OK\r\n" + "icy-notice1:
This stream requires an audio player!
\r\n" /* TODO */ + "icy-notice2:MPD - The music player daemon
\r\n" + "icy-name: %s\r\n" /* TODO */ + "icy-genre: %s\r\n" /* TODO */ + "icy-url: %s\r\n" /* TODO */ + "icy-pub:1\r\n" + "icy-metaint:%d\r\n" + /* TODO "icy-br:%d\r\n" */ + "Content-Type: %s\r\n" + "Connection: close\r\n" + "Pragma: no-cache\r\n" + "Cache-Control: no-cache, no-store\r\n" + "\r\n", + name, + genre, + url, + metaint, + /* bitrate, */ + content_type); +} + +static char * +icy_server_metadata_string(const char *stream_title, const char* stream_url) +{ + gchar *icy_metadata; + guint meta_length; + + // The leading n is a placeholder for the length information + icy_metadata = g_strdup_printf("nStreamTitle='%s';" + "StreamUrl='%s';", + stream_title, + stream_url); + + g_return_val_if_fail(icy_metadata, NULL); + + meta_length = strlen(icy_metadata); + + meta_length--; // subtract placeholder + + meta_length = ((int)meta_length / 16) + 1; + + icy_metadata[0] = meta_length; + + if (meta_length > 255) { + g_free(icy_metadata); + return NULL; + } + + return icy_metadata; +} + +struct page* +icy_server_metadata_page(const struct tag *tag, const enum tag_type *types) +{ + const gchar *tag_items[TAG_NUM_OF_ITEM_TYPES]; + gint last_item, item; + guint position; + gchar *icy_string; + struct page *icy_metadata; + gchar stream_title[(1 + 255 - 28) * 16]; // Length + Metadata - + // "StreamTitle='';StreamUrl='';" + // = 4081 - 28 + stream_title[0] = '\0'; + + last_item = -1; + + while (*types != TAG_NUM_OF_ITEM_TYPES) { + const gchar *tag_item = tag_get_value(tag, *types); + if (tag_item) + tag_items[++last_item] = tag_item; + } + + position = item = 0; + while (position < sizeof(stream_title) && item <= last_item) { + gint length = 0; + + length = g_strlcpy(stream_title + position, + tag_items[item++], + sizeof(stream_title) - position); + + position += length; + + if (item <= last_item) { + length = g_strlcpy(stream_title + position, + " - ", + sizeof(stream_title) - position); + + position += length; + } + } + + icy_string = icy_server_metadata_string(stream_title, ""); + + if (icy_string == NULL) + return NULL; + + icy_metadata = page_new_copy(icy_string, (icy_string[0] * 16) + 1); + + g_free(icy_string); + + return icy_metadata; +} diff --git a/src/IcyMetaDataServer.hxx b/src/IcyMetaDataServer.hxx new file mode 100644 index 000000000..78f1be7db --- /dev/null +++ b/src/IcyMetaDataServer.hxx @@ -0,0 +1,33 @@ +/* + * 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 + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_ICY_META_DATA_SERVER_HXX +#define MPD_ICY_META_DATA_SERVER_HXX + +#include "tag.h" + +char* +icy_server_metadata_header(const char *name, + const char *genre, const char *url, + const char *content_type, int metaint); + +struct page* +icy_server_metadata_page(const struct tag *tag, const enum tag_type *types); + +#endif diff --git a/src/icy_server.c b/src/icy_server.c deleted file mode 100644 index 4971bc0ee..000000000 --- a/src/icy_server.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" -#include "icy_server.h" - -#include - -#include - -#undef G_LOG_DOMAIN -#define G_LOG_DOMAIN "icy_server" - -char* -icy_server_metadata_header(const char *name, - const char *genre, const char *url, - const char *content_type, int metaint) -{ - return g_strdup_printf("ICY 200 OK\r\n" - "icy-notice1:
This stream requires an audio player!
\r\n" /* TODO */ - "icy-notice2:MPD - The music player daemon
\r\n" - "icy-name: %s\r\n" /* TODO */ - "icy-genre: %s\r\n" /* TODO */ - "icy-url: %s\r\n" /* TODO */ - "icy-pub:1\r\n" - "icy-metaint:%d\r\n" - /* TODO "icy-br:%d\r\n" */ - "Content-Type: %s\r\n" - "Connection: close\r\n" - "Pragma: no-cache\r\n" - "Cache-Control: no-cache, no-store\r\n" - "\r\n", - name, - genre, - url, - metaint, - /* bitrate, */ - content_type); -} - -static char * -icy_server_metadata_string(const char *stream_title, const char* stream_url) -{ - gchar *icy_metadata; - guint meta_length; - - // The leading n is a placeholder for the length information - icy_metadata = g_strdup_printf("nStreamTitle='%s';" - "StreamUrl='%s';", - stream_title, - stream_url); - - g_return_val_if_fail(icy_metadata, NULL); - - meta_length = strlen(icy_metadata); - - meta_length--; // subtract placeholder - - meta_length = ((int)meta_length / 16) + 1; - - icy_metadata[0] = meta_length; - - if (meta_length > 255) { - g_free(icy_metadata); - return NULL; - } - - return icy_metadata; -} - -struct page* -icy_server_metadata_page(const struct tag *tag, const enum tag_type *types) -{ - const gchar *tag_items[TAG_NUM_OF_ITEM_TYPES]; - gint last_item, item; - guint position; - gchar *icy_string; - struct page *icy_metadata; - gchar stream_title[(1 + 255 - 28) * 16]; // Length + Metadata - - // "StreamTitle='';StreamUrl='';" - // = 4081 - 28 - stream_title[0] = '\0'; - - last_item = -1; - - while (*types != TAG_NUM_OF_ITEM_TYPES) { - const gchar *tag_item = tag_get_value(tag, *types); - if (tag_item) - tag_items[++last_item] = tag_item; - } - - position = item = 0; - while (position < sizeof(stream_title) && item <= last_item) { - gint length = 0; - - length = g_strlcpy(stream_title + position, - tag_items[item++], - sizeof(stream_title) - position); - - position += length; - - if (item <= last_item) { - length = g_strlcpy(stream_title + position, - " - ", - sizeof(stream_title) - position); - - position += length; - } - } - - icy_string = icy_server_metadata_string(stream_title, ""); - - if (icy_string == NULL) - return NULL; - - icy_metadata = page_new_copy(icy_string, (icy_string[0] * 16) + 1); - - g_free(icy_string); - - return icy_metadata; -} diff --git a/src/icy_server.h b/src/icy_server.h deleted file mode 100644 index 15f6f36b7..000000000 --- a/src/icy_server.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef ICY_SERVER_H -#define ICY_SERVER_H - -#include "page.h" -#include "tag.h" - -#ifdef __cplusplus -extern "C" { -#endif - -char* -icy_server_metadata_header(const char *name, - const char *genre, const char *url, - const char *content_type, int metaint); - -struct page* -icy_server_metadata_page(const struct tag *tag, const enum tag_type *types); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/output/HttpdClient.cxx b/src/output/HttpdClient.cxx index 0d0e3c949..5ac3bf7cc 100644 --- a/src/output/HttpdClient.cxx +++ b/src/output/HttpdClient.cxx @@ -22,7 +22,7 @@ #include "HttpdInternal.hxx" #include "util/fifo_buffer.h" #include "page.h" -#include "icy_server.h" +#include "IcyMetaDataServer.hxx" #include "glib_socket.h" #include diff --git a/src/output/HttpdOutputPlugin.cxx b/src/output/HttpdOutputPlugin.cxx index c6367cd21..52b2e0e8d 100644 --- a/src/output/HttpdOutputPlugin.cxx +++ b/src/output/HttpdOutputPlugin.cxx @@ -26,7 +26,7 @@ #include "encoder_list.h" #include "resolver.h" #include "page.h" -#include "icy_server.h" +#include "IcyMetaDataServer.hxx" #include "fd_util.h" #include "ServerSocket.hxx" #include "Main.hxx" -- cgit v1.2.3