Commit Graph

2491 Commits

Author SHA1 Message Date
Max Kellermann 4990f04ac0 update: make addDirectoryPathToDB() non-recursive
This recursive function is very dangerous because it allocates a large
buffer on the stack in every iteration.  That may be misused to
generate a stack overflow.
2008-10-09 15:48:07 +02:00
Max Kellermann 8536a97920 update: delete directory after failed update
When a directory cannot be updated, there must be something wrong with
it, and the database contains stale data.  Remove it.
2008-10-09 15:47:59 +02:00
Max Kellermann 0daba6bd43 update: moved code to directory_make_child_checked()
The branching looks a bit complicated in addDirectoryPathToDB() -
improve its readability by moving code to a simplified separate
function.
2008-10-09 15:47:22 +02:00
Max Kellermann 2ae94fec6d update: clear root after error
When the root directory fails to update, its contents are invalid.
Clear it then.
2008-10-09 15:42:30 +02:00
Max Kellermann 2bb7bcc7b6 update: locked delete after update error
When a directory failed to update, it was removed from the database,
without freeing all children and songs (memory leak), and without
locking (race condition).  Introduce the functions clear_directory()
and delete_directory(), which do both.
2008-10-09 15:41:02 +02:00
Max Kellermann 96c681e2db dirvec: added dirvec_clear() 2008-10-09 15:37:41 +02:00
Max Kellermann 476578d2a9 update: removed addToDirectory()
Use updateInDirectory() instead of addToDirectory().  Eliminate a
duplicate stat() in updateInDirectory() by calling song_file_update()
directly.
2008-10-09 15:37:21 +02:00
Max Kellermann 60d122e850 directory: don't query database during load
Don't use db_get_directory() and traverse the full path with every
directory being loaded.  Just see if the current parent contains the
entry.  Everything else would be invalid anyway..
2008-10-09 15:37:18 +02:00
Max Kellermann 702739b879 directory: check the absolute path of a subdirectory while loading
A manipulated database could trigger an assertion failure, because the
parent didn't match.  Do a proper check if the new directory is within
the parent's.  This uses FATAL() to bail out, so MPD still dies, but
it doesn't crash.
2008-10-09 15:35:34 +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 a5480108f8 dirvec: constant pointers in dirvec_find()
dirvec_find() does not modify the object, thus it should get a const
pointer.
2008-10-09 15:24:34 +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 cb12eb8e23 database: removed local variable bufferSize
Use sizeof(buffer) instead.
2008-10-09 15:21:23 +02:00
Max Kellermann 5dc4c325aa database: simplify db_load()
Removed a superfluous closure.
2008-10-09 15:21:18 +02:00
Max Kellermann 5583b6c5e1 shout: removed DISABLED_SHOUT_ENCODER_PLUGIN
Having an array with disabled entries sucks.  Removed that
DISABLED_SHOUT_ENCODER_PLUGIN macro, and fill the plugin list only
with plugins which are actually enabled.  This should be done for all
plugin types.
2008-10-09 15:18:21 +02:00
Max Kellermann 671b455133 pcm: fix const flac in pcm_convertSampleRate()
In the libsamplerate fallback code, a "const" attribute was missing.
2008-10-09 15:18:18 +02:00
Max Kellermann 40f59cacda pcm: fixed software volume, broken by unsigned integer
"volume" was passed as an unsigned integer, which is correct.  It's
just that when it was multiplied with the sample value, the whole
operation was changed to unsigned, breaking the algorithm (and Qball's
ears).  Internally change "volume" to signed.
2008-10-09 15:18:09 +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 22645abc10 directory: fix update in root directory
Commit 0bfe7802 broke update for new files in the root directory,
because music_root->path was an empty string and not NULL.  There were
some NULL tests missing.  Change them to !isRootDirectory(path)
instead of path!=NULL.
2008-10-08 11:55:52 +02:00
Max Kellermann e8413541f4 update: fix deadlock in delete_song()
Due to a merge error, reap_update_task() called cond_signal_async()
with a locked mutex.  That always fails.  Use cond_signal_sync()
instead.
2008-10-08 11:36:38 +02:00
Max Kellermann 81220ca206 directory: include sys/types.h
ino_t and dev_t are declared in sys/types.h, not sys/stat.h.
2008-10-08 11:25:33 +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 3b6efa99da directory: directory_get_path(NULL) is not allowed
Also convert directory_get_path() to an inline function, which returns
a constant string.
2008-10-08 11:08:04 +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 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 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 e1a4474ad4 song: don't allow calling song_get_url(NULL)
The runtime check suggests that the author has somehow thought
song_get_url(NULL) might be valid.  It should not be.  Replace it with
an assertion.
2008-10-08 11:06:37 +02:00
Max Kellermann 4ab6b59aaf song: use song_file_update() in song_file_load()
Eliminate duplicated code.
2008-10-08 11:06:27 +02:00
Max Kellermann 02e8c000d1 song: song_file_update() returns bool
Instead of returning 0 or -1, return true on success and false on
failure.  This seems more natural, and when the C library was
designed, there was no "bool" data type.
2008-10-08 11:06:26 +02:00
Max Kellermann 1f9b614850 song: don't check song_is_file() in song_file_update()
This function was never used on remote songs.  Replace the runtime
check with an assertion.
2008-10-08 11:05:38 +02:00
Max Kellermann 5e7b18f874 song: removed CamelCase
CamelCase is ugly...  rename all functions.
2008-10-08 11:05:34 +02:00
Max Kellermann 5e4be9e495 song: replaced all song constructors
Provide separate constructors for creating a remote song, a local
song, and one for loading data from a song file.  This way, we can add
more assertions.
2008-10-08 11:05:25 +02:00
Max Kellermann 4a510a2674 playlist: simplified setPlaylistRandomStatus()
Check the old status before assigning.  This saves a temporary
variable.
2008-10-08 11:05:02 +02:00
Max Kellermann b084bc28ed use the "bool" data type instead of "int"
"bool" should be used in C99 programs for boolean values.
2008-10-08 11:03:39 +02:00
Max Kellermann 71351160b1 don't include os_compat.h
When there are standardized headers, use these instead of the bloated
os_compat.h.
2008-10-08 10:49:29 +02:00
Max Kellermann ca68b1c80a CPP include cleanup
Include only headers which are really used.
2008-10-08 10:49:26 +02:00
Max Kellermann b159832418 notify: removed the "Notify" typedef
Typedefs shouldn't be used, use the bare struct names instead.
2008-10-08 10:49:16 +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
Max Kellermann 4cfd356e12 dirvec: moved code to dirvec.c
Having all functions as static (non-inline) functions generates GCC
warnings, and duplicates binary code across several object files.
Most of dirvec's methods are too complex for becoming inline
functions.  Move them all to dirvec.c and publish the prototypes in
dirvec.h.
2008-10-08 06:55:10 +02:00
Max Kellermann b42974eee1 notify: loop while no signal is pending
pthread_cond_wait() may wake up spuriously.  To prevent superfluous
state checks, loop until the "pending" flag becomes true.  Removed the
dangerous assertion.
2008-10-08 06:55:08 +02:00
Max Kellermann 46eda29d1c song: really make the song struct non-packed
Somehow I must have missed this in commit 22e40b61.
2008-10-07 22:15:06 +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