]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
the new plm database tool
authorAndre <maan@p133.(none)>
Tue, 21 Feb 2006 06:06:17 +0000 (07:06 +0100)
committerAndre <maan@p133.(none)>
Tue, 21 Feb 2006 06:06:17 +0000 (07:06 +0100)
does not work yet as the ipc problems are not solved.

configure.ac
db.h
error.h
plm_dbtool.c [new file with mode: 0644]
server.c

index 46ba57e57e6e1b0f37ff92983c0a062d49964368..4f75f3ab58c78c95d5ca1a7da9f94621323397e2 100644 (file)
@@ -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
 
 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
 server_ldflags=""
 
 ########################################################################### ssl
diff --git a/db.h b/db.h
index 5f9f2cbf4b9f7c53a383d03ef36529a8911f5a67..34ea52d1d3423b678222332cea01e84afc22b122 100644 (file)
--- a/db.h
+++ b/db.h
@@ -91,5 +91,6 @@ void (*shutdown)(void);
 };
 
 int mysql_dbtool_init(struct dbtool*);
 };
 
 int mysql_dbtool_init(struct dbtool*);
+int plm_dbtool_init(struct dbtool*);
 int random_dbtool_init(struct dbtool*);
 
 int random_dbtool_init(struct dbtool*);
 
diff --git a/error.h b/error.h
index 028dd7f2e8e8832bd6b6c2970bc68bbc54471d9f..a3755cef5824011de968ec5ce30af6e8045c7773 100644 (file)
--- 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_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[];
        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"), \
 
        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
 
 /* 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(AFS);
 SS_ENUM(COMMAND);
 SS_ENUM(RANDOM_DBTOOL);
+SS_ENUM(PLM_DBTOOL);
 SS_ENUM(CRYPT);
 SS_ENUM(HTTP_SEND);
 SS_ENUM(ORTP_SEND);
 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 (file)
index 0000000..fd18f25
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2006 Andre Noll <maan@systemlinux.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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ */
+
+/** \file plm_dbtool.c Simple playlist manager for paraslash  */
+
+#include <sys/time.h> /* 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;
+}
index 044792f13c40807477cd984501deab4d0d0611e2..73b8b057cfe6071535733292bde293986f72930d 100644 (file)
--- a/server.c
+++ b/server.c
@@ -67,6 +67,11 @@ struct dbtool dblist[] = {
                .init = random_dbtool_init,
                .update_audio_file = NULL,
        },
                .init = random_dbtool_init,
                .update_audio_file = NULL,
        },
+       {
+               .name = "plm",
+               .init = plm_dbtool_init,
+               .update_audio_file = NULL,
+       },
 #ifdef HAVE_MYSQL
        {
                .name = "mysql",
 #ifdef HAVE_MYSQL
        {
                .name = "mysql",