Software /
code /
prosody
Comparison
util/stanza.lua @ 10116:4807535b8673
util.stanza: Use :text_tag internally everywhere
May allow future changes in a single place.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 02 Aug 2019 08:56:29 +0200 |
parent | 9924:5a2e53bef031 |
child | 10442:22db763c510c |
comparison
equal
deleted
inserted
replaced
10115:c0bd5daa9c7f | 10116:4807535b8673 |
---|---|
96 function stanza_mt:query(xmlns) | 96 function stanza_mt:query(xmlns) |
97 return self:tag("query", { xmlns = xmlns }); | 97 return self:tag("query", { xmlns = xmlns }); |
98 end | 98 end |
99 | 99 |
100 function stanza_mt:body(text, attr) | 100 function stanza_mt:body(text, attr) |
101 return self:tag("body", attr):text(text); | 101 return self:text_tag("body", text, attr); |
102 end | 102 end |
103 | 103 |
104 function stanza_mt:text_tag(name, text, attr, namespaces) | 104 function stanza_mt:text_tag(name, text, attr, namespaces) |
105 return self:tag(name, attr, namespaces):text(text):up(); | 105 return self:tag(name, attr, namespaces):text(text):up(); |
106 end | 106 end |
415 | 415 |
416 local function message(attr, body) | 416 local function message(attr, body) |
417 if not body then | 417 if not body then |
418 return new_stanza("message", attr); | 418 return new_stanza("message", attr); |
419 else | 419 else |
420 return new_stanza("message", attr):tag("body"):text(body):up(); | 420 return new_stanza("message", attr):text_tag("body", body); |
421 end | 421 end |
422 end | 422 end |
423 local function iq(attr) | 423 local function iq(attr) |
424 if not attr then | 424 if not attr then |
425 error("iq stanzas require id and type attributes"); | 425 error("iq stanzas require id and type attributes"); |
447 local function error_reply(orig, error_type, condition, error_message) | 447 local function error_reply(orig, error_type, condition, error_message) |
448 local t = reply(orig); | 448 local t = reply(orig); |
449 t.attr.type = "error"; | 449 t.attr.type = "error"; |
450 t:tag("error", {type = error_type}) --COMPAT: Some day xmlns:stanzas goes here | 450 t:tag("error", {type = error_type}) --COMPAT: Some day xmlns:stanzas goes here |
451 :tag(condition, xmpp_stanzas_attr):up(); | 451 :tag(condition, xmpp_stanzas_attr):up(); |
452 if error_message then t:tag("text", xmpp_stanzas_attr):text(error_message):up(); end | 452 if error_message then t:text_tag("text", error_message, xmpp_stanzas_attr); end |
453 return t; -- stanza ready for adding app-specific errors | 453 return t; -- stanza ready for adding app-specific errors |
454 end | 454 end |
455 | 455 |
456 local function presence(attr) | 456 local function presence(attr) |
457 return new_stanza("presence", attr); | 457 return new_stanza("presence", attr); |