From 146efcafa4a3af6f260917124f351ab1c3d2d1a8 Mon Sep 17 00:00:00 2001
From: Torsten Dreyer <torsten@ลง3r.de>
Date: Fri, 27 Feb 2015 11:07:25 +0100
Subject: [PATCH] JsonUriHandler: allow POST updates without child

updates to properties used to be
POST /json/some/property/path
{
  name: 'somechild',
  value: 'somevalue'
}

which required some ugly path hacking when directly updating a node.
now, this works too (and in a probably more intuitive way)
POST /json/some/property/path/somechild
{
  value: 'somevalue'
}
---
 src/Network/http/jsonprops.cxx | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/Network/http/jsonprops.cxx b/src/Network/http/jsonprops.cxx
index 362b43977..dc3ad58e0 100644
--- a/src/Network/http/jsonprops.cxx
+++ b/src/Network/http/jsonprops.cxx
@@ -19,7 +19,7 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #include "jsonprops.hxx"
-
+#include <simgear/misc/strutils.hxx>
 namespace flightgear {
 namespace http {
 
@@ -109,19 +109,29 @@ void JSON::toProp(cJSON * json, SGPropertyNode_ptr base)
 {
   if (NULL == json) return;
 
+  SGPropertyNode_ptr n = base;
+
+  // check if name is set. If so, update child with given name
+  // else update base
   cJSON * cj = cJSON_GetObjectItem(json, "name");
-  if (NULL == cj) return; // a node with no name?
-  char * name = cj->valuestring;
-  if (NULL == name) return; // still no name?
+  if ( cj ) {
+	char * name = cj->valuestring;
+    if (NULL == name) return; // no name?
 
-  //TODO: check valid name
+    string namestr = simgear::strutils::strip(string(name));
+    if( namestr.empty() )
+    	return;
 
-  int index = 0;
-  cj = cJSON_GetObjectItem(json, "index");
-  if (NULL != cj) index = cj->valueint;
-  if (index < 0) return;
+    //TODO: better check for valid name
+
+    int index = 0;
+    cj = cJSON_GetObjectItem(json, "index");
+    if (NULL != cj) index = cj->valueint;
+    if (index < 0) return;
+
+    n = base->getNode(namestr, index, true);
+  }
 
-  SGPropertyNode_ptr n = base->getNode(name, index, true);
   cJSON * children = cJSON_GetObjectItem(json, "children");
   if (NULL != children) {
     for (int i = 0; i < cJSON_GetArraySize(children); i++) {