| 1 |
using Gee; |
| 2 |
|
| 3 |
namespace Xmpp.Xep.InBandRegistration { |
| 4 |
|
| 5 |
public const string NS_URI = "jabber:iq:register"; |
| 6 |
|
| 7 |
public class Module : XmppStreamNegotiationModule { |
| 8 |
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0077_in_band_registration"); |
| 9 |
|
| 10 |
public async Form? get_from_server(XmppStream stream, Jid jid) { |
| 11 |
StanzaNode query_node = new StanzaNode.build("query", NS_URI).add_self_xmlns(); |
| 12 |
Iq.Stanza request_form_iq = new Iq.Stanza.get(query_node) { to=jid }; |
| 13 |
request_form_iq.to = jid; |
| 14 |
|
| 15 |
Iq.Stanza iq_result = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, request_form_iq); |
| 16 |
return new Form.from_node(stream, iq_result); |
| 17 |
} |
| 18 |
|
| 19 |
public async string? submit_to_server(XmppStream stream, Jid jid, Form form) { |
| 20 |
StanzaNode query_node = new StanzaNode.build("query", NS_URI).add_self_xmlns(); |
| 21 |
query_node.put_node(form.get_submit_node()); |
| 22 |
Iq.Stanza iq = new Iq.Stanza.set(query_node) { to=jid }; |
| 23 |
|
| 24 |
Iq.Stanza iq_result = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); |
| 25 |
if (iq_result.is_error()) { |
| 26 |
ErrorStanza? error_stanza = iq_result.get_error(); |
| 27 |
return error_stanza.text ?? "Error"; |
| 28 |
} |
| 29 |
|
| 30 |
return null; |
| 31 |
} |
| 32 |
|
| 33 |
public async ErrorStanza? change_password(XmppStream stream, Jid jid, string new_pw) { |
| 34 |
StanzaNode pw_change_node = new StanzaNode.build("query", NS_URI).add_self_xmlns(); |
| 35 |
StanzaNode username_node = new StanzaNode.build("username", NS_URI); |
| 36 |
StanzaNode pw_node = new StanzaNode.build("password", NS_URI); |
| 37 |
username_node.put_node(new StanzaNode.text(jid.localpart)); |
| 38 |
pw_node.put_node(new StanzaNode.text(new_pw)); |
| 39 |
pw_change_node.put_node(username_node); |
| 40 |
pw_change_node.put_node(pw_node); |
| 41 |
Iq.Stanza set_password_iq = new Iq.Stanza.set(pw_change_node) { to=jid.bare_jid.domain_jid }; |
| 42 |
|
| 43 |
Iq.Stanza chpw_result = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, set_password_iq); |
| 44 |
if (chpw_result.is_error()) { |
| 45 |
return chpw_result.get_error(); |
| 46 |
} |
| 47 |
|
| 48 |
return null; |
| 49 |
} |
| 50 |
|
| 51 |
public override bool mandatory_outstanding(XmppStream stream) { return false; } |
| 52 |
|
| 53 |
public override bool negotiation_active(XmppStream stream) { return false; } |
| 54 |
|
| 55 |
public override void attach(XmppStream stream) { } |
| 56 |
|
| 57 |
public override void detach(XmppStream stream) { } |
| 58 |
|
| 59 |
public override string get_ns() { return NS_URI; } |
| 60 |
public override string get_id() { return IDENTITY.id; } |
| 61 |
} |
| 62 |
|
| 63 |
public class Form : DataForms.DataForm { |
| 64 |
public string? oob = null; |
| 65 |
|
| 66 |
internal Form.from_node(XmppStream stream, Iq.Stanza iq) { |
| 67 |
StanzaNode? x_node = iq.stanza.get_deep_subnode(NS_URI + ":query", DataForms.NS_URI + ":x"); |
| 68 |
base.from_node(x_node ?? new StanzaNode.build("x", NS_URI).add_self_xmlns()); |
| 69 |
|
| 70 |
oob = iq.stanza.get_deep_string_content(NS_URI + ":query", "jabber:x:oob:x", "url"); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
} |