diff options
18 files changed, 189 insertions, 54 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 806a03ec2..4404be730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ###Changelog +####Version 1.11.4 +* check maximum file size when using HTTP Upload +* properly calculate caps hash +* some UI improvements + ####Version 1.11.3 * only add image files to media scanner * allow to delete files diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index 356b34e57..2356ffb94 100644 --- a/src/main/java/eu/siacs/conversations/entities/Account.java +++ b/src/main/java/eu/siacs/conversations/entities/Account.java @@ -52,8 +52,12 @@ public class Account extends AbstractEntity { public static final int OPTION_USECOMPRESSION = 3; public final HashSet<Pair<String, String>> inProgressDiscoFetches = new HashSet<>(); + public boolean httpUploadAvailable(long filesize) { + return xmppConnection != null && xmppConnection.getFeatures().httpUpload(filesize); + } + public boolean httpUploadAvailable() { - return xmppConnection != null && xmppConnection.getFeatures().httpUpload(); + return httpUploadAvailable(0); } public void setDisplayName(String displayName) { diff --git a/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java b/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java index d35a4b017..4e63a66ab 100644 --- a/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java +++ b/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java @@ -52,20 +52,16 @@ public class DownloadableFile extends File { public void setKeyAndIv(byte[] keyIvCombo) { if (keyIvCombo.length == 48) { - byte[] secretKey = new byte[32]; - byte[] iv = new byte[16]; - System.arraycopy(keyIvCombo, 0, iv, 0, 16); - System.arraycopy(keyIvCombo, 16, secretKey, 0, 32); - this.aeskey = secretKey; - this.iv = iv; + this.aeskey = new byte[32]; + this.iv = new byte[16]; + System.arraycopy(keyIvCombo, 0, this.iv, 0, 16); + System.arraycopy(keyIvCombo, 16, this.aeskey, 0, 32); } else if (keyIvCombo.length >= 32) { - byte[] secretKey = new byte[32]; - System.arraycopy(keyIvCombo, 0, secretKey, 0, 32); - this.aeskey = secretKey; + this.aeskey = new byte[32]; + System.arraycopy(keyIvCombo, 0, aeskey, 0, 32); } else if (keyIvCombo.length >= 16) { - byte[] secretKey = new byte[16]; - System.arraycopy(keyIvCombo, 0, secretKey, 0, 16); - this.aeskey = secretKey; + this.aeskey = new byte[16]; + System.arraycopy(keyIvCombo, 0, this.aeskey, 0, 16); } } diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index be9d3d924..f6a45533f 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -773,11 +773,11 @@ public class Message extends AbstractEntity { public int height = 0; } - public void setAxolotlFingerprint(String fingerprint) { + public void setFingerprint(String fingerprint) { this.axolotlFingerprint = fingerprint; } - public String getAxolotlFingerprint() { + public String getFingerprint() { return axolotlFingerprint; } diff --git a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java index 42f2d8409..c4fc30abc 100644 --- a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java +++ b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java @@ -17,6 +17,7 @@ import org.json.JSONObject; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.forms.Data; +import eu.siacs.conversations.xmpp.forms.Field; import eu.siacs.conversations.xmpp.stanzas.IqPacket; public class ServiceDiscoveryResult { @@ -189,6 +190,19 @@ public class ServiceDiscoveryResult { return false; } + public String getExtendedDiscoInformation(String formType, String name) { + for(Data form : this.forms) { + if (formType.equals(form.getFormType())) { + for(Field field: form.getFields()) { + if (name.equals(field.getFieldName())) { + return field.getValue(); + } + } + } + } + return null; + } + protected byte[] mkCapHash() { StringBuilder s = new StringBuilder(); @@ -219,8 +233,22 @@ public class ServiceDiscoveryResult { }); for(Data form : forms) { - s.append(form.getFormType()+"<"); - //TODO append fields and values + s.append(form.getFormType() + "<"); + List<Field> fields = form.getFields(); + Collections.sort(fields, new Comparator<Field>() { + @Override + public int compare(Field lhs, Field rhs) { + return lhs.getFieldName().compareTo(rhs.getFieldName()); + } + }); + for(Field field : fields) { + s.append(field.getFieldName()+"<"); + List<String> values = field.getValues(); + Collections.sort(values); + for(String value : values) { + s.append(value+"<"); + } + } } MessageDigest md; diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 9470dab88..21bdbdf63 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -6,12 +6,12 @@ import android.util.Pair; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionStatus; -import java.net.URL; import java.util.ArrayList; import java.util.Set; import java.util.UUID; import eu.siacs.conversations.Config; +import eu.siacs.conversations.crypto.OtrService; import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage; import eu.siacs.conversations.entities.Account; @@ -95,8 +95,11 @@ public class MessageParser extends AbstractParser implements conversation.setSymmetricKey(CryptoHelper.hexToBytes(key)); return null; } + final OtrService otrService = conversation.getAccount().getOtrService(); Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR, Message.STATUS_RECEIVED); + finishedMessage.setFingerprint(otrService.getFingerprint(otrSession.getRemotePublicKey())); conversation.setLastReceivedOtrMessageId(null); + return finishedMessage; } catch (Exception e) { conversation.resetOtrSession(); @@ -111,7 +114,7 @@ public class MessageParser extends AbstractParser implements XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage); if(plaintextMessage != null) { finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status); - finishedMessage.setAxolotlFingerprint(plaintextMessage.getFingerprint()); + finishedMessage.setFingerprint(plaintextMessage.getFingerprint()); Log.d(Config.LOGTAG, AxolotlService.getLogprefix(finishedMessage.getConversation().getAccount())+" Received Message with session fingerprint: "+plaintextMessage.getFingerprint()); } @@ -408,8 +411,8 @@ public class MessageParser extends AbstractParser implements message.getStatus() == Message.STATUS_RECEIVED, message.isCarbon()); if (replacedMessage != null) { - final boolean fingerprintsMatch = replacedMessage.getAxolotlFingerprint() == null - || replacedMessage.getAxolotlFingerprint().equals(message.getAxolotlFingerprint()); + final boolean fingerprintsMatch = replacedMessage.getFingerprint() == null + || replacedMessage.getFingerprint().equals(message.getFingerprint()); final boolean trueCountersMatch = replacedMessage.getTrueCounterpart() != null && replacedMessage.getTrueCounterpart().equals(message.getTrueCounterpart()); if (fingerprintsMatch && (trueCountersMatch || conversation.getMode() == Conversation.MODE_SINGLE)) { diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index 2ce737968..04c532382 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -524,8 +524,10 @@ public class DatabaseBackend extends SQLiteOpenHelper { Cursor cursor = db.query(Conversation.TABLENAME, null, Conversation.ACCOUNT + "=? AND (" + Conversation.CONTACTJID + " like ? OR " + Conversation.CONTACTJID + "=?)", selectionArgs, null, null, null); - if (cursor.getCount() == 0) + if (cursor.getCount() == 0) { + cursor.close(); return null; + } cursor.moveToFirst(); Conversation conversation = Conversation.fromCursor(cursor); cursor.close(); @@ -575,12 +577,15 @@ public class DatabaseBackend extends SQLiteOpenHelper { try { cursor.moveToFirst(); int count = cursor.getInt(0); - cursor.close(); return (count > 0); } catch (SQLiteCantOpenDatabaseException e) { return true; // better safe than sorry } catch (RuntimeException e) { return true; // better safe than sorry + } finally { + if (cursor != null) { + cursor.close(); + } } } @@ -642,11 +647,12 @@ public class DatabaseBackend extends SQLiteOpenHelper { } public Pair<Long, String> getLastMessageReceived(Account account) { + Cursor cursor = null; try { SQLiteDatabase db = this.getReadableDatabase(); String sql = "select messages.timeSent,messages.serverMsgId from accounts join conversations on accounts.uuid=conversations.accountUuid join messages on conversations.uuid=messages.conversationUuid where accounts.uuid=? and (messages.status=0 or messages.carbon=1 or messages.serverMsgId not null) order by messages.timesent desc limit 1"; String[] args = {account.getUuid()}; - Cursor cursor = db.rawQuery(sql, args); + cursor = db.rawQuery(sql, args); if (cursor.getCount() == 0) { return null; } else { @@ -655,6 +661,10 @@ public class DatabaseBackend extends SQLiteOpenHelper { } } catch (Exception e) { return null; + } finally { + if (cursor != null) { + cursor.close(); + } } } diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 18c195f12..21ba45093 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -1,6 +1,8 @@ package eu.siacs.conversations.persistance; +import android.content.Context; import android.content.Intent; +import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -8,6 +10,7 @@ import android.graphics.Matrix; import android.graphics.RectF; import android.net.Uri; import android.os.Environment; +import android.provider.OpenableColumns; import android.util.Base64; import android.util.Base64OutputStream; import android.util.Log; @@ -28,6 +31,7 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; import java.util.Locale; import eu.siacs.conversations.Config; @@ -110,6 +114,27 @@ public class FileBackend { } } + private static long getFileSize(Context context, Uri uri) { + Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); + if (cursor != null && cursor.moveToFirst()) { + return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE)); + } else { + return -1; + } + } + + public static boolean allFilesUnderSize(Context context, List<Uri> uris, long max) { + if (max <= 0) { + return true; //exception to be compatible with HTTP Upload < v0.2 + } + for(Uri uri : uris) { + if (FileBackend.getFileSize(context, uri) > max) { + return false; + } + } + return true; + } + public static String getConversationsFileDirectory() { return Environment.getExternalStorageDirectory().getAbsolutePath()+"/Conversations/"; } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 477b72bab..877e8b439 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -847,8 +847,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa private void sendFileMessage(final Message message, final boolean delay) { Log.d(Config.LOGTAG, "send file message"); final Account account = message.getConversation().getAccount(); - final XmppConnection connection = account.getXmppConnection(); - if (connection != null && connection.getFeatures().httpUpload()) { + if (account.httpUploadAvailable(fileBackend.getFile(message,false).getSize())) { mHttpConnectionManager.createNewUploadConnection(message, delay); } else { mJingleConnectionManager.createNewConnection(message); @@ -885,7 +884,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa switch (message.getEncryption()) { case Message.ENCRYPTION_NONE: if (message.needsUploading()) { - if (account.httpUploadAvailable() || message.fixCounterpart()) { + if (account.httpUploadAvailable(fileBackend.getFile(message,false).getSize()) + || message.fixCounterpart()) { this.sendFileMessage(message, delay); } else { break; @@ -897,7 +897,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa case Message.ENCRYPTION_PGP: case Message.ENCRYPTION_DECRYPTED: if (message.needsUploading()) { - if (account.httpUploadAvailable() || message.fixCounterpart()) { + if (account.httpUploadAvailable(fileBackend.getFile(message,false).getSize()) + || message.fixCounterpart()) { this.sendFileMessage(message, delay); } else { break; @@ -931,9 +932,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } break; case Message.ENCRYPTION_AXOLOTL: - message.setAxolotlFingerprint(account.getAxolotlService().getOwnFingerprint()); + message.setFingerprint(account.getAxolotlService().getOwnFingerprint()); if (message.needsUploading()) { - if (account.httpUploadAvailable() || message.fixCounterpart()) { + if (account.httpUploadAvailable(fileBackend.getFile(message,false).getSize()) + || message.fixCounterpart()) { this.sendFileMessage(message, delay); } else { break; @@ -977,7 +979,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } break; case Message.ENCRYPTION_AXOLOTL: - message.setAxolotlFingerprint(account.getAxolotlService().getOwnFingerprint()); + message.setFingerprint(account.getAxolotlService().getOwnFingerprint()); break; } } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index f11a70f78..980e51441 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -58,6 +58,7 @@ import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.entities.Transferable; +import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate; @@ -1379,12 +1380,30 @@ public class ConversationActivity extends XmppActivity } } } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_FILE || requestCode == ATTACHMENT_CHOICE_RECORD_VOICE) { - mPendingFileUris.clear(); - mPendingFileUris.addAll(extractUriFromIntent(data)); - if (xmppConnectionServiceBound) { - for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) { - attachFileToConversation(getSelectedConversation(), i.next()); + final List<Uri> uris = extractUriFromIntent(data); + final Conversation c = getSelectedConversation(); + final long max = c.getAccount() + .getXmppConnection() + .getFeatures() + .getMaxHttpUploadSize(); + final OnPresenceSelected callback = new OnPresenceSelected() { + @Override + public void onPresenceSelected() { + mPendingFileUris.clear(); + mPendingFileUris.addAll(uris); + if (xmppConnectionServiceBound) { + for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) { + attachFileToConversation(c, i.next()); + } + } } + }; + if (c.getMode() == Conversation.MODE_MULTI + || FileBackend.allFilesUnderSize(this, uris, max) + || c.getNextEncryption() == Message.ENCRYPTION_OTR) { + callback.onPresenceSelected(); + } else { + selectPresence(c, callback); } } else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) { if (mPendingImageUris.size() == 1) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index db34d1df3..c43059170 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -468,13 +468,13 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa highlightInConference(user); } } else { - activity.switchToContactDetails(message.getContact(), message.getAxolotlFingerprint()); + activity.switchToContactDetails(message.getContact(), message.getFingerprint()); } } else { Account account = message.getConversation().getAccount(); Intent intent = new Intent(activity, EditAccountActivity.class); intent.putExtra("jid", account.getJid().toBareJid().toString()); - intent.putExtra("fingerprint", message.getAxolotlFingerprint()); + intent.putExtra("fingerprint", message.getFingerprint()); startActivity(intent); } } diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 10c6b685d..787c325ae 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -688,7 +688,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } else { this.mServerInfoPep.setText(R.string.server_info_unavailable); } - if (features.httpUpload()) { + if (features.httpUpload(0)) { this.mServerInfoHttpUpload.setText(R.string.server_info_available); } else { this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable); diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java index ae7220817..8cd017bf6 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java @@ -24,6 +24,7 @@ import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.ui.adapter.ConversationAdapter; import eu.siacs.conversations.xmpp.jid.InvalidJidException; @@ -259,6 +260,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } private void share(final Conversation conversation) { + final Account account = conversation.getAccount(); mListView.setEnabled(false); if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP && !hasPgp()) { if (share.uuid == null) { @@ -270,6 +272,9 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer return; } if (share.uris.size() != 0) { + final long max = account.getXmppConnection() + .getFeatures() + .getMaxHttpUploadSize(); OnPresenceSelected callback = new OnPresenceSelected() { @Override public void onPresenceSelected() { @@ -290,7 +295,11 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } } }; - if (conversation.getAccount().httpUploadAvailable()) { + if (account.httpUploadAvailable() + && ((share.image && !neverCompressPictures()) + || conversation.getMode() == Conversation.MODE_MULTI + || FileBackend.allFilesUnderSize(this, share.uris, max)) + && conversation.getNextEncryption() != Message.ENCRYPTION_OTR) { callback.onPresenceSelected(); } else { selectPresence(conversation, callback); diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index a9f95a5b3..646c9d3f4 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -1005,6 +1005,10 @@ public abstract class XmppActivity extends Activity { } } + protected boolean neverCompressPictures() { + return getPreferences().getString("picture_compression", "auto").equals("never"); + } + protected void unregisterNdefPushMessageCallback() { NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); if (nfcAdapter != null && nfcAdapter.isEnabled()) { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 85ee8d771..d69fa4b95 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -204,7 +204,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { XmppAxolotlSession.Trust trust = message.getConversation() .getAccount().getAxolotlService().getFingerprintTrust( - message.getAxolotlFingerprint()); + message.getFingerprint()); if(trust == null || (!trust.trusted() && !trust.trustedInactive())) { viewHolder.indicator.setColorFilter(activity.getWarningTextColor()); diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index f639d3fac..eea0b5627 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1346,12 +1346,12 @@ public class XmppConnection implements Runnable { this.streamId = null; } - public List<Jid> findDiscoItemsByFeature(final String feature) { + private List<Entry<Jid, ServiceDiscoveryResult>> findDiscoItemsByFeature(final String feature) { synchronized (this.disco) { - final List<Jid> items = new ArrayList<>(); + final List<Entry<Jid, ServiceDiscoveryResult>> items = new ArrayList<>(); for (final Entry<Jid, ServiceDiscoveryResult> cursor : this.disco.entrySet()) { if (cursor.getValue().getFeatures().contains(feature)) { - items.add(cursor.getKey()); + items.add(cursor); } } return items; @@ -1359,9 +1359,9 @@ public class XmppConnection implements Runnable { } public Jid findDiscoItemByFeature(final String feature) { - final List<Jid> items = findDiscoItemsByFeature(feature); + final List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(feature); if (items.size() >= 1) { - return items.get(0); + return items.get(0).getKey(); } return null; } @@ -1505,7 +1505,6 @@ public class XmppConnection implements Runnable { public boolean pep() { synchronized (XmppConnection.this.disco) { - final Pair<String, String> needle = new Pair<>("pubsub", "pep"); ServiceDiscoveryResult info = disco.get(account.getServer()); if (info != null && info.hasIdentity("pubsub", "pep")) { return true; @@ -1534,8 +1533,35 @@ public class XmppConnection implements Runnable { this.blockListRequested = value; } - public boolean httpUpload() { - return !Config.DISABLE_HTTP_UPLOAD && findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD).size() > 0; + public boolean httpUpload(long filesize) { + if (Config.DISABLE_HTTP_UPLOAD) { + return false; + } else { + List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD); + if (items.size() > 0) { + try { + long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Xmlns.HTTP_UPLOAD, "max-file-size")); + return filesize <= maxsize; + } catch (Exception e) { + return true; + } + } else { + return false; + } + } + } + + public long getMaxHttpUploadSize() { + List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD); + if (items.size() > 0) { + try { + return Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Xmlns.HTTP_UPLOAD, "max-file-size")); + } catch (Exception e) { + return -1; + } + } else { + return -1; + } } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java index 380f02808..8dabcb5be 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java +++ b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java @@ -9,6 +9,8 @@ import eu.siacs.conversations.xml.Element; public class Data extends Element { + private static final String FORM_TYPE = "FORM_TYPE"; + public Data() { super("x"); this.setAttribute("xmlns","jabber:x:data"); @@ -17,7 +19,8 @@ public class Data extends Element { public List<Field> getFields() { ArrayList<Field> fields = new ArrayList<Field>(); for(Element child : getChildren()) { - if (child.getName().equals("field")) { + if (child.getName().equals("field") + && !FORM_TYPE.equals(child.getAttribute("var"))) { fields.add(Field.parse(child)); } } @@ -26,7 +29,8 @@ public class Data extends Element { public Field getFieldByName(String needle) { for(Element child : getChildren()) { - if (child.getName().equals("field") && needle.equals(child.getAttribute("var"))) { + if (child.getName().equals("field") + && needle.equals(child.getAttribute("var"))) { return Field.parse(child); } } @@ -76,11 +80,11 @@ public class Data extends Element { } public void setFormType(String formType) { - this.put("FORM_TYPE", formType); + this.put(FORM_TYPE, formType); } public String getFormType() { - String type = getValue("FORM_TYPE"); + String type = getValue(FORM_TYPE); return type == null ? "" : type; } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index e3eec6471..beed92fa5 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -378,7 +378,7 @@ public class JingleConnection implements Transferable { message.setEncryption(Message.ENCRYPTION_AXOLOTL); this.file.setKey(transportMessage.getKey()); this.file.setIv(transportMessage.getIv()); - message.setAxolotlFingerprint(transportMessage.getFingerprint()); + message.setFingerprint(transportMessage.getFingerprint()); } else { Log.d(Config.LOGTAG,"could not process KeyTransportMessage"); } |