diff --git a/README.md b/README.md index bdb27607..b072186a 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,13 @@ Build **Run-time dependencies** * GLib (≥ 2.38) +* glib-networking * GTK (≥ 3.22) * GPGME (For the OpenPGP plugin) * libgee-0.8 (≥ 0.10) * libgcrypt (For the OMEMO plugin) * libnotify +* libsoup (For the HTTP files plugin) * SQLite3 **Instructions** diff --git a/dino.spec b/dino.spec index 1e795995..0ea7b676 100644 --- a/dino.spec +++ b/dino.spec @@ -43,6 +43,7 @@ BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(gtk+-3.0) >= 3.22 BuildRequires: pkgconfig(gee-0.8) >= 0.10 BuildRequires: pkgconfig(libnotify) +BuildRequires: pkgconfig(libsoup-2.4) BuildRequires: pkgconfig(sqlite3) BuildRequires: libgcrypt-devel BuildRequires: gpgme-devel @@ -51,6 +52,7 @@ Requires: %{name}-libs%{?_isa} = %{version}-%{release} # Technically these aren't requirements, we just want them always installed... Requires: %{name}-plugin-omemo%{?_isa} = %{version}-%{release} Requires: %{name}-plugin-openpgp%{?_isa} = %{version}-%{release} +Requires: %{name}-plugin-http-files%{?_isa} = %{version}-%{release} %description Dino is an instant messaging client for the Jabber/XMPP network, @@ -76,6 +78,10 @@ Requires: %{name}-libs%{?_isa} = %{version}-%{release} Summary: OpenPGP plugin for %{name} Requires: %{name}-libs%{?_isa} = %{version}-%{release} +%package plugin-http-files +Summary: Http files plugin for %{name} +Requires: %{name}-libs%{?_isa} = %{version}-%{release} + %description libs The %{name}-libs package contains libraries used and provided by %{name}. @@ -91,6 +97,10 @@ OMEMO encryption to Dino. The %{name}-plugin-openpgp package contains a plugin that adds support for OpenPGP encryption to Dino. +%description plugin-http-files +The %{name}-plugin-http-files package contains a plugin that adds support for +http file upload and download to Dino. + %prep %setup -n "dino-v%{version}" #%setup -n "dino-%{commit}" @@ -168,6 +178,11 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || : %{_libdir}/dino/plugins/openpgp.so %{_datadir}/locale/*/LC_MESSAGES/dino-openpgp.mo +%files plugin-http-files +%license LICENSE +%doc README.md +%{_libdir}/dino/plugins/http-files.so + %changelog * Mon Apr 3 2017 - 0.0-1 - Split packages diff --git a/plugins/http-files/src/upload_stream_module.vala b/plugins/http-files/src/upload_stream_module.vala index 765d212e..c427f7b8 100644 --- a/plugins/http-files/src/upload_stream_module.vala +++ b/plugins/http-files/src/upload_stream_module.vala @@ -15,6 +15,7 @@ public class UploadStreamModule : XmppStreamModule { public delegate void OnUploadOk(XmppStream stream, string url_down); public delegate void OnError(XmppStream stream, string error); public void upload(XmppStream stream, string file_uri, owned OnUploadOk listener, owned OnError error_listener) { + print("up!\n"); File file = File.new_for_path(file_uri); FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); request_slot(stream, file.get_basename(), (int)file_info.get_size(), file_info.get_content_type(), @@ -27,7 +28,7 @@ public class UploadStreamModule : XmppStreamModule { Soup.Session session = new Soup.Session(); session.send_async(message); - listener(stream, url_up); + listener(stream, url_down); }, error_listener); } @@ -35,30 +36,42 @@ public class UploadStreamModule : XmppStreamModule { private delegate void OnSlotOk(XmppStream stream, string url_get, string url_put); private void request_slot(XmppStream stream, string filename, int file_size, string? content_type, owned OnSlotOk listener, owned OnError error_listener) { Flag? flag = stream.get_flag(Flag.IDENTITY); - if (flag != null) return; + if (flag == null) return; - StanzaNode request_node; - if (flag.ns_ver == NS_URI_0) { - request_node = new StanzaNode.build("request", NS_URI_0).add_self_xmlns(); - request_node.put_attribute("filename", filename).put_attribute("size", file_size.to_string()); - if (content_type != null) request_node.put_attribute("content-type", content_type); - } else{ - request_node = new StanzaNode.build("request", NS_URI).add_self_xmlns() - .put_node(new StanzaNode.build("filename", NS_URI).put_node(new StanzaNode.text(filename))) - .put_node(new StanzaNode.build("size", NS_URI).put_node(new StanzaNode.text(file_size.to_string()))); - if (content_type != null) { - request_node.put_node(new StanzaNode.build("content-type", NS_URI).put_node(new StanzaNode.text(content_type))); - } + StanzaNode? request_node = null; + switch (flag.ns_ver) { + case NS_URI_0: + request_node = new StanzaNode.build("request", NS_URI_0).add_self_xmlns(); + request_node.put_attribute("filename", filename).put_attribute("size", file_size.to_string()); + if (content_type != null) request_node.put_attribute("content-type", content_type); + break; + case NS_URI: + request_node = new StanzaNode.build("request", NS_URI).add_self_xmlns() + .put_node(new StanzaNode.build("filename", NS_URI).put_node(new StanzaNode.text(filename))) + .put_node(new StanzaNode.build("size", NS_URI).put_node(new StanzaNode.text(file_size.to_string()))); + if (content_type != null) { + request_node.put_node(new StanzaNode.build("content-type", NS_URI).put_node(new StanzaNode.text(content_type))); + } + break; } Iq.Stanza iq = new Iq.Stanza.get(request_node) { to=flag.file_store_jid }; stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => { if (iq.is_error()) { error_listener(stream, ""); - } else { - string? url_get = iq.stanza.get_deep_string_content(flag.ns_ver + ":slot", flag.ns_ver + ":get"); - string? url_put = iq.stanza.get_deep_string_content(flag.ns_ver + ":slot", flag.ns_ver + ":put"); - listener(stream, url_get, url_put); + return; } + string? url_get = null, url_put = null; + switch (flag.ns_ver) { + case NS_URI_0: + url_get = iq.stanza.get_deep_attribute(flag.ns_ver + ":slot", flag.ns_ver + ":get", flag.ns_ver + ":url"); + url_put = iq.stanza.get_deep_attribute(flag.ns_ver + ":slot", flag.ns_ver + ":put", flag.ns_ver + ":url"); + break; + case NS_URI: + url_get = iq.stanza.get_deep_string_content(flag.ns_ver + ":slot", flag.ns_ver + ":get"); + url_put = iq.stanza.get_deep_string_content(flag.ns_ver + ":slot", flag.ns_ver + ":put"); + break; + } + listener(stream, url_get, url_put); }); } @@ -86,12 +99,9 @@ public class UploadStreamModule : XmppStreamModule { if (!available) { stream.get_module(ServiceDiscovery.Module.IDENTITY).request_items(stream, stream.remote_name, (stream, items_result) => { foreach (Xep.ServiceDiscovery.Item item in items_result.items) { - if (item.name == "HTTP File Upload") { - stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, item.jid, (stream, info_result) => { - check_ns_in_info(stream, item.jid, info_result); - }); - break; - } + stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, item.jid, (stream, info_result) => { + check_ns_in_info(stream, item.jid, info_result); + }); } }); } diff --git a/xmpp-vala/src/module/xep/0030_service_discovery/items_result.vala b/xmpp-vala/src/module/xep/0030_service_discovery/items_result.vala index 2979f108..52de5efc 100644 --- a/xmpp-vala/src/module/xep/0030_service_discovery/items_result.vala +++ b/xmpp-vala/src/module/xep/0030_service_discovery/items_result.vala @@ -10,7 +10,7 @@ public class ItemsResult { public ArrayList items { owned get { ArrayList ret = new ArrayList(); - foreach (StanzaNode feature_node in iq.stanza.get_subnode("query", NS_URI_ITEMS).get_subnodes("identity", NS_URI_INFO)) { + foreach (StanzaNode feature_node in iq.stanza.get_subnode("query", NS_URI_ITEMS).get_subnodes("item", NS_URI_ITEMS)) { ret.add(new Item(feature_node.get_attribute("jid", NS_URI_ITEMS), feature_node.get_attribute("name", NS_URI_ITEMS), feature_node.get_attribute("node", NS_URI_ITEMS))); diff --git a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala index e09a3b8d..c3e08a60 100644 --- a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala +++ b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala @@ -54,7 +54,6 @@ public class Module : XmppStreamModule, Iq.Handler { public void request_items(XmppStream stream, string jid, owned OnItemsResult listener) { Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_ITEMS).add_self_xmlns()); iq.to = jid; - print(iq.stanza.to_string() + "\n"); stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => { ItemsResult? result = ItemsResult.create_from_iq(iq); stream.get_flag(Flag.IDENTITY).set_entity_items(iq.from, result != null ? result.items : null);