2013-05-30 10:22:46 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var WSP = {};
|
2013-05-30 10:22:46 +04:00
|
|
|
Cu.import("resource://gre/modules/WspPduHelper.jsm", WSP);
|
2015-09-15 21:19:45 +03:00
|
|
|
var WBXML = {};
|
2013-05-30 10:22:46 +04:00
|
|
|
Cu.import("resource://gre/modules/WbxmlPduHelper.jsm", WBXML);
|
|
|
|
|
|
|
|
// set to true to see debug messages
|
2015-09-15 21:19:45 +03:00
|
|
|
var DEBUG = WBXML.DEBUG_ALL | false;
|
2013-05-30 10:22:46 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Public identifier for SL
|
|
|
|
*
|
|
|
|
* @see http://technical.openmobilealliance.org/tech/omna/omna-wbxml-public-docid.aspx
|
|
|
|
*/
|
|
|
|
const PUBLIC_IDENTIFIER_SL = "-//WAPFORUM//DTD SL 1.0//EN";
|
|
|
|
|
|
|
|
this.PduHelper = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param data
|
|
|
|
* A wrapped object containing raw PDU data.
|
2013-07-22 13:52:45 +04:00
|
|
|
* @param contentType
|
2013-05-30 10:22:46 +04:00
|
|
|
* Content type of incoming SL message, should be "text/vnd.wap.sl" or
|
|
|
|
* "application/vnd.wap.slc".
|
|
|
|
*
|
2013-07-22 13:52:45 +04:00
|
|
|
* @return A message object containing attribute content and contentType.
|
|
|
|
* |content| will contain string of decoded SL message if successfully
|
|
|
|
* decoded, or raw data if failed.
|
|
|
|
* |contentType| will be string representing corresponding type of
|
|
|
|
* content.
|
2013-05-30 10:22:46 +04:00
|
|
|
*/
|
2013-06-17 14:49:03 +04:00
|
|
|
parse: function parse_sl(data, contentType) {
|
2013-07-22 13:52:45 +04:00
|
|
|
// We only need content and contentType
|
|
|
|
let msg = {
|
|
|
|
contentType: contentType
|
|
|
|
};
|
2013-05-30 10:22:46 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Message is compressed by WBXML, decode into string.
|
|
|
|
*
|
|
|
|
* @see WAP-192-WBXML-20010725-A
|
|
|
|
*/
|
2013-07-22 13:52:45 +04:00
|
|
|
if (contentType === "application/vnd.wap.slc") {
|
2013-05-30 10:22:46 +04:00
|
|
|
let appToken = {
|
|
|
|
publicId: PUBLIC_IDENTIFIER_SL,
|
2013-07-22 13:52:45 +04:00
|
|
|
tagTokenList: SL_TAG_FIELDS,
|
|
|
|
attrTokenList: SL_ATTRIBUTE_FIELDS,
|
|
|
|
valueTokenList: SL_VALUE_FIELDS,
|
2013-05-30 10:22:46 +04:00
|
|
|
globalTokenOverride: null
|
|
|
|
}
|
|
|
|
|
2013-07-22 13:52:45 +04:00
|
|
|
try {
|
|
|
|
let parseResult = WBXML.PduHelper.parse(data, appToken);
|
|
|
|
msg.content = parseResult.content;
|
|
|
|
msg.contentType = "text/vnd.wap.sl";
|
|
|
|
} catch (e) {
|
|
|
|
// Provide raw data if we failed to parse.
|
|
|
|
msg.content = data.array;
|
|
|
|
}
|
2013-05-30 10:22:46 +04:00
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Message is plain text, transform raw to string.
|
|
|
|
*/
|
2013-07-22 13:52:45 +04:00
|
|
|
try {
|
2013-05-30 10:22:46 +04:00
|
|
|
let stringData = WSP.Octet.decodeMultiple(data, data.array.length);
|
|
|
|
msg.content = WSP.PduHelper.decodeStringContent(stringData, "UTF-8");
|
2013-07-22 13:52:45 +04:00
|
|
|
} catch (e) {
|
|
|
|
// Provide raw data if we failed to parse.
|
|
|
|
msg.content = data.array;
|
2013-05-30 10:22:46 +04:00
|
|
|
}
|
2013-07-22 13:52:45 +04:00
|
|
|
return msg;
|
2013-05-30 10:22:46 +04:00
|
|
|
|
2013-07-22 13:52:45 +04:00
|
|
|
}
|
2013-05-30 10:22:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tag tokens
|
|
|
|
*
|
|
|
|
* @see WAP-168-SERVICELOAD-20010731-A, clause 9.3.1
|
|
|
|
*/
|
|
|
|
const SL_TAG_FIELDS = (function () {
|
|
|
|
let names = {};
|
2013-07-29 11:08:38 +04:00
|
|
|
function add(name, codepage, number) {
|
2013-05-30 10:22:46 +04:00
|
|
|
let entry = {
|
|
|
|
name: name,
|
|
|
|
number: number,
|
|
|
|
};
|
2013-07-29 11:08:38 +04:00
|
|
|
if (!names[codepage]) {
|
|
|
|
names[codepage] = {};
|
|
|
|
}
|
|
|
|
names[codepage][number] = entry;
|
2013-05-30 10:22:46 +04:00
|
|
|
}
|
|
|
|
|
2013-07-29 11:08:38 +04:00
|
|
|
add("sl", 0, 0x05);
|
2013-05-30 10:22:46 +04:00
|
|
|
|
|
|
|
return names;
|
|
|
|
})();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attribute Tokens
|
|
|
|
*
|
|
|
|
* @see WAP-168-SERVICELOAD-20010731-A, clause 9.3.2
|
|
|
|
*/
|
|
|
|
const SL_ATTRIBUTE_FIELDS = (function () {
|
|
|
|
let names = {};
|
2013-07-29 11:08:38 +04:00
|
|
|
function add(name, value, codepage, number) {
|
2013-05-30 10:22:46 +04:00
|
|
|
let entry = {
|
|
|
|
name: name,
|
|
|
|
value: value,
|
|
|
|
number: number,
|
|
|
|
};
|
2013-07-29 11:08:38 +04:00
|
|
|
if (!names[codepage]) {
|
|
|
|
names[codepage] = {};
|
|
|
|
}
|
|
|
|
names[codepage][number] = entry;
|
2013-05-30 10:22:46 +04:00
|
|
|
}
|
|
|
|
|
2013-07-29 11:08:38 +04:00
|
|
|
add("action", "execute-low", 0, 0x05);
|
|
|
|
add("action", "execute-high", 0, 0x06);
|
|
|
|
add("action", "cache", 0, 0x07);
|
|
|
|
add("href", "", 0, 0x08);
|
|
|
|
add("href", "http://", 0, 0x09);
|
|
|
|
add("href", "http://www.", 0, 0x0A);
|
|
|
|
add("href", "https://", 0, 0x0B);
|
|
|
|
add("href", "https://www.", 0, 0x0C);
|
2013-07-22 13:52:45 +04:00
|
|
|
|
|
|
|
return names;
|
|
|
|
})();
|
|
|
|
|
|
|
|
const SL_VALUE_FIELDS = (function () {
|
|
|
|
let names = {};
|
2013-07-29 11:08:38 +04:00
|
|
|
function add(value, codepage, number) {
|
2013-07-22 13:52:45 +04:00
|
|
|
let entry = {
|
|
|
|
value: value,
|
|
|
|
number: number,
|
|
|
|
};
|
2013-07-29 11:08:38 +04:00
|
|
|
if (!names[codepage]) {
|
|
|
|
names[codepage] = {};
|
|
|
|
}
|
|
|
|
names[codepage][number] = entry;
|
2013-07-22 13:52:45 +04:00
|
|
|
}
|
|
|
|
|
2013-07-29 11:08:38 +04:00
|
|
|
add(".com/", 0, 0x85);
|
|
|
|
add(".edu/", 0, 0x86);
|
|
|
|
add(".net/", 0, 0x87);
|
|
|
|
add(".org/", 0, 0x88);
|
2013-05-30 10:22:46 +04:00
|
|
|
|
|
|
|
return names;
|
|
|
|
})();
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = [
|
|
|
|
// Parser
|
|
|
|
"PduHelper",
|
|
|
|
];
|