diff options
author | Marvin W <git@larma.de> | 2018-01-12 21:03:09 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2018-01-28 00:38:47 +0100 |
commit | 782ae4c049e2b6fab13d7453cbb0e74610e7d200 (patch) | |
tree | 1b4cd0a1689cee0c2e2cac2ae9a5fb8ebbe63621 /xmpp-vala/src/module/stanza.vala | |
parent | d46d071e57e599e8cfb1780597cbecb36881c4d8 (diff) | |
download | dino-782ae4c049e2b6fab13d7453cbb0e74610e7d200.tar.gz dino-782ae4c049e2b6fab13d7453cbb0e74610e7d200.zip |
Move Jid class to xmpp-vala, partially refactor namespace
Diffstat (limited to 'xmpp-vala/src/module/stanza.vala')
-rw-r--r-- | xmpp-vala/src/module/stanza.vala | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/xmpp-vala/src/module/stanza.vala b/xmpp-vala/src/module/stanza.vala index 2bf3e29b..abdc33e9 100644 --- a/xmpp-vala/src/module/stanza.vala +++ b/xmpp-vala/src/module/stanza.vala @@ -1,70 +1,70 @@ -using Xmpp.Core; - namespace Xmpp { - public class Stanza : Object { +public class Stanza : Object { - public const string ATTRIBUTE_FROM = "from"; - public const string ATTRIBUTE_ID = "id"; - public const string ATTRIBUTE_TO = "to"; - public const string ATTRIBUTE_TYPE = "type"; + public const string ATTRIBUTE_FROM = "from"; + public const string ATTRIBUTE_ID = "id"; + public const string ATTRIBUTE_TO = "to"; + public const string ATTRIBUTE_TYPE = "type"; - public const string TYPE_ERROR = "error"; + public const string TYPE_ERROR = "error"; - private string? my_jid; + private Jid? my_jid; + private Jid? from_; + private Jid? to_; - public virtual string? from { - owned get { - string? from_attribute = stanza.get_attribute(ATTRIBUTE_FROM); - // "when a client receives a stanza that does not include a 'from' attribute, it MUST assume that the stanza - // is from the user's account on the server." (RFC6120 8.1.2.1) - if (from_attribute != null) return from_attribute; - if (my_jid != null) { - string my_bare_jid = get_bare_jid(my_jid); // has to be left-side value - return my_bare_jid; - } - return null; + public virtual Jid? from { + owned get { + string? from_attribute = stanza.get_attribute(ATTRIBUTE_FROM); + // "when a client receives a stanza that does not include a 'from' attribute, it MUST assume that the stanza + // is from the user's account on the server." (RFC6120 8.1.2.1) + if (from_attribute != null) return from_ = Jid.parse(from_attribute); + if (my_jid != null) { + return my_jid.bare_jid; } - set { stanza.set_attribute(ATTRIBUTE_FROM, value); } + return null; } + set { stanza.set_attribute(ATTRIBUTE_FROM, value.to_string()); } + } - public virtual string? id { - get { return stanza.get_attribute(ATTRIBUTE_ID); } - set { stanza.set_attribute(ATTRIBUTE_ID, value); } - } + public virtual string? id { + get { return stanza.get_attribute(ATTRIBUTE_ID); } + set { stanza.set_attribute(ATTRIBUTE_ID, value); } + } - public virtual string? to { - owned get { - string? to_attribute = stanza.get_attribute(ATTRIBUTE_TO); - // "if the stanza does not include a 'to' address then the client MUST treat it as if the 'to' address were - // included with a value of the client's full JID." (RFC6120 8.1.1.1) - return to_attribute == null ? my_jid : to_attribute; - } - set { stanza.set_attribute(ATTRIBUTE_TO, value); } + public virtual Jid? to { + owned get { + string? to_attribute = stanza.get_attribute(ATTRIBUTE_TO); + // "if the stanza does not include a 'to' address then the client MUST treat it as if the 'to' address were + // included with a value of the client's full JID." (RFC6120 8.1.1.1) + return to_attribute == null ? my_jid : to_ = Jid.parse(to_attribute); } + set { stanza.set_attribute(ATTRIBUTE_TO, value.to_string()); } + } - public virtual string? type_ { - get { return stanza.get_attribute(ATTRIBUTE_TYPE); } - set { stanza.set_attribute(ATTRIBUTE_TYPE, value); } - } + public virtual string? type_ { + get { return stanza.get_attribute(ATTRIBUTE_TYPE); } + set { stanza.set_attribute(ATTRIBUTE_TYPE, value); } + } - public StanzaNode stanza; + public StanzaNode stanza; - public Stanza.incoming(StanzaNode stanza, string? my_jid) { - this.stanza = stanza; - this.my_jid = my_jid; - } + public Stanza.incoming(StanzaNode stanza, Jid? my_jid) { + this.stanza = stanza; + this.my_jid = my_jid; + } - public Stanza.outgoing(StanzaNode stanza) { - this.stanza = stanza; - } + public Stanza.outgoing(StanzaNode stanza) { + this.stanza = stanza; + } - public bool is_error() { - return type_ == TYPE_ERROR; - } + public bool is_error() { + return type_ == TYPE_ERROR; + } - public ErrorStanza? get_error() { - return new ErrorStanza.from_stanza(this.stanza); - } + public ErrorStanza? get_error() { + return new ErrorStanza.from_stanza(this.stanza); } +} + }
\ No newline at end of file |