chiark / gitweb /
protogen: simplify handling of integers and times.
[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 = ();
ca7f5bb3
RK
48our @ah = ();
49our @ac = ();
50our @missing = ();
51
52# Mapping of return type sequences to eclient callbacks
53our @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"]],
ad131c25 62 ["playing_response" => ["queue-one"]],
ca7f5bb3
RK
63 ["list_response" => ["body"]],
64 );
65
66# eclient_response_matces(RETURNS, VARIANT)
67#
68# Return true if VARIANT matches RETURNS
69sub 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
85sub 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}
200adb00 97
ea9f5de5
RK
98# Write(PATH, LINES)
99#
100# Write array ref LINES to file PATH.
200adb00
RK
101sub Write {
102 my $path = shift;
103 my $lines = shift;
104
105 (open(F, ">$path")
106 and print F @$lines
107 and close F)
7788b7c7 108 or die "$0: $path: $!\n";
200adb00
RK
109}
110
111# Command classes -------------------------------------------------------------
112
ea9f5de5
RK
113# c_in_decl([TYPE, NAME])
114#
115# Return the C declaration for an input parameter of type TYPE with
116# name NAME.
50d905eb
RK
117sub 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";
4d80373d
RK
126 } elsif($type eq 'time') {
127 return "time_t $name";
0bc1d67c 128 } elsif($type eq 'list' or $type eq 'body') {
08af2413
RK
129 return ("char **$name",
130 "int n$name");
4d80373d
RK
131 } elsif($type eq 'literal') {
132 return ();
50d905eb 133 } else {
ec9c0462 134 die "$0: c_in_decl: unknown type '$type'\n";
50d905eb
RK
135 }
136}
137
ea9f5de5
RK
138# c_out_decl([TYPE, NAME])
139#
140# Return the C declaration for an output (reference) parameter of type
141# TYPE with name NAME.
50d905eb
RK
142sub c_out_decl {
143 my $arg = shift;
144
830d5c43 145 return () unless defined $arg;
50d905eb
RK
146 my $type = $arg->[0];
147 my $name = $arg->[1];
c12575c6 148 if($type eq 'string' or $type eq 'string-raw') {
830d5c43 149 return ("char **${name}p");
50d905eb 150 } elsif($type eq 'integer') {
830d5c43 151 return ("long *${name}p");
4d80373d
RK
152 } elsif($type eq 'time') {
153 return ("time_t *${name}p");
830d5c43
RK
154 } elsif($type eq 'boolean') {
155 return ("int *${name}p");
ec9c0462 156 } elsif($type eq 'list' or $type eq 'body') {
830d5c43
RK
157 return ("char ***${name}p",
158 "int *n${name}p");
5dc19ffd
RK
159 } elsif($type eq 'pair-list') {
160 return ("struct kvp **${name}p");
ec9c0462 161 } elsif($type eq 'queue' or $type eq 'queue-one') {
08af2413 162 return ("struct queue_entry **${name}p");
f4522fa7
RK
163 } elsif($type eq 'user') {
164 return ();
50d905eb 165 } else {
ec9c0462 166 die "$0: c_out_decl: unknown type '$type'\n";
50d905eb
RK
167 }
168}
169
ea9f5de5
RK
170# c_param_docs([TYPE, NAME})
171#
172# Return the doc string for a C input parameter.
50d905eb
RK
173sub c_param_docs {
174 my $args = shift;
08af2413
RK
175 my @d = ();
176 for my $arg (@$args) {
4d80373d
RK
177 my $type = $arg->[0];
178 my $name = $arg->[1];
179 my $description = $arg->[2];
180 if($type eq 'body' or $type eq 'list') {
08af2413 181 push(@d,
4d80373d
RK
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");
08af2413
RK
186 }
187 }
188 return @d;
50d905eb
RK
189}
190
ea9f5de5
RK
191# c_param_docs([TYPE, NAME})
192#
193# Return the doc string for a C output parameter.
830d5c43 194sub c_return_docs {
c12575c6
RK
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'
4d80373d 204 or $type eq 'time'
c12575c6
RK
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 }
830d5c43 219 }
7788b7c7
RK
220}
221
830d5c43
RK
222# simple(CMD, SUMMARY, DETAIL,
223# [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...],
c12575c6 224# [[RETURN-TYPE, RETURN-NAME, RETURN_DESCR]])
ff75e16e
RK
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.
830d5c43 229sub simple {
7788b7c7
RK
230 my $cmd = shift;
231 my $summary = shift;
232 my $detail = shift;
233 my $args = shift;
c12575c6 234 my $returns = shift;
7788b7c7 235
ff75e16e
RK
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 }
ec9c0462 244 print STDERR "Processing $cmd... ";
bcb2af72 245 # C argument types
816fbc19 246 my @cargs = ();
816fbc19
RK
247 for my $arg (@$args) {
248 if($arg->[0] eq 'body' or $arg->[0] eq 'list') {
ad131c25 249 push(@cargs, "disorder__$arg->[0]", $arg->[1], "n$arg->[1]");
816fbc19
RK
250 } elsif($arg->[0] eq 'string') {
251 push(@cargs, $arg->[1]);
bcb2af72
RK
252 } elsif($arg->[0] eq 'integer'
253 or $arg->[0] eq 'time') {
254 push(@cargs, "disorder__$arg->[0]", "$arg->[1]");
816fbc19
RK
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 }
7788b7c7 261 # Synchronous C API
ec9c0462 262 print STDERR "H ";
7788b7c7
RK
263 push(@h, "/** \@brief $summary\n",
264 " *\n",
265 " * $detail\n",
266 " *\n",
08af2413 267 " * \@param c Client\n",
830d5c43 268 c_param_docs($args),
c12575c6 269 c_return_docs($returns),
7788b7c7
RK
270 " * \@return 0 on success, non-0 on error\n",
271 " */\n",
50d905eb
RK
272 "int disorder_$cmdc(",
273 join(", ", "disorder_client *c",
274 map(c_in_decl($_), @$args),
c12575c6 275 map(c_out_decl($_), @$returns)),
830d5c43 276 ");\n\n");
ec9c0462 277 print STDERR "C ";
50d905eb
RK
278 push(@c, "int disorder_$cmdc(",
279 join(", ", "disorder_client *c",
280 map(c_in_decl($_), @$args),
c12575c6 281 map(c_out_decl($_), @$returns)),
bcb2af72 282 ") {\n");
c12575c6
RK
283 if(!defined $returns or scalar @$returns == 0) {
284 # Simple case
08af2413 285 push(@c, " return disorder_simple(",
c12575c6 286 join(", ", "c", "NULL", "\"$cmd\"", @cargs, "(char *)NULL"),
08af2413 287 ");\n");
c12575c6
RK
288 } elsif(scalar @$returns == 1
289 and $returns->[0]->[0] eq 'queue-one') {
290 # Special case
291 my $return = $$returns[0];
ec9c0462 292 push(@c, " return onequeue(c, \"$cmd\", $return->[1]p);\n");
c12575c6
RK
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];
eff6238f
RK
304 push(@c, " return pairlist(",
305 join(", ", "c", "$return->[1]p", "\"$cmd\"",
306 @cargs,
c12575c6 307 "(char *)NULL"),
eff6238f 308 ");\n");
830d5c43 309 } else {
dab87ecc 310 my $expected = 0;
c12575c6
RK
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'
4d80373d 318 or $type eq 'time'
c12575c6 319 or $type eq 'user') {
dab87ecc 320 ++$expected;
c12575c6
RK
321 }
322 }
dab87ecc
RK
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 }
c12575c6
RK
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,
e721e6b9
RK
356 " *${name}p = v[$n];\n",
357 " v[$n] = NULL;\n");
c12575c6
RK
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");
4d80373d
RK
365 } elsif($type eq 'time') {
366 push(@c,
367 " *${name}p = atoll(v[$n]);\n");
c12575c6
RK
368 } elsif($type eq 'user') {
369 push(@c,
e721e6b9
RK
370 " c->user = v[$n];\n",
371 " v[$n] = NULL;\n");
c12575c6
RK
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 }
e721e6b9
RK
384 if($expected) {
385 push(@c,
386 " free_strings(nv, v);\n");
387 }
c12575c6 388 push(@c, " return 0;\n");
830d5c43
RK
389 }
390 push(@c, "}\n\n");
7788b7c7
RK
391
392 # Asynchronous C API
ca7f5bb3
RK
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",
ca7f5bb3 402 " * \@param completed Called upon completion\n",
ad131c25
RK
403 c_param_docs($args),
404 " * \@param v Passed to \@p completed\n",
ca7f5bb3
RK
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",
ad131c25 409 "disorder_eclient_$variant *completed",
ca7f5bb3 410 map(c_in_decl($_), @$args),
ad131c25 411 "void *v"),
ca7f5bb3
RK
412 ");\n\n");
413
ad131c25
RK
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"),
bcb2af72 421 ") {\n");
ad131c25
RK
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");
ca7f5bb3
RK
433 } else {
434 push(@missing, "disorder_eclient_$cmdc");
435 }
7788b7c7
RK
436
437 # Python API
438 # TODO
439
440 # Java API
441 # TODO
ec9c0462 442 print STDERR "\n";
7788b7c7
RK
443}
444
200adb00
RK
445# TODO other command classes
446
447# Front matter ----------------------------------------------------------------
448
ff75e16e
RK
449our @generated = ("/*\n",
450 " * Automatically generated file, see scripts/protocol\n",
451 " *\n",
452 " * DO NOT EDIT.\n",
453 " */\n");
454
200adb00 455our @gpl = ("/*\n",
7788b7c7 456 " * This file is part of DisOrder.\n",
ff75e16e 457 " * Copyright (C) 2010-11 Richard Kettlewell\n",
7788b7c7
RK
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");
200adb00
RK
472
473
ff75e16e 474push(@h, @generated, @gpl,
200adb00
RK
475 "#ifndef CLIENT_STUBS_H\n",
476 "#define CLIENT_STUBS_H\n",
477 "\n");
478
ff75e16e 479push(@c, @generated, @gpl,
200adb00
RK
480 "\n");
481
ca7f5bb3
RK
482push(@ah, @generated, @gpl,
483 "#ifndef ECLIENT_STUBS_H\n",
484 "#define ECLIENT_STUBS_H\n",
485 "\n");
486
487push(@ac, @generated, @gpl,
488 "\n");
489
200adb00
RK
490# The protocol ----------------------------------------------------------------
491
96b1cf08
RK
492simple("adopt",
493 "Adopt a track",
494 "Makes the calling user owner of a randomly picked track.",
50d905eb 495 [["string", "id", "Track ID"]]);
200adb00 496
96b1cf08
RK
497simple("adduser",
498 "Create a user",
499 "Create a new user. Requires the 'admin' right. Email addresses etc must be filled in in separate commands.",
50d905eb
RK
500 [["string", "user", "New username"],
501 ["string", "password", "Initial password"],
502 ["string", "rights", "Initial rights (optional)"]]);
200adb00 503
830d5c43
RK
504simple("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)"]],
c12575c6 509 [["body", "files", "List of matching files and directories"]]);
200adb00 510
f4522fa7
RK
511simple("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"]],
c12575c6 515 [["user"]]);
f4522fa7
RK
516
517simple("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"]],
c12575c6 521 [["user"]]);
200adb00 522
96b1cf08
RK
523simple("deluser",
524 "Delete user",
525 "Requires the 'admin' right.",
50d905eb 526 [["string", "user", "User to delete"]]);
200adb00 527
830d5c43
RK
528simple("dirs",
529 "List directories in a directory",
530 "",
531 [["string", "dir", "Directory to list (optional)"],
532 ["string", "re", "Regexp that results must match (optional)"]],
c12575c6 533 [["body", "files", "List of matching directories"]]);
200adb00 534
96b1cf08
RK
535simple("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
540simple("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'.",
50d905eb
RK
543 [["string", "username", "User to modify"],
544 ["string", "property", "Property name"],
545 ["string", "value", "New property value"]]);
96b1cf08
RK
546
547simple("enable",
548 "Enable play",
549 "Requires the 'global prefs' right.",
550 []);
551
830d5c43
RK
552simple("enabled",
553 "Detect whether play is enabled",
554 "",
555 [],
c12575c6 556 [["boolean", "enabled", "1 if play is enabled and 0 otherwise"]]);
830d5c43
RK
557
558simple("exists",
559 "Test whether a track exists",
560 "",
561 [["string", "track", "Track name"]],
c12575c6 562 [["boolean", "exists", "1 if the track exists and 0 otherwise"]]);
830d5c43
RK
563
564simple("files",
565 "List files in a directory",
566 "",
567 [["string", "dir", "Directory to list (optional)"],
568 ["string", "re", "Regexp that results must match (optional)"]],
c12575c6 569 [["body", "files", "List of matching files"]]);
830d5c43
RK
570
571simple("get",
7788b7c7
RK
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.",
50d905eb
RK
574 [["string", "track", "Track name"],
575 ["string", "pref", "Preference name"]],
c12575c6 576 [["string", "value", "Preference value"]]);
200adb00 577
830d5c43 578simple("get-global",
7788b7c7
RK
579 "Get a global preference",
580 "If the preference does exist not then a null value is returned.",
50d905eb 581 [["string", "pref", "Global preference name"]],
c12575c6 582 [["string", "value", "Preference value"]]);
200adb00 583
830d5c43
RK
584simple("length",
585 "Get a track's length",
586 "If the track does not exist an error is returned.",
587 [["string", "track", "Track name"]],
c12575c6 588 [["integer", "length", "Track length in seconds"]]);
200adb00
RK
589
590# TODO log
591
830d5c43 592simple("make-cookie",
7788b7c7
RK
593 "Create a login cookie for this user",
594 "The cookie may be redeemed via the 'cookie' command",
595 [],
c12575c6 596 [["string", "cookie", "Newly created cookie"]]);
200adb00 597
0bc1d67c
RK
598simple("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"]]);
200adb00 603
0bc1d67c
RK
604simple("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"]]);
200adb00 609
ff75e16e
RK
610simple(["new", "new_tracks"],
611 "List recently added tracks",
612 "",
613 [["integer", "max", "Maximum tracks to fetch, or 0 for all available"]],
c12575c6 614 [["body", "tracks", "Recently added tracks"]]);
200adb00 615
96b1cf08
RK
616simple("nop",
617 "Do nothing",
618 "Used as a keepalive. No authentication required.",
619 []);
200adb00 620
830d5c43 621simple("part",
7788b7c7
RK
622 "Get a track name part",
623 "If the name part cannot be constructed an empty string is returned.",
50d905eb
RK
624 [["string", "track", "Track name"],
625 ["string", "context", "Context (\"sort\" or \"display\")"],
626 ["string", "part", "Name part (\"artist\", \"album\" or \"title\")"]],
c12575c6 627 [["string", "part", "Value of name part"]]);
200adb00 628
96b1cf08
RK
629simple("pause",
630 "Pause the currently playing track",
631 "Requires the 'pause' right.",
632 []);
200adb00 633
830d5c43 634simple("play",
00861dcb
RK
635 "Play a track",
636 "Requires the 'play' right.",
50d905eb 637 [["string", "track", "Track to play"]],
c12575c6 638 [["string-raw", "id", "Queue ID of new track"]]);
00861dcb 639
0bc1d67c
RK
640simple("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"]]);
200adb00 645
ec9c0462
RK
646simple("playing",
647 "Retrieve the playing track",
648 "",
649 [],
c12575c6 650 [["queue-one", "playing", "Details of the playing track"]]);
200adb00 651
96b1cf08
RK
652simple("playlist-delete",
653 "Delete a playlist",
654 "Requires the 'play' right and permission to modify the playlist.",
50d905eb 655 [["string", "playlist", "Playlist to delete"]]);
200adb00 656
830d5c43
RK
657simple("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"]],
c12575c6 661 [["body", "tracks", "List of tracks in playlist"]]);
200adb00 662
830d5c43 663simple("playlist-get-share",
7788b7c7
RK
664 "Get a playlist's sharing status",
665 "Requires the 'read' right and permission to read the playlist.",
50d905eb 666 [["string", "playlist", "Playlist to read"]],
c12575c6 667 [["string-raw", "share", "Sharing status (\"public\", \"private\" or \"shared\")"]]);
200adb00 668
3680ef53
RK
669simple("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.",
50d905eb 672 [["string", "playlist", "Playlist to delete"]]);
3680ef53 673
08af2413
RK
674simple("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"],
0bc1d67c 678 ["body", "tracks", "New list of tracks for playlist"]]);
08af2413 679
96b1cf08
RK
680simple("playlist-set-share",
681 "Set a playlist's sharing status",
7788b7c7 682 "Requires the 'play' right and permission to modify the playlist.",
50d905eb
RK
683 [["string", "playlist", "Playlist to modify"],
684 ["string", "share", "New sharing status (\"public\", \"private\" or \"shared\")"]]);
200adb00 685
96b1cf08
RK
686simple("playlist-unlock",
687 "Unlock the locked playlist playlist",
688 "The playlist to unlock is implicit in the connection.",
689 []);
200adb00 690
830d5c43
RK
691simple("playlists",
692 "List playlists",
693 "Requires the 'read' right. Only playlists that you have permission to read are returned.",
694 [],
c12575c6 695 [["body", "playlists", "Playlist names"]]);
200adb00 696
5dc19ffd
RK
697simple("prefs",
698 "Get all the preferences for a track",
699 "",
700 [["string", "track", "Track name"]],
c12575c6 701 [["pair-list", "prefs", "Track preferences"]]);
200adb00 702
08af2413
RK
703simple("queue",
704 "List the queue",
705 "",
706 [],
c12575c6 707 [["queue", "queue", "Current queue contents"]]);
200adb00 708
96b1cf08
RK
709simple("random-disable",
710 "Disable random play",
711 "Requires the 'global prefs' right.",
712 []);
713
714simple("random-enable",
715 "Enable random play",
716 "Requires the 'global prefs' right.",
717 []);
200adb00 718
830d5c43
RK
719simple("random-enabled",
720 "Detect whether random play is enabled",
721 "Random play counts as enabled even if play is disabled.",
722 [],
c12575c6 723 [["boolean", "enabled", "1 if random play is enabled and 0 otherwise"]]);
200adb00 724
08af2413
RK
725simple("recent",
726 "List recently played tracks",
727 "",
728 [],
c12575c6 729 [["queue", "recent", "Recently played tracks"]]);
200adb00 730
96b1cf08
RK
731simple("reconfigure",
732 "Re-read configuraiton file.",
733 "Requires the 'admin' right.",
734 []);
200adb00 735
830d5c43 736simple("register",
7788b7c7
RK
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.",
50d905eb
RK
739 [["string", "username", "Requested new username"],
740 ["string", "password", "Requested initial password"],
741 ["string", "email", "New user's email address"]],
c12575c6 742 [["string", "confirmation", "Confirmation string"]]);
200adb00 743
96b1cf08
RK
744simple("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.",
50d905eb 747 [["string", "username", "User to remind"]]);
200adb00 748
96b1cf08
RK
749simple("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.",
50d905eb 752 [["string", "id", "Track ID"]]);
200adb00 753
96b1cf08
RK
754simple("rescan",
755 "Rescan all collections for new or obsolete tracks.",
756 "Requires the 'rescan' right.",
7788b7c7 757 []); # TODO wait/fresh flags
200adb00 758
830d5c43 759simple("resolve",
7788b7c7
RK
760 "Resolve a track name",
761 "Converts aliases to non-alias track names",
50d905eb 762 [["string", "track", "Track name (might be an alias)"]],
c12575c6 763 [["string", "resolved", "Resolve track name (definitely not an alias)"]]);
200adb00 764
96b1cf08
RK
765simple("resume",
766 "Resume the currently playing track",
767 "Requires the 'pause' right.",
768 []);
200adb00 769
96b1cf08
RK
770simple("revoke",
771 "Revoke a cookie.",
772 "It will not subsequently be possible to log in with the cookie.",
08af2413 773 []);
200adb00 774
c12575c6
RK
775simple("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"]]);
200adb00 781
96b1cf08
RK
782simple("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.",
50d905eb 785 [["string", "id", "Track ID (optional)"]]);
200adb00 786
4d80373d
RK
787simple(["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
795simple(["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
804simple(["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"]]);
200adb00 811
96b1cf08
RK
812simple("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.",
50d905eb 815 [["string", "event", "ID of event to delete"]]);
200adb00 816
5dc19ffd
RK
817simple("schedule-get",
818 "Get the details of scheduled event",
819 "",
820 [["string", "id", "Event ID"]],
c12575c6 821 [["pair-list", "actiondata", "Details of event"]]);
200adb00 822
830d5c43
RK
823simple("schedule-list",
824 "List scheduled events",
825 "This just lists IDs. Use 'schedule-get' to retrieve more detail",
826 [],
c12575c6 827 [["body", "ids", "List of event IDs"]]);
200adb00 828
830d5c43
RK
829simple("search",
830 "Search for tracks",
831 "Terms are either keywords or tags formatted as 'tag:TAG-NAME'.",
832 [["string", "terms", "List of search terms"]],
c12575c6 833 [["body", "tracks", "List of matching tracks"]]);
200adb00 834
96b1cf08
RK
835simple("set",
836 "Set a track preference",
837 "Requires the 'prefs' right.",
50d905eb
RK
838 [["string", "track", "Track name"],
839 ["string", "pref", "Preference name"],
840 ["string", "value", "New value"]]);
200adb00 841
96b1cf08
RK
842simple("set-global",
843 "Set a global preference",
844 "Requires the 'global prefs' right.",
50d905eb
RK
845 [["string", "pref", "Preference name"],
846 ["string", "value", "New value"]]);
200adb00 847
eea34c08
RK
848simple("shutdown",
849 "Request server shutdown",
850 "Requires the 'admin' right.",
851 []);
7788b7c7 852
830d5c43
RK
853simple("stats",
854 "Get server statistics",
c12575c6 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.",
830d5c43 856 [],
c12575c6 857 [["body", "stats", "List of server information strings."]]);
200adb00 858
830d5c43
RK
859simple("tags",
860 "Get a list of known tags",
861 "Only tags which apply to at least one track are returned.",
862 [],
c12575c6 863 [["body", "tags", "List of tags"]]);
200adb00 864
96b1cf08
RK
865simple("unset",
866 "Unset a track preference",
867 "Requires the 'prefs' right.",
50d905eb
RK
868 [["string", "track", "Track name"],
869 ["string", "pref", "Preference name"]]);
200adb00 870
96b1cf08
RK
871simple("unset-global",
872 "Set a global preference",
873 "Requires the 'global prefs' right.",
50d905eb 874 [["string", "pref", "Preference name"]]);
200adb00 875
50d905eb 876# 'user' only used for authentication
200adb00 877
830d5c43 878simple("userinfo",
7788b7c7
RK
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.",
50d905eb
RK
881 [["string", "username", "User to read"],
882 ["string", "property", "Property to read"]],
c12575c6 883 [["string", "value", "Value of property"]]);
200adb00 884
830d5c43
RK
885simple("users",
886 "Get a list of users",
887 "",
888 [],
c12575c6 889 [["body", "users", "List of users"]]);
200adb00 890
830d5c43 891simple("version",
7788b7c7
RK
892 "Get the server version",
893 "",
894 [],
c12575c6
RK
895 [["string", "version", "Server version string"]]);
896
897simple(["volume", "set_volume"],
898 "Set the volume",
899 "",
900 [["integer", "left", "Left channel volume"],
901 ["integer", "right", "Right channel volume"]]);
200adb00 902
c12575c6
RK
903simple(["volume", "get_volume"],
904 "Get the volume",
905 "",
906 [],
907 [["integer", "left", "Left channel volume"],
908 ["integer", "right", "Right channel volume"]]);
200adb00
RK
909
910# End matter ------------------------------------------------------------------
911
912push(@h, "#endif\n");
913
ca7f5bb3
RK
914push(@ah, "#endif\n");
915
200adb00
RK
916# Write it all out ------------------------------------------------------------
917
7788b7c7
RK
918Write("lib/client-stubs.h", \@h);
919Write("lib/client-stubs.c", \@c);
ca7f5bb3
RK
920
921Write("lib/eclient-stubs.h", \@ah);
922Write("lib/eclient-stubs.c", \@ac);
923
924if(scalar @missing) {
925 print "Missing:\n";
926 print map(" $_\n", @missing);
927}