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 @ref 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 {
67 char *last; /* last error string */
70 /** @brief Create a new client
71 * @param verbose If nonzero, write extra junk to stderr
72 * @return Pointer to new client
74 * You must call disorder_connect(), disorder_connect_user() or
75 * disorder_connect_cookie() to connect it. Use disorder_close() to
76 * dispose of the client when finished with it.
78 disorder_client *disorder_new(int verbose) {
79 disorder_client *c = xmalloc(sizeof (struct disorder_client));
85 /** @brief Read a response line
87 * @param rp Where to store response, or NULL (UTF-8)
88 * @return Response code 0-999 or -1 on error
90 static int response(disorder_client *c, char **rp) {
93 if(inputline(c->ident, c->fpin, &r, '\n'))
95 D(("response: %s", r));
98 if(r[0] >= '0' && r[0] <= '9'
99 && r[1] >= '0' && r[1] <= '9'
100 && r[2] >= '0' && r[2] <= '9'
103 return (r[0] * 10 + r[1]) * 10 + r[2] - 111 * '0';
105 error(0, "invalid reply format from %s", c->ident);
110 /** @brief Return last response string
112 * @return Last response string (UTF-8, English) or NULL
114 const char *disorder_last(disorder_client *c) {
118 /** @brief Read and partially parse a response
120 * @param rp Where to store response text (or NULL) (UTF-8)
121 * @return 0 on success, non-0 on error
123 * 5xx responses count as errors.
125 * @p rp will NOT be filled in for xx9 responses (where it is just
126 * commentary for a command where it would normally be meaningful).
128 * NB that the response will NOT be converted to the local encoding.
130 static int check_response(disorder_client *c, char **rp) {
134 if((rc = response(c, &r)) == -1)
136 else if(rc / 100 == 2) {
138 *rp = (rc % 10 == 9) ? 0 : xstrdup(r + 4);
142 error(0, "from %s: %s", c->ident, utf82mb(r));
147 /** @brief Issue a command and parse a simple response
149 * @param rp Where to store result, or NULL
151 * @param ap Arguments (UTF-8), terminated by (char *)0
152 * @return 0 on success, non-0 on error
154 * 5xx responses count as errors.
156 * @p rp will NOT be filled in for xx9 responses (where it is just
157 * commentary for a command where it would normally be meaningful).
159 * NB that the response will NOT be converted to the local encoding
160 * nor will quotes be stripped. See dequote().
162 static int disorder_simple_v(disorder_client *c,
164 const char *cmd, va_list ap) {
169 error(0, "not connected to server");
174 dynstr_append_string(&d, cmd);
175 while((arg = va_arg(ap, const char *))) {
176 dynstr_append(&d, ' ');
177 dynstr_append_string(&d, quoteutf8(arg));
179 dynstr_append(&d, '\n');
180 dynstr_terminate(&d);
181 D(("command: %s", d.vec));
182 if(fputs(d.vec, c->fpout) < 0 || fflush(c->fpout)) {
183 error(errno, "error writing to %s", c->ident);
187 return check_response(c, rp);
190 /** @brief Issue a command and parse a simple response
192 * @param rp Where to store result, or NULL (UTF-8)
194 * @return 0 on success, non-0 on error
196 * The remaining arguments are command arguments, terminated by (char
197 * *)0. They should be in UTF-8.
199 * 5xx responses count as errors.
201 * @p rp will NOT be filled in for xx9 responses (where it is just
202 * commentary for a command where it would normally be meaningful).
204 * NB that the response will NOT be converted to the local encoding
205 * nor will quotes be stripped. See dequote().
207 static int disorder_simple(disorder_client *c,
209 const char *cmd, ...) {
214 ret = disorder_simple_v(c, rp, cmd, ap);
219 /** @brief Dequote a result string
220 * @param rc 0 on success, non-0 on error
221 * @param rp Where result string is stored (UTF-8)
224 * This is used as a wrapper around disorder_simple() to dequote
227 static int dequote(int rc, char **rp) {
231 if((rr = split(*rp, 0, SPLIT_QUOTES, 0, 0)) && *rr) {
235 error(0, "invalid reply: %s", *rp);
240 /** @brief Generic connection routine
242 * @param username Username to log in with or NULL
243 * @param password Password to log in with or NULL
244 * @param cookie Cookie to log in with or NULL
245 * @return 0 on success, non-0 on error
247 * @p cookie is tried first if not NULL. If it is NULL then @p
248 * username must not be. If @p username is not NULL then nor may @p
251 static int disorder_connect_generic(disorder_client *c,
252 const char *username,
253 const char *password,
254 const char *cookie) {
255 int fd = -1, fd2 = -1, nrvec, rc;
256 unsigned char *nonce;
260 const char *protocol, *algorithm, *challenge;
264 if((salen = find_server(&sa, &c->ident)) == (socklen_t)-1)
266 c->fpin = c->fpout = 0;
267 if((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
268 error(errno, "error calling socket");
271 if(connect(fd, sa, salen) < 0) {
272 error(errno, "error calling connect");
275 if((fd2 = dup(fd)) < 0) {
276 error(errno, "error calling dup");
279 if(!(c->fpin = fdopen(fd, "rb"))) {
280 error(errno, "error calling fdopen");
284 if(!(c->fpout = fdopen(fd2, "wb"))) {
285 error(errno, "error calling fdopen");
289 if((rc = disorder_simple(c, &r, 0, (const char *)0)))
291 if(!(rvec = split(r, &nrvec, SPLIT_QUOTES, 0, 0)))
294 error(0, "cannot parse server greeting %s", r);
298 if(strcmp(protocol, "2")) {
299 error(0, "unknown protocol version: %s", protocol);
304 if(!(nonce = unhex(challenge, &nl)))
307 if(!dequote(disorder_simple(c, &c->user, "cookie", cookie, (char *)0),
309 return 0; /* success */
311 error(0, "cookie did not work and no username available");
315 if(!(res = authhash(nonce, nl, password, algorithm))) goto error;
316 if((rc = disorder_simple(c, 0, "user", username, res, (char *)0)))
318 c->user = xstrdup(username);
331 if(fd2 != -1) close(fd2);
332 if(fd != -1) close(fd);
336 /** @brief Connect a client with a specified username and password
338 * @param username Username to log in with
339 * @param password Password to log in with
340 * @return 0 on success, non-0 on error
342 int disorder_connect_user(disorder_client *c,
343 const char *username,
344 const char *password) {
345 return disorder_connect_generic(c,
351 /** @brief Connect a client
353 * @return 0 on success, non-0 on error
355 * The connection will use the username and password found in @ref
356 * config, or directly from the database if no password is found and
357 * the database is readable (usually only for root).
359 int disorder_connect(disorder_client *c) {
360 const char *username, *password;
362 if(!(username = config->username)) {
363 error(0, "no username configured");
366 password = config->password;
368 /* Maybe we can read the database */
369 /* TODO failure to open the database should not be fatal */
370 trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE);
371 trackdb_open(TRACKDB_READ_ONLY);
372 password = trackdb_get_password(username);
377 error(0, "no password configured");
380 return disorder_connect_generic(c,
386 /** @brief Connect a client
388 * @param cookie Cookie to log in with, or NULL
389 * @return 0 on success, non-0 on error
391 * If @p cookie is NULL or does not work then we attempt to log in as
392 * guest instead (so when the cookie expires only an extra round trip
393 * is needed rathre than a complete new login).
395 int disorder_connect_cookie(disorder_client *c,
396 const char *cookie) {
397 return disorder_connect_generic(c,
403 /** @brief Close a client
405 * @return 0 on succcess, non-0 on errior
407 * The client is still closed even on error. It might well be
408 * appropriate to ignore the return value.
410 int disorder_close(disorder_client *c) {
414 if(fclose(c->fpin) < 0) {
415 error(errno, "error calling fclose");
421 if(fclose(c->fpout) < 0) {
422 error(errno, "error calling fclose");
432 /** @brief Play a track
434 * @param track Track to play (UTF-8)
435 * @return 0 on success, non-0 on error
437 int disorder_play(disorder_client *c, const char *track) {
438 return disorder_simple(c, 0, "play", track, (char *)0);
441 /** @brief Remove a track
443 * @param track Track to remove (UTF-8)
444 * @return 0 on success, non-0 on error
446 int disorder_remove(disorder_client *c, const char *track) {
447 return disorder_simple(c, 0, "remove", track, (char *)0);
450 /** @brief Move a track
452 * @param track Track to move (UTF-8)
453 * @param delta Distance to move by
454 * @return 0 on success, non-0 on error
456 int disorder_move(disorder_client *c, const char *track, int delta) {
459 byte_snprintf(d, sizeof d, "%d", delta);
460 return disorder_simple(c, 0, "move", track, d, (char *)0);
463 /** @brief Enable play
465 * @return 0 on success, non-0 on error
467 int disorder_enable(disorder_client *c) {
468 return disorder_simple(c, 0, "enable", (char *)0);
471 /** @brief Disable play
473 * @return 0 on success, non-0 on error
475 int disorder_disable(disorder_client *c) {
476 return disorder_simple(c, 0, "disable", (char *)0);
479 /** @brief Scratch the currently playing track
480 * @param id Playing track ID or NULL (UTF-8)
482 * @return 0 on success, non-0 on error
484 int disorder_scratch(disorder_client *c, const char *id) {
485 return disorder_simple(c, 0, "scratch", id, (char *)0);
488 /** @brief Shut down the server
490 * @return 0 on success, non-0 on error
492 int disorder_shutdown(disorder_client *c) {
493 return disorder_simple(c, 0, "shutdown", (char *)0);
496 /** @brief Make the server re-read its configuration
498 * @return 0 on success, non-0 on error
500 int disorder_reconfigure(disorder_client *c) {
501 return disorder_simple(c, 0, "reconfigure", (char *)0);
504 /** @brief Rescan tracks
506 * @return 0 on success, non-0 on error
508 int disorder_rescan(disorder_client *c) {
509 return disorder_simple(c, 0, "rescan", (char *)0);
512 /** @brief Get server version number
514 * @param rp Where to store version string (UTF-8)
515 * @return 0 on success, non-0 on error
517 int disorder_version(disorder_client *c, char **rp) {
518 return dequote(disorder_simple(c, rp, "version", (char *)0), rp);
521 static void client_error(const char *msg,
522 void attribute((unused)) *u) {
523 error(0, "error parsing reply: %s", msg);
526 /** @brief Get currently playing track
528 * @param qp Where to store track information
529 * @return 0 on success, non-0 on error
531 * @p qp gets NULL if no track is playing.
533 int disorder_playing(disorder_client *c, struct queue_entry **qp) {
535 struct queue_entry *q;
538 if((rc = disorder_simple(c, &r, "playing", (char *)0)))
541 q = xmalloc(sizeof *q);
542 if(queue_unmarshall(q, r, client_error, 0))
550 static int disorder_somequeue(disorder_client *c,
551 const char *cmd, struct queue_entry **qp) {
552 struct queue_entry *qh, **qt = &qh, *q;
556 if((rc = disorder_simple(c, 0, cmd, (char *)0)))
558 while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
559 if(!strcmp(l, ".")) {
564 q = xmalloc(sizeof *q);
565 if(!queue_unmarshall(q, l, client_error, 0)) {
571 error(errno, "error reading %s", c->ident);
573 error(0, "error reading %s: unexpected EOF", c->ident);
577 /** @brief Get recently played tracks
579 * @param qp Where to store track information
580 * @return 0 on success, non-0 on error
582 * The last entry in the list is the most recently played track.
584 int disorder_recent(disorder_client *c, struct queue_entry **qp) {
585 return disorder_somequeue(c, "recent", qp);
590 * @param qp Where to store track information
591 * @return 0 on success, non-0 on error
593 * The first entry in the list will be played next.
595 int disorder_queue(disorder_client *c, struct queue_entry **qp) {
596 return disorder_somequeue(c, "queue", qp);
599 /** @brief Read a dot-stuffed list
601 * @param vecp Where to store list (UTF-8)
602 * @param nvecp Where to store number of items, or NULL
603 * @return 0 on success, non-0 on error
605 * The list will have a final NULL not counted in @p nvecp.
607 static int readlist(disorder_client *c, char ***vecp, int *nvecp) {
612 while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
613 if(!strcmp(l, ".")) {
614 vector_terminate(&v);
620 vector_append(&v, l + (*l == '.'));
623 error(errno, "error reading %s", c->ident);
625 error(0, "error reading %s: unexpected EOF", c->ident);
629 /** @brief Issue a comamnd and get a list response
631 * @param vecp Where to store list (UTF-8)
632 * @param nvecp Where to store number of items, or NULL
634 * @return 0 on success, non-0 on error
636 * The remaining arguments are command arguments, terminated by (char
637 * *)0. They should be in UTF-8.
639 * 5xx responses count as errors.
641 static int disorder_simple_list(disorder_client *c,
642 char ***vecp, int *nvecp,
643 const char *cmd, ...) {
648 ret = disorder_simple_v(c, 0, cmd, ap);
651 return readlist(c, vecp, nvecp);
654 /** @brief List directories below @p dir
656 * @param dir Directory to list, or NULL for root (UTF-8)
657 * @param re Regexp that results must match, or NULL (UTF-8)
658 * @param vecp Where to store list (UTF-8)
659 * @param nvecp Where to store number of items, or NULL
660 * @return 0 on success, non-0 on error
662 int disorder_directories(disorder_client *c, const char *dir, const char *re,
663 char ***vecp, int *nvecp) {
664 return disorder_simple_list(c, vecp, nvecp, "dirs", dir, re, (char *)0);
667 /** @brief List files below @p dir
669 * @param dir Directory to list, or NULL for root (UTF-8)
670 * @param re Regexp that results must match, or NULL (UTF-8)
671 * @param vecp Where to store list (UTF-8)
672 * @param nvecp Where to store number of items, or NULL
673 * @return 0 on success, non-0 on error
675 int disorder_files(disorder_client *c, const char *dir, const char *re,
676 char ***vecp, int *nvecp) {
677 return disorder_simple_list(c, vecp, nvecp, "files", dir, re, (char *)0);
680 /** @brief List files and directories below @p dir
682 * @param dir Directory to list, or NULL for root (UTF-8)
683 * @param re Regexp that results must match, or NULL (UTF-8)
684 * @param vecp Where to store list (UTF-8)
685 * @param nvecp Where to store number of items, or NULL
686 * @return 0 on success, non-0 on error
688 int disorder_allfiles(disorder_client *c, const char *dir, const char *re,
689 char ***vecp, int *nvecp) {
690 return disorder_simple_list(c, vecp, nvecp, "allfiles", dir, re, (char *)0);
693 /** @brief Return the user we logged in with
695 * @return User name (owned by @p c, don't modify)
697 char *disorder_user(disorder_client *c) {
701 /** @brief Set a track preference
703 * @param track Track name (UTF-8)
704 * @param key Preference name (UTF-8)
705 * @param value Preference value (UTF-8)
706 * @return 0 on success, non-0 on error
708 int disorder_set(disorder_client *c, const char *track,
709 const char *key, const char *value) {
710 return disorder_simple(c, 0, "set", track, key, value, (char *)0);
713 /** @brief Unset a track preference
715 * @param track Track name (UTF-8)
716 * @param key Preference name (UTF-8)
717 * @return 0 on success, non-0 on error
719 int disorder_unset(disorder_client *c, const char *track,
721 return disorder_simple(c, 0, "unset", track, key, (char *)0);
724 /** @brief Get a track preference
726 * @param track Track name (UTF-8)
727 * @param key Preference name (UTF-8)
728 * @param valuep Where to store preference value (UTF-8)
729 * @return 0 on success, non-0 on error
731 int disorder_get(disorder_client *c,
732 const char *track, const char *key, char **valuep) {
733 return dequote(disorder_simple(c, valuep, "get", track, key, (char *)0),
737 static void pref_error_handler(const char *msg,
738 void attribute((unused)) *u) {
739 error(0, "error handling 'prefs' reply: %s", msg);
742 /** @brief Get all preferences for a trcak
744 * @param track Track name
745 * @param kp Where to store linked list of preferences
746 * @return 0 on success, non-0 on error
748 int disorder_prefs(disorder_client *c, const char *track, struct kvp **kp) {
750 int nvec, npvec, n, rc;
753 if((rc = disorder_simple_list(c, &vec, &nvec, "prefs", track, (char *)0)))
755 for(n = 0; n < nvec; ++n) {
756 if(!(pvec = split(vec[n], &npvec, SPLIT_QUOTES, pref_error_handler, 0)))
759 pref_error_handler("malformed response", 0);
762 *kp = k = xmalloc(sizeof *k);
771 /** @brief Parse a boolean response
772 * @param cmd Command for use in error messsage
773 * @param value Result from server
774 * @param flagp Where to store result
775 * @return 0 on success, non-0 on error
777 static int boolean(const char *cmd, const char *value,
779 if(!strcmp(value, "yes")) *flagp = 1;
780 else if(!strcmp(value, "no")) *flagp = 0;
782 error(0, "malformed response to '%s'", cmd);
788 /** @brief Test whether a track exists
790 * @param track Track name (UTF-8)
791 * @param existsp Where to store result (non-0 iff does exist)
792 * @return 0 on success, non-0 on error
794 int disorder_exists(disorder_client *c, const char *track, int *existsp) {
798 if((rc = disorder_simple(c, &v, "exists", track, (char *)0)))
800 return boolean("exists", v, existsp);
803 /** @brief Test whether playing is enabled
805 * @param enabledp Where to store result (non-0 iff enabled)
806 * @return 0 on success, non-0 on error
808 int disorder_enabled(disorder_client *c, int *enabledp) {
812 if((rc = disorder_simple(c, &v, "enabled", (char *)0)))
814 return boolean("enabled", v, enabledp);
817 /** @brief Get the length of a track
819 * @param track Track name (UTF-8)
820 * @param valuep Where to store length in seconds
821 * @return 0 on success, non-0 on error
823 * If the length is unknown 0 is returned.
825 int disorder_length(disorder_client *c, const char *track,
830 if((rc = disorder_simple(c, &value, "length", track, (char *)0)))
832 *valuep = atol(value);
836 /** @brief Search for tracks
838 * @param terms Search terms (UTF-8)
839 * @param vecp Where to store list (UTF-8)
840 * @param nvecp Where to store number of items, or NULL
841 * @return 0 on success, non-0 on error
843 int disorder_search(disorder_client *c, const char *terms,
844 char ***vecp, int *nvecp) {
845 return disorder_simple_list(c, vecp, nvecp, "search", terms, (char *)0);
848 /** @brief Enable random play
850 * @return 0 on success, non-0 on error
852 int disorder_random_enable(disorder_client *c) {
853 return disorder_simple(c, 0, "random-enable", (char *)0);
856 /** @brief Disable random play
858 * @return 0 on success, non-0 on error
860 int disorder_random_disable(disorder_client *c) {
861 return disorder_simple(c, 0, "random-disable", (char *)0);
864 /** @brief Test whether random play is enabled
866 * @param enabledp Where to store result (non-0 iff enabled)
867 * @return 0 on success, non-0 on error
869 int disorder_random_enabled(disorder_client *c, int *enabledp) {
873 if((rc = disorder_simple(c, &v, "random-enabled", (char *)0)))
875 return boolean("random-enabled", v, enabledp);
878 /** @brief Get server stats
880 * @param vecp Where to store list (UTF-8)
881 * @param nvecp Where to store number of items, or NULL
882 * @return 0 on success, non-0 on error
884 int disorder_stats(disorder_client *c,
885 char ***vecp, int *nvecp) {
886 return disorder_simple_list(c, vecp, nvecp, "stats", (char *)0);
889 /** @brief Set volume
891 * @param left New left channel value
892 * @param right New right channel value
893 * @return 0 on success, non-0 on error
895 int disorder_set_volume(disorder_client *c, int left, int right) {
898 if(byte_asprintf(&ls, "%d", left) < 0
899 || byte_asprintf(&rs, "%d", right) < 0)
901 return disorder_simple(c, 0, "volume", ls, rs, (char *)0);
904 /** @brief Get volume
906 * @param left Where to store left channel value
907 * @param right Where to store right channel value
908 * @return 0 on success, non-0 on error
910 int disorder_get_volume(disorder_client *c, int *left, int *right) {
914 if((rc = disorder_simple(c, &r, "volume", (char *)0)))
916 if(sscanf(r, "%d %d", left, right) != 2) {
917 error(0, "error parsing response to 'volume': '%s'", r);
923 /** @brief Log to a sink
925 * @param s Sink to write log lines to
926 * @return 0 on success, non-0 on error
928 int disorder_log(disorder_client *c, struct sink *s) {
932 if((rc = disorder_simple(c, 0, "log", (char *)0)))
934 while(inputline(c->ident, c->fpin, &l, '\n') >= 0 && strcmp(l, "."))
935 if(sink_printf(s, "%s\n", l) < 0) return -1;
936 if(ferror(c->fpin) || feof(c->fpin)) return -1;
940 /** @brief Look up a track name part
942 * @param partp Where to store result (UTF-8)
943 * @param track Track name (UTF-8)
944 * @param context Context (usually "sort" or "display") (UTF-8)
945 * @param part Track part (UTF-8)
946 * @return 0 on success, non-0 on error
948 int disorder_part(disorder_client *c, char **partp,
949 const char *track, const char *context, const char *part) {
950 return dequote(disorder_simple(c, partp, "part",
951 track, context, part, (char *)0), partp);
954 /** @brief Resolve aliases
956 * @param trackp Where to store canonical name (UTF-8)
957 * @param track Track name (UTF-8)
958 * @return 0 on success, non-0 on error
960 int disorder_resolve(disorder_client *c, char **trackp, const char *track) {
961 return dequote(disorder_simple(c, trackp, "resolve", track, (char *)0),
965 /** @brief Pause the current track
967 * @return 0 on success, non-0 on error
969 int disorder_pause(disorder_client *c) {
970 return disorder_simple(c, 0, "pause", (char *)0);
973 /** @brief Resume the current track
975 * @return 0 on success, non-0 on error
977 int disorder_resume(disorder_client *c) {
978 return disorder_simple(c, 0, "resume", (char *)0);
981 /** @brief List all known tags
983 * @param vecp Where to store list (UTF-8)
984 * @param nvecp Where to store number of items, or NULL
985 * @return 0 on success, non-0 on error
987 int disorder_tags(disorder_client *c,
988 char ***vecp, int *nvecp) {
989 return disorder_simple_list(c, vecp, nvecp, "tags", (char *)0);
992 /** @brief List all known users
994 * @param vecp Where to store list (UTF-8)
995 * @param nvecp Where to store number of items, or NULL
996 * @return 0 on success, non-0 on error
998 int disorder_users(disorder_client *c,
999 char ***vecp, int *nvecp) {
1000 return disorder_simple_list(c, vecp, nvecp, "users", (char *)0);
1003 /** @brief Get recently added tracks
1005 * @param vecp Where to store pointer to list (UTF-8)
1006 * @param nvecp Where to store count
1007 * @param max Maximum tracks to fetch, or 0 for all available
1008 * @return 0 on success, non-0 on error
1010 int disorder_new_tracks(disorder_client *c,
1011 char ***vecp, int *nvecp,
1015 sprintf(limit, "%d", max);
1016 return disorder_simple_list(c, vecp, nvecp, "new", limit, (char *)0);
1019 /** @brief Set a global preference
1021 * @param key Preference name (UTF-8)
1022 * @param value Preference value (UTF-8)
1023 * @return 0 on success, non-0 on error
1025 int disorder_set_global(disorder_client *c,
1026 const char *key, const char *value) {
1027 return disorder_simple(c, 0, "set-global", key, value, (char *)0);
1030 /** @brief Unset a global preference
1032 * @param key Preference name (UTF-8)
1033 * @return 0 on success, non-0 on error
1035 int disorder_unset_global(disorder_client *c, const char *key) {
1036 return disorder_simple(c, 0, "unset-global", key, (char *)0);
1039 /** @brief Get a global preference
1041 * @param key Preference name (UTF-8)
1042 * @param valuep Where to store preference value (UTF-8)
1043 * @return 0 on success, non-0 on error
1045 int disorder_get_global(disorder_client *c, const char *key, char **valuep) {
1046 return dequote(disorder_simple(c, valuep, "get-global", key, (char *)0),
1050 /** @brief Get server's RTP address information
1052 * @param addressp Where to store address (UTF-8)
1053 * @param portp Where to store port (UTF-8)
1054 * @return 0 on success, non-0 on error
1056 int disorder_rtp_address(disorder_client *c, char **addressp, char **portp) {
1061 if((rc = disorder_simple(c, &r, "rtp-address", (char *)0)))
1063 vec = split(r, &n, SPLIT_QUOTES, 0, 0);
1065 error(0, "malformed rtp-address reply");
1073 /** @brief Create a user
1075 * @param user Username
1076 * @param password Password
1077 * @param rights Initial rights or NULL to use default
1078 * @return 0 on success, non-0 on error
1080 int disorder_adduser(disorder_client *c,
1081 const char *user, const char *password,
1082 const char *rights) {
1083 return disorder_simple(c, 0, "adduser", user, password, rights, (char *)0);
1086 /** @brief Delete a user
1088 * @param user Username
1089 * @return 0 on success, non-0 on error
1091 int disorder_deluser(disorder_client *c, const char *user) {
1092 return disorder_simple(c, 0, "deluser", user, (char *)0);
1095 /** @brief Get user information
1097 * @param user Username
1098 * @param key Property name (UTF-8)
1099 * @param valuep Where to store value (UTF-8)
1100 * @return 0 on success, non-0 on error
1102 int disorder_userinfo(disorder_client *c, const char *user, const char *key,
1104 return dequote(disorder_simple(c, valuep, "userinfo", user, key, (char *)0),
1108 /** @brief Set user information
1110 * @param user Username
1111 * @param key Property name (UTF-8)
1112 * @param value New property value (UTF-8)
1113 * @return 0 on success, non-0 on error
1115 int disorder_edituser(disorder_client *c, const char *user,
1116 const char *key, const char *value) {
1117 return disorder_simple(c, 0, "edituser", user, key, value, (char *)0);
1120 /** @brief Register a user
1122 * @param user Username
1123 * @param password Password
1124 * @param email Email address (UTF-8)
1125 * @param confirmp Where to store confirmation string
1126 * @return 0 on success, non-0 on error
1128 int disorder_register(disorder_client *c, const char *user,
1129 const char *password, const char *email,
1131 return dequote(disorder_simple(c, confirmp, "register",
1132 user, password, email, (char *)0),
1136 /** @brief Confirm a user
1138 * @param confirm Confirmation string
1139 * @return 0 on success, non-0 on error
1141 int disorder_confirm(disorder_client *c, const char *confirm) {
1145 if(!(rc = dequote(disorder_simple(c, &u, "confirm", confirm, (char *)0),
1151 /** @brief Make a cookie for this login
1153 * @param cookiep Where to store cookie string
1154 * @return 0 on success, non-0 on error
1156 int disorder_make_cookie(disorder_client *c, char **cookiep) {
1157 return dequote(disorder_simple(c, cookiep, "make-cookie", (char *)0),
1161 /** @brief Revoke the cookie used by this session
1163 * @return 0 on success, non-0 on error
1165 int disorder_revoke(disorder_client *c) {
1166 return disorder_simple(c, 0, "revoke", (char *)0);