aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-23 21:38:07 +0200
committerMax Kellermann <max@duempel.org>2013-10-23 21:58:44 +0200
commit3d12f8d2466d6a000bb116b4363a695c862ab52d (patch)
tree21d7e2010685edf9ed8254aeff32c56cb7a8f3df /src
parentc3e720279c89a56b9bbdc46cc6d8c02aefb10ed4 (diff)
downloadmpd-3d12f8d2466d6a000bb116b4363a695c862ab52d.tar.gz
mpd-3d12f8d2466d6a000bb116b4363a695c862ab52d.tar.xz
mpd-3d12f8d2466d6a000bb116b4363a695c862ab52d.zip
UriUtil: uri_remove_auth() returns std::string
Diffstat (limited to 'src')
-rw-r--r--src/DecoderThread.cxx9
-rw-r--r--src/SongPrint.cxx14
-rw-r--r--src/util/UriUtil.cxx17
-rw-r--r--src/util/UriUtil.hxx10
4 files changed, 19 insertions, 31 deletions
diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx
index b3f0e6f36..3364f23b3 100644
--- a/src/DecoderThread.cxx
+++ b/src/DecoderThread.cxx
@@ -38,8 +38,6 @@
#include "tag/ApeReplayGain.hxx"
#include "Log.hxx"
-#include <glib.h>
-
static constexpr Domain decoder_thread_domain("decoder_thread");
/**
@@ -367,13 +365,12 @@ decoder_run_song(decoder_control &dc,
dc.state = DecoderState::ERROR;
const char *error_uri = song->uri;
- char *allocated = uri_remove_auth(error_uri);
- if (allocated != nullptr)
- error_uri = allocated;
+ const std::string allocated = uri_remove_auth(error_uri);
+ if (!allocated.empty())
+ error_uri = allocated.c_str();
dc.error.Format(decoder_domain,
"Failed to decode %s", error_uri);
- g_free(allocated);
}
dc.client_cond.signal();
diff --git a/src/SongPrint.cxx b/src/SongPrint.cxx
index 721fa1b1a..ea164d02b 100644
--- a/src/SongPrint.cxx
+++ b/src/SongPrint.cxx
@@ -27,8 +27,6 @@
#include "Client.hxx"
#include "util/UriUtil.hxx"
-#include <glib.h>
-
void
song_print_uri(Client &client, const Song &song)
{
@@ -36,17 +34,13 @@ song_print_uri(Client &client, const Song &song)
client_printf(client, "%s%s/%s\n", SONG_FILE,
song.parent->GetPath(), song.uri);
} else {
- char *allocated;
- const char *uri;
-
- uri = allocated = uri_remove_auth(song.uri);
- if (uri == NULL)
- uri = song.uri;
+ const char *uri = song.uri;
+ const std::string allocated = uri_remove_auth(uri);
+ if (!allocated.empty())
+ uri = allocated.c_str();
client_printf(client, "%s%s\n", SONG_FILE,
map_to_relative_path(uri));
-
- g_free(allocated);
}
}
diff --git a/src/util/UriUtil.cxx b/src/util/UriUtil.cxx
index a326530e0..d542fc0a9 100644
--- a/src/util/UriUtil.cxx
+++ b/src/util/UriUtil.cxx
@@ -19,8 +19,6 @@
#include "UriUtil.hxx"
-#include <glib.h>
-
#include <assert.h>
#include <string.h>
@@ -80,11 +78,10 @@ uri_safe_local(const char *uri)
}
}
-char *
+std::string
uri_remove_auth(const char *uri)
{
const char *auth, *slash, *at;
- char *p;
if (memcmp(uri, "http://", 7) == 0)
auth = uri + 7;
@@ -92,7 +89,7 @@ uri_remove_auth(const char *uri)
auth = uri + 8;
else
/* unrecognized URI */
- return nullptr;
+ return std::string();
slash = strchr(auth, '/');
if (slash == nullptr)
@@ -101,13 +98,11 @@ uri_remove_auth(const char *uri)
at = (const char *)memchr(auth, '@', slash - auth);
if (at == nullptr)
/* no auth info present, do nothing */
- return nullptr;
+ return std::string();
/* duplicate the full URI and then delete the auth
information */
- p = g_strdup(uri);
- memmove(p + (auth - uri), p + (at + 1 - uri),
- strlen(at));
-
- return p;
+ std::string result(uri);
+ result.erase(auth - uri, at + 1 - auth);
+ return result;
}
diff --git a/src/util/UriUtil.hxx b/src/util/UriUtil.hxx
index 753f6dedb..d93296b10 100644
--- a/src/util/UriUtil.hxx
+++ b/src/util/UriUtil.hxx
@@ -22,6 +22,8 @@
#include "Compiler.h"
+#include <string>
+
/**
* Checks whether the specified URI has a scheme in the form
* "scheme://".
@@ -48,11 +50,11 @@ uri_safe_local(const char *uri);
/**
* Removes HTTP username and password from the URI. This may be
* useful for displaying an URI without disclosing secrets. Returns
- * NULL if nothing needs to be removed, or if the URI is not
- * recognized.
+ * an empty string if nothing needs to be removed, or if the URI is
+ * not recognized.
*/
-gcc_malloc
-char *
+gcc_pure
+std::string
uri_remove_auth(const char *uri);
#endif