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

void P2PApplication::gotSlpStatus ( const MimeMessage slpMimeMessage,
const QString &  preamble 
) [private]

Got an MSNSLP Status header

Definition at line 1105 of file p2papplication.cpp.

References MimeMessage::getValue(), and sendP2PAck().

Referenced by gotNegotiationMessage().

{
  // An Error message, or "MSNSLP/1.0 200 OK" message
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kdDebug() << "P2PApplication: Got SLP status message (" << preamble << ")" << endl;
#endif


  // Should only be received if we started it.
  if(! isUserStartedApp())
  {
    kdWarning() << "P2PApplication: P2P message can't be handled, "
                << "unexpected SLP status response (contact=" << contactHandle_ << ")." << endl;

    sessionID_ = 0;
    sendP2PAck(P2PMessage::MSN_FLAG_ERROR);
    endApplication( i18n("The invitation was cancelled.  The contact sent bad data, or KMess doesn't support it.") );
    return;
  }


  // Parse the preamble
  QRegExp re("MSNSLP/\\d+\\.\\d+ (\\d+) ([^\r\n]+)");
  re.search(preamble);
  int     code   = re.cap(1).toUInt();
  QString detail = re.cap(2);


  // Reset the waiting state.
  if(waitingState_ == P2P_WAIT_CONTACT_ACCEPT)
  {
    waitingState_ = P2P_WAIT_DEFAULT;
  }

  // Handle the status codes


  // If the invitation was accepted
  if(code == 200)
  {
    // We don't need to do much here:
    // The message will be ACK-ed automatically with the correct session ID
    // because that ID was given in the sendSlpInvitation() method.

    // This the first ACK to be sent with the SessionID set.
    if(shouldSendAck_)
    {
      sendP2PAck();
    }

    // Dispatch to derived class,
    // It's invitation was accepted
    userStarted2_ContactAccepts(slpMimeMessage);

    // Waiting for prepare message
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
    kdDebug() << "P2PApplication: Waiting for contact to send some prepare message..." << endl;
#endif

    // TODO: I guess this will be different for file transfers..
    waitingState_ = P2P_WAIT_FOR_PREPARE;
    waitingTimer_->start(30000, true); // 30 sec
    return;
  }


  // We sent a bad address in the to: header
  if(code == 404)
  {
    if(shouldSendAck_)
    {
      sendP2PAck();
    }

    // Inform the user KMess has an error
    kdWarning() << "P2PApplication: KMess sent a bad address in the 'to:' header." << endl;
    contactAborted( i18n("The contact rejected the invitation.  An internal error occured.") );
    return;
  }


  // Something was not supported
  if(code == 500)
  {
    if(shouldSendAck_)
    {
      sendP2PAck();
    }

    if(slpMimeMessage.getValue("Content-Type") == "null")
    {
      // The Content-Type was not supported
      kdWarning() << "P2PApplication: Content-Type of our invitation was not understood" << endl;
    }
    else
    {
      // Bad header sent in SLP fields, or invitation type was not supported
      kdWarning() << "P2PApplication: Our invitation was not supported" << endl;
    }

    contactAborted( i18n("The contact rejected the invitation.  An internal error occured.") );
    return;
  }


  // The invitation was declined
  if(code == 603)
  {
    if(shouldSendAck_)
    {
      sendP2PAck();
    }

    // Contact Declined
    contactRejected();
    return;
  }


  // Last option: tell the contact it sent an unknown message

  kdWarning() << "P2PApplication: P2P message can't be handled, "
              << "unsupported SLP response (preamble=" << preamble << " contact=" << contactHandle_ << ")." << endl;

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


Generated by  Doxygen 1.6.0   Back to index