Changeset 1370 in ntrip


Ignore:
Timestamp:
Dec 28, 2008, 11:23:05 AM (15 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNC
Files:
4 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bnc.pro

    r1357 r1370  
    22# Switch to debug configuration
    33# -----------------------------
    4 CONFIG -= release
    5 CONFIG += debug
     4CONFIG -= debug
     5CONFIG += release
    66
    77DEFINES += NO_RTCM3_MAIN
  • trunk/BNC/bncsocket.cpp

    r1368 r1370  
    3232               app, SLOT(slotMessage(const QByteArray,bool)));
    3333  _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()));
    3638}
    3739
     
    3941////////////////////////////////////////////////////////////////////////////
    4042bncSocket::~bncSocket() {
     43  delete _eventLoop;
     44  delete _reply;
     45  delete _manager;
    4146  delete _socket;
    42   delete _http;
    4347}
    4448
     
    4650////////////////////////////////////////////////////////////////////////////
    4751QAbstractSocket::SocketState bncSocket::state() const {
    48   if      (_http) {
    49     if (_http->state() != QHttp::Unconnected) {
     52  if      (_manager) {
     53    if (_reply) {
    5054      return QAbstractSocket::ConnectedState;
    5155    }
     
    7377////////////////////////////////////////////////////////////////////////////
    7478qint64 bncSocket::bytesAvailable() const {
    75   if      (_http) {
     79  if      (_manager) {
    7680    return _buffer.size();
    7781  }
     
    8791////////////////////////////////////////////////////////////////////////////
    8892bool bncSocket::canReadLine() const {
    89   if      (_http) {
     93  if      (_manager) {
    9094    if (_buffer.indexOf('\n') != -1) {
    9195      return true;
     
    106110////////////////////////////////////////////////////////////////////////////
    107111QByteArray bncSocket::readLine() {
    108   if      (_http) {
     112  if      (_manager) {
    109113    int ind = _buffer.indexOf('\n');
    110114    if (ind != -1) {
     
    128132////////////////////////////////////////////////////////////////////////////
    129133void bncSocket::waitForReadyRead(int msecs) {
    130   if      (_http) {
     134  if      (_manager) {
    131135    if (bytesAvailable() > 0) {
    132136      return;
    133137    }
    134138    else {
    135       _eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
     139      _eventLoop->exec(QEventLoop::ExcludeUserInputEvents);
    136140    }
    137141  }
     
    144148////////////////////////////////////////////////////////////////////////////
    145149QByteArray bncSocket::read(qint64 maxSize) {
    146   if      (_http) {
     150  if      (_manager) {
    147151    QByteArray ret = _buffer.left(maxSize);
    148152    _buffer = _buffer.right(_buffer.size()-maxSize);
     
    289293//
    290294////////////////////////////////////////////////////////////////////////////
    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());
     295void bncSocket::slotReadyRead() {
     296  _buffer.append(_reply->readAll());
    302297  emit quitEventLoop();
    303298}
     
    305300//
    306301////////////////////////////////////////////////////////////////////////////
    307 void bncSocket::slotDone(bool error) {
    308   if (error) {
    309     emit newMessage("slotDone " + _http->errorString().toAscii(), true);
    310   }
     302void bncSocket::slotReplyFinished() {
    311303  emit quitEventLoop();
     304}
     305
     306//
     307////////////////////////////////////////////////////////////////////////////
     308void bncSocket::slotError(QNetworkReply::NetworkError) {
     309  emit newMessage("slotError " + _reply->errorString().toAscii(), true);
     310}
     311
     312//
     313////////////////////////////////////////////////////////////////////////////
     314void bncSocket::slotSslErrors(const QList<QSslError>&) {
     315  emit newMessage("slotSslErrors", true);
    312316}
    313317
     
    318322                         int timeOut, QString& msg) {
    319323
    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  }
    325342
    326343  // Network Request
    327344  // ---------------
    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());
    339353  }
    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
    350365
    351366  return success;
  • trunk/BNC/bncsocket.h

    r1368 r1370  
    2929
    3030 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>&);
    3435
    3536 private:
     
    3839                 int timeOut, QString& msg);
    3940
    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;
    4446};
    4547
Note: See TracChangeset for help on using the changeset viewer.