aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-05 21:20:42 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-05 21:20:42 +0200
commitc408c78630c86472806f9d34fc8d20943cba653e (patch)
tree2d885ca68eb718dfc2f784483c8a31264d09d592 /src
parent8e8ea0845e3c98785ef7d259a5c3f02b65cee686 (diff)
Support both new and old http upload namespaces
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/generator/IqGenerator.java18
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpUploadConnection.java18
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java8
-rw-r--r--src/main/java/de/pixart/messenger/utils/Namespace.java1
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java15
5 files changed, 44 insertions, 16 deletions
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
index 0cb542549..5926d48d4 100644
--- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
@@ -348,13 +348,21 @@ public class IqGenerator extends AbstractGenerator {
return packet;
}
- public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file, String mime) {
+ public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file, String mime, String http_upload_namespace) {
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
packet.setTo(host);
- Element request = packet.addChild("request", Namespace.HTTP_UPLOAD);
- request.setAttribute("filename", convertFilename(file.getName()));
- request.setAttribute("size", file.getExpectedSize());
- request.setAttribute("content-type", mime);
+ Element request = packet.addChild("request", http_upload_namespace);
+ if (http_upload_namespace == Namespace.HTTP_UPLOAD) {
+ request.setAttribute("filename", convertFilename(file.getName()));
+ request.setAttribute("size", file.getExpectedSize());
+ request.setAttribute("content-type", mime);
+ } else {
+ request.addChild("filename").setContent(convertFilename(file.getName()));
+ request.addChild("size").setContent(String.valueOf(file.getExpectedSize()));
+ if (mime != null) {
+ request.addChild("content-type").setContent(mime);
+ }
+ }
return packet;
}
diff --git a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
index cd73d6895..fb2d1d49e 100644
--- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
@@ -129,17 +129,25 @@ public class HttpUploadConnection implements Transferable {
this.file.setExpectedSize(pair.second);
message.resetFileParams();
this.mFileInputStream = pair.first;
- Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
- IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime);
+ String http_upload_namespace = account.getXmppConnection().getFeatures().http_upload_namespace;
+ Jid host = account.getXmppConnection().findDiscoItemByFeature(http_upload_namespace);
+ IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime, http_upload_namespace);
mXmppConnectionService.sendIqPacket(account, request, (a, packet) -> {
if (packet.getType() == IqPacket.TYPE.RESULT) {
- Element slot = packet.findChild("slot", Namespace.HTTP_UPLOAD);
+ Element slot = packet.findChild("slot", http_upload_namespace);
if (slot != null) {
try {
final Element put = slot.findChild("put");
final Element get = slot.findChild("get");
- final String putUrl = put == null ? null : put.getAttribute("url");
- final String getUrl = get == null ? null : get.getAttribute("url");
+ final String putUrl;
+ final String getUrl;
+ if (http_upload_namespace == Namespace.HTTP_UPLOAD) {
+ putUrl = put == null ? null : put.getAttribute("url");
+ getUrl = get == null ? null : get.getAttribute("url");
+ } else {
+ putUrl = put == null ? null : put.getContent();
+ getUrl = get == null ? null : get.getContent();
+ }
if (getUrl != null && putUrl != null) {
this.mGetUrl = new URL(getUrl);
this.mPutUrl = new URL(putUrl);
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index cdbdbd069..8e79d0acb 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -1217,8 +1217,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
@Override
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
- int animator = enter ? R.animator.fade_right_in : R.animator.fade_right_out;
- return AnimatorInflater.loadAnimator(getActivity(), animator);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ int animator = enter ? R.animator.fade_right_in : R.animator.fade_right_out;
+ return AnimatorInflater.loadAnimator(getActivity(), animator);
+ } else {
+ return null;
+ }
}
private void quoteText(String text) {
diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java
index b70d8040f..d2ba1a7ff 100644
--- a/src/main/java/de/pixart/messenger/utils/Namespace.java
+++ b/src/main/java/de/pixart/messenger/utils/Namespace.java
@@ -6,6 +6,7 @@ public final class Namespace {
public static final String REGISTER = "jabber:iq:register";
public static final String BYTE_STREAMS = "http://jabber.org/protocol/bytestreams";
public static final String HTTP_UPLOAD = "urn:xmpp:http:upload:0";
+ public static final String HTTP_UPLOAD_LEGACY = "urn:xmpp:http:upload";
public static final String STANZA_IDS = "urn:xmpp:sid:0";
public static final String MAM = "urn:xmpp:mam:2";
public static final String MAM_LEGACY = "urn:xmpp:mam:0";
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index 775f7b430..1ea8174fe 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -1755,6 +1755,8 @@ public class XmppConnection implements Runnable {
private boolean encryptionEnabled = false;
private boolean blockListRequested = false;
+ public String http_upload_namespace = Namespace.HTTP_UPLOAD;
+
public Features(final XmppConnection connection) {
this.connection = connection;
}
@@ -1844,10 +1846,15 @@ public class XmppConnection implements Runnable {
if (Config.DISABLE_HTTP_UPLOAD) {
return false;
} else {
- List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(Namespace.HTTP_UPLOAD);
+ List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(this.http_upload_namespace);
+ if (items.size() == 0) {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": this server does not support the latest version of XEP-0363");
+ this.http_upload_namespace = Namespace.HTTP_UPLOAD_LEGACY;
+ items = findDiscoItemsByFeature(this.http_upload_namespace);
+ }
if (items.size() > 0) {
try {
- long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Namespace.HTTP_UPLOAD, "max-file-size"));
+ long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(this.http_upload_namespace, "max-file-size"));
if (filesize <= maxsize) {
return true;
} else {
@@ -1864,10 +1871,10 @@ public class XmppConnection implements Runnable {
}
public long getMaxHttpUploadSize() {
- List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(Namespace.HTTP_UPLOAD);
+ List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(this.http_upload_namespace);
if (items.size() > 0) {
try {
- return Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Namespace.HTTP_UPLOAD, "max-file-size"));
+ return Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(this.http_upload_namespace, "max-file-size"));
} catch (Exception e) {
return -1;
}