diff --git a/internal/platform/implementation/linux/log_message.cc b/internal/platform/implementation/linux/log_message.cc index f2825d92..3fc10a47 100644 --- a/internal/platform/implementation/linux/log_message.cc +++ b/internal/platform/implementation/linux/log_message.cc @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -17,7 +18,7 @@ namespace nearby { static std::unique_ptr global_log_control_; static absl::once_flag log_control_init_; -static void init_log_control() { +static void init_log_control(std::nullptr_t) { global_log_control_ = std::make_unique(linux::getDefaultBusConnection()); } @@ -79,15 +80,16 @@ void LogControl::send(google::LogSeverity severity, const char *full_filename, static inline google::LogSeverity ConvertSeverity(api::LogMessage::Severity severity) { switch (severity) { - case api::LogMessage::Severity::kVerbose: - case api::LogMessage::Severity::kInfo: - return google::GLOG_INFO; case api::LogMessage::Severity::kWarning: return google::GLOG_WARNING; case api::LogMessage::Severity::kError: return google::GLOG_ERROR; case api::LogMessage::Severity::kFatal: return google::GLOG_FATAL; + case api::LogMessage::Severity::kVerbose: + case api::LogMessage::Severity::kInfo: + default: + return google::GLOG_INFO; } } diff --git a/internal/platform/implementation/linux/log_message.h b/internal/platform/implementation/linux/log_message.h index 56093a64..f4cbd5f8 100644 --- a/internal/platform/implementation/linux/log_message.h +++ b/internal/platform/implementation/linux/log_message.h @@ -45,19 +45,17 @@ public: protected: std::string LogLevel() override { switch (severity_) { - case api::LogMessage::Severity::kVerbose: - return "debug"; - break; case api::LogMessage::Severity::kInfo: return "info"; - break; case api::LogMessage::Severity::kWarning: return "warning"; - break; case api::LogMessage::Severity::kError: return "err"; case api::LogMessage::Severity::kFatal: return "emerg"; + case api::LogMessage::Severity::kVerbose: + default: + return "debug"; } } @@ -78,14 +76,15 @@ protected: std::string LogTarget() override { switch (log_target_) { - case kConsole: - return "console"; case kKernel: return "kmsg"; case kJournal: return "journal"; case kSyslog: return "syslog"; + case kConsole: + default: + return "console"; } } diff --git a/internal/platform/implementation/linux/platform.cc b/internal/platform/implementation/linux/platform.cc index 7ac90c14..8f8c24cc 100644 --- a/internal/platform/implementation/linux/platform.cc +++ b/internal/platform/implementation/linux/platform.cc @@ -300,7 +300,7 @@ ImplementationPlatform::SendRequest(const WebRequest &request) { if (request.method == "GET") curl_easy_setopt(handle, CURLOPT_HTTPGET, 1L); else if (request.method == "POST") - curl_easy_setopt(handle, CURLOPT_HTTPPOST, 1L); + curl_easy_setopt(handle, CURLOPT_POST, 1L); else curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, request.method.c_str()); diff --git a/internal/platform/implementation/linux/wifi_hotspot.cc b/internal/platform/implementation/linux/wifi_hotspot.cc index f448dd92..4640db2b 100644 --- a/internal/platform/implementation/linux/wifi_hotspot.cc +++ b/internal/platform/implementation/linux/wifi_hotspot.cc @@ -72,7 +72,7 @@ NetworkManagerWifiHotspotMedium::ListenForService(int port) { NEARBY_LOGS(ERROR) << __func__ << "Could not find any IPv4 addresses for active connection " - << active_connection->getObjectPath(); + << active_connection->getObjectPath(); return nullptr; } @@ -106,9 +106,9 @@ NetworkManagerWifiHotspotMedium::ListenForService(int port) { << std::strerror(errno); return nullptr; } - - return std::make_unique(sock, - system_bus_, active_connection->getObjectPath(), network_manager_); + + return std::make_unique( + sock, system_bus_, active_connection->getObjectPath(), network_manager_); } bool NetworkManagerWifiHotspotMedium::StartWifiHotspot( @@ -126,7 +126,11 @@ bool NetworkManagerWifiHotspotMedium::StartWifiHotspot( << std::strerror(ret); return false; } - std::string ssid = absl::StrCat("DIRECT-", SD_ID128_TO_STRING(id)); + + char id_cstr[SD_ID128_STRING_MAX]; + sd_id128_to_string(id, id_cstr); + + std::string ssid = absl::StrCat("DIRECT-", id_cstr); ssid.resize(32); hotspot_credentials->SetSSID(ssid); @@ -135,7 +139,9 @@ bool NetworkManagerWifiHotspotMedium::StartWifiHotspot( << std::strerror(ret); return false; } - std::string password = std::string(SD_ID128_TO_STRING(id), 15); + + sd_id128_to_string(id, id_cstr); + std::string password = std::string(id_cstr, 15); hotspot_credentials->SetPassword(password); if (auto ret = sd_id128_randomize(&id); ret < 0) { @@ -143,6 +149,7 @@ bool NetworkManagerWifiHotspotMedium::StartWifiHotspot( << std::strerror(ret); return false; } + sd_id128_to_string(id, id_cstr); std::vector ssid_bytes(ssid.begin(), ssid.end()); std::map> @@ -150,7 +157,7 @@ bool NetworkManagerWifiHotspotMedium::StartWifiHotspot( { "connection", std::map{ - {"uuid", SD_ID128_TO_UUID_STRING(id)}, + {"uuid", std::string(id_cstr)}, {"id", "Google Nearby Hotspot"}, {"type", "802-11-wireless"}, {"zone", "Public"}}, @@ -171,7 +178,7 @@ bool NetworkManagerWifiHotspotMedium::StartWifiHotspot( }, {"proto", std::vector{"rsn"}}, {"psk", password}}}, - {"ipv4", std::map{"method", "shared"}}, + {"ipv4", std::map{{"method", "shared"}}}, {"ipv6", std::map{ {"addr-gen-mode", static_cast(1)}, {"method", "shared"}, diff --git a/internal/platform/implementation/linux/wifi_lan.cc b/internal/platform/implementation/linux/wifi_lan.cc index 079772dc..d5d90e26 100644 --- a/internal/platform/implementation/linux/wifi_lan.cc +++ b/internal/platform/implementation/linux/wifi_lan.cc @@ -135,8 +135,10 @@ bool WifiLanMedium::StartDiscovery( << __func__ << ": Created a new org.freedesktop.Avahi.ServiceBrowser object at " << browser_object_path; - service_browsers_.emplace(service_type, system_bus_, browser_object_path, - std::move(callback)); + service_browsers_.emplace( + service_type, + std::make_unique( + system_bus_, browser_object_path, std::move(callback))); } catch (const sdbus::Error &e) { DBUS_LOG_METHOD_CALL_ERROR(avahi_, "ServiceBrowserPrepare", e); return false; diff --git a/internal/platform/implementation/linux/wifi_medium.cc b/internal/platform/implementation/linux/wifi_medium.cc index b79fb7a9..bc111e74 100644 --- a/internal/platform/implementation/linux/wifi_medium.cc +++ b/internal/platform/implementation/linux/wifi_medium.cc @@ -330,12 +330,16 @@ NetworkManagerWifiMedium::ConnectToNetwork(absl::string_view ssid, { sd_id128_t id; + char id_cstr[SD_ID128_UUID_STRING_MAX]; + if (auto ret = sd_id128_randomize(&id); ret < 0) { NEARBY_LOGS(ERROR) << __func__ << ": could not generation a connection UUID"; return api::WifiConnectionStatus::kUnknown; } - connection_id = SD_ID128_TO_UUID_STRING(id); + + sd_id128_to_uuid_string(id, id_cstr); + connection_id = std::string(id_cstr); } auto [auth_alg, key_mgmt] = AuthAlgAndKeyMgmt(auth_type); @@ -346,7 +350,7 @@ NetworkManagerWifiMedium::ConnectToNetwork(absl::string_view ssid, std::map{ {"uuid", connection_id}, {"autoconnect", true}, - {"id", ssid}, + {"id", std::string(ssid)}, {"type", "802-11-wireless"}, {"zone", "Public"}, }}, @@ -438,7 +442,7 @@ NetworkManagerWifiMedium::GetActiveConnection() { auto object_manager = NetworkManagerObjectManager(getProxy().getConnection()); auto conn = object_manager.GetActiveConnectionForAccessPoint(active_ap_path, getObjectPath()); - + if (conn == nullptr) { NEARBY_LOGS(ERROR) << __func__ diff --git a/internal/platform/implementation/linux/wifi_medium.h b/internal/platform/implementation/linux/wifi_medium.h index b9aa318f..e8ffcbdf 100644 --- a/internal/platform/implementation/linux/wifi_medium.h +++ b/internal/platform/implementation/linux/wifi_medium.h @@ -282,8 +282,9 @@ protected: ABSL_LOCKS_EXCLUDED(known_access_points_lock_) { absl::MutexLock l(&known_access_points_lock_); known_access_points_.erase(access_point); - known_access_points_.emplace(access_point, getProxy().getConnection(), - access_point); + known_access_points_.emplace(access_point, + std::make_unique( + getProxy().getConnection(), access_point)); } void onAccessPointRemoved(const sdbus::ObjectPath &access_point) override ABSL_LOCKS_EXCLUDED(known_access_points_lock_) {