Bug 749856 - Part 4: handle M-Retrieve.conf PDU, r=philikon
authorVicamo Yang <vyang@mozilla.com>
Mon, 04 Jun 2012 13:04:53 +0800
changeset 95732 728c759ed6544089c251612e12ce8ed2fa34c68a
parent 95731 abb9036641e2f31f9b270bce23e03fabb7b98102
child 95733 abcc96067a0f5366477ef94ed41fea5cf6c783b5
push id22837
push usereakhgari@mozilla.com
push dateMon, 04 Jun 2012 15:31:50 +0000
treeherdermozilla-central@fc94f4339da7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilikon
bugs749856
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 749856 - Part 4: handle M-Retrieve.conf PDU, r=philikon
dom/mms/src/ril/MmsPduHelper.jsm
dom/mms/src/ril/MmsService.js
dom/mms/src/ril/mms_consts.js
--- a/dom/mms/src/ril/MmsPduHelper.jsm
+++ b/dom/mms/src/ril/MmsPduHelper.jsm
@@ -8,16 +8,29 @@ const {classes: Cc, interfaces: Ci, util
 
 let WSP = {};
 Cu.import("resource://gre/modules/WspPduHelper.jsm", WSP);
 
 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.
  *
  * Boolean-value = Yes | No
  * Yes = <Octet 128>
  * No = <Octet 129>
  */
 let BooleanValue = {
@@ -1104,16 +1117,19 @@ if (DEBUG) {
   debug = function (s) {
     dump("-$- MmsPduHelper: " + s + "\n");
   };
 } else {
   debug = function (s) {};
 }
 
 const EXPORTED_SYMBOLS = ALL_CONST_SYMBOLS.concat([
+  // Utility functions
+  "translatePduErrorToStatus",
+
   // Decoders
   "BooleanValue",
   "Address",
   "HeaderField",
   "MmsHeader",
   "ContentClassValue",
   "ContentLocationValue",
   "ElementDescriptorValue",
--- a/dom/mms/src/ril/MmsService.js
+++ b/dom/mms/src/ril/MmsService.js
@@ -148,50 +148,96 @@ MmsService.prototype = {
       debug("xhr error, can't send: " + e.message);
       releaseProxyFilterAndCallback(0, null);
     }
   },
 
   /**
    * @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;
   },
 
   /**
    * Handle incoming M-Notification.ind PDU.
    *
    * @param msg
    *        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.
    *
    * @param enabled
    *        Enable or disable MMS proxy.
    */
   updateProxyInfo: function updateProxyInfo(enabled) {
     try {
       if (enabled) {
--- a/dom/mms/src/ril/mms_consts.js
+++ b/dom/mms/src/ril/mms_consts.js
@@ -35,13 +35,24 @@ const MMS_PDU_ERROR_OK                  
 const MMS_PDU_ERROR_TRANSIENT_FAILURE             = 192;
 const MMS_PDU_ERROR_TRANSIENT_MESSAGE_NOT_FOUND   = 193;
 const MMS_PDU_ERROR_TRANSIENT_NETWORK_PROBLEM     = 194;
 const MMS_PDU_ERROR_PERMANENT_FAILURE             = 224;
 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().
 const EXPORTED_SYMBOLS = ALL_CONST_SYMBOLS;