File indexing completed on 2024-10-13 03:38:13

0001 /*
0002     SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef SLAVEBASE_H
0008 #define SLAVEBASE_H
0009 
0010 #include "job_base.h" // for KIO::JobFlags
0011 #include <kio/authinfo.h>
0012 #include <kio/global.h>
0013 #include <kio/udsentry.h>
0014 
0015 #include <QByteArray>
0016 #include <QHostInfo>
0017 #include <QSsl>
0018 
0019 #include <memory>
0020 
0021 class KConfigGroup;
0022 class KRemoteEncoding;
0023 class QUrl;
0024 
0025 namespace KIO
0026 {
0027 class Connection;
0028 class SlaveBasePrivate;
0029 
0030 // TODO: Enable once file KIO worker is ported away and add endif, similar in the cpp file
0031 // #if KIOCORE_ENABLE_DEPRECATED_SINCE(version where file:/ KIO worker was ported)
0032 
0033 /**
0034  * @class KIO::SlaveBase slavebase.h <KIO/SlaveBase>
0035  *
0036  * There are two classes that specifies the protocol between application (job)
0037  * and kioslave. SlaveInterface is the class to use on the application end,
0038  * SlaveBase is the one to use on the slave end.
0039  *
0040  * Slave implementations should simply inherit SlaveBase
0041  *
0042  * A call to foo() results in a call to slotFoo() on the other end.
0043  *
0044  * Note that a kioslave doesn't have a Qt event loop. When idle, it's waiting for a command
0045  * on the socket that connects it to the application. So don't expect a kioslave to react
0046  * to D-Bus signals for instance. KIOSlaves are short-lived anyway, so any kind of watching
0047  * or listening for notifications should be done elsewhere, for instance in a kded module
0048  * (see kio_desktop's desktopnotifier.cpp for an example).
0049  *
0050  * If a kioslave needs a Qt event loop within the implementation of one method, e.g. to
0051  * wait for an asynchronous operation to finish, that is possible, using QEventLoop.
0052  *
0053  * @deprecated Since 5.96, use WorkerBase.
0054  */
0055 class SlaveBase
0056 {
0057 public:
0058     KIOCORE_DEPRECATED_VERSION_BELATED(5, 101, 5, 96, "Use WorkerBase")
0059     SlaveBase(const QByteArray &protocol, const QByteArray &pool_socket, const QByteArray &app_socket);
0060     virtual ~SlaveBase();
0061 
0062     /**
0063      * @internal
0064      * Terminate the slave by calling the destructor and then ::exit()
0065      */
0066     void exit();
0067 
0068     /**
0069      * @internal
0070      */
0071     void dispatchLoop();
0072 
0073     ///////////
0074     // Message Signals to send to the job
0075     ///////////
0076 
0077     /**
0078      * Sends data in the slave to the job (i.e.\ in get).
0079      *
0080      * To signal end of data, simply send an empty
0081      * QByteArray().
0082      *
0083      * @param data the data read by the slave
0084      */
0085     void data(const QByteArray &data);
0086 
0087     /**
0088      * Asks for data from the job.
0089      * @see readData
0090      */
0091     void dataReq();
0092 
0093     /**
0094      * open succeeds
0095      * @see open()
0096      */
0097     void opened();
0098 
0099     /**
0100      * Call to signal an error.
0101      * This also finishes the job, so you must not call
0102      * finished() after calling this.
0103      *
0104      * If the error code is KIO::ERR_SLAVE_DEFINED then the
0105      * _text should contain the complete translated text of
0106      * of the error message.
0107      *
0108      * For all other error codes, _text should match the corresponding
0109      * error code. Usually, _text is a file or host name, or the error which
0110      * was passed from the server.<br>
0111      * For example, for KIO::ERR_DOES_NOT_EXIST, _text may only
0112      * be the file or folder which does not exist, nothing else. Otherwise,
0113      * this would break error strings generated by KIO::buildErrorString().<br>
0114      * If you have to add more details than what the standard error codes
0115      * provide, you'll need to use KIO::ERR_SLAVE_DEFINED.
0116      * For a complete list of what _text should contain for each error code,
0117      * look at the source of KIO::buildErrorString().
0118      *
0119      * You can add rich text markup to the message, the places where the
0120      * error message will be displayed are rich text aware.
0121      *
0122      * @see KIO::Error
0123      * @see KIO::buildErrorString
0124      * @param _errid the error code from KIO::Error
0125      * @param _text the rich text error message
0126      */
0127     void error(int _errid, const QString &_text);
0128 
0129     /**
0130      * Call in openConnection, if you reimplement it, when you're done.
0131      */
0132     void connected();
0133 
0134     /**
0135      * Call to signal successful completion of any command
0136      * besides openConnection and closeConnection. Do not
0137      * call this after calling error().
0138      */
0139     void finished();
0140 
0141     /**
0142      * Used to report the status of the slave.
0143      * @param host the slave is currently connected to. (Should be
0144      *        empty if not connected)
0145      * @param connected Whether an actual network connection exists.
0146      **/
0147     void slaveStatus(const QString &host, bool connected);
0148 
0149     /**
0150      * Call this from stat() to express details about an object, the
0151      * UDSEntry customarily contains the atoms describing file name, size,
0152      * MIME type, etc.
0153      * @param _entry The UDSEntry containing all of the object attributes.
0154      */
0155     void statEntry(const UDSEntry &_entry);
0156 
0157     /**
0158      * Call this in listDir, each time you have a bunch of entries
0159      * to report.
0160      * @param _entry The UDSEntry containing all of the object attributes.
0161      */
0162     void listEntries(const UDSEntryList &_entry);
0163 
0164     /**
0165      * Call this at the beginning of put(), to give the size of the existing
0166      * partial file, if there is one. The @p offset argument notifies the
0167      * other job (the one that gets the data) about the offset to use.
0168      * In this case, the boolean returns whether we can indeed resume or not
0169      * (we can't if the protocol doing the get() doesn't support setting an offset)
0170      */
0171     bool canResume(KIO::filesize_t offset);
0172 
0173     /**
0174      * Call this at the beginning of get(), if the "range-start" metadata was set
0175      * and returning byte ranges is implemented by this protocol.
0176      */
0177     void canResume();
0178 
0179     ///////////
0180     // Info Signals to send to the job
0181     ///////////
0182 
0183     /**
0184      * Call this in get and copy, to give the total size
0185      * of the file.
0186      */
0187     void totalSize(KIO::filesize_t _bytes);
0188     /**
0189      * Call this during get and copy, once in a while,
0190      * to give some info about the current state.
0191      * Don't emit it in listDir, listEntries speaks for itself.
0192      */
0193     void processedSize(KIO::filesize_t _bytes);
0194 
0195     void position(KIO::filesize_t _pos);
0196 
0197     void written(KIO::filesize_t _bytes);
0198 
0199     /**
0200      * @since 5.66
0201      */
0202     void truncated(KIO::filesize_t _length);
0203 
0204     /**
0205      * Only use this if you can't know in advance the size of the
0206      * copied data. For example, if you're doing variable bitrate
0207      * compression of the source.
0208      *
0209      * STUB ! Currently unimplemented. Here now for binary compatibility.
0210      *
0211      * Call this during get and copy, once in a while,
0212      * to give some info about the current state.
0213      * Don't emit it in listDir, listEntries speaks for itself.
0214      */
0215     void processedPercent(float percent); // KF6 TODO REMOVE
0216 
0217     /**
0218      * Call this in get and copy, to give the current transfer
0219      * speed, but only if it can't be calculated out of the size you
0220      * passed to processedSize (in most cases you don't want to call it)
0221      */
0222     void speed(unsigned long _bytes_per_second);
0223 
0224     /**
0225      * Call this to signal a redirection.
0226      * The job will take care of going to that url.
0227      */
0228     void redirection(const QUrl &_url);
0229 
0230     /**
0231      * Tell that we will only get an error page here.
0232      * This means: the data you'll get isn't the data you requested,
0233      * but an error page (usually HTML) that describes an error.
0234      */
0235     void errorPage();
0236 
0237     /**
0238      * Call this in mimetype() and in get(), when you know the MIME type.
0239      * See mimetype() about other ways to implement it.
0240      */
0241     void mimeType(const QString &_type);
0242 
0243     /**
0244      * Call to signal a warning, to be displayed in a dialog box.
0245      */
0246     void warning(const QString &msg);
0247 
0248     /**
0249      * Call to signal a message, to be displayed if the application wants to,
0250      * for instance in a status bar. Usual examples are "connecting to host xyz", etc.
0251      */
0252     void infoMessage(const QString &msg);
0253 
0254     /**
0255      * Type of message box. Should be kept in sync with KMessageBox::DialogType.
0256      */
0257     enum MessageBoxType {
0258         QuestionTwoActions = 1, ///< @since 5.100
0259         WarningTwoActions = 2, ///< @since 5.100
0260         WarningContinueCancel = 3,
0261         WarningTwoActionsCancel = 4, ///< @since 5.100
0262         Information = 5,
0263         // In KMessageBox::DialogType; <unused> = 7, Error = 8, QuestionTwoActionsCancel = 9
0264         WarningContinueCancelDetailed = 10,
0265     };
0266 
0267     /**
0268      * Button codes. Should be kept in sync with KMessageBox::ButtonCode
0269      */
0270     enum ButtonCode {
0271         Ok = 1,
0272         Cancel = 2,
0273         PrimaryAction = 3, ///< @since 5.100
0274         SecondaryAction = 4, ///< @since 5.100
0275         Continue = 5,
0276     };
0277 
0278     /**
0279      * Call this to show a message box from the slave
0280      * @param type type of message box: QuestionTwoActions, WarningTwoActions, WarningContinueCancel...
0281      * @param text Message string. May contain newlines.
0282      * @param title Message box title.
0283      * @param primaryActionText the text for the first button.
0284      *                          Ignored for @p type Information & SSLMessageBox.
0285      * @param secondaryActionText the text for the second button.
0286      *                            Ignored for @p type WarningContinueCancel, WarningContinueCancelDetailed,
0287      *                            Information & SSLMessageBox.
0288      * @return a button code, as defined in ButtonCode, or 0 on communication error.
0289      */
0290     int messageBox(MessageBoxType type,
0291                    const QString &text,
0292                    const QString &title = QString(),
0293                    const QString &primaryActionText = QString(),
0294                    const QString &secondaryActionText = QString());
0295 
0296     int sslError(const QVariantMap &sslData);
0297 
0298     /**
0299      * Call this to show a message box from the slave
0300      * @param text Message string. May contain newlines.
0301      * @param type type of message box: QuestionTwoActions, WarningTwoActions, WarningContinueCancel...
0302      * @param title Message box title.
0303      * @param primaryActionText the text for the first button.
0304      *                          Ignored for @p type Information & SSLMessageBox.
0305      * @param secondaryActionText the text for the second button.
0306      *                            Ignored for @p type WarningContinueCancel, WarningContinueCancelDetailed,
0307      *                            Information & SSLMessageBox.
0308      * @param dontAskAgainName the name used to store result from 'Do not ask again' checkbox.
0309      * @return a button code, as defined in ButtonCode, or 0 on communication error.
0310      */
0311     int messageBox(const QString &text,
0312                    MessageBoxType type,
0313                    const QString &title = QString(),
0314                    const QString &primaryActionText = QString(),
0315                    const QString &secondaryActionText = QString(),
0316                    const QString &dontAskAgainName = QString());
0317 
0318     /**
0319      * Sets meta-data to be send to the application before the first
0320      * data() or finished() signal.
0321      */
0322     void setMetaData(const QString &key, const QString &value);
0323 
0324     /**
0325      * Queries for the existence of a certain config/meta-data entry
0326      * send by the application to the slave.
0327      */
0328     bool hasMetaData(const QString &key) const;
0329 
0330     /**
0331      * Queries for config/meta-data send by the application to the slave.
0332      */
0333     QString metaData(const QString &key) const;
0334 
0335     /**
0336      * @internal for ForwardingSlaveBase
0337      * Contains all metadata (but no config) sent by the application to the slave.
0338      */
0339     MetaData allMetaData() const;
0340 
0341     /**
0342      * Returns a map to query config/meta-data information from.
0343      *
0344      * The application provides the slave with all configuration information
0345      * relevant for the current protocol and host.
0346      *
0347      * Use configValue() as shortcut.
0348      * @since 5.64
0349      */
0350     QMap<QString, QVariant> mapConfig() const;
0351 
0352     /**
0353      * Returns a bool from the config/meta-data information.
0354      * @since 5.64
0355      */
0356     bool configValue(const QString &key, bool defaultValue) const;
0357 
0358     /**
0359      * Returns an int from the config/meta-data information.
0360      * @since 5.64
0361      */
0362     int configValue(const QString &key, int defaultValue) const;
0363 
0364     /**
0365      * Returns a QString from the config/meta-data information.
0366      * @since 5.64
0367      */
0368     QString configValue(const QString &key, const QString &defaultValue = QString()) const;
0369 
0370     /**
0371      * Returns a configuration object to query config/meta-data information
0372      * from.
0373      *
0374      * The application provides the slave with all configuration information
0375      * relevant for the current protocol and host.
0376      *
0377      * @note Since 5.64 prefer to use mapConfig() or one of the configValue(...) overloads.
0378      * @todo Find replacements for the other current usages of this method.
0379      */
0380     KConfigGroup *config();
0381     // KF6: perhaps rename mapConfig() to config() when removing this
0382 
0383     /**
0384      * Returns an object that can translate remote filenames into proper
0385      * Unicode forms. This encoding can be set by the user.
0386      */
0387     KRemoteEncoding *remoteEncoding();
0388 
0389     ///////////
0390     // Commands sent by the job, the slave has to
0391     // override what it wants to implement
0392     ///////////
0393 
0394     /**
0395      * Set the host
0396      *
0397      * Called directly by createWorker, this is why there is no equivalent in
0398      * SlaveInterface, unlike the other methods.
0399      *
0400      * This method is called whenever a change in host, port or user occurs.
0401      */
0402     virtual void setHost(const QString &host, quint16 port, const QString &user, const QString &pass);
0403 
0404     /**
0405      * Opens the connection (forced).
0406      *
0407      * When this function gets called the slave is operating in
0408      * connection-oriented mode.
0409      * When a connection gets lost while the slave operates in
0410      * connection oriented mode, the slave should report
0411      * ERR_CONNECTION_BROKEN instead of reconnecting. The user is
0412      * expected to disconnect the slave in the error handler.
0413      */
0414     virtual void openConnection();
0415 
0416     /**
0417      * Closes the connection (forced).
0418      *
0419      * Called when the application disconnects the slave to close
0420      * any open network connections.
0421      *
0422      * When the slave was operating in connection-oriented mode,
0423      * it should reset itself to connectionless (default) mode.
0424      */
0425     virtual void closeConnection();
0426 
0427     /**
0428      * get, aka read.
0429      * @param url the full url for this request. Host, port and user of the URL
0430      *        can be assumed to be the same as in the last setHost() call.
0431      *
0432      * The slave should first "emit" the MIME type by calling mimeType(),
0433      * and then "emit" the data using the data() method.
0434      *
0435      * The reason why we need get() to emit the MIME type is:
0436      * when pasting a URL in krunner, or konqueror's location bar,
0437      * we have to find out what is the MIME type of that URL.
0438      * Rather than doing it with a call to mimetype(), then the app or part
0439      * would have to do a second request to the same server, this is done
0440      * like this: get() is called, and when it emits the MIME type, the job
0441      * is put on hold and the right app or part is launched. When that app
0442      * or part calls get(), the slave is magically reused, and the download
0443      * can now happen. All with a single call to get() in the slave.
0444      * This mechanism is also described in KIO::get().
0445      */
0446     virtual void get(const QUrl &url);
0447 
0448     /**
0449      * open.
0450      * @param url the full url for this request. Host, port and user of the URL
0451      *        can be assumed to be the same as in the last setHost() call.
0452      * @param mode see \ref QIODevice::OpenMode
0453      */
0454     virtual void open(const QUrl &url, QIODevice::OpenMode mode);
0455 
0456     /**
0457      * read.
0458      * @param size the requested amount of data to read
0459      * @see KIO::FileJob::read()
0460      */
0461     virtual void read(KIO::filesize_t size);
0462     /**
0463      * write.
0464      * @param data the data to write
0465      * @see KIO::FileJob::write()
0466      */
0467     virtual void write(const QByteArray &data);
0468     /**
0469      * seek.
0470      * @param offset the requested amount of data to read
0471      * @see KIO::FileJob::read()
0472      */
0473     virtual void seek(KIO::filesize_t offset);
0474     /**
0475      * close.
0476      * @see KIO::FileJob::close()
0477      */
0478     virtual void close();
0479 
0480     /**
0481      * put, i.e.\ write data into a file.
0482      *
0483      * @param url where to write the file
0484      * @param permissions may be -1. In this case no special permission mode is set.
0485      * @param flags We support Overwrite here. Hopefully, we're going to
0486      * support Resume in the future, too.
0487      * If the file indeed already exists, the slave should NOT apply the
0488      * permissions change to it.
0489      * The support for resuming using .part files is done by calling canResume().
0490      *
0491      * IMPORTANT: Use the "modified" metadata in order to set the modification time of the file.
0492      *
0493      * @see canResume()
0494      */
0495     virtual void put(const QUrl &url, int permissions, JobFlags flags);
0496 
0497     /**
0498      * Finds all details for one file or directory.
0499      * The information returned is the same as what listDir returns,
0500      * but only for one file or directory.
0501      * Call statEntry() after creating the appropriate UDSEntry for this
0502      * url.
0503      *
0504      * You can use the "details" metadata to optimize this method to only
0505      * do as much work as needed by the application.
0506      * By default details is 2 (all details wanted, including modification time, size, etc.),
0507      * details==1 is used when deleting: we don't need all the information if it takes
0508      * too much time, no need to follow symlinks etc.
0509      * details==0 is used for very simple probing: we'll only get the answer
0510      * "it's a file or a directory (or a symlink), or it doesn't exist".
0511      */
0512     virtual void stat(const QUrl &url);
0513 
0514     /**
0515      * Finds MIME type for one file or directory.
0516      *
0517      * This method should either emit 'mimeType' or it
0518      * should send a block of data big enough to be able
0519      * to determine the MIME type.
0520      *
0521      * If the slave doesn't reimplement it, a get will
0522      * be issued, i.e. the whole file will be downloaded before
0523      * determining the MIME type on it - this is obviously not a
0524      * good thing in most cases.
0525      */
0526     virtual void mimetype(const QUrl &url);
0527 
0528     /**
0529      * Lists the contents of @p url.
0530      * The slave should emit ERR_CANNOT_ENTER_DIRECTORY if it doesn't exist,
0531      * if we don't have enough permissions.
0532      * You should not list files if the path in @p url is empty, but redirect
0533      * to a non-empty path instead.
0534      */
0535     virtual void listDir(const QUrl &url);
0536 
0537     /**
0538      * Create a directory
0539      * @param url path to the directory to create
0540      * @param permissions the permissions to set after creating the directory
0541      * (-1 if no permissions to be set)
0542      * The slave emits ERR_CANNOT_MKDIR if failure.
0543      */
0544     virtual void mkdir(const QUrl &url, int permissions);
0545 
0546     /**
0547      * Rename @p oldname into @p newname.
0548      * If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will
0549      * ask for copy + del instead.
0550      *
0551      * Important: the slave must implement the logic "if the destination already
0552      * exists, error ERR_DIR_ALREADY_EXIST or ERR_FILE_ALREADY_EXIST".
0553      * For performance reasons no stat is done in the destination before hand,
0554      * the slave must do it.
0555      *
0556      * By default, rename() is only called when renaming (moving) from
0557      * yourproto://host/path to yourproto://host/otherpath.
0558      *
0559      * If you set renameFromFile=true then rename() will also be called when
0560      * moving a file from file:///path to yourproto://host/otherpath.
0561      * Otherwise such a move would have to be done the slow way (copy+delete).
0562      * See KProtocolManager::canRenameFromFile() for more details.
0563      *
0564      * If you set renameToFile=true then rename() will also be called when
0565      * moving a file from yourproto: to file:.
0566      * See KProtocolManager::canRenameToFile() for more details.
0567      *
0568      * @param src where to move the file from
0569      * @param dest where to move the file to
0570      * @param flags We support Overwrite here
0571      */
0572     virtual void rename(const QUrl &src, const QUrl &dest, JobFlags flags);
0573 
0574     /**
0575      * Creates a symbolic link named @p dest, pointing to @p target, which
0576      * may be a relative or an absolute path.
0577      * @param target The string that will become the "target" of the link (can be relative)
0578      * @param dest The symlink to create.
0579      * @param flags We support Overwrite here
0580      */
0581     virtual void symlink(const QString &target, const QUrl &dest, JobFlags flags);
0582 
0583     /**
0584      * Change permissions on @p url.
0585      *
0586      * The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD
0587      */
0588     virtual void chmod(const QUrl &url, int permissions);
0589 
0590     /**
0591      * Change ownership of @p url.
0592      *
0593      * The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHOWN
0594      */
0595     virtual void chown(const QUrl &url, const QString &owner, const QString &group);
0596 
0597     /**
0598      * Sets the modification time for @p url.
0599      *
0600      * For instance this is what CopyJob uses to set mtime on dirs at the end of a copy.
0601      * It could also be used to set the mtime on any file, in theory.
0602      * The usual implementation on unix is to call utime(path, &myutimbuf).
0603      * The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_SETTIME
0604      */
0605     virtual void setModificationTime(const QUrl &url, const QDateTime &mtime);
0606 
0607     /**
0608      * Copy @p src into @p dest.
0609      *
0610      * By default, copy() is only called when copying a file from
0611      * yourproto://host/path to yourproto://host/otherpath.
0612      *
0613      * If you set copyFromFile=true then copy() will also be called when
0614      * moving a file from file:///path to yourproto://host/otherpath.
0615      * Otherwise such a copy would have to be done the slow way (get+put).
0616      * See also KProtocolManager::canCopyFromFile().
0617      *
0618      * If you set copyToFile=true then copy() will also be called when
0619      * moving a file from yourproto: to file:.
0620      * See also KProtocolManager::canCopyToFile().
0621      *
0622      * If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will
0623      * ask for get + put instead.
0624      *
0625      * If the slave returns an error ERR_FILE_ALREADY_EXIST, the job will
0626      * ask for a different destination filename.
0627      *
0628      * @param src where to copy the file from (decoded)
0629      * @param dest where to copy the file to (decoded)
0630      * @param permissions may be -1. In this case no special permission mode is set,
0631      *        and the owner and group permissions are not preserved.
0632      * @param flags We support Overwrite here
0633      *
0634      * Don't forget to set the modification time of @p dest to be the modification time of @p src.
0635      */
0636     virtual void copy(const QUrl &src, const QUrl &dest, int permissions, JobFlags flags);
0637 
0638     /**
0639      * Delete a file or directory.
0640      * @param url file/directory to delete
0641      * @param isfile if true, a file should be deleted.
0642      *               if false, a directory should be deleted.
0643      *
0644      * By default, del() on a directory should FAIL if the directory is not empty.
0645      * However, if metadata("recurse") == "true", then the slave can do a recursive deletion.
0646      * This behavior is only invoked if the slave specifies deleteRecursive=true in its protocol file.
0647      */
0648     virtual void del(const QUrl &url, bool isfile);
0649 
0650     /**
0651      * Change the destination of a symlink
0652      * @param url the url of the symlink to modify
0653      * @param target the new destination (target) of the symlink
0654      */
0655     virtual void setLinkDest(const QUrl &url, const QString &target);
0656 
0657     /**
0658      * Used for any command that is specific to this slave (protocol).
0659      *
0660      * Examples are : HTTP POST, mount and unmount (kio_file)
0661      *
0662      * @param data packed data; the meaning is completely dependent on the
0663      *        slave, but usually starts with an int for the command number.
0664      * Document your slave's commands, at least in its header file.
0665      */
0666     virtual void special(const QByteArray &data);
0667 
0668     /**
0669      * Called to get the status of the slave. Slave should respond
0670      * by calling slaveStatus(...)
0671      */
0672     virtual void slave_status();
0673 
0674     /**
0675      * Called by the scheduler to tell the slave that the configuration
0676      * changed (i.e.\ proxy settings).
0677      */
0678     virtual void reparseConfiguration();
0679 
0680     /**
0681      * @return timeout value for connecting to remote host.
0682      */
0683     int connectTimeout();
0684 
0685     /**
0686      * @return timeout value for connecting to proxy in secs.
0687      */
0688     int proxyConnectTimeout();
0689 
0690     /**
0691      * @return timeout value for read from first data from
0692      * remote host in seconds.
0693      */
0694     int responseTimeout();
0695 
0696     /**
0697      * @return timeout value for read from subsequent data from
0698      * remote host in secs.
0699      */
0700     int readTimeout();
0701 
0702     /**
0703      * This function sets a timeout of @p timeout seconds and calls
0704      * special(data) when the timeout occurs as if it was called by the
0705      * application.
0706      *
0707      * A timeout can only occur when the slave is waiting for a command
0708      * from the application.
0709      *
0710      * Specifying a negative timeout cancels a pending timeout.
0711      *
0712      * Only one timeout at a time is supported, setting a timeout
0713      * cancels any pending timeout.
0714      */
0715     void setTimeoutSpecialCommand(int timeout, const QByteArray &data = QByteArray());
0716 
0717     /////////////////
0718     // Dispatching (internal)
0719     ////////////////
0720 
0721     /**
0722      * @internal
0723      */
0724     virtual void dispatch(int command, const QByteArray &data);
0725 
0726     /**
0727      * @internal
0728      */
0729     virtual void dispatchOpenCommand(int command, const QByteArray &data);
0730 
0731     /**
0732      * Read data sent by the job, after a dataReq
0733      *
0734      * @param buffer buffer where data is stored
0735      * @return 0 on end of data,
0736      *         > 0 bytes read
0737      *         < 0 error
0738      **/
0739     int readData(QByteArray &buffer);
0740 
0741     /**
0742      * It collects entries and emits them via listEntries
0743      * when enough of them are there or a certain time
0744      * frame exceeded (to make sure the app gets some
0745      * items in time but not too many items one by one
0746      * as this will cause a drastic performance penalty).
0747      * @param entry The UDSEntry containing all of the object attributes.
0748      * @since 5.0
0749      */
0750     void listEntry(const UDSEntry &entry);
0751 
0752     /**
0753      * internal function to connect a slave to/ disconnect from
0754      * either the slave pool or the application
0755      */
0756     void connectSlave(const QString &path);
0757     void disconnectSlave();
0758 
0759     /**
0760      * Prompt the user for Authorization info (login & password).
0761      *
0762      * Use this function to request authorization information from
0763      * the end user. You can also pass an error message which explains
0764      * why a previous authorization attempt failed. Here is a very
0765      * simple example:
0766      *
0767      * \code
0768      * KIO::AuthInfo authInfo;
0769      * int errorCode = openPasswordDialogV2(authInfo);
0770      * if (!errorCode) {
0771      *    qDebug() << QLatin1String("User: ") << authInfo.username;
0772      *    qDebug() << QLatin1String("Password: not displayed here!");
0773      * } else {
0774      *    error(errorCode, QString());
0775      * }
0776      * \endcode
0777      *
0778      * You can also preset some values like the username, caption or
0779      * comment as follows:
0780      *
0781      * \code
0782      * KIO::AuthInfo authInfo;
0783      * authInfo.caption = i18n("Acme Password Dialog");
0784      * authInfo.username = "Wile E. Coyote";
0785      * QString errorMsg = i18n("You entered an incorrect password.");
0786      * int errorCode = openPasswordDialogV2(authInfo, errorMsg);
0787      * [...]
0788      * \endcode
0789      *
0790      * \note You should consider using checkCachedAuthentication() to
0791      * see if the password is available in kpasswdserver before calling
0792      * this function.
0793      *
0794      * \note A call to this function can fail and return @p false,
0795      * if the password server could not be started for whatever reason.
0796      *
0797      * \note This function does not store the password information
0798      * automatically (and has not since kdelibs 4.7). If you want to
0799      * store the password information in a persistent storage like
0800      * KWallet, then you MUST call @ref cacheAuthentication.
0801      *
0802      * @see checkCachedAuthentication
0803      * @param info  See AuthInfo.
0804      * @param errorMsg Error message to show
0805      * @return a KIO error code: NoError (0), KIO::USER_CANCELED, or other error codes.
0806      */
0807     int openPasswordDialogV2(KIO::AuthInfo &info, const QString &errorMsg = QString());
0808 
0809     /**
0810      * Checks for cached authentication based on parameters
0811      * given by @p info.
0812      *
0813      * Use this function to check if any cached password exists
0814      * for the URL given by @p info.  If @p AuthInfo::realmValue
0815      * and/or @p AuthInfo::verifyPath flag is specified, then
0816      * they will also be factored in determining the presence
0817      * of a cached password.  Note that @p Auth::url is a required
0818      * parameter when attempting to check for cached authorization
0819      * info. Here is a simple example:
0820      *
0821      * \code
0822      * AuthInfo info;
0823      * info.url = QUrl("https://www.foobar.org/foo/bar");
0824      * info.username = "somename";
0825      * info.verifyPath = true;
0826      * if ( !checkCachedAuthentication( info ) )
0827      * {
0828      *    int errorCode = openPasswordDialogV2(info);
0829      *     ....
0830      * }
0831      * \endcode
0832      *
0833      * @param       info See AuthInfo.
0834      * @return      @p true if cached Authorization is found, false otherwise.
0835      */
0836     bool checkCachedAuthentication(AuthInfo &info);
0837 
0838     /**
0839      * Caches @p info in a persistent storage like KWallet.
0840      *
0841      * Note that calling openPasswordDialogV2 does not store passwords
0842      * automatically for you (and has not since kdelibs 4.7).
0843      *
0844      * Here is a simple example of how to use cacheAuthentication:
0845      *
0846      * \code
0847      * AuthInfo info;
0848      * info.url = QUrl("https://www.foobar.org/foo/bar");
0849      * info.username = "somename";
0850      * info.verifyPath = true;
0851      * if ( !checkCachedAuthentication( info ) ) {
0852      *    int errorCode = openPasswordDialogV2(info);
0853      *    if (!errorCode) {
0854      *        if (info.keepPassword)  {  // user asked password be save/remembered
0855      *             cacheAuthentication(info);
0856      *        }
0857      *    }
0858      * }
0859      * \endcode
0860      *
0861      * @param info See AuthInfo.
0862      * @return @p true if @p info was successfully cached.
0863      */
0864     bool cacheAuthentication(const AuthInfo &info);
0865 
0866     /**
0867      * Wait for an answer to our request, until we get @p expected1 or @p expected2
0868      * @return the result from readData, as well as the cmd in *pCmd if set, and the data in @p data
0869      */
0870     int waitForAnswer(int expected1, int expected2, QByteArray &data, int *pCmd = nullptr);
0871 
0872     /**
0873      * Internal function to transmit meta data to the application.
0874      * m_outgoingMetaData will be cleared; this means that if the slave is for
0875      * example put on hold and picked up by a different KIO::Job later the new
0876      * job will not see the metadata sent before.
0877      * See kio/DESIGN.krun for an overview of the state
0878      * progression of a job/slave.
0879      * @warning calling this method may seriously interfere with the operation
0880      * of KIO which relies on the presence of some metadata at some points in time.
0881      * You should not use it if you are not familiar with KIO and not before
0882      * the slave is connected to the last job before returning to idle state.
0883      */
0884     void sendMetaData();
0885 
0886     /**
0887      * Internal function to transmit meta data to the application.
0888      * Like sendMetaData() but m_outgoingMetaData will not be cleared.
0889      * This method is mainly useful in code that runs before the slave is connected
0890      * to its final job.
0891      */
0892     void sendAndKeepMetaData();
0893 
0894     /** If your ioslave was killed by a signal, wasKilled() returns true.
0895      Check it regularly in lengthy functions (e.g. in get();) and return
0896      as fast as possible from this function if wasKilled() returns true.
0897      This will ensure that your slave destructor will be called correctly.
0898      */
0899     bool wasKilled() const;
0900 
0901     /** Internally used.
0902      * @internal
0903      */
0904     void setKillFlag();
0905 
0906     /** Internally used
0907      * @internal
0908      */
0909     void lookupHost(const QString &host);
0910 
0911     /** Internally used
0912      * @internal
0913      */
0914     int waitForHostInfo(QHostInfo &info);
0915 
0916     /**
0917      * Checks with job if privilege operation is allowed.
0918      * @return privilege operation status.
0919      * @see PrivilegeOperationStatus
0920      * @since 5.66
0921      */
0922     PrivilegeOperationStatus requestPrivilegeOperation(const QString &operationDetails);
0923 
0924     /**
0925      * Adds @p action to the list of PolicyKit actions which the
0926      * slave is authorized to perform.
0927      *
0928      * @param action the PolicyKit action
0929      * @since 5.45
0930      */
0931     void addTemporaryAuthorization(const QString &action);
0932 
0933 protected:
0934     /**
0935      * Name of the protocol supported by this slave
0936      */
0937     QByteArray mProtocol;
0938     // Often used by TcpSlaveBase and unlikely to change
0939     MetaData mOutgoingMetaData;
0940     MetaData mIncomingMetaData;
0941 
0942     enum VirtualFunctionId {
0943         AppConnectionMade = 0,
0944         GetFileSystemFreeSpace = 1, // KF6 TODO: Turn into a virtual method
0945         Truncate = 2, // KF6 TODO: Turn into a virtual method
0946     };
0947     virtual void virtual_hook(int id, void *data);
0948 
0949 private:
0950     // Convenience function converting mProtocol to QString as unsupportedActionErrorString(), which
0951     // is used in many places in the code, takes a QString parameter
0952     inline const QString protocolName() const
0953     {
0954         return QString::fromLatin1(mProtocol);
0955     }
0956 
0957     void setRunInThread(bool b);
0958 
0959     // This helps catching missing tr()/i18n() calls in error().
0960     void error(int _errid, const QByteArray &_text);
0961     void send(int cmd, const QByteArray &arr = QByteArray());
0962 
0963     std::unique_ptr<SlaveBasePrivate> const d;
0964     friend class SlaveBasePrivate;
0965     friend class WorkerThread;
0966     friend class WorkerBasePrivate;
0967     friend class WorkerSlaveBaseBridge;
0968 };
0969 }
0970 
0971 #endif
0972 
0973 // HACK see comments in workerbase.h for same include/declaration guard
0974 #ifndef KIO_UNSUPPORTEDACTIONERRORSTRING
0975 #define KIO_UNSUPPORTEDACTIONERRORSTRING
0976 
0977 namespace KIO
0978 {
0979 
0980 /**
0981  * Returns an appropriate error message if the given command @p cmd
0982  * is an unsupported action (ERR_UNSUPPORTED_ACTION).
0983  * @param protocol name of the protocol
0984  * @param cmd given command
0985  * @see enum Command
0986  */
0987 KIOCORE_EXPORT QString unsupportedActionErrorString(const QString &protocol, int cmd);
0988 }
0989 
0990 #endif