Changeset 9707 in ntrip for trunk/BNC/src
- Timestamp:
- May 4, 2022, 2:20:06 PM (3 years ago)
- Location:
- trunk/BNC/src/upload
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/src/upload/bncuploadcaster.cpp
r8904 r9707 20 20 #include "bnccore.h" 21 21 #include "bnctableitem.h" 22 #include "bncsettings.h" 22 23 23 24 using namespace std; … … 32 33 int rate) { 33 34 _mountpoint = mountpoint; 34 _ outHost= outHost;35 _ outPort= outPort;35 _casterOutHost = outHost; 36 _casterOutPort = outPort; 36 37 _ntripVersion = ntripVersion; 38 (_ntripVersion == "2s") ? _secure = true : _secure = false; 39 _postExtension = ""; 37 40 _userName = userName; 38 41 _password = password; … … 41 44 _iRow = iRow; 42 45 _rate = rate; 46 43 47 if (_rate < 0) { 44 48 _rate = 0; … … 48 52 } 49 53 _isToBeDeleted = false; 54 55 if (!QSslSocket::supportsSsl()) { 56 BNC_CORE->slotMessage("No SSL support, install OpenSSL run-time libraries", true); 57 deleteSafely(); 58 } 59 60 if (_ntripVersion != "1") { 61 bncSettings settings; 62 _proxyHost = settings.value("proxyHost").toString(); 63 _proxyPort = settings.value("proxyPort").toInt(); 64 _sslIgnoreErrors = (Qt::CheckState(settings.value("sslIgnoreErrors").toInt()) == Qt::Checked); 65 if (_secure) { 66 _casterOutPort = 443; 67 _postExtension = QString("https://%1:%2").arg(_casterOutHost).arg(_casterOutPort); 68 } 69 else { 70 _postExtension = QString("http://%1:%2").arg(_casterOutHost).arg(_casterOutPort); 71 } 72 } 50 73 51 74 connect(this, SIGNAL(newMessage(QByteArray,bool)), … … 80 103 } 81 104 if (_outSocket) { 105 disconnect(_outSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), 106 this, SLOT(slotProxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*))); 82 107 delete _outSocket; 83 108 } 84 109 } 110 111 // 112 //////////////////////////////////////////////////////////////////////////// 113 void bncUploadCaster::slotProxyAuthenticationRequired(const QNetworkProxy&, 114 QAuthenticator*) { 115 emit newMessage("slotProxyAuthenticationRequired", true); 116 } 117 118 119 /* TSL/SSL 120 //////////////////////////////////////////////////////////////////////////// 121 void bncUploadCaster::slotSslErrors(QList<QSslError> errors) { 122 123 QString msg = "SSL Error\n"; 124 QSslCertificate cert = _outSocket->sslConfiguration().peerCertificate(); 125 if (!cert.isNull()) { 126 msg += QString("Server Certificate Issued by:\n" 127 "%1\n%2\nCannot be verified\n") 128 #if QT_VERSION >= 0x050000 129 .arg(cert.issuerInfo(QSslCertificate::OrganizationalUnitName).at(0)) 130 .arg(cert.issuerInfo(QSslCertificate::Organization).at(0)); 131 #else 132 .arg(cert.issuerInfo(QSslCertificate::OrganizationalUnitName)) 133 .arg(cert.issuerInfo(QSslCertificate::Organization)); 134 #endif 135 } 136 QListIterator<QSslError> it(errors); 137 while (it.hasNext()) { 138 const QSslError& err = it.next(); 139 msg += "\n" + err.errorString(); 140 } 141 142 BNC_CORE->slotMessage(msg.toLatin1(), true); 143 144 if (_sslIgnoreErrors) { 145 _outSocket->ignoreSslErrors(); 146 } 147 else { 148 deleteSafely(); 149 } 150 } 151 */ 85 152 86 153 // Endless Loop … … 97 164 QMutexLocker locker(&_mutex); 98 165 if (_outBuffer.size() > 0) { 99 _outSocket->write(_outBuffer); 100 _outSocket->flush(); 166 if (_ntripVersion == "1") { 167 _outSocket->write(_outBuffer); 168 _outSocket->flush(); 169 } 170 else { 171 QString chunkSize = QString("%1").arg(_outBuffer.size(),0,16,QLatin1Char('0')); 172 QByteArray chunkedData = chunkSize.toLatin1() + "\r\n" + _outBuffer + "\r\n"; 173 _outSocket->write(chunkedData); 174 _outSocket->flush(); 175 } 101 176 emit newBytes(_mountpoint.toLatin1(), _outBuffer.size()); 102 177 } … … 127 202 return; 128 203 } 129 204 130 205 delete _outSocket; _outSocket = 0; 131 206 … … 142 217 } 143 218 144 _outSocket = new QTcpSocket(); 145 _outSocket->setProxy(QNetworkProxy::NoProxy); // Ntrip1: to prevent the usage of system entries 146 _outSocket->connectToHost(_outHost, _outPort); 219 _outSocket = new QSslSocket(); 220 if (_sslIgnoreErrors) { 221 _outSocket->ignoreSslErrors(); 222 } 223 _outSocket->setProxy(QNetworkProxy::NoProxy); // to prevent the usage of system entries 224 if (_ntripVersion == "1") { 225 _outHost = _casterOutHost; 226 _outPort = _casterOutPort; 227 } 228 else { 229 if (!_proxyHost.isEmpty()) { 230 _outHost = _proxyHost; 231 _outPort = _proxyPort; 232 connect(_outSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), 233 this, SLOT(slotProxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*))); 234 } 235 } 236 237 if (!_secure) { 238 _outSocket->connectToHost(_outHost, _outPort); 239 } 240 else { 241 _outSocket->connectToHostEncrypted(_outHost, _outPort);/* 242 if (!_outSocket->waitForEncrypted()) { 243 cout << "waitForEncrypted: " << _outSocket->errorString().toStdString().c_str() << endl;; 244 return; 245 }*/ 246 } 147 247 148 248 const int timeOut = 5000; // 5 seconds 149 249 if (!_outSocket->waitForConnected(timeOut)) { 150 250 emit(newMessage("Broadcaster: Connect timeout for " + _mountpoint.toLatin1() 151 + "(" + _outHost.toLatin1() + "), " + _outSocket->errorString().toLatin1(), true)); 251 + " (" + _outHost.toLatin1()+ ":" + QString("%1) ").arg(_outPort).toLatin1() 252 + _outSocket->errorString().toLatin1(), true)); 152 253 delete _outSocket; 153 254 _outSocket = 0; … … 155 256 } 156 257 157 QByteArray msg = "SOURCE " + _password.toLatin1() + " /" + 158 _mountpoint.toLatin1() + "\r\n" + 159 "Source-Agent: NTRIP BNC/" BNCVERSION "\r\n\r\n"; 160 258 QByteArray msg; 259 if (_ntripVersion == "1") { 260 msg = "SOURCE " + _password.toLatin1() + " /" + _mountpoint.toLatin1() + "\r\n" + 261 "Source-Agent: NTRIP BNC/" BNCVERSION "\r\n\r\n"; 262 } 263 else { 264 msg = "POST " + _postExtension.toLatin1() + "/" + _mountpoint.toLatin1() + " HTTP/1.1\r\n" + 265 "Host: " + _casterOutHost.toLatin1() + "\r\n" + 266 "Ntrip-Version: Ntrip/2.0\r\n" + 267 "Authorization: Basic " + (_userName + ":" + _password).toLatin1().toBase64() + "\r\n" + 268 "User-Agent: NTRIP BNC/" BNCVERSION " (" + BNC_OS + ")\r\n" + 269 "Connection: close\r\n" + 270 "Transfer-Encoding: chunked\r\n\r\n"; 271 } 272 cout << msg.toStdString().c_str(); 161 273 _outSocket->write(msg); 162 274 _outSocket->waitForBytesWritten(); 163 275 164 276 _outSocket->waitForReadyRead(); 165 QByteArray ans = _outSocket->readLine(); 277 QByteArray ans = _outSocket->readLine();cout << ans.toStdString().c_str() << endl; 166 278 167 279 if (ans.indexOf("OK") == -1) { 168 280 delete _outSocket; 169 281 _outSocket = 0; 170 emit(newMessage("Broadcaster: Connection broken for " + _mountpoint.toLatin1() , true));282 emit(newMessage("Broadcaster: Connection broken for " + _mountpoint.toLatin1() + ": " + ans.left(ans.length()-2), true)); 171 283 } 172 284 else { -
trunk/BNC/src/upload/bncuploadcaster.h
r8770 r9707 4 4 #include <QDateTime> 5 5 #include <QMutex> 6 #include <Q TcpSocket>6 #include <QSslSocket> 7 7 #include <QNetworkProxy> 8 8 #include <QThread> 9 #include <QSslError> 10 #include <iostream> 11 9 12 10 13 class bncUploadCaster : public QThread { … … 31 34 void newBytes(QByteArray staID, double nbyte); 32 35 36 private slots: 37 void slotProxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*); 38 //void slotSslErrors(QList<QSslError>); 39 33 40 private: 34 41 void open(); … … 38 45 QString _outHost; 39 46 int _outPort; 47 QString _casterOutHost; 48 int _casterOutPort; 49 QString _proxyHost; 50 int _proxyPort; 40 51 QString _userName; 41 52 QString _password; 42 53 QString _ntripVersion; 54 QString _postExtension; 43 55 bool _secure; 44 QTcpSocket* _outSocket; 56 bool _sslIgnoreErrors; 57 QSslSocket* _outSocket; 45 58 int _sOpenTrial; 46 59 QDateTime _outSocketOpenTime;
Note:
See TracChangeset
for help on using the changeset viewer.