Logo Search packages:      
Sourcecode: kmess version File versions  Download package

void P2PApplication::gotNegotiationMessage ( const QString &  slpMessage  )  [private]

Parse SLP "session negotiation messages". Those messages don't have a sessionID set, and have MSNSLP Mime fields in the body.

Parameters:
slpMessage The MSNSLP message to parse.

Definition at line 897 of file p2papplication.cpp.

References Account::getHandle(), MimeMessage::getValue(), gotSlpBye(), gotSlpInvite(), gotSlpStatus(), sendP2PAck(), and sendSlpError().

Referenced by gotNegotiationFragment().

{
  // Parse the "negotiation message" (P2PMessage with sessionID 0)

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


  // Verify it is indeed directed to us..
  QString msgTo = slpMimeMessage.getValue("To");

  if(! msgTo.isEmpty())
  {
    // Only test if the field is available. If it's not, either something
    // is wrong in this application, or the client sent a bad message and
    // we should respond with an 500 error instead.
    if( msgTo != "<msnmsgr:" + CurrentAccount::instance()->getHandle() + ">" )
    {
      if(shouldSendAck_) sendP2PAck();

      // In the future, the <msnmsgr: > string might be replaced with
      // something to support MSN to AOL chats, etc..
      kdWarning() << "P2PApplication: P2P message can't be handled, "
                  << "addressed to someone else (contact=" << contactHandle_ << ")." << endl;

      emit appInitMessage( i18n("The invitation was cancelled.  Message was not directed to us.") );
      sendSlpError("404 Not Found"); // Waits for ACK and terminates
      return;
    }
  }


  // Find out what kind of message this is:
  if(preamble.startsWith("INVITE MSNMSGR"))
  {
    // Don't accept invites if we sent one.
    if(messageID_ != 0 && isUserStartedApp())
    {
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
      kdDebug() << "P2PApplication: Got an INVITE response, rejecting (contact is likely using MSN7)." << endl;
#endif

      unsigned long tempSessionID = sessionID_;
      sessionID_ = 0;
      sendP2PAck(P2PMessage::MSN_FLAG_ERROR);
      sessionID_ = tempSessionID;
      return;
    }

    if(shouldSendAck_)
    {
      sendP2PAck();
    }

    // Got an invitation!
    gotSlpInvite(slpMimeMessage);
  }
  else if(preamble.startsWith("MSNSLP/"))
  {
    // Error message, or "MSNSLP/1.0 200 OK" message
    gotSlpStatus(slpMimeMessage, preamble);
  }
  else if(preamble.startsWith("BYE MSNMSGR"))
  {
    // Got a BYE message
    gotSlpBye(slpMimeMessage);
  }
  else
  {
    // Unknown SLP message
    kdWarning() << "P2PApplication: P2P message can't be handled, "
                << "unsuppored SLP negotiation message (preamble=" << preamble << " contact=" << contactHandle_ << ")." << endl;

    // Got an unknown SLP preamble
    sendP2PAck(P2PMessage::MSN_FLAG_ERROR);
    endApplication( i18n("The invitation was cancelled.  The contact sent bad data, or KMess doesn't support it.") );
    return;
  }
}


Generated by  Doxygen 1.6.0   Back to index