[Libreoffice-commits] core.git: Branch 'distro/cib/libreoffice-6-1' - sal/osl

2020-12-13 Thread Stephan Bergmann (via logerrit)
 sal/osl/w32/socket.cxx |   86 ++---
 1 file changed, 46 insertions(+), 40 deletions(-)

New commits:
commit ba4f3394fc63e2c74565a57a744569a5bacfd53f
Author: Stephan Bergmann 
AuthorDate: Thu Feb 7 15:36:58 2019 +0100
Commit: Thorsten Behrens 
CommitDate: Mon Dec 14 01:28:08 2020 +0100

Make osl_getLocalHostname thread-safe

Change-Id: I82b8c49fcbbec161bf968573e28992fa5737b45b
Reviewed-on: https://gerrit.libreoffice.org/67508
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 
(cherry picked from commit cb22fb0c2e49010ed066c23f0521d10cc850c280)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107496
Tested-by: Thorsten Behrens 
Reviewed-by: Thorsten Behrens 

diff --git a/sal/osl/w32/socket.cxx b/sal/osl/w32/socket.cxx
index cce9af46f142..528ad8ebc7ea 100644
--- a/sal/osl/w32/socket.cxx
+++ b/sal/osl/w32/socket.cxx
@@ -17,6 +17,10 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include 
+
+#include 
+
 #include "system.h"
 
 #include 
@@ -601,57 +605,59 @@ void SAL_CALL osl_destroyHostAddr(oslHostAddr pAddr)
 
 oslSocketResult SAL_CALL osl_getLocalHostname (rtl_uString **strLocalHostname)
 {
-static sal_Unicode LocalHostname[256] = {0};
+static auto const init = []() -> std::pair {
+sal_Unicode LocalHostname[256] = {0};
 
-if (rtl_ustr_getLength(LocalHostname) == 0)
-{
-sal_Char Host[256]= "";
-if (gethostname(Host, sizeof(Host)) == 0)
-{
-/* check if we have an FQDN; if not, try to determine it via dns 
first: */
-if (strchr(Host, '.') == nullptr)
+sal_Char Host[256]= "";
+if (gethostname(Host, sizeof(Host)) == 0)
 {
-oslHostAddr pAddr;
-rtl_uString *hostName= nullptr;
+/* check if we have an FQDN; if not, try to determine it via 
dns first: */
+if (strchr(Host, '.') == nullptr)
+{
+oslHostAddr pAddr;
+rtl_uString *hostName= nullptr;
 
-rtl_string2UString(
-, Host, strlen(Host),
-RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS);
-OSL_ASSERT(hostName != nullptr);
+rtl_string2UString(
+, Host, strlen(Host),
+RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS);
+OSL_ASSERT(hostName != nullptr);
 
-pAddr = osl_createHostAddrByName(hostName);
-rtl_uString_release (hostName);
+pAddr = osl_createHostAddrByName(hostName);
+rtl_uString_release (hostName);
 
-if (pAddr && pAddr->pHostName)
-memcpy(LocalHostname, pAddr->pHostName->buffer, 
sizeof(sal_Unicode)*(rtl_ustr_getLength(pAddr->pHostName->buffer)+1));
-else
-memset(LocalHostname, 0, sizeof(LocalHostname));
+if (pAddr && pAddr->pHostName)
+memcpy(LocalHostname, pAddr->pHostName->buffer, 
sizeof(sal_Unicode)*(rtl_ustr_getLength(pAddr->pHostName->buffer)+1));
+else
+memset(LocalHostname, 0, sizeof(LocalHostname));
 
-osl_destroyHostAddr (pAddr);
-}
-if (LocalHostname[0] == u'\0')
-{
-OUString u;
-if (rtl_convertStringToUString(
-, Host, strlen(Host), 
osl_getThreadTextEncoding(),
-(RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
- | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
- | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))
-&& u.getLength() < SAL_N_ELEMENTS(LocalHostname))
+osl_destroyHostAddr (pAddr);
+}
+if (LocalHostname[0] == u'\0')
 {
-memcpy(LocalHostname, u.getStr(), (u.getLength() + 1) * 
sizeof sal_Unicode);
+OUString u;
+if (rtl_convertStringToUString(
+, Host, strlen(Host), 
osl_getThreadTextEncoding(),
+(RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
+ | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
+ | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))
+&& u.getLength() < SAL_N_ELEMENTS(LocalHostname))
+{
+memcpy(LocalHostname, u.getStr(), (u.getLength() + 1) 
* sizeof sal_Unicode);
+}
 }
 }
-}
-}
 
-if (rtl_ustr_getLength(LocalHostname) > 0)
-{
-rtl_uString_newFromStr (strLocalHostname, LocalHostname);
-return osl_Socket_Ok;
-}
+if 

[Libreoffice-commits] core.git: Branch 'distro/cib/libreoffice-6-1' - sal/osl

2020-12-13 Thread Stephan Bergmann (via logerrit)
 sal/osl/w32/socket.cxx |   17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

New commits:
commit 12f8f2c87ffc8ec6e3e18a6125abe1716733e054
Author: Stephan Bergmann 
AuthorDate: Tue Feb 5 10:32:03 2019 +0100
Commit: Thorsten Behrens 
CommitDate: Mon Dec 14 01:27:36 2020 +0100

Improve osl_getLocalHostname on Windows

...returning a non-dotted result obtained from gethostname in case trying 
via
osl_createHostAddrByName doesn't work either.  The code had been like this 
ever
since its introduction with 74f3ed51f1e3fa7a199210fd6ffc69d78a535c08 "made
socket and pipe refcounted, added blocking read write methods, added direct
access methods for struct sockaddr", but there appears to be no good reason 
not
to return the non-dotted gethostname value as a fallback (and it may just 
have
been an oversight not to do so; and on e.g. Linux we simply return whatever 
a
successful call to gethostname provides, be it dotted or not, ever since at
least ebd00f5c46707e0dfcdd074f581ae86c0576e69b "socket.cxx -> socket.c", 
too).

(Calls to osl_getLocalHostname are few across the code base, so this change 
in
behavior is unlikely to cause any regressions.  I came across this wile 
looking
into  "Does not
support 'file://' scheme with actual hostname", but this change is 
unrelated to
any potential fix for that issue.  It just felt right to get this fixed in
passing.)

Change-Id: I78e59140579b9d37ee435a8f121e58544d2235eb
Reviewed-on: https://gerrit.libreoffice.org/67390
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 
(cherry picked from commit 3be2a53ee1a34fd4bc96e7817191fc3e0eb3c917)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107495
Tested-by: Thorsten Behrens 
Reviewed-by: Thorsten Behrens 

diff --git a/sal/osl/w32/socket.cxx b/sal/osl/w32/socket.cxx
index bf27bba1a04d..cce9af46f142 100644
--- a/sal/osl/w32/socket.cxx
+++ b/sal/osl/w32/socket.cxx
@@ -20,6 +20,7 @@
 #include "system.h"
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -607,7 +608,7 @@ oslSocketResult SAL_CALL osl_getLocalHostname (rtl_uString 
**strLocalHostname)
 sal_Char Host[256]= "";
 if (gethostname(Host, sizeof(Host)) == 0)
 {
-/* check if we have an FQDN */
+/* check if we have an FQDN; if not, try to determine it via dns 
first: */
 if (strchr(Host, '.') == nullptr)
 {
 oslHostAddr pAddr;
@@ -618,7 +619,6 @@ oslSocketResult SAL_CALL osl_getLocalHostname (rtl_uString 
**strLocalHostname)
 RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS);
 OSL_ASSERT(hostName != nullptr);
 
-/* no, determine it via dns */
 pAddr = osl_createHostAddrByName(hostName);
 rtl_uString_release (hostName);
 
@@ -629,6 +629,19 @@ oslSocketResult SAL_CALL osl_getLocalHostname (rtl_uString 
**strLocalHostname)
 
 osl_destroyHostAddr (pAddr);
 }
+if (LocalHostname[0] == u'\0')
+{
+OUString u;
+if (rtl_convertStringToUString(
+, Host, strlen(Host), 
osl_getThreadTextEncoding(),
+(RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
+ | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
+ | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))
+&& u.getLength() < SAL_N_ELEMENTS(LocalHostname))
+{
+memcpy(LocalHostname, u.getStr(), (u.getLength() + 1) * 
sizeof sal_Unicode);
+}
+}
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits