mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 921918 - 3.h/4: decode some MMS header fields as enum. r=gene
This commit is contained in:
parent
cd6f1090ff
commit
00c2e70222
@ -45,6 +45,48 @@ function defineLazyRegExp(obj, name, pattern) {
|
||||
});
|
||||
}
|
||||
|
||||
function RangedValue(name, min, max) {
|
||||
this.name = name;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
RangedValue.prototype = {
|
||||
name: null,
|
||||
min: null,
|
||||
max: null,
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object containing raw PDU data.
|
||||
*
|
||||
* @return A decoded integer.
|
||||
*
|
||||
* @throws CodeError if decoded value is not in the range [this.min, this.max].
|
||||
*/
|
||||
decode: function decode(data) {
|
||||
let value = WSP.Octet.decode(data);
|
||||
if ((value >= this.min) && (value <= this.max)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
throw new WSP.CodeError(this.name + ": invalid value " + value);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object to store encoded raw data.
|
||||
* @param value
|
||||
* An integer value within thr range [this.min, this.max].
|
||||
*/
|
||||
encode: function encode(data, value) {
|
||||
if ((value < this.min) || (value > this.max)) {
|
||||
throw new WSP.CodeError(this.name + ": invalid value " + value);
|
||||
}
|
||||
|
||||
WSP.Octet.encode(data, value);
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal decoding function for boolean values.
|
||||
*
|
||||
@ -337,44 +379,21 @@ this.MmsHeader = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Cancel-status-value = Cancel Request Successfully received |
|
||||
* Cancel Request corrupted
|
||||
*
|
||||
* @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.7
|
||||
*/
|
||||
this.CancelStatusValue = new RangedValue("Cancel-status-value", 128, 129);
|
||||
|
||||
/**
|
||||
* Content-class-value = text | image-basic| image-rich | video-basic |
|
||||
* video-rich | megapixel | content-basic | content-rich
|
||||
*
|
||||
* @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.9
|
||||
*/
|
||||
this.ContentClassValue = {
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object containing raw PDU data.
|
||||
*
|
||||
* @return A integer value for each class.
|
||||
*
|
||||
* @throws CodeError if decoded value is not in range 128..135.
|
||||
*/
|
||||
decode: function decode(data) {
|
||||
let value = WSP.Octet.decode(data);
|
||||
if ((value >= 128) && (value <= 135)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
throw new WSP.CodeError("Content-class-value: invalid class " + value);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object to store encoded raw data.
|
||||
* @param value
|
||||
* A numeric content class value to be encoded.
|
||||
*/
|
||||
encode: function encode(data, value) {
|
||||
if ((value < 128) || (value > 135)) {
|
||||
throw new WSP.CodeError("Content-class-value: invalid class " + value);
|
||||
}
|
||||
|
||||
WSP.Octet.encode(data, value);
|
||||
},
|
||||
};
|
||||
this.ContentClassValue = new RangedValue("Content-class-value", 128, 135);
|
||||
|
||||
/**
|
||||
* When used in a PDU other than M-Mbox-Delete.conf and M-Delete.conf:
|
||||
@ -969,40 +988,7 @@ this.MessageClassValue = {
|
||||
*
|
||||
* @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.30
|
||||
*/
|
||||
this.MessageTypeValue = {
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object containing raw PDU data.
|
||||
*
|
||||
* @return A decoded integer.
|
||||
*
|
||||
* @throws CodeError if decoded value is not in the range 128..151.
|
||||
*/
|
||||
decode: function decode(data) {
|
||||
let type = WSP.Octet.decode(data);
|
||||
if ((type >= 128) && (type <= 151)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
throw new WSP.CodeError("Message-type-value: invalid type " + type);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object to store encoded raw data.
|
||||
* @param type
|
||||
* A numeric message type value to be encoded.
|
||||
*
|
||||
* @throws CodeError if the value is not in the range 128..151.
|
||||
*/
|
||||
encode: function encode(data, type) {
|
||||
if ((type < 128) || (type > 151)) {
|
||||
throw new WSP.CodeError("Message-type-value: invalid type " + type);
|
||||
}
|
||||
|
||||
WSP.Octet.encode(data, type);
|
||||
},
|
||||
};
|
||||
this.MessageTypeValue = new RangedValue("Message-type-value", 128, 151);
|
||||
|
||||
/**
|
||||
* MM-flags-value = Value-length ( Add-token | Remove-token | Filter-token ) Encoded-string-value
|
||||
@ -1075,40 +1061,7 @@ this.MmFlagsValue = {
|
||||
*
|
||||
* @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.33
|
||||
*/
|
||||
this.MmStateValue = {
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object containing raw PDU data.
|
||||
*
|
||||
* @return A decoded integer.
|
||||
*
|
||||
* @throws CodeError if decoded value is not in the range 128..132.
|
||||
*/
|
||||
decode: function decode(data) {
|
||||
let state = WSP.Octet.decode(data);
|
||||
if ((state >= 128) && (state <= 132)) {
|
||||
return state;
|
||||
}
|
||||
|
||||
throw new WSP.CodeError("MM-state-value: invalid state " + state);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object to store encoded raw data.
|
||||
* @param state
|
||||
* A numeric state value to be encoded.
|
||||
*
|
||||
* @throws CodeError if state is not in the range 128..132.
|
||||
*/
|
||||
encode: function encode(data, state) {
|
||||
if ((state < 128) || (state > 132)) {
|
||||
throw new WSP.CodeError("MM-state-value: invalid state " + state);
|
||||
}
|
||||
|
||||
WSP.Octet.encode(data, state);
|
||||
},
|
||||
};
|
||||
this.MmStateValue = new RangedValue("MM-state-value", 128, 132);
|
||||
|
||||
/**
|
||||
* Priority-value = Low | Normal | High
|
||||
@ -1118,38 +1071,14 @@ this.MmStateValue = {
|
||||
*
|
||||
* @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.35
|
||||
*/
|
||||
this.PriorityValue = {
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object containing raw PDU data.
|
||||
*
|
||||
* @return A decoded integer.
|
||||
*
|
||||
* @throws CodeError if decoded value is not in the range 128..130.
|
||||
*/
|
||||
decode: function decode(data) {
|
||||
let priority = WSP.Octet.decode(data);
|
||||
if ((priority >= 128) && (priority <= 130)) {
|
||||
return priority;
|
||||
}
|
||||
this.PriorityValue = new RangedValue("Priority-value", 128, 130);
|
||||
|
||||
throw new WSP.CodeError("Priority-value: invalid priority " + priority);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object to store encoded raw data.
|
||||
* @param priority
|
||||
* A numeric priority value to be encoded.
|
||||
*/
|
||||
encode: function encode(data, priority) {
|
||||
if ((priority < 128) || (priority > 130)) {
|
||||
throw new WSP.CodeError("Priority-value: invalid priority " + priority);
|
||||
}
|
||||
|
||||
WSP.Octet.encode(data, priority);
|
||||
},
|
||||
};
|
||||
/**
|
||||
* Read-status-value = Read | Deleted without being read
|
||||
*
|
||||
* @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.38
|
||||
*/
|
||||
this.ReadStatusValue = new RangedValue("Read-status-value", 128, 129);
|
||||
|
||||
/**
|
||||
* Recommended-Retrieval-Mode-value = Manual
|
||||
@ -1179,38 +1108,7 @@ this.RecommendedRetrievalModeValue = {
|
||||
*
|
||||
* @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.43
|
||||
*/
|
||||
this.ReplyChargingValue = {
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object containing raw PDU data.
|
||||
*
|
||||
* @return A decoded integer.
|
||||
*
|
||||
* @throws CodeError if decoded value is not in the range 128..131.
|
||||
*/
|
||||
decode: function decode(data) {
|
||||
let value = WSP.Octet.decode(data);
|
||||
if ((value >= 128) && (value <= 131)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
throw new WSP.CodeError("Reply-charging-value: invalid value " + value);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object to store encoded raw data.
|
||||
* @param value
|
||||
* An integer value within thr range 128..131.
|
||||
*/
|
||||
encode: function encode(data, value) {
|
||||
if ((value < 128) || (value > 131)) {
|
||||
throw new WSP.CodeError("Reply-charging-value: invalid value " + value);
|
||||
}
|
||||
|
||||
WSP.Octet.encode(data, value);
|
||||
},
|
||||
};
|
||||
this.ReplyChargingValue = new RangedValue("Reply-charging-value", 128, 131);
|
||||
|
||||
/**
|
||||
* When used in a PDU other than M-Mbox-Delete.conf and M-Delete.conf:
|
||||
@ -1299,6 +1197,13 @@ this.RetrieveStatusValue = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Sender-visibility-value = Hide | Show
|
||||
*
|
||||
* @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.52
|
||||
*/
|
||||
this.SenderVisibilityValue = new RangedValue("Sender-visibility-value", 128, 129);
|
||||
|
||||
/**
|
||||
* Status-value = Expired | Retrieved | Rejected | Deferred | Unrecognised |
|
||||
* Indeterminate | Forwarded | Unreachable
|
||||
@ -1313,40 +1218,7 @@ this.RetrieveStatusValue = {
|
||||
*
|
||||
* @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.54
|
||||
*/
|
||||
this.StatusValue = {
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object containing raw PDU data.
|
||||
*
|
||||
* @return A decoded integer.
|
||||
*
|
||||
* @throws CodeError if decoded value is not in the range 128..135.
|
||||
*/
|
||||
decode: function decode(data) {
|
||||
let status = WSP.Octet.decode(data);
|
||||
if ((status >= 128) && (status <= 135)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
throw new WSP.CodeError("Status-value: invalid status " + status);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* A wrapped object to store encoded raw data.
|
||||
* @param value
|
||||
* A numeric status value to be encoded.
|
||||
*
|
||||
* @throws CodeError if the value is not in the range 128..135.
|
||||
*/
|
||||
encode: function encode(data, value) {
|
||||
if ((value < 128) || (value > 135)) {
|
||||
throw new WSP.CodeError("Status-value: invalid status " + value);
|
||||
}
|
||||
|
||||
WSP.Octet.encode(data, value);
|
||||
},
|
||||
};
|
||||
this.StatusValue = new RangedValue("Status-value", 128, 135);
|
||||
|
||||
this.PduHelper = {
|
||||
/**
|
||||
@ -1671,14 +1543,14 @@ const MMS_HEADER_FIELDS = (function () {
|
||||
add("x-mms-report-allowed", 0x11, BooleanValue);
|
||||
add("x-mms-response-status", 0x12, RetrieveStatusValue);
|
||||
add("x-mms-response-text", 0x13, ResponseText);
|
||||
add("x-mms-sender-visibility", 0x14, BooleanValue);
|
||||
add("x-mms-sender-visibility", 0x14, SenderVisibilityValue);
|
||||
add("x-mms-status", 0x15, StatusValue);
|
||||
add("subject", 0x16, EncodedStringValue);
|
||||
add("to", 0x17, Address);
|
||||
add("x-mms-transaction-id", 0x18, WSP.TextString);
|
||||
add("x-mms-retrieve-status", 0x19, RetrieveStatusValue);
|
||||
add("x-mms-retrieve-text", 0x1A, EncodedStringValue);
|
||||
add("x-mms-read-status", 0x1B, BooleanValue);
|
||||
add("x-mms-read-status", 0x1B, ReadStatusValue);
|
||||
add("x-mms-reply-charging", 0x1C, ReplyChargingValue);
|
||||
add("x-mms-reply-charging-deadline", 0x1D, ExpiryValue);
|
||||
add("x-mms-reply-charging-id", 0x1E, WSP.TextString);
|
||||
@ -1714,7 +1586,7 @@ const MMS_HEADER_FIELDS = (function () {
|
||||
add("x-mms-adaptation-allowed", 0x3C, BooleanValue);
|
||||
add("x-mms-replace-id", 0x3D, WSP.TextString);
|
||||
add("x-mms-cancel-id", 0x3E, WSP.TextString);
|
||||
add("x-mms-cancel-status", 0x3F, BooleanValue);
|
||||
add("x-mms-cancel-status", 0x3F, CancelStatusValue);
|
||||
|
||||
return names;
|
||||
})();
|
||||
@ -1759,6 +1631,7 @@ this.EXPORTED_SYMBOLS = ALL_CONST_SYMBOLS.concat([
|
||||
"Address",
|
||||
"HeaderField",
|
||||
"MmsHeader",
|
||||
"CancelStatusValue",
|
||||
"ContentClassValue",
|
||||
"ContentLocationValue",
|
||||
"ElementDescriptorValue",
|
||||
@ -1773,10 +1646,12 @@ this.EXPORTED_SYMBOLS = ALL_CONST_SYMBOLS.concat([
|
||||
"MmFlagsValue",
|
||||
"MmStateValue",
|
||||
"PriorityValue",
|
||||
"ReadStatusValue",
|
||||
"RecommendedRetrievalModeValue",
|
||||
"ReplyChargingValue",
|
||||
"ResponseText",
|
||||
"RetrieveStatusValue",
|
||||
"SenderVisibilityValue",
|
||||
"StatusValue",
|
||||
|
||||
// Parser
|
||||
|
@ -1357,7 +1357,7 @@ function ReadRecTransaction(mmsConnection, messageID, toAddress) {
|
||||
type: type}
|
||||
headers["to"] = to;
|
||||
headers["from"] = null;
|
||||
headers["x-mms-read-status"] = true;
|
||||
headers["x-mms-read-status"] = MMS.MMS_PDU_READ_STATUS_READ;
|
||||
|
||||
this.istream = MMS.PduHelper.compose(null, {headers: headers});
|
||||
if (!this.istream) {
|
||||
|
@ -1215,6 +1215,17 @@ MobileMessageDatabaseService.prototype = {
|
||||
delete messageRecord.envelopeIdIndex;
|
||||
}
|
||||
|
||||
// Convert some header fields that were originally decoded as BooleanValue
|
||||
// to numeric enums.
|
||||
for (let field of ["x-mms-cancel-status",
|
||||
"x-mms-sender-visibility",
|
||||
"x-mms-read-status"]) {
|
||||
let value = messageRecord.headers[field];
|
||||
if (value !== undefined) {
|
||||
messageRecord.headers[field] = value ? 128 : 129;
|
||||
}
|
||||
}
|
||||
|
||||
cursor.update(messageRecord);
|
||||
cursor.continue();
|
||||
};
|
||||
|
@ -95,6 +95,21 @@ this.MMS_PDU_STATUS_INDETERMINATE = 133;
|
||||
this.MMS_PDU_STATUS_FORWARDED = 134;
|
||||
this.MMS_PDU_STATUS_UNREACHABLE = 135;
|
||||
|
||||
// X-Mms-Cancel-Status values
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.7
|
||||
this.MMS_PDU_CANCEL_STATUS_RECEIVED = 128;
|
||||
this.MMS_PDU_CANCEL_STATUS_CORRUPTED = 129;
|
||||
|
||||
// X-Mms-Sender-Visibility
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.52
|
||||
this.MMS_PDU_SENDER_VISIBILITY_HIDE = 128;
|
||||
this.MMS_PDU_SENDER_VISIBILITY_SHOW = 129;
|
||||
|
||||
// X-Mms-Read-Status
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.38
|
||||
this.MMS_PDU_READ_STATUS_READ = 128;
|
||||
this.MMS_PDU_READ_STATUS_DELETED_UNREAD = 129;
|
||||
|
||||
// Maximum Values of MMS Parameters
|
||||
// @see OMA-TS-MMS_CONF-V1_3-20110511-C 10.2.5
|
||||
this.MMS_MAX_LENGTH_SUBJECT = 40;
|
||||
|
@ -177,6 +177,38 @@ add_test(function test_MmsHeader_encode() {
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
//
|
||||
// Test target: CancelStatusValue
|
||||
//
|
||||
|
||||
//// CancelStatusValue.decode ////
|
||||
|
||||
add_test(function test_CancelStatusValue_decode() {
|
||||
for (let i = 0; i < 256; i++) {
|
||||
if ((i >= 128) && (i <= 129)) {
|
||||
wsp_decode_test(MMS.CancelStatusValue, [i], i);
|
||||
} else {
|
||||
wsp_decode_test(MMS.CancelStatusValue, [i], null, "CodeError");
|
||||
}
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
//// CancelStatusValue.encode ////
|
||||
|
||||
add_test(function test_CancelStatusValue_encode() {
|
||||
for (let i = 0; i < 256; i++) {
|
||||
if ((i >= 128) && (i <= 129)) {
|
||||
wsp_encode_test(MMS.CancelStatusValue, i, [i]);
|
||||
} else {
|
||||
wsp_encode_test(MMS.CancelStatusValue, i, null, "CodeError");
|
||||
}
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
//
|
||||
// Test target: ContentClassValue
|
||||
//
|
||||
@ -657,6 +689,38 @@ add_test(function test_PriorityValue_encode() {
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
//
|
||||
// Test target: ReadStatusValue
|
||||
//
|
||||
|
||||
//// ReadStatusValue.decode ////
|
||||
|
||||
add_test(function test_ReadStatusValue_decode() {
|
||||
for (let i = 0; i < 256; i++) {
|
||||
if ((i >= 128) && (i <= 129)) {
|
||||
wsp_decode_test(MMS.ReadStatusValue, [i], i);
|
||||
} else {
|
||||
wsp_decode_test(MMS.ReadStatusValue, [i], null, "CodeError");
|
||||
}
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
//// ReadStatusValue.encode ////
|
||||
|
||||
add_test(function test_ReadStatusValue_encode() {
|
||||
for (let i = 0; i < 256; i++) {
|
||||
if ((i >= 128) && (i <= 129)) {
|
||||
wsp_encode_test(MMS.ReadStatusValue, i, [i]);
|
||||
} else {
|
||||
wsp_encode_test(MMS.ReadStatusValue, i, null, "CodeError");
|
||||
}
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
//
|
||||
// Test target: RecommendedRetrievalModeValue
|
||||
//
|
||||
@ -765,6 +829,38 @@ add_test(function test_RetrieveStatusValue_decode() {
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
//
|
||||
// Test target: SenderVisibilityValue
|
||||
//
|
||||
|
||||
//// SenderVisibilityValue.decode ////
|
||||
|
||||
add_test(function test_SenderVisibilityValue_decode() {
|
||||
for (let i = 0; i < 256; i++) {
|
||||
if ((i >= 128) && (i <= 129)) {
|
||||
wsp_decode_test(MMS.SenderVisibilityValue, [i], i);
|
||||
} else {
|
||||
wsp_decode_test(MMS.SenderVisibilityValue, [i], null, "CodeError");
|
||||
}
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
//// SenderVisibilityValue.encode ////
|
||||
|
||||
add_test(function test_SenderVisibilityValue_encode() {
|
||||
for (let i = 0; i < 256; i++) {
|
||||
if ((i >= 128) && (i <= 129)) {
|
||||
wsp_encode_test(MMS.SenderVisibilityValue, i, [i]);
|
||||
} else {
|
||||
wsp_encode_test(MMS.SenderVisibilityValue, i, null, "CodeError");
|
||||
}
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
//
|
||||
// Test target: StatusValue
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user