Bug 775038 - Part 3: Refactor X-Mms-Retrieve-Status decoding, r=philikon

MMS defines several status groups. They may have errors of the same
meaning but assigned with different numbers. Rename error value
constants to prevent from name collisions.

Also simplify decoding process.
This commit is contained in:
Vicamo Yang 2012-07-23 10:20:45 +08:00
parent 665069ea0e
commit 89e7398c77
3 changed files with 26 additions and 37 deletions

View File

@ -14,16 +14,16 @@ 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;
if (error == MMS_PDU_ERROR_OK) {
return MMS_PDU_STATUS_RETRIEVED;
}
if ((error >= MMS_PDU_ERROR_TRANSIENT_FAILURE)
&& (error < MMS_PDU_ERROR_PERMANENT_FAILURE)) {
return MMS_PDU_STATUS_DEFERRED;
}
return MMS_PDU_STATUS_UNRECOGNISED;
}
/**
@ -881,25 +881,14 @@ let RetrieveStatusValue = {
*/
decode: function decode(data) {
let value = WSP.Octet.decode(data);
if ((value == 128)
|| ((value >= 192) && (value <= 194))
|| ((value >= 224) && (value <= 227))) {
if (value == MMS_PDU_ERROR_OK) {
return value;
}
if ((value >= 195) && (value <= 223)) {
// The values 195 through 223 are reserved for future use to indicate
// other transient failures. An MMS Client MUST react the same to a value
// in range 195 to 223 as it does to the value 192
// (Error-transient-failure).
return MMS_PDU_ERROR_TRANSIENT_FAILURE;
if ((value >= MMS_PDU_ERROR_TRANSIENT_FAILURE) && (value < 256)) {
return value;
}
// The values 228 through 255 are reserved for future use to indicate
// other permanent failures. An MMS Client MUST react the same to a value
// in range 228 to 255 as it does to the value 224
// (Error-permanent-failure).
// Any other values SHALL NOT be used. They are reserved for future use.
// An MMS Client that receives such a reserved value MUST react the same
// as it does to the value 224 (Error-permanent-failure).

View File

@ -33,16 +33,18 @@ const MMS_PDU_TYPE_CANCEL_CONF = 151;
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.34
const MMS_VERSION = (0x01 << 4) | 0x03;
// Common Status Values
const MMS_PDU_ERROR_OK = 128;
const MMS_PDU_ERROR_TRANSIENT_FAILURE = 192;
const MMS_PDU_ERROR_PERMANENT_FAILURE = 224;
// X-Mms-Retrieve-Status values
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.50
const MMS_PDU_ERROR_OK = 128;
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;
const MMS_PDU_RETRIEVE_ERROR_TRANSIENT_MESSAGE_NOT_FOUND = 193;
const MMS_PDU_RETRIEVE_ERROR_TRANSIENT_NETWORK_PROBLEM = 194;
const MMS_PDU_RETRIEVE_ERROR_PERMANENT_SERVICE_DENIED = 225;
const MMS_PDU_RETRIEVE_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 226;
const MMS_PDU_RETRIEVE_ERROR_PERMANENT_CONTENT_UNSUPPORTED = 227;
// X-Mms-Status values
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.54

View File

@ -516,14 +516,12 @@ add_test(function test_ReplyChargingValue_decode() {
add_test(function test_RetrieveStatusValue_decode() {
for (let i = 0; i < 256; i++) {
if ((i == 128)
|| ((i >= 192) && (i <= 194))
|| ((i >= 224) && (i <= 227))) {
if ((i == MMS_PDU_ERROR_OK)
|| (i >= MMS_PDU_ERROR_TRANSIENT_FAILURE)) {
wsp_decode_test(MMS.RetrieveStatusValue, [i], i);
} else if ((i >= 195) && (i <= 223)) {
wsp_decode_test(MMS.RetrieveStatusValue, [i], 192);
} else {
wsp_decode_test(MMS.RetrieveStatusValue, [i], 224);
wsp_decode_test(MMS.RetrieveStatusValue, [i],
MMS_PDU_ERROR_PERMANENT_FAILURE);
}
}