void sendSslMetaData() { MetaData::ConstIterator it = sslMetaData.constBegin(); for (; it != sslMetaData.constEnd(); ++it) { q->setMetaData(it.key(), it.value()); } }
DataProtocol::DataProtocol(const QByteArray &pool_socket, const QByteArray &app_socket) : SlaveBase("kio_data", pool_socket, app_socket) { #else DataProtocol::DataProtocol() { #endif //qDebug(); } /* --------------------------------------------------------------------- */ DataProtocol::~DataProtocol() { //qDebug(); } /* --------------------------------------------------------------------- */ void DataProtocol::get(const QUrl &url) { ref(); //qDebug() << this; const DataHeader hdr = parseDataHeader(url, false); const int size = hdr.url.length(); const int data_ofs = qMin(hdr.data_offset, size); // FIXME: string is copied, would be nice if we could have a reference only const QByteArray url_data = hdr.url.mid(data_ofs); QByteArray outData; if (hdr.is_base64) { // base64 stuff is expected to contain the correct charset, so we just // decode it and pass it to the receiver outData = QByteArray::fromBase64(url_data); } else { QTextCodec *codec = QTextCodec::codecForName(hdr.attributes[QStringLiteral("charset")].toLatin1()); if (codec != 0) { outData = codec->toUnicode(url_data).toUtf8(); } else { outData = url_data; }/*end if*/ }/*end if*/ //qDebug() << "emit mimeType@"<<this; mimeType(hdr.mime_type); //qDebug() << "emit totalSize@"<<this; totalSize(outData.size()); //qDebug() << "emit setMetaData@"<<this; #if defined(DATAKIOSLAVE) MetaData::ConstIterator it; for (it = hdr.attributes.constBegin(); it != hdr.attributes.constEnd(); ++it) { setMetaData(it.key(), it.value()); }/*next it*/ #else setAllMetaData(hdr.attributes); #endif //qDebug() << "emit sendMetaData@"<<this; sendMetaData(); //qDebug() << "(1) queue size " << dispatchQueue.size(); // empiric studies have shown that this shouldn't be queued & dispatched data(outData); //qDebug() << "(2) queue size " << dispatchQueue.size(); DISPATCH(data(QByteArray())); //qDebug() << "(3) queue size " << dispatchQueue.size(); DISPATCH(finished()); //qDebug() << "(4) queue size " << dispatchQueue.size(); deref(); }
bool SlaveInterface::dispatch(int _cmd, const QByteArray &rawdata) { Q_D(SlaveInterface); //kDebug(7007) << "dispatch " << _cmd; QDataStream stream(rawdata); QString str1; qint32 i; qint8 b; quint32 ul; switch(_cmd) { case MSG_DATA: emit data(rawdata); break; case MSG_DATA_REQ: emit dataReq(); break; case MSG_OPENED: emit open(); break; case MSG_FINISHED: //kDebug(7007) << "Finished [this = " << this << "]"; d->offset = 0; d->speed_timer.stop(); emit finished(); break; case MSG_STAT_ENTRY: { UDSEntry entry; stream >> entry; emit statEntry(entry); break; } case MSG_LIST_ENTRIES: { quint32 count; stream >> count; UDSEntryList list; UDSEntry entry; for (uint i = 0; i < count; i++) { stream >> entry; list.append(entry); } emit listEntries(list); break; } case MSG_RESUME: { // From the put job d->offset = readFilesize_t(stream); emit canResume(d->offset); break; } case MSG_CANRESUME: // From the get job d->filesize = d->offset; emit canResume(0); // the arg doesn't matter break; case MSG_ERROR: stream >> i >> str1; kDebug(7007) << "error " << i << " " << str1; emit error(i, str1); break; case MSG_SLAVE_STATUS: { PIDType<sizeof(pid_t)>::PID_t stream_pid; pid_t pid; QByteArray protocol; stream >> stream_pid >> protocol >> str1 >> b; pid = stream_pid; emit slaveStatus(pid, protocol, str1, (b != 0)); break; } case MSG_CONNECTED: emit connected(); break; case MSG_WRITTEN: { KIO::filesize_t size = readFilesize_t(stream); emit written(size); break; } case INF_TOTAL_SIZE: { KIO::filesize_t size = readFilesize_t(stream); gettimeofday(&d->start_time, 0); d->last_time = 0; d->filesize = d->offset; d->sizes[0] = d->filesize - d->offset; d->times[0] = 0; d->nums = 1; d->speed_timer.start(1000); d->slave_calcs_speed = false; emit totalSize(size); break; } case INF_PROCESSED_SIZE: { KIO::filesize_t size = readFilesize_t(stream); emit processedSize( size ); d->filesize = size; break; } case INF_POSITION: { KIO::filesize_t pos = readFilesize_t(stream); emit position(pos); break; } case INF_SPEED: stream >> ul; d->slave_calcs_speed = true; d->speed_timer.stop(); emit speed( ul ); break; case INF_GETTING_FILE: break; case INF_ERROR_PAGE: emit errorPage(); break; case INF_REDIRECTION: { KUrl url; stream >> url; emit redirection( url ); break; } case INF_MIME_TYPE: stream >> str1; emit mimeType(str1); if (!d->connection->suspended()) d->connection->sendnow(CMD_NONE, QByteArray()); break; case INF_WARNING: stream >> str1; emit warning(str1); break; case INF_MESSAGEBOX: { kDebug(7007) << "needs a msg box"; QString text, caption, buttonYes, buttonNo, dontAskAgainName; int type; stream >> type >> text >> caption >> buttonYes >> buttonNo; if (stream.atEnd()) { messageBox(type, text, caption, buttonYes, buttonNo); } else { stream >> dontAskAgainName; messageBox(type, text, caption, buttonYes, buttonNo, dontAskAgainName); } break; } case INF_INFOMESSAGE: { QString msg; stream >> msg; emit infoMessage(msg); break; } case INF_META_DATA: { MetaData m; stream >> m; if (m.contains(QLatin1String("ssl_in_use"))) { const QLatin1String ssl_("ssl_"); const MetaData constM = m; for (MetaData::ConstIterator it = constM.lowerBound(ssl_); it != constM.constEnd(); ++it) { if (it.key().startsWith(ssl_)) { d->sslMetaData.insert(it.key(), it.value()); } else { // we're past the ssl_* entries; remember that QMap is ordered. break; } } } emit metaData(m); break; } case MSG_NET_REQUEST: { QString host; QString slaveid; stream >> host >> slaveid; requestNetwork(host, slaveid); break; } case MSG_NET_DROP: { QString host; QString slaveid; stream >> host >> slaveid; dropNetwork(host, slaveid); break; } case MSG_NEED_SUBURL_DATA: { emit needSubUrlData(); break; } case MSG_HOST_INFO_REQ: { QString hostName; stream >> hostName; HostInfo::lookupHost(hostName, this, SLOT(slotHostInfo(QHostInfo))); break; } default: kWarning(7007) << "Slave sends unknown command (" << _cmd << "), dropping slave"; return false; } return true; }