From 8db6cb34ef06dff8aaf6f4fa4189151216354c9a Mon Sep 17 00:00:00 2001 From: Andre Date: Tue, 21 Feb 2006 07:06:17 +0100 Subject: [PATCH] the new plm database tool does not work yet as the ipc problems are not solved. --- configure.ac | 2 +- db.h | 1 + error.h | 5 +- plm_dbtool.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++ server.c | 5 ++ 5 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 plm_dbtool.c diff --git a/configure.ac b/configure.ac index 46ba57e5..4f75f3ab 100644 --- a/configure.ac +++ b/configure.ac @@ -73,7 +73,7 @@ audiod_ldflags="" server_cmdline_objs="server.cmdline" server_errlist_objs="server mp3 afs command net string signal random_dbtool time daemon stat - crypt http_send db close_on_fork" + crypt http_send db close_on_fork plm_dbtool" server_ldflags="" ########################################################################### ssl diff --git a/db.h b/db.h index 5f9f2cbf..34ea52d1 100644 --- a/db.h +++ b/db.h @@ -91,5 +91,6 @@ void (*shutdown)(void); }; int mysql_dbtool_init(struct dbtool*); +int plm_dbtool_init(struct dbtool*); int random_dbtool_init(struct dbtool*); diff --git a/error.h b/error.h index 028dd7f2..a3755cef 100644 --- a/error.h +++ b/error.h @@ -23,7 +23,7 @@ enum para_subsystem {SS_RECV, SS_NET, SS_ORTP_RECV, SS_AUDIOD, SS_EXEC, SS_CLOSE_ON_FORK, SS_SIGNAL, SS_STRING, SS_DAEMON, SS_STAT, SS_TIME, SS_GRAB_CLIENT, SS_HTTP_RECV, SS_RECV_COMMON, SS_FILTER_CHAIN, SS_WAV, SS_COMPRESS, SS_OGGDEC, SS_FILTER, - SS_COMMAND, SS_RANDOM_DBTOOL, SS_CRYPT, SS_HTTP_SEND, SS_ORTP_SEND, SS_DB, SS_OGG, + SS_COMMAND, SS_RANDOM_DBTOOL, SS_PLM_DBTOOL, SS_CRYPT, SS_HTTP_SEND, SS_ORTP_SEND, SS_DB, SS_OGG, SS_MP3, SS_MP3DEC, SS_SERVER, SS_AFS, SS_MYSQL, SS_RINGBUFFER}; #define NUM_SS (SS_RINGBUFFER + 1) extern const char **para_errlist[]; @@ -224,6 +224,8 @@ extern const char **para_errlist[]; PARA_ERROR(LOCK, "lock error"), \ PARA_ERROR(SENDER_CMD, "command not supported by this sender"), \ +#define PLM_DBTOOL_ERRORS \ + PARA_ERROR(LOAD_PLAYLIST, "failed to load playlist"), \ /* these do not need error handling (yet) */ #define SERVER_ERRORS @@ -332,6 +334,7 @@ SS_ENUM(SERVER); SS_ENUM(AFS); SS_ENUM(COMMAND); SS_ENUM(RANDOM_DBTOOL); +SS_ENUM(PLM_DBTOOL); SS_ENUM(CRYPT); SS_ENUM(HTTP_SEND); SS_ENUM(ORTP_SEND); diff --git a/plm_dbtool.c b/plm_dbtool.c new file mode 100644 index 00000000..fd18f254 --- /dev/null +++ b/plm_dbtool.c @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2006 Andre Noll + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + */ + +/** \file plm_dbtool.c Simple playlist manager for paraslash */ + +#include /* gettimeofday */ +#include "server.cmdline.h" +#include "server.h" +#include "db.h" +#include "error.h" +#include "net.h" +#include "string.h" + +#define MAX_PLAYLIST_LEN 10000 +#define MAX_PLAYLIST_BYTES (1024 * 1024) + +static unsigned playlist_len, playlist_size, current_playlist_entry; +static char **playlist; + +static int com_ppl(int, int, char **); +static int com_lpl(int, int, char **); +extern struct misc_meta_data *mmd; + +/* array of commands that are supported by this database tool */ +static struct server_command cmds[] = { +{ +.name = "ppl", +.handler = com_ppl, +.perms = DB_READ, +.description = "print playlist", +.synopsis = "ppl", +.help = +"Print out the current playlist" +}, { +.name = "lpl", +.handler = com_lpl, +.perms = DB_WRITE, +.description = "load playlist", +.synopsis = "lpl", +.help = +"Read a new playlist from stdin" + +}, { +.name = NULL, +} +}; + +static void playlist_add(char *path) +{ + if (playlist_len >= playlist_size) { + if (playlist_size >= MAX_PLAYLIST_LEN) + return; + playlist_size *= 2; + playlist = para_realloc(playlist, playlist_size * sizeof(char *)); + } + PARA_DEBUG_LOG("adding #%d: %s\n", playlist_len, path); + playlist[playlist_len] = para_strdup(path); + playlist_len++; +} + +static int com_lpl(int fd, __unused int argc, __unused char *argv[]) +{ + unsigned i, loaded = 0; + char buf[_POSIX_PATH_MAX]; + ssize_t ret; + + PARA_DEBUG_LOG("freeing playlist (%d entries)\n", playlist_len); + for (i = 0; i < playlist_len; i++) + free(playlist[i]); + current_playlist_entry = 0; + playlist_len = 0; + ret = send_buffer(fd, AWAITING_DATA_MSG); + if (ret < 0) + return ret; +again: + ret = recv_bin_buffer(fd, buf + loaded, sizeof(buf) - loaded); + if (ret < 0) + goto err_out; + if (!ret) { + PARA_DEBUG_LOG("loaded playlist (%d entries)\n", playlist_len); + return playlist_len; + } + loaded += ret; + loaded = for_each_line(buf, loaded, &playlist_add, 0); + if (loaded >= sizeof(buf)) + goto err_out; + goto again; +err_out: + return -E_LOAD_PLAYLIST; +} + +static int com_ppl(int fd, __unused int argc, __unused char *argv[]) +{ + unsigned i; + + PARA_DEBUG_LOG("sending playlist (%d entries)\n", playlist_len); + for (i = 0; i < playlist_len; i++) { + int ret = send_buffer(fd, playlist[i]); + if (ret < 0) + return ret; + } + return 1; +} + +static char **plm_get_audio_file_list(unsigned int num) +{ + char **file_list; + unsigned i; + + return NULL; + num = MIN(num, playlist_len); + if (!num) + return NULL; + file_list = para_malloc((num + 1) * sizeof(char *)); + for (i = 0; i < num; i++) { + unsigned j = (current_playlist_entry + i) % playlist_len; + file_list[i] = para_strdup(playlist[j]); + } + file_list[i] = NULL; + return file_list; +} + +static void plm_shutdown(void) +{ + /* free the playlist */ +} + +/** + * the init function for the plm database tool + * + * Init all function pointers of \a db + * + * \sa struct dbtool, misc_meta_data::dbinfo, mysql.c random_dbtool.c + */ +int plm_dbtool_init(struct dbtool *db) +{ + playlist = para_calloc(100 * sizeof(char *)); /* guess 100 is enough */ + playlist_size = 100; + sprintf(mmd->dbinfo, "plm initialized"); + db->cmd_list = cmds; + db->get_audio_file_list = plm_get_audio_file_list; + db->shutdown = plm_shutdown; + return 1; +} diff --git a/server.c b/server.c index 044792f1..73b8b057 100644 --- a/server.c +++ b/server.c @@ -67,6 +67,11 @@ struct dbtool dblist[] = { .init = random_dbtool_init, .update_audio_file = NULL, }, + { + .name = "plm", + .init = plm_dbtool_init, + .update_audio_file = NULL, + }, #ifdef HAVE_MYSQL { .name = "mysql", -- 2.39.2