gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cleanup encoding of concatenated message header


From: Pavel Machek
Subject: Cleanup encoding of concatenated message header
Date: Mon, 3 Jun 2002 23:21:40 +0200
User-agent: Mutt/1.3.28i

Hi!

I changed EncodeUDH so that it returns pointer to header it
added. With this, it is easy to modify the header, which is needed for
for example concatenated messages. Commited.
                                                                Pavel

Index: common/gsm-sms.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/gsm-sms.c,v
retrieving revision 1.87
diff -u -u -r1.87 gsm-sms.c
--- common/gsm-sms.c    3 Jun 2002 20:30:45 -0000       1.87
+++ common/gsm-sms.c    3 Jun 2002 21:16:44 -0000
@@ -958,15 +958,18 @@
  * @SMS: SMS structure with the data source
  * @UDH: phone frame where to save User Data Header
  *
+ * returns pointer to data it added;
+ *
  * This function encodes the UserDataHeader as described in:
  *  o GSM 03.40 version 6.1.0 Release 1997, section 9.2.3.24
  *  o Smart Messaging Specification, Revision 1.0.0, September 15, 1997
  *  o Smart Messaging Specification, Revision 3.0.0
  */
-static GSM_Error EncodeUDH(GSM_SMSMessage *rawsms, int type)
+static char *EncodeUDH(GSM_SMSMessage *rawsms, int type)
 {
        unsigned char pos;
        char *UDH = rawsms->UserData;
+       char *res;
 
        pos = UDH[0];
 
@@ -976,7 +979,7 @@
        case SMS_VoiceMessage:
        case SMS_FaxMessage:
        case SMS_EmailMessage:
-               return GE_NOTSUPPORTED;
+               return NULL;
 #if 0
                UDH[pos+4] = UDHi.u.SpecialSMSMessageIndication.MessageCount;
                if (UDHi.u.SpecialSMSMessageIndication.Store) UDH[pos+3] |= 
0x80;
@@ -988,7 +991,8 @@
        case SMS_Ringtone:
        case SMS_MultipartMessage:
                UDH[0] += headers[type].length;
-               memcpy(UDH+pos+1, headers[type].header, headers[type].length);
+               res = UDH+pos+1;
+               memcpy(res, headers[type].header, headers[type].length);
                rawsms->UserDataLength += headers[type].length;
                rawsms->Length += headers[type].length;
                break;
@@ -1001,15 +1005,16 @@
                rawsms->Length++;               /* Length takes one byte, too */
                rawsms->UserDataLength++;
        }
-       return GE_NONE;
+       return res;
 }
 
 static GSM_Error EncodeConcatHeader(GSM_SMSMessage *rawsms, int this, int 
total)
 {
-       EncodeUDH(rawsms, SMS_ConcatenatedMessages);
-       rawsms->UserData[ 9] = 0xce;
-       rawsms->UserData[10] = total;
-       rawsms->UserData[11] = this;
+       char *header = EncodeUDH(rawsms, SMS_ConcatenatedMessages);
+       if (!header) return GE_NOTSUPPORTED;
+       header[2] = 0xce;               /* Message serial number */
+       header[3] = total;
+       header[4] = this;
        return GE_NONE;
 }
 
@@ -1084,18 +1089,16 @@
        }
 
        rawsms->Length = rawsms->UserDataLength = 0;
 
        for (i=0; i<SMS_MAX_PART_NUMBER; i++) {
                switch (sms->UserData[i].Type) {
                case SMS_BitmapData:
-                       error = GE_NONE;
                        switch (sms->UserData[0].u.Bitmap.type) {
-                       case GSM_OperatorLogo: error = EncodeUDH(rawsms, 
SMS_OpLogo); break;
+                       case GSM_OperatorLogo: if (!EncodeUDH(rawsms, 
SMS_OpLogo)) return GE_NOTSUPPORTED; break;
                        case GSM_PictureMessage: 
                        case GSM_EMSPicture:
                        case GSM_EMSAnimation: break;   /* We'll construct 
headers in EncodeSMSBitmap */
                        }
-                       if (error != GE_NONE) return error;
                        size = 
GSM_EncodeSMSBitmap(&(sms->UserData[i].u.Bitmap), rawsms->UserData + 
rawsms->UserDataLength);
                        rawsms->Length += size;
                        rawsms->UserDataLength += size;
@@ -1115,7 +1124,7 @@
                        break;
 
                case SMS_PlainText: {
-                       unsigned int length, offset = 0;
+                       unsigned int length, offset = rawsms->UserDataLength;
 
                        length = strlen(sms->UserData[0].u.Text);
                        switch (al) {
@@ -1160,8 +1169,7 @@
 
                case SMS_MultiData:
                        size = sms->UserData[0].Length;
-                       error = EncodeUDH(rawsms, SMS_MultipartMessage);
-                       if (error != GE_NONE) return error;
+                       if (!EncodeUDH(rawsms, SMS_MultipartMessage)) return 
GE_NOTSUPPORTED;
                        error = EncodeConcatHeader(rawsms, 
sms->UserData[i].u.Multi.this, sms->UserData[i].u.Multi.total);
                        if (error != GE_NONE) return error;
 
@@ -1172,8 +1180,7 @@
                        break;
 
                case SMS_RingtoneData:
-                       error = EncodeUDH(rawsms, SMS_Ringtone); 
-                       if (error != GE_NONE) return error;
+                       if (!EncodeUDH(rawsms, SMS_Ringtone)) return 
GE_NOTSUPPORTED;
                        size = GSM_EncodeSMSRingtone(rawsms->UserData + 
rawsms->Length, &sms->UserData[i].u.Ringtone);
                        rawsms->Length += size;
                        rawsms->UserDataLength += size;

-- 
(about SSSCA) "I don't say this lightly.  However, I really think that the U.S.
no longer is classifiable as a democracy, but rather as a plutocracy." --hpa



reply via email to

[Prev in Thread] Current Thread [Next in Thread]