full LinphoneAuthInfo impl for Android

This commit is contained in:
Jehan Monnier 2013-03-05 16:35:40 +01:00
parent 9d3f8f7d94
commit 018fbdb7f1
7 changed files with 250 additions and 35 deletions

View file

@ -80,6 +80,13 @@ const char *linphone_auth_info_get_userid(const LinphoneAuthInfo *i){
return i->userid;
}
const char *linphone_auth_info_get_realm(const LinphoneAuthInfo *i){
return i->realm;
}
const char *linphone_auth_info_get_ha1(const LinphoneAuthInfo *i){
return i->ha1;
}
/**
* Sets the password.
**/
@ -113,6 +120,27 @@ void linphone_auth_info_set_userid(LinphoneAuthInfo *info, const char *userid){
if (userid && strlen(userid)>0) info->userid=ms_strdup(userid);
}
/**
* Sets realm.
**/
void linphone_auth_info_set_realm(LinphoneAuthInfo *info, const char *realm){
if (info->realm){
ms_free(info->realm);
info->realm=NULL;
}
if (realm && strlen(realm)>0) info->realm=ms_strdup(realm);
}
/**
* Sets ha1.
**/
void linphone_auth_info_set_ha1(LinphoneAuthInfo *info, const char *ha1){
if (info->ha1){
ms_free(info->ha1);
info->ha1=NULL;
}
if (ha1 && strlen(ha1)>0) info->ha1=ms_strdup(ha1);
}
/**
* Destroys a LinphoneAuthInfo object.
**/

View file

@ -620,10 +620,14 @@ LINPHONE_PUBLIC LinphoneAuthInfo *linphone_auth_info_new(const char *username, c
void linphone_auth_info_set_passwd(LinphoneAuthInfo *info, const char *passwd);
void linphone_auth_info_set_username(LinphoneAuthInfo *info, const char *username);
void linphone_auth_info_set_userid(LinphoneAuthInfo *info, const char *userid);
void linphone_auth_info_set_realm(LinphoneAuthInfo *info, const char *realm);
void linphone_auth_info_set_ha1(LinphoneAuthInfo *info, const char *ha1);
const char *linphone_auth_info_get_username(const LinphoneAuthInfo *i);
const char *linphone_auth_info_get_passwd(const LinphoneAuthInfo *i);
const char *linphone_auth_info_get_userid(const LinphoneAuthInfo *i);
const char *linphone_auth_info_get_realm(const LinphoneAuthInfo *i);
const char *linphone_auth_info_get_ha1(const LinphoneAuthInfo *i);
/* you don't need those function*/
void linphone_auth_info_destroy(LinphoneAuthInfo *info);

View file

@ -1187,33 +1187,150 @@ extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnable
//Auth Info
extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
, jobject thiz
, jstring jusername
, jstring juserid
, jstring jpassword
, jstring jha1
, jstring jrealm) {
const char* username = env->GetStringUTFChars(jusername, NULL);
const char* userid = env->GetStringUTFChars(juserid, NULL);
const char* password = env->GetStringUTFChars(jpassword, NULL);
const char* ha1 = env->GetStringUTFChars(jha1, NULL);
const char* realm = env->GetStringUTFChars(jrealm, NULL);
jlong auth = (jlong)linphone_auth_info_new(username,userid,password,ha1,realm);
env->ReleaseStringUTFChars(jusername, username);
env->ReleaseStringUTFChars(juserid, userid);
env->ReleaseStringUTFChars(jpassword, password);
env->ReleaseStringUTFChars(jha1, ha1);
env->ReleaseStringUTFChars(jrealm, realm);
return auth;
, jobject thiz ) {
return (jlong)linphone_auth_info_new(NULL,NULL,NULL,NULL,NULL);
}
extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
, jobject thiz
, jlong ptr) {
linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: getPassword
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getPassword
(JNIEnv *env , jobject, jlong auth_info) {
const char* passwd = linphone_auth_info_get_passwd((LinphoneAuthInfo*)auth_info);
if (passwd) {
return env->NewStringUTF(passwd);
} else {
return NULL;
}
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: getRealm
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getRealm
(JNIEnv *env , jobject, jlong auth_info) {
const char* realm = linphone_auth_info_get_realm((LinphoneAuthInfo*)auth_info);
if (realm) {
return env->NewStringUTF(realm);
} else {
return NULL;
}
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: getUsername
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getUsername
(JNIEnv *env , jobject, jlong auth_info) {
const char* username = linphone_auth_info_get_username((LinphoneAuthInfo*)auth_info);
if (username) {
return env->NewStringUTF(username);
} else {
return NULL;
}
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: setPassword
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setPassword
(JNIEnv *env, jobject, jlong auth_info, jstring jpassword) {
const char* password = jpassword?env->GetStringUTFChars(jpassword, NULL):NULL;
linphone_auth_info_set_passwd((LinphoneAuthInfo*)auth_info,password);
if (password) env->ReleaseStringUTFChars(jpassword, password);
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: setRealm
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setRealm
(JNIEnv *env, jobject, jlong auth_info, jstring jrealm) {
const char* realm = jrealm?env->GetStringUTFChars(jrealm, NULL):NULL;
linphone_auth_info_set_realm((LinphoneAuthInfo*)auth_info,realm);
if (realm) env->ReleaseStringUTFChars(jrealm, realm);
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: setUsername
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setUsername
(JNIEnv *env, jobject, jlong auth_info, jstring jusername) {
const char* username = jusername?env->GetStringUTFChars(jusername, NULL):NULL;
linphone_auth_info_set_username((LinphoneAuthInfo*)auth_info,username);
if (username) env->ReleaseStringUTFChars(jusername, username);
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: setAuthUserId
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setUserId
(JNIEnv *env, jobject, jlong auth_info, jstring juserid) {
const char* userid = juserid?env->GetStringUTFChars(juserid, NULL):NULL;
linphone_auth_info_set_userid((LinphoneAuthInfo*)auth_info,userid);
if (userid) env->ReleaseStringUTFChars(juserid, userid);
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: getAuthUserId
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getUserId
(JNIEnv *env , jobject, jlong auth_info) {
const char* userid = linphone_auth_info_get_userid((LinphoneAuthInfo*)auth_info);
if (userid) {
return env->NewStringUTF(userid);
} else {
return NULL;
}
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: setHa1
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setHa1
(JNIEnv *env, jobject, jlong auth_info, jstring jha1) {
const char* ha1 = jha1?env->GetStringUTFChars(jha1, NULL):NULL;
linphone_auth_info_set_ha1((LinphoneAuthInfo*)auth_info,ha1);
if (ha1) env->ReleaseStringUTFChars(jha1, ha1);
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: getHa1
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getHa1
(JNIEnv *env , jobject, jlong auth_info) {
const char* ha1 = linphone_auth_info_get_ha1((LinphoneAuthInfo*)auth_info);
if (ha1) {
return env->NewStringUTF(ha1);
} else {
return NULL;
}
}
//LinphoneAddress

View file

@ -63,6 +63,26 @@ public interface LinphoneAuthInfo {
* @param realm
*/
void setRealm(String realm);
/**
* get auth userid has used in authentication header. If null, username is taken for authentication
* @return auth userid
*/
String getUserId();
/**
* set auth userid has used in authentication header. If null, username is taken for authentication
*
*/
void setUserId(String userid);
/**
* get ha1
* @return ha1
*/
String getHa1();
/**
* set ha1
*/
void setHa1(String ha1);
}

View file

@ -49,10 +49,20 @@ abstract public class LinphoneCoreFactory {
return theLinphoneCoreFactory;
}
abstract public LinphoneAuthInfo createAuthInfo(String username,String password, String realm);
/**
* create {@link LinphoneAuthInfo}
* @param username
* @param userid user id as set in auth header
* @param passwd
* @param ha1
* @param realm
* */
abstract public LinphoneAuthInfo createAuthInfo(String username, String userid, String passwd, String ha1,String realm);
abstract public LinphoneCore createLinphoneCore(LinphoneCoreListener listener, String userConfig,String factoryConfig,Object userdata) throws LinphoneCoreException;
abstract public LinphoneCore createLinphoneCore(LinphoneCoreListener listener) throws LinphoneCoreException;
/**
* Constructs a LinphoneAddress object
* @param username

View file

@ -20,36 +20,66 @@ package org.linphone.core;
class LinphoneAuthInfoImpl implements LinphoneAuthInfo {
protected final long nativePtr;
private native long newLinphoneAuthInfo(String username, String userid, String passwd, String ha1,String realm);
private native long newLinphoneAuthInfo();
private native void delete(long ptr);
private native String getPassword(long ptr);
private native String getRealm(long ptr);
private native String getUsername(long ptr);
private native void setPassword(long ptr, String password);
private native void setRealm(long ptr, String realm);
private native void setUsername(long ptr, String username);
private native void setUserId(long ptr, String username);
private native void setHa1(long ptr, String ha1);
private native String getUserId(long ptr);
private native String getHa1(long ptr);
protected LinphoneAuthInfoImpl(String username,String password, String realm) {
nativePtr = newLinphoneAuthInfo(username,"",password,"","");
this(username,null,password,null,null);
}
protected LinphoneAuthInfoImpl(String username, String userid, String passwd, String ha1,String realm) {
nativePtr = newLinphoneAuthInfo();
this.setUsername(username);
this.setUserId(userid);
this.setPassword(passwd);
this.setHa1(ha1);
}
protected void finalize() throws Throwable {
delete(nativePtr);
}
public String getPassword() {
// TODO Auto-generated method stub
throw new RuntimeException("not implemeneted yet");
return getPassword (nativePtr);
}
public String getRealm() {
// TODO Auto-generated method stub
throw new RuntimeException("not implemeneted yet");
return getRealm (nativePtr);
}
public String getUsername() {
// TODO Auto-generated method stub
throw new RuntimeException("not implemeneted yet");
return getUsername (nativePtr);
}
public void setPassword(String password) {
// TODO Auto-generated method stub
throw new RuntimeException("not implemeneted yet");
setPassword(nativePtr,password);
}
public void setRealm(String realm) {
// TODO Auto-generated method stub
throw new RuntimeException("not implemeneted yet");
setRealm(nativePtr,realm);
}
public void setUsername(String username) {
// TODO Auto-generated method stub
throw new RuntimeException("not implemeneted yet");
setUsername(nativePtr,username);
}
@Override
public String getUserId() {
return getUserId(nativePtr);
}
@Override
public void setUserId(String userid) {
setUserId(nativePtr,userid);
}
@Override
public String getHa1() {
return getHa1(nativePtr);
}
@Override
public void setHa1(String ha1) {
setHa1(nativePtr,ha1);
}
}

View file

@ -166,4 +166,10 @@ public class LinphoneCoreFactoryImpl extends LinphoneCoreFactory {
{
return System.getProperty("os.arch").contains("armv7");
}
@Override
public LinphoneAuthInfo createAuthInfo(String username, String userid,
String passwd, String ha1, String realm) {
return new LinphoneAuthInfoImpl(username,userid,passwd,ha1,realm);
}
}