Changeset 1593 in ntrip for trunk/BNC/bncnetqueryv1.cpp


Ignore:
Timestamp:
Feb 13, 2009, 6:15:22 PM (15 years ago)
Author:
mervart
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncnetqueryv1.cpp

    r1592 r1593  
    6565      }
    6666      else if (!_socket->waitForReadyRead(_timeOut)) {
     67        QString errStr = _socket->errorString();
     68        if (errStr.isEmpty()) {
     69          errStr = "Read timeout";
     70        }
    6771        delete _socket;
    6872        _socket = 0;
    6973        _status = error;
    70         emit newMessage(_url.path().toAscii() + ": Read timeout", true);
     74        emit newMessage(_url.path().toAscii() + ": " + errStr.toAscii(), true);
    7175        return;
    7276      }
     
    158162  QStringList response;
    159163  while (true) {
    160     QByteArray line = this->readNextLine();
    161     if (_status == error) {
    162       break;
     164    if (_socket->canReadLine()) {
     165      QString line = _socket->readLine();
     166
     167      if (line.indexOf("ICY 200 OK") == -1 &&
     168          line.indexOf("HTTP")       != -1 &&
     169          line.indexOf("200 OK")     != -1 ) {
     170        proxyResponse = true;
     171      }
     172
     173      if (!proxyResponse && !line.trimmed().isEmpty()) {
     174        response.push_back(line);
     175      }
     176
     177      if (line.trimmed().isEmpty()) {
     178        if (proxyResponse) {
     179          proxyResponse = false;
     180        }
     181        else {
     182          break;
     183        }
     184      }
     185
     186      if (line.indexOf("Unauthorized") != -1) {
     187        break;
     188      }
     189
     190      if (!proxyResponse                    &&
     191          line.indexOf("200 OK")      != -1 &&
     192          line.indexOf("SOURCETABLE") == -1) {
     193        response.clear();
     194      }
    163195    }
    164 
    165     if (line.indexOf("ICY 200 OK") == -1 &&
    166         line.indexOf("HTTP")       != -1 &&
    167         line.indexOf("200 OK")     != -1 ) {
    168       proxyResponse = true;
    169     }
    170 
    171     cout << proxyResponse << ": " << line.data(); cout.flush();
    172 
    173     if (!proxyResponse && !line.trimmed().isEmpty()) {
    174       response.push_back(line);
    175     }
    176 
    177     if (line.indexOf("Unauthorized") != -1) {
    178       break;
    179     }
    180 
    181     if (line.trimmed().isEmpty()) {
    182       if (proxyResponse) {
    183         proxyResponse = false;
    184         }
    185         else {
    186         break;
    187         }
    188     }
    189 
    190     if (!proxyResponse                    &&
    191         line.indexOf("200 OK")      != -1 &&
    192         line.indexOf("SOURCETABLE") == -1) {
    193       response.clear();
    194       break;
     196    else if (!_socket->waitForReadyRead(_timeOut)) {
     197      delete _socket;
     198      _socket = 0;
     199      _status = error;
     200      emit newMessage(_url.path().toAscii() + ": Response timeout", true);
     201      return;
    195202    }
    196203  }
     
    204211}
    205212
    206 //
    207 ////////////////////////////////////////////////////////////////////////////
    208 QByteArray bncNetQueryV1::readNextLine() {
    209   QByteArray buffer;
    210   char ch1 = ' ';
    211   while (true) {
    212     if (_socket->bytesAvailable()) {
    213       char ch2;
    214       _socket->read(&ch2, 1);
    215       if (ch2 != '\r') {
    216         buffer += ch2;
    217       }
    218       if ( (ch2 == '\n' && ch1 == '\r') ||
    219            (ch2 == '\r' && ch1 == '\n') ) {
    220         return buffer;
    221       }
    222       ch1 = ch2;
    223     }
    224     else if (!_socket->waitForReadyRead(_timeOut)) {
    225       delete _socket;
    226       _socket = 0;
    227       _status = error;
    228       emit newMessage(_url.path().toAscii() + ": Response timeout", true);
    229       return "";
    230     }
    231   }
    232 }
    233 
Note: See TracChangeset for help on using the changeset viewer.