TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

slavebase.h 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /*
  2. Copyright (C) 2000 David Faure <faure@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #ifndef __slavebase_h
  17. #define __slavebase_h
  18. #include <kurl.h>
  19. #include <tdeconfigbase.h>
  20. #include <tdeio/global.h>
  21. #include <tdeio/authinfo.h>
  22. class DCOPClient;
  23. class KRemoteEncoding;
  24. namespace TDEIO {
  25. class Connection;
  26. class SlaveBasePrivate;
  27. /**
  28. * There are two classes that specifies the protocol between application (job)
  29. * and tdeioslave. SlaveInterface is the class to use on the application end,
  30. * SlaveBase is the one to use on the slave end.
  31. *
  32. * Slave implementations should simply inherit SlaveBase
  33. *
  34. * A call to foo() results in a call to slotFoo() on the other end.
  35. */
  36. class TDEIO_EXPORT SlaveBase
  37. {
  38. public:
  39. SlaveBase( const TQCString &protocol, const TQCString &pool_socket, const TQCString &app_socket);
  40. virtual ~SlaveBase();
  41. /**
  42. * @internal
  43. * Terminate the slave by calling the destructor and then ::exit()
  44. */
  45. void exit();
  46. /**
  47. * @internal
  48. */
  49. void dispatchLoop();
  50. /**
  51. * @internal
  52. */
  53. void setConnection( Connection* connection ) { m_pConnection = connection; }
  54. /**
  55. * @internal
  56. */
  57. Connection *connection() const { return m_pConnection; }
  58. ///////////
  59. // Message Signals to send to the job
  60. ///////////
  61. /**
  62. * Sends data in the slave to the job (i.e. in get).
  63. *
  64. * To signal end of data, simply send an empty
  65. * TQByteArray().
  66. *
  67. * @param data the data read by the slave
  68. */
  69. void data( const TQByteArray &data );
  70. /**
  71. * Asks for data from the job.
  72. * @see readData
  73. */
  74. void dataReq( );
  75. /**
  76. * Call to signal an error.
  77. * This also finishes the job, no need to call finished.
  78. *
  79. * If the Error code is TDEIO::ERR_SLAVE_DEFINED then the
  80. * _text should contain the complete translated text of
  81. * of the error message. This message will be displayed
  82. * in an KTextBrowser which allows rich text complete
  83. * with hyper links. Email links will call the default
  84. * mailer, "exec:/command arg1 arg2" will be forked and
  85. * all other links will call the default browser.
  86. *
  87. * @see TDEIO::Error
  88. * @see KTextBrowser
  89. * @param _errid the error code from TDEIO::Error
  90. * @param _text the rich text error message
  91. */
  92. void error( int _errid, const TQString &_text );
  93. /**
  94. * Call in openConnection, if you reimplement it, when you're done.
  95. */
  96. void connected();
  97. /**
  98. * Call to signal successful completion of any command
  99. * (besides openConnection and closeConnection)
  100. */
  101. void finished();
  102. /**
  103. * Call to signal that data from the sub-URL is needed
  104. */
  105. void needSubURLData();
  106. /**
  107. * Used to report the status of the slave.
  108. * @param host the slave is currently connected to. (Should be
  109. * empty if not connected)
  110. * @param connected Whether an actual network connection exists.
  111. **/
  112. void slaveStatus(const TQString &host, bool connected);
  113. /**
  114. * Call this from stat() to express details about an object, the
  115. * UDSEntry customarily contains the atoms describing file name, size,
  116. * mimetype, etc.
  117. * @param _entry The UDSEntry containing all of the object attributes.
  118. */
  119. void statEntry( const UDSEntry& _entry );
  120. /**
  121. * Call this in listDir, each time you have a bunch of entries
  122. * to report.
  123. * @param _entry The UDSEntry containing all of the object attributes.
  124. */
  125. void listEntries( const UDSEntryList& _entry );
  126. /**
  127. * Call this at the beginning of put(), to give the size of the existing
  128. * partial file, if there is one. The @p offset argument notifies the
  129. * other job (the one that gets the data) about the offset to use.
  130. * In this case, the boolean returns whether we can indeed resume or not
  131. * (we can't if the protocol doing the get() doesn't support setting an offset)
  132. */
  133. bool canResume( TDEIO::filesize_t offset );
  134. /*
  135. * Call this at the beginning of get(), if the "resume" metadata was set
  136. * and resuming is implemented by this protocol.
  137. */
  138. void canResume();
  139. ///////////
  140. // Info Signals to send to the job
  141. ///////////
  142. /**
  143. * Call this in get and copy, to give the total size
  144. * of the file
  145. * Call in listDir too, when you know the total number of items.
  146. */
  147. void totalSize( TDEIO::filesize_t _bytes );
  148. /**
  149. * Call this during get and copy, once in a while,
  150. * to give some info about the current state.
  151. * Don't emit it in listDir, listEntries speaks for itself.
  152. */
  153. void processedSize( TDEIO::filesize_t _bytes );
  154. /**
  155. * Only use this if you can't know in advance the size of the
  156. * copied data. For example, if you're doing variable bitrate
  157. * compression of the source.
  158. *
  159. * STUB ! Currently unimplemented. Here now for binary compatibility.
  160. *
  161. * Call this during get and copy, once in a while,
  162. * to give some info about the current state.
  163. * Don't emit it in listDir, listEntries speaks for itself.
  164. */
  165. void processedPercent( float percent );
  166. /**
  167. * Call this in get and copy, to give the current transfer
  168. * speed, but only if it can't be calculated out of the size you
  169. * passed to processedSize (in most cases you don't want to call it)
  170. */
  171. void speed( unsigned long _bytes_per_second );
  172. /**
  173. * Call this to signal a redirection
  174. * The job will take care of going to that url.
  175. */
  176. void redirection( const KURL &_url );
  177. /**
  178. * Tell that we will only get an error page here.
  179. * This means: the data you'll get isn't the data you requested,
  180. * but an error page (usually HTML) that describes an error.
  181. */
  182. void errorPage();
  183. /**
  184. * Call this in mimetype() and in get(), when you know the mimetype.
  185. * See mimetype about other ways to implement it.
  186. */
  187. void mimeType( const TQString &_type );
  188. /**
  189. * Call to signal a warning, to be displayed in a dialog box.
  190. */
  191. void warning( const TQString &msg );
  192. /**
  193. * Call to signal a message, to be displayed if the application wants to,
  194. * for instance in a status bar. Usual examples are "connecting to host xyz", etc.
  195. */
  196. void infoMessage( const TQString &msg );
  197. enum MessageBoxType { QuestionYesNo = 1, WarningYesNo = 2, WarningContinueCancel = 3, WarningYesNoCancel = 4, Information = 5, SSLMessageBox = 6 };
  198. /**
  199. * Call this to show a message box from the slave
  200. * @param type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel...
  201. * @param text Message string. May contain newlines.
  202. * @param caption Message box title.
  203. * @param buttonYes The text for the first button.
  204. * The default is i18n("&Yes").
  205. * @param buttonNo The text for the second button.
  206. * The default is i18n("&No").
  207. * Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused.
  208. * and for Information, none is used.
  209. * @return a button code, as defined in KMessageBox, or 0 on communication error.
  210. */
  211. int messageBox( MessageBoxType type, const TQString &text,
  212. const TQString &caption = TQString::null,
  213. const TQString &buttonYes = TQString::null,
  214. const TQString &buttonNo = TQString::null );
  215. /**
  216. * Call this to show a message box from the slave
  217. * @param text Message string. May contain newlines.
  218. * @param type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel...
  219. * @param caption Message box title.
  220. * @param buttonYes The text for the first button.
  221. * The default is i18n("&Yes").
  222. * @param buttonNo The text for the second button.
  223. * The default is i18n("&No").
  224. * Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused.
  225. * and for Information, none is used.
  226. * @param dontAskAgainName A checkbox is added with which further confirmation can be turned off.
  227. * The string is used to lookup and store the setting in tdeioslaverc.
  228. * @return a button code, as defined in KMessageBox, or 0 on communication error.
  229. * @since 3.3
  230. */
  231. int messageBox( const TQString &text, MessageBoxType type,
  232. const TQString &caption = TQString::null,
  233. const TQString &buttonYes = TQString::null,
  234. const TQString &buttonNo = TQString::null,
  235. const TQString &dontAskAgainName = TQString::null );
  236. /**
  237. * Sets meta-data to be send to the application before the first
  238. * data() or finished() signal.
  239. */
  240. void setMetaData(const TQString &key, const TQString &value);
  241. /**
  242. * Queries for the existence of a certain config/meta-data entry
  243. * send by the application to the slave.
  244. * @since 3.2
  245. */
  246. bool hasMetaData(const TQString &key) const;
  247. /**
  248. * Queries for config/meta-data send by the application to the slave.
  249. * @since 3.2
  250. */
  251. TQString metaData(const TQString &key) const;
  252. /**
  253. * @obsolete kept for binary compatibility
  254. * Queries for the existence of a certain config/meta-data entry
  255. * send by the application to the slave.
  256. */
  257. bool hasMetaData(const TQString &key);
  258. /**
  259. * @obsolete kept for binary compatibility
  260. * Queries for config/meta-data sent by the application to the slave.
  261. */
  262. TQString metaData(const TQString &key);
  263. /**
  264. * @internal for ForwardingSlaveBase
  265. * Contains all metadata (but no config) sent by the application to the slave.
  266. * @since 3.5.2
  267. */
  268. MetaData allMetaData() const { return mIncomingMetaData; }
  269. /**
  270. * Returns a configuration object to query config/meta-data information
  271. * from.
  272. *
  273. * The application provides the slave with all configuration information
  274. * relevant for the current protocol and host.
  275. */
  276. TDEConfigBase* config();
  277. /**
  278. * Returns an object that can translate remote filenames into proper
  279. * Unicode forms. This encoding can be set by the user.
  280. *
  281. * @since 3.3
  282. */
  283. KRemoteEncoding* remoteEncoding();
  284. ///////////
  285. // Commands sent by the job, the slave has to
  286. // override what it wants to implement
  287. ///////////
  288. /**
  289. * Set the host
  290. * @param host
  291. * @param port
  292. * @param user
  293. * @param pass
  294. * Called directly by createSlave, this is why there is no equivalent in
  295. * SlaveInterface, unlike the other methods.
  296. *
  297. * This method is called whenever a change in host, port or user occurs.
  298. */
  299. virtual void setHost(const TQString& host, int port, const TQString& user, const TQString& pass);
  300. /**
  301. * Prepare slave for streaming operation
  302. */
  303. virtual void setSubURL(const KURL&url);
  304. /**
  305. * Opens the connection (forced)
  306. * When this function gets called the slave is operating in
  307. * connection-oriented mode.
  308. * When a connection gets lost while the slave operates in
  309. * connection oriented mode, the slave should report
  310. * ERR_CONNECTION_BROKEN instead of reconnecting. The user is
  311. * expected to disconnect the slave in the error handler.
  312. */
  313. virtual void openConnection();
  314. /**
  315. * Closes the connection (forced)
  316. * Called when the application disconnects the slave to close
  317. * any open network connections.
  318. *
  319. * When the slave was operating in connection-oriented mode,
  320. * it should reset itself to connectionless (default) mode.
  321. */
  322. virtual void closeConnection();
  323. /**
  324. * get, aka read.
  325. * @param url the full url for this request. Host, port and user of the URL
  326. * can be assumed to be the same as in the last setHost() call.
  327. * The slave emits the data through data
  328. */
  329. virtual void get( const KURL& url );
  330. /**
  331. * put, i.e. write data into a file.
  332. *
  333. * @param url where to write the file
  334. * @param permissions may be -1. In this case no special permission mode is set.
  335. * @param overwrite if true, any existing file will be overwritten.
  336. * If the file indeed already exists, the slave should NOT apply the
  337. * permissions change to it.
  338. * @param resume currently unused, please ignore.
  339. * The support for resuming using .part files is done by calling canResume().
  340. *
  341. * IMPORTANT: Use the "modified" metadata in order to set the modification time of the file.
  342. *
  343. * @see canResume()
  344. */
  345. virtual void put( const KURL& url, int permissions, bool overwrite, bool resume );
  346. /**
  347. * Finds all details for one file or directory.
  348. * The information returned is the same as what listDir returns,
  349. * but only for one file or directory.
  350. */
  351. virtual void stat( const KURL& url );
  352. /**
  353. * Finds mimetype for one file or directory.
  354. *
  355. * This method should either emit 'mimeType' or it
  356. * should send a block of data big enough to be able
  357. * to determine the mimetype.
  358. *
  359. * If the slave doesn't reimplement it, a get will
  360. * be issued, i.e. the whole file will be downloaded before
  361. * determining the mimetype on it - this is obviously not a
  362. * good thing in most cases.
  363. */
  364. virtual void mimetype( const KURL& url );
  365. /**
  366. * Lists the contents of @p url.
  367. * The slave should emit ERR_CANNOT_ENTER_DIRECTORY if it doesn't exist,
  368. * if we don't have enough permissions, or if it is a file
  369. * It should also emit totalFiles as soon as it knows how many
  370. * files it will list.
  371. */
  372. virtual void listDir( const KURL& url );
  373. /**
  374. * Create a directory
  375. * @param url path to the directory to create
  376. * @param permissions the permissions to set after creating the directory
  377. * (-1 if no permissions to be set)
  378. * The slave emits ERR_COULD_NOT_MKDIR if failure.
  379. */
  380. virtual void mkdir( const KURL&url, int permissions );
  381. /**
  382. * Rename @p oldname into @p newname.
  383. * If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will
  384. * ask for copy + del instead.
  385. * @param src where to move the file from
  386. * @param dest where to move the file to
  387. * @param overwrite if true, any existing file will be overwritten
  388. */
  389. virtual void rename( const KURL& src, const KURL& dest, bool overwrite );
  390. /**
  391. * Creates a symbolic link named @p dest, pointing to @p target, which
  392. * may be a relative or an absolute path.
  393. * @param target The string that will become the "target" of the link (can be relative)
  394. * @param dest The symlink to create.
  395. * @param overwrite whether to automatically overwrite if the dest exists
  396. */
  397. virtual void symlink( const TQString& target, const KURL& dest, bool overwrite );
  398. /**
  399. * Change permissions on @p path
  400. * The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD
  401. */
  402. virtual void chmod( const KURL& url, int permissions );
  403. /**
  404. * Copy @p src into @p dest.
  405. * If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will
  406. * ask for get + put instead.
  407. * @param src where to copy the file from (decoded)
  408. * @param dest where to copy the file to (decoded)
  409. * @param permissions may be -1. In this case no special permission mode is set.
  410. * @param overwrite if true, any existing file will be overwritten
  411. *
  412. */
  413. virtual void copy( const KURL &src, const KURL &dest, int permissions, bool overwrite );
  414. /**
  415. * Delete a file or directory.
  416. * @param url file/directory to delete
  417. * @param isfile if true, a file should be deleted.
  418. * if false, a directory should be deleted.
  419. */
  420. virtual void del( const KURL &url, bool isfile);
  421. // TODO KDE4: add setLinkDest() or something, to modify symlink targets.
  422. // Will be used for tdeio_file but also tdeio_remote (#97129)
  423. /**
  424. * Used for any command that is specific to this slave (protocol)
  425. * Examples are : HTTP POST, mount and unmount (tdeio_file)
  426. *
  427. * @param data packed data; the meaning is completely dependent on the
  428. * slave, but usually starts with an int for the command number.
  429. * Document your slave's commands, at least in its header file.
  430. */
  431. virtual void special( const TQByteArray & data );
  432. /**
  433. * Used for multiple get. Currently only used foir HTTP pielining
  434. * support.
  435. *
  436. * @param data packed data; Contains number of URLs to fetch, and for
  437. * each URL the URL itself and its associated MetaData.
  438. */
  439. virtual void multiGet( const TQByteArray & data );
  440. /**
  441. * Called to get the status of the slave. Slave should respond
  442. * by calling slaveStatus(...)
  443. */
  444. virtual void slave_status();
  445. /**
  446. * Called by the scheduler to tell the slave that the configuration
  447. * changed (i.e. proxy settings) .
  448. */
  449. virtual void reparseConfiguration();
  450. /**
  451. * For use with for ForwardingSlaveBase
  452. * Returns the local URL of the given remote URL if possible
  453. * @since R14.0.0
  454. */
  455. virtual void localURL( const KURL& remoteURL );
  456. /**
  457. * @return timeout value for connecting to remote host.
  458. */
  459. int connectTimeout();
  460. /**
  461. * @return timeout value for connecting to proxy in secs.
  462. */
  463. int proxyConnectTimeout();
  464. /**
  465. * @return timeout value for read from first data from
  466. * remote host in seconds.
  467. */
  468. int responseTimeout();
  469. /**
  470. * @return timeout value for read from subsequent data from
  471. * remote host in secs.
  472. */
  473. int readTimeout();
  474. /**
  475. * This function sets a timeout of @p timeout seconds and calls
  476. * special(data) when the timeout occurs as if it was called by the
  477. * application.
  478. *
  479. * A timeout can only occur when the slave is waiting for a command
  480. * from the application.
  481. *
  482. * Specifying a negative timeout cancels a pending timeout.
  483. *
  484. * Only one timeout at a time is supported, setting a timeout
  485. * cancels any pending timeout.
  486. * @since 3.1
  487. */
  488. void setTimeoutSpecialCommand(int timeout, const TQByteArray &data=TQByteArray());
  489. /**
  490. * @internal
  491. */
  492. static void sigsegv_handler(int);
  493. /**
  494. * @internal
  495. */
  496. static void sigpipe_handler(int);
  497. /////////////////
  498. // Dispatching (internal)
  499. ////////////////
  500. /**
  501. * @internal
  502. */
  503. virtual bool dispatch();
  504. /**
  505. * @internal
  506. */
  507. virtual void dispatch( int command, const TQByteArray &data );
  508. /**
  509. * Read data send by the job, after a dataReq
  510. *
  511. * @param buffer buffer where data is stored
  512. * @return 0 on end of data,
  513. * > 0 bytes read
  514. * < 0 error
  515. **/
  516. int readData( TQByteArray &buffer );
  517. /**
  518. * internal function to be called by the slave.
  519. * It collects entries and emits them via listEntries
  520. * when enough of them are there or a certain time
  521. * frame exceeded (to make sure the app gets some
  522. * items in time but not too many items one by one
  523. * as this will cause a drastic performance penalty)
  524. * @param _entry The UDSEntry containing all of the object attributes.
  525. * @param ready set to true after emitting all items. @p _entry is not
  526. * used in this case
  527. */
  528. void listEntry( const UDSEntry& _entry, bool ready);
  529. /**
  530. * internal function to connect a slave to/ disconnect from
  531. * either the slave pool or the application
  532. */
  533. void connectSlave(const TQString& path);
  534. void disconnectSlave();
  535. /**
  536. * Prompt the user for Authorization info (login & password).
  537. *
  538. * Use this function to request authorization information from
  539. * the end user. You can also pass an error message which explains
  540. * why a previous authorization attempt failed. Here is a very
  541. * simple example:
  542. *
  543. * \code
  544. * TDEIO::AuthInfo authInfo;
  545. * if ( openPassDlg( authInfo ) )
  546. * {
  547. * kdDebug() << TQString::fromLatin1("User: ")
  548. * << authInfo.username << endl;
  549. * kdDebug() << TQString::fromLatin1("Password: ")
  550. * << TQString::fromLatin1("Not displayed here!") << endl;
  551. * }
  552. * \endcode
  553. *
  554. * You can also preset some values like the username, caption or
  555. * comment as follows:
  556. *
  557. * \code
  558. * TDEIO::AuthInfo authInfo;
  559. * authInfo.caption= "Acme Password Dialog";
  560. * authInfo.username= "Wile E. Coyote";
  561. * TQString errorMsg = "You entered an incorrect password.";
  562. * if ( openPassDlg( authInfo, errorMsg ) )
  563. * {
  564. * kdDebug() << TQString::fromLatin1("User: ")
  565. * << authInfo.username << endl;
  566. * kdDebug() << TQString::fromLatin1("Password: ")
  567. * << TQString::fromLatin1("Not displayed here!") << endl;
  568. * }
  569. * \endcode
  570. *
  571. * \note You should consider using checkCachedAuthentication() to
  572. * see if the password is available in kpasswdserver before calling
  573. * this function.
  574. *
  575. * \note A call to this function can fail and return @p false,
  576. * if the UIServer could not be started for whatever reason.
  577. *
  578. * @see checkCachedAuthentication
  579. * @param info See AuthInfo.
  580. * @param errorMsg Error message to show
  581. * @return @p true if user clicks on "OK", @p false otherwsie.
  582. * @since 3.1
  583. */
  584. bool openPassDlg( TDEIO::AuthInfo& info, const TQString &errorMsg );
  585. /**
  586. * Same as above function except it does not need error message.
  587. * BIC: Combine this function with the above for KDE4.
  588. */
  589. bool openPassDlg( TDEIO::AuthInfo& info );
  590. /**
  591. * Checks for cached authentication based on parameters
  592. * given by @p info.
  593. *
  594. * Use this function to check if any cached password exists
  595. * for the URL given by @p info. If @p AuthInfo::realmValue
  596. * and/or @p AuthInfo::verifyPath flag is specified, then
  597. * they will also be factored in determining the presence
  598. * of a cached password. Note that @p Auth::url is a required
  599. * parameter when attempting to check for cached authorization
  600. * info. Here is a simple example:
  601. *
  602. * \code
  603. * AuthInfo info;
  604. * info.url = KURL("http://www.foobar.org/foo/bar");
  605. * info.username = "somename";
  606. * info.verifyPath = true;
  607. * if ( !checkCachedAuthentication( info ) )
  608. * {
  609. * if ( !openPassDlg(info) )
  610. * ....
  611. * }
  612. * \endcode
  613. *
  614. * @param info See AuthInfo.
  615. * @return @p true if cached Authorization is found, false otherwise.
  616. */
  617. bool checkCachedAuthentication( AuthInfo& info );
  618. /**
  619. * Explicitly store authentication information. openPassDlg already
  620. * stores password information automatically, you only need to call
  621. * this function if you want to store authentication information that
  622. * is different from the information returned by openPassDlg.
  623. */
  624. bool cacheAuthentication( const AuthInfo& info );
  625. /**
  626. * @obsolete as of 3.1.
  627. * TODO: Remove before KDE 4.0
  628. */
  629. bool pingCacheDaemon() const;
  630. /**
  631. * @obsolete as of 3.1. Use openPassDlg instead.
  632. * TODO: Remove before KDE 4.0
  633. * Creates a basic key to be used to cache the password.
  634. * @param url the url from which the key is supposed to be generated
  635. */
  636. TQString createAuthCacheKey( const KURL& url );
  637. /**
  638. * @obsolete as of 3.1. Use openPassDlg instead.
  639. * TODO: Remove before KDE 4.0
  640. *
  641. * Cache authentication information is now stored automatically
  642. * by openPassDlg.
  643. */
  644. void sendAuthenticationKey( const TQCString& gKey, const TQCString& key, bool keep );
  645. /**
  646. * @obsolete as of 3.1. Use openPassDlg instead.
  647. * TODO: Remove before KDE 4.0
  648. *
  649. * Cached authentication information is now session based and
  650. * removed automatically when a given session ends, i.e. the
  651. * application is closed.
  652. */
  653. void delCachedAuthentication( const TQString& key );
  654. /**
  655. * @obsolete as of 3.1. Use openPassDlg instead.
  656. * TODO: Remove before KDE 4.0
  657. */
  658. void setMultipleAuthCaching( bool ) {};
  659. /**
  660. * @obsolete as of 3.1. Use openPassDlg instead.
  661. * TODO: Remove before KDE 4.0
  662. */
  663. bool multipleAuthCaching() const { return false; }
  664. /**
  665. * Used by the slave to check if it can connect
  666. * to a given host. This should be called where the slave is ready
  667. * to do a ::connect() on a socket. For each call to
  668. * requestNetwork must exist a matching call to
  669. * dropNetwork, or the system will stay online until
  670. * KNetMgr gets closed (or the SlaveBase gets destructed)!
  671. *
  672. * If KNetMgr is not running, then this is a no-op and returns true
  673. *
  674. * @param host tells the netmgr the host the slave wants to connect
  675. * to. As this could also be a proxy, we can't just take
  676. * the host currenctly connected to (but that's the default
  677. * value)
  678. *
  679. * @return true in theorie, the host is reachable
  680. * false the system is offline and the host is in a remote network.
  681. */
  682. bool requestNetwork(const TQString& host = TQString::null);
  683. /**
  684. * Used by the slave to withdraw a connection requested by
  685. * requestNetwork. This function cancels the last call to
  686. * requestNetwork. If a client uses more than one internet
  687. * connection, it must use dropNetwork(host) to
  688. * stop each request.
  689. *
  690. * If KNetMgr is not running, then this is a no-op.
  691. *
  692. * @param host the host passed to requestNetwork
  693. *
  694. * A slave should call this function every time it disconnect from a host.
  695. * */
  696. void dropNetwork(const TQString& host = TQString::null);
  697. /**
  698. * Return the dcop client used by this slave.
  699. * @since 3.1
  700. */
  701. DCOPClient *dcopClient();
  702. /**
  703. * Wait for an answer to our request, until we get @p expected1 or @p expected2
  704. * @return the result from readData, as well as the cmd in *pCmd if set, and the data in @p data
  705. */
  706. int waitForAnswer( int expected1, int expected2, TQByteArray & data, int * pCmd = 0 );
  707. /**
  708. * Internal function to transmit meta data to the application.
  709. */
  710. void sendMetaData();
  711. /**
  712. * Name of the protocol supported by this slave
  713. */
  714. TQCString mProtocol;
  715. Connection * m_pConnection;
  716. MetaData mOutgoingMetaData;
  717. MetaData mIncomingMetaData;
  718. /** If your ioslave was killed by a signal, wasKilled() returns true.
  719. Check it regularly in lengthy functions (e.g. in get();) and return
  720. as fast as possible from this function if wasKilled() returns true.
  721. This will ensure that your slave destructor will be called correctly.
  722. @since 3.1
  723. */
  724. bool wasKilled() const;
  725. /** Internally used.
  726. * @internal
  727. * @since 3.1
  728. */
  729. void setKillFlag();
  730. protected:
  731. UDSEntryList pendingListEntries;
  732. uint listEntryCurrentSize;
  733. long listEntry_sec, listEntry_usec;
  734. Connection *appconn;
  735. TQString mPoolSocket;
  736. TQString mAppSocket;
  737. bool mConnectedToApp;
  738. static long s_seqNr;
  739. virtual void virtual_hook( int id, void* data );
  740. private:
  741. SlaveBasePrivate *d;
  742. };
  743. }
  744. #endif