[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdenetwork/kopete/protocols/msn
From:       Olivier Goffart <ogoffart () kde ! org>
Date:       2005-04-09 9:51:30
Message-ID: 20050409095130.06436494 () office ! kde ! org
[Download RAW message or body]

CVS commit by ogoffart: 

Make some code a litlle bit cleaner


  M +19 -32    msnp2p.cpp   1.32


--- kdenetwork/kopete/protocols/msn/msnp2p.cpp  #1.31:1.32
@@ -41,5 +41,13 @@
 #include <kopetetransfermanager.h>
 
-
+/**
+ * if VAR is a char*  and VAL is an integer, assing VAR[START] to VAR[START+4]  the value of VAL
+ */
+#define MKDWORD(VAR, START, VAL) {\
+        (VAR)[(START)]=  (char)( ((VAL)&0x000000FF) ) ;  \
+        (VAR)[(START)+1]=(char)( ((VAL)&0x0000FF00)  >> 8 ) ; \
+        (VAR)[(START)+2]=(char)( ((VAL)&0x00FF0000)  >> 16 ) ; \
+        (VAR)[(START)+3]=(char)( ((VAL)&0xFF000000)  >> 24 ) ; \
+}
 
 MSNP2P::MSNP2P( unsigned long int sessionID , MSNP2PDisplatcher *parent ) : QObject (parent)
@@ -141,22 +149,13 @@ void MSNP2P::sendP2PMessage(const QByteA
 
 
-        //SessionID     (it's byll if the transfer has not started.  (i.e the footer == 0)
-        unsigned long int sessionID= m_footer ? m_sessionId : 0;
-        binHeader[0]=(char)(sessionID%256);
-        binHeader[1]=(char)((unsigned long int)(sessionID/256)%256);
-        binHeader[2]=(char)((unsigned long int)(sessionID/(256*256))%256);
-        binHeader[3]=(char)((unsigned long int)(sessionID/(256*256*256))%256);
+        //SessionID     (it's nyll if the transfer has not started.  (i.e the footer == 0)
+        if(m_footer)
+                MKDWORD(binHeader,0,m_sessionId);
 
         //MessageID
-        binHeader[4]=(char)(m_msgIdentifier%256);
-        binHeader[5]=(char)((unsigned long int)(m_msgIdentifier/256)%256);
-        binHeader[6]=(char)((unsigned long int)(m_msgIdentifier/(256*256))%256);
-        binHeader[7]=(char)((unsigned long int)(m_msgIdentifier/(256*256*256))%256);
+        MKDWORD(binHeader,4,m_msgIdentifier);
 
         //offset
-        binHeader[8]=(char)(m_offset%256);
-        binHeader[9]=(char)((unsigned long int)(m_offset/256)%256);
-        binHeader[10]=(char)((unsigned long int)(m_offset/(256*256))%256);
-        binHeader[11]=(char)((unsigned long int)(m_offset/(256*256*256))%256);
+        MKDWORD(binHeader,8,m_offset);
 
         unsigned int size=dataMessage.size();
@@ -164,8 +162,5 @@ void MSNP2P::sendP2PMessage(const QByteA
         if(m_totalDataSize) //it's a splitted message
         {
-                binHeader[16]=(char)(m_totalDataSize%256);
-                binHeader[17]=(char)((unsigned long int)(m_totalDataSize/256)%256);
-                binHeader[18]=(char)((unsigned long int)(m_totalDataSize/(256*256))%256);
-                binHeader[19]=(char)((unsigned long int)(m_totalDataSize/(256*256*256))%256);
+                MKDWORD(binHeader,16,m_totalDataSize);
 
                 //update offset
@@ -179,18 +174,13 @@ void MSNP2P::sendP2PMessage(const QByteA
         else //not a splitted message, the total size is the current size
         {
-                binHeader[16]=(char)size%256;
-                binHeader[17]=(int)size/256;
+                MKDWORD(binHeader,16,size);
         }
 
         //message size
-        binHeader[24]=(char)size%256;
-        binHeader[25]=(int)size/256;
+        MKDWORD(binHeader,24,size);
 
         //Ack sessionID
 #if ! MSN_WEBCAM
-        binHeader[32]=(char)(rand()%256);
-        binHeader[33]=(char)(rand()%256);
-        binHeader[34]=(char)(rand()%256);
-        binHeader[35]=(char)(rand()%256);
+        MKDWORD(binHeader,32,rand()%0x8FFFFFF0+4);
 #else
         //For webcam, the OK and INVITE message should have the smae id, but not others.
@@ -247,8 +237,5 @@ void MSNP2P::sendP2PAck( const char* ori
         else
                 m_msgIdentifier++;
-        binHeader[4]=(char)(m_msgIdentifier%256);
-        binHeader[5]=(char)((unsigned long int)(m_msgIdentifier/256)%256);
-        binHeader[6]=(char)((unsigned long int)(m_msgIdentifier/(256*256))%256);
-        binHeader[7]=(char)((unsigned long int)(m_msgIdentifier/(256*256*256))%256);
+        MKDWORD(binHeader,4,m_msgIdentifier);
 
         if(a)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic