chiark / gitweb /
report unreadable tracks and dirs
[disorder] / server / server.c
index a30e97828b4f30a1e9a646171a7464c2d591b0c5..2875ffbf4e1625c948d504f35819a6d66ab412bb 100644 (file)
@@ -42,6 +42,7 @@
 #include "server.h"
 #include "syscalls.h"
 #include "queue.h"
+#include "server-queue.h"
 #include "play.h"
 #include "log.h"
 #include "mem.h"
@@ -391,7 +392,8 @@ static int c_user(struct conn *c,
     sink_writes(ev_writer_sink(c->w), "530 authentication failed\n");
     return 1;
   }
-  res = authhash(c->nonce, sizeof c->nonce, config->allow.s[n].s[1]);
+  res = authhash(c->nonce, sizeof c->nonce, config->allow.s[n].s[1],
+                config->authorization_algorithm);
   if(wideopen || (res && !strcmp(res, vec[1]))) {
     c->who = vec[0];
     /* currently we only bother logging remote connections */
@@ -913,6 +915,34 @@ static int c_nop(struct conn *c,
   return 1;
 }
 
+static int c_new(struct conn *c,
+                char **vec,
+                int nvec) {
+  char **tracks = trackdb_new(0, nvec > 0 ? atoi(vec[0]) : INT_MAX);
+
+  sink_printf(ev_writer_sink(c->w), "253 New track list follows\n");
+  while(*tracks) {
+    sink_printf(ev_writer_sink(c->w), "%s%s\n",
+               **tracks == '.' ? "." : "", *tracks);
+    ++tracks;
+  }
+  sink_writes(ev_writer_sink(c->w), ".\n");
+  return 1;                            /* completed */
+
+}
+
+static int c_rtp_address(struct conn *c,
+                        char attribute((unused)) **vec,
+                        int attribute((unused)) nvec) {
+  if(config->speaker_backend == BACKEND_NETWORK) {
+    sink_printf(ev_writer_sink(c->w), "252 %s %s\n",
+               quoteutf8(config->broadcast.s[0]),
+               quoteutf8(config->broadcast.s[1]));
+  } else
+    sink_writes(ev_writer_sink(c->w), "550 No RTP\n");
+  return 1;
+}
 #define C_AUTH         0001            /* must be authenticated */
 #define C_TRUSTED      0002            /* must be trusted user */
 
@@ -936,6 +966,7 @@ static const struct command {
   { "log",            0, 0,       c_log,            C_AUTH },
   { "move",           2, 2,       c_move,           C_AUTH },
   { "moveafter",      1, INT_MAX, c_moveafter,      C_AUTH },
+  { "new",            0, 1,       c_new,            C_AUTH },
   { "nop",            0, 0,       c_nop,            C_AUTH },
   { "part",           3, 3,       c_part,           C_AUTH },
   { "pause",          0, 0,       c_pause,          C_AUTH },
@@ -952,6 +983,7 @@ static const struct command {
   { "rescan",         0, 0,       c_rescan,         C_AUTH|C_TRUSTED },
   { "resolve",        1, 1,       c_resolve,        C_AUTH },
   { "resume",         0, 0,       c_resume,         C_AUTH },
+  { "rtp-address",    0, 0,       c_rtp_address,    C_AUTH },
   { "scratch",        0, 1,       c_scratch,        C_AUTH },
   { "search",         1, 1,       c_search,         C_AUTH },
   { "set",            3, 3,       c_set,            C_AUTH, },
@@ -1084,7 +1116,15 @@ static int listen_callback(ev_source *ev,
   c->reader = reader_callback;
   c->l = l;
   gcry_randomize(c->nonce, sizeof c->nonce, GCRY_STRONG_RANDOM);
-  sink_printf(ev_writer_sink(c->w), "231 %s\n", hex(c->nonce, sizeof c->nonce));
+  if(!strcmp(config->authorization_algorithm, "sha1")
+     || !strcmp(config->authorization_algorithm, "SHA1")) {
+    sink_printf(ev_writer_sink(c->w), "231 %s\n",
+               hex(c->nonce, sizeof c->nonce));
+  } else {
+    sink_printf(ev_writer_sink(c->w), "231 %s %s\n",
+               config->authorization_algorithm,
+               hex(c->nonce, sizeof c->nonce));
+  }
   return 0;
 }