diff options
Diffstat (limited to 'music.cpp')
-rw-r--r-- | music.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -25,15 +25,19 @@ void music::init(std::string root) { } } -MusicListing::p music::get(const std::string path) { +MusicListing::p music::get(const std::vector<std::string>& path) { // prefix path with our root_directory - fs::path p = root_directory / path; - - // don't allow requests with /../ in the path - if(path.find("/../") != std::string::npos) { - return MusicListing::p(); + fs::path p = root_directory; + + for(std::vector<std::string>::const_iterator it = path.begin(); it != path.end(); it++) { + // don't allow requests with /../ in the path + if(*it == "..") { + return MusicListing::p(); + } + + p /= *it; } - + if(fs::is_directory(p)) { boost::shared_ptr<MusicListing> ml(new MusicDirectory(p)); return ml; @@ -48,7 +52,7 @@ MusicListing::p music::get(const std::string path) { std::vector<MusicListing::p> music::find_artist(const std::string artist) { soci::session sql(config::vm["audist.database"].as<std::string>()); - soci::rowset<std::string> rs = (sql.prepare << "SELECT file_name FROM tracks WHERE artist_id IN (SELECT id FROM artists WHERE name ILIKE :name)", + soci::rowset<std::string> rs = (sql.prepare << "SELECT file_name FROM tracks WHERE artist_id IN (SELECT id FROM artists WHERE name LIKE :name)", soci::use("%"+artist+"%")); std::vector<MusicListing::p> results; @@ -61,7 +65,7 @@ std::vector<MusicListing::p> music::find_artist(const std::string artist) { return results; } -void MusicDirectory::render(HTTPRequest& req, HTTPResponse& res) { +void MusicDirectory::render(HTTP::Connection::p req, HTTPResponse& res) { res.add_header("content-type", "text/html"); for(PathListings::iterator it = directories.begin(); it != directories.end(); it++) { @@ -93,7 +97,7 @@ MusicDirectory::MusicDirectory(const fs::path root) { } } -void MusicTrack::render(HTTPRequest& req, HTTPResponse& res) { +void MusicTrack::render(HTTP::Connection::p req, HTTPResponse& res) { res.add_header("content-type", "application/octet-stream"); // tag test @@ -102,9 +106,9 @@ void MusicTrack::render(HTTPRequest& req, HTTPResponse& res) { fs::ifstream is(path, std::ios::binary | std::ios::in); - if(req.query.find("decoder") != req.query.end() && req.query.find("encoder") != req.query.end()) { - DecoderBase *d = decoder::get_decoder(req.query["decoder"]); - EncoderBase *e = encoder::get_encoder(req.query["encoder"]); + if(req->args.count("decoder") && req->args.count("encoder")) { + DecoderBase *d = decoder::get_decoder(req->args["decoder"]); + EncoderBase *e = encoder::get_encoder(req->args["encoder"]); Transcoder t(is, res, *d, *e); t.run(); delete d; |