chiark / gitweb /
c7ef72850cbb39163cecb103868bc41cddc87c33
[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     ["playing_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
246     my @cargs = ();
247     for my $arg (@$args) {
248         if($arg->[0] eq 'body' or $arg->[0] eq 'list') {
249             push(@cargs, "disorder__$arg->[0]", $arg->[1], "n$arg->[1]");
250         } elsif($arg->[0] eq 'string') {
251             push(@cargs, $arg->[1]);
252         } elsif($arg->[0] eq 'integer'
253                 or $arg->[0] eq 'time') {
254             push(@cargs, "disorder__$arg->[0]", "$arg->[1]");
255         } elsif($arg->[0] eq 'literal') {
256             push(@cargs, "\"$arg->[1]\"");
257         } else {
258             die "$0: unsupported arg type '$arg->[0]' for '$cmd'\n";
259         }
260     }
261     # Synchronous C API
262     print STDERR "H ";
263     push(@h, "/** \@brief $summary\n",
264          " *\n",
265          " * $detail\n",
266          " *\n",
267          " * \@param c Client\n",
268          c_param_docs($args),
269          c_return_docs($returns),
270          " * \@return 0 on success, non-0 on error\n",
271          " */\n",
272          "int disorder_$cmdc(",
273          join(", ", "disorder_client *c",
274                     map(c_in_decl($_), @$args),
275                     map(c_out_decl($_), @$returns)),
276          ");\n\n");
277     print STDERR "C ";
278     push(@c, "int disorder_$cmdc(",
279          join(", ", "disorder_client *c",
280                     map(c_in_decl($_), @$args),
281                     map(c_out_decl($_), @$returns)),
282          ") {\n");
283     if(!defined $returns or scalar @$returns == 0) {
284         # Simple case
285         push(@c, "  return disorder_simple(",
286              join(", ", "c", "NULL", "\"$cmd\"", @cargs, "(char *)NULL"),
287              ");\n");
288     } elsif(scalar @$returns == 1
289             and $returns->[0]->[0] eq 'queue-one') {
290         # Special case
291         my $return = $$returns[0];
292         push(@c, "  return onequeue(c, \"$cmd\", $return->[1]p);\n");
293     } elsif(scalar @$returns == 1
294             and $returns->[0]->[0] eq 'string-raw') {
295         # Special case
296         my $return = $$returns[0];
297         push(@c, "  return disorder_simple(",
298              join(", ", "c", "$return->[1]p", "\"$cmd\"", @cargs, "(char *)NULL"),
299              ");\n");
300     } elsif(scalar @$returns == 1
301             and $returns->[0]->[0] eq 'pair-list') {
302         # Special case
303         my $return = $$returns[0];
304         push(@c, "  return pairlist(",
305              join(", ", "c", "$return->[1]p", "\"$cmd\"",
306                   @cargs,
307                   "(char *)NULL"),
308              ");\n");
309     } else {
310         my $expected = 0;
311         for(my $n = 0; $n < scalar @$returns; ++$n) {
312             my $return = $returns->[$n];
313             my $type = $return->[0];
314             my $name = $return->[1];
315             if($type eq 'string'
316                or $type eq 'boolean'
317                or $type eq 'integer'
318                or $type eq 'time'
319                or $type eq 'user') {
320                 ++$expected;
321             }
322         }
323         if($expected) {
324             push(@c, "  char **v;\n",
325                  "  int nv, rc = disorder_simple_split(",
326                  join(", ",
327                       "c",
328                       "&v",
329                       "&nv",
330                       $expected,
331                       "\"$cmd\"",
332                       @cargs,
333                       "(char *)NULL"),
334                  ");\n",
335                  "  if(rc)\n",
336                  "    return rc;\n");
337         } else {
338             push(@c,
339                  "  int rc = disorder_simple(",
340                  join(", ",
341                       "c",
342                       "NULL",
343                       "\"$cmd\"",
344                       @cargs,
345                       "(char *)NULL"),
346                  ");\n",
347                  "  if(rc)\n",
348                  "    return rc;\n");
349         }
350         for(my $n = 0; $n < scalar @$returns; ++$n) {
351             my $return = $returns->[$n];
352             my $type = $return->[0];
353             my $name = $return->[1];
354             if($type eq 'string') {
355                 push(@c,
356                      "  *${name}p = v[$n];\n",
357                      "  v[$n] = NULL;\n");
358             } elsif($type eq 'boolean') {
359                 push(@c,
360                      "  if(boolean(\"$cmd\", v[$n], ${name}p))\n",
361                      "    return -1;\n");
362             } elsif($type eq 'integer') {
363                 push(@c,
364                      "  *${name}p = atol(v[$n]);\n");
365             } elsif($type eq 'time') {
366                 push(@c,
367                      "  *${name}p = atoll(v[$n]);\n");
368             } elsif($type eq 'user') {
369                 push(@c,
370                      "  c->user = v[$n];\n",
371                      "  v[$n] = NULL;\n");
372             } elsif($type eq 'body') {
373                 push(@c,
374                      "  if(readlist(c, ${name}p, n${name}p))\n",
375                      "    return -1;\n");
376             } elsif($type eq 'queue') {
377                 push(@c,
378                      "  if(readqueue(c, ${name}p))\n",
379                      "    return -1;\n");
380             } else {
381                 die "$0: C API: unknown return type '$type' for '$name'\n";
382             }
383         }
384         if($expected) {
385             push(@c,
386                  "  free_strings(nv, v);\n");
387         }
388         push(@c, "  return 0;\n");
389     }
390     push(@c, "}\n\n");
391
392     # Asynchronous C API
393     my $variant = find_eclient_response($returns);
394     if(defined $variant) {
395         print STDERR "AH ";
396         push(@ah,
397              "/** \@brief $summary\n",
398              " *\n",
399              " * $detail\n",
400              " *\n",
401              " * \@param c Client\n",
402              " * \@param completed Called upon completion\n",
403              c_param_docs($args),
404              " * \@param v Passed to \@p completed\n",
405              " * \@return 0 if the command was queued successfuly, non-0 on error\n",
406              " */\n",
407              "int disorder_eclient_$cmdc(",
408              join(", ", "disorder_eclient *c",
409                   "disorder_eclient_$variant *completed",
410                   map(c_in_decl($_), @$args),
411                   "void *v"),
412              ");\n\n");
413
414         print STDERR "AC ";
415         push(@ac,
416              "int disorder_eclient_$cmdc(",
417              join(", ", "disorder_eclient *c",
418                   "disorder_eclient_$variant *completed",
419                   map(c_in_decl($_), @$args),
420                   "void *v"),
421              ") {\n");
422         push(@ac, "  return simple(",
423              join(", ", 
424                   "c",
425                   "${variant}_opcallback",
426                   "(void (*)())completed",
427                   "v",
428                   "\"$cmd\"",
429                   @cargs,
430                   "(char *)0"),
431              ");\n");
432         push(@ac, "}\n\n");
433     } else {
434         push(@missing, "disorder_eclient_$cmdc");
435     }
436
437     # Python API
438     # TODO
439
440     # Java API
441     # TODO
442     print STDERR "\n";
443 }
444
445 # TODO other command classes
446
447 # Front matter ----------------------------------------------------------------
448
449 our @generated = ("/*\n",
450                   " * Automatically generated file, see scripts/protocol\n",
451                   " *\n",
452                   " * DO NOT EDIT.\n",
453                   " */\n");
454
455 our @gpl = ("/*\n",
456             " * This file is part of DisOrder.\n",
457             " * Copyright (C) 2010-11 Richard Kettlewell\n",
458             " *\n",
459             " * This program is free software: you can redistribute it and/or modify\n",
460             " * it under the terms of the GNU General Public License as published by\n",
461             " * the Free Software Foundation, either version 3 of the License, or\n",
462             " * (at your option) any later version.\n",
463             " *\n",
464             " * This program is distributed in the hope that it will be useful,\n",
465             " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
466             " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n",
467             " * GNU General Public License for more details.\n",
468             " *\n",
469             " * You should have received a copy of the GNU General Public License\n",
470             " * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n",
471             " */\n");
472
473
474 push(@h, @generated, @gpl,
475      "#ifndef CLIENT_STUBS_H\n",
476      "#define CLIENT_STUBS_H\n",
477      "\n");
478
479 push(@c, @generated, @gpl,
480      "\n");
481
482 push(@ah, @generated, @gpl,
483      "#ifndef ECLIENT_STUBS_H\n",
484      "#define ECLIENT_STUBS_H\n",
485      "\n");
486
487 push(@ac, @generated, @gpl,
488      "\n");
489
490 # The protocol ----------------------------------------------------------------
491
492 simple("adopt",
493        "Adopt a track",
494        "Makes the calling user owner of a randomly picked track.",
495        [["string", "id", "Track ID"]]);
496
497 simple("adduser",
498        "Create a user",
499        "Create a new user.  Requires the 'admin' right.  Email addresses etc must be filled in in separate commands.",
500        [["string", "user", "New username"],
501         ["string", "password", "Initial password"],
502         ["string", "rights", "Initial rights (optional)"]]);
503
504 simple("allfiles",
505        "List files and directories in a directory",
506        "See 'files' and 'dirs' for more specific lists.",
507        [["string", "dir", "Directory to list (optional)"],
508         ["string", "re", "Regexp that results must match (optional)"]],
509        [["body", "files", "List of matching files and directories"]]);
510
511 simple("confirm",
512        "Confirm registration",
513        "The confirmation string must have been created with 'register'.  The username is returned so the caller knows who they are.",
514        [["string", "confirmation", "Confirmation string"]],
515        [["user"]]);
516
517 simple("cookie",
518        "Log in with a cookie",
519        "The cookie must have been created with 'make-cookie'.  The username is returned so the caller knows who they are.",
520        [["string", "cookie", "Cookie string"]],
521        [["user"]]);
522
523 simple("deluser",
524        "Delete user",
525        "Requires the 'admin' right.",
526        [["string", "user", "User to delete"]]);
527
528 simple("dirs",
529        "List directories in a directory",
530        "",
531        [["string", "dir", "Directory to list (optional)"],
532         ["string", "re", "Regexp that results must match (optional)"]],
533        [["body", "files", "List of matching directories"]]);
534
535 simple("disable",
536        "Disable play",
537        "Play will stop at the end of the current track, if one is playing.  Requires the 'global prefs' right.",
538        []);
539
540 simple("edituser",
541        "Set a user property",
542        "With the 'admin' right you can do anything.  Otherwise you need the 'userinfo' right and can only set 'email' and 'password'.",
543        [["string", "username", "User to modify"],
544         ["string", "property", "Property name"],
545         ["string", "value", "New property value"]]);
546
547 simple("enable",
548        "Enable play",
549        "Requires the 'global prefs' right.",
550        []);
551
552 simple("enabled",
553        "Detect whether play is enabled",
554        "",
555        [],
556        [["boolean", "enabled", "1 if play is enabled and 0 otherwise"]]);
557
558 simple("exists",
559        "Test whether a track exists",
560        "",
561        [["string", "track", "Track name"]],
562        [["boolean", "exists", "1 if the track exists and 0 otherwise"]]);
563
564 simple("files",
565        "List files in a directory",
566        "",
567        [["string", "dir", "Directory to list (optional)"],
568         ["string", "re", "Regexp that results must match (optional)"]],
569        [["body", "files", "List of matching files"]]);
570
571 simple("get",
572        "Get a track preference",
573        "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.",
574        [["string", "track", "Track name"],
575         ["string", "pref", "Preference name"]],
576        [["string", "value", "Preference value"]]);
577
578 simple("get-global",
579        "Get a global preference",
580        "If the preference does exist not then a null value is returned.",
581        [["string", "pref", "Global preference name"]],
582        [["string", "value", "Preference value"]]);
583
584 simple("length",
585        "Get a track's length",
586        "If the track does not exist an error is returned.",
587        [["string", "track", "Track name"]],
588        [["integer", "length", "Track length in seconds"]]);
589
590 # TODO log
591
592 simple("make-cookie",
593        "Create a login cookie for this user",
594        "The cookie may be redeemed via the 'cookie' command",
595        [],
596        [["string", "cookie", "Newly created cookie"]]);
597
598 simple("move",
599        "Move a track",
600        "Requires one of the 'move mine', 'move random' or 'move any' rights depending on how the track came to be added to the queue.",
601        [["string", "track", "Track ID or name"],
602         ["integer", "delta", "How far to move the track towards the head of the queue"]]);
603
604 simple("moveafter",
605        "Move multiple tracks",
606        "Requires one of the 'move mine', 'move random' or 'move any' rights depending on how the track came to be added to the queue.",
607        [["string", "target", "Move after this track, or to head if \"\""],
608         ["list", "ids", "List of tracks to move by ID"]]);
609
610 simple(["new", "new_tracks"],
611        "List recently added tracks",
612        "",
613        [["integer", "max", "Maximum tracks to fetch, or 0 for all available"]],
614        [["body", "tracks", "Recently added tracks"]]);
615
616 simple("nop",
617        "Do nothing",
618        "Used as a keepalive.  No authentication required.",
619        []);
620
621 simple("part",
622        "Get a track name part",
623        "If the name part cannot be constructed an empty string is returned.",
624        [["string", "track", "Track name"],
625         ["string", "context", "Context (\"sort\" or \"display\")"],
626         ["string", "part", "Name part (\"artist\", \"album\" or \"title\")"]],
627        [["string", "part", "Value of name part"]]);
628
629 simple("pause",
630        "Pause the currently playing track",
631        "Requires the 'pause' right.",
632        []);
633
634 simple("play",
635        "Play a track",
636        "Requires the 'play' right.",
637        [["string", "track", "Track to play"]],
638        [["string-raw", "id", "Queue ID of new track"]]);
639
640 simple("playafter",
641        "Play multiple tracks",
642        "Requires the 'play' right.",
643        [["string", "target", "Insert into queue after this track, or at head if \"\""],
644         ["list", "tracks", "List of track names to play"]]);
645
646 simple("playing",
647        "Retrieve the playing track",
648        "",
649        [],
650        [["queue-one", "playing", "Details of the playing track"]]);
651
652 simple("playlist-delete",
653        "Delete a playlist",
654        "Requires the 'play' right and permission to modify the playlist.",
655        [["string", "playlist", "Playlist to delete"]]);
656
657 simple("playlist-get",
658        "List the contents of a playlist",
659        "Requires the 'read' right and oermission to read the playlist.",
660        [["string", "playlist", "Playlist name"]],
661        [["body", "tracks", "List of tracks in playlist"]]);
662
663 simple("playlist-get-share",
664        "Get a playlist's sharing status",
665        "Requires the 'read' right and permission to read the playlist.",
666        [["string", "playlist", "Playlist to read"]],
667        [["string-raw", "share", "Sharing status (\"public\", \"private\" or \"shared\")"]]);
668
669 simple("playlist-lock",
670        "Lock a playlist",
671        "Requires the 'play' right and permission to modify the playlist.  A given connection may lock at most one playlist.",
672        [["string", "playlist", "Playlist to delete"]]);
673
674 simple("playlist-set",
675        "Set the contents of a playlist",
676        "Requires the 'play' right and permission to modify the playlist, which must be locked.",
677        [["string", "playlist", "Playlist to modify"],
678         ["body", "tracks", "New list of tracks for playlist"]]);
679
680 simple("playlist-set-share",
681        "Set a playlist's sharing status",
682        "Requires the 'play' right and permission to modify the playlist.",
683        [["string", "playlist", "Playlist to modify"],
684         ["string", "share", "New sharing status (\"public\", \"private\" or \"shared\")"]]);
685
686 simple("playlist-unlock",
687        "Unlock the locked playlist playlist",
688        "The playlist to unlock is implicit in the connection.",
689        []);
690
691 simple("playlists",
692        "List playlists",
693        "Requires the 'read' right.  Only playlists that you have permission to read are returned.",
694        [],
695        [["body", "playlists", "Playlist names"]]);
696
697 simple("prefs",
698        "Get all the preferences for a track",
699        "",
700        [["string", "track", "Track name"]],
701        [["pair-list", "prefs", "Track preferences"]]);
702
703 simple("queue",
704        "List the queue",
705        "",
706        [],
707        [["queue", "queue", "Current queue contents"]]);
708
709 simple("random-disable",
710        "Disable random play",
711        "Requires the 'global prefs' right.",
712        []);
713
714 simple("random-enable",
715        "Enable random play",
716        "Requires the 'global prefs' right.",
717        []);
718
719 simple("random-enabled",
720        "Detect whether random play is enabled",
721        "Random play counts as enabled even if play is disabled.",
722        [],
723        [["boolean", "enabled", "1 if random play is enabled and 0 otherwise"]]);
724
725 simple("recent",
726        "List recently played tracks",
727        "",
728        [],
729        [["queue", "recent", "Recently played tracks"]]);
730
731 simple("reconfigure",
732        "Re-read configuraiton file.",
733        "Requires the 'admin' right.",
734        []);
735
736 simple("register",
737        "Register a new user",
738        "Requires the 'register' right which is usually only available to the 'guest' user.  Redeem the confirmation string via 'confirm' to complete registration.",
739        [["string", "username", "Requested new username"],
740         ["string", "password", "Requested initial password"],
741         ["string", "email", "New user's email address"]],
742        [["string", "confirmation", "Confirmation string"]]);
743
744 simple("reminder",
745        "Send a password reminder.",
746        "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.",
747        [["string", "username", "User to remind"]]);
748
749 simple("remove",
750        "Remove a track form the queue.",
751        "Requires one of the 'remove mine', 'remove random' or 'remove any' rights depending on how the track came to be added to the queue.",
752        [["string", "id", "Track ID"]]);
753
754 simple("rescan",
755        "Rescan all collections for new or obsolete tracks.",
756        "Requires the 'rescan' right.",
757        []);     # TODO wait/fresh flags
758
759 simple("resolve",
760        "Resolve a track name",
761        "Converts aliases to non-alias track names",
762        [["string", "track", "Track name (might be an alias)"]],
763        [["string", "resolved", "Resolve track name (definitely not an alias)"]]);
764
765 simple("resume",
766        "Resume the currently playing track",
767        "Requires the 'pause' right.",
768        []);
769
770 simple("revoke",
771        "Revoke a cookie.",
772        "It will not subsequently be possible to log in with the cookie.",
773        []);
774
775 simple("rtp-address",
776        "Get the server's RTP address information",
777        "",
778        [],
779        [["string", "address", "Where to store hostname or address"],
780         ["string", "port", "Where to store service name or port number"]]);
781
782 simple("scratch",
783        "Terminate the playing track.",
784        "Requires one of the 'scratch mine', 'scratch random' or 'scratch any' rights depending on how the track came to be added to the queue.",
785        [["string", "id", "Track ID (optional)"]]);
786
787 simple(["schedule-add", "schedule_add_play"],
788        "Schedule a track to play in the future",
789        "",
790        [["time", "when", "When to play the track"],
791         ["string", "priority", "Event priority (\"normal\" or \"junk\")"],
792         ["literal", "play", ""],
793         ["string", "track", "Track to play"]]);
794
795 simple(["schedule-add", "schedule_add_set_global"],
796        "Schedule a global setting to be changed in the future",
797        "",
798        [["time", "when", "When to change the setting"],
799         ["string", "priority", "Event priority (\"normal\" or \"junk\")"],
800         ["literal", "set-global", ""],
801         ["string", "pref", "Global preference to set"],
802         ["string", "value", "New value of global preference"]]);
803
804 simple(["schedule-add", "schedule_add_unset_global"],
805        "Schedule a global setting to be unset in the future",
806        "",
807        [["time", "when", "When to change the setting"],
808         ["string", "priority", "Event priority (\"normal\" or \"junk\")"],
809         ["literal", "set-global", ""],
810         ["string", "pref", "Global preference to set"]]);
811
812 simple("schedule-del",
813        "Delete a scheduled event.",
814        "Users can always delete their own scheduled events; with the admin right you can delete any event.",
815        [["string", "event", "ID of event to delete"]]);
816
817 simple("schedule-get",
818        "Get the details of scheduled event",
819        "",
820        [["string", "id", "Event ID"]],
821        [["pair-list", "actiondata", "Details of event"]]);
822
823 simple("schedule-list",
824        "List scheduled events",
825        "This just lists IDs.  Use 'schedule-get' to retrieve more detail",
826        [],
827        [["body", "ids", "List of event IDs"]]);
828
829 simple("search",
830        "Search for tracks",
831        "Terms are either keywords or tags formatted as 'tag:TAG-NAME'.",
832        [["string", "terms", "List of search terms"]],
833        [["body", "tracks", "List of matching tracks"]]);
834
835 simple("set",
836        "Set a track preference",
837        "Requires the 'prefs' right.",
838        [["string", "track", "Track name"],
839         ["string", "pref", "Preference name"],
840         ["string", "value", "New value"]]);
841
842 simple("set-global",
843        "Set a global preference",
844        "Requires the 'global prefs' right.",
845        [["string", "pref", "Preference name"],
846         ["string", "value", "New value"]]);
847
848 simple("shutdown",
849        "Request server shutdown",
850        "Requires the 'admin' right.",
851        []);
852
853 simple("stats",
854        "Get server statistics",
855        "The details of what the server reports are not really defined.  The returned strings are intended to be printed out one to a line.",
856        [],
857        [["body", "stats", "List of server information strings."]]);
858
859 simple("tags",
860        "Get a list of known tags",
861        "Only tags which apply to at least one track are returned.",
862        [],
863        [["body", "tags", "List of tags"]]);
864
865 simple("unset",
866        "Unset a track preference",
867        "Requires the 'prefs' right.",
868        [["string", "track", "Track name"],
869         ["string", "pref", "Preference name"]]);
870
871 simple("unset-global",
872        "Set a global preference",
873        "Requires the 'global prefs' right.",
874        [["string", "pref", "Preference name"]]);
875
876 # 'user' only used for authentication
877
878 simple("userinfo",
879        "Get a user property.",
880        "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.",
881        [["string", "username", "User to read"],
882         ["string", "property", "Property to read"]],
883        [["string", "value", "Value of property"]]);
884
885 simple("users",
886        "Get a list of users",
887        "",
888        [],
889        [["body", "users", "List of users"]]);
890
891 simple("version",
892        "Get the server version",
893        "",
894        [],
895        [["string", "version", "Server version string"]]);
896
897 simple(["volume", "set_volume"],
898        "Set the volume",
899        "",
900        [["integer", "left", "Left channel volume"],
901         ["integer", "right", "Right channel volume"]]);
902
903 simple(["volume", "get_volume"],
904        "Get the volume",
905        "",
906        [],
907        [["integer", "left", "Left channel volume"],
908         ["integer", "right", "Right channel volume"]]);
909
910 # End matter ------------------------------------------------------------------
911
912 push(@h, "#endif\n");
913
914 push(@ah, "#endif\n");
915
916 # Write it all out ------------------------------------------------------------
917
918 Write("lib/client-stubs.h", \@h);
919 Write("lib/client-stubs.c", \@c);
920
921 Write("lib/eclient-stubs.h", \@ah);
922 Write("lib/eclient-stubs.c", \@ac);
923
924 if(scalar @missing) {
925   print "Missing:\n";
926   print map("  $_\n", @missing);
927 }