Commit b4963d9f authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Put call log related code in its own files.

parent 53a34317
......@@ -65,7 +65,8 @@ LOCAL_SRC_FILES := \
xml2lpc.c \
lpc2xml.c \
remote_provisioning.c \
quality_reporting.c
quality_reporting.c \
call_log.c
ifndef LINPHONE_VERSION
LINPHONE_VERSION = "Devel"
......
......@@ -107,6 +107,7 @@
<ClCompile Include="..\..\coreapi\bellesip_sal\sal_op_publish.c" />
<ClCompile Include="..\..\coreapi\bellesip_sal\sal_op_registration.c" />
<ClCompile Include="..\..\coreapi\bellesip_sal\sal_sdp.c" />
<ClCompile Include="..\..\coreapi\call_log.c" />
<ClCompile Include="..\..\coreapi\callbacks.c" />
<ClCompile Include="..\..\coreapi\chat.c" />
<ClCompile Include="..\..\coreapi\conference.c" />
......
......@@ -42,6 +42,7 @@ set(SOURCE_FILES
bellesip_sal/sal_op_registration.c
bellesip_sal/sal_sdp.c
callbacks.c
call_log.c
chat.c
conference.c
ec-calibrator.c
......@@ -139,7 +140,19 @@ install(TARGETS linphone
)
file(GLOB HEADER_FILES "*.h")
set(HEADER_FILES
call_log.h
event.h
linphonecore.h
linphonecore_utils.h
linphonefriend.h
linphonepresence.h
linphone_tunnel.h
lpc2xml.h
lpconfig.h
sipsetup.h
xml2lpc.h
)
install(FILES ${HEADER_FILES}
DESTINATION include/linphone
......
......@@ -24,7 +24,7 @@ CLEANFILES=$(GITVERSION_FILE)
## Process this file with automake to produce Makefile.in
linphone_includedir=$(includedir)/linphone
linphone_include_HEADERS=linphonecore.h linphonefriend.h linphonepresence.h linphonecore_utils.h lpconfig.h sipsetup.h event.h xml2lpc.h lpc2xml.h linphone_tunnel.h
linphone_include_HEADERS=linphonecore.h linphonefriend.h linphonepresence.h linphonecore_utils.h lpconfig.h sipsetup.h event.h xml2lpc.h lpc2xml.h linphone_tunnel.h call_log.h
lib_LTLIBRARIES=liblinphone.la
......@@ -59,6 +59,7 @@ liblinphone_la_SOURCES=\
lpc2xml.c \
remote_provisioning.c \
quality_reporting.c quality_reporting.h\
call_log.c \
$(GITVERSION_FILE)
if BUILD_UPNP
......
/*
linphone
Copyright (C) 2010-2014 Belledonne Communications SARL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "linphonecore.h"
#include "private.h"
/*******************************************************************************
* Internal functions *
******************************************************************************/
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);
}
/*******************************************************************************
* Private functions *
******************************************************************************/
void call_logs_write_to_config_file(LinphoneCore *lc){
MSList *elem;
char logsection[32];
int i;
char *tmp;
LpConfig *cfg=lc->config;
if (linphone_core_get_global_state (lc)==LinphoneGlobalStartup) return;
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);
lp_config_set_string(cfg,logsection,"from",tmp);
ms_free(tmp);
tmp=linphone_address_as_string(cl->to);
lp_config_set_string(cfg,logsection,"to",tmp);
ms_free(tmp);
if (cl->start_date_time)
lp_config_set_int64(cfg,logsection,"start_date_time",(int64_t)cl->start_date_time);
else lp_config_set_string(cfg,logsection,"start_date",cl->start_date);
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);
lp_config_set_int(cfg,logsection,"video_enabled", cl->video_enabled);
lp_config_set_string(cfg,logsection,"call_id",cl->call_id);
}
for(;i<lc->max_call_logs;++i){
snprintf(logsection,sizeof(logsection),"call_log_%i",i);
lp_config_clean_section(cfg,logsection);
}
}
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);
if (lp_config_has_section(cfg,logsection)){
LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
cl->dir=lp_config_get_int(cfg,logsection,"dir",0);
cl->status=lp_config_get_int(cfg,logsection,"status",0);
tmp=lp_config_get_string(cfg,logsection,"from",NULL);
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);
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);
cl->quality=lp_config_get_float(cfg,logsection,"quality",-1);
cl->video_enabled=lp_config_get_int(cfg,logsection,"video_enabled",0);
tmp=lp_config_get_string(cfg,logsection,"call_id",NULL);
if (tmp) cl->call_id=ms_strdup(tmp);
lc->call_logs=ms_list_append(lc->call_logs,cl);
}else break;
}
}
/*******************************************************************************
* Public functions *
******************************************************************************/
const char *linphone_call_log_get_call_id(const LinphoneCallLog *cl){
return cl->call_id;
}
LinphoneCallDir linphone_call_log_get_dir(LinphoneCallLog *cl){
return cl->dir;
}
int linphone_call_log_get_duration(LinphoneCallLog *cl){
return cl->duration;
}
LinphoneAddress *linphone_call_log_get_from_address(LinphoneCallLog *cl){
return cl->from;
}
const rtp_stats_t *linphone_call_log_get_local_stats(const LinphoneCallLog *cl){
return &cl->local_stats;
}
float linphone_call_log_get_quality(LinphoneCallLog *cl){
return cl->quality;
}
const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){
return cl->refkey;
}
LinphoneAddress *linphone_call_log_get_remote_address(LinphoneCallLog *cl){
return (cl->dir == LinphoneCallIncoming) ? cl->from : cl->to;
}
const rtp_stats_t *linphone_call_log_get_remote_stats(const LinphoneCallLog *cl){
return &cl->remote_stats;
}
time_t linphone_call_log_get_start_date(LinphoneCallLog *cl){
return cl->start_date_time;
}
LinphoneCallStatus linphone_call_log_get_status(LinphoneCallLog *cl){
return cl->status;
}
LinphoneAddress *linphone_call_log_get_to_address(LinphoneCallLog *cl){
return cl->to;
}
void linphone_call_log_set_ref_key(LinphoneCallLog *cl, const char *refkey){
if (cl->refkey!=NULL){
ms_free(cl->refkey);
cl->refkey=NULL;
}
if (refkey) cl->refkey=ms_strdup(refkey);
}
char * linphone_call_log_to_str(LinphoneCallLog *cl){
char *status;
char *tmp;
char *from=linphone_address_as_string (cl->from);
char *to=linphone_address_as_string (cl->to);
switch(cl->status){
case LinphoneCallAborted:
status=_("aborted");
break;
case LinphoneCallSuccess:
status=_("completed");
break;
case LinphoneCallMissed:
status=_("missed");
break;
default:
status="unknown";
}
tmp=ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"),
(cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"),
cl->start_date,
from,
to,
status,
cl->duration/60,
cl->duration%60);
ms_free(from);
ms_free(to);
return tmp;
}
bool_t linphone_call_log_video_enabled(LinphoneCallLog *cl) {
return cl->video_enabled;
}
/*******************************************************************************
* Reference and user data handling functions *
******************************************************************************/
void *linphone_call_log_get_user_data(const LinphoneCallLog *cl){
return cl->user_pointer;
}
void linphone_call_log_set_user_data(LinphoneCallLog *cl, void *ud){
cl->user_pointer=ud;
}
/*******************************************************************************
* Constructor and destructor functions *
******************************************************************************/
void linphone_call_log_destroy(LinphoneCallLog *cl){
if (cl->from!=NULL) linphone_address_destroy(cl->from);
if (cl->to!=NULL) linphone_address_destroy(cl->to);
if (cl->refkey!=NULL) ms_free(cl->refkey);
if (cl->call_id) ms_free(cl->call_id);
if (cl->reporting.reports[LINPHONE_CALL_STATS_AUDIO]!=NULL) linphone_reporting_destroy(cl->reporting.reports[LINPHONE_CALL_STATS_AUDIO]);
if (cl->reporting.reports[LINPHONE_CALL_STATS_VIDEO]!=NULL) linphone_reporting_destroy(cl->reporting.reports[LINPHONE_CALL_STATS_VIDEO]);
ms_free(cl);
}
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=time(NULL);
set_call_log_date(cl,cl->start_date_time);
cl->from=from;
cl->to=to;
cl->status=LinphoneCallAborted; /*default status*/
cl->quality=-1;
cl->reporting.reports[LINPHONE_CALL_STATS_AUDIO]=linphone_reporting_new();
cl->reporting.reports[LINPHONE_CALL_STATS_VIDEO]=linphone_reporting_new();
return cl;
}
/*
linphone
Copyright (C) 2010-2014 Belledonne Communications SARL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __LINPHONE_CALL_LOG_H__
#define __LINPHONE_CALL_LOG_H__
/**
* @addtogroup call_logs
* @{
**/
/*******************************************************************************
* Structures and enums *
******************************************************************************/
/**
* Enum representing the direction of a call.
**/
enum _LinphoneCallDir {
LinphoneCallOutgoing, /**< outgoing calls*/
LinphoneCallIncoming /**< incoming calls*/
};
/**
* Typedef for enum
**/
typedef enum _LinphoneCallDir LinphoneCallDir;
/**
* Enum representing the status of a call
**/
typedef enum _LinphoneCallStatus {
LinphoneCallSuccess, /**< The call was sucessful */
LinphoneCallAborted, /**< The call was aborted */
LinphoneCallMissed, /**< The call was missed (unanswered) */
LinphoneCallDeclined /**< The call was declined, either locally or by remote end */
} LinphoneCallStatus;
/**
* Structure representing a call log.
**/
typedef struct _LinphoneCallLog LinphoneCallLog;
/*******************************************************************************
* Public functions *
******************************************************************************/
/**
* Get the call ID used by the call.
* @param[in] cl LinphoneCallLog object
* @return The call ID used by the call as a string.
**/
LINPHONE_PUBLIC const char * linphone_call_log_get_call_id(const LinphoneCallLog *cl);
/**
* Get the direction of the call.
* @param[in] cl LinphoneCallLog object
* @return The direction of the call.
**/
LINPHONE_PUBLIC LinphoneCallDir linphone_call_log_get_dir(LinphoneCallLog *cl);
/**
* Get the duration of the call.
* @param[in] cl LinphoneCallLog object
* @return The duration of the call in seconds.
**/
LINPHONE_PUBLIC int linphone_call_log_get_duration(LinphoneCallLog *cl);
/**
* Get the origin address (ie from) of the call.
* @param[in] cl LinphoneCallLog object
* @return The origin address (ie from) of the call.
**/
LINPHONE_PUBLIC LinphoneAddress * linphone_call_log_get_from_address(LinphoneCallLog *cl);
/**
* Get the RTP statistics computed locally regarding the call.
* @param[in] cl LinphoneCallLog object
* @return The RTP statistics that have been computed locally for the call.
**/
LINPHONE_PUBLIC const rtp_stats_t * linphone_call_log_get_local_stats(const LinphoneCallLog *cl);
/**
* Get the overall quality indication of the call.
* @param[in] cl LinphoneCallLog object
* @return The overall quality indication of the call.
**/
LINPHONE_PUBLIC float linphone_call_log_get_quality(LinphoneCallLog *cl);
/**
* Get the persistent reference key associated to the call log.
*
* The reference key can be for example an id to an external database.
* It is stored in the config file, thus can survive to process exits/restarts.
*
* @param[in] cl LinphoneCallLog object
* @return The reference key string that has been associated to the call log, or NULL if none has been associated.
**/
LINPHONE_PUBLIC const char * linphone_call_log_get_ref_key(const LinphoneCallLog *cl);
/**
* Get the remote address (that is from or to depending on call direction).
* @param[in] cl LinphoneCallLog object
* @return The remote address of the call.
**/
LINPHONE_PUBLIC LinphoneAddress * linphone_call_log_get_remote_address(LinphoneCallLog *cl);
/**
* Get the RTP statistics computed by the remote end and sent back via RTCP.
* @note Not implemented yet.
* @param[in] cl LinphoneCallLog object
* @return The RTP statistics that have been computed by the remote end for the call.
**/
LINPHONE_PUBLIC const rtp_stats_t * linphone_call_log_get_remote_stats(const LinphoneCallLog *cl);
/**
* Get the start date of the call.
* @param[in] cl LinphoneCallLog object
* @return The date of the beginning of the call.
**/
LINPHONE_PUBLIC time_t linphone_call_log_get_start_date(LinphoneCallLog *cl);
/**
* Get the status of the call.
* @param[in] cl LinphoneCallLog object
* @return The status of the call.
**/
LINPHONE_PUBLIC LinphoneCallStatus linphone_call_log_get_status(LinphoneCallLog *cl);
/**
* Get the destination address (ie to) of the call.
* @param[in] cl LinphoneCallLog object
* @return The destination address (ie to) of the call.
**/
LINPHONE_PUBLIC LinphoneAddress * linphone_call_log_get_to_address(LinphoneCallLog *cl);
/**
* Associate a persistent reference key to the call log.
*
* The reference key can be for example an id to an external database.
* It is stored in the config file, thus can survive to process exits/restarts.
*
* @param[in] cl LinphoneCallLog object
* @param[in] refkey The reference key string to associate to the call log.
**/
LINPHONE_PUBLIC void linphone_call_log_set_ref_key(LinphoneCallLog *cl, const char *refkey);
/**
* Tell whether video was enabled at the end of the call or not.
* @param[in] cl LinphoneCallLog object
* @return A boolean value telling whether video was enabled at the end of the call.
**/
LINPHONE_PUBLIC bool_t linphone_call_log_video_enabled(LinphoneCallLog *cl);
/**
* Get a human readable string describing the call.
* @note: the returned string must be freed by the application (use ms_free()).
* @param[in] cl LinphoneCallLog object
* @return A human readable string describing the call.
**/
LINPHONE_PUBLIC char * linphone_call_log_to_str(LinphoneCallLog *cl);
/*******************************************************************************
* Reference and user data handling functions *
******************************************************************************/
/**
* Get the user data associated with the call log.
* @param[in] cl LinphoneCallLog object
* @return The user data associated with the call log.
**/
LINPHONE_PUBLIC void *linphone_call_log_get_user_data(const LinphoneCallLog *cl);
/**
* Assign a user data to the call log.
* @param[in] cl LinphoneCallLog object
* @param[in] ud The user data to associate with the call log.
**/
LINPHONE_PUBLIC void linphone_call_log_set_user_data(LinphoneCallLog *cl, void *ud);
/*******************************************************************************
* DEPRECATED *
******************************************************************************/
/** @deprecated Use linphone_call_log_get_from_address() instead. */
#define linphone_call_log_get_from(cl) linphone_call_log_get_from_address(cl)
/** @deprecated Use linphone_call_log_get_to_address() instead. */
#define linphone_call_log_get_to(cl) linphone_call_log_get_to_address(cl)
/** @deprecated Use linphone_call_log_set_user_data() instead. */
#define linphone_call_log_set_user_pointer(cl, ud) linphone_call_log_set_user_data(cl, ud)
/** @deprecated Use linphone_call_log_get_user_data() instead. */
#define linphone_call_log_get_user_pointer(cl) linphone_call_log_get_user_data(cl)
/**
* @}
**/
#endif /* __LINPHONE_CALL_LOG_H__ */
......@@ -107,70 +107,6 @@ static size_t my_strftime(char *s, size_t max, const char *fmt, const struct t
return strftime(s, max, fmt, tm);
}
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);
cl->dir=call->dir;
cl->start_date_time=time(NULL);
set_call_log_date(cl,cl->start_date_time);
cl->from=from;
cl->to=to;
cl->status=LinphoneCallAborted; /*default status*/
cl->quality=-1;
cl->reporting.reports[LINPHONE_CALL_STATS_AUDIO]=linphone_reporting_new();
cl->reporting.reports[LINPHONE_CALL_STATS_VIDEO]=linphone_reporting_new();
return cl;
}
void call_logs_write_to_config_file(LinphoneCore *lc){
MSList *elem;
char logsection[32];
int i;
char *tmp;
LpConfig *cfg=lc->config;
if (linphone_core_get_global_state (lc)==LinphoneGlobalStartup) return;
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);
lp_config_set_string(cfg,logsection,"from",tmp);
ms_free(tmp);
tmp=linphone_address_as_string(cl->to);
lp_config_set_string(cfg,logsection,"to",tmp);
ms_free(tmp);
if (cl->start_date_time)
lp_config_set_int64(cfg,logsection,"start_date_time",(int64_t)cl->start_date_time);
else lp_config_set_string(cfg,logsection,"start_date",cl->start_date);
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);
lp_config_set_int(cfg,logsection,"video_enabled", cl->video_enabled);
lp_config_set_string(cfg,logsection,"call_id",cl->call_id);
}
for(;i<lc->max_call_logs;++i){
snprintf(logsection,sizeof(logsection),"call_log_%i",i);
lp_config_clean_section(cfg,logsection);
}
}
static time_t string_to_time(const char *date){
#ifndef WIN32
struct tm tmtime={0};
......@@ -181,230 +117,6 @@ static time_t string_to_time(const char *date){
#endif
}