|
35 | 35 |
|
36 | 36 | #include <stdio.h> |
37 | 37 | #include <time.h> |
| 38 | +#include <math.h> |
38 | 39 |
|
39 | 40 | #include "../../dprint.h" |
40 | 41 | #include "../../error.h" |
@@ -178,7 +179,7 @@ static inline int core2strar( struct sip_msg *req, str *c_vals) |
178 | 179 |
|
179 | 180 | c_vals[5] = acc_env.reason; |
180 | 181 |
|
181 | | - gettimeofday(&acc_env.ts, NULL); |
| 182 | + acc_env.ts = *get_msg_time(req); |
182 | 183 |
|
183 | 184 | return ACC_CORE_LEN; |
184 | 185 | } |
@@ -221,6 +222,8 @@ int acc_log_cdrs(struct dlg_cell *dlg, struct sip_msg *msg, acc_ctx_t* ctx) |
221 | 222 | { |
222 | 223 | static char log_msg[MAX_SYSLOG_SIZE]; |
223 | 224 | static char *log_msg_end=log_msg+MAX_SYSLOG_SIZE-2; |
| 225 | + unsigned long ms_duration; |
| 226 | + unsigned long duration; |
224 | 227 | char *p; |
225 | 228 | int i, j, ret, res = -1, n; |
226 | 229 | struct timeval start_time; |
@@ -284,12 +287,13 @@ int acc_log_cdrs(struct dlg_cell *dlg, struct sip_msg *msg, acc_ctx_t* ctx) |
284 | 287 | *(p++) = '\n'; |
285 | 288 | *(p++) = 0; |
286 | 289 |
|
| 290 | + ms_duration = TIMEVAL_MS_DIFF(start_time, ctx->bye_time); |
| 291 | + duration = ceil((double)ms_duration/1000); |
| 292 | + |
287 | 293 | LM_GEN2(acc_log_facility, acc_log_level, |
288 | 294 | "%.*screated=%lu;call_start_time=%lu;duration=%lu;ms_duration=%lu;setuptime=%lu%s", |
289 | 295 | acc_env.text.len, acc_env.text.s,(unsigned long)ctx->created, |
290 | | - (unsigned long)start_time.tv_sec, |
291 | | - (unsigned long)(ctx->bye_time.tv_sec-start_time.tv_sec), |
292 | | - (unsigned long)TIMEVAL_MS_DIFF(start_time, ctx->bye_time), |
| 296 | + (unsigned long)start_time.tv_sec, duration, ms_duration, |
293 | 297 | (unsigned long)(start_time.tv_sec - ctx->created), log_msg); |
294 | 298 |
|
295 | 299 | res = 1; |
@@ -680,10 +684,10 @@ int acc_db_cdrs(struct dlg_cell *dlg, struct sip_msg *msg, acc_ctx_t* ctx) |
680 | 684 | start_time.tv_sec - ctx->created; |
681 | 685 | VAL_NULL(db_vals+ret+nr_leg_vals+2) = 0; |
682 | 686 | VAL_TIME(db_vals+ret+nr_leg_vals+2) = ctx->created; |
683 | | - VAL_INT(db_vals+ret+nr_leg_vals+3) = |
684 | | - ctx->bye_time.tv_sec - start_time.tv_sec; |
685 | 687 | VAL_INT(db_vals+ret+nr_leg_vals+4) = |
686 | 688 | TIMEVAL_MS_DIFF(start_time, ctx->bye_time); |
| 689 | + VAL_INT(db_vals+ret+nr_leg_vals+3) = |
| 690 | + ceil((double)VAL_INT(db_vals+ret+nr_leg_vals+4)/1000); |
687 | 691 |
|
688 | 692 | total = ret + 5; |
689 | 693 | acc_dbf.use_table(db_handle, &table); |
@@ -937,6 +941,7 @@ int acc_aaa_cdrs(struct dlg_cell *dlg, struct sip_msg *msg, acc_ctx_t* ctx) |
937 | 941 | int offset, av_type; |
938 | 942 | aaa_map *r_stat; |
939 | 943 | int locked = 0; |
| 944 | + uint32_t duration, ms_duration; |
940 | 945 |
|
941 | 946 | struct acc_extra* extra; |
942 | 947 |
|
@@ -980,11 +985,11 @@ int acc_aaa_cdrs(struct dlg_cell *dlg, struct sip_msg *msg, acc_ctx_t* ctx) |
980 | 985 | ADD_AAA_AVPAIR( offset + i, val_arr[i].s, val_arr[i].len ); |
981 | 986 | offset = ret + 2; |
982 | 987 |
|
| 988 | + ms_duration = TIMEVAL_MS_DIFF(start_time, ctx->bye_time); |
| 989 | + duration = ceil((double)ms_duration/1000); |
983 | 990 | /* add duration and setup values */ |
984 | | - av_type = (uint32_t)(ctx->bye_time.tv_sec - start_time.tv_sec); |
985 | | - ADD_AAA_AVPAIR( offset + nr_leg_vals, &av_type, -1); |
986 | | - av_type = (uint32_t)TIMEVAL_MS_DIFF(start_time, ctx->bye_time); |
987 | | - ADD_AAA_AVPAIR( offset + nr_leg_vals + 1, &av_type, -1); |
| 991 | + ADD_AAA_AVPAIR( offset + nr_leg_vals, &duration, -1); |
| 992 | + ADD_AAA_AVPAIR( offset + nr_leg_vals + 1, &ms_duration, -1); |
988 | 993 | av_type = (uint32_t)(start_time.tv_sec - ctx->created); |
989 | 994 | ADD_AAA_AVPAIR( offset + nr_leg_vals + 2, &av_type, -1); |
990 | 995 |
|
@@ -1295,9 +1300,9 @@ int acc_evi_cdrs(struct dlg_cell *dlg, struct sip_msg *msg, acc_ctx_t* ctx) |
1295 | 1300 | { |
1296 | 1301 | int i, ret, res = -1, j; |
1297 | 1302 | int nr_leg_vals; |
1298 | | - int aux_time; |
1299 | 1303 | struct timeval start_time; |
1300 | 1304 | str core_s, leg_s, extra_s; |
| 1305 | + unsigned long duration, ms_duration, setup_duration; |
1301 | 1306 |
|
1302 | 1307 | struct acc_extra* extra; |
1303 | 1308 |
|
@@ -1335,19 +1340,19 @@ int acc_evi_cdrs(struct dlg_cell *dlg, struct sip_msg *msg, acc_ctx_t* ctx) |
1335 | 1340 | goto end; |
1336 | 1341 | } |
1337 | 1342 |
|
1338 | | - aux_time = ctx->bye_time.tv_sec - start_time.tv_sec; |
1339 | | - if (evi_param_set_int(evi_cdr_params[ret+nr_leg_vals+1], &aux_time) < 0) { |
| 1343 | + ms_duration = TIMEVAL_MS_DIFF(start_time, ctx->bye_time); |
| 1344 | + duration = ceil((double)ms_duration/1000); |
| 1345 | + if (evi_param_set_int(evi_cdr_params[ret+nr_leg_vals+1], &duration) < 0) { |
1340 | 1346 | LM_ERR("cannot set duration parameter\n"); |
1341 | 1347 | goto end; |
1342 | 1348 | } |
1343 | 1349 |
|
1344 | | - aux_time = TIMEVAL_MS_DIFF(start_time, ctx->bye_time); |
1345 | | - if (evi_param_set_int(evi_cdr_params[ret+nr_leg_vals+2], &aux_time) < 0) { |
| 1350 | + if (evi_param_set_int(evi_cdr_params[ret+nr_leg_vals+2], &ms_duration) < 0) { |
1346 | 1351 | LM_ERR("cannot set duration parameter\n"); |
1347 | 1352 | goto end; |
1348 | 1353 | } |
1349 | | - aux_time = start_time.tv_sec - ctx->created; |
1350 | | - if (evi_param_set_int(evi_cdr_params[ret+nr_leg_vals+3], &aux_time) < 0) { |
| 1354 | + setup_duration = start_time.tv_sec - ctx->created; |
| 1355 | + if (evi_param_set_int(evi_cdr_params[ret+nr_leg_vals+3], &setup_duration) < 0) { |
1351 | 1356 | LM_ERR("cannot set setuptime parameter\n"); |
1352 | 1357 | goto end; |
1353 | 1358 | } |
|
0 commit comments