Commit | Line | Data |
---|---|---|
460b9539 | 1 | /* |
2 | * This file is part of DisOrder. | |
1020001c | 3 | * Copyright (C) 2004, 2005, 2006, 2007 Richard Kettlewell |
460b9539 | 4 | * |
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. | |
9 | * | |
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. | |
14 | * | |
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 | |
18 | * USA | |
19 | */ | |
20 | ||
21 | #include <config.h> | |
22 | #include "types.h" | |
23 | ||
24 | #include <sys/types.h> | |
25 | #include <sys/socket.h> | |
26 | #include <netinet/in.h> | |
27 | #include <sys/un.h> | |
28 | #include <string.h> | |
29 | #include <stdio.h> | |
30 | #include <unistd.h> | |
31 | #include <errno.h> | |
32 | #include <netdb.h> | |
33 | #include <stdlib.h> | |
f0feb22e | 34 | #include <pcre.h> |
460b9539 | 35 | |
36 | #include "log.h" | |
37 | #include "mem.h" | |
38 | #include "configuration.h" | |
39 | #include "queue.h" | |
40 | #include "client.h" | |
41 | #include "charset.h" | |
42 | #include "hex.h" | |
43 | #include "split.h" | |
44 | #include "vector.h" | |
45 | #include "inputline.h" | |
46 | #include "kvp.h" | |
47 | #include "syscalls.h" | |
48 | #include "printf.h" | |
49 | #include "sink.h" | |
50 | #include "addr.h" | |
51 | #include "authhash.h" | |
52 | #include "client-common.h" | |
5df73aeb | 53 | #include "rights.h" |
f0feb22e | 54 | #include "trackdb.h" |
460b9539 | 55 | |
56 | struct disorder_client { | |
57 | FILE *fpin, *fpout; | |
58 | char *ident; | |
59 | char *user; | |
60 | int verbose; | |
61 | }; | |
62 | ||
63 | disorder_client *disorder_new(int verbose) { | |
64 | disorder_client *c = xmalloc(sizeof (struct disorder_client)); | |
65 | ||
66 | c->verbose = verbose; | |
67 | return c; | |
68 | } | |
69 | ||
70 | /* read a response line. | |
71 | * If @rp@ is not a null pointer, returns the whole response through it. | |
72 | * Return value is the response code, or -1 on error. */ | |
73 | static int response(disorder_client *c, char **rp) { | |
74 | char *r; | |
75 | ||
76 | if(inputline(c->ident, c->fpin, &r, '\n')) | |
77 | return -1; | |
78 | D(("response: %s", r)); | |
79 | if(rp) | |
80 | *rp = r; | |
81 | if(r[0] >= '0' && r[0] <= '9' | |
82 | && r[1] >= '0' && r[1] <= '9' | |
83 | && r[2] >= '0' && r[2] <= '9' | |
84 | && r[3] == ' ') | |
85 | return (r[0] * 10 + r[1]) * 10 + r[2] - 111 * '0'; | |
86 | else { | |
87 | error(0, "invalid reply format from %s", c->ident); | |
88 | return -1; | |
89 | } | |
90 | } | |
91 | ||
92 | /* Read a response. | |
93 | * If @rp@ is not a null pointer then the response text (excluding | |
94 | * the status code) is returned through it, UNLESS the response code | |
95 | * is xx9. | |
96 | * Return value is 0 for 2xx responses and -1 otherwise. | |
97 | */ | |
98 | static int check_response(disorder_client *c, char **rp) { | |
99 | int rc; | |
100 | char *r; | |
101 | ||
102 | if((rc = response(c, &r)) == -1) | |
103 | return -1; | |
104 | else if(rc / 100 == 2) { | |
105 | if(rp) | |
106 | *rp = (rc % 10 == 9) ? 0 : xstrdup(r + 4); | |
107 | return 0; | |
108 | } else { | |
109 | if(c->verbose) | |
110 | error(0, "from %s: %s", c->ident, utf82mb(r)); | |
111 | return -1; | |
112 | } | |
113 | } | |
114 | ||
115 | static int disorder_simple_v(disorder_client *c, | |
116 | char **rp, | |
117 | const char *cmd, va_list ap) { | |
118 | const char *arg; | |
119 | struct dynstr d; | |
120 | ||
121 | if(cmd) { | |
122 | dynstr_init(&d); | |
123 | dynstr_append_string(&d, cmd); | |
124 | while((arg = va_arg(ap, const char *))) { | |
125 | dynstr_append(&d, ' '); | |
126 | dynstr_append_string(&d, quoteutf8(arg)); | |
127 | } | |
128 | dynstr_append(&d, '\n'); | |
129 | dynstr_terminate(&d); | |
130 | D(("command: %s", d.vec)); | |
131 | if(fputs(d.vec, c->fpout) < 0 || fflush(c->fpout)) { | |
132 | error(errno, "error writing to %s", c->ident); | |
133 | return -1; | |
134 | } | |
135 | } | |
136 | return check_response(c, rp); | |
137 | } | |
138 | ||
139 | /* Execute a simple command with any number of arguments. | |
140 | * @rp@ and return value as for check_response(). | |
141 | */ | |
142 | static int disorder_simple(disorder_client *c, | |
143 | char **rp, | |
144 | const char *cmd, ...) { | |
145 | va_list ap; | |
146 | int ret; | |
147 | ||
148 | va_start(ap, cmd); | |
149 | ret = disorder_simple_v(c, rp, cmd, ap); | |
150 | va_end(ap); | |
151 | return ret; | |
152 | } | |
153 | ||
154 | static int connect_sock(void *vc, | |
155 | const struct sockaddr *sa, | |
156 | socklen_t len, | |
157 | const char *ident) { | |
158 | const char *username, *password; | |
159 | disorder_client *c = vc; | |
460b9539 | 160 | |
161 | if(!(username = config->username)) { | |
162 | error(0, "no username configured"); | |
163 | return -1; | |
164 | } | |
f0feb22e RK |
165 | password = config->password; |
166 | if(!password) { | |
167 | /* Maybe we can read the database */ | |
168 | /* TODO failure to open the database should not be fatal */ | |
169 | trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE); | |
170 | trackdb_open(TRACKDB_READ_ONLY); | |
171 | password = trackdb_get_password(username); | |
172 | trackdb_close(); | |
173 | } | |
174 | if(!password) { | |
175 | /* Oh well */ | |
176 | error(0, "no password configured"); | |
177 | return -1; | |
460b9539 | 178 | } |
179 | return disorder_connect_sock(c, sa, len, username, password, ident); | |
180 | } | |
181 | ||
182 | int disorder_connect(disorder_client *c) { | |
183 | return with_sockaddr(c, connect_sock); | |
184 | } | |
185 | ||
186 | static int check_running(void attribute((unused)) *c, | |
187 | const struct sockaddr *sa, | |
188 | socklen_t len, | |
189 | const char attribute((unused)) *ident) { | |
190 | int fd, ret; | |
191 | ||
192 | if((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) | |
193 | fatal(errno, "error calling socket"); | |
194 | if(connect(fd, sa, len) < 0) { | |
195 | if(errno == ECONNREFUSED || errno == ENOENT) | |
196 | ret = 0; | |
197 | else | |
198 | fatal(errno, "error calling connect"); | |
199 | } else | |
200 | ret = 1; | |
201 | xclose(fd); | |
202 | return ret; | |
203 | } | |
204 | ||
205 | int disorder_running(disorder_client *c) { | |
206 | return with_sockaddr(c, check_running); | |
207 | } | |
208 | ||
209 | int disorder_connect_sock(disorder_client *c, | |
210 | const struct sockaddr *sa, | |
211 | socklen_t len, | |
212 | const char *username, | |
213 | const char *password, | |
214 | const char *ident) { | |
637fdea3 | 215 | int fd = -1, fd2 = -1, nrvec; |
460b9539 | 216 | unsigned char *nonce; |
217 | size_t nl; | |
218 | const char *res; | |
637fdea3 RK |
219 | char *r, **rvec; |
220 | const char *algo = "SHA1"; | |
460b9539 | 221 | |
222 | if(!password) { | |
223 | error(0, "no password found"); | |
224 | return -1; | |
225 | } | |
226 | c->fpin = c->fpout = 0; | |
227 | if((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) { | |
228 | error(errno, "error calling socket"); | |
229 | return -1; | |
230 | } | |
231 | if(connect(fd, sa, len) < 0) { | |
232 | error(errno, "error calling connect"); | |
233 | goto error; | |
234 | } | |
235 | if((fd2 = dup(fd)) < 0) { | |
236 | error(errno, "error calling dup"); | |
237 | goto error; | |
238 | } | |
239 | if(!(c->fpin = fdopen(fd, "rb"))) { | |
240 | error(errno, "error calling fdopen"); | |
241 | goto error; | |
242 | } | |
243 | fd = -1; | |
244 | if(!(c->fpout = fdopen(fd2, "wb"))) { | |
245 | error(errno, "error calling fdopen"); | |
246 | goto error; | |
247 | } | |
248 | fd2 = -1; | |
249 | c->ident = xstrdup(ident); | |
250 | if(disorder_simple(c, &r, 0, (const char *)0)) | |
251 | return -1; | |
637fdea3 RK |
252 | if(!(rvec = split(r, &nrvec, SPLIT_QUOTES, 0, 0))) |
253 | return -1; | |
254 | if(nrvec > 1) { | |
255 | algo = *rvec++; | |
256 | --nrvec; | |
257 | } | |
258 | if(!nrvec) | |
259 | return -1; | |
260 | if(!(nonce = unhex(*rvec, &nl))) | |
460b9539 | 261 | return -1; |
637fdea3 | 262 | if(!(res = authhash(nonce, nl, password, algo))) goto error; |
460b9539 | 263 | if(disorder_simple(c, 0, "user", username, res, (char *)0)) |
264 | return -1; | |
265 | c->user = xstrdup(username); | |
266 | return 0; | |
267 | error: | |
268 | if(c->fpin) fclose(c->fpin); | |
269 | if(c->fpout) fclose(c->fpout); | |
270 | if(fd2 != -1) close(fd2); | |
271 | if(fd != -1) close(fd); | |
272 | return -1; | |
273 | } | |
274 | ||
275 | int disorder_close(disorder_client *c) { | |
276 | int ret = 0; | |
277 | ||
278 | if(c->fpin) { | |
279 | if(fclose(c->fpin) < 0) { | |
280 | error(errno, "error calling fclose"); | |
281 | ret = -1; | |
282 | } | |
283 | c->fpin = 0; | |
284 | } | |
285 | if(c->fpout) { | |
286 | if(fclose(c->fpout) < 0) { | |
287 | error(errno, "error calling fclose"); | |
288 | ret = -1; | |
289 | } | |
290 | c->fpout = 0; | |
291 | } | |
292 | return 0; | |
293 | } | |
294 | ||
295 | int disorder_become(disorder_client *c, const char *user) { | |
296 | if(disorder_simple(c, 0, "become", user, (char *)0)) return -1; | |
297 | c->user = xstrdup(user); | |
298 | return 0; | |
299 | } | |
300 | ||
301 | int disorder_play(disorder_client *c, const char *track) { | |
302 | return disorder_simple(c, 0, "play", track, (char *)0); | |
303 | } | |
304 | ||
305 | int disorder_remove(disorder_client *c, const char *track) { | |
306 | return disorder_simple(c, 0, "remove", track, (char *)0); | |
307 | } | |
308 | ||
309 | int disorder_move(disorder_client *c, const char *track, int delta) { | |
310 | char d[16]; | |
311 | ||
312 | byte_snprintf(d, sizeof d, "%d", delta); | |
313 | return disorder_simple(c, 0, "move", track, d, (char *)0); | |
314 | } | |
315 | ||
316 | int disorder_enable(disorder_client *c) { | |
317 | return disorder_simple(c, 0, "enable", (char *)0); | |
318 | } | |
319 | ||
320 | int disorder_disable(disorder_client *c) { | |
321 | return disorder_simple(c, 0, "disable", (char *)0); | |
322 | } | |
323 | ||
324 | int disorder_scratch(disorder_client *c, const char *id) { | |
325 | return disorder_simple(c, 0, "scratch", id, (char *)0); | |
326 | } | |
327 | ||
328 | int disorder_shutdown(disorder_client *c) { | |
329 | return disorder_simple(c, 0, "shutdown", (char *)0); | |
330 | } | |
331 | ||
332 | int disorder_reconfigure(disorder_client *c) { | |
333 | return disorder_simple(c, 0, "reconfigure", (char *)0); | |
334 | } | |
335 | ||
336 | int disorder_rescan(disorder_client *c) { | |
337 | return disorder_simple(c, 0, "rescan", (char *)0); | |
338 | } | |
339 | ||
340 | int disorder_version(disorder_client *c, char **rp) { | |
341 | return disorder_simple(c, rp, "version", (char *)0); | |
342 | } | |
343 | ||
344 | static void client_error(const char *msg, | |
345 | void attribute((unused)) *u) { | |
346 | error(0, "error parsing reply: %s", msg); | |
347 | } | |
348 | ||
349 | int disorder_playing(disorder_client *c, struct queue_entry **qp) { | |
350 | char *r; | |
351 | struct queue_entry *q; | |
352 | ||
353 | if(disorder_simple(c, &r, "playing", (char *)0)) | |
354 | return -1; | |
355 | if(r) { | |
356 | q = xmalloc(sizeof *q); | |
357 | if(queue_unmarshall(q, r, client_error, 0)) | |
358 | return -1; | |
359 | *qp = q; | |
360 | } else | |
361 | *qp = 0; | |
362 | return 0; | |
363 | } | |
364 | ||
365 | static int disorder_somequeue(disorder_client *c, | |
366 | const char *cmd, struct queue_entry **qp) { | |
367 | struct queue_entry *qh, **qt = &qh, *q; | |
368 | char *l; | |
369 | ||
370 | if(disorder_simple(c, 0, cmd, (char *)0)) | |
371 | return -1; | |
372 | while(inputline(c->ident, c->fpin, &l, '\n') >= 0) { | |
373 | if(!strcmp(l, ".")) { | |
374 | *qt = 0; | |
375 | *qp = qh; | |
376 | return 0; | |
377 | } | |
378 | q = xmalloc(sizeof *q); | |
379 | if(!queue_unmarshall(q, l, client_error, 0)) { | |
380 | *qt = q; | |
381 | qt = &q->next; | |
382 | } | |
383 | } | |
384 | if(ferror(c->fpin)) | |
385 | error(errno, "error reading %s", c->ident); | |
386 | else | |
387 | error(0, "error reading %s: unexpected EOF", c->ident); | |
388 | return -1; | |
389 | } | |
390 | ||
391 | int disorder_recent(disorder_client *c, struct queue_entry **qp) { | |
392 | return disorder_somequeue(c, "recent", qp); | |
393 | } | |
394 | ||
395 | int disorder_queue(disorder_client *c, struct queue_entry **qp) { | |
396 | return disorder_somequeue(c, "queue", qp); | |
397 | } | |
398 | ||
399 | static int readlist(disorder_client *c, char ***vecp, int *nvecp) { | |
400 | char *l; | |
401 | struct vector v; | |
402 | ||
403 | vector_init(&v); | |
404 | while(inputline(c->ident, c->fpin, &l, '\n') >= 0) { | |
405 | if(!strcmp(l, ".")) { | |
406 | vector_terminate(&v); | |
407 | if(nvecp) | |
408 | *nvecp = v.nvec; | |
409 | *vecp = v.vec; | |
410 | return 0; | |
411 | } | |
412 | vector_append(&v, l + (*l == '.')); | |
413 | } | |
414 | if(ferror(c->fpin)) | |
415 | error(errno, "error reading %s", c->ident); | |
416 | else | |
417 | error(0, "error reading %s: unexpected EOF", c->ident); | |
418 | return -1; | |
419 | } | |
420 | ||
421 | static int disorder_simple_list(disorder_client *c, | |
422 | char ***vecp, int *nvecp, | |
423 | const char *cmd, ...) { | |
424 | va_list ap; | |
425 | int ret; | |
426 | ||
427 | va_start(ap, cmd); | |
428 | ret = disorder_simple_v(c, 0, cmd, ap); | |
429 | va_end(ap); | |
430 | if(ret) return ret; | |
431 | return readlist(c, vecp, nvecp); | |
432 | } | |
433 | ||
434 | int disorder_directories(disorder_client *c, const char *dir, const char *re, | |
435 | char ***vecp, int *nvecp) { | |
436 | return disorder_simple_list(c, vecp, nvecp, "dirs", dir, re, (char *)0); | |
437 | } | |
438 | ||
439 | int disorder_files(disorder_client *c, const char *dir, const char *re, | |
440 | char ***vecp, int *nvecp) { | |
441 | return disorder_simple_list(c, vecp, nvecp, "files", dir, re, (char *)0); | |
442 | } | |
443 | ||
444 | int disorder_allfiles(disorder_client *c, const char *dir, const char *re, | |
445 | char ***vecp, int *nvecp) { | |
446 | return disorder_simple_list(c, vecp, nvecp, "allfiles", dir, re, (char *)0); | |
447 | } | |
448 | ||
449 | char *disorder_user(disorder_client *c) { | |
450 | return c->user; | |
451 | } | |
452 | ||
453 | int disorder_set(disorder_client *c, const char *track, | |
454 | const char *key, const char *value) { | |
455 | return disorder_simple(c, 0, "set", track, key, value, (char *)0); | |
456 | } | |
457 | ||
458 | int disorder_unset(disorder_client *c, const char *track, | |
459 | const char *key) { | |
460 | return disorder_simple(c, 0, "unset", track, key, (char *)0); | |
461 | } | |
462 | ||
463 | int disorder_get(disorder_client *c, | |
464 | const char *track, const char *key, char **valuep) { | |
465 | return disorder_simple(c, valuep, "get", track, key, (char *)0); | |
466 | } | |
467 | ||
468 | static void pref_error_handler(const char *msg, | |
469 | void attribute((unused)) *u) { | |
470 | error(0, "error handling 'prefs' reply: %s", msg); | |
471 | } | |
472 | ||
473 | int disorder_prefs(disorder_client *c, const char *track, struct kvp **kp) { | |
474 | char **vec, **pvec; | |
475 | int nvec, npvec, n; | |
476 | struct kvp *k; | |
477 | ||
478 | if(disorder_simple_list(c, &vec, &nvec, "prefs", track, (char *)0)) | |
479 | return -1; | |
480 | for(n = 0; n < nvec; ++n) { | |
481 | if(!(pvec = split(vec[n], &npvec, SPLIT_QUOTES, pref_error_handler, 0))) | |
482 | return -1; | |
483 | if(npvec != 2) { | |
484 | pref_error_handler("malformed response", 0); | |
485 | return -1; | |
486 | } | |
487 | *kp = k = xmalloc(sizeof *k); | |
488 | k->name = pvec[0]; | |
489 | k->value = pvec[1]; | |
490 | kp = &k->next; | |
491 | } | |
492 | *kp = 0; | |
493 | return 0; | |
494 | } | |
495 | ||
496 | static int boolean(const char *cmd, const char *value, | |
497 | int *flagp) { | |
498 | if(!strcmp(value, "yes")) *flagp = 1; | |
499 | else if(!strcmp(value, "no")) *flagp = 0; | |
500 | else { | |
501 | error(0, "malformed response to '%s'", cmd); | |
502 | return -1; | |
503 | } | |
504 | return 0; | |
505 | } | |
506 | ||
507 | int disorder_exists(disorder_client *c, const char *track, int *existsp) { | |
508 | char *v; | |
509 | ||
510 | if(disorder_simple(c, &v, "exists", track, (char *)0)) return -1; | |
511 | return boolean("exists", v, existsp); | |
512 | } | |
513 | ||
514 | int disorder_enabled(disorder_client *c, int *enabledp) { | |
515 | char *v; | |
516 | ||
517 | if(disorder_simple(c, &v, "enabled", (char *)0)) return -1; | |
518 | return boolean("enabled", v, enabledp); | |
519 | } | |
520 | ||
521 | int disorder_length(disorder_client *c, const char *track, | |
522 | long *valuep) { | |
523 | char *value; | |
524 | ||
525 | if(disorder_simple(c, &value, "length", track, (char *)0)) return -1; | |
526 | *valuep = atol(value); | |
527 | return 0; | |
528 | } | |
529 | ||
530 | int disorder_search(disorder_client *c, const char *terms, | |
531 | char ***vecp, int *nvecp) { | |
532 | return disorder_simple_list(c, vecp, nvecp, "search", terms, (char *)0); | |
533 | } | |
534 | ||
535 | int disorder_random_enable(disorder_client *c) { | |
536 | return disorder_simple(c, 0, "random-enable", (char *)0); | |
537 | } | |
538 | ||
539 | int disorder_random_disable(disorder_client *c) { | |
540 | return disorder_simple(c, 0, "random-disable", (char *)0); | |
541 | } | |
542 | ||
543 | int disorder_random_enabled(disorder_client *c, int *enabledp) { | |
544 | char *v; | |
545 | ||
546 | if(disorder_simple(c, &v, "random-enabled", (char *)0)) return -1; | |
547 | return boolean("random-enabled", v, enabledp); | |
548 | } | |
549 | ||
550 | int disorder_stats(disorder_client *c, | |
551 | char ***vecp, int *nvecp) { | |
552 | return disorder_simple_list(c, vecp, nvecp, "stats", (char *)0); | |
553 | } | |
554 | ||
555 | int disorder_set_volume(disorder_client *c, int left, int right) { | |
556 | char *ls, *rs; | |
557 | ||
558 | if(byte_asprintf(&ls, "%d", left) < 0 | |
559 | || byte_asprintf(&rs, "%d", right) < 0) | |
560 | return -1; | |
561 | if(disorder_simple(c, 0, "volume", ls, rs, (char *)0)) return -1; | |
562 | return 0; | |
563 | } | |
564 | ||
565 | int disorder_get_volume(disorder_client *c, int *left, int *right) { | |
566 | char *r; | |
567 | ||
568 | if(disorder_simple(c, &r, "volume", (char *)0)) return -1; | |
569 | if(sscanf(r, "%d %d", left, right) != 2) { | |
570 | error(0, "error parsing response to 'volume': '%s'", r); | |
571 | return -1; | |
572 | } | |
573 | return 0; | |
574 | } | |
575 | ||
576 | int disorder_log(disorder_client *c, struct sink *s) { | |
577 | char *l; | |
578 | ||
579 | if(disorder_simple(c, 0, "log", (char *)0)) return -1; | |
580 | while(inputline(c->ident, c->fpin, &l, '\n') >= 0 && strcmp(l, ".")) | |
581 | if(sink_printf(s, "%s\n", l) < 0) return -1; | |
582 | if(ferror(c->fpin) || feof(c->fpin)) return -1; | |
583 | return 0; | |
584 | } | |
585 | ||
586 | int disorder_part(disorder_client *c, char **partp, | |
587 | const char *track, const char *context, const char *part) { | |
588 | return disorder_simple(c, partp, "part", track, context, part, (char *)0); | |
589 | } | |
590 | ||
591 | int disorder_resolve(disorder_client *c, char **trackp, const char *track) { | |
592 | return disorder_simple(c, trackp, "resolve", track, (char *)0); | |
593 | } | |
594 | ||
595 | int disorder_pause(disorder_client *c) { | |
596 | return disorder_simple(c, 0, "pause", (char *)0); | |
597 | } | |
598 | ||
599 | int disorder_resume(disorder_client *c) { | |
600 | return disorder_simple(c, 0, "resume", (char *)0); | |
601 | } | |
602 | ||
603 | int disorder_tags(disorder_client *c, | |
604 | char ***vecp, int *nvecp) { | |
605 | return disorder_simple_list(c, vecp, nvecp, "tags", (char *)0); | |
606 | } | |
607 | ||
c3be4f19 RK |
608 | int disorder_users(disorder_client *c, |
609 | char ***vecp, int *nvecp) { | |
610 | return disorder_simple_list(c, vecp, nvecp, "users", (char *)0); | |
611 | } | |
612 | ||
2a10b70b RK |
613 | /** @brief Get recentl added tracks |
614 | * @param c Client | |
615 | * @param vecp Where to store pointer to list | |
616 | * @param nvecp Where to store count | |
617 | * @param max Maximum tracks to fetch, or 0 for all available | |
618 | * @return 0 on success, non-0 on error | |
619 | */ | |
620 | int disorder_new_tracks(disorder_client *c, | |
621 | char ***vecp, int *nvecp, | |
622 | int max) { | |
623 | char limit[32]; | |
624 | ||
625 | sprintf(limit, "%d", max); | |
626 | return disorder_simple_list(c, vecp, nvecp, "new", limit, (char *)0); | |
627 | } | |
628 | ||
460b9539 | 629 | int disorder_set_global(disorder_client *c, |
630 | const char *key, const char *value) { | |
631 | return disorder_simple(c, 0, "set-global", key, value, (char *)0); | |
632 | } | |
633 | ||
634 | int disorder_unset_global(disorder_client *c, const char *key) { | |
635 | return disorder_simple(c, 0, "unset-global", key, (char *)0); | |
636 | } | |
637 | ||
638 | int disorder_get_global(disorder_client *c, const char *key, char **valuep) { | |
639 | return disorder_simple(c, valuep, "get-global", key, (char *)0); | |
640 | } | |
641 | ||
ca831831 RK |
642 | int disorder_rtp_address(disorder_client *c, char **addressp, char **portp) { |
643 | char *r; | |
644 | int rc, n; | |
645 | char **vec; | |
646 | ||
647 | if((rc = disorder_simple(c, &r, "rtp-address", (char *)0))) | |
648 | return rc; | |
649 | vec = split(r, &n, SPLIT_QUOTES, 0, 0); | |
650 | if(n != 2) { | |
651 | error(0, "malformed rtp-address reply"); | |
652 | return -1; | |
653 | } | |
654 | *addressp = vec[0]; | |
655 | *portp = vec[1]; | |
656 | return 0; | |
657 | } | |
658 | ||
f0feb22e RK |
659 | int disorder_adduser(disorder_client *c, |
660 | const char *user, const char *password) { | |
661 | return disorder_simple(c, 0, "adduser", user, password, (char *)0); | |
662 | } | |
663 | ||
664 | int disorder_deluser(disorder_client *c, const char *user) { | |
665 | return disorder_simple(c, 0, "deluser", user, (char *)0); | |
666 | } | |
667 | ||
a55c70c7 RK |
668 | int disorder_userinfo(disorder_client *c, const char *user, const char *key, |
669 | char **valuep) { | |
670 | return disorder_simple(c, valuep, "userinfo", user, key, (char *)0); | |
5df73aeb RK |
671 | } |
672 | ||
673 | int disorder_edituser(disorder_client *c, const char *user, | |
674 | const char *key, const char *value) { | |
675 | return disorder_simple(c, 0, "edituser", user, key, value, (char *)0); | |
676 | } | |
677 | ||
460b9539 | 678 | /* |
679 | Local Variables: | |
680 | c-basic-offset:2 | |
681 | comment-column:40 | |
682 | End: | |
683 | */ |