Browse code

pv: {line.count} - count last line without \n

Daniel-Constantin Mierla authored on 07/10/2021 07:21:20
Showing 1 changed files
... ...
@@ -2435,19 +2435,22 @@ int tr_eval_line(struct sip_msg *msg, tr_param_t *tp, int subtype,
2435 2435
 			break;
2436 2436
 
2437 2437
 		case TR_LINE_COUNT:
2438
-			n=0;
2439
-			for(i=0; i<val->rs.len; i++)
2440
-				if(val->rs.s[i]=='\n')
2438
+			n = 0;
2439
+			if(val->rs.len>0) {
2440
+				for(i=0; i<val->rs.len; i++) {
2441
+					if(val->rs.s[i]=='\n') {
2442
+						n++;
2443
+					}
2444
+				}
2445
+				if(val->rs.s[val->rs.len-1]!='\n') {
2441 2446
 					n++;
2442
-			if(n==0 && val->rs.len>0)
2443
-				n = 1;
2447
+				}
2448
+			}
2444 2449
 			val->flags = PV_TYPE_INT|PV_VAL_INT|PV_VAL_STR;
2445 2450
 			val->ri = n;
2446 2451
 			val->rs.s = int2str(val->ri, &val->rs.len);
2447 2452
 			break;
2448 2453
 
2449
-			break;
2450
-
2451 2454
 		default:
2452 2455
 			LM_ERR("unknown subtype %d\n",
2453 2456
 					subtype);