Commit d6cdbe46 authored by Gautier Pelloux-Prayer's avatar Gautier Pelloux-Prayer
Browse files

lpconfig.c: add lp_config_relative_file_exists and use it to avoid...

lpconfig.c: add lp_config_relative_file_exists and use it to avoid false-positive logs for .linphone.ecstate file
parent a097d8d8
......@@ -37,7 +37,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/mseventqueue.h"
#include "mediastreamer2/mssndcard.h"
static const char EC_STATE_STORE[] = ".linphone.ecstate";
static const char *EC_STATE_STORE = ".linphone.ecstate";
#define EC_STATE_MAX_LEN 1048576 // 1Mo
static void linphone_call_stats_uninit(LinphoneCallStats *stats);
......@@ -1980,7 +1980,8 @@ void linphone_call_init_audio_stream(LinphoneCall *call){
audio_stream_set_echo_canceller_params(audiostream,len,delay,framesize);
if (audiostream->ec) {
char *statestr=ms_malloc0(EC_STATE_MAX_LEN);
if (lp_config_read_relative_file(lc->config, EC_STATE_STORE, statestr, EC_STATE_MAX_LEN) == 0) {
if (lp_config_relative_file_exists(lc->config, EC_STATE_STORE)
&& 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);
}
ms_free(statestr);
......
......@@ -100,7 +100,7 @@ LpItem * lp_comment_new(const char *comment){
pos=strchr(item->value,'\r');
if (pos==NULL)
pos=strchr(item->value,'\n');
if(pos) {
*pos='\0'; /*replace the '\n' */
}
......@@ -362,7 +362,7 @@ LpConfig *lp_config_new_with_factory(const char *config_filename, const char *fa
ms_message("Using (r/w) config information from %s", config_filename);
lpconfig->filename=ortp_strdup(config_filename);
lpconfig->tmpfilename=ortp_strdup_printf("%s.tmp",config_filename);
#if !defined(WIN32)
{
struct stat fileStat;
......@@ -719,6 +719,20 @@ static char *_lp_config_dirname(char *path) {
#endif
}
bool_t lp_config_relative_file_exists(const LpConfig *lpconfig, const char *filename) {
if (lpconfig->filename == NULL)
return FALSE;
char *dir = _lp_config_dirname(lpconfig->filename);
char *filepath = ms_strdup_printf("%s/%s", dir, filename);
FILE *file = fopen(filepath, "r");
ms_free(dir);
ms_free(filepath);
if (file) {
fclose(file);
}
return file != NULL;
}
void lp_config_write_relative_file(const LpConfig *lpconfig, const char *filename, const char *data) {
if (lpconfig->filename == NULL) return;
if(strlen(data) > 0) {
......@@ -760,7 +774,7 @@ int lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename,
ms_free(dir);
ms_free(filepath);
return 0;
err:
ms_free(dir);
ms_free(filepath);
......
......@@ -290,6 +290,11 @@ LINPHONE_PUBLIC void lp_config_write_relative_file(const LpConfig *lpconfig, con
*/
LINPHONE_PUBLIC int lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename, char *data, size_t max_length);
/**
* @return TRUE if file exists relative to the to the current location
**/
LINPHONE_PUBLIC bool_t lp_config_relative_file_exists(const LpConfig *lpconfig, const char *filename);
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment