dom/wappush/src/gonk/SlPduHelper.jsm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
michael@0 8
michael@0 9 let WSP = {};
michael@0 10 Cu.import("resource://gre/modules/WspPduHelper.jsm", WSP);
michael@0 11 let WBXML = {};
michael@0 12 Cu.import("resource://gre/modules/WbxmlPduHelper.jsm", WBXML);
michael@0 13
michael@0 14 // set to true to see debug messages
michael@0 15 let DEBUG = WBXML.DEBUG_ALL | false;
michael@0 16
michael@0 17 /**
michael@0 18 * Public identifier for SL
michael@0 19 *
michael@0 20 * @see http://technical.openmobilealliance.org/tech/omna/omna-wbxml-public-docid.aspx
michael@0 21 */
michael@0 22 const PUBLIC_IDENTIFIER_SL = "-//WAPFORUM//DTD SL 1.0//EN";
michael@0 23
michael@0 24 this.PduHelper = {
michael@0 25
michael@0 26 /**
michael@0 27 * @param data
michael@0 28 * A wrapped object containing raw PDU data.
michael@0 29 * @param contentType
michael@0 30 * Content type of incoming SL message, should be "text/vnd.wap.sl" or
michael@0 31 * "application/vnd.wap.slc".
michael@0 32 *
michael@0 33 * @return A message object containing attribute content and contentType.
michael@0 34 * |content| will contain string of decoded SL message if successfully
michael@0 35 * decoded, or raw data if failed.
michael@0 36 * |contentType| will be string representing corresponding type of
michael@0 37 * content.
michael@0 38 */
michael@0 39 parse: function parse_sl(data, contentType) {
michael@0 40 // We only need content and contentType
michael@0 41 let msg = {
michael@0 42 contentType: contentType
michael@0 43 };
michael@0 44
michael@0 45 /**
michael@0 46 * Message is compressed by WBXML, decode into string.
michael@0 47 *
michael@0 48 * @see WAP-192-WBXML-20010725-A
michael@0 49 */
michael@0 50 if (contentType === "application/vnd.wap.slc") {
michael@0 51 let appToken = {
michael@0 52 publicId: PUBLIC_IDENTIFIER_SL,
michael@0 53 tagTokenList: SL_TAG_FIELDS,
michael@0 54 attrTokenList: SL_ATTRIBUTE_FIELDS,
michael@0 55 valueTokenList: SL_VALUE_FIELDS,
michael@0 56 globalTokenOverride: null
michael@0 57 }
michael@0 58
michael@0 59 try {
michael@0 60 let parseResult = WBXML.PduHelper.parse(data, appToken);
michael@0 61 msg.content = parseResult.content;
michael@0 62 msg.contentType = "text/vnd.wap.sl";
michael@0 63 } catch (e) {
michael@0 64 // Provide raw data if we failed to parse.
michael@0 65 msg.content = data.array;
michael@0 66 }
michael@0 67
michael@0 68 return msg;
michael@0 69 }
michael@0 70
michael@0 71 /**
michael@0 72 * Message is plain text, transform raw to string.
michael@0 73 */
michael@0 74 try {
michael@0 75 let stringData = WSP.Octet.decodeMultiple(data, data.array.length);
michael@0 76 msg.content = WSP.PduHelper.decodeStringContent(stringData, "UTF-8");
michael@0 77 } catch (e) {
michael@0 78 // Provide raw data if we failed to parse.
michael@0 79 msg.content = data.array;
michael@0 80 }
michael@0 81 return msg;
michael@0 82
michael@0 83 }
michael@0 84 };
michael@0 85
michael@0 86 /**
michael@0 87 * Tag tokens
michael@0 88 *
michael@0 89 * @see WAP-168-SERVICELOAD-20010731-A, clause 9.3.1
michael@0 90 */
michael@0 91 const SL_TAG_FIELDS = (function () {
michael@0 92 let names = {};
michael@0 93 function add(name, codepage, number) {
michael@0 94 let entry = {
michael@0 95 name: name,
michael@0 96 number: number,
michael@0 97 };
michael@0 98 if (!names[codepage]) {
michael@0 99 names[codepage] = {};
michael@0 100 }
michael@0 101 names[codepage][number] = entry;
michael@0 102 }
michael@0 103
michael@0 104 add("sl", 0, 0x05);
michael@0 105
michael@0 106 return names;
michael@0 107 })();
michael@0 108
michael@0 109 /**
michael@0 110 * Attribute Tokens
michael@0 111 *
michael@0 112 * @see WAP-168-SERVICELOAD-20010731-A, clause 9.3.2
michael@0 113 */
michael@0 114 const SL_ATTRIBUTE_FIELDS = (function () {
michael@0 115 let names = {};
michael@0 116 function add(name, value, codepage, number) {
michael@0 117 let entry = {
michael@0 118 name: name,
michael@0 119 value: value,
michael@0 120 number: number,
michael@0 121 };
michael@0 122 if (!names[codepage]) {
michael@0 123 names[codepage] = {};
michael@0 124 }
michael@0 125 names[codepage][number] = entry;
michael@0 126 }
michael@0 127
michael@0 128 add("action", "execute-low", 0, 0x05);
michael@0 129 add("action", "execute-high", 0, 0x06);
michael@0 130 add("action", "cache", 0, 0x07);
michael@0 131 add("href", "", 0, 0x08);
michael@0 132 add("href", "http://", 0, 0x09);
michael@0 133 add("href", "http://www.", 0, 0x0A);
michael@0 134 add("href", "https://", 0, 0x0B);
michael@0 135 add("href", "https://www.", 0, 0x0C);
michael@0 136
michael@0 137 return names;
michael@0 138 })();
michael@0 139
michael@0 140 const SL_VALUE_FIELDS = (function () {
michael@0 141 let names = {};
michael@0 142 function add(value, codepage, number) {
michael@0 143 let entry = {
michael@0 144 value: value,
michael@0 145 number: number,
michael@0 146 };
michael@0 147 if (!names[codepage]) {
michael@0 148 names[codepage] = {};
michael@0 149 }
michael@0 150 names[codepage][number] = entry;
michael@0 151 }
michael@0 152
michael@0 153 add(".com/", 0, 0x85);
michael@0 154 add(".edu/", 0, 0x86);
michael@0 155 add(".net/", 0, 0x87);
michael@0 156 add(".org/", 0, 0x88);
michael@0 157
michael@0 158 return names;
michael@0 159 })();
michael@0 160
michael@0 161 this.EXPORTED_SYMBOLS = [
michael@0 162 // Parser
michael@0 163 "PduHelper",
michael@0 164 ];

mercurial