Commit Graph

74 Commits

Author SHA1 Message Date
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
91ebf46853 path: don't export path_set_fs_charset()
The function path_set_fs_charset() is only used in path.c.
2009-02-20 14:49:57 +01:00
Max Kellermann
09ecfb6567 path: validate configured character set 2009-02-20 12:31:00 +01:00
Max Kellermann
80799fa84e use config_get_string() instead of config_get_param()
config_get_string() is easier to use than config_get_param() because
it unpacks the config_param struct.
2009-01-25 16:00:51 +01:00
Max Kellermann
4d472c265e conf: no CamelCase, part I
Renamed functions, types, variables.
2009-01-17 20:23:27 +01:00
Max Kellermann
f0b865b4ca path: include cleanup 2009-01-08 21:29:29 +01:00
Max Kellermann
5ed5aa99ac path: allocate buffer in fs_charset conversion functions
Don't use fixed static buffers.  GLib allocates a new string for us
anyway, let's just return this one instead of copying it.
2009-01-08 21:20:46 +01:00
Max Kellermann
530f0b71de path, tag: don't allocate GError for charset conversion
Pass NULL instead of &error to g_convert().  We're not interested in
the error object.
2009-01-04 19:50:22 +01:00
Max Kellermann
da69382273 path: removed pfx_dir()
Use GLib's g_build_filename() instead of pfx_dir().
2009-01-04 19:37:19 +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
4d3dd1ed2a path: use GLib logging 2008-12-29 17:32:53 +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
Thomas Jansen
2720585731 replaced mpd_likely/mpd_unlikely by G_LIKELY/G_UNLIKELY
We want to remove gcc.h eventually. This takes care of all the
G_LIKELY/G_UNLIKELY macros.
2008-12-02 02:22:43 +01:00
Konstantin Sobolev
ddab531b4a path: fix g_convert() argument order
g_convert() wants the destination character set first.  This was mixed
up.
2008-11-20 17:48:11 +01:00
Max Kellermann
19d3345ab8 path: removed superfluous error check in path_set_fs_charset()
The code which had a possible error condition had been removed.
2008-11-05 21:42:55 +01:00
Max Kellermann
2a1a37107f path: don't allocate charset twice
Make the local variable "charset" const, and don't duplicate its
value.  It is already duplicated by path_set_fs_charset().
2008-11-05 18:26:45 +01:00
Max Kellermann
6a7a26fe42 path: get filesystem charset from GLib
GLib provides the function g_get_filename_charsets() which determines
the file system character set.  This changes MPD's fallback: GLib
prefers UTF-8 as a fallback.  MPD used to fall back to ISO Latin 1.
2008-11-05 18:25:57 +01:00
Max Kellermann
3002fd18cb path: no CamelCase
Rename variables and functions.
2008-11-05 18:21:52 +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
d8e877e335 path: moved playlist_dir to mapper.c
Added the function map_spl_utf8_to_fs() which replaces
utf8_to_fs_playlist_path().
2008-10-31 16:47:14 +01:00
Max Kellermann
6757c17689 removed UTF-8 library, use GLib instead
Removed duplicated code.
2008-10-31 13:57:10 +01:00
Max Kellermann
71fe7ad81a path: free GLib error in fs_charset_to_utf8()
g_error_free() was missing in case g_convert() failed.
2008-10-31 12:20:48 +01:00
Max Kellermann
1d385190a0 path: removed pathcpy_trunc()
There was only one user of pathcpy_trunc(), which can be eliminated.
2008-10-20 22:18:42 +02:00
Max Kellermann
49260e6db2 path: replaced parent_path() with g_path_get_dirname()
Again, GLib's version is more robust than ours.
2008-10-20 22:18:40 +02: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
7366191f0d mapper: moved musicDir initialization from path.c
Moved the musicDir variable and its initialization code from path.c to
mapper.c.
2008-10-15 19:36:33 +02:00
Max Kellermann
76779f0fbe path: allow starting MPD with non-existing music directory
When the music directory is not mounted yet, let MPD start anyway.
2008-10-15 19:36:31 +02:00
Max Kellermann
8746a58ab9 path, tag_id3: use g_convert() instead of charConv.c
GLib provides an easier API for character set conversion than iconv().
Use g_convert() / g_convert_with_fallback() for all character
conversions.  We should optimize the path.h API later to return a
newly allocated buffer, so we can just pass GLib's return value.
2008-10-15 19:36:30 +02:00
Eric Wong
8bb96d46e8 path: add mpd_basename() function
This is like basename(3) but with predictable semantics independent
of C library or build options used.  This is also much more strict
and does not account for trailing slashes (mpd should never deal with
trailing slashes on internal functions).
2008-09-29 13:16:48 +02:00
Max Kellermann
43c389b961 added "length" parameter to validUtf8String()
At several places, we create temporary copies of non-null-terminated
strings, just to use them in functions like validUtf8String().  We can
save this temporary allocation and avoid heap fragmentation if we
add a length parameter instead of expecting a null-terminated string.
2008-08-29 09:38:58 +02:00
Max Kellermann
6fbdc721d9 fix -Wconst warnings
[ew: cleaned up the dirty union hack a bit]
Signed-off-by: Eric Wong <normalperson@yhbt.net>

git-svn-id: https://svn.musicpd.org/mpd/trunk@7180 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-02-05 10:17:33 +00:00
Eric Wong
cb8f1af3bd Cleanup #includes of standard system headers and put them in one place
This will make refactoring features easier, especially now that
pthreads support and larger refactorings are on the horizon.

Hopefully, this will make porting to other platforms (even
non-UNIX-like ones for masochists) easier, too.

os_compat.h will house all the #includes for system headers
considered to be the "core" of MPD.  Headers for optional
features will be left to individual source files.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7130 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-03 07:29:49 +00:00
Eric Wong
b1cdf8dadf document parent_path()
git-svn-id: https://svn.musicpd.org/mpd/trunk@7128 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-03 07:22:18 +00:00
Eric Wong
47efe42321 Make utf8_to_fs_playlist_path universally accessible
git-svn-id: https://svn.musicpd.org/mpd/trunk@7115 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:07:34 +00:00
Eric Wong
b79f6b882a Merge branches/ew r7104
thread-safety work in preparation for rewrite to use pthreads

Expect no regressions against trunk (r7078), possibly minor
performance improvements in update (due to fewer heap
allocations), but increased stack usage.

Applied the following patches:

* maxpath_str for reentrancy (temporary fix, reverted)
* path: start working on thread-safe variants of these methods
* Re-entrancy work on path/character-set conversions
* directory.c: exploreDirectory() use reentrant functions here
* directory/update: more use of reentrant functions + cleanups
* string_toupper: a strdup-less version of strDupToUpper
* get_song_url: a static-variable-free version of getSongUrl()
* Use reentrant/thread-safe get_song_url everywhere
* replace rmp2amp with the reentrant version, rmp2amp_r
* Get rid of the non-reentrant/non-thread-safe rpp2app, too.
* buffer2array: assert strdup() returns a usable value in unit tests
* replace utf8ToFsCharset and fsCharsetToUtf8 with thread-safe variants
* fix storing playlists w/o absolute paths
* parent_path(), a reentrant version of parentPath()
* parentPath => parent_path for reentrancy and thread-safety
* allow "make test" to automatically run embedded unit tests
* remove convStrDup() and maxpath_str()
* use MPD_PATH_MAX everywhere instead of MAXPATHLEN
* path: get rid of appendSlash, pfx_path and just use pfx_dir
* get_song_url: fix the ability to play songs in the top-level music_directory

git-svn-id: https://svn.musicpd.org/mpd/trunk@7106 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-12-28 02:56:25 +00:00
J. Alexander Treuman
8d89add8e7 adding \n to a bunch of error message strings
git-svn-id: https://svn.musicpd.org/mpd/trunk@6826 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-27 21:03:22 +00:00
J. Alexander Treuman
bba444524e Changing all calls to ERROR() followed by exit(EXIT_FAILURE) with a single
call to FATAL().

git-svn-id: https://svn.musicpd.org/mpd/trunk@6276 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-26 18:15:54 +00:00
Avuton Olrich
a061da8fb5 The massive copyright update
git-svn-id: https://svn.musicpd.org/mpd/trunk@5834 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-04-05 03:22:33 +00:00
J. Alexander Treuman
7b1e14b8e8 Reverting all of my localization changes. It was a horrible
implementation, and fixing it is a big enough job that I don't know when
I'll get around to it.  Probably best just starting from scratch anyhow.

git-svn-id: https://svn.musicpd.org/mpd/trunk@5373 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-02-18 00:42:22 +00:00
Eric Wong
b443363aa6 Don't initialize globals to zero (or NULL)
Some compilers and linkers aren't smart enough to optimize this,
as global variables are implictly initialized to zero.  As a
result, binaries are a bit smaller as more goes in the .bss and
less in the text section.

git-svn-id: https://svn.musicpd.org/mpd/trunk@5254 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-01-14 03:07:53 +00:00
J. Alexander Treuman
438c1add9d Convert log messages sent to stdout to the current locale's charset.
git-svn-id: https://svn.musicpd.org/mpd/trunk@5227 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-01-08 04:31:44 +00:00
J. Alexander Treuman
90b4af0341 Moving pathConvCharset to charConv.c so it can be reused for localization.
git-svn-id: https://svn.musicpd.org/mpd/trunk@5226 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-01-08 03:28:36 +00:00
J. Alexander Treuman
bcb493cfd3 Moving localization stuff from path.c to localization.c so we can reuse it
for log messages when outputting to console.

git-svn-id: https://svn.musicpd.org/mpd/trunk@5225 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-01-08 03:15:33 +00:00
Eric Wong
e1d1a703f1 path.c: speling fix (I coulda sworn I fixed this before... in -ke)
git-svn-id: https://svn.musicpd.org/mpd/trunk@4904 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-10-14 08:50:23 +00:00
Eric Wong
90847fc881 Replace strdup and {c,re,m}alloc with x* variants to check for OOM errors
I'm checking for zero-size allocations and assert()-ing them,
so we can more easily get backtraces and debug problems, but we'll
also allow -DNDEBUG people to live on the edge if they wish.

We do not rely on errno when checking for OOM errors because
some implementations of malloc do not set it, and malloc
is commonly overridden by userspace wrappers.

I've spent some time looking through the source and didn't find any
obvious places where we would explicitly allocate 0 bytes, so we
shouldn't trip any of those assertions.

We also avoid allocating zero bytes because C libraries don't
handle this consistently (some return NULL, some not); and it's
dangerous either way.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4690 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-26 06:25:57 +00:00
Eric Wong
6459b3ee29 Revert leaks from r4311, and also the leak fixes as a result of that
utf8ToFsCharset() and fsCharsetToUtf8() got very broken in r4311, and
resulted in several commits to fix those leaks.  Unfortunately, not all
of those newly introduced leaks were fixed, nor was the result pretty.

Also, fixed a double-free in lsPlaylists().  This is very hard
to trigger (and therefore exploit) at the moment because we
check printDirectoryInfo() beforehand.

Intended behavior for utf8ToFsCharset() and fsCharsetToUtf8() as
God^H^H^Hshank originally intended is now documented in path.h
to prevent future errors like this.

mpd could still use some good valgrind testing before the 0.12.0
release.

<plug>In addition to reducing heap fragmentation, malloc
reductions from mpd-ke greatly reduces the chance of leaks from
happening due to programming errors.</plug>

git-svn-id: https://svn.musicpd.org/mpd/trunk@4639 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-14 13:46:51 +00:00
Eric Wong
263a9d583a remove clumsy strncpy use
strncpy isn't really safe because it doesn't guarantee null termination,
and we have had to work around it in several places.
strlcpy (from OpenBSD) isn't great, either because it often leaves
errors going unchecked (by truncating strings).

So we'll add the pathcpy_trunc() function with is basically strlcpy
with a hardcoded MAXPATHLEN as the limit, and we'll acknowledge
truncation since we only work on paths and MAXPATHLEN should be
set correctly by the system headers[1].

file-specific notes:

inputStream_http:
eyeballing the changes here, it seems to look alright but I
haven't actually tested it myself.

ls:
don't even bother printing a file if the filename is too long
(and when is it ever?) since we won't be able to read it anyways.

metadataChunk:
it's only metadata, and it's only for showin the user, so truncating
it here souldn't be a big issue.
memset to zero in init is unecessary, so lets not waste cycles

[1] - If the system headers are screwed up, then we're majorly
screwed regardless of what we do :x

git-svn-id: https://svn.musicpd.org/mpd/trunk@4491 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-30 10:31:41 +00:00
Avuton Olrich
29a25b9933 Add mpd-indent.sh
Indent the entire tree, hopefully we can keep
it indented.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4410 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-20 16:02:40 +00:00
Eric Wong
a234780aab sparse: ANSI-fy function declarations
These are just warnings from sparse, but it makes the output
easier to read.  I ran this through a quick perl script, but
of course verified the output by looking at the diff and making
sure the thing still compiles.

here's the quick perl script I wrote to generate this patch:
----------- 8< -----------
use Tie::File;
defined(my $pid = open my $fh, '-|') or die $!;
if (!$pid) {
open STDERR, '>&STDOUT' or die $!;
exec 'sparse', @ARGV or die $!;
}
my $na = 'warning: non-ANSI function declaration of function';
while (<$fh>) {
print STDERR $_;
if (/^(.+?\.[ch]):(\d+):(\d+): $na '(\w+)'/o) {
my ($f, $l, $pos, $func) = ($1, $2, $3, $4);
$l--;
tie my @x, 'Tie::File', $f or die "$!: $f";
print '-', $x[$l], "\n";
$x[$l] =~ s/\b($func\s*)\(\s*\)/$1(void)/;
print '+', $x[$l], "\n";
untie @x;
}
}

git-svn-id: https://svn.musicpd.org/mpd/trunk@4378 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-17 00:15:34 +00:00
J. Alexander Treuman
2fa7125cce Change shank's email address
git-svn-id: https://svn.musicpd.org/mpd/trunk@4333 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-14 19:37:45 +00:00