static int readPayloadStream( tr_handshake * handshake, struct evbuffer * inbuf ) { int i; const size_t needlen = HANDSHAKE_SIZE; dbgmsg( handshake, "reading payload stream... have %zu, need %zu", evbuffer_get_length( inbuf ), needlen ); if( evbuffer_get_length( inbuf ) < needlen ) return READ_LATER; /* parse the handshake ... */ i = parseHandshake( handshake, inbuf ); dbgmsg( handshake, "parseHandshake returned %d", i ); if( i != HANDSHAKE_OK ) return tr_handshakeDone( handshake, FALSE ); /* we've completed the BT handshake... pass the work on to peer-msgs */ return tr_handshakeDone( handshake, TRUE ); }
void AsyncCDDBPLookup::read() { switch ( state_ ) { case WaitingForGreeting: if ( !parseGreeting( readLine() ) ) { result_ = ServerError; doQuit(); return; } doHandshake(); break; case WaitingForHandshake: if ( !parseHandshake( readLine() ) ) { result_ = ServerError; doQuit(); return; } doProto(); break; case WaitingForProtoResponse: // Ignore the response for now readLine(); doQuery(); break; case WaitingForQueryResponse: result_ = parseQuery( readLine() ); switch ( result_ ) { case Success: requestCDInfoForMatch(); break; case MultipleRecordFound: state_ = WaitingForMoreMatches; break; default: // Error :( doQuit(); return; } break; case WaitingForMoreMatches: { QString line = readLine(); if (line.startsWith(QLatin1String( "." ))) requestCDInfoForMatch(); else parseExtraMatch( line ); } break; case WaitingForCDInfoResponse: { Result result = parseRead( readLine() ); if ( Success != result ) { result_ = result; doQuit(); return; } state_ = WaitingForCDInfoData; } break; case WaitingForCDInfoData: { QString line = readLine(); if (line.startsWith(QLatin1String( "." ))) { parseCDInfoData(); requestCDInfoForMatch(); } else cdInfoBuffer_ << line; } break; case WaitingForQuitResponse: state_ = Idle; char c; while ( socket_->bytesAvailable() ) socket_->getChar(&c); close(); emit finished( result_ ); break; default: break; } }