aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Dahlin <sadmac@google.com>2016-03-11 15:12:31 -0800
committerCasey Dahlin <sadmac@google.com>2016-03-16 11:34:10 -0700
commit18b389918bf285eb25a05ef8b84b51bc586be5f6 (patch)
tree87d6641bc5108c556d1774c345e37ef1d71efd19
parent562e97b8d82a7c3f49a1e293ab55d5f14df489c5 (diff)
downloadplatform2-18b389918bf285eb25a05ef8b84b51bc586be5f6.zip
platform2-18b389918bf285eb25a05ef8b84b51bc586be5f6.tar.xz
webserver: Switch webservd to binder in Android
This should fix chromeos building as a side effect, as we're not depending on flags the gyp file doesn't set anymore. BUG=b:27204884, b:27504653 TEST=Weaved can successfully connect to webservd. Change-Id: Ibab792660600c761eb85f81e3f1fe4dce050b286
-rw-r--r--webserver/libwebserv/request.cc6
-rw-r--r--webserver/libwebserv/request.h11
-rw-r--r--webserver/libwebserv/server.cc32
-rw-r--r--webserver/libwebserv/server.h43
-rw-r--r--webserver/test-client/main.cc42
-rw-r--r--webserver/webservd/main.cc69
6 files changed, 94 insertions, 109 deletions
diff --git a/webserver/libwebserv/request.cc b/webserver/libwebserv/request.cc
index 5d7abf7..972ef6c 100644
--- a/webserver/libwebserv/request.cc
+++ b/webserver/libwebserv/request.cc
@@ -22,6 +22,7 @@
namespace libwebserv {
+#ifndef __ANDROID__
FileInfo::FileInfo(DBusProtocolHandler* handler,
int file_id,
const std::string& request_id,
@@ -44,6 +45,7 @@ void FileInfo::GetData(
success_callback,
error_callback);
}
+#endif // !__ANDROID__
RequestImpl::RequestImpl(DBusProtocolHandler* handler,
const std::string& url,
@@ -71,6 +73,7 @@ std::vector<PairOfStrings> Request::GetFormDataPost() const {
return std::vector<PairOfStrings>{post_data_.begin(), post_data_.end()};
}
+#ifndef __ANDROID__
std::vector<std::pair<std::string, const FileInfo*>> Request::GetFiles() const {
std::vector<std::pair<std::string, const FileInfo*>> data;
data.reserve(file_info_.size());
@@ -79,6 +82,7 @@ std::vector<std::pair<std::string, const FileInfo*>> Request::GetFiles() const {
}
return data;
}
+#endif // !__ANDROID__
std::vector<std::string> Request::GetFormField(const std::string& name) const {
std::vector<std::string> data;
@@ -117,6 +121,7 @@ std::vector<std::string> Request::GetFormFieldGet(
return data;
}
+#ifndef __ANDROID__
std::vector<const FileInfo*> Request::GetFileInfo(
const std::string& name) const {
std::vector<const FileInfo*> data;
@@ -127,6 +132,7 @@ std::vector<const FileInfo*> Request::GetFileInfo(
}
return data;
}
+#endif // !__ANDROID__
std::vector<PairOfStrings> Request::GetHeaders() const {
return std::vector<PairOfStrings>{headers_.begin(), headers_.end()};
diff --git a/webserver/libwebserv/request.h b/webserver/libwebserv/request.h
index 2950d1b..49e1064 100644
--- a/webserver/libwebserv/request.h
+++ b/webserver/libwebserv/request.h
@@ -33,9 +33,11 @@ struct MHD_Connection;
namespace libwebserv {
+using PairOfStrings = std::pair<std::string, std::string>;
+
+#ifndef __ANDROID__
class DBusProtocolHandler;
-using PairOfStrings = std::pair<std::string, std::string>;
// This class represents the file information about a file uploaded via
// POST request using multipart/form-data request.
@@ -67,6 +69,7 @@ class LIBWEBSERV_EXPORT FileInfo final {
DISALLOW_COPY_AND_ASSIGN(FileInfo);
};
+#endif // !__ANDROID__
// A class that represents the HTTP request data.
class LIBWEBSERV_EXPORT Request {
@@ -104,9 +107,11 @@ class LIBWEBSERV_EXPORT Request {
// POST data.
std::vector<PairOfStrings> GetFormDataPost() const;
+#ifndef __ANDROID__
// Returns a list of file information records for all the file uploads in
// the POST request.
std::vector<std::pair<std::string, const FileInfo*>> GetFiles() const;
+#endif // !__ANDROID__
// Gets the values of form field with given |name|. This includes both
// values provided on the URL and as part of form data in POST request.
@@ -119,8 +124,10 @@ class LIBWEBSERV_EXPORT Request {
// Gets the values of URL query parameters with given |name|.
std::vector<std::string> GetFormFieldGet(const std::string& name) const;
+#ifndef __ANDROID__
// Gets the file upload parameters for a file form field of given |name|.
std::vector<const FileInfo*> GetFileInfo(const std::string& name) const;
+#endif // !__ANDROID__
// Returns a list of key-value pairs for all the request headers.
std::vector<PairOfStrings> GetHeaders() const;
@@ -138,7 +145,9 @@ class LIBWEBSERV_EXPORT Request {
std::string method_;
std::multimap<std::string, std::string> post_data_;
std::multimap<std::string, std::string> get_data_;
+#ifndef __ANDROID__
std::multimap<std::string, std::unique_ptr<FileInfo>> file_info_;
+#endif // !__ANDROID__
std::multimap<std::string, std::string> headers_;
};
diff --git a/webserver/libwebserv/server.cc b/webserver/libwebserv/server.cc
index abbc5b5..e4ef6df 100644
--- a/webserver/libwebserv/server.cc
+++ b/webserver/libwebserv/server.cc
@@ -14,19 +14,27 @@
#include <libwebserv/server.h>
-#if defined(WEBSERV_USE_DBUS)
+#ifdef __ANDROID__
+#include "libwebserv/binder_server.h"
+#else
#include "libwebserv/dbus_server.h"
-#endif // defined(WEBSERV_USE_DBUS)
+#endif // __ANDROID__
-#if defined(WEBSERV_USE_BINDER)
-#include "libwebserv/binder_server.h"
-#endif // defined(WEBSERV_USE_BINDER)
using std::unique_ptr;
namespace libwebserv {
-#if defined(WEBSERV_USE_DBUS)
+#ifdef __ANDROID__
+std::unique_ptr<Server> Server::ConnectToServerViaBinder(
+ brillo::MessageLoop* message_loop,
+ const base::Closure& on_server_online,
+ const base::Closure& on_server_offline) {
+ return unique_ptr<Server>(new BinderServer(
+ message_loop, on_server_online, on_server_offline,
+ android::BinderWrapper::GetOrCreateInstance()));
+}
+#else
unique_ptr<Server> Server::ConnectToServerViaDBus(
const scoped_refptr<dbus::Bus>& bus,
const std::string& service_name,
@@ -38,17 +46,7 @@ unique_ptr<Server> Server::ConnectToServerViaDBus(
server->Connect(bus, service_name, cb, on_server_online, on_server_offline);
return ret;
}
-#endif // defined(WEBSERV_USE_DBUS)
+#endif // __ANDROID__
-#if defined(WEBSERV_USE_BINDER)
-std::unique_ptr<Server> Server::ConnectToServerViaBinder(
- brillo::MessageLoop* message_loop,
- const base::Closure& on_server_online,
- const base::Closure& on_server_offline) {
- return unique_ptr<Server>(new BinderServer(
- message_loop, on_server_online, on_server_offline,
- android::BinderWrapper::GetOrCreateInstance()));
-}
-#endif // defined(WEBSERV_USE_BINDER)
} // namespace libwebserv
diff --git a/webserver/libwebserv/server.h b/webserver/libwebserv/server.h
index 6eb8c07..c285005 100644
--- a/webserver/libwebserv/server.h
+++ b/webserver/libwebserv/server.h
@@ -15,13 +15,6 @@
#ifndef WEBSERVER_LIBWEBSERV_SERVER_H_
#define WEBSERVER_LIBWEBSERV_SERVER_H_
-// In our own Android.mk, we set these flags for ourselves. However, for
-// libraries consuming libwebserv, they don't have any of that logic. Leave us
-// with DBus bindings until the Binder interface is ready.
-#if !defined(WEBSERV_USE_DBUS) && !defined(WEBSERV_USE_BINDER)
-#define WEBSERV_USE_DBUS
-#endif
-
#include <memory>
#include <string>
@@ -29,15 +22,13 @@
#include <base/macros.h>
#include <libwebserv/export.h>
-#if defined(WEBSERV_USE_DBUS)
+#ifdef __ANDROID__
+#include <brillo/message_loops/message_loop.h>
+#else
#include <base/memory/ref_counted.h>
#include <brillo/dbus/async_event_sequencer.h>
#include <dbus/bus.h>
-#endif // defined(WEBSERV_USE_DBUS)
-
-#if defined(WEBSERV_USE_BINDER)
-#include <brillo/message_loops/message_loop.h>
-#endif // defined(WEBSERV_USE_BINDER)
+#endif // __ANDROID__
namespace libwebserv {
@@ -50,12 +41,9 @@ class LIBWEBSERV_EXPORT Server {
Server() = default;
virtual ~Server() = default;
-#if defined(WEBSERV_USE_DBUS)
+#ifdef __ANDROID__
// Establish a connection to the system webserver.
//
- // |service_name| is the well known D-Bus name of the client's process, used
- // to expose a callback D-Bus object the web server calls back with incoming
- // requests.
// |on_server_online| and |on_server_offline| will notify the caller when the
// server comes up and down.
//
@@ -63,17 +51,16 @@ class LIBWEBSERV_EXPORT Server {
// process is actually running (ignoring webserver crashes and restarts).
// All registered request handlers will simply be re-registered when the
// webserver appears again.
- static std::unique_ptr<Server> ConnectToServerViaDBus(
- const scoped_refptr<dbus::Bus>& bus,
- const std::string& service_name,
- const brillo::dbus_utils::AsyncEventSequencer::CompletionAction& cb,
+ static std::unique_ptr<Server> ConnectToServerViaBinder(
+ brillo::MessageLoop* message_loop,
const base::Closure& on_server_online,
const base::Closure& on_server_offline);
-#endif // defined(WEBSERV_USE_DBUS)
-
-#if defined(WEBSERV_USE_BINDER)
+#else
// Establish a connection to the system webserver.
//
+ // |service_name| is the well known D-Bus name of the client's process, used
+ // to expose a callback D-Bus object the web server calls back with incoming
+ // requests.
// |on_server_online| and |on_server_offline| will notify the caller when the
// server comes up and down.
//
@@ -81,11 +68,13 @@ class LIBWEBSERV_EXPORT Server {
// process is actually running (ignoring webserver crashes and restarts).
// All registered request handlers will simply be re-registered when the
// webserver appears again.
- static std::unique_ptr<Server> ConnectToServerViaBinder(
- brillo::MessageLoop* message_loop,
+ static std::unique_ptr<Server> ConnectToServerViaDBus(
+ const scoped_refptr<dbus::Bus>& bus,
+ const std::string& service_name,
+ const brillo::dbus_utils::AsyncEventSequencer::CompletionAction& cb,
const base::Closure& on_server_online,
const base::Closure& on_server_offline);
-#endif // defined(WEBSERV_USE_BINDER)
+#endif // __ANDROID__
// A helper method that returns the default handler for "http".
virtual ProtocolHandler* GetDefaultHttpHandler() = 0;
diff --git a/webserver/test-client/main.cc b/webserver/test-client/main.cc
index 215e317..2ec89ea 100644
--- a/webserver/test-client/main.cc
+++ b/webserver/test-client/main.cc
@@ -23,16 +23,7 @@
#define LOG_TAG webservd_testc
-#if defined(WEBSERV_USE_DBUS)
-
-#include <brillo/daemons/dbus_daemon.h>
-#include <brillo/dbus/async_event_sequencer.h>
-
-// If we're using DBus, pick a base class that does DBus related init.
-using WebservTestClientBaseClass = brillo::DBusDaemon;
-using brillo::dbus_utils::AsyncEventSequencer;
-
-#elif defined(WEBSERV_USE_BINDER)
+#ifdef __ANDROID__
#include <binderwrapper/binder_wrapper.h>
@@ -41,8 +32,15 @@ using brillo::dbus_utils::AsyncEventSequencer;
using WebservTestClientBaseClass = brillo::Daemon;
#else
-#error "You must select one of Binder or DBus as an RPC mechanism."
-#endif // defined(WEBSERV_USE_DBUS)
+
+#include <brillo/daemons/dbus_daemon.h>
+#include <brillo/dbus/async_event_sequencer.h>
+
+// If we're using DBus, pick a base class that does DBus related init.
+using WebservTestClientBaseClass = brillo::DBusDaemon;
+using brillo::dbus_utils::AsyncEventSequencer;
+
+#endif // __ANDROID__
using libwebserv::Server;
using libwebserv::ProtocolHandler;
@@ -85,13 +83,7 @@ class WebservTestClient : public WebservTestClientBaseClass {
if (exit_code != EX_OK)
return exit_code;
-#ifdef WEBSERV_USE_DBUS
- webserver_ = Server::ConnectToServerViaDBus(
- bus_, bus_->GetConnectionName(),
- AsyncEventSequencer::GetDefaultCompletionAction(),
- base::Bind(&LogServerOnlineStatus, true /* online */),
- base::Bind(&LogServerOnlineStatus, false /* offline */));
-#elif WEBSERV_USE_BINDER
+#ifdef __ANDROID__
android::BinderWrapper::Create();
if (!binder_watcher_.Init()) {
return EX_OSERR;
@@ -101,7 +93,13 @@ class WebservTestClient : public WebservTestClientBaseClass {
brillo::MessageLoop::current(),
base::Bind(&LogServerOnlineStatus, true /* online */),
base::Bind(&LogServerOnlineStatus, false /* offline */));
-#endif // WEBSERV_USE_DBUS || WEBSERV_USE_BINDER
+#else
+ webserver_ = Server::ConnectToServerViaDBus(
+ bus_, bus_->GetConnectionName(),
+ AsyncEventSequencer::GetDefaultCompletionAction(),
+ base::Bind(&LogServerOnlineStatus, true /* online */),
+ base::Bind(&LogServerOnlineStatus, false /* offline */));
+#endif // __ANDROID__
// Note that adding this handler is only local, and we won't receive
// requests until the library does some async book keeping.
@@ -116,9 +114,9 @@ class WebservTestClient : public WebservTestClientBaseClass {
private:
std::unique_ptr<Server> webserver_;
-#if WEBSERV_USE_BINDER
+#ifdef __ANDROID__
brillo::BinderWatcher binder_watcher_;
-#endif // WEBSERV_USE_BINDER
+#endif // __ANDROID__
DISALLOW_COPY_AND_ASSIGN(WebservTestClient);
}; // class WebservTestClient
diff --git a/webserver/webservd/main.cc b/webserver/webservd/main.cc
index 8782e15..fe0dac8 100644
--- a/webserver/webservd/main.cc
+++ b/webserver/webservd/main.cc
@@ -19,82 +19,67 @@
#include <base/command_line.h>
#include <base/files/file_util.h>
-#ifdef WEBSERV_USE_BINDER
+#ifdef __ANDROID__
#include <binderwrapper/binder_wrapper.h>
#include <brillo/binder_watcher.h>
#include <brillo/daemons/daemon.h>
-#endif // WEBSERV_USE_BINDER
-#ifdef WEBSERV_USE_DBUS
+#else
#include <brillo/dbus/async_event_sequencer.h>
#include <brillo/dbus/exported_object_manager.h>
#include <brillo/daemons/dbus_daemon.h>
-#endif // WEBSERV_USE_DBUS
-#include <brillo/flag_helper.h>
-#if !defined(__ANDROID__)
#include <brillo/minijail/minijail.h>
-#endif // !defined(__ANDROID__)
+#endif // __ANDROID__
+#include <brillo/flag_helper.h>
#include <brillo/syslog_logging.h>
-#ifdef WEBSERV_USE_BINDER
+#ifdef __ANDROID__
#include "webservd/binder_server.h"
-#endif // WEBSERV_USE_BINDER
-#include "webservd/config.h"
-#include "webservd/log_manager.h"
-#ifdef WEBSERV_USE_DBUS
+#include "webserv_common/binder_constants.h"
+#else
#include "webservd/server.h"
#endif
+#include "webservd/config.h"
+#include "webservd/log_manager.h"
#include "webservd/utils.h"
-#ifdef WEBSERV_USE_BINDER
-#include "webserv_common/binder_constants.h"
-#endif // WEBSERV_USE_BINDER
-
#if defined(__ANDROID__)
-#ifdef WEBSERV_USE_BINDER
#include <firewalld/firewall.h>
#else
-#include "webservd/firewalld_firewall.h"
-using FirewallImpl = webservd::FirewalldFirewall;
-#endif
-#else
#include "webservd/permission_broker_firewall.h"
using FirewallImpl = webservd::PermissionBrokerFirewall;
#endif // defined(__ANDROID__)
-#ifdef WEBSERV_USE_DBUS
+#ifdef __ANDROID__
+using BaseDaemon = brillo::Daemon;
+#else
using brillo::dbus_utils::AsyncEventSequencer;
using BaseDaemon = brillo::DBusServiceDaemon;
-#else
-using BaseDaemon = brillo::Daemon;
-#endif // WEBSERV_USE_DBUS
+#endif // __ANDROID__
namespace {
const char kDefaultConfigFilePath[] = "/etc/webservd/config";
-#ifdef WEBSERV_USE_DBUS
+#ifndef __ANDROID__
const char kServiceName[] = "org.chromium.WebServer";
const char kRootServicePath[] = "/org/chromium/WebServer";
-#endif // WEBSERV_USE_DBUS
-
-#if !defined(__ANDROID__)
const char kWebServerUserName[] = "webservd";
const char kWebServerGroupName[] = "webservd";
#endif // !defined(__ANDROID__)
class Daemon final : public BaseDaemon {
public:
-#ifdef WEBSERV_USE_DBUS
+#ifdef __ANDROID__
explicit Daemon(webservd::Config config)
- : DBusServiceDaemon{kServiceName, kRootServicePath},
- config_{std::move(config)} {}
+ : config_{std::move(config)} {}
#else
explicit Daemon(webservd::Config config)
- : config_{std::move(config)} {}
-#endif // WEBSERV_USE_DBUS
+ : DBusServiceDaemon{kServiceName, kRootServicePath},
+ config_{std::move(config)} {}
+#endif // __ANDROID__
protected:
-#ifdef WEBSERV_USE_DBUS
+#ifndef __ANDROID__
void RegisterDBusObjectsAsync(AsyncEventSequencer* sequencer) override {
webservd::LogManager::Init(base::FilePath{config_.log_directory});
server_.reset(new webservd::Server{
@@ -107,10 +92,10 @@ class Daemon final : public BaseDaemon {
void OnShutdown(int* /* return_code */) override {
server_.reset();
}
-#endif // WEBSERV_USE_DBUS
+#endif // !__ANDROID__
private:
-#ifdef WEBSERV_USE_BINDER
+#ifdef __ANDROID__
int OnInit() override {
int result = brillo::Daemon::OnInit();
if (result != EX_OK) {
@@ -136,15 +121,15 @@ class Daemon final : public BaseDaemon {
return EX_OK;
}
-#endif // WEBSERV_USE_BINDER
+#endif // __ANDROID__
webservd::Config config_;
-#ifdef WEBSERV_USE_DBUS
- std::unique_ptr<webservd::Server> server_;
-#else
+#ifdef __ANDROID__
std::unique_ptr<webservd::BinderServer> server_;
brillo::BinderWatcher binder_watcher_;
-#endif // WEBSERV_USE_DBUS
+#else
+ std::unique_ptr<webservd::Server> server_;
+#endif // __ANDROID__
DISALLOW_COPY_AND_ASSIGN(Daemon);
};