util/stanza.lua
changeset 10450 5c2d1b13537c
parent 10449 f53c03ab4357
child 10507 e25a1a9a6e7e
equal deleted inserted replaced
10449:f53c03ab4357 10450:5c2d1b13537c
   445 			type = ((orig.name == "iq" and "result") or orig.attr.type)
   445 			type = ((orig.name == "iq" and "result") or orig.attr.type)
   446 		});
   446 		});
   447 end
   447 end
   448 
   448 
   449 local xmpp_stanzas_attr = { xmlns = xmlns_stanzas };
   449 local xmpp_stanzas_attr = { xmlns = xmlns_stanzas };
   450 local function error_reply(orig, error_type, condition, error_message)
   450 local function error_reply(orig, error_type, condition, error_message, error_by)
   451 	if not is_stanza(orig) then
   451 	if not is_stanza(orig) then
   452 		error("bad argument to error_reply: expected stanza, got "..type(orig));
   452 		error("bad argument to error_reply: expected stanza, got "..type(orig));
   453 	elseif orig.attr.type == "error" then
   453 	elseif orig.attr.type == "error" then
   454 		error("bad argument to error_reply: got stanza of type error which must not be replied to");
   454 		error("bad argument to error_reply: got stanza of type error which must not be replied to");
   455 	end
   455 	end
   456 	local t = reply(orig);
   456 	local t = reply(orig);
   457 	t.attr.type = "error";
   457 	t.attr.type = "error";
   458 	t:tag("error", {type = error_type}) --COMPAT: Some day xmlns:stanzas goes here
   458 	if t.attr.from == error_by then
       
   459 		error_by = nil;
       
   460 	end
       
   461 	t:tag("error", {type = error_type, by = error_by}) --COMPAT: Some day xmlns:stanzas goes here
   459 	:tag(condition, xmpp_stanzas_attr):up();
   462 	:tag(condition, xmpp_stanzas_attr):up();
   460 	if error_message then t:text_tag("text", error_message, xmpp_stanzas_attr); end
   463 	if error_message then t:text_tag("text", error_message, xmpp_stanzas_attr); end
   461 	return t; -- stanza ready for adding app-specific errors
   464 	return t; -- stanza ready for adding app-specific errors
   462 end
   465 end
   463 
   466