Bug 231331. Pass correct parameter to native code.

This commit is contained in:
Jim Norman 2007-01-02 07:48:36 +00:00
parent 17b3766285
commit 0b4d751ef2
2 changed files with 235 additions and 232 deletions

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Tue Jan 2 12:33:19 MST 2007 - jnorman@novell.com
- Bug 231331. Pass correct parameter from JNI to native code.
------------------------------------------------------------------- -------------------------------------------------------------------
Tue Dec 5 22:12:04 US/Mountain 2006 - cmashayekhi@novell.com Tue Dec 5 22:12:04 US/Mountain 2006 - cmashayekhi@novell.com

View File

@ -20,235 +20,233 @@
* *
***********************************************************************/ ***********************************************************************/
#include "com_novell_casa_MiCasa.h" #include "com_novell_casa_MiCasa.h"
#include <jni.h> #include <jni.h>
#include <micasa_mgmd.h> #include <micasa_mgmd.h>
#include <sscs_utf8.h>
#ifdef __cplusplus
#ifdef __cplusplus extern "C" {
extern "C" { #endif
#endif
JNIEXPORT jint JNICALL
JNIEXPORT jint JNICALL Java_com_novell_casa_MiCasa_jmiCASASetCredential
Java_com_novell_casa_MiCasa_jmiCASASetCredential (JNIEnv *env, jobject notused,
(JNIEnv *env, jobject notused, jint ssFlags,
jint ssFlags, jstring jsAppSecretID,
jstring jsAppSecretID, jstring jsSharedSecretID,
jstring jsSharedSecretID, jint jUsernameType,
jint jUsernameType, jstring jsUsername,
jstring jsUsername, jstring jsPassword
jstring jsPassword )
) {
{ int rcode = 0;
int rcode = 0; SSCS_SECRET_ID_T appSecretId = {0};
SSCS_SECRET_ID_T appSecretId = {0}; SSCS_SECRET_ID_T sharedSecretId = {0};
SSCS_SECRET_ID_T sharedSecretId = {0}; SSCS_BASIC_CREDENTIAL credential = {0};
SSCS_BASIC_CREDENTIAL credential = {0};
const char* utf_string;
const char* utf_string; jboolean isCopy;
jboolean isCopy; utf_string = (*env)->GetStringUTFChars(env, jsAppSecretID, &isCopy);
utf_string = (*env)->GetStringUTFChars(env, jsAppSecretID, &isCopy);
sscs_Utf8Strcpy((char*)appSecretId.id, utf_string);
sscs_Utf8Strcpy((char*)appSecretId.id, utf_string); appSecretId.len = sscs_Utf8Strlen(utf_string) + 1;
appSecretId.len = sscs_Utf8Strlen(utf_string) + 1;
if (isCopy == JNI_TRUE)
if (isCopy == JNI_TRUE) (*env)->ReleaseStringUTFChars(env,jsAppSecretID, utf_string);
(*env)->ReleaseStringUTFChars(env,jsAppSecretID, utf_string);
// handle sharedsecretid
// handle sharedsecretid if (jsSharedSecretID)
if (jsSharedSecretID) {
{ utf_string = (*env)->GetStringUTFChars(env, jsSharedSecretID, &isCopy);
utf_string = (*env)->GetStringUTFChars(env, jsSharedSecretID, &isCopy); sscs_Utf8Strcpy((char*)sharedSecretId.id, utf_string);
sscs_Utf8Strcpy((char*)sharedSecretId.id, utf_string); sharedSecretId.len = sscs_Utf8Strlen(utf_string)+1;
sharedSecretId.len = sscs_Utf8Strlen(utf_string)+1;
if (isCopy == JNI_TRUE)
if (isCopy == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, jsSharedSecretID, utf_string);
(*env)->ReleaseStringUTFChars(env, jsSharedSecretID, utf_string); }
}
// setup credential
// setup credential utf_string = (*env)->GetStringUTFChars(env, jsUsername, &isCopy);
utf_string = (*env)->GetStringUTFChars(env, jsUsername, &isCopy); sscs_Utf8Strcpy((char*)credential.username, utf_string);
sscs_Utf8Strcpy((char*)credential.username, utf_string); credential.unLen = sscs_Utf8Strlen(utf_string)+1;
credential.unLen = sscs_Utf8Strlen(utf_string)+1; credential.unFlags = jUsernameType;
credential.unFlags = jUsernameType; if (isCopy == JNI_TRUE)
if (isCopy == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, jsUsername, utf_string);
(*env)->ReleaseStringUTFChars(env, jsUsername, utf_string);
// password
// password utf_string = (*env)->GetStringUTFChars(env, jsPassword, &isCopy);
utf_string = (*env)->GetStringUTFChars(env, jsPassword, &isCopy); sscs_Utf8Strcpy((char*)credential.password, utf_string);
sscs_Utf8Strcpy((char*)credential.password, utf_string); credential.pwordLen = sscs_Utf8Strlen(utf_string)+1;
credential.pwordLen = sscs_Utf8Strlen(utf_string)+1; if (isCopy == JNI_TRUE)
if (isCopy == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, jsPassword, utf_string);
(*env)->ReleaseStringUTFChars(env, jsPassword, utf_string);
// make the call
// make the call if (jsSharedSecretID)
if (jsSharedSecretID) rcode = miCASASetCredential(
rcode = miCASASetCredential( ssFlags,
ssFlags, &appSecretId,
&appSecretId, &sharedSecretId,
&sharedSecretId, SSCS_CRED_TYPE_BASIC_F,
SSCS_CRED_TYPE_BASIC_F, &credential,
&credential, NULL
NULL );
); else
else rcode = miCASASetCredential(
rcode = miCASASetCredential( ssFlags,
ssFlags, &appSecretId,
&appSecretId, NULL,
NULL, SSCS_CRED_TYPE_BASIC_F,
SSCS_CRED_TYPE_BASIC_F, &credential,
&credential, NULL
NULL );
);
return rcode;
return rcode; }
}
/*
/* * Class: com_novell_casa_micasa_SecretStore
* Class: com_novell_casa_micasa_SecretStore * Method: jmiCASAGetCredential
* Method: jmiCASAGetCredential * Signature: (I[B[BILcom/novell/casa/micasa/Secret;)I
* Signature: (I[B[BILcom/novell/casa/micasa/Secret;)I */
*/ JNIEXPORT jint JNICALL
JNIEXPORT jint JNICALL Java_com_novell_casa_MiCasa_jmiCASAGetCredential
Java_com_novell_casa_MiCasa_jmiCASAGetCredential (JNIEnv *env, jobject unused,
(JNIEnv *env, jobject unused, jint ssFlags,
jint ssFlags, jstring jsAppSecretID,
jstring jsAppSecretID, jstring jsSharedSecretID,
jstring jsSharedSecretID, jint jUsernameType,
jint jUsernameType, jobject jcred)
jobject jcred) {
{ int rcode = 0;
int rcode = 0; uint32_t iCredType = SSCS_CRED_TYPE_BASIC_F;
int iCredType = SSCS_CRED_TYPE_BASIC_F; SSCS_SECRET_ID_T appSecretId = {0};
SSCS_SECRET_ID_T appSecretId = {0}; SSCS_SECRET_ID_T sharedSecretId = {0};
SSCS_SECRET_ID_T sharedSecretId = {0}; SSCS_BASIC_CREDENTIAL credential = {0};
SSCS_BASIC_CREDENTIAL credential = {0};
const char* utf_string;
const char* utf_string; jboolean isCopy;
jboolean isCopy;
int unType = jUsernameType; utf_string = (*env)->GetStringUTFChars(env, jsAppSecretID, &isCopy);
sscs_Utf8Strcpy((char*)appSecretId.id, utf_string);
utf_string = (*env)->GetStringUTFChars(env, jsAppSecretID, &isCopy); appSecretId.len = sscs_Utf8Strlen(utf_string) + 1;
sscs_Utf8Strcpy((char*)appSecretId.id, utf_string); if (isCopy == JNI_TRUE)
appSecretId.len = sscs_Utf8Strlen(utf_string) + 1; (*env)->ReleaseStringUTFChars(env, jsAppSecretID, utf_string);
if (isCopy == JNI_TRUE)
(*env)->ReleaseStringUTFChars(env, jsAppSecretID, utf_string); // handle sharedsecretid
if (jsSharedSecretID)
// handle sharedsecretid {
if (jsSharedSecretID) utf_string = (*env)->GetStringUTFChars(env, jsSharedSecretID, &isCopy);
{ sscs_Utf8Strcpy((char*)sharedSecretId.id, utf_string);
utf_string = (*env)->GetStringUTFChars(env, jsSharedSecretID, &isCopy); sharedSecretId.len = sscs_Utf8Strlen(utf_string)+1;
sscs_Utf8Strcpy((char*)sharedSecretId.id, utf_string);
sharedSecretId.len = sscs_Utf8Strlen(utf_string)+1; if (isCopy == JNI_TRUE)
(*env)->ReleaseStringUTFChars(env, jsSharedSecretID, utf_string);
if (isCopy == JNI_TRUE) }
(*env)->ReleaseStringUTFChars(env, jsSharedSecretID, utf_string);
} // make the call
if (jsSharedSecretID)
// make the call rcode = miCASAGetCredential(
if (jsSharedSecretID) ssFlags,
rcode = miCASAGetCredential( &appSecretId,
ssFlags, &sharedSecretId,
&appSecretId, &iCredType,
&sharedSecretId, &credential,
&iCredType, NULL
&credential, );
NULL else
); rcode = miCASAGetCredential(
else ssFlags,
rcode = miCASAGetCredential( &appSecretId,
ssFlags, NULL,
&appSecretId, &iCredType,
NULL, &credential,
&iCredType, NULL
&credential, );
NULL
);
if (rcode == 0)
{
if (rcode == 0) // we have a credential
{ jclass theclazz;
// we have a credential jmethodID mid;
jclass theclazz;
jmethodID mid; theclazz = (*env)->GetObjectClass(env, jcred);
mid = (*env)->GetMethodID(env, theclazz, "setUsername", "(Ljava/lang/String;)V");
theclazz = (*env)->GetObjectClass(env, jcred); if (mid != NULL)
mid = (*env)->GetMethodID(env, theclazz, "setUsername", "(Ljava/lang/String;)V"); {
if (mid != NULL) //printf("The Username: %s\r\n", credential.username);
{ jstring jusername = (*env)->NewStringUTF(env, (char *)credential.username);
//printf("The Username: %s\r\n", credential.username); (*env)->CallObjectMethod(env, jcred, mid, jusername);
jstring jusername = (*env)->NewStringUTF(env, (char *)credential.username); }
(*env)->CallObjectMethod(env, jcred, mid, jusername);
} mid = (*env)->GetMethodID(env, theclazz, "setPassword", "(Ljava/lang/String;)V");
{
mid = (*env)->GetMethodID(env, theclazz, "setPassword", "(Ljava/lang/String;)V"); jstring jpassword = (*env)->NewStringUTF(env, (char *)credential.password);
{ (*env)->CallObjectMethod(env, jcred, mid, jpassword);
jstring jpassword = (*env)->NewStringUTF(env, (char *)credential.password); }
(*env)->CallObjectMethod(env, jcred, mid, jpassword); }
} return rcode;
} }
return rcode;
}
/*
* Class: com_novell_casa_micasa_SecretStore
/* * Method: jmiCASARemoveCredential
* Class: com_novell_casa_micasa_SecretStore * Signature: (I[B[B)I
* Method: jmiCASARemoveCredential */
* Signature: (I[B[B)I JNIEXPORT jint JNICALL
*/ Java_com_novell_casa_MiCasa_jmiCASARemoveCredential
JNIEXPORT jint JNICALL (JNIEnv *env, jobject unused,
Java_com_novell_casa_MiCasa_jmiCASARemoveCredential jint ssFlags,
(JNIEnv *env, jobject unused, jstring jsAppSecretID,
jint ssFlags, jstring jsSharedSecretID)
jstring jsAppSecretID, {
jstring jsSharedSecretID) int rcode = 0;
{ SSCS_SECRET_ID_T appSecretId = {0};
int rcode = 0; SSCS_SECRET_ID_T sharedSecretId = {0};
SSCS_SECRET_ID_T appSecretId = {0};
SSCS_SECRET_ID_T sharedSecretId = {0}; const char* utf_string;
jboolean isCopy;
const char* utf_string;
jboolean isCopy; utf_string = (*env)->GetStringUTFChars(env, jsAppSecretID, &isCopy);
sscs_Utf8Strcpy((char*)appSecretId.id, utf_string);
utf_string = (*env)->GetStringUTFChars(env, jsAppSecretID, &isCopy); appSecretId.len = sscs_Utf8Strlen(utf_string) + 1;
sscs_Utf8Strcpy((char*)appSecretId.id, utf_string); if (isCopy == JNI_TRUE)
appSecretId.len = sscs_Utf8Strlen(utf_string) + 1; (*env)->ReleaseStringUTFChars(env, jsAppSecretID, utf_string);
if (isCopy == JNI_TRUE)
(*env)->ReleaseStringUTFChars(env, jsAppSecretID, utf_string); // handle sharedsecretid
if (jsSharedSecretID)
// handle sharedsecretid {
if (jsSharedSecretID) utf_string = (*env)->GetStringUTFChars(env, jsSharedSecretID, &isCopy);
{ sscs_Utf8Strcpy((char*)sharedSecretId.id, utf_string);
utf_string = (*env)->GetStringUTFChars(env, jsSharedSecretID, &isCopy); sharedSecretId.len = sscs_Utf8Strlen(utf_string)+1;
sscs_Utf8Strcpy((char*)sharedSecretId.id, utf_string);
sharedSecretId.len = sscs_Utf8Strlen(utf_string)+1; if (isCopy == JNI_TRUE)
(*env)->ReleaseStringUTFChars(env, jsSharedSecretID, utf_string);
if (isCopy == JNI_TRUE) }
(*env)->ReleaseStringUTFChars(env, jsSharedSecretID, utf_string);
} // make the call
if (jsSharedSecretID)
// make the call rcode = miCASARemoveCredential(
if (jsSharedSecretID) ssFlags,
rcode = miCASARemoveCredential( &appSecretId,
ssFlags, &sharedSecretId,
&appSecretId, NULL);
&sharedSecretId,
NULL); else
rcode = miCASARemoveCredential(
else ssFlags,
rcode = miCASARemoveCredential( &appSecretId,
ssFlags, NULL,
&appSecretId, NULL);
NULL,
NULL); return rcode;
}
return rcode;
}
#ifdef __cplusplus
}
#ifdef __cplusplus #endif
}
#endif