chiark / gitweb /
server: setting playing and random-play global prefs now works
authorRichard Kettlewell <rjk@terraraq.org.uk>
Sun, 31 Jul 2011 13:43:15 +0000 (14:43 +0100)
committerRichard Kettlewell <rjk@terraraq.org.uk>
Sun, 31 Jul 2011 13:43:15 +0000 (14:43 +0100)
properly.

Formerly the global prefs would be changed but the other actions
required to switch state properly were not carried out.  This was
documented, making it a design flaw rather than an implementation
error.

doc/disorder_preferences.5.in
server/disorder-server.h
server/play.c
server/server.c

index 9fbe6fbc8f8729a74cbd795598751280b2e8930f..3ce67d9bfff2ecd0c581e3c1967e3560ff649ae5 100644 (file)
@@ -92,12 +92,10 @@ the listed tags.
 .B playing
 If unset or \fByes\fR then play is enabled.
 Otherwise it is disabled.
 .B playing
 If unset or \fByes\fR then play is enabled.
 Otherwise it is disabled.
-Use \fBdisable\fR rather than setting it directly.
 .TP
 .B random\-play
 If unset or \fByes\fR then random play is enabled.
 Otherwise it is disabled.
 .TP
 .B random\-play
 If unset or \fByes\fR then random play is enabled.
 Otherwise it is disabled.
-Use \fBdisable\fR rather than setting it directly.
 .PP
 Global preferences starting '_' are read-only (in the sense that you cannot
 modify them; the server may modify them as part of its normal operation).
 .PP
 Global preferences starting '_' are read-only (in the sense that you cannot
 modify them; the server may modify them as part of its normal operation).
index 2e7374e077b8ca789911ce332d83039b80b101aa..bc90c9b046548d167042551a8bd04fcf5c8e4677 100644 (file)
@@ -179,13 +179,16 @@ void play(ev_source *ev);
 /* try to play something, if playing is enabled and nothing is playing
  * already */
 
 /* try to play something, if playing is enabled and nothing is playing
  * already */
 
+/** @brief Return true if @p represents a true flag */
+int flag_enabled(const char *s);
+
 int playing_is_enabled(void);
 /* return true iff playing is enabled */
 
 void enable_playing(const char *who, ev_source *ev);
 /* enable playing */
 
 int playing_is_enabled(void);
 /* return true iff playing is enabled */
 
 void enable_playing(const char *who, ev_source *ev);
 /* enable playing */
 
-void disable_playing(const char *who);
+void disable_playing(const char *who, ev_source *ev);
 /* disable playing. */
 
 int random_is_enabled(void);
 /* disable playing. */
 
 int random_is_enabled(void);
@@ -194,7 +197,7 @@ int random_is_enabled(void);
 void enable_random(const char *who, ev_source *ev);
 /* enable random play */
 
 void enable_random(const char *who, ev_source *ev);
 /* enable random play */
 
-void disable_random(const char *who);
+void disable_random(const char *who, ev_source *ev);
 /* disable random play */
 
 void scratch(const char *who, const char *id);
 /* disable random play */
 
 void scratch(const char *who, const char *id);
index 8406238d52f8865fe62047725ce05d87ec886d8d..9b919d1d13c301509d969b1568a1fdf671557598 100644 (file)
@@ -640,11 +640,13 @@ void play(ev_source *ev) {
 
 /* Miscelleneous ------------------------------------------------------------ */
 
 
 /* Miscelleneous ------------------------------------------------------------ */
 
+int flag_enabled(const char *s) {
+  return !s || !strcmp(s, "yes");
+}
+
 /** @brief Return true if play is enabled */
 int playing_is_enabled(void) {
 /** @brief Return true if play is enabled */
 int playing_is_enabled(void) {
-  const char *s = trackdb_get_global("playing");
-
-  return !s || !strcmp(s, "yes");
+  return flag_enabled(trackdb_get_global("playing"));
 }
 
 /** @brief Enable play */
 }
 
 /** @brief Enable play */
@@ -656,15 +658,13 @@ void enable_playing(const char *who, ev_source *ev) {
 }
 
 /** @brief Disable play */
 }
 
 /** @brief Disable play */
-void disable_playing(const char *who) {
+void disable_playing(const char *who, ev_source attribute((unused)) *ev) {
   trackdb_set_global("playing", "no", who);
 }
 
 /** @brief Return true if random play is enabled */
 int random_is_enabled(void) {
   trackdb_set_global("playing", "no", who);
 }
 
 /** @brief Return true if random play is enabled */
 int random_is_enabled(void) {
-  const char *s = trackdb_get_global("random-play");
-
-  return !s || !strcmp(s, "yes");
+  return flag_enabled(trackdb_get_global("random-play"));
 }
 
 /** @brief Enable random play */
 }
 
 /** @brief Enable random play */
@@ -675,7 +675,7 @@ void enable_random(const char *who, ev_source *ev) {
 }
 
 /** @brief Disable random play */
 }
 
 /** @brief Disable random play */
-void disable_random(const char *who) {
+void disable_random(const char *who, ev_source attribute((unused)) *ev) {
   trackdb_set_global("random-play", "no", who);
 }
 
   trackdb_set_global("random-play", "no", who);
 }
 
index d8a84ea5683d0423ed85417c72c49a5dab402354..239c54eb8b47850afa19136fef2567457052d5eb 100644 (file)
@@ -201,9 +201,9 @@ static int reader_error(ev_source attribute((unused)) *ev,
 
 static int c_disable(struct conn *c, char **vec, int nvec) {
   if(nvec == 0)
 
 static int c_disable(struct conn *c, char **vec, int nvec) {
   if(nvec == 0)
-    disable_playing(c->who);
+    disable_playing(c->who, c->ev);
   else if(nvec == 1 && !strcmp(vec[0], "now"))
   else if(nvec == 1 && !strcmp(vec[0], "now"))
-    disable_playing(c->who);
+    disable_playing(c->who, c->ev);
   else {
     sink_writes(ev_writer_sink(c->w), "550 invalid argument\n");
     return 1;                  /* completed */
   else {
     sink_writes(ev_writer_sink(c->w), "550 invalid argument\n");
     return 1;                  /* completed */
@@ -866,7 +866,7 @@ static int c_random_enable(struct conn *c,
 static int c_random_disable(struct conn *c,
                            char attribute((unused)) **vec,
                            int attribute((unused)) nvec) {
 static int c_random_disable(struct conn *c,
                            char attribute((unused)) **vec,
                            int attribute((unused)) nvec) {
-  disable_random(c->who);
+  disable_random(c->who, c->ev);
   sink_writes(ev_writer_sink(c->w), "250 OK\n");
   return 1;                    /* completed */
 }
   sink_writes(ev_writer_sink(c->w), "250 OK\n");
   return 1;                    /* completed */
 }
@@ -1150,10 +1150,17 @@ static int c_set_global(struct conn *c,
     sink_writes(ev_writer_sink(c->w), "550 cannot set internal global preferences\n");
     return 1;
   }
     sink_writes(ev_writer_sink(c->w), "550 cannot set internal global preferences\n");
     return 1;
   }
-  if(trackdb_set_global(vec[0], vec[1], c->who))
-    sink_printf(ev_writer_sink(c->w), "250 OK\n");
-  else
-    sink_writes(ev_writer_sink(c->w), "550 not found\n");
+  /* We special-case the 'magic' preferences here. */
+  if(!strcmp(vec[0], "playing")) {
+    (flag_enabled(vec[1]) ? enable_playing : disable_playing)(c->who, c->ev);
+  } else if(!strcmp(vec[0], "random-play")) {
+    (flag_enabled(vec[1]) ? enable_random : disable_random)(c->who, c->ev);
+  } else {
+    if(trackdb_set_global(vec[0], vec[1], c->who))
+      sink_printf(ev_writer_sink(c->w), "250 OK\n");
+    else
+      sink_writes(ev_writer_sink(c->w), "550 not found\n");
+  }
   return 1;
 }
 
   return 1;
 }