[Solved] Read from QSslSocket results irregular data
-
wrote on 10 Jun 2012, 16:41 last edited by
Hi guys,
I read from a QSslSocket to receive yenc encoded usenet articles and save it to files, but something is wrong. Some articles have wrong CRCs while decoding (one "Segment" for each article and file):
@
QSslSocket *sslSocket;
QFile output;void Segment::socketReadyRead() {
const QByteArray data = sslSocket->readAll();output.write(data); if (data.contains("=yend")) { sslSocket->close(); }
}
@What is wrong with my code? Someone has a hint for me?
Thanks!
Kai -
wrote on 11 Jun 2012, 13:07 last edited by
How do you calculate the CRC? How do you do the yEnc decoding? Is it possible that there is data before =ybegin and after =yend?
For example, if readAll() returns "[data]=yend\n" you'll add the whole =yend\n part to output, which might not be expected by the decryption algorithm, and thus corrupt your last data segment. -
wrote on 11 Jun 2012, 13:41 last edited by
The yenc encoding process works after all articles are downloaded, each article in one file. The yenc decoding class works 100% (with correct CRCs), if I download all articles with another program (newsreader/grabber etc.), the yenc decoder decodes it with no errors! ...therefore the problems are in my downloading code!
-
wrote on 11 Jun 2012, 15:23 last edited by
I suggest to add some qDebug() and check if corrupted files have more that one call of Segment::socketReadyRead().
Is it pseudocode?
Why don't you open file before writing with QIODevice::Append mode?
You don't call flush and close on QFile so it's not sure that all data is written to device(some device buffer etc). -
wrote on 11 Jun 2012, 18:26 last edited by
It's not a part for this sample here. File will open before connect to host and closed after socket is closed (in other functions)! Segment::socketReadyRead() is called multiple times of course, it's a TCP based connection.
-
wrote on 11 Jun 2012, 19:11 last edited by
I still wonder whether there's data after "=yend", since you just use readAll and push that into output without truncating after "=yend"...
-
wrote on 11 Jun 2012, 20:52 last edited by
=yend is part of last data block, after this article ends.
Last line of each article is:
=yend size=<...> part=<lastPartNumber> pcrc32=<crc> -
wrote on 12 Jun 2012, 10:16 last edited by
Addition:
pcrc32=<8 char hexvalue> Representing the 8-bit CRC32 of the encoded binary part
crc32=<8 char hexvalue> Representing the 8-bit CRC32 of the encoded binary -
wrote on 12 Jun 2012, 17:48 last edited by
I found the (simple) problem!
In NNTP protocol some lines (I read line by line now) begins with a double-dot, this must detect and replace with a single dot, that's it! All CRCs are conform now!
Thanks to all for help anyway!
1/9