Bug 749856 - Part 7: send M-NotifyResp.ind response back, r=philikon

This commit is contained in:
Vicamo Yang 2012-06-01 16:49:01 +08:00
parent 5e6c2d1678
commit b08f13bda9
3 changed files with 52 additions and 9 deletions

View File

@ -1189,6 +1189,10 @@ const MMS_PDU_TYPES = (function () {
add(MMS_PDU_TYPE_RETRIEVE_CONF, true, ["x-mms-message-type",
"x-mms-mms-version",
"content-type"]);
add(MMS_PDU_TYPE_NOTIFYRESP_IND, false, ["x-mms-message-type",
"x-mms-transaction-id",
"x-mms-mms-version",
"x-mms-status"]);
return pdus;
})();

View File

@ -94,11 +94,13 @@ MmsService.prototype = {
* "GET" or "POST".
* @param url
* Target url string.
* @param istream [optional]
* An nsIInputStream instance as data source to be sent.
* @param callback
* A callback function that takes two arguments: one for http status,
* the other for wrapped PDU data for further parsing.
*/
sendMmsRequest: function sendMmsRequest(method, url, callback) {
sendMmsRequest: function sendMmsRequest(method, url, istream, callback) {
let that = this;
function releaseProxyFilterAndCallback(status, data) {
// Always release proxy filter before callback.
@ -117,7 +119,12 @@ MmsService.prototype = {
// Basic setups
xhr.open(method, url, true);
xhr.responseType = "arraybuffer";
xhr.setRequestHeader("Content-Length", 0);
if (istream) {
xhr.setRequestHeader("Content-Type", "application/vnd.wap.mms-message");
xhr.setRequestHeader("Content-Length", istream.available());
} else {
xhr.setRequestHeader("Content-Length", 0);
}
// Setup event listeners
xhr.onerror = function () {
@ -154,13 +161,40 @@ MmsService.prototype = {
}
// Send request
xhr.send();
xhr.send(istream);
} catch (e) {
debug("xhr error, can't send: " + e.message);
releaseProxyFilterAndCallback(0, null);
}
},
/**
* Send M-NotifyResp.ind back to MMSC.
*
* @param tid
* X-Mms-Transaction-ID of the message.
* @param status
* X-Mms-Status of the response.
*
* @see OMA-TS-MMS_ENC-V1_3-20110913-A section 6.2
*/
sendNotificationResponse: function sendNotificationResponse(tid, status) {
debug("sendNotificationResponse: tid = " + tid + ", status = " + status);
let headers = {};
// Mandatory fields
headers["x-mms-message-type"] = MMS.MMS_PDU_TYPE_NOTIFYRESP_IND;
headers["x-mms-transaction-id"] = tid;
headers["x-mms-mms-version"] = MMS.MMS_VERSION;
headers["x-mms-status"] = status;
// Optional fields
headers["x-mms-report-allowed"] = true;
let istream = MMS.PduHelper.compose(null, {headers: headers});
this.sendMmsRequest("POST", this.MMSC, istream);
},
/**
* @param file
* A nsIFile object indicating where to save the data.
@ -273,19 +307,20 @@ MmsService.prototype = {
*/
handleNotificationIndication: function handleNotificationIndication(msg) {
function callback(status, retr) {
// FIXME
let tid = msg.headers["x-mms-transaction-id"];
this.sendNotificationResponse(tid, status);
}
function retrCallback(error, retr) {
callback(MMS.translatePduErrorToStatus(error), retr);
callback.call(this, MMS.translatePduErrorToStatus(error), retr);
}
let url = msg.headers["x-mms-content-location"].uri;
this.sendMmsRequest("GET", url, (function (status, data) {
this.sendMmsRequest("GET", url, null, (function (status, 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);
callback.call(this, MMS.MMS_PDU_STATUS_DEFERRED, null);
} else if (!this.parseStreamAndDispatch(data, retrCallback.bind(this))) {
callback.call(this, MMS.MMS_PDU_STATUS_UNRECOGNISED, null);
}
}).bind(this));
},

View File

@ -29,6 +29,10 @@ const MMS_PDU_TYPE_DELETE_CONF = 149;
const MMS_PDU_TYPE_CANCEL_REQ = 150;
const MMS_PDU_TYPE_CANCEL_CONF = 151;
// MMS version 1.3
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.34
const MMS_VERSION = (0x01 << 4) | 0x03;
// X-Mms-Retrieve-Status values
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.50
const MMS_PDU_ERROR_OK = 128;