From ad492e00c1aafb3aec7c385e1a29606742433e7e Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 15 Jun 2008 14:19:11 +0100 Subject: [PATCH] Send clients a rights-changed message when their rights change. Organization: Straylight/Edgeware From: Richard Kettlewell --- doc/disorder_protocol.5.in | 3 +++ lib/eclient.c | 11 +++++++++++ lib/eclient.h | 5 +++++ server/server.c | 20 +++++++++++++++++--- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/doc/disorder_protocol.5.in b/doc/disorder_protocol.5.in index 367a68a..85c16a2 100644 --- a/doc/disorder_protocol.5.in +++ b/doc/disorder_protocol.5.in @@ -620,6 +620,9 @@ A track started playing. .B resume The current track was resumed. .TP +.B rights-changed \fIRIGHTS\fR +User's rights were changed. +.TP .B scratched The current track was scratched. .PP diff --git a/lib/eclient.c b/lib/eclient.c index e7395f3..ad34a21 100644 --- a/lib/eclient.c +++ b/lib/eclient.c @@ -184,6 +184,7 @@ static void logentry_user_add(disorder_eclient *c, int nvec, char **vec); 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); /* Tables ********************************************************************/ @@ -209,6 +210,7 @@ static const struct logentry_handler logentry_handlers[] = { LE(recent_removed, 1, 1), LE(removed, 1, 2), LE(rescanned, 0, 0), + LE(rights_changed, 1, 1), LE(scratched, 2, 2), LE(state, 1, 1), LE(user_add, 1, 1), @@ -1563,6 +1565,15 @@ static void logentry_user_edit(disorder_eclient *c, c->log_callbacks->user_edit(c->log_v, vec[0], vec[1]); } +static void logentry_rights_changed(disorder_eclient *c, + int attribute((unused)) nvec, char **vec) { + if(c->log_callbacks->rights_changed) { + rights_type r; + if(parse_rights(vec[0], &r, 0/*report*/)) + c->log_callbacks->rights_changed(c->log_v, r); + } +} + static const struct { unsigned long bit; const char *enable; diff --git a/lib/eclient.h b/lib/eclient.h index 1d1b301..be5730c 100644 --- a/lib/eclient.h +++ b/lib/eclient.h @@ -24,6 +24,8 @@ #ifndef ECLIENT_H #define ECLIENT_H +#include "rights.h" + /* Asynchronous client interface */ /** @brief Handle type */ @@ -162,6 +164,9 @@ typedef struct disorder_eclient_log_callbacks { /** @brief Called when a user is edited (admins only) */ void (*user_edit)(void *v, const char *user, const char *property); + + /** @brief Called when your rights change */ + void (*rights_changed)(void *v, rights_type new_rights); } disorder_eclient_log_callbacks; /* State bits */ diff --git a/server/server.c b/server/server.c index 46647b1..1bfa29a 100644 --- a/server/server.c +++ b/server/server.c @@ -876,6 +876,7 @@ static void logclient(const char *msg, void *user) { if(!c->w || !c->r) { /* This connection has gone up in smoke for some reason */ eventlog_remove(c->lo); + c->lo = 0; return; } /* user-* messages are restricted */ @@ -1244,10 +1245,21 @@ static int c_edituser(struct conn *c, /* Update rights for this user */ rights_type r; - if(parse_rights(vec[2], &r, 1)) - for(d = connections; d; d = d->next) - if(!strcmp(d->who, vec[0])) + if(!parse_rights(vec[2], &r, 1)) { + const char *new_rights = rights_string(r); + for(d = connections; d; d = d->next) { + if(!strcmp(d->who, vec[0])) { + /* Update rights */ d->rights = r; + /* Notify any log connections */ + if(d->lo) + sink_printf(ev_writer_sink(d->w), + "%"PRIxMAX" rights-changed %s\n", + (uintmax_t)time(0), + new_rights); + } + } + } } sink_writes(ev_writer_sink(c->w), "250 OK\n"); } else { @@ -1762,6 +1774,7 @@ static int listen_callback(ev_source *ev, D(("server listen_callback fd %d (%s)", fd, l->name)); nonblock(fd); cloexec(fd); + c->next = connections; c->tag = tags++; c->ev = ev; c->w = ev_writer_new(ev, fd, writer_error, c, @@ -1773,6 +1786,7 @@ static int listen_callback(ev_source *ev, c->reader = reader_callback; c->l = l; c->rights = 0; + connections = c; gcry_randomize(c->nonce, sizeof c->nonce, GCRY_STRONG_RANDOM); sink_printf(ev_writer_sink(c->w), "231 %d %s %s\n", 2, -- [mdw]