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

void P2PApplication::sendP2PMessage ( const QByteArray &  messageData,
int  flagField = 0,
uint  footerCode = 0 
) [private]

Constructs and sends an P2P Message.

This method includes some of the global fields in the message body.

Parameters:
messageData The message to send. This could be a binary file data block.
flagField The flag-field content.
footerCode The message footer.

Definition at line 1639 of file p2papplication.cpp.

References generateID(), and P2PMessage::insertBytes().

Referenced by sendCancelMessage(), sendDataPreparation(), sendSlpMessage(), and slotSendData().

{
#ifdef KMESSTEST
  ASSERT( messageData.size() <= 1202 );
#endif

  MimeMessage message;

  // Reset this flag to make sure no other
  // "500 Internal Error" will be sent afterwards.
  gotSlpMessage_ = false;

  // Initialize the header
  QByteArray header(48);
  header.fill(0x00);


  // Determine the message ID:
  if(messageID_ == 0)
  {
    // This is the first P2P message we send, initialize message ID
    messageID_ = generateID();
  }
  else if(messageOffset_ == 0)
  {
    // Only increments the ID if this is not a "fragmented message".
    messageID_++;
  }


  // Determine the message size:
  uint messageSize = messageData.size();
  uint totalSize;
  uint offsetField;

  if(messageTotalSize_ == 0)
  {
    // Normal message:
    totalSize   = messageData.size();
    offsetField = 0;
  }
  else
  {
    // Splitted message:
    totalSize   = messageTotalSize_;
    offsetField = messageOffset_;
  }


  // Generate Unique ID for this message
  lastUniqueID_ = generateID();



  // Update the header
  P2PMessage::insertBytes(header, sessionID_,     0);    // 1: Session ID
  P2PMessage::insertBytes(header, messageID_,     4);    // 2: BaseIdentifier (starts random [4, 4294967295])
  P2PMessage::insertBytes(header, offsetField,    8);    // 3: Offset (if more then 1202 bytes to send)
  P2PMessage::insertBytes(header, totalSize,      16);   // 4: Total size of the message
  P2PMessage::insertBytes(header, messageSize,    24);   // 5: This message size, size of previous if no data
  P2PMessage::insertBytes(header, flagField,      28);   // 6: Message type (flags)
  P2PMessage::insertBytes(header, lastUniqueID_,  32);   // 7: Field2 of previous for ACK-messages (base message ID)
//P2PMessage::insertBytes(header, 0,              36);   // 8: Field7 of previous for ACK-messages (unique ID)
//P2PMessage::insertBytes(header, 0,              40);   // 9: Field4 of previous for ACK-messages (size)


  // Update the offset fields for splitted messages
  if(messageTotalSize_ != 0)
  {
    messageOffset_ += messageSize;
    // If we transmitted all parts, reset the fields for the next normal message
    if(messageOffset_ >= messageTotalSize_)
    {
      messageOffset_    = 0;
      messageTotalSize_ = 0;
    }
  }


  // At the end of the message we need to add an footer of 4 bytes.
  // This is little endian format, so we can't use P2PMessage::insertBytes()
  //
  // Possible values:
  //  0x00 session
  //  0x01 for display/emoticon
  //  0x02 filetransfer, or start menu code

  char footer[4];
  footer[0] = (char) ((footerCode >> 24) & 0xFF);
  footer[1] = (char) ((footerCode >> 16) & 0xFF);
  footer[2] = (char) ((footerCode >>  8) & 0xFF);
  footer[3] = (char) ( footerCode        & 0xFF);


  // Assign the message fields
  message.addField("MIME-Version", "1.0");
  message.addField("Content-Type", "application/x-msnmsgrp2p");
  message.addField("P2P-Dest",     contactHandle_);
  message.setBinaryData(header.data(), messageData.data(), footer, messageData.size());


  // Send the message
  emit putMsg(message);


#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kdDebug() << "P2PApplication: Message transmitted "
            << "(SID="         << sessionID_
            << " MID="         << messageID_
            << " UID="         << lastUniqueID_
            << " flags="       << flagField
            << " size="        << messageSize
            << ")" << endl;
#endif
}


Generated by  Doxygen 1.6.0   Back to index