
57 changed files with 1090 additions and 1052 deletions
@ -0,0 +1,60 @@ |
|||||
|
# Copyright 2018, pEp Foundation
|
||||
|
# This file is part of pEp JNI Adapter
|
||||
|
# This file may be used under the terms of the GNU General Public License version 3
|
||||
|
# see LICENSE.txt
|
||||
|
|
||||
|
include ../../Makefile.conf |
||||
|
|
||||
|
MARKER_DIR=../../build/marker/ |
||||
|
|
||||
|
PEP_HEADER:=$(shell $(CXX) $(CXXFLAGS) -E -M ../cxx/get_header.cc | grep -oe '[^[:space:]]*pEpEngine\.h' | head -1) |
||||
|
|
||||
|
# Every ysl2 file that needs to be "compiled" separately, needs to generate a "marker" file
|
||||
|
# The marker serves as the make target.
|
||||
|
# If the marker file is older than its corresponding ysl2 file, or not exsiting, the ysl2 file will be "compiled"
|
||||
|
# Naming:
|
||||
|
# For a ysl2 file called "gen_example_stuff.ysl2", a marker file called "gen_example_stuff.marker" is expected.
|
||||
|
YML2_MARKERS= \
|
||||
|
$(MARKER_DIR)/gen_java_Engine.marker \
|
||||
|
$(MARKER_DIR)/gen_java_Message.marker \
|
||||
|
$(MARKER_DIR)/gen_cpp_Engine.marker \
|
||||
|
$(MARKER_DIR)/gen_cpp_Message.marker \
|
||||
|
$(MARKER_DIR)/gen_throw_pEp_exception.marker |
||||
|
|
||||
|
# All code genration will be done upon change of these files
|
||||
|
YML2_INCLUDES= \
|
||||
|
textutils.ysl2 \
|
||||
|
types_c.ysl2 \
|
||||
|
types_java.ysl2 |
||||
|
|
||||
|
|
||||
|
.PHONY: all codegen gen-status-codes create-dirs remove-dirs clean |
||||
|
|
||||
|
all: codegen |
||||
|
|
||||
|
# ------------- YML2 CodeGen --------------
|
||||
|
codegen: create-dirs gen-status-codes $(YML2_MARKERS) |
||||
|
|
||||
|
$(YML2_MARKERS): $(MARKER_DIR)/%.marker : %.ysl2 pEp.yml2 $(YML2_INCLUDES) |
||||
|
$(YML2_PROC) -y $< pEp.yml2 |
||||
|
|
||||
|
gen-status-codes: status_list.yml2 passphrase_status_list.yml2 |
||||
|
|
||||
|
status_list.yml2: pEp.yml2 |
||||
|
bash ../../utils/extract_pEp_status_codes_from_engine.sh "$(PEP_HEADER)" $@ |
||||
|
|
||||
|
passphrase_status_list.yml2: status_list.yml2 |
||||
|
grep passphrase $< > $@ |
||||
|
|
||||
|
# ------------- Housekeeping ---------------
|
||||
|
create-dirs: |
||||
|
mkdir -p $(MARKER_DIR) |
||||
|
|
||||
|
#rm -rf is too dangerous for vars
|
||||
|
remove-dirs: |
||||
|
rm -rf ../../build/marker |
||||
|
|
||||
|
clean: remove-dirs |
||||
|
rm -f status_list.yml2 |
||||
|
rm -f passphrase_status_list.yml2 |
||||
|
|
@ -0,0 +1,327 @@ |
|||||
|
include yslt.yml2 |
||||
|
|
||||
|
tstylesheet { |
||||
|
include ./textutils.ysl2 |
||||
|
include ./types_java.ysl2 |
||||
|
|
||||
|
template "/namespace[@name='pEp']" { |
||||
|
apply "struct|enum|exception", 0; |
||||
|
document "../java/foundation/pEp/jniadapter/exceptions/pEpException.java", "text" { |
||||
|
|| |
||||
|
package foundation.pEp.jniadapter.exceptions; |
||||
|
|
||||
|
public class pEpException extends RuntimeException { |
||||
|
public pEpException(String message) { |
||||
|
super(message); |
||||
|
} |
||||
|
} |
||||
|
|| |
||||
|
} |
||||
|
document("../../build/marker/gen_java_Message.marker", "text") > "" |
||||
|
} |
||||
|
|
||||
|
template "struct" { |
||||
|
const "cname" call "toJava" with "type", "@name"; |
||||
|
document("../java/foundation/pEp/jniadapter/{$cname}.java", "text") |
||||
|
|| |
||||
|
package foundation.pEp.jniadapter; |
||||
|
|
||||
|
import foundation.pEp.jniadapter.interfaces.*; |
||||
|
import foundation.pEp.jniadapter.exceptions.*; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Vector; |
||||
|
import java.util.Date; |
||||
|
import java.util.HashMap; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
public class «$cname» implements MessageInterface, AutoCloseable, Serializable { |
||||
|
private static final long serialVersionUID = 2119420428331150924L; |
||||
|
private long handle; |
||||
|
|
||||
|
native long init(); |
||||
|
native void release(long handle); |
||||
|
|
||||
|
public «$cname»() { |
||||
|
handle = init(); |
||||
|
} |
||||
|
|
||||
|
private native long _«$cname»( |
||||
|
byte[] mime_text |
||||
|
) throws pEpException; |
||||
|
|
||||
|
public «$cname»(String mime_text) { |
||||
|
byte[] _mime_text = Utils.toUTF8(mime_text); |
||||
|
handle = _«$cname»(_mime_text); |
||||
|
} |
||||
|
|
||||
|
private native byte[] _encodeMIME() throws pEpException; |
||||
|
|
||||
|
public String encodeMIME() { |
||||
|
return Utils.toUTF16(_encodeMIME()); |
||||
|
} |
||||
|
|
||||
|
private «$cname»(long h) { |
||||
|
handle = h; |
||||
|
} |
||||
|
|
||||
|
public final void close() { |
||||
|
release(handle); |
||||
|
} |
||||
|
|
||||
|
final protected long getHandle() { |
||||
|
return handle; |
||||
|
} |
||||
|
|
||||
|
`` apply "enum", mode=inner |
||||
|
`` apply "*[name(.)!='enum']", mode=entry |
||||
|
} |
||||
|
|| |
||||
|
document("../java/foundation/pEp/jniadapter/interfaces/{$cname}Interface.java", "text") |
||||
|
|| |
||||
|
package foundation.pEp.jniadapter.interfaces; |
||||
|
|
||||
|
import foundation.pEp.jniadapter.*; |
||||
|
import foundation.pEp.jniadapter.Message.*; |
||||
|
import java.util.Date; |
||||
|
import java.util.Vector; |
||||
|
import java.util.ArrayList; |
||||
|
|
||||
|
public interface «$cname»Interface { |
||||
|
public String encodeMIME(); |
||||
|
|
||||
|
`` apply "*[name(.)!='enum']", mode=interface |
||||
|
} |
||||
|
|| |
||||
|
} |
||||
|
|
||||
|
template "enum" { |
||||
|
const "jname" call "toJava" with "type", "@name"; |
||||
|
document("../java/foundation/pEp/jniadapter/{$jname}.java", "text") |
||||
|
|| |
||||
|
// CodeGen template enum |
||||
|
package foundation.pEp.jniadapter; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
|
||||
|
`` apply ".", 0, mode=inner |
||||
|
|| |
||||
|
|
||||
|
} |
||||
|
|
||||
|
template "enum", mode=inner { |
||||
|
const "jname" call "CamelCase" with "text", "@name"; |
||||
|
|| |
||||
|
// CodeGen template enum, mode=inner |
||||
|
public enum «$jname» { |
||||
|
`` apply "*", mode=value |
||||
|
; |
||||
|
|
||||
|
public final int value; |
||||
|
|
||||
|
private static HashMap<Integer, «$jname»> intMap; |
||||
|
|
||||
|
private «$jname»(int value) { |
||||
|
this.value = value; |
||||
|
} |
||||
|
|
||||
|
public static «$jname» getByInt(int value){ |
||||
|
if (intMap == null) { |
||||
|
intMap = new HashMap<Integer, «$jname»>(); |
||||
|
for («$jname» s : «$jname».values()) { |
||||
|
intMap.put(s.value, s); |
||||
|
} |
||||
|
} |
||||
|
if (intMap.containsKey(value)) { |
||||
|
return intMap.get(value); |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|| |
||||
|
} |
||||
|
|
||||
|
function "exception" { |
||||
|
param "name"; |
||||
|
|
||||
|
document "../java/foundation/pEp/jniadapter/exceptions/{$name}.java", "text" { |
||||
|
| package foundation.pEp.jniadapter.exceptions; |
||||
|
| |
||||
|
| public class «$name» extends pEpException { |
||||
|
| public «$name»(String message) { |
||||
|
| super(message); |
||||
|
| } |
||||
|
| } |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
template "exception" for "*[text()!=0]" call "exception" |
||||
|
with "name" call "CamelCase" with "text", "name(.)"; |
||||
|
|
||||
|
|
||||
|
template "*", mode=entry { |
||||
|
const "ctype", "name(.)"; |
||||
|
const "type" call "toJava" with "type", "name(.)"; |
||||
|
const "itype" call "toIntermediate" with "type", "name(.)"; |
||||
|
const "name" call "toJava" with "type", "name(*[position()=1])"; |
||||
|
|
||||
|
|| |
||||
|
// CodeGen template * mode=entry |
||||
|
|| |
||||
|
choose { |
||||
|
when "$ctype = 'identity'" { |
||||
|
|| |
||||
|
// Property type: Identity. [java: «$type», intermediate: «$itype», ctype: «$ctype»] |
||||
|
public «$type» get«$name»() { |
||||
|
«$itype» res = _get«$name»(); |
||||
|
if (res != null) { |
||||
|
return new «$type»(_get«$name»()); |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
private native «$itype» _get«$name»(); |
||||
|
|
||||
|
public void set«$name»(«$type» value) { |
||||
|
if (value != null) { |
||||
|
_set«$name»(new «$itype»(value)); |
||||
|
} else { |
||||
|
_set«$name»(null); |
||||
|
} |
||||
|
} |
||||
|
private native void _set«$name»(«$itype» value); |
||||
|
|
||||
|
|
||||
|
|| |
||||
|
} |
||||
|
|
||||
|
when "$ctype = 'identitylist' or $ctype = 'bloblist' or $ctype = 'stringlist' or $ctype = 'stringpairlist'" { |
||||
|
const "ename", "substring-after(substring($type,1,string-length($type)-1), '<')"; |
||||
|
const "iename" choose { |
||||
|
when "$ctype = 'stringlist'" > byte[] |
||||
|
when "$ctype = 'stringpairlist'" > Pair<byte[],byte[]> |
||||
|
otherwise > _«$ename» |
||||
|
} |
||||
|
const "convget" choose { |
||||
|
when "$ctype = 'stringlist'" > Utils.toUTF16(i) |
||||
|
when "$ctype = 'stringpairlist'" > new Pair<String, String>(Utils.toUTF16(i.first), Utils.toUTF16(i.second)) |
||||
|
otherwise > new «$ename»(i) |
||||
|
} |
||||
|
const "convset" choose { |
||||
|
when "$ctype = 'stringlist'" > Utils.toUTF8(i) |
||||
|
when "$ctype = 'stringpairlist'" > new Pair<byte[],byte[]>(Utils.toUTF8(i.first), Utils.toUTF8(i.second)) |
||||
|
otherwise > new _«$ename»(i) |
||||
|
} |
||||
|
|| |
||||
|
// Property type: list type. [java: «$type», intermediate: «$itype», ctype: «$ctype»] |
||||
|
public «$type» get«$name»() { |
||||
|
«$itype» glist = _get«$name»(); |
||||
|
if (glist != null) { |
||||
|
«$type» list = new «$type»(); |
||||
|
for («$iename» i : glist) { |
||||
|
list.add(«$convget»); |
||||
|
} |
||||
|
return list; |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
private native «$itype» _get«$name»(); |
||||
|
|
||||
|
public void set«$name»(«$type» value) { |
||||
|
if (value != null) { |
||||
|
«$itype» list = new «$itype»(); |
||||
|
for («$ename» i : value) { |
||||
|
list.add(«$convset»); |
||||
|
} |
||||
|
_set«$name»(list); |
||||
|
} else { |
||||
|
_set«$name»(null); |
||||
|
} |
||||
|
} |
||||
|
private native void _set«$name»(«$itype» value); |
||||
|
|
||||
|
|
||||
|
|| |
||||
|
} |
||||
|
|
||||
|
when "$itype != $type" { |
||||
|
|| |
||||
|
// Property type: differs from intermediate. [java: «$type», intermediate: «$itype», ctype: «$ctype»] |
||||
|
public «$type» get«$name»() { |
||||
|
«$itype» res = _get«$name»(); |
||||
|
if (res != null) { |
||||
|
return Utils.toUTF16(res); |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
private native «$itype» _get«$name»(); |
||||
|
|
||||
|
public void set«$name»(«$type» value) { |
||||
|
if (value != null) { |
||||
|
_set«$name»(Utils.toUTF8(value)); |
||||
|
} else { |
||||
|
_set«$name»(new byte[0]); |
||||
|
} |
||||
|
} |
||||
|
private native void _set«$name»(«$itype» value); |
||||
|
|
||||
|
|
||||
|
|| |
||||
|
} |
||||
|
|
||||
|
when "../enum[@name=$ctype]" { |
||||
|
|| |
||||
|
// Property type: enum type. [java: «$type», intermediate: «$itype», ctype: «$ctype»] |
||||
|
public «$type» get«$name»() { |
||||
|
return «$type».getByInt(_get«$name»()); |
||||
|
} |
||||
|
private native int _get«$name»(); |
||||
|
public void set«$name»(«$type» value) { |
||||
|
if(value != null) |
||||
|
_set«$name»(value.value); |
||||
|
else |
||||
|
_set«$name»(0); |
||||
|
} |
||||
|
private native void _set«$name»(int value); |
||||
|
|
||||
|
|| |
||||
|
} |
||||
|
|
||||
|
otherwise { |
||||
|
|| |
||||
|
// Property type: no intermediate type [java: «$type», intermediate: «$itype», ctype: «$ctype»] |
||||
|
public «$type» get«$name»() { |
||||
|
return get«$name»(); |
||||
|
} |
||||
|
private native «$type» _get«$name»(); |
||||
|
|
||||
|
public void set«$name»(«$type» value) { |
||||
|
_set«$name»(value); |
||||
|
} |
||||
|
private native void _set«$name»(«$type» value); |
||||
|
|
||||
|
|
||||
|
|| |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
template "*", mode=interface { |
||||
|
const "type" call "toJava" with "type", "name(.)"; |
||||
|
const "name" call "toJava" with "type", "name(*[position()=1])"; |
||||
|
|
||||
|
|| |
||||
|
public «$type» get«$name»(); |
||||
|
|
||||
|
public void set«$name»(«$type» value); |
||||
|
|
||||
|
|| |
||||
|
} |
||||
|
|
||||
|
template "*", mode=value { |
||||
|
const "name" call "toJava" with "type", "name(.)"; |
||||
|
| «$name» («.»)`if "position()!=last()" > , ` |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,65 @@ |
|||||
|
include yslt.yml2 |
||||
|
|
||||
|
tstylesheet { |
||||
|
include ./textutils.ysl2 |
||||
|
|
||||
|
template "/" { |
||||
|
apply "namespace", 0; |
||||
|
document "../cxx/throw_pEp_exception.hh", "text" |
||||
|
|| |
||||
|
#pragma once |
||||
|
|
||||
|
#include <jni.h> |
||||
|
|
||||
|
namespace pEp { |
||||
|
namespace JNIAdapter { |
||||
|
jint throw_pEp_Exception(JNIEnv *env, PEP_STATUS status); |
||||
|
}; |
||||
|
}; |
||||
|
|
||||
|
|| |
||||
|
document("../../build/marker/gen_throw_pEp_exception.marker", "text") > "" |
||||
|
} |
||||
|
|
||||
|
template "namespace" |
||||
|
document("../cxx/throw_pEp_exception.cc", "text") |
||||
|
|| |
||||
|
#include <assert.h> |
||||
|
#include <pEp/pEpEngine.h> |
||||
|
#include "throw_pEp_exception.hh" |
||||
|
|
||||
|
namespace pEp { |
||||
|
namespace JNIAdapter { |
||||
|
jint throw_pEp_Exception(JNIEnv *env, PEP_STATUS status) |
||||
|
{ |
||||
|
jclass ex; |
||||
|
const char *ex_name; |
||||
|
|
||||
|
switch (status) { |
||||
|
`` apply "exception/*[text()!=0]", 4, mode=case |
||||
|
default: |
||||
|
assert(0); |
||||
|
ex_name = "Exception"; |
||||
|
} |
||||
|
|
||||
|
ex = env->FindClass(ex_name); |
||||
|
assert(ex); |
||||
|
|
||||
|
if (ex == NULL) { |
||||
|
ex = env->FindClass("java/lang/NoClassDefFoundError"); |
||||
|
assert(ex); |
||||
|
} |
||||
|
|
||||
|
return env->ThrowNew(ex, ex_name); |
||||
|
} |
||||
|
}; |
||||
|
}; |
||||
|
|| |
||||
|
|
||||
|
template "*", mode=case { |
||||
|
| case `call "UCASE" with "text", "name(.)"`: |
||||
|
| ex_name = "foundation/pEp/jniadapter/exceptions/`call "CamelCase" with "text", "name(.)"`"; |
||||
|
| break; |
||||
|
} |
||||
|
} |
||||
|
|
@ -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<String> extra, |
|
||||
Message.EncFormat enc_format |
|
||||
) throws pEpException; |
|
||||
|
|
||||
public class DecryptResult { |
|
||||
public Message dst; |
|
||||
public Color color; |
|
||||
} |
|
||||
|
|
||||
public native DecryptResult decrypt_message( |
|
||||
Message src, |
|
||||
ArrayList<String> keylist |
|
||||
) throws pEpException; |
|
||||
|
|
||||
public native Color outgoing_message_color( |
|
||||
Message msg |
|
||||
) throws pEpException; |
|
||||
} |
|
@ -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<Integer, TextFormat> tag = |
|
||||
new HashMap<Integer, TextFormat>(); |
|
||||
} |
|
||||
|
|
||||
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<Integer, Direction> tag = |
|
||||
new HashMap<Integer, Direction>(); |
|
||||
} |
|
||||
|
|
||||
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<Integer, EncFormat> tag = |
|
||||
new HashMap<Integer, EncFormat>(); |
|
||||
} |
|
||||
|
|
||||
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<Blob> getAttachments(); |
|
||||
public native void setAttachments(ArrayList<Blob> 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<Identity> getTo(); |
|
||||
public native void setTo(ArrayList<Identity> value); |
|
||||
|
|
||||
public native Identity getRecvBy(); |
|
||||
public native void setRecvBy(Identity value); |
|
||||
|
|
||||
public native ArrayList<Identity> getCc(); |
|
||||
public native void setCc(ArrayList<Identity> value); |
|
||||
|
|
||||
public native ArrayList<Identity> getBcc(); |
|
||||
public native void setBcc(ArrayList<Identity> value); |
|
||||
|
|
||||
public native ArrayList<Identity> getReplyTo(); |
|
||||
public native void setReplyTo(ArrayList<Identity> value); |
|
||||
|
|
||||
private native ArrayList<byte[]> _getInReplyTo(); |
|
||||
private native void _setInReplyTo(ArrayList<byte[]> value); |
|
||||
public ArrayList<String> getInReplyTo() { |
|
||||
return AbstractEngine.toUTF16(_getInReplyTo()); |
|
||||
} |
|
||||
public void setInReplyTo(ArrayList<String> value) { |
|
||||
_setInReplyTo(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
private native ArrayList<byte[]> _getReferences(); |
|
||||
private native void _setReferences(ArrayList<byte[]> value); |
|
||||
public ArrayList<String> getReferences() { |
|
||||
return AbstractEngine.toUTF16(_getReferences()); |
|
||||
} |
|
||||
public void setReferences(ArrayList<String> value) { |
|
||||
_setReferences(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
private native ArrayList<byte[]> _getKeywords(); |
|
||||
private native void _setKeywords(ArrayList<byte[]> value); |
|
||||
public ArrayList<String> getKeywords() { |
|
||||
return AbstractEngine.toUTF16(_getKeywords()); |
|
||||
} |
|
||||
public void setKeywords(ArrayList<String> 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<Pair<byte[], byte[]>> _getOptFields(); |
|
||||
private native void _setOptFields(Vector<Pair<byte[], byte[]>> value); |
|
||||
public Vector<Pair<String, String>> getOptFields() { |
|
||||
return AbstractEngine.toUTF16(_getOptFields()); |
|
||||
} |
|
||||
public void setOptFields(Vector<Pair<String, String>> value) { |
|
||||
_setOptFields(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
public native Message.EncFormat getEncFormat(); |
|
||||
public native void setEncFormat(Message.EncFormat value); |
|
||||
|
|
||||
} |
|
@ -1,11 +0,0 @@ |
|||||
package foundation.pEp.jniadapter; |
|
||||
import java.util.concurrent.atomic.AtomicLong; |
|
||||
|
|
||||
abstract class UniquelyIdentifiable { |
|
||||
static final AtomicLong NEXT_ID = new AtomicLong(1); |
|
||||
final long id = NEXT_ID.getAndIncrement(); |
|
||||
|
|
||||
public long getId() { |
|
||||
return id; |
|
||||
} |
|
||||
} |
|
@ -1,252 +0,0 @@ |
|||||
include yslt.yml2 |
|
||||
|
|
||||
tstylesheet { |
|
||||
include ./textutils.ysl2 |
|
||||
include ./types_java.ysl2 |
|
||||
|
|
||||
template "/namespace[@name='pEp']" apply "struct|enum|exception", 0; |
|
||||
|
|
||||
template "struct" { |
|
||||
const "cname" call "toJava" with "type", "@name"; |
|
||||
document("foundation/pEp/jniadapter/{$cname}.java", "text") |
|
||||
|| |
|
||||
package foundation.pEp.jniadapter; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
import java.util.Vector; |
|
||||
import java.util.Date; |
|
||||
import java.util.HashMap; |
|
||||
import java.io.Serializable; |
|
||||
|
|
||||
public class «$cname» implements AutoCloseable, Serializable { |
|
||||
private static final long serialVersionUID = 2119420428331150924L; |
|
||||
private long handle; |
|
||||
|
|
||||
native long init(); |
|
||||
native void release(long handle); |
|
||||
|
|
||||
public «$cname»() { |
|
||||
handle = init(); |
|
||||
} |
|
||||
|
|
||||
private native long _«$cname»( |
|
||||
byte[] mime_text |
|
||||
) throws pEpException; |
|
||||
|
|
||||
public «$cname»(String mime_text) { |
|
||||
byte[] _mime_text = AbstractEngine.toUTF8(mime_text); |
|
||||
handle = _«$cname»(_mime_text); |
|
||||
} |
|
||||
|
|
||||
public native byte[] _encodeMIME() throws pEpException; |
|
||||
|
|
||||
public String encodeMIME() { |
|
||||
return AbstractEngine.toUTF16(_encodeMIME()); |
|
||||
} |
|
||||
|
|
||||
private «$cname»(long h) { |
|
||||
handle = h; |
|
||||
} |
|
||||
|
|
||||
public final void close() { |
|
||||
release(handle); |
|
||||
} |
|
||||
|
|
||||
final protected long getHandle() { |
|
||||
return handle; |
|
||||
} |
|
||||
|
|
||||
`` apply "enum", mode=inner |
|
||||
`` apply "*[name(.)!='enum']", mode=entry |
|
||||
} |
|
||||
|| |
|
||||
} |
|
||||
|
|
||||
template "enum|exception" { |
|
||||
const "jname" call "toJava" with "type", "@name"; |
|
||||
document("foundation/pEp/jniadapter/{$jname}.java", "text") |
|
||||
|| |
|
||||
package foundation.pEp.jniadapter; |
|
||||
|
|
||||
import java.util.HashMap; |
|
||||
|
|
||||
`` apply ".", 0, mode=inner |
|
||||
|| |
|
||||
} |
|
||||
|
|
||||
template "enum|exception", mode=inner { |
|
||||
const "jname" call "CamelCase" with "text", "@name"; |
|
||||
|| |
|
||||
public enum «$jname» { |
|
||||
`` apply "*", mode=value |
|
||||
; |
|
||||
|
|
||||
public final int value; |
|
||||
|
|
||||
private static HashMap<Integer, «$jname»> intMap; |
|
||||
|
|
||||
private «$jname»(int value) { |
|
||||
this.value = value; |
|
||||
} |
|
||||
|
|
||||
public static «$jname» getByInt(int value){ |
|
||||
if (intMap == null) { |
|
||||
intMap = new HashMap<Integer, «$jname»>(); |
|
||||
for («$jname» s : «$jname».values()) { |
|
||||
intMap.put(s.value, s); |
|
||||
} |
|
||||
} |
|
||||
if (intMap.containsKey(value)) { |
|
||||
return intMap.get(value); |
|
||||
} |
|
||||
return null; |
|
||||
} |
|
||||
} |
|
||||
|| |
|
||||
} |
|
||||
|
|
||||
template "*", mode=entry { |
|
||||
const "ctype", "name(.)"; |
|
||||
const "type" call "toJava" with "type", "name(.)"; |
|
||||
const "itype" call "toIntermediate" with "type", "name(.)"; |
|
||||
const "name" call "toJava" with "type", "name(*[position()=1])"; |
|
||||
|
|
||||
choose { |
|
||||
when "$ctype = 'identity'" |
|
||||
|| |
|
||||
private native «$itype» _get«$name»(); |
|
||||
private native void _set«$name»(«$itype» value); |
|
||||
public «$type» get«$name»() { |
|
||||
«$itype» res = _get«$name»(); |
|
||||
if(res != null){ |
|
||||
return new «$type»(_get«$name»()); |
|
||||
}else{ |
|
||||
return null; |
|
||||
} |
|
||||
} |
|
||||
public void set«$name»(«$type» value) { |
|
||||
if(value != null) |
|
||||
_set«$name»(new «$itype»(value)); |
|
||||
else |
|
||||
_set«$name»(null); |
|
||||
} |
|
||||
|
|
||||
|| |
|
||||
|
|
||||
when "$ctype = 'identitylist' or $ctype = 'bloblist' or $ctype = 'stringlist' or $ctype = 'stringpairlist'" |
|
||||
{ |
|
||||
|
|
||||
const "ename", "substring-after(substring($type,1,string-length($type)-1), '<')"; |
|
||||
const "iename" choose { |
|
||||
when "$ctype = 'stringlist'" > byte[] |
|
||||
when "$ctype = 'stringpairlist'" > Pair<byte[],byte[]> |
|
||||
otherwise > _«$ename» |
|
||||
} |
|
||||
const "convget" choose { |
|
||||
when "$ctype = 'stringlist'" > AbstractEngine.toUTF16(i) |
|
||||
when "$ctype = 'stringpairlist'" > new Pair<String, String>(AbstractEngine.toUTF16(i.first), AbstractEngine.toUTF16(i.second)) |
|
||||
otherwise > new «$ename»(i) |
|
||||
} |
|
||||
const "convset" choose { |
|
||||
when "$ctype = 'stringlist'" > AbstractEngine.toUTF8(i) |
|
||||
when "$ctype = 'stringpairlist'" > new Pair<byte[],byte[]>(AbstractEngine.toUTF8(i.first), AbstractEngine.toUTF8(i.second)) |
|
||||
otherwise > new _«$ename»(i) |
|
||||
} |
|
||||
|| |
|
||||
private native «$itype» _get«$name»(); |
|
||||
private native void _set«$name»(«$itype» value); |
|
||||
public «$type» get«$name»() { |
|
||||
«$itype» glist = _get«$name»(); |
|
||||
if(glist != null){ |
|
||||
«$type» list = new «$type»(); |
|
||||
for («$iename» i : glist) |
|
||||
list.add(«$convget»); |
|
||||
return list; |
|
||||
} |
|
||||
return null; |
|
||||
} |
|
||||
public void set«$name»(«$type» value) { |
|
||||
if(value != null){ |
|
||||
«$itype» list = new «$itype»(); |
|
||||
for («$ename» i : value) |
|
||||
list.add(«$convset»); |
|
||||
_set«$name»(list); |
|
||||
}else{ |
|
||||
_set«$name»(null); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|| |
|
||||
} |
|
||||
|
|
||||
when "$itype != $type" |
|
||||
|| |
|
||||
private native «$itype» _get«$name»(); |
|
||||
private native void _set«$name»(«$itype» value); |
|
||||
public «$type» get«$name»() { |
|
||||
«$itype» res = _get«$name»(); |
|
||||
if(res != null) |
|
||||
return AbstractEngine.toUTF16(res); |
|
||||
else |
|
||||
return null; |
|
||||
} |
|
||||
public void set«$name»(«$type» value) { |
|
||||
if(value != null) |
|
||||
_set«$name»(AbstractEngine.toUTF8(value)); |
|
||||
else |
|
||||
_set«$name»(new byte[0]); |
|
||||
} |
|
||||
|
|
||||
|| |
|
||||
|
|
||||
when "$itype != $type" |
|
||||
|| |
|
||||
private native «$itype» _get«$name»(); |
|
||||
private native void _set«$name»(«$itype» value); |
|
||||
public «$type» get«$name»() { |
|
||||
«$itype» res = _get«$name»(); |
|
||||
if(res != null) |
|
||||
return AbstractEngine.toUTF16(res); |
|
||||
else |
|
||||
return null; |
|
||||
} |
|
||||
public void set«$name»(«$type» value) { |
|
||||
if(value != null) |
|
||||
_set«$name»(AbstractEngine.toUTF8(value)); |
|
||||
else |
|
||||
_set«$name»(null); |
|
||||
} |
|
||||
|
|
||||
|| |
|
||||
|
|
||||
when "../enum[@name=$ctype]" |
|
||||
|| |
|
||||
private native int _get«$name»(); |
|
||||
public «$itype» get«$name»() { |
|
||||
return «$itype».getByInt(_get«$name»()); |
|
||||
} |
|
||||
private native void _set«$name»(int value); |
|
||||
public void set«$name»(«$itype» value) { |
|
||||
if(value != null) |
|
||||
_set«$name»(value.value); |
|
||||
else |
|
||||
_set«$name»(0); |
|
||||
} |
|
||||
|
|
||||
|| |
|
||||
|
|
||||
otherwise |
|
||||
|| |
|
||||
public native «$itype» get«$name»(); |
|
||||
public native void set«$name»(«$itype» value); |
|
||||
|
|
||||
|| |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
template "*", mode=value { |
|
||||
const "name" call "toJava" with "type", "name(.)"; |
|
||||
| «$name» («.»)`if "position()!=last()" > , ` |
|
||||
} |
|
||||
} |
|
||||
|
|
@ -1,35 +0,0 @@ |
|||||
include yslt.yml2 |
|
||||
|
|
||||
tstylesheet { |
|
||||
include ./textutils.ysl2 |
|
||||
|
|
||||
template "/" { |
|
||||
| package foundation.pEp.jniadapter; |
|
||||
| |
|
||||
| public class pEpException extends RuntimeException { |
|
||||
| public pEpException(String message) { |
|
||||
| super(message); |
|
||||
| } |
|
||||
| } |
|
||||
|
|
||||
apply "namespace/exception[@name='Status']", 0; |
|
||||
} |
|
||||
|
|
||||
function "exception" { |
|
||||
param "name"; |
|
||||
|
|
||||
document "foundation/pEp/jniadapter/{$name}.java", "text" { |
|
||||
| package foundation.pEp.jniadapter; |
|
||||
| |
|
||||
| public class «$name» extends pEpException { |
|
||||
| public «$name»(String message) { |
|
||||
| super(message); |
|
||||
| } |
|
||||
| } |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
template "exception" for "*[text()!=0]" call "exception" |
|
||||
with "name" call "CamelCase" with "text", "name(.)"; |
|
||||
} |
|
||||
|
|
@ -1,64 +0,0 @@ |
|||||
include yslt.yml2 |
|
||||
|
|
||||
tstylesheet { |
|
||||
include ./textutils.ysl2 |
|
||||
|
|
||||
template "/" { |
|
||||
apply "namespace", 0; |
|
||||
document "throw_pEp_exception.hh", "text" |
|
||||
|| |
|
||||
#pragma once |
|
||||
|
|
||||
#include <jni.h> |
|
||||
|
|
||||
namespace pEp { |
|
||||
namespace JNIAdapter { |
|
||||
jint throw_pEp_Exception(JNIEnv *env, PEP_STATUS status); |
|
||||
}; |
|
||||
}; |
|
||||
|
|
||||
|| |
|
||||
|
|
||||
} |
|
||||
|
|
||||
template "namespace" |
|
||||
|| |
|
||||
#include <assert.h> |
|
||||
#include <pEp/pEpEngine.h> |
|
||||
#include "throw_pEp_exception.hh" |
|
||||
|
|
||||
namespace pEp { |
|
||||
namespace JNIAdapter { |
|
||||
jint throw_pEp_Exception(JNIEnv *env, PEP_STATUS status) |
|
||||
{ |
|
||||
jclass ex; |
|
||||
const char *ex_name; |
|
||||
|
|
||||
switch (status) { |
|
||||
`` apply "exception/*[text()!=0]", 4, mode=case |
|
||||
default: |
|
||||
assert(0); |
|
||||
ex_name = "Exception"; |
|
||||
} |
|
||||
|
|
||||
ex = env->FindClass(ex_name); |
|
||||
assert(ex); |
|
||||
|
|
||||
if (ex == NULL) { |
|
||||
ex = env->FindClass("java/lang/NoClassDefFoundError"); |
|
||||
assert(ex); |
|
||||
} |
|
||||
|
|
||||
return env->ThrowNew(ex, ex_name); |
|
||||
} |
|
||||
}; |
|
||||
}; |
|
||||
|| |
|
||||
|
|
||||
template "*", mode=case { |
|
||||
| case `call "UCASE" with "text", "name(.)"`: |
|
||||
| ex_name = "foundation/pEp/jniadapter/`call "CamelCase" with "text", "name(.)"`"; |
|
||||
| break; |
|
||||
} |
|
||||
} |
|
||||
|
|
@ -0,0 +1,12 @@ |
|||||
|
package foundation.pEp.jniadapter; |
||||
|
import java.util.concurrent.atomic.AtomicLong; |
||||
|
|
||||
|
// Abstract here so you can only inherit from, but not instantiate
|
||||
|
abstract public class UniquelyIdentifiable { |
||||
|
private static final AtomicLong NEXT_ID = new AtomicLong(1); |
||||
|
private final long id = NEXT_ID.getAndIncrement(); |
||||
|
|
||||
|
protected long getId() { |
||||
|
return id; |
||||
|
} |
||||
|
} |
@ -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<byte[]> toUTF8(Vector<String> list) { |
||||
|
if (list == null) |
||||
|
return null; |
||||
|
|
||||
|
Vector<byte[]> result = new Vector<byte[]>(list.size()); |
||||
|
|
||||
|
for (int i=0; i<list.size(); i++) |
||||
|
result.add(toUTF8(list.get(i))); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static Pair<byte[], byte[]> toUTF8(Pair<String, String> pair) { |
||||
|
if (pair == null) |
||||
|
return null; |
||||
|
|
||||
|
Pair<byte[], byte[]> result = new Pair<byte[], byte[]>(); |
||||
|
|
||||
|
result.first = toUTF8(pair.first); |
||||
|
result.second = toUTF8(pair.second); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static ArrayList<Pair<byte[], byte[]>> toUTF8(ArrayList<Pair<String, String>> list) { |
||||
|
if (list == null) |
||||
|
return null; |
||||
|
|
||||
|
ArrayList<Pair<byte[], byte[]>> result = new ArrayList<Pair<byte[], byte[]>>(list.size()); |
||||
|
|
||||
|
for (int i=0; i<list.size(); i++) |
||||
|
result.set(i, toUTF8(list.get(i))); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static String toUTF16(byte[] utf8) { |
||||
|
if (utf8 == null) |
||||
|
return null; |
||||
|
|
||||
|
try { |
||||
|
byte newUtf8[] = new byte[utf8.length]; |
||||
|
System.arraycopy(utf8,0,newUtf8,0,utf8.length); |
||||
|
|
||||
|
return new String(newUtf8, "UTF-8"); |
||||
|
} |
||||
|
catch (UnsupportedEncodingException e) { |
||||
|
assert false; |
||||
|
return new String(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static Vector<String> toUTF16(Vector<byte[]> list) { |
||||
|
if (list == null) |
||||
|
return null; |
||||
|
|
||||
|
Vector<String> result = new Vector<String>(list.size()); |
||||
|
|
||||
|
for (int i=0; i<list.size(); i++) |
||||
|
result.add(toUTF16(list.get(i))); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static Pair<String, String> toUTF16(Pair<byte[], byte[]> pair) { |
||||
|
if (pair == null) |
||||
|
return null; |
||||
|
|
||||
|
Pair<String, String> result = new Pair<String,String>(); |
||||
|
|
||||
|
result.first = toUTF16(pair.first); |
||||
|
result.second = toUTF16(pair.second); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static ArrayList<Pair<String, String>> toUTF16(ArrayList<Pair<byte[], byte[]>> list) { |
||||
|
if (list == null) |
||||
|
return null; |
||||
|
|
||||
|
ArrayList<Pair<String, String>> result = new ArrayList<Pair<String, String>>(list.size()); |
||||
|
|
||||
|
for (int i=0; i<list.size(); i++) |
||||
|
result.set(i, toUTF16(list.get(i))); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
package foundation.pEp.jniadapter; |
||||
|
|
||||
|
public class decrypt_message_Return { |
||||
|
public Message dst; |
||||
|
public Rating rating; |
||||
|
public int flags; |
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
package foundation.pEp.jniadapter.interfaces; |
||||
|
|
||||
|
import foundation.pEp.jniadapter.Message; |
||||
|
import foundation.pEp.jniadapter.Sync; |
||||
|
|
||||
|
public interface AbstractEngineInterface extends AutoCloseable { |
||||
|
public String getVersion(); |
||||
|
|
||||
|
public String getProtocolVersion(); |
||||
|
|
||||
|
public void startKeyserverLookup(); |
||||
|
|
||||
|
public void stopKeyserverLookup(); |
||||
|
|
||||
|
public void startSync(); |
||||
|
|
||||
|
public void stopSync(); |
||||
|
|
||||
|
public boolean isSyncRunning(); |
||||
|
|
||||
|
public void setMessageToSendCallback(Sync.MessageToSendCallback messageToSendCallback); |
||||
|
|
||||
|
public void setNotifyHandshakeCallback(Sync.NotifyHandshakeCallback notifyHandshakeCallback); |
||||
|
|
||||
|
public void setNeedsFastPollCallback(Sync.NeedsFastPollCallback needsFastPollCallback); |
||||
|
|
||||
|
public void setPassphraseRequiredCallback(Sync.PassphraseRequiredCallback passphraseRequiredCallback); |
||||
|
|
||||
|
public Message incomingMessageFromPGPText(String pgpText, Message.EncFormat encFormat); |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
package foundation.pEp.jniadapter.interfaces; |
||||
|
|
||||
|
public interface BlobInterface { |
||||
|
|
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
package foundation.pEp.jniadapter.interfaces; |
||||
|
|
||||
|
import foundation.pEp.jniadapter.Rating; |
||||
|
|
||||
|
public interface IdentityInterface { |
||||
|
public Rating getRating(); |
||||
|
} |
Loading…
Reference in new issue