annotate mod_component_client/mod_component_client.lua @ 1208:defa479a7d53

mod_component_client: Fire connect (logged in) and disconnect events
author Waqas Hussain <waqas20@gmail.com>
date Fri, 11 Oct 2013 16:56:06 -0400
parents 8b14cdfe0213
children fc39f78e2b36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
993
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1 --[[
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 mod_component_client.lua
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 This module turns Prosody hosts into components of other XMPP servers.
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 Config:
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9 VirtualHost "component.example.com"
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 component_client = {
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 host = "localhost";
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 port = 5347;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 secret = "hunter2";
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 }
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 ]]
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 local socket = require "socket"
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 local logger = require "util.logger";
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 local sha1 = require "util.hashes".sha1;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 local st = require "util.stanza";
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 local jid_split = require "util.jid".split;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 local new_xmpp_stream = require "util.xmppstream".new;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 local uuid_gen = require "util.uuid".generate;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 local core_process_stanza = prosody.core_process_stanza;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 local hosts = prosody.hosts;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 local log = module._log;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 local config = module:get_option("component_client", {});
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 local server_host = config.host or "localhost";
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 local server_port = config.port or 5347;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 local server_secret = config.secret or error("client_component.secret not provided");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 local __conn;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 local listener = {};
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 local session;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 local xmlns_component = 'jabber:component:accept';
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 local stream_callbacks = { default_ns = xmlns_component };
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 function stream_callbacks.error(session, error, data, data2)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 if session.destroyed then return; end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 module:log("warn", "Error processing component stream: %s", tostring(error));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 if error == "no-stream" then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 session:close("invalid-namespace");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 elseif error == "parse-error" then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 session.log("warn", "External component %s XML parse error: %s", tostring(session.host), tostring(data));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 session:close("not-well-formed");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 elseif error == "stream-error" then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59 local condition, text = "undefined-condition";
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60 for child in data:children() do
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 if child.attr.xmlns == xmlns_xmpp_streams then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 if child.name ~= "text" then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 condition = child.name;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 else
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 text = child:get_text();
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67 if condition ~= "undefined-condition" and text then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68 break;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
71 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
72 text = condition .. (text and (" ("..text..")") or "");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
73 session.log("info", "Session closed by remote with error: %s", text);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
74 session:close(nil, text);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
75 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
78 function stream_callbacks.streamopened(session, attr)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
79 -- TODO check id~=nil, from==module.host
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
80 module:log("debug", "Sending handshake");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
81 local handshake = st.stanza("handshake"):text(sha1(attr.id..server_secret, true));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
82 session.send(handshake);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
83 session.notopen = nil;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
84 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
85
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
86 function stream_callbacks.streamclosed(session)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
87 session.log("debug", "Received </stream:stream>");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
88 session:close();
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
89 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
90
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
91 module:hook("stanza/jabber:component:accept:handshake", function(event)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
92 session.type = "component";
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
93 module:log("debug", "Handshake complete");
1208
defa479a7d53 mod_component_client: Fire connect (logged in) and disconnect events
Waqas Hussain <waqas20@gmail.com>
parents: 993
diff changeset
94 module:fire_event("component_client/connected", {});
993
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
95 return true; -- READY!
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
96 end);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
97
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
98 module:hook("route/remote", function(event)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
99 return session and session.send(event.stanza);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
100 end);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
101
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
102 function stream_callbacks.handlestanza(session, stanza)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
103 -- Namespaces are icky.
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
104 if not stanza.attr.xmlns and stanza.name == "handshake" then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
105 stanza.attr.xmlns = xmlns_component;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
106 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
107 if not stanza.attr.xmlns or stanza.attr.xmlns == "jabber:client" then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
108 if not stanza.attr.from then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
109 session.log("warn", "Rejecting stanza with no 'from' address");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
110 session.send(st.error_reply(stanza, "modify", "bad-request", "Components MUST get a 'from' address on stanzas"));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
111 return;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
112 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
113 local _, domain = jid_split(stanza.attr.to);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
114 if not domain then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
115 session.log("warn", "Rejecting stanza with no 'to' address");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
116 session.send(st.error_reply(stanza, "modify", "bad-request", "Components MUST get a 'to' address on stanzas"));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
117 return;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
118 elseif domain ~= session.host then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
119 session.log("warn", "Component received stanza with unknown 'to' address");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
120 session.send(st.error_reply(stanza, "cancel", "not-allowed", "Component doesn't serve this JID"));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
121 return;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
122 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
123 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
124 return core_process_stanza(session, stanza);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
125 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
126
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
127 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
128 local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
129 local function session_close(session, reason)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
130 if session.destroyed then return; end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
131 if session.conn then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
132 if session.notopen then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
133 session.send("<?xml version='1.0'?>");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
134 session.send(st.stanza("stream:stream", default_stream_attr):top_tag());
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
135 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
136 if reason then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
137 if type(reason) == "string" then -- assume stream error
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
138 module:log("info", "Disconnecting component, <stream:error> is: %s", reason);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
139 session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
140 elseif type(reason) == "table" then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
141 if reason.condition then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
142 local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up();
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
143 if reason.text then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
144 stanza:tag("text", stream_xmlns_attr):text(reason.text):up();
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
145 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
146 if reason.extra then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
147 stanza:add_child(reason.extra);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
148 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
149 module:log("info", "Disconnecting component, <stream:error> is: %s", tostring(stanza));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
150 session.send(stanza);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
151 elseif reason.name then -- a stanza
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
152 module:log("info", "Disconnecting component, <stream:error> is: %s", tostring(reason));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
153 session.send(reason);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
154 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
155 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
156 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
157 session.send("</stream:stream>");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
158 session.conn:close();
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
159 listener.ondisconnect(session.conn, "stream error");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
160 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
161 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
162
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
163 function listener.onconnect(conn)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
164 session = { type = "component_unauthed", conn = conn, send = function (data) return conn:write(tostring(data)); end, host = module.host };
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
165
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
166 -- Logging functions --
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
167 local conn_name = "jcp"..tostring(session):match("[a-f0-9]+$");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
168 session.log = logger.init(conn_name);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
169 session.close = session_close;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
170
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
171 session.log("info", "Outgoing Jabber component connection");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
172
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
173 local stream = new_xmpp_stream(session, stream_callbacks);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
174 session.stream = stream;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
175
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
176 function session.data(conn, data)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
177 local ok, err = stream:feed(data);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
178 if ok then return; end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
179 module:log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
180 session:close("not-well-formed");
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
181 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
182
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
183 session.dispatch_stanza = stream_callbacks.handlestanza;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
184
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
185 session.notopen = true;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
186 session.send(st.stanza("stream:stream", {
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
187 to = session.host;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
188 ["xmlns:stream"] = 'http://etherx.jabber.org/streams';
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
189 xmlns = xmlns_component;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
190 }):top_tag());
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
191
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
192 --sessions[conn] = session;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
193 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
194 function listener.onincoming(conn, data)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
195 --local session = sessions[conn];
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
196 session.data(conn, data);
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
197 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
198 function listener.ondisconnect(conn, err)
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
199 --local session = sessions[conn];
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
200 if session then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
201 (session.log or log)("info", "component disconnected: %s (%s)", tostring(session.host), tostring(err));
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
202 if session.on_destroy then session:on_destroy(err); end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
203 --sessions[conn] = nil;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
204 for k in pairs(session) do
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
205 if k ~= "log" and k ~= "close" then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
206 session[k] = nil;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
207 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
208 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
209 session.destroyed = true;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
210 session = nil;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
211 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
212 __conn = nil;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
213 module:log("error", "connection lost");
1208
defa479a7d53 mod_component_client: Fire connect (logged in) and disconnect events
Waqas Hussain <waqas20@gmail.com>
parents: 993
diff changeset
214 module:fire_event("component_client/disconnected", { reason = err });
993
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
215 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
216
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
217 function connect()
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
218 ------------------------
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
219 -- Taken from net.http
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
220 local conn = socket.tcp ( )
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
221 conn:settimeout ( 10 )
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
222 local ok, err = conn:connect ( server_host , server_port )
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
223 if not ok and err ~= "timeout" then
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
224 return nil, err;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
225 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
226
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
227 local handler , conn = server.wrapclient ( conn , server_host , server_port , listener , "*l")
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
228 __conn = conn;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
229 ------------------------
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
230 return true;
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
231 end
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
232 assert(connect());
8b14cdfe0213 mod_component_client: Initial commit. Allows Prosody to act as an external component for other XMPP servers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
233