diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-01-02 22:28:26 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-01-02 22:28:26 +0100 |
commit | 0e3c3380d519b033500b4ed1ccd3acf707c34372 (patch) | |
tree | 115cbbf0200fc34011e68b32e56d58458a72d87f /music.cpp | |
parent | 237c3e226b7c2ac391b0e8d354e5fc6f587a41ba (diff) |
Merge HTTPResponse into HTTP::Connection.
Diffstat (limited to 'music.cpp')
-rw-r--r-- | music.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -23,11 +23,11 @@ void music::init(std::string root) { root_directory = root; } -MusicListing::p music::get(const std::vector<std::string>& path) { +MusicListing::p music::get(const HTTP::Connection::PathList& path) { // prefix path with our root_directory fs::path p = root_directory; - for(std::vector<std::string>::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<std::string>& path) { } MusicListing::p music::get(const std::string& path) { - std::vector<std::string> 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("<a href=\"/files%s\">%s</a><br />") % rel_path % rel_path)); + req->send_data(boost::str(boost::format("<a href=\"/files%s\">%s</a><br />") % 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("<a href=\"/files%s\">%s</a><br />") % rel_path % rel_path)); + req->send_data(boost::str(boost::format("<a href=\"/files%s\">%s</a><br />") % 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()); } } } |