Merge "ginstall: add flash unlock support for gflt"
diff --git a/cmds/host-test-ssdptax.sh b/cmds/host-test-ssdptax.sh
index 3b12fdf..ebb3ae7 100755
--- a/cmds/host-test-ssdptax.sh
+++ b/cmds/host-test-ssdptax.sh
@@ -5,12 +5,21 @@
 . ./wvtest/wvtest.sh
 
 SSDP=./host-ssdptax
-
 FIFO="/tmp/ssdptax.test.$$"
-python ./ssdptax-test-server.py "$FIFO" &
-sleep 0.5
 
 WVSTART "ssdptax test"
-WVPASSEQ "$($SSDP -t $FIFO)" "ssdp 00:00:00:00:00:00 Test Device;Google Fiber ssdptax"
 
+python ./ssdptax-test-server.py "$FIFO" 1 &
+sleep 0.5
+WVPASSEQ "$($SSDP -t $FIFO)" "ssdp 00:00:00:00:00:00 Test Device;Google Fiber ssdptax"
+rm "$FIFO"
+
+python ./ssdptax-test-server.py "$FIFO" 2 &
+sleep 0.5
+WVPASSEQ "$($SSDP -t $FIFO)" "ssdp 00:00:00:00:00:00 REDACTED;server type"
+rm "$FIFO"
+
+python ./ssdptax-test-server.py "$FIFO" 3 &
+sleep 0.5
+WVPASSEQ "$($SSDP -t $FIFO)" "ssdp 00:00:00:00:00:00 Unknown;server type"
 rm "$FIFO"
diff --git a/cmds/hostnamelookup.gperf b/cmds/hostnamelookup.gperf
index 0330867..5c3526f 100644
--- a/cmds/hostnamelookup.gperf
+++ b/cmds/hostnamelookup.gperf
@@ -75,10 +75,16 @@
 NP-1P| "Roku", "Roku LT 2700"
 NP-1X| "Roku", "Roku 1 2710"
 NP-2L| "Roku", "Roku Streaming Stick 3500"
+NP-2N| "Roku TV", "Roku TV"
 NP-41| "Roku", "Roku 3 4200"
+NP-4A| "Roku", "Roku 2 4210X"
 NP-4E| "Roku", "Roku 3 4230RW"
+NP-5F| "Roku", "Roku 2 4210X"
+NP-5G| "Roku", "Roku 3 4230X"
+NP-5S| "Roku", "Roku Streaming Stick 3600"
 NP-5Y| "Roku", "Roku 2 4210"
 NP-63| "Roku", "Roku 3 4230"
+NP-YW| "Roku TV", "Roku TV"
 NP-YY| "Roku", "Roku 4 4400"
 OBi200%1,3,6,12,15,28,42,66| "Obihai VoIP Adaptor", "OBi200"
 OBi202%1,3,6,12,15,28,42,66| "Obihai VoIP Adaptor", "OBi202"
diff --git a/cmds/ssdptax-test-server.py b/cmds/ssdptax-test-server.py
index c0346cb..54831d4 100644
--- a/cmds/ssdptax-test-server.py
+++ b/cmds/ssdptax-test-server.py
@@ -8,18 +8,39 @@
 import sys
 
 
+text_device_xml = """<root>
+  <specVersion><major>1</major><minor>0</minor></specVersion>
+  <device><friendlyName>Test Device</friendlyName>
+  <manufacturer>Google Fiber</manufacturer>
+  <modelDescription>Unit Test</modelDescription>
+  <modelName>ssdptax</modelName>
+</device></root>"""
+
+
+email_address_xml = """<root>
+  <specVersion><major>1</major><minor>0</minor></specVersion>
+  <device><friendlyName>FOOBAR: foo@example.com:</friendlyName>
+  <manufacturer>Google Fiber</manufacturer>
+  <modelDescription>Unit Test</modelDescription>
+  <modelName>ssdptax</modelName>
+</device></root>"""
+
+
+no_friendlyname_xml = """<root>
+  <specVersion><major>1</major><minor>0</minor></specVersion>
+  <device></device></root>"""
+
+
+xml = ['']
+
+
 class XmlHandler(BaseHTTPServer.BaseHTTPRequestHandler):
   def do_GET(self):
     self.send_response(200)
     self.send_header('Content-type','text/xml')
     self.end_headers()
-    self.wfile.write("""<root>
-        <specVersion><major>1</major><minor>0</minor></specVersion>
-        <device><friendlyName>Test Device</friendlyName>
-        <manufacturer>Google Fiber</manufacturer>
-        <modelDescription>Unit Test</modelDescription>
-        <modelName>ssdptax</modelName>
-    </device></root>""")
+    self.wfile.write(xml[0])
+
 
 def main():
   un = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -27,6 +48,14 @@
   un.listen(1)
   conn, _ = un.accept()
 
+  testnum = int(sys.argv[2])
+  if testnum == 1:
+    xml[0] = text_device_xml
+  if testnum == 2:
+    xml[0] = email_address_xml
+  if testnum == 3:
+    xml[0] = no_friendlyname_xml
+
   s = BaseHTTPServer.HTTPServer(("", 0), XmlHandler)
   sn = s.socket.getsockname()
   port = sn[1]
diff --git a/cmds/ssdptax.cc b/cmds/ssdptax.cc
index 2a991cb..2a06c7a 100644
--- a/cmds/ssdptax.cc
+++ b/cmds/ssdptax.cc
@@ -31,6 +31,7 @@
 #include <curl/curl.h>
 #include <getopt.h>
 #include <netinet/in.h>
+#include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -172,6 +173,27 @@
 
 
 /*
+ * Returns true if the friendlyName appears to include an email address.
+ */
+bool contains_email_address(const std::string &friendlyName)
+{
+  regex_t r_email;
+  int rc;
+
+  if (regcomp(&r_email, ".+@[a-z0-9.-]+\\.[a-z0-9.-]+",
+        REG_EXTENDED | REG_ICASE | REG_NOSUB)) {
+    fprintf(stderr, "%s: regcomp failed!\n", __FUNCTION__);
+    exit(1);
+  }
+
+  rc = regexec(&r_email, friendlyName.c_str(), 0, NULL, 0);
+  regfree(&r_email);
+
+  return (rc == 0);
+}
+
+
+/*
  * Combine the manufacturer and model. If the manufacturer name
  * is already present in the model string, don't duplicate it.
  */
@@ -206,7 +228,9 @@
   }
 
   mac = get_l2addr_for_ip(info->ipaddr);
-  if (info->friendlyName.length() > 0) {
+  if (contains_email_address(info->friendlyName)) {
+    result = "ssdp " + mac + " REDACTED;" + info->srv_type;
+  } else if (info->friendlyName.length() > 0) {
     result = "ssdp " + mac + " " + info->friendlyName + ";" +
       unfriendly_name(info->manufacturer, info->model);
   } else {