plugins/mod_component.lua
author Matthew Wild <mwild1@gmail.com>
Mon, 30 Apr 2012 01:20:13 +0100
changeset 4806 27a99c289b90
parent 4805 1aeece2cc814
child 4993 5243b74a4cbb
permissions -rw-r--r--
mod_component: Allow unauthenticated components to authenticate (thanks Maranda)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 1405
diff changeset
     1
-- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2490
diff changeset
     2
-- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2490
diff changeset
     3
-- Copyright (C) 2008-2010 Waqas Hussain
902
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     4
-- 
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     5
-- This project is MIT/X11 licensed. Please see the
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     6
-- COPYING file in the source package for more information.
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     7
--
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     8
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
     9
module:set_global();
902
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
local t_concat = table.concat;
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    12
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    13
local logger = require "util.logger";
902
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    14
local sha1 = require "util.hashes".sha1;
1042
a3d77353c18a mod_*: Fix a load of global accesses
Matthew Wild <mwild1@gmail.com>
parents: 981
diff changeset
    15
local st = require "util.stanza";
902
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    16
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    17
local jid_split = require "util.jid".split;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    18
local new_xmpp_stream = require "util.xmppstream".new;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    19
local uuid_gen = require "util.uuid".generate;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    20
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    21
902
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    22
local log = module._log;
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    23
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    24
local sessions = module:shared("sessions");
3581
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
    25
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    26
function module.add_host(module)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    27
	if module:get_host_type() ~= "component" then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    28
		error("Don't load mod_component manually, it should be for a component, please see http://prosody.im/doc/components", 0);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    29
	end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    30
	
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    31
	local env = module.environment;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    32
	env.connected = false;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    33
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    34
	local send;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    35
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    36
	local function on_destroy(session, err)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    37
		env.connected = false;
3581
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
    38
		send = nil;
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
    39
		session.on_destroy = nil;
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
    40
	end
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    41
	
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    42
	-- Handle authentication attempts by component
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    43
	local function handle_component_auth(event)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    44
		local session, stanza = event.origin, event.stanza;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    45
		
4806
27a99c289b90 mod_component: Allow unauthenticated components to authenticate (thanks Maranda)
Matthew Wild <mwild1@gmail.com>
parents: 4805
diff changeset
    46
		if session.type ~= "component_unauthed" then return; end
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    47
	
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    48
		if (not session.host) or #stanza.tags > 0 then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    49
			(session.log or log)("warn", "Invalid component handshake for host: %s", session.host);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    50
			session:close("not-authorized");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    51
			return true;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    52
		end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    53
		
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    54
		local secret = module:get_option("component_secret");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    55
		if not secret then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    56
			(session.log or log)("warn", "Component attempted to identify as %s, but component_secret is not set", session.host);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    57
			session:close("not-authorized");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    58
			return true;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    59
		end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    60
		
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    61
		local supplied_token = t_concat(stanza);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    62
		local calculated_token = sha1(session.streamid..secret, true);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    63
		if supplied_token:lower() ~= calculated_token:lower() then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    64
			module:log("info", "Component authentication failed for %s", session.host);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    65
			session:close{ condition = "not-authorized", text = "Given token does not match calculated token" };
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    66
			return true;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    67
		end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    68
		
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    69
		if env.connected then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    70
			module:log("error", "Second component attempted to connect, denying connection");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    71
			session:close{ condition = "conflict", text = "Component already connected" };
4734
4d43dbd6de17 mod_component: Return true after denying a second component connection for a host (thanks xnyhps)
Matthew Wild <mwild1@gmail.com>
parents: 4655
diff changeset
    72
			return true;
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    73
		end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    74
		
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    75
		env.connected = true;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    76
		send = session.send;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    77
		session.on_destroy = on_destroy;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    78
		session.component_validate_from = module:get_option_boolean("validate_from_addresses", true);
4805
1aeece2cc814 mod_component: Components start out as component_unauthed until successful authentication (thanks xnyhps)
Matthew Wild <mwild1@gmail.com>
parents: 4803
diff changeset
    79
		session.type = "component";
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    80
		module:log("info", "External component successfully authenticated");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    81
		session.send(st.stanza("handshake"));
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    82
	
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    83
		return true;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    84
	end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    85
	module:hook("stanza/jabber:component:accept:handshake", handle_component_auth);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    86
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    87
	-- Handle stanzas addressed to this component
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    88
	local function handle_stanza(event)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    89
		local stanza = event.stanza;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    90
		if send then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    91
			stanza.attr.xmlns = nil;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    92
			send(stanza);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    93
		else
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    94
			module:log("warn", "Component not connected, bouncing error for: %s", stanza:top_tag());
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    95
			if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    96
				event.origin.send(st.error_reply(stanza, "wait", "service-unavailable", "Component unavailable"));
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    97
			end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    98
		end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
    99
		return true;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   100
	end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   101
	
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   102
	module:hook("iq/bare", handle_stanza, -1);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   103
	module:hook("message/bare", handle_stanza, -1);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   104
	module:hook("presence/bare", handle_stanza, -1);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   105
	module:hook("iq/full", handle_stanza, -1);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   106
	module:hook("message/full", handle_stanza, -1);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   107
	module:hook("presence/full", handle_stanza, -1);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   108
	module:hook("iq/host", handle_stanza, -1);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   109
	module:hook("message/host", handle_stanza, -1);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   110
	module:hook("presence/host", handle_stanza, -1);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   111
end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   112
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   113
--- Network and stream part ---
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   114
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   115
local xmlns_component = 'jabber:component:accept';
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   116
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   117
local listener = {};
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   118
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   119
--- Callbacks/data for xmppstream to handle streams for us ---
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   120
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   121
local stream_callbacks = { default_ns = xmlns_component };
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   122
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   123
local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   124
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   125
function stream_callbacks.error(session, error, data, data2)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   126
	if session.destroyed then return; end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   127
	module:log("warn", "Error processing component stream: "..tostring(error));
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   128
	if error == "no-stream" then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   129
		session:close("invalid-namespace");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   130
	elseif error == "parse-error" then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   131
		session.log("warn", "External component %s XML parse error: %s", tostring(session.host), tostring(data));
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   132
		session:close("not-well-formed");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   133
	elseif error == "stream-error" then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   134
		local condition, text = "undefined-condition";
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   135
		for child in data:children() do
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   136
			if child.attr.xmlns == xmlns_xmpp_streams then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   137
				if child.name ~= "text" then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   138
					condition = child.name;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   139
				else
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   140
					text = child:get_text();
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   141
				end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   142
				if condition ~= "undefined-condition" and text then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   143
					break;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   144
				end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   145
			end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   146
		end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   147
		text = condition .. (text and (" ("..text..")") or "");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   148
		session.log("info", "Session closed by remote with error: %s", text);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   149
		session:close(nil, text);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   150
	end
3581
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
   151
end
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
   152
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   153
function stream_callbacks.streamopened(session, attr)
4655
9159546cb2f3 mod_component: Handle component connecting to non-existent host
Matthew Wild <mwild1@gmail.com>
parents: 4650
diff changeset
   154
	if not hosts[attr.to] or not hosts[attr.to].modules.component then
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   155
		session:close{ condition = "host-unknown", text = tostring(attr.to).." does not match any configured external components" };
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   156
		return;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   157
	end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   158
	session.host = attr.to;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   159
	session.streamid = uuid_gen();
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   160
	session.notopen = nil;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   161
	-- Return stream header
4803
39ba097ec641 mod_component: Send <?xml on initial stream (thanks xnyhps)
Matthew Wild <mwild1@gmail.com>
parents: 4757
diff changeset
   162
	session.send("<?xml version='1.0'?>");
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   163
	session.send(st.stanza("stream:stream", { xmlns=xmlns_component,
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   164
			["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.host }):top_tag());
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   165
end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   166
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   167
function stream_callbacks.streamclosed(session)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   168
	session.log("debug", "Received </stream:stream>");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   169
	session:close();
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   170
end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   171
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   172
local core_process_stanza = core_process_stanza;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   173
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   174
function stream_callbacks.handlestanza(session, stanza)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   175
	-- Namespaces are icky.
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   176
	if not stanza.attr.xmlns and stanza.name == "handshake" then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   177
		stanza.attr.xmlns = xmlns_component;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   178
	end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   179
	if not stanza.attr.xmlns or stanza.attr.xmlns == "jabber:client" then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   180
		local from = stanza.attr.from;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   181
		if from then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   182
			if session.component_validate_from then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   183
				local _, domain = jid_split(stanza.attr.from);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   184
				if domain ~= session.host then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   185
					-- Return error
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   186
					session.log("warn", "Component sent stanza with missing or invalid 'from' address");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   187
					session:close{
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   188
						condition = "invalid-from";
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   189
						text = "Component tried to send from address <"..tostring(from)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   190
							   .."> which is not in domain <"..tostring(session.host)..">";
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   191
					};
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   192
					return;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   193
				end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   194
			end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   195
		else
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   196
			stanza.attr.from = session.host; -- COMPAT: Strictly we shouldn't allow this
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   197
		end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   198
		if not stanza.attr.to then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   199
			session.log("warn", "Rejecting stanza with no 'to' address");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   200
			session.send(st.error_reply(stanza, "modify", "bad-request", "Components MUST specify a 'to' address on stanzas"));
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   201
			return;
3581
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
   202
		end
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
   203
	end
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   204
	return core_process_stanza(session, stanza);
3581
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
   205
end
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
   206
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   207
--- Closing a component connection
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   208
local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   209
local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   210
local function session_close(session, reason)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   211
	if session.destroyed then return; end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   212
	if session.conn then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   213
		if session.notopen then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   214
			session.send("<?xml version='1.0'?>");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   215
			session.send(st.stanza("stream:stream", default_stream_attr):top_tag());
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   216
		end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   217
		if reason then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   218
			if type(reason) == "string" then -- assume stream error
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   219
				module:log("info", "Disconnecting component, <stream:error> is: %s", reason);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   220
				session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }));
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   221
			elseif type(reason) == "table" then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   222
				if reason.condition then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   223
					local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up();
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   224
					if reason.text then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   225
						stanza:tag("text", stream_xmlns_attr):text(reason.text):up();
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   226
					end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   227
					if reason.extra then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   228
						stanza:add_child(reason.extra);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   229
					end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   230
					module:log("info", "Disconnecting component, <stream:error> is: %s", tostring(stanza));
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   231
					session.send(stanza);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   232
				elseif reason.name then -- a stanza
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   233
					module:log("info", "Disconnecting component, <stream:error> is: %s", tostring(reason));
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   234
					session.send(reason);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   235
				end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   236
			end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   237
		end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   238
		session.send("</stream:stream>");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   239
		session.conn:close();
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   240
		listener.ondisconnect(session.conn, "stream error");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   241
	end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   242
end
3581
3f3f8227ba76 mod_component: Updated to use events for hooking stanzas instead of the component stanza handler, and the on_destroy callback.
Waqas Hussain <waqas20@gmail.com>
parents: 3579
diff changeset
   243
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   244
--- Component connlistener
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   245
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   246
function listener.onconnect(conn)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   247
	local _send = conn.write;
4805
1aeece2cc814 mod_component: Components start out as component_unauthed until successful authentication (thanks xnyhps)
Matthew Wild <mwild1@gmail.com>
parents: 4803
diff changeset
   248
	local session = { type = "component_unauthed", conn = conn, send = function (data) return _send(conn, tostring(data)); end };
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   249
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   250
	-- Logging functions --
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   251
	local conn_name = "jcp"..tostring(conn):match("[a-f0-9]+$");
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   252
	session.log = logger.init(conn_name);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   253
	session.close = session_close;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   254
	
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   255
	session.log("info", "Incoming Jabber component connection");
3531
f41e1cfe92f4 mod_component: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3503
diff changeset
   256
	
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   257
	local stream = new_xmpp_stream(session, stream_callbacks);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   258
	session.stream = stream;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   259
	
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   260
	session.notopen = true;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   261
	
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   262
	function session.reset_stream()
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   263
		session.notopen = true;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   264
		session.stream:reset();
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   265
	end
3531
f41e1cfe92f4 mod_component: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3503
diff changeset
   266
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   267
	function session.data(conn, data)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   268
		local ok, err = stream:feed(data);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   269
		if ok then return; end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   270
		module:log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   271
		session:close("not-well-formed");
902
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   272
	end
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   273
	
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   274
	session.dispatch_stanza = stream_callbacks.handlestanza;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   275
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   276
	sessions[conn] = session;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   277
end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   278
function listener.onincoming(conn, data)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   279
	local session = sessions[conn];
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   280
	session.data(conn, data);
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   281
end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   282
function listener.ondisconnect(conn, err)
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   283
	local session = sessions[conn];
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   284
	if session then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   285
		(session.log or log)("info", "component disconnected: %s (%s)", tostring(session.host), tostring(err));
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   286
		if session.on_destroy then session:on_destroy(err); end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   287
		sessions[conn] = nil;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   288
		for k in pairs(session) do
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   289
			if k ~= "log" and k ~= "close" then
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   290
				session[k] = nil;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   291
			end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   292
		end
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   293
		session.destroyed = true;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   294
		session = nil;
902
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   295
	end
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   296
end
00daf63c129e Add initial mod_component for XEP-0114 support. Albert, where are you?
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   297
4650
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   298
module:add_item("net-provider", {
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   299
	name = "component";
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   300
	listener = listener;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   301
	default_port = 5347;
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   302
	multiplex = {
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   303
		pattern = "^<.*:stream.*%sxmlns%s*=%s*(['\"])jabber:component%1.*>";
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   304
	};
464ca74ddf6a mod_component: Make a shared module, and move the xmppcomponent_listener into it ('port'ing over to portmanager). Ha ha.
Matthew Wild <mwild1@gmail.com>
parents: 4464
diff changeset
   305
});