From a490402721d80d9d20d2b130170643c285b5470e Mon Sep 17 00:00:00 2001 From: badaix Date: Sat, 7 Oct 2017 10:33:10 +0200 Subject: [PATCH] x-out spotify username and password --- server/streamreader/spotifyStream.cpp | 5 ++++ server/streamreader/streamUri.cpp | 36 +++++++++++++++++++++++++-- server/streamreader/streamUri.h | 3 +++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/server/streamreader/spotifyStream.cpp b/server/streamreader/spotifyStream.cpp index 81476417..cc11edda 100644 --- a/server/streamreader/spotifyStream.cpp +++ b/server/streamreader/spotifyStream.cpp @@ -51,6 +51,11 @@ SpotifyStream::SpotifyStream(PcmListener* pcmListener, const StreamUri& uri) : P params_ += " --onstart \"" + onstart + "\""; if (!onstop.empty()) params_ += " --onstop \"" + onstop + "\""; + + if (uri_.query.find("username") != uri_.query.end()) + uri_.query["username"] = "xxx"; + if (uri_.query.find("password") != uri_.query.end()) + uri_.query["password"] = "xxx"; // LOG(INFO) << "params: " << params << "\n"; } diff --git a/server/streamreader/streamUri.cpp b/server/streamreader/streamUri.cpp index 8238fc8a..962e3d4b 100644 --- a/server/streamreader/streamUri.cpp +++ b/server/streamreader/streamUri.cpp @@ -26,7 +26,14 @@ using namespace std; namespace strutils = utils::string; -StreamUri::StreamUri(const std::string& streamUri) +StreamUri::StreamUri(const std::string& uri) +{ + parse(uri); +} + + + +void StreamUri::parse(const std::string& streamUri) { // https://en.wikipedia.org/wiki/Uniform_Resource_Identifier // scheme:[//[user:password@]host[:port]][/]path[?query][#fragment] @@ -92,13 +99,38 @@ StreamUri::StreamUri(const std::string& streamUri) query[key] = value; } } + LOG(DEBUG) << "StreamUri.toString: " << toString() << "\n"; +} + + +std::string StreamUri::toString() const +{ +// scheme:[//[user:password@]host[:port]][/]path[?query][#fragment] + stringstream ss; + ss << scheme << "://" << host << "/" + path; + if (!query.empty()) + { + ss << "?"; + auto iter = query.begin(); + while (true) + { + ss << iter->first << "=" << iter->second; + if (++iter == query.end()) + break; + ss << "&"; + } + } + if (!fragment.empty()) + ss << "#" << fragment; + + return ss.str(); } json StreamUri::toJson() const { json j = { - {"raw", uri}, + {"raw", toString()}, {"scheme", scheme}, {"host", host}, {"path", path}, diff --git a/server/streamreader/streamUri.h b/server/streamreader/streamUri.h index 4553b169..c174a498 100644 --- a/server/streamreader/streamUri.h +++ b/server/streamreader/streamUri.h @@ -49,6 +49,9 @@ struct StreamUri std::string id() const; json toJson() const; std::string getQuery(const std::string& key, const std::string& def = "") const; + + void parse(const std::string& streamUri); + std::string toString() const; };