From 9a5138ce981697e243fa0de2bc2668eaa80efb76 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Fri, 31 Dec 2010 00:09:06 +0100 Subject: Hacked stuff to work again. --- music.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'music.cpp') diff --git a/music.cpp b/music.cpp index 1651d53..5292e66 100644 --- a/music.cpp +++ b/music.cpp @@ -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& 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::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 ml(new MusicDirectory(p)); return ml; @@ -48,7 +52,7 @@ MusicListing::p music::get(const std::string path) { std::vector music::find_artist(const std::string artist) { soci::session sql(config::vm["audist.database"].as()); - soci::rowset rs = (sql.prepare << "SELECT file_name FROM tracks WHERE artist_id IN (SELECT id FROM artists WHERE name ILIKE :name)", + soci::rowset 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 results; @@ -61,7 +65,7 @@ std::vector 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; -- cgit v1.2.3