core/xmlhandlers.lua

changeset 31
aaccbf07849b
parent 20
6885fd2cf51f
child 38
3fdfd6e0cb4e
equal deleted inserted replaced
30:bcf539295f2d 31:aaccbf07849b
26 local send = session.send; 26 local send = session.send;
27 27
28 local stanza 28 local stanza
29 function xml_handlers:StartElement(name, attr) 29 function xml_handlers:StartElement(name, attr)
30 if stanza and #chardata > 0 then 30 if stanza and #chardata > 0 then
31 -- We have some character data in the buffer
31 stanza:text(t_concat(chardata)); 32 stanza:text(t_concat(chardata));
32 print("Char data:", t_concat(chardata));
33 chardata = {}; 33 chardata = {};
34 end 34 end
35 curr_ns,name = name:match("^(.+):(%w+)$"); 35 curr_ns,name = name:match("^(.+):(%w+)$");
36 print("Tag received:", name, tostring(curr_ns));
37 if not stanza then 36 if not stanza then
38 if session.notopen then 37 if session.notopen then
39 if name == "stream" then 38 if name == "stream" then
40 session.host = attr.to or error("Client failed to specify destination hostname"); 39 session.host = attr.to or error("Client failed to specify destination hostname");
41 session.version = attr.version or 0; 40 session.version = attr.version or 0;
68 t_insert(chardata, data); 67 t_insert(chardata, data);
69 end 68 end
70 end 69 end
71 function xml_handlers:EndElement(name) 70 function xml_handlers:EndElement(name)
72 curr_ns,name = name:match("^(.+):(%w+)$"); 71 curr_ns,name = name:match("^(.+):(%w+)$");
73 --print("<"..name.."/>", tostring(stanza), tostring(#stanza.last_add < 1), tostring(stanza.last_add[#stanza.last_add].name));
74 if (not stanza) or #stanza.last_add < 0 or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then error("XML parse error in client stream"); end 72 if (not stanza) or #stanza.last_add < 0 or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then error("XML parse error in client stream"); end
75 if stanza and #chardata > 0 then 73 if stanza and #chardata > 0 then
74 -- We have some character data in the buffer
76 stanza:text(t_concat(chardata)); 75 stanza:text(t_concat(chardata));
77 print("Char data:", t_concat(chardata));
78 chardata = {}; 76 chardata = {};
79 end 77 end
80 -- Complete stanza 78 -- Complete stanza
81 print(name, tostring(#stanza.last_add));
82 if #stanza.last_add == 0 then 79 if #stanza.last_add == 0 then
83 session.stanza_dispatch(stanza); 80 session.stanza_dispatch(stanza);
84 stanza = nil; 81 stanza = nil;
85 else 82 else
86 stanza:up(); 83 stanza:up();

mercurial