Refactor: Break out semi-octet decoder

Refactor decode_scts to use this function
This commit is contained in:
Yang Gu 2010-04-02 14:20:31 +08:00 committed by Denis Kenzior
parent 8bad7e540a
commit 8bc04ba93a
2 changed files with 13 additions and 6 deletions

View File

@ -372,6 +372,11 @@ static gboolean encode_scts(const struct sms_scts *in, unsigned char *pdu,
return TRUE;
}
guint8 sms_decode_semi_octet(guint8 in)
{
return (in & 0x0f) * 10 + (in >> 4);
}
static gboolean decode_scts(const unsigned char *pdu, int len,
int *offset, struct sms_scts *out)
{
@ -381,22 +386,22 @@ static gboolean decode_scts(const unsigned char *pdu, int len,
return FALSE;
next_octet(pdu, len, offset, &oct);
out->year = (oct & 0x0f) * 10 + ((oct & 0xf0) >> 4);
out->year = sms_decode_semi_octet(oct);
next_octet(pdu, len, offset, &oct);
out->month = (oct & 0x0f) * 10 + ((oct & 0xf0) >> 4);
out->month = sms_decode_semi_octet(oct);
next_octet(pdu, len, offset, &oct);
out->day = (oct & 0x0f) * 10 + ((oct & 0xf0) >> 4);
out->day = sms_decode_semi_octet(oct);
next_octet(pdu, len, offset, &oct);
out->hour = (oct & 0x0f) * 10 + ((oct & 0xf0) >> 4);
out->hour = sms_decode_semi_octet(oct);
next_octet(pdu, len, offset, &oct);
out->minute = (oct & 0x0f) * 10 + ((oct & 0xf0) >> 4);
out->minute = sms_decode_semi_octet(oct);
next_octet(pdu, len, offset, &oct);
out->second = (oct & 0x0f) * 10 + ((oct & 0xf0) >> 4);
out->second = sms_decode_semi_octet(oct);
next_octet(pdu, len, offset, &oct);

View File

@ -422,6 +422,8 @@ gboolean sms_decode_address_field(const unsigned char *pdu, int len,
gboolean sms_encode_address_field(const struct sms_address *in, gboolean sc,
unsigned char *pdu, int *offset);
guint8 sms_decode_semi_octet(guint8 in);
int sms_udl_in_bytes(guint8 ud_len, guint8 dcs);
time_t sms_scts_to_time(const struct sms_scts *scts, struct tm *remote);