Browse code

pv: added {param.in,name[,sep]}

- return 1 if param name is found in the list, 0 if not found

Daniel-Constantin Mierla authored on 01/06/2021 08:36:26
Showing 2 changed files
... ...
@@ -1807,6 +1807,7 @@ int tr_eval_paramlist(struct sip_msg *msg, tr_param_t *tp, int subtype,
1807 1807
 	switch(subtype)
1808 1808
 	{
1809 1809
 		case TR_PL_VALUE:
1810
+		case TR_PL_IN:
1810 1811
 			if(tp==NULL)
1811 1812
 			{
1812 1813
 				LM_ERR("value invalid parameters\n");
... ...
@@ -1831,11 +1832,23 @@ int tr_eval_paramlist(struct sip_msg *msg, tr_param_t *tp, int subtype,
1831 1832
 				if (pit->name.len==sv.len
1832 1833
 						&& strncasecmp(pit->name.s, sv.s, sv.len)==0)
1833 1834
 				{
1834
-					val->rs = pit->body;
1835
+					if(subtype==TR_PL_IN) {
1836
+						val->ri = 1;
1837
+						val->flags = PV_TYPE_INT|PV_VAL_INT|PV_VAL_STR;
1838
+						val->rs.s = int2str(val->ri, &val->rs.len);
1839
+					} else {
1840
+						val->rs = pit->body;
1841
+					}
1835 1842
 					goto done;
1836 1843
 				}
1837 1844
 			}
1838
-			val->rs = _tr_empty;
1845
+			if(subtype==TR_PL_IN) {
1846
+				val->ri = 0;
1847
+				val->flags = PV_TYPE_INT|PV_VAL_INT|PV_VAL_STR;
1848
+				val->rs.s = int2str(val->ri, &val->rs.len);
1849
+			} else {
1850
+				val->rs = _tr_empty;
1851
+			}
1839 1852
 			break;
1840 1853
 
1841 1854
 		case TR_PL_VALUEAT:
... ...
@@ -3176,139 +3189,77 @@ char* tr_parse_paramlist(str* in, trans_t *t)
3176 3189
 	name.len = p - name.s;
3177 3190
 	trim(&name);
3178 3191
 
3179
-	if(name.len==5 && strncasecmp(name.s, "value", 5)==0)
3180
-	{
3192
+	if(name.len==5 && strncasecmp(name.s, "value", 5)==0) {
3181 3193
 		t->subtype = TR_PL_VALUE;
3182
-		if(*p!=TR_PARAM_MARKER)
3183
-		{
3184
-			LM_ERR("invalid value transformation: %.*s\n",
3185
-					in->len, in->s);
3186
-			goto error;
3187
-		}
3188
-		p++;
3194
+	} else if(name.len==2 && strncasecmp(name.s, "in", 2)==0) {
3195
+		t->subtype = TR_PL_IN;
3196
+	} else if(name.len==7 && strncasecmp(name.s, "valueat", 7)==0) {
3197
+		t->subtype = TR_PL_VALUEAT;
3198
+	} else if(name.len==4 && strncasecmp(name.s, "name", 4)==0) {
3199
+		t->subtype = TR_PL_NAME;
3200
+	} else if(name.len==5 && strncasecmp(name.s, "count", 5)==0) {
3201
+		t->subtype = TR_PL_COUNT;
3202
+	} else {
3203
+		goto unknown;
3204
+	}
3205
+
3206
+	if(*p!=TR_PARAM_MARKER)
3207
+	{
3208
+		LM_ERR("invalid %.*s transformation: %.*s\n",
3209
+				name.len, name.s, in->len, in->s);
3210
+		goto error;
3211
+	}
3212
+	p++;
3213
+
3214
+	if(t->subtype == TR_PL_VALUE || t->subtype == TR_PL_IN) {
3189 3215
 		_tr_parse_sparam(p, p0, tp, spec, ps, in, s);
3190 3216
 		t->params = tp;
3191 3217
 		tp = 0;
3192 3218
 		while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
3193
-
3194
-		if(*p==TR_PARAM_MARKER)
3195
-		{
3196
-			start_pos = ++p;
3197
-			_tr_parse_sparam(p, p0, tp, spec, ps, in, s);
3198
-			t->params->next = tp;
3199
-			tp = 0;
3200
-			if (p - start_pos != 1)
3201
-			{
3202
-				LM_ERR("invalid separator in transformation: "
3203
-						"%.*s\n", in->len, in->s);
3204
-				goto error;
3205
-			}
3206
-			while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
3207
-		}
3208
-
3209
-		if(*p!=TR_RBRACKET)
3210
-		{
3211
-			LM_ERR("invalid value transformation: %.*s!\n",
3212
-					in->len, in->s);
3213
-			goto error;
3214
-		}
3215
-		goto done;
3216
-	} else if(name.len==7 && strncasecmp(name.s, "valueat", 7)==0) {
3217
-		t->subtype = TR_PL_VALUEAT;
3218
-		if(*p!=TR_PARAM_MARKER)
3219
-		{
3220
-			LM_ERR("invalid name transformation: %.*s\n",
3221
-					in->len, in->s);
3222
-			goto error;
3223
-		}
3224
-		p++;
3219
+	} else if(t->subtype == TR_PL_VALUEAT || t->subtype == TR_PL_NAME) {
3225 3220
 		_tr_parse_nparam(p, p0, tp, spec, n, sign, in, s)
3226 3221
 			t->params = tp;
3227 3222
 		tp = 0;
3228 3223
 		while(is_in_str(p, in) && (*p==' ' || *p=='\t' || *p=='\n')) p++;
3224
+	}
3229 3225
 
3230
-		if(*p==TR_PARAM_MARKER)
3231
-		{
3226
+	if(t->subtype == TR_PL_COUNT) {
3227
+		if(*p==TR_PARAM_MARKER) {
3232 3228
 			start_pos = ++p;
3233
-			_tr_parse_sparam(p, p0, tp, spec, ps, in, s);
3234
-			t->params->next = tp;
3229
+			_tr_parse_sparamx(p, p0, tp, spec, ps, in, s, 1);
3230
+			t->params = tp;
3235 3231
 			tp = 0;
3236
-			if (p - start_pos != 1)
3237
-			{
3232
+			if (tp->type != TR_PARAM_SPEC && p - start_pos != 1) {
3238 3233
 				LM_ERR("invalid separator in transformation: "
3239 3234
 						"%.*s\n", in->len, in->s);
3240 3235
 				goto error;
3241 3236
 			}
3242
-			while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
3243
-		}
3244
-
3245
-		if(*p!=TR_RBRACKET)
3246
-		{
3247
-			LM_ERR("invalid name transformation: %.*s!\n",
3248
-					in->len, in->s);
3249
-			goto error;
3250
-		}
3251
-		goto done;
3252
-	} else if(name.len==4 && strncasecmp(name.s, "name", 4)==0) {
3253
-		t->subtype = TR_PL_NAME;
3254
-		if(*p!=TR_PARAM_MARKER)
3255
-		{
3256
-			LM_ERR("invalid name transformation: %.*s\n",
3257
-					in->len, in->s);
3258
-			goto error;
3259 3237
 		}
3260
-		p++;
3261
-		_tr_parse_nparam(p, p0, tp, spec, n, sign, in, s)
3262
-			t->params = tp;
3263
-		tp = 0;
3264
-		while(is_in_str(p, in) && (*p==' ' || *p=='\t' || *p=='\n')) p++;
3265
-
3266
-		if(*p==TR_PARAM_MARKER)
3267
-		{
3238
+	} else {
3239
+		if(*p==TR_PARAM_MARKER) {
3268 3240
 			start_pos = ++p;
3269 3241
 			_tr_parse_sparam(p, p0, tp, spec, ps, in, s);
3270 3242
 			t->params->next = tp;
3271 3243
 			tp = 0;
3272
-			if (p - start_pos != 1)
3273
-			{
3274
-				LM_ERR("invalid separator in transformation: "
3275
-						"%.*s\n", in->len, in->s);
3276
-				goto error;
3277
-			}
3278
-			while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
3279
-		}
3280
-
3281
-		if(*p!=TR_RBRACKET)
3282
-		{
3283
-			LM_ERR("invalid name transformation: %.*s!\n",
3284
-					in->len, in->s);
3285
-			goto error;
3286
-		}
3287
-		goto done;
3288
-	} else if(name.len==5 && strncasecmp(name.s, "count", 5)==0) {
3289
-		t->subtype = TR_PL_COUNT;
3290
-		if(*p==TR_PARAM_MARKER) {
3291
-			start_pos = ++p;
3292
-			_tr_parse_sparamx(p, p0, tp, spec, ps, in, s, 1);
3293
-			t->params = tp;
3294
-			if (tp->type != TR_PARAM_SPEC && p - start_pos != 1) {
3244
+			if (p - start_pos != 1) {
3295 3245
 				LM_ERR("invalid separator in transformation: "
3296 3246
 						"%.*s\n", in->len, in->s);
3297 3247
 				goto error;
3298 3248
 			}
3299
-			tp = 0;
3300
-
3301
-			while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
3302
-			if(*p!=TR_RBRACKET) {
3303
-				LM_ERR("invalid name transformation: %.*s!\n",
3304
-						in->len, in->s);
3305
-				goto error;
3306
-			}
3307 3249
 		}
3250
+	}
3308 3251
 
3309
-		goto done;
3252
+	while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
3253
+	if(*p!=TR_RBRACKET) {
3254
+		LM_ERR("invalid %.*s transformation: %.*s!\n",
3255
+				name.len, name.s, in->len, in->s);
3256
+		goto error;
3310 3257
 	}
3311 3258
 
3259
+	t->name = name;
3260
+	return p;
3261
+
3262
+unknown:
3312 3263
 	LM_ERR("unknown transformation: %.*s/%.*s!\n",
3313 3264
 			in->len, in->s, name.len, name.s);
3314 3265
 error:
... ...
@@ -3317,9 +3268,6 @@ error:
3317 3268
 	if(spec)
3318 3269
 		pv_spec_free(spec);
3319 3270
 	return NULL;
3320
-done:
3321
-	t->name = name;
3322
-	return p;
3323 3271
 }
3324 3272
 
3325 3273
 
... ...
@@ -55,7 +55,8 @@ enum _tr_uri_subtype {
55 55
 	TR_URI_SURI
56 56
 };
57 57
 enum _tr_param_subtype {
58
-	TR_PL_NONE=0, TR_PL_VALUE, TR_PL_VALUEAT, TR_PL_NAME, TR_PL_COUNT
58
+	TR_PL_NONE=0, TR_PL_VALUE, TR_PL_VALUEAT, TR_PL_NAME, TR_PL_COUNT,
59
+	TR_PL_IN
59 60
 };
60 61
 enum _tr_nameaddr_subtype {
61 62
 	TR_NA_NONE=0, TR_NA_NAME, TR_NA_URI, TR_NA_LEN