46 lines
1.7 KiB
GDScript3
46 lines
1.7 KiB
GDScript3
|
extends Node
|
||
|
class_name Stanza
|
||
|
|
||
|
const disco_info_queury := "<query xmlns='http://jabber.org/protocol/disco#info'/>"
|
||
|
const disco_items_queury := "<query xmlns='http://jabber.org/protocol/disco#items'/>"
|
||
|
|
||
|
static func yield_as_is():
|
||
|
return yield()
|
||
|
|
||
|
static func unwrap_query_result(iq: Xml.XmlElement) -> Sums.Result:
|
||
|
if iq == null or iq.name != "iq" or not "type" in iq.attributes:
|
||
|
return Sums.Result.make_error(ERR_INVALID_DATA)
|
||
|
|
||
|
# todo: Delegate strctured XMPP error.
|
||
|
if iq.attributes["type"] != "result":
|
||
|
return Sums.Result.make_error(ERR_INVALID_DATA)
|
||
|
|
||
|
for child in iq.children:
|
||
|
if child.is_element() and child.name == "query":
|
||
|
return Sums.Result.make_value(child)
|
||
|
|
||
|
return Sums.Result.make_error(ERR_INVALID_DATA)
|
||
|
|
||
|
static func form_presence(id: String, from: String, to: String, type, payload: String) -> String:
|
||
|
if type != null:
|
||
|
return """<presence from='{from}' id='{id}' to='{to}' type='{type}'>{payload}</presence>""".format({
|
||
|
"from": from.xml_escape(),
|
||
|
"id": id.xml_escape(),
|
||
|
"to": to.xml_escape(),
|
||
|
"type": type,
|
||
|
"payload": payload
|
||
|
})
|
||
|
else:
|
||
|
return """<presence from='{from}' id='{id}' to='{to}'>{payload}</presence>""".format({
|
||
|
"from": from.xml_escape(),
|
||
|
"id": id.xml_escape(),
|
||
|
"to": to.xml_escape(),
|
||
|
"payload": payload
|
||
|
})
|
||
|
|
||
|
static func presence_result(stanza: Xml.XmlElement) -> Sums.Result:
|
||
|
if "type" in stanza.attributes and stanza.attributes["type"] == "error":
|
||
|
return Sums.Result.make_error(stanza)
|
||
|
else:
|
||
|
return Sums.Result.make_value(stanza)
|