version 1.5.0 #11

Merged
kriztan merged 103 commits from development into master 6 years ago
  1. 10
      CHANGELOG.md
  2. 9
      README.md
  3. 6
      build.gradle
  4. 4
      src/main/java/eu/siacs/conversations/Config.java
  5. 20
      src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
  6. 2
      src/main/java/eu/siacs/conversations/crypto/sasl/ScramSha1.java
  7. 4
      src/main/java/eu/siacs/conversations/entities/Account.java
  8. 28
      src/main/java/eu/siacs/conversations/entities/Downloadable.java
  9. 17
      src/main/java/eu/siacs/conversations/entities/DownloadableFile.java
  10. 274
      src/main/java/eu/siacs/conversations/entities/Message.java
  11. 3
      src/main/java/eu/siacs/conversations/entities/Roster.java
  12. 28
      src/main/java/eu/siacs/conversations/entities/Transferable.java
  13. 9
      src/main/java/eu/siacs/conversations/entities/TransferablePlaceholder.java
  14. 12
      src/main/java/eu/siacs/conversations/generator/IqGenerator.java
  15. 22
      src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
  16. 74
      src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java
  17. 135
      src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
  18. 204
      src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java
  19. 15
      src/main/java/eu/siacs/conversations/parser/MessageParser.java
  20. 3
      src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
  21. 20
      src/main/java/eu/siacs/conversations/persistance/FileBackend.java
  22. 12
      src/main/java/eu/siacs/conversations/services/AvatarService.java
  23. 54
      src/main/java/eu/siacs/conversations/services/NotificationService.java
  24. 337
      src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
  25. 8
      src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
  26. 3
      src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
  27. 206
      src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
  28. 138
      src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
  29. 23
      src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
  30. 74
      src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
  31. 10
      src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
  32. 35
      src/main/java/eu/siacs/conversations/ui/XmppActivity.java
  33. 4
      src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java
  34. 9
      src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
  35. 52
      src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
  36. 4
      src/main/java/eu/siacs/conversations/utils/CryptoHelper.java
  37. 2
      src/main/java/eu/siacs/conversations/utils/DNSHelper.java
  38. 2
      src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java
  39. 14
      src/main/java/eu/siacs/conversations/utils/GeoHelper.java
  40. 487
      src/main/java/eu/siacs/conversations/utils/MimeUtils.java
  41. 41
      src/main/java/eu/siacs/conversations/utils/UIHelper.java
  42. 1
      src/main/java/eu/siacs/conversations/utils/Xmlns.java
  43. 38
      src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
  44. 53
      src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
  45. 13
      src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
  46. 4
      src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
  47. 2
      src/main/res/drawable/es_slidingpane_shadow.xml
  48. 2
      src/main/res/drawable/grey.xml
  49. 4
      src/main/res/drawable/infocard_border.xml
  50. 2
      src/main/res/drawable/message_border.xml
  51. 2
      src/main/res/drawable/snackbar.xml
  52. 6
      src/main/res/layout-w945dp/fragment_conversations_overview.xml
  53. 8
      src/main/res/layout/account_row.xml
  54. 4
      src/main/res/layout/actionview_search.xml
  55. 4
      src/main/res/layout/activity_about.xml
  56. 22
      src/main/res/layout/activity_change_password.xml
  57. 46
      src/main/res/layout/activity_contact_details.xml
  58. 79
      src/main/res/layout/activity_edit_account.xml
  59. 21
      src/main/res/layout/activity_muc_details.xml
  60. 22
      src/main/res/layout/activity_publish_profile_picture.xml
  61. 2
      src/main/res/layout/activity_start_conversation.xml
  62. 24
      src/main/res/layout/activity_verify_otr.xml
  63. 14
      src/main/res/layout/contact.xml
  64. 4
      src/main/res/layout/contact_key.xml
  65. 16
      src/main/res/layout/conversation_list_row.xml
  66. 8
      src/main/res/layout/create_contact_dialog.xml
  67. 14
      src/main/res/layout/fragment_conversation.xml
  68. 6
      src/main/res/layout/fragment_conversations_overview.xml
  69. 8
      src/main/res/layout/join_conference_dialog.xml
  70. 2
      src/main/res/layout/list_item_tag.xml
  71. 4
      src/main/res/layout/manage_accounts.xml
  72. 17
      src/main/res/layout/message_received.xml
  73. 17
      src/main/res/layout/message_sent.xml
  74. 7
      src/main/res/layout/message_status.xml
  75. 2
      src/main/res/layout/quickedit.xml
  76. 7
      src/main/res/menu/conversations.xml
  77. 20
      src/main/res/menu/message_context.xml
  78. 2
      src/main/res/values-ar-rEG/strings.xml
  79. 10
      src/main/res/values-bg/strings.xml
  80. 5
      src/main/res/values-ca/strings.xml
  81. 10
      src/main/res/values-cs/strings.xml
  82. 10
      src/main/res/values-de/strings.xml
  83. 5
      src/main/res/values-el/strings.xml
  84. 10
      src/main/res/values-es/strings.xml
  85. 10
      src/main/res/values-eu/strings.xml
  86. 5
      src/main/res/values-fr/strings.xml
  87. 1
      src/main/res/values-gl/strings.xml
  88. 5
      src/main/res/values-id/strings.xml
  89. 5
      src/main/res/values-it/strings.xml
  90. 1
      src/main/res/values-iw/strings.xml
  91. 5
      src/main/res/values-ja/strings.xml
  92. 5
      src/main/res/values-ko/strings.xml
  93. 2
      src/main/res/values-ms/strings.xml
  94. 8
      src/main/res/values-nl/strings.xml
  95. 5
      src/main/res/values-pl/strings.xml
  96. 297
      src/main/res/values-pt/strings.xml
  97. 1
      src/main/res/values-ro-rRO/strings.xml
  98. 5
      src/main/res/values-ru/strings.xml
  99. 13
      src/main/res/values-sk/strings.xml
  100. 10
      src/main/res/values-sr/strings.xml

10
CHANGELOG.md

@ -1,5 +1,15 @@
###Changelog
####Version 1.5.0
* upload files to HTTP host and share them in MUCs. requires new [HttpUploadComponent](https://github.com/siacs/HttpUploadComponent) on server side
####Version 1.4.5
* fixes to message parser to not display some ejabberd muc status messages
####Version 1.4.4
* added unread count badges on supported devices
* rewrote message parser
####Version 1.4.0
* send button turns into quick action button to offer faster access to take photo, send location or record audio
* visually seperate merged messages

9
README.md

@ -42,6 +42,8 @@ run your own XMPP server for you and your friends. These XEP's are:
* XEP-0065: SOCKS5 Bytestreams (or mod_proxy65). Will be used to transfer
files if both parties are behind a firewall (NAT).
* XEP-0163: Personal Eventing Protocol for avatars
* XEP-0191: Blocking command lets you blacklist spammers or block contacts
without removing them from your roster.
* XEP-0198: Stream Management allows XMPP to survive small network outages and
changes of the underlying TCP connection.
* XEP-0280: Message Carbons which automatically syncs the messages you send to
@ -54,8 +56,9 @@ run your own XMPP server for you and your friends. These XEP's are:
* XEP-0352: Client State Indication lets the server know whether or not
Conversations is in the background. Allows the server to save bandwidth by
withholding unimportant packages.
* XEP-0191: Blocking command lets you blacklist spammers or block contacts
without removing them from your roster.
* XEP-xxxx: HttpUpload allows you to share files in conferences and with offline
contacts. Requires an [additional component](https://github.com/siacs/HttpUploadComponent)
on your server.
## Team
@ -252,7 +255,7 @@ decrypting and encrypting takes longer than OTR. It is however asynchronous and
works well with message carbons.
To use OpenPGP you have to install the open source app
[OpenKeychain](www.openkeychain.org) and then long press on the account in
[OpenKeychain](http://www.openkeychain.org) and then long press on the account in
manage accounts and choose renew PGP announcement from the contextual menu.
#### How does the encryption for conferences work?

6
build.gradle

@ -45,9 +45,9 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 74
versionName "1.4.6"
}
versionCode 78
versionName "1.5.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7

4
src/main/java/eu/siacs/conversations/Config.java

@ -16,7 +16,7 @@ public final class Config {
public static final int CARBON_GRACE_PERIOD = 60;
public static final int MINI_GRACE_PERIOD = 750;
public static final int AVATAR_SIZE = 192;
public static final int AVATAR_SIZE = 384;
public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP;
public static final int MESSAGE_MERGE_WINDOW = 20;
@ -32,6 +32,8 @@ public final class Config {
public static final boolean EXTENDED_SM_LOGGING = true; // log stanza counts
public static final boolean RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE = true; //setting to true might increase power consumption
public static final boolean ENCRYPT_ON_HTTP_UPLOADED = false;
public static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
public static final long MAM_MAX_CATCHUP = MILLISECONDS_IN_DAY / 2;
public static final int MAM_MAX_MESSAGES = 500;

20
src/main/java/eu/siacs/conversations/crypto/PgpEngine.java

@ -59,9 +59,9 @@ public class PgpEngine {
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
final HttpConnectionManager manager = mXmppConnectionService.getHttpConnectionManager();
if (message.trusted()
&& message.bodyContainsDownloadable()
&& message.treatAsDownloadable() != Message.Decision.NEVER
&& manager.getAutoAcceptFileSize() > 0) {
manager.createNewConnection(message);
manager.createNewDownloadConnection(message);
}
callback.success(message);
}
@ -98,7 +98,7 @@ public class PgpEngine {
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
URL url = message.getImageParams().url;
URL url = message.getFileParams().url;
mXmppConnectionService.getFileBackend().updateFileParams(message,url);
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
PgpEngine.this.mXmppConnectionService
@ -143,11 +143,15 @@ public class PgpEngine {
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message
.getConversation().getAccount().getJid().toBareJid().toString());
if (message.getType() == Message.TYPE_TEXT) {
if (!message.needsUploading()) {
params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
InputStream is = new ByteArrayInputStream(message.getBody()
.getBytes());
String body;
if (message.hasFileOnRemoteHost()) {
body = message.getFileParams().url.toString();
} else {
body = message.getBody();
}
InputStream is = new ByteArrayInputStream(body.getBytes());
final OutputStream os = new ByteArrayOutputStream();
api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
@ -184,7 +188,7 @@ public class PgpEngine {
}
}
});
} else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
} else {
try {
DownloadableFile inputFile = this.mXmppConnectionService
.getFileBackend().getFile(message, true);

2
src/main/java/eu/siacs/conversations/crypto/sasl/ScramSha1.java

@ -185,7 +185,7 @@ public class ScramSha1 extends SaslMechanism {
case RESPONSE_SENT:
final String clientCalculatedServerFinalMessage = "v=" +
Base64.encodeToString(serverSignature, Base64.NO_WRAP);
if (!clientCalculatedServerFinalMessage.equals(new String(Base64.decode(challenge, Base64.DEFAULT)))) {
if (challenge == null || !clientCalculatedServerFinalMessage.equals(new String(Base64.decode(challenge, Base64.DEFAULT)))) {
throw new AuthenticationException("Server final message does not match calculated final message");
}
state = State.VALID_SERVER_RESPONSE;

4
src/main/java/eu/siacs/conversations/entities/Account.java

@ -44,6 +44,10 @@ public class Account extends AbstractEntity {
public static final int OPTION_REGISTER = 2;
public static final int OPTION_USECOMPRESSION = 3;
public boolean httpUploadAvailable() {
return xmppConnection != null && xmppConnection.getFeatures().httpUpload();
}
public static enum State {
DISABLED,
OFFLINE,

28
src/main/java/eu/siacs/conversations/entities/Downloadable.java

@ -1,28 +0,0 @@
package eu.siacs.conversations.entities;
public interface Downloadable {
public final String[] VALID_IMAGE_EXTENSIONS = {"webp", "jpeg", "jpg", "png", "jpe"};
public final String[] VALID_CRYPTO_EXTENSIONS = {"pgp", "gpg", "otr"};
public static final int STATUS_UNKNOWN = 0x200;
public static final int STATUS_CHECKING = 0x201;
public static final int STATUS_FAILED = 0x202;
public static final int STATUS_OFFER = 0x203;
public static final int STATUS_DOWNLOADING = 0x204;
public static final int STATUS_DELETED = 0x205;
public static final int STATUS_OFFER_CHECK_FILESIZE = 0x206;
public static final int STATUS_UPLOADING = 0x207;
public boolean start();
public int getStatus();
public long getFileSize();
public int getProgress();
public String getMimeType();
public void cancel();
}

17
src/main/java/eu/siacs/conversations/entities/DownloadableFile.java

@ -20,6 +20,8 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.MimeUtils;
import android.util.Log;
public class DownloadableFile extends File {
@ -56,16 +58,11 @@ public class DownloadableFile extends File {
public String getMimeType() {
String path = this.getAbsolutePath();
try {
String mime = URLConnection.guessContentTypeFromName(path.replace("#",""));
if (mime != null) {
return mime;
} else if (mime == null && path.endsWith(".webp")) {
return "image/webp";
} else {
return "";
}
} catch (final StringIndexOutOfBoundsException e) {
int start = path.lastIndexOf('.') + 1;
if (start < path.length()) {
String mime = MimeUtils.guessMimeTypeFromExtension(path.substring(start));
return mime == null ? "" : mime;
} else {
return "";
}
}

274
src/main/java/eu/siacs/conversations/entities/Message.java

@ -9,6 +9,7 @@ import java.util.Arrays;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.MimeUtils;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
@ -69,7 +70,7 @@ public class Message extends AbstractEntity {
protected String remoteMsgId = null;
protected String serverMsgId = null;
protected Conversation conversation = null;
protected Downloadable downloadable = null;
protected Transferable transferable = null;
private Message mNextMessage = null;
private Message mPreviousMessage = null;
@ -307,12 +308,12 @@ public class Message extends AbstractEntity {
this.trueCounterpart = trueCounterpart;
}
public Downloadable getDownloadable() {
return this.downloadable;
public Transferable getTransferable() {
return this.transferable;
}
public void setDownloadable(Downloadable downloadable) {
this.downloadable = downloadable;
public void setTransferable(Transferable transferable) {
this.transferable = transferable;
}
public boolean equals(Message message) {
@ -320,15 +321,25 @@ public class Message extends AbstractEntity {
return this.serverMsgId.equals(message.getServerMsgId());
} else if (this.body == null || this.counterpart == null) {
return false;
} else if (message.getRemoteMsgId() != null) {
return (message.getRemoteMsgId().equals(this.remoteMsgId) || message.getRemoteMsgId().equals(this.uuid))
&& this.counterpart.equals(message.getCounterpart())
&& this.body.equals(message.getBody());
} else {
return this.remoteMsgId == null
&& this.counterpart.equals(message.getCounterpart())
&& this.body.equals(message.getBody())
&& Math.abs(this.getTimeSent() - message.getTimeSent()) < Config.MESSAGE_MERGE_WINDOW * 1000;
String body, otherBody;
if (this.hasFileOnRemoteHost()) {
body = getFileParams().url.toString();
otherBody = message.body == null ? null : message.body.trim();
} else {
body = this.body;
otherBody = message.body;
}
if (message.getRemoteMsgId() != null) {
return (message.getRemoteMsgId().equals(this.remoteMsgId) || message.getRemoteMsgId().equals(this.uuid))
&& this.counterpart.equals(message.getCounterpart())
&& body.equals(otherBody);
} else {
return this.remoteMsgId == null
&& this.counterpart.equals(message.getCounterpart())
&& body.equals(otherBody)
&& Math.abs(this.getTimeSent() - message.getTimeSent()) < Config.MESSAGE_MERGE_WINDOW * 1000;
}
}
}
@ -363,8 +374,8 @@ public class Message extends AbstractEntity {
public boolean mergeable(final Message message) {
return message != null &&
(message.getType() == Message.TYPE_TEXT &&
this.getDownloadable() == null &&
message.getDownloadable() == null &&
this.getTransferable() == null &&
message.getTransferable() == null &&
message.getEncryption() != Message.ENCRYPTION_PGP &&
this.getType() == message.getType() &&
//this.getStatus() == message.getStatus() &&
@ -375,8 +386,8 @@ public class Message extends AbstractEntity {
(message.getTimeSent() - this.getTimeSent()) <= (Config.MESSAGE_MERGE_WINDOW * 1000) &&
!GeoHelper.isGeoUri(message.getBody()) &&
!GeoHelper.isGeoUri(this.body) &&
!message.bodyContainsDownloadable() &&
!this.bodyContainsDownloadable() &&
message.treatAsDownloadable() == Decision.NEVER &&
this.treatAsDownloadable() == Decision.NEVER &&
!message.getBody().startsWith(ME_COMMAND) &&
!this.getBody().startsWith(ME_COMMAND) &&
!this.bodyIsHeart() &&
@ -434,48 +445,97 @@ public class Message extends AbstractEntity {
return (status > STATUS_RECEIVED || (contact != null && contact.trusted()));
}
public boolean bodyContainsDownloadable() {
/**
* there are a few cases where spaces result in an unwanted behavior, e.g.
* "http://example.com/image.jpg text that will not be shown /abc.png"
* or more than one image link in one message.
*/
if (body.trim().contains(" ")) {
public boolean fixCounterpart() {
Presences presences = conversation.getContact().getPresences();
if (counterpart != null && presences.has(counterpart.getResourcepart())) {
return true;
} else if (presences.size() >= 1) {
try {
counterpart = Jid.fromParts(conversation.getJid().getLocalpart(),
conversation.getJid().getDomainpart(),
presences.asStringArray()[0]);
return true;
} catch (InvalidJidException e) {
counterpart = null;
return false;
}
} else {
counterpart = null;
return false;
}
}
public enum Decision {
MUST,
SHOULD,
NEVER,
}
private static String extractRelevantExtension(URL url) {
String path = url.getPath();
if (path == null || path.isEmpty()) {
return null;
}
String filename = path.substring(path.lastIndexOf('/') + 1).toLowerCase();
String[] extensionParts = filename.split("\\.");
if (extensionParts.length == 2) {
return extensionParts[extensionParts.length - 1];
} else if (extensionParts.length == 3 && Arrays
.asList(Transferable.VALID_CRYPTO_EXTENSIONS)
.contains(extensionParts[extensionParts.length - 1])) {
return extensionParts[extensionParts.length -2];
}
return null;
}
public String getMimeType() {
if (relativeFilePath != null) {
int start = relativeFilePath.lastIndexOf('.') + 1;
if (start < relativeFilePath.length()) {
return MimeUtils.guessMimeTypeFromExtension(relativeFilePath.substring(start));
} else {
return null;
}
} else {
try {
return MimeUtils.guessMimeTypeFromExtension(extractRelevantExtension(new URL(body.trim())));
} catch (MalformedURLException e) {
return null;
}
}
}
public Decision treatAsDownloadable() {
if (body.trim().contains(" ")) {
return Decision.NEVER;
}
try {
URL url = new URL(body);
if (!url.getProtocol().equalsIgnoreCase("http")
&& !url.getProtocol().equalsIgnoreCase("https")) {
return false;
if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
return Decision.NEVER;
}
String sUrlPath = url.getPath();
if (sUrlPath == null || sUrlPath.isEmpty()) {
return false;
String extension = extractRelevantExtension(url);
if (extension == null) {
return Decision.NEVER;
}
String ref = url.getRef();
boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}");
int iSlashIndex = sUrlPath.lastIndexOf('/') + 1;
String sLastUrlPath = sUrlPath.substring(iSlashIndex).toLowerCase();
String[] extensionParts = sLastUrlPath.split("\\.");
if (extensionParts.length == 2
&& Arrays.asList(Downloadable.VALID_IMAGE_EXTENSIONS).contains(
extensionParts[extensionParts.length - 1])) {
return true;
} else if (extensionParts.length == 3
&& Arrays
.asList(Downloadable.VALID_CRYPTO_EXTENSIONS)
.contains(extensionParts[extensionParts.length - 1])
&& Arrays.asList(Downloadable.VALID_IMAGE_EXTENSIONS).contains(
extensionParts[extensionParts.length - 2])) {
return true;
if (encrypted) {
if (MimeUtils.guessMimeTypeFromExtension(extension) != null) {
return Decision.MUST;
} else {
return Decision.NEVER;
}
} else if (Arrays.asList(Transferable.VALID_IMAGE_EXTENSIONS).contains(extension)
|| Arrays.asList(Transferable.WELL_KNOWN_EXTENSIONS).contains(extension)) {
return Decision.SHOULD;
} else {
return false;
return Decision.NEVER;
}
} catch (MalformedURLException e) {
return false;
return Decision.NEVER;
}
}
@ -483,74 +543,77 @@ public class Message extends AbstractEntity {
return body != null && UIHelper.HEARTS.contains(body.trim());
}
public ImageParams getImageParams() {
ImageParams params = getLegacyImageParams();
public FileParams getFileParams() {
FileParams params = getLegacyFileParams();
if (params != null) {
return params;
}
params = new ImageParams();
if (this.downloadable != null) {
params.size = this.downloadable.getFileSize();
params = new FileParams();
if (this.transferable != null) {
params.size = this.transferable.getFileSize();
}
if (body == null) {
return params;
}
String parts[] = body.split("\\|");
if (parts.length == 1) {
try {
params.size = Long.parseLong(parts[0]);
} catch (NumberFormatException e) {
params.origin = parts[0];
switch (parts.length) {
case 1:
try {
params.size = Long.parseLong(parts[0]);
} catch (NumberFormatException e) {
try {
params.url = new URL(parts[0]);
} catch (MalformedURLException e1) {
params.url = null;
}
}
break;
case 2:
case 4:
try {
params.url = new URL(parts[0]);
} catch (MalformedURLException e1) {
params.url = null;
}
}
} else if (parts.length == 3) {
try {
params.size = Long.parseLong(parts[0]);
} catch (NumberFormatException e) {
params.size = 0;
}
try {
params.width = Integer.parseInt(parts[1]);
} catch (NumberFormatException e) {
params.width = 0;
}
try {
params.height = Integer.parseInt(parts[2]);
} catch (NumberFormatException e) {
params.height = 0;
}
} else if (parts.length == 4) {
params.origin = parts[0];
try {
params.url = new URL(parts[0]);
} catch (MalformedURLException e1) {
params.url = null;
}
try {
params.size = Long.parseLong(parts[1]);
} catch (NumberFormatException e) {
params.size = 0;
}
try {
params.width = Integer.parseInt(parts[2]);
} catch (NumberFormatException e) {
params.width = 0;
}
try {
params.height = Integer.parseInt(parts[3]);
} catch (NumberFormatException e) {
params.height = 0;
}
try {
params.size = Long.parseLong(parts[1]);
} catch (NumberFormatException e) {
params.size = 0;
}
try {
params.width = Integer.parseInt(parts[2]);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
params.width = 0;
}
try {
params.height = Integer.parseInt(parts[3]);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
params.height = 0;
}
break;
case 3:
try {
params.size = Long.parseLong(parts[0]);
} catch (NumberFormatException e) {
params.size = 0;
}
try {
params.width = Integer.parseInt(parts[1]);
} catch (NumberFormatException e) {
params.width = 0;
}
try {
params.height = Integer.parseInt(parts[2]);
} catch (NumberFormatException e) {
params.height = 0;
}
break;
}
return params;
}
public ImageParams getLegacyImageParams() {
ImageParams params = new ImageParams();
public FileParams getLegacyFileParams() {
FileParams params = new FileParams();
if (body == null) {
return params;
}
@ -586,11 +649,18 @@ public class Message extends AbstractEntity {
return type == TYPE_FILE || type == TYPE_IMAGE;
}
public class ImageParams {
public boolean hasFileOnRemoteHost() {
return isFileOrImage() && getFileParams().url != null;
}
public boolean needsUploading() {
return isFileOrImage() && getFileParams().url == null;
}
public class FileParams {
public URL url;
public long size = 0;
public int width = 0;
public int height = 0;
public String origin;
}
}

3
src/main/java/eu/siacs/conversations/entities/Roster.java

@ -74,6 +74,9 @@ public class Roster {
}
public void initContact(final Contact contact) {
if (contact == null) {
return;
}
contact.setAccount(account);
contact.setOption(Contact.Options.IN_ROSTER);
synchronized (this.contacts) {

28
src/main/java/eu/siacs/conversations/entities/Transferable.java

@ -0,0 +1,28 @@
package eu.siacs.conversations.entities;
public interface Transferable {
String[] VALID_IMAGE_EXTENSIONS = {"webp", "jpeg", "jpg", "png", "jpe"};
String[] VALID_CRYPTO_EXTENSIONS = {"pgp", "gpg", "otr"};
String[] WELL_KNOWN_EXTENSIONS = {"pdf","m4a","mp3","avi","mp4","apk","vcf"};
int STATUS_UNKNOWN = 0x200;
int STATUS_CHECKING = 0x201;
int STATUS_FAILED = 0x202;
int STATUS_OFFER = 0x203;
int STATUS_DOWNLOADING = 0x204;
int STATUS_DELETED = 0x205;
int STATUS_OFFER_CHECK_FILESIZE = 0x206;
int STATUS_UPLOADING = 0x207;
boolean start();
int getStatus();
long getFileSize();
int getProgress();
void cancel();
}

9
src/main/java/eu/siacs/conversations/entities/DownloadablePlaceholder.java → src/main/java/eu/siacs/conversations/entities/TransferablePlaceholder.java

@ -1,10 +1,10 @@
package eu.siacs.conversations.entities;
public class DownloadablePlaceholder implements Downloadable {
public class TransferablePlaceholder implements Transferable {
private int status;
public DownloadablePlaceholder(int status) {
public TransferablePlaceholder(int status) {
this.status = status;
}
@Override
@ -27,11 +27,6 @@ public class DownloadablePlaceholder implements Downloadable {
return 0;
}
@Override
public String getMimeType() {
return "";
}
@Override
public void cancel() {

12
src/main/java/eu/siacs/conversations/generator/IqGenerator.java

@ -6,6 +6,7 @@ import java.util.List;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.services.MessageArchiveService;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.PhoneHelper;
@ -102,7 +103,7 @@ public class IqGenerator extends AbstractGenerator {
public IqPacket retrieveVcardAvatar(final Avatar avatar) {
final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
packet.setTo(avatar.owner);
packet.addChild("vCard","vcard-temp");
packet.addChild("vCard", "vcard-temp");
return packet;
}
@ -194,4 +195,13 @@ public class IqGenerator extends AbstractGenerator {
item.setAttribute("role", role);
return packet;
}
public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file) {
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("size").setContent(String.valueOf(file.getExpectedSize()));
return packet;
}
}

22
src/main/java/eu/siacs/conversations/generator/MessageGenerator.java

@ -73,7 +73,13 @@ public class MessageGenerator extends AbstractGenerator {
packet.addChild("no-copy", "urn:xmpp:hints");
packet.addChild("no-permanent-store", "urn:xmpp:hints");
try {
packet.setBody(otrSession.transformSending(message.getBody())[0]);
String content;
if (message.hasFileOnRemoteHost()) {
content = message.getFileParams().url.toString();
} else {
content = message.getBody();
}
packet.setBody(otrSession.transformSending(content)[0]);
return packet;
} catch (OtrException e) {
return null;
@ -86,7 +92,11 @@ public class MessageGenerator extends AbstractGenerator {
public MessagePacket generateChat(Message message, boolean addDelay) {
MessagePacket packet = preparePacket(message, addDelay);
packet.setBody(message.getBody());
if (message.hasFileOnRemoteHost()) {
packet.setBody(message.getFileParams().url.toString());
} else {
packet.setBody(message.getBody());
}
return packet;
}
@ -96,13 +106,11 @@ public class MessageGenerator extends AbstractGenerator {
public MessagePacket generatePgpChat(Message message, boolean addDelay) {
MessagePacket packet = preparePacket(message, addDelay);
packet.setBody("This is an XEP-0027 encryted message");
packet.setBody("This is an XEP-0027 encrypted message");
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
packet.addChild("x", "jabber:x:encrypted").setContent(
message.getEncryptedBody());
packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody());
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
packet.addChild("x", "jabber:x:encrypted").setContent(
message.getBody());
packet.addChild("x", "jabber:x:encrypted").setContent(message.getBody());
}
return packet;
}

74
src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java

@ -1,11 +1,22 @@
package eu.siacs.conversations.http;
import org.apache.http.conn.ssl.StrictHostnameVerifier;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.AbstractConnectionManager;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
public class HttpConnectionManager extends AbstractConnectionManager {
@ -13,16 +24,67 @@ public class HttpConnectionManager extends AbstractConnectionManager {
super(service);
}
private List<HttpConnection> connections = new CopyOnWriteArrayList<HttpConnection>();
private List<HttpDownloadConnection> downloadConnections = new CopyOnWriteArrayList<>();
private List<HttpUploadConnection> uploadConnections = new CopyOnWriteArrayList<>();
public HttpDownloadConnection createNewDownloadConnection(Message message) {
return this.createNewDownloadConnection(message, false);
}
public HttpDownloadConnection createNewDownloadConnection(Message message, boolean interactive) {
HttpDownloadConnection connection = new HttpDownloadConnection(this);
connection.init(message,interactive);
this.downloadConnections.add(connection);
return connection;
}
public HttpConnection createNewConnection(Message message) {
HttpConnection connection = new HttpConnection(this);
public HttpUploadConnection createNewUploadConnection(Message message) {
HttpUploadConnection connection = new HttpUploadConnection(this);
connection.init(message);
this.connections.add(connection);
this.uploadConnections.add(connection);
return connection;
}
public void finishConnection(HttpConnection connection) {
this.connections.remove(connection);
public void finishConnection(HttpDownloadConnection connection) {
this.downloadConnections.remove(connection);
}
public void finishUploadConnection(HttpUploadConnection httpUploadConnection) {
this.uploadConnections.remove(httpUploadConnection);
}
public void setupTrustManager(final HttpsURLConnection connection, final boolean interactive) {
final X509TrustManager trustManager;
final HostnameVerifier hostnameVerifier;
if (interactive) {
trustManager = mXmppConnectionService.getMemorizingTrustManager();
hostnameVerifier = mXmppConnectionService
.getMemorizingTrustManager().wrapHostnameVerifier(
new StrictHostnameVerifier());
} else {
trustManager = mXmppConnectionService.getMemorizingTrustManager()
.getNonInteractive();
hostnameVerifier = mXmppConnectionService
.getMemorizingTrustManager()
.wrapHostnameVerifierNonInteractive(
new StrictHostnameVerifier());
}
try {
final SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new X509TrustManager[]{trustManager},
mXmppConnectionService.getRNG());
final SSLSocketFactory sf = sc.getSocketFactory();
final String[] cipherSuites = CryptoHelper.getOrderedCipherSuites(
sf.getSupportedCipherSuites());
if (cipherSuites.length > 0) {
sc.getDefaultSSLParameters().setCipherSuites(cipherSuites);
}
connection.setSSLSocketFactory(sf);
connection.setHostnameVerifier(hostnameVerifier);
} catch (final KeyManagementException | NoSuchAlgorithmException ignored) {
}
}
}

135
src/main/java/eu/siacs/conversations/http/HttpConnection.java → src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java

@ -3,8 +3,7 @@ package eu.siacs.conversations.http;
import android.content.Intent;
import android.net.Uri;
import android.os.SystemClock;
import org.apache.http.conn.ssl.StrictHostnameVerifier;
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.IOException;
@ -12,25 +11,20 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Transferable;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
public class HttpConnection implements Downloadable {
public class HttpDownloadConnection implements Transferable {
private HttpConnectionManager mHttpConnectionManager;
private XmppConnectionService mXmppConnectionService;
@ -38,12 +32,12 @@ public class HttpConnection implements Downloadable {
private URL mUrl;
private Message message;
private DownloadableFile file;
private int mStatus = Downloadable.STATUS_UNKNOWN;
private int mStatus = Transferable.STATUS_UNKNOWN;
private boolean acceptedAutomatically = false;
private int mProgress = 0;
private long mLastGuiRefresh = 0;
public HttpConnection(HttpConnectionManager manager) {
public HttpDownloadConnection(HttpConnectionManager manager) {
this.mHttpConnectionManager = manager;
this.mXmppConnectionService = manager.getXmppConnectionService();
}
@ -63,8 +57,12 @@ public class HttpConnection implements Downloadable {
}
public void init(Message message) {
init(message, false);
}
public void init(Message message, boolean interactive) {
this.message = message;
this.message.setDownloadable(this);
this.message.setTransferable(this);
try {
mUrl = new URL(message.getBody());
String[] parts = mUrl.getPath().toLowerCase().split("\\.");
@ -92,7 +90,7 @@ public class HttpConnection implements Downloadable {
&& this.file.getKey() == null) {
this.message.setEncryption(Message.ENCRYPTION_NONE);
}
checkFileSize(false);
checkFileSize(interactive);
} catch (MalformedURLException e) {
this.cancel();
}
@ -104,7 +102,7 @@ public class HttpConnection implements Downloadable {
public void cancel() {
mHttpConnectionManager.finishConnection(this);
message.setDownloadable(null);
message.setTransferable(null);
mXmppConnectionService.updateConversationUi();
}
@ -112,7 +110,7 @@ public class HttpConnection implements Downloadable {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
mXmppConnectionService.sendBroadcast(intent);
message.setDownloadable(null);
message.setTransferable(null);
mHttpConnectionManager.finishConnection(this);
mXmppConnectionService.updateConversationUi();
if (acceptedAutomatically) {
@ -125,42 +123,6 @@ public class HttpConnection implements Downloadable {
mXmppConnectionService.updateConversationUi();
}
private void setupTrustManager(final HttpsURLConnection connection,
final boolean interactive) {
final X509TrustManager trustManager;
final HostnameVerifier hostnameVerifier;
if (interactive) {
trustManager = mXmppConnectionService.getMemorizingTrustManager();
hostnameVerifier = mXmppConnectionService
.getMemorizingTrustManager().wrapHostnameVerifier(
new StrictHostnameVerifier());
} else {
trustManager = mXmppConnectionService.getMemorizingTrustManager()
.getNonInteractive();
hostnameVerifier = mXmppConnectionService
.getMemorizingTrustManager()
.wrapHostnameVerifierNonInteractive(
new StrictHostnameVerifier());
}
try {
final SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new X509TrustManager[]{trustManager},
mXmppConnectionService.getRNG());
final SSLSocketFactory sf = sc.getSocketFactory();
final String[] cipherSuites = CryptoHelper.getOrderedCipherSuites(
sf.getSupportedCipherSuites());
if (cipherSuites.length > 0) {
sc.getDefaultSSLParameters().setCipherSuites(cipherSuites);
}
connection.setSSLSocketFactory(sf);
connection.setHostnameVerifier(hostnameVerifier);
} catch (final KeyManagementException | NoSuchAlgorithmException ignored) {
}
}
private class FileSizeChecker implements Runnable {
private boolean interactive = false;
@ -176,43 +138,46 @@ public class HttpConnection implements Downloadable {
size = retrieveFileSize();
} catch (SSLHandshakeException e) {
changeStatus(STATUS_OFFER_CHECK_FILESIZE);
HttpConnection.this.acceptedAutomatically = false;
HttpConnection.this.mXmppConnectionService.getNotificationService().push(message);
HttpDownloadConnection.this.acceptedAutomatically = false;
HttpDownloadConnection.this.mXmppConnectionService.getNotificationService().push(message);
return;
} catch (IOException e) {
Log.d(Config.LOGTAG, "io exception in http file size checker: " + e.getMessage());
if (interactive) {
mXmppConnectionService.showErrorToastInUi(R.string.file_not_found_on_remote_host);
}
cancel();
return;
}
file.setExpectedSize(size);
if (size <= mHttpConnectionManager.getAutoAcceptFileSize()) {
HttpConnection.this.acceptedAutomatically = true;
HttpDownloadConnection.this.acceptedAutomatically = true;
new Thread(new FileDownloader(interactive)).start();
} else {
changeStatus(STATUS_OFFER);
HttpConnection.this.acceptedAutomatically = false;
HttpConnection.this.mXmppConnectionService.getNotificationService().push(message);
HttpDownloadConnection.this.acceptedAutomatically = false;
HttpDownloadConnection.this.mXmppConnectionService.getNotificationService().push(message);
}
}
private long retrieveFileSize() throws IOException,
SSLHandshakeException {
changeStatus(STATUS_CHECKING);
HttpURLConnection connection = (HttpURLConnection) mUrl
.openConnection();
connection.setRequestMethod("HEAD");
if (connection instanceof HttpsURLConnection) {
setupTrustManager((HttpsURLConnection) connection, interactive);
}
connection.connect();
String contentLength = connection.getHeaderField("Content-Length");
if (contentLength == null) {
throw new IOException();
}
try {
return Long.parseLong(contentLength, 10);
} catch (NumberFormatException e) {
throw new IOException();
}
private long retrieveFileSize() throws IOException {
Log.d(Config.LOGTAG,"retrieve file size. interactive:"+String.valueOf(interactive));
changeStatus(STATUS_CHECKING);
HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection();
connection.setRequestMethod("HEAD");
if (connection instanceof HttpsURLConnection) {
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
}
connection.connect();
String contentLength = connection.getHeaderField("Content-Length");
if (contentLength == null) {
throw new IOException();
}
try {
return Long.parseLong(contentLength, 10);
} catch (NumberFormatException e) {
throw new IOException();
}
}
}
@ -235,19 +200,18 @@ public class HttpConnection implements Downloadable {
} catch (SSLHandshakeException e) {
changeStatus(STATUS_OFFER);
} catch (IOException e) {
mXmppConnectionService.showErrorToastInUi(R.string.file_not_found_on_remote_host);
cancel();
}
}
private void download() throws SSLHandshakeException, IOException {
HttpURLConnection connection = (HttpURLConnection) mUrl
.openConnection();
HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection();
if (connection instanceof HttpsURLConnection) {
setupTrustManager((HttpsURLConnection) connection, interactive);
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
}
connection.connect();
BufferedInputStream is = new BufferedInputStream(
connection.getInputStream());
BufferedInputStream is = new BufferedInputStream(connection.getInputStream());
file.getParentFile().mkdirs();
file.createNewFile();
OutputStream os = file.createOutputStream();
@ -269,8 +233,8 @@ public class HttpConnection implements Downloadable {
}
private void updateImageBounds() {
message.setType(Message.TYPE_IMAGE);
mXmppConnectionService.getFileBackend().updateFileParams(message,mUrl);
message.setType(Message.TYPE_FILE);
mXmppConnectionService.getFileBackend().updateFileParams(message, mUrl);
mXmppConnectionService.updateMessage(message);
}
@ -302,9 +266,4 @@ public class HttpConnection implements Downloadable {
public int getProgress() {
return this.mProgress;
}
@Override
public String getMimeType() {
return "";
}
}

204
src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java

@ -0,0 +1,204 @@
package eu.siacs.conversations.http;
import android.app.PendingIntent;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Transferable;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.UiCallback;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.Xmlns;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class HttpUploadConnection implements Transferable {
private HttpConnectionManager mHttpConnectionManager;
private XmppConnectionService mXmppConnectionService;
private boolean canceled = false;
private Account account;
private DownloadableFile file;
private Message message;
private URL mGetUrl;
private URL mPutUrl;
private byte[] key = null;
private long transmitted = 0;
private long expected = 1;
public HttpUploadConnection(HttpConnectionManager httpConnectionManager) {
this.mHttpConnectionManager = httpConnectionManager;
this.mXmppConnectionService = httpConnectionManager.getXmppConnectionService();
}
@Override
public boolean start() {
return false;
}
@Override
public int getStatus() {
return STATUS_UPLOADING;
}
@Override
public long getFileSize() {
return this.file.getExpectedSize();
}
@Override
public int getProgress() {
return (int) ((((double) transmitted) / expected) * 100);
}
@Override
public void cancel() {
this.canceled = true;
}
private void fail() {
mHttpConnectionManager.finishUploadConnection(this);
message.setTransferable(null);
mXmppConnectionService.markMessage(message,Message.STATUS_SEND_FAILED);
}
public void init(Message message) {
this.message = message;
message.setTransferable(this);
mXmppConnectionService.markMessage(message,Message.STATUS_UNSEND);
this.account = message.getConversation().getAccount();
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
this.file.setExpectedSize(this.file.getSize());
if (Config.ENCRYPT_ON_HTTP_UPLOADED) {
this.key = new byte[48];
mXmppConnectionService.getRNG().nextBytes(this.key);
this.file.setKey(this.key);
}
Jid host = account.getXmppConnection().findDiscoItemByFeature(Xmlns.HTTP_UPLOAD);
IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host,file);
mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
Element slot = packet.findChild("slot",Xmlns.HTTP_UPLOAD);
if (slot != null) {
try {
mGetUrl = new URL(slot.findChildContent("get"));
mPutUrl = new URL(slot.findChildContent("put"));
if (!canceled) {
new Thread(new FileUploader()).start();
}
} catch (MalformedURLException e) {
fail();
}
} else {
fail();
}
} else {
fail();
}
}
});
}
private class FileUploader implements Runnable {
@Override
public void run() {
this.upload();
}
private void upload() {
OutputStream os = null;
InputStream is = null;
HttpURLConnection connection = null;
try {
Log.d(Config.LOGTAG, "uploading to " + mPutUrl.toString());
connection = (HttpURLConnection) mPutUrl.openConnection();
if (connection instanceof HttpsURLConnection) {
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, true);
}
connection.setRequestMethod("PUT");
connection.setFixedLengthStreamingMode((int) file.getExpectedSize());
connection.setDoOutput(true);
connection.connect();
os = connection.getOutputStream();
is = file.createInputStream();
transmitted = 0;
expected = file.getExpectedSize();
int count = -1;
byte[] buffer = new byte[4096];
while (((count = is.read(buffer)) != -1) && !canceled) {
transmitted += count;
os.write(buffer, 0, count);
mXmppConnectionService.updateConversationUi();
}
os.flush();
os.close();
is.close();
int code = connection.getResponseCode();
if (code == 200) {
Log.d(Config.LOGTAG, "finished uploading file");
Message.FileParams params = message.getFileParams();
if (key != null) {
mGetUrl = new URL(mGetUrl.toString() + "#" + CryptoHelper.bytesToHex(key));
}
mXmppConnectionService.getFileBackend().updateFileParams(message, mGetUrl);
message.setTransferable(null);
message.setCounterpart(message.getConversation().getJid().toBareJid());
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
mXmppConnectionService.getPgpEngine().encrypt(message, new UiCallback<Message>() {
@Override
public void success(Message message) {
mXmppConnectionService.resendMessage(message);
}
@Override
public void error(int errorCode, Message object) {
fail();
}
@Override
public void userInputRequried(PendingIntent pi, Message object) {
fail();
}
});
} else {
mXmppConnectionService.resendMessage(message);
}
} else {
fail();
}
} catch (IOException e) {
Log.d(Config.LOGTAG, e.getMessage());
fail();
} finally {
FileBackend.close(is);
FileBackend.close(os);
if (connection != null) {
connection.disconnect();
}
}
}
}
}

15
src/main/java/eu/siacs/conversations/parser/MessageParser.java

@ -239,6 +239,12 @@ public class MessageParser extends AbstractParser implements
final Jid to = packet.getTo();
final Jid from = packet.getFrom();
final String remoteMsgId = packet.getId();
if (from == null || to == null) {
Log.d(Config.LOGTAG,"no to or from in: "+packet.toString());
return;
}
boolean isTypeGroupChat = packet.getType() == MessagePacket.TYPE_GROUPCHAT;
boolean isProperlyAddressed = !to.isBareJid() || account.countPresences() == 1;
boolean isMucStatusMessage = from.isBareJid() && mucUserElement != null && mucUserElement.hasChild("status");
@ -250,11 +256,6 @@ public class MessageParser extends AbstractParser implements
counterpart = from;
}
if (from == null || to == null) {
Log.d(Config.LOGTAG,"no to or from in: "+packet.toString());
return;
}
Invite invite = extractInvite(packet);
if (invite != null && invite.execute(account)) {
return;
@ -360,8 +361,8 @@ public class MessageParser extends AbstractParser implements
mXmppConnectionService.databaseBackend.createMessage(message);
}
final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager();
if (message.trusted() && message.bodyContainsDownloadable() && manager.getAutoAcceptFileSize() > 0) {
manager.createNewConnection(message);
if (message.trusted() && message.treatAsDownloadable() != Message.Decision.NEVER && manager.getAutoAcceptFileSize() > 0) {
manager.createNewDownloadConnection(message);
} else if (!message.isRead()) {
mXmppConnectionService.getNotificationService().push(message);
}

3
src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java

@ -386,8 +386,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
SQLiteDatabase db = this.getReadableDatabase();