void SSDP::ProcessData( MSocketDevice *pSocket ) { QByteArray buffer; long nBytes = 0; while ((nBytes = pSocket->bytesAvailable()) > 0) { buffer.resize(nBytes); long nRead = 0; do { long ret = pSocket->readBlock( buffer.data() + nRead, nBytes - nRead ); if (ret < 0) { LOG(VB_GENERAL, LOG_ERR, QString("Socket readBlock error %1") .arg(pSocket->error())); buffer.clear(); break; } nRead += ret; if (0 == ret) { LOG(VB_SOCKET, LOG_WARNING, QString("%1 bytes reported available, " "but only %2 bytes read.") .arg(nBytes).arg(nRead)); nBytes = nRead; buffer.resize(nBytes); break; } } while (nRead < nBytes); if (buffer.isEmpty()) continue; QHostAddress peerAddress = pSocket->peerAddress(); quint16 peerPort = pSocket->peerPort (); // ------------------------------------------------------------------ QString str = QString(buffer.constData()); QStringList lines = str.split("\r\n", QString::SkipEmptyParts); QString sRequestLine = lines.size() ? lines[0] : ""; lines.pop_front(); // ------------------------------------------------------------------ // Parse request Type // ------------------------------------------------------------------ LOG(VB_UPNP, LOG_DEBUG, QString("SSDP::ProcessData - requestLine: %1") .arg(sRequestLine)); SSDPRequestType eType = ProcessRequestLine( sRequestLine ); // ------------------------------------------------------------------ // Read Headers into map // ------------------------------------------------------------------ QStringMap headers; for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) { QString sLine = *it; QString sName = sLine.section( ':', 0, 0 ).trimmed(); QString sValue = sLine.section( ':', 1 ); sValue.truncate( sValue.length() ); //-2 if ((sName.length() != 0) && (sValue.length() !=0)) headers.insert( sName.toLower(), sValue.trimmed() ); } #if 0 pSocket->SetDestAddress( peerAddress, peerPort ); #endif // -------------------------------------------------------------- // See if this is a valid request // -------------------------------------------------------------- switch( eType ) { case SSDP_MSearch: { // ---------------------------------------------------------- // If we haven't enabled notifications yet, then we don't // want to answer search requests. // ---------------------------------------------------------- if (m_pNotifyTask != NULL) ProcessSearchRequest( headers, peerAddress, peerPort ); break; } case SSDP_MSearchResp: ProcessSearchResponse( headers); break; case SSDP_Notify: ProcessNotify( headers ); break; case SSDP_Unknown: default: LOG(VB_UPNP, LOG_ERR, "SSPD::ProcessData - Unknown request Type."); break; } } }
void SSDP::ProcessData( MSocketDevice *pSocket ) { long nBytes = 0; long nRead = 0; while ((nBytes = pSocket->bytesAvailable()) > 0) { QByteArray buffer; buffer.resize(nBytes); nRead = pSocket->readBlock( buffer.data(), nBytes ); QHostAddress peerAddress = pSocket->peerAddress(); quint16 peerPort = pSocket->peerPort (); // ------------------------------------------------------------------ QString str = QString(buffer.constData()); QStringList lines = str.split("\r\n", QString::SkipEmptyParts); QString sRequestLine = lines.size() ? lines[0] : ""; lines.pop_front(); // ------------------------------------------------------------------ // Parse request Type // ------------------------------------------------------------------ VERBOSE(VB_UPNP+VB_EXTRA, QString( "SSDP::ProcessData - requestLine: %1" ) .arg( sRequestLine )); SSDPRequestType eType = ProcessRequestLine( sRequestLine ); // ------------------------------------------------------------------ // Read Headers into map // ------------------------------------------------------------------ QStringMap headers; for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) { QString sLine = *it; QString sName = sLine.section( ':', 0, 0 ).trimmed(); QString sValue = sLine.section( ':', 1 ); sValue.truncate( sValue.length() ); //-2 if ((sName.length() != 0) && (sValue.length() !=0)) headers.insert( sName.toLower(), sValue.trimmed() ); } // pSocket->SetDestAddress( peerAddress, peerPort ); // -------------------------------------------------------------- // See if this is a valid request // -------------------------------------------------------------- switch( eType ) { case SSDP_MSearch: { // ---------------------------------------------------------- // If we haven't enabled notifications yet, then we don't // want to answer search requests. // ---------------------------------------------------------- if (m_pNotifyTask != NULL) ProcessSearchRequest( headers, peerAddress, peerPort ); break; } case SSDP_MSearchResp: ProcessSearchResponse( headers); break; case SSDP_Notify: ProcessNotify( headers ); break; case SSDP_Unknown: default: VERBOSE(VB_UPNP, "SSPD::ProcessData - Unknown request Type."); break; } } }