Browse code

- better escape support in strings (e.g. \", \<cr>, \x0a, \012) - minor config parsing string optimizations

Andrei Pelinescu-Onciul authored on 08/10/2004 13:19:07
Showing 3 changed files
... ...
@@ -50,7 +50,7 @@ MAIN_NAME=ser
50 50
 VERSION = 0
51 51
 PATCHLEVEL = 8
52 52
 SUBLEVEL =   99
53
-EXTRAVERSION = -dev8
53
+EXTRAVERSION = -dev9
54 54
 
55 55
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
56 56
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -10,6 +10,11 @@ new archs:
10 10
  - mips2/cobalt experimental support
11 11
  - x86_64 experimental support
12 12
 modules:
13
+ -  tm has a new parameter: restart_fr_on_each_reply. If set (default)
14
+    fr_inv timer will be restarted for each provisional reply, if not set
15
+    it will be restarted only for the first reply and for replies >=180
16
+    (but only if increasing, eg.: 180, 181 ...). Usefull when dealing with bad
17
+    UAs that re-transmit 180s.
13 18
  - nathelper received port  test (flag 16 for nat_uac_test): compares the
14 19
    source port of the message with sip port in the first Via and returns
15 20
    true if different.
... ...
@@ -36,7 +41,10 @@ core:
36 41
  - new parts:
37 42
        UNIX domain socket server implemented
38 43
  - changes: 
39
- 	-  avp (Attribute-Value Pair) support added
44
+    - config: better escape support in strings (e.g. \", \<cr>, \x0a, \012)
45
+    - bad network addresses are now automatically fixed
46
+      (e.g. 192.168.1.80/27 => 192.168.1.64/27)
47
+    -  avp (Attribute-Value Pair) support added
40 48
     -  multicast support added (see mcast_loopback & mcast_ttl)
41 49
     -  saving of procces group id enabled, if the -G option is specified
42 50
        (a safe way to quickly kill all ser processes)
... ...
@@ -49,6 +49,7 @@
49 49
  *               sock_group  (andrei)
50 50
  *  2004-05-03  applied multicast support patch from janakj
51 51
  *              added MCAST_TTL (andrei)
52
+ *  2004-10-08  more escapes: \", \xHH, \nnn and minor optimizations (andrei)
52 53
  */
53 54
 
54 55
 
... ...
@@ -68,15 +69,23 @@
68 69
 	#define COMMENT_LN_S	2
69 70
 	#define STRING_S		3
70 71
 
72
+	#define STR_BUF_ALLOC_UNIT	128
73
+	struct str_buf{
74
+		char* s;
75
+		char* crt;
76
+		int left;
77
+	};
78
+
71 79
 	
72 80
 	static int comment_nest=0;
73 81
 	static int state=0;
74
-	static char* tstr=0;
82
+	static struct str_buf s_buf;
75 83
 	int line=1;
76 84
 	int column=1;
77 85
 	int startcolumn=1;
78 86
 
79
-	static char* addstr(char*, char**);
87
+	static char* addchar(struct str_buf *, char);
88
+	static char* addstr(struct str_buf *, char*, int);
80 89
 	static void count();
81 90
 
82 91
 
... ...
@@ -459,30 +468,32 @@ EAT_ABLE	[\ \t\b\r]
459 468
 
460 469
 <STRING1>{QUOTES} { count(); state=INITIAL_S; BEGIN(INITIAL); 
461 470
 						yytext[yyleng-1]=0; yyleng--;
462
-						addstr(yytext, &tstr);
463
-						yylval.strval=tstr; tstr=0;
471
+						addstr(&s_buf, yytext, yyleng);
472
+						yylval.strval=s_buf.s;
473
+						memset(&s_buf, 0, sizeof(s_buf));
464 474
 						return STRING;
465 475
 					}
466 476
 <STRING2>{TICK}  { count(); state=INITIAL_S; BEGIN(INITIAL); 
467 477
 						yytext[yyleng-1]=0; yyleng--;
468
-						addstr(yytext, &tstr);
469
-						yylval.strval=tstr;
470
-						tstr=0;
478
+						addstr(&s_buf, yytext, yyleng);
479
+						yylval.strval=s_buf.s;
480
+						memset(&s_buf, 0, sizeof(s_buf));
471 481
 						return STRING;
472 482
 					}
473 483
 <STRING2>.|{EAT_ABLE}|{CR}	{ yymore(); }
474 484
 
475
-<STRING1>\\n		{ count(); yytext[yyleng-2]='\n';yytext[yyleng-1]=0; 
476
-						yyleng--; addstr(yytext, &tstr); }
477
-<STRING1>\\r		{ count(); yytext[yyleng-2]='\r';yytext[yyleng-1]=0; 
478
-						yyleng--; addstr(yytext, &tstr); }
479
-<STRING1>\\a		{ count(); yytext[yyleng-2]='\a';yytext[yyleng-1]=0; 
480
-						yyleng--; addstr(yytext, &tstr); }
481
-<STRING1>\\t		{ count(); yytext[yyleng-2]='\t';yytext[yyleng-1]=0; 
482
-						yyleng--; addstr(yytext, &tstr); }
483
-<STRING1>\\\\		{ count(); yytext[yyleng-2]='\\';yytext[yyleng-1]=0; 
484
-						yyleng--; addstr(yytext, &tstr); } 
485
-<STRING1>.|{EAT_ABLE}|{CR}	{ yymore(); }
485
+<STRING1>\\n		{ count(); addchar(&s_buf, '\n'); }
486
+<STRING1>\\r		{ count(); addchar(&s_buf, '\r'); }
487
+<STRING1>\\a		{ count(); addchar(&s_buf, '\a'); }
488
+<STRING1>\\t		{ count(); addchar(&s_buf, '\t'); }
489
+<STRING1>\\{QUOTES}	{ count(); addchar(&s_buf, '"');  }
490
+<STRING1>\\\\		{ count(); addchar(&s_buf, '\\'); } 
491
+<STRING1>\\x{HEX}{1,2}	{ count(); addchar(&s_buf, 
492
+											(char)strtol(yytext+2, 0, 16)); }
493
+<STRING1>\\[0-7]{1,3}	{ count(); addchar(&s_buf, 
494
+											(char)strtol(yytext+1, 0, 8));  }
495
+<STRING1>\\{CR}		{ count(); } /* eat escaped CRs */
496
+<STRING1>.|{EAT_ABLE}|{CR}	{ addchar(&s_buf, *yytext); }
486 497
 
487 498
 
488 499
 <INITIAL,COMMENT>{COM_START}	{ count(); comment_nest++; state=COMMENT_S;
... ...
@@ -497,8 +508,7 @@ EAT_ABLE	[\ \t\b\r]
497 508
 
498 509
 <INITIAL>{COM_LINE}.*{CR}	{ count(); } 
499 510
 
500
-<INITIAL>{ID}			{ count(); addstr(yytext, &tstr);
501
-						  yylval.strval=tstr; tstr=0; return ID; }
511
+<INITIAL>{ID}			{ count(); yylval.strval=yytext; return ID; }
502 512
 
503 513
 
504 514
 <<EOF>>							{
... ...
@@ -506,7 +516,11 @@ EAT_ABLE	[\ \t\b\r]
506 516
 										case STRING_S: 
507 517
 											LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF in"
508 518
 														" unclosed string\n");
509
-											if (tstr) {pkg_free(tstr);tstr=0;}
519
+											if (s_buf.s){
520
+												pkg_free(s_buf.s);
521
+												memset(&s_buf, 0,
522
+															sizeof(s_buf));
523
+											}
510 524
 											break;
511 525
 										case COMMENT_S:
512 526
 											LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF:"
... ...
@@ -522,28 +536,41 @@ EAT_ABLE	[\ \t\b\r]
522 536
 			
523 537
 %%
524 538
 
525
-static char* addstr(char * src, char ** dest)
539
+
540
+static char* addchar(struct str_buf* dst, char c)
541
+{
542
+	return addstr(dst, &c, 1);
543
+}
544
+
545
+
546
+
547
+static char* addstr(struct str_buf* dst_b, char* src, int len)
526 548
 {
527 549
 	char *tmp;
528
-	unsigned len1, len2;
550
+	unsigned size;
551
+	unsigned used;
529 552
 	
530
-	if (*dest==0){
531
-		len1 = strlen(src);
532
-		*dest = pkg_malloc(len1 + 1);
533
-		if (*dest == 0) goto error;
534
-		memcpy(*dest, src, len1 + 1);
535
-	}else{
536
-		len1=strlen(*dest);
537
-		len2=strlen(src);
538
-		tmp=pkg_malloc(len1+len2+1);
553
+	if (dst_b->left<(len+1)){
554
+		used=(unsigned)(dst_b->crt-dst_b->s);
555
+		size=used+len+1;
556
+		/* round up to next multiple */
557
+		size+= STR_BUF_ALLOC_UNIT-size%STR_BUF_ALLOC_UNIT;
558
+		tmp=pkg_malloc(size);
539 559
 		if (tmp==0) goto error;
540
-		memcpy(tmp, *dest, len1);
541
-		memcpy(tmp+len1, src, len2);
542
-		tmp[len1+len2]=0;
543
-		pkg_free(*dest);
544
-		*dest=tmp;
560
+		if (dst_b->s){
561
+			memcpy(tmp, dst_b->s, used); 
562
+			pkg_free(dst_b->s);
563
+		}
564
+		dst_b->s=tmp;
565
+		dst_b->crt=dst_b->s+used;
566
+		dst_b->left=size-used;
545 567
 	}
546
-	return *dest;
568
+	memcpy(dst_b->crt, src, len);
569
+	dst_b->crt+=len;
570
+	*(dst_b->crt)=0;
571
+	dst_b->left-=len;
572
+	
573
+	return dst_b->s;
547 574
 error:
548 575
 	LOG(L_CRIT, "ERROR:lex:addstr: memory allocation error\n");
549 576
 	return 0;