class SlaveBase

There are two classes that specifies the protocol between application (job) and kioslave. More...

Full nameKIO::SlaveBase
Definition#include <slavebase.h>
Inherited byTCPSlaveBase
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Types

Public Methods

Public Static Methods

Protected Methods

Protected Members


Detailed Description

There are two classes that specifies the protocol between application (job) and kioslave. SlaveInterface is the class to use on the application end, SlaveBase is the one to use on the slave end.

Slave implementations should simply inherit SlaveBase

A call to foo() results in a call to slotFoo() on the other end.

 SlaveBase ( const QCString &protocol, const QCString &pool_socket, const QCString &app_socket)

SlaveBase

 ~SlaveBase ()

~SlaveBase

[virtual]

void  dispatchLoop ()

dispatchLoop

void  setConnection ( Connection* connection )

setConnection

Connection * connection ()

connection

[const]

void  data ( const QByteArray &data )

data

Sends data in the slave to the job (i.e. in get).

To signal end of data, simply send an empty QByteArray().

Parameters:
datathe data read by the slave

void  dataReq ( )

dataReq

Asks for data from the job.

See also: readData

void  error ( int _errid, const QString &_text )

error

Call to signal an error. This also finishes the job, no need to call finished.

void  connected ()

connected

Call in openConnection, if you reimplement it, when you're done.

void  finished ()

finished

Call to signal successful completion of any command (besides openConnection and closeConnection)

void  needSubURLData ()

needSubURLData

Call to signal that data from the sub-URL is needed

void  slaveStatus (const QString &host, bool connected)

slaveStatus

Used to report the status of the slave.

Parameters:
hostthe slave is currently connected to. (Should be empty if not connected)
connectedWhether an actual network connection exists.

void  statEntry ( const UDSEntry& _entry )

statEntry

Call this from stat() to express details about an object, the UDSEntry customarily contains the atoms describing file name, size, mimetype, etc.

Parameters:
_entryThe UDSEntry containing all of the object attributes.

void  listEntries ( const UDSEntryList& _entry )

listEntries

Call this in listDir, each time you have a bunch of entries to report.

bool  canResume ( unsigned long offset )

canResume

Call this at the beginning of put(), to give the size of the existing partial file, if there is one. The offset argument notifies the other job (the one that gets the data) about the offset to use. In this case, the boolean returns whether we can indeed resume or not (we can't if the protocol doing the get() doesn't support setting an offset)

void  canResume ()

canResume

void  totalSize ( unsigned long _bytes )

totalSize

Call this in get and copy, to give the total size of the file Call in listDir too, when you know the total number of items.

void  processedSize ( unsigned long _bytes )

processedSize

Call this during get and copy, once in a while, to give some info about the current state. Don't emit it in listDir, listEntries speaks for itself.

void  speed ( unsigned long _bytes_per_second )

speed

Call this in get and copy, to give the current transfer speed. Usually worked out as processed_size / ( t - t_start )

void  redirection ( const KURL &_url )

redirection

Call this to signal a redirection The job will take care of going to that url.

void  errorPage ()

errorPage

Tell that we will only get an error page here. This means: the data you'll get isn't the data you requested, but an error page (usually HTML) that describes an error.

void  mimeType ( const QString &_type )

mimeType

Call this in mimetype, when you know the mimetype. See mimetype about other ways to implement it.

void  gettingFile ( const QString &_file )

gettingFile

void  warning ( const QString &msg )

warning

Call to signal a warning, to be displayed in a dialog box.

void  infoMessage ( const QString &msg )

infoMessage

Call to signal a message, to be displayed if the application wants to, for instance in a status bar. Usual examples are "connecting to host xyz", etc.

enum { QuestionYesNo = 1, WarningYesNo = 2, WarningContinueCancel = 3, WarningYesNoCancel = 4, Information = 5, SSLMessageBox = 6 }

int  messageBox ( int type, const QString &text, const QString &caption = QString::null, const QString &buttonYes = QString::null, const QString &buttonNo = QString::null )

messageBox

Call this to show a message box from the slave (it will in fact be handled by kio_uiserver, so that the progress info dialog for the slave is hidden while this message box is shown)

Parameters:
typetype of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel...
textMessage string. May contain newlines.
captionMessage box title.
buttonYesThe text for the first button. The default is i18n("&Yes").
buttonNoThe text for the second button. The default is i18n("&No"). Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused. and for Information, none is used.

Returns: a button code, as defined in KMessageBox, or 0 on communication error.

void  setMetaData (const QString &key, const QString &value)

setMetaData

Sets meta-data to be send to the application before the first data() or finished() signal.

bool  hasMetaData (const QString &key)

hasMetaData

Queries for the existance of a certain config/meta-data entry send by the application to the slave.

QString  metaData (const QString &key)

metaData

Queries for config/meta-data send by the application to the slave.

KConfigBase*  config ()

config

Returns a configuration object to query config/meta-data information from.

The application provides the slave with all configuration information relevant for the current protocol and host.

void  setHost (const QString& host, int port, const QString& user, const QString& pass)

setHost

[virtual]

Set the host

This method is called whenever a change in host, port or user occurs.

Parameters:
pass Called directly by createSlave, this is why there is no equivalent in SlaveInterface, unlike the other methods.

void  setSubURL (const KURL&url)

setSubURL

[virtual]

Prepare slave for streaming operation

void  openConnection ()

openConnection

[virtual]

Opens the connection (forced) When this function gets called the slave is operating in connection-oriented mode. When a connection gets lost while the slave operates in connection oriented mode, the slave should report ERR_CONNECTION_BROKEN instead of reconnecting.

void  closeConnection ()

closeConnection

[virtual]

Closes the connection (forced) Called when the application disconnects the slave to close any open network connections.

When the slave was operating in connection-oriented mode, it should reset itself to connectionless (default) mode.

void  get ( const KURL& url )

get

[virtual]

get, aka read.

Parameters:
urlthe full url for this request. Host, port and user of the URL can be assumed to be the same as in the last setHost() call. The slave emits the data through data

void  put ( const KURL& url, int permissions, bool overwrite, bool resume )

put

[virtual]

put, aka write.

Parameters:
pathwhere to write the file (decoded)
permissionsmay be -1. In this case no special permission mode is set.
overwriteif true, any existing file will be overwritten. If the file indeed already exists, the slave should NOT apply the permissions change to it.
resume

void  stat ( const KURL& url )

stat

[virtual]

Finds all details for one file or directory. The information returned is the same as what listDir returns, but only for one file or directory.

void  mimetype ( const KURL& url )

mimetype

[virtual]

Finds mimetype for one file or directory.

This method should either emit 'mimeType' or it should send a block of data big enough to be able to determine the mimetype.

If the slave doesn't reimplement it, a get will be issued, i.e. the whole file will be downloaded before determining the mimetype on it - this is obviously not a good thing in most cases.

void  listDir ( const KURL& url )

listDir

[virtual]

Lists the contents of path. The slave should emit ERR_CANNOT_ENTER_DIRECTORY if it doesn't exist, if we don't have enough permissions, or if it is a file It should also emit totalFiles as soon as it knows how many files it will list.

void  mkdir ( const KURL&url, int permissions )

mkdir

[virtual]

Create a directory

Parameters:
pathpath to the directory to create
permissionsthe permissions to set after creating the directory (-1 if no permissions to be set) The slave emits ERR_COULD_NOT_MKDIR if failure.

void  rename ( const KURL& src, const KURL& dest, bool overwrite )

rename

[virtual]

Rename oldname into newname. If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will ask for copy + del instead.

Parameters:
srcwhere to move the file from
destwhere to move the file to
overwriteif true, any existing file will be overwritten

void  symlink ( const QString& target, const KURL& dest, bool overwrite )

symlink

[virtual]

Creates a symbolic link named dest, pointing to target, which may be a relative or an absolute path.

Parameters:
targetThe string that will become the "target" of the link (can be relative)
destThe symlink to create.
overwritewhether to automatically overwrite if the dest exists

void  chmod ( const KURL& url, int permissions )

chmod

[virtual]

Change permissions on path The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD

void  copy ( const KURL &src, const KURL &dest, int permissions, bool overwrite )

copy

[virtual]

Copy src into dest. If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will ask for get + put instead.

Parameters:
srcwhere to copy the file from (decoded)
destwhere to copy the file to (decoded)
permissionsmay be -1. In this case no special permission mode is set.
overwriteif true, any existing file will be overwritten

void  del ( const KURL &url, bool isfile)

del

[virtual]

Delete a file or directory.

Parameters:
pathfile/directory to delete
isfileif true, a file should be deleted. if false, a directory should be deleted.

void  special ( const QByteArray & )

special

[virtual]

Used for any command that is specific to this slave (protocol) Examples are : HTTP POST, mount and unmount (kio_file)

Parameters:
datapacked data; the meaning is completely dependent on the slave, but usually starts with an int for the command number. Document your slave's commands, at least in its header file.

void  slave_status ()

slave_status

[virtual]

Called to get the status of the slave. Slave should respond by calling slaveStatus(...)

void  reparseConfiguration ()

reparseConfiguration

[virtual]

Called by the scheduler to tell the slave that the configuration changed (i.e. proxy settings) .

int  connectTimeout ()

connectTimeout

Returns: timeout value for connecting to remote host.

int  proxyConnectTimeout ()

proxyConnectTimeout

Returns: timeout value for connecting to proxy in secs.

int  responseTimeout ()

responseTimeout

Returns: timeout value for read from first data from remote host in seconds.

int  readTimeout ()

readTimeout

Returns: timeout value for read from subsequent data from remote host in secs.

void  sigsegv_handler (int)

sigsegv_handler

[static]

void  sigpipe_handler (int)

sigpipe_handler

[static]

bool  dispatch ()

dispatch

[virtual]

void  dispatch ( int command, const QByteArray &data )

dispatch

[virtual]

int  readData ( QByteArray &buffer )

readData

Read data send by the job, after a dataReq

Parameters:
bufferbuffer where data is stored

Returns: 0 on end of data, > 0 bytes read < 0 error

void  listEntry ( const UDSEntry& _entry, bool ready)

listEntry

[protected]

internal function to be called by the slave. It collects entries and emits them via listEntries when enough of them are there or a certain time frame exceeded (to make sure the app gets some items in time but not too many items one by one as this will cause a drastic performance penalty)

Parameters:
readyset to true after emitting all items. _entry is not used in this case

void  connectSlave (const QString& path)

connectSlave

[protected]

internal function to connect a slave to/ disconnect from either the slave pool or the application

void  disconnectSlave ()

disconnectSlave

[protected]

bool  pingCacheDaemon ()

pingCacheDaemon

[protected const]

Checks whether the password daemon kdesud is running or if it can be started if it is not.

Returns: true if password daemon is/can be started successfully.

bool  openPassDlg ( KIO::AuthInfo& info )

openPassDlg

[protected]

Prompt the user for Authrization info (login & password).

Use this function to request authorization info from the the end user. For example to open an empty password dialog using default values:


 KIO::AuthInfo authInfo;
 bool result = openPassDlg( authInfo );
 if ( result )
 {
    printf( "Username: %s", result.username.latin1() );
    printf( "Password: %s", result.password.latin1() );
 }

You can also pre-set some values like the username before hand if it is known as well as the comment and caption to be displayed:


 authInfo.comment= "Enter username and password to access acmeone";
 authInfo.caption= "Acme Password Dialog";
 authInfo.username= "Wiley E. Caiody";
 bool result = openPassDlg( authInfo );
 if ( result )
 {
    printf( "Username: %s", result.username.latin1() );
    printf( "Password: %s", result.password.latin1() );
 }

NOTE: A call to this function can also fail and result in a return value of false, if the UIServer could not be started for whatever reason.

Parameters:
SeeAuthInfo.

Returns: TRUE if user clicks on "OK", FALSE otherwsie.

bool  openPassDlg ( const QString& msg, QString& user, QString& passwd, bool lock = false )

openPassDlg

[protected]

Same as above except in the arguments it accepts.

Parameters:
msgi18n'ed message to explain the dialog box
useruser name, in and out
passpassword, in and out
lockflag used to make the username field read-only.

bool  checkCachedAuthentication ( AuthInfo& info )

checkCachedAuthentication

[protected]

Checks for cached authentication based on paramters given by info.

Use this function to check if any cached password exists for the URL given by info. If AuthInfo::realmValue is present and/or the AuthInfo::verifyPath flag is set, then they will also be factored in determining the presence of a cached password. Note that Auth::url is a required parameter when attempting to check for cached authorization info. Here is a simple example:


 AuthInfo info;
 info.url = KURL("http://www.foobar.org/foo/bar");
 info.username = "somename";
 info.verifyPath = true;
 if ( !checkCachedAuthentication( info ) )
 {
    if ( !openPassDlg(info) )
     ....
 }

If the protocol allows multiple resources within the same location to be protected by different passwords, then to determine the correct password and send pre-emtively, i.e. before the other end requires it, you can use one or both of the following methods: set the unique identifier using AuthInfo::realmValue or require that a path match be performed using AuthInfo::verifyPath.


 info.url = KURL("http://www.foobar.org/foo/bar");
 info.verifyPath = true;
 info.realmValue = "unique_identifier";

NOTE: A call to this function will fail and return false, whenever the "kdesud" could not be started for whatever reason or an invalid URL is supplied.

Parameters:
SeeAuthInfo.

Returns: TRUE if cached Authorization is found, false otherwise.

bool  checkCachedAuthentication ( const KURL& url, QString& user, QString& passwd, QString& realm, QString& extra, bool verify = true )

checkCachedAuthentication

[protected]

Same as above except in the number of arguments it accepts.

Parameters:
urlurl for which to check cached Authentication.
usercached user name.
passwcached password.
realmunique key to distinguish protection spaces (ex: HTTP Realm values)
extraextra info to store (ex: Authentication strings in Digest Authentication )
verifyif true, check new url contains cached url (== same protection space)

bool  checkCachedAuthentication ( const KURL& url, QString& user, QString& passwd)

checkCachedAuthentication

[protected]

Same as above except in the number of arguments it takes.

Parameters:
urlurl for which to check cached Authentication.
usercached user name.
passwcached password.

bool  cacheAuthentication ( const AuthInfo& info )

cacheAuthentication

[protected]

Caches authentication information in the "kdesud" deamon.

Use this function to cache correct authorization information so that you will not have to request it again from the end user. By default this info is automatically deleted if the application that cached it is shutdown properly. You can change this by setting the @AuthInfo::keepPassword flag so that the password is cached for the duration of the current KDE session or until the end-user manually clears it by stopping the "kdesud" process.

This method also allows you to cache different passwords for the same location by utilizing the AuthInfo::realmValue variable. This identifier can be any value such as the path so long as it is unique. However this function, by default, does not check whether the actual login information that is supposed to be cached is unique. Thus, if login information has previously been stored with the same key, it will simply be overwritten with this newer one. If you require the ability to cache more than one login information per server, you can override this default behavior using setMultipleAuthCaching(bool).

NOTE: A call to this function can fail and return a negative result if the "kdesud" daemon used to cache the login information is not running and cannot for whatever reason be re-started. The same is true if invalid URL is supplied since a storage key cannot be generated without it! Additionally, if the application that requested the caching of the login info terminates abnormally (ex: crashes), then the cached password will be kept for the entire duration of the current KDE session or until such time as the end-user manually stops the running "kdesud" process.

Parameters:
SeeAuthInfo.

Returns: TRUE if the authorization info was sucessfully cached.

bool  cacheAuthentication ( const KURL& url, const QString& user, const QString& passwd, const QString& realm = QString::null, const QString& extra = QString::null )

cacheAuthentication

[protected]

Same as above except in the number of arguments it takes.

Parameters:
urlurl for which Authentication is to be cached.
useruser name to be cached.
passwpassword to be cached.
realmunique key to distinguish protection spaces (ex: HTTP Realm values)
extraextra info to store (ex: Authentication strings in Digest Authentication )

Returns: true if Authentication was sucessfully cached

QString  createAuthCacheKey ( const KURL& url )

createAuthCacheKey

[protected]

Creates a basic key to be used to cache the password.

Parameters:
urlthe url from which the key is supposed to be generated

void  sendAuthenticationKey ( const QCString& gKey, const QCString& key, bool keep )

sendAuthenticationKey

[protected]

Sends the authentication key to the application.

This method informs the scheduler about the password to be cached so that it can be removed promptly when the application closes if the keep flag is not set.

Note that the reason for having and sending two keys is so that all passwords for a specific site get deleted properly. This becomes an issue when some protocols such as

Parameters:
gKeythe group id for auth-info stored
keymodified group-key based on realm value
keepindicates password should be cahed for entire KDE session or not.

void  delCachedAuthentication ( const QString& key )

delCachedAuthentication

[protected]

Delete any cached password with the given key.

To use this function simply invoke it by doing delCachedAuthentication( createAuthCacheKey(KURL) );

Parameters:
keythe cached password group-key to be deleted.

void  setMultipleAuthCaching ( bool enable )

setMultipleAuthCaching

[protected]

Setup support for multiple auth-info caching to a single server.

Calling this function with the argument set to true will allow a user to work on multiple resources located under different accounts but on the same server without being re-prompted for authorization each time. Simply put if you have a "foo" and a "bar" account on a given machine at "foobar.com" and you log into this machine using both of the accounts, then the authorization information you supplied for both accounts will be cached. This is also true if you have N number of accounts and you logged into all of them. Otherwise, the default behavior is for the latest login will simply overwrite the previous one.

Parameters:
enableif true allow multiple auth-info caching.

bool  multipleAuthCaching ()

multipleAuthCaching

[protected const]

Returns: true if multiple auth-info caching is enabled.

bool  requestNetwork (const QString& host = QString::null)

requestNetwork

[protected]

Used by the slave to check if it can connect to a given host. This should be called where the slave is ready to do a ::connect() on a socket. For each call to requestNetwork must exist a matching call to dropNetwork, or the system will stay online until KNetMgr gets closed (or the SlaveBase gets destructed)!

If KNetMgr is not running, then this is a no-op and returns true

Parameters:
hosttells the netmgr the host the slave wants to connect to. As this could also be a proxy, we can't just take the host currenctly connected to (but that's the default value)

Returns: true in theorie, the host is reachable false the system is offline and the host is in a remote network.

void  dropNetwork (const QString& host = QString::null)

dropNetwork

[protected]

Used by the slave to withdraw a connection requested by requestNetwork. This function cancels the last call to requestNetwork. If a client uses more than one internet connection, it must use dropNetwork(host) to stop each request.

If KNetMgr is not running, then this is a no-op.

A slave should call this function every time it disconnect from a host.

Parameters:
hostthe host passed to requestNetwork

int  waitForAnswer ( int expected1, int expected2, QByteArray & data, int * pCmd = 0 )

waitForAnswer

[protected]

Wait for an answer to our request, until we get expected1 or expected2

Returns: the result from readData, as well as the cmd in *pCmd if set, and the data in data

void  sendMetaData ()

sendMetaData

[protected]

Internal function to transmit meta data to the application.

QCString mProtocol

mProtocol

[protected]

Connection * m_pConnection

m_pConnection

[protected]

MetaData mOutgoingMetaData

mOutgoingMetaData

[protected]

MetaData mIncomingMetaData

mIncomingMetaData

[protected]


Generated by: dfaure on kde.faure.org on Thu Jan 17 22:16:53 2002, using kdoc 2.0a53.