From a43380181e8bdaedaf08e59c73b9299a56e8fbcc Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 4 Nov 2013 16:32:30 +0100 Subject: [PATCH] Fix auth infos edition + updated belle-sip/linphone (needed for fix) --- src/org/linphone/LinphonePreferences.java | 64 +++++++++++++++++------ submodules/belle-sip | 2 +- submodules/linphone | 2 +- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/org/linphone/LinphonePreferences.java b/src/org/linphone/LinphonePreferences.java index 2a8ab1f43..fd64106bb 100644 --- a/src/org/linphone/LinphonePreferences.java +++ b/src/org/linphone/LinphonePreferences.java @@ -106,23 +106,45 @@ public class LinphonePreferences { } private LinphoneAuthInfo getAuthInfo(int n) { - LinphoneAuthInfo[] authsInfos = getLc().getAuthInfosList(); - // In case you have multiple proxy configs with same auth info - if (n > 0 && n >= authsInfos.length) { - LinphoneProxyConfig prxCfg = getProxyConfig(n); - try { - LinphoneAddress addr = LinphoneCoreFactory.instance().createLinphoneAddress(prxCfg.getIdentity()); - return getLc().findAuthInfo(addr.getUserName(), null); - } catch (LinphoneCoreException e) { } - return null; - } - else if (n < 0 || n >= authsInfos.length) { - return null; + LinphoneProxyConfig prxCfg = getProxyConfig(n); + try { + LinphoneAddress addr = LinphoneCoreFactory.instance().createLinphoneAddress(prxCfg.getIdentity()); + LinphoneAuthInfo authInfo = getLc().findAuthInfo(addr.getUserName(), null, addr.getDomain()); + return authInfo; + } catch (LinphoneCoreException e) { + e.printStackTrace(); } return null; } + /** + * Removes a authInfo from the core and returns a copy of it. + * Useful to edit a authInfo (you should call saveAuthInfo after the modifications to save them). + */ + private LinphoneAuthInfo getClonedAuthInfo(int n) { + LinphoneProxyConfig prxCfg = getProxyConfig(n); + try { + LinphoneAddress addr = LinphoneCoreFactory.instance().createLinphoneAddress(prxCfg.getIdentity()); + LinphoneAuthInfo authInfo = getLc().findAuthInfo(addr.getUserName(), null, addr.getDomain()); + LinphoneAuthInfo cloneAuthInfo = authInfo.clone(); + getLc().removeAuthInfo(authInfo); + return cloneAuthInfo; + } catch (LinphoneCoreException e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Saves a authInfo into the core. + * Useful to save the changes made to a cloned authInfo. + */ + private void saveAuthInfo(LinphoneAuthInfo authInfo) { + getLc().addAuthInfo(authInfo); + } + private String tempUsername; private String tempUserId; private String tempPassword; @@ -151,7 +173,7 @@ public class LinphonePreferences { } catch (NumberFormatException nfe) { } } - LinphoneAuthInfo authInfo = LinphoneCoreFactory.instance().createAuthInfo(tempUsername, tempUserId, tempPassword, null, null); + LinphoneAuthInfo authInfo = LinphoneCoreFactory.instance().createAuthInfo(tempUsername, tempUserId, tempPassword, null, null, tempDomain); getLc().addProxyConfig(prxCfg); getLc().addAuthInfo(authInfo); @@ -175,12 +197,14 @@ public class LinphonePreferences { public void setAccountUsername(int n, String username) { String identity = "sip:" + username + "@" + getAccountDomain(n); - LinphoneAuthInfo info = getAuthInfo(n); // Get the auth info before editing the proxy config to ensure to get the correct auth info + LinphoneAuthInfo info = getClonedAuthInfo(n); // Get the auth info before editing the proxy config to ensure to get the correct auth info try { LinphoneProxyConfig prxCfg = getProxyConfig(n); prxCfg.setIdentity(identity); prxCfg.done(); + info.setUsername(username); + saveAuthInfo(info); } catch (LinphoneCoreException e) { e.printStackTrace(); } @@ -196,7 +220,9 @@ public class LinphonePreferences { } public void setAccountUserId(int n, String userId) { - getAuthInfo(n).setUserId(userId); + LinphoneAuthInfo info = getClonedAuthInfo(n); + info.setUserId(userId); + saveAuthInfo(info); } public String getAccountUserId(int n) { @@ -209,7 +235,9 @@ public class LinphonePreferences { } public void setAccountPassword(int n, String password) { - getAuthInfo(n).setPassword(password); + LinphoneAuthInfo info = getClonedAuthInfo(n); + info.setPassword(password); + saveAuthInfo(info); } public String getAccountPassword(int n) { @@ -226,6 +254,10 @@ public class LinphonePreferences { String proxy = "sip:" + domain; try { + LinphoneAuthInfo authInfo = getClonedAuthInfo(n); + authInfo.setDomain(domain); + saveAuthInfo(authInfo); + LinphoneProxyConfig prxCfg = getProxyConfig(n); prxCfg.setIdentity(identity); prxCfg.setProxy(proxy); diff --git a/submodules/belle-sip b/submodules/belle-sip index 38b76142a..2eb17045f 160000 --- a/submodules/belle-sip +++ b/submodules/belle-sip @@ -1 +1 @@ -Subproject commit 38b76142a0186d393bea57a7f3e7886652900a91 +Subproject commit 2eb17045f1aaf99efe5b5447b2c76a8b7dab8434 diff --git a/submodules/linphone b/submodules/linphone index 74e889fcc..50f9d3580 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 74e889fcc4ae3b61a3d632b108d8493590ccec9d +Subproject commit 50f9d358046b1950e9d0aa3bf1f4527faa79697e