From 39bcf88a39b597d6189359e15955b76ff8fed524 Mon Sep 17 00:00:00 2001 From: Vicamo Yang Date: Fri, 1 Jun 2012 16:48:51 +0800 Subject: [PATCH] Bug 749856 - Part 4: handle M-Retrieve.conf PDU, r=philikon --- dom/mms/src/ril/MmsPduHelper.jsm | 16 +++++++++ dom/mms/src/ril/MmsService.js | 58 ++++++++++++++++++++++++++++---- dom/mms/src/ril/mms_consts.js | 11 ++++++ 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/dom/mms/src/ril/MmsPduHelper.jsm b/dom/mms/src/ril/MmsPduHelper.jsm index b2087176e3c..096945f924e 100644 --- a/dom/mms/src/ril/MmsPduHelper.jsm +++ b/dom/mms/src/ril/MmsPduHelper.jsm @@ -13,6 +13,19 @@ Cu.import("resource://gre/modules/mms_consts.js"); let DEBUG; // set to true to see debug messages +function translatePduErrorToStatus(error) { + switch (error) { + case MMS_PDU_ERROR_OK: + return MMS_PDU_STATUS_RETRIEVED; + case MMS_PDU_ERROR_TRANSIENT_FAILURE: + case MMS_PDU_ERROR_TRANSIENT_MESSAGE_NOT_FOUND: + case MMS_PDU_ERROR_TRANSIENT_NETWORK_PROBLEM: + return MMS_PDU_STATUS_DEFERRED; + default: + return MMS_PDU_STATUS_UNRECOGNISED; + } +} + /** * Internal decoding function for boolean values. * @@ -1109,6 +1122,9 @@ if (DEBUG) { } const EXPORTED_SYMBOLS = ALL_CONST_SYMBOLS.concat([ + // Utility functions + "translatePduErrorToStatus", + // Decoders "BooleanValue", "Address", diff --git a/dom/mms/src/ril/MmsService.js b/dom/mms/src/ril/MmsService.js index bf84e24e87e..e667358aff3 100644 --- a/dom/mms/src/ril/MmsService.js +++ b/dom/mms/src/ril/MmsService.js @@ -153,22 +153,32 @@ MmsService.prototype = { /** * @param data * A wrapped object containing raw PDU data. + * @param options + * Additional options to be passed to corresponding PDU handler. + * + * @return true if incoming data parsed successfully and passed to PDU + * handler; false otherwise. */ - parseStreamAndDispatch: function parseStreamAndDispatch(data) { + parseStreamAndDispatch: function parseStreamAndDispatch(data, options) { let msg = MMS.PduHelper.parse(data, null); if (!msg) { - return; + return false; } debug("parseStreamAndDispatch: msg = " + JSON.stringify(msg)); switch (msg.type) { case MMS.MMS_PDU_TYPE_NOTIFICATION_IND: - this.handleNotificationIndication(msg); + this.handleNotificationIndication(msg, options); + break; + case MMS.MMS_PDU_TYPE_RETRIEVE_CONF: + this.handleRetrieveConfirmation(msg, options); break; default: debug("Unsupported X-MMS-Message-Type: " + msg.type); - break; + return false; } + + return true; }, /** @@ -178,14 +188,50 @@ MmsService.prototype = { * The MMS message object. */ handleNotificationIndication: function handleNotificationIndication(msg) { + function callback(status, retr) { + // FIXME + } + + function retrCallback(error, retr) { + callback(MMS.translatePduErrorToStatus(error), retr); + } + let url = msg.headers["x-mms-content-location"].uri; this.sendMmsRequest("GET", url, (function (status, data) { - if (data) { - this.parseStreamAndDispatch(data); + if (!data) { + callback.call(null, MMS.MMS_PDU_STATUS_DEFERRED, null); + } else if (!this.parseStreamAndDispatch(data, retrCallback)) { + callback.call(null, MMS.MMS_PDU_STATUS_UNRECOGNISED, null); } }).bind(this)); }, + /** + * Handle incoming M-Retrieve.conf PDU. + * + * @param msg + * The MMS message object. + * @param callback + * A callback function that accepts one argument as retrieved message. + */ + handleRetrieveConfirmation: function handleRetrieveConfirmation(msg, callback) { + function callbackIfValid(status, msg) { + if (callback) { + callback(status, msg) + } + } + + let status = msg.headers["x-mms-retrieve-status"]; + if ((status != null) && (status != MMS.MMS_PDU_ERROR_OK)) { + callbackIfValid(status, msg); + return; + } + + // FIXME: further processing + + callbackIfValid(MMS.MMS_PDU_ERROR_OK, msg); + }, + /** * Update proxyInfo & MMSC from preferences. * diff --git a/dom/mms/src/ril/mms_consts.js b/dom/mms/src/ril/mms_consts.js index 782f36f0b44..fc43c622fba 100644 --- a/dom/mms/src/ril/mms_consts.js +++ b/dom/mms/src/ril/mms_consts.js @@ -40,6 +40,17 @@ const MMS_PDU_ERROR_PERMANENT_SERVICE_DENIED = 225; const MMS_PDU_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 226; const MMS_PDU_ERROR_PERMANENT_CONTENT_UNSUPPORTED = 227; +// X-Mms-Status values +// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.54 +const MMS_PDU_STATUS_EXPIRED = 128; +const MMS_PDU_STATUS_RETRIEVED = 129; +const MMS_PDU_STATUS_REJECTED = 130; +const MMS_PDU_STATUS_DEFERRED = 131; +const MMS_PDU_STATUS_UNRECOGNISED = 132; +const MMS_PDU_STATUS_INDETERMINATE = 133; +const MMS_PDU_STATUS_FORWARDED = 134; +const MMS_PDU_STATUS_UNREACHABLE = 135; + const ALL_CONST_SYMBOLS = Object.keys(this); // Allow this file to be imported via Components.utils.import().