chiark / gitweb /
protogen: support schedule-add.
[disorder] / scripts / protocol
CommitLineData
200adb00
RK
1#! /usr/bin/perl -w
2#
3# This file is part of DisOrder.
ff75e16e 4# Copyright (C) 2010-11 Richard Kettlewell
200adb00
RK
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19use strict;
20
ec9c0462
RK
21# This file contains the definition of the disorder protocol, plus
22# code to generates stubs for it in the various supported languages.
23#
24# At the time of writing it is a work in progress!
25
26#
27# Types:
28#
29# string A (Unicode) string.
c12575c6 30# string-raw A string that is not subject to de-quoting (return only)
ec9c0462 31# integer An integer. Decimal on the wire.
4d80373d 32# time A timestamp. Decimal on the wire.
ec9c0462
RK
33# boolean True or false. "yes" or "no" on the wire.
34# list In commands: a list of strings in the command.
35# In returns: a list of lines in the response.
5dc19ffd 36# pair-list In returns: a list of key-value pairs in a response body.
ec9c0462
RK
37# body In commands: a list of strings as a command body.
38# In returns: a list of strings as a response body.
39# queue In returns: a list of queue entries in a response body.
40# queue-one In returns: a queue entry in the response.
4d80373d 41# literal Constant string sent in sequence
ec9c0462
RK
42#
43
200adb00
RK
44# Variables and utilities -----------------------------------------------------
45
46our @h = ();
47our @c = ();
48
ea9f5de5
RK
49# Write(PATH, LINES)
50#
51# Write array ref LINES to file PATH.
200adb00
RK
52sub Write {
53 my $path = shift;
54 my $lines = shift;
55
56 (open(F, ">$path")
57 and print F @$lines
58 and close F)
7788b7c7 59 or die "$0: $path: $!\n";
200adb00
RK
60}
61
62# Command classes -------------------------------------------------------------
63
ea9f5de5
RK
64# c_in_decl([TYPE, NAME])
65#
66# Return the C declaration for an input parameter of type TYPE with
67# name NAME.
50d905eb
RK
68sub c_in_decl {
69 my $arg = shift;
70
71 my $type = $arg->[0];
72 my $name = $arg->[1];
73 if($type eq 'string') {
74 return "const char *$name";
75 } elsif($type eq 'integer') {
76 return "long $name";
4d80373d
RK
77 } elsif($type eq 'time') {
78 return "time_t $name";
0bc1d67c 79 } elsif($type eq 'list' or $type eq 'body') {
08af2413
RK
80 return ("char **$name",
81 "int n$name");
4d80373d
RK
82 } elsif($type eq 'literal') {
83 return ();
50d905eb 84 } else {
ec9c0462 85 die "$0: c_in_decl: unknown type '$type'\n";
50d905eb
RK
86 }
87}
88
ea9f5de5
RK
89# c_out_decl([TYPE, NAME])
90#
91# Return the C declaration for an output (reference) parameter of type
92# TYPE with name NAME.
50d905eb
RK
93sub c_out_decl {
94 my $arg = shift;
95
830d5c43 96 return () unless defined $arg;
50d905eb
RK
97 my $type = $arg->[0];
98 my $name = $arg->[1];
c12575c6 99 if($type eq 'string' or $type eq 'string-raw') {
830d5c43 100 return ("char **${name}p");
50d905eb 101 } elsif($type eq 'integer') {
830d5c43 102 return ("long *${name}p");
4d80373d
RK
103 } elsif($type eq 'time') {
104 return ("time_t *${name}p");
830d5c43
RK
105 } elsif($type eq 'boolean') {
106 return ("int *${name}p");
ec9c0462 107 } elsif($type eq 'list' or $type eq 'body') {
830d5c43
RK
108 return ("char ***${name}p",
109 "int *n${name}p");
5dc19ffd
RK
110 } elsif($type eq 'pair-list') {
111 return ("struct kvp **${name}p");
ec9c0462 112 } elsif($type eq 'queue' or $type eq 'queue-one') {
08af2413 113 return ("struct queue_entry **${name}p");
f4522fa7
RK
114 } elsif($type eq 'user') {
115 return ();
50d905eb 116 } else {
ec9c0462 117 die "$0: c_out_decl: unknown type '$type'\n";
50d905eb
RK
118 }
119}
120
ea9f5de5
RK
121# c_param_docs([TYPE, NAME})
122#
123# Return the doc string for a C input parameter.
50d905eb
RK
124sub c_param_docs {
125 my $args = shift;
08af2413
RK
126 my @d = ();
127 for my $arg (@$args) {
4d80373d
RK
128 my $type = $arg->[0];
129 my $name = $arg->[1];
130 my $description = $arg->[2];
131 if($type eq 'body' or $type eq 'list') {
08af2413 132 push(@d,
4d80373d
RK
133 " * \@param $name $description\n",
134 " * \@param n$name Length of $name\n");
135 } elsif($type ne 'literal') {
136 push(@d, " * \@param $name $description\n");
08af2413
RK
137 }
138 }
139 return @d;
50d905eb
RK
140}
141
ea9f5de5
RK
142# c_param_docs([TYPE, NAME})
143#
144# Return the doc string for a C output parameter.
830d5c43 145sub c_return_docs {
c12575c6
RK
146 my $returns = shift;
147 return () unless defined $returns;
148 for my $return (@$returns) {
149 my $type = $return->[0];
150 my $name = $return->[1];
151 my $descr = $return->[2];
152 if($type eq 'string'
153 or $type eq 'string-raw'
154 or $type eq 'integer'
4d80373d 155 or $type eq 'time'
c12575c6
RK
156 or $type eq 'boolean') {
157 return (" * \@param ${name}p $descr\n");
158 } elsif($type eq 'list' or $type eq 'body') {
159 return (" * \@param ${name}p $descr\n",
160 " * \@param n${name}p Number of elements in ${name}p\n");
161 } elsif($type eq 'pair-list') {
162 return (" * \@param ${name}p $descr\n");
163 } elsif($type eq 'queue' or $type eq 'queue-one') {
164 return (" * \@param ${name}p $descr\n");
165 } elsif($type eq 'user') {
166 return ();
167 } else {
168 die "$0: c_return_docs: unknown type '$type'\n";
169 }
830d5c43 170 }
7788b7c7
RK
171}
172
830d5c43
RK
173# simple(CMD, SUMMARY, DETAIL,
174# [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...],
c12575c6 175# [[RETURN-TYPE, RETURN-NAME, RETURN_DESCR]])
ff75e16e
RK
176#
177# CMD is normally just the name of the command, but can
178# be [COMMAND,FUNCTION] if the function name should differ
179# from the protocol command.
830d5c43 180sub simple {
7788b7c7
RK
181 my $cmd = shift;
182 my $summary = shift;
183 my $detail = shift;
184 my $args = shift;
c12575c6 185 my $returns = shift;
7788b7c7 186
ff75e16e
RK
187 my $cmdc;
188 if(ref $cmd eq 'ARRAY') {
189 $cmdc = $$cmd[1];
190 $cmd = $$cmd[0];
191 } else {
192 $cmdc = $cmd;
193 $cmdc =~ s/-/_/g;
194 }
ec9c0462 195 print STDERR "Processing $cmd... ";
7788b7c7 196 # Synchronous C API
ec9c0462 197 print STDERR "H ";
7788b7c7
RK
198 push(@h, "/** \@brief $summary\n",
199 " *\n",
200 " * $detail\n",
201 " *\n",
08af2413 202 " * \@param c Client\n",
830d5c43 203 c_param_docs($args),
c12575c6 204 c_return_docs($returns),
7788b7c7
RK
205 " * \@return 0 on success, non-0 on error\n",
206 " */\n",
50d905eb
RK
207 "int disorder_$cmdc(",
208 join(", ", "disorder_client *c",
209 map(c_in_decl($_), @$args),
c12575c6 210 map(c_out_decl($_), @$returns)),
830d5c43 211 ");\n\n");
ec9c0462 212 print STDERR "C ";
50d905eb
RK
213 push(@c, "int disorder_$cmdc(",
214 join(", ", "disorder_client *c",
215 map(c_in_decl($_), @$args),
c12575c6 216 map(c_out_decl($_), @$returns)),
830d5c43 217 ") {\n");
ff75e16e
RK
218 my @cargs = ();
219 for my $arg (@$args) {
220 if($arg->[0] eq 'body' or $arg->[0] eq 'list') {
221 push(@cargs, "disorder_$arg->[0]", $arg->[1], "n$arg->[1]");
222 } elsif($arg->[0] eq 'string') {
223 push(@cargs, $arg->[1]);
224 } elsif($arg->[0] eq 'integer') {
225 push(@cargs, "buf_$arg->[1]");
226 push(@c, " char buf_$arg->[1]\[16];\n",
227 " byte_snprintf(buf_$arg->[1], sizeof buf_$arg->[1], \"%ld\", $arg->[1]);\n");
4d80373d
RK
228 } elsif($arg->[0] eq 'time') {
229 push(@cargs, "buf_$arg->[1]");
230 push(@c, " char buf_$arg->[1]\[16];\n",
231 " byte_snprintf(buf_$arg->[1], sizeof buf_$arg->[1], \"%lld\", (long long)$arg->[1]);\n");
232 } elsif($arg->[0] eq 'literal') {
233 push(@cargs, "\"$arg->[1]\"");
ff75e16e
RK
234 } else {
235 die "$0: unsupported arg type '$arg->[0]' for '$cmd'\n";
236 }
237 }
c12575c6
RK
238 if(!defined $returns or scalar @$returns == 0) {
239 # Simple case
08af2413 240 push(@c, " return disorder_simple(",
c12575c6 241 join(", ", "c", "NULL", "\"$cmd\"", @cargs, "(char *)NULL"),
08af2413 242 ");\n");
c12575c6
RK
243 } elsif(scalar @$returns == 1
244 and $returns->[0]->[0] eq 'queue-one') {
245 # Special case
246 my $return = $$returns[0];
ec9c0462 247 push(@c, " return onequeue(c, \"$cmd\", $return->[1]p);\n");
c12575c6
RK
248 } elsif(scalar @$returns == 1
249 and $returns->[0]->[0] eq 'string-raw') {
250 # Special case
251 my $return = $$returns[0];
252 push(@c, " return disorder_simple(",
253 join(", ", "c", "$return->[1]p", "\"$cmd\"", @cargs, "(char *)NULL"),
254 ");\n");
255 } elsif(scalar @$returns == 1
256 and $returns->[0]->[0] eq 'pair-list') {
257 # Special case
258 my $return = $$returns[0];
eff6238f
RK
259 push(@c, " return pairlist(",
260 join(", ", "c", "$return->[1]p", "\"$cmd\"",
261 @cargs,
c12575c6 262 "(char *)NULL"),
eff6238f 263 ");\n");
830d5c43 264 } else {
c12575c6
RK
265 my $split = 0;
266 for(my $n = 0; $n < scalar @$returns; ++$n) {
267 my $return = $returns->[$n];
268 my $type = $return->[0];
269 my $name = $return->[1];
270 if($type eq 'string'
271 or $type eq 'boolean'
272 or $type eq 'integer'
4d80373d 273 or $type eq 'time'
c12575c6
RK
274 or $type eq 'user') {
275 $split = 1;
276 }
277 }
278 if($split) {
279 push(@c, " char **v, *r;\n",
280 " int nv;\n");
281 }
282 push(@c,
283 " int rc = disorder_simple(",
284 join(", ",
285 "c",
286 $split ? "&r" : "NULL",
287 "\"$cmd\"",
288 @cargs,
289 "(char *)NULL"),
290 ");\n",
291 " if(rc)\n",
292 " return rc;\n");
293 if($split) {
294 push(@c,
295 " v = split(r, &nv, SPLIT_QUOTES, 0, 0);\n",
296 " if(nv != ", scalar @$returns, ") {\n",
297 " disorder_error(0, \"malformed reply to %s\", \"$cmd\");\n",
298 " return -1;\n",
299 " }\n");
300 }
301 for(my $n = 0; $n < scalar @$returns; ++$n) {
302 my $return = $returns->[$n];
303 my $type = $return->[0];
304 my $name = $return->[1];
305 if($type eq 'string') {
306 push(@c,
307 " *${name}p = v[$n];\n");
308 } elsif($type eq 'boolean') {
309 push(@c,
310 " if(boolean(\"$cmd\", v[$n], ${name}p))\n",
311 " return -1;\n");
312 } elsif($type eq 'integer') {
313 push(@c,
314 " *${name}p = atol(v[$n]);\n");
4d80373d
RK
315 } elsif($type eq 'time') {
316 push(@c,
317 " *${name}p = atoll(v[$n]);\n");
c12575c6
RK
318 } elsif($type eq 'user') {
319 push(@c,
320 " c->user = v[$n];\n");
321 } elsif($type eq 'body') {
322 push(@c,
323 " if(readlist(c, ${name}p, n${name}p))\n",
324 " return -1;\n");
325 } elsif($type eq 'queue') {
326 push(@c,
327 " if(readqueue(c, ${name}p))\n",
328 " return -1;\n");
329 } else {
330 die "$0: C API: unknown return type '$type' for '$name'\n";
331 }
332 }
333 push(@c, " return 0;\n");
334 # TODO xfree unconsumed split output
830d5c43
RK
335 }
336 push(@c, "}\n\n");
7788b7c7
RK
337
338 # Asynchronous C API
339 # TODO
340
341 # Python API
342 # TODO
343
344 # Java API
345 # TODO
ec9c0462 346 print STDERR "\n";
7788b7c7
RK
347}
348
200adb00
RK
349# TODO other command classes
350
351# Front matter ----------------------------------------------------------------
352
ff75e16e
RK
353our @generated = ("/*\n",
354 " * Automatically generated file, see scripts/protocol\n",
355 " *\n",
356 " * DO NOT EDIT.\n",
357 " */\n");
358
200adb00 359our @gpl = ("/*\n",
7788b7c7 360 " * This file is part of DisOrder.\n",
ff75e16e 361 " * Copyright (C) 2010-11 Richard Kettlewell\n",
7788b7c7
RK
362 " *\n",
363 " * This program is free software: you can redistribute it and/or modify\n",
364 " * it under the terms of the GNU General Public License as published by\n",
365 " * the Free Software Foundation, either version 3 of the License, or\n",
366 " * (at your option) any later version.\n",
367 " *\n",
368 " * This program is distributed in the hope that it will be useful,\n",
369 " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
370 " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
371 " * GNU General Public License for more details.\n",
372 " *\n",
373 " * You should have received a copy of the GNU General Public License\n",
374 " * along with this program. If not, see <http://www.gnu.org/licenses/>.\n",
375 " */\n");
200adb00
RK
376
377
ff75e16e 378push(@h, @generated, @gpl,
200adb00
RK
379 "#ifndef CLIENT_STUBS_H\n",
380 "#define CLIENT_STUBS_H\n",
381 "\n");
382
ff75e16e 383push(@c, @generated, @gpl,
200adb00
RK
384 "\n");
385
386# The protocol ----------------------------------------------------------------
387
96b1cf08
RK
388simple("adopt",
389 "Adopt a track",
390 "Makes the calling user owner of a randomly picked track.",
50d905eb 391 [["string", "id", "Track ID"]]);
200adb00 392
96b1cf08
RK
393simple("adduser",
394 "Create a user",
395 "Create a new user. Requires the 'admin' right. Email addresses etc must be filled in in separate commands.",
50d905eb
RK
396 [["string", "user", "New username"],
397 ["string", "password", "Initial password"],
398 ["string", "rights", "Initial rights (optional)"]]);
200adb00 399
830d5c43
RK
400simple("allfiles",
401 "List files and directories in a directory",
402 "See 'files' and 'dirs' for more specific lists.",
403 [["string", "dir", "Directory to list (optional)"],
404 ["string", "re", "Regexp that results must match (optional)"]],
c12575c6 405 [["body", "files", "List of matching files and directories"]]);
200adb00 406
f4522fa7
RK
407simple("confirm",
408 "Confirm registration",
409 "The confirmation string must have been created with 'register'. The username is returned so the caller knows who they are.",
410 [["string", "confirmation", "Confirmation string"]],
c12575c6 411 [["user"]]);
f4522fa7
RK
412
413simple("cookie",
414 "Log in with a cookie",
415 "The cookie must have been created with 'make-cookie'. The username is returned so the caller knows who they are.",
416 [["string", "cookie", "Cookie string"]],
c12575c6 417 [["user"]]);
200adb00 418
96b1cf08
RK
419simple("deluser",
420 "Delete user",
421 "Requires the 'admin' right.",
50d905eb 422 [["string", "user", "User to delete"]]);
200adb00 423
830d5c43
RK
424simple("dirs",
425 "List directories in a directory",
426 "",
427 [["string", "dir", "Directory to list (optional)"],
428 ["string", "re", "Regexp that results must match (optional)"]],
c12575c6 429 [["body", "files", "List of matching directories"]]);
200adb00 430
96b1cf08
RK
431simple("disable",
432 "Disable play",
433 "Play will stop at the end of the current track, if one is playing. Requires the 'global prefs' right.",
434 []);
435
436simple("edituser",
437 "Set a user property",
438 "With the 'admin' right you can do anything. Otherwise you need the 'userinfo' right and can only set 'email' and 'password'.",
50d905eb
RK
439 [["string", "username", "User to modify"],
440 ["string", "property", "Property name"],
441 ["string", "value", "New property value"]]);
96b1cf08
RK
442
443simple("enable",
444 "Enable play",
445 "Requires the 'global prefs' right.",
446 []);
447
830d5c43
RK
448simple("enabled",
449 "Detect whether play is enabled",
450 "",
451 [],
c12575c6 452 [["boolean", "enabled", "1 if play is enabled and 0 otherwise"]]);
830d5c43
RK
453
454simple("exists",
455 "Test whether a track exists",
456 "",
457 [["string", "track", "Track name"]],
c12575c6 458 [["boolean", "exists", "1 if the track exists and 0 otherwise"]]);
830d5c43
RK
459
460simple("files",
461 "List files in a directory",
462 "",
463 [["string", "dir", "Directory to list (optional)"],
464 ["string", "re", "Regexp that results must match (optional)"]],
c12575c6 465 [["body", "files", "List of matching files"]]);
830d5c43
RK
466
467simple("get",
7788b7c7
RK
468 "Get a track preference",
469 "If the track does not exist that is an error. If the track exists but the preference does not then a null value is returned.",
50d905eb
RK
470 [["string", "track", "Track name"],
471 ["string", "pref", "Preference name"]],
c12575c6 472 [["string", "value", "Preference value"]]);
200adb00 473
830d5c43 474simple("get-global",
7788b7c7
RK
475 "Get a global preference",
476 "If the preference does exist not then a null value is returned.",
50d905eb 477 [["string", "pref", "Global preference name"]],
c12575c6 478 [["string", "value", "Preference value"]]);
200adb00 479
830d5c43
RK
480simple("length",
481 "Get a track's length",
482 "If the track does not exist an error is returned.",
483 [["string", "track", "Track name"]],
c12575c6 484 [["integer", "length", "Track length in seconds"]]);
200adb00
RK
485
486# TODO log
487
830d5c43 488simple("make-cookie",
7788b7c7
RK
489 "Create a login cookie for this user",
490 "The cookie may be redeemed via the 'cookie' command",
491 [],
c12575c6 492 [["string", "cookie", "Newly created cookie"]]);
200adb00 493
0bc1d67c
RK
494simple("move",
495 "Move a track",
496 "Requires one of the 'move mine', 'move random' or 'move any' rights depending on how the track came to be added to the queue.",
497 [["string", "track", "Track ID or name"],
498 ["integer", "delta", "How far to move the track towards the head of the queue"]]);
200adb00 499
0bc1d67c
RK
500simple("moveafter",
501 "Move multiple tracks",
502 "Requires one of the 'move mine', 'move random' or 'move any' rights depending on how the track came to be added to the queue.",
503 [["string", "target", "Move after this track, or to head if \"\""],
504 ["list", "ids", "List of tracks to move by ID"]]);
200adb00 505
ff75e16e
RK
506simple(["new", "new_tracks"],
507 "List recently added tracks",
508 "",
509 [["integer", "max", "Maximum tracks to fetch, or 0 for all available"]],
c12575c6 510 [["body", "tracks", "Recently added tracks"]]);
200adb00 511
96b1cf08
RK
512simple("nop",
513 "Do nothing",
514 "Used as a keepalive. No authentication required.",
515 []);
200adb00 516
830d5c43 517simple("part",
7788b7c7
RK
518 "Get a track name part",
519 "If the name part cannot be constructed an empty string is returned.",
50d905eb
RK
520 [["string", "track", "Track name"],
521 ["string", "context", "Context (\"sort\" or \"display\")"],
522 ["string", "part", "Name part (\"artist\", \"album\" or \"title\")"]],
c12575c6 523 [["string", "part", "Value of name part"]]);
200adb00 524
96b1cf08
RK
525simple("pause",
526 "Pause the currently playing track",
527 "Requires the 'pause' right.",
528 []);
200adb00 529
830d5c43 530simple("play",
00861dcb
RK
531 "Play a track",
532 "Requires the 'play' right.",
50d905eb 533 [["string", "track", "Track to play"]],
c12575c6 534 [["string-raw", "id", "Queue ID of new track"]]);
00861dcb 535
0bc1d67c
RK
536simple("playafter",
537 "Play multiple tracks",
538 "Requires the 'play' right.",
539 [["string", "target", "Insert into queue after this track, or at head if \"\""],
540 ["list", "tracks", "List of track names to play"]]);
200adb00 541
ec9c0462
RK
542simple("playing",
543 "Retrieve the playing track",
544 "",
545 [],
c12575c6 546 [["queue-one", "playing", "Details of the playing track"]]);
200adb00 547
96b1cf08
RK
548simple("playlist-delete",
549 "Delete a playlist",
550 "Requires the 'play' right and permission to modify the playlist.",
50d905eb 551 [["string", "playlist", "Playlist to delete"]]);
200adb00 552
830d5c43
RK
553simple("playlist-get",
554 "List the contents of a playlist",
555 "Requires the 'read' right and oermission to read the playlist.",
556 [["string", "playlist", "Playlist name"]],
c12575c6 557 [["body", "tracks", "List of tracks in playlist"]]);
200adb00 558
830d5c43 559simple("playlist-get-share",
7788b7c7
RK
560 "Get a playlist's sharing status",
561 "Requires the 'read' right and permission to read the playlist.",
50d905eb 562 [["string", "playlist", "Playlist to read"]],
c12575c6 563 [["string-raw", "share", "Sharing status (\"public\", \"private\" or \"shared\")"]]);
200adb00 564
3680ef53
RK
565simple("playlist-lock",
566 "Lock a playlist",
567 "Requires the 'play' right and permission to modify the playlist. A given connection may lock at most one playlist.",
50d905eb 568 [["string", "playlist", "Playlist to delete"]]);
3680ef53 569
08af2413
RK
570simple("playlist-set",
571 "Set the contents of a playlist",
572 "Requires the 'play' right and permission to modify the playlist, which must be locked.",
573 [["string", "playlist", "Playlist to modify"],
0bc1d67c 574 ["body", "tracks", "New list of tracks for playlist"]]);
08af2413 575
96b1cf08
RK
576simple("playlist-set-share",
577 "Set a playlist's sharing status",
7788b7c7 578 "Requires the 'play' right and permission to modify the playlist.",
50d905eb
RK
579 [["string", "playlist", "Playlist to modify"],
580 ["string", "share", "New sharing status (\"public\", \"private\" or \"shared\")"]]);
200adb00 581
96b1cf08
RK
582simple("playlist-unlock",
583 "Unlock the locked playlist playlist",
584 "The playlist to unlock is implicit in the connection.",
585 []);
200adb00 586
830d5c43
RK
587simple("playlists",
588 "List playlists",
589 "Requires the 'read' right. Only playlists that you have permission to read are returned.",
590 [],
c12575c6 591 [["body", "playlists", "Playlist names"]]);
200adb00 592
5dc19ffd
RK
593simple("prefs",
594 "Get all the preferences for a track",
595 "",
596 [["string", "track", "Track name"]],
c12575c6 597 [["pair-list", "prefs", "Track preferences"]]);
200adb00 598
08af2413
RK
599simple("queue",
600 "List the queue",
601 "",
602 [],
c12575c6 603 [["queue", "queue", "Current queue contents"]]);
200adb00 604
96b1cf08
RK
605simple("random-disable",
606 "Disable random play",
607 "Requires the 'global prefs' right.",
608 []);
609
610simple("random-enable",
611 "Enable random play",
612 "Requires the 'global prefs' right.",
613 []);
200adb00 614
830d5c43
RK
615simple("random-enabled",
616 "Detect whether random play is enabled",
617 "Random play counts as enabled even if play is disabled.",
618 [],
c12575c6 619 [["boolean", "enabled", "1 if random play is enabled and 0 otherwise"]]);
200adb00 620
08af2413
RK
621simple("recent",
622 "List recently played tracks",
623 "",
624 [],
c12575c6 625 [["queue", "recent", "Recently played tracks"]]);
200adb00 626
96b1cf08
RK
627simple("reconfigure",
628 "Re-read configuraiton file.",
629 "Requires the 'admin' right.",
630 []);
200adb00 631
830d5c43 632simple("register",
7788b7c7
RK
633 "Register a new user",
634 "Requires the 'register' right which is usually only available to the 'guest' user. Redeem the confirmation string via 'confirm' to complete registration.",
50d905eb
RK
635 [["string", "username", "Requested new username"],
636 ["string", "password", "Requested initial password"],
637 ["string", "email", "New user's email address"]],
c12575c6 638 [["string", "confirmation", "Confirmation string"]]);
200adb00 639
96b1cf08
RK
640simple("reminder",
641 "Send a password reminder.",
642 "If the user has no valid email address, or no password, or a reminder has been sent too recently, then no reminder will be sent.",
50d905eb 643 [["string", "username", "User to remind"]]);
200adb00 644
96b1cf08
RK
645simple("remove",
646 "Remove a track form the queue.",
647 "Requires one of the 'remove mine', 'remove random' or 'remove any' rights depending on how the track came to be added to the queue.",
50d905eb 648 [["string", "id", "Track ID"]]);
200adb00 649
96b1cf08
RK
650simple("rescan",
651 "Rescan all collections for new or obsolete tracks.",
652 "Requires the 'rescan' right.",
7788b7c7 653 []); # TODO wait/fresh flags
200adb00 654
830d5c43 655simple("resolve",
7788b7c7
RK
656 "Resolve a track name",
657 "Converts aliases to non-alias track names",
50d905eb 658 [["string", "track", "Track name (might be an alias)"]],
c12575c6 659 [["string", "resolved", "Resolve track name (definitely not an alias)"]]);
200adb00 660
96b1cf08
RK
661simple("resume",
662 "Resume the currently playing track",
663 "Requires the 'pause' right.",
664 []);
200adb00 665
96b1cf08
RK
666simple("revoke",
667 "Revoke a cookie.",
668 "It will not subsequently be possible to log in with the cookie.",
08af2413 669 []);
200adb00 670
c12575c6
RK
671simple("rtp-address",
672 "Get the server's RTP address information",
673 "",
674 [],
675 [["string", "address", "Where to store hostname or address"],
676 ["string", "port", "Where to store service name or port number"]]);
200adb00 677
96b1cf08
RK
678simple("scratch",
679 "Terminate the playing track.",
680 "Requires one of the 'scratch mine', 'scratch random' or 'scratch any' rights depending on how the track came to be added to the queue.",
50d905eb 681 [["string", "id", "Track ID (optional)"]]);
200adb00 682
4d80373d
RK
683simple(["schedule-add", "schedule_add_play"],
684 "Schedule a track to play in the future",
685 "",
686 [["time", "when", "When to play the track"],
687 ["string", "priority", "Event priority (\"normal\" or \"junk\")"],
688 ["literal", "play", ""],
689 ["string", "track", "Track to play"]]);
690
691simple(["schedule-add", "schedule_add_set_global"],
692 "Schedule a global setting to be changed in the future",
693 "",
694 [["time", "when", "When to change the setting"],
695 ["string", "priority", "Event priority (\"normal\" or \"junk\")"],
696 ["literal", "set-global", ""],
697 ["string", "pref", "Global preference to set"],
698 ["string", "value", "New value of global preference"]]);
699
700simple(["schedule-add", "schedule_add_unset_global"],
701 "Schedule a global setting to be unset in the future",
702 "",
703 [["time", "when", "When to change the setting"],
704 ["string", "priority", "Event priority (\"normal\" or \"junk\")"],
705 ["literal", "set-global", ""],
706 ["string", "pref", "Global preference to set"]]);
200adb00 707
96b1cf08
RK
708simple("schedule-del",
709 "Delete a scheduled event.",
710 "Users can always delete their own scheduled events; with the admin right you can delete any event.",
50d905eb 711 [["string", "event", "ID of event to delete"]]);
200adb00 712
5dc19ffd
RK
713simple("schedule-get",
714 "Get the details of scheduled event",
715 "",
716 [["string", "id", "Event ID"]],
c12575c6 717 [["pair-list", "actiondata", "Details of event"]]);
200adb00 718
830d5c43
RK
719simple("schedule-list",
720 "List scheduled events",
721 "This just lists IDs. Use 'schedule-get' to retrieve more detail",
722 [],
c12575c6 723 [["body", "ids", "List of event IDs"]]);
200adb00 724
830d5c43
RK
725simple("search",
726 "Search for tracks",
727 "Terms are either keywords or tags formatted as 'tag:TAG-NAME'.",
728 [["string", "terms", "List of search terms"]],
c12575c6 729 [["body", "tracks", "List of matching tracks"]]);
200adb00 730
96b1cf08
RK
731simple("set",
732 "Set a track preference",
733 "Requires the 'prefs' right.",
50d905eb
RK
734 [["string", "track", "Track name"],
735 ["string", "pref", "Preference name"],
736 ["string", "value", "New value"]]);
200adb00 737
96b1cf08
RK
738simple("set-global",
739 "Set a global preference",
740 "Requires the 'global prefs' right.",
50d905eb
RK
741 [["string", "pref", "Preference name"],
742 ["string", "value", "New value"]]);
200adb00 743
eea34c08
RK
744simple("shutdown",
745 "Request server shutdown",
746 "Requires the 'admin' right.",
747 []);
7788b7c7 748
830d5c43
RK
749simple("stats",
750 "Get server statistics",
c12575c6 751 "The details of what the server reports are not really defined. The returned strings are intended to be printed out one to a line.",
830d5c43 752 [],
c12575c6 753 [["body", "stats", "List of server information strings."]]);
200adb00 754
830d5c43
RK
755simple("tags",
756 "Get a list of known tags",
757 "Only tags which apply to at least one track are returned.",
758 [],
c12575c6 759 [["body", "tags", "List of tags"]]);
200adb00 760
96b1cf08
RK
761simple("unset",
762 "Unset a track preference",
763 "Requires the 'prefs' right.",
50d905eb
RK
764 [["string", "track", "Track name"],
765 ["string", "pref", "Preference name"]]);
200adb00 766
96b1cf08
RK
767simple("unset-global",
768 "Set a global preference",
769 "Requires the 'global prefs' right.",
50d905eb 770 [["string", "pref", "Preference name"]]);
200adb00 771
50d905eb 772# 'user' only used for authentication
200adb00 773
830d5c43 774simple("userinfo",
7788b7c7
RK
775 "Get a user property.",
776 "If the user does not exist an error is returned, if the user exists but the property does not then a null value is returned.",
50d905eb
RK
777 [["string", "username", "User to read"],
778 ["string", "property", "Property to read"]],
c12575c6 779 [["string", "value", "Value of property"]]);
200adb00 780
830d5c43
RK
781simple("users",
782 "Get a list of users",
783 "",
784 [],
c12575c6 785 [["body", "users", "List of users"]]);
200adb00 786
830d5c43 787simple("version",
7788b7c7
RK
788 "Get the server version",
789 "",
790 [],
c12575c6
RK
791 [["string", "version", "Server version string"]]);
792
793simple(["volume", "set_volume"],
794 "Set the volume",
795 "",
796 [["integer", "left", "Left channel volume"],
797 ["integer", "right", "Right channel volume"]]);
200adb00 798
c12575c6
RK
799simple(["volume", "get_volume"],
800 "Get the volume",
801 "",
802 [],
803 [["integer", "left", "Left channel volume"],
804 ["integer", "right", "Right channel volume"]]);
200adb00
RK
805
806# End matter ------------------------------------------------------------------
807
808push(@h, "#endif\n");
809
810# Write it all out ------------------------------------------------------------
811
7788b7c7
RK
812Write("lib/client-stubs.h", \@h);
813Write("lib/client-stubs.c", \@c);