[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gsm-sms.c cleanup
From: |
Pavel Machek |
Subject: |
gsm-sms.c cleanup |
Date: |
Mon, 3 Jun 2002 11:59:06 +0200 |
User-agent: |
Mutt/1.3.28i |
Hi!
EncodeUDH does not need UDH parameter at all, moved encoding of concat
header to separate function. Killed char *message, so that it does not
confuse people.
It looks cleaner to me, so I'm commiting it.
Pavel
Index: common/gsm-sms.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/gsm-sms.c,v
retrieving revision 1.84
diff -u -u -r1.84 gsm-sms.c
--- common/gsm-sms.c 2 Jun 2002 21:36:45 -0000 1.84
+++ common/gsm-sms.c 3 Jun 2002 09:43:58 -0000
@@ -963,9 +963,10 @@
* 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, char *UDH)
+static GSM_Error EncodeUDH(GSM_SMSMessage *rawsms, int type)
{
unsigned char pos;
+ char *UDH = rawsms->UserData;
pos = UDH[0];
@@ -998,6 +999,17 @@
return GE_NONE;
}
+static GSM_Error EncodeConcatHeader(GSM_SMSMessage *rawsms, int this, int
total)
+{
+ EncodeUDH(rawsms, SMS_ConcatenatedMessages);
+ rawsms->Length --;
+ rawsms->UserDataLength --;
+ rawsms->UserData[ 9] = 0xce;
+ rawsms->UserData[10] = total;
+ rawsms->UserData[11] = this;
+ return GE_NONE;
+}
+
/* Returns used length */
int EncodeNokiaText(char *text, char *message)
{
@@ -1034,8 +1046,7 @@
GSM_Error EncodeData(GSM_API_SMS *sms, GSM_SMSMessage *rawsms)
{
SMS_AlphabetType al = SMS_DefaultAlphabet;
- unsigned int i, size = 0, offset = 0;
- char *message = rawsms->UserData;
+ unsigned int i, size = 0;
GSM_Error error;
/* Additional Headers */
@@ -1076,14 +1087,14 @@
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_OperatorLogo: error = EncodeUDH(rawsms,
SMS_OpLogo); 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), message +
rawsms->UserDataLength);
+ size =
GSM_EncodeSMSBitmap(&(sms->UserData[i].u.Bitmap), rawsms->UserData +
rawsms->UserDataLength);
rawsms->Length += size;
rawsms->UserDataLength += size;
rawsms->DCS = 0xf5;
@@ -1091,25 +1102,25 @@
break;
case SMS_PlainText: {
- unsigned int length;
+ unsigned int length, offset = 0;
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[i].u.Text, message + offset);
+ size = Pack7BitCharacters((7 - (UDH_Length %
7)) % 7, sms->UserData[i].u.Text, rawsms->UserData + 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];
+ memcpy(rawsms->UserData + offset,
sms->UserData[i].u.Text + 1, sms->UserData[i].u.Text[0]);
+ rawsms->UserDataLength = rawsms->Length =
sms->UserData[i].u.Text[0] + offset;
break;
case SMS_UCS2:
rawsms->DCS |= 0x08;
- EncodeUnicode(message + offset,
sms->UserData[i].u.Text, length);
+ EncodeUnicode(rawsms->UserData + offset,
sms->UserData[i].u.Text, length);
length *= 2;
rawsms->UserDataLength = rawsms->Length =
length + offset;
break;
@@ -1120,13 +1131,13 @@
}
case SMS_NokiaText:
- size = EncodeNokiaText(sms->UserData[i].u.Text, message
+ rawsms->UserDataLength);
+ size = EncodeNokiaText(sms->UserData[i].u.Text,
rawsms->UserData + rawsms->UserDataLength);
rawsms->Length += size;
rawsms->UserDataLength += size;
break;
case SMS_iMelodyText:
- size = GSM_EncodeSMSiMelody(sms->UserData[i].u.Text,
message + rawsms->UserDataLength);
+ size = GSM_EncodeSMSiMelody(sms->UserData[i].u.Text,
rawsms->UserData + rawsms->UserDataLength);
dprintf("Imelody, size %d\n", size);
rawsms->Length += size;
rawsms->UserDataLength += size;
@@ -1136,19 +1147,12 @@
case SMS_MultiData:
size = sms->UserData[0].Length;
- error = EncodeUDH(rawsms, 0x05, message);
+ error = EncodeUDH(rawsms, SMS_MultipartMessage);
+ if (error != GE_NONE) return error;
+ error = EncodeConcatHeader(rawsms,
sms->UserData[i].u.Multi.this, sms->UserData[i].u.Multi.total);
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);
+ memcpy(rawsms->UserData + rawsms->UserDataLength,
sms->UserData[i].u.Multi.Binary, MAX_SMS_PART);
rawsms->Length += size;
rawsms->UserDataLength += size;
rawsms->DCS = 0xf5;
@@ -1156,9 +1160,9 @@
break;
case SMS_RingtoneData:
- error = EncodeUDH(rawsms, SMS_Ringtone, message);
+ error = EncodeUDH(rawsms, SMS_Ringtone);
if (error != GE_NONE) return error;
- size = GSM_EncodeSMSRingtone(message + rawsms->Length,
&sms->UserData[i].u.Ringtone);
+ size = GSM_EncodeSMSRingtone(rawsms->UserData +
rawsms->Length, &sms->UserData[i].u.Ringtone);
rawsms->Length += size;
rawsms->UserDataLength += size;
rawsms->DCS = 0xf5;
--
(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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gsm-sms.c cleanup,
Pavel Machek <=