]> sjero.net Git - linphone/commitdiff
full LinphoneAuthInfo impl for Android
authorJehan Monnier <jehan.monnier@linphone.org>
Tue, 5 Mar 2013 15:35:40 +0000 (16:35 +0100)
committerSimon Morlat <simon.morlat@linphone.org>
Mon, 11 Mar 2013 15:57:16 +0000 (16:57 +0100)
coreapi/authentication.c
coreapi/linphonecore.h
coreapi/linphonecore_jni.cc
java/common/org/linphone/core/LinphoneAuthInfo.java
java/common/org/linphone/core/LinphoneCoreFactory.java
java/impl/org/linphone/core/LinphoneAuthInfoImpl.java
java/impl/org/linphone/core/LinphoneCoreFactoryImpl.java

index 4b5d10fa8560d9f1e146c714310638b2ab4254bd..8ab1c21ffdb406ecba2ebc1f8e82f5a4677dc687 100644 (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.
 **/
index 7212f26c49b64ba64b7fa6c1c76c308efda89892..de8a05afacdca7ca725bfd562aab4dadc46982a7 100644 (file)
@@ -617,10 +617,14 @@ LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *useri
 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);
index 57ab7c4ca1a5b68f506b817761837e5c3a264f4b..6b6c3f5ce8c640bdf4c2e1cdddb4996a300bd16a 100644 (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
 
index 6590dafebbf4f827504082768ce62542df604113..ed8a8401769b3208c49840926cafa0001d474861 100644 (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);
+       
 }
 
 
index 399b9ec8d8b2321ab28854762d32b04b6c017231..ea325057e34a76a07c0805cf3b0479ee7c3cf87c 100644 (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 
index 45fd8a45e23fc1b20d493eb4e4b9cc38af7fe418..dee96fe5dd4341b27faa2cfc22fa710977217c4d 100644 (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);
+               
        }
 }
index 2e5c4cf5992ca20ba43372285da56af906c197e8..7b21ecaae367cddccb5df402388beccb0fb03fde 100644 (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);
+       }
 }