Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi,

This patch remove the function _osl_getDomainName and replace it by a
_osl_gethostbyname_r. Next part of the previous patch. I think maybe
without this patch, there is some problems on Android with the function
getdomainname due to my previous patch, sorry.

Best regards

-- 
Arnaud Versini
From 57d12f3e9b2b82ae8b1d8a7397268b3742ba0d3e Mon Sep 17 00:00:00 2001
From: Arnaud Versini <arnaud.versini@gmail.com>
Date: Sun, 13 Nov 2011 16:01:31 +0100
Subject: [PATCH] Remove _osl_getDomainName and simplify
 _osl_getFullQualifiedDomainName

---
 sal/osl/unx/socket.c |  142 ++++---------------------------------------------
 1 files changed, 12 insertions(+), 130 deletions(-)

diff --git a/sal/osl/unx/socket.c b/sal/osl/unx/socket.c
index 9c33eaf..ed31a82 100644
--- a/sal/osl/unx/socket.c
+++ b/sal/osl/unx/socket.c
@@ -40,7 +40,6 @@
 
 #include "sockimpl.h"
 
-
 /* defines for poll */
 #ifdef HAVE_POLL_H
 #undef HAVE_POLL_H
@@ -809,142 +808,25 @@ static struct hostent* _osl_gethostbyname_r (
 #endif
 }
 
-static sal_Bool  _osl_getDomainName (sal_Char *buffer, sal_Int32 bufsiz)
-{
-    sal_Bool result = (getdomainname(buffer, bufsiz) == 0);
-    if  (!result) {
-        OSL_TRACE("osl_getDomainName failed. Errno: %d; %s\n",
-                      errno,
-                      strerror(errno));
-    }
-    return (result);
-}
-
 static sal_Char* _osl_getFullQualifiedDomainName (const sal_Char *pHostName)
 {
 #   define DOMAINNAME_LENGTH 512
-    sal_uInt32          nLengthOfHostName;
-    static sal_uInt32   nLengthOfDomainName = 0;
-    static sal_Char    *pDomainName = NULL;
-
-    sal_Char  *pFullQualifiedName;
-
-    /* get a '\0' terminated domainname */
-
-    /* read default domainname default from environment */
-    if (nLengthOfDomainName == 0)
-    {
-        sal_Char *pEnvDomain;
-
-        pEnvDomain = getenv ("STAR_OVERRIDE_DOMAINNAME");
-        if (pEnvDomain)
-        {
-            pDomainName = strdup (pEnvDomain);
-            nLengthOfDomainName = strlen (pDomainName);
-        }
-    }
-
-    if (nLengthOfDomainName == 0)
-    {
-        sal_Char pDomainNameBuffer[ DOMAINNAME_LENGTH ];
-
-        pDomainNameBuffer[0] = '\0';
-
-        if (_osl_getDomainName (pDomainNameBuffer, DOMAINNAME_LENGTH))
-        {
-            pDomainName = strdup (pDomainNameBuffer);
-            nLengthOfDomainName = strlen (pDomainName);
-        }
-    }
-
-    /* compose hostname and domainname */
-    nLengthOfHostName = strlen( pHostName );
-    pFullQualifiedName = (sal_Char*) malloc( (nLengthOfHostName + 1
-                            + nLengthOfDomainName + 1) * sizeof(sal_Char) );
-    memcpy( pFullQualifiedName, pHostName,
-        (nLengthOfHostName + 1) * sizeof(sal_Char) );
+    struct hostent  aHostByName;
+    struct hostent *pHostByName;
+    sal_Char        pQualifiedHostBuffer[ MAX_HOSTBUFFER_SIZE ];
+    sal_Char  *pFullQualifiedName = NULL;
+    int     nErrorNo;
 
-    if ( nLengthOfDomainName > 0 )
+    pHostByName = _osl_gethostbyname_r (
+        pHostName,
+        &aHostByName, pQualifiedHostBuffer,
+        sizeof(pQualifiedHostBuffer), &nErrorNo );
+    if (pHostByName != NULL)
     {
-        /* fqdn = hostname + '.' + domainname + '\0' */
-        pFullQualifiedName[ nLengthOfHostName ] = '.';
-        memcpy( pFullQualifiedName + nLengthOfHostName + 1, pDomainName,
-            nLengthOfDomainName + 1 );
+        pFullQualifiedName = strdup(pHostByName->h_name);
     }
-
-    /* check whether full-qualified name and hostname point to the same host
-     * should almost always be true */
-    if ( nLengthOfDomainName > 0 )
-    {
-        struct hostent *pQualifiedHostByName;
-        struct hostent *pHostByName;
-        sal_Bool        bHostsAreEqual;
-
-        /* buffer for calls to reentrant version of gethostbyname */
-        struct hostent  aHostByName, aQualifiedHostByName;
-        sal_Char        pHostBuffer[ MAX_HOSTBUFFER_SIZE ];
-        sal_Char        pQualifiedHostBuffer[ MAX_HOSTBUFFER_SIZE ];
-        int     nErrorNo;
-
-        pHostBuffer[0] = '\0';
-        pQualifiedHostBuffer[0] = '\0';
-
-        /* get list of addresses */
-        pQualifiedHostByName = _osl_gethostbyname_r (
-            pFullQualifiedName,
-            &aQualifiedHostByName, pQualifiedHostBuffer,
-            sizeof(pQualifiedHostBuffer), &nErrorNo );
-        pHostByName = _osl_gethostbyname_r (
-            pHostName,
-            &aHostByName, pHostBuffer,
-            sizeof(pHostBuffer), &nErrorNo );
-
-        /* compare addresses */
-        bHostsAreEqual = sal_False;
-        if ( pQualifiedHostByName && pHostByName )
-        {
-            sal_Char **p, **q;
-            struct in_addr in;
-
-            /* lists are expected to be (very) short */
-            for ( p = pQualifiedHostByName->h_addr_list; *p != NULL; p++ )
-            {
-                for ( q = pHostByName->h_addr_list; *q != NULL; q++ )
-                {
-                    /* in.s_addr may be in_addr_t or uint32_t or heaven knows */
-                    if ( memcmp( *p, *q, sizeof(in.s_addr) ) == 0 )
-                    {
-                        bHostsAreEqual = sal_True;
-                        break;
-                    }
-                }
-                if ( bHostsAreEqual )
-                    break;
-            }
-        }
-
-        /* very strange case, but have to believe it: reduce the
-         * full qualified name to the unqualified host name */
-        if ( !bHostsAreEqual )
-        {
-            sal_Char *pTmp;
-
-            OSL_TRACE("_osl_getFullQualifiedDomainName: "
-                      "suspect FQDN: %s\n", pFullQualifiedName);
-
-            pFullQualifiedName[ nLengthOfHostName ] = '\0';
-            pTmp = (sal_Char*)realloc ( pFullQualifiedName,
-                                (nLengthOfHostName + 1) * sizeof( sal_Char ));
-            if (pTmp)
-                pFullQualifiedName = pTmp;
-        }
-    }
-
-    /* always return a hostname looked up as carefully as possible
-     * this string must be freed by the caller */
     return pFullQualifiedName;
 }
-
 /*****************************************************************************/
 /* _osl_isFullQualifiedDomainName */
 /*****************************************************************************/
-- 
1.7.5.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.