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 # boolean(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] $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 ", int *$return->[0]);\n",
102 push(@c, "int disorder_$cmdc(disorder_client *c",
103 map(", const char *$_->[0]", @$args),
104 ", int *$return->[0]) {\n",
106 " int rc = disorder_simple(c, &v, \"$cmd\"",
107 map(", $_->[0]", @$args),
109 " if(rc) return rc;\n",
110 " if(!strcmp(v, \"yes\")) *$return->[0] = 1;\n",
111 " if(!strcmp(v, \"no\")) *$return->[0] = 0;\n",
113 " disorder_error(0, \"malformed response to '$cmd' command\");\n",
130 # TODO other command classes
132 # Front matter ----------------------------------------------------------------
135 " * This file is part of DisOrder.\n",
136 " * Copyright (C) 2010 Richard Kettlewell\n",
138 " * This program is free software: you can redistribute it and/or modify\n",
139 " * it under the terms of the GNU General Public License as published by\n",
140 " * the Free Software Foundation, either version 3 of the License, or\n",
141 " * (at your option) any later version.\n",
143 " * This program is distributed in the hope that it will be useful,\n",
144 " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
145 " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
146 " * GNU General Public License for more details.\n",
148 " * You should have received a copy of the GNU General Public License\n",
149 " * along with this program. If not, see <http://www.gnu.org/licenses/>.\n",
154 "#ifndef CLIENT_STUBS_H\n",
155 "#define CLIENT_STUBS_H\n",
161 # The protocol ----------------------------------------------------------------
165 "Makes the calling user owner of a randomly picked track.",
166 [["id", "Track ID"]]);
170 "Create a new user. Requires the 'admin' right. Email addresses etc must be filled in in separate commands.",
171 [["user", "New username"],
172 ["password", "Initial password"],
173 ["rights", "Initial rights (optional)"]]);
178 "Confirm user registration",
179 "The confirmation string is as returned by the register command.",
180 [["confirmation", "Confirmnation string"]]);
186 "Requires the 'admin' right.",
187 [["user", "User to delete"]]);
193 "Play will stop at the end of the current track, if one is playing. Requires the 'global prefs' right.",
197 "Set a user property",
198 "With the 'admin' right you can do anything. Otherwise you need the 'userinfo' right and can only set 'email' and 'password'.",
199 [["username", "User to modify"],
200 ["property", "Property name"],
201 ["value", "New property value"]]);
205 "Requires the 'global prefs' right.",
209 "Detect whether play is enabled",
212 ["enabled", "1 if play is enabled and 0 otherwise"]);
215 "Test whether a track exists",
217 [["track", "Track name"]],
218 ["exists", "1 if the track exists and 0 otherwise"]);
240 "Used as a keepalive. No authentication required.",
246 "Pause the currently playing track",
247 "Requires the 'pause' right.",
254 simple("playlist-delete",
256 "Requires the 'play' right and permission to modify the playlist.",
257 [["playlist", "Playlist to delete"]]);
261 # TODO playlist-get-share
263 simple("playlist-lock",
265 "Requires the 'play' right and permission to modify the playlist. A given connection may lock at most one playlist.",
266 [["playlist", "Playlist to delete"]]);
270 simple("playlist-set-share",
271 "Set a playlist's sharing status",
272 "Requires the 'play' right and permission to modify the playlist. ",
273 [["playlist", "Playlist to modify"],
274 ["share", "New sharing status ('public', 'private' or 'shared')"]]);
276 simple("playlist-unlock",
277 "Unlock the locked playlist playlist",
278 "The playlist to unlock is implicit in the connection.",
287 simple("random-disable",
288 "Disable random play",
289 "Requires the 'global prefs' right.",
292 simple("random-enable",
293 "Enable random play",
294 "Requires the 'global prefs' right.",
297 boolean("random-enabled",
298 "Detect whether random play is enabled",
299 "Random play counts as enabled even if play is disabled.",
301 ["enabled", "1 if random play is enabled and 0 otherwise"]);
303 # TODO random-enabled
307 simple("reconfigure",
308 "Re-read configuraiton file.",
309 "Requires the 'admin' right.",
315 "Send a password reminder.",
316 "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.",
317 [["username", "User to remind"]]);
320 "Remove a track form the queue.",
321 "Requires one of the 'remove mine', 'remove random' or 'remove any' rights depending on how the track came to be added to the queue.",
322 [["id", "Track ID"]]);
325 "Rescan all collections for new or obsolete tracks.",
326 "Requires the 'rescan' right.",
327 []); # TODO wait/fresh flags
332 "Resume the currently playing track",
333 "Requires the 'pause' right.",
338 "It will not subsequently be possible to log in with the cookie.",
339 [["cookie", "Cookie to revoke"]]);
344 "Terminate the playing track.",
345 "Requires one of the 'scratch mine', 'scratch random' or 'scratch any' rights depending on how the track came to be added to the queue.",
346 [["id", "Track ID (optional)"]]);
350 simple("schedule-del",
351 "Delete a scheduled event.",
352 "Users can always delete their own scheduled events; with the admin right you can delete any event.",
353 [["event", "ID of event to delete"]]);
362 "Set a track preference",
363 "Requires the 'prefs' right.",
364 [["track", "Track name"],
365 ["pref", "Preference name"],
366 ["value", "New value"]]);
369 "Set a global preference",
370 "Requires the 'global prefs' right.",
371 [["pref", "Preference name"],
372 ["value", "New value"]]);
379 "Unset a track preference",
380 "Requires the 'prefs' right.",
381 [["track", "Track name"],
382 ["pref", "Preference name"]]);
384 simple("unset-global",
385 "Set a global preference",
386 "Requires the 'global prefs' right.",
387 [["pref", "Preference name"]]);
389 # user is only used by connect functions
399 # End matter ------------------------------------------------------------------
401 push(@h, "#endif\n");
403 # Write it all out ------------------------------------------------------------
405 Write("client-stubs.h", \@h);
406 Write("client-stubs.c", \@c);