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) {
217 if((rr = split(*rp, 0, SPLIT_QUOTES, 0, 0)) && *rr) {
221 error(0, "invalid reply: %s", *rp);
226 /** @brief Generic connection routine
228 * @param username Username to log in with or NULL
229 * @param password Password to log in with or NULL
230 * @param cookie Cookie to log in with or NULL
231 * @return 0 on success, non-0 on error
233 * @p cookie is tried first if not NULL. If it is NULL then @p
234 * username must not be. If @p username is not NULL then nor may @p
237 static int disorder_connect_generic(disorder_client *c,
238 const char *username,
239 const char *password,
240 const char *cookie) {
241 int fd = -1, fd2 = -1, nrvec, rc;
242 unsigned char *nonce;
246 const char *protocol, *algorithm, *challenge;
250 if((salen = find_server(&sa, &c->ident)) == (socklen_t)-1)
252 c->fpin = c->fpout = 0;
253 if((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
254 error(errno, "error calling socket");
257 if(connect(fd, sa, salen) < 0) {
258 error(errno, "error calling connect");
261 if((fd2 = dup(fd)) < 0) {
262 error(errno, "error calling dup");
265 if(!(c->fpin = fdopen(fd, "rb"))) {
266 error(errno, "error calling fdopen");
270 if(!(c->fpout = fdopen(fd2, "wb"))) {
271 error(errno, "error calling fdopen");
275 if((rc = disorder_simple(c, &r, 0, (const char *)0)))
277 if(!(rvec = split(r, &nrvec, SPLIT_QUOTES, 0, 0)))
280 error(0, "cannot parse server greeting %s", r);
284 if(strcmp(protocol, "2")) {
285 error(0, "unknown protocol version: %s", protocol);
290 if(!(nonce = unhex(challenge, &nl)))
293 if(!dequote(disorder_simple(c, &c->user, "cookie", cookie, (char *)0),
295 return 0; /* success */
297 error(0, "cookie did not work and no username available");
301 if(!(res = authhash(nonce, nl, password, algorithm))) goto error;
302 if((rc = disorder_simple(c, 0, "user", username, res, (char *)0)))
304 c->user = xstrdup(username);
317 if(fd2 != -1) close(fd2);
318 if(fd != -1) close(fd);
322 /** @brief Connect a client with a specified username and password
324 * @param username Username to log in with
325 * @param password Password to log in with
326 * @return 0 on success, non-0 on error
328 int disorder_connect_user(disorder_client *c,
329 const char *username,
330 const char *password) {
331 return disorder_connect_generic(c,
337 /** @brief Connect a client
339 * @return 0 on success, non-0 on error
341 * The connection will use the username and password found in @ref
342 * config, or directly from the database if no password is found and
343 * the database is readable (usually only for root).
345 int disorder_connect(disorder_client *c) {
346 const char *username, *password;
348 if(!(username = config->username)) {
349 error(0, "no username configured");
352 password = config->password;
354 /* Maybe we can read the database */
355 /* TODO failure to open the database should not be fatal */
356 trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE);
357 trackdb_open(TRACKDB_READ_ONLY);
358 password = trackdb_get_password(username);
363 error(0, "no password configured");
366 return disorder_connect_generic(c,
372 /** @brief Connect a client
374 * @param cookie Cookie to log in with, or NULL
375 * @return 0 on success, non-0 on error
377 * If @p cookie is NULL or does not work then we attempt to log in as
378 * guest instead (so when the cookie expires only an extra round trip
379 * is needed rathre than a complete new login).
381 int disorder_connect_cookie(disorder_client *c,
382 const char *cookie) {
383 return disorder_connect_generic(c,
389 /** @brief Close a client
391 * @return 0 on succcess, non-0 on errior
393 * The client is still closed even on error. It might well be
394 * appropriate to ignore the return value.
396 int disorder_close(disorder_client *c) {
400 if(fclose(c->fpin) < 0) {
401 error(errno, "error calling fclose");
407 if(fclose(c->fpout) < 0) {
408 error(errno, "error calling fclose");
418 /** @brief Play a track
420 * @param track Track to play (UTF-8)
421 * @return 0 on success, non-0 on error
423 int disorder_play(disorder_client *c, const char *track) {
424 return disorder_simple(c, 0, "play", track, (char *)0);
427 /** @brief Remove a track
429 * @param track Track to remove (UTF-8)
430 * @return 0 on success, non-0 on error
432 int disorder_remove(disorder_client *c, const char *track) {
433 return disorder_simple(c, 0, "remove", track, (char *)0);
436 /** @brief Move a track
438 * @param track Track to move (UTF-8)
439 * @param delta Distance to move by
440 * @return 0 on success, non-0 on error
442 int disorder_move(disorder_client *c, const char *track, int delta) {
445 byte_snprintf(d, sizeof d, "%d", delta);
446 return disorder_simple(c, 0, "move", track, d, (char *)0);
449 /** @brief Enable play
451 * @return 0 on success, non-0 on error
453 int disorder_enable(disorder_client *c) {
454 return disorder_simple(c, 0, "enable", (char *)0);
457 /** @brief Disable play
459 * @return 0 on success, non-0 on error
461 int disorder_disable(disorder_client *c) {
462 return disorder_simple(c, 0, "disable", (char *)0);
465 /** @brief Scratch the currently playing track
466 * @param id Playing track ID or NULL (UTF-8)
468 * @return 0 on success, non-0 on error
470 int disorder_scratch(disorder_client *c, const char *id) {
471 return disorder_simple(c, 0, "scratch", id, (char *)0);
474 /** @brief Shut down the server
476 * @return 0 on success, non-0 on error
478 int disorder_shutdown(disorder_client *c) {
479 return disorder_simple(c, 0, "shutdown", (char *)0);
482 /** @brief Make the server re-read its configuration
484 * @return 0 on success, non-0 on error
486 int disorder_reconfigure(disorder_client *c) {
487 return disorder_simple(c, 0, "reconfigure", (char *)0);
490 /** @brief Rescan tracks
492 * @return 0 on success, non-0 on error
494 int disorder_rescan(disorder_client *c) {
495 return disorder_simple(c, 0, "rescan", (char *)0);
498 /** @brief Get server version number
500 * @param rp Where to store version string (UTF-8)
501 * @return 0 on success, non-0 on error
503 int disorder_version(disorder_client *c, char **rp) {
504 return dequote(disorder_simple(c, rp, "version", (char *)0), rp);
507 static void client_error(const char *msg,
508 void attribute((unused)) *u) {
509 error(0, "error parsing reply: %s", msg);
512 /** @brief Get currently playing track
514 * @param qp Where to store track information
515 * @return 0 on success, non-0 on error
517 * @p qp gets NULL if no track is playing.
519 int disorder_playing(disorder_client *c, struct queue_entry **qp) {
521 struct queue_entry *q;
524 if((rc = disorder_simple(c, &r, "playing", (char *)0)))
527 q = xmalloc(sizeof *q);
528 if(queue_unmarshall(q, r, client_error, 0))
536 static int disorder_somequeue(disorder_client *c,
537 const char *cmd, struct queue_entry **qp) {
538 struct queue_entry *qh, **qt = &qh, *q;
542 if((rc = disorder_simple(c, 0, cmd, (char *)0)))
544 while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
545 if(!strcmp(l, ".")) {
550 q = xmalloc(sizeof *q);
551 if(!queue_unmarshall(q, l, client_error, 0)) {
557 error(errno, "error reading %s", c->ident);
559 error(0, "error reading %s: unexpected EOF", c->ident);
563 /** @brief Get recently played tracks
565 * @param qp Where to store track information
566 * @return 0 on success, non-0 on error
568 * The last entry in the list is the most recently played track.
570 int disorder_recent(disorder_client *c, struct queue_entry **qp) {
571 return disorder_somequeue(c, "recent", qp);
576 * @param qp Where to store track information
577 * @return 0 on success, non-0 on error
579 * The first entry in the list will be played next.
581 int disorder_queue(disorder_client *c, struct queue_entry **qp) {
582 return disorder_somequeue(c, "queue", qp);
585 /** @brief Read a dot-stuffed list
587 * @param vecp Where to store list (UTF-8)
588 * @param nvecp Where to store number of items, or NULL
589 * @return 0 on success, non-0 on error
591 * The list will have a final NULL not counted in @p nvecp.
593 static int readlist(disorder_client *c, char ***vecp, int *nvecp) {
598 while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
599 if(!strcmp(l, ".")) {
600 vector_terminate(&v);
606 vector_append(&v, l + (*l == '.'));
609 error(errno, "error reading %s", c->ident);
611 error(0, "error reading %s: unexpected EOF", c->ident);
615 /** @brief Issue a comamnd and get a list response
617 * @param vecp Where to store list (UTF-8)
618 * @param nvecp Where to store number of items, or NULL
620 * @return 0 on success, non-0 on error
622 * The remaining arguments are command arguments, terminated by (char
623 * *)0. They should be in UTF-8.
625 * 5xx responses count as errors.
627 static int disorder_simple_list(disorder_client *c,
628 char ***vecp, int *nvecp,
629 const char *cmd, ...) {
634 ret = disorder_simple_v(c, 0, cmd, ap);
637 return readlist(c, vecp, nvecp);
640 /** @brief List directories below @p dir
642 * @param dir Directory to list, or NULL for root (UTF-8)
643 * @param re Regexp that results must match, or NULL (UTF-8)
644 * @param vecp Where to store list (UTF-8)
645 * @param nvecp Where to store number of items, or NULL
646 * @return 0 on success, non-0 on error
648 int disorder_directories(disorder_client *c, const char *dir, const char *re,
649 char ***vecp, int *nvecp) {
650 return disorder_simple_list(c, vecp, nvecp, "dirs", dir, re, (char *)0);
653 /** @brief List files below @p dir
655 * @param dir Directory to list, or NULL for root (UTF-8)
656 * @param re Regexp that results must match, or NULL (UTF-8)
657 * @param vecp Where to store list (UTF-8)
658 * @param nvecp Where to store number of items, or NULL
659 * @return 0 on success, non-0 on error
661 int disorder_files(disorder_client *c, const char *dir, const char *re,
662 char ***vecp, int *nvecp) {
663 return disorder_simple_list(c, vecp, nvecp, "files", dir, re, (char *)0);
666 /** @brief List files and directories below @p dir
668 * @param dir Directory to list, or NULL for root (UTF-8)
669 * @param re Regexp that results must match, or NULL (UTF-8)
670 * @param vecp Where to store list (UTF-8)
671 * @param nvecp Where to store number of items, or NULL
672 * @return 0 on success, non-0 on error
674 int disorder_allfiles(disorder_client *c, const char *dir, const char *re,
675 char ***vecp, int *nvecp) {
676 return disorder_simple_list(c, vecp, nvecp, "allfiles", dir, re, (char *)0);
679 /** @brief Return the user we logged in with
681 * @return User name (owned by @p c, don't modify)
683 char *disorder_user(disorder_client *c) {
687 /** @brief Set a track preference
689 * @param track Track name (UTF-8)
690 * @param key Preference name (UTF-8)
691 * @param value Preference value (UTF-8)
692 * @return 0 on success, non-0 on error
694 int disorder_set(disorder_client *c, const char *track,
695 const char *key, const char *value) {
696 return disorder_simple(c, 0, "set", track, key, value, (char *)0);
699 /** @brief Unset a track preference
701 * @param track Track name (UTF-8)
702 * @param key Preference name (UTF-8)
703 * @return 0 on success, non-0 on error
705 int disorder_unset(disorder_client *c, const char *track,
707 return disorder_simple(c, 0, "unset", track, key, (char *)0);
710 /** @brief Get a track preference
712 * @param track Track name (UTF-8)
713 * @param key Preference name (UTF-8)
714 * @param valuep Where to store preference value (UTF-8)
715 * @return 0 on success, non-0 on error
717 int disorder_get(disorder_client *c,
718 const char *track, const char *key, char **valuep) {
719 return dequote(disorder_simple(c, valuep, "get", track, key, (char *)0),
723 static void pref_error_handler(const char *msg,
724 void attribute((unused)) *u) {
725 error(0, "error handling 'prefs' reply: %s", msg);
728 /** @param Get all preferences for a trcak
730 * @param track Track name
731 * @param kp Where to store linked list of preferences
732 * @return 0 on success, non-0 on error
734 int disorder_prefs(disorder_client *c, const char *track, struct kvp **kp) {
736 int nvec, npvec, n, rc;
739 if((rc = disorder_simple_list(c, &vec, &nvec, "prefs", track, (char *)0)))
741 for(n = 0; n < nvec; ++n) {
742 if(!(pvec = split(vec[n], &npvec, SPLIT_QUOTES, pref_error_handler, 0)))
745 pref_error_handler("malformed response", 0);
748 *kp = k = xmalloc(sizeof *k);
757 /** @brief Parse a boolean response
758 * @param cmd Command for use in error messsage
759 * @param value Result from server
760 * @param flagp Where to store result
761 * @return 0 on success, non-0 on error
763 static int boolean(const char *cmd, const char *value,
765 if(!strcmp(value, "yes")) *flagp = 1;
766 else if(!strcmp(value, "no")) *flagp = 0;
768 error(0, "malformed response to '%s'", cmd);
774 /** @brief Test whether a track exists
776 * @param track Track name (UTF-8)
777 * @param existsp Where to store result (non-0 iff does exist)
778 * @return 0 on success, non-0 on error
780 int disorder_exists(disorder_client *c, const char *track, int *existsp) {
784 if((rc = disorder_simple(c, &v, "exists", track, (char *)0)))
786 return boolean("exists", v, existsp);
789 /** @brief Test whether playing is enabled
791 * @param enabledp Where to store result (non-0 iff enabled)
792 * @return 0 on success, non-0 on error
794 int disorder_enabled(disorder_client *c, int *enabledp) {
798 if((rc = disorder_simple(c, &v, "enabled", (char *)0)))
800 return boolean("enabled", v, enabledp);
803 /** @brief Get the length of a track
805 * @param track Track name (UTF-8)
806 * @param valuep Where to store length in seconds
807 * @return 0 on success, non-0 on error
809 * If the length is unknown 0 is returned.
811 int disorder_length(disorder_client *c, const char *track,
816 if((rc = disorder_simple(c, &value, "length", track, (char *)0)))
818 *valuep = atol(value);
822 /** @brief Search for tracks
824 * @param terms Search terms (UTF-8)
825 * @param vecp Where to store list (UTF-8)
826 * @param nvecp Where to store number of items, or NULL
827 * @return 0 on success, non-0 on error
829 int disorder_search(disorder_client *c, const char *terms,
830 char ***vecp, int *nvecp) {
831 return disorder_simple_list(c, vecp, nvecp, "search", terms, (char *)0);
834 /** @brief Enable random play
836 * @return 0 on success, non-0 on error
838 int disorder_random_enable(disorder_client *c) {
839 return disorder_simple(c, 0, "random-enable", (char *)0);
842 /** @brief Disable random play
844 * @return 0 on success, non-0 on error
846 int disorder_random_disable(disorder_client *c) {
847 return disorder_simple(c, 0, "random-disable", (char *)0);
850 /** @brief Test whether random play is enabled
852 * @param existsp Where to store result (non-0 iff enabled)
853 * @return 0 on success, non-0 on error
855 int disorder_random_enabled(disorder_client *c, int *enabledp) {
859 if((rc = disorder_simple(c, &v, "random-enabled", (char *)0)))
861 return boolean("random-enabled", v, enabledp);
864 /** @brief Get server stats
866 * @param vecp Where to store list (UTF-8)
867 * @param nvecp Where to store number of items, or NULL
868 * @return 0 on success, non-0 on error
870 int disorder_stats(disorder_client *c,
871 char ***vecp, int *nvecp) {
872 return disorder_simple_list(c, vecp, nvecp, "stats", (char *)0);
875 /** @brief Set volume
877 * @param left New left channel value
878 * @param right New right channel value
879 * @return 0 on success, non-0 on error
881 int disorder_set_volume(disorder_client *c, int left, int right) {
884 if(byte_asprintf(&ls, "%d", left) < 0
885 || byte_asprintf(&rs, "%d", right) < 0)
887 return disorder_simple(c, 0, "volume", ls, rs, (char *)0);
890 /** @brief Get volume
892 * @param left Where to store left channel value
893 * @param right Where to store right channel value
894 * @return 0 on success, non-0 on error
896 int disorder_get_volume(disorder_client *c, int *left, int *right) {
900 if((rc = disorder_simple(c, &r, "volume", (char *)0)))
902 if(sscanf(r, "%d %d", left, right) != 2) {
903 error(0, "error parsing response to 'volume': '%s'", r);
909 /** @brief Log to a sink
911 * @param s Sink to write log lines to
912 * @return 0 on success, non-0 on error
914 int disorder_log(disorder_client *c, struct sink *s) {
918 if((rc = disorder_simple(c, 0, "log", (char *)0)))
920 while(inputline(c->ident, c->fpin, &l, '\n') >= 0 && strcmp(l, "."))
921 if(sink_printf(s, "%s\n", l) < 0) return -1;
922 if(ferror(c->fpin) || feof(c->fpin)) return -1;
926 /** @brief Look up a track name part
928 * @param partp Where to store result (UTF-8)
929 * @param track Track name (UTF-8)
930 * @param context Context (usually "sort" or "display") (UTF-8)
931 * @param part Track part (UTF-8)
932 * @return 0 on success, non-0 on error
934 int disorder_part(disorder_client *c, char **partp,
935 const char *track, const char *context, const char *part) {
936 return dequote(disorder_simple(c, partp, "part",
937 track, context, part, (char *)0), partp);
940 /** @brief Resolve aliases
942 * @param trackkp Where to store canonical name (UTF-8)
943 * @param track Track name (UTF-8)
944 * @return 0 on success, non-0 on error
946 int disorder_resolve(disorder_client *c, char **trackp, const char *track) {
947 return dequote(disorder_simple(c, trackp, "resolve", track, (char *)0),
951 /** @brief Pause the current track
953 * @return 0 on success, non-0 on error
955 int disorder_pause(disorder_client *c) {
956 return disorder_simple(c, 0, "pause", (char *)0);
959 /** @brief Resume the current track
961 * @return 0 on success, non-0 on error
963 int disorder_resume(disorder_client *c) {
964 return disorder_simple(c, 0, "resume", (char *)0);
967 /** @brief List all known tags
969 * @param vecp Where to store list (UTF-8)
970 * @param nvecp Where to store number of items, or NULL
971 * @return 0 on success, non-0 on error
973 int disorder_tags(disorder_client *c,
974 char ***vecp, int *nvecp) {
975 return disorder_simple_list(c, vecp, nvecp, "tags", (char *)0);
978 /** @brief List all known users
980 * @param vecp Where to store list (UTF-8)
981 * @param nvecp Where to store number of items, or NULL
982 * @return 0 on success, non-0 on error
984 int disorder_users(disorder_client *c,
985 char ***vecp, int *nvecp) {
986 return disorder_simple_list(c, vecp, nvecp, "users", (char *)0);
989 /** @brief Get recently added tracks
991 * @param vecp Where to store pointer to list (UTF-8)
992 * @param nvecp Where to store count
993 * @param max Maximum tracks to fetch, or 0 for all available
994 * @return 0 on success, non-0 on error
996 int disorder_new_tracks(disorder_client *c,
997 char ***vecp, int *nvecp,
1001 sprintf(limit, "%d", max);
1002 return disorder_simple_list(c, vecp, nvecp, "new", limit, (char *)0);
1005 /** @brief Set a global preference
1007 * @param key Preference name (UTF-8)
1008 * @param value Preference value (UTF-8)
1009 * @return 0 on success, non-0 on error
1011 int disorder_set_global(disorder_client *c,
1012 const char *key, const char *value) {
1013 return disorder_simple(c, 0, "set-global", key, value, (char *)0);
1016 /** @brief Unset a global preference
1018 * @param key Preference name (UTF-8)
1019 * @return 0 on success, non-0 on error
1021 int disorder_unset_global(disorder_client *c, const char *key) {
1022 return disorder_simple(c, 0, "unset-global", key, (char *)0);
1025 /** @brief Get a global preference
1027 * @param key Preference name (UTF-8)
1028 * @param valuep Where to store preference value (UTF-8)
1029 * @return 0 on success, non-0 on error
1031 int disorder_get_global(disorder_client *c, const char *key, char **valuep) {
1032 return dequote(disorder_simple(c, valuep, "get-global", key, (char *)0),
1036 /** @brief Get server's RTP address information
1038 * @param addressp Where to store address (UTF-8)
1039 * @param portp Where to store port (UTF-8)
1040 * @return 0 on success, non-0 on error
1042 int disorder_rtp_address(disorder_client *c, char **addressp, char **portp) {
1047 if((rc = disorder_simple(c, &r, "rtp-address", (char *)0)))
1049 vec = split(r, &n, SPLIT_QUOTES, 0, 0);
1051 error(0, "malformed rtp-address reply");
1059 /** @brief Create a user
1061 * @param user Username
1062 * @param password Password
1063 * @param rights Initial rights or NULL to use default
1064 * @return 0 on success, non-0 on error
1066 int disorder_adduser(disorder_client *c,
1067 const char *user, const char *password,
1068 const char *rights) {
1069 return disorder_simple(c, 0, "adduser", user, password, rights, (char *)0);
1072 /** @brief Delete a user
1074 * @param user Username
1075 * @return 0 on success, non-0 on error
1077 int disorder_deluser(disorder_client *c, const char *user) {
1078 return disorder_simple(c, 0, "deluser", user, (char *)0);
1081 /** @brief Get user information
1083 * @param user Username
1084 * @param key Property name (UTF-8)
1085 * @param valuep Where to store value (UTF-8)
1086 * @return 0 on success, non-0 on error
1088 int disorder_userinfo(disorder_client *c, const char *user, const char *key,
1090 return dequote(disorder_simple(c, valuep, "userinfo", user, key, (char *)0),
1094 /** @brief Set user information
1096 * @param user Username
1097 * @param key Property name (UTF-8)
1098 * @param value New property value (UTF-8)
1099 * @return 0 on success, non-0 on error
1101 int disorder_edituser(disorder_client *c, const char *user,
1102 const char *key, const char *value) {
1103 return disorder_simple(c, 0, "edituser", user, key, value, (char *)0);
1106 /** @brief Register a user
1108 * @param user Username
1109 * @param password Password
1110 * @param email Email address (UTF-8)
1111 * @param rights Initial rights or NULL to use default
1112 * @param confirmp Where to store confirmation string
1113 * @return 0 on success, non-0 on error
1115 int disorder_register(disorder_client *c, const char *user,
1116 const char *password, const char *email,
1118 return dequote(disorder_simple(c, confirmp, "register",
1119 user, password, email, (char *)0),
1123 /** @brief Confirm a user
1125 * @param confirm Confirmation string
1126 * @return 0 on success, non-0 on error
1128 int disorder_confirm(disorder_client *c, const char *confirm) {
1129 return disorder_simple(c, 0, "confirm", confirm, (char *)0);
1132 /** @brief Make a cookie for this login
1134 * @param cookiep Where to store cookie string
1135 * @return 0 on success, non-0 on error
1137 int disorder_make_cookie(disorder_client *c, char **cookiep) {
1138 return dequote(disorder_simple(c, cookiep, "make-cookie", (char *)0),