From d42ea45b1c7356793aa55edf55baeaaf4cd3398f Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Mon, 1 Sep 2014 13:51:49 +0200 Subject: fixed #403 --- src/eu/siacs/conversations/utils/XmlHelper.java | 12 ++++++++++++ src/eu/siacs/conversations/xml/Element.java | 13 +++---------- src/eu/siacs/conversations/xml/Tag.java | 4 +++- 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 src/eu/siacs/conversations/utils/XmlHelper.java (limited to 'src/eu') diff --git a/src/eu/siacs/conversations/utils/XmlHelper.java b/src/eu/siacs/conversations/utils/XmlHelper.java new file mode 100644 index 00000000..4dee07cf --- /dev/null +++ b/src/eu/siacs/conversations/utils/XmlHelper.java @@ -0,0 +1,12 @@ +package eu.siacs.conversations.utils; + +public class XmlHelper { + public static String encodeEntities(String content) { + content = content.replace("&", "&"); + content = content.replace("<", "<"); + content = content.replace(">", ">"); + content = content.replace("\"", """); + content = content.replace("'", "'"); + return content; + } +} diff --git a/src/eu/siacs/conversations/xml/Element.java b/src/eu/siacs/conversations/xml/Element.java index 3d22ba6a..cc21a780 100644 --- a/src/eu/siacs/conversations/xml/Element.java +++ b/src/eu/siacs/conversations/xml/Element.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import eu.siacs.conversations.utils.XmlHelper; + public class Element { protected String name; protected Hashtable attributes = new Hashtable(); @@ -116,7 +118,7 @@ public class Element { startTag.setAtttributes(this.attributes); elementOutput.append(startTag); if (content != null) { - elementOutput.append(encodeEntities(content)); + elementOutput.append(XmlHelper.encodeEntities(content)); } else { for (Element child : children) { elementOutput.append(child.toString()); @@ -132,15 +134,6 @@ public class Element { return name; } - private String encodeEntities(String content) { - content = content.replace("&", "&"); - content = content.replace("<", "<"); - content = content.replace(">", ">"); - content = content.replace("\"", """); - content = content.replace("'", "'"); - return content; - } - public void clearChildren() { this.children.clear(); } diff --git a/src/eu/siacs/conversations/xml/Tag.java b/src/eu/siacs/conversations/xml/Tag.java index 2d5ffdbc..a9eecad6 100644 --- a/src/eu/siacs/conversations/xml/Tag.java +++ b/src/eu/siacs/conversations/xml/Tag.java @@ -5,6 +5,8 @@ import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; +import eu.siacs.conversations.utils.XmlHelper; + public class Tag { public static final int NO = -1; public static final int START = 0; @@ -84,7 +86,7 @@ public class Tag { tagOutput.append(' '); tagOutput.append(entry.getKey()); tagOutput.append("=\""); - tagOutput.append(entry.getValue()); + tagOutput.append(XmlHelper.encodeEntities(entry.getValue())); tagOutput.append('"'); } } -- cgit v1.2.3 From c62937016b08b2335af78cdc7b46093cc96c3956 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 2 Sep 2014 11:19:05 +0200 Subject: rotate avatars Conflicts: src/eu/siacs/conversations/persistance/FileBackend.java --- .../conversations/persistance/FileBackend.java | 92 +++++++++++++--------- 1 file changed, 55 insertions(+), 37 deletions(-) (limited to 'src/eu') diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index 8fdc7ee7..d8166040 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -44,8 +44,9 @@ public class FileBackend { private Context context; private LruCache thumbnailCache; - - private SimpleDateFormat imageDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS",Locale.US); + + private SimpleDateFormat imageDateFormat = new SimpleDateFormat( + "yyyyMMdd_HHmmssSSS", Locale.US); public FileBackend(Context context) { this.context = context; @@ -85,14 +86,15 @@ public class FileBackend { } return new JingleFile(path + "/" + filename); } - + public JingleFile getJingleFile(Message message) { return getJingleFile(message, true); } public JingleFile getJingleFile(Message message, boolean decrypted) { StringBuilder filename = new StringBuilder(); - filename.append(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()); + filename.append(Environment.getExternalStoragePublicDirectory( + Environment.DIRECTORY_PICTURES).getAbsolutePath()); filename.append("/Conversations/"); filename.append(message.getUuid()); if ((decrypted) || (message.getEncryption() == Message.ENCRYPTION_NONE)) { @@ -106,7 +108,7 @@ public class FileBackend { } return new JingleFile(filename.toString()); } - + public Bitmap resize(Bitmap originalBitmap, int size) { int w = originalBitmap.getWidth(); int h = originalBitmap.getHeight(); @@ -144,7 +146,8 @@ public class FileBackend { private JingleFile copyImageToPrivateStorage(Message message, Uri image, int sampleSize) throws ImageCopyException { try { - InputStream is = context.getContentResolver().openInputStream(image); + InputStream is = context.getContentResolver() + .openInputStream(image); JingleFile file = getJingleFile(message); file.getParentFile().mkdirs(); file.createNewFile(); @@ -194,17 +197,23 @@ public class FileBackend { } } } - + private int getRotation(Uri image) { if ("content".equals(image.getScheme())) { - Cursor cursor = context.getContentResolver().query(image, - new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); - - if (cursor.getCount() != 1) { - return -1; - } - cursor.moveToFirst(); - return cursor.getInt(0); + try { + Cursor cursor = context + .getContentResolver() + .query(image, + new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, + null, null, null); + if (cursor.getCount() != 1) { + return -1; + } + cursor.moveToFirst(); + return cursor.getInt(0); + } catch (IllegalArgumentException e) { + return -1; + } } else { ExifInterface exif; try { @@ -273,28 +282,32 @@ public class FileBackend { public Uri getTakePhotoUri() { StringBuilder pathBuilder = new StringBuilder(); - pathBuilder.append(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)); + pathBuilder.append(Environment + .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)); pathBuilder.append('/'); pathBuilder.append("Camera"); pathBuilder.append('/'); - pathBuilder.append("IMG_"+this.imageDateFormat.format(new Date())+".jpg"); - Uri uri = Uri.parse("file://"+pathBuilder.toString()); + pathBuilder.append("IMG_" + this.imageDateFormat.format(new Date()) + + ".jpg"); + Uri uri = Uri.parse("file://" + pathBuilder.toString()); File file = new File(uri.toString()); file.getParentFile().mkdirs(); return uri; } - + public Avatar getPepAvatar(Uri image, int size, Bitmap.CompressFormat format) { try { Avatar avatar = new Avatar(); Bitmap bm = cropCenterSquare(image, size); - if (bm==null) { + if (bm == null) { return null; } ByteArrayOutputStream mByteArrayOutputStream = new ByteArrayOutputStream(); - Base64OutputStream mBase64OutputSttream = new Base64OutputStream(mByteArrayOutputStream, Base64.DEFAULT); + Base64OutputStream mBase64OutputSttream = new Base64OutputStream( + mByteArrayOutputStream, Base64.DEFAULT); MessageDigest digest = MessageDigest.getInstance("SHA-1"); - DigestOutputStream mDigestOutputStream = new DigestOutputStream(mBase64OutputSttream, digest); + DigestOutputStream mDigestOutputStream = new DigestOutputStream( + mBase64OutputSttream, digest); if (!bm.compress(format, 75, mDigestOutputStream)) { return null; } @@ -309,25 +322,26 @@ public class FileBackend { return null; } } - + public boolean isAvatarCached(Avatar avatar) { File file = new File(getAvatarPath(context, avatar.getFilename())); return file.exists(); } - + public boolean save(Avatar avatar) { if (isAvatarCached(avatar)) { return true; } String filename = getAvatarPath(context, avatar.getFilename()); - File file = new File(filename+".tmp"); + File file = new File(filename + ".tmp"); file.getParentFile().mkdirs(); try { file.createNewFile(); FileOutputStream mFileOutputStream = new FileOutputStream(file); MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.reset(); - DigestOutputStream mDigestOutputStream = new DigestOutputStream(mFileOutputStream, digest); + DigestOutputStream mDigestOutputStream = new DigestOutputStream( + mFileOutputStream, digest); mDigestOutputStream.write(avatar.getImageAsBytes()); mDigestOutputStream.flush(); mDigestOutputStream.close(); @@ -337,7 +351,7 @@ public class FileBackend { file.renameTo(new File(filename)); return true; } else { - Log.d("xmppService","sha1sum mismatch for "+avatar.owner); + Log.d("xmppService", "sha1sum mismatch for " + avatar.owner); file.delete(); return false; } @@ -349,9 +363,9 @@ public class FileBackend { return false; } } - + public static String getAvatarPath(Context context, String avatar) { - return context.getFilesDir().getAbsolutePath() + "/avatars/"+avatar; + return context.getFilesDir().getAbsolutePath() + "/avatars/" + avatar; } public Bitmap cropCenterSquare(Uri image, int size) { @@ -361,16 +375,20 @@ public class FileBackend { InputStream is = context.getContentResolver() .openInputStream(image); Bitmap input = BitmapFactory.decodeStream(is, null, options); - if (input==null) { + if (input == null) { return null; } else { + int rotation = getRotation(image); + if (rotation > 0) { + input = rotate(input, rotation); + } return cropCenterSquare(input, size); } } catch (FileNotFoundException e) { return null; } } - + public static Bitmap cropCenterSquare(Bitmap input, int size) { int w = input.getWidth(); int h = input.getHeight(); @@ -381,8 +399,7 @@ public class FileBackend { float outHeight = scale * h; float left = (size - outWidth) / 2; float top = (size - outHeight) / 2; - RectF target = new RectF(left, top, left + outWidth, top - + outHeight); + RectF target = new RectF(left, top, left + outWidth, top + outHeight); Bitmap output = Bitmap.createBitmap(size, size, input.getConfig()); Canvas canvas = new Canvas(output); @@ -412,11 +429,11 @@ public class FileBackend { return inSampleSize; } - + public Uri getJingleFileUri(Message message) { File file = getJingleFile(message); if (file.exists()) { - return Uri.parse("file://"+file.getAbsolutePath()); + return Uri.parse("file://" + file.getAbsolutePath()); } else { return ImageProvider.getProviderUri(message); } @@ -436,8 +453,9 @@ public class FileBackend { } public static Bitmap getAvatar(String avatar, int size, Context context) { - Bitmap bm = BitmapFactory.decodeFile(FileBackend.getAvatarPath(context, avatar)); - if (bm==null) { + Bitmap bm = BitmapFactory.decodeFile(FileBackend.getAvatarPath(context, + avatar)); + if (bm == null) { return null; } return cropCenterSquare(bm, UIHelper.getRealPx(size, context)); -- cgit v1.2.3 From 567827ffcaba46e062a8d087392d780c377d282f Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 2 Sep 2014 11:26:56 +0200 Subject: fixed #406 --- src/eu/siacs/conversations/ui/ShareWithActivity.java | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/eu') diff --git a/src/eu/siacs/conversations/ui/ShareWithActivity.java b/src/eu/siacs/conversations/ui/ShareWithActivity.java index 461aaec4..57b4ba31 100644 --- a/src/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/eu/siacs/conversations/ui/ShareWithActivity.java @@ -100,11 +100,9 @@ public class ShareWithActivity extends XmppActivity { }); for (final Conversation conversation : convList) { if (!isImage || conversation.getMode() == Conversation.MODE_SINGLE) { - View view = createContactView( - conversation.getName(useSubject), + View view = createContactView(conversation.getName(useSubject), conversation.getLatestMessage().getBody().trim(), - UIHelper.getContactPicture(conversation, 48, - this.getApplicationContext(), false)); + conversation.getImage(getApplicationContext(), 48)); view.setOnClickListener(new OnClickListener() { @Override @@ -136,19 +134,17 @@ public class ShareWithActivity extends XmppActivity { }); for (int i = 0; i < contactsList.size(); ++i) { - final Contact con = contactsList.get(i); - View view = createContactView( - con.getDisplayName(), - con.getJid(), - UIHelper.getContactPicture(con, 48, - this.getApplicationContext(), false)); + final Contact contact = contactsList.get(i); + View view = createContactView(contact.getDisplayName(), + contact.getJid(), + contact.getImage(48, getApplicationContext())); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Conversation conversation = xmppConnectionService - .findOrCreateConversation(con.getAccount(), - con.getJid(), false); + .findOrCreateConversation(contact.getAccount(), + contact.getJid(), false); share(conversation); } }); -- cgit v1.2.3 From f1494f83ff7dd9c7d0ebdb176d36293f42297988 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 3 Sep 2014 13:05:22 +0200 Subject: fixed pgp signature creation --- src/eu/siacs/conversations/crypto/PgpEngine.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/eu') diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java index 65b7ccc7..7b5ef905 100644 --- a/src/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/eu/siacs/conversations/crypto/PgpEngine.java @@ -292,9 +292,25 @@ public class PgpEngine { switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, 0)) { case OpenPgpApi.RESULT_CODE_SUCCESS: StringBuilder signatureBuilder = new StringBuilder(); - String[] lines = os.toString().split("\n"); - for (int i = 7; i < lines.length - 1; ++i) { - signatureBuilder.append(lines[i].trim()); + try { + os.flush(); + String[] lines = os.toString().split("\n"); + boolean sig = false; + for(String line : lines) { + if (sig) { + if (line.contains("END PGP SIGNATURE")) { + sig = false; + } else { + signatureBuilder.append(line.trim()); + } + } + if (line.contains("BEGIN PGP SIGNATURE")) { + sig = true; + } + } + } catch (IOException e) { + callback.error(R.string.openpgp_error, account); + return; } account.setKey("pgp_signature", signatureBuilder.toString()); callback.success(account); -- cgit v1.2.3 From 2b941d19f8cc9a517806a27d1ac976afbaa1677a Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 3 Sep 2014 15:33:44 +0200 Subject: more openpgp bug fixes --- src/eu/siacs/conversations/crypto/PgpEngine.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/eu') diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java index 7b5ef905..d8222ac5 100644 --- a/src/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/eu/siacs/conversations/crypto/PgpEngine.java @@ -168,8 +168,10 @@ public class PgpEngine { os.flush(); StringBuilder encryptedMessageBody = new StringBuilder(); String[] lines = os.toString().split("\n"); - for (int i = 3; i < lines.length - 1; ++i) { - encryptedMessageBody.append(lines[i].trim()); + for (int i = 2; i < lines.length - 1; ++i) { + if (!lines[i].contains("Version")) { + encryptedMessageBody.append(lines[i].trim()); + } } message.setEncryptedBody(encryptedMessageBody .toString()); @@ -301,7 +303,9 @@ public class PgpEngine { if (line.contains("END PGP SIGNATURE")) { sig = false; } else { - signatureBuilder.append(line.trim()); + if (!line.contains("Version")) { + signatureBuilder.append(line.trim()); + } } } if (line.contains("BEGIN PGP SIGNATURE")) { -- cgit v1.2.3