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') {
48 die "$0: unknown type '$type'\n";
57 if($type eq 'string') {
58 return "char **${name}p";
59 } elsif($type eq 'integer') {
60 return "long *${name}p";
62 die "$0: unknown type '$type'\n";
68 return map(" * \@param $_->[1] $_->[2]\n", @$args);
71 # simple(CMD, SUMMARY, DETAIL, [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...],)
73 # Response is simply success/failure
83 push(@h, "/** \@brief $summary\n",
88 " * \@return 0 on success, non-0 on error\n",
90 "int disorder_$cmdc(",
91 join(", ", "disorder_client *c",
92 map(c_in_decl($_), @$args)),
94 push(@c, "int disorder_$cmdc(",
95 join(", ", "disorder_client *c",
96 map(c_in_decl($_), @$args)),
98 " return disorder_simple(c, 0, \"$cmd\"",
99 map(", $_->[1]", @$args),
113 # string(CMD, SUMMARY, DETAIL, [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...], [RETURN, DESCR])
115 # Response is a string, or failure, or 555 for "none".
126 push(@h, "/** \@brief $summary\n",
131 " * \@param $return->[0]p $return->[1]\n",
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 "char **$return->[0]p"),
139 push(@c, "int disorder_$cmdc(",
140 join(", ", "disorder_client *c",
141 map(c_in_decl($_), @$args),
142 "char **$return->[0]p"),
144 " return dequote(disorder_simple(c, $return->[0]p, \"$cmd\"",
145 map(", $_->[1]", @$args),
146 ", (char *)0), $return->[0]p);\n",
159 # string_login(CMD, SUMMARY, DETAIL, [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...])
161 # Like string(), but the server returns a username, which we squirrel
162 # away rather than returning to the caller.
173 push(@h, "/** \@brief $summary\n",
178 " * \@return 0 on success, non-0 on error\n",
180 "int disorder_$cmdc(",
181 join(", ", "disorder_client *c",
182 map(c_in_decl($_), @$args)),
184 push(@c, "int disorder_$cmdc(",
185 join(", ", "disorder_client *c",
186 map(c_in_decl($_), @$args)),
190 " if((rc = disorder_simple(c, &u, \"$cmd\"",
191 map(", $_->[1]", @$args),
208 # boolean(CMD, SUMMARY, DETAIL, [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...], [RETURN, DESCR])
210 # Response is yes/no or failure
221 push(@h, "/** \@brief $summary\n",
226 " * \@param $return->[0]p $return->[1]\n",
227 " * \@return 0 on success, non-0 on error\n",
229 "int disorder_$cmdc(",
230 join(", ", "disorder_client *c",
231 map(c_in_decl($_), @$args),
232 "int *$return->[0]p"),
234 push(@c, "int disorder_$cmdc(",
235 join(", ", "disorder_client *c",
236 map(c_in_decl($_), @$args),
237 "int *$return->[0]p"),
241 " if((rc = disorder_simple(c, &v, \"$cmd\"",
242 map(", $_->[1]", @$args),
245 " return boolean(\"$cmd\", v, $return->[0]p);\n",
258 # integer(CMD, SUMMARY, DETAIL, [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...], [RETURN, DESCR])
260 # Response is an integer, or failure
271 push(@h, "/** \@brief $summary\n",
276 " * \@param $return->[0]p $return->[1]\n",
277 " * \@return 0 on success, non-0 on error\n",
279 "int disorder_$cmdc(",
280 join(", ", "disorder_client *c",
281 map(c_in_decl($_), @$args),
282 "long *$return->[0]p"),
284 push(@c, "int disorder_$cmdc(",
285 join(", ", "disorder_client *c",
286 map(c_in_decl($_), @$args),
287 "long *$return->[0]p"),
292 " if((rc = disorder_simple(c, &v, \"$cmd\"",
293 map(", $_->[1]", @$args),
296 " *$return->[0]p = atol(v);\n",
311 # list(CMD, SUMMARY, DETAIL, [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...], [RETURN, DESCR])
313 # Response is a a list of strings in a dot-stuffed body
324 push(@h, "/** \@brief $summary\n",
329 " * \@param $return->[0]p $return->[1]\n",
330 " * \@param n$return->[0]p Number of elements in $return->[0]p\n",
331 " * \@return 0 on success, non-0 on error\n",
333 "int disorder_$cmdc(",
334 join(", ", "disorder_client *c",
335 map(c_in_decl($_), @$args),
336 "char ***$return->[0]p",
337 "int *n$return->[0]p"),
339 push(@c, "int disorder_$cmdc(",
340 join(", ", "disorder_client *c",
341 map(c_in_decl($_), @$args),
342 "char ***$return->[0]p",
343 "int *n$return->[0]p"),
345 " return disorder_simple_list(c, $return->[0]p, n$return->[0]p, \"$cmd\"",
346 map(", $_->[1]", @$args),
360 # TODO other command classes
362 # Front matter ----------------------------------------------------------------
365 " * This file is part of DisOrder.\n",
366 " * Copyright (C) 2010 Richard Kettlewell\n",
368 " * This program is free software: you can redistribute it and/or modify\n",
369 " * it under the terms of the GNU General Public License as published by\n",
370 " * the Free Software Foundation, either version 3 of the License, or\n",
371 " * (at your option) any later version.\n",
373 " * This program is distributed in the hope that it will be useful,\n",
374 " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
375 " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
376 " * GNU General Public License for more details.\n",
378 " * You should have received a copy of the GNU General Public License\n",
379 " * along with this program. If not, see <http://www.gnu.org/licenses/>.\n",
384 "#ifndef CLIENT_STUBS_H\n",
385 "#define CLIENT_STUBS_H\n",
391 # The protocol ----------------------------------------------------------------
395 "Makes the calling user owner of a randomly picked track.",
396 [["string", "id", "Track ID"]]);
400 "Create a new user. Requires the 'admin' right. Email addresses etc must be filled in in separate commands.",
401 [["string", "user", "New username"],
402 ["string", "password", "Initial password"],
403 ["string", "rights", "Initial rights (optional)"]]);
406 "List files and directories in a directory",
407 "See 'files' and 'dirs' for more specific lists.",
408 [["string", "dir", "Directory to list (optional)"],
409 ["string", "re", "Regexp that results must match (optional)"]],
410 ["files", "List of matching files and directories"]);
412 string_login("confirm",
413 "Confirm registration",
414 "The confirmation string must have been created with 'register'. The username is returned so the caller knows who they are.",
415 [["string", "confirmation", "Confirmation string"]]);
417 string_login("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"]]);
424 "Requires the 'admin' right.",
425 [["string", "user", "User to delete"]]);
428 "List directories in a directory",
430 [["string", "dir", "Directory to list (optional)"],
431 ["string", "re", "Regexp that results must match (optional)"]],
432 ["files", "List of matching directories"]);
436 "Play will stop at the end of the current track, if one is playing. Requires the 'global prefs' right.",
440 "Set a user property",
441 "With the 'admin' right you can do anything. Otherwise you need the 'userinfo' right and can only set 'email' and 'password'.",
442 [["string", "username", "User to modify"],
443 ["string", "property", "Property name"],
444 ["string", "value", "New property value"]]);
448 "Requires the 'global prefs' right.",
452 "Detect whether play is enabled",
455 ["enabled", "1 if play is enabled and 0 otherwise"]);
458 "Test whether a track exists",
460 [["string", "track", "Track name"]],
461 ["exists", "1 if the track exists and 0 otherwise"]);
464 "List files in a directory",
466 [["string", "dir", "Directory to list (optional)"],
467 ["string", "re", "Regexp that results must match (optional)"]],
468 ["files", "List of matching files"]);
471 "Get a track preference",
472 "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.",
473 [["string", "track", "Track name"],
474 ["string", "pref", "Preference name"]],
475 ["value", "Preference value"]);
478 "Get a global preference",
479 "If the preference does exist not then a null value is returned.",
480 [["string", "pref", "Global preference name"]],
481 ["value", "Preference value"]);
484 "Get a track's length",
485 "If the track does not exist an error is returned.",
486 [["string", "track", "Track name"]],
487 ["length", "Track length in seconds"]);
491 string("make-cookie",
492 "Create a login cookie for this user",
493 "The cookie may be redeemed via the 'cookie' command",
495 ["cookie", "Newly created cookie"]);
505 "Used as a keepalive. No authentication required.",
509 "Get a track name part",
510 "If the name part cannot be constructed an empty string is returned.",
511 [["string", "track", "Track name"],
512 ["string", "context", "Context (\"sort\" or \"display\")"],
513 ["string", "part", "Name part (\"artist\", \"album\" or \"title\")"]],
514 ["part", "Value of name part"]);
517 "Pause the currently playing track",
518 "Requires the 'pause' right.",
523 "Requires the 'play' right.",
524 [["string", "track", "Track to play"]],
525 ["id", "Queue ID of new track"]);
531 simple("playlist-delete",
533 "Requires the 'play' right and permission to modify the playlist.",
534 [["string", "playlist", "Playlist to delete"]]);
537 "List the contents of a playlist",
538 "Requires the 'read' right and oermission to read the playlist.",
539 [["string", "playlist", "Playlist name"]],
540 ["tracks", "List of tracks in playlist"]);
542 string("playlist-get-share",
543 "Get a playlist's sharing status",
544 "Requires the 'read' right and permission to read the playlist.",
545 [["string", "playlist", "Playlist to read"]],
546 ["share", "Sharing status (\"public\", \"private\" or \"shared\")"]);
548 simple("playlist-lock",
550 "Requires the 'play' right and permission to modify the playlist. A given connection may lock at most one playlist.",
551 [["string", "playlist", "Playlist to delete"]]);
553 simple("playlist-set-share",
554 "Set a playlist's sharing status",
555 "Requires the 'play' right and permission to modify the playlist.",
556 [["string", "playlist", "Playlist to modify"],
557 ["string", "share", "New sharing status (\"public\", \"private\" or \"shared\")"]]);
559 simple("playlist-unlock",
560 "Unlock the locked playlist playlist",
561 "The playlist to unlock is implicit in the connection.",
566 "Requires the 'read' right. Only playlists that you have permission to read are returned.",
568 ["playlists", "Playlist names"]);
574 simple("random-disable",
575 "Disable random play",
576 "Requires the 'global prefs' right.",
579 simple("random-enable",
580 "Enable random play",
581 "Requires the 'global prefs' right.",
584 boolean("random-enabled",
585 "Detect whether random play is enabled",
586 "Random play counts as enabled even if play is disabled.",
588 ["enabled", "1 if random play is enabled and 0 otherwise"]);
592 simple("reconfigure",
593 "Re-read configuraiton file.",
594 "Requires the 'admin' right.",
598 "Register a new user",
599 "Requires the 'register' right which is usually only available to the 'guest' user. Redeem the confirmation string via 'confirm' to complete registration.",
600 [["string", "username", "Requested new username"],
601 ["string", "password", "Requested initial password"],
602 ["string", "email", "New user's email address"]],
603 ["confirmation", "Confirmation string"]);
606 "Send a password reminder.",
607 "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.",
608 [["string", "username", "User to remind"]]);
611 "Remove a track form the queue.",
612 "Requires one of the 'remove mine', 'remove random' or 'remove any' rights depending on how the track came to be added to the queue.",
613 [["string", "id", "Track ID"]]);
616 "Rescan all collections for new or obsolete tracks.",
617 "Requires the 'rescan' right.",
618 []); # TODO wait/fresh flags
621 "Resolve a track name",
622 "Converts aliases to non-alias track names",
623 [["string", "track", "Track name (might be an alias)"]],
624 ["resolved", "Resolve track name (definitely not an alias)"]);
627 "Resume the currently playing track",
628 "Requires the 'pause' right.",
633 "It will not subsequently be possible to log in with the cookie.",
634 []); # TODO fix docs!
639 "Terminate the playing track.",
640 "Requires one of the 'scratch mine', 'scratch random' or 'scratch any' rights depending on how the track came to be added to the queue.",
641 [["string", "id", "Track ID (optional)"]]);
645 simple("schedule-del",
646 "Delete a scheduled event.",
647 "Users can always delete their own scheduled events; with the admin right you can delete any event.",
648 [["string", "event", "ID of event to delete"]]);
652 list("schedule-list",
653 "List scheduled events",
654 "This just lists IDs. Use 'schedule-get' to retrieve more detail",
656 ["ids", "List of event IDs"]);
660 "Terms are either keywords or tags formatted as 'tag:TAG-NAME'.",
661 [["string", "terms", "List of search terms"]],
662 ["tracks", "List of matching tracks"]);
665 "Set a track preference",
666 "Requires the 'prefs' right.",
667 [["string", "track", "Track name"],
668 ["string", "pref", "Preference name"],
669 ["string", "value", "New value"]]);
672 "Set a global preference",
673 "Requires the 'global prefs' right.",
674 [["string", "pref", "Preference name"],
675 ["string", "value", "New value"]]);
678 "Request server shutdown",
679 "Requires the 'admin' right.",
683 "Get server statistics",
684 "The details of what the server reports are not really defined. The returned strings are intended to be printed out one to a line..",
686 ["stats", "List of server information strings."]);
689 "Get a list of known tags",
690 "Only tags which apply to at least one track are returned.",
692 ["tags", "List of tags"]);
695 "Unset a track preference",
696 "Requires the 'prefs' right.",
697 [["string", "track", "Track name"],
698 ["string", "pref", "Preference name"]]);
700 simple("unset-global",
701 "Set a global preference",
702 "Requires the 'global prefs' right.",
703 [["string", "pref", "Preference name"]]);
705 # 'user' only used for authentication
708 "Get a user property.",
709 "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.",
710 [["string", "username", "User to read"],
711 ["string", "property", "Property to read"]],
712 ["value", "Value of property"]);
715 "Get a list of users",
718 ["users", "List of users"]);
721 "Get the server version",
724 ["version", "Server version string"]);
728 # End matter ------------------------------------------------------------------
730 push(@h, "#endif\n");
732 # Write it all out ------------------------------------------------------------
734 Write("lib/client-stubs.h", \@h);
735 Write("lib/client-stubs.c", \@c);