Exemple #1
0
void PackerJob::pack()
{
	struct _stat fileInfo;
	for (UINT i = 0; i < m_files.size(); i++) {
		if (_wstat(m_files[i], &fileInfo) == 0)
			m_uiFileSize += (UINT64)fileInfo.st_size;
	}

	setStatus(STATUS_PACKING);
	m_startTS = time(0);

	int res = createZipFile();
	if (res == ZIP_OK) {
		UploadJob *ujob = new UploadJob(this);
		ujob->m_tab->m_job = ujob;
		ujob->start();
	}
	else {
		if (res == ZIP_ERRNO) {
			Utils::msgBox(TranslateT("Error occurred when zipping the file(s)."), MB_OK | MB_ICONERROR);
			delete m_tab;
		}

		DeleteFile(m_tszFilePath);
	}
}
        void testSslJobs()
        {
            const QString aFile = QFINDTESTDATA("sendfiletest.cpp");
            const QString destFile = QDir::tempPath() + "/kdeconnect-test-sentfile";
            QFile(destFile).remove();

            const QString deviceId = KdeConnectConfig::instance()->deviceId()
                        , deviceName = "testdevice"
                        , deviceType = KdeConnectConfig::instance()->deviceType();

            KdeConnectConfig* kcc = KdeConnectConfig::instance();
            kcc->addTrustedDevice(deviceId, deviceName, deviceType);
            kcc->setDeviceProperty(deviceId, QString("certificate"), QString::fromLatin1(kcc->certificate().toPem())); // Using same certificate from kcc, instead of generating

            QSharedPointer<QFile> f(new QFile(aFile));
            UploadJob* uj = new UploadJob(f, deviceId);
            QSignalSpy spyUpload(uj, &KJob::result);
            uj->start();

            auto info = uj->transferInfo();
            info.insert("deviceId", deviceId);
            info.insert("size", aFile.size());

            DownloadJob* dj = new DownloadJob(QHostAddress::LocalHost, info);

            QVERIFY(dj->getPayload()->open(QIODevice::ReadOnly));

            FileTransferJob* ft = new FileTransferJob(dj->getPayload(), uj->transferInfo()["size"].toInt(), QUrl::fromLocalFile(destFile));

            QSignalSpy spyDownload(dj, &KJob::result);
            QSignalSpy spyTransfer(ft, &KJob::result);

            ft->start();
            dj->start();

            QVERIFY(spyTransfer.count() || spyTransfer.wait(1000000000));

            if (ft->error()) qWarning() << "fterror" << ft->errorString();

            QCOMPARE(ft->error(), 0);
            QCOMPARE(spyDownload.count(), 1);
            QCOMPARE(spyUpload.count(), 1);

            QFile resultFile(destFile), originFile(aFile);
            QVERIFY(resultFile.open(QIODevice::ReadOnly));
            QVERIFY(originFile.open(QIODevice::ReadOnly));

            const QByteArray resultContents = resultFile.readAll(), originContents = originFile.readAll();
            QCOMPARE(resultContents.size(), originContents.size());
            QCOMPARE(resultFile.readAll(), originFile.readAll());
        }
bool LanDeviceLink::sendPackage(NetworkPackage& np)
{
    if (np.hasPayload()) {
         UploadJob* job = new UploadJob(np.payload());
         job->start();
         np.setPayloadTransferInfo(job->getTransferInfo());
    }

    int written = mSocketLineReader->write(np.serialize());
    //TODO: Actually detect if a package is received or not, now we keep TCP
    //"ESTABLISHED" connections that look legit (return true when we use them),
    //but that are actually broken
    return (written != -1);
}