Browse code

pvars: silent version for pv_parse_spec

- added a silent version for pv_parse_spec (pv_parse_spec2()), so
that the script parsing fallback from pvars to avps for
ambiguous identifiers can happen without a ton of error messages

Andrei Pelinescu-Onciul authored on 12/12/2008 13:20:55
Showing 3 changed files
... ...
@@ -1913,6 +1913,7 @@ pvar:	PVAR {
1913 1913
 			if (pv_parse_spec(&s_tmp, pv_spec)==0){
1914 1914
 				yyerror("unknown script pseudo variable");
1915 1915
 				pkg_free(pv_spec);
1916
+				pv_spec=0;
1916 1917
 				YYABORT;
1917 1918
 			}
1918 1919
 			$$=pv_spec;
... ...
@@ -1927,7 +1928,7 @@ avp_pvar:	AVP_OR_PVAR {
1927 1928
 				}
1928 1929
 				memset(lval_tmp, 0, sizeof(*lval_tmp));
1929 1930
 				s_tmp.s=$1; s_tmp.len=strlen(s_tmp.s);
1930
-				if (pv_parse_spec(&s_tmp, &lval_tmp->lv.pvs)==0){
1931
+				if (pv_parse_spec2(&s_tmp, &lval_tmp->lv.pvs, 1)==0){
1931 1932
 					/* not a pvar, try avps */
1932 1933
 					lval_tmp->lv.avps.type|= AVP_NAME_STR;
1933 1934
 					lval_tmp->lv.avps.name.s.s = s_tmp.s+1;
... ...
@@ -352,7 +352,7 @@ pv_export_t* pv_lookup_spec_name(str *pvname, pv_spec_p e)
352 352
 	return NULL;
353 353
 }
354 354
 
355
-char* pv_parse_spec(str *in, pv_spec_p e)
355
+char* pv_parse_spec2(str *in, pv_spec_p e, int silent)
356 356
 {
357 357
 	char *p;
358 358
 	str s;
... ...
@@ -364,7 +364,7 @@ char* pv_parse_spec(str *in, pv_spec_p e)
364 364
 
365 365
 	if(in==NULL || in->s==NULL || e==NULL || *in->s!=PV_MARKER)
366 366
 	{
367
-		LM_ERR("bad parameters\n");
367
+		if (!silent) LM_ERR("bad parameters\n");
368 368
 		return NULL;
369 369
 	}
370 370
 	
... ...
@@ -411,8 +411,9 @@ char* pv_parse_spec(str *in, pv_spec_p e)
411 411
 			p++;
412 412
 			pvstate = 4;
413 413
 		} else {
414
-			LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s,
415
-					pvstate);
414
+			if (!silent)
415
+				LM_ERR("invalid char '%c' in [%.*s] (%d)\n",
416
+							*p, in->len, in->s, pvstate);
416 417
 			goto error;
417 418
 		}
418 419
 	} else { 
... ...
@@ -433,21 +434,24 @@ char* pv_parse_spec(str *in, pv_spec_p e)
433 434
 done_inm:
434 435
 	if((pte = pv_lookup_spec_name(&pvname, e))==NULL)
435 436
 	{
436
-		LM_ERR("error searching pvar \"%.*s\"\n", pvname.len, pvname.s);
437
+		if (!silent) 
438
+			LM_ERR("error searching pvar \"%.*s\"\n", pvname.len, pvname.s);
437 439
 		goto error;
438 440
 	}
439 441
 	if(pte->parse_name!=NULL && pvstate!=2 && pvstate!=5)
440 442
 	{
441
-		LM_ERR("pvar \"%.*s\" expects an inner name\n",
442
-				pvname.len, pvname.s);
443
+		if (!silent) 
444
+			LM_ERR("pvar \"%.*s\" expects an inner name\n",
445
+						pvname.len, pvname.s);
443 446
 		goto error;
444 447
 	}
445 448
 	if(pvstate==2 || pvstate==5)
446 449
 	{
447 450
 		if(pte->parse_name==NULL)
448 451
 		{
449
-			LM_ERR("pvar \"%.*s\" does not get name param\n",
450
-					pvname.len, pvname.s);
452
+			if (!silent)
453
+				LM_ERR("pvar \"%.*s\" does not get name param\n",
454
+						pvname.len, pvname.s);
451 455
 			goto error;
452 456
 		}
453 457
 		s.s = p;
... ...
@@ -470,15 +474,17 @@ done_inm:
470 474
 
471 475
 		if(p==s.s)
472 476
 		{
473
-			LM_ERR("pvar \"%.*s\" does not get empty name param\n",
474
-					pvname.len, pvname.s);
477
+			if (!silent)
478
+				LM_ERR("pvar \"%.*s\" does not get empty name param\n",
479
+						pvname.len, pvname.s);
475 480
 			goto error;
476 481
 		}
477 482
 		s.len = p - s.s;
478 483
 		if(pte->parse_name(e, &s)!=0)
479 484
 		{
480
-			LM_ERR("pvar \"%.*s\" has an invalid name param [%.*s]\n",
481
-					pvname.len, pvname.s, s.len, s.s);
485
+			if (!silent)
486
+				LM_ERR("pvar \"%.*s\" has an invalid name param [%.*s]\n",
487
+						pvname.len, pvname.s, s.len, s.s);
482 488
 			goto error;
483 489
 		}
484 490
 		if(pvstate==2)
... ...
@@ -494,8 +500,9 @@ done_inm:
494 500
 				p++;
495 501
 				pvstate = 4;
496 502
 			} else {
497
-				LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s,
498
-					pvstate);
503
+				if (!silent)
504
+					LM_ERR("invalid char '%c' in [%.*s] (%d)\n",
505
+								*p, in->len, in->s, pvstate);
499 506
 				goto error;
500 507
 			}
501 508
 		} else {
... ...
@@ -504,8 +511,9 @@ done_inm:
504 511
 				p++;
505 512
 				goto done_all;
506 513
 			} else {
507
-				LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s,
508
-					pvstate);
514
+				if (!silent)
515
+					LM_ERR("invalid char '%c' in [%.*s] (%d)\n",
516
+								*p, in->len, in->s, pvstate);
509 517
 				goto error;
510 518
 			}
511 519
 		}
... ...
@@ -515,8 +523,9 @@ done_vnm:
515 523
 	{
516 524
 		if(pte->parse_index==NULL)
517 525
 		{
518
-			LM_ERR("pvar \"%.*s\" does not get index param\n",
519
-					pvname.len, pvname.s);
526
+			if (!silent)
527
+				LM_ERR("pvar \"%.*s\" does not get index param\n",
528
+						pvname.len, pvname.s);
520 529
 			goto error;
521 530
 		}
522 531
 		s.s = p;
... ...
@@ -538,15 +547,17 @@ done_vnm:
538 547
 
539 548
 		if(p==s.s)
540 549
 		{
541
-			LM_ERR("pvar \"%.*s\" does not get empty index param\n",
542
-					pvname.len, pvname.s);
550
+			if (!silent)
551
+				LM_ERR("pvar \"%.*s\" does not get empty index param\n",
552
+						pvname.len, pvname.s);
543 553
 			goto error;
544 554
 		}
545 555
 		s.len = p - s.s;
546 556
 		if(pte->parse_index(e, &s)!=0)
547 557
 		{
548
-			LM_ERR("pvar \"%.*s\" has an invalid index param [%.*s]\n",
549
-					pvname.len, pvname.s, s.len, s.s);
558
+			if (!silent)
559
+				LM_ERR("pvar \"%.*s\" has an invalid index param [%.*s]\n",
560
+						pvname.len, pvname.s, s.len, s.s);
550 561
 			goto error;
551 562
 		}
552 563
 		p++;
... ...
@@ -557,8 +568,9 @@ done_vnm:
557 568
 			p++;
558 569
 			pvstate = 4;
559 570
 		} else {
560
-			LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s,
561
-					pvstate);
571
+			if (!silent)
572
+				LM_ERR("invalid char '%c' in [%.*s] (%d)\n",
573
+							*p, in->len, in->s, pvstate);
562 574
 			goto error;
563 575
 		}
564 576
 	}
... ...
@@ -594,8 +606,9 @@ done_idx:
594 606
 
595 607
 		if(p==s.s)
596 608
 		{
597
-			LM_ERR("pvar \"%.*s\" does not get empty index param\n",
598
-					pvname.len, pvname.s);
609
+			if (!silent)
610
+				LM_ERR("pvar \"%.*s\" does not get empty index param\n",
611
+						pvname.len, pvname.s);
599 612
 			goto error;
600 613
 		}
601 614
 		s.len = p - s.s + 1;
... ...
@@ -603,12 +616,14 @@ done_idx:
603 616
 		p = tr_lookup(&s, &tr);
604 617
 		if(p==NULL)
605 618
 		{
606
-			LM_ERR("bad tr in pvar name \"%.*s\"\n", pvname.len, pvname.s);
619
+			if (!silent)
620
+				LM_ERR("bad tr in pvar name \"%.*s\"\n", pvname.len, pvname.s);
607 621
 			goto error;
608 622
 		}
609 623
 		if(*p!=PV_RNBRACKET)
610 624
 		{
611
-			LM_ERR("bad pvar name \"%.*s\" (%c)!\n", in->len, in->s, *p);
625
+			if (!silent)
626
+				LM_ERR("bad pvar name \"%.*s\" (%c)!\n", in->len, in->s, *p);
612 627
 			goto error;
613 628
 		}
614 629
 		e->trans = (void*)tr;
... ...
@@ -621,11 +636,15 @@ done_all:
621 636
 	return p;
622 637
 
623 638
 error:
624
-	if(p!=NULL)
625
-		LM_ERR("wrong char [%c/%d] in [%.*s] at [%d (%d)]\n", *p, (int)*p,
626
-			in->len, in->s, (int)(p-in->s), pvstate);
627
-	else
628
-		LM_ERR("invalid parsing in [%.*s] at (%d)\n", in->len, in->s, pvstate);
639
+	if(p!=NULL){
640
+		if (!silent)
641
+			LM_ERR("wrong char [%c/%d] in [%.*s] at [%d (%d)]\n", *p, (int)*p,
642
+					in->len, in->s, (int)(p-in->s), pvstate);
643
+	}else{
644
+		if (!silent)
645
+			LM_ERR("invalid parsing in [%.*s] at (%d)\n",
646
+						in->len, in->s, pvstate);
647
+	}
629 648
 	return NULL;
630 649
 
631 650
 } /* end: pv_parse_spec */
... ...
@@ -158,7 +158,8 @@ typedef struct _pv_elem
158 158
 	struct _pv_elem *next;
159 159
 } pv_elem_t, *pv_elem_p;
160 160
 
161
-char* pv_parse_spec(str *in, pv_spec_p sp);
161
+char* pv_parse_spec2(str *in, pv_spec_p sp, int silent);
162
+#define pv_parse_spec(in, sp) pv_parse_spec2((in), (sp), 0)
162 163
 int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value);
163 164
 int pv_print_spec(struct sip_msg* msg, pv_spec_p sp, char *buf, int *len);
164 165
 int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len);