2 * This file is part of DisOrder.
3 * Copyright (C) 2004, 2005, 2006, 2007 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 /** @file lib/client.c
21 * @brief Simple C client
23 * See @file lib/eclient.c for an asynchronous-capable client
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
44 #include "configuration.h"
51 #include "inputline.h"
58 #include "client-common.h"
62 struct disorder_client
{
69 /** @brief Create a new client
70 * @param verbose If nonzero, write extra junk to stderr
71 * @return Pointer to new client
73 * You must call disorder_connect() or disorder_connect_cookie() to
74 * connect it. Use disorder_close() to dispose of the client when
77 disorder_client
*disorder_new(int verbose
) {
78 disorder_client
*c
= xmalloc(sizeof (struct disorder_client
));
84 /** @brief Read a response line
86 * @param rp Where to store response, or NULL (UTF-8)
87 * @return Response code 0-999 or -1 on error
89 static int response(disorder_client
*c
, char **rp
) {
92 if(inputline(c
->ident
, c
->fpin
, &r
, '\n'))
94 D(("response: %s", r
));
97 if(r
[0] >= '0' && r
[0] <= '9'
98 && r
[1] >= '0' && r
[1] <= '9'
99 && r
[2] >= '0' && r
[2] <= '9'
101 return (r
[0] * 10 + r
[1]) * 10 + r
[2] - 111 * '0';
103 error(0, "invalid reply format from %s", c
->ident
);
108 /** @brief Read and partially parse a response
110 * @param rp Where to store response text (or NULL) (UTF-8)
111 * @return 0 on success, non-0 on error
113 * 5xx responses count as errors.
115 * @p rp will NOT be filled in for xx9 responses (where it is just
116 * commentary for a command where it would normally be meaningful).
118 * NB that the response will NOT be converted to the local encoding.
120 static int check_response(disorder_client
*c
, char **rp
) {
124 if((rc
= response(c
, &r
)) == -1)
126 else if(rc
/ 100 == 2) {
128 *rp
= (rc
% 10 == 9) ?
0 : xstrdup(r
+ 4);
132 error(0, "from %s: %s", c
->ident
, utf82mb(r
));
137 /** @brief Issue a command and parse a simple response
139 * @param rp Where to store result, or NULL
141 * @param ap Arguments (UTF-8), terminated by (char *)0
142 * @return 0 on success, non-0 on error
144 * 5xx responses count as errors.
146 * @p rp will NOT be filled in for xx9 responses (where it is just
147 * commentary for a command where it would normally be meaningful).
149 * NB that the response will NOT be converted to the local encoding
150 * nor will quotes be stripped. See dequote().
152 static int disorder_simple_v(disorder_client
*c
,
154 const char *cmd
, va_list ap
) {
160 dynstr_append_string(&d
, cmd
);
161 while((arg
= va_arg(ap
, const char *))) {
162 dynstr_append(&d
, ' ');
163 dynstr_append_string(&d
, quoteutf8(arg
));
165 dynstr_append(&d
, '\n');
166 dynstr_terminate(&d
);
167 D(("command: %s", d
.vec
));
168 if(fputs(d
.vec
, c
->fpout
) < 0 || fflush(c
->fpout
)) {
169 error(errno
, "error writing to %s", c
->ident
);
173 return check_response(c
, rp
);
176 /** @brief Issue a command and parse a simple response
178 * @param rp Where to store result, or NULL (UTF-8)
180 * @return 0 on success, non-0 on error
182 * The remaining arguments are command arguments, terminated by (char
183 * *)0. They should be in UTF-8.
185 * 5xx responses count as errors.
187 * @p rp will NOT be filled in for xx9 responses (where it is just
188 * commentary for a command where it would normally be meaningful).
190 * NB that the response will NOT be converted to the local encoding
191 * nor will quotes be stripped. See dequote().
193 static int disorder_simple(disorder_client
*c
,
195 const char *cmd
, ...) {
200 ret
= disorder_simple_v(c
, rp
, cmd
, ap
);
205 /** @brief Dequote a result string
206 * @param rc 0 on success, non-0 on error
207 * @param rp Where result string is stored (UTF-8)
210 * This is used as a wrapper around disorder_simple() to dequote
213 static int dequote(int rc
, char **rp
) {
216 if((rr
= split(*rp
, 0, SPLIT_QUOTES
, 0, 0)) && *rr
) {
220 error(0, "invalid reply: %s", *rp
);
225 /** @brief Generic connection routine
227 * @param username Username to log in with or NULL
228 * @param password Password to log in with or NULL
229 * @param cookie Cookie to log in with or NULL
230 * @return 0 on success, non-0 on error
232 * @p cookie is tried first if not NULL. If it is NULL then @p
233 * username must not be. If @p username is not NULL then nor may @p
236 static int disorder_connect_generic(disorder_client
*c
,
237 const char *username
,
238 const char *password
,
239 const char *cookie
) {
240 int fd
= -1, fd2
= -1, nrvec
;
241 unsigned char *nonce
;
245 const char *protocol
, *algorithm
, *challenge
;
249 if((salen
= find_server(&sa
, &c
->ident
)) == (socklen_t
)-1)
251 c
->fpin
= c
->fpout
= 0;
252 if((fd
= socket(sa
->sa_family
, SOCK_STREAM
, 0)) < 0) {
253 error(errno
, "error calling socket");
256 if(connect(fd
, sa
, salen
) < 0) {
257 error(errno
, "error calling connect");
260 if((fd2
= dup(fd
)) < 0) {
261 error(errno
, "error calling dup");
264 if(!(c
->fpin
= fdopen(fd
, "rb"))) {
265 error(errno
, "error calling fdopen");
269 if(!(c
->fpout
= fdopen(fd2
, "wb"))) {
270 error(errno
, "error calling fdopen");
274 if(disorder_simple(c
, &r
, 0, (const char *)0))
276 if(!(rvec
= split(r
, &nrvec
, SPLIT_QUOTES
, 0, 0)))
279 error(0, "cannot parse server greeting %s", r
);
283 if(strcmp(protocol
, "2")) {
284 error(0, "unknown protocol version: %s", protocol
);
289 if(!(nonce
= unhex(challenge
, &nl
)))
292 if(!dequote(disorder_simple(c
, &c
->user
, "cookie", cookie
, (char *)0),
294 return 0; /* success */
296 error(0, "cookie did not work and no username available");
300 if(!(res
= authhash(nonce
, nl
, password
, algorithm
))) goto error
;
301 if(disorder_simple(c
, 0, "user", username
, res
, (char *)0))
303 c
->user
= xstrdup(username
);
306 if(c
->fpin
) fclose(c
->fpin
);
307 if(c
->fpout
) fclose(c
->fpout
);
308 if(fd2
!= -1) close(fd2
);
309 if(fd
!= -1) close(fd
);
313 /** @brief Connect a client
315 * @return 0 on success, non-0 on error
317 * The connection will use the username and password found in @ref
318 * config, or directly from the database if no password is found and
319 * the database is readable (usually only for root).
321 int disorder_connect(disorder_client
*c
) {
322 const char *username
, *password
;
324 if(!(username
= config
->username
)) {
325 error(0, "no username configured");
328 password
= config
->password
;
330 /* Maybe we can read the database */
331 /* TODO failure to open the database should not be fatal */
332 trackdb_init(TRACKDB_NO_RECOVER
|TRACKDB_NO_UPGRADE
);
333 trackdb_open(TRACKDB_READ_ONLY
);
334 password
= trackdb_get_password(username
);
339 error(0, "no password configured");
342 return disorder_connect_generic(c
,
348 /** @brief Connect a client
350 * @param cookie Cookie to log in with, or NULL
351 * @return 0 on success, non-0 on error
353 * If @p cookie is NULL or does not work then we attempt to log in as
354 * guest instead (so when the cookie expires only an extra round trip
355 * is needed rathre than a complete new login).
357 int disorder_connect_cookie(disorder_client
*c
,
358 const char *cookie
) {
359 return disorder_connect_generic(c
,
365 /** @brief Close a client
367 * @return 0 on succcess, non-0 on errior
369 * The client is still closed even on error. It might well be
370 * appropriate to ignore the return value.
372 int disorder_close(disorder_client
*c
) {
376 if(fclose(c
->fpin
) < 0) {
377 error(errno
, "error calling fclose");
383 if(fclose(c
->fpout
) < 0) {
384 error(errno
, "error calling fclose");
394 int disorder_become(disorder_client
*c
, const char *user
) {
395 if(disorder_simple(c
, 0, "become", user
, (char *)0)) return -1;
396 c
->user
= xstrdup(user
);
400 /** @brief Play a track
402 * @param track Track to play (UTF-8)
403 * @return 0 on success, non-0 on error
405 int disorder_play(disorder_client
*c
, const char *track
) {
406 return disorder_simple(c
, 0, "play", track
, (char *)0);
409 /** @brief Remove a track
411 * @param track Track to remove (UTF-8)
412 * @return 0 on success, non-0 on error
414 int disorder_remove(disorder_client
*c
, const char *track
) {
415 return disorder_simple(c
, 0, "remove", track
, (char *)0);
418 /** @brief Move a track
420 * @param track Track to move (UTF-8)
421 * @param delta Distance to move by
422 * @return 0 on success, non-0 on error
424 int disorder_move(disorder_client
*c
, const char *track
, int delta
) {
427 byte_snprintf(d
, sizeof d
, "%d", delta
);
428 return disorder_simple(c
, 0, "move", track
, d
, (char *)0);
431 /** @brief Enable play
433 * @return 0 on success, non-0 on error
435 int disorder_enable(disorder_client
*c
) {
436 return disorder_simple(c
, 0, "enable", (char *)0);
439 /** @brief Disable play
441 * @return 0 on success, non-0 on error
443 int disorder_disable(disorder_client
*c
) {
444 return disorder_simple(c
, 0, "disable", (char *)0);
447 /** @brief Scratch the currently playing track
448 * @param id Playing track ID or NULL (UTF-8)
450 * @return 0 on success, non-0 on error
452 int disorder_scratch(disorder_client
*c
, const char *id
) {
453 return disorder_simple(c
, 0, "scratch", id
, (char *)0);
456 /** @brief Shut down the server
458 * @return 0 on success, non-0 on error
460 int disorder_shutdown(disorder_client
*c
) {
461 return disorder_simple(c
, 0, "shutdown", (char *)0);
464 /** @brief Make the server re-read its configuration
466 * @return 0 on success, non-0 on error
468 int disorder_reconfigure(disorder_client
*c
) {
469 return disorder_simple(c
, 0, "reconfigure", (char *)0);
472 /** @brief Rescan tracks
474 * @return 0 on success, non-0 on error
476 int disorder_rescan(disorder_client
*c
) {
477 return disorder_simple(c
, 0, "rescan", (char *)0);
480 /** @brief Get server version number
482 * @param rp Where to store version string (UTF-8)
483 * @return 0 on success, non-0 on error
485 int disorder_version(disorder_client
*c
, char **rp
) {
486 return dequote(disorder_simple(c
, rp
, "version", (char *)0), rp
);
489 static void client_error(const char *msg
,
490 void attribute((unused
)) *u
) {
491 error(0, "error parsing reply: %s", msg
);
494 /** @brief Get currently playing track
496 * @param qp Where to store track information
497 * @return 0 on success, non-0 on error
499 * @p qp gets NULL if no track is playing.
501 int disorder_playing(disorder_client
*c
, struct queue_entry
**qp
) {
503 struct queue_entry
*q
;
505 if(disorder_simple(c
, &r
, "playing", (char *)0))
508 q
= xmalloc(sizeof *q
);
509 if(queue_unmarshall(q
, r
, client_error
, 0))
517 static int disorder_somequeue(disorder_client
*c
,
518 const char *cmd
, struct queue_entry
**qp
) {
519 struct queue_entry
*qh
, **qt
= &qh
, *q
;
522 if(disorder_simple(c
, 0, cmd
, (char *)0))
524 while(inputline(c
->ident
, c
->fpin
, &l
, '\n') >= 0) {
525 if(!strcmp(l
, ".")) {
530 q
= xmalloc(sizeof *q
);
531 if(!queue_unmarshall(q
, l
, client_error
, 0)) {
537 error(errno
, "error reading %s", c
->ident
);
539 error(0, "error reading %s: unexpected EOF", c
->ident
);
543 /** @brief Get recently played tracks
545 * @param qp Where to store track information
546 * @return 0 on success, non-0 on error
548 * The last entry in the list is the most recently played track.
550 int disorder_recent(disorder_client
*c
, struct queue_entry
**qp
) {
551 return disorder_somequeue(c
, "recent", qp
);
556 * @param qp Where to store track information
557 * @return 0 on success, non-0 on error
559 * The first entry in the list will be played next.
561 int disorder_queue(disorder_client
*c
, struct queue_entry
**qp
) {
562 return disorder_somequeue(c
, "queue", qp
);
565 /** @brief Read a dot-stuffed list
567 * @param vecp Where to store list (UTF-8)
568 * @param nvecp Where to store number of items, or NULL
569 * @return 0 on success, non-0 on error
571 * The list will have a final NULL not counted in @p nvecp.
573 static int readlist(disorder_client
*c
, char ***vecp
, int *nvecp
) {
578 while(inputline(c
->ident
, c
->fpin
, &l
, '\n') >= 0) {
579 if(!strcmp(l
, ".")) {
580 vector_terminate(&v
);
586 vector_append(&v
, l
+ (*l
== '.'));
589 error(errno
, "error reading %s", c
->ident
);
591 error(0, "error reading %s: unexpected EOF", c
->ident
);
595 /** @brief Issue a comamnd and get a list response
597 * @param vecp Where to store list (UTF-8)
598 * @param nvecp Where to store number of items, or NULL
600 * @return 0 on success, non-0 on error
602 * The remaining arguments are command arguments, terminated by (char
603 * *)0. They should be in UTF-8.
605 * 5xx responses count as errors.
607 static int disorder_simple_list(disorder_client
*c
,
608 char ***vecp
, int *nvecp
,
609 const char *cmd
, ...) {
614 ret
= disorder_simple_v(c
, 0, cmd
, ap
);
617 return readlist(c
, vecp
, nvecp
);
620 /** @brief List directories below @p dir
622 * @param dir Directory to list, or NULL for root (UTF-8)
623 * @param re Regexp that results must match, or NULL (UTF-8)
624 * @param vecp Where to store list (UTF-8)
625 * @param nvecp Where to store number of items, or NULL
626 * @return 0 on success, non-0 on error
628 int disorder_directories(disorder_client
*c
, const char *dir
, const char *re
,
629 char ***vecp
, int *nvecp
) {
630 return disorder_simple_list(c
, vecp
, nvecp
, "dirs", dir
, re
, (char *)0);
633 /** @brief List files below @p dir
635 * @param dir Directory to list, or NULL for root (UTF-8)
636 * @param re Regexp that results must match, or NULL (UTF-8)
637 * @param vecp Where to store list (UTF-8)
638 * @param nvecp Where to store number of items, or NULL
639 * @return 0 on success, non-0 on error
641 int disorder_files(disorder_client
*c
, const char *dir
, const char *re
,
642 char ***vecp
, int *nvecp
) {
643 return disorder_simple_list(c
, vecp
, nvecp
, "files", dir
, re
, (char *)0);
646 /** @brief List files and directories below @p dir
648 * @param dir Directory to list, or NULL for root (UTF-8)
649 * @param re Regexp that results must match, or NULL (UTF-8)
650 * @param vecp Where to store list (UTF-8)
651 * @param nvecp Where to store number of items, or NULL
652 * @return 0 on success, non-0 on error
654 int disorder_allfiles(disorder_client
*c
, const char *dir
, const char *re
,
655 char ***vecp
, int *nvecp
) {
656 return disorder_simple_list(c
, vecp
, nvecp
, "allfiles", dir
, re
, (char *)0);
659 /** @brief Return the user we logged in with
661 * @return User name (owned by @p c, don't modify)
663 char *disorder_user(disorder_client
*c
) {
667 /** @brief Set a track preference
669 * @param track Track name (UTF-8)
670 * @param key Preference name (UTF-8)
671 * @param value Preference value (UTF-8)
672 * @return 0 on success, non-0 on error
674 int disorder_set(disorder_client
*c
, const char *track
,
675 const char *key
, const char *value
) {
676 return disorder_simple(c
, 0, "set", track
, key
, value
, (char *)0);
679 /** @brief Unset a track preference
681 * @param track Track name (UTF-8)
682 * @param key Preference name (UTF-8)
683 * @return 0 on success, non-0 on error
685 int disorder_unset(disorder_client
*c
, const char *track
,
687 return disorder_simple(c
, 0, "unset", track
, key
, (char *)0);
690 /** @brief Get a track preference
692 * @param track Track name (UTF-8)
693 * @param key Preference name (UTF-8)
694 * @param valuep Where to store preference value (UTF-8)
695 * @return 0 on success, non-0 on error
697 int disorder_get(disorder_client
*c
,
698 const char *track
, const char *key
, char **valuep
) {
699 return dequote(disorder_simple(c
, valuep
, "get", track
, key
, (char *)0),
703 static void pref_error_handler(const char *msg
,
704 void attribute((unused
)) *u
) {
705 error(0, "error handling 'prefs' reply: %s", msg
);
708 /** @param Get all preferences for a trcak
710 * @param track Track name
711 * @param kp Where to store linked list of preferences
712 * @return 0 on success, non-0 on error
714 int disorder_prefs(disorder_client
*c
, const char *track
, struct kvp
**kp
) {
719 if(disorder_simple_list(c
, &vec
, &nvec
, "prefs", track
, (char *)0))
721 for(n
= 0; n
< nvec
; ++n
) {
722 if(!(pvec
= split(vec
[n
], &npvec
, SPLIT_QUOTES
, pref_error_handler
, 0)))
725 pref_error_handler("malformed response", 0);
728 *kp
= k
= xmalloc(sizeof *k
);
737 /** @brief Parse a boolean response
738 * @param cmd Command for use in error messsage
739 * @param value Result from server
740 * @param flagp Where to store result
741 * @return 0 on success, non-0 on error
743 static int boolean(const char *cmd
, const char *value
,
745 if(!strcmp(value
, "yes")) *flagp
= 1;
746 else if(!strcmp(value
, "no")) *flagp
= 0;
748 error(0, "malformed response to '%s'", cmd
);
754 /** @brief Test whether a track exists
756 * @param track Track name (UTF-8)
757 * @param existsp Where to store result (non-0 iff does exist)
758 * @return 0 on success, non-0 on error
760 int disorder_exists(disorder_client
*c
, const char *track
, int *existsp
) {
763 if(disorder_simple(c
, &v
, "exists", track
, (char *)0)) return -1;
764 return boolean("exists", v
, existsp
);
767 /** @brief Test whether playing is enabled
769 * @param enabledp Where to store result (non-0 iff enabled)
770 * @return 0 on success, non-0 on error
772 int disorder_enabled(disorder_client
*c
, int *enabledp
) {
775 if(disorder_simple(c
, &v
, "enabled", (char *)0)) return -1;
776 return boolean("enabled", v
, enabledp
);
779 /** @brief Get the length of a track
781 * @param track Track name (UTF-8)
782 * @param valuep Where to store length in seconds
783 * @return 0 on success, non-0 on error
785 * If the length is unknown 0 is returned.
787 int disorder_length(disorder_client
*c
, const char *track
,
791 if(disorder_simple(c
, &value
, "length", track
, (char *)0)) return -1;
792 *valuep
= atol(value
);
796 /** @brief Search for tracks
798 * @param terms Search terms (UTF-8)
799 * @param vecp Where to store list (UTF-8)
800 * @param nvecp Where to store number of items, or NULL
801 * @return 0 on success, non-0 on error
803 int disorder_search(disorder_client
*c
, const char *terms
,
804 char ***vecp
, int *nvecp
) {
805 return disorder_simple_list(c
, vecp
, nvecp
, "search", terms
, (char *)0);
808 /** @brief Enable random play
810 * @return 0 on success, non-0 on error
812 int disorder_random_enable(disorder_client
*c
) {
813 return disorder_simple(c
, 0, "random-enable", (char *)0);
816 /** @brief Disable random play
818 * @return 0 on success, non-0 on error
820 int disorder_random_disable(disorder_client
*c
) {
821 return disorder_simple(c
, 0, "random-disable", (char *)0);
824 /** @brief Test whether random play is enabled
826 * @param existsp Where to store result (non-0 iff enabled)
827 * @return 0 on success, non-0 on error
829 int disorder_random_enabled(disorder_client
*c
, int *enabledp
) {
832 if(disorder_simple(c
, &v
, "random-enabled", (char *)0)) return -1;
833 return boolean("random-enabled", v
, enabledp
);
836 /** @brief Get server stats
838 * @param vecp Where to store list (UTF-8)
839 * @param nvecp Where to store number of items, or NULL
840 * @return 0 on success, non-0 on error
842 int disorder_stats(disorder_client
*c
,
843 char ***vecp
, int *nvecp
) {
844 return disorder_simple_list(c
, vecp
, nvecp
, "stats", (char *)0);
847 /** @brief Set volume
849 * @param left New left channel value
850 * @param right New right channel value
851 * @return 0 on success, non-0 on error
853 int disorder_set_volume(disorder_client
*c
, int left
, int right
) {
856 if(byte_asprintf(&ls
, "%d", left
) < 0
857 || byte_asprintf(&rs
, "%d", right
) < 0)
859 if(disorder_simple(c
, 0, "volume", ls
, rs
, (char *)0)) return -1;
863 /** @brief Get volume
865 * @param left Where to store left channel value
866 * @param right Where to store right channel value
867 * @return 0 on success, non-0 on error
869 int disorder_get_volume(disorder_client
*c
, int *left
, int *right
) {
872 if(disorder_simple(c
, &r
, "volume", (char *)0)) return -1;
873 if(sscanf(r
, "%d %d", left
, right
) != 2) {
874 error(0, "error parsing response to 'volume': '%s'", r
);
880 /** @brief Log to a sink
882 * @param s Sink to write log lines to
883 * @return 0 on success, non-0 on error
885 int disorder_log(disorder_client
*c
, struct sink
*s
) {
888 if(disorder_simple(c
, 0, "log", (char *)0)) return -1;
889 while(inputline(c
->ident
, c
->fpin
, &l
, '\n') >= 0 && strcmp(l
, "."))
890 if(sink_printf(s
, "%s\n", l
) < 0) return -1;
891 if(ferror(c
->fpin
) || feof(c
->fpin
)) return -1;
895 /** @brief Look up a track name part
897 * @param partp Where to store result (UTF-8)
898 * @param track Track name (UTF-8)
899 * @param context Context (usually "sort" or "display") (UTF-8)
900 * @param part Track part (UTF-8)
901 * @return 0 on success, non-0 on error
903 int disorder_part(disorder_client
*c
, char **partp
,
904 const char *track
, const char *context
, const char *part
) {
905 return dequote(disorder_simple(c
, partp
, "part",
906 track
, context
, part
, (char *)0), partp
);
909 /** @brief Resolve aliases
911 * @param trackkp Where to store canonical name (UTF-8)
912 * @param track Track name (UTF-8)
913 * @return 0 on success, non-0 on error
915 int disorder_resolve(disorder_client
*c
, char **trackp
, const char *track
) {
916 return dequote(disorder_simple(c
, trackp
, "resolve", track
, (char *)0),
920 /** @brief Pause the current track
922 * @return 0 on success, non-0 on error
924 int disorder_pause(disorder_client
*c
) {
925 return disorder_simple(c
, 0, "pause", (char *)0);
928 /** @brief Resume the current track
930 * @return 0 on success, non-0 on error
932 int disorder_resume(disorder_client
*c
) {
933 return disorder_simple(c
, 0, "resume", (char *)0);
936 /** @brief List all known tags
938 * @param vecp Where to store list (UTF-8)
939 * @param nvecp Where to store number of items, or NULL
940 * @return 0 on success, non-0 on error
942 int disorder_tags(disorder_client
*c
,
943 char ***vecp
, int *nvecp
) {
944 return disorder_simple_list(c
, vecp
, nvecp
, "tags", (char *)0);
947 /** @brief List all known users
949 * @param vecp Where to store list (UTF-8)
950 * @param nvecp Where to store number of items, or NULL
951 * @return 0 on success, non-0 on error
953 int disorder_users(disorder_client
*c
,
954 char ***vecp
, int *nvecp
) {
955 return disorder_simple_list(c
, vecp
, nvecp
, "users", (char *)0);
958 /** @brief Get recently added tracks
960 * @param vecp Where to store pointer to list (UTF-8)
961 * @param nvecp Where to store count
962 * @param max Maximum tracks to fetch, or 0 for all available
963 * @return 0 on success, non-0 on error
965 int disorder_new_tracks(disorder_client
*c
,
966 char ***vecp
, int *nvecp
,
970 sprintf(limit
, "%d", max
);
971 return disorder_simple_list(c
, vecp
, nvecp
, "new", limit
, (char *)0);
974 /** @brief Set a global preference
976 * @param key Preference name (UTF-8)
977 * @param value Preference value (UTF-8)
978 * @return 0 on success, non-0 on error
980 int disorder_set_global(disorder_client
*c
,
981 const char *key
, const char *value
) {
982 return disorder_simple(c
, 0, "set-global", key
, value
, (char *)0);
985 /** @brief Unset a global preference
987 * @param key Preference name (UTF-8)
988 * @return 0 on success, non-0 on error
990 int disorder_unset_global(disorder_client
*c
, const char *key
) {
991 return disorder_simple(c
, 0, "unset-global", key
, (char *)0);
994 /** @brief Get a global preference
996 * @param key Preference name (UTF-8)
997 * @param valuep Where to store preference value (UTF-8)
998 * @return 0 on success, non-0 on error
1000 int disorder_get_global(disorder_client
*c
, const char *key
, char **valuep
) {
1001 return dequote(disorder_simple(c
, valuep
, "get-global", key
, (char *)0),
1005 /** @brief Get server's RTP address information
1007 * @param addressp Where to store address (UTF-8)
1008 * @param portp Where to store port (UTF-8)
1009 * @return 0 on success, non-0 on error
1011 int disorder_rtp_address(disorder_client
*c
, char **addressp
, char **portp
) {
1016 if((rc
= disorder_simple(c
, &r
, "rtp-address", (char *)0)))
1018 vec
= split(r
, &n
, SPLIT_QUOTES
, 0, 0);
1020 error(0, "malformed rtp-address reply");
1028 /** @brief Create a user
1030 * @param user Username
1031 * @param password Password
1032 * @param rights Initial rights or NULL to use default
1033 * @return 0 on success, non-0 on error
1035 int disorder_adduser(disorder_client
*c
,
1036 const char *user
, const char *password
,
1037 const char *rights
) {
1038 return disorder_simple(c
, 0, "adduser", user
, password
, rights
, (char *)0);
1041 /** @brief Delete a user
1043 * @param user Username
1044 * @return 0 on success, non-0 on error
1046 int disorder_deluser(disorder_client
*c
, const char *user
) {
1047 return disorder_simple(c
, 0, "deluser", user
, (char *)0);
1050 /** @brief Get user information
1052 * @param user Username
1053 * @param key Property name (UTF-8)
1054 * @param valuep Where to store value (UTF-8)
1055 * @return 0 on success, non-0 on error
1057 int disorder_userinfo(disorder_client
*c
, const char *user
, const char *key
,
1059 return dequote(disorder_simple(c
, valuep
, "userinfo", user
, key
, (char *)0),
1063 /** @brief Set user information
1065 * @param user Username
1066 * @param key Property name (UTF-8)
1067 * @param value New property value (UTF-8)
1068 * @return 0 on success, non-0 on error
1070 int disorder_edituser(disorder_client
*c
, const char *user
,
1071 const char *key
, const char *value
) {
1072 return disorder_simple(c
, 0, "edituser", user
, key
, value
, (char *)0);
1075 /** @brief Register a user
1077 * @param user Username
1078 * @param password Password
1079 * @param email Email address (UTF-8)
1080 * @param rights Initial rights or NULL to use default
1081 * @param confirmp Where to store confirmation string
1082 * @return 0 on success, non-0 on error
1084 int disorder_register(disorder_client
*c
, const char *user
,
1085 const char *password
, const char *email
,
1087 return dequote(disorder_simple(c
, confirmp
, "register",
1088 user
, password
, email
, (char *)0),
1092 /** @brief Confirm a user
1094 * @param confirm Confirmation string
1095 * @return 0 on success, non-0 on error
1097 int disorder_confirm(disorder_client
*c
, const char *confirm
) {
1098 return disorder_simple(c
, 0, "confirm", confirm
, (char *)0);
1101 /** @brief Make a cookie for this login
1103 * @param cookiep Where to store cookie string
1104 * @return 0 on success, non-0 on error
1106 int disorder_make_cookie(disorder_client
*c
, char **cookiep
) {
1107 return dequote(disorder_simple(c
, cookiep
, "make-cookie", (char *)0),