Browse Source

JNI-123 - "get rid of c-style casts"

jni117
heck 5 years ago
parent
commit
3e71c76515
  1. 16
      src/codegen/gen_cpp_Engine.ysl2
  2. 16
      src/codegen/gen_cpp_Message.ysl2
  3. 18
      src/cxx/basic_api.cc
  4. 60
      src/cxx/foundation_pEp_jniadapter_AbstractEngine.cc
  5. 6
      src/cxx/foundation_pEp_jniadapter__Blob.cc
  6. 2
      src/cxx/identity_api.cc
  7. 64
      src/cxx/jniutils.cc

16
src/codegen/gen_cpp_Engine.ysl2

@ -206,8 +206,8 @@ tstylesheet {
jfieldID field_value = env->GetFieldID(clazz_«$ljtype», "value", "I");
assert(field_value);
jobjectArray values = (jobjectArray) env->CallStaticObjectMethod(clazz_«$ljtype»,
method_values);
jobjectArray values = static_cast<jobjectArray>(env->CallStaticObjectMethod(clazz_«$ljtype»,
method_values));
assert(values);
if (env->ExceptionCheck()) {
return nullptr; // handle exception in Java
@ -218,7 +218,7 @@ tstylesheet {
jobject element = env->GetObjectArrayElement(values, i);
assert(element);
jint value = env->GetIntField(element, field_value);
if (value == (jint) _«$name») {
if (value == static_cast<jint>(_«$name»)) {
«$name»_ = element;
break;
}
@ -235,7 +235,7 @@ tstylesheet {
assert(clazz_«$name»_);
jmethodID constructor_«$name»_ = env->GetMethodID(clazz_«$name»_, "<init>", "(J)V");
assert(constructor_«$name»_);
«$name»_ = env->NewObject(clazz_«$name»_, constructor_«$name»_, (jlong) _«$name»);
«$name»_ = env->NewObject(clazz_«$name»_, constructor_«$name»_, reinterpret_cast<jlong>(_«$name»));
}
||
@ -251,15 +251,15 @@ tstylesheet {
choose {
when "$type = 'message'"
| message *_«$name» = (message *) callLongMethod(env, «$name», "getHandle");
| message *_«$name» = reinterpret_cast<message *>(callLongMethod(env, «$name», "getHandle"));
when "$type='EncFormat' or $type='SyncHandshakeResult' or $type='CipherSuite'"
| √$type _«$name» = to_«$type»(env, «$name»);
when "$type='bool'"
| bool _«$name» = (bool) «$name»;
| bool _«$name» = «$name»;
when "$type='int'"
| int _«$name» = (int) «$name»;
| int _«$name» = «$name»;
when "$type='uint'"
| auto _«$name» = (unsigned int) «$name»;
| unsigned int _«$name» = «$name»;
when "$type='string'"
| const char *_«$name» = to_string(env, «$name»);
otherwise {

16
src/codegen/gen_cpp_Message.ysl2

@ -37,7 +37,7 @@ tstylesheet {
return NULL;
}
return (::«@name» *) (intptr_t) (int64_t) env->GetLongField(me, handle);
return reinterpret_cast<::«@name» *>(env->GetLongField(me, handle));
}
};
};
@ -52,16 +52,16 @@ tstylesheet {
::«@name» * _obj = ::new_«@name»(PEP_dir_incoming);
if (!_obj) {
outOfMemory(env);
return (jlong) 0;
return 0;
}
return (jlong) (int64_t) (intptr_t) _obj;
return reinterpret_cast<jlong>(_obj);
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_«$jname»_release(JNIEnv *env, jobject obj, jlong value)
{
pEpLog("called");
if (value) {
::«@name» *_obj = (::«@name» *) (intptr_t) (int64_t) value;
::«@name» *_obj = reinterpret_cast<::«@name» *>(value);
::free_«@name»(_obj);
}
}
@ -70,13 +70,13 @@ tstylesheet {
{
pEpLog("called");
char *_mime_text = to_string(env, mime_text);
size_t _size = (size_t) env->GetArrayLength(mime_text);
size_t _size = env->GetArrayLength(mime_text);
::«@name» *_msg = nullptr;
PEP_STATUS status = mime_decode_«@name»(_mime_text, _size, &_msg, NULL);
if (status)
throw_pEp_Exception(env, status);
return (jlong) (int64_t) (intptr_t) _msg;
return reinterpret_cast<jlong>(_msg);
}
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_«$jname»__1encodeMIME(JNIEnv *env, jobject msg)
@ -141,7 +141,7 @@ tstylesheet {
||
choose {
when "../enum[@name=$type]"
|> return (jint) _obj->«$cname»;
|> return _obj->«$cname»;
otherwise
|> return from_«$type»(env, _obj->«$cname»);
}
@ -155,7 +155,7 @@ tstylesheet {
||
choose {
when "../enum[@name=$type]"
|> _obj->«$cname» = («$ctype») (int) value;
|> _obj->«$cname» = static_cast<«$ctype»>(value);
otherwise {
choose {
when "$type = 'string'" {

18
src/cxx/basic_api.cc

@ -60,7 +60,7 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1trustwords(
lang = "en";
status = passphraseWrap(::trustwords,
session(), (const char *) _ident->fpr, lang, &words, &wsize, 10);
session(), static_cast<const char*>(_ident->fpr), lang, &words, &wsize, 10);
if (status != PEP_STATUS_OK) {
throw_pEp_Exception(env, status);
@ -298,8 +298,8 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1importKey(
}
std::lock_guard<std::mutex> l(*mutex_local);
size_t _size = (size_t) env->GetArrayLength(key);
const char *_key = (char *) env->GetByteArrayElements(key, NULL);
size_t _size = static_cast<size_t>(env->GetArrayLength(key));
jbyte* _key = env->GetByteArrayElements(key, NULL);
if(_key == NULL){
throw_pEp_Exception(env, PEP_OUT_OF_MEMORY);
@ -308,7 +308,7 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1importKey(
identity_list *_identities;
PEP_STATUS status = passphraseWrap(::import_key, session(), _key, _size, &_identities);
PEP_STATUS status = passphraseWrap(::import_key, session(), reinterpret_cast<const char*>(_key), _size, &_identities);
if (status != PEP_STATUS_OK && status != PEP_KEY_IMPORTED) {
throw_pEp_Exception(env, status);
return NULL;
@ -319,7 +319,7 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1importKey(
identities_ = from_identitylist(env, _identities);
}
env->ReleaseByteArrayElements(key, (jbyte *) _key, JNI_ABORT);
env->ReleaseByteArrayElements(key, _key, JNI_ABORT);
return identities_;
}
@ -338,7 +338,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passive_1
}
std::lock_guard<std::mutex> l(*mutex_local);
::config_passive_mode(session(), (bool)enable);
::config_passive_mode(session(), static_cast<bool>(enable));
}
@ -356,7 +356,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1unencrypt
}
std::lock_guard<std::mutex> l(*mutex_local);
::config_unencrypted_subject(session(), (bool)enable);
::config_unencrypted_subject(session(), static_cast<bool>(enable));
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1add(
@ -463,7 +463,7 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1getCrashdum
}
std::lock_guard<std::mutex> l(*mutex_local);
int _maxlines = (int) maxlines;
int _maxlines = static_cast<int>(maxlines);
char *_logdata;
PEP_STATUS status = passphraseWrap(::get_crashdump_log, session(), _maxlines, &_logdata);
@ -545,7 +545,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphras
}
std::lock_guard<std::mutex> l(*mutex_local);
bool _enable = (bool) enable;
bool _enable = static_cast<bool>(enable);
const char *_passphrase = to_string(env, passphrase);
PEP_STATUS status = ::config_passphrase_for_new_keys(session(),_enable,passphrase_cache.add_stored(_passphrase));

60
src/cxx/foundation_pEp_jniadapter_AbstractEngine.cc

@ -42,12 +42,12 @@ jclass passphraseTypeClass = nullptr;
namespace JNISync {
JNIEnv* env() {
JNIEnv *thread_env = nullptr;
int status = jvm->GetEnv((void**)&thread_env, JNI_VERSION_1_6);
int status = jvm->GetEnv(reinterpret_cast<void**>(&thread_env), JNI_VERSION_1_6);
if (status < 0) {
#ifdef ANDROID
status = jvm->AttachCurrentThread(&thread_env, nullptr);
#else
status = jvm->AttachCurrentThread((void **) &thread_env, nullptr);
status = jvm->AttachCurrentThread(reinterpret_cast<void**>(&thread_env), nullptr);
#endif
}
assert(status >= 0);
@ -69,15 +69,15 @@ namespace JNISync {
void jni_init() {
JNIEnv *_env = JNISync::env();
messageClass = reinterpret_cast<jclass>(
messageClass = static_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Message")));
identityClass = reinterpret_cast<jclass>(
identityClass = static_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/_Identity")));
signalClass = reinterpret_cast<jclass>(
signalClass = static_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/SyncHandshakeSignal")));
passphraseTypeClass = reinterpret_cast<jclass>(
passphraseTypeClass = static_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/PassphraseType")));
engineClass = reinterpret_cast<jclass>(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Engine")));
engineClass = static_cast<jclass>(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Engine")));
messageConstructorMethodID = _env->GetMethodID(messageClass, "<init>", "(J)V");
messageToSendMethodID = _env->GetMethodID(
@ -113,8 +113,8 @@ char* JNIAdapter::passphraseRequiredCallback(const PEP_STATUS status) {
assert(passphrase_status_values);
assert(passphrase_type_field_value);
jobjectArray values = (jobjectArray) JNISync::env()->CallStaticObjectMethod(passphraseTypeClass,
passphrase_status_values);
jobjectArray values = static_cast<jobjectArray>(JNISync::env()->CallStaticObjectMethod(passphraseTypeClass,
passphrase_status_values));
if (JNISync::env()->ExceptionCheck()) {
JNISync::env()->ExceptionClear();
@ -126,7 +126,7 @@ char* JNIAdapter::passphraseRequiredCallback(const PEP_STATUS status) {
jobject element = JNISync::env()->GetObjectArrayElement(values, i);
assert(element);
jint value = JNISync::env()->GetIntField(element, passphrase_type_field_value);
if (value == (jint) status) {
if (value == static_cast<jint>(status)) {
status_ = element;
break;
}
@ -141,7 +141,7 @@ char* JNIAdapter::passphraseRequiredCallback(const PEP_STATUS status) {
JNISync::env()->ExceptionClear();
}
jbyteArray ppJBA = reinterpret_cast<jbyteArray>(ppJO);
jbyteArray ppJBA = static_cast<jbyteArray>(ppJO);
char* passphrase_ = to_string( JNISync::env(), ppJBA);
return passphrase_;
@ -166,7 +166,7 @@ PEP_STATUS messageToSend(message *msg)
jobject msg_ = nullptr;
assert(messageClass && messageConstructorMethodID && objj && messageToSendMethodID);
msg_ = JNISync::env()->NewObject(messageClass, messageConstructorMethodID, (jlong) msg);
msg_ = JNISync::env()->NewObject(messageClass, messageConstructorMethodID, reinterpret_cast<jlong>(msg));
PEP_STATUS status = (PEP_STATUS) JNISync::env()->CallIntMethod(objj, messageToSendMethodID, msg_);
if (JNISync::env()->ExceptionCheck()) {
@ -196,8 +196,8 @@ PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handsha
assert(sync_handshake_signal_values);
assert(signal_field_value);
jobjectArray values = (jobjectArray) JNISync::env()->CallStaticObjectMethod(signalClass,
sync_handshake_signal_values);
jobjectArray values = static_cast<jobjectArray>(JNISync::env()->CallStaticObjectMethod(signalClass,
sync_handshake_signal_values));
if (JNISync::env()->ExceptionCheck()) {
JNISync::env()->ExceptionClear();
return PEP_UNKNOWN_ERROR;
@ -208,7 +208,7 @@ PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handsha
jobject element = JNISync::env()->GetObjectArrayElement(values, i);
assert(element);
jint value = JNISync::env()->GetIntField(element, signal_field_value);
if (value == (jint) signal) {
if (value == static_cast<jint>(signal)) {
signal_ = element;
break;
}
@ -298,7 +298,7 @@ JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1getPro
int examine_identity(pEp_identity *ident, void *arg)
{
locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg;
locked_queue< pEp_identity * > *queue = static_cast<locked_queue<pEp_identity*>*>(arg);
queue->push_back(identity_dup(ident));
return 0;
}
@ -306,7 +306,7 @@ int examine_identity(pEp_identity *ident, void *arg)
pEp_identity *retrieve_next_identity(void *arg)
{
pEpLog("called");
locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg;
locked_queue< pEp_identity * > *queue = static_cast<locked_queue<pEp_identity*>*>(arg);
while (!queue->size())
usleep(100000);
@ -319,7 +319,7 @@ pEp_identity *retrieve_next_identity(void *arg)
static void *keyserver_thread_routine(void *arg)
{
PEP_STATUS status = do_keymanagement(retrieve_next_identity, arg);
locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg;
locked_queue< pEp_identity * > *queue = static_cast<locked_queue<pEp_identity*>*>(arg);
while (queue->size()) {
pEp_identity *ident = queue->front();
@ -328,7 +328,7 @@ static void *keyserver_thread_routine(void *arg)
}
delete queue;
return (void *) status;
return reinterpret_cast<void*>(status);
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startKeyserverLookup(
@ -359,20 +359,20 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startKeys
return;
}
thread = (pthread_t *) env->GetLongField(obj, thread_handle);
thread = reinterpret_cast<pthread_t*>(env->GetLongField(obj, thread_handle));
if (thread)
return;
thread = (pthread_t *) calloc(1, sizeof(pthread_t));
thread = static_cast<pthread_t*>(calloc(1, sizeof(pthread_t)));
assert(thread);
env->SetLongField(obj, thread_handle, (jlong) thread);
env->SetLongField(obj, thread_handle, reinterpret_cast<jlong>(thread));
queue = new locked_queue< pEp_identity * >();
env->SetLongField(obj, queue_handle, (jlong) queue);
env->SetLongField(obj, queue_handle, reinterpret_cast<jlong>(queue));
register_examine_function(Adapter::session(), examine_identity, (void *) queue);
register_examine_function(Adapter::session(), examine_identity,static_cast<void*>(queue));
pthread_create(thread, nullptr, keyserver_thread_routine, (void *) queue);
pthread_create(thread, nullptr, keyserver_thread_routine, static_cast<void*>(queue));
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopKeyserverLookup(
@ -403,14 +403,14 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopKeyse
return;
}
thread = (pthread_t *) env->GetLongField(obj, thread_handle);
thread = reinterpret_cast<pthread_t*>(env->GetLongField(obj, thread_handle));
if (!thread)
return;
queue = (locked_queue< pEp_identity * > *) env->GetLongField(obj, queue_handle);
queue = reinterpret_cast<locked_queue<pEp_identity*>*>(env->GetLongField(obj, queue_handle));
env->SetLongField(obj, queue_handle, (jlong) 0);
env->SetLongField(obj, thread_handle, (jlong) 0);
env->SetLongField(obj, queue_handle, 0);
env->SetLongField(obj, thread_handle, 0);
register_examine_function(Adapter::session(), nullptr, nullptr);
@ -471,7 +471,7 @@ JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1isSyn
}
std::lock_guard<std::mutex> l(*mutex_local);
return (jboolean) Adapter::is_sync_running();
return static_cast<jboolean>(Adapter::is_sync_running());
}
} // extern "C"

6
src/cxx/foundation_pEp_jniadapter__Blob.cc

@ -20,7 +20,7 @@ namespace pEp {
return NULL;
}
return (::bloblist_t *) (intptr_t) (int64_t) env->GetLongField(me, handle);
return reinterpret_cast<::bloblist_t*>(env->GetLongField(me, handle));
}
};
};
@ -38,7 +38,7 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter__1Blob__1dataToXER(J
// RFC 1049 / RFC 2045 : The type, subtype, and parameter names are not case sensitive.
if(strcasecmp(b->mime_type, "application/pEp.sync") == 0) {
PEP_STATUS status = ::PER_to_XER_Sync_msg(b->value, (size_t) b->size, &out);
PEP_STATUS status = ::PER_to_XER_Sync_msg(b->value, static_cast<size_t>(b->size), &out);
if (status)
throw_pEp_Exception(env, status);
@ -49,7 +49,7 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter__1Blob__1dataToXER(J
// RFC 1049 / RFC 2045 : The type, subtype, and parameter names are not case sensitive.
if(strcasecmp(b->mime_type, "application/pEp.keyreset") == 0) {
PEP_STATUS status = ::PER_to_XER_Distribution_msg(b->value, (size_t) b->size, &out);
PEP_STATUS status = ::PER_to_XER_Distribution_msg(b->value, static_cast<size_t>(b->size), &out);
if (status)
throw_pEp_Exception(env, status);

2
src/cxx/identity_api.cc

@ -9,7 +9,7 @@ extern "C" {
JNIEXPORT jint JNICALL Java_foundation_pEp_jniadapter_Identity__1getRating(JNIEnv *env, jobject thiz, jint comm_type)
{
pEpLog("called");
return ::rating_from_comm_type((PEP_comm_type) comm_type);
return ::rating_from_comm_type(static_cast<PEP_comm_type>(comm_type));
}
} // extern "C"

64
src/cxx/jniutils.cc

@ -20,7 +20,7 @@ namespace pEp {
jobject obj
)
{
long engine_obj_id = (long)callLongMethod(env, obj, "getId");
long engine_obj_id = static_cast<long>(callLongMethod(env, obj, "getId"));
assert(engine_obj_id);
pEpLog("for java object id: " << engine_obj_id);
std::mutex *engine_obj_mutex = engine_objid_mutex.at(engine_obj_id);
@ -34,7 +34,7 @@ namespace pEp {
jobject obj
)
{
long engine_obj_id = (long)callLongMethod(env, obj, "getId");
long engine_obj_id = static_cast<long>(callLongMethod(env, obj, "getId"));
assert(engine_obj_id);
std::mutex *engine_obj_mutex = new std::mutex();
pEpLog(engine_obj_mutex << " with native_handle: " << engine_obj_mutex->native_handle() << " for java object id: " << engine_obj_id);
@ -51,7 +51,7 @@ namespace pEp {
jobject obj
)
{
long engine_obj_id = (long)callLongMethod(env, obj, "getId");
long engine_obj_id = static_cast<long>(callLongMethod(env, obj, "getId"));
assert(engine_obj_id);
std::mutex *engine_obj_mutex = engine_objid_mutex.at(engine_obj_id);
pEpLog(engine_obj_mutex << " with native_handle: " << engine_obj_mutex->native_handle() << " for java object id: " << engine_obj_id);
@ -278,7 +278,7 @@ namespace pEp {
return NULL;
size_t l = env->GetArrayLength(str);
char *_str = (char *) calloc(1,l+1);
char *_str = static_cast<char*>(calloc(1,l+1));
assert(_str);
env->GetByteArrayRegion(str, 0, l, (jbyte*)_str);
return _str;
@ -320,7 +320,7 @@ namespace pEp {
jint i;
for (_sl = sl, i = 0; i < (int) size; i++) {
jobject o = callObjectMethod(env, obj, "get", i);
jbyteArray a = reinterpret_cast<jbyteArray>(o);
jbyteArray a = static_cast<jbyteArray>(o);
char * str = to_string(env, a);
_sl = stringlist_add(_sl, str);
env->DeleteLocalRef(o);
@ -391,10 +391,10 @@ namespace pEp {
for (_sl = sl, i = 0; i < (int) size; i++) {
jobject pair = callObjectMethod(env, obj, "get", i);
jbyteArray first =
reinterpret_cast<jbyteArray>(env->GetObjectField(pair,
static_cast<jbyteArray>(env->GetObjectField(pair,
first_id));
jbyteArray second =
reinterpret_cast<jbyteArray>(env->GetObjectField(pair,
static_cast<jbyteArray>(env->GetObjectField(pair,
second_id));
char *first_str = to_string(env, first);
@ -413,7 +413,7 @@ namespace pEp {
jobject from_timestamp(JNIEnv *env, timestamp *ts)
{
if (!ts)
return (jobject) NULL;
return NULL;
//LOGD("/* Seconds (0-60) */ FROM :%d", ts->tm_sec);
//LOGD("/* Minutes (0-59) */ :%d", ts->tm_min);
@ -443,7 +443,7 @@ namespace pEp {
jlong t = callLongMethod(env, date, "getTime");
//LOGD( "Set Time to : %lld", t);
timestamp *ts = (timestamp*)calloc(1, sizeof(timestamp));
timestamp *ts = static_cast<timestamp*>(calloc(1, sizeof(timestamp)));
assert(ts);
if (ts == NULL)
return NULL;
@ -468,8 +468,7 @@ namespace pEp {
{
if (value) {
jfieldID fieldID = getFieldID(env, classname, name, "[B");
env->SetObjectField(obj, fieldID,
reinterpret_cast<jobject>(from_string(env, value)));
env->SetObjectField(obj, fieldID, static_cast<jobject>(from_string(env, value)));
}
}
@ -480,8 +479,7 @@ namespace pEp {
{
if (value) {
jfieldID fieldID = getFieldID(env, classname, name, "[B", clazz);
env->SetObjectField(obj, fieldID,
reinterpret_cast<jobject>(from_string(env, value)));
env->SetObjectField(obj, fieldID, static_cast<jobject>(from_string(env, value)));
}
}
@ -506,15 +504,15 @@ namespace pEp {
_setStringField(env, classname, obj, "username", ident->username);
jfieldID comm_type_id = getFieldID(env, classname, "comm_type", "I");
env->SetIntField(obj, comm_type_id, (jint) (int) ident->comm_type);
env->SetIntField(obj, comm_type_id, static_cast<jint>(ident->comm_type));
_setStringField(env, classname, obj, "lang", ident->lang);
jfieldID me_id = getFieldID(env, classname, "me", "Z");
env->SetBooleanField(obj, me_id, (jboolean) ident->me);
env->SetBooleanField(obj, me_id, static_cast<jboolean>(ident->me));
jfieldID flags_id = getFieldID(env, classname, "flags", "I");
env->SetIntField(obj, flags_id, (jint) (int) ident->flags);
env->SetIntField(obj, flags_id, static_cast<jint>(ident->flags));
}
return obj;
@ -538,15 +536,15 @@ namespace pEp {
_setStringField(env, classname, obj, "username", ident->username, identityClass);
jfieldID comm_type_id = getFieldID(env, classname, "comm_type", "I", identityClass);
env->SetIntField(obj, comm_type_id, (jint) (int) ident->comm_type);
env->SetIntField(obj, comm_type_id, static_cast<jint>(ident->comm_type));
_setStringField(env, classname, obj, "lang", ident->lang, identityClass);
jfieldID me_id = getFieldID(env, classname, "me", "Z", identityClass);
env->SetBooleanField(obj, me_id, (jboolean) ident->me);
env->SetBooleanField(obj, me_id, static_cast<jboolean>(ident->me));
jfieldID flags_id = getFieldID(env, classname, "flags", "I", identityClass);
env->SetIntField(obj, flags_id, (jint) (int) ident->flags);
env->SetIntField(obj, flags_id, static_cast<jint>(ident->flags));
}
return obj;
@ -558,7 +556,7 @@ namespace pEp {
jfieldID fieldID = getFieldID(env, classname, name, "[B");
jobject fobj = env->GetObjectField(obj, fieldID);
char *res = to_string(env, reinterpret_cast<jbyteArray>(fobj));
char *res = to_string(env, static_cast<jbyteArray>(fobj));
env->DeleteLocalRef(fobj);
return res;
@ -578,7 +576,7 @@ namespace pEp {
ident->username = _getStringField(env, classname, obj, "username");
jfieldID comm_type_id = getFieldID(env, classname, "comm_type", "I");
ident->comm_type = (PEP_comm_type) (int) env->GetIntField(obj, comm_type_id);
ident->comm_type = static_cast<PEP_comm_type>(env->GetIntField(obj, comm_type_id));
char *lang = _getStringField(env, classname, obj, "lang");
if (lang && lang[0]) {
@ -588,10 +586,10 @@ namespace pEp {
free(lang);
jfieldID me_id = getFieldID(env, classname, "me", "Z");
ident->me = (bool) env->GetBooleanField(obj, me_id);
ident->me = static_cast<bool>(env->GetBooleanField(obj, me_id));
jfieldID flags_id = getFieldID(env, classname, "flags", "I");
ident->flags = (identity_flags_t) (int) env->GetIntField(obj, flags_id);
ident->flags = static_cast<identity_flags_t>(env->GetIntField(obj, flags_id));
return ident;
}
@ -654,9 +652,9 @@ namespace pEp {
env->DeleteLocalRef(clazz);
jfieldID fieldID = getFieldID(env, classname, "data", "[B");
jbyteArray _data = env->NewByteArray((jsize) b->size);
env->SetByteArrayRegion(_data, 0, b->size, (jbyte*)b->value);
env->SetObjectField(obj, fieldID, reinterpret_cast<jobject>(_data));
jbyteArray _data = env->NewByteArray(static_cast<jsize>(b->size));
env->SetByteArrayRegion(_data, 0, b->size, reinterpret_cast<jbyte*>(b->value));
env->SetObjectField(obj, fieldID, static_cast<jobject>(_data));
_setStringField(env, classname, obj, "mime_type", b->mime_type);
_setStringField(env, classname, obj, "filename", b->filename);
@ -698,12 +696,12 @@ namespace pEp {
char *filename = _getStringField(env, classname, obj, "filename");
jfieldID data_id = getFieldID(env, classname, "data", "[B");
jbyteArray _data = reinterpret_cast<jbyteArray>(env->GetObjectField(obj, data_id));
size_t size = (size_t) env->GetArrayLength(_data);
char *b = (char *) malloc(size);
jbyteArray _data = static_cast<jbyteArray>(env->GetObjectField(obj, data_id));
size_t size = static_cast<size_t>(env->GetArrayLength(_data));
char *b = static_cast<char *>(malloc(size));
assert(b);
env->GetByteArrayRegion(_data, 0, size, (jbyte*)b);
env->GetByteArrayRegion(_data, 0, size, reinterpret_cast<jbyte*>(b));
bloblist_t *bl = new_bloblist( b, size, mime_type, filename);
free(mime_type);
@ -743,7 +741,7 @@ namespace pEp {
assert(field_value);
env->DeleteLocalRef(clazz_enc_format);
return (PEP_enc_format) env->GetIntField(obj, field_value);
return static_cast<PEP_enc_format>(env->GetIntField(obj, field_value));
}
PEP_CIPHER_SUITE to_CipherSuite(JNIEnv *env, jobject obj)
@ -754,7 +752,7 @@ namespace pEp {
assert(field_value);
env->DeleteLocalRef(clazz_enc_format);
return (PEP_CIPHER_SUITE) env->GetIntField(obj, field_value);
return static_cast<PEP_CIPHER_SUITE>(env->GetIntField(obj, field_value));
}
sync_handshake_result to_SyncHandshakeResult(JNIEnv *env, jobject obj)
@ -765,7 +763,7 @@ namespace pEp {
assert(field_value);
env->DeleteLocalRef(clazz_enc_format);
return (sync_handshake_result) env->GetIntField(obj, field_value);
return static_cast<sync_handshake_result>(env->GetIntField(obj, field_value));
}
};
};

Loading…
Cancel
Save