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 -------------------------------------------------------------
38 # simple(CMD, SUMMARY, DETAIL, [[NAME,DESCR], [NAME,DESCR], ...],)
40 # Response is simply success/failure
50 push(@h, "/** \@brief $summary\n",
54 map(" * \@param $_->[0] $_->[1]\n", @$args),
55 " * \@return 0 on success, non-0 on error\n",
57 "int disorder_$cmdc(disorder_client *c",
58 map(", const char *$_->[0]", @$args), ");\n",
60 push(@c, "int disorder_$cmdc(disorder_client *c",
61 map(", const char *$_->[0]", @$args), ") {\n",
62 " return disorder_simple(c, 0, \"$cmd\"",
63 map(", $_->[0]", @$args),
77 # string(CMD, SUMMARY, DETAIL, [[NAME,DESCR], [NAME,DESCR], ...], [RETURN, DESCR])
79 # Response is a string, or failure, or 555 for "none".
90 push(@h, "/** \@brief $summary\n",
94 map(" * \@param $_->[0] $_->[1]\n", @$args),
95 " * \@param $return->[0]p $return->[1]\n",
96 " * \@return 0 on success, non-0 on error\n",
98 "int disorder_$cmdc(disorder_client *c",
99 map(", const char *$_->[0]", @$args),
100 ", char **$return->[0]p);\n",
102 push(@c, "int disorder_$cmdc(disorder_client *c",
103 map(", const char *$_->[0]", @$args),
104 ", char **$return->[0]p) {\n",
105 " return dequote(disorder_simple(c, $return->[0]p, \"$cmd\"",
106 map(", $_->[0]", @$args),
107 ", (char *)0), $return->[0]p);\n",
120 # string_login(CMD, SUMMARY, DETAIL, [[NAME,DESCR], [NAME,DESCR], ...])
122 # Like string(), but the server returns a username, which we squirrel
123 # away rather than returning to the caller.
134 push(@h, "/** \@brief $summary\n",
138 map(" * \@param $_->[0] $_->[1]\n", @$args),
139 " * \@return 0 on success, non-0 on error\n",
141 "int disorder_$cmdc(disorder_client *c",
142 map(", const char *$_->[0]", @$args),
144 push(@c, "int disorder_$cmdc(disorder_client *c",
145 map(", const char *$_->[0]", @$args),
149 " if((rc = disorder_simple(c, &u, \"$cmd\"",
150 map(", $_->[0]", @$args),
167 # boolean(CMD, SUMMARY, DETAIL, [[NAME,DESCR], [NAME,DESCR], ...], [RETURN, DESCR])
169 # Response is yes/no or failure
180 push(@h, "/** \@brief $summary\n",
184 map(" * \@param $_->[0] $_->[1]\n", @$args),
185 " * \@param $return->[0]p $return->[1]\n",
186 " * \@return 0 on success, non-0 on error\n",
188 "int disorder_$cmdc(disorder_client *c",
189 map(", const char *$_->[0]", @$args),
190 ", int *$return->[0]p);\n",
192 push(@c, "int disorder_$cmdc(disorder_client *c",
193 map(", const char *$_->[0]", @$args),
194 ", int *$return->[0]p) {\n",
197 " if((rc = disorder_simple(c, &v, \"$cmd\"",
198 map(", $_->[0]", @$args),
201 " return boolean(\"$cmd\", v, $return->[0]p);\n",
214 # integer(CMD, SUMMARY, DETAIL, [[NAME,DESCR], [NAME,DESCR], ...], [RETURN, DESCR])
216 # Response is an integer, or failure
227 push(@h, "/** \@brief $summary\n",
231 map(" * \@param $_->[0] $_->[1]\n", @$args),
232 " * \@param $return->[0]p $return->[1]\n",
233 " * \@return 0 on success, non-0 on error\n",
235 "int disorder_$cmdc(disorder_client *c",
236 map(", const char *$_->[0]", @$args),
237 ", long *$return->[0]p);\n",
239 push(@c, "int disorder_$cmdc(disorder_client *c",
240 map(", const char *$_->[0]", @$args),
241 ", long *$return->[0]p) {\n",
245 " if((rc = disorder_simple(c, &v, \"$cmd\"",
246 map(", $_->[0]", @$args),
249 " *$return->[0]p = atol(v);\n",
264 # list(CMD, SUMMARY, DETAIL, [[NAME,DESCR], [NAME,DESCR], ...], [RETURN, DESCR])
266 # Response is a a list of strings in a dot-stuffed body
277 push(@h, "/** \@brief $summary\n",
281 map(" * \@param $_->[0] $_->[1]\n", @$args),
282 " * \@param $return->[0]p $return->[1]\n",
283 " * \@param n$return->[0]p Number of elements in $return->[0]p\n",
284 " * \@return 0 on success, non-0 on error\n",
286 "int disorder_$cmdc(disorder_client *c",
287 map(", const char *$_->[0]", @$args),
288 ", char ***$return->[0]p, int *n$return->[0]p);\n",
290 push(@c, "int disorder_$cmdc(disorder_client *c",
291 map(", const char *$_->[0]", @$args),
292 ", char ***$return->[0]p, int *n$return->[0]p) {\n",
293 " return disorder_simple_list(c, $return->[0]p, n$return->[0]p, \"$cmd\"",
294 map(", $_->[0]", @$args),
308 # TODO other command classes
310 # Front matter ----------------------------------------------------------------
313 " * This file is part of DisOrder.\n",
314 " * Copyright (C) 2010 Richard Kettlewell\n",
316 " * This program is free software: you can redistribute it and/or modify\n",
317 " * it under the terms of the GNU General Public License as published by\n",
318 " * the Free Software Foundation, either version 3 of the License, or\n",
319 " * (at your option) any later version.\n",
321 " * This program is distributed in the hope that it will be useful,\n",
322 " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
323 " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
324 " * GNU General Public License for more details.\n",
326 " * You should have received a copy of the GNU General Public License\n",
327 " * along with this program. If not, see <http://www.gnu.org/licenses/>.\n",
332 "#ifndef CLIENT_STUBS_H\n",
333 "#define CLIENT_STUBS_H\n",
339 # The protocol ----------------------------------------------------------------
343 "Makes the calling user owner of a randomly picked track.",
344 [["id", "Track ID"]]);
348 "Create a new user. Requires the 'admin' right. Email addresses etc must be filled in in separate commands.",
349 [["user", "New username"],
350 ["password", "Initial password"],
351 ["rights", "Initial rights (optional)"]]);
354 "List files and directories in a directory",
355 "See 'files' and 'dirs' for more specific lists.",
356 [["dir", "Directory to list (optional)"],
357 ["re", "Regexp that results must match (optional)"]],
358 ["files", "List of matching files and directories"]);
360 string_login("confirm",
361 "Confirm registration",
362 "The confirmation string must have been created with 'register'. The username is returned so the caller knows who they are.",
363 [["confirmation", "Confirmation string"]]);
365 string_login("cookie",
366 "Log in with a cookie",
367 "The cookie must have been created with 'make-cookie'. The username is returned so the caller knows who they are.",
368 [["cookie", "Cookie string"]]);
372 "Requires the 'admin' right.",
373 [["user", "User to delete"]]);
376 "List directories in a directory",
378 [["dir", "Directory to list (optional)"],
379 ["re", "Regexp that results must match (optional)"]],
380 ["files", "List of matching directories"]);
384 "Play will stop at the end of the current track, if one is playing. Requires the 'global prefs' right.",
388 "Set a user property",
389 "With the 'admin' right you can do anything. Otherwise you need the 'userinfo' right and can only set 'email' and 'password'.",
390 [["username", "User to modify"],
391 ["property", "Property name"],
392 ["value", "New property value"]]);
396 "Requires the 'global prefs' right.",
400 "Detect whether play is enabled",
403 ["enabled", "1 if play is enabled and 0 otherwise"]);
406 "Test whether a track exists",
408 [["track", "Track name"]],
409 ["exists", "1 if the track exists and 0 otherwise"]);
412 "List files in a directory",
414 [["dir", "Directory to list (optional)"],
415 ["re", "Regexp that results must match (optional)"]],
416 ["files", "List of matching files"]);
419 "Get a track preference",
420 "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.",
421 [["track", "Track name"],
422 ["pref", "Preference name"]],
423 ["value", "Preference value"]);
426 "Get a global preference",
427 "If the preference does exist not then a null value is returned.",
428 [["pref", "Global preference name"]],
429 ["value", "Preference value"]);
432 "Get a track's length",
433 "If the track does not exist an error is returned.",
434 [["track", "Track name"]],
435 ["length", "Track length in seconds"]);
439 string("make-cookie",
440 "Create a login cookie for this user",
441 "The cookie may be redeemed via the 'cookie' command",
443 ["cookie", "Newly created cookie"]);
453 "Used as a keepalive. No authentication required.",
457 "Get a track name part",
458 "If the name part cannot be constructed an empty string is returned.",
459 [["track", "Track name"],
460 ["context", "Context (\"sort\" or \"display\")"],
461 ["part", "Name part (\"artist\", \"album\" or \"title\")"]],
462 ["part", "Value of name part"]);
465 "Pause the currently playing track",
466 "Requires the 'pause' right.",
471 "Requires the 'play' right.",
472 [["track", "Track to play"]],
473 ["id", "Queue ID of new track"]);
479 simple("playlist-delete",
481 "Requires the 'play' right and permission to modify the playlist.",
482 [["playlist", "Playlist to delete"]]);
485 "List the contents of a playlist",
486 "Requires the 'read' right and oermission to read the playlist.",
487 [["playlist", "Playlist name"]],
488 ["tracks", "List of tracks in playlist"]);
490 string("playlist-get-share",
491 "Get a playlist's sharing status",
492 "Requires the 'read' right and permission to read the playlist.",
493 [["playlist", "Playlist to read"]],
494 ["share", "Sharing status (\"public\", \"private\" or \"shared\")"]);
496 simple("playlist-lock",
498 "Requires the 'play' right and permission to modify the playlist. A given connection may lock at most one playlist.",
499 [["playlist", "Playlist to delete"]]);
501 simple("playlist-set-share",
502 "Set a playlist's sharing status",
503 "Requires the 'play' right and permission to modify the playlist.",
504 [["playlist", "Playlist to modify"],
505 ["share", "New sharing status (\"public\", \"private\" or \"shared\")"]]);
507 simple("playlist-unlock",
508 "Unlock the locked playlist playlist",
509 "The playlist to unlock is implicit in the connection.",
514 "Requires the 'read' right. Only playlists that you have permission to read are returned.",
516 ["playlists", "Playlist names"]);
522 simple("random-disable",
523 "Disable random play",
524 "Requires the 'global prefs' right.",
527 simple("random-enable",
528 "Enable random play",
529 "Requires the 'global prefs' right.",
532 boolean("random-enabled",
533 "Detect whether random play is enabled",
534 "Random play counts as enabled even if play is disabled.",
536 ["enabled", "1 if random play is enabled and 0 otherwise"]);
540 simple("reconfigure",
541 "Re-read configuraiton file.",
542 "Requires the 'admin' right.",
546 "Register a new user",
547 "Requires the 'register' right which is usually only available to the 'guest' user. Redeem the confirmation string via 'confirm' to complete registration.",
548 [["username", "Requested new username"],
549 ["password", "Requested initial password"],
550 ["email", "New user's email address"]],
551 ["confirmation", "Confirmation string"]);
554 "Send a password reminder.",
555 "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.",
556 [["username", "User to remind"]]);
559 "Remove a track form the queue.",
560 "Requires one of the 'remove mine', 'remove random' or 'remove any' rights depending on how the track came to be added to the queue.",
561 [["id", "Track ID"]]);
564 "Rescan all collections for new or obsolete tracks.",
565 "Requires the 'rescan' right.",
566 []); # TODO wait/fresh flags
569 "Resolve a track name",
570 "Converts aliases to non-alias track names",
571 [["track", "Track name (might be an alias)"]],
572 ["resolved", "Resolve track name (definitely not an alias)"]);
575 "Resume the currently playing track",
576 "Requires the 'pause' right.",
581 "It will not subsequently be possible to log in with the cookie.",
582 []); # TODO fix docs!
587 "Terminate the playing track.",
588 "Requires one of the 'scratch mine', 'scratch random' or 'scratch any' rights depending on how the track came to be added to the queue.",
589 [["id", "Track ID (optional)"]]);
593 simple("schedule-del",
594 "Delete a scheduled event.",
595 "Users can always delete their own scheduled events; with the admin right you can delete any event.",
596 [["event", "ID of event to delete"]]);
600 list("schedule-list",
601 "List scheduled events",
602 "This just lists IDs. Use 'schedule-get' to retrieve more detail",
604 ["ids", "List of event IDs"]);
608 "Terms are either keywords or tags formatted as 'tag:TAG-NAME'.",
609 [["terms", "List of search terms"]],
610 ["tracks", "List of matching tracks"]);
613 "Set a track preference",
614 "Requires the 'prefs' right.",
615 [["track", "Track name"],
616 ["pref", "Preference name"],
617 ["value", "New value"]]);
620 "Set a global preference",
621 "Requires the 'global prefs' right.",
622 [["pref", "Preference name"],
623 ["value", "New value"]]);
626 "Request server shutdown",
627 "Requires the 'admin' right.",
631 "Get server statistics",
632 "The details of what the server reports are not really defined. The returned strings are intended to be printed out one to a line..",
634 ["stats", "List of server information strings."]);
637 "Get a list of known tags",
638 "Only tags which apply to at least one track are returned.",
640 ["tags", "List of tags"]);
643 "Unset a track preference",
644 "Requires the 'prefs' right.",
645 [["track", "Track name"],
646 ["pref", "Preference name"]]);
648 simple("unset-global",
649 "Set a global preference",
650 "Requires the 'global prefs' right.",
651 [["pref", "Preference name"]]);
656 "Get a user property.",
657 "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.",
658 [["username", "User to read"],
659 ["property", "Property to read"]],
660 ["value", "Value of property"]);
663 "Get a list of users",
666 ["users", "List of users"]);
669 "Get the server version",
672 ["version", "Server version string"]);
676 # End matter ------------------------------------------------------------------
678 push(@h, "#endif\n");
680 # Write it all out ------------------------------------------------------------
682 Write("lib/client-stubs.h", \@h);
683 Write("lib/client-stubs.c", \@c);