diff --git a/Plugins/TimestampPlugin.h b/Plugins/TimestampPlugin.h new file mode 100644 index 000000000..7d840808c --- /dev/null +++ b/Plugins/TimestampPlugin.h @@ -0,0 +1,85 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +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 Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + +#ifndef TIMESTAMPPLUGIN_H_ +#define TIMESTAMPPLUGIN_H_ + +#include + +#include "BasePlugin.h" +#include "RouteParameters.h" + +class TimestampPlugin : public BasePlugin { +public: + TimestampPlugin(QueryObjectsStorage * objects) { + nodeHelpDesk = objects->nodeHelpDesk; + } + std::string GetDescriptor() const { return std::string("timestamp"); } + std::string GetVersionString() const { return std::string("0.3 (DL)"); } + void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { + std::string tmp; + std::string JSONParameter; + + //json + JSONParameter = routeParameters.options.Find("jsonp"); + if("" != JSONParameter) { + reply.content += JSONParameter; + reply.content += "("; + } + + reply.status = http::Reply::ok; + reply.content += ("{"); + reply.content += ("\"version\":0.3,"); + reply.content += ("\"status\":"); + reply.content += "0,"; + reply.content += ("\"timestamp\":\""); + reply.content += "n/a"; + reply.content += "\""; + reply.content += ",\"transactionId\":\"OSRM Routing Engine JSON timestamp (v0.3)\""; + reply.content += ("}"); + reply.headers.resize(3); + if("" != JSONParameter) { + reply.content += ")"; + reply.headers[1].name = "Content-Type"; + reply.headers[1].value = "text/javascript"; + reply.headers[2].name = "Content-Disposition"; + reply.headers[2].value = "attachment; filename=\"timestamp.js\""; + } else { + reply.headers[1].name = "Content-Type"; + reply.headers[1].value = "application/x-javascript"; + reply.headers[2].name = "Content-Disposition"; + reply.headers[2].value = "attachment; filename=\"timestamp.json\""; + } + reply.headers[0].name = "Content-Length"; + intToString(reply.content.size(), tmp); + reply.headers[0].value = tmp; + } +private: + inline bool checkCoord(const _Coordinate & c) { + if(c.lat > 90*100000 || c.lat < -90*100000 || c.lon > 180*100000 || c.lon <-180*100000) { + return false; + } + return true; + } + + NodeInformationHelpDesk * nodeHelpDesk; +}; + +#endif /* TIMESTAMPPLUGIN_H_ */ diff --git a/routed.cpp b/routed.cpp index 65ae56344..d3bb20001 100644 --- a/routed.cpp +++ b/routed.cpp @@ -33,6 +33,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Plugins/HelloWorldPlugin.h" #include "Plugins/LocatePlugin.h" #include "Plugins/NearestPlugin.h" +#include "Plugins/TimestampPlugin.h" #include "Plugins/ViaRoutePlugin.h" #include "Util/InputFileUtil.h" @@ -108,6 +109,8 @@ int main (int argc, char *argv[]) { h.RegisterPlugin(new NearestPlugin(objects)); + h.RegisterPlugin(new TimestampPlugin(objects)); + h.RegisterPlugin(new ViaRoutePlugin(objects)); boost::thread t(boost::bind(&Server::Run, s));