From 0e3c3380d519b033500b4ed1ccd3acf707c34372 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 2 Jan 2011 22:28:26 +0100 Subject: Merge HTTPResponse into HTTP::Connection. --- music.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'music.cpp') diff --git a/music.cpp b/music.cpp index 9892526..3552f8e 100644 --- a/music.cpp +++ b/music.cpp @@ -23,11 +23,11 @@ void music::init(std::string root) { root_directory = root; } -MusicListing::p music::get(const std::vector& path) { +MusicListing::p music::get(const HTTP::Connection::PathList& path) { // prefix path with our root_directory fs::path p = root_directory; - for(std::vector::const_iterator it = path.begin(); it != path.end(); it++) { + for(HTTP::Connection::PathList::const_iterator it = path.begin(); it != path.end(); it++) { // don't allow requests with /../ in the path if(*it == "..") { return MusicListing::p(); @@ -48,7 +48,7 @@ MusicListing::p music::get(const std::vector& path) { } MusicListing::p music::get(const std::string& path) { - std::vector path_vector; + HTTP::Connection::PathList path_vector; boost::algorithm::split(path_vector, path, boost::algorithm::is_any_of("/\\")); return get(path_vector); } @@ -93,16 +93,16 @@ void music::update(const MusicDirectory& dir) { std::for_each(dir.directories.begin(), dir.directories.end(), update); } -void MusicDirectory::render(HTTP::Connection::p req, HTTPResponse& res) { - res.add_header("content-type", "text/html"); +void MusicDirectory::render(HTTP::Connection::p req) { + req->add_header("content-type", "text/html"); for(PathListings::iterator it = directories.begin(); it != directories.end(); it++) { std::string rel_path = it->string().substr(music::root_directory.string().size()); - res.write(boost::str(boost::format("%s
") % rel_path % rel_path)); + req->send_data(boost::str(boost::format("%s
") % rel_path % rel_path)); } for(PathListings::iterator it = tracks.begin(); it != tracks.end(); it++) { std::string rel_path = it->string().substr(music::root_directory.string().size()); - res.write(boost::str(boost::format("%s
") % rel_path % rel_path)); + req->send_data(boost::str(boost::format("%s
") % rel_path % rel_path)); } } @@ -125,8 +125,8 @@ MusicDirectory::MusicDirectory(const fs::path root) { } } -void MusicTrack::render(HTTP::Connection::p req, HTTPResponse& res) { - res.add_header("content-type", "application/octet-stream"); +void MusicTrack::render(HTTP::Connection::p req) { + req->add_header("content-type", "application/octet-stream"); // tag test Tag *t = new ID3Tag(path.string()); @@ -135,20 +135,20 @@ void MusicTrack::render(HTTP::Connection::p req, HTTPResponse& res) { 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(path.string(), res, *d, *e); + Transcoder t(path.string(), req, *d, *e); t.run(); delete d; delete e; } else { fs::ifstream is(path, std::ios::in | std::ios::binary); is.seekg(0, std::ios::end); - res.add_header("content-length", boost::str(boost::format("%d") % is.tellg())); + req->add_header("content-length", boost::str(boost::format("%d") % is.tellg())); is.seekg(0, std::ios::beg); char data[0x1000]; while(is.good()) { is.read(data, 0x1000); - res.write(data, is.gcount()); + req->send_data(data, is.gcount()); } } } -- cgit v1.2.3