gnokii-users
[Top][All Lists]
Advanced

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

Possibility to send text with PictureMessage


From: Pavel Machek
Subject: Possibility to send text with PictureMessage
Date: Thu, 30 May 2002 11:11:06 +0200
User-agent: Mutt/1.3.28i

Hi!

This adds possibility to send user-defined text along with picture
message. Plus, in case of multiple messages being sent, it makes the
last one smaller. Hopefully this fixes Nokia crash on receiving of
such message. Will commit to CVS, soon.
                                                                Pavel

--- gnokii.ofic/common/gsm-sms.c        Thu May 30 01:09:58 2002
+++ gnokii.new/common/gsm-sms.c Thu May 30 02:18:19 2002
@@ -1026,9 +1026,9 @@
        for (i = 0; i < 3; i++) {
                switch (sms->UserData[i].Type) {
                case SMS_PlainText:
-                       text_index     = i; break;
+                       text_index = i; break;
                case SMS_BitmapData:
-                       bitmap_index   = i; break;
+                       bitmap_index = i; break;
                case SMS_RingtoneData:
                        ringtone_index = i; break;
                case SMS_iMelodyText:
@@ -1079,6 +1079,35 @@
        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_EMSPicture:
+               case GSM_PictureMessage:
+               case GSM_EMSAnimation: break;   /* We'll construct headers in 
EncodeSMSBitmap */
+               }
+               if (error != GE_NONE) return error;
+
+#ifdef BITMAP_SUPPORT
+               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[bitmap_index].u.Bitmap), message + 
rawsms->UserDataLength);
+               rawsms->Length += size;
+               rawsms->UserDataLength += size;
+               rawsms->DCS = 0xf5;
+               rawsms->UDHIndicator = 1;
+#else
+               return GE_NOTSUPPORTED;
+#endif
+       }
+
        /* Text Coding */
        if (text_index != -1) {
                switch (al) {
@@ -1134,7 +1163,7 @@
 
        /* MultiData coding */
        if (multi_index != -1) {
-               size = 128;
+               size = sms->UserData[0].Length;
                error = EncodeUDH(rawsms, 0x05, message);
                rawsms->UserData[10] = sms->UserData[multi_index].u.Multi.total;
                rawsms->UserData[11] = sms->UserData[multi_index].u.Multi.this;
@@ -1146,27 +1175,6 @@
                rawsms->UDHIndicator = 1;               
        }
 
-       /* 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_EMSPicture:
-               case GSM_PictureMessage:
-               case GSM_EMSAnimation: break;   /* We'll construct headers in 
EncodeSMSBitmap */
-               }
-               if (error != GE_NONE) return error;
-
-#ifdef BITMAP_SUPPORT
-               size = 
GSM_EncodeSMSBitmap(&(sms->UserData[bitmap_index].u.Bitmap), message + 
rawsms->UserDataLength);
-               rawsms->Length += size;
-               rawsms->UserDataLength += size;
-               rawsms->DCS = 0xf5;
-               rawsms->UDHIndicator = 1;
-#else
-               return GE_NOTSUPPORTED;
-#endif
-       }
 
        /* Ringtone coding */
        if (ringtone_index != -1) {
@@ -1236,9 +1244,13 @@
        for (i=0; i<count; i++) {
                printf("Sending sms #%d\n", i);
                sms.UserData[0].Type = SMS_MultiData;
+               sms.UserData[0].Length = 128;
+               if (i+1 == count)
+                       sms.UserData[0].Length = rawsms->UserDataLength % 128;
                memcpy(sms.UserData[0].u.Multi.Binary, rawsms->UserData + 
i*128, 128);
                sms.UserData[0].u.Multi.this = i+1;
                sms.UserData[0].u.Multi.total = count;
+               sms.UserData[1].Type = SMS_NoData;
                data->SMS = &sms;
                error = SendSMS(data, state);
                if (error != GE_NONE) return error;
--- gnokii.ofic/gnokii/gnokii.c Wed May 29 13:33:06 2002
+++ gnokii.new/gnokii/gnokii.c  Thu May 30 02:29:50 2002
@@ -411,6 +411,35 @@
        exit(1);
 }
 
+static GSM_Error readtext(SMS_UserData *udata, int input_len)
+{
+       char message_buffer[255 * GSM_MAX_SMS_LENGTH];
+       int chars_read;
+
+       fprintf(stderr, _("Please enter SMS text. End your input with 
<cr><control-D>:"));
+
+       /* Get message text from stdin. */
+       chars_read = fread(message_buffer, 1, sizeof(message_buffer), stdin);
+
+       if (chars_read == 0) {
+               fprintf(stderr, _("Couldn't read from stdin!\n"));
+               return GE_INTERNALERROR;
+       } else if (chars_read > input_len || chars_read > sizeof(udata->u.Text) 
- 1) {
+               fprintf(stderr, _("Input too long! (%d, maximum is %d)\n"), 
chars_read, input_len);
+               return GE_INTERNALERROR;
+       }
+
+       /*  Null terminate. */
+       message_buffer[chars_read] = 0x00;
+       if (udata->Type != SMS_iMelodyText && chars_read > 0 && 
message_buffer[chars_read - 1] == '\n') 
+               message_buffer[--chars_read] = 0x00;
+       strncpy(udata->u.Text, message_buffer, chars_read);
+       udata->u.Text[chars_read] = 0;
+       udata->Length = chars_read;
+
+       return GE_NONE;
+}
+
 /* Send  SMS messages. */
 static int sendsms(int argc, char *argv[])
 {
@@ -418,8 +447,7 @@
        GSM_Error error;
        /* The maximum length of an uncompressed concatenated short message is
           255 * 153 = 39015 default alphabet characters */
-       char message_buffer[255 * GSM_MAX_SMS_LENGTH];
-       int input_len, chars_read;
+       int input_len;
        int i;
 
        struct option options[] = {
@@ -504,30 +532,14 @@
                        sendsms_usage();
                }
        }
-
-       fprintf(stderr, _("Please enter SMS text. End your input with 
<cr><control-D>:"));
-
-       /* Get message text from stdin. */
-       chars_read = fread(message_buffer, 1, sizeof(message_buffer), stdin);
-
-       if (chars_read == 0) {
-               fprintf(stderr, _("Couldn't read from stdin!\n"));
-               return -1;
-       } else if (chars_read > input_len || chars_read > 
sizeof(sms.UserData[0].u.Text) - 1) {
-               fprintf(stderr, _("Input too long! (%d, maximum is %d)\n"), 
chars_read, input_len);
-               return -1;
-       }
-
-       /*  Null terminate. */
-       message_buffer[chars_read] = 0x00;
-       if (sms.UserData[0].Type != SMS_iMelodyText && chars_read > 0 && 
message_buffer[chars_read - 1] == '\n') 
-               message_buffer[--chars_read] = 0x00;
-       if (chars_read < 1) {
+       
+       error = readtext(&sms.UserData[0], input_len);
+       if (error != GE_NONE) return -1;
+       if (sms.UserData[0].Length < 1) {
                fprintf(stderr, _("Empty message. Quitting.\n"));
                return -1;
        }
-       strncpy(sms.UserData[0].u.Text, message_buffer, chars_read);
-       sms.UserData[0].u.Text[chars_read] = 0;
+
        data.SMS = &sms;
 
        /* Send the message. */
@@ -1449,8 +1461,8 @@
        sms.UserData[1].Type = SMS_NoData;
        if (sms.UserData[0].u.Bitmap.type == GSM_PictureMessage) {
                sms.UserData[1].Type = SMS_PlainText;
+               readtext(&sms.UserData[1], 120);
                sms.UserData[2].Type = SMS_NoData;
-               strcpy(sms.UserData[1].u.Text, "testtest");
        }
 
        /* Send the message. */

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