Lots of updates to webserver.

Make ssl keys consistent (and write to the correct location)
Make sessions keyed by connection id
Clean up logging frameworks
Add new static files, and make firmware update work
Make sensors work again
Add better json handling

Change-Id: I531a0fd7d583e049949cf27aa71544808fd7642d
diff --git a/boost-dbus/test/avahi.cpp b/boost-dbus/test/avahi.cpp
index 5d2deb8..1b46c02 100644
--- a/boost-dbus/test/avahi.cpp
+++ b/boost-dbus/test/avahi.cpp
@@ -8,7 +8,6 @@
 #include <dbus/filter.hpp>
 #include <dbus/match.hpp>
 #include <dbus/message.hpp>
-#include <dbus/utility.hpp>
 #include <functional>
 
 #include <unistd.h>
@@ -123,57 +122,25 @@
   io.run();
 }
 
-void query_interfaces(dbus::connection_ptr system_bus,
-                      std::string& service_name, std::string& object_name) {
-  dbus::endpoint service_daemon(service_name, object_name,
-                                "org.freedestop.DBus.Introspectable");
-  dbus::message m = dbus::message::new_call(service_daemon, "Introspect");
-  try {
-    auto r = system_bus->send(m);
-    std::vector<std::string> names;
-    // Todo(ed) figure out why we're occassionally getting access
-    // denied errors
-    // EXPECT_EQ(ec, boost::system::errc::success);
-
-    std::string xml;
-    r.unpack(xml);
-    // TODO(ed) names needs lock for multithreaded access
-    dbus::read_dbus_xml_names(xml, names);
-    // loop over the newly added items
-    for (auto name : names) {
-      std::cout << name << "\n";
-      auto new_service_string = object_name + "/" + name;
-      query_interfaces(system_bus, service_name, new_service_string);
-    }
-  } catch (boost::system::error_code e) {
-    std::cout << e;
-  }
-}
-
 TEST(BOOST_DBUS, SingleSensorChanged) {
   boost::asio::io_service io;
 
   auto system_bus = std::make_shared<dbus::connection>(io, dbus::bus::system);
 
-  dbus::match ma(system_bus,
-                 "type='signal',path_namespace='/xyz/openbmc_project/sensors'");
+  dbus::match ma(system_bus, "type='signal',path_namespace='/xyz/openbmc_project/sensors'");
 
   dbus::filter f(system_bus, [](dbus::message& m) {
     auto member = m.get_member();
     return member == "PropertiesChanged";
   });
 
-  // std::function<void(boost::system::error_code, dbus::message)> event_handler
-  // =
-
   f.async_dispatch([&](boost::system::error_code ec, dbus::message s) {
     std::string object_name;
     EXPECT_EQ(s.get_path(),
               "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp");
 
     std::vector<std::pair<std::string, dbus::dbus_variant>> values;
-    s.unpack(object_name).unpack(values);
-
+    s.unpack(object_name, values);
     EXPECT_EQ(object_name, "xyz.openbmc_project.Sensor.Value");
 
     EXPECT_EQ(values.size(), 1);
@@ -226,8 +193,7 @@
               "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp");
 
     std::vector<std::pair<std::string, dbus::dbus_variant>> values;
-    s.unpack(object_name).unpack(values);
-
+    s.unpack(object_name, values);
     EXPECT_EQ(object_name, "xyz.openbmc_project.Sensor.Value");
 
     EXPECT_EQ(values.size(), 1);
@@ -239,6 +205,7 @@
     } else {
       f.async_dispatch(callback);
     }
+    s.unpack(object_name, values);
 
   };
   f.async_dispatch(callback);
@@ -275,18 +242,11 @@
     io.stop();
     FAIL() << "Callback was never called\n";
   });
-  std::string requested_name = "xyz.openbmc_project.fwupdate1.server";
-  auto system_bus = std::make_shared<dbus::connection>(io, dbus::bus::system);
-  //system_bus->request_name(requested_name);
 
-  /* not sure we even need to add a match for method calls,
-   * but this is how you might do it .... */
-  dbus::match ma(
-      system_bus,
-      "type='method_call',path_namespace='/xyz/openbmc_project/fwupdate1'");
+  auto system_bus = std::make_shared<dbus::connection>(io, dbus::bus::system);
+  std::string requested_name = system_bus->get_unique_name();
 
   dbus::filter f(system_bus, [](dbus::message& m) {
-    // std::cerr << "filter called: " << m << std::endl;
     return (m.get_member() == "Get" &&
             m.get_interface() == "org.freedesktop.DBus.Properties" &&
             m.get_signature() == "ss");
@@ -298,7 +258,7 @@
           FAIL() << ec;
         } else {
           std::string intf_name, prop_name;
-          s.unpack(intf_name).unpack(prop_name);
+          s.unpack(intf_name, prop_name);
 
           EXPECT_EQ(intf_name, "xyz.openbmc_project.fwupdate1");
           EXPECT_EQ(prop_name, "State");
@@ -306,25 +266,26 @@
           // send a reply so dbus doesn't get angry?
           auto r = system_bus->reply(s);
           r.pack("IDLE");
-          system_bus->async_send(
-              r, [&](boost::system::error_code ec, dbus::message s) {});
-          io.stop();
+          system_bus->async_send(r, [&](boost::system::error_code ec,
+                                        dbus::message s) { });
+           io.stop();
         }
-      };
+     };
   f.async_dispatch(method_handler);
 
-  dbus::endpoint test_endpoint(requested_name, "/xyz/openbmc_project/fwupdate1",
-                               "org.freedesktop.DBus.Properties");
+  dbus::endpoint test_endpoint(
+      requested_name,
+      "/xyz/openbmc_project/fwupdate1",
+      "org.freedesktop.DBus.Properties");
 
   auto method_name = std::string("Get");
   auto m = dbus::message::new_call(test_endpoint, method_name);
 
-  m.pack("xyz.openbmc_project.fwupdate1");
-  m.pack("State");
-
-  system_bus->async_send(m, [&](boost::system::error_code ec, dbus::message s) {
-    std::cerr << "received s: " << s << std::endl;
-  });
+  m.pack("xyz.openbmc_project.fwupdate1", "State");
+  system_bus->async_send(m,
+                        [&](boost::system::error_code ec, dbus::message s) {
+                        std::cerr <<"received s: " << s << std::endl;
+                        });
 
   io.run();
 }
diff --git a/boost-dbus/test/error.cpp b/boost-dbus/test/error.cpp
new file mode 100644
index 0000000..0c0cf60
--- /dev/null
+++ b/boost-dbus/test/error.cpp
@@ -0,0 +1,26 @@
+// Copyright (c) Benjamin Kietzman (github.com/bkietz)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <dbus/connection.hpp>
+#include <dbus/endpoint.hpp>
+#include <dbus/filter.hpp>
+#include <dbus/match.hpp>
+#include <dbus/message.hpp>
+#include <functional>
+
+#include <unistd.h>
+#include <gtest/gtest.h>
+
+using namespace boost::asio;
+using namespace dbus;
+using boost::system::error_code;
+
+TEST(ErrorTest, GetHostName) {
+  io_service io;
+  EXPECT_THROW(connection system_bus(io, "unix:path=/foo/bar/baz_socket"),
+               boost::system::system_error);
+
+  io.run();
+}
\ No newline at end of file
diff --git a/boost-dbus/test/message.cpp b/boost-dbus/test/message.cpp
index 8c8169f..aaf49c6 100644
--- a/boost-dbus/test/message.cpp
+++ b/boost-dbus/test/message.cpp
@@ -47,7 +47,21 @@
   m.pack(v);
 
   std::vector<dbus::dbus_variant> av{{std::string("hello world"), 1, 42}};
-  m.pack(av);
+  m.pack(v, av);
+}
+
+
+TEST(MessageTest, VariadicCallback) {
+    auto signal_name = std::string("PropertiesChanged");
+  dbus::endpoint test_endpoint(
+      "org.freedesktop.Avahi",
+      "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp",
+      "org.freedesktop.DBus.Properties");
+  auto m = dbus::message::new_signal(test_endpoint, signal_name);
+
+  dbus::dbus_variant v(std::string("hello world"));
+  std::vector<dbus::dbus_variant> av{{std::string("hello world"), 1, 42}};
+  m.pack(v, av);
 }
 
 // I actually don't know what to do with these yet.