Mercurial > prosody-modules
comparison mod_flash_policy/mod_flash_policy.lua @ 394:4219f69be1cf
Let session.send() actually send the config string
author | leonbogaert@gmail.com |
---|---|
date | Tue, 26 Jul 2011 13:18:38 +0000 |
parents | eebc19c224fb |
children | 77ca0947647b |
comparison
equal
deleted
inserted
replaced
393:20ef4a289d7d | 394:4219f69be1cf |
---|---|
1 local filters = require "util.filters"; | 1 local filters = require "util.filters"; |
2 local config = {} | 2 local config = {} |
3 config.file = module:get_option_string("crossdomain_file", ""); | 3 config.file = module:get_option_string("crossdomain_file", ""); |
4 config.string = module:get_option_string("crossdomain_string", [[<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd"><cross-domain-policy><site-control permitted-cross-domain-policies="master-only"/><allow-access-from domain="*" /></cross-domain-policy>]]); | 4 config.string = module:get_option_string("crossdomain_string", [[<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dt$ |
5 local string = '' | 5 local string = '' |
6 if not config.file ~= '' then | 6 if not config.file ~= '' then |
7 local f = assert(io.open(config.file)); | 7 local f = assert(io.open(config.file)); |
8 string = f:read("*all"); | 8 string = f:read("*all"); |
9 else | 9 else |
10 string = config.string | 10 string = config.string |
11 end | 11 end |
12 | 12 |
13 module:log("debug", "crossdomain string: "..string); | 13 module:log("debug", "crossdomain string: "..string); |
14 | 14 |
15 module:set_global(); | 15 module:set_global(); |
16 | 16 |
17 function filter_policy(data, session) | 17 function filter_policy(data, session) |
18 -- Since we only want to check the first block of data, remove the filter | 18 -- Since we only want to check the first block of data, remove the filter |
19 filters.remove_filter(session, "bytes/in", filter_policy); | 19 filters.remove_filter(session, "bytes/in", filter_policy); |
20 if data == "<policy-file-request/>\0" then | 20 if data == "<policy-file-request/>\0" then |
21 session.send([[<?xml version="1.0"?> | 21 session.send(string.."\0"); |
22 <!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd"> | 22 return nil; -- Drop data to prevent it reaching the XMPP parser |
23 <cross-domain-policy> | 23 else |
24 <site-control permitted-cross-domain-policies="master-only"/> | 24 return data; -- Pass data through, it wasn't a policy request |
25 <allow-access-from domain="livechat.concepts.tim-online.nl" to-ports="5222" /> | 25 end |
26 </cross-domain-policy>]].."\0"); | 26 |
27 return nil; -- Drop data to prevent it reaching the XMPP parser | |
28 else | |
29 return data; -- Pass data through, it wasn't a policy request | |
30 end | |
31 | |
32 end | 27 end |
33 | 28 |
34 function filter_session(session) | 29 function filter_session(session) |
35 if session.type == "c2s_unauthed" then | 30 if session.type == "c2s_unauthed" then |
36 filters.add_filter(session, "bytes/in", filter_policy, -1); | 31 filters.add_filter(session, "bytes/in", filter_policy, -1); |
37 end | 32 end |
38 end | 33 end |
39 | 34 |
40 function module.load() | 35 function module.load() |
41 filters.add_filter_hook(filter_session); | 36 filters.add_filter_hook(filter_session); |
42 end | 37 end |
43 | 38 |
44 function module.unload() | 39 function module.unload() |
45 filters.remove_filter_hook(filter_session); | 40 filters.remove_filter_hook(filter_session); |
46 end | 41 end |