From a8d895a34d525a27b0bbe277255eff3d88db2bf8 Mon Sep 17 00:00:00 2001 From: Vicamo Yang Date: Mon, 23 Jul 2012 10:20:50 +0800 Subject: [PATCH] Bug 775038 - Part 4: fix type parameter decode, r=philikon --- dom/mms/src/ril/MmsPduHelper.jsm | 2 +- dom/mms/src/ril/WspPduHelper.jsm | 51 ++++++++++++++++++---------- dom/mms/tests/test_wsp_pdu_helper.js | 18 ++++++++++ 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/dom/mms/src/ril/MmsPduHelper.jsm b/dom/mms/src/ril/MmsPduHelper.jsm index cd845ac6c9e..9553c42efdc 100644 --- a/dom/mms/src/ril/MmsPduHelper.jsm +++ b/dom/mms/src/ril/MmsPduHelper.jsm @@ -1299,7 +1299,7 @@ const MMS_WELL_KNOWN_PARAMS = (function () { params[name] = params[number] = entry; } - add("type", 0x02, WSP.ConstrainedEncoding); + add("type", 0x02, WSP.TypeValue); return params; })(); diff --git a/dom/mms/src/ril/WspPduHelper.jsm b/dom/mms/src/ril/WspPduHelper.jsm index 9cc7824ca5d..cc971040477 100644 --- a/dom/mms/src/ril/WspPduHelper.jsm +++ b/dom/mms/src/ril/WspPduHelper.jsm @@ -1038,6 +1038,37 @@ let UriValue = { }, }; +/** + * Internal coder for "type" parameter. + * + * Type-value = Constrained-encoding + * + * @see WAP-230-WSP-20010705-a table 38 + */ +let TypeValue = { + /** + * @param data + * A wrapped object containing raw PDU data. + * + * @return Decoded content type string. + */ + decode: function decode(data) { + let numOrStr = ConstrainedEncoding.decode(data); + if (typeof numOrStr == "string") { + return numOrStr.toLowerCase(); + } + + let number = numOrStr; + let entry = WSP_WELL_KNOWN_CONTENT_TYPES[number]; + if (!entry) { + throw new NotWellKnownEncodingError( + "Constrained-media: not well known media " + number); + } + + return entry.type; + }, +}; + /** * Parameter = Typed-parameter | Untyped-parameter * @@ -1539,23 +1570,8 @@ let ContentTypeValue = { * is not registered or supported. */ decodeConstrainedMedia: function decodeConstrainedMedia(data) { - let numOrStr = ConstrainedEncoding.decode(data); - if (typeof numOrStr == "string") { - return { - media: numOrStr.toLowerCase(), - params: null, - }; - } - - let number = numOrStr; - let entry = WSP_WELL_KNOWN_CONTENT_TYPES[number]; - if (!entry) { - throw new NotWellKnownEncodingError( - "Constrained-media: not well known media " + number); - } - return { - media: entry.type, + media: TypeValue.decode(data), params: null, }; }, @@ -1991,7 +2007,7 @@ const WSP_WELL_KNOWN_PARAMS = (function () { //add("filename", 0x06); Deprecated add("differences", 0x07, FieldName); add("padding", 0x08, ShortInteger); - add("type", 0x09, ConstrainedEncoding); + add("type", 0x09, TypeValue); add("start", 0x0A, TextValue); // Deprecated, but used in some carriers, eg. T-Mobile. //add("start-info", 0x0B); Deprecated //add("comment", 0x0C); Deprecated @@ -2109,6 +2125,7 @@ const EXPORTED_SYMBOLS = ALL_CONST_SYMBOLS.concat([ "QValue", "VersionValue", "UriValue", + "TypeValue", "Parameter", "Header", "WellKnownHeader", diff --git a/dom/mms/tests/test_wsp_pdu_helper.js b/dom/mms/tests/test_wsp_pdu_helper.js index 653f06f7936..50d01106357 100644 --- a/dom/mms/tests/test_wsp_pdu_helper.js +++ b/dom/mms/tests/test_wsp_pdu_helper.js @@ -540,6 +540,24 @@ add_test(function test_UriValue_decode() { run_next_test(); }); +// +// Test target: TypeValue +// + +//// TypeValue.decode //// + +add_test(function test_TypeValue_decode() { + // Test for string-typed return value from ConstrainedEncoding + wsp_decode_test(WSP.TypeValue, [65, 0], "a"); + // Test for number-typed return value from ConstrainedEncoding + wsp_decode_test(WSP.TypeValue, [0x33 | 0x80], + "application/vnd.wap.multipart.related"); + // Test for NotWellKnownEncodingError + wsp_decode_test(WSP.TypeValue, [0x80], null, "NotWellKnownEncodingError"); + + run_next_test(); +}); + // // Test target: Parameter //