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