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(), disorder_connect_user() or
74 * disorder_connect_cookie() to connect it. Use disorder_close() to
75 * dispose of the client when finished with it.
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 with a specified username and password
315 * @param username Username to log in with
316 * @param password Password to log in with
317 * @return 0 on success, non-0 on error
319 int disorder_connect_user(disorder_client *c,
320 const char *username,
321 const char *password) {
322 return disorder_connect_generic(c,
328 /** @brief Connect a client
330 * @return 0 on success, non-0 on error
332 * The connection will use the username and password found in @ref
333 * config, or directly from the database if no password is found and
334 * the database is readable (usually only for root).
336 int disorder_connect(disorder_client *c) {
337 const char *username, *password;
339 if(!(username = config->username)) {
340 error(0, "no username configured");
343 password = config->password;
345 /* Maybe we can read the database */
346 /* TODO failure to open the database should not be fatal */
347 trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE);
348 trackdb_open(TRACKDB_READ_ONLY);
349 password = trackdb_get_password(username);
354 error(0, "no password configured");
357 return disorder_connect_generic(c,
363 /** @brief Connect a client
365 * @param cookie Cookie to log in with, or NULL
366 * @return 0 on success, non-0 on error
368 * If @p cookie is NULL or does not work then we attempt to log in as
369 * guest instead (so when the cookie expires only an extra round trip
370 * is needed rathre than a complete new login).
372 int disorder_connect_cookie(disorder_client *c,
373 const char *cookie) {
374 return disorder_connect_generic(c,
380 /** @brief Close a client
382 * @return 0 on succcess, non-0 on errior
384 * The client is still closed even on error. It might well be
385 * appropriate to ignore the return value.
387 int disorder_close(disorder_client *c) {
391 if(fclose(c->fpin) < 0) {
392 error(errno, "error calling fclose");
398 if(fclose(c->fpout) < 0) {
399 error(errno, "error calling fclose");
409 /** @brief Play a track
411 * @param track Track to play (UTF-8)
412 * @return 0 on success, non-0 on error
414 int disorder_play(disorder_client *c, const char *track) {
415 return disorder_simple(c, 0, "play", track, (char *)0);
418 /** @brief Remove a track
420 * @param track Track to remove (UTF-8)
421 * @return 0 on success, non-0 on error
423 int disorder_remove(disorder_client *c, const char *track) {
424 return disorder_simple(c, 0, "remove", track, (char *)0);
427 /** @brief Move a track
429 * @param track Track to move (UTF-8)
430 * @param delta Distance to move by
431 * @return 0 on success, non-0 on error
433 int disorder_move(disorder_client *c, const char *track, int delta) {
436 byte_snprintf(d, sizeof d, "%d", delta);
437 return disorder_simple(c, 0, "move", track, d, (char *)0);
440 /** @brief Enable play
442 * @return 0 on success, non-0 on error
444 int disorder_enable(disorder_client *c) {
445 return disorder_simple(c, 0, "enable", (char *)0);
448 /** @brief Disable play
450 * @return 0 on success, non-0 on error
452 int disorder_disable(disorder_client *c) {
453 return disorder_simple(c, 0, "disable", (char *)0);
456 /** @brief Scratch the currently playing track
457 * @param id Playing track ID or NULL (UTF-8)
459 * @return 0 on success, non-0 on error
461 int disorder_scratch(disorder_client *c, const char *id) {
462 return disorder_simple(c, 0, "scratch", id, (char *)0);
465 /** @brief Shut down the server
467 * @return 0 on success, non-0 on error
469 int disorder_shutdown(disorder_client *c) {
470 return disorder_simple(c, 0, "shutdown", (char *)0);
473 /** @brief Make the server re-read its configuration
475 * @return 0 on success, non-0 on error
477 int disorder_reconfigure(disorder_client *c) {
478 return disorder_simple(c, 0, "reconfigure", (char *)0);
481 /** @brief Rescan tracks
483 * @return 0 on success, non-0 on error
485 int disorder_rescan(disorder_client *c) {
486 return disorder_simple(c, 0, "rescan", (char *)0);
489 /** @brief Get server version number
491 * @param rp Where to store version string (UTF-8)
492 * @return 0 on success, non-0 on error
494 int disorder_version(disorder_client *c, char **rp) {
495 return dequote(disorder_simple(c, rp, "version", (char *)0), rp);
498 static void client_error(const char *msg,
499 void attribute((unused)) *u) {
500 error(0, "error parsing reply: %s", msg);
503 /** @brief Get currently playing track
505 * @param qp Where to store track information
506 * @return 0 on success, non-0 on error
508 * @p qp gets NULL if no track is playing.
510 int disorder_playing(disorder_client *c, struct queue_entry **qp) {
512 struct queue_entry *q;
514 if(disorder_simple(c, &r, "playing", (char *)0))
517 q = xmalloc(sizeof *q);
518 if(queue_unmarshall(q, r, client_error, 0))
526 static int disorder_somequeue(disorder_client *c,
527 const char *cmd, struct queue_entry **qp) {
528 struct queue_entry *qh, **qt = &qh, *q;
531 if(disorder_simple(c, 0, cmd, (char *)0))
533 while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
534 if(!strcmp(l, ".")) {
539 q = xmalloc(sizeof *q);
540 if(!queue_unmarshall(q, l, client_error, 0)) {
546 error(errno, "error reading %s", c->ident);
548 error(0, "error reading %s: unexpected EOF", c->ident);
552 /** @brief Get recently played tracks
554 * @param qp Where to store track information
555 * @return 0 on success, non-0 on error
557 * The last entry in the list is the most recently played track.
559 int disorder_recent(disorder_client *c, struct queue_entry **qp) {
560 return disorder_somequeue(c, "recent", qp);
565 * @param qp Where to store track information
566 * @return 0 on success, non-0 on error
568 * The first entry in the list will be played next.
570 int disorder_queue(disorder_client *c, struct queue_entry **qp) {
571 return disorder_somequeue(c, "queue", qp);
574 /** @brief Read a dot-stuffed list
576 * @param vecp Where to store list (UTF-8)
577 * @param nvecp Where to store number of items, or NULL
578 * @return 0 on success, non-0 on error
580 * The list will have a final NULL not counted in @p nvecp.
582 static int readlist(disorder_client *c, char ***vecp, int *nvecp) {
587 while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
588 if(!strcmp(l, ".")) {
589 vector_terminate(&v);
595 vector_append(&v, l + (*l == '.'));
598 error(errno, "error reading %s", c->ident);
600 error(0, "error reading %s: unexpected EOF", c->ident);
604 /** @brief Issue a comamnd and get a list response
606 * @param vecp Where to store list (UTF-8)
607 * @param nvecp Where to store number of items, or NULL
609 * @return 0 on success, non-0 on error
611 * The remaining arguments are command arguments, terminated by (char
612 * *)0. They should be in UTF-8.
614 * 5xx responses count as errors.
616 static int disorder_simple_list(disorder_client *c,
617 char ***vecp, int *nvecp,
618 const char *cmd, ...) {
623 ret = disorder_simple_v(c, 0, cmd, ap);
626 return readlist(c, vecp, nvecp);
629 /** @brief List directories below @p dir
631 * @param dir Directory to list, or NULL for root (UTF-8)
632 * @param re Regexp that results must match, or NULL (UTF-8)
633 * @param vecp Where to store list (UTF-8)
634 * @param nvecp Where to store number of items, or NULL
635 * @return 0 on success, non-0 on error
637 int disorder_directories(disorder_client *c, const char *dir, const char *re,
638 char ***vecp, int *nvecp) {
639 return disorder_simple_list(c, vecp, nvecp, "dirs", dir, re, (char *)0);
642 /** @brief List files below @p dir
644 * @param dir Directory to list, or NULL for root (UTF-8)
645 * @param re Regexp that results must match, or NULL (UTF-8)
646 * @param vecp Where to store list (UTF-8)
647 * @param nvecp Where to store number of items, or NULL
648 * @return 0 on success, non-0 on error
650 int disorder_files(disorder_client *c, const char *dir, const char *re,
651 char ***vecp, int *nvecp) {
652 return disorder_simple_list(c, vecp, nvecp, "files", dir, re, (char *)0);
655 /** @brief List files and directories below @p dir
657 * @param dir Directory to list, or NULL for root (UTF-8)
658 * @param re Regexp that results must match, or NULL (UTF-8)
659 * @param vecp Where to store list (UTF-8)
660 * @param nvecp Where to store number of items, or NULL
661 * @return 0 on success, non-0 on error
663 int disorder_allfiles(disorder_client *c, const char *dir, const char *re,
664 char ***vecp, int *nvecp) {
665 return disorder_simple_list(c, vecp, nvecp, "allfiles", dir, re, (char *)0);
668 /** @brief Return the user we logged in with
670 * @return User name (owned by @p c, don't modify)
672 char *disorder_user(disorder_client *c) {
676 /** @brief Set a track preference
678 * @param track Track name (UTF-8)
679 * @param key Preference name (UTF-8)
680 * @param value Preference value (UTF-8)
681 * @return 0 on success, non-0 on error
683 int disorder_set(disorder_client *c, const char *track,
684 const char *key, const char *value) {
685 return disorder_simple(c, 0, "set", track, key, value, (char *)0);
688 /** @brief Unset a track preference
690 * @param track Track name (UTF-8)
691 * @param key Preference name (UTF-8)
692 * @return 0 on success, non-0 on error
694 int disorder_unset(disorder_client *c, const char *track,
696 return disorder_simple(c, 0, "unset", track, key, (char *)0);
699 /** @brief Get a track preference
701 * @param track Track name (UTF-8)
702 * @param key Preference name (UTF-8)
703 * @param valuep Where to store preference value (UTF-8)
704 * @return 0 on success, non-0 on error
706 int disorder_get(disorder_client *c,
707 const char *track, const char *key, char **valuep) {
708 return dequote(disorder_simple(c, valuep, "get", track, key, (char *)0),
712 static void pref_error_handler(const char *msg,
713 void attribute((unused)) *u) {
714 error(0, "error handling 'prefs' reply: %s", msg);
717 /** @param Get all preferences for a trcak
719 * @param track Track name
720 * @param kp Where to store linked list of preferences
721 * @return 0 on success, non-0 on error
723 int disorder_prefs(disorder_client *c, const char *track, struct kvp **kp) {
728 if(disorder_simple_list(c, &vec, &nvec, "prefs", track, (char *)0))
730 for(n = 0; n < nvec; ++n) {
731 if(!(pvec = split(vec[n], &npvec, SPLIT_QUOTES, pref_error_handler, 0)))
734 pref_error_handler("malformed response", 0);
737 *kp = k = xmalloc(sizeof *k);
746 /** @brief Parse a boolean response
747 * @param cmd Command for use in error messsage
748 * @param value Result from server
749 * @param flagp Where to store result
750 * @return 0 on success, non-0 on error
752 static int boolean(const char *cmd, const char *value,
754 if(!strcmp(value, "yes")) *flagp = 1;
755 else if(!strcmp(value, "no")) *flagp = 0;
757 error(0, "malformed response to '%s'", cmd);
763 /** @brief Test whether a track exists
765 * @param track Track name (UTF-8)
766 * @param existsp Where to store result (non-0 iff does exist)
767 * @return 0 on success, non-0 on error
769 int disorder_exists(disorder_client *c, const char *track, int *existsp) {
772 if(disorder_simple(c, &v, "exists", track, (char *)0)) return -1;
773 return boolean("exists", v, existsp);
776 /** @brief Test whether playing is enabled
778 * @param enabledp Where to store result (non-0 iff enabled)
779 * @return 0 on success, non-0 on error
781 int disorder_enabled(disorder_client *c, int *enabledp) {
784 if(disorder_simple(c, &v, "enabled", (char *)0)) return -1;
785 return boolean("enabled", v, enabledp);
788 /** @brief Get the length of a track
790 * @param track Track name (UTF-8)
791 * @param valuep Where to store length in seconds
792 * @return 0 on success, non-0 on error
794 * If the length is unknown 0 is returned.
796 int disorder_length(disorder_client *c, const char *track,
800 if(disorder_simple(c, &value, "length", track, (char *)0)) return -1;
801 *valuep = atol(value);
805 /** @brief Search for tracks
807 * @param terms Search terms (UTF-8)
808 * @param vecp Where to store list (UTF-8)
809 * @param nvecp Where to store number of items, or NULL
810 * @return 0 on success, non-0 on error
812 int disorder_search(disorder_client *c, const char *terms,
813 char ***vecp, int *nvecp) {
814 return disorder_simple_list(c, vecp, nvecp, "search", terms, (char *)0);
817 /** @brief Enable random play
819 * @return 0 on success, non-0 on error
821 int disorder_random_enable(disorder_client *c) {
822 return disorder_simple(c, 0, "random-enable", (char *)0);
825 /** @brief Disable random play
827 * @return 0 on success, non-0 on error
829 int disorder_random_disable(disorder_client *c) {
830 return disorder_simple(c, 0, "random-disable", (char *)0);
833 /** @brief Test whether random play is enabled
835 * @param existsp Where to store result (non-0 iff enabled)
836 * @return 0 on success, non-0 on error
838 int disorder_random_enabled(disorder_client *c, int *enabledp) {
841 if(disorder_simple(c, &v, "random-enabled", (char *)0)) return -1;
842 return boolean("random-enabled", v, enabledp);
845 /** @brief Get server stats
847 * @param vecp Where to store list (UTF-8)
848 * @param nvecp Where to store number of items, or NULL
849 * @return 0 on success, non-0 on error
851 int disorder_stats(disorder_client *c,
852 char ***vecp, int *nvecp) {
853 return disorder_simple_list(c, vecp, nvecp, "stats", (char *)0);
856 /** @brief Set volume
858 * @param left New left channel value
859 * @param right New right channel value
860 * @return 0 on success, non-0 on error
862 int disorder_set_volume(disorder_client *c, int left, int right) {
865 if(byte_asprintf(&ls, "%d", left) < 0
866 || byte_asprintf(&rs, "%d", right) < 0)
868 if(disorder_simple(c, 0, "volume", ls, rs, (char *)0)) return -1;
872 /** @brief Get volume
874 * @param left Where to store left channel value
875 * @param right Where to store right channel value
876 * @return 0 on success, non-0 on error
878 int disorder_get_volume(disorder_client *c, int *left, int *right) {
881 if(disorder_simple(c, &r, "volume", (char *)0)) return -1;
882 if(sscanf(r, "%d %d", left, right) != 2) {
883 error(0, "error parsing response to 'volume': '%s'", r);
889 /** @brief Log to a sink
891 * @param s Sink to write log lines to
892 * @return 0 on success, non-0 on error
894 int disorder_log(disorder_client *c, struct sink *s) {
897 if(disorder_simple(c, 0, "log", (char *)0)) return -1;
898 while(inputline(c->ident, c->fpin, &l, '\n') >= 0 && strcmp(l, "."))
899 if(sink_printf(s, "%s\n", l) < 0) return -1;
900 if(ferror(c->fpin) || feof(c->fpin)) return -1;
904 /** @brief Look up a track name part
906 * @param partp Where to store result (UTF-8)
907 * @param track Track name (UTF-8)
908 * @param context Context (usually "sort" or "display") (UTF-8)
909 * @param part Track part (UTF-8)
910 * @return 0 on success, non-0 on error
912 int disorder_part(disorder_client *c, char **partp,
913 const char *track, const char *context, const char *part) {
914 return dequote(disorder_simple(c, partp, "part",
915 track, context, part, (char *)0), partp);
918 /** @brief Resolve aliases
920 * @param trackkp Where to store canonical name (UTF-8)
921 * @param track Track name (UTF-8)
922 * @return 0 on success, non-0 on error
924 int disorder_resolve(disorder_client *c, char **trackp, const char *track) {
925 return dequote(disorder_simple(c, trackp, "resolve", track, (char *)0),
929 /** @brief Pause the current track
931 * @return 0 on success, non-0 on error
933 int disorder_pause(disorder_client *c) {
934 return disorder_simple(c, 0, "pause", (char *)0);
937 /** @brief Resume the current track
939 * @return 0 on success, non-0 on error
941 int disorder_resume(disorder_client *c) {
942 return disorder_simple(c, 0, "resume", (char *)0);
945 /** @brief List all known tags
947 * @param vecp Where to store list (UTF-8)
948 * @param nvecp Where to store number of items, or NULL
949 * @return 0 on success, non-0 on error
951 int disorder_tags(disorder_client *c,
952 char ***vecp, int *nvecp) {
953 return disorder_simple_list(c, vecp, nvecp, "tags", (char *)0);
956 /** @brief List all known users
958 * @param vecp Where to store list (UTF-8)
959 * @param nvecp Where to store number of items, or NULL
960 * @return 0 on success, non-0 on error
962 int disorder_users(disorder_client *c,
963 char ***vecp, int *nvecp) {
964 return disorder_simple_list(c, vecp, nvecp, "users", (char *)0);
967 /** @brief Get recently added tracks
969 * @param vecp Where to store pointer to list (UTF-8)
970 * @param nvecp Where to store count
971 * @param max Maximum tracks to fetch, or 0 for all available
972 * @return 0 on success, non-0 on error
974 int disorder_new_tracks(disorder_client *c,
975 char ***vecp, int *nvecp,
979 sprintf(limit, "%d", max);
980 return disorder_simple_list(c, vecp, nvecp, "new", limit, (char *)0);
983 /** @brief Set a global preference
985 * @param key Preference name (UTF-8)
986 * @param value Preference value (UTF-8)
987 * @return 0 on success, non-0 on error
989 int disorder_set_global(disorder_client *c,
990 const char *key, const char *value) {
991 return disorder_simple(c, 0, "set-global", key, value, (char *)0);
994 /** @brief Unset a global preference
996 * @param key Preference name (UTF-8)
997 * @return 0 on success, non-0 on error
999 int disorder_unset_global(disorder_client *c, const char *key) {
1000 return disorder_simple(c, 0, "unset-global", key, (char *)0);
1003 /** @brief Get a global preference
1005 * @param key Preference name (UTF-8)
1006 * @param valuep Where to store preference value (UTF-8)
1007 * @return 0 on success, non-0 on error
1009 int disorder_get_global(disorder_client *c, const char *key, char **valuep) {
1010 return dequote(disorder_simple(c, valuep, "get-global", key, (char *)0),
1014 /** @brief Get server's RTP address information
1016 * @param addressp Where to store address (UTF-8)
1017 * @param portp Where to store port (UTF-8)
1018 * @return 0 on success, non-0 on error
1020 int disorder_rtp_address(disorder_client *c, char **addressp, char **portp) {
1025 if((rc = disorder_simple(c, &r, "rtp-address", (char *)0)))
1027 vec = split(r, &n, SPLIT_QUOTES, 0, 0);
1029 error(0, "malformed rtp-address reply");
1037 /** @brief Create a user
1039 * @param user Username
1040 * @param password Password
1041 * @param rights Initial rights or NULL to use default
1042 * @return 0 on success, non-0 on error
1044 int disorder_adduser(disorder_client *c,
1045 const char *user, const char *password,
1046 const char *rights) {
1047 return disorder_simple(c, 0, "adduser", user, password, rights, (char *)0);
1050 /** @brief Delete a user
1052 * @param user Username
1053 * @return 0 on success, non-0 on error
1055 int disorder_deluser(disorder_client *c, const char *user) {
1056 return disorder_simple(c, 0, "deluser", user, (char *)0);
1059 /** @brief Get user information
1061 * @param user Username
1062 * @param key Property name (UTF-8)
1063 * @param valuep Where to store value (UTF-8)
1064 * @return 0 on success, non-0 on error
1066 int disorder_userinfo(disorder_client *c, const char *user, const char *key,
1068 return dequote(disorder_simple(c, valuep, "userinfo", user, key, (char *)0),
1072 /** @brief Set user information
1074 * @param user Username
1075 * @param key Property name (UTF-8)
1076 * @param value New property value (UTF-8)
1077 * @return 0 on success, non-0 on error
1079 int disorder_edituser(disorder_client *c, const char *user,
1080 const char *key, const char *value) {
1081 return disorder_simple(c, 0, "edituser", user, key, value, (char *)0);
1084 /** @brief Register a user
1086 * @param user Username
1087 * @param password Password
1088 * @param email Email address (UTF-8)
1089 * @param rights Initial rights or NULL to use default
1090 * @param confirmp Where to store confirmation string
1091 * @return 0 on success, non-0 on error
1093 int disorder_register(disorder_client *c, const char *user,
1094 const char *password, const char *email,
1096 return dequote(disorder_simple(c, confirmp, "register",
1097 user, password, email, (char *)0),
1101 /** @brief Confirm a user
1103 * @param confirm Confirmation string
1104 * @return 0 on success, non-0 on error
1106 int disorder_confirm(disorder_client *c, const char *confirm) {
1107 return disorder_simple(c, 0, "confirm", confirm, (char *)0);
1110 /** @brief Make a cookie for this login
1112 * @param cookiep Where to store cookie string
1113 * @return 0 on success, non-0 on error
1115 int disorder_make_cookie(disorder_client *c, char **cookiep) {
1116 return dequote(disorder_simple(c, cookiep, "make-cookie", (char *)0),