[Libreoffice-commits] online.git: common/Util.cpp common/Util.hpp loleaflet/html wsd/FileServer.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp
gokaysatir (via logerrit)
logerrit at kemper.freedesktop.org
Wed Apr 1 19:46:57 UTC 2020
common/Util.cpp | 24 ++++++++++++++++++++++++
common/Util.hpp | 28 +++++++++++++++++++++++++++-
loleaflet/html/loleaflet.html.m4 | 1 +
wsd/FileServer.cpp | 1 +
wsd/LOOLWSD.cpp | 22 ++++++++++++++++++++++
wsd/LOOLWSD.hpp | 4 ++++
6 files changed, 79 insertions(+), 1 deletion(-)
New commits:
commit a486bad79be3838d115e09ccbb55ec47ea36274a
Author: gokaysatir <gokaysatir at gmail.com>
AuthorDate: Mon Mar 30 02:31:23 2020 +0300
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Wed Apr 1 20:45:32 2020 +0100
tdf#130568 - Add server os pretty name to help->about
Change-Id: Id6de533dfb8e34a05d348f8ae701bf3c524c9b95
diff --git a/common/Util.cpp b/common/Util.cpp
index 137ec3897..2abbd4d11 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -929,6 +929,30 @@ namespace Util
return false;
#endif
}
+
+ std::map<std::string, std::string> stringVectorToMap(std::vector<std::string> sVector, const char delimiter)
+ {
+ std::map<std::string, std::string> result;
+
+ for (std::vector<std::string>::iterator it = sVector.begin(); it != sVector.end(); it++)
+ {
+ size_t delimiterPosition = 0;
+ delimiterPosition = (*it).find(delimiter, 0);
+ if (delimiterPosition != std::string::npos)
+ {
+ std::string key = (*it).substr(0, delimiterPosition);
+ delimiterPosition++;
+ std::string value = (*it).substr(delimiterPosition);
+ result[key] = value;
+ }
+ else
+ {
+ LOG_WRN("Util::stringVectorToMap => record is misformed: " << (*it));
+ }
+ }
+
+ return result;
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/common/Util.hpp b/common/Util.hpp
index 52043692f..fd1589cfe 100644
--- a/common/Util.hpp
+++ b/common/Util.hpp
@@ -72,7 +72,7 @@ namespace Util
/// to send data to the child.
int spawnProcess(const std::string &cmd, const StringVector &args,
const std::vector<int>* fdsToKeep = nullptr, int *stdInput = nullptr);
-
+
#endif
/// Hex to unsigned char
@@ -972,6 +972,32 @@ int main(int argc, char**argv)
* test tool targets (typically fuzzing) where start-up speed is critical.
*/
bool isFuzzing();
+
+ /**
+ * Splits string into vector<string>. Does not accept referenced variables for easy
+ * usage like (splitString("test", ..)) or (splitString(getStringOnTheFly(), ..))
+ */
+ inline std::vector<std::string> splitStringToVector(std::string const str, const char delim)
+ {
+ size_t start;
+ size_t end = 0;
+
+ std::vector<std::string> result;
+
+ while ((start = str.find_first_not_of(delim, end)) != std::string::npos)
+ {
+ end = str.find(delim, start);
+ result.push_back(str.substr(start, end - start));
+ }
+ return result;
+ }
+
+ /**
+ * Converts vector of strings to map. Strings should have formed like this: key + delimiter + value.
+ * In case of a misformed string or zero length vector, returns an empty map.
+ */
+ std::map<std::string, std::string> stringVectorToMap(std::vector<std::string> sVector, const char delimiter);
+
} // end namespace Util
#endif
diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index 1bb0c44c9..a2c1a45cf 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -220,6 +220,7 @@ m4_ifelse(MOBILEAPP,[true],
<div id="loolwsd-id"></div>
<h3>LOKit</h3>
<div id="lokit-version"></div>
+ <div id="os-name" style="text-align:center"><label>%OS_INFO%</label></div>
<p>Copyright © _YEAR_, VENDOR.</p>
</div>
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index ce9e12756..9d833c510 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -649,6 +649,7 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
Poco::replaceInPlace(preprocess, std::string("%HOST%"), host);
Poco::replaceInPlace(preprocess, std::string("%VERSION%"), std::string(LOOLWSD_VERSION_HASH));
Poco::replaceInPlace(preprocess, std::string("%SERVICE_ROOT%"), LOOLWSD::ServiceRoot);
+ Poco::replaceInPlace(preprocess, std::string("%OS_INFO%"), LOOLWSD::OSInfo);
std::string protocolDebug = "false";
if (config.getBool("logging.protocol"))
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 9c040a8fd..54ba8e2b9 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -726,6 +726,7 @@ std::string LOOLWSD::ServerName;
std::string LOOLWSD::FileServerRoot;
std::string LOOLWSD::ServiceRoot;
std::string LOOLWSD::LOKitVersion;
+std::string LOOLWSD::OSInfo;
std::string LOOLWSD::HostIdentifier;
std::string LOOLWSD::ConfigFile = LOOLWSD_CONFIGDIR "/loolwsd.xml";
std::string LOOLWSD::ConfigDir = LOOLWSD_CONFIGDIR "/conf.d";
@@ -749,6 +750,25 @@ std::unique_ptr<TraceFileWriter> LOOLWSD::TraceDumper;
std::unique_ptr<ClipboardCache> LOOLWSD::SavedClipboards;
#endif
+void LOOLWSD::getOSInfo(){
+ #if !MOBILEAPP
+ // It might be neither mobile nor linux (in the future). That is not handled. If it is not mobile, it is Linux.
+
+ // Read operating system info. We can read "os-release" file, located in /etc.
+ std::ifstream ifs("/etc/os-release");
+ std::string str(std::istreambuf_iterator<char>{ifs}, {});
+ std::vector<std::string> infoList = Util::splitStringToVector(str, '\n');
+ std::map<std::string, std::string> releaseInfo = Util::stringVectorToMap(infoList, '=');
+ LOOLWSD::OSInfo = "unknown";
+
+ if (releaseInfo.find("PRETTY_NAME") != releaseInfo.end()) {
+ LOOLWSD::OSInfo = releaseInfo["PRETTY_NAME"];
+ }
+ #else
+ // Some more cases might be added in the future.
+ #endif
+}
+
/// This thread polls basic web serving, and handling of
/// websockets before upgrade: when upgraded they go to the
/// relevant DocumentBroker poll instead.
@@ -886,6 +906,8 @@ void LOOLWSD::initialize(Application& self)
AutoPtr<AppConfigMap> defConfig(new AppConfigMap(DefAppConfig));
conf.addWriteable(defConfig, PRIO_SYSTEM); // Lowest priority
+ LOOLWSD::getOSInfo();
+
#if !MOBILEAPP
// Load default configuration files, if present.
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 383263314..469d26bec 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -70,6 +70,7 @@ public:
static std::string FileServerRoot;
static std::string ServiceRoot; ///< There are installations that need prefixing every page with some path.
static std::string LOKitVersion;
+ static std::string OSInfo;
static std::string HostIdentifier; ///< A unique random hash that identifies this server
static std::string LogLevel;
static bool AnonymizeUserData;
@@ -219,6 +220,9 @@ public:
static std::string getVersionJSON();
+ /// Reads OS information, puts them into LOOLWSD::OSInfo variable
+ static void getOSInfo();
+
int innerMain();
protected:
More information about the Libreoffice-commits
mailing list