Changeset View
Changeset View
Standalone View
Standalone View
src/util/externalcommandhelper.cpp
Show First 20 Lines • Show All 146 Lines • ▼ Show 20 Line(s) | 136 | { | |||
---|---|---|---|---|---|
147 | 147 | | |||
148 | if (device.write(buffer) != buffer.size()) { | 148 | if (device.write(buffer) != buffer.size()) { | ||
149 | qCritical() << xi18n("Could not write to device <filename>%1</filename>.", targetDevice); | 149 | qCritical() << xi18n("Could not write to device <filename>%1</filename>.", targetDevice); | ||
150 | return false; | 150 | return false; | ||
151 | } | 151 | } | ||
152 | return true; | 152 | return true; | ||
153 | } | 153 | } | ||
154 | 154 | | |||
155 | bool ExternalCommandHelper::copyblocks(const QByteArray& signature, const quint64 nonce, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize) | 155 | QVariantMap ExternalCommandHelper::copyblocks(const QByteArray& signature, const quint64 nonce, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize) | ||
156 | { | 156 | { | ||
157 | QVariantMap reply; | ||||
158 | reply[QStringLiteral("success")] = true; | ||||
159 | | ||||
157 | if (m_Nonces.find(nonce) != m_Nonces.end()) | 160 | if (m_Nonces.find(nonce) != m_Nonces.end()) | ||
158 | m_Nonces.erase( nonce ); | 161 | m_Nonces.erase( nonce ); | ||
159 | else | 162 | else { | ||
160 | return false; | 163 | reply[QStringLiteral("success")] = false; | ||
164 | return reply; | ||||
165 | } | ||||
161 | 166 | | |||
162 | QByteArray request; | 167 | QByteArray request; | ||
163 | 168 | | |||
164 | request.setNum(nonce); | 169 | request.setNum(nonce); | ||
165 | request.append(sourceDevice.toUtf8()); | 170 | request.append(sourceDevice.toUtf8()); | ||
166 | request.append(QByteArray::number(sourceFirstByte)); | 171 | request.append(QByteArray::number(sourceFirstByte)); | ||
167 | request.append(QByteArray::number(sourceLength)); | 172 | request.append(QByteArray::number(sourceLength)); | ||
168 | request.append(targetDevice.toUtf8()); | 173 | request.append(targetDevice.toUtf8()); | ||
169 | request.append(QByteArray::number(targetFirstByte)); | 174 | request.append(QByteArray::number(targetFirstByte)); | ||
170 | request.append(QByteArray::number(blockSize)); | 175 | request.append(QByteArray::number(blockSize)); | ||
171 | 176 | | |||
172 | QByteArray hash = QCryptographicHash::hash(request, QCryptographicHash::Sha512); | 177 | QByteArray hash = QCryptographicHash::hash(request, QCryptographicHash::Sha512); | ||
173 | if (!m_publicKey.verifyMessage(hash, signature, QCA::EMSA3_Raw)) { | 178 | if (!m_publicKey.verifyMessage(hash, signature, QCA::EMSA3_Raw)) { | ||
174 | qCritical() << xi18n("Invalid cryptographic signature"); | 179 | qCritical() << xi18n("Invalid cryptographic signature"); | ||
175 | return false; | 180 | reply[QStringLiteral("success")] = false; | ||
181 | return reply; | ||||
176 | } | 182 | } | ||
177 | 183 | | |||
178 | const qint64 blocksToCopy = sourceLength / blockSize; | 184 | const qint64 blocksToCopy = sourceLength / blockSize; | ||
179 | qint64 readOffset = sourceFirstByte; | 185 | qint64 readOffset = sourceFirstByte; | ||
180 | qint64 writeOffset = targetFirstByte; | 186 | qint64 writeOffset = targetFirstByte; | ||
181 | qint32 copyDirection = 1; | 187 | qint32 copyDirection = 1; | ||
182 | 188 | | |||
183 | if (targetFirstByte > sourceFirstByte) { | 189 | if (targetFirstByte > sourceFirstByte) { | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 239 | if (rval && lastBlock > 0) { | |||
234 | Q_ASSERT(lastBlock < blockSize); | 240 | Q_ASSERT(lastBlock < blockSize); | ||
235 | 241 | | |||
236 | const qint64 lastBlockReadOffset = copyDirection > 0 ? readOffset + blockSize * blocksCopied : sourceFirstByte; | 242 | const qint64 lastBlockReadOffset = copyDirection > 0 ? readOffset + blockSize * blocksCopied : sourceFirstByte; | ||
237 | const qint64 lastBlockWriteOffset = copyDirection > 0 ? writeOffset + blockSize * blocksCopied : targetFirstByte; | 243 | const qint64 lastBlockWriteOffset = copyDirection > 0 ? writeOffset + blockSize * blocksCopied : targetFirstByte; | ||
238 | report[QStringLiteral("report")]= xi18nc("@info:progress", "Copying remainder of block size %1 from %2 to %3.", lastBlock, lastBlockReadOffset, lastBlockWriteOffset); | 244 | report[QStringLiteral("report")]= xi18nc("@info:progress", "Copying remainder of block size %1 from %2 to %3.", lastBlock, lastBlockReadOffset, lastBlockWriteOffset); | ||
239 | HelperSupport::progressStep(report); | 245 | HelperSupport::progressStep(report); | ||
240 | rval = readData(sourceDevice, buffer, lastBlockReadOffset, lastBlock); | 246 | rval = readData(sourceDevice, buffer, lastBlockReadOffset, lastBlock); | ||
241 | 247 | | |||
242 | if (rval) | 248 | if (rval) { | ||
249 | if (targetDevice.isEmpty()) | ||||
250 | reply[QStringLiteral("targetByteArray")] = buffer; | ||||
251 | else | ||||
243 | rval = writeData(targetDevice, buffer, lastBlockWriteOffset); | 252 | rval = writeData(targetDevice, buffer, lastBlockWriteOffset); | ||
253 | } | ||||
244 | 254 | | |||
245 | if (rval) { | 255 | if (rval) { | ||
246 | HelperSupport::progressStep(100); | 256 | HelperSupport::progressStep(100); | ||
247 | bytesWritten += buffer.size(); | 257 | bytesWritten += buffer.size(); | ||
248 | } | 258 | } | ||
249 | } | 259 | } | ||
250 | 260 | | |||
251 | report[QStringLiteral("report")] = xi18ncp("@info:progress argument 2 is a string such as 7 bytes (localized accordingly)", "Copying 1 block (%2) finished.", "Copying %1 blocks (%2) finished.", blocksCopied, i18np("1 byte", "%1 bytes", bytesWritten)); | 261 | report[QStringLiteral("report")] = xi18ncp("@info:progress argument 2 is a string such as 7 bytes (localized accordingly)", "Copying 1 block (%2) finished.", "Copying %1 blocks (%2) finished.", blocksCopied, i18np("1 byte", "%1 bytes", bytesWritten)); | ||
252 | HelperSupport::progressStep(report); | 262 | HelperSupport::progressStep(report); | ||
253 | 263 | | |||
254 | return rval; | 264 | reply[QStringLiteral("success")] = rval; | ||
265 | return reply; | ||||
255 | } | 266 | } | ||
256 | 267 | | |||
257 | QVariantMap ExternalCommandHelper::start(const QByteArray& signature, const quint64 nonce, const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode) | 268 | QVariantMap ExternalCommandHelper::start(const QByteArray& signature, const quint64 nonce, const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode) | ||
258 | { | 269 | { | ||
259 | QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); | 270 | QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); | ||
260 | QVariantMap reply; | 271 | QVariantMap reply; | ||
261 | reply[QStringLiteral("success")] = true; | 272 | reply[QStringLiteral("success")] = true; | ||
262 | 273 | | |||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |