Mercurial > trustbridge
annotate ui/downloader_win.cpp @ 1176:c8f698ca6355
(issue128) Rename cinst to trustbridge-certificate-installer
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 22 Sep 2014 11:34:06 +0200 |
parents | 09bb19e5e369 |
children | 82fab0c689bf |
rev | line source |
---|---|
404 | 1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
7 */ | |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 /** |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 * @file downloader_win.cpp |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
10 * @brief Downloader implementation for Windows |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
11 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 * We use Windows API here instead of Qt because we want to avoid |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 * QtNetworks SSL stack which is based on OpenSSL and so |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 * we might be incompatible with GPL code. Also using the |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
15 * native API means that the security of the SSL implementation |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 * is tied to the security of the system. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
18 */ |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 #include "downloader.h" |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 #ifdef Q_OS_WIN |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
21 #ifndef MYVERSION |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
22 #define MYVERSION "1" |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
23 #endif |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
24 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 #include <windows.h> |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
26 #include <winhttp.h> |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
27 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
28 #include <QDebug> |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
29 #include <QDateTime> |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
30 #include <QSaveFile> |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
31 #include <QFileInfo> |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
32 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
33 #define DEBUG if (1) qDebug() << __PRETTY_FUNCTION__ |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
34 |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
35 #define MAX_SW_SIZE 10485760 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
36 #define MAX_LIST_SIZE 1048576 |
27
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
37 /** @brief Download a file from the Internet |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
38 * |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
39 * @param[in] HSession the session to work in. |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
40 * @param[in] HConnect the connection to use. |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
41 * @param[in] resource the resource to download. |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
42 * @param[in] filename where the file should be saved. |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
43 * @param[in] maxSize maximum amount of bytes to download |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
44 * |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
45 * @returns True if the download was successful. |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
46 */ |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
47 bool downloadFile(HINTERNET hSession, HINTERNET hConnect, |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
48 LPCWSTR resource, const QString &filename, DWORD maxSize); |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
49 |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
50 /** @brief get the last modified header of a resource. |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
51 * |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
52 * On error call getLastError to get extended error information. |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
53 * This function still does not do any networking but only initializes |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
54 * it. |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
55 * |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
56 * @param[in] HSession the session to work in. |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
57 * @param[in] HConnect the connection to use. |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
58 * @param[in] resource the resource to check the last-modified date on |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
59 * |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
60 * @returns the last modified date or a null datetime in case of errors |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
61 */ |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
62 QDateTime getLastModifiedHeader(HINTERNET hSession, |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
63 HINTERNET hConnect, LPCWSTR resource); |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
64 |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
65 /** @brief verify that the certificate of the request matches |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
66 * |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
67 * Validates the certificate against the member variable certificate |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
68 * |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
69 * @param[in] hRequest: The request from which to get the certificate |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
70 * |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
71 * @returns True if the certificate exactly matches the one in hRequest |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
72 */ |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
73 |
62cd56cea09b
Start on polarssl Downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
74 bool verifyCertificate(HINTERNET hRequest); |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
75 |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
76 |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
77 #define LIST_RESOURCE "/incoming/aheinecke/test" |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
78 #define SW_RESOURCE "/incoming/aheinecke/test" |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
79 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
80 /** @brief A wrapper around a HINTERNET structure that handles closing |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
81 * |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
82 * Holds a HINTERNET structure and closes it if necessary on destruction. |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
83 * |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
84 */ |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
85 class SmartHINTERNET { |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
86 public: |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
87 SmartHINTERNET() : handle(NULL) {} |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
88 |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
89 ~SmartHINTERNET() { |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
90 if (handle) { |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
91 WinHttpCloseHandle(handle); |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
92 } |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
93 } |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
94 |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
95 HINTERNET handle; |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
96 }; |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
97 |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
98 /** @brief Qt wrapper around FormatMessage |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
99 * |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
100 * @returns The error message of the error that occurred |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
101 */ |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
102 const QString getLastErrorMsg() { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
103 LPWSTR bufPtr = NULL; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
104 DWORD err = GetLastError(); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
105 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
106 FORMAT_MESSAGE_FROM_SYSTEM | |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
107 FORMAT_MESSAGE_IGNORE_INSERTS, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
108 NULL, err, 0, (LPWSTR)&bufPtr, 0, NULL); |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
109 if (!bufPtr) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
110 HMODULE hWinhttp = GetModuleHandleW(L"winhttp"); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
111 if (hWinhttp) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
112 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
113 FORMAT_MESSAGE_FROM_HMODULE | |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
114 FORMAT_MESSAGE_IGNORE_INSERTS, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
115 hWinhttp, HRESULT_CODE(err), 0, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
116 (LPWSTR)&bufPtr, 0, NULL); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
117 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
118 } |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
119 const QString result = |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
120 (bufPtr) ? QString::fromUtf16((const ushort*)bufPtr).trimmed() : |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
121 QString("Unknown Error %1").arg(err); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
122 LocalFree(bufPtr); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
123 return result; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
124 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
125 |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
126 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
127 /** @brief open a session with appropriate proxy settings |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
128 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
129 * @param[inout] *pHSession pointer to a HInternet structure |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
130 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
131 * On error call getLastError to get extended error information. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
132 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
133 * @returns True on success, false on error. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
134 */ |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
135 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
136 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
137 bool openSession(HINTERNET *pHSession) |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
138 { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
139 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
140 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
141 DEBUG; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
142 if (!pHSession) { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
143 SetLastError(ERROR_INVALID_PARAMETER); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
144 return false; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
145 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
146 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
147 memset(&proxyConfig, 0, sizeof (WINHTTP_CURRENT_USER_IE_PROXY_CONFIG)); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
148 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
149 if (WinHttpGetIEProxyConfigForCurrentUser(&proxyConfig)) { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
150 if (proxyConfig.fAutoDetect) { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
151 // TODO Handle this |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
152 qDebug() << "Autodetect is set"; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
153 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
154 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
155 if (proxyConfig.lpszProxy || proxyConfig.lpszProxyBypass) { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
156 DEBUG << "Using proxies."; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
157 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
158 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
159 if (proxyConfig.lpszProxy) { |
409
09bb19e5e369
Remove m13 mentions and change test certificate to intevation.de
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
160 *pHSession = WinHttpOpen(L"TrustBridge "MYVERSION, |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
161 WINHTTP_ACCESS_TYPE_NAMED_PROXY, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
162 proxyConfig.lpszProxy, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
163 proxyConfig.lpszProxyBypass, 0); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
164 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
165 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
166 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
167 if (!*pHSession) { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
168 DEBUG << "No IE Proxy falling back to default proxy"; |
409
09bb19e5e369
Remove m13 mentions and change test certificate to intevation.de
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
169 *pHSession = WinHttpOpen(L"TrustBridge "MYVERSION, |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
170 WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
171 WINHTTP_NO_PROXY_NAME, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
172 WINHTTP_NO_PROXY_BYPASS, 0); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
173 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
174 // Cleanup |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
175 if (proxyConfig.lpszAutoConfigUrl) { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
176 GlobalFree(proxyConfig.lpszAutoConfigUrl); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
177 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
178 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
179 if (proxyConfig.lpszProxy) { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
180 GlobalFree(proxyConfig.lpszProxy); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
181 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
182 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
183 if (proxyConfig.lpszProxyBypass) { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
184 GlobalFree(proxyConfig.lpszProxyBypass); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
185 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
186 return *pHSession; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
187 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
188 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
189 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
190 /** @brief initialize a connection in the session |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
191 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
192 * @param[in] HSession the session to work in. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
193 * @param[inout] *pHConnect pointer to the connection. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
194 * @param[in] url pointer to the URL in wchar representation. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
195 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
196 * On error call getLastError to get extended error information. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
197 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
198 * @returns True on success, false on error. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
199 */ |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
200 bool initializeConnection(HINTERNET hSession, HINTERNET *pHConnect, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
201 LPCWSTR url) |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
202 { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
203 DEBUG; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
204 if (!hSession || !pHConnect) { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
205 SetLastError(ERROR_INVALID_PARAMETER); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
206 return false; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
207 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
208 // Initialize connection. No request is done here. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
209 *pHConnect = WinHttpConnect(hSession, url, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
210 INTERNET_DEFAULT_HTTPS_PORT, 0); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
211 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
212 return *pHConnect; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
213 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
214 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
215 /** @brief Create a request |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
216 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
217 * @param[in] HSession the session to work in. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
218 * @param[in] HConnect the connection to use. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
219 * @param[inout] *pHRequest pointer to the request structure to be filled. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
220 * @param[in] requestType the HTTP request to be made default is GET |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
221 * @param[in] resource pointer to the resource to request in wchar |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
222 * representation. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
223 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
224 * On error call getLastError to get extended error information. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
225 * This function still does not do any networking but only initializes |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
226 * it. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
227 * |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
228 * @returns True on success, false on error. |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
229 */ |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
230 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
231 bool createRequest(HINTERNET hSession, HINTERNET hConnect, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
232 HINTERNET *pHRequest, LPCWSTR requestType, LPCWSTR resource) |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
233 { |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
234 DWORD dwSSLFlag; |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
235 DEBUG; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
236 if (!hSession || !hConnect || !pHRequest) { |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
237 SetLastError(ERROR_INVALID_PARAMETER); |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
238 return false; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
239 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
240 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
241 *pHRequest = WinHttpOpenRequest(hConnect, requestType, resource, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
242 NULL, WINHTTP_NO_REFERER, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
243 WINHTTP_DEFAULT_ACCEPT_TYPES, |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
244 WINHTTP_FLAG_SECURE); |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
245 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
246 dwSSLFlag = SECURITY_FLAG_IGNORE_UNKNOWN_CA; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
247 dwSSLFlag |= SECURITY_FLAG_IGNORE_CERT_DATE_INVALID; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
248 dwSSLFlag |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
249 dwSSLFlag |= SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
250 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
251 WinHttpSetOption(*pHRequest, WINHTTP_OPTION_SECURITY_FLAGS, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
252 &dwSSLFlag, sizeof(dwSSLFlag)); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
253 |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
254 return *pHRequest; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
255 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
256 |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
257 bool Downloader::verifyCertificate(HINTERNET hRequest) |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
258 { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
259 CERT_CONTEXT *certContext = NULL; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
260 DWORD certContextLen = sizeof(CERT_CONTEXT); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
261 bool retval = false; |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
262 |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
263 if (!WinHttpQueryOption(hRequest, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
264 WINHTTP_OPTION_SERVER_CERT_CONTEXT, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
265 &certContext, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
266 &certContextLen)) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
267 DEBUG << "Unable to get server certificate"; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
268 return false; |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
269 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
270 |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
271 QByteArray serverCert ((const char *) certContext->pbCertEncoded, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
272 certContext->cbCertEncoded); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
273 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
274 retval = (serverCert == mCert); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
275 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
276 if (!retval) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
277 DEBUG << "Certificate is not the same as the pinned one!" |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
278 << "Base64 cert: " << serverCert.toBase64(); |
18
f4f957c58e0a
Move listuitol and add cert pinning with a test certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
17
diff
changeset
|
279 emit error("Invalid certificate", InvalidCertificate); |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
280 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
281 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
282 CertFreeCertificateContext(certContext); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
283 return retval; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
284 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
285 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
286 QDateTime Downloader::getLastModifiedHeader(HINTERNET hSession, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
287 HINTERNET hConnect, LPCWSTR resource) |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
288 { |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
289 SmartHINTERNET sHRequest; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
290 SYSTEMTIME lMod; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
291 DWORD sizeOfSystemtime = sizeof (SYSTEMTIME); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
292 QDateTime retval; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
293 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
294 memset(&lMod, 0, sizeof (SYSTEMTIME)); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
295 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
296 if (!hSession || !hConnect || !resource) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
297 SetLastError(ERROR_INVALID_PARAMETER); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
298 return retval; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
299 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
300 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
301 if (!createRequest(hSession, hConnect, &sHRequest.handle, L"HEAD", |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
302 resource)) { |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
303 return retval; |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
304 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
305 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
306 if (!WinHttpSendRequest(sHRequest.handle, |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
307 WINHTTP_NO_ADDITIONAL_HEADERS, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
308 0, WINHTTP_NO_REQUEST_DATA, 0, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
309 0, 0)) { |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
310 return retval; |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
311 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
312 |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
313 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
314 if (!WinHttpReceiveResponse(sHRequest.handle, NULL)) { |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
315 return retval; |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
316 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
317 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
318 if (!verifyCertificate(sHRequest.handle)) { |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
319 DEBUG << "Certificate verification failed"; |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
320 return retval; |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
321 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
322 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
323 if (!(WinHttpQueryHeaders(sHRequest.handle, |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
324 WINHTTP_QUERY_LAST_MODIFIED | |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
325 WINHTTP_QUERY_FLAG_SYSTEMTIME, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
326 NULL, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
327 &lMod, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
328 &sizeOfSystemtime, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
329 WINHTTP_NO_HEADER_INDEX))) { |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
330 return retval; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
331 } |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
332 |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
333 retval = QDateTime(QDate(lMod.wYear, lMod.wMonth, lMod.wDay), |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
334 QTime(lMod.wHour, lMod.wMinute, lMod.wSecond, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
335 lMod.wMilliseconds), |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
336 Qt::UTC); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
337 return retval; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
338 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
339 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
340 bool Downloader::downloadFile(HINTERNET hSession, HINTERNET hConnect, |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
341 LPCWSTR resource, const QString &fileName, DWORD maxSize) |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
342 { |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
343 SmartHINTERNET sHRequest; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
344 bool retval = false; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
345 DWORD bytesAvailable = 0, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
346 bytesRead = 0, |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
347 totalDownloaded = 0, |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
348 contentLength = 0, |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
349 sizeOfDWORD = sizeof (DWORD); |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
350 |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
351 QSaveFile outputFile(fileName); |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
352 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
353 if (!hSession || !hConnect || !resource) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
354 SetLastError(ERROR_INVALID_PARAMETER); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
355 return retval; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
356 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
357 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
358 if (!createRequest(hSession, hConnect, &sHRequest.handle, L"GET", |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
359 resource)) { |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
360 return retval; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
361 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
362 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
363 if (!WinHttpSendRequest(sHRequest.handle, |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
364 WINHTTP_NO_ADDITIONAL_HEADERS, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
365 0, WINHTTP_NO_REQUEST_DATA, 0, |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
366 0, 0)) { |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
367 return retval; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
368 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
369 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
370 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
371 if (!WinHttpReceiveResponse(sHRequest.handle, NULL)) { |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
372 return retval; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
373 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
374 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
375 if (!verifyCertificate(sHRequest.handle)) { |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
376 DEBUG << "Certificate verification failed"; |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
377 return retval; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
378 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
379 |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
380 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
381 if (!(WinHttpQueryHeaders(sHRequest.handle, |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
382 WINHTTP_QUERY_CONTENT_LENGTH | |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
383 WINHTTP_QUERY_FLAG_NUMBER, |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
384 NULL, |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
385 &contentLength, |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
386 &sizeOfDWORD, |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
387 WINHTTP_NO_HEADER_INDEX))) { |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
388 // Continue anyway as we later really check how |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
389 // much we download. |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
390 DEBUG << "No content-length"; |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
391 } |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
392 |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
393 if (contentLength > maxSize) { |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
394 return retval; |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
395 } |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
396 |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
397 if (contentLength) { |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
398 QFileInfo finf(fileName); |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
399 if (finf.exists() && finf.isReadable() && |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
400 finf.size() == contentLength) { |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
401 // We already have data of the same size |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
402 // No need to waste bandwidth. |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
403 DEBUG << "Skipping download because file exists"; |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
404 retval = true; |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
405 return retval; |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
406 } |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
407 } |
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
408 |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
409 // Open / Create the file to write to. |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
410 if (!outputFile.open(QIODevice::WriteOnly)) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
411 DEBUG << "Failed to open file"; |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
412 return retval; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
413 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
414 |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
415 DEBUG << "output file size: " << outputFile.size(); |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
416 do |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
417 { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
418 char outBuf[8192]; // 8KB is the internal buffer size of winhttp |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
419 memset(outBuf, 0, sizeof(outBuf)); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
420 bytesRead = 0; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
421 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
422 if (!WinHttpQueryDataAvailable(sHRequest.handle, &bytesAvailable)) { |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
423 DEBUG << "Querying for available data failed"; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
424 retval = false; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
425 break; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
426 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
427 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
428 if (!bytesAvailable) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
429 // Might indicate that we are done. |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
430 break; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
431 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
432 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
433 if (bytesAvailable > maxSize) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
434 DEBUG << "File to large"; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
435 retval = false; |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
436 SetLastError(ERROR_INVALID_DATA); |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
437 break; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
438 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
439 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
440 if (!WinHttpReadData(sHRequest.handle, (LPVOID)outBuf, |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
441 sizeof(outBuf), &bytesRead)) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
442 DEBUG << "Error reading data"; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
443 break; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
444 } else { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
445 if (bytesRead) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
446 // Write data to file. |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
447 if (outputFile.write(outBuf, bytesRead) != |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
448 bytesRead) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
449 DEBUG << "Error writing to file."; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
450 retval = false; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
451 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
452 // Completed a read / write cycle. If not error follows |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
453 // the download was successful. |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
454 retval = true; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
455 } else { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
456 // Should not happen as we queried for available |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
457 // bytes before and the function did not return an |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
458 // error. |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
459 DEBUG << "Unable to read available data"; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
460 retval = false; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
461 break; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
462 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
463 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
464 totalDownloaded += bytesRead; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
465 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
466 if (totalDownloaded > maxSize) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
467 DEBUG << "Downloaded too much data. Breaking."; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
468 retval = false; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
469 break; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
470 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
471 } while (bytesAvailable > 0); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
472 |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
473 if (retval && outputFile.isOpen()) { |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
474 // Actually save the file to disk / move to homedir |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
475 retval = outputFile.commit(); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
476 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
477 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
478 return retval; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
479 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
480 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
481 void Downloader::run() { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
482 bool results = false; |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
483 SmartHINTERNET sHSession; |
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
484 SmartHINTERNET sHConnect; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
485 wchar_t wUrl[mUrl.size() + 1]; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
486 QDateTime lastModifiedSoftware; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
487 QDateTime lastModifiedList; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
488 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
489 int rc = 0; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
490 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
491 memset(wUrl, 0, sizeof (wchar_t) * (mUrl.size() + 1)); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
492 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
493 rc = mUrl.toWCharArray(wUrl); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
494 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
495 if (rc != mUrl.size()) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
496 DEBUG << "Problem converting to wchar array"; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
497 return; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
498 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
499 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
500 // Should not be necessary because we initialized the memory |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
501 wUrl[rc] = '\0'; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
502 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
503 // Initialize connection |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
504 if (!openSession(&sHConnect.handle)) { |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
505 DEBUG << "Failed to open session: " << getLastErrorMsg(); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
506 return; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
507 } |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
508 if (!initializeConnection(sHConnect.handle, &sHConnect.handle, wUrl)) { |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
509 DEBUG << "Failed to initialize connection: " << getLastErrorMsg(); |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
510 return; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
511 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
512 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
513 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
514 lastModifiedSoftware = getLastModifiedHeader(sHConnect.handle, sHConnect.handle, |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
515 L""SW_RESOURCE); |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
516 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
517 lastModifiedList = getLastModifiedHeader(sHConnect.handle, sHConnect.handle, |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
518 L""LIST_RESOURCE); |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
519 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
520 if (!lastModifiedList.isValid() || !lastModifiedSoftware.isValid()) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
521 DEBUG << "Could not read headers: " << getLastErrorMsg(); |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
522 return; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
523 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
524 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
525 if (!mLastModSW.isValid() || lastModifiedSoftware > mLastModSW) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
526 QString dataDirectory = getDataDirectory(); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
527 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
528 if (dataDirectory.isEmpty()) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
529 DEBUG << "Failed to get data directory"; |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
530 return; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
531 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
532 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
533 QString fileName = dataDirectory.append("/SW-") |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
534 .append(lastModifiedSoftware.toString("yyyymmddHHmmss")) |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
535 .append(".exe"); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
536 |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
537 DEBUG << "fileName: " << fileName; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
538 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
539 if (!downloadFile(sHConnect.handle, sHConnect.handle, L""SW_RESOURCE, |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
540 fileName, MAX_SW_SIZE)) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
541 DEBUG << "Error downloading File: " << getLastErrorMsg(); |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
542 return; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
543 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
544 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
545 emit newSoftwareAvailable(fileName, lastModifiedSoftware); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
546 } else if (!mLastModList.isValid() || lastModifiedList > mLastModList) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
547 QString dataDirectory = getDataDirectory(); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
548 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
549 if (dataDirectory.isEmpty()) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
550 DEBUG << "Failed to get data directory"; |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
551 return; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
552 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
553 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
554 QString fileName = dataDirectory.append("/list-") |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
555 .append(lastModifiedSoftware.toString("yyyymmddHHmmss")) |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
556 .append(".txt"); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
557 |
17
c12825a651ed
Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents:
15
diff
changeset
|
558 DEBUG << "fileName: " << fileName; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
559 |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
560 if (!downloadFile(sHConnect.handle, sHConnect.handle, L""LIST_RESOURCE, |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
561 fileName, MAX_LIST_SIZE)) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
562 DEBUG << "Error downloading File: " << getLastErrorMsg(); |
23
7d07d261b003
Wrap HINTERNET handles in a class to take advantage of scoping
Andre Heinecke <aheinecke@intevation.de>
parents:
20
diff
changeset
|
563 return; |
15
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
564 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
565 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
566 emit newListAvailable(fileName, lastModifiedList); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
567 } |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
568 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
569 DEBUG << "SW date: " << lastModifiedSoftware; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
570 DEBUG << "List date: " << lastModifiedList; |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
571 |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
572 if (!results) { |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
573 // Report any errors. |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
574 DEBUG << "Error" << GetLastError(); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
575 emit error(tr("Unknown Problem when connecting"), ErrUnknown); |
95e1b6edf2fc
Implement more downloader functionality for Windows
Andre Heinecke <aheinecke@intevation.de>
parents:
11
diff
changeset
|
576 } |
20
fec1a610d43f
Mark usage of goto with TODOs to remove them
Andre Heinecke <aheinecke@intevation.de>
parents:
18
diff
changeset
|
577 |
11
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
578 return; |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
579 } |
7e2f14c7aba2
Split up downloader component and further implement it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
580 #endif |