Comparison

core/xmlhandlers.lua @ 341:a9e02b5c58d2

Don't error if streamopened/streamclosed callback is not specified for a session
author Matthew Wild <mwild1@gmail.com>
date Wed, 19 Nov 2008 05:10:16 +0000
parent 334:bffd80e8c7a3
child 355:e25c8d91b37f
comparison
equal deleted inserted replaced
340:a31715bf08eb 341:a9e02b5c58d2
67 end 67 end
68 68
69 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
70 if session.notopen then 70 if session.notopen then
71 print("client opening with "..tostring(name)); 71 print("client opening with "..tostring(name));
72 if name == "stream" and cb_streamopened then 72 if name == "stream" then
73 cb_streamopened(session, attr); 73 if cb_streamopened then
74 cb_streamopened(session, attr);
75 end
74 return; 76 return;
75 end 77 end
76 error("Client failed to open stream successfully"); 78 error("Client failed to open stream successfully");
77 end 79 end
78 if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then 80 if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then
95 end 97 end
96 end 98 end
97 function xml_handlers:EndElement(name) 99 function xml_handlers:EndElement(name)
98 curr_ns,name = name:match("^(.+)|([%w%-]+)$"); 100 curr_ns,name = name:match("^(.+)|([%w%-]+)$");
99 if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then 101 if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then
100 if name == "stream" and cb_streamclosed then 102 if name == "stream" then
101 log("debug", "Stream closed"); 103 log("debug", "Stream closed");
102 cb_streamclosed(session); 104 if cb_streamclosed then
105 cb_streamclosed(session);
106 end
103 return; 107 return;
104 elseif name == "error" then 108 elseif name == "error" then
105 error("Stream error: "..tostring(name)..": "..tostring(stanza)); 109 error("Stream error: "..tostring(name)..": "..tostring(stanza));
106 else 110 else
107 error("XML parse error in client stream"); 111 error("XML parse error in client stream with element: "..name);
108 end 112 end
109 end 113 end
110 if stanza and #chardata > 0 then 114 if stanza and #chardata > 0 then
111 -- We have some character data in the buffer 115 -- We have some character data in the buffer
112 stanza:text(t_concat(chardata)); 116 stanza:text(t_concat(chardata));