diff --git a/src/gsm.c b/src/gsm.c index 561efc8..1ba4956 100644 --- a/src/gsm.c +++ b/src/gsm.c @@ -712,7 +712,6 @@ int gsm_fetch_message_list(GSM * gsm, GSMMessageList list) /* gsm_fetch_message */ int gsm_fetch_message(GSM * gsm, unsigned int index) { - gsm->event.message.index = index; /* FIXME may be over-written */ return gsm_modem_get_message(gsm->modem, index); } @@ -1387,6 +1386,7 @@ static int _gsm_trigger_cmgr(GSM * gsm, char const * result) unsigned int * length = &gsm->event.message.length; struct tm t; char * p; + GSMCommand * gsmc; char * q; #ifdef DEBUG @@ -1421,6 +1421,10 @@ static int _gsm_trigger_cmgr(GSM * gsm, char const * result) else if((p = _cmgr_pdu_parse(result, &gsm->event.message.date, gsm->number)) != 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); if((q = g_convert(p, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL)) != NULL) { @@ -1484,7 +1488,7 @@ static char * _cmgr_pdu_parse(char const * pdu, time_t * timestamp, if((smscl * 2) + 2 + 4 + addrl + 2 > len) return NULL; /* FIXME actually parse the number */ - snprintf(number, min(addrl + 1, sizeof(number)), "%s", q + 2); + snprintf(number, min(addrl + 1, 32), "%s", q + 2); q = pdu + (smscl * 2) + 2 + 4 + addrl + 2; if(sscanf(q, "%02X", &pid) != 1) /* PID */ return NULL; diff --git a/src/modem.c b/src/modem.c index 46de3bc..5259a1d 100644 --- a/src/modem.c +++ b/src/modem.c @@ -294,14 +294,23 @@ int gsm_modem_get_message_list(GSMModem * gsmm, GSMMessageList list) /* gsm_modem_get_message */ int gsm_modem_get_message(GSMModem * gsmm, unsigned int index) { + GSMCommand * gsmc; char cmd[32]; + unsigned long i = index; if(gsm_modem_set_message_format(gsmm, GSM_MESSAGE_FORMAT_PDU) != 0) return 1; snprintf(cmd, sizeof(cmd), "%s%u", "AT+CMGR=", index); + if((gsmc = gsm_command_new(cmd)) == NULL) + return 1; + gsm_command_set_priority(gsmc, GSM_PRIORITY_NORMAL); + gsm_command_set_error(gsmc, GSM_ERROR_MESSAGE_FETCH_FAILED); + gsm_command_set_data(gsmc, (void *)i); /* XXX ugly */ /* XXX race condition here if the user forces out of PDU mode */ - return gsm_queue_full(gsmm->gsm, GSM_PRIORITY_LOW, cmd, - GSM_ERROR_MESSAGE_FETCH_FAILED, NULL); + if(gsm_queue_command(gsmm->gsm, gsmc) == 0) + return 0; + gsm_command_delete(gsmc); + return 1; }