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 static int disorder_connect_sock(disorder_client *c,
70 const struct sockaddr *sa,
76 /** @brief Create a new client
77 * @param verbose If nonzero, write extra junk to stderr
78 * @return Pointer to new client
80 * You must call disorder_connect() to connect it. Use
81 * disorder_close() to dispose of the client when finished with it.
83 disorder_client *disorder_new(int verbose) {
84 disorder_client *c = xmalloc(sizeof (struct disorder_client));
90 /** @brief Read a response line
92 * @param rp Where to store response, or NULL (UTF-8)
93 * @return Response code 0-999 or -1 on error
95 static int response(disorder_client *c, char **rp) {
98 if(inputline(c->ident, c->fpin, &r, '\n'))
100 D(("response: %s", r));
103 if(r[0] >= '0' && r[0] <= '9'
104 && r[1] >= '0' && r[1] <= '9'
105 && r[2] >= '0' && r[2] <= '9'
107 return (r[0] * 10 + r[1]) * 10 + r[2] - 111 * '0';
109 error(0, "invalid reply format from %s", c->ident);
114 /** @brief Read and partially parse a response
116 * @param rp Where to store response text (or NULL) (UTF-8)
117 * @return 0 on success, non-0 on error
119 * 5xx responses count as errors.
121 * @p rp will NOT be filled in for xx9 responses (where it is just
122 * commentary for a command where it would normally be meaningful).
124 * NB that the response will NOT be converted to the local encoding.
126 static int check_response(disorder_client *c, char **rp) {
130 if((rc = response(c, &r)) == -1)
132 else if(rc / 100 == 2) {
134 *rp = (rc % 10 == 9) ? 0 : xstrdup(r + 4);
138 error(0, "from %s: %s", c->ident, utf82mb(r));
143 /** @brief Issue a command and parse a simple response
145 * @param rp Where to store result, or NULL
147 * @param ap Arguments (UTF-8), terminated by (char *)0
148 * @return 0 on success, non-0 on error
150 * 5xx responses count as errors.
152 * @p rp will NOT be filled in for xx9 responses (where it is just
153 * commentary for a command where it would normally be meaningful).
155 * NB that the response will NOT be converted to the local encoding
156 * nor will quotes be stripped. See dequote().
158 static int disorder_simple_v(disorder_client *c,
160 const char *cmd, va_list ap) {
166 dynstr_append_string(&d, cmd);
167 while((arg = va_arg(ap, const char *))) {
168 dynstr_append(&d, ' ');
169 dynstr_append_string(&d, quoteutf8(arg));
171 dynstr_append(&d, '\n');
172 dynstr_terminate(&d);
173 D(("command: %s", d.vec));
174 if(fputs(d.vec, c->fpout) < 0 || fflush(c->fpout)) {
175 error(errno, "error writing to %s", c->ident);
179 return check_response(c, rp);
182 /** @brief Issue a command and parse a simple response
184 * @param rp Where to store result, or NULL (UTF-8)
186 * @return 0 on success, non-0 on error
188 * The remaining arguments are command arguments, terminated by (char
189 * *)0. They should be in UTF-8.
191 * 5xx responses count as errors.
193 * @p rp will NOT be filled in for xx9 responses (where it is just
194 * commentary for a command where it would normally be meaningful).
196 * NB that the response will NOT be converted to the local encoding
197 * nor will quotes be stripped. See dequote().
199 static int disorder_simple(disorder_client *c,
201 const char *cmd, ...) {
206 ret = disorder_simple_v(c, rp, cmd, ap);
211 static int connect_sock(void *vc,
212 const struct sockaddr *sa,
215 const char *username, *password;
216 disorder_client *c = vc;
218 if(!(username = config->username)) {
219 error(0, "no username configured");
222 password = config->password;
224 /* Maybe we can read the database */
225 /* TODO failure to open the database should not be fatal */
226 trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE);
227 trackdb_open(TRACKDB_READ_ONLY);
228 password = trackdb_get_password(username);
233 error(0, "no password configured");
236 return disorder_connect_sock(c, sa, len, username, password, ident);
239 /** @brief Connect a client
241 * @return 0 on success, non-0 on error
243 * The connection will use the username and password found in @ref
246 int disorder_connect(disorder_client *c) {
247 return with_sockaddr(c, connect_sock);
250 static int disorder_connect_sock(disorder_client *c,
251 const struct sockaddr *sa,
253 const char *username,
254 const char *password,
256 int fd = -1, fd2 = -1, nrvec;
257 unsigned char *nonce;
261 const char *protocol, *algorithm, *challenge;
264 error(0, "no password found");
267 c->fpin = c->fpout = 0;
268 if((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
269 error(errno, "error calling socket");
272 if(connect(fd, sa, len) < 0) {
273 error(errno, "error calling connect");
276 if((fd2 = dup(fd)) < 0) {
277 error(errno, "error calling dup");
280 if(!(c->fpin = fdopen(fd, "rb"))) {
281 error(errno, "error calling fdopen");
285 if(!(c->fpout = fdopen(fd2, "wb"))) {
286 error(errno, "error calling fdopen");
290 c->ident = xstrdup(ident);
291 if(disorder_simple(c, &r, 0, (const char *)0))
293 if(!(rvec = split(r, &nrvec, SPLIT_QUOTES, 0, 0)))
296 error(0, "cannot parse server greeting %s", r);
300 if(strcmp(protocol, "2")) {
301 error(0, "unknown protocol version: %s", protocol);
306 if(!(nonce = unhex(challenge, &nl)))
308 if(!(res = authhash(nonce, nl, password, algorithm))) goto error;
309 if(disorder_simple(c, 0, "user", username, res, (char *)0))
311 c->user = xstrdup(username);
314 if(c->fpin) fclose(c->fpin);
315 if(c->fpout) fclose(c->fpout);
316 if(fd2 != -1) close(fd2);
317 if(fd != -1) close(fd);
321 /** @brief Close a client
323 * @return 0 on succcess, non-0 on errior
325 * The client is still closed even on error. It might well be
326 * appropriate to ignore the return value.
328 int disorder_close(disorder_client *c) {
332 if(fclose(c->fpin) < 0) {
333 error(errno, "error calling fclose");
339 if(fclose(c->fpout) < 0) {
340 error(errno, "error calling fclose");
348 int disorder_become(disorder_client *c, const char *user) {
349 if(disorder_simple(c, 0, "become", user, (char *)0)) return -1;
350 c->user = xstrdup(user);
354 /** @brief Play a track
356 * @param track Track to play (UTF-8)
357 * @return 0 on success, non-0 on error
359 int disorder_play(disorder_client *c, const char *track) {
360 return disorder_simple(c, 0, "play", track, (char *)0);
363 /** @brief Remove a track
365 * @param track Track to remove (UTF-8)
366 * @return 0 on success, non-0 on error
368 int disorder_remove(disorder_client *c, const char *track) {
369 return disorder_simple(c, 0, "remove", track, (char *)0);
372 /** @brief Move a track
374 * @param track Track to move (UTF-8)
375 * @param delta Distance to move by
376 * @return 0 on success, non-0 on error
378 int disorder_move(disorder_client *c, const char *track, int delta) {
381 byte_snprintf(d, sizeof d, "%d", delta);
382 return disorder_simple(c, 0, "move", track, d, (char *)0);
385 /** @brief Enable play
387 * @return 0 on success, non-0 on error
389 int disorder_enable(disorder_client *c) {
390 return disorder_simple(c, 0, "enable", (char *)0);
393 /** @brief Disable play
395 * @return 0 on success, non-0 on error
397 int disorder_disable(disorder_client *c) {
398 return disorder_simple(c, 0, "disable", (char *)0);
401 /** @brief Scratch the currently playing track
402 * @param id Playing track ID or NULL (UTF-8)
404 * @return 0 on success, non-0 on error
406 int disorder_scratch(disorder_client *c, const char *id) {
407 return disorder_simple(c, 0, "scratch", id, (char *)0);
410 /** @brief Shut down the server
412 * @return 0 on success, non-0 on error
414 int disorder_shutdown(disorder_client *c) {
415 return disorder_simple(c, 0, "shutdown", (char *)0);
418 /** @brief Make the server re-read its configuration
420 * @return 0 on success, non-0 on error
422 int disorder_reconfigure(disorder_client *c) {
423 return disorder_simple(c, 0, "reconfigure", (char *)0);
426 /** @brief Rescan tracks
428 * @return 0 on success, non-0 on error
430 int disorder_rescan(disorder_client *c) {
431 return disorder_simple(c, 0, "rescan", (char *)0);
434 /** @brief Dequote a result string
435 * @param rc 0 on success, non-0 on error
436 * @param rp Where result string is stored (UTF-8)
439 * This is used as a wrapper around disorder_simple() to dequote
442 static int dequote(int rc, char **rp) {
445 if((rr = split(*rp, 0, SPLIT_QUOTES, 0, 0)) && *rr) {
449 error(0, "invalid reply: %s", *rp);
454 /** @brief Get server version number
456 * @param rp Where to store version string (UTF-8)
457 * @return 0 on success, non-0 on error
459 int disorder_version(disorder_client *c, char **rp) {
460 return dequote(disorder_simple(c, rp, "version", (char *)0), rp);
463 static void client_error(const char *msg,
464 void attribute((unused)) *u) {
465 error(0, "error parsing reply: %s", msg);
468 /** @brief Get currently playing track
470 * @param qp Where to store track information
471 * @return 0 on success, non-0 on error
473 * @p qp gets NULL if no track is playing.
475 int disorder_playing(disorder_client *c, struct queue_entry **qp) {
477 struct queue_entry *q;
479 if(disorder_simple(c, &r, "playing", (char *)0))
482 q = xmalloc(sizeof *q);
483 if(queue_unmarshall(q, r, client_error, 0))
491 static int disorder_somequeue(disorder_client *c,
492 const char *cmd, struct queue_entry **qp) {
493 struct queue_entry *qh, **qt = &qh, *q;
496 if(disorder_simple(c, 0, cmd, (char *)0))
498 while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
499 if(!strcmp(l, ".")) {
504 q = xmalloc(sizeof *q);
505 if(!queue_unmarshall(q, l, client_error, 0)) {
511 error(errno, "error reading %s", c->ident);
513 error(0, "error reading %s: unexpected EOF", c->ident);
517 /** @brief Get recently played tracks
519 * @param qp Where to store track information
520 * @return 0 on success, non-0 on error
522 * The last entry in the list is the most recently played track.
524 int disorder_recent(disorder_client *c, struct queue_entry **qp) {
525 return disorder_somequeue(c, "recent", qp);
530 * @param qp Where to store track information
531 * @return 0 on success, non-0 on error
533 * The first entry in the list will be played next.
535 int disorder_queue(disorder_client *c, struct queue_entry **qp) {
536 return disorder_somequeue(c, "queue", qp);
539 /** @brief Read a dot-stuffed list
541 * @param vecp Where to store list (UTF-8)
542 * @param nvecp Where to store number of items, or NULL
543 * @return 0 on success, non-0 on error
545 * The list will have a final NULL not counted in @p nvecp.
547 static int readlist(disorder_client *c, char ***vecp, int *nvecp) {
552 while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
553 if(!strcmp(l, ".")) {
554 vector_terminate(&v);
560 vector_append(&v, l + (*l == '.'));
563 error(errno, "error reading %s", c->ident);
565 error(0, "error reading %s: unexpected EOF", c->ident);
569 /** @brief Issue a comamnd and get a list response
571 * @param vecp Where to store list (UTF-8)
572 * @param nvecp Where to store number of items, or NULL
574 * @return 0 on success, non-0 on error
576 * The remaining arguments are command arguments, terminated by (char
577 * *)0. They should be in UTF-8.
579 * 5xx responses count as errors.
581 static int disorder_simple_list(disorder_client *c,
582 char ***vecp, int *nvecp,
583 const char *cmd, ...) {
588 ret = disorder_simple_v(c, 0, cmd, ap);
591 return readlist(c, vecp, nvecp);
594 /** @brief List directories below @p dir
596 * @param dir Directory to list (UTF-8)
597 * @param re Regexp that results must match, or NULL (UTF-8)
598 * @param vecp Where to store list (UTF-8)
599 * @param nvecp Where to store number of items, or NULL
600 * @return 0 on success, non-0 on error
602 int disorder_directories(disorder_client *c, const char *dir, const char *re,
603 char ***vecp, int *nvecp) {
604 return disorder_simple_list(c, vecp, nvecp, "dirs", dir, re, (char *)0);
607 /** @brief List files below @p dir
609 * @param dir Directory to list (UTF-8)
610 * @param re Regexp that results must match, or NULL (UTF-8)
611 * @param vecp Where to store list (UTF-8)
612 * @param nvecp Where to store number of items, or NULL
613 * @return 0 on success, non-0 on error
615 int disorder_files(disorder_client *c, const char *dir, const char *re,
616 char ***vecp, int *nvecp) {
617 return disorder_simple_list(c, vecp, nvecp, "files", dir, re, (char *)0);
620 /** @brief List files and directories below @p dir
622 * @param dir Directory to list (UTF-8)
623 * @param re Regexp that results must match, or NULL (UTF-8)
624 * @param vecp Where to store list (UTF-8)
625 * @param nvecp Where to store number of items, or NULL
626 * @return 0 on success, non-0 on error
628 int disorder_allfiles(disorder_client *c, const char *dir, const char *re,
629 char ***vecp, int *nvecp) {
630 return disorder_simple_list(c, vecp, nvecp, "allfiles", dir, re, (char *)0);
633 /** @brief Return the user we logged in with
635 * @return User name (owned by @p c, don't modify)
637 char *disorder_user(disorder_client *c) {
641 /** @brief Set a track preference
643 * @param track Track name (UTF-8)
644 * @param key Preference name (UTF-8)
645 * @param value Preference value (UTF-8)
646 * @return 0 on success, non-0 on error
648 int disorder_set(disorder_client *c, const char *track,
649 const char *key, const char *value) {
650 return disorder_simple(c, 0, "set", track, key, value, (char *)0);
653 /** @brief Unset a track preference
655 * @param track Track name (UTF-8)
656 * @param key Preference name (UTF-8)
657 * @return 0 on success, non-0 on error
659 int disorder_unset(disorder_client *c, const char *track,
661 return disorder_simple(c, 0, "unset", track, key, (char *)0);
664 /** @brief Get a track preference
666 * @param track Track name (UTF-8)
667 * @param key Preference name (UTF-8)
668 * @param valuep Where to store preference value (UTF-8)
669 * @return 0 on success, non-0 on error
671 int disorder_get(disorder_client *c,
672 const char *track, const char *key, char **valuep) {
673 return dequote(disorder_simple(c, valuep, "get", track, key, (char *)0),
677 static void pref_error_handler(const char *msg,
678 void attribute((unused)) *u) {
679 error(0, "error handling 'prefs' reply: %s", msg);
682 /** @param Get all preferences for a trcak
684 * @param track Track name
685 * @param kp Where to store linked list of preferences
686 * @return 0 on success, non-0 on error
688 int disorder_prefs(disorder_client *c, const char *track, struct kvp **kp) {
693 if(disorder_simple_list(c, &vec, &nvec, "prefs", track, (char *)0))
695 for(n = 0; n < nvec; ++n) {
696 if(!(pvec = split(vec[n], &npvec, SPLIT_QUOTES, pref_error_handler, 0)))
699 pref_error_handler("malformed response", 0);
702 *kp = k = xmalloc(sizeof *k);
711 /** @brief Parse a boolean response
712 * @param cmd Command for use in error messsage
713 * @param value Result from server
714 * @param flagp Where to store result
715 * @return 0 on success, non-0 on error
717 static int boolean(const char *cmd, const char *value,
719 if(!strcmp(value, "yes")) *flagp = 1;
720 else if(!strcmp(value, "no")) *flagp = 0;
722 error(0, "malformed response to '%s'", cmd);
728 /** @brief Test whether a track exists
730 * @param track Track name (UTF-8)
731 * @param existsp Where to store result (non-0 iff does exist)
732 * @return 0 on success, non-0 on error
734 int disorder_exists(disorder_client *c, const char *track, int *existsp) {
737 if(disorder_simple(c, &v, "exists", track, (char *)0)) return -1;
738 return boolean("exists", v, existsp);
741 /** @brief Test whether playing is enabled
743 * @param enabledp Where to store result (non-0 iff enabled)
744 * @return 0 on success, non-0 on error
746 int disorder_enabled(disorder_client *c, int *enabledp) {
749 if(disorder_simple(c, &v, "enabled", (char *)0)) return -1;
750 return boolean("enabled", v, enabledp);
753 /** @brief Get the length of a track
755 * @param track Track name (UTF-8)
756 * @param valuep Where to store length in seconds
757 * @return 0 on success, non-0 on error
759 * If the length is unknown 0 is returned.
761 int disorder_length(disorder_client *c, const char *track,
765 if(disorder_simple(c, &value, "length", track, (char *)0)) return -1;
766 *valuep = atol(value);
770 /** @brief Search for tracks
772 * @param terms Search terms (UTF-8)
773 * @param vecp Where to store list (UTF-8)
774 * @param nvecp Where to store number of items, or NULL
775 * @return 0 on success, non-0 on error
777 int disorder_search(disorder_client *c, const char *terms,
778 char ***vecp, int *nvecp) {
779 return disorder_simple_list(c, vecp, nvecp, "search", terms, (char *)0);
782 /** @brief Enable random play
784 * @return 0 on success, non-0 on error
786 int disorder_random_enable(disorder_client *c) {
787 return disorder_simple(c, 0, "random-enable", (char *)0);
790 /** @brief Disable random play
792 * @return 0 on success, non-0 on error
794 int disorder_random_disable(disorder_client *c) {
795 return disorder_simple(c, 0, "random-disable", (char *)0);
798 /** @brief Test whether random play is enabled
800 * @param existsp Where to store result (non-0 iff enabled)
801 * @return 0 on success, non-0 on error
803 int disorder_random_enabled(disorder_client *c, int *enabledp) {
806 if(disorder_simple(c, &v, "random-enabled", (char *)0)) return -1;
807 return boolean("random-enabled", v, enabledp);
810 /** @brief Get server stats
812 * @param vecp Where to store list (UTF-8)
813 * @param nvecp Where to store number of items, or NULL
814 * @return 0 on success, non-0 on error
816 int disorder_stats(disorder_client *c,
817 char ***vecp, int *nvecp) {
818 return disorder_simple_list(c, vecp, nvecp, "stats", (char *)0);
821 /** @brief Set volume
823 * @param left New left channel value
824 * @param right New right channel value
825 * @return 0 on success, non-0 on error
827 int disorder_set_volume(disorder_client *c, int left, int right) {
830 if(byte_asprintf(&ls, "%d", left) < 0
831 || byte_asprintf(&rs, "%d", right) < 0)
833 if(disorder_simple(c, 0, "volume", ls, rs, (char *)0)) return -1;
837 /** @brief Get volume
839 * @param left Where to store left channel value
840 * @param right Where to store right channel value
841 * @return 0 on success, non-0 on error
843 int disorder_get_volume(disorder_client *c, int *left, int *right) {
846 if(disorder_simple(c, &r, "volume", (char *)0)) return -1;
847 if(sscanf(r, "%d %d", left, right) != 2) {
848 error(0, "error parsing response to 'volume': '%s'", r);
854 /** @brief Log to a sink
856 * @param s Sink to write log lines to
857 * @return 0 on success, non-0 on error
859 int disorder_log(disorder_client *c, struct sink *s) {
862 if(disorder_simple(c, 0, "log", (char *)0)) return -1;
863 while(inputline(c->ident, c->fpin, &l, '\n') >= 0 && strcmp(l, "."))
864 if(sink_printf(s, "%s\n", l) < 0) return -1;
865 if(ferror(c->fpin) || feof(c->fpin)) return -1;
869 /** @brief Look up a track name part
871 * @param partp Where to store result (UTF-8)
872 * @param track Track name (UTF-8)
873 * @param context Context (usually "sort" or "display") (UTF-8)
874 * @param part Track part (UTF-8)
875 * @return 0 on success, non-0 on error
877 int disorder_part(disorder_client *c, char **partp,
878 const char *track, const char *context, const char *part) {
879 return dequote(disorder_simple(c, partp, "part",
880 track, context, part, (char *)0), partp);
883 /** @brief Resolve aliases
885 * @param trackkp Where to store canonical name (UTF-8)
886 * @param track Track name (UTF-8)
887 * @return 0 on success, non-0 on error
889 int disorder_resolve(disorder_client *c, char **trackp, const char *track) {
890 return dequote(disorder_simple(c, trackp, "resolve", track, (char *)0),
894 /** @brief Pause the current track
896 * @return 0 on success, non-0 on error
898 int disorder_pause(disorder_client *c) {
899 return disorder_simple(c, 0, "pause", (char *)0);
902 /** @brief Resume the current track
904 * @return 0 on success, non-0 on error
906 int disorder_resume(disorder_client *c) {
907 return disorder_simple(c, 0, "resume", (char *)0);
910 /** @brief List all known tags
912 * @param vecp Where to store list (UTF-8)
913 * @param nvecp Where to store number of items, or NULL
914 * @return 0 on success, non-0 on error
916 int disorder_tags(disorder_client *c,
917 char ***vecp, int *nvecp) {
918 return disorder_simple_list(c, vecp, nvecp, "tags", (char *)0);
921 /** @brief List all known users
923 * @param vecp Where to store list (UTF-8)
924 * @param nvecp Where to store number of items, or NULL
925 * @return 0 on success, non-0 on error
927 int disorder_users(disorder_client *c,
928 char ***vecp, int *nvecp) {
929 return disorder_simple_list(c, vecp, nvecp, "users", (char *)0);
932 /** @brief Get recently added tracks
934 * @param vecp Where to store pointer to list (UTF-8)
935 * @param nvecp Where to store count
936 * @param max Maximum tracks to fetch, or 0 for all available
937 * @return 0 on success, non-0 on error
939 int disorder_new_tracks(disorder_client *c,
940 char ***vecp, int *nvecp,
944 sprintf(limit, "%d", max);
945 return disorder_simple_list(c, vecp, nvecp, "new", limit, (char *)0);
948 /** @brief Set a global preference
950 * @param key Preference name (UTF-8)
951 * @param value Preference value (UTF-8)
952 * @return 0 on success, non-0 on error
954 int disorder_set_global(disorder_client *c,
955 const char *key, const char *value) {
956 return disorder_simple(c, 0, "set-global", key, value, (char *)0);
959 /** @brief Unset a global preference
961 * @param key Preference name (UTF-8)
962 * @return 0 on success, non-0 on error
964 int disorder_unset_global(disorder_client *c, const char *key) {
965 return disorder_simple(c, 0, "unset-global", key, (char *)0);
968 /** @brief Get a global preference
970 * @param key Preference name (UTF-8)
971 * @param valuep Where to store preference value (UTF-8)
972 * @return 0 on success, non-0 on error
974 int disorder_get_global(disorder_client *c, const char *key, char **valuep) {
975 return dequote(disorder_simple(c, valuep, "get-global", key, (char *)0),
979 /** @brief Get server's RTP address information
981 * @param addressp Where to store address (UTF-8)
982 * @param portp Where to store port (UTF-8)
983 * @return 0 on success, non-0 on error
985 int disorder_rtp_address(disorder_client *c, char **addressp, char **portp) {
990 if((rc = disorder_simple(c, &r, "rtp-address", (char *)0)))
992 vec = split(r, &n, SPLIT_QUOTES, 0, 0);
994 error(0, "malformed rtp-address reply");
1002 /** @brief Create a user
1004 * @param user Username
1005 * @param password Password
1006 * @param rights Initial rights or NULL to use default
1007 * @return 0 on success, non-0 on error
1009 int disorder_adduser(disorder_client *c,
1010 const char *user, const char *password,
1011 const char *rights) {
1012 return disorder_simple(c, 0, "adduser", user, password, rights, (char *)0);
1015 /** @brief Delete a user
1017 * @param user Username
1018 * @return 0 on success, non-0 on error
1020 int disorder_deluser(disorder_client *c, const char *user) {
1021 return disorder_simple(c, 0, "deluser", user, (char *)0);
1024 /** @brief Get user information
1026 * @param user Username
1027 * @param key Property name (UTF-8)
1028 * @param valuep Where to store value (UTF-8)
1029 * @return 0 on success, non-0 on error
1031 int disorder_userinfo(disorder_client *c, const char *user, const char *key,
1033 return dequote(disorder_simple(c, valuep, "userinfo", user, key, (char *)0),
1037 /** @brief Set user information
1039 * @param user Username
1040 * @param key Property name (UTF-8)
1041 * @param value New property value (UTF-8)
1042 * @return 0 on success, non-0 on error
1044 int disorder_edituser(disorder_client *c, const char *user,
1045 const char *key, const char *value) {
1046 return disorder_simple(c, 0, "edituser", user, key, value, (char *)0);
1049 /** @brief Register a user
1051 * @param user Username
1052 * @param password Password
1053 * @param email Email address (UTF-8)
1054 * @param rights Initial rights or NULL to use default
1055 * @param confirmp Where to store confirmation string
1056 * @return 0 on success, non-0 on error
1058 int disorder_register(disorder_client *c, const char *user,
1059 const char *password, const char *email,
1061 return dequote(disorder_simple(c, confirmp, "register",
1062 user, password, email, (char *)0),
1066 /** @brief Confirm a user
1068 * @param confirm Confirmation string
1069 * @return 0 on success, non-0 on error
1071 int disorder_confirm(disorder_client *c, const char *confirm) {
1072 return disorder_simple(c, 0, "confirm", confirm, (char *)0);
1075 /** @brief Make a cookie for this login
1077 * @param cookiep Where to store cookie string
1078 * @return 0 on success, non-0 on error
1080 int disorder_make_cookie(disorder_client *c, char **cookiep) {
1081 return dequote(disorder_simple(c, cookiep, "make-cookie", (char *)0),