1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SAL_QA_OSL_SOCKET_SOCKETHELPER_HXX
21 #define INCLUDED_SAL_QA_OSL_SOCKET_SOCKETHELPER_HXX
23 #include <sal/types.h>
24 #include <rtl/textenc.h>
25 #include <rtl/ustring.hxx>
26 #include <rtl/ustring.h>
28 #include <osl/socket.hxx>
29 #include <osl/socket.h>
31 #include <osl/thread.hxx>
33 #include <osl/file.hxx>
35 #include <osl/mutex.hxx>
43 // OS dependent declaration and includes
45 #if ( defined UNX ) //Unix
54 #include <sys/statfs.h>
55 #include <sys/statvfs.h>
56 #include <sys/types.h>
57 #include <sys/socket.h>
59 #include <netinet/in.h>
60 #include <arpa/inet.h>
64 #ifndef _OSL_SOCKET_CONST_H_
66 #if ( defined WNT ) // Windows
77 /** test output if SILENT_TEST is 0
79 #if OSL_DEBUG_LEVEL > 0
80 # define SILENT_TEST 0
82 # define SILENT_TEST 1
86 # define t_print(...) { }
88 # define t_print printf
91 /** convert UString and OUString to std::string
93 #define STD_STRING(s) (std::string((const char *)s.getStr()))
95 /** compare two OUString.
97 sal_Bool
compareUString( const ::rtl::OUString
& ustr1
, const ::rtl::OUString
& ustr2
);
98 /** compare a OUString and an ASCII string.
100 sal_Bool
compareUString( const ::rtl::OUString
& ustr
, const sal_Char
*astr
);
101 /** compare two socket address.
103 sal_Bool
compareSocketAddr( const ::osl::SocketAddr
& addr1
, const ::osl::SocketAddr
& addr2
);
104 //char * oustring2char( const ::rtl::OUString & str );
105 /** print a UNI_CODE String. And also print some comments of the string.
107 void printUString( const ::rtl::OUString
& str
, const char * msg
= "" );
108 /** get the local host name.
109 mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name,
110 if no entry in /etc/hosts, it returns "localhost" + domain name
112 ::rtl::OUString
getHost();
113 /** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu
115 ::rtl::OUString
getThisHostname();
116 /** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("")
118 ::rtl::OUString
getIPbyName( rtl::OString
const& str_name
);
119 /** get local ethernet IP
121 ::rtl::OUString
getLocalIP( );
122 /** construct error message
124 ::rtl::OUString
outputError( const ::rtl::OUString
& returnVal
, const ::rtl::OUString
& rightVal
, const sal_Char
* msg
= "");
125 void thread_sleep( sal_Int32 _nSec
);
126 /** print Boolean value.
128 void printBool( sal_Bool bOk
);
129 /** print content of a ByteSequence.
131 void printByteSequence_IP( const ::rtl::ByteSequence
& bsByteSeq
, sal_Int32 nLen
);
132 /** convert an IP which is stored as a UString format to a ByteSequence array for later use.
134 ::rtl::ByteSequence
UStringIPToByteSequence( ::rtl::OUString aUStr
);
135 /** print a socket result name.
137 void printSocketResult( oslSocketResult eResult
);
138 /** if 4 parts of an IP addr are equal to specified values
140 sal_Bool
ifIpv4is( const ::rtl::ByteSequence Ipaddr
, sal_Int8 seq1
, sal_Int8 seq2
, sal_Int8 seq3
, sal_Int8 seq4
);
141 /** if the IP or hostname is available( alive )
143 //sal_Bool ifAvailable( const char * stringAddrOrHostName );
144 sal_Bool
ifAvailable( rtl::OUString
const& strAddrOrHostName
);
146 class ClientSocketThread : public Thread
147 class ServerSocketThread : public Thread
148 class ValueCheckProvider
149 class ClientReadSocketThread : public Thread
150 class ServerWriteSocketThread : public Thread
151 class AcceptorThread : public Thread
152 class CloseSocketThread : public Thread
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */