xmpp-vala/core+libdino: concurrency + nullity improvements
This commit is contained in:
parent
765c2605cd
commit
f95b4f4e09
|
@ -3,7 +3,7 @@ public class Dino.Entities.Jid : Object {
|
||||||
public string domainpart { get; set; }
|
public string domainpart { get; set; }
|
||||||
public string? resourcepart { get; set; }
|
public string? resourcepart { get; set; }
|
||||||
|
|
||||||
public Jid? bare_jid {
|
public Jid bare_jid {
|
||||||
owned get { return localpart != null ? new Jid(@"$localpart@$domainpart") : new Jid(domainpart); }
|
owned get { return localpart != null ? new Jid(@"$localpart@$domainpart") : new Jid(domainpart); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,13 +47,17 @@ public class AvatarManager : StreamInteractionModule, Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pixbuf? get_avatar_by_hash(string hash) {
|
private Pixbuf? get_avatar_by_hash(string hash) {
|
||||||
|
lock (cached_pixbuf) {
|
||||||
if (cached_pixbuf.has_key(hash)) {
|
if (cached_pixbuf.has_key(hash)) {
|
||||||
return cached_pixbuf[hash];
|
return cached_pixbuf[hash];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Pixbuf? image = avatar_storage.get_image(hash);
|
Pixbuf? image = avatar_storage.get_image(hash);
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
|
lock (cached_pixbuf) {
|
||||||
cached_pixbuf[hash] = image;
|
cached_pixbuf[hash] = image;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,14 +66,18 @@ public class AvatarManager : StreamInteractionModule, Object {
|
||||||
if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
|
if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
|
||||||
jid_ = jid.bare_jid;
|
jid_ = jid.bare_jid;
|
||||||
}
|
}
|
||||||
|
lock(user_avatars) {
|
||||||
string? user_avatars_id = user_avatars[jid_];
|
string? user_avatars_id = user_avatars[jid_];
|
||||||
if (user_avatars_id != null) {
|
if (user_avatars_id != null) {
|
||||||
return get_avatar_by_hash(user_avatars_id);
|
return get_avatar_by_hash(user_avatars_id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
lock(vcard_avatars) {
|
||||||
string? vcard_avatars_id = vcard_avatars[jid_];
|
string? vcard_avatars_id = vcard_avatars[jid_];
|
||||||
if (vcard_avatars_id != null) {
|
if (vcard_avatars_id != null) {
|
||||||
return get_avatar_by_hash(vcard_avatars_id);
|
return get_avatar_by_hash(vcard_avatars_id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,21 +111,27 @@ public class AvatarManager : StreamInteractionModule, Object {
|
||||||
on_vcard_avatar_received(account, new Jid(jid), id)
|
on_vcard_avatar_received(account, new Jid(jid), id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
lock (user_avatars) {
|
||||||
user_avatars = db.get_avatar_hashes(Source.USER_AVATARS);
|
user_avatars = db.get_avatar_hashes(Source.USER_AVATARS);
|
||||||
foreach (Jid jid in user_avatars.keys) {
|
foreach (Jid jid in user_avatars.keys) {
|
||||||
on_user_avatar_received(account, jid, user_avatars[jid]);
|
on_user_avatar_received(account, jid, user_avatars[jid]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
lock (vcard_avatars) {
|
||||||
vcard_avatars = db.get_avatar_hashes(Source.VCARD);
|
vcard_avatars = db.get_avatar_hashes(Source.VCARD);
|
||||||
foreach (Jid jid in vcard_avatars.keys) {
|
foreach (Jid jid in vcard_avatars.keys) {
|
||||||
on_vcard_avatar_received(account, jid, vcard_avatars[jid]);
|
on_vcard_avatar_received(account, jid, vcard_avatars[jid]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void on_user_avatar_received(Account account, Jid jid, string id) {
|
private void on_user_avatar_received(Account account, Jid jid, string id) {
|
||||||
|
lock (user_avatars) {
|
||||||
if (!user_avatars.has_key(jid) || user_avatars[jid] != id) {
|
if (!user_avatars.has_key(jid) || user_avatars[jid] != id) {
|
||||||
user_avatars[jid] = id;
|
user_avatars[jid] = id;
|
||||||
db.set_avatar_hash(jid, id, Source.USER_AVATARS);
|
db.set_avatar_hash(jid, id, Source.USER_AVATARS);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Pixbuf? avatar = avatar_storage.get_image(id);
|
Pixbuf? avatar = avatar_storage.get_image(id);
|
||||||
if (avatar != null) {
|
if (avatar != null) {
|
||||||
received_avatar(avatar, jid, account);
|
received_avatar(avatar, jid, account);
|
||||||
|
@ -125,12 +139,14 @@ public class AvatarManager : StreamInteractionModule, Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_vcard_avatar_received(Account account, Jid jid, string id) {
|
private void on_vcard_avatar_received(Account account, Jid jid, string id) {
|
||||||
|
lock (vcard_avatars) {
|
||||||
if (!vcard_avatars.has_key(jid) || vcard_avatars[jid] != id) {
|
if (!vcard_avatars.has_key(jid) || vcard_avatars[jid] != id) {
|
||||||
vcard_avatars[jid] = id;
|
vcard_avatars[jid] = id;
|
||||||
if (!jid.is_full()) { // don't save muc avatars
|
if (!jid.is_full()) { // don't save muc avatars
|
||||||
db.set_avatar_hash(jid, id, Source.VCARD);
|
db.set_avatar_hash(jid, id, Source.VCARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Pixbuf? avatar = avatar_storage.get_image(id);
|
Pixbuf? avatar = avatar_storage.get_image(id);
|
||||||
if (avatar != null) {
|
if (avatar != null) {
|
||||||
received_avatar(avatar, jid, account);
|
received_avatar(avatar, jid, account);
|
||||||
|
|
|
@ -161,9 +161,8 @@ public class MucManager : StreamInteractionModule, Object {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_stream_negotiated(Account account) {
|
private void on_stream_negotiated(Account account, Core.XmppStream stream) {
|
||||||
Core.XmppStream stream = stream_interactor.get_stream(account);
|
stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, o) => {
|
||||||
if (stream != null) stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, o) => {
|
|
||||||
Tuple<MucManager, Account> tuple = o as Tuple<MucManager, Account>;
|
Tuple<MucManager, Account> tuple = o as Tuple<MucManager, Account>;
|
||||||
MucManager outer_ = tuple.a;
|
MucManager outer_ = tuple.a;
|
||||||
Account account_ = tuple.b;
|
Account account_ = tuple.b;
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class StreamInteractor {
|
||||||
|
|
||||||
public signal void account_added(Account account);
|
public signal void account_added(Account account);
|
||||||
public signal void account_removed(Account account);
|
public signal void account_removed(Account account);
|
||||||
public signal void stream_negotiated(Account account);
|
public signal void stream_negotiated(Account account, Core.XmppStream stream);
|
||||||
|
|
||||||
public ModuleManager module_manager;
|
public ModuleManager module_manager;
|
||||||
public ConnectionManager connection_manager;
|
public ConnectionManager connection_manager;
|
||||||
|
@ -59,7 +59,7 @@ public class StreamInteractor {
|
||||||
|
|
||||||
private void on_stream_opened(Account account, Core.XmppStream stream) {
|
private void on_stream_opened(Account account, Core.XmppStream stream) {
|
||||||
stream.stream_negotiated.connect( (stream) => {
|
stream.stream_negotiated.connect( (stream) => {
|
||||||
stream_negotiated(account);
|
stream_negotiated(account, stream);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,18 @@
|
||||||
namespace Xmpp.Core {
|
namespace Xmpp.Core {
|
||||||
|
|
||||||
public class StanzaAttribute : StanzaEntry {
|
public class StanzaAttribute : StanzaEntry {
|
||||||
|
|
||||||
public StanzaAttribute() {}
|
internal const string ATTRIBUTE_STRING_FORMAT = "{%s}:%s='%s'";
|
||||||
|
internal const string ATTRIBUTE_STRING_NO_NS_FORMAT = "%s='%s'";
|
||||||
|
internal const string ATTRIBUTE_STRING_ANSI_FORMAT = ANSI_COLOR_GRAY+"{%s}:"+ANSI_COLOR_END+"%s="+ANSI_COLOR_GREEN+"'%s'"+ANSI_COLOR_END;
|
||||||
|
internal const string ATTRIBUTE_STRING_ANSI_NO_NS_FORMAT = "%s="+ANSI_COLOR_GREEN+"'%s'"+ANSI_COLOR_END;
|
||||||
|
internal const string ATTRIBUTE_XML_FORMAT = "%s:%s='%s'";
|
||||||
|
internal const string ATTRIBUTE_XML_NO_NS_FORMAT = "%s='%s'";
|
||||||
|
internal const string ATTRIBUTE_XML_ANSI_FORMAT = "%s:%s="+ANSI_COLOR_GREEN+"'%s'"+ANSI_COLOR_END;
|
||||||
|
internal const string ATTRIBUTE_XML_ANSI_NO_NS_FORMAT = "%s="+ANSI_COLOR_GREEN+"'%s'"+ANSI_COLOR_END;
|
||||||
|
|
||||||
|
internal StanzaAttribute() {
|
||||||
|
}
|
||||||
|
|
||||||
public StanzaAttribute.build(string ns_uri, string name, string val) {
|
public StanzaAttribute.build(string ns_uri, string name, string val) {
|
||||||
this.ns_uri = ns_uri;
|
this.ns_uri = ns_uri;
|
||||||
|
@ -9,29 +20,47 @@ public class StanzaAttribute : StanzaEntry {
|
||||||
this.val = val;
|
this.val = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string to_string() {
|
internal string printf(string fmt, bool no_ns = false, string? ns_name = null) {
|
||||||
if (ns_uri == null) {
|
if (no_ns) {
|
||||||
return @"$name='$val'";
|
return fmt.printf(name, (!)val);
|
||||||
} else {
|
} else {
|
||||||
return @"{$ns_uri}:$name='$val'";
|
if (ns_name == null) {
|
||||||
|
return fmt.printf((!)ns_uri, name, (!)val);
|
||||||
|
} else {
|
||||||
|
return fmt.printf((!)ns_name, name, (!)val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string to_string() {
|
||||||
|
return printf(ATTRIBUTE_STRING_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
public string to_ansi_string(bool hide_ns = false) {
|
public string to_ansi_string(bool hide_ns = false) {
|
||||||
if (ns_uri == null || hide_ns) {
|
if (hide_ns) {
|
||||||
return @"$name=$ANSI_COLOR_GREEN'$val'$ANSI_COLOR_END";
|
return printf(ATTRIBUTE_STRING_ANSI_NO_NS_FORMAT, true);
|
||||||
} else {
|
} else {
|
||||||
return @"$ANSI_COLOR_GRAY{$ns_uri}:$ANSI_COLOR_END$name=$ANSI_COLOR_GREEN'$val'$ANSI_COLOR_END";
|
return printf(ATTRIBUTE_STRING_ANSI_FORMAT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string to_xml(NamespaceState? state_) throws XmlError {
|
public string to_xml(NamespaceState? state_ = null) throws XmlError {
|
||||||
NamespaceState state = state_ ?? new NamespaceState();
|
NamespaceState state = state_ ?? new NamespaceState();
|
||||||
if (ns_uri == state.current_ns_uri || (ns_uri == XMLNS_URI && name == "xmlns")) {
|
if (ns_uri == state.current_ns_uri || (ns_uri == XMLNS_URI && name == "xmlns")) {
|
||||||
return @"$name='$val'";
|
return printf(ATTRIBUTE_XML_NO_NS_FORMAT, true);
|
||||||
} else {
|
} else {
|
||||||
return "%s:%s='%s'".printf (state.find_name (ns_uri), name, val);
|
return printf(ATTRIBUTE_XML_FORMAT, false, state.find_name((!)ns_uri));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string to_ansi_xml(NamespaceState? state_ = null) throws XmlError {
|
||||||
|
NamespaceState state = state_ ?? new NamespaceState();
|
||||||
|
if (ns_uri == state.current_ns_uri || (ns_uri == XMLNS_URI && name == "xmlns")) {
|
||||||
|
return printf(ATTRIBUTE_XML_ANSI_NO_NS_FORMAT, true);
|
||||||
|
} else {
|
||||||
|
return printf(ATTRIBUTE_XML_ANSI_FORMAT, false, state.find_name((!)ns_uri));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,17 @@ public abstract class StanzaEntry {
|
||||||
public string name;
|
public string name;
|
||||||
public string? val;
|
public string? val;
|
||||||
|
|
||||||
public string encoded_val {
|
public string? encoded_val {
|
||||||
owned get {
|
owned get {
|
||||||
return val != null ? val.replace("&", "&").replace("\"", """).replace("'", "'").replace("<", "<").replace(">", ">") : null;
|
if (val == null) return null;
|
||||||
|
return ((!)val).replace("&", "&").replace("\"", """).replace("'", "'").replace("<", "<").replace(">", ">");
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
string tmp = value.replace(">", ">").replace("<", "<").replace("'","'").replace(""","\"");
|
if (value == null) {
|
||||||
|
val = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string tmp = ((!)value).replace(">", ">").replace("<", "<").replace("'","'").replace(""","\"");
|
||||||
while (tmp.contains("&#")) {
|
while (tmp.contains("&#")) {
|
||||||
int start = tmp.index_of("&#");
|
int start = tmp.index_of("&#");
|
||||||
int end = tmp.index_of(";", start);
|
int end = tmp.index_of(";", start);
|
||||||
|
@ -39,26 +44,20 @@ public abstract class StanzaEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NoStanza : StanzaEntry {
|
|
||||||
public NoStanza(string? name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class StanzaNode : StanzaEntry {
|
public class StanzaNode : StanzaEntry {
|
||||||
public ArrayList<StanzaNode> sub_nodes = new ArrayList<StanzaNode>();
|
public ArrayList<StanzaNode> sub_nodes = new ArrayList<StanzaNode>();
|
||||||
public ArrayList<StanzaAttribute> attributes = new ArrayList<StanzaAttribute>();
|
public ArrayList<StanzaAttribute> attributes = new ArrayList<StanzaAttribute>();
|
||||||
public bool has_nodes = false;
|
public bool has_nodes = false;
|
||||||
public bool pseudo = false;
|
public bool pseudo = false;
|
||||||
|
|
||||||
public StanzaNode() {
|
internal StanzaNode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public StanzaNode.build(string name, string ns_uri = "jabber:client", ArrayList<StanzaNode>? nodes = null, ArrayList<StanzaAttribute>? attrs = null) {
|
public StanzaNode.build(string name, string ns_uri = "jabber:client", ArrayList<StanzaNode>? nodes = null, ArrayList<StanzaAttribute>? attrs = null) {
|
||||||
this.ns_uri = ns_uri;
|
this.ns_uri = ns_uri;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
if (nodes != null) this.sub_nodes.add_all(nodes);
|
if (nodes != null) this.sub_nodes.add_all((!)nodes);
|
||||||
if (attrs != null) this.attributes.add_all(attrs);
|
if (attrs != null) this.attributes.add_all((!)attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StanzaNode.text(string text) {
|
public StanzaNode.text(string text) {
|
||||||
|
@ -72,7 +71,8 @@ public class StanzaNode : StanzaEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public StanzaNode add_self_xmlns() {
|
public StanzaNode add_self_xmlns() {
|
||||||
return put_attribute("xmlns", ns_uri);
|
if (ns_uri == null) return this;
|
||||||
|
return put_attribute("xmlns", (!)ns_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public unowned string? get_attribute(string name, string? ns_uri = null) {
|
public unowned string? get_attribute(string name, string? ns_uri = null) {
|
||||||
|
@ -88,7 +88,7 @@ public class StanzaNode : StanzaEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (var attr in attributes) {
|
foreach (var attr in attributes) {
|
||||||
if (attr.ns_uri == _ns_uri && attr.name == _name) return attr.val;
|
if (attr.ns_uri == (!)_ns_uri && attr.name == _name) return attr.val;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -96,19 +96,19 @@ public class StanzaNode : StanzaEntry {
|
||||||
public int get_attribute_int(string name, int def = -1, string? ns_uri = null) {
|
public int get_attribute_int(string name, int def = -1, string? ns_uri = null) {
|
||||||
string? res = get_attribute(name, ns_uri);
|
string? res = get_attribute(name, ns_uri);
|
||||||
if (res == null) return def;
|
if (res == null) return def;
|
||||||
return int.parse(res);
|
return int.parse((!)res);
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint get_attribute_uint(string name, uint def = 0, string? ns_uri = null) {
|
public uint get_attribute_uint(string name, uint def = 0, string? ns_uri = null) {
|
||||||
string? res = get_attribute(name, ns_uri);
|
string? res = get_attribute(name, ns_uri);
|
||||||
if (res == null) return def;
|
if (res == null) return def;
|
||||||
return (uint) long.parse(res);
|
return (uint) long.parse((!)res);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool get_attribute_bool(string name, bool def = false, string? ns_uri = null) {
|
public bool get_attribute_bool(string name, bool def = false, string? ns_uri = null) {
|
||||||
string? res = get_attribute(name, ns_uri);
|
string? res = get_attribute(name, ns_uri);
|
||||||
if (res == null) return def;
|
if (res == null) return def;
|
||||||
return res.down() == "true" || res == "1";
|
return ((!)res).down() == "true" || res == "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
public StanzaAttribute? get_attribute_raw(string name, string? ns_uri = null) {
|
public StanzaAttribute? get_attribute_raw(string name, string? ns_uri = null) {
|
||||||
|
@ -137,34 +137,26 @@ public class StanzaNode : StanzaEntry {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StanzaEntry get(...) {
|
|
||||||
va_list l = va_list();
|
|
||||||
StanzaEntry? res = get_deep_attribute_(va_list.copy(l));
|
|
||||||
if (res != null) return res;
|
|
||||||
res = get_deep_subnode_(va_list.copy(l));
|
|
||||||
if (res != null) return res;
|
|
||||||
return new NoStanza("-");
|
|
||||||
}
|
|
||||||
|
|
||||||
public unowned string? get_deep_attribute(...) {
|
public unowned string? get_deep_attribute(...) {
|
||||||
va_list l = va_list();
|
va_list l = va_list();
|
||||||
var res = get_deep_attribute_(va_list.copy(l));
|
StanzaAttribute? res = get_deep_attribute_(va_list.copy(l));
|
||||||
if (res == null) return null;
|
if (res == null) return null;
|
||||||
return res.val;
|
return ((!)res).val;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StanzaAttribute? get_deep_attribute_(va_list l) {
|
public StanzaAttribute? get_deep_attribute_(va_list l) {
|
||||||
StanzaNode? node = this;
|
StanzaNode node = this;
|
||||||
string? attribute_name = l.arg();
|
string? attribute_name = l.arg();
|
||||||
if (attribute_name == null) return null;
|
if (attribute_name == null) return null;
|
||||||
while (true) {
|
while (true) {
|
||||||
string? s = l.arg();
|
string? s = l.arg();
|
||||||
if (s == null) break;
|
if (s == null) break;
|
||||||
node = node.get_subnode(attribute_name);
|
StanzaNode? node_tmp = node.get_subnode((!)attribute_name);
|
||||||
if (node == null) return null;
|
if (node_tmp == null) return null;
|
||||||
|
node = (!)node_tmp;
|
||||||
attribute_name = s;
|
attribute_name = s;
|
||||||
}
|
}
|
||||||
return node.get_attribute_raw(attribute_name);
|
return node.get_attribute_raw((!)attribute_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StanzaNode? get_subnode(string name, string? ns_uri = null, bool recurse = false) {
|
public StanzaNode? get_subnode(string name, string? ns_uri = null, bool recurse = false) {
|
||||||
|
@ -217,35 +209,35 @@ public class StanzaNode : StanzaEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public StanzaNode? get_deep_subnode_(va_list l) {
|
public StanzaNode? get_deep_subnode_(va_list l) {
|
||||||
StanzaNode? node = this;
|
StanzaNode node = this;
|
||||||
while (true) {
|
while (true) {
|
||||||
string? s = l.arg();
|
string? s = l.arg();
|
||||||
if (s == null) break;
|
if (s == null) break;
|
||||||
node = node.get_subnode(s);
|
StanzaNode? node_tmp = node.get_subnode((!)s);
|
||||||
if (node == null) return null;
|
if (node_tmp == null) return null;
|
||||||
|
node = (!)node_tmp;
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<StanzaNode> get_deep_subnodes(...) {
|
public ArrayList<StanzaNode> get_deep_subnodes(...) {
|
||||||
va_list l = va_list();
|
va_list l = va_list();
|
||||||
var res = get_deep_subnodes_(va_list.copy(l));
|
return get_deep_subnodes_(va_list.copy(l));
|
||||||
if (res != null) return res;
|
|
||||||
return new ArrayList<StanzaNode>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<StanzaNode> get_deep_subnodes_(va_list l) {
|
public ArrayList<StanzaNode> get_deep_subnodes_(va_list l) {
|
||||||
StanzaNode? node = this;
|
StanzaNode node = this;
|
||||||
string? subnode_name = l.arg();
|
string? subnode_name = l.arg();
|
||||||
if (subnode_name == null) return new ArrayList<StanzaNode>();
|
if (subnode_name == null) return new ArrayList<StanzaNode>();
|
||||||
while (true) {
|
while (true) {
|
||||||
string? s = l.arg();
|
string? s = l.arg();
|
||||||
if (s == null) break;
|
if (s == null) break;
|
||||||
node = node.get_subnode(subnode_name);
|
StanzaNode? node_tmp = node.get_subnode((!)subnode_name);
|
||||||
if (node == null) return new ArrayList<StanzaNode>();
|
if (node_tmp == null) return new ArrayList<StanzaNode>();
|
||||||
|
node = (!)node_tmp;
|
||||||
subnode_name = s;
|
subnode_name = s;
|
||||||
}
|
}
|
||||||
return node.get_subnodes(subnode_name);
|
return node.get_subnodes((!)subnode_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<StanzaNode> get_all_subnodes() {
|
public ArrayList<StanzaNode> get_all_subnodes() {
|
||||||
|
@ -255,7 +247,7 @@ public class StanzaNode : StanzaEntry {
|
||||||
public ArrayList<StanzaNode> get_deep_all_subnodes(...) {
|
public ArrayList<StanzaNode> get_deep_all_subnodes(...) {
|
||||||
va_list l = va_list();
|
va_list l = va_list();
|
||||||
StanzaNode? node = get_deep_subnode_(va_list.copy(l));
|
StanzaNode? node = get_deep_subnode_(va_list.copy(l));
|
||||||
if (node != null) return node.get_all_subnodes();
|
if (node != null) return ((!)node).get_all_subnodes();
|
||||||
return new ArrayList<StanzaNode>();
|
return new ArrayList<StanzaNode>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,14 +264,16 @@ public class StanzaNode : StanzaEntry {
|
||||||
public unowned string? get_deep_string_content(...) {
|
public unowned string? get_deep_string_content(...) {
|
||||||
va_list l = va_list();
|
va_list l = va_list();
|
||||||
StanzaNode? node = get_deep_subnode_(va_list.copy(l));
|
StanzaNode? node = get_deep_subnode_(va_list.copy(l));
|
||||||
if (node != null) return node.get_string_content();
|
if (node != null) return ((!)node).get_string_content();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StanzaNode put_attribute(string name, string val, string? ns_uri = null) {
|
public StanzaNode put_attribute(string name, string val, string? ns_uri = null) {
|
||||||
if (name == "xmlns") ns_uri = XMLNS_URI;
|
string? _ns_uri = ns_uri;
|
||||||
if (ns_uri == null) ns_uri = this.ns_uri;
|
if (name == "xmlns") _ns_uri = XMLNS_URI;
|
||||||
attributes.add(new StanzaAttribute.build(ns_uri, name, val));
|
if (_ns_uri == null) _ns_uri = this.ns_uri;
|
||||||
|
if (_ns_uri == null) return this;
|
||||||
|
attributes.add(new StanzaAttribute.build((!)_ns_uri, name, val));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,75 +296,79 @@ public class StanzaNode : StanzaEntry {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string to_string(int i = 0) {
|
private const string TAG_START_BEGIN_FORMAT = "%s<{%s}:%s";
|
||||||
|
private const string TAG_START_EMPTY_END = " />\n";
|
||||||
|
private const string TAG_START_CONTENT_END = ">\n";
|
||||||
|
private const string TAG_END_FORMAT = "%s</{%s}:%s>\n";
|
||||||
|
private const string TAG_ANSI_START_BEGIN_FORMAT = "%s"+ANSI_COLOR_YELLOW+"<"+ANSI_COLOR_GRAY+"{%s}:"+ANSI_COLOR_YELLOW+"%s"+ANSI_COLOR_END;
|
||||||
|
private const string TAG_ANSI_START_BEGIN_NO_NS_FORMAT = "%s"+ANSI_COLOR_YELLOW+"<%s"+ANSI_COLOR_END;
|
||||||
|
private const string TAG_ANSI_START_EMPTY_END = ANSI_COLOR_YELLOW+" />"+ANSI_COLOR_END+"\n";
|
||||||
|
private const string TAG_ANSI_START_CONTENT_END = ANSI_COLOR_YELLOW+">"+ANSI_COLOR_END+"\n";
|
||||||
|
private const string TAG_ANSI_END_FORMAT = "%s"+ANSI_COLOR_YELLOW+"</"+ANSI_COLOR_GRAY+"{%s}:"+ANSI_COLOR_YELLOW+"%s>"+ANSI_COLOR_END+"\n";
|
||||||
|
private const string TAG_ANSI_END_NO_NS_FORMAT = "%s"+ANSI_COLOR_YELLOW+"</%s>"+ANSI_COLOR_END+"\n";
|
||||||
|
|
||||||
|
internal string printf(int i, string fmt_start_begin, string start_empty_end, string start_content_end, string fmt_end, string fmt_attr, bool no_ns = false) {
|
||||||
string indent = string.nfill (i * 2, ' ');
|
string indent = string.nfill (i * 2, ' ');
|
||||||
if (name == "#text") {
|
if (name == "#text") {
|
||||||
return @"$indent$val\n";
|
return indent + ((!)val).replace("\n", indent + "\n") + "\n";
|
||||||
}
|
}
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.append(@"$indent<{$ns_uri}:$name");
|
if (no_ns) {
|
||||||
|
sb.append_printf(fmt_start_begin, indent, name);
|
||||||
|
} else {
|
||||||
|
sb.append_printf(fmt_start_begin, indent, (!)ns_uri, name);
|
||||||
|
}
|
||||||
foreach (StanzaAttribute attr in attributes) {
|
foreach (StanzaAttribute attr in attributes) {
|
||||||
sb.append_printf(" %s", attr.to_string());
|
sb.append_printf(" %s", attr.printf(fmt_attr, no_ns));
|
||||||
}
|
}
|
||||||
if (!has_nodes && sub_nodes.size == 0) {
|
if (!has_nodes && sub_nodes.size == 0) {
|
||||||
sb.append(" />\n");
|
sb.append(start_empty_end);
|
||||||
} else {
|
} else {
|
||||||
sb.append(">\n");
|
sb.append(start_content_end);
|
||||||
if (sub_nodes.size != 0) {
|
if (sub_nodes.size != 0) {
|
||||||
foreach (StanzaNode subnode in sub_nodes) {
|
foreach (StanzaNode subnode in sub_nodes) {
|
||||||
sb.append(subnode.to_string(i+1));
|
sb.append(subnode.printf(i+1, fmt_start_begin, start_empty_end, start_content_end, fmt_end, fmt_attr, no_ns));
|
||||||
|
}
|
||||||
|
if (no_ns) {
|
||||||
|
sb.append_printf(fmt_end, indent, name);
|
||||||
|
} else {
|
||||||
|
sb.append_printf(fmt_end, indent, (!)ns_uri, name);
|
||||||
}
|
}
|
||||||
sb.append(@"$indent</{$ns_uri}:$name>\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sb.str;
|
return sb.str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string to_string(int i = 0) {
|
||||||
|
return printf(i, TAG_START_BEGIN_FORMAT, TAG_START_EMPTY_END, TAG_START_CONTENT_END, TAG_END_FORMAT, StanzaAttribute.ATTRIBUTE_STRING_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
public string to_ansi_string(bool hide_ns = false, int i = 0) {
|
public string to_ansi_string(bool hide_ns = false, int i = 0) {
|
||||||
string indent = string.nfill (i * 2, ' ');
|
if (hide_ns) {
|
||||||
if (name == "#text") {
|
return printf(i, TAG_ANSI_START_BEGIN_NO_NS_FORMAT, TAG_ANSI_START_EMPTY_END, TAG_ANSI_START_CONTENT_END, TAG_ANSI_END_NO_NS_FORMAT, StanzaAttribute.ATTRIBUTE_STRING_ANSI_NO_NS_FORMAT, true);
|
||||||
return @"$indent$val\n";
|
|
||||||
}
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.append(@"$indent$ANSI_COLOR_YELLOW<");
|
|
||||||
if (!hide_ns) sb.append(@"$ANSI_COLOR_GRAY{$ns_uri}:$ANSI_COLOR_YELLOW");
|
|
||||||
sb.append(@"$name$ANSI_COLOR_END");
|
|
||||||
foreach (StanzaAttribute attr in attributes) {
|
|
||||||
sb.append_printf(" %s", attr.to_ansi_string(hide_ns));
|
|
||||||
}
|
|
||||||
if (!has_nodes && sub_nodes.size == 0) {
|
|
||||||
sb.append(@" $ANSI_COLOR_YELLOW/>$ANSI_COLOR_END\n");
|
|
||||||
} else {
|
} else {
|
||||||
sb.append(@"$ANSI_COLOR_YELLOW>$ANSI_COLOR_END\n");
|
return printf(i, TAG_ANSI_START_BEGIN_FORMAT, TAG_ANSI_START_EMPTY_END, TAG_ANSI_START_CONTENT_END, TAG_ANSI_END_FORMAT, StanzaAttribute.ATTRIBUTE_STRING_ANSI_FORMAT);
|
||||||
if (sub_nodes.size != 0) {
|
|
||||||
foreach (StanzaNode subnode in sub_nodes) {
|
|
||||||
sb.append(subnode.to_ansi_string(hide_ns, i + 1));
|
|
||||||
}
|
}
|
||||||
sb.append(@"$indent$ANSI_COLOR_YELLOW</");
|
|
||||||
if (!hide_ns) sb.append(@"$ANSI_COLOR_GRAY{$ns_uri}:$ANSI_COLOR_YELLOW");
|
|
||||||
sb.append(@"$name>$ANSI_COLOR_END\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string to_xml(NamespaceState? state = null) throws XmlError {
|
public string to_xml(NamespaceState? state = null) throws XmlError {
|
||||||
NamespaceState my_state = state ?? new NamespaceState.for_stanza();
|
NamespaceState my_state = state ?? new NamespaceState.for_stanza();
|
||||||
if (name == "#text") return @"$encoded_val";
|
if (name == "#text") return val == null ? "" : (!)encoded_val;
|
||||||
foreach (var xmlns in get_attributes_by_ns_uri (XMLNS_URI)) {
|
foreach (var xmlns in get_attributes_by_ns_uri (XMLNS_URI)) {
|
||||||
|
if (xmlns.val == null) continue;
|
||||||
if (xmlns.name == "xmlns") {
|
if (xmlns.name == "xmlns") {
|
||||||
my_state = new NamespaceState.with_current(my_state, xmlns.val);
|
my_state = new NamespaceState.with_current(my_state, (!)xmlns.val);
|
||||||
} else {
|
} else {
|
||||||
my_state = new NamespaceState.with_assoc(my_state, xmlns.val, xmlns.name);
|
my_state = new NamespaceState.with_assoc(my_state, (!)xmlns.val, xmlns.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
if (ns_uri == my_state.current_ns_uri) {
|
if (ns_uri == my_state.current_ns_uri) {
|
||||||
sb.append(@"<$name");
|
sb.append_printf("<%s", name);
|
||||||
} else {
|
} else {
|
||||||
sb.append_printf("<%s:%s", my_state.find_name (ns_uri), name);
|
sb.append_printf("<%s:%s", my_state.find_name ((!)ns_uri), name);
|
||||||
}
|
}
|
||||||
var attr_ns_state = new NamespaceState.with_current(my_state, ns_uri);
|
var attr_ns_state = new NamespaceState.with_current(my_state, (!)ns_uri);
|
||||||
foreach (StanzaAttribute attr in attributes) {
|
foreach (StanzaAttribute attr in attributes) {
|
||||||
sb.append_printf(" %s", attr.to_xml(attr_ns_state));
|
sb.append_printf(" %s", attr.to_xml(attr_ns_state));
|
||||||
}
|
}
|
||||||
|
@ -385,7 +383,7 @@ public class StanzaNode : StanzaEntry {
|
||||||
if (ns_uri == my_state.current_ns_uri) {
|
if (ns_uri == my_state.current_ns_uri) {
|
||||||
sb.append(@"</$name>");
|
sb.append(@"</$name>");
|
||||||
} else {
|
} else {
|
||||||
sb.append_printf("</%s:%s>", my_state.find_name (ns_uri), name);
|
sb.append_printf("</%s:%s>", my_state.find_name ((!)ns_uri), name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,10 @@ public class StanzaReader {
|
||||||
|
|
||||||
private void update_buffer() throws XmlError {
|
private void update_buffer() throws XmlError {
|
||||||
try {
|
try {
|
||||||
|
InputStream? input = this.input;
|
||||||
if (input == null) throw new XmlError.EOF("No input stream specified and end of buffer reached.");
|
if (input == null) throw new XmlError.EOF("No input stream specified and end of buffer reached.");
|
||||||
if (cancellable.is_cancelled()) throw new XmlError.EOF("Input stream is canceled.");
|
if (cancellable.is_cancelled()) throw new XmlError.EOF("Input stream is canceled.");
|
||||||
buffer_fill = (int) input.read(buffer, cancellable);
|
buffer_fill = (int) ((!)input).read(buffer, cancellable);
|
||||||
if (buffer_fill == 0) throw new XmlError.EOF("End of input stream reached.");
|
if (buffer_fill == 0) throw new XmlError.EOF("End of input stream reached.");
|
||||||
buffer_pos = 0;
|
buffer_pos = 0;
|
||||||
} catch (GLib.IOError e) {
|
} catch (GLib.IOError e) {
|
||||||
|
@ -140,21 +141,21 @@ public class StanzaReader {
|
||||||
|
|
||||||
private void handle_stanza_ns(StanzaNode res) throws XmlError {
|
private void handle_stanza_ns(StanzaNode res) throws XmlError {
|
||||||
foreach (StanzaAttribute attr in res.attributes) {
|
foreach (StanzaAttribute attr in res.attributes) {
|
||||||
if (attr.name == "xmlns") {
|
if (attr.name == "xmlns" && attr.val != null) {
|
||||||
attr.ns_uri = XMLNS_URI;
|
attr.ns_uri = XMLNS_URI;
|
||||||
ns_state.set_current(attr.val);
|
ns_state.set_current((!)attr.val);
|
||||||
} else if (attr.name.contains(":")) {
|
} else if (attr.name.contains(":") && attr.val != null) {
|
||||||
var split = attr.name.split(":");
|
var split = attr.name.split(":");
|
||||||
if (split[0] == "xmlns") {
|
if (split[0] == "xmlns") {
|
||||||
attr.ns_uri = XMLNS_URI;
|
attr.ns_uri = XMLNS_URI;
|
||||||
attr.name = split[1];
|
attr.name = split[1];
|
||||||
ns_state.add_assoc(attr.val, attr.name);
|
ns_state.add_assoc((!)attr.val, attr.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handle_entry_ns(res);
|
handle_entry_ns(res);
|
||||||
foreach (StanzaAttribute attr in res.attributes) {
|
foreach (StanzaAttribute attr in res.attributes) {
|
||||||
handle_entry_ns(attr, res.ns_uri);
|
handle_entry_ns(attr, res.ns_uri ?? ns_state.current_ns_uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +230,7 @@ public class StanzaReader {
|
||||||
skip_single();
|
skip_single();
|
||||||
if (desc.contains(":")) {
|
if (desc.contains(":")) {
|
||||||
var split = desc.split(":");
|
var split = desc.split(":");
|
||||||
assert(split[0] == ns_state.find_name(res.ns_uri));
|
assert(split[0] == ns_state.find_name((!)res.ns_uri));
|
||||||
assert(split[1] == res.name);
|
assert(split[1] == res.name);
|
||||||
} else {
|
} else {
|
||||||
assert(ns_state.current_ns_uri == res.ns_uri);
|
assert(ns_state.current_ns_uri == res.ns_uri);
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class XmppLog {
|
||||||
}
|
}
|
||||||
if (inner == null) return true;
|
if (inner == null) return true;
|
||||||
foreach (StanzaNode snode in node.get_all_subnodes()) {
|
foreach (StanzaNode snode in node.get_all_subnodes()) {
|
||||||
if (inner.matches(snode)) return true;
|
if (((!)inner).matches(snode)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -78,10 +78,10 @@ public class XmppLog {
|
||||||
private ArrayList<NodeLogDesc> descs = new ArrayList<NodeLogDesc>();
|
private ArrayList<NodeLogDesc> descs = new ArrayList<NodeLogDesc>();
|
||||||
|
|
||||||
public XmppLog(string? ident = null, string? desc = null) {
|
public XmppLog(string? ident = null, string? desc = null) {
|
||||||
this.ident = ident;
|
this.ident = ident ?? "";
|
||||||
this.desc = desc;
|
this.desc = desc ?? "";
|
||||||
this.use_ansi = is_atty(stderr.fileno());
|
this.use_ansi = is_atty(stderr.fileno());
|
||||||
while (this.desc != null && this.desc.contains(";")) {
|
while (this.desc.contains(";")) {
|
||||||
string opt = this.desc.substring(0, this.desc.index_of(";"));
|
string opt = this.desc.substring(0, this.desc.index_of(";"));
|
||||||
this.desc = this.desc.substring(opt.length + 1);
|
this.desc = this.desc.substring(opt.length + 1);
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
@ -91,7 +91,7 @@ public class XmppLog {
|
||||||
case "show-ns": hide_ns = false; break;
|
case "show-ns": hide_ns = false; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (desc != null) {
|
if (desc != "") {
|
||||||
foreach (string d in this.desc.split("|")) {
|
foreach (string d in this.desc.split("|")) {
|
||||||
descs.add(new NodeLogDesc(d));
|
descs.add(new NodeLogDesc(d));
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ public class XmppLog {
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool should_log_node(StanzaNode node) {
|
public virtual bool should_log_node(StanzaNode node) {
|
||||||
if (ident == null || desc == null) return false;
|
if (ident == "" || desc == "") return false;
|
||||||
if (desc == "all") return true;
|
if (desc == "all") return true;
|
||||||
foreach (var desc in descs) {
|
foreach (var desc in descs) {
|
||||||
if (desc.matches(node)) return true;
|
if (desc.matches(node)) return true;
|
||||||
|
@ -108,7 +108,7 @@ public class XmppLog {
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool should_log_str(string str) {
|
public virtual bool should_log_str(string str) {
|
||||||
if (ident == null || desc == null) return false;
|
if (ident == "" || desc == "") return false;
|
||||||
if (desc == "all") return true;
|
if (desc == "all") return true;
|
||||||
foreach (var desc in descs) {
|
foreach (var desc in descs) {
|
||||||
if (desc.name == "#text") return true;
|
if (desc.name == "#text") return true;
|
||||||
|
@ -158,12 +158,12 @@ public class XmppStream {
|
||||||
public signal void stream_negotiated(XmppStream stream);
|
public signal void stream_negotiated(XmppStream stream);
|
||||||
|
|
||||||
public void connect(string? remote_name = null) throws IOStreamError {
|
public void connect(string? remote_name = null) throws IOStreamError {
|
||||||
if (remote_name != null) this.remote_name = remote_name;
|
if (remote_name != null) this.remote_name = (!)remote_name;
|
||||||
SocketClient client = new SocketClient();
|
SocketClient client = new SocketClient();
|
||||||
try {
|
try {
|
||||||
SocketConnection? stream = client.connect(new NetworkService("xmpp-client", "tcp", this.remote_name));
|
SocketConnection? stream = client.connect(new NetworkService("xmpp-client", "tcp", this.remote_name));
|
||||||
if (stream == null) throw new IOStreamError.CONNECT("client.connect() returned null");
|
if (stream == null) throw new IOStreamError.CONNECT("client.connect() returned null");
|
||||||
reset_stream(stream);
|
reset_stream((!)stream);
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
stderr.printf("CONNECTION LOST?\n");
|
stderr.printf("CONNECTION LOST?\n");
|
||||||
throw new IOStreamError.CONNECT(e.message);
|
throw new IOStreamError.CONNECT(e.message);
|
||||||
|
@ -172,11 +172,14 @@ public class XmppStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() throws IOStreamError {
|
public void disconnect() throws IOStreamError {
|
||||||
if (writer == null) throw new IOStreamError.DISCONNECT("trying to disconnect, but no stream open");
|
StanzaWriter? writer = this.writer;
|
||||||
|
StanzaReader? reader = this.reader;
|
||||||
|
IOStream? stream = this.stream;
|
||||||
|
if (writer == null || reader == null || stream == null) throw new IOStreamError.DISCONNECT("trying to disconnect, but no stream open");
|
||||||
log.str("OUT", "</stream:stream>");
|
log.str("OUT", "</stream:stream>");
|
||||||
writer.write.begin("</stream:stream>");
|
((!)writer).write.begin("</stream:stream>");
|
||||||
reader.cancel();
|
((!)reader).cancel();
|
||||||
stream.close_async.begin();
|
((!)stream).close_async.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset_stream(IOStream stream) {
|
public void reset_stream(IOStream stream) {
|
||||||
|
@ -195,9 +198,10 @@ public class XmppStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
public StanzaNode read() throws IOStreamError {
|
public StanzaNode read() throws IOStreamError {
|
||||||
|
StanzaReader? reader = this.reader;
|
||||||
if (reader == null) throw new IOStreamError.READ("trying to read, but no stream open");
|
if (reader == null) throw new IOStreamError.READ("trying to read, but no stream open");
|
||||||
try {
|
try {
|
||||||
StanzaNode node = reader.read_node();
|
StanzaNode node = ((!)reader).read_node();
|
||||||
log.node("IN", node);
|
log.node("IN", node);
|
||||||
return node;
|
return node;
|
||||||
} catch (XmlError e) {
|
} catch (XmlError e) {
|
||||||
|
@ -206,10 +210,11 @@ public class XmppStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(StanzaNode node) throws IOStreamError {
|
public void write(StanzaNode node) throws IOStreamError {
|
||||||
|
StanzaWriter? writer = this.writer;
|
||||||
if (writer == null) throw new IOStreamError.WRITE("trying to write, but no stream open");
|
if (writer == null) throw new IOStreamError.WRITE("trying to write, but no stream open");
|
||||||
try {
|
try {
|
||||||
log.node("OUT", node);
|
log.node("OUT", node);
|
||||||
writer.write_node(node);
|
((!)writer).write_node(node);
|
||||||
} catch (XmlError e) {
|
} catch (XmlError e) {
|
||||||
throw new IOStreamError.WRITE(e.message);
|
throw new IOStreamError.WRITE(e.message);
|
||||||
}
|
}
|
||||||
|
@ -230,7 +235,7 @@ public class XmppStream {
|
||||||
public T? get_flag<T>(FlagIdentity<T>? identity) {
|
public T? get_flag<T>(FlagIdentity<T>? identity) {
|
||||||
if (identity == null) return null;
|
if (identity == null) return null;
|
||||||
foreach (var flag in flags) {
|
foreach (var flag in flags) {
|
||||||
if (identity.matches(flag)) return identity.cast(flag);
|
if (((!)identity).matches(flag)) return ((!)identity).cast(flag);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -254,7 +259,7 @@ public class XmppStream {
|
||||||
public T? get_module<T>(ModuleIdentity<T>? identity) {
|
public T? get_module<T>(ModuleIdentity<T>? identity) {
|
||||||
if (identity == null) return null;
|
if (identity == null) return null;
|
||||||
foreach (var module in modules) {
|
foreach (var module in modules) {
|
||||||
if (identity.matches(module)) return identity.cast(module);
|
if (((!)identity).matches(module)) return ((!)identity).cast(module);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -315,10 +320,10 @@ public class XmppStream {
|
||||||
bool mandatory_outstanding = false;
|
bool mandatory_outstanding = false;
|
||||||
bool negotiation_active = false;
|
bool negotiation_active = false;
|
||||||
foreach (XmppStreamModule module in modules) {
|
foreach (XmppStreamModule module in modules) {
|
||||||
XmppStreamNegotiationModule negotiation_module = module as XmppStreamNegotiationModule;
|
XmppStreamNegotiationModule? negotiation_module = module as XmppStreamNegotiationModule;
|
||||||
if (negotiation_module != null) {
|
if (negotiation_module != null) {
|
||||||
if (negotiation_module.negotiation_active(this)) negotiation_active = true;
|
if (((!)negotiation_module).negotiation_active(this)) negotiation_active = true;
|
||||||
if (negotiation_module.mandatory_outstanding(this)) mandatory_outstanding = true;
|
if (((!)negotiation_module).mandatory_outstanding(this)) mandatory_outstanding = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!negotiation_active) {
|
if (!negotiation_active) {
|
||||||
|
@ -341,8 +346,10 @@ public class XmppStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
private StanzaNode read_root() throws IOStreamError {
|
private StanzaNode read_root() throws IOStreamError {
|
||||||
|
StanzaReader? reader = this.reader;
|
||||||
|
if (reader == null) throw new IOStreamError.READ("trying to read, but no stream open");
|
||||||
try {
|
try {
|
||||||
StanzaNode node = reader.read_root_node();
|
StanzaNode node = ((!)reader).read_root_node();
|
||||||
log.node("IN ROOT", node);
|
log.node("IN ROOT", node);
|
||||||
return node;
|
return node;
|
||||||
} catch (XmlError e) {
|
} catch (XmlError e) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
namespace Xmpp {
|
namespace Xmpp {
|
||||||
public string? get_bare_jid(string jid) {
|
public string get_bare_jid(string jid) {
|
||||||
return jid.split("/")[0];
|
return jid.split("/")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,16 +167,16 @@ public class Module : XmppStreamModule {
|
||||||
flag.finish_muc_enter(bare_jid, get_resource_part(presence.from));
|
flag.finish_muc_enter(bare_jid, get_resource_part(presence.from));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string? affiliation = x_node["item", "affiliation"].val;
|
string? affiliation = x_node.get_deep_attribute("item", "affiliation");
|
||||||
if (affiliation != null) {
|
if (affiliation != null) {
|
||||||
received_occupant_affiliation(stream, presence.from, affiliation);
|
received_occupant_affiliation(stream, presence.from, affiliation);
|
||||||
}
|
}
|
||||||
string? jid = x_node["item", "jid"].val;
|
string? jid = x_node.get_deep_attribute("item", "jid");
|
||||||
if (jid != null) {
|
if (jid != null) {
|
||||||
flag.set_real_jid(presence.from, jid);
|
flag.set_real_jid(presence.from, jid);
|
||||||
received_occupant_jid(stream, presence.from, jid);
|
received_occupant_jid(stream, presence.from, jid);
|
||||||
}
|
}
|
||||||
string? role = x_node["item", "role"].val;
|
string? role = x_node.get_deep_attribute("item", "role");
|
||||||
if (role != null) {
|
if (role != null) {
|
||||||
received_occupant_role(stream, presence.from, role);
|
received_occupant_role(stream, presence.from, role);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class Module : XmppStreamModule {
|
||||||
public override void detach(XmppStream stream) { }
|
public override void detach(XmppStream stream) { }
|
||||||
|
|
||||||
public static void require(XmppStream stream) {
|
public static void require(XmppStream stream) {
|
||||||
if (stream.get_module(IDENTITY) == null) stderr.printf("");
|
if (stream.get_module(IDENTITY) == null) stream.add_module(new Module());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string get_ns() { return NS_URI; }
|
public override string get_ns() { return NS_URI; }
|
||||||
|
|
Loading…
Reference in a new issue