3 # This file is part of DisOrder.
4 # Copyright (C) 2010 Richard Kettlewell
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.
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.
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/>.
21 # Variables and utilities -----------------------------------------------------
33 or die "$0: $path: $!\n";
36 # Command classes -------------------------------------------------------------
43 if($type eq 'string') {
44 return "const char *$name";
45 } elsif($type eq 'integer') {
47 } elsif($type eq 'list') {
48 return ("char **$name",
51 die "$0: unknown type '$type'\n";
58 return () unless defined $arg;
61 if($type eq 'string') {
62 return ("char **${name}p");
63 } elsif($type eq 'integer') {
64 return ("long *${name}p");
65 } elsif($type eq 'boolean') {
66 return ("int *${name}p");
67 } elsif($type eq 'list') {
68 return ("char ***${name}p",
70 } elsif($type eq 'queue') {
71 return ("struct queue_entry **${name}p");
73 die "$0: unknown type '$type'\n";
80 for my $arg (@$args) {
81 if($arg->[0] eq 'list') {
83 " * \@param $arg->[1] $arg->[2]\n",
84 " * \@param n$arg->[1] Length of $arg->[1]\n");
86 push(@d, " * \@param $arg->[1] $arg->[2]\n");
94 return () unless defined $return;
95 my $type = $return->[0];
96 my $name = $return->[1];
97 my $descr = $return->[2];
100 or $type eq 'boolean') {
101 return (" * \@param ${name}p $descr\n");
102 } elsif($type eq 'list') {
103 return (" * \@param ${name}p $descr\n",
104 " * \@param n${name}p Number of elements in ${name}p\n");
105 } elsif($type eq 'queue') {
106 return (" * \@param ${name}p $descr\n");
108 die "$0: unknown return type '$type'\n";
112 # simple(CMD, SUMMARY, DETAIL,
113 # [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...],
114 # [RETURN-TYPE, RETURN-NAME, RETURN_DESCR])
125 push(@h, "/** \@brief $summary\n",
129 " * \@param c Client\n",
131 c_return_docs($return),
132 " * \@return 0 on success, non-0 on error\n",
134 "int disorder_$cmdc(",
135 join(", ", "disorder_client *c",
136 map(c_in_decl($_), @$args),
137 c_out_decl($return)),
139 push(@c, "int disorder_$cmdc(",
140 join(", ", "disorder_client *c",
141 map(c_in_decl($_), @$args),
142 c_out_decl($return)),
144 if(!defined $return) {
146 for my $arg (@$args) {
147 if($arg->[0] eq 'list') {
148 push(@cargs, "disorder_body", $arg->[1], "n$arg->[1]");
150 push(@cargs, $arg->[1]);
153 push(@c, " return disorder_simple(",
154 join(", ", "c", 0, "\"$cmd\"", @cargs, "(char *)0"),
156 } elsif($return->[0] eq 'string') {
157 push(@c, " return dequote(disorder_simple(c, $return->[1]p, \"$cmd\"",
158 map(", $_->[1]", @$args),
159 ", (char *)0), $return->[1]p);\n");
160 } elsif($return->[0] eq 'boolean') {
161 push(@c, " char *v;\n",
163 " if((rc = disorder_simple(c, &v, \"$cmd\"",
164 map(", $_->[1]", @$args),
167 " return boolean(\"$cmd\", v, $return->[1]p);\n");
168 } elsif($return->[0] eq 'integer') {
169 push(@c, " char *v;\n",
172 " if((rc = disorder_simple(c, &v, \"$cmd\"",
173 map(", $_->[1]", @$args),
176 " *$return->[1]p = atol(v);\n",
179 } elsif($return->[0] eq 'list') {
180 push(@c, " return disorder_simple_list(c, $return->[1]p, n$return->[1]p, \"$cmd\"",
181 map(", $_->[1]", @$args),
183 } elsif($return->[0] eq 'queue') {
184 push(@c, " return disorder_somequeue(c, \"$cmd\", $return->[1]p);\n");
186 die "$0: unknown return type '$return->[0]' for '$cmd'\n";
200 # string_login(CMD, SUMMARY, DETAIL, [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...])
202 # Like string(), but the server returns a username, which we squirrel
203 # away rather than returning to the caller.
214 push(@h, "/** \@brief $summary\n",
219 " * \@return 0 on success, non-0 on error\n",
221 "int disorder_$cmdc(",
222 join(", ", "disorder_client *c",
223 map(c_in_decl($_), @$args)),
225 push(@c, "int disorder_$cmdc(",
226 join(", ", "disorder_client *c",
227 map(c_in_decl($_), @$args)),
231 " if((rc = disorder_simple(c, &u, \"$cmd\"",
232 map(", $_->[1]", @$args),
249 # TODO other command classes
251 # Front matter ----------------------------------------------------------------
254 " * This file is part of DisOrder.\n",
255 " * Copyright (C) 2010 Richard Kettlewell\n",
257 " * This program is free software: you can redistribute it and/or modify\n",
258 " * it under the terms of the GNU General Public License as published by\n",
259 " * the Free Software Foundation, either version 3 of the License, or\n",
260 " * (at your option) any later version.\n",
262 " * This program is distributed in the hope that it will be useful,\n",
263 " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
264 " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
265 " * GNU General Public License for more details.\n",
267 " * You should have received a copy of the GNU General Public License\n",
268 " * along with this program. If not, see <http://www.gnu.org/licenses/>.\n",
273 "#ifndef CLIENT_STUBS_H\n",
274 "#define CLIENT_STUBS_H\n",
280 # The protocol ----------------------------------------------------------------
284 "Makes the calling user owner of a randomly picked track.",
285 [["string", "id", "Track ID"]]);
289 "Create a new user. Requires the 'admin' right. Email addresses etc must be filled in in separate commands.",
290 [["string", "user", "New username"],
291 ["string", "password", "Initial password"],
292 ["string", "rights", "Initial rights (optional)"]]);
295 "List files and directories in a directory",
296 "See 'files' and 'dirs' for more specific lists.",
297 [["string", "dir", "Directory to list (optional)"],
298 ["string", "re", "Regexp that results must match (optional)"]],
299 ["list", "files", "List of matching files and directories"]);
301 string_login("confirm",
302 "Confirm registration",
303 "The confirmation string must have been created with 'register'. The username is returned so the caller knows who they are.",
304 [["string", "confirmation", "Confirmation string"]]);
306 string_login("cookie",
307 "Log in with a cookie",
308 "The cookie must have been created with 'make-cookie'. The username is returned so the caller knows who they are.",
309 [["string", "cookie", "Cookie string"]]);
313 "Requires the 'admin' right.",
314 [["string", "user", "User to delete"]]);
317 "List directories in a directory",
319 [["string", "dir", "Directory to list (optional)"],
320 ["string", "re", "Regexp that results must match (optional)"]],
321 ["list", "files", "List of matching directories"]);
325 "Play will stop at the end of the current track, if one is playing. Requires the 'global prefs' right.",
329 "Set a user property",
330 "With the 'admin' right you can do anything. Otherwise you need the 'userinfo' right and can only set 'email' and 'password'.",
331 [["string", "username", "User to modify"],
332 ["string", "property", "Property name"],
333 ["string", "value", "New property value"]]);
337 "Requires the 'global prefs' right.",
341 "Detect whether play is enabled",
344 ["boolean", "enabled", "1 if play is enabled and 0 otherwise"]);
347 "Test whether a track exists",
349 [["string", "track", "Track name"]],
350 ["boolean", "exists", "1 if the track exists and 0 otherwise"]);
353 "List files in a directory",
355 [["string", "dir", "Directory to list (optional)"],
356 ["string", "re", "Regexp that results must match (optional)"]],
357 ["list", "files", "List of matching files"]);
360 "Get a track preference",
361 "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.",
362 [["string", "track", "Track name"],
363 ["string", "pref", "Preference name"]],
364 ["string", "value", "Preference value"]);
367 "Get a global preference",
368 "If the preference does exist not then a null value is returned.",
369 [["string", "pref", "Global preference name"]],
370 ["string", "value", "Preference value"]);
373 "Get a track's length",
374 "If the track does not exist an error is returned.",
375 [["string", "track", "Track name"]],
376 ["integer", "length", "Track length in seconds"]);
380 simple("make-cookie",
381 "Create a login cookie for this user",
382 "The cookie may be redeemed via the 'cookie' command",
384 ["string", "cookie", "Newly created cookie"]);
394 "Used as a keepalive. No authentication required.",
398 "Get a track name part",
399 "If the name part cannot be constructed an empty string is returned.",
400 [["string", "track", "Track name"],
401 ["string", "context", "Context (\"sort\" or \"display\")"],
402 ["string", "part", "Name part (\"artist\", \"album\" or \"title\")"]],
403 ["string", "part", "Value of name part"]);
406 "Pause the currently playing track",
407 "Requires the 'pause' right.",
412 "Requires the 'play' right.",
413 [["string", "track", "Track to play"]],
414 ["string", "id", "Queue ID of new track"]);
420 simple("playlist-delete",
422 "Requires the 'play' right and permission to modify the playlist.",
423 [["string", "playlist", "Playlist to delete"]]);
425 simple("playlist-get",
426 "List the contents of a playlist",
427 "Requires the 'read' right and oermission to read the playlist.",
428 [["string", "playlist", "Playlist name"]],
429 ["list", "tracks", "List of tracks in playlist"]);
431 simple("playlist-get-share",
432 "Get a playlist's sharing status",
433 "Requires the 'read' right and permission to read the playlist.",
434 [["string", "playlist", "Playlist to read"]],
435 ["string", "share", "Sharing status (\"public\", \"private\" or \"shared\")"]);
437 simple("playlist-lock",
439 "Requires the 'play' right and permission to modify the playlist. A given connection may lock at most one playlist.",
440 [["string", "playlist", "Playlist to delete"]]);
442 simple("playlist-set",
443 "Set the contents of a playlist",
444 "Requires the 'play' right and permission to modify the playlist, which must be locked.",
445 [["string", "playlist", "Playlist to modify"],
446 ["list", "tracks", "New list of tracks for playlist"]]);
448 simple("playlist-set-share",
449 "Set a playlist's sharing status",
450 "Requires the 'play' right and permission to modify the playlist.",
451 [["string", "playlist", "Playlist to modify"],
452 ["string", "share", "New sharing status (\"public\", \"private\" or \"shared\")"]]);
454 simple("playlist-unlock",
455 "Unlock the locked playlist playlist",
456 "The playlist to unlock is implicit in the connection.",
461 "Requires the 'read' right. Only playlists that you have permission to read are returned.",
463 ["list", "playlists", "Playlist names"]);
471 ["queue", "queue", "Current queue contents"]);
473 simple("random-disable",
474 "Disable random play",
475 "Requires the 'global prefs' right.",
478 simple("random-enable",
479 "Enable random play",
480 "Requires the 'global prefs' right.",
483 simple("random-enabled",
484 "Detect whether random play is enabled",
485 "Random play counts as enabled even if play is disabled.",
487 ["boolean", "enabled", "1 if random play is enabled and 0 otherwise"]);
490 "List recently played tracks",
493 ["queue", "recent", "Recently played tracks"]);
495 simple("reconfigure",
496 "Re-read configuraiton file.",
497 "Requires the 'admin' right.",
501 "Register a new user",
502 "Requires the 'register' right which is usually only available to the 'guest' user. Redeem the confirmation string via 'confirm' to complete registration.",
503 [["string", "username", "Requested new username"],
504 ["string", "password", "Requested initial password"],
505 ["string", "email", "New user's email address"]],
506 ["string", "confirmation", "Confirmation string"]);
509 "Send a password reminder.",
510 "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.",
511 [["string", "username", "User to remind"]]);
514 "Remove a track form the queue.",
515 "Requires one of the 'remove mine', 'remove random' or 'remove any' rights depending on how the track came to be added to the queue.",
516 [["string", "id", "Track ID"]]);
519 "Rescan all collections for new or obsolete tracks.",
520 "Requires the 'rescan' right.",
521 []); # TODO wait/fresh flags
524 "Resolve a track name",
525 "Converts aliases to non-alias track names",
526 [["string", "track", "Track name (might be an alias)"]],
527 ["string", "resolved", "Resolve track name (definitely not an alias)"]);
530 "Resume the currently playing track",
531 "Requires the 'pause' right.",
536 "It will not subsequently be possible to log in with the cookie.",
542 "Terminate the playing track.",
543 "Requires one of the 'scratch mine', 'scratch random' or 'scratch any' rights depending on how the track came to be added to the queue.",
544 [["string", "id", "Track ID (optional)"]]);
548 simple("schedule-del",
549 "Delete a scheduled event.",
550 "Users can always delete their own scheduled events; with the admin right you can delete any event.",
551 [["string", "event", "ID of event to delete"]]);
555 simple("schedule-list",
556 "List scheduled events",
557 "This just lists IDs. Use 'schedule-get' to retrieve more detail",
559 ["list", "ids", "List of event IDs"]);
563 "Terms are either keywords or tags formatted as 'tag:TAG-NAME'.",
564 [["string", "terms", "List of search terms"]],
565 ["list", "tracks", "List of matching tracks"]);
568 "Set a track preference",
569 "Requires the 'prefs' right.",
570 [["string", "track", "Track name"],
571 ["string", "pref", "Preference name"],
572 ["string", "value", "New value"]]);
575 "Set a global preference",
576 "Requires the 'global prefs' right.",
577 [["string", "pref", "Preference name"],
578 ["string", "value", "New value"]]);
581 "Request server shutdown",
582 "Requires the 'admin' right.",
586 "Get server statistics",
587 "The details of what the server reports are not really defined. The returned strings are intended to be printed out one to a line..",
589 ["list", "stats", "List of server information strings."]);
592 "Get a list of known tags",
593 "Only tags which apply to at least one track are returned.",
595 ["list", "tags", "List of tags"]);
598 "Unset a track preference",
599 "Requires the 'prefs' right.",
600 [["string", "track", "Track name"],
601 ["string", "pref", "Preference name"]]);
603 simple("unset-global",
604 "Set a global preference",
605 "Requires the 'global prefs' right.",
606 [["string", "pref", "Preference name"]]);
608 # 'user' only used for authentication
611 "Get a user property.",
612 "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.",
613 [["string", "username", "User to read"],
614 ["string", "property", "Property to read"]],
615 ["string", "value", "Value of property"]);
618 "Get a list of users",
621 ["list", "users", "List of users"]);
624 "Get the server version",
627 ["string", "version", "Server version string"]);
631 # End matter ------------------------------------------------------------------
633 push(@h, "#endif\n");
635 # Write it all out ------------------------------------------------------------
637 Write("lib/client-stubs.h", \@h);
638 Write("lib/client-stubs.c", \@c);