Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mms-lib] Handle X-Mms-Retrieve-Status in M-Retrieve.conf
It's one of the ways of telling us that the message has expired.
  • Loading branch information
monich committed May 8, 2014
1 parent 9af7411 commit d18e4ab
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 32 deletions.
10 changes: 7 additions & 3 deletions mms-lib/src/mms_codec.c
Expand Up @@ -853,7 +853,8 @@ static gboolean extract_status(struct wsp_header_iter *iter, void *user)
return FALSE;
}

static gboolean extract_retrieve_status(struct wsp_header_iter *iter, void *user)
static gboolean extract_retrieve_status(struct wsp_header_iter *iter,
void *user)
{
unsigned char *out = user;
const unsigned char *p;
Expand All @@ -863,6 +864,7 @@ static gboolean extract_retrieve_status(struct wsp_header_iter *iter, void *user

p = wsp_header_iter_get_val(iter);

/* Accept known codes, ignore unknown ones */
switch (p[0]) {
case MMS_MESSAGE_RETRIEVE_STATUS_OK:
case MMS_MESSAGE_RETRIEVE_STATUS_ERR_TRANS_FAILURE:
Expand All @@ -873,10 +875,10 @@ static gboolean extract_retrieve_status(struct wsp_header_iter *iter, void *user
case MMS_MESSAGE_RETRIEVE_STATUS_ERR_PERM_MESSAGE_NOT_FOUND:
case MMS_MESSAGE_RETRIEVE_STATUS_ERR_PERM_CONTENT_UNSUPPORTED:
*out = p[0];
return TRUE;
break;
}

return FALSE;
return TRUE;
}

static gboolean extract_read_status(struct wsp_header_iter *iter, void *user)
Expand Down Expand Up @@ -1350,6 +1352,8 @@ static gboolean decode_retrieve_conf(struct wsp_header_iter *iter,
HEADER_FLAG_MANDATORY, &out->rc.date,
MMS_HEADER_READ_REPORT,
0, &out->rc.rr,
MMS_HEADER_RETRIEVE_STATUS,
0, &out->rc.retrieve_status,
MMS_HEADER_INVALID) == FALSE)
return FALSE;

Expand Down
1 change: 1 addition & 0 deletions mms-lib/src/mms_codec.h
Expand Up @@ -120,6 +120,7 @@ struct mms_retrieve_conf {
char *msgid;
time_t date;
gboolean rr;
enum mms_message_retrieve_status retrieve_status;
};

struct mms_send_req {
Expand Down
71 changes: 42 additions & 29 deletions mms-lib/src/mms_task_decode.c
Expand Up @@ -102,7 +102,7 @@ mms_task_decode_make_content_id(

static
MMSMessage*
mms_task_decode_process_retrieve_conf(
mms_task_decode_retrieve_conf(
MMSTask* task,
const MMSPdu* pdu,
const guint8* pdu_data,
Expand Down Expand Up @@ -200,51 +200,64 @@ mms_task_decode_process_retrieve_conf(
}

static
MMSMessage*
void
mms_task_decode_process_pdu(
MMSTask* task,
const guint8* data,
gsize len)
MMSTaskDecode* dec,
MMSPdu* pdu)
{
MMSMessage* msg = NULL;
MMSPdu* pdu = g_new0(MMSPdu, 1);
MMSTask* task = &dec->task;
const void* data = g_mapped_file_get_contents(dec->map);
const gsize len = g_mapped_file_get_length(dec->map);
if (mms_message_decode(data, len, pdu)) {
if (pdu->type == MMS_MESSAGE_TYPE_RETRIEVE_CONF) {
msg = mms_task_decode_process_retrieve_conf(task, pdu, data, len);
struct mms_retrieve_conf* rc = &pdu->rc;
if (rc->retrieve_status == 0 /* no status at all */ ||
rc->retrieve_status == MMS_MESSAGE_RETRIEVE_STATUS_OK) {
MMSMessage* msg;
msg = mms_task_decode_retrieve_conf(task, pdu, data, len);
if (msg) {
/* Successfully received and decoded MMS message */
mms_task_queue_and_unref(task->delegate,
mms_task_ack_new(task->config, task->handler,
task->id, task->imsi, dec->transaction_id));
mms_task_queue_and_unref(task->delegate,
mms_task_publish_new(task->config, task->handler, msg));
mms_message_unref(msg);
return;
}
} else {
/* MMS server returned an error. Most likely, MMS message
* has expired. We need more MMS_RECEIVE_STATE values to
* better describe it to the user. */
MMS_ERR("MMSC responded with %u", rc->retrieve_status);
mms_handler_message_receive_state_changed(task->handler,
task->id, MMS_RECEIVE_STATE_DOWNLOAD_ERROR);
return;
}
} else {
MMS_ERR("Unexpected MMS PDU type %u", (guint)pdu->type);
}
} else {
MMS_ERR("Failed to decode MMS PDU");
}
mms_message_free(pdu);
return msg;

/* Tell MMS server that we didn't understand this PDU */
mms_task_queue_and_unref(task->delegate,
mms_task_notifyresp_new(task->config, task->handler, task->id,
task->imsi, dec->transaction_id,
MMS_MESSAGE_NOTIFY_STATUS_UNRECOGNISED));
mms_handler_message_receive_state_changed(task->handler, task->id,
MMS_RECEIVE_STATE_DECODING_ERROR);
}

static
void
mms_task_decode_run(
MMSTask* task)
{
MMSTaskDecode* dec = MMS_TASK_DECODE(task);
const void* data = g_mapped_file_get_contents(dec->map);
const gsize size = g_mapped_file_get_length(dec->map);
MMSMessage* msg = mms_task_decode_process_pdu(task, data, size);
if (msg) {
mms_task_queue_and_unref(task->delegate,
mms_task_ack_new(task->config, task->handler, task->id, task->imsi,
dec->transaction_id));
mms_task_queue_and_unref(task->delegate,
mms_task_publish_new(task->config, task->handler, msg));
mms_message_unref(msg);
} else {
mms_handler_message_receive_state_changed(task->handler, task->id,
MMS_RECEIVE_STATE_DECODING_ERROR);
mms_task_queue_and_unref(task->delegate,
mms_task_notifyresp_new(task->config, task->handler, task->id,
task->imsi, dec->transaction_id,
MMS_MESSAGE_NOTIFY_STATUS_UNRECOGNISED));
}
MMSPdu* pdu = g_new0(MMSPdu, 1);
mms_task_decode_process_pdu(MMS_TASK_DECODE(task), pdu);
mms_message_free(pdu);
mms_task_set_state(task, MMS_TASK_STATE_DONE);
}

Expand Down
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions mms-lib/test/retrieve/test_retrieve.c
Expand Up @@ -209,6 +209,18 @@ static const TestDesc retrieve_tests[] = {
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
0
},{
"MessageNotFound",
NULL,
"m-notification.ind",
"m-retrieve.conf",
SOUP_STATUS_OK,
MMS_CONTENT_TYPE,
NULL,
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
0
},{
"GarbageRetrieve",
NULL,
Expand Down

0 comments on commit d18e4ab

Please sign in to comment.