Commit Graph

200 Commits

Author SHA1 Message Date
Max Kellermann
d99f074eb7 directory: replace dirvec with doubly linked list
Random access is not needed, and a linked list is easier to manage: we
don't need to (re-)allocate the pointer array.
2012-01-24 20:49:53 +01:00
Max Kellermann
420a4c163d directory: simplify constructors and clarify API documentation
Pass only the "name" to a directory, instead of the full (relative)
path.
2012-01-24 20:03:18 +01:00
Max Kellermann
49b84f9229 db_print: print absolute URI of playlist entries
The protocol mandates that playlist URIs are absolute (i.e. full URI
relative to the music directory, not relative to the parent
directory).  This adds the parameter "directory" to the "playlist"
visitor method.
2011-10-08 14:51:18 +02:00
Max Kellermann
c779e2674a db_visitor: add method playlist() 2011-09-13 22:02:37 +02:00
Max Kellermann
a94d4be466 db_plugin: add method visit() 2011-09-13 21:47:00 +02:00
Max Kellermann
412cf974a4 directory: don't visit "self" in _walk()
Let the caller decide if the current directory should be visited.
2011-09-13 20:44:35 +02:00
Max Kellermann
2ff35c8bfa directory: don't require a "directory" visitor
.. to recurse.  A visitor may not have one, but still be interested in
a recursive search.
2011-09-13 20:44:00 +02:00
Max Kellermann
169db88c20 database: add struct db_visitor
Use this struct for db_walk().
2011-09-13 19:37:28 +02:00
Max Kellermann
c6cbcc2c25 copyright year 2011 2011-01-29 10:13:54 +01:00
Max Kellermann
bedb82bf4d directory: free playlist vector in directory_free() 2010-07-25 13:31:39 +02:00
Max Kellermann
e598922133 update: store playlist files in database
Don't open the music directory for each "lsinfo" call.  Get the list
of playlist files from the memory database.
2010-07-21 09:26:50 +02:00
Avuton Olrich
9d3865cb95 Update copyright notices. 2009-12-31 20:58:43 -08:00
Max Kellermann
5b82ffc291 include config.h in all sources
After we've been hit by Large File Support problems several times in
the past week (which only occur on 32 bit platforms, which I don't
have), this is yet another attempt to fix the issue.
2009-11-12 09:17:03 +01:00
Max Kellermann
7dddd9beda directory: free empty directories after removing them (memleak)
dirvec_delete() does not free the object, we have to call
directory_free() afterwards.
2009-08-14 11:52:00 +02:00
Max Kellermann
7f38c3fc78 directory: added directory_lookup_song()
Moved code from db_get_song().
2009-04-01 18:41:37 +02:00
Max Kellermann
36ec2edacf directory: renamed directory_get_directory()
Renamed directory_get_directory() to directory_lookup_directory().
Added API documentation.
2009-04-01 18:41:33 +02:00
Avuton Olrich
0aee49bdf8 all: Update copyright header.
This updates the copyright header to all be the same, which is
pretty much an update of where to mail request for a copy of the GPL
and the years of the MPD project. This also puts all committers under
'The Music Player Project' umbrella. These entries should go
individually in the AUTHORS file, for consistancy.
2009-03-13 11:51:55 -07:00
Max Kellermann
a45922cd66 use g_free() instead of free()
On some platforms, g_free() must be used for memory allocated by
GLib.  This patch intends to correct a lot of occurrences, but is
probably not complete.
2009-01-25 18:47:21 +01:00
Max Kellermann
cc4e0a786d directory: use GLib instead of utils.h 2009-01-02 16:26:19 +01:00
Max Kellermann
8f9d9cc042 directory: directory_free() frees children
directory_free() should free all of its children (subdirectories and
songs).  This way, db_finish() properly frees all allocated memory.
2008-10-31 09:20:02 +01:00
Max Kellermann
ba96920a52 path: replaced mpd_basename() with g_path_get_basename()
GLib's g_path_get_basename() is much more reliable than
mpd_basename().  The latter could be tricked into an assertion
failure.
2008-10-20 22:18:12 +02:00
Max Kellermann
3b6ff84393 directory: added directory_get_name()
directory_get_name() returns the base name of the directory.
2008-10-13 16:32:39 +02:00
Eric Wong
8d907fb9fa directory: use mpd_sizeof_str_flex_array for path, too
This way we avoid unnecessary heap allocations.
2008-10-13 09:55:00 +02:00
Max Kellermann
cbc0764613 directory: added inline wrappers for accessing children
Some tiny utilities... wrappers like these may become helpful when we
introduce locking.
2008-10-09 15:34:07 +02:00
Max Kellermann
68f716a28b directory: moved dirvec struct declaration to dirvec.h
No idea why it was created in directory.h, but it should be in
dirvec.h.
2008-10-09 15:24:05 +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
Max Kellermann
0bfe7802d2 directory: path must not be NULL
For the root directory, let's set path to an empty string.  This saves
a few checks.
2008-10-08 11:08:16 +02:00
Max Kellermann
68977af6e0 directory: eliminate CamelCase
CamelCase is ugly, rename the functions.
2008-10-08 11:07:58 +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
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
ba5c9b0375 directory: converted isRootDirectory() to an inline function
The function isRootDirectory() is tiny and can be converted to an
inline function.  Don't allow name==NULL.
2008-10-08 11:06:44 +02:00
Max Kellermann
5e7b18f874 song: removed CamelCase
CamelCase is ugly...  rename all functions.
2008-10-08 11:05:34 +02:00
Max Kellermann
d562ba5fbb song: converted typedef Song to struct song
Again, a data type which can be forward-declared.
2008-10-08 10:49:11 +02:00
Max Kellermann
25f67da58c directory: converted typedef Directory to struct directory
The struct can be forward-declared by other headers, which relaxes the
header dependencies.
2008-10-08 10:49:05 +02:00
Max Kellermann
3c1142cbcb update: merged exploreDirectory() into updateDirectory()
exploreDirectory() duplicates some code in updateDirectory().  Merge
both functions, and use directory_is_empty() to determine whether
update or explore mode should be used.
2008-10-08 10:48:55 +02:00
Max Kellermann
e79aacf1db directory: added directory_is_empty()
directory_is_empty() is a tiny inline function which determine if a
directory has any child objects (sub directories or songs).
2008-10-08 10:48:49 +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
81ce068085 directory: fix return value in removeDeletedFromDirectory
oops :x
2008-10-07 22:11:21 +02:00
Eric Wong
7d8c9cc7e3 directory: serialize song deletes from playlist during update
This makes the update code thread-safe and doesn't penalize
the playlist code by complicating it with complicated and
error-prone locks (and the associated overhead, not everybody
has a thread-implementation as good as NPTL).

The update task blocks during the delete; but the update task is
a slow task anyways so we can block w/o people caring too much.

This was also our only freeSong call site, so remove that
function.

Note that deleting entire directories is not fully thread-safe,
yet; as their traversals are not yet locked.
2008-10-07 22:11:16 +02:00
Eric Wong
2b965a5424 directory: use songvec_for_each for iterators
Get rid of songvec_write so we can enforce proper locking
2008-10-07 22:10:48 +02:00
Eric Wong
8be6026336 dbUtils/directory: traverseAllIn forEachSong returns -1 on error
Being consistent with most UNIX functions...
2008-10-07 22:07:44 +02:00
Eric Wong
0d34815f6c Assert if we don't have song or song->url set
song objects cannot exist without a path or URL
2008-10-07 21:20:34 +02:00
Eric Wong
f1c53fe0ed song: stop storing song_type
We already know if a song is a URL or not based on whether it
has parentDir defined or not.  Hopefully one day in the future
we can drop HTTP support from MPD entirely when an HTTP
filesystem comes along and we can access streams via open(2).
2008-10-06 18:52:13 +02:00
Eric Wong
267b2cd6e6 song: use flex arrays to store song->url
Reduce the number of allocations we make, so there's less
pressure on the allocator and less overhead to keep track
of the allocations in.
2008-10-06 18:46:52 +02:00
Eric Wong
836dcc28c5 directory: reuse existing directory if found on update
Instead of allocating a new one, just reuse an existing
one if one is found when rereading the DB.  This is a small
makes the previous commit work on subdirectories
of the root music directory.

[1] "song: better handling of existing songs when rereading DB"
2008-10-06 18:37:13 +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
Eric Wong
19a4803bc9 directory: streamline deletes
Instead of relying on the shortname, just pass the song pointer
to prevent redundant lookups during deletes.
2008-10-06 18:20:53 +02:00
Eric Wong
11245dc119 directory: isRootDirectory() is a one-liner
Improving the signal to noise ratio...
2008-09-29 13:18:27 +02:00
Eric Wong
da79498afd directory: writeDirectoryInfo propagates errors
If a write failed, it's a good sign subsequent writes will fail,
too, so propgate errors all the way up the stack.
2008-09-29 13:17:52 +02:00
Eric Wong
4e15e292e0 directory: make it clear that DIRECTORY_MTIME is deprecated
A long time ago in an mpd far away...
2008-09-29 13:17:48 +02:00