From ace189f5f2e6364eb1e85a2244d00131f9119cb5 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 26 Jun 2012 23:12:38 +0200 Subject: [PATCH] change the way call log dates are stored in linphonerc --- coreapi/linphonecore.c | 51 +++++++++++++++++++++++++++++------------- coreapi/linphonecore.h | 1 + coreapi/lpconfig.c | 19 ++++++++++++++++ coreapi/lpconfig.h | 17 ++++++++++++++ 4 files changed, 73 insertions(+), 15 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index d48c2fa28..174f6c9c6 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define _GNU_SOURCE + #include "linphonecore.h" #include "sipsetup.h" #include "lpconfig.h" @@ -85,23 +87,24 @@ static size_t my_strftime(char *s, size_t max, const char *fmt, const struct t #endif /*_WIN32_WCE*/ } -static void set_call_log_date(LinphoneCallLog *cl, const struct tm *loctime){ - my_strftime(cl->start_date,sizeof(cl->start_date),"%c",loctime); +static void set_call_log_date(LinphoneCallLog *cl, time_t start_time){ + struct tm loctime; +#ifdef WIN32 +#if !defined(_WIN32_WCE) + loctime=*localtime(&start_time); + /*FIXME*/ +#endif /*_WIN32_WCE*/ +#else + localtime_r(&start_time,&loctime); +#endif + my_strftime(cl->start_date,sizeof(cl->start_date),"%c",&loctime); } LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){ LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1); - struct tm loctime; cl->dir=call->dir; -#ifdef WIN32 -#if !defined(_WIN32_WCE) - loctime=*localtime(&call->start_time); - /*FIXME*/ -#endif /*_WIN32_WCE*/ -#else - localtime_r(&call->start_time,&loctime); -#endif - set_call_log_date(cl,&loctime); + cl->start_date_time=call->start_time; + set_call_log_date(cl,cl->start_date_time); cl->from=from; cl->to=to; cl->status=LinphoneCallAborted; /*default status*/ @@ -120,6 +123,7 @@ void call_logs_write_to_config_file(LinphoneCore *lc){ for(i=0,elem=lc->call_logs;elem!=NULL;elem=elem->next,++i){ LinphoneCallLog *cl=(LinphoneCallLog*)elem->data; snprintf(logsection,sizeof(logsection),"call_log_%i",i); + lp_config_clean_section(cfg,logsection); lp_config_set_int(cfg,logsection,"dir",cl->dir); lp_config_set_int(cfg,logsection,"status",cl->status); tmp=linphone_address_as_string(cl->from); @@ -128,7 +132,7 @@ void call_logs_write_to_config_file(LinphoneCore *lc){ tmp=linphone_address_as_string(cl->to); lp_config_set_string(cfg,logsection,"to",tmp); ms_free(tmp); - lp_config_set_string(cfg,logsection,"start_date",cl->start_date); + lp_config_set_int64(cfg,logsection,"start_date_time",(int64_t)cl->start_date_time); lp_config_set_int(cfg,logsection,"duration",cl->duration); if (cl->refkey) lp_config_set_string(cfg,logsection,"refkey",cl->refkey); lp_config_set_float(cfg,logsection,"quality",cl->quality); @@ -140,10 +144,17 @@ void call_logs_write_to_config_file(LinphoneCore *lc){ } } +static time_t string_to_time(const char *date){ + struct tm tmtime={0}; + strptime(date,"%c",&tmtime); + return mktime(&tmtime); +} + static void call_logs_read_from_config_file(LinphoneCore *lc){ char logsection[32]; int i; const char *tmp; + uint64_t sec; LpConfig *cfg=lc->config; for(i=0;;++i){ snprintf(logsection,sizeof(logsection),"call_log_%i",i); @@ -155,8 +166,18 @@ static void call_logs_read_from_config_file(LinphoneCore *lc){ if (tmp) cl->from=linphone_address_new(tmp); tmp=lp_config_get_string(cfg,logsection,"to",NULL); if (tmp) cl->to=linphone_address_new(tmp); - tmp=lp_config_get_string(cfg,logsection,"start_date",NULL); - if (tmp) strncpy(cl->start_date,tmp,sizeof(cl->start_date)); + sec=lp_config_get_int64(cfg,logsection,"start_date_time",0); + if (sec) { + /*new call log format with date expressed in seconds */ + cl->start_date_time=(time_t)sec; + set_call_log_date(cl,cl->start_date_time); + }else{ + tmp=lp_config_get_string(cfg,logsection,"start_date",NULL); + if (tmp) { + strncpy(cl->start_date,tmp,sizeof(cl->start_date)); + cl->start_date_time=string_to_time(cl->start_date); + } + } cl->duration=lp_config_get_int(cfg,logsection,"duration",0); tmp=lp_config_get_string(cfg,logsection,"refkey",NULL); if (tmp) cl->refkey=ms_strdup(tmp); diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 79d6204a0..81044fff5 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -155,6 +155,7 @@ typedef struct _LinphoneCallLog{ float quality; int video_enabled; struct _LinphoneCore *lc; + time_t start_date_time; /**Start date of the call in seconds as expressed in a time_t */ } LinphoneCallLog; diff --git a/coreapi/lpconfig.c b/coreapi/lpconfig.c index d12166ec4..4cd7202cc 100644 --- a/coreapi/lpconfig.c +++ b/coreapi/lpconfig.c @@ -277,6 +277,18 @@ int lp_config_get_int(LpConfig *lpconfig,const char *section, const char *key, i else return default_value; } +int64_t lp_config_get_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t default_value){ + const char *str=lp_config_get_string(lpconfig,section,key,NULL); + if (str!=NULL) { +#ifdef WIN32 + return (int64_t)_atoi64(str); +#else + return atoll(str); +#endif + } + else return default_value; +} + float lp_config_get_float(LpConfig *lpconfig,const char *section, const char *key, float default_value){ const char *str=lp_config_get_string(lpconfig,section,key,NULL); float ret=default_value; @@ -312,6 +324,13 @@ void lp_config_set_int(LpConfig *lpconfig,const char *section, const char *key, lp_config_set_string(lpconfig,section,key,tmp); } +void lp_config_set_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t value){ + char tmp[30]; + snprintf(tmp,sizeof(tmp),"%lli",(long long)value); + lp_config_set_string(lpconfig,section,key,tmp); +} + + void lp_config_set_float(LpConfig *lpconfig,const char *section, const char *key, float value){ char tmp[30]; snprintf(tmp,sizeof(tmp),"%f",value); diff --git a/coreapi/lpconfig.h b/coreapi/lpconfig.h index ed7a66b1e..c1821d2aa 100644 --- a/coreapi/lpconfig.h +++ b/coreapi/lpconfig.h @@ -66,6 +66,16 @@ int lp_config_read_file(LpConfig *lpconfig, const char *filename); * The default integer value is returned if the config item isn't found. **/ int lp_config_get_int(LpConfig *lpconfig,const char *section, const char *key, int default_value); + +/** + * Retrieves a configuration item as a 64 bit integer, given its section, key, and default value. + * + * @ingroup misc + * The default integer value is returned if the config item isn't found. +**/ +int64_t lp_config_get_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t default_value); + + int lp_config_read_file(LpConfig *lpconfig, const char *filename); /** * Retrieves a configuration item as a float, given its section, key, and default value. @@ -86,6 +96,13 @@ void lp_config_set_string(LpConfig *lpconfig,const char *section, const char *ke * @ingroup misc **/ void lp_config_set_int(LpConfig *lpconfig,const char *section, const char *key, int value); +/** + * Sets a 64 bits integer config item + * + * @ingroup misc +**/ +void lp_config_set_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t value); + /** * Sets a float config item *