Browse code

pv: added {val.ne} transformation

- return empty string if the variable value is $null

Daniel-Constantin Mierla authored on 22/11/2021 17:54:02
Showing 2 changed files
... ...
@@ -2551,6 +2551,16 @@ int tr_eval_val(struct sip_msg *msg, tr_param_t *tp, int subtype,
2551 2551
 				val->flags = PV_TYPE_INT|PV_VAL_INT|PV_VAL_STR;
2552 2552
 			}
2553 2553
 			break;
2554
+		case TR_VAL_NE:
2555
+			if(val->flags&PV_VAL_NULL) {
2556
+				val->ri = 0;
2557
+				tr_set_crt_buffer();
2558
+				val->rs.s = _tr_buffer;
2559
+				val->rs.s[0] = '\0';
2560
+				val->rs.len = 0;
2561
+				val->flags = PV_VAL_STR;
2562
+			}
2563
+			break;
2554 2564
 		case TR_VAL_JSON:
2555 2565
 			if(val->flags&PV_VAL_NULL) {
2556 2566
 				val->ri = 0;
... ...
@@ -3831,6 +3841,9 @@ char* tr_parse_val(str* in, trans_t *t)
3831 3841
 	if(name.len==2 && strncasecmp(name.s, "n0", 2)==0) {
3832 3842
 		t->subtype = TR_VAL_N0;
3833 3843
 		goto done;
3844
+	} else if(name.len==2 && strncasecmp(name.s, "ne", 2)==0) {
3845
+		t->subtype = TR_VAL_NE;
3846
+		goto done;
3834 3847
 	} else if(name.len==4 && strncasecmp(name.s, "json", 4)==0) {
3835 3848
 		t->subtype = TR_VAL_JSON;
3836 3849
 		goto done;
... ...
@@ -73,7 +73,7 @@ enum _tr_urialias_subtype {
73 73
 };
74 74
 
75 75
 enum _tr_val_subtype {
76
-	TR_VAL_NONE=0, TR_VAL_N0, TR_VAL_JSON
76
+	TR_VAL_NONE=0, TR_VAL_N0, TR_VAL_NE, TR_VAL_JSON
77 77
 };
78 78
 
79 79