aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Account.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/DownloadableFile.java20
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Message.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/ServiceDiscoveryResult.java32
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java16
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java20
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java29
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java12
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java36
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java42
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java12
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java2
17 files changed, 196 insertions, 53 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Account.java b/src/main/java/de/thedevstack/conversationsplus/entities/Account.java
index f7dee013..bc956364 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Account.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Account.java
@@ -55,8 +55,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/de/thedevstack/conversationsplus/entities/DownloadableFile.java b/src/main/java/de/thedevstack/conversationsplus/entities/DownloadableFile.java
index 424d0301..101475c3 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/DownloadableFile.java
+++ b/src/main/java/de/thedevstack/conversationsplus/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/de/thedevstack/conversationsplus/entities/Message.java b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
index 39fcdfb2..6a6a5e50 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
@@ -710,11 +710,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/de/thedevstack/conversationsplus/entities/ServiceDiscoveryResult.java b/src/main/java/de/thedevstack/conversationsplus/entities/ServiceDiscoveryResult.java
index cfba7c4f..562d95b7 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/ServiceDiscoveryResult.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/ServiceDiscoveryResult.java
@@ -17,6 +17,7 @@ import org.json.JSONObject;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.forms.Data;
+import de.thedevstack.conversationsplus.xmpp.forms.Field;
import de.thedevstack.conversationsplus.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/de/thedevstack/conversationsplus/parser/MessageParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
index 6bb47aa4..c65df887 100644
--- a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
+++ b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
@@ -16,6 +16,7 @@ import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.utils.AvatarUtil;
import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.crypto.OtrService;
import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlService;
import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlServiceImpl;
import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlMessage;
@@ -102,8 +103,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();
@@ -118,7 +122,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());
Logging.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(finishedMessage.getConversation().getAccount())+" Received Message with session fingerprint: "+plaintextMessage.getFingerprint());
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
index ea7edb99..4157d6f8 100644
--- a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
+++ b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
@@ -525,8 +525,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();
@@ -576,12 +578,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();
+ }
}
}
@@ -643,11 +648,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 {
@@ -656,6 +662,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
} catch (Exception e) {
return null;
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
index 6e07f49c..d92401ba 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
@@ -818,8 +818,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private void sendFileMessage(final Message message, final boolean delay) {
Logging.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);
@@ -856,7 +855,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;
@@ -868,7 +868,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;
@@ -902,9 +903,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;
@@ -948,7 +950,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
break;
case Message.ENCRYPTION_AXOLOTL:
- message.setAxolotlFingerprint(account.getAxolotlService().getOwnFingerprint());
+ message.setFingerprint(account.getAxolotlService().getOwnFingerprint());
break;
}
}
@@ -2564,9 +2566,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (unreadCount != count) {
Logging.d(Config.LOGTAG, "update unread count to " + count);
if (count > 0) {
- ShortcutBadger.with(getApplicationContext()).count(count);
+ ShortcutBadger.applyCount(getApplicationContext(), count);
} else {
- ShortcutBadger.with(getApplicationContext()).remove();
+ ShortcutBadger.removeCount(getApplicationContext());
}
unreadCount = count;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
index c78d5951..5942bac6 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
@@ -66,6 +66,7 @@ import de.thedevstack.conversationsplus.services.XmppConnectionService.OnConvers
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnRosterUpdate;
import de.thedevstack.conversationsplus.ui.adapter.ConversationAdapter;
import de.thedevstack.conversationsplus.utils.ExceptionHelper;
+import de.thedevstack.conversationsplus.utils.FileUtils;
import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -1306,12 +1307,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
+ || FileUtils.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/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
index 5a8bd3db..7c5f6ffa 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
@@ -466,13 +466,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/de/thedevstack/conversationsplus/ui/EditAccountActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
index abb43c4e..2b8e619f 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
@@ -691,7 +691,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/de/thedevstack/conversationsplus/ui/ShareWithActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
index 3446bfbd..51fe92bb 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
@@ -28,8 +28,10 @@ import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
+import de.thedevstack.conversationsplus.persistance.FileBackend;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.ui.adapter.ConversationAdapter;
+import de.thedevstack.conversationsplus.utils.FileUtils;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -263,6 +265,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) {
@@ -274,6 +277,9 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
return;
}
if (share.uris.size() != 0) {
+ final long max = account.getXmppConnection()
+ .getFeatures()
+ .getMaxHttpUploadSize();
OnPresenceSelected callback;
if (this.share.image) {
// TODO: attachementCounter should be set and decremented correctly
@@ -299,7 +305,11 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
}
};
}
- if (conversation.getAccount().httpUploadAvailable()) {
+ if (account.httpUploadAvailable()
+ && ((share.image && !neverCompressPictures())
+ || conversation.getMode() == Conversation.MODE_MULTI
+ || FileUtils.allFilesUnderSize(this, share.uris, max))
+ && conversation.getNextEncryption() != Message.ENCRYPTION_OTR) {
callback.onPresenceSelected();
} else {
selectPresence(conversation, callback);
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
index f7856a9c..f2ee20a0 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
@@ -957,6 +957,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/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
index 9311674b..b2dca6b9 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
@@ -197,7 +197,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(ConversationsPlusColors.warning());
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java b/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java
index d1ac2d34..3ee15f70 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java
@@ -10,8 +10,10 @@ import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
+import android.provider.OpenableColumns;
import java.io.File;
+import java.util.List;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
@@ -187,6 +189,40 @@ public final class FileUtils {
return secondToLastPart;
}
+ /**
+ * Retrieve file size from given uri
+ * @param context actual Context
+ * @param uri uri to file
+ * @return file size or -1 in case of error
+ */
+ 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;
+ }
+ }
+
+ /**
+ * Check for given list of uris if corresponding file sizes are all smaller than given maximum
+ * @param context actual Context
+ * @param uris list of uris
+ * @param max maximum file size
+ * @return true if all file sizes are smaller than max, false otherwise
+ */
+ 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 (getFileSize(context, uri) > max) {
+ return false;
+ }
+ }
+ return true;
+ }
+
private FileUtils() {
// Utility class - do not instantiate
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
index 9036bf8d..58352d4f 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
@@ -1317,12 +1317,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;
@@ -1330,9 +1330,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;
}
@@ -1481,7 +1481,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;
@@ -1510,8 +1509,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/de/thedevstack/conversationsplus/xmpp/forms/Data.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java
index cb612a07..caa1890e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java
@@ -9,6 +9,8 @@ import de.thedevstack.conversationsplus.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/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java
index 618d75ee..b4c05ce4 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java
@@ -381,7 +381,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 {
Logging.d(Config.LOGTAG,"could not process KeyTransportMessage");
}