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 {
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) {
170 dynstr_append_string(&d, cmd);
171 while((arg = va_arg(ap, const char *))) {
172 dynstr_append(&d, ' ');
173 dynstr_append_string(&d, quoteutf8(arg));
175 dynstr_append(&d, '\n');
176 dynstr_terminate(&d);
177 D(("command: %s", d.vec));
178 if(fputs(d.vec, c->fpout) < 0 || fflush(c->fpout)) {
179 error(errno, "error writing to %s", c->ident);
183 return check_response(c, rp);
186 /** @brief Issue a command and parse a simple response
188 * @param rp Where to store result, or NULL (UTF-8)
190 * @return 0 on success, non-0 on error
192 * The remaining arguments are command arguments, terminated by (char
193 * *)0. They should be in UTF-8.
195 * 5xx responses count as errors.
197 * @p rp will NOT be filled in for xx9 responses (where it is just
198 * commentary for a command where it would normally be meaningful).
200 * NB that the response will NOT be converted to the local encoding
201 * nor will quotes be stripped. See dequote().
203 static int disorder_simple(disorder_client *c,
205 const char *cmd, ...) {
210 ret = disorder_simple_v(c, rp, cmd, ap);
215 /** @brief Dequote a result string
216 * @param rc 0 on success, non-0 on error
217 * @param rp Where result string is stored (UTF-8)
220 * This is used as a wrapper around disorder_simple() to dequote
223 static int dequote(int rc, char **rp) {
227 if((rr = split(*rp, 0, SPLIT_QUOTES, 0, 0)) && *rr) {
231 error(0, "invalid reply: %s", *rp);
236 /** @brief Generic connection routine
238 * @param username Username to log in with or NULL
239 * @param password Password to log in with or NULL
240 * @param cookie Cookie to log in with or NULL
241 * @return 0 on success, non-0 on error
243 * @p cookie is tried first if not NULL. If it is NULL then @p
244 * username must not be. If @p username is not NULL then nor may @p
247 static int disorder_connect_generic(disorder_client *c,
248 const char *username,
249 const char *password,
250 const char *cookie) {
251 int fd = -1, fd2 = -1, nrvec, rc;
252 unsigned char *nonce;
256 const char *protocol, *algorithm, *challenge;
260 if((salen = find_server(&sa, &c->ident)) == (socklen_t)-1)
262 c->fpin = c->fpout = 0;
263 if((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
264 error(errno, "error calling socket");
267 if(connect(fd, sa, salen) < 0) {
268 error(errno, "error calling connect");
271 if((fd2 = dup(fd)) < 0) {
272 error(errno, "error calling dup");
275 if(!(c->fpin = fdopen(fd, "rb"))) {
276 error(errno, "error calling fdopen");
280 if(!(c->fpout = fdopen(fd2, "wb"))) {
281 error(errno, "error calling fdopen");
285 if((rc = disorder_simple(c, &r, 0, (const char *)0)))
287 if(!(rvec = split(r, &nrvec, SPLIT_QUOTES, 0, 0)))
290 error(0, "cannot parse server greeting %s", r);
294 if(strcmp(protocol, "2")) {
295 error(0, "unknown protocol version: %s", protocol);
300 if(!(nonce = unhex(challenge, &nl)))
303 if(!dequote(disorder_simple(c, &c->user, "cookie", cookie, (char *)0),
305 return 0; /* success */
307 error(0, "cookie did not work and no username available");
311 if(!(res = authhash(nonce, nl, password, algorithm))) goto error;
312 if((rc = disorder_simple(c, 0, "user", username, res, (char *)0)))
314 c->user = xstrdup(username);
327 if(fd2 != -1) close(fd2);
328 if(fd != -1) close(fd);
332 /** @brief Connect a client with a specified username and password
334 * @param username Username to log in with
335 * @param password Password to log in with
336 * @return 0 on success, non-0 on error
338 int disorder_connect_user(disorder_client *c,
339 const char *username,
340 const char *password) {
341 return disorder_connect_generic(c,
347 /** @brief Connect a client
349 * @return 0 on success, non-0 on error
351 * The connection will use the username and password found in @ref
352 * config, or directly from the database if no password is found and
353 * the database is readable (usually only for root).
355 int disorder_connect(disorder_client *c) {
356 const char *username, *password;
358 if(!(username = config->username)) {
359 error(0, "no username configured");
362 password = config->password;
364 /* Maybe we can read the database */
365 /* TODO failure to open the database should not be fatal */
366 trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE);
367 trackdb_open(TRACKDB_READ_ONLY);
368 password = trackdb_get_password(username);
373 error(0, "no password configured");
376 return disorder_connect_generic(c,
382 /** @brief Connect a client
384 * @param cookie Cookie to log in with, or NULL
385 * @return 0 on success, non-0 on error
387 * If @p cookie is NULL or does not work then we attempt to log in as
388 * guest instead (so when the cookie expires only an extra round trip
389 * is needed rathre than a complete new login).
391 int disorder_connect_cookie(disorder_client *c,
392 const char *cookie) {
393 return disorder_connect_generic(c,
399 /** @brief Close a client
401 * @return 0 on succcess, non-0 on errior
403 * The client is still closed even on error. It might well be
404 * appropriate to ignore the return value.
406 int disorder_close(disorder_client *c) {
410 if(fclose(c->fpin) < 0) {
411 error(errno, "error calling fclose");
417 if(fclose(c->fpout) < 0) {
418 error(errno, "error calling fclose");
428 /** @brief Play a track
430 * @param track Track to play (UTF-8)
431 * @return 0 on success, non-0 on error
433 int disorder_play(disorder_client *c, const char *track) {
434 return disorder_simple(c, 0, "play", track, (char *)0);
437 /** @brief Remove a track
439 * @param track Track to remove (UTF-8)
440 * @return 0 on success, non-0 on error
442 int disorder_remove(disorder_client *c, const char *track) {
443 return disorder_simple(c, 0, "remove", track, (char *)0);
446 /** @brief Move a track
448 * @param track Track to move (UTF-8)
449 * @param delta Distance to move by
450 * @return 0 on success, non-0 on error
452 int disorder_move(disorder_client *c, const char *track, int delta) {
455 byte_snprintf(d, sizeof d, "%d", delta);
456 return disorder_simple(c, 0, "move", track, d, (char *)0);
459 /** @brief Enable play
461 * @return 0 on success, non-0 on error
463 int disorder_enable(disorder_client *c) {
464 return disorder_simple(c, 0, "enable", (char *)0);
467 /** @brief Disable play
469 * @return 0 on success, non-0 on error
471 int disorder_disable(disorder_client *c) {
472 return disorder_simple(c, 0, "disable", (char *)0);
475 /** @brief Scratch the currently playing track
476 * @param id Playing track ID or NULL (UTF-8)
478 * @return 0 on success, non-0 on error
480 int disorder_scratch(disorder_client *c, const char *id) {
481 return disorder_simple(c, 0, "scratch", id, (char *)0);
484 /** @brief Shut down the server
486 * @return 0 on success, non-0 on error
488 int disorder_shutdown(disorder_client *c) {
489 return disorder_simple(c, 0, "shutdown", (char *)0);
492 /** @brief Make the server re-read its configuration
494 * @return 0 on success, non-0 on error
496 int disorder_reconfigure(disorder_client *c) {
497 return disorder_simple(c, 0, "reconfigure", (char *)0);
500 /** @brief Rescan tracks
502 * @return 0 on success, non-0 on error
504 int disorder_rescan(disorder_client *c) {
505 return disorder_simple(c, 0, "rescan", (char *)0);
508 /** @brief Get server version number
510 * @param rp Where to store version string (UTF-8)
511 * @return 0 on success, non-0 on error
513 int disorder_version(disorder_client *c, char **rp) {
514 return dequote(disorder_simple(c, rp, "version", (char *)0), rp);
517 static void client_error(const char *msg,
518 void attribute((unused)) *u) {
519 error(0, "error parsing reply: %s", msg);
522 /** @brief Get currently playing track
524 * @param qp Where to store track information
525 * @return 0 on success, non-0 on error
527 * @p qp gets NULL if no track is playing.
529 int disorder_playing(disorder_client *c, struct queue_entry **qp) {
531 struct queue_entry *q;
534 if((rc = disorder_simple(c, &r, "playing", (char *)0)))
537 q = xmalloc(sizeof *q);
538 if(queue_unmarshall(q, r, client_error, 0))
546 static int disorder_somequeue(disorder_client *c,
547 const char *cmd, struct queue_entry **qp) {
548 struct queue_entry *qh, **qt = &qh, *q;
552 if((rc = disorder_simple(c, 0, cmd, (char *)0)))
554 while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
555 if(!strcmp(l, ".")) {
560 q = xmalloc(sizeof *q);
561 if(!queue_unmarshall(q, l, client_error, 0)) {
567 error(errno, "error reading %s", c->ident);
569 error(0, "error reading %s: unexpected EOF", c->ident);
573 /** @brief Get recently played tracks
575 * @param qp Where to store track information
576 * @return 0 on success, non-0 on error
578 * The last entry in the list is the most recently played track.
580 int disorder_recent(disorder_client *c, struct queue_entry **qp) {
581 return disorder_somequeue(c, "recent", qp);
586 * @param qp Where to store track information
587 * @return 0 on success, non-0 on error
589 * The first entry in the list will be played next.
591 int disorder_queue(disorder_client *c, struct queue_entry **qp) {
592 return disorder_somequeue(c, "queue", qp);
595 /** @brief Read a dot-stuffed list
597 * @param vecp Where to store list (UTF-8)
598 * @param nvecp Where to store number of items, or NULL
599 * @return 0 on success, non-0 on error
601 * The list will have a final NULL not counted in @p nvecp.
603 static int readlist(disorder_client *c, char ***vecp, int *nvecp) {
608 while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
609 if(!strcmp(l, ".")) {
610 vector_terminate(&v);
616 vector_append(&v, l + (*l == '.'));
619 error(errno, "error reading %s", c->ident);
621 error(0, "error reading %s: unexpected EOF", c->ident);
625 /** @brief Issue a comamnd and get a list response
627 * @param vecp Where to store list (UTF-8)
628 * @param nvecp Where to store number of items, or NULL
630 * @return 0 on success, non-0 on error
632 * The remaining arguments are command arguments, terminated by (char
633 * *)0. They should be in UTF-8.
635 * 5xx responses count as errors.
637 static int disorder_simple_list(disorder_client *c,
638 char ***vecp, int *nvecp,
639 const char *cmd, ...) {
644 ret = disorder_simple_v(c, 0, cmd, ap);
647 return readlist(c, vecp, nvecp);
650 /** @brief List directories below @p dir
652 * @param dir Directory to list, or NULL for root (UTF-8)
653 * @param re Regexp that results must match, or NULL (UTF-8)
654 * @param vecp Where to store list (UTF-8)
655 * @param nvecp Where to store number of items, or NULL
656 * @return 0 on success, non-0 on error
658 int disorder_directories(disorder_client *c, const char *dir, const char *re,
659 char ***vecp, int *nvecp) {
660 return disorder_simple_list(c, vecp, nvecp, "dirs", dir, re, (char *)0);
663 /** @brief List files below @p dir
665 * @param dir Directory to list, or NULL for root (UTF-8)
666 * @param re Regexp that results must match, or NULL (UTF-8)
667 * @param vecp Where to store list (UTF-8)
668 * @param nvecp Where to store number of items, or NULL
669 * @return 0 on success, non-0 on error
671 int disorder_files(disorder_client *c, const char *dir, const char *re,
672 char ***vecp, int *nvecp) {
673 return disorder_simple_list(c, vecp, nvecp, "files", dir, re, (char *)0);
676 /** @brief List files and directories below @p dir
678 * @param dir Directory to list, or NULL for root (UTF-8)
679 * @param re Regexp that results must match, or NULL (UTF-8)
680 * @param vecp Where to store list (UTF-8)
681 * @param nvecp Where to store number of items, or NULL
682 * @return 0 on success, non-0 on error
684 int disorder_allfiles(disorder_client *c, const char *dir, const char *re,
685 char ***vecp, int *nvecp) {
686 return disorder_simple_list(c, vecp, nvecp, "allfiles", dir, re, (char *)0);
689 /** @brief Return the user we logged in with
691 * @return User name (owned by @p c, don't modify)
693 char *disorder_user(disorder_client *c) {
697 /** @brief Set a track preference
699 * @param track Track name (UTF-8)
700 * @param key Preference name (UTF-8)
701 * @param value Preference value (UTF-8)
702 * @return 0 on success, non-0 on error
704 int disorder_set(disorder_client *c, const char *track,
705 const char *key, const char *value) {
706 return disorder_simple(c, 0, "set", track, key, value, (char *)0);
709 /** @brief Unset a track preference
711 * @param track Track name (UTF-8)
712 * @param key Preference name (UTF-8)
713 * @return 0 on success, non-0 on error
715 int disorder_unset(disorder_client *c, const char *track,
717 return disorder_simple(c, 0, "unset", track, key, (char *)0);
720 /** @brief Get a track preference
722 * @param track Track name (UTF-8)
723 * @param key Preference name (UTF-8)
724 * @param valuep Where to store preference value (UTF-8)
725 * @return 0 on success, non-0 on error
727 int disorder_get(disorder_client *c,
728 const char *track, const char *key, char **valuep) {
729 return dequote(disorder_simple(c, valuep, "get", track, key, (char *)0),
733 static void pref_error_handler(const char *msg,
734 void attribute((unused)) *u) {
735 error(0, "error handling 'prefs' reply: %s", msg);
738 /** @param Get all preferences for a trcak
740 * @param track Track name
741 * @param kp Where to store linked list of preferences
742 * @return 0 on success, non-0 on error
744 int disorder_prefs(disorder_client *c, const char *track, struct kvp **kp) {
746 int nvec, npvec, n, rc;
749 if((rc = disorder_simple_list(c, &vec, &nvec, "prefs", track, (char *)0)))
751 for(n = 0; n < nvec; ++n) {
752 if(!(pvec = split(vec[n], &npvec, SPLIT_QUOTES, pref_error_handler, 0)))
755 pref_error_handler("malformed response", 0);
758 *kp = k = xmalloc(sizeof *k);
767 /** @brief Parse a boolean response
768 * @param cmd Command for use in error messsage
769 * @param value Result from server
770 * @param flagp Where to store result
771 * @return 0 on success, non-0 on error
773 static int boolean(const char *cmd, const char *value,
775 if(!strcmp(value, "yes")) *flagp = 1;
776 else if(!strcmp(value, "no")) *flagp = 0;
778 error(0, "malformed response to '%s'", cmd);
784 /** @brief Test whether a track exists
786 * @param track Track name (UTF-8)
787 * @param existsp Where to store result (non-0 iff does exist)
788 * @return 0 on success, non-0 on error
790 int disorder_exists(disorder_client *c, const char *track, int *existsp) {
794 if((rc = disorder_simple(c, &v, "exists", track, (char *)0)))
796 return boolean("exists", v, existsp);
799 /** @brief Test whether playing is enabled
801 * @param enabledp Where to store result (non-0 iff enabled)
802 * @return 0 on success, non-0 on error
804 int disorder_enabled(disorder_client *c, int *enabledp) {
808 if((rc = disorder_simple(c, &v, "enabled", (char *)0)))
810 return boolean("enabled", v, enabledp);
813 /** @brief Get the length of a track
815 * @param track Track name (UTF-8)
816 * @param valuep Where to store length in seconds
817 * @return 0 on success, non-0 on error
819 * If the length is unknown 0 is returned.
821 int disorder_length(disorder_client *c, const char *track,
826 if((rc = disorder_simple(c, &value, "length", track, (char *)0)))
828 *valuep = atol(value);
832 /** @brief Search for tracks
834 * @param terms Search terms (UTF-8)
835 * @param vecp Where to store list (UTF-8)
836 * @param nvecp Where to store number of items, or NULL
837 * @return 0 on success, non-0 on error
839 int disorder_search(disorder_client *c, const char *terms,
840 char ***vecp, int *nvecp) {
841 return disorder_simple_list(c, vecp, nvecp, "search", terms, (char *)0);
844 /** @brief Enable random play
846 * @return 0 on success, non-0 on error
848 int disorder_random_enable(disorder_client *c) {
849 return disorder_simple(c, 0, "random-enable", (char *)0);
852 /** @brief Disable random play
854 * @return 0 on success, non-0 on error
856 int disorder_random_disable(disorder_client *c) {
857 return disorder_simple(c, 0, "random-disable", (char *)0);
860 /** @brief Test whether random play is enabled
862 * @param existsp Where to store result (non-0 iff enabled)
863 * @return 0 on success, non-0 on error
865 int disorder_random_enabled(disorder_client *c, int *enabledp) {
869 if((rc = disorder_simple(c, &v, "random-enabled", (char *)0)))
871 return boolean("random-enabled", v, enabledp);
874 /** @brief Get server stats
876 * @param vecp Where to store list (UTF-8)
877 * @param nvecp Where to store number of items, or NULL
878 * @return 0 on success, non-0 on error
880 int disorder_stats(disorder_client *c,
881 char ***vecp, int *nvecp) {
882 return disorder_simple_list(c, vecp, nvecp, "stats", (char *)0);
885 /** @brief Set volume
887 * @param left New left channel value
888 * @param right New right channel value
889 * @return 0 on success, non-0 on error
891 int disorder_set_volume(disorder_client *c, int left, int right) {
894 if(byte_asprintf(&ls, "%d", left) < 0
895 || byte_asprintf(&rs, "%d", right) < 0)
897 return disorder_simple(c, 0, "volume", ls, rs, (char *)0);
900 /** @brief Get volume
902 * @param left Where to store left channel value
903 * @param right Where to store right channel value
904 * @return 0 on success, non-0 on error
906 int disorder_get_volume(disorder_client *c, int *left, int *right) {
910 if((rc = disorder_simple(c, &r, "volume", (char *)0)))
912 if(sscanf(r, "%d %d", left, right) != 2) {
913 error(0, "error parsing response to 'volume': '%s'", r);
919 /** @brief Log to a sink
921 * @param s Sink to write log lines to
922 * @return 0 on success, non-0 on error
924 int disorder_log(disorder_client *c, struct sink *s) {
928 if((rc = disorder_simple(c, 0, "log", (char *)0)))
930 while(inputline(c->ident, c->fpin, &l, '\n') >= 0 && strcmp(l, "."))
931 if(sink_printf(s, "%s\n", l) < 0) return -1;
932 if(ferror(c->fpin) || feof(c->fpin)) return -1;
936 /** @brief Look up a track name part
938 * @param partp Where to store result (UTF-8)
939 * @param track Track name (UTF-8)
940 * @param context Context (usually "sort" or "display") (UTF-8)
941 * @param part Track part (UTF-8)
942 * @return 0 on success, non-0 on error
944 int disorder_part(disorder_client *c, char **partp,
945 const char *track, const char *context, const char *part) {
946 return dequote(disorder_simple(c, partp, "part",
947 track, context, part, (char *)0), partp);
950 /** @brief Resolve aliases
952 * @param trackkp Where to store canonical name (UTF-8)
953 * @param track Track name (UTF-8)
954 * @return 0 on success, non-0 on error
956 int disorder_resolve(disorder_client *c, char **trackp, const char *track) {
957 return dequote(disorder_simple(c, trackp, "resolve", track, (char *)0),
961 /** @brief Pause the current track
963 * @return 0 on success, non-0 on error
965 int disorder_pause(disorder_client *c) {
966 return disorder_simple(c, 0, "pause", (char *)0);
969 /** @brief Resume the current track
971 * @return 0 on success, non-0 on error
973 int disorder_resume(disorder_client *c) {
974 return disorder_simple(c, 0, "resume", (char *)0);
977 /** @brief List all known tags
979 * @param vecp Where to store list (UTF-8)
980 * @param nvecp Where to store number of items, or NULL
981 * @return 0 on success, non-0 on error
983 int disorder_tags(disorder_client *c,
984 char ***vecp, int *nvecp) {
985 return disorder_simple_list(c, vecp, nvecp, "tags", (char *)0);
988 /** @brief List all known users
990 * @param vecp Where to store list (UTF-8)
991 * @param nvecp Where to store number of items, or NULL
992 * @return 0 on success, non-0 on error
994 int disorder_users(disorder_client *c,
995 char ***vecp, int *nvecp) {
996 return disorder_simple_list(c, vecp, nvecp, "users", (char *)0);
999 /** @brief Get recently added tracks
1001 * @param vecp Where to store pointer to list (UTF-8)
1002 * @param nvecp Where to store count
1003 * @param max Maximum tracks to fetch, or 0 for all available
1004 * @return 0 on success, non-0 on error
1006 int disorder_new_tracks(disorder_client *c,
1007 char ***vecp, int *nvecp,
1011 sprintf(limit, "%d", max);
1012 return disorder_simple_list(c, vecp, nvecp, "new", limit, (char *)0);
1015 /** @brief Set a global preference
1017 * @param key Preference name (UTF-8)
1018 * @param value Preference value (UTF-8)
1019 * @return 0 on success, non-0 on error
1021 int disorder_set_global(disorder_client *c,
1022 const char *key, const char *value) {
1023 return disorder_simple(c, 0, "set-global", key, value, (char *)0);
1026 /** @brief Unset a global preference
1028 * @param key Preference name (UTF-8)
1029 * @return 0 on success, non-0 on error
1031 int disorder_unset_global(disorder_client *c, const char *key) {
1032 return disorder_simple(c, 0, "unset-global", key, (char *)0);
1035 /** @brief Get a global preference
1037 * @param key Preference name (UTF-8)
1038 * @param valuep Where to store preference value (UTF-8)
1039 * @return 0 on success, non-0 on error
1041 int disorder_get_global(disorder_client *c, const char *key, char **valuep) {
1042 return dequote(disorder_simple(c, valuep, "get-global", key, (char *)0),
1046 /** @brief Get server's RTP address information
1048 * @param addressp Where to store address (UTF-8)
1049 * @param portp Where to store port (UTF-8)
1050 * @return 0 on success, non-0 on error
1052 int disorder_rtp_address(disorder_client *c, char **addressp, char **portp) {
1057 if((rc = disorder_simple(c, &r, "rtp-address", (char *)0)))
1059 vec = split(r, &n, SPLIT_QUOTES, 0, 0);
1061 error(0, "malformed rtp-address reply");
1069 /** @brief Create a user
1071 * @param user Username
1072 * @param password Password
1073 * @param rights Initial rights or NULL to use default
1074 * @return 0 on success, non-0 on error
1076 int disorder_adduser(disorder_client *c,
1077 const char *user, const char *password,
1078 const char *rights) {
1079 return disorder_simple(c, 0, "adduser", user, password, rights, (char *)0);
1082 /** @brief Delete a user
1084 * @param user Username
1085 * @return 0 on success, non-0 on error
1087 int disorder_deluser(disorder_client *c, const char *user) {
1088 return disorder_simple(c, 0, "deluser", user, (char *)0);
1091 /** @brief Get user information
1093 * @param user Username
1094 * @param key Property name (UTF-8)
1095 * @param valuep Where to store value (UTF-8)
1096 * @return 0 on success, non-0 on error
1098 int disorder_userinfo(disorder_client *c, const char *user, const char *key,
1100 return dequote(disorder_simple(c, valuep, "userinfo", user, key, (char *)0),
1104 /** @brief Set user information
1106 * @param user Username
1107 * @param key Property name (UTF-8)
1108 * @param value New property value (UTF-8)
1109 * @return 0 on success, non-0 on error
1111 int disorder_edituser(disorder_client *c, const char *user,
1112 const char *key, const char *value) {
1113 return disorder_simple(c, 0, "edituser", user, key, value, (char *)0);
1116 /** @brief Register a user
1118 * @param user Username
1119 * @param password Password
1120 * @param email Email address (UTF-8)
1121 * @param rights Initial rights or NULL to use default
1122 * @param confirmp Where to store confirmation string
1123 * @return 0 on success, non-0 on error
1125 int disorder_register(disorder_client *c, const char *user,
1126 const char *password, const char *email,
1128 return dequote(disorder_simple(c, confirmp, "register",
1129 user, password, email, (char *)0),
1133 /** @brief Confirm a user
1135 * @param confirm Confirmation string
1136 * @return 0 on success, non-0 on error
1138 int disorder_confirm(disorder_client *c, const char *confirm) {
1139 return disorder_simple(c, 0, "confirm", confirm, (char *)0);
1142 /** @brief Make a cookie for this login
1144 * @param cookiep Where to store cookie string
1145 * @return 0 on success, non-0 on error
1147 int disorder_make_cookie(disorder_client *c, char **cookiep) {
1148 return dequote(disorder_simple(c, cookiep, "make-cookie", (char *)0),