1 | /* -------------------------------------------------------------------------
|
---|
2 | * BKG NTRIP Client
|
---|
3 | * -------------------------------------------------------------------------
|
---|
4 | *
|
---|
5 | * Class: bncNetRequest
|
---|
6 | *
|
---|
7 | * Purpose: Prepare and submit network request
|
---|
8 | *
|
---|
9 | * Author: L. Mervart
|
---|
10 | *
|
---|
11 | * Created: 09-Dec-2008
|
---|
12 | *
|
---|
13 | * Changes:
|
---|
14 | *
|
---|
15 | * -----------------------------------------------------------------------*/
|
---|
16 |
|
---|
17 | #include <iostream>
|
---|
18 | #include <iomanip>
|
---|
19 |
|
---|
20 | #include "bncnetrequest.h"
|
---|
21 |
|
---|
22 | using namespace std;
|
---|
23 |
|
---|
24 | #define AGENTVERSION "1.7"
|
---|
25 |
|
---|
26 | // Constructor
|
---|
27 | ////////////////////////////////////////////////////////////////////////////
|
---|
28 | bncNetRequest::bncNetRequest() {
|
---|
29 | _manager = 0;
|
---|
30 | _reply = 0;
|
---|
31 | }
|
---|
32 |
|
---|
33 | // Destructor
|
---|
34 | ////////////////////////////////////////////////////////////////////////////
|
---|
35 | bncNetRequest::~bncNetRequest() {
|
---|
36 | delete _reply;
|
---|
37 | delete _manager;
|
---|
38 | }
|
---|
39 |
|
---|
40 | // Network Request
|
---|
41 | ////////////////////////////////////////////////////////////////////////////
|
---|
42 | t_irc bncNetRequest::request(const QUrl& mountPoint, const QByteArray& ggaStr) {
|
---|
43 |
|
---|
44 | // Network Access Manager
|
---|
45 | // ----------------------
|
---|
46 | if (_manager == 0) {
|
---|
47 | _manager = new QNetworkAccessManager(this);
|
---|
48 | }
|
---|
49 | else {
|
---|
50 | return failure;
|
---|
51 | }
|
---|
52 |
|
---|
53 | // Proxy
|
---|
54 | // -----
|
---|
55 | QSettings settings;
|
---|
56 | QString proxyHost = settings.value("proxyHost").toString();
|
---|
57 | if (proxyHost.isEmpty()) {
|
---|
58 | QNetworkProxy proxy(QNetworkProxy::NoProxy);
|
---|
59 | _manager->setProxy(proxy);
|
---|
60 | }
|
---|
61 | else {
|
---|
62 | QNetworkProxy proxy(QNetworkProxy::Socks5Proxy);
|
---|
63 | proxy.setHostName(proxyHost);
|
---|
64 | proxy.setPort(settings.value("proxyPort").toInt());
|
---|
65 | _manager->setProxy(proxy);
|
---|
66 | }
|
---|
67 |
|
---|
68 | connect(_manager, SIGNAL(finished(QNetworkReply*)),
|
---|
69 | this, SLOT(slotReplyFinished(QNetworkReply*)));
|
---|
70 |
|
---|
71 | // Network Request
|
---|
72 | // ---------------
|
---|
73 | /// QNetworkRequest request;
|
---|
74 | /// request.setUrl(mountPoint);
|
---|
75 | /// request.setRawHeader("User-Agent", "NTRIP BNC/" AGENTVERSION);
|
---|
76 | /// request.setRawHeader("Host", mountPoint.host().toAscii());
|
---|
77 | ///
|
---|
78 | /// QString uName = QUrl::fromPercentEncoding(mountPoint.userName().toAscii());
|
---|
79 | /// QString passW = QUrl::fromPercentEncoding(mountPoint.password().toAscii());
|
---|
80 | /// if (!uName.isEmpty() || !passW.isEmpty()) {
|
---|
81 | /// QByteArray userAndPwd = "Basic " + (uName.toAscii() + ":" +
|
---|
82 | /// passW.toAscii()).toBase64();
|
---|
83 | /// request.setRawHeader("Authorization", userAndPwd);
|
---|
84 | /// }
|
---|
85 | ///
|
---|
86 | /// if (!ggaStr.isEmpty()) {
|
---|
87 | /// request.setRawHeader("", ggaStr);
|
---|
88 | /// }
|
---|
89 |
|
---|
90 | QHttpRequestHeader header("GET", "/CBRU0", 1, 1);
|
---|
91 |
|
---|
92 | header.addValue("User-Agent", "NTRIP BNC/1.7");
|
---|
93 |
|
---|
94 | QByteArray userAndPwd = "Basic " + QByteArray("cvutlukes:monitoring").toBase64();
|
---|
95 | header.addValue("Authorization", userAndPwd);
|
---|
96 |
|
---|
97 | QHttp* http = new QHttp("czeposr.cuzk.cz", 2101);
|
---|
98 |
|
---|
99 | connect(http, SIGNAL(readyRead(const QHttpResponseHeader&)),
|
---|
100 | this, SLOT(slotReadyRead()));
|
---|
101 |
|
---|
102 | QBuffer buffer;
|
---|
103 | http->request(header, 0, &buffer);
|
---|
104 |
|
---|
105 | while (true) {
|
---|
106 | if (buffer.bytesAvailable()) {
|
---|
107 | QByteArray arr = buffer.readAll();
|
---|
108 | cout << arr.data();
|
---|
109 | }
|
---|
110 | else {
|
---|
111 | buffer.waitForReadyRead(1000);
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | return success;
|
---|
117 | }
|
---|
118 |
|
---|
119 | //
|
---|
120 | ////////////////////////////////////////////////////////////////////////////
|
---|
121 | void bncNetRequest::slotReplyFinished(QNetworkReply*) {
|
---|
122 | cout << "slotReplyFinished" << endl;
|
---|
123 | this->deleteLater();
|
---|
124 | }
|
---|
125 |
|
---|
126 | //
|
---|
127 | ////////////////////////////////////////////////////////////////////////////
|
---|
128 | void bncNetRequest::slotReadyRead() {
|
---|
129 | cout << "slotReadyRead" << endl;
|
---|
130 | QByteArray buffer = _reply->readAll();
|
---|
131 | cout << buffer.data();
|
---|
132 | }
|
---|
133 |
|
---|
134 | //
|
---|
135 | ////////////////////////////////////////////////////////////////////////////
|
---|
136 | void bncNetRequest::slotError(QNetworkReply::NetworkError) {
|
---|
137 | cout << "slotError " << _reply->error() << endl
|
---|
138 | << _reply->errorString().toAscii().data() << endl;
|
---|
139 | }
|
---|
140 |
|
---|
141 | //
|
---|
142 | ////////////////////////////////////////////////////////////////////////////
|
---|
143 | void bncNetRequest::slotSslErrors(QList<QSslError>) {
|
---|
144 | cout << "slotSslError" << endl;
|
---|
145 | }
|
---|
146 |
|
---|