From 5c102112f4a3b71145bf42091d93d5d353d2b143 Mon Sep 17 00:00:00 2001 From: Richard Kettlewell Date: Sun, 3 Aug 2008 20:47:10 +0100 Subject: [PATCH 1/1] Playlist event log support for server and eclient. --- doc/disorder_protocol.5.in | 17 ++++++++++++++++- lib/eclient.c | 27 +++++++++++++++++++++++++++ lib/eclient.h | 11 ++++++++++- lib/trackdb-playlists.c | 14 ++++++++++++-- 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/doc/disorder_protocol.5.in b/doc/disorder_protocol.5.in index c258b0b..5a8a481 100644 --- a/doc/disorder_protocol.5.in +++ b/doc/disorder_protocol.5.in @@ -612,6 +612,21 @@ Further details aren't included any more. .B playing \fITRACK\fR [\fIUSERNAME\fR] Started playing \fITRACK\fR. .TP +.B playlist_created \fIPLAYLIST\fR \fISHARING\fR +Sent when a playlist is created. +For private playlists this is intended to be sent only to the owner (but +this is not currently implemented). +.TP +.B playlist_deleted \fIPLAYLIST\fR +Sent when a playlist is deleted. +For private playlists this is intended to be sent only to the owner (but +this is not currently implemented). +.TP +.B playlist_modified \fIPLAYLIST\fR \fISHARING\fR +Sent when a playlist is modified (either its contents or its sharing status). +For private playlists this is intended to be sent only to the owner (but +this is not currently implemented). +.TP .B queue \fIQUEUE-ENTRY\fR... Added \fITRACK\fR to the queue. .TP @@ -673,7 +688,7 @@ The current track was scratched. To simplify client implementation, \fBstate\fR commands reflecting the current state are sent at the start of the log. .RE -.TB +.TP .B user_add \fIUSERNAME\fR A user was created. .TP diff --git a/lib/eclient.c b/lib/eclient.c index 8efb07f..8e89a31 100644 --- a/lib/eclient.c +++ b/lib/eclient.c @@ -191,6 +191,9 @@ static void logentry_user_confirm(disorder_eclient *c, int nvec, char **vec); static void logentry_user_delete(disorder_eclient *c, int nvec, char **vec); static void logentry_user_edit(disorder_eclient *c, int nvec, char **vec); static void logentry_rights_changed(disorder_eclient *c, int nvec, char **vec); +static void logentry_playlist_created(disorder_eclient *c, int nvec, char **vec); +static void logentry_playlist_deleted(disorder_eclient *c, int nvec, char **vec); +static void logentry_playlist_modified(disorder_eclient *c, int nvec, char **vec); /* Tables ********************************************************************/ @@ -211,6 +214,9 @@ static const struct logentry_handler logentry_handlers[] = { LE(failed, 2, 2), LE(moved, 1, 1), LE(playing, 1, 2), + LE(playlist_created, 2, 2), + LE(playlist_deleted, 1, 1), + LE(playlist_modified, 2, 2), LE(queue, 2, INT_MAX), LE(recent_added, 2, INT_MAX), LE(recent_removed, 1, 1), @@ -1768,6 +1774,27 @@ static void logentry_rights_changed(disorder_eclient *c, } } +static void logentry_playlist_created(disorder_eclient *c, + int attribute((unused)) nvec, + char **vec) { + if(c->log_callbacks->playlist_created) + c->log_callbacks->playlist_created(c->log_v, vec[0], vec[1]); +} + +static void logentry_playlist_deleted(disorder_eclient *c, + int attribute((unused)) nvec, + char **vec) { + if(c->log_callbacks->playlist_deleted) + c->log_callbacks->playlist_deleted(c->log_v, vec[0]); +} + +static void logentry_playlist_modified(disorder_eclient *c, + int attribute((unused)) nvec, + char **vec) { + if(c->log_callbacks->playlist_modified) + c->log_callbacks->playlist_modified(c->log_v, vec[0], vec[1]); +} + static const struct { unsigned long bit; const char *enable; diff --git a/lib/eclient.h b/lib/eclient.h index 7bf34d5..2bbc367 100644 --- a/lib/eclient.h +++ b/lib/eclient.h @@ -1,6 +1,6 @@ /* * This file is part of DisOrder. - * Copyright (C) 2006, 2007 Richard Kettlewell + * Copyright (C) 2006-2008 Richard Kettlewell * * 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 @@ -167,6 +167,15 @@ typedef struct disorder_eclient_log_callbacks { /** @brief Called when your rights change */ void (*rights_changed)(void *v, rights_type new_rights); + + /** @brief Called when a new playlist is created */ + void (*playlist_created)(void *v, const char *playlist, const char *sharing); + + /** @brief Called when a playlist is modified */ + void (*playlist_modified)(void *v, const char *playlist, const char *sharing); + + /** @brief Called when a new playlist is deleted */ + void (*playlist_deleted)(void *v, const char *playlist); } disorder_eclient_log_callbacks; /* State bits */ diff --git a/lib/trackdb-playlists.c b/lib/trackdb-playlists.c index 133e8b7..bef7107 100644 --- a/lib/trackdb-playlists.c +++ b/lib/trackdb-playlists.c @@ -32,6 +32,7 @@ #include "log.h" #include "configuration.h" #include "vector.h" +#include "eventlog.h" static int trackdb_playlist_get_tid(const char *name, const char *who, @@ -293,6 +294,7 @@ static int trackdb_playlist_set_tid(const char *name, struct kvp *k; int e; const char *s; + const char *event = "playlist_modified"; if((e = trackdb_getdata(trackdb_playlistsdb, name, &k, tid)) && e != DB_NOTFOUND) @@ -311,6 +313,7 @@ static int trackdb_playlist_set_tid(const char *name, k = 0; kvp_set(&k, "count", 0); kvp_set(&k, "sharing", defshare); + event = "playlist_created"; } /* Check that the modification is allowed */ if(!(s = kvp_get(k, "sharing"))) { @@ -354,7 +357,11 @@ static int trackdb_playlist_set_tid(const char *name, kvp_set(&k, "count", b); } /* Store the resulting record */ - return trackdb_putdata(trackdb_playlistsdb, name, k, tid, 0); + e = trackdb_putdata(trackdb_playlistsdb, name, k, tid, 0); + /* Log the event */ + if(!e) + eventlog(event, name, kvp_get(k, "sharing"), (char *)0); + return e; } /** @brief Get a list of playlists @@ -468,7 +475,10 @@ static int trackdb_playlist_delete_tid(const char *name, if(!playlist_may_write(name, who, s)) return EACCES; /* Delete the playlist */ - return trackdb_delkey(trackdb_playlistsdb, name, tid); + e = trackdb_delkey(trackdb_playlistsdb, name, tid); + if(!e) + eventlog("playlist_deleted", name, 0); + return e; } /* -- 2.11.0