Commit ace189f5 authored by Simon Morlat's avatar Simon Morlat

change the way call log dates are stored in linphonerc

parent f5169e00
......@@ -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);
}
LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
static void set_call_log_date(LinphoneCallLog *cl, time_t start_time){
struct tm loctime;
cl->dir=call->dir;
#ifdef WIN32
#if !defined(_WIN32_WCE)
loctime=*localtime(&call->start_time);
loctime=*localtime(&start_time);
/*FIXME*/
#endif /*_WIN32_WCE*/
#else
localtime_r(&call->start_time,&loctime);
localtime_r(&start_time,&loctime);
#endif
set_call_log_date(cl,&loctime);
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);
cl->dir=call->dir;
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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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
*
......
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