Changeset 1370 in ntrip
- Timestamp:
- Dec 28, 2008, 11:23:05 AM (16 years ago)
- Location:
- trunk/BNC
- Files:
-
- 4 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bnc.pro
r1357 r1370 2 2 # Switch to debug configuration 3 3 # ----------------------------- 4 CONFIG -= release5 CONFIG += debug4 CONFIG -= debug 5 CONFIG += release 6 6 7 7 DEFINES += NO_RTCM3_MAIN -
trunk/BNC/bncsocket.cpp
r1368 r1370 32 32 app, SLOT(slotMessage(const QByteArray,bool))); 33 33 _socket = 0; 34 _http = 0; 35 connect(this, SIGNAL(quitEventLoop()), &_eventLoop, SLOT(quit())); 34 _manager = 0; 35 _reply = 0; 36 _eventLoop = new QEventLoop(); 37 connect(this, SIGNAL(quitEventLoop()), _eventLoop, SLOT(quit())); 36 38 } 37 39 … … 39 41 //////////////////////////////////////////////////////////////////////////// 40 42 bncSocket::~bncSocket() { 43 delete _eventLoop; 44 delete _reply; 45 delete _manager; 41 46 delete _socket; 42 delete _http;43 47 } 44 48 … … 46 50 //////////////////////////////////////////////////////////////////////////// 47 51 QAbstractSocket::SocketState bncSocket::state() const { 48 if (_ http) {49 if (_ http->state() != QHttp::Unconnected) {52 if (_manager) { 53 if (_reply) { 50 54 return QAbstractSocket::ConnectedState; 51 55 } … … 73 77 //////////////////////////////////////////////////////////////////////////// 74 78 qint64 bncSocket::bytesAvailable() const { 75 if (_ http) {79 if (_manager) { 76 80 return _buffer.size(); 77 81 } … … 87 91 //////////////////////////////////////////////////////////////////////////// 88 92 bool bncSocket::canReadLine() const { 89 if (_ http) {93 if (_manager) { 90 94 if (_buffer.indexOf('\n') != -1) { 91 95 return true; … … 106 110 //////////////////////////////////////////////////////////////////////////// 107 111 QByteArray bncSocket::readLine() { 108 if (_ http) {112 if (_manager) { 109 113 int ind = _buffer.indexOf('\n'); 110 114 if (ind != -1) { … … 128 132 //////////////////////////////////////////////////////////////////////////// 129 133 void bncSocket::waitForReadyRead(int msecs) { 130 if (_ http) {134 if (_manager) { 131 135 if (bytesAvailable() > 0) { 132 136 return; 133 137 } 134 138 else { 135 _eventLoop .exec(QEventLoop::ExcludeUserInputEvents);139 _eventLoop->exec(QEventLoop::ExcludeUserInputEvents); 136 140 } 137 141 } … … 144 148 //////////////////////////////////////////////////////////////////////////// 145 149 QByteArray bncSocket::read(qint64 maxSize) { 146 if (_ http) {150 if (_manager) { 147 151 QByteArray ret = _buffer.left(maxSize); 148 152 _buffer = _buffer.right(_buffer.size()-maxSize); … … 289 293 // 290 294 //////////////////////////////////////////////////////////////////////////// 291 void bncSocket::slotRequestFinished(int /* id */, bool error) { 292 if (error) { 293 emit newMessage("slotRequestFinished " + 294 _http->errorString().toAscii(), true); 295 } 296 } 297 298 // 299 //////////////////////////////////////////////////////////////////////////// 300 void bncSocket::slotReadyRead(const QHttpResponseHeader&) { 301 _buffer.append(_http->readAll()); 295 void bncSocket::slotReadyRead() { 296 _buffer.append(_reply->readAll()); 302 297 emit quitEventLoop(); 303 298 } … … 305 300 // 306 301 //////////////////////////////////////////////////////////////////////////// 307 void bncSocket::slotDone(bool error) { 308 if (error) { 309 emit newMessage("slotDone " + _http->errorString().toAscii(), true); 310 } 302 void bncSocket::slotReplyFinished() { 311 303 emit quitEventLoop(); 304 } 305 306 // 307 //////////////////////////////////////////////////////////////////////////// 308 void bncSocket::slotError(QNetworkReply::NetworkError) { 309 emit newMessage("slotError " + _reply->errorString().toAscii(), true); 310 } 311 312 // 313 //////////////////////////////////////////////////////////////////////////// 314 void bncSocket::slotSslErrors(const QList<QSslError>&) { 315 emit newMessage("slotSslErrors", true); 312 316 } 313 317 … … 318 322 int timeOut, QString& msg) { 319 323 320 321 delete _http; 322 _http = new QHttp(); 323 324 _http->setHost(url.host()); 324 // Network Access Manager 325 // ---------------------- 326 if (_manager == 0) { 327 _manager = new QNetworkAccessManager(this); 328 } 329 else { 330 return failure; 331 } 332 333 // Default scheme and path 334 // ----------------------- 335 QUrl urlLoc(url); 336 if (urlLoc.scheme().isEmpty()) { 337 urlLoc.setScheme("http"); 338 } 339 if (urlLoc.path().isEmpty()) { 340 urlLoc.setPath("/"); 341 } 325 342 326 343 // Network Request 327 344 // --------------- 328 QString path = url.path(); 329 if (path.isEmpty()) { 330 path = "/"; 331 } 332 QHttpRequestHeader request("GET", path); 333 request.addValue("Host" , url.host().toAscii()); 334 request.addValue("Ntrip-Version", "NTRIP/2.0"); 335 request.addValue("User-Agent" , "NTRIP BNC/" BNCVERSION); 336 if (!url.userName().isEmpty()) { 337 request.addValue("Authorization", "Basic " + 338 (url.userName() + ":" + url.password()).toAscii().toBase64()); 345 QNetworkRequest request; 346 request.setUrl(urlLoc); 347 request.setRawHeader("Host" , urlLoc.host().toAscii()); 348 request.setRawHeader("Ntrip-Version", "NTRIP/2.0"); 349 request.setRawHeader("User-Agent" , "NTRIP BNC/1.7"); 350 if (!urlLoc.userName().isEmpty()) { 351 request.setRawHeader("Authorization", "Basic " + 352 (urlLoc.userName() + ":" + urlLoc.password()).toAscii().toBase64()); 339 353 } 340 request.addValue("Connection" , "close"); 341 342 343 connect(_http, SIGNAL(done(bool)), this, SLOT(slotDone(bool))); 344 connect(_http, SIGNAL(requestFinished(int, bool)), 345 this, SLOT(slotRequestFinished(int, bool))); 346 connect(_http, SIGNAL(readyRead(const QHttpResponseHeader&)), 347 this, SLOT(slotReadyRead(const QHttpResponseHeader&))); 348 349 _http->request(request); 354 request.setRawHeader("Connection" , "close"); 355 356 _reply = _manager->get(request); 357 358 connect(_reply, SIGNAL(finished()), this, SLOT(slotReplyFinished())); 359 connect(_reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead())); 360 connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), 361 this, SLOT(slotError(QNetworkReply::NetworkError))); 362 connect(_reply, SIGNAL(sslErrors(const QList<QSslError>&)), 363 this, SLOT(slotSslErrors(const QList<QSslError>&))); 364 350 365 351 366 return success; -
trunk/BNC/bncsocket.h
r1368 r1370 29 29 30 30 private slots: 31 void slotDone(bool); 32 void slotRequestFinished(int, bool); 33 void slotReadyRead(const QHttpResponseHeader&); 31 void slotReplyFinished(); 32 void slotReadyRead(); 33 void slotError(QNetworkReply::NetworkError); 34 void slotSslErrors(const QList<QSslError>&); 34 35 35 36 private: … … 38 39 int timeOut, QString& msg); 39 40 40 QTcpSocket* _socket; 41 QHttp* _http; 42 QByteArray _buffer; 43 QEventLoop _eventLoop; 41 QTcpSocket* _socket; 42 QNetworkAccessManager* _manager; 43 QNetworkReply* _reply; 44 QEventLoop* _eventLoop; 45 QByteArray _buffer; 44 46 }; 45 47
Note:
See TracChangeset
for help on using the changeset viewer.