Volker Birk 10 years ago
parent
commit
9a00643bf5
  1. 11
      src/Makefile
  2. 32
      src/gen_java_Engine.ysl2
  3. 93
      src/gen_java_Message.ysl2
  4. 109
      src/org/pEp/jniadapter/AbstractEngine.java
  5. 11
      src/org/pEp/jniadapter/Identity.java
  6. 4
      src/org/pEp/jniadapter/Pair.java
  7. 62
      src/pEp.yml2
  8. 22
      src/types_java.ysl2

11
src/Makefile

@ -9,6 +9,8 @@ $(JAR): org/pEp/jniadapter/pEpException.java org/pEp/jniadapter/AbstractEngine.j
javac org/pEp/jniadapter/*.java
jar cf $@ org/pEp/jniadapter/*.class
org_pEp_jniadapter_AbstractEngine.o: org_pEp_jniadapter_AbstractEngine.h org_pEp_jniadapter_AbstractEngine.cc throw_pEp_exception.hh jniutils.hh
org_pEp_jniadapter_AbstractEngine.h: org/pEp/jniadapter/AbstractEngine.java
javah org.pEp.jniadapter.AbstractEngine
@ -18,8 +20,6 @@ org_pEp_jniadapter_Engine.h: org/pEp/jniadapter/Engine.java
org_pEp_jniadapter_MimeMessage.h: org/pEp/jniadapter/MimeMessage.java
javah org.pEp.jniadapter.MimeMessage
org_pEp_jniadapter_AbstractEngine.o: org_pEp_jniadapter_AbstractEngine.h org_pEp_jniadapter_AbstractEngine.cc throw_pEp_exception.hh jniutils.hh
%.o: %.cc %.h jniutils.hh
$(LIBRARY): org_pEp_jniadapter_AbstractEngine.o org_pEp_jniadapter_Engine.o org_pEp_jniadapter_MimeMessage.o throw_pEp_exception.o jniutils.o
@ -28,11 +28,8 @@ $(LIBRARY): org_pEp_jniadapter_AbstractEngine.o org_pEp_jniadapter_Engine.o org_
org/pEp/jniadapter/pEpException.java: pEp.yml2 gen_java_exceptions.ysl2
yml2proc -y gen_java_exceptions.ysl2 $< -o $@
org/pEp/jniadapter/Engine.java : pEp.yml2 gen_java_Engine.ysl2 types_java.ysl2
yml2proc -y gen_java_Engine.ysl2 $< -o $@
org/pEp/jniadapter/MimeMessage.java : pEp.yml2 gen_java_Message.ysl2 types_java.ysl2
yml2proc -y gen_java_Message.ysl2 $< -o $@
org/pEp/jniadapter/Engine.java org/pEp/jniadapter/MimeMessage.java : pEp.yml2 gen_java_Message.ysl2 types_java.ysl2
yml2proc -y gen_java_Message.ysl2 $<
throw_pEp_exception.cc throw_pEp_exception.hh: pEp.yml2 gen_throw_pEp_exception.ysl2 textutils.ysl2
yml2proc -y gen_throw_pEp_exception.ysl2 $< -o throw_pEp_exception.cc

32
src/gen_java_Engine.ysl2

@ -1,32 +0,0 @@
include yslt.yml2
tstylesheet {
include ./types_java.ysl2
template "/"
||
package org.pEp.jniadapter;
final public class Engine extends AbstractEngine {
public Engine() throws pEpException { }
`` apply "namespace/interface/method";
}
||
template "method"
||
public native void «@name»(
`` apply "parm", 2
) throws pEpException;`if "position()!=last()" > \n`
||
template "parm" {
const "dir", "name(*[1])";
const "type", "name(*[2])";
const "name", "name(*[3])";
| `call "toJava" with "type", "$type"` «translate($name,'-','_')»`if "position()!=last()" > ,`
}
}

93
src/gen_java_Message.ysl2

@ -3,61 +3,88 @@ include yslt.yml2
tstylesheet {
include ./types_java.ysl2
template "/namespace[@name='pEp']" apply "struct", 0;
template "/namespace[@name='pEp']" apply "struct|interface", 0;
template "struct[@name='message']"
||
package org.pEp.jniadapter;
template "interface" {
const "cname" call "toJava" with "type", "@name";
document("org/pEp/jniadapter/{$cname}.java", "text")
||
package org.pEp.jniadapter;
import java.util.Date;
import java.util.ArrayList;
public class MimeMessage {
public enum TextFormat {
plain (0),
html (1),
other (255);
final public class «$cname» extends AbstractEngine {
public «$cname»() throws pEpException { }
`` apply "namespace/interface/method";
}
||
}
public final int value;
template "struct" {
const "cname" call "toJava" with "type", "@name";
document("org/pEp/jniadapter/{$cname}.java", "text")
||
package org.pEp.jniadapter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
public class «$cname» {
`` apply "enum"
`` apply "*[name(.)!='enum']", mode=entry
TextFormat(int value) {
this.value = value;
}
||
}
public enum Direction {
incoming (0),
outgoing (1);
template "enum"
||
public enum «@name» {
`` apply "*", mode=value
;
public final int value;
public static final HashMap<Integer, «@name»> tag =
new HashMap<Integer, «@name»>();
Direction(int value) {
«@name»(int value) {
this.value = value;
fill(value);
}
private void fill(int value) {
tag.put(value, this);
}
}
public enum EncFormat {
none (0),
pieces (1),
S_MIME (2),
PGP_MIME (3),
PEP (4);
||
public final int value;
template "method"
||
public native void «@name»(
`` apply "parm", 2
) throws pEpException;`if "position()!=last()" > \n`
||
EncFormat(int value) {
this.value = value;
}
template "parm" {
const "dir", "name(*[1])";
const "type", "name(*[2])";
const "name", "name(*[3])";
| `call "toJava" with "type", "$type"` «translate($name,'-','_')»`if "position()!=last()" > ,`
}
``apply "entry";
}
||
template "*", mode=entry {
const "type", "name(.)";
const "name", "name(*[position()=1])";
template "entry"
||
public native †@type ©@name();
public native void ©@name(†@type value);
private native †$type _©$name();
private native void _©$name(†$type value);
||
}
template "*", mode=value | «name(.)» («.»)`if "position()!=last()" > , `
}

109
src/org/pEp/jniadapter/AbstractEngine.java

@ -1,15 +1,19 @@
package org.pEp.jniadapter;
abstract class AbstractEngine implements AutoCloseable {
static {
System.loadLibrary("pEpJNI");
}
import java.util.ArrayList;
import java.io.UnsupportedEncodingException; import java.text.Normalizer;
abstract class AbstractEngine implements AutoCloseable { static {
System.loadLibrary("pEpJNI"); }
private native void init() throws pEpException;
private native void release();
private native void init() throws pEpException; private native void
release();
private long handle;
final protected long getHandle() { return handle; }
final protected long getHandle() {
return handle;
}
public AbstractEngine() throws pEpException {
init();
@ -18,5 +22,96 @@ abstract class AbstractEngine implements AutoCloseable {
final public void close() {
release();
}
public static byte[] toUTF8(String str) {
try {
String _str = Normalizer.normalize(str, Normalizer.Form.NFC);
return _str.getBytes("UTF-8");
}
catch (UnsupportedEncodingException e) {
assert false;
return new byte[0];
}
}
public static ArrayList<byte[]> toUTF8(ArrayList<String> list) {
ArrayList<byte[]> result = new ArrayList<byte[]>(list.size());
for (int i=0; i<list.size(); i++)
result.set(i, toUTF8(list.get(i)));
return result;
}
public static Pair<byte[], byte[]> toUTF8(Pair<String, String> pair) {
Pair<byte[], byte[]> result = new Pair<byte[], byte[]>();
result.first = toUTF8(pair.first);
result.second = toUTF8(pair.second);
return result;
}
public static String toUTF16(byte[] utf8) {
try {
return new String(utf8, "UTF-8");
}
catch (UnsupportedEncodingException e) {
assert false;
return new String();
}
}
public static ArrayList<String> toUTF16(ArrayList<byte[]> list) {
ArrayList<String> result = new ArrayList<String>(list.size());
for (int i=0; i<list.size(); i++)
result.set(i, toUTF16(list.get(i)));
return result;
}
public static Pair<String, String> toUTF16(Pair<byte[], byte[]> pair) {
Pair<String, String> result = new Pair<String,String>();
result.first = toUTF16(pair.first);
result.second = toUTF16(pair.second);
return result;
}
public class _Identity {
public byte[] address;
public byte[] fpr;
public byte[] user_id;
public byte[] username;
CommType comm_type;
public byte[] lang;
public boolean me;
public _Identity(Identity value) {
address = toUTF8(value.address);
fpr = toUTF8(value.fpr);
user_id = toUTF8(value.user_id);
username = toUTF8(value.username);
comm_type = value.comm_type;
lang = toUTF8(value.lang);
me = value.me;
}
public Identity getIdentity() {
Identity ident = new Identity(me);
ident.address = toUTF16(address);
ident.fpr = toUTF16(fpr);
ident.user_id = toUTF16(user_id);
ident.username = toUTF16(username);
ident.comm_type = comm_type;
ident.lang = toUTF16(lang);
ident.me = me;
return ident;
}
}
}

11
src/org/pEp/jniadapter/Identity.java

@ -7,9 +7,14 @@ public class Identity {
public String username;
CommType comm_type;
public String lang;
private boolean me;
public boolean me;
public Identity() { this.me = false; }
public Identity(boolean me) { this.me = me; }
public Identity() {
this.me = false;
}
public Identity(boolean me) {
this.me = me;
}
}

4
src/org/pEp/jniadapter/Pair.java

@ -1,7 +1,7 @@
package org.pEp.jniadapter;
public class Pair<F, S> {
private F first;
private S second;
public F first;
public S second;
}

62
src/pEp.yml2

@ -4,7 +4,6 @@ decl interface @name;
decl exception @name;
decl method @name;
decl struct @name;
decl entry @type @name;
namespace pEp {
exception pEp_status {
@ -51,7 +50,7 @@ namespace pEp {
pEp_unknown_error > -1
};
interface message_api {
interface Engine {
method encrypt_message(
in message src,
in stringlist extra,
@ -73,26 +72,45 @@ namespace pEp {
};
struct message {
entry direction dir;
entry string id;
entry string shortmsg;
entry string longmsg;
entry string longmsg_formatted;
entry bloblist attachments;
entry timestamp sent;
entry timestamp recv;
entry identity from;
entry identitylist to;
entry identity recv_by;
entry identitylist cc;
entry identitylist bcc;
entry identitylist reply_to;
entry stringlist in_reply_to;
entry stringlist references;
entry stringlist keywords;
entry string comments;
entry stringpairlist opt_fields;
entry encformat enc_format;
enum TextFormat {
plain > 0
html > 1
other > 255
}
enum Direction {
incoming > 0
outgoing > 1
}
enum EncFormat {
none > 0
pieces > 1
SMIME > 2
PGPMIME > 3
PEP > 4
}
direction dir;
string id;
string shortmsg;
string longmsg;
string longmsg_formatted;
bloblist attachments;
timestamp sent;
timestamp recv;
identity from;
identitylist to;
identity recv_by;
identitylist cc;
identitylist bcc;
identitylist reply_to;
stringlist in_reply_to;
stringlist references;
stringlist keywords;
string comments;
stringpairlist opt_fields;
encformat enc_format;
};
};

22
src/types_java.ysl2

@ -4,19 +4,33 @@ function "toJava" {
param "type";
choose {
when "$type='stringlist'" > String[]
when "$type='stringlist'" > ArrayList<String>
when "$type='string'" > String
when "$type='message'" > MimeMessage
when "$type='identity'" > Identity
when "$type='identitylist'" > Identity[]
when "$type='identitylist'" > ArrayList<Identity>
when "$type='timestamp'" > Date
when "$type='encformat'" > MimeMessage.EncFormat
when "$type='bloblist'" > Blob[]
when "$type='stringpairlist'" > Pair<String, String>[]
when "$type='bloblist'" > ArrayList<Blob>
when "$type='stringpairlist'" > ArrayList<Pair<String, String>>
when "$type='message'" > MimeMessage
otherwise call "CamelCase" with "text", "$type";
}
}
function "toIntermediate" {
param "type";
choose {
when "$type='stringlist'" > ArrayList<byte[]>
when "$type='stringpairlist'" > ArrayList<Pair<byte[], byte[]>>
when "$type='string'" > byte[]
otherwise call "toJava" with "type", "$type";
}
}
define operator "†([$@]?[a-zA-Z0-9_]+)" as call "toJava" with "type", "%1";
define operator "¡([$@]?[a-zA-Z0-9_]+)" as call "toIntermediate" with "type", "%1";

Loading…
Cancel
Save