mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-24 16:38:56 -05:00
use base64 encoding for file names uploaded with http
This commit is contained in:
parent
bbceee7f61
commit
c9e6d05fa0
@ -10,12 +10,15 @@ import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.state.PreKeyRecord;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.R;
|
||||
@ -315,7 +318,7 @@ public class IqGenerator extends AbstractGenerator {
|
||||
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
||||
packet.setTo(host);
|
||||
Element request = packet.addChild("request", Xmlns.HTTP_UPLOAD);
|
||||
request.addChild("filename").setContent(file.getName());
|
||||
request.addChild("filename").setContent(convertFilename(file.getName()));
|
||||
request.addChild("size").setContent(String.valueOf(file.getExpectedSize()));
|
||||
if (mime != null) {
|
||||
request.addChild("content-type").setContent(mime);
|
||||
@ -323,6 +326,23 @@ public class IqGenerator extends AbstractGenerator {
|
||||
return packet;
|
||||
}
|
||||
|
||||
private static String convertFilename(String name) {
|
||||
int pos = name.indexOf('.');
|
||||
if (pos != -1) {
|
||||
try {
|
||||
UUID uuid = UUID.fromString(name.substring(0, pos));
|
||||
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
|
||||
bb.putLong(uuid.getMostSignificantBits());
|
||||
bb.putLong(uuid.getLeastSignificantBits());
|
||||
return Base64.encodeToString(bb.array(), Base64.URL_SAFE) + name.substring(pos, name.length());
|
||||
} catch (Exception e) {
|
||||
return name;
|
||||
}
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public IqPacket generateCreateAccountWithCaptcha(Account account, String id, Data data) {
|
||||
final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
|
||||
register.setFrom(account.getJid().toBareJid());
|
||||
|
@ -1255,7 +1255,7 @@ public class XmppConnection implements Runnable {
|
||||
}
|
||||
|
||||
private String nextRandomId() {
|
||||
return new BigInteger(50, mXmppConnectionService.getRNG()).toString(32);
|
||||
return new BigInteger(50, mXmppConnectionService.getRNG()).toString(36);
|
||||
}
|
||||
|
||||
public String sendIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {
|
||||
|
Loading…
Reference in New Issue
Block a user