source: ntrip/trunk/BNC/bncnetqueryv1.cpp@ 1390

Last change on this file since 1390 was 1390, checked in by mervart, 15 years ago

* empty log message *

File size: 3.3 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncNetQueryV1
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
20#include "bncnetqueryv1.h"
21
22using namespace std;
23
24#define BNCVERSION "1.7"
25
26// Constructor
27////////////////////////////////////////////////////////////////////////////
28bncNetQueryV1::bncNetQueryV1() {
29 _socket = 0;
30}
31
32// Destructor
33////////////////////////////////////////////////////////////////////////////
34bncNetQueryV1::~bncNetQueryV1() {
35 delete _socket;
36}
37
38//
39////////////////////////////////////////////////////////////////////////////
40void bncNetQueryV1::stop() {
41
42}
43
44//
45////////////////////////////////////////////////////////////////////////////
46void bncNetQueryV1::waitForRequestResult(const QUrl& url, QByteArray& outData) {
47}
48
49//
50////////////////////////////////////////////////////////////////////////////
51void bncNetQueryV1::waitForReadyRead(QByteArray& outData) {
52
53}
54
55// Connect to Caster, send the Request
56////////////////////////////////////////////////////////////////////////////
57void bncNetQueryV1::startRequest(const QUrl& url, const QByteArray& gga) {
58
59 const int timeOut = 5000;
60
61 _status = running;
62
63 delete _socket;
64 _socket = new QTcpSocket();
65
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
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() ) {
83 _socket->connectToHost(urlLoc.host(), urlLoc.port());
84 }
85 else {
86 _socket->connectToHost(proxyHost, proxyPort);
87 }
88 if (!_socket->waitForConnected(timeOut)) {
89 delete _socket;
90 _socket = 0;
91 _status = error;
92 return;
93 }
94
95 // Send Request
96 // ------------
97 QString uName = QUrl::fromPercentEncoding(urlLoc.userName().toAscii());
98 QString passW = QUrl::fromPercentEncoding(urlLoc.password().toAscii());
99 QByteArray userAndPwd;
100
101 if(!uName.isEmpty() || !passW.isEmpty()) {
102 userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" +
103 passW.toAscii()).toBase64() + "\r\n";
104 }
105
106 QByteArray reqStr;
107 if ( proxyHost.isEmpty() ) {
108 if (urlLoc.path().indexOf("/") != 0) urlLoc.setPath("/");
109 reqStr = "GET " + urlLoc.path().toAscii() + " HTTP/1.0\r\n"
110 + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n"
111 + userAndPwd + "\r\n";
112 } else {
113 reqStr = "GET " + urlLoc.toEncoded() + " HTTP/1.0\r\n"
114 + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n"
115 + "Host: " + urlLoc.host().toAscii() + "\r\n"
116 + userAndPwd + "\r\n";
117 }
118
119 // NMEA string to handle VRS stream
120 // --------------------------------
121 if (!gga.isEmpty()) {
122 reqStr += gga + "\r\n";
123 }
124
125 _socket->write(reqStr, reqStr.length());
126
127 if (!_socket->waitForBytesWritten(timeOut)) {
128 delete _socket;
129 _socket = 0;
130 _status = error;
131 }
132}
133
Note: See TracBrowser for help on using the repository browser.