~ubuntu-branches/debian/sid/kamailio/sid

« back to all changes in this revision

Viewing changes to modules/acc/acc.c

  • Committer: Package Import Robot
  • Author(s): Victor Seva
  • Date: 2014-01-06 11:47:13 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140106114713-t8xidp4arzrnyeya
Tags: 4.1.1-1
* New upstream release
* debian/patches:
  - add upstream fixes
* Added tls outbound websocket autheph dnssec modules
  - openssl exception added to their license
* removing sparc and ia64 from supported archs
  for mono module (Closes: #728915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
extern struct acc_extra *log_extra;
76
76
extern struct acc_extra *leg_info;
77
77
extern struct acc_enviroment acc_env;
 
78
extern char *acc_time_format;
78
79
 
79
80
#ifdef RAD_ACC
80
81
extern struct acc_extra *rad_extra;
90
91
static db_func_t acc_dbf;
91
92
static db1_con_t* db_handle=0;
92
93
extern struct acc_extra *db_extra;
93
 
extern int acc_db_insert_mode;
94
94
#endif
95
95
 
96
96
/* arrays used to collect the values before being
97
 
 * pushed to the storage backend (whatever used) */
98
 
static str val_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG];
99
 
static int int_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG];
100
 
static char type_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG];
 
97
 * pushed to the storage backend (whatever used)
 
98
 * (3 = datetime + max 2 from time_mode) */
 
99
static str val_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
 
100
static int int_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
 
101
static char type_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
 
102
 
 
103
#define ACC_TIME_FORMAT_SIZE    128
 
104
static char acc_time_format_buf[ACC_TIME_FORMAT_SIZE];
101
105
 
102
106
/********************************************
103
107
 *        acc CORE function
173
177
        c_vals[5] = acc_env.reason;
174
178
        t_vals[5] = TYPE_STR;
175
179
 
176
 
        acc_env.ts = time(NULL);
 
180
        gettimeofday(&acc_env.tv, NULL);
 
181
        acc_env.ts = acc_env.tv.tv_sec;
 
182
 
177
183
        return ACC_CORE_LEN;
178
184
}
179
185
 
224
230
        int n;
225
231
        int m;
226
232
        int i;
 
233
        struct tm *t;
227
234
 
228
235
        /* get default values */
229
236
        m = core2strar( rq, val_arr, int_arr, type_arr);
275
282
        *(p++) = '\n';
276
283
        *(p++) = 0;
277
284
 
278
 
        LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu%s",
279
 
                acc_env.text.len, acc_env.text.s,(unsigned long) acc_env.ts, log_msg);
 
285
        if(acc_time_mode==1) {
 
286
                LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%u%s",
 
287
                        acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
 
288
                        acc_time_exten.s, (unsigned int)acc_env.tv.tv_usec,
 
289
                        log_msg);
 
290
        } else if(acc_time_mode==2) {
 
291
                LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%.3f%s",
 
292
                        acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
 
293
                        acc_time_attr.s,
 
294
                        (((double)(acc_env.tv.tv_sec * 1000)
 
295
                                                        + (acc_env.tv.tv_usec / 1000)) / 1000),
 
296
                        log_msg);
 
297
        } else if(acc_time_mode==3 || acc_time_mode==4) {
 
298
                if(acc_time_mode==3) {
 
299
                        t = localtime(&acc_env.ts);
 
300
                } else {
 
301
                        t = gmtime(&acc_env.ts);
 
302
                }
 
303
                if(strftime(acc_time_format_buf, ACC_TIME_FORMAT_SIZE,
 
304
                                        acc_time_format, t)<=0) {
 
305
                        acc_time_format_buf[0] = '\0';
 
306
                }
 
307
                LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%s%s",
 
308
                        acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
 
309
                        acc_time_attr.s,
 
310
                        acc_time_format_buf,
 
311
                        log_msg);
 
312
        } else {
 
313
                LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu%s",
 
314
                        acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
 
315
                        log_msg);
 
316
        }
280
317
 
281
318
        return 1;
282
319
}
288
325
 
289
326
#ifdef SQL_ACC
290
327
 
291
 
/* caution: keys need to be aligned to core format */
292
 
static db_key_t db_keys[ACC_CORE_LEN+1+MAX_ACC_EXTRA+MAX_ACC_LEG];
293
 
static db_val_t db_vals[ACC_CORE_LEN+1+MAX_ACC_EXTRA+MAX_ACC_LEG];
294
 
 
 
328
/* caution: keys need to be aligned to core format
 
329
 * (3 = datetime + max 2 from time_mode) */
 
330
static db_key_t db_keys[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
 
331
static db_val_t db_vals[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
 
332
 
 
333
 
 
334
int acc_get_db_handlers(void **vf, void **vh) {
 
335
        if(db_handle==0)
 
336
                return -1;
 
337
        *vf = (void*)&acc_dbf;
 
338
        *vh = (void*)db_handle;
 
339
        return 0;
 
340
}
295
341
 
296
342
static void acc_db_init_keys(void)
297
343
{
311
357
        db_keys[n++] = &acc_sipreason_col;
312
358
        db_keys[n++] = &acc_time_col;
313
359
        time_idx = n-1;
 
360
        if(acc_time_mode==1 || acc_time_mode==2
 
361
                        || acc_time_mode==3 || acc_time_mode==4) {
 
362
                db_keys[n++] = &acc_time_attr;
 
363
                if(acc_time_mode==1) {
 
364
                        db_keys[n++] = &acc_time_exten;
 
365
                }
 
366
        }
314
367
 
315
368
        /* init the extra db keys */
316
369
        for(extra=db_extra; extra ; extra=extra->next)
326
379
                VAL_NULL(db_vals+i)=0;
327
380
        }
328
381
        VAL_TYPE(db_vals+time_idx)=DB1_DATETIME;
 
382
        if(acc_time_mode==1) {
 
383
                VAL_TYPE(db_vals+time_idx+1)=DB1_INT;
 
384
                VAL_TYPE(db_vals+time_idx+2)=DB1_INT;
 
385
        } else if(acc_time_mode==2) {
 
386
                VAL_TYPE(db_vals+time_idx+1)=DB1_DOUBLE;
 
387
        } else if(acc_time_mode==3 || acc_time_mode==4) {
 
388
                VAL_TYPE(db_vals+time_idx+1)=DB1_STRING;
 
389
        }
329
390
}
330
391
 
331
392
 
376
437
        int m;
377
438
        int n;
378
439
        int i;
 
440
        struct tm *t;
379
441
 
380
442
        /* formated database columns */
381
443
        m = core2strar( rq, val_arr, int_arr, type_arr );
384
446
                VAL_STR(db_vals+i) = val_arr[i];
385
447
        /* time value */
386
448
        VAL_TIME(db_vals+(m++)) = acc_env.ts;
 
449
        /* extra time value */
 
450
        if(acc_time_mode==1) {
 
451
                VAL_INT(db_vals+(m++)) = (int)acc_env.tv.tv_sec;
 
452
                i++;
 
453
                VAL_INT(db_vals+(m++)) = (int)acc_env.tv.tv_usec;
 
454
                i++;
 
455
        } else if(acc_time_mode==2) {
 
456
                VAL_DOUBLE(db_vals+(m++)) = ((double)(acc_env.tv.tv_sec * 1000)
 
457
                                                        + (acc_env.tv.tv_usec / 1000)) / 1000;
 
458
                i++;
 
459
        } else if(acc_time_mode==3 || acc_time_mode==4) {
 
460
                if(acc_time_mode==3) {
 
461
                        t = localtime(&acc_env.ts);
 
462
                } else {
 
463
                        t = gmtime(&acc_env.ts);
 
464
                }
 
465
                if(strftime(acc_time_format_buf, ACC_TIME_FORMAT_SIZE,
 
466
                                        acc_time_format, t)<=0) {
 
467
                        acc_time_format_buf[0] = '\0';
 
468
                }
 
469
                VAL_STRING(db_vals+(m++)) = acc_time_format_buf;
 
470
                i++;
 
471
        }
387
472
 
388
473
        /* extra columns */
389
474
        m += extra2strar( db_extra, rq, val_arr+m, int_arr+m, type_arr+m);