From 96b763067e82d4b3a1b08b3a3c0ccca2114c35f3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 28 Jul 2013 20:31:27 +0200 Subject: ape: convert to C++ --- src/ApeLoader.cxx | 115 ++++++++++++++++++++++++++++ src/ApeLoader.hxx | 43 +++++++++++ src/ApeReplayGain.cxx | 78 +++++++++++++++++++ src/ApeReplayGain.hxx | 30 ++++++++ src/ApeTag.cxx | 104 +++++++++++++++++++++++++ src/ApeTag.hxx | 40 ++++++++++ src/DecoderThread.cxx | 5 +- src/SongUpdate.cxx | 2 +- src/ape.c | 115 ---------------------------- src/ape.h | 42 ----------- src/decoder/WavpackDecoderPlugin.cxx | 2 +- src/playlist/EmbeddedCuePlaylistPlugin.cxx | 5 +- src/replay_gain_ape.c | 78 ------------------- src/replay_gain_ape.h | 32 -------- src/tag_ape.c | 117 ----------------------------- src/tag_ape.h | 40 ---------- 16 files changed, 414 insertions(+), 434 deletions(-) create mode 100644 src/ApeLoader.cxx create mode 100644 src/ApeLoader.hxx create mode 100644 src/ApeReplayGain.cxx create mode 100644 src/ApeReplayGain.hxx create mode 100644 src/ApeTag.cxx create mode 100644 src/ApeTag.hxx delete mode 100644 src/ape.c delete mode 100644 src/ape.h delete mode 100644 src/replay_gain_ape.c delete mode 100644 src/replay_gain_ape.h delete mode 100644 src/tag_ape.c delete mode 100644 src/tag_ape.h (limited to 'src') diff --git a/src/ApeLoader.cxx b/src/ApeLoader.cxx new file mode 100644 index 000000000..dfbdb4ef3 --- /dev/null +++ b/src/ApeLoader.cxx @@ -0,0 +1,115 @@ +/* + * 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 "ApeLoader.hxx" + +#include + +#include +#include +#include +#include + +struct ape_footer { + unsigned char id[8]; + uint32_t version; + uint32_t length; + uint32_t count; + unsigned char flags[4]; + unsigned char reserved[8]; +}; + +static bool +ape_scan_internal(FILE *fp, ApeTagCallback callback) +{ + /* determine if file has an apeV2 tag */ + struct ape_footer footer; + if (fseek(fp, -(long)sizeof(footer), SEEK_END) || + fread(&footer, 1, sizeof(footer), fp) != sizeof(footer) || + memcmp(footer.id, "APETAGEX", sizeof(footer.id)) != 0 || + GUINT32_FROM_LE(footer.version) != 2000) + return false; + + /* find beginning of ape tag */ + size_t remaining = GUINT32_FROM_LE(footer.length); + if (remaining <= sizeof(footer) + 10 || + /* refuse to load more than one megabyte of tag data */ + remaining > 1024 * 1024 || + fseek(fp, -(long)remaining, SEEK_END)) + return false; + + /* read tag into buffer */ + remaining -= sizeof(footer); + assert(remaining > 10); + + char *buffer = (char *)g_malloc(remaining); + if (fread(buffer, 1, remaining, fp) != remaining) { + g_free(buffer); + return false; + } + + /* read tags */ + unsigned n = GUINT32_FROM_LE(footer.count); + const char *p = buffer; + while (n-- && remaining > 10) { + size_t size = GUINT32_FROM_LE(*(const uint32_t *)p); + p += 4; + remaining -= 4; + unsigned long flags = GUINT32_FROM_LE(*(const uint32_t *)p); + p += 4; + remaining -= 4; + + /* get the key */ + const char *key = p; + while (remaining > size && *p != '\0') { + p++; + remaining--; + } + p++; + remaining--; + + /* get the value */ + if (remaining < size) + break; + + if (!callback(flags, key, p, size)) + break; + + p += size; + remaining -= size; + } + + g_free(buffer); + return true; +} + +bool +tag_ape_scan(const char *path_fs, ApeTagCallback callback) +{ + FILE *fp; + + fp = fopen(path_fs, "rb"); + if (fp == nullptr) + return false; + + bool success = ape_scan_internal(fp, callback); + fclose(fp); + return success; +} diff --git a/src/ApeLoader.hxx b/src/ApeLoader.hxx new file mode 100644 index 000000000..a32ab840c --- /dev/null +++ b/src/ApeLoader.hxx @@ -0,0 +1,43 @@ +/* + * 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_APE_LOADER_HXX +#define MPD_APE_LOADER_HXX + +#include "check.h" + +#include + +#include + +typedef std::function ApeTagCallback; + +/** + * Scans the APE tag values from a file. + * + * @param path_fs the path of the file in filesystem encoding + * @return false if the file could not be opened or if no APE tag is + * present + */ +bool +tag_ape_scan(const char *path_fs, ApeTagCallback callback); + +#endif diff --git a/src/ApeReplayGain.cxx b/src/ApeReplayGain.cxx new file mode 100644 index 000000000..0135d1b61 --- /dev/null +++ b/src/ApeReplayGain.cxx @@ -0,0 +1,78 @@ +/* + * 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 "ApeReplayGain.hxx" +#include "ApeLoader.hxx" +#include "replay_gain_info.h" + +#include + +#include +#include + +static bool +replay_gain_ape_callback(unsigned long flags, const char *key, + const char *_value, size_t value_length, + struct replay_gain_info *info) +{ + /* we only care about utf-8 text tags */ + if ((flags & (0x3 << 1)) != 0) + return false; + + char value[16]; + if (value_length >= sizeof(value)) + return false; + + memcpy(value, _value, value_length); + value[value_length] = 0; + + if (g_ascii_strcasecmp(key, "replaygain_track_gain") == 0) { + info->tuples[REPLAY_GAIN_TRACK].gain = atof(value); + return true; + } else if (g_ascii_strcasecmp(key, "replaygain_album_gain") == 0) { + info->tuples[REPLAY_GAIN_ALBUM].gain = atof(value); + return true; + } else if (g_ascii_strcasecmp(key, "replaygain_track_peak") == 0) { + info->tuples[REPLAY_GAIN_TRACK].peak = atof(value); + return true; + } else if (g_ascii_strcasecmp(key, "replaygain_album_peak") == 0) { + info->tuples[REPLAY_GAIN_ALBUM].peak = atof(value); + return true; + } else + return false; +} + +bool +replay_gain_ape_read(const char *path_fs, struct replay_gain_info *info) +{ + bool found = false; + + auto callback = [info, &found] + (unsigned long flags, const char *key, + const char *value, + size_t value_length) { + found |= replay_gain_ape_callback(flags, key, + value, value_length, + info); + return true; + }; + + return tag_ape_scan(path_fs, callback) && found; +} diff --git a/src/ApeReplayGain.hxx b/src/ApeReplayGain.hxx new file mode 100644 index 000000000..4bc34a9d2 --- /dev/null +++ b/src/ApeReplayGain.hxx @@ -0,0 +1,30 @@ +/* + * 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_APE_REPLAY_GAIN_HXX +#define MPD_APE_REPLAY_GAIN_HXX + +#include "check.h" + +struct replay_gain_info; + +bool +replay_gain_ape_read(const char *path_fs, struct replay_gain_info *info); + +#endif diff --git a/src/ApeTag.cxx b/src/ApeTag.cxx new file mode 100644 index 000000000..1195ffe5f --- /dev/null +++ b/src/ApeTag.cxx @@ -0,0 +1,104 @@ +/* + * 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 "ApeTag.hxx" +#include "ApeLoader.hxx" +#include "tag.h" +#include "tag_table.h" +#include "tag_handler.h" + +const struct tag_table ape_tags[] = { + { "album artist", TAG_ALBUM_ARTIST }, + { "year", TAG_DATE }, + { nullptr, TAG_NUM_OF_ITEM_TYPES } +}; + +static enum tag_type +tag_ape_name_parse(const char *name) +{ + enum tag_type type = tag_table_lookup_i(ape_tags, name); + if (type == TAG_NUM_OF_ITEM_TYPES) + type = tag_name_parse_i(name); + + return type; +} + +/** + * @return true if the item was recognized + */ +static bool +tag_ape_import_item(unsigned long flags, + const char *key, const char *value, size_t value_length, + const struct tag_handler *handler, void *handler_ctx) +{ + /* we only care about utf-8 text tags */ + if ((flags & (0x3 << 1)) != 0) + return false; + + tag_handler_invoke_pair(handler, handler_ctx, key, value); + + enum tag_type type = tag_ape_name_parse(key); + if (type == TAG_NUM_OF_ITEM_TYPES) + return false; + + bool recognized = false; + const char *end = value + value_length; + while (true) { + /* multiple values are separated by null bytes */ + const char *n = (const char *)memchr(value, 0, end - value); + if (n != nullptr) { + if (n > value) { + tag_handler_invoke_tag(handler, handler_ctx, + type, value); + recognized = true; + } + + value = n + 1; + } else { + char *p = g_strndup(value, end - value); + tag_handler_invoke_tag(handler, handler_ctx, + type, p); + g_free(p); + recognized = true; + break; + } + } + + return recognized; +} + +bool +tag_ape_scan2(const char *path_fs, + const struct tag_handler *handler, void *handler_ctx) +{ + bool recognized = false; + + auto callback = [handler, handler_ctx, &recognized] + (unsigned long flags, const char *key, + const char *value, + size_t value_length) { + recognized |= tag_ape_import_item(flags, key, value, + value_length, + handler, handler_ctx); + return true; + }; + + return tag_ape_scan(path_fs, callback) && recognized; +} diff --git a/src/ApeTag.hxx b/src/ApeTag.hxx new file mode 100644 index 000000000..3e6655531 --- /dev/null +++ b/src/ApeTag.hxx @@ -0,0 +1,40 @@ +/* + * 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_APE_TAG_HXX +#define MPD_APE_TAG_HXX + +#include "tag_table.h" + +#include + +struct tag_handler; + +extern const struct tag_table ape_tags[]; + +/** + * Scan the APE tags of a file. + * + * @param path_fs the path of the file in filesystem encoding + */ +bool +tag_ape_scan2(const char *path_fs, + const struct tag_handler *handler, void *handler_ctx); + +#endif diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx index f69a5fb3c..747319463 100644 --- a/src/DecoderThread.cxx +++ b/src/DecoderThread.cxx @@ -32,10 +32,7 @@ #include "InputStream.hxx" #include "DecoderList.hxx" #include "util/UriUtil.hxx" - -extern "C" { -#include "replay_gain_ape.h" -} +#include "ApeReplayGain.hxx" #include diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx index cfe4741c9..8285cdd99 100644 --- a/src/SongUpdate.cxx +++ b/src/SongUpdate.cxx @@ -29,9 +29,9 @@ #include "DecoderPlugin.hxx" #include "DecoderList.hxx" #include "TagId3.hxx" +#include "ApeTag.hxx" extern "C" { -#include "tag_ape.h" #include "tag_handler.h" } diff --git a/src/ape.c b/src/ape.c deleted file mode 100644 index 6257fe6b3..000000000 --- a/src/ape.c +++ /dev/null @@ -1,115 +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 "ape.h" - -#include - -#include -#include -#include -#include - -struct ape_footer { - unsigned char id[8]; - uint32_t version; - uint32_t length; - uint32_t count; - unsigned char flags[4]; - unsigned char reserved[8]; -}; - -static bool -ape_scan_internal(FILE *fp, tag_ape_callback_t callback, void *ctx) -{ - /* determine if file has an apeV2 tag */ - struct ape_footer footer; - if (fseek(fp, -(long)sizeof(footer), SEEK_END) || - fread(&footer, 1, sizeof(footer), fp) != sizeof(footer) || - memcmp(footer.id, "APETAGEX", sizeof(footer.id)) != 0 || - GUINT32_FROM_LE(footer.version) != 2000) - return false; - - /* find beginning of ape tag */ - size_t remaining = GUINT32_FROM_LE(footer.length); - if (remaining <= sizeof(footer) + 10 || - /* refuse to load more than one megabyte of tag data */ - remaining > 1024 * 1024 || - fseek(fp, -(long)remaining, SEEK_END)) - return false; - - /* read tag into buffer */ - remaining -= sizeof(footer); - assert(remaining > 10); - - char *buffer = g_malloc(remaining); - if (fread(buffer, 1, remaining, fp) != remaining) { - g_free(buffer); - return false; - } - - /* read tags */ - unsigned n = GUINT32_FROM_LE(footer.count); - const char *p = buffer; - while (n-- && remaining > 10) { - size_t size = GUINT32_FROM_LE(*(const uint32_t *)p); - p += 4; - remaining -= 4; - unsigned long flags = GUINT32_FROM_LE(*(const uint32_t *)p); - p += 4; - remaining -= 4; - - /* get the key */ - const char *key = p; - while (remaining > size && *p != '\0') { - p++; - remaining--; - } - p++; - remaining--; - - /* get the value */ - if (remaining < size) - break; - - if (!callback(flags, key, p, size, ctx)) - break; - - p += size; - remaining -= size; - } - - g_free(buffer); - return true; -} - -bool -tag_ape_scan(const char *path_fs, tag_ape_callback_t callback, void *ctx) -{ - FILE *fp; - - fp = fopen(path_fs, "rb"); - if (fp == NULL) - return false; - - bool success = ape_scan_internal(fp, callback, ctx); - fclose(fp); - return success; -} diff --git a/src/ape.h b/src/ape.h deleted file mode 100644 index c2b271b15..000000000 --- a/src/ape.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 MPD_APE_H -#define MPD_APE_H - -#include "check.h" - -#include -#include - -typedef bool (*tag_ape_callback_t)(unsigned long flags, const char *key, - const char *value, size_t value_length, - void *ctx); - -/** - * Scans the APE tag values from a file. - * - * @param path_fs the path of the file in filesystem encoding - * @return false if the file could not be opened or if no APE tag is - * present - */ -bool -tag_ape_scan(const char *path_fs, tag_ape_callback_t callback, void *ctx); - -#endif diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx index 6776f7193..a1512ee63 100644 --- a/src/decoder/WavpackDecoderPlugin.cxx +++ b/src/decoder/WavpackDecoderPlugin.cxx @@ -27,7 +27,7 @@ extern "C" { } #include "tag_handler.h" -#include "tag_ape.h" +#include "ApeTag.hxx" #include #include diff --git a/src/playlist/EmbeddedCuePlaylistPlugin.cxx b/src/playlist/EmbeddedCuePlaylistPlugin.cxx index 8f8d87153..c45e1d718 100644 --- a/src/playlist/EmbeddedCuePlaylistPlugin.cxx +++ b/src/playlist/EmbeddedCuePlaylistPlugin.cxx @@ -29,14 +29,11 @@ #include "tag.h" #include "tag_handler.h" #include "TagId3.hxx" +#include "ApeTag.hxx" #include "Song.hxx" #include "TagFile.hxx" #include "cue/CueParser.hxx" -extern "C" { -#include "tag_ape.h" -} - #include #include #include diff --git a/src/replay_gain_ape.c b/src/replay_gain_ape.c deleted file mode 100644 index 0b59e3c02..000000000 --- a/src/replay_gain_ape.c +++ /dev/null @@ -1,78 +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 "replay_gain_ape.h" -#include "replay_gain_info.h" -#include "ape.h" - -#include - -#include -#include - -struct rg_ape_ctx { - struct replay_gain_info *info; - bool found; -}; - -static bool -replay_gain_ape_callback(unsigned long flags, const char *key, - const char *_value, size_t value_length, void *_ctx) -{ - struct rg_ape_ctx *ctx = _ctx; - - /* we only care about utf-8 text tags */ - if ((flags & (0x3 << 1)) != 0) - return true; - - char value[16]; - if (value_length >= sizeof(value)) - return true; - memcpy(value, _value, value_length); - value[value_length] = 0; - - if (g_ascii_strcasecmp(key, "replaygain_track_gain") == 0) { - ctx->info->tuples[REPLAY_GAIN_TRACK].gain = atof(value); - ctx->found = true; - } else if (g_ascii_strcasecmp(key, "replaygain_album_gain") == 0) { - ctx->info->tuples[REPLAY_GAIN_ALBUM].gain = atof(value); - ctx->found = true; - } else if (g_ascii_strcasecmp(key, "replaygain_track_peak") == 0) { - ctx->info->tuples[REPLAY_GAIN_TRACK].peak = atof(value); - ctx->found = true; - } else if (g_ascii_strcasecmp(key, "replaygain_album_peak") == 0) { - ctx->info->tuples[REPLAY_GAIN_ALBUM].peak = atof(value); - ctx->found = true; - } - - return true; -} - -bool -replay_gain_ape_read(const char *path_fs, struct replay_gain_info *info) -{ - struct rg_ape_ctx ctx = { - .info = info, - .found = false, - }; - - return tag_ape_scan(path_fs, replay_gain_ape_callback, &ctx) && - ctx.found; -} diff --git a/src/replay_gain_ape.h b/src/replay_gain_ape.h deleted file mode 100644 index 35760a0aa..000000000 --- a/src/replay_gain_ape.h +++ /dev/null @@ -1,32 +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 MPD_REPLAY_GAIN_APE_H -#define MPD_REPLAY_GAIN_APE_H - -#include "check.h" - -#include - -struct replay_gain_info; - -bool -replay_gain_ape_read(const char *path_fs, struct replay_gain_info *info); - -#endif diff --git a/src/tag_ape.c b/src/tag_ape.c deleted file mode 100644 index 0adc43092..000000000 --- a/src/tag_ape.c +++ /dev/null @@ -1,117 +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 "tag_ape.h" -#include "tag.h" -#include "tag_table.h" -#include "tag_handler.h" -#include "ape.h" - -const struct tag_table ape_tags[] = { - { "album artist", TAG_ALBUM_ARTIST }, - { "year", TAG_DATE }, - { NULL, TAG_NUM_OF_ITEM_TYPES } -}; - -static enum tag_type -tag_ape_name_parse(const char *name) -{ - enum tag_type type = tag_table_lookup_i(ape_tags, name); - if (type == TAG_NUM_OF_ITEM_TYPES) - type = tag_name_parse_i(name); - - return type; -} - -/** - * @return true if the item was recognized - */ -static bool -tag_ape_import_item(unsigned long flags, - const char *key, const char *value, size_t value_length, - const struct tag_handler *handler, void *handler_ctx) -{ - /* we only care about utf-8 text tags */ - if ((flags & (0x3 << 1)) != 0) - return false; - - tag_handler_invoke_pair(handler, handler_ctx, key, value); - - enum tag_type type = tag_ape_name_parse(key); - if (type == TAG_NUM_OF_ITEM_TYPES) - return false; - - bool recognized = false; - const char *end = value + value_length; - while (true) { - /* multiple values are separated by null bytes */ - const char *n = memchr(value, 0, end - value); - if (n != NULL) { - if (n > value) { - tag_handler_invoke_tag(handler, handler_ctx, - type, value); - recognized = true; - } - - value = n + 1; - } else { - char *p = g_strndup(value, end - value); - tag_handler_invoke_tag(handler, handler_ctx, - type, p); - g_free(p); - recognized = true; - break; - } - } - - return recognized; -} - -struct tag_ape_ctx { - const struct tag_handler *handler; - void *handler_ctx; - - bool recognized; -}; - -static bool -tag_ape_callback(unsigned long flags, const char *key, - const char *value, size_t value_length, void *_ctx) -{ - struct tag_ape_ctx *ctx = _ctx; - - ctx->recognized |= tag_ape_import_item(flags, key, value, value_length, - ctx->handler, ctx->handler_ctx); - return true; -} - -bool -tag_ape_scan2(const char *path_fs, - const struct tag_handler *handler, void *handler_ctx) -{ - struct tag_ape_ctx ctx = { - .handler = handler, - .handler_ctx = handler_ctx, - .recognized = false, - }; - - return tag_ape_scan(path_fs, tag_ape_callback, &ctx) && - ctx.recognized; -} diff --git a/src/tag_ape.h b/src/tag_ape.h deleted file mode 100644 index e2daf088d..000000000 --- a/src/tag_ape.h +++ /dev/null @@ -1,40 +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 MPD_TAG_APE_H -#define MPD_TAG_APE_H - -#include "tag_table.h" - -#include - -struct tag_handler; - -extern const struct tag_table ape_tags[]; - -/** - * Scan the APE tags of a file. - * - * @param path_fs the path of the file in filesystem encoding - */ -bool -tag_ape_scan2(const char *path_fs, - const struct tag_handler *handler, void *handler_ctx); - -#endif -- cgit v1.2.3