diff options
author | Max Kellermann <max@duempel.org> | 2009-02-27 19:20:11 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-02-27 19:20:11 +0100 |
commit | eae0287466020b5b5aee137fb4599136420f89a2 (patch) | |
tree | 23c1e1202a94e130f4c3ec006d1a4894939d6b92 /src/uri.c | |
parent | 9dd00dfab7a7991c53d2f1dcff4cc2828abf7854 (diff) | |
download | mpd-eae0287466020b5b5aee137fb4599136420f89a2.tar.gz mpd-eae0287466020b5b5aee137fb4599136420f89a2.tar.xz mpd-eae0287466020b5b5aee137fb4599136420f89a2.zip |
song_print: hide HTTP password in playlist
Added the uri_remove_auth() library function which strips username
and password from a HTTP URI, and use it in song_print_url(). This
allows you to add HTTP URIs to the playlist including secret username
and password, without disclosing it to all MPD clients.
Diffstat (limited to 'src/uri.c')
-rw-r--r-- | src/uri.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -35,3 +35,35 @@ uri_get_suffix(const char *uri) return dot != NULL ? dot + 1 : NULL; } + +char * +uri_remove_auth(const char *uri) +{ + const char *auth, *slash, *at; + char *p; + + if (strncmp(uri, "http://", 7) == 0) + auth = uri + 7; + else if (strncmp(uri, "https://", 8) == 0) + auth = uri + 8; + else + /* unrecognized URI */ + return NULL; + + slash = strchr(auth, '/'); + if (slash == NULL) + slash = auth + strlen(auth); + + at = memchr(auth, '@', slash - auth); + if (at == NULL) + /* no auth info present, do nothing */ + return NULL; + + /* 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; +} |