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 yes/no or failure
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(CMD, SUMMARY, DETAIL, [[NAME,DESCR], [NAME,DESCR], ...])
122 # Response is yes/no or failure
133 push(@h, "/** \@brief $summary\n",
137 map(" * \@param $_->[0] $_->[1]\n", @$args),
138 " * \@return 0 on success, non-0 on error\n",
140 "int disorder_$cmdc(disorder_client *c",
141 map(", const char *$_->[0]", @$args),
143 push(@c, "int disorder_$cmdc(disorder_client *c",
144 map(", const char *$_->[0]", @$args),
148 " if((rc = disorder_simple(c, &u, \"$cmd\"",
149 map(", $_->[0]", @$args),
166 # boolean(CMD, SUMMARY, DETAIL, [[NAME,DESCR], [NAME,DESCR], ...], [RETURN, DESCR])
168 # Response is yes/no or failure
179 push(@h, "/** \@brief $summary\n",
183 map(" * \@param $_->[0] $_->[1]\n", @$args),
184 " * \@param $return->[0]p $return->[1]\n",
185 " * \@return 0 on success, non-0 on error\n",
187 "int disorder_$cmdc(disorder_client *c",
188 map(", const char *$_->[0]", @$args),
189 ", int *$return->[0]p);\n",
191 push(@c, "int disorder_$cmdc(disorder_client *c",
192 map(", const char *$_->[0]", @$args),
193 ", int *$return->[0]p) {\n",
196 " if((rc = disorder_simple(c, &v, \"$cmd\"",
197 map(", $_->[0]", @$args),
200 " return boolean(\"$cmd\", v, $return->[0]p);\n",
213 # TODO other command classes
215 # Front matter ----------------------------------------------------------------
218 " * This file is part of DisOrder.\n",
219 " * Copyright (C) 2010 Richard Kettlewell\n",
221 " * This program is free software: you can redistribute it and/or modify\n",
222 " * it under the terms of the GNU General Public License as published by\n",
223 " * the Free Software Foundation, either version 3 of the License, or\n",
224 " * (at your option) any later version.\n",
226 " * This program is distributed in the hope that it will be useful,\n",
227 " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
228 " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
229 " * GNU General Public License for more details.\n",
231 " * You should have received a copy of the GNU General Public License\n",
232 " * along with this program. If not, see <http://www.gnu.org/licenses/>.\n",
237 "#ifndef CLIENT_STUBS_H\n",
238 "#define CLIENT_STUBS_H\n",
244 # The protocol ----------------------------------------------------------------
248 "Makes the calling user owner of a randomly picked track.",
249 [["id", "Track ID"]]);
253 "Create a new user. Requires the 'admin' right. Email addresses etc must be filled in in separate commands.",
254 [["user", "New username"],
255 ["password", "Initial password"],
256 ["rights", "Initial rights (optional)"]]);
260 string_login("confirm",
261 "Confirm registration",
262 "The confirmation string must have been created with 'register'. The username is returned so the caller knows who they are.",
263 [["confirmation", "Confirmation string"]]);
264 #TODO update docs - this logs you in
266 string_login("cookie",
267 "Log in with a cookie",
268 "The cookie must have been created with 'make-cookie'. The username is returned so the caller knows who they are.",
269 [["cookie", "Cookie string"]]);
273 "Requires the 'admin' right.",
274 [["user", "User to delete"]]);
280 "Play will stop at the end of the current track, if one is playing. Requires the 'global prefs' right.",
284 "Set a user property",
285 "With the 'admin' right you can do anything. Otherwise you need the 'userinfo' right and can only set 'email' and 'password'.",
286 [["username", "User to modify"],
287 ["property", "Property name"],
288 ["value", "New property value"]]);
292 "Requires the 'global prefs' right.",
296 "Detect whether play is enabled",
299 ["enabled", "1 if play is enabled and 0 otherwise"]);
302 "Test whether a track exists",
304 [["track", "Track name"]],
305 ["exists", "1 if the track exists and 0 otherwise"]);
310 "Get a track preference",
311 "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.",
312 [["track", "Track name"],
313 ["pref", "Preference name"]],
314 ["value", "Preference value"]);
317 "Get a global preference",
318 "If the preference does exist not then a null value is returned.",
319 [["pref", "Global preference name"]],
320 ["value", "Preference value"]);
326 string("make-cookie",
327 "Create a login cookie for this user",
328 "The cookie may be redeemed via the 'cookie' command",
330 ["cookie", "Newly created cookie"]);
340 "Used as a keepalive. No authentication required.",
344 "Get a track name part",
345 "If the name part cannot be constructed an empty string is returned.",
346 [["track", "Track name"],
347 ["context", "Context (\"sort\" or \"display\")"],
348 ["part", "Name part (\"artist\", \"album\" or \"title\")"]],
349 ["part", "Value of name part"]);
352 "Pause the currently playing track",
353 "Requires the 'pause' right.",
360 simple("playlist-delete",
362 "Requires the 'play' right and permission to modify the playlist.",
363 [["playlist", "Playlist to delete"]]);
367 # TODO playlist-get-share
369 simple("playlist-lock",
371 "Requires the 'play' right and permission to modify the playlist. A given connection may lock at most one playlist.",
372 [["playlist", "Playlist to delete"]]);
374 string("playlist-get-share",
375 "Get a playlist's sharing status",
376 "Requires the 'read' right and permission to read the playlist.",
377 [["playlist", "Playlist to read"]],
378 ["share", "Sharing status (\"public\", \"private\" or \"shared\")"]);
380 simple("playlist-set-share",
381 "Set a playlist's sharing status",
382 "Requires the 'play' right and permission to modify the playlist.",
383 [["playlist", "Playlist to modify"],
384 ["share", "New sharing status (\"public\", \"private\" or \"shared\")"]]);
386 simple("playlist-unlock",
387 "Unlock the locked playlist playlist",
388 "The playlist to unlock is implicit in the connection.",
397 simple("random-disable",
398 "Disable random play",
399 "Requires the 'global prefs' right.",
402 simple("random-enable",
403 "Enable random play",
404 "Requires the 'global prefs' right.",
407 boolean("random-enabled",
408 "Detect whether random play is enabled",
409 "Random play counts as enabled even if play is disabled.",
411 ["enabled", "1 if random play is enabled and 0 otherwise"]);
415 simple("reconfigure",
416 "Re-read configuraiton file.",
417 "Requires the 'admin' right.",
421 "Register a new user",
422 "Requires the 'register' right which is usually only available to the 'guest' user. Redeem the confirmation string via 'confirm' to complete registration.",
423 [["username", "Requested new username"],
424 ["password", "Requested initial password"],
425 ["email", "New user's email address"]],
426 ["confirmation", "Confirmation string"]);
429 "Send a password reminder.",
430 "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.",
431 [["username", "User to remind"]]);
434 "Remove a track form the queue.",
435 "Requires one of the 'remove mine', 'remove random' or 'remove any' rights depending on how the track came to be added to the queue.",
436 [["id", "Track ID"]]);
439 "Rescan all collections for new or obsolete tracks.",
440 "Requires the 'rescan' right.",
441 []); # TODO wait/fresh flags
444 "Resolve a track name",
445 "Converts aliases to non-alias track names",
446 [["track", "Track name (might be an alias)"]],
447 ["resolved", "Resolve track name (definitely not an alias)"]);
450 "Resume the currently playing track",
451 "Requires the 'pause' right.",
456 "It will not subsequently be possible to log in with the cookie.",
457 []); # TODO fix docs!
462 "Terminate the playing track.",
463 "Requires one of the 'scratch mine', 'scratch random' or 'scratch any' rights depending on how the track came to be added to the queue.",
464 [["id", "Track ID (optional)"]]);
468 simple("schedule-del",
469 "Delete a scheduled event.",
470 "Users can always delete their own scheduled events; with the admin right you can delete any event.",
471 [["event", "ID of event to delete"]]);
480 "Set a track preference",
481 "Requires the 'prefs' right.",
482 [["track", "Track name"],
483 ["pref", "Preference name"],
484 ["value", "New value"]]);
487 "Set a global preference",
488 "Requires the 'global prefs' right.",
489 [["pref", "Preference name"],
490 ["value", "New value"]]);
492 # TODO shutdown (also needs documenting)
499 "Unset a track preference",
500 "Requires the 'prefs' right.",
501 [["track", "Track name"],
502 ["pref", "Preference name"]]);
504 simple("unset-global",
505 "Set a global preference",
506 "Requires the 'global prefs' right.",
507 [["pref", "Preference name"]]);
512 "Get a user property.",
513 "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.",
514 [["username", "User to read"],
515 ["property", "Property to read"]],
516 ["value", "Value of property"]);
521 "Get the server version",
524 ["version", "Server version string"]);
528 # End matter ------------------------------------------------------------------
530 push(@h, "#endif\n");
532 # Write it all out ------------------------------------------------------------
534 Write("lib/client-stubs.h", \@h);
535 Write("lib/client-stubs.c", \@c);