Browse code

siptrace: helper function for db insert

Daniel-Constantin Mierla authored on 10/04/2020 08:01:12
Showing 1 changed files
... ...
@@ -567,6 +567,24 @@ static int sip_trace_store(siptrace_data_t *sto, dest_info_t *dst,
567 567
 	return ret;
568 568
 }
569 569
 
570
+static int sip_trace_insert_db(db_key_t *db_keys, db_val_t *db_vals,
571
+		int db_nkeys, char *dtext)
572
+{
573
+	LM_DBG("storing info - %s\n", dtext);
574
+	if(trace_delayed != 0 && db_funcs.insert_delayed != NULL) {
575
+		if(db_funcs.insert_delayed(db_con, db_keys, db_vals, db_nkeys) < 0) {
576
+			LM_ERR("error storing trace - %s\n", dtext);
577
+			return -1;
578
+		}
579
+	} else {
580
+		if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) {
581
+			LM_ERR("error storing trace - %s\n", dtext);
582
+			return -1;
583
+		}
584
+	}
585
+	return 0;
586
+}
587
+
570 588
 static int sip_trace_store_db(siptrace_data_t *sto)
571 589
 {
572 590
 	if((trace_to_database == 0) && ((_siptrace_mode & SIPTRACE_MODE_DB) == 0)) {
... ...
@@ -646,17 +664,8 @@ static int sip_trace_store_db(siptrace_data_t *sto)
646 664
 		db_vals[9].val.str_val.s = "";
647 665
 		db_vals[9].val.str_val.len = 0;
648 666
 
649
-		LM_DBG("storing info...\n");
650
-		if(trace_delayed != 0 && db_funcs.insert_delayed != NULL) {
651
-			if(db_funcs.insert_delayed(db_con, db_keys, db_vals, NR_KEYS) < 0) {
652
-				LM_ERR("error storing trace\n");
653
-				goto error;
654
-			}
655
-		} else {
656
-			if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) {
657
-				LM_ERR("error storing trace\n");
658
-				goto error;
659
-			}
667
+		if(sip_trace_insert_db(db_keys, db_vals, NR_KEYS, "no user") < 0) {
668
+			goto error;
660 669
 		}
661 670
 #ifdef STATISTICS
662 671
 		update_stat(sto->stat, 1);
... ...
@@ -668,34 +677,16 @@ static int sip_trace_store_db(siptrace_data_t *sto)
668 677
 
669 678
 	db_vals[9].val.str_val = sto->avp_value.s;
670 679
 
671
-	LM_DBG("storing info...\n");
672
-	if(trace_delayed != 0 && db_funcs.insert_delayed != NULL) {
673
-		if(db_funcs.insert_delayed(db_con, db_keys, db_vals, NR_KEYS) < 0) {
674
-			LM_ERR("error storing trace\n");
675
-			goto error;
676
-		}
677
-	} else {
678
-		if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) {
679
-			LM_ERR("error storing trace\n");
680
-			goto error;
681
-		}
680
+	if(sip_trace_insert_db(db_keys, db_vals, NR_KEYS, "first user") < 0) {
681
+		goto error;
682 682
 	}
683 683
 
684 684
 	sto->avp = search_next_avp(&sto->state, &sto->avp_value);
685 685
 	while(sto->avp != NULL) {
686 686
 		db_vals[9].val.str_val = sto->avp_value.s;
687 687
 
688
-		LM_DBG("storing info...\n");
689
-		if(trace_delayed != 0 && db_funcs.insert_delayed != NULL) {
690
-			if(db_funcs.insert_delayed(db_con, db_keys, db_vals, NR_KEYS) < 0) {
691
-				LM_ERR("error storing trace\n");
692
-				goto error;
693
-			}
694
-		} else {
695
-			if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) {
696
-				LM_ERR("error storing trace\n");
697
-				goto error;
698
-			}
688
+		if(sip_trace_insert_db(db_keys, db_vals, NR_KEYS, "extra user") < 0) {
689
+			goto error;
699 690
 		}
700 691
 		sto->avp = search_next_avp(&sto->state, &sto->avp_value);
701 692
 	}