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