Handle if Items/InfoResult are null

This commit is contained in:
fiaxh 2020-04-25 16:12:08 +02:00
parent 231df1bbbb
commit ee9795d8f4
5 changed files with 25 additions and 7 deletions

View file

@ -26,6 +26,10 @@ public class ItemsResult {
}
public static ItemsResult? create_from_iq(Iq.Stanza iq) {
if (iq.type_ != Iq.Stanza.TYPE_RESULT) return null;
if (iq.stanza.get_subnode("query", NS_URI_ITEMS) == null) return null;
return new ItemsResult.from_iq(iq);
}
}

View file

@ -46,11 +46,11 @@ public class Module : XmppStreamModule, Iq.Handler {
if (flag.has_entity_feature(jid, feature) == null) {
InfoResult? info_result = yield request_info(stream, jid);
stream.get_flag(Flag.IDENTITY).set_entity_features(info_result.iq.from, info_result != null ? info_result.features : null);
stream.get_flag(Flag.IDENTITY).set_entity_identities(info_result.iq.from, info_result != null ? info_result.identities : null);
stream.get_flag(Flag.IDENTITY).set_entity_features(jid, info_result != null ? info_result.features : null);
stream.get_flag(Flag.IDENTITY).set_entity_identities(jid, info_result != null ? info_result.identities : null);
}
return flag.has_entity_feature(jid, feature);
return flag.has_entity_feature(jid, feature) ?? false;
}
public async Gee.Set<Identity>? get_entity_identities(XmppStream stream, Jid jid) {

View file

@ -35,6 +35,7 @@ public class Module : XmppStreamModule, Iq.Handler {
private async void query_availability(XmppStream stream) {
ServiceDiscovery.ItemsResult? items_result = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_items(stream, stream.remote_name);
if (items_result == null) return;
foreach (Xep.ServiceDiscovery.Item item in items_result.items) {
bool has_feature = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).has_entity_feature(stream, item.jid, NS_URI);

View file

@ -86,6 +86,7 @@ namespace Xmpp.Xep.EntityCapabilities {
ServiceDiscovery.Identity identity = storage.get_identities(caps_hash);
if (identity == null) {
ServiceDiscovery.InfoResult? info_result = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, jid_from);
if (info_result == null) return;
store_entity_result(stream, caps_hash, info_result);
} else {
stream.get_flag(ServiceDiscovery.Flag.IDENTITY).set_entity_features(jid_from, capabilities);

View file

@ -116,14 +116,26 @@ public class Module : XmppStreamModule {
bool available = check_ns_in_info(stream, stream.remote_name, info_result);
if (!available) {
ServiceDiscovery.ItemsResult? items_result = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_items(stream, stream.remote_name);
if (items_result == null) return;
for (int i = 0; i < 2; i++) {
foreach (Xep.ServiceDiscovery.Item item in items_result.items) {
// First try the promising items and only afterwards all the others
bool promising_upload_item = item.jid.to_string().has_prefix("upload");
if ((i == 0 && !promising_upload_item) || (i == 1) && promising_upload_item) continue;
ServiceDiscovery.InfoResult? info_result2 = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, item.jid);
check_ns_in_info(stream, item.jid, info_result2);
bool available2 = check_ns_in_info(stream, item.jid, info_result2);
if (available2) return;
}
}
}
}
private bool check_ns_in_info(XmppStream stream, Jid jid, Xep.ServiceDiscovery.InfoResult info_result) {
private bool check_ns_in_info(XmppStream stream, Jid jid, Xep.ServiceDiscovery.InfoResult? info_result) {
if (info_result == null) return false;
bool ver_available = false;
bool ver_0_available = false;
foreach (string feature in info_result.features) {