Mercurial > prosody-modules
comparison mod_flash_policy/mod_flash_policy.lua @ 395:77ca0947647b
Copied from bash :s
author | leonbogaert@gmail.com |
---|---|
date | Tue, 26 Jul 2011 13:19:09 +0000 |
parents | 4219f69be1cf |
children | 7dbde05b48a9 |
comparison
equal
deleted
inserted
replaced
394:4219f69be1cf | 395:77ca0947647b |
---|---|
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.dt$ | 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>]]); |
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(string.."\0"); | 21 session.send(string.."\0"); |
22 return nil; -- Drop data to prevent it reaching the XMPP parser | 22 return nil; -- Drop data to prevent it reaching the XMPP parser |
23 else | 23 else |
24 return data; -- Pass data through, it wasn't a policy request | 24 return data; -- Pass data through, it wasn't a policy request |
25 end | 25 end |
26 | 26 |
27 end | 27 end |
28 | 28 |
29 function filter_session(session) | 29 function filter_session(session) |
30 if session.type == "c2s_unauthed" then | 30 if session.type == "c2s_unauthed" then |
31 filters.add_filter(session, "bytes/in", filter_policy, -1); | 31 filters.add_filter(session, "bytes/in", filter_policy, -1); |
32 end | 32 end |
33 end | 33 end |
34 | 34 |
35 function module.load() | 35 function module.load() |
36 filters.add_filter_hook(filter_session); | 36 filters.add_filter_hook(filter_session); |
37 end | 37 end |
38 | 38 |
39 function module.unload() | 39 function module.unload() |
40 filters.remove_filter_hook(filter_session); | 40 filters.remove_filter_hook(filter_session); |
41 end | 41 end |