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

void P2PApplication::sendCancelMessage ( const ApplicationCancelReason  cancelReason  )  [protected, virtual, inherited]

Send a cancel message. Some errors also terminate the application eventually.

Parameters:
cancelReason The reason why the application is cancelled.
MSNSLP related notes: Error reasons sending an MSNSLP error messages should only be used in the contactStarted1 / contactStarted2 methods.. Once the MSNSLP error message is sent, P2PApplication waits for the contact to ACK, and terminates the application afterwards. Hence, you don't have to call endApplication() from contactStarted1 / contactStarted2.

When an MSNSLP error is sent at a different moment, this will likely result in undefined responses from the other client (or the error message might be ignored). If KMess is compiled in debug mode, an assertion in sendSlpError() will detect this.

The following cancelReason values are supported:

  • CANCEL_INVITATION The user declined the invitation.

This sends an "MSNSLP 603 Decline" message, waits for the contact to ACK and terminates this application afterwards.

This reason will be used automatically.

  • CANCEL_SESSION / CANCEL_FAILED The user aborted the session.

If called from contactStarted1_ContactInvitesUser(), this sends an "MSNSLP 603 Decline" message, waits for the contact to ACK and terminates this application afterwards.

From other methods an P2P ACK message is sent with the "error flag" set (type 8).

Within the userStarted3_UserPrepares() method, CANCEL_SESSION is the only valid response. If KMess is compiled in debug mode, an assertion will be triggered otherwise.

  • CANCEL_NOT_INSTALLED The requested service/application is not installed.

This sends an "MSNSLP 500 Internal Error" message, waits for the contact to ACK and terminates this application afterwards.

This reason should only be used in contactStarted1_ContactInvitesUser(). The default implementation in Application::contactStarted1_ContactInvitesUser() uses this reason automatically to cancel the invitation. Hence the base class is used to reject unknown services automatically.

  • CANCEL_TIMEOUT There was a timeout waiting for the contact to accept or send certain P2P data. Usually this reason is used internally by certain timeout functions. This sends an P2P message with the "waiting flag" set (type 4).

  • CANCEL_INVALID_SLP_CONTENT_TYPE Sends an "MSNSLP 500 Internal Error" message back, but without an Content-Type set.

This reason should only be used from contactStarted1_ContactInvitesUser() or userStarted2_ContactAccepts() to indicate the given Content-Type is not supported. Other invocations result in undefined responses from the other client (it will likely be ignored).

Implements Application.

Definition at line 1320 of file p2papplication.cpp.

References P2PApplication::sendP2PAck(), P2PApplication::sendP2PMessage(), and P2PApplication::sendSlpError().

Referenced by contactStarted1_ContactInvitesUser(), PictureTransferP2P::contactStarted1_ContactInvitesUser(), P2PApplication::contactStarted1_ContactInvitesUser(), FileTransferP2P::contactStarted1_ContactInvitesUser(), PictureTransferP2P::contactStarted2_UserAccepts(), FileTransferP2P::contactStarted2_UserAccepts(), PictureTransferP2P::gotData(), FileTransferP2P::gotData(), P2PApplication::gotSlpInvite(), P2PApplication::sendData(), FileTransferP2P::slotCancelTransfer(), and P2PApplication::slotCleanup().

{
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kdDebug() << "P2PApplication - sendCancelMessage (reason=" << cancelReason << ")." << endl;
#endif

  // We'll send the cancel message!
  sentCancelMessage_ = true;

  // I don't care what the reason is if you had
  // to send the data-preparation ACK
  if(userShouldAcknowledge_)
  {
#ifdef KMESSTEST
    ASSERT( cancelReason == CANCEL_SESSION );
#endif

    // Cancelled the data preparation message
    sendP2PAck(P2PMessage::MSN_FLAG_ERROR);
    userShouldAcknowledge_ = false;
    shouldSendAck_         = false;
    return;
  }



  // Declined the invitation
  if(cancelReason == CANCEL_INVITATION)
  {
    // Use the cancel-reason to send the correct message:
    sendSlpError("603 Decline", invitationSessionID_, invitationContentType_);
    return;
  }


  // Timeout waiting for some P2P data
  // ...or timeout waiting for contact to accept.
  if(cancelReason == CANCEL_TIMEOUT)
  {
    sendP2PMessage(0, P2PMessage::MSN_FLAG_WAITING, 0);
    shouldSendAck_ = false;
    return;
  }


  // The application type is not installed
  if(cancelReason == CANCEL_NOT_INSTALLED && gotSlpMessage_)
  {
    // Usually this particular error is invoked from Application::contactStarted1_ContactInvitesUser().
    sendSlpError("500 Internal Error", invitationSessionID_, invitationContentType_);
    return;
  }


  // User or application wants to abort
  if(cancelReason == CANCEL_SESSION || cancelReason == CANCEL_FAILED)
  {
    if(gotSlpMessage_)
    {
      // Cancelled while in SLP negotiate mode.
      // Include the original content-type to tell the other
      // client that part of the message was not in error.
      sendSlpError("500 Internal Error", invitationSessionID_, invitationContentType_);
      return;
    }
    else
    {
      // TODO: these error messages are somehow rejected with
      // another "error in binary fields" error-message response.
      // One way of testing this code is causing the file-open code
      // in P2PPictureTransfer::userStarted3_UserPrepares() to fail.

      // Cancelled while receiving data
      sendP2PAck(P2PMessage::MSN_FLAG_ERROR);
      return;
    }
  }


  // Invalid content type received
  if(cancelReason == CANCEL_INVALID_SLP_CONTENT_TYPE)
  {
    // Send an 500 error message without content-type set
    sendSlpError("500 Internal Error");
    return;
  }


  // Last option, unknown cancel message
#ifdef KMESSDEBUG_MIMEAPPLICATION
  kdWarning() << "MimeApplication: unknown cancelReason used." << endl;
#endif

  sendP2PAck(P2PMessage::MSN_FLAG_ERROR);
}


Generated by  Doxygen 1.6.0   Back to index