chiark / gitweb /
banish fd passing. currently a bit ugly but seems to work
[disorder] / lib / client.c
index ddf88bb48aa5d8e67f79cb086eaa8c6d6b566212..d68d9d76a9ded92d3932cb762c7f4410a5db4d11 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2006 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2006, 2007 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
@@ -207,11 +207,12 @@ int disorder_connect_sock(disorder_client *c,
                          const char *username,
                          const char *password,
                          const char *ident) {
-  int fd = -1, fd2 = -1;
+  int fd = -1, fd2 = -1, nrvec;
   unsigned char *nonce;
   size_t nl;
   const char *res;
-  char *r;
+  char *r, **rvec;
+  const char *algo = "SHA1";
 
   if(!password) {
     error(0, "no password found");
@@ -243,9 +244,17 @@ int disorder_connect_sock(disorder_client *c,
   c->ident = xstrdup(ident);
   if(disorder_simple(c, &r, 0, (const char *)0))
     return -1;
-  if(!(nonce = unhex(r, &nl)))
+  if(!(rvec = split(r, &nrvec, SPLIT_QUOTES, 0, 0)))
+    return -1;
+  if(nrvec > 1) {
+    algo = *rvec++;
+    --nrvec;
+  }
+  if(!nrvec)
+    return -1;
+  if(!(nonce = unhex(*rvec, &nl)))
     return -1;
-  if(!(res = authhash(nonce, nl, password))) goto error;
+  if(!(res = authhash(nonce, nl, password, algo))) goto error;
   if(disorder_simple(c, 0, "user", username, res, (char *)0))
     return -1;
   c->user = xstrdup(username);
@@ -591,6 +600,22 @@ int disorder_tags(disorder_client *c,
   return disorder_simple_list(c, vecp, nvecp, "tags", (char *)0);
 }
 
+/** @brief Get recentl added tracks
+ * @param c Client
+ * @param vecp Where to store pointer to list
+ * @param nvecp Where to store count
+ * @param max Maximum tracks to fetch, or 0 for all available
+ * @return 0 on success, non-0 on error
+ */
+int disorder_new_tracks(disorder_client *c,
+                       char ***vecp, int *nvecp,
+                       int max) {
+  char limit[32];
+
+  sprintf(limit, "%d", max);
+  return disorder_simple_list(c, vecp, nvecp, "new", limit, (char *)0);
+}
+
 int disorder_set_global(disorder_client *c,
                        const char *key, const char *value) {
   return disorder_simple(c, 0, "set-global", key, value, (char *)0);
@@ -610,4 +635,3 @@ c-basic-offset:2
 comment-column:40
 End:
 */
-/* arch-tag:3937adbfa9480384606631d8e0365885 */