• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

  • sources
  • kde-4.14
  • kdelibs
  • kio
  • kio
slavebase.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2000 Waldo Bastian <bastian@kde.org>
4  * Copyright (c) 2000 David Faure <faure@kde.org>
5  * Copyright (c) 2000 Stephan Kulow <coolo@kde.org>
6  * Copyright (c) 2007 Thiago Macieira <thiago@kde.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License version 2 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  **/
23 
24 #include "slavebase.h"
25 
26 #include <config.h>
27 
28 #include <sys/time.h>
29 
30 #include <kdebug.h>
31 #include <stdlib.h>
32 #include <errno.h>
33 #include <unistd.h>
34 #include <signal.h>
35 #include <time.h>
36 
37 #include <QtCore/QFile>
38 #include <QtCore/QList>
39 #include <QtCore/QDateTime>
40 #include <QtCore/QCoreApplication>
41 
42 #include <kcrash.h>
43 #include <kconfig.h>
44 #include <kconfiggroup.h>
45 #include <kde_file.h>
46 #include <klocale.h>
47 
48 #include "kremoteencoding.h"
49 
50 #include "connection.h"
51 #include "ioslave_defaults.h"
52 #include "slaveinterface.h"
53 #include "kpasswdserver_p.h"
54 
55 #ifndef NDEBUG
56 #ifdef HAVE_BACKTRACE
57 #include <execinfo.h>
58 #endif
59 #endif
60 
61 extern "C" {
62  static void sigsegv_handler(int sig);
63  static void sigpipe_handler(int sig);
64 }
65 
66 using namespace KIO;
67 
68 typedef QList<QByteArray> AuthKeysList;
69 typedef QMap<QString,QByteArray> AuthKeysMap;
70 #define KIO_DATA QByteArray data; QDataStream stream( &data, QIODevice::WriteOnly ); stream
71 #define KIO_FILESIZE_T(x) quint64(x)
72 
73 namespace KIO {
74 
75 class SlaveBasePrivate {
76 public:
77  SlaveBase* q;
78  SlaveBasePrivate(SlaveBase* owner): q(owner), m_passwdServer(0) {}
79  ~SlaveBasePrivate() { delete m_passwdServer; }
80 
81  UDSEntryList pendingListEntries;
82  QTime m_timeSinceLastBatch;
83  Connection appConnection;
84  QString poolSocket;
85  bool isConnectedToApp;
86  static qlonglong s_seqNr;
87 
88  QString slaveid;
89  bool resume:1;
90  bool needSendCanResume:1;
91  bool onHold:1;
92  bool wasKilled:1;
93  bool inOpenLoop:1;
94  bool exit_loop:1;
95  MetaData configData;
96  KConfig *config;
97  KConfigGroup *configGroup;
98  KUrl onHoldUrl;
99 
100  struct timeval last_tv;
101  KIO::filesize_t totalSize;
102  KIO::filesize_t sentListEntries;
103  KRemoteEncoding *remotefile;
104  time_t timeout;
105  enum { Idle, InsideMethod, FinishedCalled, ErrorCalled } m_state;
106  QByteArray timeoutData;
107 
108  KPasswdServer* m_passwdServer;
109 
110  // Reconstructs configGroup from configData and mIncomingMetaData
111  void rebuildConfig()
112  {
113  configGroup->deleteGroup(KConfigGroup::WriteConfigFlags());
114 
115  // mIncomingMetaData cascades over config, so we write config first,
116  // to let it be overwritten
117  MetaData::ConstIterator end = configData.constEnd();
118  for (MetaData::ConstIterator it = configData.constBegin(); it != end; ++it)
119  configGroup->writeEntry(it.key(), it->toUtf8(), KConfigGroup::WriteConfigFlags());
120 
121  end = q->mIncomingMetaData.constEnd();
122  for (MetaData::ConstIterator it = q->mIncomingMetaData.constBegin(); it != end; ++it)
123  configGroup->writeEntry(it.key(), it->toUtf8(), KConfigGroup::WriteConfigFlags());
124  }
125 
126  void verifyState(const char* cmdName)
127  {
128  if ((m_state != FinishedCalled) && (m_state != ErrorCalled)){
129  kWarning(7019) << cmdName << "did not call finished() or error()! Please fix the KIO slave.";
130  }
131  }
132 
133  void verifyErrorFinishedNotCalled(const char* cmdName)
134  {
135  if (m_state == FinishedCalled || m_state == ErrorCalled) {
136  kWarning(7019) << cmdName << "called finished() or error(), but it's not supposed to! Please fix the KIO slave.";
137  }
138  }
139 
140  KPasswdServer* passwdServer()
141  {
142  if (!m_passwdServer) {
143  m_passwdServer = new KPasswdServer;
144  }
145 
146  return m_passwdServer;
147  }
148 };
149 
150 }
151 
152 static SlaveBase *globalSlave;
153 qlonglong SlaveBasePrivate::s_seqNr;
154 
155 static volatile bool slaveWriteError = false;
156 
157 static const char *s_protocol;
158 
159 #ifdef Q_OS_UNIX
160 extern "C" {
161 static void genericsig_handler(int sigNumber)
162 {
163  KDE_signal(sigNumber,SIG_IGN);
164  //WABA: Don't do anything that requires malloc, we can deadlock on it since
165  //a SIGTERM signal can come in while we are in malloc/free.
166  //kDebug()<<"kioslave : exiting due to signal "<<sigNumber;
167  //set the flag which will be checked in dispatchLoop() and which *should* be checked
168  //in lengthy operations in the various slaves
169  if (globalSlave!=0)
170  globalSlave->setKillFlag();
171  KDE_signal(SIGALRM,SIG_DFL);
172  alarm(5); //generate an alarm signal in 5 seconds, in this time the slave has to exit
173 }
174 }
175 #endif
176 
178 
179 SlaveBase::SlaveBase( const QByteArray &protocol,
180  const QByteArray &pool_socket,
181  const QByteArray &app_socket )
182  : mProtocol(protocol),
183  d(new SlaveBasePrivate(this))
184 
185 {
186  d->poolSocket = QFile::decodeName(pool_socket);
187  s_protocol = protocol.data();
188 #ifdef Q_OS_UNIX
189  if (qgetenv("KDE_DEBUG").isEmpty())
190  {
191  KCrash::setCrashHandler( sigsegv_handler );
192  KDE_signal(SIGILL,&sigsegv_handler);
193  KDE_signal(SIGTRAP,&sigsegv_handler);
194  KDE_signal(SIGABRT,&sigsegv_handler);
195  KDE_signal(SIGBUS,&sigsegv_handler);
196  KDE_signal(SIGALRM,&sigsegv_handler);
197  KDE_signal(SIGFPE,&sigsegv_handler);
198 #ifdef SIGPOLL
199  KDE_signal(SIGPOLL, &sigsegv_handler);
200 #endif
201 #ifdef SIGSYS
202  KDE_signal(SIGSYS, &sigsegv_handler);
203 #endif
204 #ifdef SIGVTALRM
205  KDE_signal(SIGVTALRM, &sigsegv_handler);
206 #endif
207 #ifdef SIGXCPU
208  KDE_signal(SIGXCPU, &sigsegv_handler);
209 #endif
210 #ifdef SIGXFSZ
211  KDE_signal(SIGXFSZ, &sigsegv_handler);
212 #endif
213  }
214 
215  struct sigaction act;
216  act.sa_handler = sigpipe_handler;
217  sigemptyset( &act.sa_mask );
218  act.sa_flags = 0;
219  sigaction( SIGPIPE, &act, 0 );
220 
221  KDE_signal(SIGINT,&genericsig_handler);
222  KDE_signal(SIGQUIT,&genericsig_handler);
223  KDE_signal(SIGTERM,&genericsig_handler);
224 #endif
225 
226  globalSlave=this;
227 
228  d->isConnectedToApp = true;
229 
230  // by kahl for netmgr (need a way to identify slaves)
231  d->slaveid = protocol;
232  d->slaveid += QString::number(getpid());
233  d->resume = false;
234  d->needSendCanResume = false;
235  d->config = new KConfig(QString(), KConfig::SimpleConfig);
236  // The KConfigGroup needs the KConfig to exist during its whole lifetime.
237  d->configGroup = new KConfigGroup(d->config, QString());
238  d->onHold = false;
239  d->wasKilled=false;
240  d->last_tv.tv_sec = 0;
241  d->last_tv.tv_usec = 0;
242 // d->processed_size = 0;
243  d->totalSize=0;
244  d->sentListEntries=0;
245  d->timeout = 0;
246  connectSlave(QFile::decodeName(app_socket));
247 
248  d->remotefile = 0;
249  d->inOpenLoop = false;
250  d->exit_loop = false;
251 }
252 
253 SlaveBase::~SlaveBase()
254 {
255  delete d->configGroup;
256  delete d->config;
257  delete d->remotefile;
258  delete d;
259  s_protocol = "";
260 }
261 
262 void SlaveBase::dispatchLoop()
263 {
264  while (!d->exit_loop) {
265  if (d->timeout && (d->timeout < time(0))) {
266  QByteArray data = d->timeoutData;
267  d->timeout = 0;
268  d->timeoutData = QByteArray();
269  special(data);
270  }
271 
272  Q_ASSERT(d->appConnection.inited());
273 
274  int ms = -1;
275  if (d->timeout)
276  ms = 1000 * qMax<time_t>(d->timeout - time(0), 1);
277 
278  int ret = -1;
279  if (d->appConnection.hasTaskAvailable() || d->appConnection.waitForIncomingTask(ms)) {
280  // dispatch application messages
281  int cmd;
282  QByteArray data;
283  ret = d->appConnection.read(&cmd, data);
284 
285  if (ret != -1) {
286  if (d->inOpenLoop)
287  dispatchOpenCommand(cmd, data);
288  else
289  dispatch(cmd, data);
290  }
291  } else {
292  ret = d->appConnection.isConnected() ? 0 : -1;
293  }
294 
295  if (ret == -1) { // some error occurred, perhaps no more application
296  // When the app exits, should the slave be put back in the pool ?
297  if (!d->exit_loop && d->isConnectedToApp && !d->poolSocket.isEmpty()) {
298  disconnectSlave();
299  d->isConnectedToApp = false;
300  closeConnection();
301  connectSlave(d->poolSocket);
302  } else {
303  break;
304  }
305  }
306 
307  //I think we get here when we were killed in dispatch() and not in select()
308  if (wasKilled()) {
309  kDebug(7019) << "slave was killed, returning";
310  break;
311  }
312 
313  // execute deferred deletes
314  QCoreApplication::sendPostedEvents(NULL, QEvent::DeferredDelete);
315  }
316 
317  // execute deferred deletes
318  QCoreApplication::sendPostedEvents(NULL, QEvent::DeferredDelete);
319 }
320 
321 void SlaveBase::connectSlave(const QString &address)
322 {
323  d->appConnection.connectToRemote(address);
324 
325  if (!d->appConnection.inited())
326  {
327  kDebug(7019) << "failed to connect to" << address << endl
328  << "Reason:" << d->appConnection.errorString();
329  exit();
330  return;
331  }
332 
333  d->inOpenLoop = false;
334 }
335 
336 void SlaveBase::disconnectSlave()
337 {
338  d->appConnection.close();
339 }
340 
341 void SlaveBase::setMetaData(const QString &key, const QString &value)
342 {
343  mOutgoingMetaData.insert(key, value); // replaces existing key if already there
344 }
345 
346 QString SlaveBase::metaData(const QString &key) const
347 {
348  if (mIncomingMetaData.contains(key))
349  return mIncomingMetaData[key];
350  if (d->configData.contains(key))
351  return d->configData[key];
352  return QString();
353 }
354 
355 MetaData SlaveBase::allMetaData() const
356 {
357  return mIncomingMetaData;
358 }
359 
360 bool SlaveBase::hasMetaData(const QString &key) const
361 {
362  if (mIncomingMetaData.contains(key))
363  return true;
364  if (d->configData.contains(key))
365  return true;
366  return false;
367 }
368 
369 KConfigGroup *SlaveBase::config()
370 {
371  return d->configGroup;
372 }
373 
374 void SlaveBase::sendMetaData()
375 {
376  sendAndKeepMetaData();
377  mOutgoingMetaData.clear();
378 }
379 
380 void SlaveBase::sendAndKeepMetaData()
381 {
382  if (!mOutgoingMetaData.isEmpty()) {
383  KIO_DATA << mOutgoingMetaData;
384 
385  send(INF_META_DATA, data);
386  }
387 }
388 
389 KRemoteEncoding *SlaveBase::remoteEncoding()
390 {
391  if (d->remotefile)
392  return d->remotefile;
393 
394  const QByteArray charset (metaData(QLatin1String("Charset")).toLatin1());
395  return (d->remotefile = new KRemoteEncoding( charset ));
396 }
397 
398 void SlaveBase::data( const QByteArray &data )
399 {
400  sendMetaData();
401  send( MSG_DATA, data );
402 }
403 
404 void SlaveBase::dataReq( )
405 {
406  //sendMetaData();
407  if (d->needSendCanResume)
408  canResume(0);
409  send( MSG_DATA_REQ );
410 }
411 
412 void SlaveBase::opened()
413 {
414  sendMetaData();
415  send( MSG_OPENED );
416  d->inOpenLoop = true;
417 }
418 
419 void SlaveBase::error( int _errid, const QString &_text )
420 {
421  if (d->m_state == d->ErrorCalled) {
422  kWarning(7019) << "error() called twice! Please fix the KIO slave.";
423  return;
424  } else if (d->m_state == d->FinishedCalled) {
425  kWarning(7019) << "error() called after finished()! Please fix the KIO slave.";
426  return;
427  }
428 
429  d->m_state = d->ErrorCalled;
430  mIncomingMetaData.clear(); // Clear meta data
431  d->rebuildConfig();
432  mOutgoingMetaData.clear();
433  KIO_DATA << (qint32) _errid << _text;
434 
435  send( MSG_ERROR, data );
436  //reset
437  d->sentListEntries=0;
438  d->totalSize=0;
439  d->inOpenLoop=false;
440 }
441 
442 void SlaveBase::connected()
443 {
444  send( MSG_CONNECTED );
445 }
446 
447 void SlaveBase::finished()
448 {
449  if (d->m_state == d->FinishedCalled) {
450  kWarning(7019) << "finished() called twice! Please fix the KIO slave.";
451  return;
452  } else if (d->m_state == d->ErrorCalled) {
453  kWarning(7019) << "finished() called after error()! Please fix the KIO slave.";
454  return;
455  }
456 
457  d->m_state = d->FinishedCalled;
458  mIncomingMetaData.clear(); // Clear meta data
459  d->rebuildConfig();
460  sendMetaData();
461  send( MSG_FINISHED );
462 
463  // reset
464  d->sentListEntries=0;
465  d->totalSize=0;
466  d->inOpenLoop=false;
467 }
468 
469 void SlaveBase::needSubUrlData()
470 {
471  send( MSG_NEED_SUBURL_DATA );
472 }
473 
474 /*
475  * Map pid_t to a signed integer type that makes sense for QByteArray;
476  * only the most common sizes 16 bit and 32 bit are special-cased.
477  */
478 template<int T> struct PIDType { typedef pid_t PID_t; } ;
479 template<> struct PIDType<2> { typedef qint16 PID_t; } ;
480 template<> struct PIDType<4> { typedef qint32 PID_t; } ;
481 
482 void SlaveBase::slaveStatus( const QString &host, bool connected )
483 {
484  pid_t pid = getpid();
485  qint8 b = connected ? 1 : 0;
486  KIO_DATA << (PIDType<sizeof(pid_t)>::PID_t)pid << mProtocol << host << b;
487  if (d->onHold)
488  stream << d->onHoldUrl;
489  send( MSG_SLAVE_STATUS, data );
490 }
491 
492 void SlaveBase::canResume()
493 {
494  send( MSG_CANRESUME );
495 }
496 
497 void SlaveBase::totalSize( KIO::filesize_t _bytes )
498 {
499  KIO_DATA << KIO_FILESIZE_T(_bytes);
500  send( INF_TOTAL_SIZE, data );
501 
502  //this one is usually called before the first item is listed in listDir()
503  d->totalSize=_bytes;
504  d->sentListEntries=0;
505 }
506 
507 void SlaveBase::processedSize( KIO::filesize_t _bytes )
508 {
509  bool emitSignal=false;
510  struct timeval tv;
511  int gettimeofday_res=gettimeofday( &tv, 0L );
512 
513  if( _bytes == d->totalSize )
514  emitSignal=true;
515  else if ( gettimeofday_res == 0 ) {
516  time_t msecdiff = 2000;
517  if (d->last_tv.tv_sec) {
518  // Compute difference, in ms
519  msecdiff = 1000 * ( tv.tv_sec - d->last_tv.tv_sec );
520  time_t usecdiff = tv.tv_usec - d->last_tv.tv_usec;
521  if ( usecdiff < 0 ) {
522  msecdiff--;
523  msecdiff += 1000;
524  }
525  msecdiff += usecdiff / 1000;
526  }
527  emitSignal=msecdiff >= 100; // emit size 10 times a second
528  }
529 
530  if( emitSignal ) {
531  KIO_DATA << KIO_FILESIZE_T(_bytes);
532  send( INF_PROCESSED_SIZE, data );
533  if ( gettimeofday_res == 0 ) {
534  d->last_tv.tv_sec = tv.tv_sec;
535  d->last_tv.tv_usec = tv.tv_usec;
536  }
537  }
538 // d->processed_size = _bytes;
539 }
540 
541 void SlaveBase::written( KIO::filesize_t _bytes )
542 {
543  KIO_DATA << KIO_FILESIZE_T(_bytes);
544  send( MSG_WRITTEN, data );
545 }
546 
547 void SlaveBase::position( KIO::filesize_t _pos )
548 {
549  KIO_DATA << KIO_FILESIZE_T(_pos);
550  send( INF_POSITION, data );
551 }
552 
553 void SlaveBase::processedPercent( float /* percent */ )
554 {
555  kDebug(7019) << "STUB";
556 }
557 
558 
559 void SlaveBase::speed( unsigned long _bytes_per_second )
560 {
561  KIO_DATA << (quint32) _bytes_per_second;
562  send( INF_SPEED, data );
563 }
564 
565 void SlaveBase::redirection( const KUrl& _url )
566 {
567  KIO_DATA << _url;
568  send( INF_REDIRECTION, data );
569 }
570 
571 void SlaveBase::errorPage()
572 {
573  send( INF_ERROR_PAGE );
574 }
575 
576 static bool isSubCommand(int cmd)
577 {
578  return ( (cmd == CMD_REPARSECONFIGURATION) ||
579  (cmd == CMD_META_DATA) ||
580  (cmd == CMD_CONFIG) ||
581  (cmd == CMD_SUBURL) ||
582  (cmd == CMD_SLAVE_STATUS) ||
583  (cmd == CMD_SLAVE_CONNECT) ||
584  (cmd == CMD_SLAVE_HOLD) ||
585  (cmd == CMD_MULTI_GET));
586 }
587 
588 void SlaveBase::mimeType( const QString &_type)
589 {
590  kDebug(7019) << _type;
591  int cmd;
592  do
593  {
594  // Send the meta-data each time we send the mime-type.
595  if (!mOutgoingMetaData.isEmpty())
596  {
597  // kDebug(7019) << "emitting meta data";
598  KIO_DATA << mOutgoingMetaData;
599  send( INF_META_DATA, data );
600  }
601  KIO_DATA << _type;
602  send( INF_MIME_TYPE, data );
603  while(true)
604  {
605  cmd = 0;
606  int ret = -1;
607  if (d->appConnection.hasTaskAvailable() || d->appConnection.waitForIncomingTask(-1)) {
608  ret = d->appConnection.read( &cmd, data );
609  }
610  if (ret == -1) {
611  kDebug(7019) << "read error";
612  exit();
613  return;
614  }
615  // kDebug(7019) << "got" << cmd;
616  if ( cmd == CMD_HOST) // Ignore.
617  continue;
618  if (!isSubCommand(cmd))
619  break;
620 
621  dispatch( cmd, data );
622  }
623  }
624  while (cmd != CMD_NONE);
625  mOutgoingMetaData.clear();
626 }
627 
628 void SlaveBase::exit()
629 {
630  d->exit_loop = true;
631  // Using ::exit() here is too much (crashes in qdbus's qglobalstatic object),
632  // so let's cleanly exit dispatchLoop() instead.
633  // Update: we do need to call exit(), otherwise a long download (get()) would
634  // keep going until it ends, even though the application exited.
635  ::exit(255);
636 }
637 
638 void SlaveBase::warning( const QString &_msg)
639 {
640  KIO_DATA << _msg;
641  send( INF_WARNING, data );
642 }
643 
644 void SlaveBase::infoMessage( const QString &_msg)
645 {
646  KIO_DATA << _msg;
647  send( INF_INFOMESSAGE, data );
648 }
649 
650 bool SlaveBase::requestNetwork(const QString& host)
651 {
652  KIO_DATA << host << d->slaveid;
653  send( MSG_NET_REQUEST, data );
654 
655  if ( waitForAnswer( INF_NETWORK_STATUS, 0, data ) != -1 )
656  {
657  bool status;
658  QDataStream stream( data );
659  stream >> status;
660  return status;
661  } else
662  return false;
663 }
664 
665 void SlaveBase::dropNetwork(const QString& host)
666 {
667  KIO_DATA << host << d->slaveid;
668  send( MSG_NET_DROP, data );
669 }
670 
671 void SlaveBase::statEntry( const UDSEntry& entry )
672 {
673  KIO_DATA << entry;
674  send( MSG_STAT_ENTRY, data );
675 }
676 
677 void SlaveBase::listEntry( const UDSEntry& entry, bool _ready )
678 {
679  static const int maximum_updatetime = 300;
680 
681  // We start measuring the time from the point we start filling the list
682  if (d->pendingListEntries.isEmpty()) {
683  d->m_timeSinceLastBatch.restart();
684  }
685 
686  if (!_ready) {
687  d->pendingListEntries.append(entry);
688 
689  // If more then maximum_updatetime time is passed, emit the current batch
690  if (d->m_timeSinceLastBatch.elapsed() > maximum_updatetime) {
691  _ready = true;
692  }
693  }
694 
695  if (_ready) { // may happen when we started with !ready
696  listEntries( d->pendingListEntries );
697  d->pendingListEntries.clear();
698 
699  // Restart time
700  d->m_timeSinceLastBatch.restart();
701  }
702 }
703 
704 void SlaveBase::listEntries( const UDSEntryList& list )
705 {
706  KIO_DATA << (quint32)list.count();
707  UDSEntryList::ConstIterator it = list.begin();
708  const UDSEntryList::ConstIterator end = list.end();
709  for (; it != end; ++it)
710  stream << *it;
711  send( MSG_LIST_ENTRIES, data);
712  d->sentListEntries+=(uint)list.count();
713 }
714 
715 static void sigsegv_handler(int sig)
716 {
717 #ifdef Q_OS_UNIX
718  KDE_signal(sig,SIG_DFL); // Next one kills
719 
720  //Kill us if we deadlock
721  KDE_signal(SIGALRM,SIG_DFL);
722  alarm(5); //generate an alarm signal in 5 seconds, in this time the slave has to exit
723 
724  // Debug and printf should be avoided because they might
725  // call malloc.. and get in a nice recursive malloc loop
726  char buffer[120];
727  qsnprintf(buffer, sizeof(buffer), "kioslave: ####### CRASH ###### protocol = %s pid = %d signal = %d\n", s_protocol, getpid(), sig);
728  write(2, buffer, strlen(buffer));
729 #ifndef NDEBUG
730 #ifdef HAVE_BACKTRACE
731  void* trace[256];
732  int n = backtrace(trace, 256);
733  if (n)
734  backtrace_symbols_fd(trace, n, 2);
735 #endif
736 #endif
737  ::exit(1);
738 #endif
739 }
740 
741 static void sigpipe_handler (int)
742 {
743  // We ignore a SIGPIPE in slaves.
744  // A SIGPIPE can happen in two cases:
745  // 1) Communication error with application.
746  // 2) Communication error with network.
747  slaveWriteError = true;
748 
749  // Don't add anything else here, especially no debug output
750 }
751 
752 void SlaveBase::setHost(QString const &, quint16, QString const &, QString const &)
753 {
754 }
755 
756 void SlaveBase::openConnection(void)
757 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_CONNECT)); }
758 void SlaveBase::closeConnection(void)
759 { } // No response!
760 void SlaveBase::stat(KUrl const &)
761 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_STAT)); }
762 void SlaveBase::put(KUrl const &, int, JobFlags )
763 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_PUT)); }
764 void SlaveBase::special(const QByteArray &)
765 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_SPECIAL)); }
766 void SlaveBase::listDir(KUrl const &)
767 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_LISTDIR)); }
768 void SlaveBase::get(KUrl const & )
769 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_GET)); }
770 void SlaveBase::open(KUrl const &, QIODevice::OpenMode)
771 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_OPEN)); }
772 void SlaveBase::read(KIO::filesize_t)
773 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_READ)); }
774 void SlaveBase::write(const QByteArray &)
775 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_WRITE)); }
776 void SlaveBase::seek(KIO::filesize_t)
777 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_SEEK)); }
778 void SlaveBase::close()
779 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_CLOSE)); }
780 void SlaveBase::mimetype(KUrl const &url)
781 { get(url); }
782 void SlaveBase::rename(KUrl const &, KUrl const &, JobFlags)
783 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_RENAME)); }
784 void SlaveBase::symlink(QString const &, KUrl const &, JobFlags)
785 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_SYMLINK)); }
786 void SlaveBase::copy(KUrl const &, KUrl const &, int, JobFlags)
787 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_COPY)); }
788 void SlaveBase::del(KUrl const &, bool)
789 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_DEL)); }
790 void SlaveBase::setLinkDest(const KUrl &, const QString&)
791 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_SETLINKDEST)); }
792 void SlaveBase::mkdir(KUrl const &, int)
793 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_MKDIR)); }
794 void SlaveBase::chmod(KUrl const &, int)
795 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_CHMOD)); }
796 void SlaveBase::setModificationTime(KUrl const &, const QDateTime&)
797 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_SETMODIFICATIONTIME)); }
798 void SlaveBase::chown(KUrl const &, const QString &, const QString &)
799 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_CHOWN)); }
800 void SlaveBase::setSubUrl(KUrl const &)
801 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_SUBURL)); }
802 void SlaveBase::multiGet(const QByteArray &)
803 { error( ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(mProtocol, CMD_MULTI_GET)); }
804 
805 
806 void SlaveBase::slave_status()
807 { slaveStatus( QString(), false ); }
808 
809 void SlaveBase::reparseConfiguration()
810 {
811  delete d->remotefile;
812  d->remotefile = 0;
813 }
814 
815 bool SlaveBase::openPasswordDialog( AuthInfo& info, const QString &errorMsg )
816 {
817  const long windowId = metaData(QLatin1String("window-id")).toLong();
818  const unsigned long userTimestamp = metaData(QLatin1String("user-timestamp")).toULong();
819  QString errorMessage;
820  if (metaData(QLatin1String("no-auth-prompt")).compare(QLatin1String("true"), Qt::CaseInsensitive) == 0) {
821  errorMessage = QLatin1String("<NoAuthPrompt>");
822  } else {
823  errorMessage = errorMsg;
824  }
825 
826  AuthInfo dlgInfo (info);
827  // Make sure the modified flag is not set.
828  dlgInfo.setModified(false);
829  // Prevent queryAuthInfo from caching the user supplied password since
830  // we need the ioslaves to first authenticate against the server with
831  // it to ensure it is valid.
832  dlgInfo.setExtraField(QLatin1String("skip-caching-on-query"), true);
833 
834  KPasswdServer* passwdServer = d->passwdServer();
835 
836  if (passwdServer) {
837  qlonglong seqNr = passwdServer->queryAuthInfo(dlgInfo, errorMessage, windowId,
838  SlaveBasePrivate::s_seqNr, userTimestamp);
839  if (seqNr > 0) {
840  SlaveBasePrivate::s_seqNr = seqNr;
841  if (dlgInfo.isModified()) {
842  info = dlgInfo;
843  return true;
844  }
845  }
846  }
847 
848  return false;
849 }
850 
851 int SlaveBase::messageBox( MessageBoxType type, const QString &text, const QString &caption,
852  const QString &buttonYes, const QString &buttonNo )
853 {
854  return messageBox( text, type, caption, buttonYes, buttonNo, QString() );
855 }
856 
857 int SlaveBase::messageBox( const QString &text, MessageBoxType type, const QString &caption,
858  const QString &buttonYes, const QString &buttonNo,
859  const QString &dontAskAgainName )
860 {
861  kDebug(7019) << "messageBox " << type << " " << text << " - " << caption << buttonYes << buttonNo;
862  KIO_DATA << (qint32)type << text << caption << buttonYes << buttonNo << dontAskAgainName;
863  send( INF_MESSAGEBOX, data );
864  if ( waitForAnswer( CMD_MESSAGEBOXANSWER, 0, data ) != -1 )
865  {
866  QDataStream stream( data );
867  int answer;
868  stream >> answer;
869  kDebug(7019) << "got messagebox answer" << answer;
870  return answer;
871  } else
872  return 0; // communication failure
873 }
874 
875 bool SlaveBase::canResume( KIO::filesize_t offset )
876 {
877  kDebug(7019) << "offset=" << KIO::number(offset);
878  d->needSendCanResume = false;
879  KIO_DATA << KIO_FILESIZE_T(offset);
880  send( MSG_RESUME, data );
881  if ( offset )
882  {
883  int cmd;
884  if ( waitForAnswer( CMD_RESUMEANSWER, CMD_NONE, data, &cmd ) != -1 )
885  {
886  kDebug(7019) << "returning" << (cmd == CMD_RESUMEANSWER);
887  return cmd == CMD_RESUMEANSWER;
888  } else
889  return false;
890  }
891  else // No resuming possible -> no answer to wait for
892  return true;
893 }
894 
895 
896 
897 int SlaveBase::waitForAnswer( int expected1, int expected2, QByteArray & data, int *pCmd )
898 {
899  int cmd, result = -1;
900  for (;;)
901  {
902  if (d->appConnection.hasTaskAvailable() || d->appConnection.waitForIncomingTask(-1)) {
903  result = d->appConnection.read( &cmd, data );
904  }
905  if (result == -1) {
906  kDebug(7019) << "read error.";
907  return -1;
908  }
909 
910  if ( cmd == expected1 || cmd == expected2 )
911  {
912  if ( pCmd ) *pCmd = cmd;
913  return result;
914  }
915  if ( isSubCommand(cmd) )
916  {
917  dispatch( cmd, data );
918  }
919  else
920  {
921  kFatal(7019) << "Got cmd " << cmd << " while waiting for an answer!";
922  }
923  }
924 }
925 
926 
927 int SlaveBase::readData( QByteArray &buffer)
928 {
929  int result = waitForAnswer( MSG_DATA, 0, buffer );
930  //kDebug(7019) << "readData: length = " << result << " ";
931  return result;
932 }
933 
934 void SlaveBase::setTimeoutSpecialCommand(int timeout, const QByteArray &data)
935 {
936  if (timeout > 0)
937  d->timeout = time(0)+(time_t)timeout;
938  else if (timeout == 0)
939  d->timeout = 1; // Immediate timeout
940  else
941  d->timeout = 0; // Canceled
942 
943  d->timeoutData = data;
944 }
945 
946 void SlaveBase::dispatch( int command, const QByteArray &data )
947 {
948  QDataStream stream( data );
949 
950  KUrl url;
951  int i;
952 
953  switch( command ) {
954  case CMD_HOST: {
955  // Reset s_seqNr, see kpasswdserver/DESIGN
956  SlaveBasePrivate::s_seqNr = 0;
957  QString passwd;
958  QString host, user;
959  quint16 port;
960  stream >> host >> port >> user >> passwd;
961  d->m_state = d->InsideMethod;
962  setHost( host, port, user, passwd );
963  d->verifyErrorFinishedNotCalled("setHost()");
964  d->m_state = d->Idle;
965  } break;
966  case CMD_CONNECT: {
967  openConnection( );
968  } break;
969  case CMD_DISCONNECT: {
970  closeConnection( );
971  } break;
972  case CMD_SLAVE_STATUS: {
973  d->m_state = d->InsideMethod;
974  slave_status();
975  // TODO verify that the slave has called slaveStatus()?
976  d->verifyErrorFinishedNotCalled("slave_status()");
977  d->m_state = d->Idle;
978  } break;
979  case CMD_SLAVE_CONNECT: {
980  d->onHold = false;
981  QString app_socket;
982  QDataStream stream( data );
983  stream >> app_socket;
984  d->appConnection.send( MSG_SLAVE_ACK );
985  disconnectSlave();
986  d->isConnectedToApp = true;
987  connectSlave(app_socket);
988  virtual_hook(AppConnectionMade, 0);
989  } break;
990  case CMD_SLAVE_HOLD: {
991  KUrl url;
992  QDataStream stream( data );
993  stream >> url;
994  d->onHoldUrl = url;
995  d->onHold = true;
996  disconnectSlave();
997  d->isConnectedToApp = false;
998  // Do not close connection!
999  connectSlave(d->poolSocket);
1000  } break;
1001  case CMD_REPARSECONFIGURATION: {
1002  d->m_state = d->InsideMethod;
1003  reparseConfiguration();
1004  d->verifyErrorFinishedNotCalled("reparseConfiguration()");
1005  d->m_state = d->Idle;
1006  } break;
1007  case CMD_CONFIG: {
1008  stream >> d->configData;
1009  d->rebuildConfig();
1010 #if 0 //TODO: decide what to do in KDE 4.1
1011  KSocks::setConfig(d->configGroup);
1012 #endif
1013  delete d->remotefile;
1014  d->remotefile = 0;
1015  } break;
1016  case CMD_GET: {
1017  stream >> url;
1018  d->m_state = d->InsideMethod;
1019  get( url );
1020  d->verifyState("get()");
1021  d->m_state = d->Idle;
1022  } break;
1023  case CMD_OPEN: {
1024  stream >> url >> i;
1025  QIODevice::OpenMode mode = QFlag(i);
1026  d->m_state = d->InsideMethod;
1027  open(url, mode); //krazy:exclude=syscalls
1028  d->m_state = d->Idle;
1029  } break;
1030  case CMD_PUT: {
1031  int permissions;
1032  qint8 iOverwrite, iResume;
1033  stream >> url >> iOverwrite >> iResume >> permissions;
1034  JobFlags flags;
1035  if ( iOverwrite != 0 ) flags |= Overwrite;
1036  if ( iResume != 0 ) flags |= Resume;
1037 
1038  // Remember that we need to send canResume(), TransferJob is expecting
1039  // it. Well, in theory this shouldn't be done if resume is true.
1040  // (the resume bool is currently unused)
1041  d->needSendCanResume = true /* !resume */;
1042 
1043  d->m_state = d->InsideMethod;
1044  put( url, permissions, flags);
1045  d->verifyState("put()");
1046  d->m_state = d->Idle;
1047  } break;
1048  case CMD_STAT: {
1049  stream >> url;
1050  d->m_state = d->InsideMethod;
1051  stat( url ); //krazy:exclude=syscalls
1052  d->verifyState("stat()");
1053  d->m_state = d->Idle;
1054  } break;
1055  case CMD_MIMETYPE: {
1056  stream >> url;
1057  d->m_state = d->InsideMethod;
1058  mimetype( url );
1059  d->verifyState("mimetype()");
1060  d->m_state = d->Idle;
1061  } break;
1062  case CMD_LISTDIR: {
1063  stream >> url;
1064  d->m_state = d->InsideMethod;
1065  listDir( url );
1066  d->verifyState("listDir()");
1067  d->m_state = d->Idle;
1068  } break;
1069  case CMD_MKDIR: {
1070  stream >> url >> i;
1071  d->m_state = d->InsideMethod;
1072  mkdir( url, i ); //krazy:exclude=syscalls
1073  d->verifyState("mkdir()");
1074  d->m_state = d->Idle;
1075  } break;
1076  case CMD_RENAME: {
1077  qint8 iOverwrite;
1078  KUrl url2;
1079  stream >> url >> url2 >> iOverwrite;
1080  JobFlags flags;
1081  if ( iOverwrite != 0 ) flags |= Overwrite;
1082  d->m_state = d->InsideMethod;
1083  rename( url, url2, flags ); //krazy:exclude=syscalls
1084  d->verifyState("rename()");
1085  d->m_state = d->Idle;
1086  } break;
1087  case CMD_SYMLINK: {
1088  qint8 iOverwrite;
1089  QString target;
1090  stream >> target >> url >> iOverwrite;
1091  JobFlags flags;
1092  if ( iOverwrite != 0 ) flags |= Overwrite;
1093  d->m_state = d->InsideMethod;
1094  symlink( target, url, flags );
1095  d->verifyState("symlink()");
1096  d->m_state = d->Idle;
1097  } break;
1098  case CMD_COPY: {
1099  int permissions;
1100  qint8 iOverwrite;
1101  KUrl url2;
1102  stream >> url >> url2 >> permissions >> iOverwrite;
1103  JobFlags flags;
1104  if ( iOverwrite != 0 ) flags |= Overwrite;
1105  d->m_state = d->InsideMethod;
1106  copy( url, url2, permissions, flags );
1107  d->verifyState("copy()");
1108  d->m_state = d->Idle;
1109  } break;
1110  case CMD_DEL: {
1111  qint8 isFile;
1112  stream >> url >> isFile;
1113  d->m_state = d->InsideMethod;
1114  del( url, isFile != 0);
1115  d->verifyState("del()");
1116  d->m_state = d->Idle;
1117  } break;
1118  case CMD_CHMOD: {
1119  stream >> url >> i;
1120  d->m_state = d->InsideMethod;
1121  chmod( url, i);
1122  d->verifyState("chmod()");
1123  d->m_state = d->Idle;
1124  } break;
1125  case CMD_CHOWN: {
1126  QString owner, group;
1127  stream >> url >> owner >> group;
1128  d->m_state = d->InsideMethod;
1129  chown(url, owner, group);
1130  d->verifyState("chown()");
1131  d->m_state = d->Idle;
1132  } break;
1133  case CMD_SETMODIFICATIONTIME: {
1134  QDateTime dt;
1135  stream >> url >> dt;
1136  d->m_state = d->InsideMethod;
1137  setModificationTime(url, dt);
1138  d->verifyState("setModificationTime()");
1139  d->m_state = d->Idle;
1140  } break;
1141  case CMD_SPECIAL: {
1142  d->m_state = d->InsideMethod;
1143  special( data );
1144  d->verifyState("special()");
1145  d->m_state = d->Idle;
1146  } break;
1147  case CMD_META_DATA: {
1148  //kDebug(7019) << "(" << getpid() << ") Incoming meta-data...";
1149  stream >> mIncomingMetaData;
1150  d->rebuildConfig();
1151  } break;
1152  case CMD_SUBURL: {
1153  stream >> url;
1154  d->m_state = d->InsideMethod;
1155  setSubUrl(url);
1156  d->verifyErrorFinishedNotCalled("setSubUrl()");
1157  d->m_state = d->Idle;
1158  } break;
1159  case CMD_NONE: {
1160  kWarning(7019) << "Got unexpected CMD_NONE!";
1161  } break;
1162  case CMD_MULTI_GET: {
1163  d->m_state = d->InsideMethod;
1164  multiGet( data );
1165  d->verifyState("multiGet()");
1166  d->m_state = d->Idle;
1167  } break;
1168  default: {
1169  // Some command we don't understand.
1170  // Just ignore it, it may come from some future version of KDE.
1171  } break;
1172  }
1173 }
1174 
1175 bool SlaveBase::checkCachedAuthentication( AuthInfo& info )
1176 {
1177  KPasswdServer* passwdServer = d->passwdServer();
1178  return (passwdServer &&
1179  passwdServer->checkAuthInfo(info, metaData(QLatin1String("window-id")).toLong(),
1180  metaData(QLatin1String("user-timestamp")).toULong()));
1181 }
1182 
1183 void SlaveBase::dispatchOpenCommand( int command, const QByteArray &data )
1184 {
1185  QDataStream stream( data );
1186 
1187  switch( command ) {
1188  case CMD_READ: {
1189  KIO::filesize_t bytes;
1190  stream >> bytes;
1191  read(bytes);
1192  break;
1193  }
1194  case CMD_WRITE: {
1195  write(data);
1196  break;
1197  }
1198  case CMD_SEEK: {
1199  KIO::filesize_t offset;
1200  stream >> offset;
1201  seek(offset);
1202  }
1203  case CMD_NONE:
1204  break;
1205  case CMD_CLOSE:
1206  close(); // must call finish(), which will set d->inOpenLoop=false
1207  break;
1208  default:
1209  // Some command we don't understand.
1210  // Just ignore it, it may come from some future version of KDE.
1211  break;
1212  }
1213 }
1214 
1215 bool SlaveBase::cacheAuthentication( const AuthInfo& info )
1216 {
1217  KPasswdServer* passwdServer = d->passwdServer();
1218 
1219  if (!passwdServer) {
1220  return false;
1221  }
1222 
1223  passwdServer->addAuthInfo(info, metaData(QLatin1String("window-id")).toLongLong());
1224  return true;
1225 }
1226 
1227 int SlaveBase::connectTimeout()
1228 {
1229  bool ok;
1230  QString tmp = metaData(QLatin1String("ConnectTimeout"));
1231  int result = tmp.toInt(&ok);
1232  if (ok)
1233  return result;
1234  return DEFAULT_CONNECT_TIMEOUT;
1235 }
1236 
1237 int SlaveBase::proxyConnectTimeout()
1238 {
1239  bool ok;
1240  QString tmp = metaData(QLatin1String("ProxyConnectTimeout"));
1241  int result = tmp.toInt(&ok);
1242  if (ok)
1243  return result;
1244  return DEFAULT_PROXY_CONNECT_TIMEOUT;
1245 }
1246 
1247 
1248 int SlaveBase::responseTimeout()
1249 {
1250  bool ok;
1251  QString tmp = metaData(QLatin1String("ResponseTimeout"));
1252  int result = tmp.toInt(&ok);
1253  if (ok)
1254  return result;
1255  return DEFAULT_RESPONSE_TIMEOUT;
1256 }
1257 
1258 
1259 int SlaveBase::readTimeout()
1260 {
1261  bool ok;
1262  QString tmp = metaData(QLatin1String("ReadTimeout"));
1263  int result = tmp.toInt(&ok);
1264  if (ok)
1265  return result;
1266  return DEFAULT_READ_TIMEOUT;
1267 }
1268 
1269 bool SlaveBase::wasKilled() const
1270 {
1271  return d->wasKilled;
1272 }
1273 
1274 void SlaveBase::setKillFlag()
1275 {
1276  d->wasKilled=true;
1277 }
1278 
1279 void SlaveBase::send(int cmd, const QByteArray& arr )
1280 {
1281  slaveWriteError = false;
1282  if (!d->appConnection.send(cmd, arr))
1283  // Note that slaveWriteError can also be set by sigpipe_handler
1284  slaveWriteError = true;
1285  if (slaveWriteError) exit();
1286 }
1287 
1288 void SlaveBase::virtual_hook( int, void* )
1289 { /*BASE::virtual_hook( id, data );*/ }
1290 
1291 void SlaveBase::lookupHost(const QString& host)
1292 {
1293  KIO_DATA << host;
1294  send(MSG_HOST_INFO_REQ, data);
1295 }
1296 
1297 int SlaveBase::waitForHostInfo(QHostInfo& info)
1298 {
1299  QByteArray data;
1300  int result = waitForAnswer(CMD_HOST_INFO, 0, data);
1301 
1302  if (result == -1) {
1303  info.setError(QHostInfo::UnknownError);
1304  info.setErrorString(i18n("Unknown Error"));
1305  return result;
1306  }
1307 
1308  QDataStream stream(data);
1309  QString hostName;
1310  QList<QHostAddress> addresses;
1311  int error;
1312  QString errorString;
1313 
1314  stream >> hostName >> addresses >> error >> errorString;
1315 
1316  info.setHostName(hostName);
1317  info.setAddresses(addresses);
1318  info.setError(QHostInfo::HostInfoError(error));
1319  info.setErrorString(errorString);
1320 
1321  return result;
1322 }
QIODevice::OpenMode
typedef OpenMode
DEFAULT_RESPONSE_TIMEOUT
#define DEFAULT_RESPONSE_TIMEOUT
Definition: ioslave_defaults.h:23
s_protocol
static const char * s_protocol
Definition: slavebase.cpp:157
KIO::unsupportedActionErrorString
QString unsupportedActionErrorString(const QString &protocol, int cmd)
Returns an appropriate error message if the given command cmd is an unsupported action (ERR_UNSUPPORT...
Definition: global.cpp:376
KIO::SlaveBase::finished
void finished()
Call to signal successful completion of any command besides openConnection and closeConnection.
Definition: slavebase.cpp:447
i18n
QString i18n(const char *text)
KIO::SlaveBase::redirection
void redirection(const KUrl &_url)
Call this to signal a redirection The job will take care of going to that url.
Definition: slavebase.cpp:565
isSubCommand
static bool isSubCommand(int cmd)
Definition: slavebase.cpp:576
KIO::Overwrite
When set, automatically overwrite the destination if it exists already.
Definition: jobclasses.h:67
QString::toULong
ulong toULong(bool *ok, int base) const
KIO::SlaveBase::dropNetwork
void dropNetwork(const QString &host=QString())
Used by the slave to withdraw a connection requested by requestNetwork.
Definition: slavebase.cpp:665
DEFAULT_CONNECT_TIMEOUT
#define DEFAULT_CONNECT_TIMEOUT
Definition: ioslave_defaults.h:24
KIO::filesize_t
qulonglong filesize_t
64-bit file size
Definition: global.h:57
KIO::INF_NETWORK_STATUS
Definition: slaveinterface.h:58
KIO::INF_INFOMESSAGE
Definition: slaveinterface.h:56
QMap::contains
bool contains(const Key &key) const
KIO::INF_PROCESSED_SIZE
Definition: slaveinterface.h:48
kdebug.h
ioslave_defaults.h
slaveinterface.h
KIO::INF_META_DATA
Definition: slaveinterface.h:57
KIO::SlaveBase::warning
void warning(const QString &msg)
Call to signal a warning, to be displayed in a dialog box.
Definition: slavebase.cpp:638
KIO::CMD_CHOWN
Definition: global.h:181
KIO::SlaveBase::~SlaveBase
virtual ~SlaveBase()
Definition: slavebase.cpp:253
KIO::CMD_CONFIG
Definition: global.h:177
KIO::SlaveBase::virtual_hook
virtual void virtual_hook(int id, void *data)
Definition: slavebase.cpp:1288
QByteArray
KIO::CMD_HOST
Definition: global.h:151
KIO::SlaveBase::put
virtual void put(const KUrl &url, int permissions, JobFlags flags)
put, i.e.
Definition: slavebase.cpp:762
KIO::UDSEntry
Universal Directory Service.
Definition: udsentry.h:58
group
DEFAULT_PROXY_CONNECT_TIMEOUT
#define DEFAULT_PROXY_CONNECT_TIMEOUT
Definition: ioslave_defaults.h:26
connection.h
KIO::SlaveBase::chown
virtual void chown(const KUrl &url, const QString &owner, const QString &group)
Change ownership of url The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHOWN.
Definition: slavebase.cpp:798
KIO::SlaveBase::dispatchLoop
void dispatchLoop()
Definition: slavebase.cpp:262
KIO::AuthInfo::setExtraField
void setExtraField(const QString &fieldName, const QVariant &value)
Set Extra Field Value.
Definition: authinfo.cpp:177
KIO::SlaveBase::disconnectSlave
void disconnectSlave()
Definition: slavebase.cpp:336
QDataStream
timeout
int timeout
KIO::CMD_SLAVE_STATUS
Definition: global.h:154
KIO::SlaveBase::copy
virtual void copy(const KUrl &src, const KUrl &dest, int permissions, JobFlags flags)
Copy src into dest.
Definition: slavebase.cpp:786
KIO::KPasswdServer::checkAuthInfo
bool checkAuthInfo(KIO::AuthInfo &info, qlonglong windowId, qlonglong usertime)
Check if kpasswdserver has cached authentication information regarding an AuthInfo object...
Definition: kpasswdserver.cpp:47
KIO::SlaveBase::dispatch
virtual void dispatch(int command, const QByteArray &data)
Definition: slavebase.cpp:946
kconfig.h
KIO::CMD_SUBURL
Definition: global.h:174
QMap
Definition: netaccess.h:36
KIO::SlaveBase::errorPage
void errorPage()
Tell that we will only get an error page here.
Definition: slavebase.cpp:571
KIO::CMD_STAT
Definition: global.h:161
KIO::SlaveBase::symlink
virtual void symlink(const QString &target, const KUrl &dest, JobFlags flags)
Creates a symbolic link named dest, pointing to target, which may be a relative or an absolute path...
Definition: slavebase.cpp:784
KIO::SlaveBase::openPasswordDialog
bool openPasswordDialog(KIO::AuthInfo &info, const QString &errorMsg=QString())
Prompt the user for Authorization info (login & password).
Definition: slavebase.cpp:815
KRemoteEncoding
Allows encoding and decoding properly remote filenames into Unicode.
Definition: kremoteencoding.h:44
KIO::SlaveBase::responseTimeout
int responseTimeout()
Definition: slavebase.cpp:1248
KIO::SlaveBase::multiGet
virtual void multiGet(const QByteArray &data)
Used for multiple get.
Definition: slavebase.cpp:802
KIO::AuthInfo
This class is intended to make it easier to prompt for, cache and retrieve authorization information...
Definition: authinfo.h:57
KIO::SlaveBase::wasKilled
bool wasKilled() const
If your ioslave was killed by a signal, wasKilled() returns true.
Definition: slavebase.cpp:1269
KIO::CMD_OPEN
Definition: global.h:180
KConfig::SimpleConfig
KIO::SlaveBase::setSubUrl
virtual void setSubUrl(const KUrl &url)
Prepare slave for streaming operation.
Definition: slavebase.cpp:800
KIO::CMD_MIMETYPE
Definition: global.h:162
QHostInfo::setAddresses
void setAddresses(const QList< QHostAddress > &addresses)
KIO::MSG_CONNECTED
Definition: slaveinterface.h:71
quint32
KIO::SlaveBase::mIncomingMetaData
MetaData mIncomingMetaData
Definition: slavebase.h:894
KIO::SlaveBase::checkCachedAuthentication
bool checkCachedAuthentication(AuthInfo &info)
Checks for cached authentication based on parameters given by info.
Definition: slavebase.cpp:1175
KIO::CMD_CONNECT
Definition: global.h:152
KIO::CMD_SPECIAL
Definition: global.h:169
KIO::SlaveBase::write
virtual void write(const QByteArray &data)
Definition: slavebase.cpp:774
KIO::CMD_SLAVE_HOLD
Definition: global.h:156
QMap::clear
void clear()
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
KIO::MSG_DATA
Definition: slaveinterface.h:68
QTime
KIO::SlaveBase::mimetype
virtual void mimetype(const KUrl &url)
Finds mimetype for one file or directory.
Definition: slavebase.cpp:780
KIO::SlaveBase::dataReq
void dataReq()
Asks for data from the job.
Definition: slavebase.cpp:404
genericsig_handler
static void genericsig_handler(int sigNumber)
Definition: slavebase.cpp:161
AuthKeysMap
QMap< QString, QByteArray > AuthKeysMap
Definition: slavebase.cpp:69
KIO::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:396
KIO::SlaveBase::setMetaData
void setMetaData(const QString &key, const QString &value)
Sets meta-data to be send to the application before the first data() or finished() signal...
Definition: slavebase.cpp:341
KIO::SlaveBase::connectSlave
void connectSlave(const QString &path)
internal function to connect a slave to/ disconnect from either the slave pool or the application ...
Definition: slavebase.cpp:321
KIO::SlaveBase::reparseConfiguration
virtual void reparseConfiguration()
Called by the scheduler to tell the slave that the configuration changed (i.e.
Definition: slavebase.cpp:809
KIO::MSG_SLAVE_STATUS
Definition: slaveinterface.h:77
KUrl
KIO::CMD_READ
Definition: global.h:182
KIO::CMD_META_DATA
Definition: global.h:172
KIO::CMD_SETLINKDEST
Definition: global.h:179
config
KSharedConfigPtr config()
KIO::SlaveBase::mimeType
void mimeType(const QString &_type)
Call this in mimetype() and in get(), when you know the mimetype.
Definition: slavebase.cpp:588
KIO::SlaveBase::special
virtual void special(const QByteArray &data)
Used for any command that is specific to this slave (protocol) Examples are : HTTP POST...
Definition: slavebase.cpp:764
KIO::SlaveBase::del
virtual void del(const KUrl &url, bool isfile)
Delete a file or directory.
Definition: slavebase.cpp:788
KIO::SlaveBase::totalSize
void totalSize(KIO::filesize_t _bytes)
Call this in get and copy, to give the total size of the file.
Definition: slavebase.cpp:497
KIO::CMD_LISTDIR
Definition: global.h:163
KIO::MSG_FINISHED
Definition: slaveinterface.h:72
KIO::SlaveBase::processedPercent
void processedPercent(float percent)
Only use this if you can't know in advance the size of the copied data.
Definition: slavebase.cpp:553
KIO::SlaveBase::stat
virtual void stat(const KUrl &url)
Finds all details for one file or directory.
Definition: slavebase.cpp:760
KIO::MSG_RESUME
Definition: slaveinterface.h:76
KIO::SlaveBase::chmod
virtual void chmod(const KUrl &url, int permissions)
Change permissions on url The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD. ...
Definition: slavebase.cpp:794
KIO::CMD_SETMODIFICATIONTIME
Definition: global.h:170
KIO::CMD_COPY
Definition: global.h:166
kpasswdserver_p.h
KIO::SlaveBase::readTimeout
int readTimeout()
Definition: slavebase.cpp:1259
KIO::MSG_LIST_ENTRIES
Definition: slaveinterface.h:74
KIO::SlaveBase::messageBox
int messageBox(MessageBoxType type, const QString &text, const QString &caption=QString(), const QString &buttonYes=i18n("&Yes"), const QString &buttonNo=i18n("&No"))
Call this to show a message box from the slave.
Definition: slavebase.cpp:851
KIO::SlaveBase::connected
void connected()
Call in openConnection, if you reimplement it, when you're done.
Definition: slavebase.cpp:442
globalSlave
static SlaveBase * globalSlave
Definition: slavebase.cpp:152
KIO::SlaveBase::infoMessage
void infoMessage(const QString &msg)
Call to signal a message, to be displayed if the application wants to, for instance in a status bar...
Definition: slavebase.cpp:644
KIO::SlaveBase::processedSize
void processedSize(KIO::filesize_t _bytes)
Call this during get and copy, once in a while, to give some info about the current state...
Definition: slavebase.cpp:507
QString::number
QString number(int n, int base)
QList::count
int count(const T &value) const
KIO::SlaveBase::canResume
void canResume()
Call this at the beginning of get(), if the "resume" metadata was set and resuming is implemented by ...
Definition: slavebase.cpp:492
AuthKeysList
QList< QByteArray > AuthKeysList
Definition: slavebase.cpp:68
KIO::SlaveBase::config
KConfigGroup * config()
Returns a configuration object to query config/meta-data information from.
Definition: slavebase.cpp:369
KIO::MSG_NET_DROP
Definition: slaveinterface.h:80
KIO::SlaveBase::dispatchOpenCommand
virtual void dispatchOpenCommand(int command, const QByteArray &data)
Definition: slavebase.cpp:1183
KIO::SlaveBase::open
virtual void open(const KUrl &url, QIODevice::OpenMode mode)
open.
Definition: slavebase.cpp:770
KIO::AuthInfo::isModified
bool isModified() const
Use this method to check if the object was modified.
Definition: authinfo.cpp:165
KIO::SlaveBase::setTimeoutSpecialCommand
void setTimeoutSpecialCommand(int timeout, const QByteArray &data=QByteArray())
This function sets a timeout of timeout seconds and calls special(data) when the timeout occurs as if...
Definition: slavebase.cpp:934
kremoteencoding.h
KIO::SlaveBase
There are two classes that specifies the protocol between application (job) and kioslave.
Definition: slavebase.h:50
KIO::Resume
When set, automatically append to the destination file if it exists already.
Definition: jobclasses.h:60
KIO::SlaveBase::mOutgoingMetaData
MetaData mOutgoingMetaData
Definition: slavebase.h:893
sigsegv_handler
static void sigsegv_handler(int sig)
Definition: slavebase.cpp:715
KIO::SlaveBase::allMetaData
MetaData allMetaData() const
Definition: slavebase.cpp:355
QString::toInt
int toInt(bool *ok, int base) const
KIO::SlaveBase::close
virtual void close()
Definition: slavebase.cpp:778
KIO::SlaveBase::statEntry
void statEntry(const UDSEntry &_entry)
Call this from stat() to express details about an object, the UDSEntry customarily contains the atoms...
Definition: slavebase.cpp:671
KIO::MSG_NEED_SUBURL_DATA
Definition: slaveinterface.h:81
KIO::SlaveBase::cacheAuthentication
bool cacheAuthentication(const AuthInfo &info)
Caches info in a persistent storage like KWallet.
Definition: slavebase.cpp:1215
KIO::SlaveBase::requestNetwork
bool requestNetwork(const QString &host=QString())
Used by the slave to check if it can connect to a given host.
Definition: slavebase.cpp:650
KIO::SlaveBase::setLinkDest
virtual void setLinkDest(const KUrl &url, const QString &target)
Change the destination of a symlink.
Definition: slavebase.cpp:790
KIO::SlaveBase::slave_status
virtual void slave_status()
Called to get the status of the slave.
Definition: slavebase.cpp:806
KIO::MSG_STAT_ENTRY
Definition: slaveinterface.h:73
KIO::MSG_NET_REQUEST
Definition: slaveinterface.h:79
KIO::SlaveBase::AppConnectionMade
Definition: slavebase.h:897
KIO::SlaveBase::connectTimeout
int connectTimeout()
Definition: slavebase.cpp:1227
kcrash.h
QString
QList< QByteArray >
KIO::CMD_PUT
Definition: global.h:160
KIO::SlaveBase::closeConnection
virtual void closeConnection()
Closes the connection (forced) Called when the application disconnects the slave to close any open ne...
Definition: slavebase.cpp:758
KIO::SlaveBase::hasMetaData
bool hasMetaData(const QString &key) const
Queries for the existence of a certain config/meta-data entry send by the application to the slave...
Definition: slavebase.cpp:360
emitSignal
static void emitSignal(const QString &signalName, const QVariantList &args)
Definition: kdirnotify.cpp:28
KIO::CMD_RENAME
Definition: global.h:165
KIO::SlaveBase::data
void data(const QByteArray &data)
Sends data in the slave to the job (i.e.
Definition: slavebase.cpp:398
KIO::KPasswdServer::queryAuthInfo
qlonglong queryAuthInfo(KIO::AuthInfo &info, const QString &errorMsg, qlonglong windowId, qlonglong seqNr, qlonglong usertime)
Let kpasswdserver ask the user for authentication information.
Definition: kpasswdserver.cpp:113
KIO::SlaveBase::exit
void exit()
Definition: slavebase.cpp:628
KIO::SlaveBase::position
void position(KIO::filesize_t _pos)
Definition: slavebase.cpp:547
KIO::SlaveBase::written
void written(KIO::filesize_t _bytes)
Definition: slavebase.cpp:541
KIO::INF_TOTAL_SIZE
Definition: slaveinterface.h:47
QHostInfo::setErrorString
void setErrorString(const QString &str)
QList::end
iterator end()
QHostInfo::setHostName
void setHostName(const QString &hostName)
KIO::CMD_DEL
Definition: global.h:167
QFlag
KIO::CMD_MKDIR
Definition: global.h:164
KIO::SlaveBase::remoteEncoding
KRemoteEncoding * remoteEncoding()
Returns an object that can translate remote filenames into proper Unicode forms.
Definition: slavebase.cpp:389
KIO::CMD_SEEK
Definition: global.h:184
KIO::SlaveBase::mkdir
virtual void mkdir(const KUrl &url, int permissions)
Create a directory.
Definition: slavebase.cpp:792
KIO::CMD_RESUMEANSWER
Definition: global.h:176
KIO::INF_WARNING
Definition: slaveinterface.h:53
KIO::SlaveBase::MessageBoxType
MessageBoxType
Definition: slavebase.h:248
KIO::CMD_MESSAGEBOXANSWER
Definition: global.h:175
KIO_FILESIZE_T
#define KIO_FILESIZE_T(x)
Definition: slavebase.cpp:71
KIO::SlaveBase::error
void error(int _errid, const QString &_text)
Call to signal an error.
Definition: slavebase.cpp:419
ok
KGuiItem ok()
KIO::SlaveBase::read
virtual void read(KIO::filesize_t size)
Definition: slavebase.cpp:772
QString::toLong
long toLong(bool *ok, int base) const
KIO::SlaveBase::lookupHost
void lookupHost(const QString &host)
Internally used.
Definition: slavebase.cpp:1291
KIO::CMD_CLOSE
Definition: global.h:185
KIO::SlaveBase::listDir
virtual void listDir(const KUrl &url)
Lists the contents of url.
Definition: slavebase.cpp:766
KConfigGroup
KIO::SlaveBase::proxyConnectTimeout
int proxyConnectTimeout()
Definition: slavebase.cpp:1237
KIO::INF_POSITION
Definition: slaveinterface.h:60
KConfig
KIO::SlaveBase::sendAndKeepMetaData
void sendAndKeepMetaData()
Internal function to transmit meta data to the application.
Definition: slavebase.cpp:380
DEFAULT_READ_TIMEOUT
#define DEFAULT_READ_TIMEOUT
Definition: ioslave_defaults.h:25
KIO::INF_SPEED
Definition: slaveinterface.h:49
KIO::CMD_DISCONNECT
Definition: global.h:153
KIO::SlaveBase::metaData
QString metaData(const QString &key) const
Queries for config/meta-data send by the application to the slave.
Definition: slavebase.cpp:346
KIO::INF_MESSAGEBOX
Definition: slaveinterface.h:59
KIO::INF_REDIRECTION
Definition: slaveinterface.h:50
KIO::SlaveBase::needSubUrlData
void needSubUrlData()
Call to signal that data from the sub-URL is needed.
Definition: slavebase.cpp:469
KIO::SlaveBase::get
virtual void get(const KUrl &url)
get, aka read.
Definition: slavebase.cpp:768
KIO::CMD_CHMOD
Definition: global.h:168
KIO::AuthInfo::setModified
void setModified(bool flag)
Use this method to indicate that this object has been modified.
Definition: authinfo.cpp:170
KIO::SlaveBase::listEntry
void listEntry(const UDSEntry &_entry, bool ready)
internal function to be called by the slave.
Definition: slavebase.cpp:677
KIO::MSG_DATA_REQ
Definition: slaveinterface.h:69
KIO::CMD_NONE
Definition: global.h:157
KIO::SlaveBase::rename
virtual void rename(const KUrl &src, const KUrl &dest, JobFlags flags)
Rename oldname into newname.
Definition: slavebase.cpp:782
QLatin1String
KIO::SlaveBase::setModificationTime
virtual void setModificationTime(const KUrl &url, const QDateTime &mtime)
Sets the modification time for For instance this is what CopyJob uses to set mtime on dirs at the en...
Definition: slavebase.cpp:796
KIO::SlaveBase::speed
void speed(unsigned long _bytes_per_second)
Call this in get and copy, to give the current transfer speed, but only if it can't be calculated out...
Definition: slavebase.cpp:559
KIO::SlaveBase::opened
void opened()
open succedes
Definition: slavebase.cpp:412
KIO::KPasswdServer
Interface class for kpasswdserver.
Definition: kpasswdserver_p.h:40
QCoreApplication::sendPostedEvents
void sendPostedEvents()
KIO::MSG_WRITTEN
Definition: slaveinterface.h:86
KIO::ERR_UNSUPPORTED_ACTION
Definition: global.h:202
QList< UDSEntry >::ConstIterator
typedef ConstIterator
QByteArray::data
char * data()
KIO::SlaveBase::sendMetaData
void sendMetaData()
Internal function to transmit meta data to the application.
Definition: slavebase.cpp:374
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
qint32
KIO::MSG_SLAVE_ACK
Definition: slaveinterface.h:78
KIO::SlaveBase::waitForHostInfo
int waitForHostInfo(QHostInfo &info)
Internally used.
Definition: slavebase.cpp:1297
QMap::insert
iterator insert(const Key &key, const T &value)
QMap::isEmpty
bool isEmpty() const
KIO::KPasswdServer::addAuthInfo
void addAuthInfo(const KIO::AuthInfo &info, qlonglong windowId)
Manually add authentication information to kpasswdserver's cache.
Definition: kpasswdserver.cpp:185
KIO::CMD_SLAVE_CONNECT
Definition: global.h:155
slavebase.h
KIO_DATA
#define KIO_DATA
Definition: slavebase.cpp:70
slaveWriteError
static volatile bool slaveWriteError
Definition: slavebase.cpp:155
KIO::SlaveBase::waitForAnswer
int waitForAnswer(int expected1, int expected2, QByteArray &data, int *pCmd=0)
Wait for an answer to our request, until we get expected1 or expected2.
Definition: slavebase.cpp:897
QMap< QString, QString >::ConstIterator
typedef ConstIterator
KIO::SlaveBase::slaveStatus
void slaveStatus(const QString &host, bool connected)
Used to report the status of the slave.
Definition: slavebase.cpp:482
KIO::CMD_MULTI_GET
Definition: global.h:178
KIO::MSG_ERROR
Definition: slaveinterface.h:70
KIO::MSG_CANRESUME
Definition: slaveinterface.h:82
sigpipe_handler
static void sigpipe_handler(int sig)
Definition: slavebase.cpp:741
KIO::SlaveBase::SlaveBase
SlaveBase(const QByteArray &protocol, const QByteArray &pool_socket, const QByteArray &app_socket)
Definition: slavebase.cpp:179
KIO::SlaveBase::listEntries
void listEntries(const UDSEntryList &_entry)
Call this in listDir, each time you have a bunch of entries to report.
Definition: slavebase.cpp:704
end
const KShortcut & end()
KIO::SlaveBase::mProtocol
QByteArray mProtocol
Name of the protocol supported by this slave.
Definition: slavebase.h:891
KIO::MSG_OPENED
Definition: slaveinterface.h:85
KIO::CMD_HOST_INFO
Definition: global.h:186
QHostInfo
KIO::MSG_HOST_INFO_REQ
Definition: slaveinterface.h:87
kFatal
static QDebug kFatal(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KIO::SlaveBase::readData
int readData(QByteArray &buffer)
Read data sent by the job, after a dataReq.
Definition: slavebase.cpp:927
QList::begin
iterator begin()
KIO::CMD_SYMLINK
Definition: global.h:173
KIO::SlaveBase::seek
virtual void seek(KIO::filesize_t offset)
Definition: slavebase.cpp:776
KIO::SlaveBase::openConnection
virtual void openConnection()
Opens the connection (forced) When this function gets called the slave is operating in connection-ori...
Definition: slavebase.cpp:756
KIO::CMD_WRITE
Definition: global.h:183
KIO::CMD_REPARSECONFIGURATION
Definition: global.h:171
KIO::SlaveBase::setKillFlag
void setKillFlag()
Internally used.
Definition: slavebase.cpp:1274
QFile::decodeName
QString decodeName(const QByteArray &localFileName)
kconfiggroup.h
QDateTime
KCrash::setCrashHandler
void setCrashHandler(HandlerType handler=defaultCrashHandler)
KIO::INF_ERROR_PAGE
Definition: slaveinterface.h:52
QHostInfo::setError
void setError(HostInfoError error)
KIO::number
QString number(KIO::filesize_t size)
Converts a size to a string representation Not unlike QString::number(...)
Definition: global.cpp:63
KIO::SlaveBase::setHost
virtual void setHost(const QString &host, quint16 port, const QString &user, const QString &pass)
Set the host.
Definition: slavebase.cpp:752
KRecentDirs::list
QStringList list(const QString &fileClass)
Returns a list of directories associated with this file-class.
Definition: krecentdirs.cpp:60
KIO::CMD_GET
Definition: global.h:159
KIO::INF_MIME_TYPE
Definition: slaveinterface.h:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal