aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
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/util
parentc3e720279c89a56b9bbdc46cc6d8c02aefb10ed4 (diff)
downloadmpd-3d12f8d2466d6a000bb116b4363a695c862ab52d.tar.gz
mpd-3d12f8d2466d6a000bb116b4363a695c862ab52d.tar.xz
mpd-3d12f8d2466d6a000bb116b4363a695c862ab52d.zip
UriUtil: uri_remove_auth() returns std::string
Diffstat (limited to 'src/util')
-rw-r--r--src/util/UriUtil.cxx17
-rw-r--r--src/util/UriUtil.hxx10
2 files changed, 12 insertions, 15 deletions
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