Browse code

acc: set again the type of db vals

- work properly when nullable modparam is set and var can be null on
some transactions

Daniel-Constantin Mierla authored on 13/11/2021 19:31:38
Showing 1 changed files
... ...
@@ -466,7 +466,9 @@ int acc_db_request( struct sip_msg *rq)
466 466
 			LM_DBG("attr[%d] is NULL\n", i);
467 467
 			VAL_NULL(db_vals + i) = 1;
468 468
 		} else {
469
-			LM_DBG("attr[%d] is STR\n", i);
469
+			LM_DBG("attr[%d] is STR len=%d\n", i, val_arr[i].len);
470
+			VAL_NULL(db_vals+i) = 0;
471
+			VAL_TYPE(db_vals+i)=DB1_STR;
470 472
 			VAL_STR(db_vals+i) = val_arr[i];
471 473
 		}
472 474
 	}
... ...
@@ -502,6 +504,8 @@ int acc_db_request( struct sip_msg *rq)
502 504
 			if (acc_extra_nullable == 1 && type_arr[i] == TYPE_NULL) {
503 505
 					VAL_NULL(db_vals + i) = 1;
504 506
 				} else {
507
+					VAL_NULL(db_vals+i) = 0;
508
+					VAL_TYPE(db_vals+i)=DB1_STR;
505 509
 					VAL_STR(db_vals+i)=val_arr[i];
506 510
 				}
507 511
 			}
Browse code

acc: simplify index shifting for adding time variants in db accounting

Daniel-Constantin Mierla authored on 11/11/2021 19:39:10
Showing 1 changed files
... ...
@@ -429,18 +429,19 @@ int acc_db_request( struct sip_msg *rq)
429 429
 	for(i=0; i<m; i++)
430 430
 		VAL_STR(db_vals+i) = val_arr[i];
431 431
 	/* time value */
432
-	VAL_TIME(db_vals+(m++)) = acc_env.ts;
432
+	VAL_TIME(db_vals+m) = acc_env.ts;
433
+	m++;
433 434
 	/* extra time value */
434 435
 	if(acc_time_mode==1) {
435
-		VAL_INT(db_vals+(m++)) = (int)acc_env.tv.tv_sec;
436
-		i++;
437
-		VAL_INT(db_vals+(m++)) = (int)acc_env.tv.tv_usec;
438
-		i++;
436
+		VAL_INT(db_vals+m) = (int)acc_env.tv.tv_sec;
437
+		m++;
438
+		VAL_INT(db_vals+m) = (int)acc_env.tv.tv_usec;
439
+		m++;
439 440
 	} else if(acc_time_mode==2) {
440 441
 		dtime = (double)acc_env.tv.tv_usec;
441 442
 		dtime = (dtime / 1000000) + (double)acc_env.tv.tv_sec;
442
-		VAL_DOUBLE(db_vals+(m++)) = dtime;
443
-		i++;
443
+		VAL_DOUBLE(db_vals+m) = dtime;
444
+		m++;
444 445
 	} else if(acc_time_mode==3 || acc_time_mode==4) {
445 446
 		if(acc_time_mode==3) {
446 447
 			localtime_r(&acc_env.ts, &t);
... ...
@@ -451,19 +452,21 @@ int acc_db_request( struct sip_msg *rq)
451 452
 					acc_time_format, &t)<=0) {
452 453
 			acc_time_format_buf[0] = '\0';
453 454
 		}
454
-		VAL_STRING(db_vals+(m++)) = acc_time_format_buf;
455
-		i++;
455
+		VAL_STRING(db_vals+m) = acc_time_format_buf;
456
+		m++;
456 457
 	}
458
+	i = m;
457 459
 
458 460
 	/* extra columns */
459 461
 	o = extra2strar( db_extra, rq, val_arr+m, int_arr+m, type_arr+m);
460 462
 	m += o;
461 463
 
462
-	for( i++ ; i<m; i++) {
464
+	for( ; i<m; i++) {
463 465
 		if (acc_extra_nullable == 1 && type_arr[i] == TYPE_NULL) {
464 466
 			LM_DBG("attr[%d] is NULL\n", i);
465 467
 			VAL_NULL(db_vals + i) = 1;
466 468
 		} else {
469
+			LM_DBG("attr[%d] is STR\n", i);
467 470
 			VAL_STR(db_vals+i) = val_arr[i];
468 471
 		}
469 472
 	}
Browse code

acc: debug messages to print the type of extra acc attrs

Daniel-Constantin Mierla authored on 11/11/2021 11:59:11
Showing 1 changed files
... ...
@@ -461,6 +461,7 @@ int acc_db_request( struct sip_msg *rq)
461 461
 
462 462
 	for( i++ ; i<m; i++) {
463 463
 		if (acc_extra_nullable == 1 && type_arr[i] == TYPE_NULL) {
464
+			LM_DBG("attr[%d] is NULL\n", i);
464 465
 			VAL_NULL(db_vals + i) = 1;
465 466
 		} else {
466 467
 			VAL_STR(db_vals+i) = val_arr[i];
Browse code

acc: increase acc and cdr extra values

Stefan Mititelu authored on 21/10/2021 08:33:59
Showing 1 changed files
... ...
@@ -61,9 +61,9 @@ extern struct acc_extra *db_extra;
61 61
 /* arrays used to collect the values before being
62 62
  * pushed to the storage backend (whatever used)
63 63
  * (3 = datetime + max 2 from time_mode) */
64
-static str val_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
65
-static int int_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
66
-static char type_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
64
+static str *val_arr = NULL;
65
+static int *int_arr = NULL;
66
+static char *type_arr = NULL;
67 67
 
68 68
 #define ACC_TIME_FORMAT_SIZE	128
69 69
 static char acc_time_format_buf[ACC_TIME_FORMAT_SIZE];
... ...
@@ -160,7 +160,7 @@ int core2strar(struct sip_msg *req, str *c_vals, int *i_vals, char *t_vals)
160 160
 /********************************************
161 161
  *        LOG  ACCOUNTING
162 162
  ********************************************/
163
-static str log_attrs[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG];
163
+static str *log_attrs = NULL;
164 164
 
165 165
 #define SET_LOG_ATTR(_n,_atr)  \
166 166
 	do { \
... ...
@@ -309,8 +309,8 @@ int acc_is_db_ready(void)
309 309
 
310 310
 /* caution: keys need to be aligned to core format
311 311
  * (3 = datetime + max 2 from time_mode) */
312
-static db_key_t db_keys[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
313
-static db_val_t db_vals[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
312
+static db_key_t *db_keys = NULL;
313
+static db_val_t *db_vals = NULL;
314 314
 
315 315
 
316 316
 int acc_get_db_handlers(void **vf, void **vh) {
... ...
@@ -624,3 +624,62 @@ void acc_api_set_arrays(acc_info_t *inf)
624 624
 	inf->leg_info = leg_info;
625 625
 }
626 626
 
627
+int acc_arrays_alloc(void) {
628
+	if ((val_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(str))) == NULL) {
629
+		LM_ERR("failed to alloc val_arr\n");
630
+		return -1;
631
+	}
632
+
633
+	if ((int_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(int))) == NULL) {
634
+		LM_ERR("failed to alloc int_arr\n");
635
+		return -1;
636
+	}
637
+
638
+	if ((type_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(char))) == NULL) {
639
+		LM_ERR("failed to alloc type_arr\n");
640
+		return -1;
641
+	}
642
+
643
+	if ((log_attrs = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(str))) == NULL) {
644
+		LM_ERR("failed to alloc log_attrs\n");
645
+		return -1;
646
+	}
647
+
648
+	if ((db_keys = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(db_key_t))) == NULL) {
649
+		LM_ERR("failed to alloc db_keys\n");
650
+		return -1;
651
+	}
652
+
653
+	if ((db_vals = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(db_val_t))) == NULL) {
654
+		LM_ERR("failed to alloc db_vals\n");
655
+		return -1;
656
+	}
657
+
658
+	return 1;
659
+}
660
+
661
+void acc_arrays_free(void) {
662
+	if (val_arr) {
663
+		pkg_free(val_arr);
664
+	}
665
+
666
+	if (int_arr) {
667
+		pkg_free(int_arr);
668
+	}
669
+
670
+	if (type_arr) {
671
+		pkg_free(type_arr);
672
+	}
673
+
674
+	if (log_attrs) {
675
+		pkg_free(log_attrs);
676
+	}
677
+
678
+	if (db_keys) {
679
+		pkg_free(db_keys);
680
+	}
681
+
682
+	if (db_vals) {
683
+		pkg_free(db_vals);
684
+	}
685
+}
Browse code

acc: new parameter acc_extra_nullable

- if set to 1, set NULL db values for varaibles that are $null
- GH #2531

Daniel-Constantin Mierla authored on 03/11/2020 13:55:45
Showing 1 changed files
... ...
@@ -52,6 +52,7 @@ extern struct acc_extra *log_extra;
52 52
 extern struct acc_extra *leg_info;
53 53
 extern struct acc_enviroment acc_env;
54 54
 extern char *acc_time_format;
55
+extern int acc_extra_nullable;
55 56
 
56 57
 static db_func_t acc_dbf;
57 58
 static db1_con_t* db_handle=0;
... ...
@@ -458,8 +459,13 @@ int acc_db_request( struct sip_msg *rq)
458 459
 	o = extra2strar( db_extra, rq, val_arr+m, int_arr+m, type_arr+m);
459 460
 	m += o;
460 461
 
461
-	for( i++ ; i<m; i++)
462
-		VAL_STR(db_vals+i) = val_arr[i];
462
+	for( i++ ; i<m; i++) {
463
+		if (acc_extra_nullable == 1 && type_arr[i] == TYPE_NULL) {
464
+			VAL_NULL(db_vals + i) = 1;
465
+		} else {
466
+			VAL_STR(db_vals+i) = val_arr[i];
467
+		}
468
+	}
463 469
 
464 470
 	if (acc_dbf.use_table(db_handle, &acc_env.text/*table*/) < 0) {
465 471
 		LM_ERR("error in use_table\n");
... ...
@@ -488,8 +494,13 @@ int acc_db_request( struct sip_msg *rq)
488 494
 	} else {
489 495
 		n = legs2strar(leg_info,rq,val_arr+m,int_arr+m,type_arr+m,1);
490 496
 		do {
491
-			for (i=m; i<m+n; i++)
492
-				VAL_STR(db_vals+i)=val_arr[i];
497
+			for (i=m; i<m+n; i++) {
498
+			if (acc_extra_nullable == 1 && type_arr[i] == TYPE_NULL) {
499
+					VAL_NULL(db_vals + i) = 1;
500
+				} else {
501
+					VAL_STR(db_vals+i)=val_arr[i];
502
+				}
503
+			}
493 504
 			if(acc_db_insert_mode==1 && acc_dbf.insert_delayed!=NULL) {
494 505
 				if(acc_dbf.insert_delayed(db_handle,db_keys,db_vals,m+n)<0) {
495 506
 					LM_ERR("failed to insert delayed into database\n");
Browse code

acc: add to-tag for locally generated replies

Julien Chavanton authored on 28/07/2020 23:22:42
Showing 1 changed files
... ...
@@ -123,6 +123,13 @@ int core2strar(struct sip_msg *req, str *c_vals, int *i_vals, char *t_vals)
123 123
 		t_vals[2] = TYPE_NULL;
124 124
 	}
125 125
 
126
+	LM_DBG("default - totag[%.*s]\n", c_vals[2].len, c_vals[2].s);
127
+	if (c_vals[2].len == 0 && acc_env.to_tag.s && acc_env.to_tag.len > 0) {
128
+		LM_DBG("extra [%p] totag[%.*s]\n", acc_env.to_tag.s, acc_env.to_tag.len, acc_env.to_tag.s);
129
+		c_vals[2].len = acc_env.to_tag.len;
130
+		c_vals[2].s = acc_env.to_tag.s;
131
+	}
132
+
126 133
 	/* Callid */
127 134
 	if (req->callid && req->callid->body.len) {
128 135
 		c_vals[3] = req->callid->body;
Browse code

acc: use localtime_r() for a safer multi-thread usage

Victor Seva authored on 12/05/2020 14:11:29
Showing 1 changed files
... ...
@@ -195,7 +195,7 @@ int acc_log_request( struct sip_msg *rq)
195 195
 	int m;
196 196
 	int o;
197 197
 	int i;
198
-	struct tm *t;
198
+	struct tm t;
199 199
 	double dtime;
200 200
 
201 201
 	/* get default values */
... ...
@@ -262,12 +262,12 @@ int acc_log_request( struct sip_msg *rq)
262 262
 				acc_time_attr.s, dtime, log_msg);
263 263
 	} else if(acc_time_mode==3 || acc_time_mode==4) {
264 264
 		if(acc_time_mode==3) {
265
-			t = localtime(&acc_env.ts);
265
+			localtime_r(&acc_env.ts, &t);
266 266
 		} else {
267
-			t = gmtime(&acc_env.ts);
267
+			gmtime_r(&acc_env.ts, &t);
268 268
 		}
269 269
 		if(strftime(acc_time_format_buf, ACC_TIME_FORMAT_SIZE,
270
-					acc_time_format, t)<=0) {
270
+					acc_time_format, &t)<=0) {
271 271
 			acc_time_format_buf[0] = '\0';
272 272
 		}
273 273
 		LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%s%s",
... ...
@@ -412,7 +412,7 @@ int acc_db_request( struct sip_msg *rq)
412 412
 	int n;
413 413
 	int i;
414 414
 	int o;
415
-	struct tm *t;
415
+	struct tm t;
416 416
 	double dtime;
417 417
 
418 418
 	/* formated database columns */
... ...
@@ -435,12 +435,12 @@ int acc_db_request( struct sip_msg *rq)
435 435
 		i++;
436 436
 	} else if(acc_time_mode==3 || acc_time_mode==4) {
437 437
 		if(acc_time_mode==3) {
438
-			t = localtime(&acc_env.ts);
438
+			localtime_r(&acc_env.ts, &t);
439 439
 		} else {
440
-			t = gmtime(&acc_env.ts);
440
+			gmtime_r(&acc_env.ts, &t);
441 441
 		}
442 442
 		if(strftime(acc_time_format_buf, ACC_TIME_FORMAT_SIZE,
443
-					acc_time_format, t)<=0) {
443
+					acc_time_format, &t)<=0) {
444 444
 			acc_time_format_buf[0] = '\0';
445 445
 		}
446 446
 		VAL_STRING(db_vals+(m++)) = acc_time_format_buf;
Browse code

acc: fix generating duplicates for missed calls

- fix generating duplicates for missed calls (#GH1674)
- patch from Julien Chavanton jchavanton at gmail dot com

Henning Westerholt authored on 01/11/2018 20:21:28
Showing 1 changed files
... ...
@@ -526,7 +526,7 @@ int is_eng_acc_on(sip_msg_t *msg)
526 526
 	}
527 527
 	while(e) {
528 528
 		if(e->flags & 1) {
529
-			if(msg->flags & e->acc_flag) {
529
+			if(isflagset(msg, e->acc_flag) == 1) {
530 530
 				return 1;
531 531
 			}
532 532
 		}
... ...
@@ -549,7 +549,7 @@ int is_eng_mc_on(sip_msg_t *msg)
549 549
 	}
550 550
 	while(e) {
551 551
 		if(e->flags & 1) {
552
-			if(msg->flags & e->missed_flag) {
552
+			if(isflagset(msg, e->missed_flag) == 1) {
553 553
 				return 1;
554 554
 			}
555 555
 		}
... ...
@@ -579,15 +579,15 @@ int acc_run_engines(struct sip_msg *msg, int type, int *reset)
579 579
 	inf.leg_info = leg_info;
580 580
 	while(e) {
581 581
 		if(e->flags & 1) {
582
-			if((type==0) && (msg->flags&(e->acc_flag))) {
582
+			if((type==0) && isflagset(msg, e->acc_flag) == 1) {
583 583
 				LM_DBG("acc event for engine: %s\n", e->name);
584 584
 				e->acc_req(msg, &inf);
585
-				if(reset) *reset |= e->acc_flag;
585
+				if(reset) *reset |= 1 << e->acc_flag;
586 586
 			}
587
-			if((type==1) && (msg->flags&(e->missed_flag))) {
587
+			if((type==1) && isflagset(msg, e->missed_flag) == 1) {
588 588
 				LM_DBG("missed event for engine: %s\n", e->name);
589 589
 				e->acc_req(msg, &inf);
590
-				if(reset) *reset |= e->missed_flag;
590
+				if(reset) *reset |= 1 << e->missed_flag;
591 591
 			}
592 592
 		}
593 593
 		e = e->next;
Browse code

acc: check if async task workers are active before doing async insert

Daniel-Constantin Mierla authored on 12/11/2017 11:08:02
Showing 1 changed files
... ...
@@ -35,6 +35,7 @@
35 35
 #include "../../core/error.h"
36 36
 #include "../../core/mem/mem.h"
37 37
 #include "../../core/usr_avp.h"
38
+#include "../../core/async_task.h"
38 39
 #include "../../lib/srdb1/db.h"
39 40
 #include "../../core/parser/hf.h"
40 41
 #include "../../core/parser/msg_parser.h"
... ...
@@ -465,7 +466,8 @@ int acc_db_request( struct sip_msg *rq)
465 466
 				LM_ERR("failed to insert delayed into database\n");
466 467
 				goto error;
467 468
 			}
468
-		} else if(acc_db_insert_mode==2 && acc_dbf.insert_async!=NULL) {
469
+		} else if(acc_db_insert_mode==2 && acc_dbf.insert_async!=NULL
470
+				&& async_task_workers_active()) {
469 471
 			if (acc_dbf.insert_async(db_handle, db_keys, db_vals, m) < 0) {
470 472
 				LM_ERR("failed to insert async into database\n");
471 473
 				goto error;
Browse code

acc: allow accounting only for external accounting engine

- have accounting via external engines without a need to have log flag set

Daniel-Constantin Mierla authored on 31/10/2017 11:31:26
Showing 1 changed files
... ...
@@ -510,6 +510,52 @@ error:
510 510
 	return -1;
511 511
 }
512 512
 
513
+/**
514
+ * @brief test if acc flag from enternal engines is set
515
+ */
516
+int is_eng_acc_on(sip_msg_t *msg)
517
+{
518
+	acc_engine_t *e;
519
+
520
+	e = acc_api_get_engines();
521
+
522
+	if(e==NULL) {
523
+		return 0;
524
+	}
525
+	while(e) {
526
+		if(e->flags & 1) {
527
+			if(msg->flags & e->acc_flag) {
528
+				return 1;
529
+			}
530
+		}
531
+		e = e->next;
532
+	}
533
+	return 0;
534
+}
535
+
536
+/**
537
+ * @brief test if acc flag from enternal engines is set
538
+ */
539
+int is_eng_mc_on(sip_msg_t *msg)
540
+{
541
+	acc_engine_t *e;
542
+
543
+	e = acc_api_get_engines();
544
+
545
+	if(e==NULL) {
546
+		return 0;
547
+	}
548
+	while(e) {
549
+		if(e->flags & 1) {
550
+			if(msg->flags & e->missed_flag) {
551
+				return 1;
552
+			}
553
+		}
554
+		e = e->next;
555
+	}
556
+	return 0;
557
+}
558
+
513 559
 /**
514 560
  * @brief execute all acc engines for a SIP request event
515 561
  */
Browse code

acc: relocated the code related to diameter accounting to acc_diameter

Daniel-Constantin Mierla authored on 09/08/2017 13:28:25
Showing 1 changed files
... ...
@@ -47,23 +47,11 @@
47 47
 #include "acc_logic.h"
48 48
 #include "acc_api.h"
49 49
 
50
-#ifdef DIAM_ACC
51
-#include "diam_dict.h"
52
-#include "diam_message.h"
53
-#include "diam_tcp.h"
54
-#endif
55
-
56 50
 extern struct acc_extra *log_extra;
57 51
 extern struct acc_extra *leg_info;
58 52
 extern struct acc_enviroment acc_env;
59 53
 extern char *acc_time_format;
60 54
 
61
-#ifdef DIAM_ACC
62
-extern char *diameter_client_host;
63
-extern int diameter_client_port;
64
-extern struct acc_extra *dia_extra;
65
-#endif
66
-
67 55
 static db_func_t acc_dbf;
68 56
 static db1_con_t* db_handle=0;
69 57
 extern struct acc_extra *db_extra;
... ...
@@ -111,7 +99,7 @@ int core2strar(struct sip_msg *req, str *c_vals, int *i_vals, char *t_vals)
111 99
 	/* from/to URI and TAG */
112 100
 	if (req->msg_flags&FL_REQ_UPSTREAM) {
113 101
 		LM_DBG("the flag UPSTREAM is set -> swap F/T\n"); \
114
-		from = acc_env.to;
102
+			from = acc_env.to;
115 103
 		to = req->from;
116 104
 	} else {
117 105
 		from = req->from;
... ...
@@ -252,8 +240,8 @@ int acc_log_request( struct sip_msg *rq)
252 240
 				}
253 241
 			}
254 242
 		} while (p!=log_msg_end && (n=legs2strar(leg_info,rq,val_arr+m,
255
-							int_arr+m,type_arr+m,
256
-							0))!=0);
243
+						int_arr+m,type_arr+m,
244
+						0))!=0);
257 245
 	}
258 246
 
259 247
 	/* terminating line */
... ...
@@ -262,15 +250,15 @@ int acc_log_request( struct sip_msg *rq)
262 250
 
263 251
 	if(acc_time_mode==1) {
264 252
 		LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%u%s",
265
-			acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
266
-			acc_time_exten.s, (unsigned int)acc_env.tv.tv_usec,
267
-			log_msg);
253
+				acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
254
+				acc_time_exten.s, (unsigned int)acc_env.tv.tv_usec,
255
+				log_msg);
268 256
 	} else if(acc_time_mode==2) {
269 257
 		dtime = (double)acc_env.tv.tv_usec;
270 258
 		dtime = (dtime / 1000000) + (double)acc_env.tv.tv_sec;
271 259
 		LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%.3f%s",
272
-			acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
273
-			acc_time_attr.s, dtime, log_msg);
260
+				acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
261
+				acc_time_attr.s, dtime, log_msg);
274 262
 	} else if(acc_time_mode==3 || acc_time_mode==4) {
275 263
 		if(acc_time_mode==3) {
276 264
 			t = localtime(&acc_env.ts);
... ...
@@ -282,14 +270,14 @@ int acc_log_request( struct sip_msg *rq)
282 270
 			acc_time_format_buf[0] = '\0';
283 271
 		}
284 272
 		LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%s%s",
285
-			acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
286
-			acc_time_attr.s,
287
-			acc_time_format_buf,
288
-			log_msg);
273
+				acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
274
+				acc_time_attr.s,
275
+				acc_time_format_buf,
276
+				log_msg);
289 277
 	} else {
290 278
 		LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu%s",
291
-			acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
292
-			log_msg);
279
+				acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
280
+				log_msg);
293 281
 	}
294 282
 	/* free memory allocated by extra2strar */
295 283
 	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
... ...
@@ -510,7 +498,7 @@ int acc_db_request( struct sip_msg *rq)
510 498
 				}
511 499
 			}
512 500
 		}while ( (n=legs2strar(leg_info,rq,val_arr+m,int_arr+m,
513
-				       type_arr+m,0))!=0 );
501
+						type_arr+m,0))!=0 );
514 502
 	}
515 503
 
516 504
 	/* free memory allocated by extra2strar */
... ...
@@ -522,266 +510,6 @@ error:
522 510
 	return -1;
523 511
 }
524 512
 
525
-
526
-/************ RADIUS & DIAMETER helper functions **************/
527
-#if defined (DIAM_ACC)
528
-#ifndef UINT4
529
-#define UINT4 uint32_t
530
-#endif
531
-inline static UINT4 phrase2code(str *phrase)
532
-{
533
-	UINT4 code;
534
-	int i;
535
-
536
-	if (phrase->len<3) return 0;
537
-	code=0;
538
-	for (i=0;i<3;i++) {
539
-		if (!(phrase->s[i]>='0' && phrase->s[i]<'9'))
540
-				return 0;
541
-		code=code*10+phrase->s[i]-'0';
542
-	}
543
-	return code;
544
-}
545
-#endif
546
-
547
-
548
-
549
-/********************************************
550
- *        DIAMETER  ACCOUNTING
551
- ********************************************/
552
-#ifdef DIAM_ACC
553
-
554
-#define AA_REQUEST 265
555
-#define AA_ANSWER  265
556
-
557
-#define ACCOUNTING_REQUEST 271
558
-#define ACCOUNTING_ANSWER  271
559
-
560
-static int diam_attrs[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG];
561
-
562
-int acc_diam_init()
563
-{
564
-	int n;
565
-	int m;
566
-
567
-	n = 0;
568
-	/* caution: keep these aligned to core acc output */
569
-	diam_attrs[n++] = AVP_SIP_METHOD;
570
-	diam_attrs[n++] = AVP_SIP_FROM_TAG;
571
-	diam_attrs[n++] = AVP_SIP_TO_TAG;
572
-	diam_attrs[n++] = AVP_SIP_CALLID;
573
-	diam_attrs[n++] = AVP_SIP_STATUS;
574
-
575
-	m = extra2int( dia_extra, diam_attrs+n);
576
-	if (m<0) {
577
-		LM_ERR("extra names for DIAMETER must be integer AVP codes\n");
578
-		return -1;
579
-	}
580
-	n += m;
581
-
582
-	m = extra2int( leg_info, diam_attrs+n);
583
-	if (m<0) {
584
-		LM_ERR("leg info names for DIAMTER must be integer AVP codes\n");
585
-		return -1;
586
-	}
587
-	n += m;
588
-
589
-	return 0;
590
-}
591
-
592
-
593
-inline unsigned long diam_status(struct sip_msg *rq, int code)
594
-{
595
-	if ((rq->REQ_METHOD==METHOD_INVITE || rq->REQ_METHOD==METHOD_ACK)
596
-				&& code>=200 && code<300) 
597
-		return AAA_ACCT_START;
598
-
599
-	if ((rq->REQ_METHOD==METHOD_BYE || rq->REQ_METHOD==METHOD_CANCEL))
600
-		return AAA_ACCT_STOP;
601
-
602
-	if (code>=200 && code <=300)  
603
-		return AAA_ACCT_EVENT;
604
-
605
-	return -1;
606
-}
607
-
608
-
609
-int acc_diam_request( struct sip_msg *req )
610
-{
611
-	int attr_cnt;
612
-	int cnt;
613
-	AAAMessage *send = NULL;
614
-	AAA_AVP *avp;
615
-	struct sip_uri puri;
616
-	str *uri;
617
-	int ret;
618
-	int i;
619
-	int status;
620
-	char tmp[2];
621
-	unsigned int mid;
622
-	int m;
623
-	int o;
624
-
625
-	attr_cnt = core2strar( req, val_arr, int_arr, type_arr );
626
-	/* last value is not used */
627
-	attr_cnt--;
628
-
629
-	if ( (send=AAAInMessage(ACCOUNTING_REQUEST, AAA_APP_NASREQ))==NULL) {
630
-		LM_ERR("failed to create new AAA request\n");
631
-		return -1;
632
-	}
633
-
634
-	m = 0;
635
-	o = 0;
636
-	/* AVP_ACCOUNTIG_RECORD_TYPE */
637
-	if( (status = diam_status(req, acc_env.code))<0) {
638
-		LM_ERR("status unknown\n");
639
-		goto error;
640
-	}
641
-	tmp[0] = status+'0';
642
-	tmp[1] = 0;
643
-	if( (avp=AAACreateAVP(AVP_Accounting_Record_Type, 0, 0, tmp,
644
-	1, AVP_DUPLICATE_DATA)) == 0) {
645
-		LM_ERR("failed to create AVP:no more free memory!\n");
646
-		goto error;
647
-	}
648
-	if( AAAAddAVPToMessage(send, avp, 0)!= AAA_ERR_SUCCESS) {
649
-		LM_ERR("avp not added \n");
650
-		AAAFreeAVP(&avp);
651
-		goto error;
652
-	}
653
-	/* SIP_MSGID AVP */
654
-	mid = req->id;
655
-	if( (avp=AAACreateAVP(AVP_SIP_MSGID, 0, 0, (char*)(&mid), 
656
-	sizeof(mid), AVP_DUPLICATE_DATA)) == 0) {
657
-		LM_ERR("failed to create AVP:no more free memory!\n");
658
-		goto error;
659
-	}
660
-	if( AAAAddAVPToMessage(send, avp, 0)!= AAA_ERR_SUCCESS) {
661
-		LM_ERR("avp not added \n");
662
-		AAAFreeAVP(&avp);
663
-		goto error;
664
-	}
665
-
666
-	/* SIP Service AVP */
667
-	if( (avp=AAACreateAVP(AVP_Service_Type, 0, 0, SIP_ACCOUNTING, 
668
-	SERVICE_LEN, AVP_DUPLICATE_DATA)) == 0) {
669
-		LM_ERR("failed to create AVP:no more free memory!\n");
670
-		goto error;
671
-	}
672
-	if( AAAAddAVPToMessage(send, avp, 0)!= AAA_ERR_SUCCESS) {
673
-		LM_ERR("avp not added \n");
674
-		AAAFreeAVP(&avp);
675
-		goto error;
676
-	}
677
-
678
-	/* also the extra attributes */
679
-	o = extra2strar( dia_extra, req, val_arr, int_arr, type_arr);
680
-	attr_cnt += o;
681
-	m = attr_cnt;
682
-
683
-	/* add attributes */
684
-	for(i=0; i<attr_cnt; i++) {
685
-		if((avp=AAACreateAVP(diam_attrs[i], 0,0, val_arr[i].s, val_arr[i].len,
686
-		AVP_DUPLICATE_DATA)) == 0) {
687
-			LM_ERR("failed to create AVP: no more free memory!\n");
688
-			goto error;
689
-		}
690
-		if( AAAAddAVPToMessage(send, avp, 0)!= AAA_ERR_SUCCESS) {
691
-			LM_ERR("avp not added \n");
692
-			AAAFreeAVP(&avp);
693
-			goto error;
694
-		}
695
-	}
696
-
697
-	/* and the leg attributes */
698
-	if ( leg_info ) {
699
-	        cnt = legs2strar(leg_info,req,val_arr,int_arr,type_arr,1);
700
-		do {
701
-			for (i=0; i<cnt; i++) {
702
-				if((avp=AAACreateAVP(diam_attrs[attr_cnt+i], 0, 0,
703
-				val_arr[i].s, val_arr[i].len, AVP_DUPLICATE_DATA)) == 0) {
704
-					LM_ERR("failed to create AVP: no more free memory!\n");
705
-					goto error;
706
-				}
707
-				if( AAAAddAVPToMessage(send, avp, 0)!= AAA_ERR_SUCCESS) {
708
-					LM_ERR("avp not added \n");
709
-					AAAFreeAVP(&avp);
710
-					goto error;
711
-				}
712
-			}
713
-		} while ( (cnt=legs2strar(leg_info,req,val_arr,int_arr,
714
-					  type_arr,0))!=0 );
715
-	}
716
-
717
-	if (get_uri(req, &uri) < 0) {
718
-		LM_ERR("failed to get uri, From/To URI not found\n");
719
-		goto error;
720
-	}
721
-
722
-	if (parse_uri(uri->s, uri->len, &puri) < 0) {
723
-		LM_ERR("failed to parse From/To URI\n");
724
-		goto error;
725
-	}
726
-
727
-	/* Destination-Realm AVP */
728
-	if( (avp=AAACreateAVP(AVP_Destination_Realm, 0, 0, puri.host.s,
729
-	puri.host.len, AVP_DUPLICATE_DATA)) == 0) {
730
-		LM_ERR("failed to create AVP:no more free memory!\n");
731
-		goto error;
732
-	}
733
-
734
-	if( AAAAddAVPToMessage(send, avp, 0)!= AAA_ERR_SUCCESS) {
735
-		LM_ERR("avp not added \n");
736
-		AAAFreeAVP(&avp);
737
-		goto error;
738
-	}
739
-
740
-	/* prepare the message to be sent over the network */
741
-	if(AAABuildMsgBuffer(send) != AAA_ERR_SUCCESS) {
742
-		LM_ERR("message buffer not created\n");
743
-		goto error;
744
-	}
745
-
746
-	if(sockfd==AAA_NO_CONNECTION) {
747
-		sockfd = init_mytcp(diameter_client_host, diameter_client_port);
748
-		if(sockfd==AAA_NO_CONNECTION) {
749
-			LM_ERR("failed to reconnect to Diameter client\n");
750
-			goto error;
751
-		}
752
-	}
753
-
754
-	/* send the message to the DIAMETER client */
755
-	ret = tcp_send_recv(sockfd, send->buf.s, send->buf.len, rb, req->id);
756
-	if(ret == AAA_CONN_CLOSED) {
757
-		LM_NOTICE("connection to Diameter client closed.It will be "
758
-				"reopened by the next request\n");
759
-		close(sockfd);
760
-		sockfd = AAA_NO_CONNECTION;
761
-		goto error;
762
-	}
763
-
764
-	if(ret != ACC_SUCCESS) {
765
-		/* a transmission error occurred */
766
-		LM_ERR("message sending to the DIAMETER backend authorization "
767
-				"server failed\n");
768
-		goto error;
769
-	}
770
-
771
-	AAAFreeMessage(&send);
772
-	/* free memory allocated by extra2strar */
773
-	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
774
-	return 1;
775
-
776
-error:
777
-	AAAFreeMessage(&send);
778
-	/* free memory allocated by extra2strar */
779
-	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
780
-	return -1;
781
-}
782
-
783
-#endif
784
-
785 513
 /**
786 514
  * @brief execute all acc engines for a SIP request event
787 515
  */
Browse code

acc: removed define for SQL_ACC

- it was enabled for more than 10 years and the module links to
lib/srdb1 anyhow

Daniel-Constantin Mierla authored on 09/08/2017 11:37:20
Showing 1 changed files
... ...
@@ -64,11 +64,9 @@ extern int diameter_client_port;
64 64
 extern struct acc_extra *dia_extra;
65 65
 #endif
66 66
 
67
-#ifdef SQL_ACC
68 67
 static db_func_t acc_dbf;
69 68
 static db1_con_t* db_handle=0;
70 69
 extern struct acc_extra *db_extra;
71
-#endif
72 70
 
73 71
 /* arrays used to collect the values before being
74 72
  * pushed to the storage backend (whatever used)
... ...
@@ -306,16 +304,12 @@ int acc_log_request( struct sip_msg *rq)
306 304
 
307 305
 int acc_is_db_ready(void)
308 306
 {
309
-#ifdef SQL_ACC
310 307
 	if(db_handle!=0)
311 308
 		return 1;
312
-#endif
313 309
 
314 310
 	return 0;
315 311
 }
316 312
 
317
-#ifdef SQL_ACC
318
-
319 313
 /* caution: keys need to be aligned to core format
320 314
  * (3 = datetime + max 2 from time_mode) */
321 315
 static db_key_t db_keys[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
... ...
@@ -528,8 +522,6 @@ error:
528 522
 	return -1;
529 523
 }
530 524
 
531
-#endif
532
-
533 525
 
534 526
 /************ RADIUS & DIAMETER helper functions **************/
535 527
 #if defined (DIAM_ACC)
Browse code

acc: added acc_request(reason, table)

- wrapper around acc_log_request() and acc_db_request(), writting acc
record to log and db backend (if db_url is set)

Daniel-Constantin Mierla authored on 09/08/2017 06:59:00
Showing 1 changed files
... ...
@@ -304,6 +304,16 @@ int acc_log_request( struct sip_msg *rq)
304 304
  *        SQL  ACCOUNTING
305 305
  ********************************************/
306 306
 
307
+int acc_is_db_ready(void)
308
+{
309
+#ifdef SQL_ACC
310
+	if(db_handle!=0)
311
+		return 1;
312
+#endif
313
+
314
+	return 0;
315
+}
316
+
307 317
 #ifdef SQL_ACC
308 318
 
309 319
 /* caution: keys need to be aligned to core format
Browse code

acc Remove radius support code (now in separate module - acc_radius.so)

Olle E. Johansson authored on 02/01/2017 20:07:38
Showing 1 changed files
... ...
@@ -47,10 +47,6 @@
47 47
 #include "acc_logic.h"
48 48
 #include "acc_api.h"
49 49
 
50
-#ifdef RAD_ACC
51
-#include "../misc_radius/radius.h"
52
-#endif
53
-
54 50
 #ifdef DIAM_ACC
55 51
 #include "diam_dict.h"
56 52
 #include "diam_message.h"
... ...
@@ -62,10 +58,6 @@ extern struct acc_extra *leg_info;
62 58
 extern struct acc_enviroment acc_env;
63 59
 extern char *acc_time_format;
64 60
 
65
-#ifdef RAD_ACC
66
-extern struct acc_extra *rad_extra;
67
-#endif
68
-
69 61
 #ifdef DIAM_ACC
70 62
 extern char *diameter_client_host;
71 63
 extern int diameter_client_port;
... ...
@@ -530,7 +522,7 @@ error:
530 522
 
531 523
 
532 524
 /************ RADIUS & DIAMETER helper functions **************/
533
-#if defined(RAD_ACC) || defined (DIAM_ACC)
525
+#if defined (DIAM_ACC)
534 526
 #ifndef UINT4
535 527
 #define UINT4 uint32_t
536 528
 #endif
... ...
@@ -551,176 +543,6 @@ inline static UINT4 phrase2code(str *phrase)
551 543
 #endif
552 544
 
553 545
 
554
-/********************************************
555
- *        RADIUS  ACCOUNTING
556
- ********************************************/
557
-#ifdef RAD_ACC
558
-enum { RA_ACCT_STATUS_TYPE=0, RA_SERVICE_TYPE, RA_SIP_RESPONSE_CODE,
559
-	RA_SIP_METHOD, RA_TIME_STAMP, RA_STATIC_MAX};
560
-enum {RV_STATUS_START=0, RV_STATUS_STOP, RV_STATUS_ALIVE, RV_STATUS_FAILED,
561
-	RV_SIP_SESSION, RV_STATIC_MAX};
562
-static struct attr
563
-	rd_attrs[RA_STATIC_MAX+ACC_CORE_LEN-2+MAX_ACC_EXTRA+MAX_ACC_LEG];
564
-static struct val rd_vals[RV_STATIC_MAX];
565
-
566
-int init_acc_rad(char *rad_cfg, int srv_type)
567
-{
568
-	int n;
569
-
570
-	memset(rd_attrs, 0, sizeof(rd_attrs));
571
-	memset(rd_vals, 0, sizeof(rd_vals));
572
-	rd_attrs[RA_ACCT_STATUS_TYPE].n  = "Acct-Status-Type";
573
-	rd_attrs[RA_SERVICE_TYPE].n      = "Service-Type";
574
-	rd_attrs[RA_SIP_RESPONSE_CODE].n = "Sip-Response-Code";
575
-	rd_attrs[RA_SIP_METHOD].n        = "Sip-Method";
576
-	rd_attrs[RA_TIME_STAMP].n        = "Event-Timestamp";
577
-	n = RA_STATIC_MAX;
578
-	/* caution: keep these aligned to core acc output */
579
-	rd_attrs[n++].n                  = "Sip-From-Tag";
580
-	rd_attrs[n++].n                  = "Sip-To-Tag";
581
-	rd_attrs[n++].n                  = "Acct-Session-Id";
582
-
583
-	rd_vals[RV_STATUS_START].n        = "Start";
584
-	rd_vals[RV_STATUS_STOP].n         = "Stop";
585
-	rd_vals[RV_STATUS_ALIVE].n        = "Alive";
586
-	rd_vals[RV_STATUS_FAILED].n       = "Failed";
587
-	rd_vals[RV_SIP_SESSION].n         = "Sip-Session";
588
-
589
-	/* add and count the extras as attributes */
590
-	n += extra2attrs( rad_extra, rd_attrs, n);
591
-	/* add and count the legs as attributes */
592
-	n += extra2attrs( leg_info, rd_attrs, n);
593
-
594
-	/* read config */
595
-	if ((rh = rc_read_config(rad_cfg)) == NULL) {
596
-		LM_ERR("failed to open radius config file: %s\n", rad_cfg );
597
-		return -1;
598
-	}
599
-	/* read dictionary */
600
-	if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))!=0) {
601
-		LM_ERR("failed to read radius dictionary\n");
602
-		return -1;
603
-	}
604
-
605
-	INIT_AV(rh, rd_attrs, n, rd_vals, RV_STATIC_MAX, "acc", -1, -1);
606
-
607
-	if (srv_type != -1)
608
-		rd_vals[RV_SIP_SESSION].v = srv_type;
609
-
610
-	return 0;
611
-}
612
-
613
-
614
-static inline UINT4 rad_status( struct sip_msg *req, int code )
615
-{
616