[1382] | 1 | /* -------------------------------------------------------------------------
|
---|
| 2 | * BKG NTRIP Client
|
---|
| 3 | * -------------------------------------------------------------------------
|
---|
| 4 | *
|
---|
[1383] | 5 | * Class: bncNetQueryV1
|
---|
[1382] | 6 | *
|
---|
| 7 | * Purpose: Blocking Network Requests (NTRIP Version 1)
|
---|
| 8 | *
|
---|
| 9 | * Author: L. Mervart
|
---|
| 10 | *
|
---|
| 11 | * Created: 27-Dec-2008
|
---|
| 12 | *
|
---|
| 13 | * Changes:
|
---|
| 14 | *
|
---|
| 15 | * -----------------------------------------------------------------------*/
|
---|
| 16 |
|
---|
| 17 | #include <iostream>
|
---|
| 18 | #include <iomanip>
|
---|
| 19 |
|
---|
[1385] | 20 | #include "bncnetqueryv1.h"
|
---|
[1382] | 21 |
|
---|
| 22 | using namespace std;
|
---|
| 23 |
|
---|
| 24 | #define BNCVERSION "1.7"
|
---|
| 25 |
|
---|
| 26 | // Constructor
|
---|
| 27 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1383] | 28 | bncNetQueryV1::bncNetQueryV1() {
|
---|
[1382] | 29 | _socket = 0;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | // Destructor
|
---|
| 33 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1383] | 34 | bncNetQueryV1::~bncNetQueryV1() {
|
---|
[1382] | 35 | delete _socket;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | //
|
---|
| 39 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1390] | 40 | void bncNetQueryV1::stop() {
|
---|
| 41 |
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | //
|
---|
| 45 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1384] | 46 | void bncNetQueryV1::waitForRequestResult(const QUrl& url, QByteArray& outData) {
|
---|
[1382] | 47 | }
|
---|
| 48 |
|
---|
| 49 | //
|
---|
| 50 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1384] | 51 | void bncNetQueryV1::waitForReadyRead(QByteArray& outData) {
|
---|
[1382] | 52 |
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | // Connect to Caster, send the Request
|
---|
| 56 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1384] | 57 | void bncNetQueryV1::startRequest(const QUrl& url, const QByteArray& gga) {
|
---|
[1382] | 58 |
|
---|
[1385] | 59 | const int timeOut = 5000;
|
---|
| 60 |
|
---|
| 61 | _status = running;
|
---|
| 62 |
|
---|
[1382] | 63 | delete _socket;
|
---|
| 64 | _socket = new QTcpSocket();
|
---|
| 65 |
|
---|
[1385] | 66 | // Default scheme and path
|
---|
| 67 | // -----------------------
|
---|
| 68 | QUrl urlLoc(url);
|
---|
| 69 | if (urlLoc.scheme().isEmpty()) {
|
---|
| 70 | urlLoc.setScheme("http");
|
---|
| 71 | }
|
---|
| 72 | if (urlLoc.path().isEmpty()) {
|
---|
| 73 | urlLoc.setPath("/");
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[1382] | 76 | // Connect the Socket
|
---|
| 77 | // ------------------
|
---|
| 78 | QSettings settings;
|
---|
| 79 | QString proxyHost = settings.value("proxyHost").toString();
|
---|
| 80 | int proxyPort = settings.value("proxyPort").toInt();
|
---|
| 81 |
|
---|
| 82 | if ( proxyHost.isEmpty() ) {
|
---|
[1385] | 83 | _socket->connectToHost(urlLoc.host(), urlLoc.port());
|
---|
[1382] | 84 | }
|
---|
| 85 | else {
|
---|
| 86 | _socket->connectToHost(proxyHost, proxyPort);
|
---|
| 87 | }
|
---|
| 88 | if (!_socket->waitForConnected(timeOut)) {
|
---|
| 89 | delete _socket;
|
---|
| 90 | _socket = 0;
|
---|
[1385] | 91 | _status = error;
|
---|
| 92 | return;
|
---|
[1382] | 93 | }
|
---|
| 94 |
|
---|
| 95 | // Send Request
|
---|
| 96 | // ------------
|
---|
[1385] | 97 | QString uName = QUrl::fromPercentEncoding(urlLoc.userName().toAscii());
|
---|
| 98 | QString passW = QUrl::fromPercentEncoding(urlLoc.password().toAscii());
|
---|
[1382] | 99 | QByteArray userAndPwd;
|
---|
| 100 |
|
---|
[1385] | 101 | if(!uName.isEmpty() || !passW.isEmpty()) {
|
---|
[1382] | 102 | userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" +
|
---|
| 103 | passW.toAscii()).toBase64() + "\r\n";
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | QByteArray reqStr;
|
---|
| 107 | if ( proxyHost.isEmpty() ) {
|
---|
[1385] | 108 | if (urlLoc.path().indexOf("/") != 0) urlLoc.setPath("/");
|
---|
| 109 | reqStr = "GET " + urlLoc.path().toAscii() + " HTTP/1.0\r\n"
|
---|
[1382] | 110 | + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n"
|
---|
| 111 | + userAndPwd + "\r\n";
|
---|
| 112 | } else {
|
---|
[1385] | 113 | reqStr = "GET " + urlLoc.toEncoded() + " HTTP/1.0\r\n"
|
---|
[1382] | 114 | + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n"
|
---|
[1385] | 115 | + "Host: " + urlLoc.host().toAscii() + "\r\n"
|
---|
[1382] | 116 | + userAndPwd + "\r\n";
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | // NMEA string to handle VRS stream
|
---|
| 120 | // --------------------------------
|
---|
[1385] | 121 | if (!gga.isEmpty()) {
|
---|
| 122 | reqStr += gga + "\r\n";
|
---|
[1382] | 123 | }
|
---|
| 124 |
|
---|
| 125 | _socket->write(reqStr, reqStr.length());
|
---|
| 126 |
|
---|
| 127 | if (!_socket->waitForBytesWritten(timeOut)) {
|
---|
| 128 | delete _socket;
|
---|
| 129 | _socket = 0;
|
---|
[1385] | 130 | _status = error;
|
---|
[1382] | 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|