slavebase.h

00001 /*
00002    Copyright (C) 2000 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef __slavebase_h
00021 #define __slavebase_h
00022 
00023 #include <kurl.h>
00024 #include <kconfigbase.h>
00025 #include <kio/global.h>
00026 #include <kio/authinfo.h>
00027 
00028 class DCOPClient;
00029 class KRemoteEncoding;
00030 
00031 namespace KIO {
00032 
00033 class Connection;
00034 class SlaveBasePrivate;
00035 
00045 class KIO_EXPORT SlaveBase
00046 {
00047 public:
00048     SlaveBase( const QCString &protocol, const QCString &pool_socket, const QCString &app_socket);
00049     virtual ~SlaveBase();
00050 
00055     void exit();
00056 
00060     void dispatchLoop();
00061 
00065     void setConnection( Connection* connection ) { m_pConnection = connection; }
00069     Connection *connection() const { return m_pConnection; }
00070 
00071 
00073     // Message Signals to send to the job
00075 
00084     void data( const QByteArray &data );
00085 
00090     void dataReq( );
00091 
00109     void error( int _errid, const QString &_text );
00110 
00114     void connected();
00115 
00120     void finished();
00121 
00125     void needSubURLData();
00126 
00133     void slaveStatus(const QString &host, bool connected);
00134 
00141     void statEntry( const UDSEntry& _entry );
00142 
00148     void listEntries( const UDSEntryList& _entry );
00149 
00157     bool canResume( KIO::filesize_t offset );
00158 
00159     /*
00160      * Call this at the beginning of get(), if the "resume" metadata was set
00161      * and resuming is implemented by this protocol.
00162      */
00163     void canResume();
00164 
00166     // Info Signals to send to the job
00168 
00174     void totalSize( KIO::filesize_t _bytes );
00180     void processedSize( KIO::filesize_t _bytes );
00181 
00193     void processedPercent( float percent );
00194 
00200     void speed( unsigned long _bytes_per_second );
00201 
00206     void redirection( const KURL &_url );
00207 
00213     void errorPage();
00214 
00219     void mimeType( const QString &_type );
00220 
00224     void warning( const QString &msg );
00225 
00230     void infoMessage( const QString &msg );
00231 
00232     enum MessageBoxType { QuestionYesNo = 1, WarningYesNo = 2, WarningContinueCancel = 3, WarningYesNoCancel = 4, Information = 5, SSLMessageBox = 6 };
00233 
00247     int messageBox( MessageBoxType type, const QString &text,
00248                     const QString &caption = QString::null,
00249                     const QString &buttonYes = QString::null,
00250                     const QString &buttonNo = QString::null );
00251 
00268     int messageBox( const QString &text, MessageBoxType type,
00269                     const QString &caption = QString::null,
00270                     const QString &buttonYes = QString::null,
00271                     const QString &buttonNo = QString::null,
00272                     const QString &dontAskAgainName = QString::null );
00273 
00278     void setMetaData(const QString &key, const QString &value);
00279 
00285     bool hasMetaData(const QString &key) const;
00286 
00291     QString metaData(const QString &key) const;
00292 
00298     bool hasMetaData(const QString &key);
00299 
00304     QString metaData(const QString &key);
00305 
00313     KConfigBase* config();
00314 
00321     KRemoteEncoding* remoteEncoding();
00322 
00323 
00325     // Commands sent by the job, the slave has to
00326     // override what it wants to implement
00328 
00340     virtual void setHost(const QString& host, int port, const QString& user, const QString& pass);
00341 
00345     virtual void setSubURL(const KURL&url);
00346 
00356     virtual void openConnection();
00357 
00366     virtual void closeConnection();
00367 
00374     virtual void get( const KURL& url );
00375 
00385     virtual void put( const KURL& url, int permissions, bool overwrite, bool resume );
00386 
00392     virtual void stat( const KURL& url );
00393 
00406     virtual void mimetype( const KURL& url );
00407 
00415     virtual void listDir( const KURL& url );
00416 
00424     virtual void mkdir( const KURL&url, int permissions );
00425 
00434     virtual void rename( const KURL& src, const KURL& dest, bool overwrite );
00435 
00443     virtual void symlink( const QString& target, const KURL& dest, bool overwrite );
00444 
00449     virtual void chmod( const KURL& url, int permissions );
00450 
00461     virtual void copy( const KURL &src, const KURL &dest, int permissions, bool overwrite );
00462 
00469     virtual void del( const KURL &url, bool isfile);
00470 
00471     // TODO KDE4: add setLinkDest() or something, to modify symlink targets.
00472     // Will be used for kio_file but also kio_remote (#97129)
00473 
00482     virtual void special( const QByteArray & data );
00483 
00491     virtual void multiGet( const QByteArray & data );
00492 
00497     virtual void slave_status();
00498 
00503     virtual void reparseConfiguration();
00504 
00505 
00509     int connectTimeout();
00510 
00514     int proxyConnectTimeout();
00515 
00520     int responseTimeout();
00521 
00526     int readTimeout();
00527 
00542     void setTimeoutSpecialCommand(int timeout, const QByteArray &data=QByteArray());
00543 
00547     static void sigsegv_handler(int);
00551     static void sigpipe_handler(int);
00552 
00554     // Dispatching (internal)
00556 
00560     virtual bool dispatch();
00564     virtual void dispatch( int command, const QByteArray &data );
00565 
00574     int readData( QByteArray &buffer );
00575 
00587     void listEntry( const UDSEntry& _entry, bool ready);
00588 
00593     void connectSlave(const QString& path);
00594     void disconnectSlave();
00595 
00645     bool openPassDlg( KIO::AuthInfo& info, const QString &errorMsg );
00646 
00651     bool openPassDlg( KIO::AuthInfo& info );
00652 
00680     bool checkCachedAuthentication( AuthInfo& info );
00681 
00688     bool cacheAuthentication( const AuthInfo& info );
00689 
00694     bool pingCacheDaemon() const;
00695 
00702     QString createAuthCacheKey( const KURL& url );
00703 
00711     void sendAuthenticationKey( const QCString& gKey, const QCString& key, bool keep );
00712 
00721     void delCachedAuthentication( const QString& key );
00722 
00727     void setMultipleAuthCaching( bool ) {};
00728 
00733     bool multipleAuthCaching() const { return false; }
00734 
00753     bool requestNetwork(const QString& host = QString::null);
00754 
00768     void dropNetwork(const QString& host = QString::null);
00769 
00774     DCOPClient *dcopClient();
00775 
00780     int waitForAnswer( int expected1, int expected2, QByteArray & data, int * pCmd = 0 );
00781 
00785     void sendMetaData();
00786 
00790     QCString mProtocol;
00791 
00792     Connection * m_pConnection;
00793 
00794     MetaData mOutgoingMetaData;
00795     MetaData mIncomingMetaData;
00796 
00803     bool wasKilled() const;
00804 
00809     void setKillFlag();
00810 
00811 protected:
00812     UDSEntryList pendingListEntries;
00813     uint listEntryCurrentSize;
00814     long listEntry_sec, listEntry_usec;
00815     Connection *appconn;
00816     QString mPoolSocket;
00817     QString mAppSocket;
00818     bool mConnectedToApp;
00819     static long s_seqNr;
00820     virtual void virtual_hook( int id, void* data );
00821 
00822 private:
00823     SlaveBasePrivate *d;
00824 };
00825 
00826 }
00827 
00828 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys