Logo Search packages:      
Sourcecode: kmess version File versions

void P2PApplicationBase::gotNegotiationFragment ( const P2PMessage p2pMessage  )  [private]

Called when a SLP message fragment was received.

The fragments is buffered until all parts are received. The gotNegotiationMessage() will be called afterwards.

Parameters:
p2pMessage The received P2P message with SLP payload.

Definition at line 957 of file p2papplicationbase.cpp.

References P2PMessage::getData(), P2PMessage::getDataSize(), and P2PMessage::isLastFragment().

Referenced by gotMessage().

{
  if(! p2pMessage.isLastFragment())
  {
    // Not everything received yet, buffer it.
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
    kDebug() << "Got an SLP fragment, buffering it.";
#endif

    if(buffer_ == 0)
    {
      buffer_ = new QBuffer();
      buffer_->open(QIODevice::ReadWrite);
    }

    buffer_->write( p2pMessage.getData(), p2pMessage.getDataSize() );
  }
  else
  {
    // Read the message or buffer
    QString slpData;
    QByteArray bufferData;

    if(buffer_ != 0)
    {
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
      kDebug() << "Got the last SLP fragment.";
#endif

      // Append the last MSNSLP fraqment and call the method.
      buffer_->write( p2pMessage.getData(), p2pMessage.getDataSize() );
      buffer_->reset();

      // Read the buffer
      bufferData = buffer_->readAll();
      slpData    = QString::fromUtf8( bufferData.data(), bufferData.size() );

      delete buffer_;
      buffer_ = 0;
    }
    else
    {
      // Read the data directly from the message
      slpData = QString::fromUtf8( p2pMessage.getData(), (int)p2pMessage.getDataSize() );
    }

    // Remove the first preamble line, because it's not in MIME format.
    // Parse the remaining as MIME fields.
    int      preambleEnd  = slpData.indexOf("\r\n");
    QString  preamble     ( slpData.left( (preambleEnd == -1) ? 20 : preambleEnd     ) );
    QString  slpMimePart  ( slpData.mid ( (preambleEnd == -1) ?  0 : preambleEnd + 2 ) );
    MimeMessage slpMessage( slpMimePart );

    // Parse the negotiation message
    gotNegotiationMessage( slpMessage, preamble );
  }
}


Generated by  Doxygen 1.6.0   Back to index