Fixes for bugs pointed out by updating warnings

This commit is contained in:
Grant Limberg 2015-04-29 19:29:35 -07:00
parent 0a2d1e7a66
commit 7e0cc28a89
3 changed files with 103 additions and 100 deletions

View File

@ -111,12 +111,18 @@ jobject createEvent(JNIEnv *env, ZT1_Event event)
case ZT1_EVENT_OFFLINE:
fieldName = "EVENT_OFFLINE";
break;
case ZT1_EVENT_ONLINE:
fieldName = "EVENT_ONLINE";
break;
case ZT1_EVENT_DOWN:
fieldName = "EVENT_DOWN";
break;
case ZT1_EVENT_FATAL_ERROR_IDENTITY_COLLISION:
fieldName = "EVENT_FATAL_ERROR_IDENTITY_COLLISION";
break;
case ZT1_EVENT_SAW_MORE_RECENT_VERSION:
fieldName = "EVENT_SAW_MORE_RECENT_VERSION";
break;
case ZT1_EVENT_AUTHENTICATION_FAILURE:
fieldName = "EVENT_AUTHENTICATION_FAILURE";
break;
@ -332,7 +338,7 @@ jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr)
jclass inetSocketAddressClass = NULL;
jmethodID inetSocketAddress_constructor = NULL;
inetSocketAddressClass == env->FindClass("java/net/InetSocketAddress");
inetSocketAddressClass = env->FindClass("java/net/InetSocketAddress");
if(inetSocketAddressClass == NULL)
{
return NULL;
@ -631,155 +637,124 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig
jfieldID multicastSubscriptionsField = NULL;
jfieldID assignedAddressesField = NULL;
vnetConfigClass = env->FindClass("com/zerotierone/sdk/VirtualNetworkConfig");
if(vnetConfigClass == NULL)
{
vnetConfigClass = env->FindClass("com/zerotierone/sdk/VirtualNetworkConfig");
if(vnetConfigClass == NULL)
{
return NULL;
}
LOGE("Couldn't find com.zerotierone.sdk.VirtualNetworkConfig");
return NULL;
}
vnetConfig_constructor = env->GetMethodID(
vnetConfigClass, "<init>", "()V");
if(vnetConfig_constructor == NULL)
{
jmethodID vnetConfig_constructor = env->GetMethodID(
vnetConfigClass, "<init>", "()V");
if(vnetConfig_constructor == NULL)
{
return NULL;
}
LOGE("Couldn't find VirtualNetworkConfig Constructor");
return NULL;
}
jobject vnetConfigObj = env->NewObject(vnetConfigClass, vnetConfig_constructor);
if(vnetConfigObj == NULL)
{
LOGE("Error creating new VirtualNetworkConfig object");
return NULL;
}
nwidField = env->GetFieldID(vnetConfigClass, "nwid", "J");
if(nwidField == NULL)
{
nwidField = env->GetFieldID(vnetConfigClass, "nwid", "J");
if(nwidField == NULL)
{
return NULL;
}
LOGE("Error getting nwid field");
return NULL;
}
macField = env->GetFieldID(vnetConfigClass, "mac", "J");
if(macField == NULL)
{
macField = env->GetFieldID(vnetConfigClass, "mac", "J");
if(macField == NULL)
{
return NULL;
}
LOGE("Error getting mac field");
return NULL;
}
nameField = env->GetFieldID(vnetConfigClass, "name", "Ljava/lang/String;");
if(nameField == NULL)
{
nameField = env->GetFieldID(vnetConfigClass, "name", "Ljava/lang/String;");
if(nameField == NULL)
{
return NULL;
}
LOGE("Error getting name field");
return NULL;
}
statusField = env->GetFieldID(vnetConfigClass, "status", "Lcom/zerotierone/sdk/VirtualNetworkStatus;");
if(statusField == NULL)
{
statusField = env->GetFieldID(vnetConfigClass, "status", "Lcom/zerotierone/sdk/VirtualNetworStatus;");
if(statusField == NULL)
{
return NULL;
}
LOGE("Error getting status field");
return NULL;
}
typeField = env->GetFieldID(vnetConfigClass, "type", "Lcom/zerotierone/sdk/VirtualNetworkType;");
if(typeField == NULL)
{
typeField = env->GetFieldID(vnetConfigClass, "type", "Lcom/zerotierone/sdk/VirtualNetworkType;");
if(typeField == NULL)
{
return NULL;
}
LOGE("Error getting type field");
return NULL;
}
mtuField = env->GetFieldID(vnetConfigClass, "mtu", "I");
if(mtuField == NULL)
{
mtuField = env->GetFieldID(vnetConfigClass, "mtu", "I");
if(mtuField == NULL)
{
return NULL;
}
LOGE("Error getting mtu field");
return NULL;
}
dhcpField = env->GetFieldID(vnetConfigClass, "dhcp", "Z");
if(dhcpField == NULL)
{
dhcpField = env->GetFieldID(vnetConfigClass, "dhcp", "Z");
if(dhcpField == NULL)
{
return NULL;
}
LOGE("Error getting dhcp field");
return NULL;
}
bridgeField = env->GetFieldID(vnetConfigClass, "bridge", "Z");
if(bridgeField == NULL)
{
bridgeField = env->GetFieldID(vnetConfigClass, "bridge", "Z");
if(bridgeField == NULL)
{
return NULL;
}
LOGE("Error getting bridge field");
return NULL;
}
broadcastEnabledField = env->GetFieldID(vnetConfigClass, "broadcastEnabled", "Z");
if(broadcastEnabledField == NULL)
{
broadcastEnabledField = env->GetFieldID(vnetConfigClass, "broadcastEnabled", "Z");
if(broadcastEnabledField == NULL)
{
return NULL;
}
LOGE("Error getting broadcastEnabled field");
return NULL;
}
portErrorField = env->GetFieldID(vnetConfigClass, "portError", "I");
if(portErrorField == NULL)
{
portErrorField == env->GetFieldID(vnetConfigClass, "portError", "I");
if(portErrorField == NULL)
{
return NULL;
}
LOGE("Error getting portError field");
return NULL;
}
enabledField = env->GetFieldID(vnetConfigClass, "enabled", "Z");
if(enabledField == NULL)
{
enabledField = env->GetFieldID(vnetConfigClass, "enabled", "Z");
if(enabledField == NULL)
{
return NULL;
}
LOGE("Error getting enabled field");
return NULL;
}
netconfRevisionField = env->GetFieldID(vnetConfigClass, "netconfRevision", "J");
if(netconfRevisionField == NULL)
{
netconfRevisionField = env->GetFieldID(vnetConfigClass, "netconfRevision", "J");
if(netconfRevisionField == NULL)
{
return NULL;
}
LOGE("Error getting netconfRevision field");
return NULL;
}
multicastSubscriptionsField = env->GetFieldID(vnetConfigClass, "multicastSubscriptions", "Ljava/util/ArrayList;");
if(multicastSubscriptionsField == NULL)
{
multicastSubscriptionsField = env->GetFieldID(vnetConfigClass, "multicastSubscriptions", "Ljava/util/ArrayList;");
if(multicastSubscriptionsField == NULL)
{
return NULL;
}
LOGE("Error getting multicastSubscriptions field");
return NULL;
}
assignedAddressesField = env->GetFieldID(vnetConfigClass, "assignedAddresses", "Ljava/util/ArrayList;");
if(assignedAddressesField == NULL)
{
assignedAddressesField = env->GetFieldID(vnetConfigClass, "assignedAddresses", "Ljava/util/ArrayList;");
if(assignedAddressesField == NULL)
{
return NULL;
}
LOGE("Error getting assignedAddresses field");
return NULL;
}
env->SetLongField(vnetConfigObj, nwidField, vnetConfig.nwid);
@ -865,7 +840,7 @@ jobject newVersion(JNIEnv *env, int major, int minor, int rev, long featureFlags
jfieldID featureFlagsField = NULL;
majorField = env->GetFieldID(versionClass, "major", "I");
if(majorField = NULL)
if(majorField == NULL)
{
return NULL;
}
@ -892,6 +867,8 @@ jobject newVersion(JNIEnv *env, int major, int minor, int rev, long featureFlags
env->SetIntField(versionObj, minorField, (jint)minor);
env->SetIntField(versionObj, revisionField, (jint)rev);
env->SetLongField(versionObj, featureFlagsField, (jlong)featureFlags);
return versionObj;
}
#ifdef __cplusplus

View File

@ -53,6 +53,19 @@ namespace {
, configListener(NULL)
{}
~JniRef()
{
JNIEnv *env = NULL;
jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
env->DeleteGlobalRef(dataStoreGetListener);
env->DeleteGlobalRef(dataStorePutListener);
env->DeleteGlobalRef(packetSender);
env->DeleteGlobalRef(eventListener);
env->DeleteGlobalRef(frameListener);
env->DeleteGlobalRef(configListener);
}
uint64_t id;
JavaVM *jvm;
@ -250,7 +263,7 @@ namespace {
{
const char* message = (const char*)data;
jstring messageStr = env->NewStringUTF(message);
env->CallVoidMethod(ref->eventListener, onTraceMethod);
env->CallVoidMethod(ref->eventListener, onTraceMethod, messageStr);
}
}
break;
@ -356,12 +369,12 @@ namespace {
// set operation
jbyteArray bufferObj = env->NewByteArray(bufferSize);
env->SetByteArrayRegion(bufferObj, 0, bufferSize, (jbyte*)buffer);
bool secure = secure != 0;
bool bsecure = secure != 0;
return env->CallIntMethod(ref->dataStorePutListener,
dataStorePutCallbackMethod,
nameStr, bufferObj, secure);
nameStr, bufferObj, bsecure);
}
}
@ -439,11 +452,12 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_node_1init(
return NULL; // exception already thrown
}
ref->dataStoreGetListener = env->GetObjectField(obj, fid);
if(ref->dataStoreGetListener == NULL)
jobject tmp = env->GetObjectField(obj, fid);
if(tmp == NULL)
{
return NULL;
}
ref->dataStoreGetListener = env->NewGlobalRef(tmp);
fid = env->GetFieldID(
cls, "putListener", "Lcom/zerotierone/sdk/DataStorePutListener;");
@ -453,11 +467,12 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_node_1init(
return NULL; // exception already thrown
}
ref->dataStorePutListener = env->GetObjectField(obj, fid);
if(ref->dataStorePutListener == NULL)
tmp = env->GetObjectField(obj, fid);
if(tmp == NULL)
{
return NULL;
}
ref->dataStorePutListener = env->NewGlobalRef(tmp);
fid = env->GetFieldID(
cls, "sender", "Lcom/zerotierone/sdk/PacketSender;");
@ -466,11 +481,12 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_node_1init(
return NULL; // exception already thrown
}
ref->packetSender = env->GetObjectField(obj, fid);
if(ref->packetSender == NULL)
tmp = env->GetObjectField(obj, fid);
if(tmp == NULL)
{
return NULL;
}
ref->packetSender = env->NewGlobalRef(tmp);
fid = env->GetFieldID(
cls, "frameListener", "Lcom/zerotierone/sdk/VirtualNetworkFrameListener;");
@ -479,11 +495,12 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_node_1init(
return NULL; // exception already thrown
}
ref->frameListener = env->GetObjectField(obj, fid);
if(ref->frameListener = NULL)
tmp = env->GetObjectField(obj, fid);
if(tmp == NULL)
{
return NULL;
}
ref->frameListener = env->NewGlobalRef(tmp);
fid = env->GetFieldID(
cls, "configListener", "Lcom/zerotierone/sdk/VirtualNetworkConfigListener;");
@ -492,11 +509,12 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_node_1init(
return NULL; // exception already thrown
}
ref->configListener = env->GetObjectField(obj, fid);
if(ref->configListener == NULL)
tmp = env->GetObjectField(obj, fid);
if(tmp == NULL)
{
return NULL;
}
ref->configListener = env->NewGlobalRef(tmp);
fid = env->GetFieldID(
cls, "eventListener", "Lcom/zerotierone/sdk/EventListener;");
@ -505,11 +523,12 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_node_1init(
return NULL;
}
ref->eventListener = env->GetObjectField(obj, fid);
if(ref->eventListener == NULL)
tmp = env->GetObjectField(obj, fid);
if(tmp == NULL)
{
return NULL;
}
ref->eventListener = env->NewGlobalRef(tmp);
ZT1_ResultCode rc = ZT1_Node_new(
&node,
@ -722,7 +741,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_processWirePacket(
memcpy(ipv6.sin6_addr.s6_addr, addr, 16);
memcpy(&remoteAddress, &ipv6, sizeof(sockaddr_in6));
}
else if(addrSize = 4)
else if(addrSize == 4)
{
// IPV4 address
sockaddr_in ipv4 = {};
@ -759,7 +778,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_processWirePacket(
env->ReleaseByteArrayElements(addressArray, addr, 0);
env->ReleaseByteArrayElements(in_packetData, packetData, 0);
return createResultObject(env, ZT1_RESULT_OK);
return createResultObject(env, rc);
}
/*

View File

@ -41,6 +41,13 @@ public enum Event {
*/
EVENT_OFFLINE,
/**
* Node is online -- at least one upstream node appears reachable
*
* Meta-data: none
*/
EVENT_ONLINE,
/**
* Node is shutting down
*