dom/wappush/src/gonk/WapPushManager.js

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 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 10 Cu.import("resource://gre/modules/Services.jsm");
michael@0 11 Cu.import("resource://gre/modules/PhoneNumberUtils.jsm");
michael@0 12 Cu.import("resource://gre/modules/WspPduHelper.jsm", this);
michael@0 13
michael@0 14 const DEBUG = false; // set to true to see debug messages
michael@0 15
michael@0 16 /**
michael@0 17 * WAP Push decoders
michael@0 18 */
michael@0 19 XPCOMUtils.defineLazyGetter(this, "SI", function () {
michael@0 20 let SI = {};
michael@0 21 Cu.import("resource://gre/modules/SiPduHelper.jsm", SI);
michael@0 22 return SI;
michael@0 23 });
michael@0 24
michael@0 25 XPCOMUtils.defineLazyGetter(this, "SL", function () {
michael@0 26 let SL = {};
michael@0 27 Cu.import("resource://gre/modules/SlPduHelper.jsm", SL);
michael@0 28 return SL;
michael@0 29 });
michael@0 30
michael@0 31 XPCOMUtils.defineLazyGetter(this, "CP", function () {
michael@0 32 let CP = {};
michael@0 33 Cu.import("resource://gre/modules/CpPduHelper.jsm", CP);
michael@0 34 return CP;
michael@0 35 });
michael@0 36
michael@0 37 XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
michael@0 38 "@mozilla.org/system-message-internal;1",
michael@0 39 "nsISystemMessagesInternal");
michael@0 40 XPCOMUtils.defineLazyServiceGetter(this, "gRIL",
michael@0 41 "@mozilla.org/ril;1",
michael@0 42 "nsIRadioInterfaceLayer");
michael@0 43
michael@0 44 /**
michael@0 45 * Helpers for WAP PDU processing.
michael@0 46 */
michael@0 47 this.WapPushManager = {
michael@0 48
michael@0 49 /**
michael@0 50 * Parse raw PDU data and deliver to a proper target.
michael@0 51 *
michael@0 52 * @param data
michael@0 53 * A wrapped object containing raw PDU data.
michael@0 54 * @param options
michael@0 55 * Extra context for decoding.
michael@0 56 */
michael@0 57 processMessage: function processMessage(data, options) {
michael@0 58 try {
michael@0 59 PduHelper.parse(data, true, options);
michael@0 60 debug("options: " + JSON.stringify(options));
michael@0 61 } catch (ex) {
michael@0 62 debug("Failed to parse sessionless WSP PDU: " + ex.message);
michael@0 63 return;
michael@0 64 }
michael@0 65
michael@0 66 let appid = options.headers["x-wap-application-id"];
michael@0 67 if (!appid) {
michael@0 68 // Assume message without applicatioin ID is WAP Push
michael@0 69 debug("Push message doesn't contains X-Wap-Application-Id.");
michael@0 70 }
michael@0 71
michael@0 72 // MMS
michael@0 73 if (appid == "x-wap-application:mms.ua") {
michael@0 74 let mmsService = Cc["@mozilla.org/mms/rilmmsservice;1"]
michael@0 75 .getService(Ci.nsIMmsService);
michael@0 76 mmsService.QueryInterface(Ci.nsIWapPushApplication)
michael@0 77 .receiveWapPush(data.array, data.array.length, data.offset, options);
michael@0 78 return;
michael@0 79 }
michael@0 80
michael@0 81 /**
michael@0 82 * Non-MMS, handled according to content type
michael@0 83 *
michael@0 84 * WAP Type content-type x-wap-application-id
michael@0 85 * MMS "application/vnd.wap.mms-message" "x-wap-application:mms.ua"
michael@0 86 * SI "text/vnd.wap.si" "x-wap-application:wml.ua"
michael@0 87 * SI(WBXML) "application/vnd.wap.sic" "x-wap-application:wml.ua"
michael@0 88 * SL "text/vnd.wap.sl" "x-wap-application:wml.ua"
michael@0 89 * SL(WBXML) "application/vnd.wap.slc" "x-wap-application:wml.ua"
michael@0 90 * Provisioning "text/vnd.wap.connectivity-xml" "x-wap-application:wml.ua"
michael@0 91 * Provisioning(WBXML) "application/vnd.wap.connectivity-wbxml" "x-wap-application:wml.ua"
michael@0 92 *
michael@0 93 * @see http://technical.openmobilealliance.org/tech/omna/omna-wsp-content-type.aspx
michael@0 94 */
michael@0 95 let contentType = options.headers["content-type"].media;
michael@0 96 let msg;
michael@0 97 let authInfo = null;
michael@0 98
michael@0 99 if (contentType === "text/vnd.wap.si" ||
michael@0 100 contentType === "application/vnd.wap.sic") {
michael@0 101 msg = SI.PduHelper.parse(data, contentType);
michael@0 102 } else if (contentType === "text/vnd.wap.sl" ||
michael@0 103 contentType === "application/vnd.wap.slc") {
michael@0 104 msg = SL.PduHelper.parse(data, contentType);
michael@0 105 } else if (contentType === "text/vnd.wap.connectivity-xml" ||
michael@0 106 contentType === "application/vnd.wap.connectivity-wbxml") {
michael@0 107 // Apply HMAC authentication on WBXML encoded CP message.
michael@0 108 if (contentType === "application/vnd.wap.connectivity-wbxml") {
michael@0 109 let params = options.headers["content-type"].params;
michael@0 110 let sec = params && params.sec;
michael@0 111 let mac = params && params.mac;
michael@0 112 authInfo = CP.Authenticator.check(data.array.subarray(data.offset),
michael@0 113 sec, mac, function getNetworkPin() {
michael@0 114 let imsi = gRIL.getRadioInterface(options.serviceId).rilContext.imsi;
michael@0 115 return CP.Authenticator.formatImsi(imsi);
michael@0 116 });
michael@0 117 }
michael@0 118
michael@0 119 msg = CP.PduHelper.parse(data, contentType);
michael@0 120 } else {
michael@0 121 // Unsupported type, provide raw data.
michael@0 122 msg = {
michael@0 123 contentType: contentType,
michael@0 124 content: data.array
michael@0 125 };
michael@0 126 msg.content.length = data.array.length;
michael@0 127 }
michael@0 128
michael@0 129 let sender = PhoneNumberUtils.normalize(options.sourceAddress, false);
michael@0 130 let parsedSender = PhoneNumberUtils.parse(sender);
michael@0 131 if (parsedSender && parsedSender.internationalNumber) {
michael@0 132 sender = parsedSender.internationalNumber;
michael@0 133 }
michael@0 134
michael@0 135 gSystemMessenger.broadcastMessage("wappush-received", {
michael@0 136 sender: sender,
michael@0 137 contentType: msg.contentType,
michael@0 138 content: msg.content,
michael@0 139 authInfo: authInfo,
michael@0 140 serviceId: options.serviceId
michael@0 141 });
michael@0 142 },
michael@0 143
michael@0 144 /**
michael@0 145 * @param array
michael@0 146 * A Uint8Array or an octet array representing raw PDU data.
michael@0 147 * @param length
michael@0 148 * Length of the array.
michael@0 149 * @param offset
michael@0 150 * Offset of the array that a raw PDU data begins.
michael@0 151 * @param options
michael@0 152 * WDP bearer information.
michael@0 153 */
michael@0 154 receiveWdpPDU: function receiveWdpPDU(array, length, offset, options) {
michael@0 155 if ((options.bearer == null) || !options.sourceAddress
michael@0 156 || (options.sourcePort == null) || !array) {
michael@0 157 debug("Incomplete WDP PDU");
michael@0 158 return;
michael@0 159 }
michael@0 160
michael@0 161 if (options.destinationPort != WDP_PORT_PUSH) {
michael@0 162 debug("Not WAP Push port: " + options.destinationPort);
michael@0 163 return;
michael@0 164 }
michael@0 165
michael@0 166 this.processMessage({array: array, offset: offset}, options);
michael@0 167 },
michael@0 168 };
michael@0 169
michael@0 170 let debug;
michael@0 171 if (DEBUG) {
michael@0 172 debug = function (s) {
michael@0 173 dump("-*- WapPushManager: " + s + "\n");
michael@0 174 };
michael@0 175 } else {
michael@0 176 debug = function (s) {};
michael@0 177 }
michael@0 178
michael@0 179 this.EXPORTED_SYMBOLS = ALL_CONST_SYMBOLS.concat([
michael@0 180 "WapPushManager",
michael@0 181 ]);
michael@0 182

mercurial