Commit Graph

282 Commits

Author SHA1 Message Date
Eric Wollesen
b8ebb748c9 Add sticker list command.
[mk: merged memory leak patch; fixed indentation (tabs); fixed
documentation typo]
2009-03-03 07:49:23 +01:00
Max Kellermann
75c2029b1c tag: no CamelCase
Renamed numOfItems to num_items.
2009-02-27 09:01:55 +01:00
Max Kellermann
6823217697 ls: moved generic URI utilities to uri.c
"ls" is a bad name for a library which parses URIs.  We'll move the
rest of the "ls" library later.
2009-02-25 16:44:06 +01:00
Romain Bignon
9fe459f625 added the shufflerange command
This command shuffles a range of songs.
2009-02-13 10:43:30 +01:00
Max Kellermann
9d447dda1d audio: moved code to output_command.c
The output_command library provides a command interface to the audio
outputs.  It assumes the input comes from an untrusted source
(i.e. the client) and verifies all parameters.
2009-02-11 18:02:45 +01:00
Max Kellermann
e7505381eb audio: moved protocol code to output_print.c 2009-02-10 18:51:42 +01:00
Vladimir S Eremin
cde4cb944e playlist: provide information about "next song"
In random mode, this patch allows clients to see the "next song" in
the queue.
2009-02-09 10:38:03 +01:00
Max Kellermann
94685aa9bd playlist_save: added spl_save_playlist()
spl_save_playlist() is a wrapper for spl_save_queue().
2009-02-04 22:15:37 +01:00
Max Kellermann
2a1bef2225 playlist_print: added wrappers for printing the queue
Hide the details of the playlist behind wrapper functions.
2009-02-04 22:09:04 +01:00
Max Kellermann
60bec77664 playlist_print: use bool instead of int
Return true on success, instead of 0.  Converted the "detail"
parameter to bool.
2009-02-04 21:04:30 +01:00
Max Kellermann
f817285922 playlist_print: no CamelCase
Renamed one function.
2009-02-04 21:02:11 +01:00
Max Kellermann
8d3205871c playlist: renamed global "playlist" variable to "g_playlist"
Export the "g_playlist" variable, and pass it to all playlist
functions.  This way, we can split playlist.c easier into separate
parts.  The code which initializes the singleton variable is moved to
playlist_global.c.
2009-02-04 18:56:41 +01:00
Max Kellermann
98cb8f3969 playlist: moved savePlaylist() and loadPlaylsit() to playlist_save.c 2009-01-25 14:11:47 +01:00
Max Kellermann
6a2118d04c queue_print, dbUtils: use struct locate_item_list
Changed the function prototypes to get locate_item_list objects
instead of num_items/items.
2009-01-24 15:56:34 +01:00
Max Kellermann
ba7c996266 locate: added struct locate_item_list
Instead of passing two parameters around (number of items, array of
items), combine both in a variable size struct.
2009-01-24 15:56:30 +01:00
Max Kellermann
3582977e01 locate: no CamelCase
Renamed functions and variables.
2009-01-24 15:26:59 +01:00
Max Kellermann
cf9595df18 playlist: removed locate functions to queue_print.c
Now playlist.c does not contain any protocol specific code anymore.
2009-01-24 14:55:28 +01:00
Max Kellermann
53e712aca4 locate: renamed LocateTagItem to "struct locate_item"
No CamelCase and no typedefs.
2009-01-24 14:52:05 +01:00
Max Kellermann
627d590ce5 command: use queue_print_*()
Replaced several wrapper functions from playlist.c, and make command.c
use the queue print functions directly.
2009-01-24 14:52:04 +01:00
Laszlo Ashin
84b63c45fa command: eliminate gcc warning
Argument cmd of function command_available() is not used if mpd was
configured without sqlite.
2009-01-24 11:13:58 +01:00
Max Kellermann
48d3404727 commands: don't advertise "sticker" unless configured
In the return value of the "commands" command, don't list the
"sticker" command if no sticker file is configured.
2009-01-23 18:51:14 +01:00
Max Kellermann
8afe24c1de playlist: moved PlaylistInfo() to playlist_print.c
PlaylistInfo() (notice the capital 'P') sends a stored playlist to the
client.  Move it to a separate library, where all the code which glues
the playlist and the MPD protocol together will live.
2009-01-23 16:34:27 +01:00
Max Kellermann
e5c323fd57 playlist: removed stopOnError flag from playPlaylist()
All callers pass false.  Don't bother to collect that parameter.
2009-01-23 00:10:50 +01:00
Max Kellermann
5541015ac6 command: don't restart player in the "status" command
Don't attempt to restart the player if it was stopped, but there were
still songs left on the playlist.  This looks like it has been a
workaround for a bug which has been fixed long time ago.
2009-01-21 16:17:57 +01:00
Qball Cow
d10910cc90 Add space after sticker: to make it consistent. 2009-01-20 13:55:21 +01:00
Max Kellermann
f9c693e602 command: added "sticker" command
The "sticker" command allows clients to query or manipulate the
sticker database.  This patch implements the sub-commands "get" and
"set"; more will follow soon (enumeration), as well as extended
"lsinfo" / "playlistinfo" versions.
2009-01-19 19:09:49 +01:00
Max Kellermann
9933144de7 mapper: make the playlist directory optional 2009-01-18 16:15:45 +01:00
Max Kellermann
0d449d8df7 stats: no CamelCase
Renamed functions and types.
2009-01-18 15:22:26 +01:00
Max Kellermann
983822ea52 command: restore the "playlistinfo -1" behavior
If a range is "-1", display the whole list.  This behavior is
undocumented, but some clients rely on it.
2009-01-11 17:11:11 +01:00
Max Kellermann
8ebe7bfb25 playlist: pass unsigned integers to playlistInfo()
A song index cannot be negative.  Also require the second parameter to
be valid.
2009-01-10 17:39:49 +01:00
Max Kellermann
b7c4b78846 playlist: exclude end of range
In a range "start:end", "end" itself should not be included.  Use the
same semantics as other languages implementing ranges, e.g. Python.
2009-01-10 17:05:03 +01:00
Thomas Jansen
6f0781f039 command: playlistinfo now uses a range argument rather than just a song id
Loosely based on a patch provided by lesion in bug #1766. The playlistinfo
command can now retrieve ranges of the playlist. The new argument indicates
which entry is the last one that will be displayed. The number of displayed
entries may be smaller than expected if the end of the playlist is reached.

Previous usage:
playlistinfo [start]

New usage:
playlistinfo [start[:end]]
2009-01-10 16:50:34 +01:00
Thomas Jansen
8ed3cf3e6b command: add a parser for range arguments
A range argument looks like start[:end] and is used to specify the entries
of a list that should be returned (rather than the whole list).
2009-01-10 16:48:12 +01:00
Max Kellermann
5e93d3682f added missing explicit config.h includes 2009-01-08 21:37:02 +01:00
Max Kellermann
8c5470a3db playlist: log errors during loadPlaylist()
Don't call command_error() if loading a song from the playlist fails.
This may result in assertion failures, since command_error() may be
called more than once.
2009-01-04 18:59:32 +01:00
Max Kellermann
45597cc571 ls: renamed functions, no CamelCase 2009-01-04 17:46:42 +01:00
Max Kellermann
7d87f71d83 command: check URI scheme in "addid"
Check if the URI scheme is supported by MPD, and print an error
message if not.  Optimize the checks in "add" and "playlistadd".
2009-01-04 16:22:08 +01:00
Max Kellermann
ef0b328a3c command: added variable "uri" to command handlers
Don't work with argv[1], give it the better name "uri".
2009-01-04 16:19:45 +01:00
Max Kellermann
dec4e4ca85 don't include utils.h when it isn't used 2009-01-03 14:52:56 +01:00
Max Kellermann
2cf96abcc1 command: fix adding local files on !WIN32
Due to a typo, adding local files was always denied.

Disable the second playlist_append_file() invocation on WIN32.
2009-01-03 12:29:42 +01:00
Viliam Mateicka
9a70c4d06d Moving mixers to audio outputs 2008-12-31 16:46:41 +01:00
Max Kellermann
bb55ec6b4e command: don't allow adding local files on WIN32
There are no unix sockets on WIN32, and therefore no authentication.
WIN32 might have similar capabilities, but until we implement them,
disable that MPD feature.
2008-12-30 19:14:13 +01:00
Max Kellermann
95b3430f52 removed os_compat.h
Only include headers which are really needed.  os_compat.h aimed to
make MPD easily portable, but was never actually made portable.
2008-12-29 17:28:32 +01:00
Max Kellermann
041b8f697b command: use gmtime() on WIN32
gmtime_r() is not available.
2008-12-29 17:28:13 +01:00
Max Kellermann
5aa1afe693 command: reject unsupported URI schemes
When a client-specified URI has a scheme which is not supported, do
not try to open it as a local file, but provide a meaningful error
message.
2008-12-16 21:23:29 +01:00
Max Kellermann
1d82edc6d3 ls: make printRemoteUrlHandlers() return void
printRemoteUrlHandlers() cannot fail, and does not need a return
value.
2008-12-16 21:18:31 +01:00
Thomas Jansen
c06ce44768 replaced mpd_printf etc by G_GNUC_PRINTF
We want to remove gcc.h eventually. This takes care of all the G_GNUC_PRINTF
macros.
2008-12-02 03:00:02 +01:00
Thomas Jansen
bc74503a69 command.c: replaced mpd_unused by G_GNUC_UNUSED 2008-11-24 14:55:32 +01:00
Max Kellermann
d0779e71ab command: format strerror() with "%s"
We shouldn't pass strerror() where a format string is expected.
2008-11-22 14:57:00 +01:00
Marc Pavot
0bad84066b command: allow clients to subscribe to specific idle events
The client may provide the names of idle events as arguments to the
"idle" command to inform MPD that it is only interested in these
events.
2008-11-22 13:26:21 +01:00
Max Kellermann
9fdac529b4 path: removed sanitizePathDup()
We don't need to sanitize the path, because the mapper already checks
for malformed paths.
2008-10-31 16:50:51 +01:00
Max Kellermann
90e9079142 client: use GSList instead of struct strnode for command lists
Replace a custom data structure with a GLib one.
2008-10-31 09:17:56 +01:00
Max Kellermann
4fa36a15bf command: removed range check from check_bool()
check_bool() accepts only "0" or "1".  The range check is superfluous.
2008-10-26 16:19:33 +01:00
Max Kellermann
098991f8e8 command: fix boolean value parser
Due to a logic error, no value was valid for the boolean value
parser.  Replace "||" with "&&".
2008-10-23 18:06:05 +02:00
Max Kellermann
93598e28f4 stored_playlist: renamed and moved spl_delete() to stored_playlist.c
The function deletePlaylist() shouldn't be in playlist.c.
2008-10-23 09:54:32 +02:00
Max Kellermann
e172874cc6 command: check over/underflows in check_int()
The "long" result of strtol() was implicitly casted down to a 32 bit
integer.  Add some range checking instead.
2008-10-23 09:54:10 +02:00
Max Kellermann
95ae1d9e9e command: added check_unsigned() / check_bool()
Many command arguments must not be negative; add a separate
parser/checker function for that.  For the same reason, add
check_bool().  This eliminates two strange special cases handlers from
check_int().
2008-10-23 09:53:35 +02:00
Max Kellermann
bc938603f6 playlist: unsigned integers
There are some integers which have a "magic" -1 value which means
"undefined" or "nothing".  All others can be converted to unsigned,
since they must not contain a negative number.
2008-10-23 07:19:46 +02:00
Max Kellermann
890b067346 command: use the bool datatype instead of int
Instead of returning 0 for success and -1 for failure, return true or
false.  This seems more natural.
2008-10-22 21:41:54 +02:00
Max Kellermann
d4f3c09081 command: converted COMMAND_RETURN_* macros to enum
Also add names for "error" and "ok".  I don't like passing anonymous
integer codes around.

This is not yet complete: lots of functions (e.g. in playlist.c)
follow the same convention of -1/0, and these have to be adapted, too.
2008-10-22 21:41:49 +02:00
Max Kellermann
d11ee6580c command: replaced "goto" with "break"
http://xkcd.com/292/
2008-10-22 21:40:58 +02:00
Max Kellermann
51a6ee88f7 command: no CamelCase
Eliminate CamelCase in all public and static functions.
2008-10-22 21:40:44 +02:00
Max Kellermann
69c563b511 command: removed CommandHandlerFunction typedef
The typedef CommandHandlerFunction is only used once.  Move its type
into the command struct.
2008-10-22 21:40:36 +02:00
Max Kellermann
d0a9dcdcf5 ack: converted ACK_ERROR_* macros to enum 2008-10-22 21:40:32 +02:00
Max Kellermann
7aca4cd194 stored_playlist: send timestamps
Send last modification timestamps to the client.  This allows the
client to see when another client modifies a stored playlist.
2008-10-22 19:18:39 +02:00
Max Kellermann
9c983c442c command: added command "listplaylists"
"listplaylists" returns a list of all stored playlists.  This command
seems more elaborate than listing them below "lsinfo".
2008-10-22 19:16:56 +02:00
Max Kellermann
f8e586402d command: added print_spl_list()
The function print_spl_list() replaces the old function lsPlaylists()
from ls.c.
2008-10-22 19:16:35 +02:00
Max Kellermann
d2606baa79 stored_playlist: de-CamelCase moved function
Rename addToStoredPlaylist() to spl_append_uri(), and remove the
clearStoredPlaylist() macro.
2008-10-22 17:23:58 +02:00
Max Kellermann
ac853b6165 stored_playlist: no CamelCase
Renamed all public functions, prefix is "spl_".
2008-10-22 17:21:59 +02:00
Max Kellermann
a4def81313 renamed storedPlaylist.c to stored_playlist.c
No CamelCase in file names.
2008-10-22 17:21:57 +02:00
Max Kellermann
1c62e2cd62 command: added "commands" array instead of registering manually
The list of commands is known at compile time.  Instead of creating a
linked list on startup, we can just register all commands in a static
sorted array.
2008-10-22 10:08:14 +02:00
Max Kellermann
84d0f56eaf command: make command pointers constant
The command pointers which are passed around aren't being modified -
in fact, no command pointer must be modified once it has been added to
the commandList.
2008-10-22 09:59:01 +02:00
Max Kellermann
4b4f7df933 command: renamed CommandEntry to struct command
No CamelCase and no struct typedefs.
2008-10-22 09:58:13 +02:00
Max Kellermann
02a2a407c1 client: converted permissions to unsigned
client->permission is a bit set, and should be unsigned.
2008-10-17 23:53:28 +02:00
Max Kellermann
7ca19736c9 command: expect "file:///" url for local files
When adding a local file, clients have to use the "file" URI schema
described in RFC 1738 3.10.  By adding this schema to "urlhandlers", a
client can detect whether this feature is available.
2008-10-17 17:53:43 +02:00
Max Kellermann
beec15ddaa command: special case for "add /"
The undocumented command "add /" adds the full music database to the
playlist.  Don't interpret this special path as a local file path.
2008-10-16 07:40:34 +02:00
Max Kellermann
8c0060fae4 playlist: added support for adding songs not in the music database
Clients which have authenticated via unix socket may add local files
to the MPD playlist, provided that they own the file.
2008-10-15 22:35:13 +02:00
Max Kellermann
0b44cad2ce command: print error message on "addid" failure
Returning the playlist_result value from a command handler does not
make sense.  Call print_playlist_result() there, and forward its
return value.
2008-10-15 22:35:04 +02:00
Max Kellermann
a3e3d2c950 command: added command "idle"
"idle" waits until something noteworthy happens on the server,
e.g. song change, playlist modified, database updated.  This allows
clients to keep up to date without polling.
2008-10-14 22:38:14 +02:00
Max Kellermann
5de7521900 player: added player_get_audio_format()
player_get_audio_format() replaces getPlayerSampleRate(),
getPlayerBits(), getPlayerChannels().
2008-10-10 14:51:22 +02:00
Max Kellermann
0b4dfae22e player: added player_control.audio_format
This replaces the attributes bits, channels, sampleRate.
2008-10-10 14:47:58 +02:00
Max Kellermann
4beba26c61 update: make the job id unsigned
Since the return value cannot be -1 anymore, we can make it unsigned.
2008-10-09 19:20:05 +02:00
Max Kellermann
f1022bcc12 update: job ID must be positive
The documentation for directory_update_init() was incorrect: a job ID
must be positive, not non-negative.  If the update queue is full and
no job was created, it makes more sense to return 0 instead of -1,
because it is more consistent with the return value of isUpdatingDB().
2008-10-09 19:17:44 +02:00
Max Kellermann
a0c044df11 diretory: moved code to directory_save.c, directory_print.c
Remove clutter from directory.c.  Everything which saves or loads
to/from the hard disk goes to directory_save.c, and code which sends
directory information to the client is moved into directory_print.c.
2008-10-09 15:23:37 +02:00
Qball Cow
ecc3c39e2f Fix error code for "Playlist already exists"
With commit 6dcd7fea (if I am not mistaken) the error returned when
you try to save to an existing playlist is wrong.  Instead of
MPD_ACK_ERROR_EXIST, MPD_ACK_ERROR_NO_EXIST is returned.  This is
obviously wrong and breaks gmpc.
2008-10-09 11:51:22 +02:00
Max Kellermann
bb8a9533b1 database: renamed functions, "db_" prefix and no CamelCase
Yet another CamelCase removal patch.
2008-10-08 11:07:55 +02:00
Max Kellermann
7a023eb0b2 database: removed printDirectoryInfo()
The same can be achieved with directory_print(db_get_directory()).
2008-10-08 11:07:39 +02:00
Max Kellermann
8a50e8a266 directory: moved code to database.c
Taming the directory.c monster, part II: move the database management
stuff to database.  directory.c should only contain code which works
on directory objects.
2008-10-08 11:07:35 +02:00
Max Kellermann
7b9bed8398 directory: moved code to update.c
The source directory.c mixes several libraries: directory object
management, database management and database update, resulting in a
1000+ line monster.  Move the whole database update code to update.c.
2008-10-08 10:48:48 +02:00
Eric Wong
d51da61b2d command: fix return status
This got broken when listHandlerFunc was removed.  Since we no
longer need it and it's confusing, remove processCommandInternal
and just use process_command.
2008-10-06 18:39:33 +02:00
Eric Wong
8faf648784 command: get rid of specialized list handlers
commands should really not behave differently if they're issued
inside a command list or not; so stop having special handler
functions to deal with them.  "update" was the only command
that used this functionality and I changed that in the last
commit to serialize access.
2008-10-06 18:34:18 +02:00
Eric Wong
37a8239f44 directory: simplify list update handling logic
Now the "update" command can be issued multiple times regardless
of whether the client is in list mode or not.

We serialize the update tasks to prevent updates from trampling
over each other and will spawn another update task
once the current one is finished updating and reaped.

Right now we cap the queue size to 32 which is probably enough (I
bet most people usually run update with no argument anyways);
but we can make it grow/shrink dynamically if needed.  There'll
still be a hard-coded limit to prevent DoS attacks, though.
2008-10-06 18:32:27 +02:00
Max Kellermann
226d52b36f switch to C99 types, part II
Do full C99 integer type conversion in all modules which were not
touched by Eric's merged patch.
2008-09-29 15:49:29 +02:00
Eric Wong
5f0ed72c48 command: don't clobber next list value when preparsing
This only breaks "update" under list command mode and
no other commands.  This can be done more optimally
without the extra heap allocation via xstrdup(); but is
uncommon enough to not matter.
2008-09-29 13:18:35 +02:00
Max Kellermann
05f66e04a4 update: send proper response to the client
Due to a merge error, I broke the function handleUpdate().  It did not
do anything for the global update, and it did not send a proper
response to the client.  This patch fixes both bugs.
2008-09-25 22:46:03 +02:00
Max Kellermann
ad92d9a894 command: fix command "addid"
With patch 8d2830b3, I broke "addid": it did not return the id of the
new song, because of a typo in the return condition (== instead of
!=).
2008-09-23 23:59:55 +02:00
Eric Wong
3f0ae13c4b directory: update do its work inside a thread
A lot of the preparation was needed (and done in previous
months) in making update thread-safe, but here it is.

This was the first thing I made work inside a thread when I
started mpd-uclinux many years ago, and also the last thing I've
done in mainline mpd to work inside a thread, go figure.
2008-09-23 22:37:18 +02:00
Max Kellermann
bd81fd8b0c playlist: return -1 after assert(0)
print_playlist_result() had an assert(0) at the end, in case there was
an invalid result value.  With NDEBUG, this resulted in a function not
returning a value - add a dummy "return -1" at the end to keep gcc
quiet.
2008-09-07 19:19:48 +02:00
Max Kellermann
1ce5f4d75b command: use client_[gs]et_permission()
Don't pass a pointer to client->permission to processCommand(), better
let the code in command.c use the new permission getter/setter
functions.
2008-09-07 19:17:25 +02:00
Max Kellermann
bf6994d8e3 command: don't pass permission as pointer where appropriate
Some functions don't want to modify a client's permission set.  Pass
the permissions to them by value, not by reference.
2008-09-07 19:15:45 +02:00