diff --git a/src/foundation/pEp/jniadapter/AbstractEngine.java b/src/foundation/pEp/jniadapter/AbstractEngine.java index 496c118..fa45755 100644 --- a/src/foundation/pEp/jniadapter/AbstractEngine.java +++ b/src/foundation/pEp/jniadapter/AbstractEngine.java @@ -29,7 +29,7 @@ abstract class AbstractEngine extends UniquelyIdentifiable implements AbstractEn } final public void close() { - synchronized (AbstractEngine.class){ + synchronized (AbstractEngine.class) { release(); } } @@ -75,110 +75,10 @@ abstract class AbstractEngine extends UniquelyIdentifiable implements AbstractEn private native boolean _isSyncRunning(); - public static byte[] toUTF8(String str) { - if (str == null) - return null; - - try { - String _str = Normalizer.normalize(str, Normalizer.Form.NFC); - byte _buf[] = _str.getBytes("UTF-8"); - byte _cpy[] = new byte[_buf.length]; - System.arraycopy(_buf,0,_cpy,0,_buf.length); - return _cpy; - } - catch (UnsupportedEncodingException e) { - assert false; - return new byte[0]; - } - } - - public static Vector toUTF8(Vector list) { - if (list == null) - return null; - - Vector result = new Vector(list.size()); - - for (int i=0; i toUTF8(Pair pair) { - if (pair == null) - return null; - - Pair result = new Pair(); - - result.first = toUTF8(pair.first); - result.second = toUTF8(pair.second); - - return result; - } - - public static ArrayList> toUTF8(ArrayList> list) { - if (list == null) - return null; - - ArrayList> result = new ArrayList>(list.size()); - - for (int i=0; i toUTF16(Vector list) { - if (list == null) - return null; - - Vector result = new Vector(list.size()); - - for (int i=0; i toUTF16(Pair pair) { - if (pair == null) - return null; - - Pair result = new Pair(); - - result.first = toUTF16(pair.first); - result.second = toUTF16(pair.second); - - return result; - } - - public static ArrayList> toUTF16(ArrayList> list) { - if (list == null) - return null; - - ArrayList> result = new ArrayList>(list.size()); - - for (int i=0; i> opts = new ArrayList<>(); Pair xpEp = new Pair<>(); xpEp.first = "X-pEp-Version"; - xpEp.second = this.getProtocolVersion();; + xpEp.second = this.getProtocolVersion(); opts.add(xpEp); msg.setOptFields(opts); - if(encFormat == Message.EncFormat.PEP) { + if (encFormat == Message.EncFormat.PEP) { // For EncFormat.PEP // The pgpText goes into the attachment index 1 msg.setShortmsg("p≡p"); @@ -257,14 +157,12 @@ abstract class AbstractEngine extends UniquelyIdentifiable implements AbstractEn attachments.add(att0); attachments.add(att1); msg.setAttachments(attachments); - } - else if (encFormat == Message.EncFormat.PEPEncInlineEA) { + } else if (encFormat == Message.EncFormat.PEPEncInlineEA) { // For EncFormat.PEPEncInlineEA // The pgpText goes into the longMessage msg.setShortmsg(""); msg.setLongmsg(pgpText); - } - else { + } else { throw new pEpCannotEncode("Message.Encformat not supported: " + encFormat.toString()); } diff --git a/src/foundation/pEp/jniadapter/Blob.java b/src/foundation/pEp/jniadapter/Blob.java index dffd60f..9d2c7cc 100644 --- a/src/foundation/pEp/jniadapter/Blob.java +++ b/src/foundation/pEp/jniadapter/Blob.java @@ -22,15 +22,15 @@ public class Blob implements BlobInterface, Serializable { String ret = ""; ret += "mime_type: \"" + mime_type + "\"\n"; ret += "filename: \"" + filename + "\"\n"; - ret += "data plain: \"" + AbstractEngine.toUTF16(data) + "\"\n"; + ret += "data plain: \"" + Utils.toUTF16(data) + "\"\n"; ret += "data decoded: \"" + _b.dataToXER() + "\"\n"; return ret; } Blob(_Blob b) { data = b.data; - mime_type = AbstractEngine.toUTF16(b.mime_type); - filename = AbstractEngine.toUTF16(b.filename); + mime_type = Utils.toUTF16(b.mime_type); + filename = Utils.toUTF16(b.filename); } } diff --git a/src/foundation/pEp/jniadapter/Engine.java.target b/src/foundation/pEp/jniadapter/Engine.java.target deleted file mode 100644 index 7708586..0000000 --- a/src/foundation/pEp/jniadapter/Engine.java.target +++ /dev/null @@ -1,28 +0,0 @@ -package foundation.pEp.jniadapter; - -import java.util.ArrayList; -import java.util.Vector; - -final public class Engine extends AbstractEngine { - public Engine() throws pEpException { } - - public native Message encrypt_message( - Message src, - ArrayList extra, - Message.EncFormat enc_format - ) throws pEpException; - - public class DecryptResult { - public Message dst; - public Color color; - } - - public native DecryptResult decrypt_message( - Message src, - ArrayList keylist - ) throws pEpException; - - public native Color outgoing_message_color( - Message msg - ) throws pEpException; -} diff --git a/src/foundation/pEp/jniadapter/Identity.java b/src/foundation/pEp/jniadapter/Identity.java index 3f72b90..54ff7de 100644 --- a/src/foundation/pEp/jniadapter/Identity.java +++ b/src/foundation/pEp/jniadapter/Identity.java @@ -23,12 +23,12 @@ public class Identity implements IdentityInterface, Serializable { } public Identity(_Identity i) { - address = AbstractEngine.toUTF16(i.address); - fpr = AbstractEngine.toUTF16(i.fpr); - user_id = AbstractEngine.toUTF16(i.user_id); - username = AbstractEngine.toUTF16(i.username); + address = Utils.toUTF16(i.address); + fpr = Utils.toUTF16(i.fpr); + user_id = Utils.toUTF16(i.user_id); + username = Utils.toUTF16(i.username); comm_type = CommType.Management.tag.get(i.comm_type); - lang = AbstractEngine.toUTF16(i.lang); + lang = Utils.toUTF16(i.lang); me = i.me; flags = i.flags; } diff --git a/src/foundation/pEp/jniadapter/Message.java.target b/src/foundation/pEp/jniadapter/Message.java.target deleted file mode 100644 index 6cdc3e6..0000000 --- a/src/foundation/pEp/jniadapter/Message.java.target +++ /dev/null @@ -1,218 +0,0 @@ -package foundation.pEp.jniadapter; - -import java.util.ArrayList; -import java.util.Vector; -import java.util.Date; -import java.util.HashMap; - -public class Message implements AutoCloseable { - private final long handle; - - native long init(); - native void release(long handle); - - public Message() { - handle = init(); - } - - public final void close() { - release(handle); - } - - public enum TextFormat { - Plain (0), - Html (1), - Other (255) - ; - - static class Management { - public static final HashMap tag = - new HashMap(); - } - - public final int value; - - TextFormat(int value) { - this.value = value; - fill(value); - } - - private void fill(int value) { - Management.tag.put(value, this); - } - } - - public enum Direction { - Incoming (0), - Outgoing (1) - ; - - static class Management { - public static final HashMap tag = - new HashMap(); - } - - public final int value; - - Direction(int value) { - this.value = value; - fill(value); - } - - private void fill(int value) { - Management.tag.put(value, this); - } - } - - public enum EncFormat { - None (0), - Pieces (1), - SMIME (2), - PGPMIME (3), - PEP (4) - ; - - static class Management { - public static final HashMap tag = - new HashMap(); - } - - public final int value; - - EncFormat(int value) { - this.value = value; - fill(value); - } - - private void fill(int value) { - Management.tag.put(value, this); - } - } - - private native int _getDir(); - private native void _setDir(int value); - public Direction getDir() { - return Direction.tag.get(_getDir()); - } - public void setDir(Direction value) { - _setDir(value.value); - } - - private native byte[] _getId(); - private native void _setId(byte[] value); - public String getId() { - return AbstractEngine.toUTF16(_getId()); - } - public void setId(String value) { - _setId(AbstractEngine.toUTF8(value)); - } - - private native byte[] _getShortmsg(); - private native void _setShortmsg(byte[] value); - public String getShortmsg() { - return AbstractEngine.toUTF16(_getShortmsg()); - } - public void setShortmsg(String value) { - _setShortmsg(AbstractEngine.toUTF8(value)); - } - - private native byte[] _getLongmsg(); - private native void _setLongmsg(byte[] value); - public String getLongmsg() { - return AbstractEngine.toUTF16(_getLongmsg()); - } - public void setLongmsg(String value) { - _setLongmsg(AbstractEngine.toUTF8(value)); - } - - private native byte[] _getLongmsgFormatted(); - private native void _setLongmsgFormatted(byte[] value); - public String getLongmsgFormatted() { - return AbstractEngine.toUTF16(_getLongmsgFormatted()); - } - public void setLongmsgFormatted(String value) { - _setLongmsgFormatted(AbstractEngine.toUTF8(value)); - } - - public native ArrayList getAttachments(); - public native void setAttachments(ArrayList value); - - public native Date getSent(); - public native void setSent(Date value); - - public native Date getRecv(); - public native void setRecv(Date value); - - private native AbstractEngine._Identity _getFrom(); - private native void _setFrom(AbstractEngine._Identity value); - public Identity getFrom() { - return new _getFrom().getIdentity(); - } - public void setFrom(Identity value) { - _setFrom(new AbstractEngine._Identity(value)); - } - - public native ArrayList getTo(); - public native void setTo(ArrayList value); - - public native Identity getRecvBy(); - public native void setRecvBy(Identity value); - - public native ArrayList getCc(); - public native void setCc(ArrayList value); - - public native ArrayList getBcc(); - public native void setBcc(ArrayList value); - - public native ArrayList getReplyTo(); - public native void setReplyTo(ArrayList value); - - private native ArrayList _getInReplyTo(); - private native void _setInReplyTo(ArrayList value); - public ArrayList getInReplyTo() { - return AbstractEngine.toUTF16(_getInReplyTo()); - } - public void setInReplyTo(ArrayList value) { - _setInReplyTo(AbstractEngine.toUTF8(value)); - } - - private native ArrayList _getReferences(); - private native void _setReferences(ArrayList value); - public ArrayList getReferences() { - return AbstractEngine.toUTF16(_getReferences()); - } - public void setReferences(ArrayList value) { - _setReferences(AbstractEngine.toUTF8(value)); - } - - private native ArrayList _getKeywords(); - private native void _setKeywords(ArrayList value); - public ArrayList getKeywords() { - return AbstractEngine.toUTF16(_getKeywords()); - } - public void setKeywords(ArrayList value) { - _setKeywords(AbstractEngine.toUTF8(value)); - } - - private native byte[] _getComments(); - private native void _setComments(byte[] value); - public String getComments() { - return AbstractEngine.toUTF16(_getComments()); - } - public void setComments(String value) { - _setComments(AbstractEngine.toUTF8(value)); - } - - private native Vector> _getOptFields(); - private native void _setOptFields(Vector> value); - public Vector> getOptFields() { - return AbstractEngine.toUTF16(_getOptFields()); - } - public void setOptFields(Vector> value) { - _setOptFields(AbstractEngine.toUTF8(value)); - } - - public native Message.EncFormat getEncFormat(); - public native void setEncFormat(Message.EncFormat value); - -} diff --git a/src/foundation/pEp/jniadapter/Utils.java b/src/foundation/pEp/jniadapter/Utils.java new file mode 100644 index 0000000..709998f --- /dev/null +++ b/src/foundation/pEp/jniadapter/Utils.java @@ -0,0 +1,115 @@ +package foundation.pEp.jniadapter; + +import java.io.UnsupportedEncodingException; +import java.text.Normalizer; +import java.util.ArrayList; +import java.util.Vector; + +public class Utils { + private Utils() { } + + public static byte[] toUTF8(String str) { + if (str == null) + return null; + + try { + String _str = Normalizer.normalize(str, Normalizer.Form.NFC); + byte _buf[] = _str.getBytes("UTF-8"); + byte _cpy[] = new byte[_buf.length]; + System.arraycopy(_buf,0,_cpy,0,_buf.length); + return _cpy; + } + catch (UnsupportedEncodingException e) { + assert false; + return new byte[0]; + } + } + + public static Vector toUTF8(Vector list) { + if (list == null) + return null; + + Vector result = new Vector(list.size()); + + for (int i=0; i toUTF8(Pair pair) { + if (pair == null) + return null; + + Pair result = new Pair(); + + result.first = toUTF8(pair.first); + result.second = toUTF8(pair.second); + + return result; + } + + public static ArrayList> toUTF8(ArrayList> list) { + if (list == null) + return null; + + ArrayList> result = new ArrayList>(list.size()); + + for (int i=0; i toUTF16(Vector list) { + if (list == null) + return null; + + Vector result = new Vector(list.size()); + + for (int i=0; i toUTF16(Pair pair) { + if (pair == null) + return null; + + Pair result = new Pair(); + + result.first = toUTF16(pair.first); + result.second = toUTF16(pair.second); + + return result; + } + + public static ArrayList> toUTF16(ArrayList> list) { + if (list == null) + return null; + + ArrayList> result = new ArrayList>(list.size()); + + for (int i=0; i return new Boolean(_«@name»(`apply "parm/*", mode=basic_parm_name`)); otherwise - |> return AbstractEngine.toUTF16(_«@name»(`apply "parm/*", mode=basic_parm_name`)); + |> return Utils.toUTF16(_«@name»(`apply "parm/*", mode=basic_parm_name`)); } || } @@ -191,14 +191,14 @@ tstylesheet { // TODO factorize type conversion with multireturn and gen_java_message.java when "count(parm[returns][stringlist|string|sstring]) > 0" - |> return AbstractEngine.toUTF16(_«@name»(`apply "parm[in]", mode=call;`)); + |> return Utils.toUTF16(_«@name»(`apply "parm[in]", mode=call;`)); when "count(parm[returns]/stringpairlist) > 0" || ArrayList> glist = _«@name»(`apply "parm[in]", mode=call;`); if(glist != null){ ArrayList> list = new ArrayList>(); for (Pair i : glist) - list.add(new Pair(AbstractEngine.toUTF16(i.first), AbstractEngine.toUTF16(i.second))); + list.add(new Pair(Utils.toUTF16(i.first), Utils.toUTF16(i.second))); return list; } return null; @@ -287,7 +287,7 @@ tstylesheet { if "$dir = 'in' or $dir = 'inout'" choose { when "$type = 'string' or $type = 'stringlist'" - | ¡$type _«$name» = AbstractEngine.toUTF8(«$name»); + | ¡$type _«$name» = Utils.toUTF8(«$name»); when "$type = 'identity'" || _Identity _«$name» = null; @@ -311,7 +311,7 @@ tstylesheet { if "$dir != 'in'" choose { when "$type = 'string' or $type = 'stringlist'" - | result.«$name» = AbstractEngine.toUTF16(_result.«$name»); + | result.«$name» = Utils.toUTF16(_result.«$name»); when "$type = 'identity'" | result.«$name» = Identity(«$name»); otherwise diff --git a/src/gen_java_Message.ysl2 b/src/gen_java_Message.ysl2 index 19b0a94..655f075 100644 --- a/src/gen_java_Message.ysl2 +++ b/src/gen_java_Message.ysl2 @@ -34,14 +34,14 @@ tstylesheet { ) throws pEpException; public «$cname»(String mime_text) { - byte[] _mime_text = AbstractEngine.toUTF8(mime_text); + byte[] _mime_text = Utils.toUTF8(mime_text); handle = _«$cname»(_mime_text); } public native byte[] _encodeMIME() throws pEpException; public String encodeMIME() { - return AbstractEngine.toUTF16(_encodeMIME()); + return Utils.toUTF16(_encodeMIME()); } private «$cname»(long h) { @@ -157,13 +157,13 @@ tstylesheet { otherwise > _«$ename» } const "convget" choose { - when "$ctype = 'stringlist'" > AbstractEngine.toUTF16(i) - when "$ctype = 'stringpairlist'" > new Pair(AbstractEngine.toUTF16(i.first), AbstractEngine.toUTF16(i.second)) + when "$ctype = 'stringlist'" > Utils.toUTF16(i) + when "$ctype = 'stringpairlist'" > new Pair(Utils.toUTF16(i.first), Utils.toUTF16(i.second)) otherwise > new «$ename»(i) } const "convset" choose { - when "$ctype = 'stringlist'" > AbstractEngine.toUTF8(i) - when "$ctype = 'stringpairlist'" > new Pair(AbstractEngine.toUTF8(i.first), AbstractEngine.toUTF8(i.second)) + when "$ctype = 'stringlist'" > Utils.toUTF8(i) + when "$ctype = 'stringpairlist'" > new Pair(Utils.toUTF8(i.first), Utils.toUTF8(i.second)) otherwise > new _«$ename»(i) } || @@ -200,13 +200,13 @@ tstylesheet { public «$type» get«$name»() { «$itype» res = _get«$name»(); if(res != null) - return AbstractEngine.toUTF16(res); + return Utils.toUTF16(res); else return null; } public void set«$name»(«$type» value) { if(value != null) - _set«$name»(AbstractEngine.toUTF8(value)); + _set«$name»(Utils.toUTF8(value)); else _set«$name»(new byte[0]); } @@ -220,13 +220,13 @@ tstylesheet { public «$type» get«$name»() { «$itype» res = _get«$name»(); if(res != null) - return AbstractEngine.toUTF16(res); + return Utils.toUTF16(res); else return null; } public void set«$name»(«$type» value) { if(value != null) - _set«$name»(AbstractEngine.toUTF8(value)); + _set«$name»(Utils.toUTF8(value)); else _set«$name»(null); } @@ -280,13 +280,13 @@ tstylesheet { otherwise > _«$ename» } const "convget" choose { - when "$ctype = 'stringlist'" > AbstractEngine.toUTF16(i) - when "$ctype = 'stringpairlist'" > new Pair(AbstractEngine.toUTF16(i.first), AbstractEngine.toUTF16(i.second)) + when "$ctype = 'stringlist'" > Utils.toUTF16(i) + when "$ctype = 'stringpairlist'" > new Pair(Utils.toUTF16(i.first), Utils.toUTF16(i.second)) otherwise > new «$ename»(i) } const "convset" choose { - when "$ctype = 'stringlist'" > AbstractEngine.toUTF8(i) - when "$ctype = 'stringpairlist'" > new Pair(AbstractEngine.toUTF8(i.first), AbstractEngine.toUTF8(i.second)) + when "$ctype = 'stringlist'" > Utils.toUTF8(i) + when "$ctype = 'stringpairlist'" > new Pair(Utils.toUTF8(i.first), Utils.toUTF8(i.second)) otherwise > new _«$ename»(i) } ||