From: Carl Hetherington Date: Sat, 9 Aug 2014 12:27:45 +0000 (+0100) Subject: Remove JSON server code. X-Git-Tag: v2.0.48~561^2~85 X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;h=2c47ecfa01206bb295f76d6a8b328c3cc5c4a3cb;p=dcpomatic.git Remove JSON server code. --- diff --git a/src/lib/json_server.cc b/src/lib/json_server.cc deleted file mode 100644 index 1be3c7d0e..000000000 --- a/src/lib/json_server.cc +++ /dev/null @@ -1,193 +0,0 @@ -/* - Copyright (C) 2014 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include -#include "json_server.h" -#include "job_manager.h" -#include "job.h" -#include "util.h" -#include "film.h" -#include "transcode_job.h" - -using std::string; -using std::stringstream; -using std::cout; -using std::map; -using std::list; -using boost::thread; -using boost::shared_ptr; -using boost::dynamic_pointer_cast; -using boost::asio::ip::tcp; - -#define MAX_LENGTH 512 - -enum State { - AWAITING_G, - AWAITING_E, - AWAITING_T, - AWAITING_SPACE, - READING_URL, -}; - -JSONServer::JSONServer (int port) -{ - new thread (boost::bind (&JSONServer::run, this, port)); -} - -void -JSONServer::run (int port) -try -{ - boost::asio::io_service io_service; - tcp::acceptor a (io_service, tcp::endpoint (tcp::v4 (), port)); - while (true) { - try { - shared_ptr s (new tcp::socket (io_service)); - a.accept (*s); - handle (s); - } - catch (...) { - - } - } -} -catch (...) -{ - -} - -void -JSONServer::handle (shared_ptr socket) -{ - string url; - State state = AWAITING_G; - - while (true) { - char data[MAX_LENGTH]; - boost::system::error_code error; - size_t len = socket->read_some (boost::asio::buffer (data), error); - if (error) { - cout << "error.\n"; - break; - } - - char* p = data; - char* e = data + len; - while (p != e) { - - State old_state = state; - switch (state) { - case AWAITING_G: - if (*p == 'G') { - state = AWAITING_E; - } - break; - case AWAITING_E: - if (*p == 'E') { - state = AWAITING_T; - } - break; - case AWAITING_T: - if (*p == 'T') { - state = AWAITING_SPACE; - } - break; - case AWAITING_SPACE: - if (*p == ' ') { - state = READING_URL; - } - break; - case READING_URL: - if (*p == ' ') { - request (url, socket); - state = AWAITING_G; - url = ""; - } else { - url += *p; - } - break; - } - - if (state == old_state && state != READING_URL) { - state = AWAITING_G; - } - - ++p; - } - } -} - -void -JSONServer::request (string url, shared_ptr socket) -{ - cout << "request: " << url << "\n"; - - map r = split_get_request (url); - for (map::iterator i = r.begin(); i != r.end(); ++i) { - cout << i->first << " => " << i->second << "\n"; - } - - string action; - if (r.find ("action") != r.end ()) { - action = r["action"]; - } - - stringstream json; - if (action == "status") { - - list > jobs = JobManager::instance()->get (); - - json << "{ \"jobs\": ["; - for (list >::iterator i = jobs.begin(); i != jobs.end(); ++i) { - - json << "{ "; - - if ((*i)->film()) { - json << "\"dcp\": \"" << (*i)->film()->dcp_name() << "\", "; - } - - json << "\"name\": \"" << (*i)->json_name() << "\", " - << "\"progress\": " << (*i)->progress () << ", " - << "\"status\": \"" << (*i)->json_status() << "\""; - json << " }"; - - list >::iterator j = i; - ++j; - if (j != jobs.end ()) { - json << ", "; - } - } - json << "] }"; - - if (json.str().empty ()) { - json << "{ }"; - } - } - - stringstream reply; - reply << "HTTP/1.1 200 OK\r\n" - << "Content-Length: " << json.str().length() << "\r\n" - << "Content-Type: application/json\r\n" - << "\r\n" - << json.str () << "\r\n"; - cout << "reply: " << json.str() << "\n"; - boost::asio::write (*socket, boost::asio::buffer (reply.str().c_str(), reply.str().length())); -} diff --git a/src/lib/json_server.h b/src/lib/json_server.h deleted file mode 100644 index 623067558..000000000 --- a/src/lib/json_server.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright (C) 2014 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -class JSONServer -{ -public: - JSONServer (int port); - -private: - void run (int port); - void handle (boost::shared_ptr socket); - void request (std::string url, boost::shared_ptr socket); -}; - - diff --git a/src/lib/wscript b/src/lib/wscript index 6d563f255..f53ae7b74 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -40,7 +40,6 @@ sources = """ job.cc job_manager.cc kdm.cc - json_server.cc log.cc md5_digester.cc piece.cc