Use a stanza for c2s stream features instead of an array of strings. Removes a FIXME.
[prosody.git] / plugins / mod_tls.lua
1
2 local st = require "util.stanza";
3
4 --local sessions = sessions;
5
6 local t_insert = table.insert;
7
8 local log = require "util.logger".init("mod_starttls");
9
10 local xmlns_starttls ='urn:ietf:params:xml:ns:xmpp-tls';
11
12 add_handler("c2s_unauthed", "starttls", xmlns_starttls,
13                 function (session, stanza)
14                         if session.conn.starttls then
15                                 session.send(st.stanza("proceed", { xmlns = xmlns_starttls }));
16                                 -- FIXME: I'm commenting the below, not sure why it was necessary
17                                 -- sessions[session.conn] = nil;
18                                 session:reset_stream();
19                                 session.conn.starttls();
20                                 session.log("info", "TLS negotiation started...");
21                         else
22                                 -- FIXME: What reply?
23                                 session.log("warn", "Attempt to start TLS, but TLS is not available on this connection");
24                         end
25                 end);
26                 
27 local starttls_attr = { xmlns = xmlns_starttls };
28 add_event_hook("stream-features", 
29                                         function (session, features)                                                                                            
30                                                 if session.conn.starttls then
31                                                         features:tag("starttls", starttls_attr):up();
32                                                 end
33                                         end);