aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/generator
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-26 22:56:17 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-26 22:56:17 +0200
commita554be18a60380d624fc9c65416368775cba9bae (patch)
treebe455ef73e0c047a47bd71651382f2d22dd115ab /src/main/java/de/pixart/messenger/generator
parent369e48c2203a694088156574dd7c7044f68e907b (diff)
add support for S3 file transfers
Diffstat (limited to 'src/main/java/de/pixart/messenger/generator')
-rw-r--r--src/main/java/de/pixart/messenger/generator/IqGenerator.java42
-rw-r--r--src/main/java/de/pixart/messenger/generator/MessageGenerator.java29
2 files changed, 53 insertions, 18 deletions
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
index 73f9c7ec8..159e730f3 100644
--- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
@@ -352,21 +352,37 @@ public class IqGenerator extends AbstractGenerator {
return packet;
}
- public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file, String mime, String http_upload_namespace) {
+ public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file, String mime) {
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
packet.setTo(host);
- 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);
- }
- }
+ Element request = packet.addChild("request", Namespace.HTTP_UPLOAD);
+ request.setAttribute("filename", convertFilename(file.getName()));
+ request.setAttribute("size", file.getExpectedSize());
+ request.setAttribute("content-type", mime);
+ return packet;
+ }
+
+ public IqPacket requestHttpUploadLegacySlot(Jid host, DownloadableFile file, String mime) {
+ IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
+ packet.setTo(host);
+ Element request = packet.addChild("request", Namespace.HTTP_UPLOAD_LEGACY);
+ request.addChild("filename").setContent(convertFilename(file.getName()));
+ request.addChild("size").setContent(String.valueOf(file.getExpectedSize()));
+ request.addChild("content-type").setContent(mime);
+ return packet;
+ }
+
+ public IqPacket requestP1S3Slot(Jid host, String md5) {
+ IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
+ packet.setTo(host);
+ packet.query(Namespace.P1_S3_FILE_TRANSFER).setAttribute("md5", md5);
+ return packet;
+ }
+
+ public IqPacket requestP1S3Url(Jid host, String fileId) {
+ IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
+ packet.setTo(host);
+ packet.query(Namespace.P1_S3_FILE_TRANSFER).setAttribute("fileid", fileId);
return packet;
}
diff --git a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java
index 57867bc2f..369a1963e 100644
--- a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java
@@ -3,6 +3,7 @@ package de.pixart.messenger.generator;
import net.java.otr4j.OtrException;
import net.java.otr4j.session.Session;
+import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -16,6 +17,7 @@ import de.pixart.messenger.entities.Account;
import de.pixart.messenger.entities.Contact;
import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.entities.Message;
+import de.pixart.messenger.http.P1S3UrlStreamHandler;
import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.utils.Namespace;
import de.pixart.messenger.xml.Element;
@@ -136,8 +138,17 @@ public class MessageGenerator extends AbstractGenerator {
String content;
if (message.hasFileOnRemoteHost()) {
Message.FileParams fileParams = message.getFileParams();
- content = fileParams.url.toString();
- packet.addChild("x", Namespace.OOB).addChild("url").setContent(content);
+ final URL url = fileParams.url;
+ if (P1S3UrlStreamHandler.PROTOCOL_NAME.equals(url.getProtocol())) {
+ Element x = packet.addChild("x", Namespace.P1_S3_FILE_TRANSFER);
+ final String file = url.getFile();
+ x.setAttribute("name", file.charAt(0) == '/' ? file.substring(1) : file);
+ x.setAttribute("fileid", url.getHost());
+ return packet;
+ } else {
+ content = url.toString();
+ packet.addChild("x", Namespace.OOB).addChild("url").setContent(content);
+ }
} else {
content = message.getBody();
}
@@ -148,9 +159,17 @@ public class MessageGenerator extends AbstractGenerator {
public MessagePacket generatePgpChat(Message message) {
MessagePacket packet = preparePacket(message);
if (message.hasFileOnRemoteHost()) {
- final String url = message.getFileParams().url.toString();
- packet.setBody(url);
- packet.addChild("x", Namespace.OOB).addChild("url").setContent(url);
+ Message.FileParams fileParams = message.getFileParams();
+ final URL url = fileParams.url;
+ if (P1S3UrlStreamHandler.PROTOCOL_NAME.equals(url.getProtocol())) {
+ Element x = packet.addChild("x", Namespace.P1_S3_FILE_TRANSFER);
+ final String file = url.getFile();
+ x.setAttribute("name", file.charAt(0) == '/' ? file.substring(1) : file);
+ x.setAttribute("fileid", url.getHost());
+ } else {
+ packet.setBody(url.toString());
+ packet.addChild("x", Namespace.OOB).addChild("url").setContent(url.toString());
+ }
} else {
if (Config.supportUnencrypted()) {
packet.setBody(PGP_FALLBACK_MESSAGE);