comparison ui/downloader.cpp @ 76:63b79d135631

Remove QTextStream usage. The QTextStream usage in this way caused a segmentation fault on Windows
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 19 Mar 2014 16:33:25 +0000
parents 7e304573ebd1
children 17e1c8f37d72
comparison
equal deleted inserted replaced
75:ec0f4efefb7b 76:63b79d135631
6 6
7 #include <QFile> 7 #include <QFile>
8 #include <QDir> 8 #include <QDir>
9 #include <QDebug> 9 #include <QDebug>
10 #include <QStandardPaths> 10 #include <QStandardPaths>
11 #include <QTextStream>
12 #include <QLocale> 11 #include <QLocale>
13 #include <QSaveFile> 12 #include <QSaveFile>
14 13
15 #include <polarssl/net.h> 14 #include <polarssl/net.h>
16 #include <polarssl/ssl.h> 15 #include <polarssl/ssl.h>
66 QMap<QString, QString> Downloader::parseHeaders(QByteArray *data) 65 QMap<QString, QString> Downloader::parseHeaders(QByteArray *data)
67 { 66 {
68 int bodyStart = data->indexOf("\r\n\r\n"); 67 int bodyStart = data->indexOf("\r\n\r\n");
69 QMap<QString, QString> retval; 68 QMap<QString, QString> retval;
70 QByteArray headers; 69 QByteArray headers;
71 QTextStream responseStream(&headers); 70 QString response(*data);
72 if (bodyStart == -1) { 71 if (bodyStart == -1) {
73 qDebug() << "Could not find header end."; 72 qDebug() << "Could not find header end.";
74 emit error(tr("Invalid response"), 73 emit error(tr("Invalid response"),
75 SSLConnection::InvalidResponse); 74 SSLConnection::InvalidResponse);
76 return retval; 75 return retval;
78 77
79 /* Take the headers with one additional line break */ 78 /* Take the headers with one additional line break */
80 headers = data->left(bodyStart + 2); 79 headers = data->left(bodyStart + 2);
81 /* Chop off the head */ 80 /* Chop off the head */
82 81
83 while (1) { 82 foreach (const QString& line, response.split("\r\n")) {
84 QString line = responseStream.readLine();
85 int sepPos = -1; 83 int sepPos = -1;
86 if (line.isNull()) {
87 break;
88 }
89 sepPos = line.indexOf(": "); 84 sepPos = line.indexOf(": ");
90 if (sepPos == -1) { 85 if (sepPos == -1) {
91 continue; 86 continue;
92 } 87 }
93 QString key = line.left(sepPos); 88 QString key = line.left(sepPos);
101 } 96 }
102 97
103 QDateTime Downloader::getLastModifiedHeader(const QString &resource) { 98 QDateTime Downloader::getLastModifiedHeader(const QString &resource) {
104 int ret = -1; 99 int ret = -1;
105 QByteArray response; 100 QByteArray response;
106 QTextStream responseStream(&response);
107 QLocale cLocale = QLocale::c(); 101 QLocale cLocale = QLocale::c();
108 QMap<QString, QString> headers; 102 QMap<QString, QString> headers;
109 QString headRequest = 103 QString headRequest =
110 QString::fromLatin1("HEAD %1 HTTP/1.0\r\n\r\n").arg(resource); 104 QString::fromLatin1("HEAD %1 HTTP/1.0\r\n\r\n").arg(resource);
111 105

http://wald.intevation.org/projects/trustbridge/