From db5fc6ea89802168e61a73d34cffa9582872d6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Fri, 12 Dec 2014 12:11:51 +0100 Subject: [PATCH] Fix the reading of .linpohne.ecstate --- coreapi/linphonecall.c | 10 ++++++---- coreapi/lpconfig.c | 29 +++++++++++++++-------------- coreapi/lpconfig.h | 8 +++++--- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index ce9bfa38b..9cf05f1a2 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -38,6 +38,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "mediastreamer2/mssndcard.h" static const char EC_STATE_STORE[] = ".linphone.ecstate"; +static const size_t EC_STATE_MAX_LEN = 1048576; // 1Mo static void linphone_call_stats_uninit(LinphoneCallStats *stats); @@ -1581,14 +1582,15 @@ void linphone_call_init_audio_stream(LinphoneCall *call){ audio_stream_enable_gain_control(audiostream,TRUE); if (linphone_core_echo_cancellation_enabled(lc)){ int len,delay,framesize; - char *statestr=lp_config_read_relative_file(lc->config, EC_STATE_STORE); + char statestr[EC_STATE_MAX_LEN]; len=lp_config_get_int(lc->config,"sound","ec_tail_len",0); delay=lp_config_get_int(lc->config,"sound","ec_delay",0); framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0); audio_stream_set_echo_canceller_params(audiostream,len,delay,framesize); - if (statestr && audiostream->ec){ - ms_filter_call_method(audiostream->ec,MS_ECHO_CANCELLER_SET_STATE_STRING,(void*)statestr); - ms_free(statestr); + if (audiostream->ec) { + if (lp_config_read_relative_file(lc->config, EC_STATE_STORE, statestr, EC_STATE_MAX_LEN) == 0) { + ms_filter_call_method(audiostream->ec, MS_ECHO_CANCELLER_SET_STATE_STRING, statestr); + } } } audio_stream_enable_automatic_gain_control(audiostream,linphone_core_agc_enabled(lc)); diff --git a/coreapi/lpconfig.c b/coreapi/lpconfig.c index a940fb696..ee87ac023 100644 --- a/coreapi/lpconfig.c +++ b/coreapi/lpconfig.c @@ -734,25 +734,26 @@ void lp_config_write_relative_file(const LpConfig *lpconfig, const char *filenam } } -char *lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename) { +int lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename, char *data, size_t max_length) { char *dir = _lp_config_dirname(lpconfig->filename); char *filepath = ms_strdup_printf("%s/%s", dir, filename); - char *result = NULL; - if(ortp_file_exist(filepath) == 0) { - FILE *file = fopen(filepath, "r"); - if(file != NULL) { - result = ms_new0(char, MAX_LEN); - if(fgets(result, MAX_LEN, file) == NULL) { - ms_error("%s could not be loaded", filepath); - } - fclose(file); - } else { - ms_error("Could not open %s for read", filepath); + FILE *file = fopen(filepath, "r"); + if(file != NULL) { + if(fgets(data, max_length, file) == NULL) { + ms_error("%s could not be loaded. %s", filepath, strerror(errno)); + goto err; } + fclose(file); } else { - ms_message("%s does not exist", filepath); + ms_error("Could not open %s for read. %s", filepath, strerror(errno)); + goto err; } ms_free(dir); ms_free(filepath); - return result; + return 0; + +err: + ms_free(dir); + ms_free(filepath); + return -1; } diff --git a/coreapi/lpconfig.h b/coreapi/lpconfig.h index 3498f00d2..65fd613f4 100644 --- a/coreapi/lpconfig.h +++ b/coreapi/lpconfig.h @@ -281,12 +281,14 @@ LINPHONE_PUBLIC void lp_config_unref(LpConfig *lpconfig); LINPHONE_PUBLIC void lp_config_write_relative_file(const LpConfig *lpconfig, const char *filename, const char *data); /** - * @brief Read a string from a file placed relatively with the Linphone configuration file + * @brief Read a string from a file placed beside the Linphone configuration file * @param lpconfig LpConfig instance used as a reference * @param filename Name of the file where data will be read from. The name is relative to the place of the config file - * @return The read string + * @param data Buffer where read string will be stored + * @param max_length Length of the buffer + * @return 0 on success, -1 on failure */ -LINPHONE_PUBLIC char *lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename); +LINPHONE_PUBLIC int lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename, char *data, size_t max_length); #ifdef __cplusplus }