Thu, 23 Mar 2023 18:56:32 +0000
component: Avoid adding to the global stream metatable
This allows component and client connections to be made side-by-side.
Previous to this change, loading this connection module would break the
ability to make client connections, due to overriding stream methods such as
:reopen() and :reset().
A next step would be to share the methods that the two connection modules have
in common.
6
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | local stanza_mt = getmetatable(require "util.stanza".stanza()); |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | |
15
be4154ed4e3a
util.xstanza: Fix and rename error_from_stanza() -> get_error()
Matthew Wild <mwild1@gmail.com>
parents:
6
diff
changeset
|
3 | local xmlns_stanzas = "urn:ietf:params:xml:ns:xmpp-stanzas"; |
be4154ed4e3a
util.xstanza: Fix and rename error_from_stanza() -> get_error()
Matthew Wild <mwild1@gmail.com>
parents:
6
diff
changeset
|
4 | |
be4154ed4e3a
util.xstanza: Fix and rename error_from_stanza() -> get_error()
Matthew Wild <mwild1@gmail.com>
parents:
6
diff
changeset
|
5 | function stanza_mt:get_error() |
6
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | local type, condition, text; |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | |
15
be4154ed4e3a
util.xstanza: Fix and rename error_from_stanza() -> get_error()
Matthew Wild <mwild1@gmail.com>
parents:
6
diff
changeset
|
8 | local error_tag = self:get_child("error"); |
6
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | if not error_tag then |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | return nil, nil; |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | end |
15
be4154ed4e3a
util.xstanza: Fix and rename error_from_stanza() -> get_error()
Matthew Wild <mwild1@gmail.com>
parents:
6
diff
changeset
|
12 | type = error_tag.attr.type; |
6
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | for child in error_tag:children() do |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | if child.attr.xmlns == xmlns_stanzas then |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | if child.name == "text" then |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | text = child:get_text(); |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | else |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | condition = child.name; |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | end |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | if condition and text then |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | break; |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | end |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | end |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | end |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | return type, condition, text; |
f8e0ab90d84e
util.xstanza: New library to extend util.stanza with XMPP-specific helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | end |