source: ntrip/trunk/BNC/bncnetqueryrtp.cpp@ 1410

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

* empty log message *

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