My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60


/*
* The listener calls this script on the caller domain and checks whether there is a message in the caller message queue
*/

var wp = google.gears.workerPool;
wp.allowCrossOrigin();
wp.onmessage = function(a, b, message) {

// parse the hostname out of the messages's origin
var origin = new String(message.origin);
var parts = origin.split("/");
var domain = parts[2];

var recipient = domain;
var channelId = message.text;

// Create the table in case it is not there yet
var db = google.gears.factory.create('beta.database');
db.open('database-xssinterface');
db.execute('create table if not exists XSSMessageQueue' +
' (id INTEGER PRIMARY KEY AUTOINCREMENT, recipient_domain TEXT, channel_id TEXT, message TEXT, insert_time INTEGER)');

// delete (and thus ignore) old messages
var maxAge = new Date().getTime() - 2000;
db.execute('delete from XSSMessageQueue where insert_time < ?',[maxAge]);

db.close();

// Start looking for new messages
var timer = google.gears.factory.create('beta.timer');
timer.setInterval(function() {
// get a new db handle on each iteration
var db = google.gears.factory.create('beta.database');
db.open('database-xssinterface');

db.execute("BEGIN TRANSACTION");

// find new messages for meps
var rs = db.execute('select id, message from XSSMessageQueue where recipient_domain = ? and channel_id = ?', [recipient, channelId]);

// there are new messages for the recipient
while(rs.isValidRow()) {
var id = rs.field(0);
var text = rs.field(1);

// send the message to our creator
wp.sendMessage(text, message.sender);
db.execute("DELETE from XSSMessageQueue where id = ?", [id]); // unqueue message
rs.next()
}

rs.close();

db.execute("COMMIT")

db.close();
}, 300);
}
Show details Hide details

Change log

r101 by nicolas.albert on Nov 19, 2008   Diff
 Issue 5   : http://code.google.com/p/xssint
erface/issues/detail?id=5
xssinterface handle host:port, better
cross-domain policy compliance
Go to: 
Project members, sign in to write a code review

Older revisions

r72 by malte.ubl on Mar 13, 2008   Diff
Improved Documentation
r63 by malte.ubl on Mar 10, 2008   Diff
Improved Google Gears Performance by
using a single transaction
r61 by malte.ubl on Mar 10, 2008   Diff
Made tests independent of used domains
All revisions of this file

File info

Size: 1809 bytes, 60 lines
Hosted by Google Code