/**
+ * Copyright (C) 2008-2011 by ProFUSION embedded systems
* Copyright (C) 2007 by INdT
*
- * This program is free software; you can redistribute it and/or
+ * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation; either version 2.1 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.
+ * This library 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
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
*
- * @author Gustavo Sverzut Barbieri <gustavo.barbieri@openbossa.org>
+ * @author Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
*/
/**
* In theory this should not happen, so let's wait for bug reports.
*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#define _XOPEN_SOURCE 600
#include <lightmediascanner_plugin.h>
#include <lightmediascanner_db.h>
#include <sys/types.h>
perror("read");
return -4;
} else if (r != sizeof(buf) - 1) {
- fprintf(stderr, "ERROR: premature end of file: read %d of %d bytes.\n",
- r, sizeof(buf) - 1);
+ fprintf(stderr, "ERROR: premature end of file: read %zd of %zd"
+ "bytes.\n", r, sizeof(buf) - 1);
return -5;
}
if (memcmp(buf + 1, header + 1, sizeof(buf) - 1) != 0) {
fprintf(stderr, "ERROR: invalid pls header '%.*s'\n",
- sizeof(buf) - 1, buf);
+ (int)sizeof(buf) - 1, buf);
return -6;
}
static const struct lms_string_size _exts[] = {
LMS_STATIC_STRING_SIZE(".pls")
};
+static const char *_cats[] = {
+ "multimedia",
+ "audio",
+ "playlist",
+ NULL
+};
+static const char *_authors[] = {
+ "Gustavo Sverzut Barbieri",
+ NULL
+};
struct plugin {
struct lms_plugin plugin;
static void *
_match(struct plugin *p, const char *path, int len, int base)
{
- int i;
+ long i;
i = lms_which_extension(path, len, _exts, LMS_ARRAY_SIZE(_exts));
if (i < 0)
static int
_parse(struct plugin *plugin, struct lms_context *ctxt, const struct lms_file_info *finfo, void *match)
{
- struct lms_playlist_info info = {0};
- int fd, r, ext_idx;
+ struct lms_playlist_info info = { };
+ int fd, r;
+ long ext_idx;
fd = open(finfo->path, O_RDONLY);
if (fd < 0) {
return -1;
}
- ext_idx = ((int)match) - 1;
- info.title.len = finfo->path_len - finfo->base - _exts[ext_idx].len;
- info.title.str = malloc((info.title.len + 1) * sizeof(char));
- memcpy(info.title.str, finfo->path + finfo->base, info.title.len);
- info.title.str[info.title.len] = '\0';
+ ext_idx = ((long)match) - 1;
+ lms_string_size_strndup(&info.title, finfo->path + finfo->base,
+ finfo->path_len - finfo->base - _exts[ext_idx].len);
lms_charset_conv(ctxt->cs_conv, &info.title.str, &info.title.len);
info.id = finfo->id;
r = lms_db_playlist_add(plugin->playlist_db, &info);
- if (info.title.str)
- free(info.title.str);
+ free(info.title.str);
posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
close(fd);
plugin->plugin.setup = (lms_plugin_setup_fn_t)_setup;
plugin->plugin.start = (lms_plugin_start_fn_t)_start;
plugin->plugin.finish = (lms_plugin_finish_fn_t)_finish;
+ plugin->plugin.order = 0;
return (struct lms_plugin *)plugin;
}
+
+API const struct lms_plugin_info *
+lms_plugin_info(void)
+{
+ static struct lms_plugin_info info = {
+ _name,
+ _cats,
+ "Playlists (INI-style)",
+ PACKAGE_VERSION,
+ _authors,
+ "http://github.com/profusion/lightmediascanner"
+ };
+
+ return &info;
+}