Forgotten file.
This commit is contained in:
commit
f1f59d770e
@ -53,13 +53,9 @@ public:
|
|||||||
_RouteSummary() : lengthString("0"), durationString("0"), startName(0), destName(0) {}
|
_RouteSummary() : lengthString("0"), durationString("0"), startName(0), destName(0) {}
|
||||||
void BuildDurationAndLengthStrings(const double distance, const unsigned time) {
|
void BuildDurationAndLengthStrings(const double distance, const unsigned time) {
|
||||||
//compute distance/duration for route summary
|
//compute distance/duration for route summary
|
||||||
std::ostringstream s;
|
intToString(round(distance), lengthString);
|
||||||
s << round(distance);
|
|
||||||
lengthString = s.str();
|
|
||||||
int travelTime = time/10 + 1;
|
int travelTime = time/10 + 1;
|
||||||
s.str("");
|
intToString(travelTime, durationString);
|
||||||
s << travelTime;
|
|
||||||
durationString = s.str();
|
|
||||||
}
|
}
|
||||||
} summary;
|
} summary;
|
||||||
|
|
||||||
|
@ -21,8 +21,11 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef BASIC_DATASTRUCTURES_H
|
#ifndef BASIC_DATASTRUCTURES_H
|
||||||
#define BASIC_DATASTRUCTURES_H
|
#define BASIC_DATASTRUCTURES_H
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
namespace http {
|
namespace http {
|
||||||
|
|
||||||
const std::string okString = "HTTP/1.0 200 OK\r\n";
|
const std::string okString = "HTTP/1.0 200 OK\r\n";
|
||||||
@ -70,15 +73,13 @@ struct Reply {
|
|||||||
std::vector<boost::asio::const_buffer> HeaderstoBuffers();
|
std::vector<boost::asio::const_buffer> HeaderstoBuffers();
|
||||||
std::string content;
|
std::string content;
|
||||||
static Reply stockReply(status_type status);
|
static Reply stockReply(status_type status);
|
||||||
void setSize(unsigned size) {
|
void setSize(const unsigned size) {
|
||||||
for (std::size_t i = 0; i < headers.size(); ++i) {
|
BOOST_FOREACH (const Header& h, headers) {
|
||||||
Header& h = headers[i];
|
if("Content-Length" == h.name) {
|
||||||
if("Content-Length" == h.name) {
|
std::string sizeString;
|
||||||
std::stringstream sizeString;
|
intToString(size,h.value );
|
||||||
sizeString << size;
|
}
|
||||||
h.value = sizeString.str();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../DataStructures/HashTable.h"
|
#include "../DataStructures/HashTable.h"
|
||||||
#include "../Plugins/BasePlugin.h"
|
#include "../Plugins/BasePlugin.h"
|
||||||
#include "../Plugins/RouteParameters.h"
|
#include "../Plugins/RouteParameters.h"
|
||||||
|
#include "../Util/StringUtil.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
namespace http {
|
namespace http {
|
||||||
@ -71,16 +72,17 @@ public:
|
|||||||
bool result = boost::spirit::qi::parse(it, request.end(), apiParser); // returns true if successful
|
bool result = boost::spirit::qi::parse(it, request.end(), apiParser); // returns true if successful
|
||||||
if (!result || (it != request.end()) ) {
|
if (!result || (it != request.end()) ) {
|
||||||
rep = http::Reply::stockReply(http::Reply::badRequest);
|
rep = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
std::stringstream content;
|
|
||||||
int position = std::distance(request.begin(), it);
|
int position = std::distance(request.begin(), it);
|
||||||
content << "Input seems to be malformed close to position " << position << "<br>";
|
std::string tmp_position_string;
|
||||||
content << "<pre>";
|
intToString(position, tmp_position_string);
|
||||||
content << req.uri << "<br>";
|
rep.content += "Input seems to be malformed close to position ";
|
||||||
|
rep.content += "<br><pre>";
|
||||||
|
rep.content += request;
|
||||||
|
rep.content += tmp_position_string;
|
||||||
|
rep.content += "<br>";
|
||||||
for(unsigned i = 0, end = std::distance(request.begin(), it); i < end; ++i)
|
for(unsigned i = 0, end = std::distance(request.begin(), it); i < end; ++i)
|
||||||
content << " ";
|
rep.content += " ";
|
||||||
content << "^" << "<br>";
|
rep.content += "^<br></pre>";
|
||||||
content << "</pre>";
|
|
||||||
rep.content += content.str();
|
|
||||||
} else {
|
} else {
|
||||||
//Finished parsing, lets call the right plugin to handle the request
|
//Finished parsing, lets call the right plugin to handle the request
|
||||||
if(pluginMap.Holds(routeParameters.service)) {
|
if(pluginMap.Holds(routeParameters.service)) {
|
||||||
|
@ -21,14 +21,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef STRINGUTIL_H_
|
#ifndef STRINGUTIL_H_
|
||||||
#define STRINGUTIL_H_
|
#define STRINGUTIL_H_
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
#include <boost/spirit/include/karma.hpp>
|
#include <boost/spirit/include/karma.hpp>
|
||||||
#include <boost/spirit/include/qi.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
#include "../DataStructures/Coordinate.h"
|
#include "../DataStructures/Coordinate.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
@ -80,6 +80,20 @@ static inline int stringToInt(const std::string& input) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void doubleToString(const double value, std::string & output){
|
||||||
|
output.clear();
|
||||||
|
std::back_insert_iterator<std::string> sink(output);
|
||||||
|
boost::spirit::karma::generate(sink, boost::spirit::karma::double_, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void doubleToStringWithTwoDigitsBehindComma(const double value, std::string & output){
|
||||||
|
// The largest 32-bit integer is 4294967295, that is 10 chars
|
||||||
|
// On the safe side, add 1 for sign, and 1 for trailing zero
|
||||||
|
char buffer[12] ;
|
||||||
|
sprintf(buffer, "%g", value) ;
|
||||||
|
output = buffer ;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void convertInternalLatLonToString(const int value, std::string & output) {
|
static inline void convertInternalLatLonToString(const int value, std::string & output) {
|
||||||
char buffer[100];
|
char buffer[100];
|
||||||
buffer[10] = 0; // Nullterminierung
|
buffer[10] = 0; // Nullterminierung
|
||||||
@ -106,70 +120,37 @@ static inline void convertInternalReversedCoordinateToString(const _Coordinate &
|
|||||||
output += " ";
|
output += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void doubleToString(const double value, std::string & output){
|
inline void replaceAll(std::string &s, const std::string &sub, const std::string &other) {
|
||||||
// The largest 32-bit integer is 4294967295, that is 10 chars
|
boost::replace_all(s, sub, other);
|
||||||
// On the safe side, add 1 for sign, and 1 for trailing zero
|
|
||||||
char buffer[12] ;
|
|
||||||
sprintf(buffer, "%f", value) ;
|
|
||||||
output = buffer ;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void doubleToStringWithTwoDigitsBehindComma(const double value, std::string & output){
|
|
||||||
// The largest 32-bit integer is 4294967295, that is 10 chars
|
|
||||||
// On the safe side, add 1 for sign, and 1 for trailing zero
|
|
||||||
char buffer[12] ;
|
|
||||||
sprintf(buffer, "%g", value) ;
|
|
||||||
output = buffer ;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string & replaceAll(std::string &s, const std::string &sub, const std::string &other) {
|
|
||||||
assert(!sub.empty());
|
|
||||||
size_t b = 0;
|
|
||||||
for (;;) {
|
|
||||||
b = s.find(sub, b);
|
|
||||||
if (b == s.npos) break;
|
|
||||||
s.replace(b, sub.size(), other);
|
|
||||||
b += other.size();
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void stringSplit(const std::string &s, const char delim, std::vector<std::string>& result) {
|
inline void stringSplit(const std::string &s, const char delim, std::vector<std::string>& result) {
|
||||||
std::stringstream ss(s);
|
boost::split(result, s, boost::is_any_of(std::string(&delim)));
|
||||||
std::string item;
|
|
||||||
while(std::getline(ss, item, delim)) {
|
|
||||||
if(item.size() > 0)
|
|
||||||
result.push_back(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static std::string originals[] = {"&", "\"", "<", ">", "'", "[", "]", "\\"};
|
static std::string originals[] = {"&", "\"", "<", ">", "'", "[", "]", "\\"};
|
||||||
static std::string entities[] = {"&", """, "<", ">", "'", "&91;", "&93;", " \" };
|
static std::string entities[] = {"&", """, "<", ">", "'", "&91;", "&93;", " \" };
|
||||||
|
|
||||||
inline std::string HTMLEntitize( std::string result) {
|
inline std::string HTMLEntitize( std::string & result) {
|
||||||
for(unsigned i = 0; i < sizeof(originals)/sizeof(std::string); i++) {
|
for(unsigned i = 0; i < sizeof(originals)/sizeof(std::string); ++i) {
|
||||||
result = replaceAll(result, originals[i], entities[i]);
|
replaceAll(result, originals[i], entities[i]);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string HTMLDeEntitize( std::string result) {
|
inline std::string HTMLDeEntitize( std::string & result) {
|
||||||
for(unsigned i = 0; i < sizeof(originals)/sizeof(std::string); i++) {
|
for(unsigned i = 0; i < sizeof(originals)/sizeof(std::string); ++i) {
|
||||||
result = replaceAll(result, entities[i], originals[i]);
|
replaceAll(result, entities[i], originals[i]);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool StringStartsWith(std::string & input, std::string & prefix) {
|
inline bool StringStartsWith(const std::string & input, const std::string & prefix) {
|
||||||
return (input.find(prefix) == 0);
|
return boost::starts_with(input, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function returns a 'random' filename in temporary directors.
|
||||||
/*
|
// May not be platform independent.
|
||||||
* Function returns a 'random' filename in temporary directors.
|
|
||||||
* May not be platform independent.
|
|
||||||
*/
|
|
||||||
inline void GetTemporaryFileName(std::string & filename) {
|
inline void GetTemporaryFileName(std::string & filename) {
|
||||||
char buffer[L_tmpnam];
|
char buffer[L_tmpnam];
|
||||||
char * retPointer = tmpnam (buffer);
|
char * retPointer = tmpnam (buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user