-rw-r--r-- | noncore/net/ubrowser/httpfactory.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/noncore/net/ubrowser/httpfactory.cpp b/noncore/net/ubrowser/httpfactory.cpp index 4ace4cb..b37e9f9 100644 --- a/noncore/net/ubrowser/httpfactory.cpp +++ b/noncore/net/ubrowser/httpfactory.cpp @@ -178,116 +178,122 @@ const QMimeSource * HttpFactory::data(const QString &abs_or_rel_name, const QStr } return 0; } const QByteArray HttpFactory::processResponse( int sockfd, bool &isText ) const { QByteArray inputBin( 1 ); QByteArray conClosedErr( 27 ); char conClosedErrMsg[] = "Connection to server closed"; QString currentLine; bool done=false, chunked=false; int dataLength = 0; for( int i = 0; i < 27; i++) { conClosedErr[i] = conClosedErrMsg[i]; } while( !done ) { recv( sockfd, inputBin.data(), inputBin.size(), 0 ); currentLine += *(inputBin.data()); if( *(inputBin.data()) == '\n' ) { if( currentLine.isEmpty() || currentLine.startsWith( "\r") ) { printf( "HttpFactory::processResponse: end of header\n" ); if( chunked ) { return recieveChunked( sockfd ); } else { return recieveNormal( sockfd, dataLength ); } done = true; } if( currentLine.contains( "Transfer-Encoding: chunked", false) >= 1 ) { chunked = true; printf( "HttpFactory::processResponse: chunked encoding\n" ); } if( currentLine.contains( "Content-Type: text", false ) >= 1 ) { isText = true; printf( "HttpFactory::processResponse: content type text\n" ); - if( currentLine.contains( "html", false ) ) + if( currentLine.contains( "html", false ) >= 1) { browser->setTextFormat(Qt::RichText); printf( "HttpFactory::processResponse: content type html\n" ); } } if( currentLine.contains( "Content-Type: image", false ) >= 1 ) { isText = false; printf( "HttpFactory::processResponse: content type image\n" ); } if( currentLine.contains( "Content-Length", false ) >= 1 ) { currentLine.remove( 0, 16 ); dataLength = currentLine.toInt(); printf( "HttpFactory::processResponse: content length: %d\n", dataLength ); } + if( currentLine.contains( "404", false ) >= 1 ) + { + printf( "HttpFactory::processResponse: 404 error\n" ); + return 0; + } + currentLine = ""; printf("HttpFactory::processResponse: reseting currentLine: %s\n", currentLine.latin1() ); } } } const QByteArray HttpFactory::recieveNormal( int sockfd, int dataLen ) const { printf( "HttpFactory::recieveNormal: recieving w/out chunked encoding\n" ); QByteArray data( dataLen ); QByteArray temp( dataLen ); int recieved, i; recieved = recv( sockfd, temp.data(), temp.size(), 0 ); printf( "HttpFactory::recieveNormal: found some data: %s\n", (char *)temp.data() ); for( i = 0; i < recieved; i++ ) { data[i] = temp[i]; } dataLen -= recieved; while( dataLen > 0 ) { recieved = recv( sockfd, temp.data(), temp.size(), 0 ); dataLen -= recieved; // printf( "HttpFactory::recieveNormal: found some more data: %s\n", (char *)temp.data() ); for( int j = 0; j < recieved; j++ ) { data[i] = temp[j]; i++; } temp.fill('\0'); } printf( "HttpFactory::recieveNormal: end of data\n" ); return data; } const QByteArray HttpFactory::recieveChunked( int sockfd ) const { printf( "HttpFactory::recieveChunked: recieving data with chunked encoding\n" ); QByteArray data; QByteArray temp( 1 ); int recieved, i = 0, cSize = 0; QString cSizeS; printf( "HttpFactory::recieveChunked: temp.size(): %d\n", temp.size() ); |