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 36
  - new parts:
37 37
        UNIX domain socket server implemented
38 38
  - changes: 
39
- 	-  avp (Attribute-Value Pair) support added
39
+    - config: better escape support in strings (e.g. \", \<cr>, \x0a, \012)
40
+    - bad network addresses are now automatically fixed
41
+      (e.g. 192.168.1.80/27 => 192.168.1.64/27)
42
+    -  avp (Attribute-Value Pair) support added
40 43
     -  multicast support added (see mcast_loopback & mcast_ttl)
41 44
     -  saving of procces group id enabled, if the -G option is specified
42 45
        (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 68
 	#define COMMENT_LN_S	2
69 69
 	#define STRING_S		3
70 70
 
71
+	#define STR_BUF_ALLOC_UNIT	128
72
+	struct str_buf{
73
+		char* s;
74
+		char* crt;
75
+		int left;
76
+	};
77
+
71 78
 	
72 79
 	static int comment_nest=0;
73 80
 	static int state=0;
74
-	static char* tstr=0;
81
+	static struct str_buf s_buf;
75 82
 	int line=1;
76 83
 	int column=1;
77 84
 	int startcolumn=1;
78 85
 
79
-	static char* addstr(char*, char**);
86
+	static char* addchar(struct str_buf *, char);
87
+	static char* addstr(struct str_buf *, char*, int);
80 88
 	static void count();
81 89
 
82 90
 
... ...
@@ -459,30 +468,32 @@ EAT_ABLE	[\ \t\b\r]
459 459
 
460 460
 <STRING1>{QUOTES} { count(); state=INITIAL_S; BEGIN(INITIAL); 
461 461
 						yytext[yyleng-1]=0; yyleng--;
462
-						addstr(yytext, &tstr);
463
-						yylval.strval=tstr; tstr=0;
462
+						addstr(&s_buf, yytext, yyleng);
463
+						yylval.strval=s_buf.s;
464
+						memset(&s_buf, 0, sizeof(s_buf));
464 465
 						return STRING;
465 466
 					}
466 467
 <STRING2>{TICK}  { count(); state=INITIAL_S; BEGIN(INITIAL); 
467 468
 						yytext[yyleng-1]=0; yyleng--;
468
-						addstr(yytext, &tstr);
469
-						yylval.strval=tstr;
470
-						tstr=0;
469
+						addstr(&s_buf, yytext, yyleng);
470
+						yylval.strval=s_buf.s;
471
+						memset(&s_buf, 0, sizeof(s_buf));
471 472
 						return STRING;
472 473
 					}
473 474
 <STRING2>.|{EAT_ABLE}|{CR}	{ yymore(); }
474 475
 
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(); }
476
+<STRING1>\\n		{ count(); addchar(&s_buf, '\n'); }
477
+<STRING1>\\r		{ count(); addchar(&s_buf, '\r'); }
478
+<STRING1>\\a		{ count(); addchar(&s_buf, '\a'); }
479
+<STRING1>\\t		{ count(); addchar(&s_buf, '\t'); }
480
+<STRING1>\\{QUOTES}	{ count(); addchar(&s_buf, '"');  }
481
+<STRING1>\\\\		{ count(); addchar(&s_buf, '\\'); } 
482
+<STRING1>\\x{HEX}{1,2}	{ count(); addchar(&s_buf, 
483
+											(char)strtol(yytext+2, 0, 16)); }
484
+<STRING1>\\[0-7]{1,3}	{ count(); addchar(&s_buf, 
485
+											(char)strtol(yytext+1, 0, 8));  }
486
+<STRING1>\\{CR}		{ count(); } /* eat escaped CRs */
487
+<STRING1>.|{EAT_ABLE}|{CR}	{ addchar(&s_buf, *yytext); }
486 488
 
487 489
 
488 490
 <INITIAL,COMMENT>{COM_START}	{ count(); comment_nest++; state=COMMENT_S;
... ...
@@ -497,8 +508,7 @@ EAT_ABLE	[\ \t\b\r]
497 497
 
498 498
 <INITIAL>{COM_LINE}.*{CR}	{ count(); } 
499 499
 
500
-<INITIAL>{ID}			{ count(); addstr(yytext, &tstr);
501
-						  yylval.strval=tstr; tstr=0; return ID; }
500
+<INITIAL>{ID}			{ count(); yylval.strval=yytext; return ID; }
502 501
 
503 502
 
504 503
 <<EOF>>							{
... ...
@@ -506,7 +516,11 @@ EAT_ABLE	[\ \t\b\r]
506 506
 										case STRING_S: 
507 507
 											LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF in"
508 508
 														" unclosed string\n");
509
-											if (tstr) {pkg_free(tstr);tstr=0;}
509
+											if (s_buf.s){
510
+												pkg_free(s_buf.s);
511
+												memset(&s_buf, 0,
512
+															sizeof(s_buf));
513
+											}
510 514
 											break;
511 515
 										case COMMENT_S:
512 516
 											LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF:"
... ...
@@ -522,28 +536,41 @@ EAT_ABLE	[\ \t\b\r]
522 522
 			
523 523
 %%
524 524
 
525
-static char* addstr(char * src, char ** dest)
525
+
526
+static char* addchar(struct str_buf* dst, char c)
527
+{
528
+	return addstr(dst, &c, 1);
529
+}
530
+
531
+
532
+
533
+static char* addstr(struct str_buf* dst_b, char* src, int len)
526 534
 {
527 535
 	char *tmp;
528
-	unsigned len1, len2;
536
+	unsigned size;
537
+	unsigned used;
529 538
 	
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);
539
+	if (dst_b->left<(len+1)){
540
+		used=(unsigned)(dst_b->crt-dst_b->s);
541
+		size=used+len+1;
542
+		/* round up to next multiple */
543
+		size+= STR_BUF_ALLOC_UNIT-size%STR_BUF_ALLOC_UNIT;
544
+		tmp=pkg_malloc(size);
539 545
 		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;
546
+		if (dst_b->s){
547
+			memcpy(tmp, dst_b->s, used); 
548
+			pkg_free(dst_b->s);
549
+		}
550
+		dst_b->s=tmp;
551
+		dst_b->crt=dst_b->s+used;
552
+		dst_b->left=size-used;
545 553
 	}
546
-	return *dest;
554
+	memcpy(dst_b->crt, src, len);
555
+	dst_b->crt+=len;
556
+	*(dst_b->crt)=0;
557
+	dst_b->left-=len;
558
+	
559
+	return dst_b->s;
547 560
 error:
548 561
 	LOG(L_CRIT, "ERROR:lex:addstr: memory allocation error\n");
549 562
 	return 0;