Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #12147 from gabrielesvelto/bug-887156-wappush-whit…
Browse files Browse the repository at this point in the history
…elist

Bug 887156 - Add a mechanism to filter WAP Push messages based on a whitelist of source MSISDNs r=timdream
  • Loading branch information
gabrielesvelto committed Sep 12, 2013
2 parents 7691c10 + f2d84fe commit fe406c3
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 9 deletions.
1 change: 1 addition & 0 deletions apps/wappush/.gitignore
@@ -0,0 +1 @@
js/whitelist.json
1 change: 1 addition & 0 deletions apps/wappush/index.html
Expand Up @@ -22,6 +22,7 @@

<!-- Specific code -->
<script defer src="js/wappush.js"></script>
<script defer src="js/whitelist.js"></script>
</head>

<body role="application">
Expand Down
39 changes: 30 additions & 9 deletions apps/wappush/js/wappush.js
Expand Up @@ -64,6 +64,35 @@ var WapPushManager = {
return parsed;
},

/**
* Establish if we must show this message or not; the message is shown only
* if the following conditions are met:
* - WAP Push functionality is enabled
* - The message is either a SI or SL message
* - The sender's MSISDN is whitelisted or whitelisting is disabled
*
* @param {Object} message The message to be checked
*
* @return {Boolean} true if the message should be displayed, false otherwise
*/
shouldDisplayMessage: function wpm_shouldDisplayMessage(message) {
if (!this._wapPushEnabled || !WhiteList.has(message.sender)) {
/* WAP push functionality is either completely disabled or the message
* comes from a non white-listed MSISDN, ignore it. */
return false;
}

if ((message.contentType != 'text/vnd.wap.si') &&
(message.contentType != 'text/vnd.wap.sl')) {
// Only accept SI and SL messages
console.log('Unsupported or invalid content type "' +
message.contentType + '" for WAP Push message\n');
return false;
}

return true;
},

/**
* Handler for the wappush-received system messages, stores the message into
* the internal database and posts a notification which can be used to
Expand All @@ -75,15 +104,7 @@ var WapPushManager = {
var self = this;
var timestamp = Date.now();

if (!this._wapPushEnabled) {
this.close();
return;
}

if ((message.contentType != 'text/vnd.wap.si') &&
(message.contentType != 'text/vnd.wap.sl')) {
console.log('Unsupported or invalid content type "' +
message.contentType + '" for WAP Push message\n');
if (!this.shouldDisplayMessage(message)) {
this.close();
return;
}
Expand Down
56 changes: 56 additions & 0 deletions apps/wappush/js/whitelist.js
@@ -0,0 +1,56 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */

'use strict';

/**
* MSISDN whitelist, if not empty only the messages sent from the MSISDNs
* present in the list will be shown to the user, others will be discarded.
*/
var WhiteList = {
/** An array holding the list of MSISDNs */
_whiteList: [],

/**
* Read the whitelist.json file from disk and initialize the whitelist with
* it. If the file is not present or empty the whitelist will be empty.
*/
init: function wl_init() {
var xhr = new XMLHttpRequest();
xhr.overrideMimeType('application/json');
xhr.open('GET', 'js/whitelist.json', true);
xhr.send(null);

xhr.onreadystatechange = (function wl_load(evt) {
if (xhr.readyState != 4)
return;

if (xhr.status == 0 || xhr.status == 200) {
var list = JSON.parse(xhr.responseText);
var whiteList = [];

list.forEach(function wl_addTo(item) {
whiteList.push(item);
});

this._whiteList = whiteList;
}
}).bind(this);
},

/**
* Checks if the element is in the whitelist.
*
* @return {Boolean} true if the element is in the whitelist, always return
* true if the whitelist is empty
*/
has: function wl_has(value) {
if (this._whiteList.length === 0) {
return true;
}

return (this._whiteList.indexOf(value) !== -1);
}
};

WhiteList.init();
7 changes: 7 additions & 0 deletions build/applications-data.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fe406c3

Please sign in to comment.