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