From 7f9119e06ed0e407019b158047a637139e5deba4 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Thu, 3 Jun 2010 19:00:59 +0000 Subject: [PATCH] Code cleanup --- src/gsm.c | 22 ++++++++++------------ src/phone.c | 5 ++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/gsm.c b/src/gsm.c index bf35aad..38910dd 100644 --- a/src/gsm.c +++ b/src/gsm.c @@ -1450,7 +1450,6 @@ static int _gsm_trigger_cmgr(GSM * gsm, char const * result) struct tm t; char * p; GSMCommand * gsmc; - char * q; size_t l = 0; #ifdef DEBUG @@ -1485,22 +1484,14 @@ static int _gsm_trigger_cmgr(GSM * gsm, char const * result) } else if((p = _cmgr_pdu_parse(result, &gsm->event.message.date, gsm->number, - &gsm->event.message.encoding, - &l)) != NULL) + &gsm->event.message.encoding, &l)) + != NULL) { gsm->event.message.index = 0; if((gsmc = g_slist_nth_data(gsm->queue, 0)) != NULL) gsm->event.message.index /* XXX ugly */ = (unsigned long)gsm_command_get_data(gsmc); gsm->event.message.number = gsm->number; /* XXX ugly */ - if(gsm->event.message.encoding == GSM_ENCODING_UTF8 - && (q = g_convert(p, -1, "UTF-8", "ISO-8859-1", - NULL, NULL, NULL)) != NULL) - { - free(p); - p = q; - l = strlen(p) + 1; - } gsm->event.message.length = l; gsm->event.message.content = p; _gsm_event_send(gsm, GSM_EVENT_TYPE_MESSAGE); @@ -1597,6 +1588,7 @@ static char * _cmgr_pdu_parse_encoding_default(char const * pdu, size_t len, char const * q; unsigned int u; unsigned char byte; + char * r; if((p = malloc(len - i + 1)) == NULL) return NULL; @@ -1628,8 +1620,14 @@ static char * _cmgr_pdu_parse_encoding_default(char const * pdu, size_t len, } } *encoding = GSM_ENCODING_UTF8; + if((r = g_convert((char *)p, j, "UTF-8", "ISO-8859-1", NULL, NULL, + NULL)) != NULL) + { + free(p); + p = (unsigned char *)r; + j = strlen(r); + } *length = j; - p[j] = '\0'; return (char *)p; } diff --git a/src/phone.c b/src/phone.c index 6ed69f3..e83824b 100644 --- a/src/phone.c +++ b/src/phone.c @@ -432,8 +432,6 @@ static void _on_plug_embedded(gpointer data) /* phone_delete */ void phone_delete(Phone * phone) { - PhonePlugin * plugin; - phone_unload_all(phone); if(phone->config != NULL) config_delete(phone->config); @@ -2472,9 +2470,10 @@ static int _gsm_event_message(Phone * phone, GSMEvent * event) encoding = event->message.encoding; length = event->message.length; - if((content = malloc(length)) == NULL) + if((content = malloc(length + 1)) == NULL) return 1; /* XXX report error */ memcpy(content, event->message.content, length); + content[length] = '\0'; /* just in case */ phone_event(phone, PHONE_EVENT_SMS_RECEIVING, &encoding, &content, &length); phone_event(phone, PHONE_EVENT_SMS_RECEIVED);