From 9801ad5b4e7aaf1fd20c82d2923aa7aaedd1c2f4 Mon Sep 17 00:00:00 2001 From: mikomarrache Date: Tue, 14 Apr 2015 15:22:29 +0300 Subject: [PATCH 1/4] acc: add new types Add new types to support core fields of type date (for start and end date) and double (for duration). --- modules/acc/acc_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/acc/acc_api.h b/modules/acc/acc_api.h index f2efbe40292..f252b589582 100644 --- a/modules/acc/acc_api.h +++ b/modules/acc/acc_api.h @@ -110,7 +110,7 @@ typedef struct acc_engine { #define ACC_CORE_LEN 6 -enum {TYPE_NULL = 0, TYPE_INT, TYPE_STR}; +enum {TYPE_NULL = 0, TYPE_INT, TYPE_STR, TYPE_DOUBLE, TYPE_DATE}; typedef int (*register_engine_f)(acc_engine_t *eng); From b38874078ccf23b093bc94484e08bf1a4ba53f90 Mon Sep 17 00:00:00 2001 From: mikomarrache Date: Tue, 14 Apr 2015 15:29:02 +0300 Subject: [PATCH 2/4] acc: change type of core fields to real types Change the type of the core fields as follows: -> start and end as dates (instead of string) -> duration as double (instead of string) Then, set the db_val with appropriate value and type. --- modules/acc/acc_cdr.c | 54 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/modules/acc/acc_cdr.c b/modules/acc/acc_cdr.c index d01beb96f62..a547c34ab31 100644 --- a/modules/acc/acc_cdr.c +++ b/modules/acc/acc_cdr.c @@ -90,6 +90,8 @@ extern str acc_cdrs_table; extern int cdr_log_enable; extern int _acc_cdr_on_failed; +static int string2time( str* time_str, struct timeval* time_value); + /* write all basic information to buffers(e.g. start-time ...) */ static int cdr_core2strar( struct dlg_cell* dlg, str* values, @@ -111,13 +113,13 @@ static int cdr_core2strar( struct dlg_cell* dlg, duration = dlgb.get_dlg_var( dlg, (str*)&cdr_duration_str); values[0] = ( start != NULL ? *start : empty_string); - types[0] = ( start != NULL ? TYPE_STR : TYPE_NULL); + types[0] = ( start != NULL ? TYPE_DATE : TYPE_NULL); values[1] = ( end != NULL ? *end : empty_string); - types[1] = ( end != NULL ? TYPE_STR : TYPE_NULL); + types[1] = ( end != NULL ? TYPE_DATE : TYPE_NULL); values[2] = ( duration != NULL ? *duration : empty_string); - types[2] = ( duration != NULL ? TYPE_STR : TYPE_NULL); + types[2] = ( duration != NULL ? TYPE_DOUBLE : TYPE_NULL); return MAX_CDR_CORE; } @@ -138,6 +140,10 @@ static int db_write_cdr( struct dlg_cell* dialog, db1_con_t *dh=NULL; void *vf=NULL; void *vh=NULL; + struct timeval timeval_val; + long long_val; + double double_val; + char * end; if(acc_cdrs_table.len<=0) return 0; @@ -157,9 +163,45 @@ static int db_write_cdr( struct dlg_cell* dialog, for(i=0; i Date: Tue, 14 Apr 2015 15:53:29 +0300 Subject: [PATCH 3/4] acc: fix copy/paste error --- modules/acc/acc_cdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/acc/acc_cdr.c b/modules/acc/acc_cdr.c index a547c34ab31..845fc126228 100644 --- a/modules/acc/acc_cdr.c +++ b/modules/acc/acc_cdr.c @@ -175,7 +175,7 @@ static int db_write_cdr( struct dlg_cell* dialog, LM_ERR("failed to convert string to integer - %d.\n", errno); goto error; } - VAL_INT(db_cdr_vals+i) = cdr_value_array[i]; + VAL_INT(db_cdr_vals+i) = long_val; break; case TYPE_STR: VAL_TYPE(db_cdr_vals+i)=DB1_STR; From 287884ba9183da3eed2eb4fba1e31d287730fe26 Mon Sep 17 00:00:00 2001 From: mikomarrache Date: Tue, 14 Apr 2015 20:37:37 +0300 Subject: [PATCH 4/4] acc: update schema and version Change type of columns: -> start_time and end_time as datetime -> duration as float Also increment version of acc_cdrs table. --- lib/srdb1/schema/acc_cdrs.xml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/srdb1/schema/acc_cdrs.xml b/lib/srdb1/schema/acc_cdrs.xml index 22cba14416a..84bb678fa98 100644 --- a/lib/srdb1/schema/acc_cdrs.xml +++ b/lib/srdb1/schema/acc_cdrs.xml @@ -9,7 +9,7 @@ acc_cdrs - 1 + 2&MYSQL_TABLE_TYPE; This table is used by the ACC module to report on CDRs relying on dialog callbacks. More information is available at: &KAMAILIO_MOD_DOC;acc.html @@ -28,24 +28,22 @@ start_time - string - 32 - Start time + datetime + Start date and time end_time - string - 32 - End time + datetime + End date and time duration - string - 32 + float + 10,3 Duration