From 0f1244eb5f4e9379fd6dfa114318547caa15aa17 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 9 May 2010 21:35:22 +0000 Subject: [PATCH] Fetching incoming messages as they are reported --- src/gsm.c | 25 +++++++++++++++++++++++++ src/gsm.h | 9 +++++++++ src/phone.c | 6 ++++++ 3 files changed, 40 insertions(+) diff --git a/src/gsm.c b/src/gsm.c index b1d9b3c..c0631d4 100644 --- a/src/gsm.c +++ b/src/gsm.c @@ -169,6 +169,7 @@ static int _gsm_trigger_cme_error(GSM * gsm, char const * result, static int _gsm_trigger_cms_error(GSM * gsm, char const * result); static int _gsm_trigger_cmgl(GSM * gsm, char const * result); static int _gsm_trigger_cmgs(GSM * gsm, char const * result); +static int _gsm_trigger_cmti(GSM * gsm, char const * result); static int _gsm_trigger_connect(GSM * gsm, char const * result, gboolean * answered); static int _gsm_trigger_cops(GSM * gsm, char const * result); @@ -198,6 +199,7 @@ static GSMTrigger _gsm_triggers[] = GSM_TRIGGER("+CMS ERROR: ", cms_error), GSM_TRIGGER("+CMGL: ", cmgl), GSM_TRIGGER("+CMGS: ", cmgs), + GSM_TRIGGER("+CMTI: ", cmti), GSM_TRIGGER("CONNECT", connect), GSM_TRIGGER("+COPS: ", cops), GSM_TRIGGER("+CPBR: ", cpbr), @@ -482,6 +484,12 @@ int gsm_event(GSM * gsm, GSMEventType type, ...) event->incoming_call.calltype = va_arg(ap, unsigned int); break; + case GSM_EVENT_TYPE_INCOMING_MESSAGE: + event->incoming_message.memory = va_arg(ap, + char const *); + event->incoming_message.index = va_arg(ap, + unsigned int); + break; case GSM_EVENT_TYPE_MESSAGE_LIST: event->message_list.start = va_arg(ap, unsigned int); event->message_list.end = va_arg(ap, unsigned int); @@ -1130,6 +1138,23 @@ static int _gsm_trigger_cmgs(GSM * gsm, char const * result) } +/* gsm_trigger_cmti */ +static int _gsm_trigger_cmti(GSM * gsm, char const * result) +{ + char memory[32]; + +#ifdef DEBUG + fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, result); +#endif + if(sscanf(result, "\"%31[^\"]\",%u", memory, + &gsm->event.incoming_message.index) != 2) + return 1; + memory[sizeof(memory) - 1] = '\0'; + gsm->event.incoming_message.memory = memory; + return 0; +} + + /* gsm_trigger_connect */ static int _gsm_trigger_connect(GSM * gsm, char const * result, gboolean * answered) diff --git a/src/gsm.h b/src/gsm.h index 94693b4..af9881c 100644 --- a/src/gsm.h +++ b/src/gsm.h @@ -43,6 +43,7 @@ typedef enum _GSMEventType GSM_EVENT_TYPE_CONTACT_LIST, GSM_EVENT_TYPE_FUNCTIONAL, GSM_EVENT_TYPE_INCOMING_CALL, + GSM_EVENT_TYPE_INCOMING_MESSAGE, GSM_EVENT_TYPE_MESSAGE_LIST, GSM_EVENT_TYPE_MESSAGE_SENT, GSM_EVENT_TYPE_OPERATOR, @@ -188,6 +189,14 @@ typedef union _GSMEvent GSMCallType calltype; } incoming_call; + /* GSM_EVENT_TYPE_INCOMING_MESSAGE */ + struct + { + GSMEventType type; + char const * memory; + unsigned int index; + } incoming_message; + /* GSM_EVENT_TYPE_MESSAGE_SENT */ struct { diff --git a/src/phone.c b/src/phone.c index 98ea519..4702626 100644 --- a/src/phone.c +++ b/src/phone.c @@ -1444,6 +1444,12 @@ static int _phone_gsm_event(GSMEvent * event, gpointer data) phone_show_call(phone, TRUE, PHONE_CALL_INCOMING, "", ""); return 0; + case GSM_EVENT_TYPE_INCOMING_MESSAGE: + /* FIXME warn the user */ + _phone_fetch_messages(phone, + event->incoming_message.index, + event->incoming_message.index); + return 0; case GSM_EVENT_TYPE_MESSAGE_LIST: _phone_fetch_messages(phone, event->message_list.start, event->message_list.end);