Software /
code /
prosody
Comparison
core/xmlhandlers.lua @ 331:830fd67f9378
Quite some changes, to:
- Small logging fix for s2smanager
- Send a stream error if an incoming s2s connection is to an unrecognised hostname (fixes #11)
- init_xmlhandlers now takes a table of callbacks (includes changes to net/xmpp*_listener for this)
- Move sending of unavailable presence to where it should be, sessionmanager.destroy_session
- Fix sending of stream errors to wrong connection
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 18 Nov 2008 17:52:33 +0000 |
parent | 166:d4ee015fcee4 |
child | 334:bffd80e8c7a3 |
comparison
equal
deleted
inserted
replaced
330:d9d4c1de16ce | 331:830fd67f9378 |
---|---|
23 | 23 |
24 local ns_prefixes = { | 24 local ns_prefixes = { |
25 ["http://www.w3.org/XML/1998/namespace"] = "xml"; | 25 ["http://www.w3.org/XML/1998/namespace"] = "xml"; |
26 } | 26 } |
27 | 27 |
28 function init_xmlhandlers(session, streamopened) | 28 function init_xmlhandlers(session, stream_callbacks) |
29 local ns_stack = { "" }; | 29 local ns_stack = { "" }; |
30 local curr_ns = ""; | 30 local curr_ns = ""; |
31 local curr_tag; | 31 local curr_tag; |
32 local chardata = {}; | 32 local chardata = {}; |
33 local xml_handlers = {}; | 33 local xml_handlers = {}; |
34 local log = session.log or default_log; | 34 local log = session.log or default_log; |
35 --local print = function (...) log("info", "xmlhandlers", t_concatall({...}, "\t")); end | 35 --local print = function (...) log("info", "xmlhandlers", t_concatall({...}, "\t")); end |
36 | 36 |
37 local send = session.send; | 37 local send = session.send; |
38 | |
39 local cb_streamopened = stream_callbacks.streamopened; | |
40 local cb_streamclosed = stream_callbacks.streamclosed; | |
38 | 41 |
39 local stanza | 42 local stanza |
40 function xml_handlers:StartElement(name, attr) | 43 function xml_handlers:StartElement(name, attr) |
41 if stanza and #chardata > 0 then | 44 if stanza and #chardata > 0 then |
42 -- We have some character data in the buffer | 45 -- We have some character data in the buffer |
63 end | 66 end |
64 end | 67 end |
65 | 68 |
66 if not stanza then --if we are not currently inside a stanza | 69 if not stanza then --if we are not currently inside a stanza |
67 if session.notopen then | 70 if session.notopen then |
68 if name == "stream" then | 71 print("client opening with "..tostring(name)); |
69 streamopened(session, attr); | 72 if name == "stream" and cb_streamopened then |
73 cb_streamopened(session, attr); | |
70 return; | 74 return; |
71 end | 75 end |
72 error("Client failed to open stream successfully"); | 76 error("Client failed to open stream successfully"); |
73 end | 77 end |
74 if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then | 78 if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then |
75 error("Client sent invalid top-level stanza"); | 79 error("Client sent invalid top-level stanza"); |
76 end | 80 end |
77 | 81 |
78 stanza = st.stanza(name, attr); --{ to = attr.to, type = attr.type, id = attr.id, xmlns = curr_ns }); | 82 stanza = st.stanza(name, attr); |
79 curr_tag = stanza; | 83 curr_tag = stanza; |
80 else -- we are inside a stanza, so add a tag | 84 else -- we are inside a stanza, so add a tag |
81 attr.xmlns = nil; | 85 attr.xmlns = nil; |
82 if curr_ns ~= "jabber:server" and curr_ns ~= "jabber:client" then | 86 if curr_ns ~= "jabber:server" and curr_ns ~= "jabber:client" then |
83 attr.xmlns = curr_ns; | 87 attr.xmlns = curr_ns; |
91 end | 95 end |
92 end | 96 end |
93 function xml_handlers:EndElement(name) | 97 function xml_handlers:EndElement(name) |
94 curr_ns,name = name:match("^(.+)|([%w%-]+)$"); | 98 curr_ns,name = name:match("^(.+)|([%w%-]+)$"); |
95 if (not stanza) or #stanza.last_add < 0 or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then | 99 if (not stanza) or #stanza.last_add < 0 or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then |
96 if name == "stream" then | 100 if name == "stream" and cb_streamclosed then |
97 log("debug", "Stream closed"); | 101 log("debug", "Stream closed"); |
98 sm_destroy_session(session); | 102 cb_streamclosed(session); |
99 return; | 103 return; |
100 elseif name == "error" then | 104 elseif name == "error" then |
101 error("Stream error: "..tostring(name)..": "..tostring(stanza)); | 105 error("Stream error: "..tostring(name)..": "..tostring(stanza)); |
102 else | 106 else |
103 error("XML parse error in client stream"); | 107 error("XML parse error in client stream"); |