Skip to content

Commit

Permalink
indirection: get timezone from coolwsd.xml
Browse files Browse the repository at this point in the history
- before this patch we were trying to get timezone from the os timezone
  file. But that is not consistent because most of the VMs would have
  timezone set to UTC

Signed-off-by: Rashesh <[email protected]>
Change-Id: Id241ad6f57eeb3c084733f174ba5d1c4a547ced6
  • Loading branch information
Rash419 committed Sep 11, 2024
1 parent cee77a8 commit 4d405f7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 40 deletions.
33 changes: 5 additions & 28 deletions common/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ namespace Util
return id;
}

std::string getVersionJSON(bool enableExperimental, bool geolocationSetup)
std::string getVersionJSON(bool enableExperimental, const std::string& timezone)
{
std::string version, hash;
Util::getVersionInfo(version, hash);
Expand All @@ -415,13 +415,10 @@ namespace Util
"\"Id\": \"" +
Util::getProcessIdentifier() + "\", ";

if (geolocationSetup)
json += "\"TimeZone\": \"" + getIANATimezone() +
"\", "
"\"Options\": \"" +
std::string(enableExperimental ? " (E)" : "") + "\" }";
else
json += "\"Options\": \"" + std::string(enableExperimental ? " (E)" : "") + "\" }";
if (!timezone.empty())
json += "\"TimeZone\": \"" + timezone + "\", ";

json += "\"Options\": \"" + std::string(enableExperimental ? " (E)" : "") + "\" }";
return json;
}

Expand Down Expand Up @@ -963,26 +960,6 @@ namespace Util
}
}

std::string getIANATimezone()
{
const char* tzfile = "/etc/localtime";
char buf[PATH_MAX];

ssize_t len = readlink(tzfile, buf, sizeof(buf) - 1);
if (len != -1)
{
buf[len] = '\0';
std::string fullPath(buf);

std::string prefix = "../usr/share/zoneinfo/";
if (fullPath.substr(0, prefix.size()) == prefix)
{
return fullPath.substr(prefix.size());
}
}
return std::string();
}

std::string Backtrace::Symbol::toString() const
{
std::string s;
Expand Down
5 changes: 1 addition & 4 deletions common/Util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ namespace Util
///< A random hex string that identifies the current process.
const std::string& getProcessIdentifier();

std::string getVersionJSON(bool enableExperimental, bool geolocationSetup);
std::string getVersionJSON(bool enableExperimental, const std::string& timezone);

/// Return a string that is unique across processes and calls.
std::string UniqueId();
Expand Down Expand Up @@ -1553,9 +1553,6 @@ int main(int argc, char**argv)
return oss.str();
}

/// Get IANA timezone name
std::string getIANATimezone();

/// Asserts in the debug builds, otherwise just logs.
void assertCorrectThread(std::thread::id owner, const char* fileName, int lineNo);

Expand Down
3 changes: 2 additions & 1 deletion coolwsd.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@
<migration_timeout_secs desc="The maximum number of seconds waiting for shutdown migration message from indirection server before unloading an document. Defaults to 180 second." type="uint" default="180"></migration_timeout_secs>
<geolocation_setup>
<enable desc="Enable geolocation_setup when using indirection server with geolocation configuration" type="bool" default="false">false</enable>
<timezone desc="IANA timezone of server. For example: Europe/Berlin "></timezone>
</geolocation_setup>
<server_name desc="server name to show in cluster overview admin panel"></server_name>
<server_name desc="server name to show in cluster overview admin panel" type="string" default=""></server_name>
</indirection_endpoint>

@LOCK_CONFIGURATION@
Expand Down
10 changes: 7 additions & 3 deletions wsd/Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <chrono>
#include <iomanip>
#include <string>
#include <sys/poll.h>
#include <unistd.h>

Expand All @@ -22,6 +23,7 @@
#include "Admin.hpp"
#include "AdminModel.hpp"
#include "Auth.hpp"
#include "ConfigUtil.hpp"
#include <Common.hpp>
#include <Log.hpp>
#include <Protocol.hpp>
Expand Down Expand Up @@ -131,9 +133,11 @@ void AdminSocketHandler::handleMessage(const std::vector<char> &payload)
else if (tokens.equals(0, "version"))
{
// Send COOL version information
sendTextFrame("coolserver " +
Util::getVersionJSON(EnableExperimental, COOLWSD::IndirectionServerEnabled &&
COOLWSD::GeolocationSetup));
std::string timezoneName;
if (COOLWSD::IndirectionServerEnabled && COOLWSD::GeolocationSetup)
timezoneName = config::getString("indirection_endpoint.geolocation_setup.timezone", "");

sendTextFrame("coolserver " + Util::getVersionJSON(EnableExperimental, timezoneName));

// Send LOKit version information
sendTextFrame("lokitversion " + COOLWSD::LOKitVersion);
Expand Down
1 change: 1 addition & 0 deletions wsd/COOLWSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,7 @@ void COOLWSD::innerInitialize(Application& self)
{ "deepl.enabled", "false" },
{ "zotero.enable", "true" },
{ "indirection_endpoint.geolocation_setup.enable", "false" },
{ "indirection_endpoint.geolocation_setup.timezone", "" },
{ "indirection_endpoint.server_name", "" },
{ "indirection_endpoint.url", "" },
#if !MOBILEAPP
Expand Down
3 changes: 2 additions & 1 deletion wsd/ClientRequestDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,8 @@ static std::string getCapabilitiesJson(bool convertToAvailable)

if (COOLWSD::IndirectionServerEnabled && COOLWSD::GeolocationSetup)
{
std::string timezoneName = Util::getIANATimezone();
std::string timezoneName =
config::getString("indirection_endpoint.geolocation_setup.timezone", "");
if (!timezoneName.empty())
capabilities->set("timezone", std::string(timezoneName));
}
Expand Down
9 changes: 6 additions & 3 deletions wsd/ClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <Poco/StreamCopier.h>
#include <Poco/URI.h>

#include "ConfigUtil.hpp"
#include "DocumentBroker.hpp"
#include "COOLWSD.hpp"
#include "FileServer.hpp"
Expand Down Expand Up @@ -635,10 +636,12 @@ bool ClientSession::_handleInput(const char *buffer, int length)
}
}

std::string timezoneName;
if (COOLWSD::IndirectionServerEnabled && COOLWSD::GeolocationSetup)
timezoneName = config::getString("indirection_endpoint.geolocation_setup.timezone", "");

// Send COOL version information
sendTextFrame("coolserver " +
Util::getVersionJSON(EnableExperimental, COOLWSD::IndirectionServerEnabled &&
COOLWSD::GeolocationSetup));
sendTextFrame("coolserver " + Util::getVersionJSON(EnableExperimental, timezoneName));
// Send LOKit version information
sendTextFrame("lokitversion " + COOLWSD::LOKitVersion);

Expand Down

0 comments on commit 4d405f7

Please sign in to comment.