tcpslavebase.h
00001 /* 00002 * Copyright (C) 2000 Alex Zepeda <zipzippy@sonic.net> 00003 * Copyright (C) 2001 George Staikos <staikos@kde.org> 00004 * Copyright (C) 2001 Dawit Alemayehu <adawit@kde.org> 00005 * 00006 * This file is part of the KDE project 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Library General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Library General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Library General Public License 00019 * along with this library; see the file COPYING.LIB. If not, write to 00020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 * Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #ifndef _TCP_SLAVEBASE_H 00025 #define _TCP_SLAVEBASE_H 00026 00027 #include <sys/types.h> 00028 #include <stdio.h> 00029 00030 #include <kextsock.h> 00031 #include <tdeio/slavebase.h> 00032 00033 00034 namespace TDEIO { 00035 00045 class TDEIO_EXPORT TCPSlaveBase : public SlaveBase 00046 { 00047 public: 00048 TCPSlaveBase(unsigned short int defaultPort, const TQCString &protocol, 00049 const TQCString &poolSocket, const TQCString &appSocket); 00050 00051 TCPSlaveBase(unsigned short int defaultPort, const TQCString &protocol, 00052 const TQCString &poolSocket, const TQCString &appSocket, 00053 bool useSSL); 00054 00055 virtual ~TCPSlaveBase(); 00056 00057 protected: 00058 00059 #ifndef KDE_NO_COMPAT 00060 00063 KDE_DEPRECATED ssize_t Write(const void *data, ssize_t len) { return write( data, len ); } 00064 00068 KDE_DEPRECATED ssize_t Read(void *data, ssize_t len) { return read( data, len ); } 00069 00073 KDE_DEPRECATED ssize_t ReadLine(char *data, ssize_t len) { return readLine( data, len ); } 00074 00078 KDE_DEPRECATED unsigned short int GetPort(unsigned short int p) { return port(p); } 00079 00083 KDE_DEPRECATED bool ConnectToHost( const TQString &host, unsigned int port, 00084 bool sendError ) { return connectToHost( host, port, sendError ); } 00085 00089 KDE_DEPRECATED void CloseDescriptor() { closeDescriptor(); } 00090 00094 KDE_DEPRECATED bool AtEOF() { return atEnd(); } 00095 00099 KDE_DEPRECATED bool InitializeSSL() { return initializeSSL(); } 00100 00104 KDE_DEPRECATED void CleanSSL() { cleanSSL(); } 00105 #endif 00106 00117 ssize_t write(const void *data, ssize_t len); 00118 00129 ssize_t read(void *data, ssize_t len); 00130 00134 ssize_t readLine(char *data, ssize_t len); 00135 00143 void setBlockSize(int sz); 00144 00153 unsigned short int port(unsigned short int _port); 00154 00173 bool connectToHost( const TQString &host, unsigned int port, 00174 bool sendError = true ); 00175 00183 bool usingSSL() const { return m_bIsSSL; } 00184 00192 bool usingTLS() const; 00193 00201 bool usingTLS(); 00202 00209 bool canUseTLS(); 00210 00220 int startTLS(); 00221 00225 void stopTLS(); 00226 00234 void closeDescriptor(); 00235 00236 00240 bool atEnd(); 00241 00242 00249 void setSSLMetaData(); 00250 00251 00255 bool initializeSSL(); 00256 00257 00261 void cleanSSL(); 00262 00272 bool isConnectionValid(); 00273 00284 int connectResult(); 00285 00296 bool waitForResponse( int t ); 00297 00307 void setBlockConnection( bool b ); 00308 00319 void setConnectTimeout( int t ); 00320 00326 bool isSSLTunnelEnabled(); 00327 00343 void setEnableSSLTunnel( bool enable ); 00344 00355 void setRealHost( const TQString& realHost ); 00356 00357 // don't use me! 00358 void doConstructorStuff(); 00359 00360 // For the certificate verification code 00361 int verifyCertificate(); 00362 00363 // For prompting for the certificate to use 00364 void certificatePrompt(); 00365 00366 // Did the user abort (as the reason for connectToHost returning false) 00367 bool userAborted() const; 00368 00369 protected: 00370 int m_iSock; 00371 bool m_bIsSSL; 00372 unsigned short int m_iPort; 00373 unsigned short int m_iDefaultPort; 00374 TQCString m_sServiceName; 00375 FILE *fp; 00376 00377 private: 00378 bool doSSLHandShake( bool sendError ); 00379 00380 protected: 00381 virtual void virtual_hook( int id, void* data ); 00382 private: 00383 class TcpSlaveBasePrivate; 00384 TcpSlaveBasePrivate *d; 00385 }; 00386 00387 } 00388 00389 #endif