Browse code

- from_uri & to_uri script support (exaclty like uri, from_uri==myself or from_uri=~'^sip:[0-9]{7}@' a.s.o)

Andrei Pelinescu-Onciul authored on 19/10/2004 13:40:05
Showing 7 changed files
... ...
@@ -50,7 +50,7 @@ MAIN_NAME=ser
50 50
 VERSION = 0
51 51
 PATCHLEVEL = 8
52 52
 SUBLEVEL =   99
53
-EXTRAVERSION = -dev10
53
+EXTRAVERSION = -dev11
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]")
... ...
@@ -41,6 +41,9 @@ core:
41 41
  - new parts:
42 42
        UNIX domain socket server implemented
43 43
  - changes: 
44
+    - added from_uri & to_uri: behave exactly like uri but use the
45
+	   "From:"/"To:" uris
46
+       (e.g.: if (from_uri==myself) ..., if (to_uri=~"^sip:test@")... )
44 47
     - config: better escape support in strings (e.g. \", \<cr>, \x0a, \012)
45 48
     - bad network addresses are now automatically fixed
46 49
       (e.g. 192.168.1.80/27 => 192.168.1.64/27)
... ...
@@ -50,6 +50,7 @@
50 50
  *  2004-05-03  applied multicast support patch from janakj
51 51
  *              added MCAST_TTL (andrei)
52 52
  *  2004-10-08  more escapes: \", \xHH, \nnn and minor optimizations (andrei)
53
+ *  2004-10-19  added FROM_URI and TO_URI (andrei)
53 54
  */
54 55
 
55 56
 
... ...
@@ -143,6 +144,8 @@ METHOD	method
143 143
    call it "uri" from route{} and status from onreply_route{}
144 144
 */
145 145
 URI		"uri"|"status"
146
+FROM_URI	"from_uri"
147
+TO_URI		"to_uri"
146 148
 SRCIP	src_ip
147 149
 SRCPORT	src_port
148 150
 DSTIP	dst_ip
... ...
@@ -326,6 +329,8 @@ EAT_ABLE	[\ \t\b\r]
326 326
 
327 327
 <INITIAL>{METHOD}	{ count(); yylval.strval=yytext; return METHOD; }
328 328
 <INITIAL>{URI}	{ count(); yylval.strval=yytext; return URI; }
329
+<INITIAL>{FROM_URI}	{ count(); yylval.strval=yytext; return FROM_URI; }
330
+<INITIAL>{TO_URI}	{ count(); yylval.strval=yytext; return TO_URI; }
329 331
 <INITIAL>{SRCIP}	{ count(); yylval.strval=yytext; return SRCIP; }
330 332
 <INITIAL>{SRCPORT}	{ count(); yylval.strval=yytext; return SRCPORT; }
331 333
 <INITIAL>{DSTIP}	{ count(); yylval.strval=yytext; return DSTIP; }
... ...
@@ -56,6 +56,7 @@
56 56
                added MCAST_TTL (andrei)
57 57
  * 2004-07-05  src_ip & dst_ip will detect ip addresses between quotes
58 58
  *              (andrei)
59
+ * 2004-10-19  added FROM_URI, TO_URI (andrei)
59 60
  */
60 61
 
61 62
 
... ...
@@ -173,6 +174,8 @@ static struct id_list* mk_listen_id(char*, int, int);
173 173
 %token ISFLAGSET
174 174
 %token METHOD
175 175
 %token URI
176
+%token FROM_URI
177
+%token TO_URI
176 178
 %token SRCIP
177 179
 %token SRCPORT
178 180
 %token DSTIP
... ...
@@ -299,6 +302,7 @@ static struct id_list* mk_listen_id(char*, int, int);
299 299
 %type <intval> proto port
300 300
 %type <intval> equalop strop intop
301 301
 %type <strval> host_sep
302
+%type <intval> uri_type
302 303
 /*%type <route_el> rules;
303 304
   %type <route_el> rule;
304 305
 */
... ...
@@ -840,6 +844,11 @@ strop:	equalop	{$$=$1; }
840 840
 		| MATCH	{$$=MATCH_OP; }
841 841
 		;
842 842
 
843
+uri_type:	URI			{$$=URI_O;}
844
+		|	FROM_URI	{$$=FROM_URI_O;}
845
+		|	TO_URI		{$$=TO_URI_O;}
846
+		;
847
+
843 848
 exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST, 
844 849
 													METHOD_O, $3);
845 850
 									}
... ...
@@ -850,17 +859,17 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
850 850
 		| METHOD error	{ $$=0; yyerror("invalid operator,"
851 851
 										"== , !=, or =~ expected");
852 852
 						}
853
-		| URI strop STRING 	{$$ = mk_elem(	$2, STRING_ST,
854
-												URI_O, $3); 
853
+		| uri_type strop STRING	{$$ = mk_elem(	$2, STRING_ST,
854
+												$1, $3); 
855 855
 				 				}
856
-		| URI strop host 	{$$ = mk_elem(	$2, STRING_ST,
857
-											URI_O, $3); 
856
+		| uri_type strop host 	{$$ = mk_elem(	$2, STRING_ST,
857
+											$1, $3); 
858 858
 				 			}
859
-		| URI equalop MYSELF    { $$=mk_elem(	$2, MYSELF_ST,
860
-												URI_O, 0);
859
+		| uri_type equalop MYSELF	{ $$=mk_elem(	$2, MYSELF_ST,
860
+													$1, 0);
861 861
 								}
862
-		| URI strop error { $$=0; yyerror("string or MYSELF expected"); }
863
-		| URI error	{ $$=0; yyerror("invalid operator,"
862
+		| uri_type strop error { $$=0; yyerror("string or MYSELF expected"); }
863
+		| uri_type error	{ $$=0; yyerror("invalid operator,"
864 864
 									" == , != or =~ expected");
865 865
 					}
866 866
 		| SRCPORT intop NUMBER	{ $$=mk_elem(	$2, NUMBER_ST,
... ...
@@ -941,8 +950,8 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
941 941
 						 			"expected" ); }
942 942
 		| DSTIP error { $$=0; 
943 943
 						yyerror("invalid operator, ==, != or =~ expected");}
944
-		| MYSELF equalop URI    { $$=mk_elem(	$2, MYSELF_ST,
945
-												URI_O, 0);
944
+		| MYSELF equalop uri_type	{ $$=mk_elem(	$2, MYSELF_ST,
945
+													$3, 0);
946 946
 								}
947 947
 		| MYSELF equalop SRCIP  { $$=mk_elem(	$2, MYSELF_ST,
948 948
 												SRCIP_O, 0);
... ...
@@ -39,6 +39,7 @@
39 39
  *  2003-05-23  comp_ip fixed, now it will resolve its operand and compare
40 40
  *              the ip with all the addresses (andrei)
41 41
  *  2003-10-10  added more operators support to comp_* (<,>,<=,>=,!=) (andrei)
42
+ *  2004-10-19  added from_uri & to_uri (andrei)
42 43
  */
43 44
 
44 45
  
... ...
@@ -61,6 +62,8 @@
61 61
 #include "ip_addr.h"
62 62
 #include "resolve.h"
63 63
 #include "parser/parse_uri.h"
64
+#include "parser/parse_from.h"
65
+#include "parser/parse_to.h"
64 66
 #include "mem/mem.h"
65 67
 
66 68
 
... ...
@@ -482,6 +485,7 @@ error_op:
482 482
 static int eval_elem(struct expr* e, struct sip_msg* msg)
483 483
 {
484 484
 
485
+	struct sip_uri uri;
485 486
 	int ret;
486 487
 	ret=E_BUG;
487 488
 	
... ...
@@ -517,6 +521,46 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
517 517
 					}
518 518
 				}
519 519
 				break;
520
+		case FROM_URI_O:
521
+				if (parse_from_header(msg)!=0){
522
+					LOG(L_ERR, "ERROR: eval_elem: bad or missing"
523
+								" From: header\n");
524
+					goto error;
525
+				}
526
+				if (e->subtype==MYSELF_ST){
527
+					if (parse_uri(get_from(msg)->uri.s, get_from(msg)->uri.len,
528
+									&uri) < 0){
529
+						LOG(L_ERR, "ERROR: eval_elem: bad uri in From:\n");
530
+						goto error;
531
+					}
532
+					ret=check_self_op(e->op, &uri.host,
533
+										uri.port_no?uri.port_no:SIP_PORT);
534
+				}else{
535
+					ret=comp_strstr(&get_from(msg)->uri,
536
+							e->r.param, e->op, e->subtype);
537
+				}
538
+				break;
539
+		case TO_URI_O:
540
+				if ((msg->to==0) && ((parse_headers(msg, HDR_TO, 0)==-1) ||
541
+							(msg->to==0))){
542
+					LOG(L_ERR, "ERROR: eval_elem: bad or missing"
543
+								" To: header\n");
544
+					goto error;
545
+				}
546
+				/* to content is parsed automatically */
547
+				if (e->subtype==MYSELF_ST){
548
+					if (parse_uri(get_to(msg)->uri.s, get_to(msg)->uri.len,
549
+									&uri) < 0){
550
+						LOG(L_ERR, "ERROR: eval_elem: bad uri in To:\n");
551
+						goto error;
552
+					}
553
+					ret=check_self_op(e->op, &uri.host,
554
+										uri.port_no?uri.port_no:SIP_PORT);
555
+				}else{
556
+					ret=comp_strstr(&get_to(msg)->uri,
557
+										e->r.param, e->op, e->subtype);
558
+				}
559
+				break;
520 560
 		case SRCIP_O:
521 561
 				ret=comp_ip(&msg->rcv.src_ip, e->r.param, e->op, e->subtype);
522 562
 				break;
... ...
@@ -146,6 +146,12 @@ void print_expr(struct expr* exp)
146 146
 			case URI_O:
147 147
 				DBG("uri");
148 148
 				break;
149
+			case FROM_URI_O:
150
+				DBG("from_uri");
151
+				break;
152
+			case TO_URI_O:
153
+				DBG("to_uri");
154
+				break;
149 155
 			case SRCIP_O:
150 156
 				DBG("srcip");
151 157
 				break;
... ...
@@ -55,7 +55,7 @@
55 55
 enum { EXP_T=1, ELEM_T };
56 56
 enum { AND_OP=1, OR_OP, NOT_OP };
57 57
 enum { EQUAL_OP=10, MATCH_OP, GT_OP, LT_OP, GTE_OP, LTE_OP, DIFF_OP, NO_OP };
58
-enum { METHOD_O=1, URI_O, SRCIP_O, SRCPORT_O,
58
+enum { METHOD_O=1, URI_O, FROM_URI_O, TO_URI_O, SRCIP_O, SRCPORT_O,
59 59
 	   DSTIP_O, DSTPORT_O, PROTO_O, AF_O, MSGLEN_O, DEFAULT_O, ACTION_O,
60 60
 	   NUMBER_O};
61 61