diff --git a/coreapi/account_creator.c b/coreapi/account_creator.c index 574baf34f..cb859f163 100644 --- a/coreapi/account_creator.c +++ b/coreapi/account_creator.c @@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "linphone/account_creator.h" #include "linphone/core.h" +#include "linphone/lpconfig.h" #include "private.h" #if !_WIN32 #include "regex.h" @@ -107,6 +108,42 @@ static bool_t is_matching_regex(const char *entry, const char* regex) { #endif } +LinphoneProxyConfig * linphone_account_creator_configure_proxy_config(const LinphoneAccountCreator *creator) { + LinphoneAuthInfo *info; + LinphoneProxyConfig *cfg = linphone_core_create_proxy_config(creator->core); + char *identity_str = _get_identity(creator); + LinphoneAddress *identity = linphone_address_new(identity_str); + ms_free(identity_str); + + linphone_proxy_config_set_identity_address(cfg, identity); + if (creator->phone_country_code) { + linphone_proxy_config_set_dial_prefix(cfg, creator->phone_country_code); + } else if (creator->phone_number) { + int dial_prefix_number = linphone_dial_plan_lookup_ccc_from_e164(creator->phone_number); + char buff[4]; + snprintf(buff, sizeof(buff), "%d", dial_prefix_number); + linphone_proxy_config_set_dial_prefix(cfg, buff); + } + + info = linphone_auth_info_new(linphone_address_get_username(identity), // username + NULL, //user id + creator->password, // passwd + creator->password ? NULL : creator->ha1, // ha1 + !creator->password && creator->ha1 ? linphone_address_get_domain(identity) : NULL, // realm - assumed to be domain + linphone_address_get_domain(identity) // domain + ); + linphone_core_add_auth_info(creator->core, info); + linphone_address_unref(identity); + + if (linphone_core_add_proxy_config(creator->core, cfg) != -1) { + linphone_core_set_default_proxy(creator->core, cfg); + return cfg; + } + + linphone_core_remove_auth_info(creator->core, info); + return NULL; +} + LinphoneProxyConfig * linphone_account_creator_configure(const LinphoneAccountCreator *creator) { LinphoneAuthInfo *info; LinphoneProxyConfig *cfg = creator->proxy_cfg; diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 672e5690a..ae08613cd 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -6000,6 +6000,13 @@ extern "C" void Java_org_linphone_core_LpConfigImpl_sync(JNIEnv *env, jobject th lp_config_sync(lp); } +extern "C" void Java_org_linphone_core_LpConfigImpl_loadXmlFile(JNIEnv *env, jobject thiz, jlong lpc, jstring jfilename) { + const char *filename = GetStringUTFChars(env, jfilename); + LpConfig *lp = (LpConfig *)lpc; + linphone_config_load_from_xml_file(lp, filename, NULL); + ReleaseStringUTFChars(env, jfilename, filename); +} + extern "C" void Java_org_linphone_core_LpConfigImpl_delete(JNIEnv *env, jobject thiz, jlong lpc) { LpConfig *lp = (LpConfig *)lpc; lp_config_destroy(lp); @@ -8748,6 +8755,15 @@ extern "C" jint Java_org_linphone_core_LinphoneAccountCreatorImpl_updatePassword return status; } +extern "C" jobject Java_org_linphone_core_LinphoneAccountCreatorImpl_configureProxyConfig(JNIEnv *env, jobject thiz, jlong ptr) { + LinphoneAccountCreator *account_creator = (LinphoneAccountCreator *)ptr; + LinphoneProxyConfig *lpc = linphone_account_creator_configure(account_creator); + LinphoneCore *lc = account_creator->core; + LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); + LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); + return getProxy(env, lpc, lcData->core); +} + extern "C" jobject Java_org_linphone_core_LinphoneAccountCreatorImpl_configure(JNIEnv *env, jobject thiz, jlong ptr) { LinphoneAccountCreator *account_creator = (LinphoneAccountCreator *)ptr; LinphoneProxyConfig *lpc = linphone_account_creator_configure(account_creator); diff --git a/coreapi/lpconfig.c b/coreapi/lpconfig.c index 1e55d02d9..1c87904d6 100644 --- a/coreapi/lpconfig.c +++ b/coreapi/lpconfig.c @@ -27,6 +27,7 @@ #include "private.h" #include "bctoolbox/vfs.h" #include "belle-sip/object.h" +#include "xml2lpc.h" #include #include @@ -402,7 +403,7 @@ LpConfig * linphone_config_new_from_buffer(const char *buffer){ static int _linphone_config_init_from_files(LinphoneConfig *lpconfig, const char *config_filename, const char *factory_config_filename) { lpconfig->g_bctbx_vfs = bctbx_vfs_get_default(); - + if (config_filename!=NULL){ if(ortp_file_exist(config_filename) == 0) { lpconfig->filename=lp_realpath(config_filename, NULL); @@ -480,6 +481,34 @@ LinphoneStatus linphone_config_read_file(LpConfig *lpconfig, const char *filenam return -1; } +char* linphone_config_load_from_xml_file(LpConfig *lpc, const char *filename, void* ctx) { + xml2lpc_context *context = NULL; + char* path = lp_realpath(filename, NULL); + char* error_msg = NULL; + + if (path) { + int result = -1; + context = xml2lpc_context_new(NULL, ctx); + result = xml2lpc_set_xml_string(context, path); + if (result == 0) { + result = xml2lpc_convert(context, lpc); + if (result == 0) { + // if the remote provisioning added a proxy config and none was set before, set it + if (lp_config_has_section(lpc, "proxy_0") && lp_config_get_int(lpc, "sip", "default_proxy", -1) == -1){ + lp_config_set_int(lpc, "sip", "default_proxy", 0); + } + lp_config_sync(lpc); + } else { + error_msg = "xml to lpc failed"; + } + } else { + error_msg = "invalid xml"; + } + } + if (context) xml2lpc_context_destroy(context); + return error_msg; +} + void lp_item_set_value(LpItem *item, const char *value){ if (item->value != value) { char *prev_value=item->value; @@ -758,14 +787,14 @@ void linphone_config_set_skip_flag_for_section(LpConfig *lpconfig, const char *s void lp_item_write(LpItem *item, LpConfig *lpconfig){ int ret =-1 ; - if (item->is_comment){ + if (item->is_comment){ ret =bctbx_file_fprintf(lpconfig->pFile, 0, "%s\n",item->value); } else if (item->value && item->value[0] != '\0' ){ ret =bctbx_file_fprintf(lpconfig->pFile, 0, "%s=%s\n",item->key,item->value); } - + else { ms_warning("Not writing item %s to file, it is empty", item->key); } @@ -792,7 +821,7 @@ void lp_section_write(LpSection *sec,LpConfig *lpconfig){ bctbx_list_for_each2(sec->items, (void (*)(void*, void*))lp_item_write, (void *)lpconfig); if (bctbx_file_fprintf(lpconfig->pFile, 0, "\n")< 0) ms_error("lp_section_write : write error"); - + } LinphoneStatus linphone_config_sync(LpConfig *lpconfig){ @@ -811,7 +840,7 @@ LinphoneStatus linphone_config_sync(LpConfig *lpconfig){ lpconfig->readonly = TRUE; return -1; } - + bctbx_list_for_each2(lpconfig->sections,(void (*)(void *,void*))lp_section_write,(void *)lpconfig); bctbx_file_close(pFile); @@ -1018,7 +1047,7 @@ LinphoneStatus linphone_config_read_relative_file(const LpConfig *lpconfig, cons if(bctbx_file_read(pFile, data, 1, (off_t)max_length) < 0){ ms_error("%s could not be loaded.", realfilepath); goto err; - + } bctbx_file_close(pFile); @@ -1109,7 +1138,7 @@ int linphone_config_has_entry(const LpConfig *lpconfig, const char *section, con return lp_section_find_item(sec,key) != NULL; } else return FALSE; - + } BELLE_SIP_INSTANCIATE_VPTR( diff --git a/coreapi/remote_provisioning.c b/coreapi/remote_provisioning.c index 0bb40595b..9da88531a 100644 --- a/coreapi/remote_provisioning.c +++ b/coreapi/remote_provisioning.c @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "private.h" #include "xml2lpc.h" +#include "linphone/lpconfig.h" #define XML2LPC_CALLBACK_BUFFER_SIZE 1024 @@ -34,27 +35,8 @@ static void xml2lpc_callback(void *ctx, xml2lpc_log_level level, const char *fmt } static void linphone_remote_provisioning_apply(LinphoneCore *lc, const char *xml) { - xml2lpc_context *context = xml2lpc_context_new(xml2lpc_callback, lc); - int result = xml2lpc_set_xml_string(context, xml); - char * error_msg = NULL; - if (result == 0) { - LpConfig * lpc = linphone_core_get_config(lc); - result = xml2lpc_convert(context, lpc); - if (result == 0) { - // if the remote provisioning added a proxy config and none was set before, set it - if (lp_config_has_section(lpc, "proxy_0") && lp_config_get_int(lpc, "sip", "default_proxy", -1) == -1){ - lp_config_set_int(lpc, "sip", "default_proxy", 0); - } - lp_config_sync(lpc); + char* error_msg = linphone_config_load_from_xml_file(linphone_core_get_config(lc), xml, lc); - } else { - error_msg = "xml to lpc failed"; - } - } else { - error_msg = "invalid xml"; - } - - xml2lpc_context_destroy(context); linphone_configuring_terminated(lc ,error_msg ? LinphoneConfiguringFailed : LinphoneConfiguringSuccessful , error_msg); diff --git a/include/linphone/account_creator.h b/include/linphone/account_creator.h index a4bfca7c4..81fe0aca7 100644 --- a/include/linphone/account_creator.h +++ b/include/linphone/account_creator.h @@ -491,12 +491,19 @@ LINPHONE_PUBLIC void linphone_account_creator_cbs_set_update_account(LinphoneAcc /************************** End Account Creator Cbs **************************/ +/** + * + * @param[in] creator LinphoneAccountCreator object + * @return A LinphoneProxyConfig object if successful, NULL otherwise + **/ +LINPHONE_PUBLIC LinphoneProxyConfig * linphone_account_creator_create_proxy_config(const LinphoneAccountCreator *creator); + /** * Configure an account (create a proxy config and authentication info for it). * @param[in] creator LinphoneAccountCreator object * @return A LinphoneProxyConfig object if successful, NULL otherwise **/ -LINPHONE_PUBLIC LinphoneProxyConfig * linphone_account_creator_configure(const LinphoneAccountCreator *creator); +LINPHONE_DEPRECATED LINPHONE_PUBLIC LinphoneProxyConfig * linphone_account_creator_configure(const LinphoneAccountCreator *creator); /** * @} diff --git a/include/linphone/lpconfig.h b/include/linphone/lpconfig.h index d178dab2d..3f8893e65 100644 --- a/include/linphone/lpconfig.h +++ b/include/linphone/lpconfig.h @@ -82,6 +82,15 @@ LINPHONE_PUBLIC LinphoneConfig * linphone_config_new_with_factory(const char *co */ LINPHONE_PUBLIC LinphoneStatus linphone_config_read_file(LinphoneConfig *lpconfig, const char *filename); +/** + * Reads a xml config file and fill the LinphoneConfig with the read config dynamic values. + * @ingroup misc + * @param lpconfig The LinphoneConfig object to fill with the content of the file + * @param filename The filename of the config file to read to fill the LinphoneConfig + * @param ctx The context given to xml2lpc callback + */ +LINPHONE_PUBLIC char* linphone_config_load_from_xml_file(LpConfig *lpc, const char *filename, void* ctx); + /** * Retrieves a configuration item as a string, given its section, key, and default value. * @@ -198,7 +207,7 @@ LINPHONE_PUBLIC int linphone_config_has_entry(const LinphoneConfig *lpconfig, co * @param[in] key **/ LINPHONE_PUBLIC void linphone_config_clean_entry(LinphoneConfig *lpconfig, const char *section, const char *key); - + /** * Returns the list of sections' names in the LinphoneConfig. * @param[in] lpconfig The LinphoneConfig object diff --git a/java/common/org/linphone/core/LpConfig.java b/java/common/org/linphone/core/LpConfig.java index 4ddc7b2d5..ec925626b 100644 --- a/java/common/org/linphone/core/LpConfig.java +++ b/java/common/org/linphone/core/LpConfig.java @@ -21,12 +21,12 @@ package org.linphone.core; /** * The LpConfig object is used to manipulate a configuration file. - * + * *
  * The format of the configuration file is a .ini like format:
  * - sections are defined in []
  * - each section contains a sequence of key=value pairs.
- * 
+ *
  * Example:
  * [sound]
  * echocanceler=1
@@ -47,7 +47,7 @@ public interface LpConfig {
 	 * @param value the value of the setting
 	 */
 	void setInt(String section, String key, int value);
-	
+
 	/**
 	 * Sets an float config item
 	 * @param section the section in the lpconfig
@@ -80,7 +80,7 @@ public interface LpConfig {
 	 * @param max the max of the range
 	 */
 	void setIntRange(String section, String key, int min, int max);
-	
+
 	/**
 	 * Gets a int from the config
 	 * @param section the section in the lpconfig
@@ -89,7 +89,7 @@ public interface LpConfig {
 	 * @return the value of the setting or the default value if not set
 	 */
 	int getInt(String section, String key, int defaultValue);
-	
+
 	/**
 	 * Gets a float from the config
 	 * @param section the section in the lpconfig
@@ -98,7 +98,7 @@ public interface LpConfig {
 	 * @return the value of the setting or the default value if not set
 	 */
 	float getFloat(String section, String key, float defaultValue);
-	
+
 	/**
 	 * Gets a boolean from the config
 	 * @param section the section in the lpconfig
@@ -107,7 +107,7 @@ public interface LpConfig {
 	 * @return the value of the setting or the default value if not set
 	 */
 	boolean getBool(String section, String key, boolean defaultValue);
-	
+
 	/**
 	 * Gets a string from the config
 	 * @param section the section in the lpconfig
@@ -116,7 +116,7 @@ public interface LpConfig {
 	 * @return the value of the setting or the default value if not set
 	 */
 	String getString(String section, String key, String defaultValue);
-	
+
 	/**
 	 * Gets a int range from the config
 	 * @param section the section in the lpconfig
@@ -129,4 +129,10 @@ public interface LpConfig {
 	 * Synchronize LpConfig with file
 	 */
 	void sync();
+
+	/**
+	 * Load the value of the given xml file
+	 * @param fileName the name of the xml file
+	 */
+	void loadXmlFile(String fileName);
 }
diff --git a/java/impl/org/linphone/core/LpConfigImpl.java b/java/impl/org/linphone/core/LpConfigImpl.java
index a8d6d6b04..285795f38 100644
--- a/java/impl/org/linphone/core/LpConfigImpl.java
+++ b/java/impl/org/linphone/core/LpConfigImpl.java
@@ -22,40 +22,40 @@ class LpConfigImpl implements LpConfig {
 
 	private long nativePtr;
 	boolean ownPtr = false;
-	
+
 	public LpConfigImpl(long ptr) {
 		nativePtr = ptr;
 	}
-	
+
 	private native long newLpConfigImpl(String file);
 	private native long newLpConfigImplFromBuffer(String buffer);
 	private native void delete(long ptr);
-	
+
 	@Deprecated
 	public LpConfigImpl(String file) {
 		nativePtr = newLpConfigImpl(file);
 		ownPtr = true;
 	}
-	
+
 	private LpConfigImpl() {
 		nativePtr = -1;
 		ownPtr = false;
 	}
-	
+
 	public static LpConfigImpl fromFile(String file) {
 		LpConfigImpl impl = new LpConfigImpl();
 		impl.nativePtr = impl.newLpConfigImpl(file);
 		impl.ownPtr = true;
 		return impl;
 	}
-	
+
 	public static LpConfigImpl fromBuffer(String buffer) {
 		LpConfigImpl impl = new LpConfigImpl();
 		impl.nativePtr = impl.newLpConfigImplFromBuffer(buffer);
 		impl.ownPtr = true;
 		return impl;
 	}
-	
+
 	protected void finalize() throws Throwable {
 		if(ownPtr) {
 			delete(nativePtr);
@@ -128,4 +128,8 @@ class LpConfigImpl implements LpConfig {
 		return getIntRange(nativePtr, section, key, defaultMin, defaultMax);
 	}
 
+	private native void loadXmlFile(long ptr, String fileName);
+	public void loadXmlFile(String fileName) {
+		loadXmlFile(nativePtr, fileName);
+	}
 }