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

P2PApplication Class Reference
[network/applications]

#include <p2papplication.h>

Inheritance diagram for P2PApplication:

P2PApplicationBase Application FileTransferP2P InkTransferP2P MsnObjectTransferP2P UnknownApplication

List of all members.


Detailed Description

An Application subclass implementing MSNSLP on top of MSN6 P2P-style conversations.

This base class aims to hide all complex details of the P2P and MSNSLP communication. To implement a P2P service, create a derived class which implements the userStarted*, contactStarted* and getAppId() methods.

User-started invitations are handled this way:

Contacted-started invitations are handled this way:

To cancel a running session, call userAborted() or use sendCancelMessage(). In most cases the application will terminate automatically after the contact ACK-ed the cancel message. Otherwise, endApplication() needs to be called manually.

When a data transfer is active, the methods showTransferMessage(), showTransferProgress(), showTransferComplete() are called to inform the derived class of the status. It can update the GUI from these methods.

--- internals ----

This class extends the P2PApplicationBase class, to implement the MSNSLP communication. This is a session protocol which is transferred over the P2P payloads. New messages are delivered by the base class though the gotNegotiationMessage() method.

The exact contents of the P2P message is described in the P2PApplicationBase API documentation. This class calls typically calls the sendSlpMessage() and the other send..() methods to dispatch the messages.

Some third party clients (including KMess 1.4.x) seam to send incorrect message fields. This class is able to handle those not-entirely valid messages as well. The situations where this happens are marked as "HACK" in the code.

Author:
Diederik van der Boor

Definition at line 109 of file p2papplication.h.


Public Types

enum  ApplicationMode { APP_MODE_NORMAL, APP_MODE_ERROR_HANDLER, APP_MODE_DATACAST }

Signals

void applicationMessage (const ChatMessage &message)
void deleteMe (Application *object)
void updateApplicationMessage (const QString &messageId, const QString &newMessage)

Public Member Functions

virtual void contactAborted (const QString &message=QString::null)
 The contact aborted the session.
QString getBranch () const
 Return the identifier the SLP INVITE message.
QString getCallID () const
 Return the identifier of the SLP session.
ChatgetChat () const
 Return the chat the application was originally created for (may be null).
const QString & getContactHandle () const
 Return the handle of the other contact.
const QString & getCookie () const
 Return the application's identifying cookie.
unsigned long getLastContactMessageID () const
 Return the message ID used in the previous message from the contact.
int getMode () const
 Return the current mode of the application.
const QString & getNonce () const
 Returns the nonce that's being expected.
quint32 getSessionID () const
 Return the session ID, this identifies the P2P session.
void gotCommand (QString command)
 A command for the application was received (i.e. "Accept" or "Reject").
void gotMessage (const P2PMessage &p2pMessage)
 Main entry function for incoming incoming messages.
bool hasUnAckedMessage (const P2PMessage &p2pMessage)
 Returns whether the application can handle the given ACK message.
bool isClosing () const
 Indicate whether the application is closing or not.
virtual bool isPrivateChatRequired () const
 Returns whether the application can operate in a multi-chat session, or requires a private chat.
 P2PApplication (ApplicationList *applicationList)
 Constructor, initializes the P2PApplication instance fields.
bool sendNextDataParts (int preferredFragments)
 Called when the connection is ready to send more file data.
void setChat (Chat *chat)
 Set the chat the application was originally created for.
void setMode (ApplicationMode mode)
 Change the current mode.
void start ()
 Start the application.
virtual void userAborted ()
 Called when the user aborted the application.
virtual ~P2PApplication ()
 Class destructor.

Protected Types

enum  ApplicationCancelReason {
  CANCEL_INVITATION, CANCEL_ABORT, CANCEL_NOT_INSTALLED, CANCEL_TIMEOUT,
  CANCEL_FAILED, CANCEL_INVALID_SLP_CONTENT_TYPE
}
enum  P2PDataType {
  P2P_TYPE_NEGOTIATION = 0, P2P_TYPE_PICTURE = 1, P2P_TYPE_FILE = 2, P2P_TYPE_INK = 3,
  P2P_TYPE_WEBCAM = 4
}
 The data type being sent. More...
enum  P2PMessageType {
  P2P_MSG_UNKNOWN = 0, P2P_MSG_SESSION_INVITATION = 1, P2P_MSG_SESSION_OK = 2, P2P_MSG_TRANSFER_INVITATION = 9,
  P2P_MSG_TRANSFER_OK = 3, P2P_MSG_DATA_PREPARATION = 4, P2P_MSG_DATA = 5, P2P_MSG_SESSION_BYE = 6,
  P2P_MSG_SESSION_DECLINE = 10, P2P_MSG_TRANSFER_DECLINE = 7, P2P_MSG_SLP_ERROR = 8, P2P_MSG_WEBCAM_SETUP = 11,
  P2P_MSG_WEBCAM_SYN = 12, P2P_MSG_WEBCAM_ACK = 13
}
 The meta type of a P2P message. More...
enum  P2PWaitingState {
  P2P_WAIT_DEFAULT = 0, P2P_WAIT_FOR_SLP_OK_ACK = 1, P2P_WAIT_FOR_FILE_DATA = 2, P2P_WAIT_FOR_WEBCAM_DATA = 19,
  P2P_WAIT_FOR_PREPARE = 3, P2P_WAIT_FOR_PREPARE_ACK = 4, P2P_WAIT_FOR_SLP_BYE = 5, P2P_WAIT_FOR_SLP_BYE_ACK = 6,
  P2P_WAIT_FOR_SLP_ERR_ACK = 7, P2P_WAIT_FOR_INVITE_ACK = 18, P2P_WAIT_CONTACT_ACCEPT = 8, P2P_WAIT_FOR_TRANSFER_ACCEPT = 9,
  P2P_WAIT_FOR_INVITE_TR_ACK = 19, P2P_WAIT_FOR_CONNECTION = 10, P2P_WAIT_FOR_DATA_ACK = 11, P2P_WAIT_FOR_TRANSFER_ACK = 12,
  P2P_WAIT_FOR_HANDSHAKE = 13, P2P_WAIT_FOR_HANDSHAKE_OK = 14, P2P_WAIT_FOR_CONNECTION2 = 15, P2P_WAIT_USER_ACCEPT = 16,
  P2P_WAIT_END_APPLICATION = 17
}
 An indication which message is expected from the contact. More...

Protected Member Functions

void abortDataSending ()
 Make sure no more data will be sent.
void contactRejected (const QString &message=QString::null)
 The contact declined the invitation.
virtual void contactStarted1_ContactInvitesUser (const MimeMessage &message)
 Step 1 of a contact-started chat: the contact invites the user.
virtual void contactStarted2_UserAccepts ()
 Step 2 of a contact-started chat: the user accepts.
virtual void contactStarted3_ContactConfirmsAccept (const MimeMessage &message)
virtual void contactStarted4_ContactConfirmsPreparation ()
 Step 4 of a contact-started chat: the contact confirms the data-preparation message.
void delayDeletion (bool doDelay)
void endApplication ()
 Request to delete this application.
void endApplicationLater ()
 Scheduelle termination, but wait for last incoming packets.
QString generateCookie () const
 Generate a random cookie value.
virtual QString getContactAbortMessage () const
 Return an abort message to display.
virtual QString getContactRejectMessage () const
 Return a reject message to display.
const QString & getExternalIp () const
 Return the external IP address.
const QString & getInvitationContentType () const
 Return the Content-Type of the invitation message.
quint32 getInvitationSessionID () const
 Return the identifier of the SLP INVITE message.
const QString & getLocalIp () const
unsigned long getTransferredBytes () const
 Return the number of transferred bytes.
virtual QString getUserAbortMessage () const
 Return an abort message to display.
virtual QString getUserRejectMessage () const
 Return a reject message to display.
P2PWaitingState getWaitingState () const
 Return the current waiting state.
virtual void gotData (const P2PMessage &message)
 Called when data is received.
virtual void gotDataComplete (const P2PMessage &lastMessage)
 Called internally after all data is received.
virtual bool gotUnhandledAck (const P2PMessage &message, P2PMessageType ackedMessageType)
 Called when an ack is received, which is not handled internally.
bool hasUnAckedMessage (const P2PMessageType messageType)
 Return whether a given message type is still unacked.
bool isFirstMessageSent () const
 Test whether the first message has been sent.
bool isP2PAckSent () const
 Test whether a P2P ack was sent for the current message.
bool isTransferActive () const
 Test whether the transfer is active.
bool isTransferComplete () const
 Verify whether the transfer was initiated and was completed.
bool isUserStartedApp () const
 Return the "user started this app" state.
bool isWaitingForUser () const
 Return true if we're waiting for the user to accept.
bool isWaitingState (P2PWaitingState waitingState) const
 Test whether a given waiting state is set.
void modifyOfferMessage (const QString &newMessage=QString())
 Replace an application's accept/reject/cancel links with another text.
void offerAcceptOrReject (const QString &appHtml)
 Let the user accept or reject the application.
void offerCancel (const QString &appHtml)
 Let the user cancel the application.
void sendCancelMessage (const ApplicationCancelReason cancelReason)
 Send a cancel message.
void sendData (QIODevice *dataSource, const P2PDataType dataType)
 Send file data in P2P packets.
void sendDataPreparation ()
 Send the data preparation message.
void sendDataPreparationAck ()
 Send the data preparation ACK.
void sendDirectConnectionHandshake (const QString &nonce)
 Send the direct connection handshake.
void sendP2PAbort ()
 Send a low-level control message to terminate the session.
bool sendP2PAck ()
 Send an ACK message if this is needed.
void sendP2PMessage (const QByteArray &messageData, int flagField=0, P2PDataType footerCode=P2P_TYPE_NEGOTIATION, P2PMessageType messageType=P2P_MSG_UNKNOWN)
 Sends a complete P2P message payload.
void sendP2PWaitingError ()
 Send a low-level error message that the application is waiting for a certain message.
void sendSlpMessage (const QString &slpMessage, P2PMessageType messageType)
 Send a complete SLP message in multiple P2P packets.
void sendSlpOkMessage (const MimeMessage &message)
 Send the 200 OK message to accept the invitation.
void sendSlpSessionInvitation (quint32 sessionID, const QString &eufGuid, const int appId, const QString &context)
 Send the invitation for a normal session.
void sendSlpTransferInvitation ()
 Send the invitation for a direct connection.
void setApplicationType (ChatMessage::MessageType type)
 Set the type of application we're starting.
void setClosing (bool closing)
 Indicate the application is closing or not.
void setCurrentMessageType (P2PMessageType messageType)
 Set the current message type, for debugging.
void setDataCastSessionID (quint32 sessionID)
void setUserAborted (bool userAborted)
 Notify this base class the user is aborting the session.
void setWaitingState (P2PWaitingState waitingState, int timeout)
 Indicate which packet is expected next.
virtual void showEventMessage (const QString &message, const ChatMessage::ContentsClass contents, bool isIncoming=true)
 Show a message to notify the user of an event.
virtual void showSystemMessage (const QString &message, const ChatMessage::ContentsClass contents, bool isIncoming=true)
 Show a message to notify about a system error.
virtual void showTransferComplete ()
 Called when the transfer is complete.
virtual void showTransferMessage (const QString &message)
 Show a message to inform about a transfer event.
virtual void showTransferProgress (const ulong bytesTransferred)
 Show the progress made during a transfer.
void startByInvite (const QString &invitationCookie)
 Start the application internally (from an invite message).
bool stopWaitingTimer ()
 Stop the waiting timer.
void testDataSendingAborted ()
 Test if the contact aborted the sending of data.
virtual void userRejected ()
 Called when the user rejected (declined) the application.
virtual void userStarted1_UserInvitesContact ()
 Step 1 of a user-started chat: the user invites the contact.
virtual void userStarted2_ContactAccepts (const MimeMessage &message)
 Step 2 of a user-started chat: the contact accepts.
virtual void userStarted3_UserPrepares ()
 Step 3 of a user-started chat: the user prepares for the session.
bool writeP2PDataToFile (const P2PMessage &message, QIODevice *file)
 Utility function to write P2P data to a file, also deals with message offsets.

Private Slots

void slotConnectionAuthorized ()
 Called when the direct connection is authorized by one of the P2P applications.
void slotConnectionEstablished ()
 Called when the direct connection is established.
void slotConnectionFailed ()
 Called when a direct connection could not be made.

Private Member Functions

void gotAck (const P2PMessage &message, const P2PMessageType messageType)
 Parse the received ACK message.
void gotAck_dataPreparation ()
 Called when the ACK for the data preparation was received.
void gotAck_dataReceived ()
 Called when the ACK for the sent file data was received.
void gotAck_slpBye ()
 Called when the ACK for the SLP BYE message was received.
void gotAck_slpError ()
 Called when the ACK for a SLP Error was received.
void gotAck_slpSessionInvitation ()
 Called when the ACK for the first SLP INVITE message was received.
void gotAck_slpSessionOk ()
 Called when the ACK of the SLP OK message was received.
void gotAck_slpTransferDecline ()
 Called when the ACK for the SLP transfer decline message was received.
void gotAck_slpTransferInvitation ()
 Called when the ACK for the SLP transfer INVITE message was received.
void gotAck_slpTransferOk ()
 Called when the ACK for the SLP transfer OK mesages was received.
void gotDataPreparation (const P2PMessage &message)
 Called when the data preparation message is received.
void gotDirectConnectionHandshake (const P2PMessage &message)
 Got an direct connection handshake ack.
void gotNegotiationMessage (const MimeMessage &slpMessage, const QString &preamble)
 Called when an complete SLP message is received.
void gotSlpAck (const MimeMessage &slpMessage)
 Called when an SLP ACK message was received.
void gotSlpBye (const MimeMessage &slpMessage)
 Called when an SLP BYE message was received.
void gotSlpInvite (const MimeMessage &slpMessage)
 Called when a SLP INVITE message was received.
void gotSlpOk (const MimeMessage &slpMessage)
 Called when a SLP 200 OK message was received.
void gotSlpSessionInvitation (const MimeMessage &slpMimeBody)
 Called when a SLP session invitation was received.
void gotSlpStatus (const MimeMessage &slpMessage, const QString &preamble)
 Called when a SLP status message was received.
void gotSlpTransferInvitation (const MimeMessage &slpMimeBody)
 Called when a SLP transfer invitation was received.
void gotSlpTransferResponse (const MimeMessage &slpMimeBody, bool secondInvite=false)
 Called when a response to a SLP transfer message was received.
void initiateTransfer ()
 Notify the derived class it can initiate the file transfer.
void sendSlpBye ()
 Send a SLP BYE message to close the session.
void sendSlpError (const QString &statusLine, const ulong sessionID=0, const QString &messageContentType=0, P2PMessageType messageType=P2P_MSG_SLP_ERROR)
 Send an SLP error response.
void sendSlpInvitation (const MimeMessage &message, const QString &contentType, P2PMessageType messageType)
 Utility function to send an SLP INVITE message.
void showTimeoutMessage (P2PWaitingState waitingState)
 Show a timeout message because an expected message was not received.

Private Attributes

ApplicationListapplicationList_
QString branch_
QString callID_
bool gotSlpMessage_
QString invitationContentType_
int invitationCSeq_
quint32 invitationSessionID_
QString nonce_
quint32 sessionID_
bool userShouldAcknowledge_

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index