gnokii-users
[Top][All Lists]
Advanced

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

Introducing: NokiaText type


From: Pavel Machek
Subject: Introducing: NokiaText type
Date: Sat, 1 Jun 2002 00:57:44 +0200
User-agent: Mutt/1.3.28i

Hi!

It seems to me that NokiaText is slightly different from PlainText;
NokiaText can only be used inside PictureMessage and it carries length
with itself.

It allowed me to clean EncodeData a bit more, getting rid of *_index
variables. It now looks like this:

If there are no big complains, I'll commit it. It looks better to my
eyes ;-).
                                                                Pavel

--- gnokii.ofic/common/gsm-sms.c        Fri May 31 21:53:04 2002
+++ gnokii.ofic2/common/gsm-sms.c       Sat Jun  1 00:53:11 2002
@@ -585,7 +585,7 @@
 
                        size = rawsms->UserDataLength - 4 - 
sms->UserData[0].u.Bitmap.size;
                        /* Second part is a text */
-                       sms->UserData[1].Type = SMS_PlainText;
+                       sms->UserData[1].Type = SMS_NokiaText;
                        DecodeData(rawsms->UserData + 5 + 
sms->UserData[0].u.Bitmap.size,
                                   (unsigned char *)&(sms->UserData[1].u.Text),
                                   rawsms->Length - 
sms->UserData[0].u.Bitmap.size - 4,
@@ -595,7 +595,7 @@
                        dprintf("First text then picture!\n");
 
                        /* First part is a text */
-                       sms->UserData[1].Type = SMS_PlainText;
+                       sms->UserData[1].Type = SMS_NokiaText;
                        DecodeData(rawsms->UserData + 3,
                                   (unsigned char *)&(sms->UserData[1].u.Text),
                                   rawsms->UserData[1], rawsms->UserData[0], 0, 
sms->DCS);
@@ -998,6 +998,26 @@
        return GE_NONE;
 }
 
+/* Returns used length */
+int EncodeNokiaText(char *text, char *message)
+{
+       int current = 0;
+       /* FIXME: unicode length is not as simple as strlen */
+       int uni = 0, len;                    /* 0 .. ISO-8859-1, 1 .. Unicode */
+
+       message[current++]=uni;
+
+       /* Length for text part */
+       len = strlen(text)*(uni + 1);
+       message[current++]=0x00;
+       message[current++]=len;
+       if (uni)
+               EncodeUnicode(message+current, text, strlen(text));
+       else
+               memcpy(message+current, text, strlen(text));
+       current += len;
+       return current;
+}
 
 /**
  * EncodeData - encodes the date from the SMS structure to the phone frame
@@ -1011,36 +1031,13 @@
  * This function does the phone frame encoding basing on the given SMS
  * structure. This function is capable to create only one frame at a time.
  */
-GSM_Error EncodeData(GSM_API_SMS *sms, GSM_SMSMessage *rawsms, bool multipart)
+GSM_Error EncodeData(GSM_API_SMS *sms, GSM_SMSMessage *rawsms)
 {
-       SMS_AlphabetType al;
-       unsigned int i, length, size = 0, offset = 0;
-       int text_index = -1, bitmap_index = -1, ringtone_index = -1, 
imelody_index = -1, multi_index = -1;
+       SMS_AlphabetType al = SMS_DefaultAlphabet;
+       unsigned int i, size = 0, offset = 0;
        char *message = rawsms->UserData;
        GSM_Error error;
 
-       for (i = 0; i < 3; i++) {
-               switch (sms->UserData[i].Type) {
-               case SMS_PlainText:
-                       text_index = i; break;
-               case SMS_BitmapData:
-                       bitmap_index = i; break;
-               case SMS_RingtoneData:
-                       ringtone_index = i; break;
-               case SMS_iMelodyText:
-                       imelody_index = i; break;
-               case SMS_MultiData:
-                       multi_index = i; break;
-               case SMS_NoData:
-                       break;
-               default:
-                       fprintf(stderr, "What kind of ninja-mutant UserData is 
this?\n");
-                       break;
-               }
-       }
-
-       length = strlen(sms->UserData[0].u.Text);
-
        /* Additional Headers */
        switch (sms->DCS.Type) {
        case SMS_GeneralDataCoding:
@@ -1072,118 +1069,108 @@
                return GE_SMSWRONGFORMAT;
        }
 
-       if ((al == SMS_8bit) && multipart) al = SMS_DefaultAlphabet;
        rawsms->Length = rawsms->UserDataLength = 0;
 
-       /* Bitmap coding */
-       if (bitmap_index != -1) {
-               error = GE_NONE;
-               switch (sms->UserData[0].u.Bitmap.type) {
-               case GSM_OperatorLogo: error = EncodeUDH(rawsms, SMS_OpLogo, 
message); break;
-               case GSM_PictureMessage: 
-               case GSM_EMSPicture:
-               case GSM_EMSAnimation: break;   /* We'll construct headers in 
EncodeSMSBitmap */
-               }
-               if (error != GE_NONE) return error;
+       for (i=0; i<3; 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, message); break;
+                       case GSM_PictureMessage: 
+                       case GSM_EMSPicture:
+                       case GSM_EMSAnimation: break;   /* We'll construct 
headers in EncodeSMSBitmap */
+                       }
+                       if (error != GE_NONE) return error;
 
-               if (text_index != -1) {         /* This is quite a dirty hack */
-                       if (sms->UserData[0].u.Bitmap.type != 
GSM_PictureMessage)
-                               return GE_SMSWRONGFORMAT;
-                       strcpy(sms->UserData[bitmap_index].u.Bitmap.text, 
sms->UserData[text_index].u.Text);
-                       text_index = -1;
-               }
+                       size = 
GSM_EncodeSMSBitmap(&(sms->UserData[i].u.Bitmap), message + 
rawsms->UserDataLength);
+                       rawsms->Length += size;
+                       rawsms->UserDataLength += size;
+                       rawsms->DCS = 0xf5;
+                       rawsms->UDHIndicator = 1;
+                       break;
 
-               size = 
GSM_EncodeSMSBitmap(&(sms->UserData[bitmap_index].u.Bitmap), message + 
rawsms->UserDataLength);
-               rawsms->Length += size;
-               rawsms->UserDataLength += size;
-               rawsms->DCS = 0xf5;
-               rawsms->UDHIndicator = 1;
-       }
-
-       /* Text Coding */
-       if (text_index != -1) {
-               switch (al) {
-               case SMS_DefaultAlphabet:
-                       if (multipart) {
-                               offset = 4;
-                               memcpy(message + 1, "\x00\x00\x00", 3);
-                               rawsms->DCS |= 0xf4;
-                       }
+               case SMS_PlainText: {
+                       unsigned int length;
+
+                       length = strlen(sms->UserData[0].u.Text);
+                       switch (al) {
+                       case SMS_DefaultAlphabet:
 #define UDH_Length 0
-                       size = Pack7BitCharacters((7 - (UDH_Length % 7)) % 7, 
sms->UserData[text_index].u.Text, message + offset);
-                       // sms->Length = 8 * 0 + (7 - (0 % 7)) % 7 + length + 
offset;
-                       rawsms->Length = 
strlen(sms->UserData[text_index].u.Text);
-                       rawsms->UserDataLength = size + offset;
-                       if (multipart) {
-                               message[2] = (size & 0xff00) >> 8;
-                               message[3] = (size & 0x00ff);
+                               size = Pack7BitCharacters((7 - (UDH_Length % 
7)) % 7, sms->UserData[i].u.Text, message + offset);
+                               // sms->Length = 8 * 0 + (7 - (0 % 7)) % 7 + 
length + offset;
+                               rawsms->Length = 
strlen(sms->UserData[i].u.Text);
+                               rawsms->UserDataLength = size + offset;
+                               break;
+                       case SMS_8bit:
+                               rawsms->DCS |= 0xf4;
+                               memcpy(message, sms->UserData[i].u.Text + 1, 
sms->UserData[i].u.Text[0]);
+                               rawsms->UserDataLength = rawsms->Length = 
sms->UserData[i].u.Text[0];
+                               break;
+                       case SMS_UCS2:
+                               rawsms->DCS |= 0x08;
+                               EncodeUnicode(message + offset, 
sms->UserData[i].u.Text, length);
+                               length *= 2;
+                               rawsms->UserDataLength = rawsms->Length = 
length + offset;
+                               break;
+                       default:
+                               return GE_SMSWRONGFORMAT;
                        }
                        break;
-               case SMS_8bit:
-                       rawsms->DCS |= 0xf4;
-                       memcpy(message, sms->UserData[text_index].u.Text + 1, 
sms->UserData[text_index].u.Text[0]);
-                       rawsms->UserDataLength = rawsms->Length = 
sms->UserData[text_index].u.Text[0];
+               }
+
+               case SMS_NokiaText:
+                       size = EncodeNokiaText(sms->UserData[i].u.Text, message 
+ rawsms->UserDataLength);
+                       rawsms->Length += size;
+                       rawsms->UserDataLength += size;
                        break;
-               case SMS_UCS2:
-                       if (multipart) {
-                               offset = 4;
-                               memcpy(message + 1, "\x02\x00\x00", 3);
-                       }
-                       rawsms->DCS |= 0x08;
-                       EncodeUnicode(message + offset, 
sms->UserData[text_index].u.Text, length);
-                       length *= 2;
-                       rawsms->UserDataLength = rawsms->Length = length + 
offset;
-                       if (multipart) {
-                               message[2] = (length & 0xff00) >> 8;
-                               message[3] = (length & 0x00ff);
-                       }
+
+               case SMS_iMelodyText:
+                       size = GSM_EncodeSMSiMelody(sms->UserData[i].u.Text, 
message + rawsms->UserDataLength);
+                       dprintf("Imelody, size %d\n", size);
+                       rawsms->Length += size;
+                       rawsms->UserDataLength += size;
+                       rawsms->DCS = 0xf5;
+                       rawsms->UDHIndicator = 1;
                        break;
-               default:
-                       return GE_SMSWRONGFORMAT;
-               }
-       }
 
-       /* iMelody coding */
-       if (imelody_index != -1) {
-               size = GSM_EncodeSMSiMelody(sms->UserData[0].u.Text, message + 
rawsms->UserDataLength);
-               printf("Imelody, size %d\n", size);
-               rawsms->Length += size;
-               rawsms->UserDataLength += size;
-               rawsms->DCS = 0xf5;
-               rawsms->UDHIndicator = 1;
-       }
+               case SMS_MultiData:
+                       size = sms->UserData[0].Length;
+                       error = EncodeUDH(rawsms, 0x05, message);
+                       if (error != GE_NONE) return error;
+
+                       message[0] += 5;
+                       rawsms->Length += 5;
+                       rawsms->UserDataLength += 5;
+                       rawsms->UserData[ 7] = 0x00;
+                       rawsms->UserData[ 8] = 0x03;
+                       rawsms->UserData[ 9] = 0xce;
+                       rawsms->UserData[10] = sms->UserData[i].u.Multi.total;
+                       rawsms->UserData[11] = sms->UserData[i].u.Multi.this;
+
+                       memcpy(message + rawsms->UserDataLength, 
sms->UserData[i].u.Multi.Binary, MAX_SMS_PART);
+                       rawsms->Length += size;
+                       rawsms->UserDataLength += size;
+                       rawsms->DCS = 0xf5;
+                       rawsms->UDHIndicator = 1;
+                       break;
 
-       /* MultiData coding */
-       if (multi_index != -1) {
-               size = sms->UserData[0].Length;
-               error = EncodeUDH(rawsms, 0x05, message);
-               if (error != GE_NONE) return error;
+               case SMS_RingtoneData:
+                       error = EncodeUDH(rawsms, SMS_Ringtone, message); 
+                       if (error != GE_NONE) return error;
+                       size = GSM_EncodeSMSRingtone(message + rawsms->Length, 
&sms->UserData[i].u.Ringtone);
+                       rawsms->Length += size;
+                       rawsms->UserDataLength += size;
+                       rawsms->DCS = 0xf5;
+                       rawsms->UDHIndicator = 1;
+                       break;
 
-               message[0] += 5;
-               rawsms->Length += 5;
-               rawsms->UserDataLength += 5;
-               rawsms->UserData[ 7] = 0x00;
-               rawsms->UserData[ 8] = 0x03;
-               rawsms->UserData[ 9] = 0xce;
-               rawsms->UserData[10] = sms->UserData[multi_index].u.Multi.total;
-               rawsms->UserData[11] = sms->UserData[multi_index].u.Multi.this;
-
-               memcpy(message + rawsms->UserDataLength, 
sms->UserData[multi_index].u.Multi.Binary, MAX_SMS_PART);
-               rawsms->Length += size;
-               rawsms->UserDataLength += size;
-               rawsms->DCS = 0xf5;
-               rawsms->UDHIndicator = 1;               
-       }
-
-       /* Ringtone coding */
-       if (ringtone_index != -1) {
-               error = EncodeUDH(rawsms, SMS_Ringtone, message); 
-               if (error != GE_NONE) return error;
-               size = GSM_EncodeSMSRingtone(message + rawsms->Length, 
&sms->UserData[ringtone_index].u.Ringtone);
-               rawsms->Length += size;
-               rawsms->UserDataLength += size;
-               rawsms->DCS = 0xf5;
-               rawsms->UDHIndicator = 1;
+               case SMS_NoData:
+                       return GE_NONE;
+
+               default:
+                       fprintf(stderr, "What kind of ninja-mutant UserData is 
this?\n");
+               }
        }
        return GE_NONE;
 }
@@ -1204,7 +1191,7 @@
                return GE_NOTSUPPORTED;
        }
 
-       EncodeData(SMS, rawsms, 0);
+       EncodeData(SMS, rawsms);
 
        return GE_NONE;
 }
@@ -1283,7 +1270,7 @@
        if (error != GE_NONE) return error;
 
        if (data->RawSMS->Length > 171) {
-               printf("SMS is too long? %d\n", data->RawSMS->Length);
+               dprintf("SMS is too long? %d\n", data->RawSMS->Length);
                return SendLongSMS(data, state);
        }
 
Binary files gnokii.ofic/common/libgnokii.so and 
gnokii.ofic2/common/libgnokii.so differ
Binary files gnokii.ofic/gnokii/gnokii and gnokii.ofic2/gnokii/gnokii differ
diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x *.rej 
-x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x compile.h 
-x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x 
vmlinuz -x TAGS -x bootsect -x *RCS* -x conmakehash -x map -x build -x build -x 
configure -x *target* -x *.flags -x *.bak gnokii.ofic/gnokii/gnokii.c 
gnokii.ofic2/gnokii/gnokii.c
--- gnokii.ofic/gnokii/gnokii.c Thu May 30 11:39:26 2002
+++ gnokii.ofic2/gnokii/gnokii.c        Sat Jun  1 00:09:53 2002
@@ -1457,10 +1457,9 @@
                }
        }
 
-       /* FIXME: read from the stdin */
        sms.UserData[1].Type = SMS_NoData;
        if (sms.UserData[0].u.Bitmap.type == GSM_PictureMessage) {
-               sms.UserData[1].Type = SMS_PlainText;
+               sms.UserData[1].Type = SMS_NokiaText;
                readtext(&sms.UserData[1], 120);
                sms.UserData[2].Type = SMS_NoData;
                //              strcpy(sms.UserData[1].u.Text, "Ahoj, tohle je 
mala zprava na testovani telefonu");
Binary files gnokii.ofic/gnokiid/gnokiid and gnokii.ofic2/gnokiid/gnokiid differ
diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x *.rej 
-x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x compile.h 
-x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x 
vmlinuz -x TAGS -x bootsect -x *RCS* -x conmakehash -x map -x build -x build -x 
configure -x *target* -x *.flags -x *.bak gnokii.ofic/include/gsm-sms.h 
gnokii.ofic2/include/gsm-sms.h
--- gnokii.ofic/include/gsm-sms.h       Fri May 31 21:50:01 2002
+++ gnokii.ofic2/include/gsm-sms.h      Sat Jun  1 00:08:41 2002
@@ -305,7 +305,8 @@
        SMS_RingtoneData = 0x03,
        SMS_iMelodyText  = 0x04,
        SMS_MultiData    = 0x05,
-       SMS_OtherData    = 0x06
+       SMS_NokiaText    = 0x06,
+       SMS_OtherData    = 0x07
 } SMS_DataType;
 
 /*** FOLDER INFO ***/

-- 
(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]