From b3df86baf28d846a98b19983a6b28cb93ad9bdb7 Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Mon, 24 Apr 2017 15:51:54 +0200 Subject: [PATCH] Fix remote provisioning --- coreapi/lpconfig.c | 48 +++++++++++++++++++++++------------ coreapi/remote_provisioning.c | 2 +- include/linphone/lpconfig.h | 10 ++++++++ 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/coreapi/lpconfig.c b/coreapi/lpconfig.c index 12d14b65b..e41a20116 100644 --- a/coreapi/lpconfig.c +++ b/coreapi/lpconfig.c @@ -481,29 +481,45 @@ LinphoneStatus linphone_config_read_file(LpConfig *lpconfig, const char *filenam return -1; } +static char* _linphone_config_xml_convert(LpConfig *lpc, xml2lpc_context *context, int result) { + char* error_msg = NULL; + 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"; + } + return error_msg; +} + char* linphone_config_load_from_xml_file(LpConfig *lpc, const char *filename, void* lc, 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(ctx, lc); - result = xml2lpc_set_xml_file(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"; - } + error_msg = _linphone_config_xml_convert(lpc, context, xml2lpc_set_xml_file(context, path)); + } + if (context) xml2lpc_context_destroy(context); + return error_msg; +} + +char* linphone_config_load_from_xml_string(LpConfig *lpc, const char *buffer, void* lc, void* ctx) { + xml2lpc_context *context = NULL; + char* error_msg = NULL; + + if (buffer != NULL) { + context = xml2lpc_context_new(ctx, lc); + error_msg = _linphone_config_xml_convert(lpc, context, xml2lpc_set_xml_string(context, buffer)); } if (context) xml2lpc_context_destroy(context); return error_msg; diff --git a/coreapi/remote_provisioning.c b/coreapi/remote_provisioning.c index daadf4163..213613803 100644 --- a/coreapi/remote_provisioning.c +++ b/coreapi/remote_provisioning.c @@ -35,7 +35,7 @@ static void xml2lpc_callback(void *ctx, xml2lpc_log_level level, const char *fmt } static void linphone_remote_provisioning_apply(LinphoneCore *lc, const char *xml) { - char* error_msg = linphone_config_load_from_xml_file(linphone_core_get_config(lc), xml, lc, xml2lpc_callback); + char* error_msg = linphone_config_load_from_xml_string(linphone_core_get_config(lc), xml, lc, xml2lpc_callback); linphone_configuring_terminated(lc ,error_msg ? LinphoneConfiguringFailed : LinphoneConfiguringSuccessful diff --git a/include/linphone/lpconfig.h b/include/linphone/lpconfig.h index 72b06213d..8da6d23bf 100644 --- a/include/linphone/lpconfig.h +++ b/include/linphone/lpconfig.h @@ -92,6 +92,16 @@ LINPHONE_PUBLIC LinphoneStatus linphone_config_read_file(LinphoneConfig *lpconfi */ LINPHONE_PUBLIC char* linphone_config_load_from_xml_file(LpConfig *lpc, const char *filename, void* lc, void* ctx); +/** + * Reads a xml config string 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 buffer The string of the config file to fill the LinphoneConfig + * @param lc LinphoneCore to share with xml2lpc + * @param ctx The context given to xml2lpc callback + */ +LINPHONE_PUBLIC char* linphone_config_load_from_xml_string(LpConfig *lpc, const char *buffer, void* lc, void* ctx); + /** * Retrieves a configuration item as a string, given its section, key, and default value. *