[Debian-iot-packaging] [openzwave-controlpanel] 06/81: Fix bug in the association code not checking returned association count. Remove old submit for device operations and go to AJAX dynamic updates. Sped up resets significantly. Return some HTML to AJAX posts to prevent Firefox from generating errors. Minor UI bug fixes and tweaks for consistency when removing nodes.

Dara Adib daradib-guest at moszumanska.debian.org
Thu Dec 22 16:57:44 UTC 2016


This is an automated email from the git hooks/post-receive script.

daradib-guest pushed a commit to branch debian/master
in repository openzwave-controlpanel.

commit 8c9c2f291ad0d1dff85f9abc13ec3210531fb95e
Author: glsatz <glsatz at gmail.com>
Date:   Tue May 17 00:08:52 2011 +0000

    Fix bug in the association code not checking returned association count.
    Remove old submit for device operations and go to AJAX dynamic
    updates. Sped up resets significantly.
    Return some HTML to AJAX posts to prevent Firefox from generating errors.
    Minor UI bug fixes and tweaks for consistency when removing nodes.
---
 cp.html       |  2 --
 cp.js         | 62 ++++++++++++++++++++++++++++++++++++++++-------------
 ozwcp.cpp     | 12 ++++++-----
 webserver.cpp | 69 ++++++++++++++++++++++-------------------------------------
 4 files changed, 80 insertions(+), 65 deletions(-)

diff --git a/cp.html b/cp.html
index 3d1fe91..655672c 100644
--- a/cp.html
+++ b/cp.html
@@ -25,8 +25,6 @@
     </style>
   <link rel="icon" href="favicon.png" type="image/x-icon">
   <link rel="shortcut icon" href="favicon.png" type="image/x-icon">
-  <script type="text/javascript" src="dev.js">
-    </script>
   <script type="text/javascript" src="cp.js">
     </script>
 </head>
diff --git a/cp.js b/cp.js
index b08f484..88512e6 100644
--- a/cp.js
+++ b/cp.js
@@ -73,11 +73,10 @@ function PollReply()
       document.getElementById('cmode').value = elem[0].getAttribute('cmode');
     if (elem[0].getAttribute('save') != needsave) {
 	needsave = elem[0].getAttribute('save');
-	span = document.getElementById('saveinfo');
 	if (needsave == '1') {
-	  span.style.display = 'block';
+	  document.getElementById('saveinfo').style.display = 'block';
 	} else {
-	  span.style.display = 'none';
+	  document.getElementById('saveinfo').style.display = 'none';
 	}
     }
     elem = xml.getElementsByTagName('admin');
@@ -173,7 +172,8 @@ function Poll()
 function BED()
 {
   var forms = document.forms;
-  var off = (dev.length == 0) && !usb;
+  var off = (document.DevPost.devname.value.length == 0) && !document.DevPost.usbb.checked;
+  var info;
 
   for (var i = 0; i < forms.length; i++) {
     if (forms[i].name == '')
@@ -193,15 +193,24 @@ function BED()
   document.getElementById('configinfo').checked = false;
   document.AdmPost.adminops.selectedIndex = 0;
   document.AdmPost.adminops.disabled = off;
+  info = document.getElementById('adminfo');
+  info.style.display = 'none';
   document.NodePost.nodeops.selectedIndex = 0;
   document.NodePost.nodeops.disabled = off;
+  info = document.getElementById('nodeinfo');
+  info.style.display = 'none';
+  info = document.getElementById('nodecntl');
+  info.style.display = 'none';
   if (off) {
-    document.getElementById('configcur').innerHTML = '';
-    document.getElementById('configcon').innerHTML = '';
-    document.getElementById('configinfo').innerHTML = '';
-  } else {
-    document.DevPost.devname.value = dev;
-    document.DevPost.usbb.checked = usb;
+    document.getElementById('homeid').value = '';
+    document.getElementById('cmode').value = '';
+    document.getElementById('nodecount').value = '';
+    document.getElementById('saveinfo').style.display = 'none';
+    document.getElementById('tbody').innerHTML= '';
+    document.getElementById('divconfigcur').innerHTML = '';
+    document.getElementById('divconfigcon').innerHTML = '';
+    document.getElementById('divconfiginfo').innerHTML = '';
+    document.getElementById('logdata').innerHTML= '';
   }
   if (!off) {
     Poll();
@@ -210,6 +219,7 @@ function BED()
     clearTimeout(polltmr);
     clearTimeout(pollwait);
   }
+  curnode=null;
 }
 function DoConfig(id)
 {
@@ -273,11 +283,27 @@ function DoDevUSB()
 function DoDevPost(fun)
 {
   if (document.DevPost.devname.value.length > 0 || document.DevPost.usbb.checked) {
-    document.DevPost.action='/devpost.html?dev='+document.DevPost.devname.value+'&fn='+fun+'&usb='+document.DevPost.usbb.checked;
-    document.DevPost.submit();
-    return true;
-  } else
-    return false;
+    var posthttp;
+    var params;
+
+    params = 'dev='+document.DevPost.devname.value+'&fn='+fun+'&usb='+document.DevPost.usbb.checked;
+    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
+      posthttp=new XMLHttpRequest();
+    } else {
+      posthttp=new ActiveXObject("Microsoft.XMLHTTP");
+    }
+    posthttp.open('POST','devpost.html',false);
+    posthttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+    posthttp.setRequestHeader("Content-length", params.length);
+    posthttp.setRequestHeader("Connection", "close");
+    posthttp.send(params);
+    if (fun == 'close') {
+      document.DevPost.devname = '';
+      document.DevPost.usbb.checked = false;
+    }
+    BED();
+  }
+  return false;
 }
 function DoAdmPost(can)
 {
@@ -316,6 +342,12 @@ function DoAdmPost(can)
   posthttp.setRequestHeader("Content-length", params.length);
   posthttp.setRequestHeader("Connection", "close");
   posthttp.send(params);
+  if (fun == 'remc' || fun == 'remd') {
+    document.getElementById('divconfigcur').innerHTML = '';
+    document.getElementById('divconfigcon').innerHTML = '';
+    document.getElementById('divconfiginfo').innerHTML = '';
+    curnode = null;
+  }
   return false;
 }
 function DoAdmHelp()
diff --git a/ozwcp.cpp b/ozwcp.cpp
index ec290b5..cf86241 100644
--- a/ozwcp.cpp
+++ b/ozwcp.cpp
@@ -431,11 +431,13 @@ void OnNotification (Notification const* _notification, void* _context)
       Log::Write("Notification: Group Home 0x%08x Node %d Group %d",
 		 _notification->GetHomeId(), _notification->GetNodeId(), _notification->GetGroupIdx());
       uint8 *v;
-      uint8 n = Manager::Get()->GetAssociations(homeId, _notification->GetNodeId(), _notification->GetGroupIdx(), &v);
-      pthread_mutex_lock(&nlock);
-      nodes[_notification->GetNodeId()]->addGroup(_notification->GetNodeId(), _notification->GetGroupIdx(), n, v);
-      pthread_mutex_unlock(&nlock);
-      delete [] v;
+      int8 n = Manager::Get()->GetAssociations(homeId, _notification->GetNodeId(), _notification->GetGroupIdx(), &v);
+      if (n > 0) {
+	pthread_mutex_lock(&nlock);
+	nodes[_notification->GetNodeId()]->addGroup(_notification->GetNodeId(), _notification->GetGroupIdx(), n, v);
+	pthread_mutex_unlock(&nlock);
+	delete [] v;
+      }
     }
     break;
   case Notification::Type_NodeNew:
diff --git a/webserver.cpp b/webserver.cpp
index 972fb05..c01f927 100644
--- a/webserver.cpp
+++ b/webserver.cpp
@@ -65,7 +65,7 @@ using namespace OpenZWave;
 #define FNF "<html><head><title>File not found</title></head><body>File not found: %s</body></html>"
 #define UNKNOWN "<html><head><title>Nothingness</title></head><body>There is nothing here. Sorry.</body></html>\n"
 #define DEFAULT "<script type=\"text/javascript\"> document.location.href='/';</script>"
-#define DEVJS "var dev = '%s'; var usb = %s;\n"
+#define EMPTY "<html></html>"
 
 typedef struct _conninfo {
   conntype_t conn_type;
@@ -425,7 +425,14 @@ int web_config_post (void *cls, enum MHD_ValueKind kind, const char *key, const
   conninfo_t *cp = (conninfo_t *)cls;
 
   fprintf(stderr, "post: key=%s data=%s size=%d\n", key, data, size);
-  if (strcmp(cp->conn_url, "/valuepost.html") == 0) {
+  if (strcmp(cp->conn_url, "/devpost.html") == 0) {
+    if (strcmp(key, "fn") == 0)
+      cp->conn_arg1 = (void *)strdup(data);
+    else if (strcmp(key, "dev") == 0)
+      cp->conn_arg2 = (void *)strdup(data);
+    else if (strcmp(key, "usb") == 0)
+      cp->conn_arg3 = (void *)strdup(data);
+  } else if (strcmp(cp->conn_url, "/valuepost.html") == 0) {
     cp->conn_arg1 = (void *)strdup(key);
     cp->conn_arg2 = (void *)strdup(data);
   } else if (strcmp(cp->conn_url, "/admpost.html") == 0) {
@@ -519,55 +526,37 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
       ret = web_send_file(conn, "cp.js", MHD_HTTP_OK);
     else if (strcmp(url, "/favicon.png") == 0)
       ret = web_send_file(conn, "openzwavetinyicon.png", MHD_HTTP_OK);
-    else if (strcmp(url, "/dev.js") == 0) {
-      int len = sizeof(DEVJS) - 1; // %s but one for \0
-      char *s;
-      if (devname != NULL) {
-	len += strlen(devname);
-	logbytes = 0;
-	setNodesChanged(true);
-      }
-      s = (char *)malloc(len);
-      if (s == NULL) {
-	fprintf(stderr, "Out of memory dev.js\n");
-	exit(1);
-      }
-      snprintf(s, len, DEVJS, devname ? devname : "", usb ? "true" : "false");
-      ret = web_send_data(conn, s, MHD_HTTP_OK, true, false, "text/javascript"); // free but no copy
-    } else if (strcmp(url, "/poll.xml") == 0 && (devname != NULL || usb)) {
+    else if (strcmp(url, "/poll.xml") == 0 && (devname != NULL || usb))
       ret = SendPollResponse(conn);
-    } else
+    else
       ret = web_send_data(conn, UNKNOWN, MHD_HTTP_NOT_FOUND, false, false, NULL); // no free, no copy
     return ret;
   } else if (strcmp(method, MHD_HTTP_METHOD_POST) == 0) {
     cp = (conninfo_t *)*ptr;
     if (strcmp(url, "/devpost.html") == 0) {
-      const char *fun = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "fn");
-      const char *dev = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "dev");
-      const char *usbp = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "usb");
       if (*up_data_size != 0) {
 	MHD_post_process(cp->conn_pp, up_data, *up_data_size);
 	*up_data_size = 0;
 
-	if (strcmp(fun, "open") == 0) { /* start connection */
+	if (strcmp((char *)cp->conn_arg1, "open") == 0) { /* start connection */
 	  if (devname != NULL) {
 	    free(devname);
 	    devname = NULL;
 	  }
-	  if (usbp != NULL && strcmp(usbp, "true") == 0) {
+	  if ((char *)cp->conn_arg3 != NULL && strcmp((char *)cp->conn_arg3, "true") == 0) {
 	    Manager::Get()->AddDriver("HID Controller", Driver::ControllerInterface_Hid );
 	    usb = true;
 	  } else {
-	    devname = (char *)malloc(strlen(dev) + 1);
+	    devname = (char *)malloc(strlen((char *)cp->conn_arg2) + 1);
 	    if (devname == NULL) {
 	      fprintf(stderr, "Out of memory open devname\n");
 	      exit(1);
 	    }
 	    usb = false;
-	    strcpy(devname, dev);
+	    strcpy(devname, (char *)cp->conn_arg2);
 	    Manager::Get()->AddDriver(devname);
 	  }
-	} else if (strcmp(fun, "close") == 0) { /* terminate */
+	} else if (strcmp((char *)cp->conn_arg1, "close") == 0) { /* terminate */
 	  if (devname != NULL || usb)
 	    Manager::Get()->RemoveDriver(devname ? devname : "HID Controller");
 	  if (devname != NULL) {
@@ -576,17 +565,18 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
 	  }
 	  usb = false;
 	  homeId = 0;
-	} else if (strcmp(fun, "reset") == 0) { /* reset */
+	} else if (strcmp((char *)cp->conn_arg1, "reset") == 0) { /* reset */
 	  Manager::Get()->ResetController(homeId);
+	  sleep(2);
 	  Manager::Get()->RemoveDriver(devname ? devname : "HID Controller");
 	  sleep(5);
 	  if (devname != NULL)
 	    Manager::Get()->AddDriver(devname);
 	  else
 	    Manager::Get()->AddDriver("HID Controller", Driver::ControllerInterface_Hid );
-	} else if (strcmp(fun, "sreset") == 0) { /* soft reset */
+	} else if (strcmp((char *)cp->conn_arg1, "sreset") == 0) { /* soft reset */
 	  Manager::Get()->SoftReset(homeId);
-	} else if (strcmp(fun, "exit") == 0) { /* exit */
+	} else if (strcmp((char *)cp->conn_arg1, "exit") == 0) { /* exit */
 	  pthread_mutex_lock(&glock);
 	  Manager::Get()->RemoveDriver(devname ? devname : "HID Controller");
 	  if (devname != NULL) {
@@ -613,7 +603,7 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
 	}
 	return MHD_YES;
       } else
-	ret = web_send_data(conn, "", MHD_HTTP_OK, false, false, NULL); // no free, no copy
+	ret = web_send_data(conn, EMPTY, MHD_HTTP_OK, false, false, NULL); // no free, no copy
     } else if (strcmp(url, "/admpost.html") == 0) {
       if (*up_data_size != 0) {
 	MHD_post_process(cp->conn_pp, up_data, *up_data_size);
@@ -636,13 +626,6 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
 							       web_controller_update, this, true));
 	} else if (strcmp((char *)cp->conn_arg1, "cprim") == 0) {
 	  setAdminFunction("Create Primary");
-
-
-
-
-
-
-
 	  setAdminState(
 			Manager::Get()->BeginControllerCommand(homeId,
 							       Driver::ControllerCommand_CreateNewPrimary,
@@ -737,7 +720,7 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
 	}
 	return MHD_YES;
       } else
-	ret = web_send_data(conn, "", MHD_HTTP_OK, false, false, NULL); // no free, no copy
+	ret = web_send_data(conn, EMPTY, MHD_HTTP_OK, false, false, NULL); // no free, no copy
     } else if (strcmp(url, "/nodepost.html") == 0) {
       if (*up_data_size != 0) {
 	uint8 node;
@@ -756,7 +739,7 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
 	}
 	return MHD_YES;
       } else
-	ret = web_send_data(conn, "", MHD_HTTP_OK, false, false, NULL); // no free, no copy
+	ret = web_send_data(conn, EMPTY, MHD_HTTP_OK, false, false, NULL); // no free, no copy
     } else if (strcmp(url, "/grouppost.html") == 0) {
       if (*up_data_size != 0) {
 	uint8 node;
@@ -777,7 +760,7 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
 	}
 	return MHD_YES;
       } else
-	ret = web_send_data(conn, "", MHD_HTTP_OK, false, false, NULL); // no free, no copy
+	ret = web_send_data(conn, EMPTY, MHD_HTTP_OK, false, false, NULL); // no free, no copy
     } else if (strcmp(url, "/pollpost.html") == 0) {
       if (*up_data_size != 0) {
 	uint8 node;
@@ -797,7 +780,7 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
 	}
 	return MHD_YES;
       } else
-	ret = web_send_data(conn, "", MHD_HTTP_OK, false, false, NULL); // no free, no copy
+	ret = web_send_data(conn, EMPTY, MHD_HTTP_OK, false, false, NULL); // no free, no copy
     } else if (strcmp(url, "/savepost.html") == 0) {
       if (*up_data_size != 0) {
 	MHD_post_process(cp->conn_pp, up_data, *up_data_size);
@@ -811,7 +794,7 @@ int Webserver::Handler (struct MHD_Connection *conn, const char *url,
 	}
 	return MHD_YES;
       } else
-	ret = web_send_data(conn, "", MHD_HTTP_OK, false, false, NULL); // no free, no copy
+	ret = web_send_data(conn, EMPTY, MHD_HTTP_OK, false, false, NULL); // no free, no copy
     } else
       ret = web_send_data(conn, UNKNOWN, MHD_HTTP_NOT_FOUND, false, false, NULL); // no free, no copy
     return ret;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-iot/openzwave-controlpanel.git



More information about the Debian-iot-packaging mailing list