25#include <simgear/debug/logstream.hxx>
26#include <simgear/misc/strutils.hxx>
41static void ReplaceAll(std::string & str,
const std::string & from,
const std::string & to)
44 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
45 str.replace(start_pos, from.length(), to);
46 start_pos += to.length();
69 for (
int i = 0;
i < node->nChildren();
i++)
70 push_back(node->getChild(
i));
71 std::sort(begin(), end(), CompareNodes());
76 bool operator() (
const SGPropertyNode *a,
const SGPropertyNode *b)
const {
77 int r = strcmp(a->getNameString().c_str(), b->getNameString().c_str());
78 return r ? r < 0 : a->getIndex() < b->getIndex();
86 case simgear::props::NONE:
return "";
87 case simgear::props::ALIAS:
return "alias";
88 case simgear::props::BOOL:
return "bool";
89 case simgear::props::INT:
return "int";
90 case simgear::props::LONG:
return "long";
91 case simgear::props::FLOAT:
return "float";
92 case simgear::props::DOUBLE:
return "double";
93 case simgear::props::STRING:
return "string";
94 case simgear::props::UNSPECIFIED:
return "unspecified";
95 case simgear::props::EXTENDED:
return "extended";
96 case simgear::props::VEC3D:
return "vec3d";
97 case simgear::props::VEC4D:
return "vec4d";
104 using namespace simgear::strutils;
106 string path = prefix;
121 setAttribute(
"href",
string(
"/json/")+propertyPath+
"?i=y")->
136 for( string_list::iterator it = items.begin(); it != items.end(); ++it ) {
137 if( (*it).empty() )
continue;
138 path.append( *it ).append(
"/" );
170 string value = node->getStringValue();
171 int len = value.length();
173 if( len < 15 ) len = 15;
177 if( node->getType() == simgear::props::BOOL ) {
183 }
else if( len < 60 ) {
191 int rows = (len / 60)+1;
193 root =
new DOMNode(
"textarea" );
207 string propertyPath = request.
Uri;
210 propertyPath = propertyPath.substr(
getUri().size() );
213 size_t pos = propertyPath.find(
'?' );
214 if( pos != string::npos ) {
215 propertyPath = propertyPath.substr( 0, pos-1 );
219 while( !propertyPath.empty() && propertyPath[ propertyPath.length()-1 ] ==
'/' )
220 propertyPath = propertyPath.substr(0,propertyPath.length()-1);
225 SG_LOG(SG_NETWORK,SG_INFO,
"httpd: setting " << propertyPath <<
" to '" << value <<
"'" );
229 catch(
string & s ) {
230 SG_LOG(SG_NETWORK,SG_WARN,
"httpd: setting " << propertyPath <<
" to '" << value <<
"' failed: " << s );
236 if( it->first ==
"submit" )
continue;
237 string pp = propertyPath +
"/" + it->first;
238 SG_LOG(SG_NETWORK,SG_INFO,
"httpd: setting " << pp <<
" to '" << it->second <<
"'" );
242 catch(
string & s ) {
243 SG_LOG(SG_NETWORK,SG_WARN,
"httpd: setting " << pp <<
" to '" << it->second <<
"' failed: " << s );
269 SGPropertyNode_ptr node;
271 node =
fgGetNode(
string(
"/") + propertyPath );
273 catch(
string & s ) {
274 SG_LOG(SG_NETWORK,SG_WARN,
"httpd: reading '" << propertyPath <<
"' failed: " << s );
276 if( !node.valid() ) {
286 }
else if( node->nChildren() > 0 ) {
316 for(SortedChilds::iterator it = sortedChilds.begin(); it != sortedChilds.end(); ++it ) {
320 SGPropertyNode_ptr child = *it;
321 string name = child->getDisplayName(
true);
329 if ( child->nChildren() > 0 ) {
349 if ( child->nChildren() == 0 ) {
400 response.
Content =
"<!DOCTYPE html>";
403 response.
Header[
"Content-Type"] =
"text/html; charset=UTF-8";
virtual std::string render() const
virtual DOMNode * setAttribute(const std::string &name, const std::string &value)
virtual DOMNode * addChild(DOMElement *child)
std::string get(const std::string &key) const
StringMap RequestVariables
virtual bool handleGetRequest(const HTTPRequest &request, HTTPResponse &response, Connection *connection)
Convenience method for GET Requests, gets called by handleRequest if not overridden.
SortedChilds(SGPropertyNode_ptr node)
const std::string & getUri() const
Getter for the URI this handler serves.
std::vector< std::string > string_list
static const std::string specialChars[][2]
static std::string htmlSpecialChars(const std::string &s)
static void ReplaceAll(std::string &str, const std::string &from, const std::string &to)
static DOMNode * createLabeledRadioButton(const char *label, const std::string &name, bool checked)
static DOMElement * renderPropertyValueElement(SGPropertyNode_ptr node)
static const char * getPropertyTypeString(simgear::props::Type type)
DOMElement * createHeader(const string &prefix, const string &propertyPath)
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
bool fgSetString(char const *name, char const *str)
Set a string value for a property.
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
std::vector< std::string > split(std::string str, char d)