Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sal / qa / osl / socket / sockethelper.hxx
blob49785cd504321f25e0d7c8cd01a2d91d4aabd659
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 _SOCKETHELPER_HXX_
21 #define _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>
36 #include <osl/time.h>
38 #ifdef __cplusplus
39 extern "C"
41 #endif
43 //------------------------------------------------------------------------
44 // OS dependent declaration and includes
45 //------------------------------------------------------------------------
46 #if ( defined UNX ) //Unix
48 #include <unistd.h>
49 #include <limits.h>
50 #include <string.h>
51 #include <math.h>
52 #include <errno.h>
53 #include <fcntl.h>
54 #include <sys/stat.h>
55 #include <sys/statfs.h>
56 #include <sys/statvfs.h>
57 #include <sys/types.h>
58 #include <sys/socket.h>
59 #include <netdb.h>
60 #include <netinet/in.h>
61 #include <arpa/inet.h>
62 #include <sys/wait.h>
63 #endif
65 #ifndef _OSL_SOCKET_CONST_H_
67 #if ( defined WNT ) // Windows
68 #include <winsock.h>
69 #include <string.h>
70 #endif
72 #endif
74 #ifdef __cplusplus
76 #endif
78 /** test output if SILENT_TEST is 0
80 #if OSL_DEBUG_LEVEL > 0
81 # define SILENT_TEST 0
82 #else
83 # define SILENT_TEST 1
84 #endif
86 #if SILENT_TEST
87 # define t_print(...) { }
88 #else
89 # define t_print printf
90 #endif
92 /** convert UString and OUString to std::string
94 #define STD_STRING(s) (std::string((const char *)s.getStr()))
96 /** compare two OUString.
98 sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 );
99 /** compare a OUString and an ASCII string.
101 sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr );
102 /** compare two socket address.
104 sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2 );
105 //char * oustring2char( const ::rtl::OUString & str );
106 /** print a UNI_CODE String. And also print some comments of the string.
108 void printUString( const ::rtl::OUString & str, const char * msg = "" );
109 /** get the local host name.
110 mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name,
111 if no entry in /etc/hosts, it returns "localhost" + domain name
113 ::rtl::OUString getHost( void );
114 /** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu
116 ::rtl::OUString getThisHostname( void );
117 /** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("")
119 ::rtl::OUString getIPbyName( rtl::OString const& str_name );
120 /** get local ethernet IP
122 ::rtl::OUString getLocalIP( );
123 /** construct error message
125 ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = "");
126 void thread_sleep( sal_Int32 _nSec );
127 /** print Boolean value.
129 void printBool( sal_Bool bOk );
130 /** print content of a ByteSequence.
132 void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen );
133 /** convert an IP which is stored as a UString format to a ByteSequence array for later use.
135 ::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr );
136 /** print a socket result name.
138 void printSocketResult( oslSocketResult eResult );
139 /** if 4 parts of an IP addr are equal to specified values
141 sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 );
142 /** if the IP or hostname is availble( alive )
144 //sal_Bool ifAvailable( const char * stringAddrOrHostName );
145 sal_Bool ifAvailable( rtl::OUString const& strAddrOrHostName );
147 class ClientSocketThread : public Thread
148 class ServerSocketThread : public Thread
149 class ValueCheckProvider
150 class ClientReadSocketThread : public Thread
151 class ServerWriteSocketThread : public Thread
152 class AcceptorThread : public Thread
153 class CloseSocketThread : public Thread
157 #endif
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */