- from_uri & to_uri script support (exaclty like uri, from_uri==myself
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Tue, 19 Oct 2004 13:40:05 +0000 (13:40 +0000)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Tue, 19 Oct 2004 13:40:05 +0000 (13:40 +0000)
 or from_uri=~'^sip:[0-9]{7}@' a.s.o)

Makefile.defs
NEWS
cfg.lex
cfg.y
route.c
route_struct.c
route_struct.h

index f127d59..c4aa2bd 100644 (file)
@@ -50,7 +50,7 @@ MAIN_NAME=ser
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   99
-EXTRAVERSION = -dev10
+EXTRAVERSION = -dev11
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
diff --git a/NEWS b/NEWS
index bc700dc..6342b98 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,9 @@ core:
  - new parts:
        UNIX domain socket server implemented
  - changes: 
+    - added from_uri & to_uri: behave exactly like uri but use the
+          "From:"/"To:" uris
+       (e.g.: if (from_uri==myself) ..., if (to_uri=~"^sip:test@")... )
     - config: better escape support in strings (e.g. \", \<cr>, \x0a, \012)
     - bad network addresses are now automatically fixed
       (e.g. 192.168.1.80/27 => 192.168.1.64/27)
diff --git a/cfg.lex b/cfg.lex
index 268493b..1fc2e6f 100644 (file)
--- a/cfg.lex
+++ b/cfg.lex
@@ -50,6 +50,7 @@
  *  2004-05-03  applied multicast support patch from janakj
  *              added MCAST_TTL (andrei)
  *  2004-10-08  more escapes: \", \xHH, \nnn and minor optimizations (andrei)
+ *  2004-10-19  added FROM_URI and TO_URI (andrei)
  */
 
 
@@ -143,6 +144,8 @@ METHOD      method
    call it "uri" from route{} and status from onreply_route{}
 */
 URI            "uri"|"status"
+FROM_URI       "from_uri"
+TO_URI         "to_uri"
 SRCIP  src_ip
 SRCPORT        src_port
 DSTIP  dst_ip
@@ -326,6 +329,8 @@ EAT_ABLE    [\ \t\b\r]
 
 <INITIAL>{METHOD}      { count(); yylval.strval=yytext; return METHOD; }
 <INITIAL>{URI} { count(); yylval.strval=yytext; return URI; }
+<INITIAL>{FROM_URI}    { count(); yylval.strval=yytext; return FROM_URI; }
+<INITIAL>{TO_URI}      { count(); yylval.strval=yytext; return TO_URI; }
 <INITIAL>{SRCIP}       { count(); yylval.strval=yytext; return SRCIP; }
 <INITIAL>{SRCPORT}     { count(); yylval.strval=yytext; return SRCPORT; }
 <INITIAL>{DSTIP}       { count(); yylval.strval=yytext; return DSTIP; }
diff --git a/cfg.y b/cfg.y
index 560dbb9..c7972c5 100644 (file)
--- a/cfg.y
+++ b/cfg.y
@@ -56,6 +56,7 @@
                added MCAST_TTL (andrei)
  * 2004-07-05  src_ip & dst_ip will detect ip addresses between quotes
  *              (andrei)
+ * 2004-10-19  added FROM_URI, TO_URI (andrei)
  */
 
 
@@ -173,6 +174,8 @@ static struct id_list* mk_listen_id(char*, int, int);
 %token ISFLAGSET
 %token METHOD
 %token URI
+%token FROM_URI
+%token TO_URI
 %token SRCIP
 %token SRCPORT
 %token DSTIP
@@ -299,6 +302,7 @@ static struct id_list* mk_listen_id(char*, int, int);
 %type <intval> proto port
 %type <intval> equalop strop intop
 %type <strval> host_sep
+%type <intval> uri_type
 /*%type <route_el> rules;
   %type <route_el> rule;
 */
@@ -840,6 +844,11 @@ strop:     equalop {$$=$1; }
                | MATCH {$$=MATCH_OP; }
                ;
 
+uri_type:      URI                     {$$=URI_O;}
+               |       FROM_URI        {$$=FROM_URI_O;}
+               |       TO_URI          {$$=TO_URI_O;}
+               ;
+
 exp_elem:      METHOD strop STRING     {$$= mk_elem(   $2, STRING_ST, 
                                                                                                        METHOD_O, $3);
                                                                        }
@@ -850,17 +859,17 @@ exp_elem: METHOD strop STRING     {$$= mk_elem(   $2, STRING_ST,
                | METHOD error  { $$=0; yyerror("invalid operator,"
                                                                                "== , !=, or =~ expected");
                                                }
-               | URI strop STRING      {$$ = mk_elem(  $2, STRING_ST,
-                                                                                               URI_O, $3); 
+               | uri_type strop STRING {$$ = mk_elem(  $2, STRING_ST,
+                                                                                               $1, $3); 
                                                                }
-               | URI strop host        {$$ = mk_elem(  $2, STRING_ST,
-                                                                                       URI_O, $3); 
+               | uri_type strop host   {$$ = mk_elem(  $2, STRING_ST,
+                                                                                       $1, $3); 
                                                        }
-               | URI equalop MYSELF    { $$=mk_elem(   $2, MYSELF_ST,
-                                                                                               URI_O, 0);
+               | uri_type equalop MYSELF       { $$=mk_elem(   $2, MYSELF_ST,
+                                                                                                       $1, 0);
                                                                }
-               | URI strop error { $$=0; yyerror("string or MYSELF expected"); }
-               | URI error     { $$=0; yyerror("invalid operator,"
+               | uri_type strop error { $$=0; yyerror("string or MYSELF expected"); }
+               | uri_type error        { $$=0; yyerror("invalid operator,"
                                                                        " == , != or =~ expected");
                                        }
                | SRCPORT intop NUMBER  { $$=mk_elem(   $2, NUMBER_ST,
@@ -941,8 +950,8 @@ exp_elem:   METHOD strop STRING     {$$= mk_elem(   $2, STRING_ST,
                                                                        "expected" ); }
                | DSTIP error { $$=0; 
                                                yyerror("invalid operator, ==, != or =~ expected");}
-               | MYSELF equalop URI    { $$=mk_elem(   $2, MYSELF_ST,
-                                                                                               URI_O, 0);
+               | MYSELF equalop uri_type       { $$=mk_elem(   $2, MYSELF_ST,
+                                                                                                       $3, 0);
                                                                }
                | MYSELF equalop SRCIP  { $$=mk_elem(   $2, MYSELF_ST,
                                                                                                SRCIP_O, 0);
diff --git a/route.c b/route.c
index 09cd70d..b26a8df 100644 (file)
--- a/route.c
+++ b/route.c
@@ -39,6 +39,7 @@
  *  2003-05-23  comp_ip fixed, now it will resolve its operand and compare
  *              the ip with all the addresses (andrei)
  *  2003-10-10  added more operators support to comp_* (<,>,<=,>=,!=) (andrei)
+ *  2004-10-19  added from_uri & to_uri (andrei)
  */
 
  
@@ -61,6 +62,8 @@
 #include "ip_addr.h"
 #include "resolve.h"
 #include "parser/parse_uri.h"
+#include "parser/parse_from.h"
+#include "parser/parse_to.h"
 #include "mem/mem.h"
 
 
@@ -482,6 +485,7 @@ error_op:
 static int eval_elem(struct expr* e, struct sip_msg* msg)
 {
 
+       struct sip_uri uri;
        int ret;
        ret=E_BUG;
        
@@ -517,6 +521,46 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
                                        }
                                }
                                break;
+               case FROM_URI_O:
+                               if (parse_from_header(msg)!=0){
+                                       LOG(L_ERR, "ERROR: eval_elem: bad or missing"
+                                                               " From: header\n");
+                                       goto error;
+                               }
+                               if (e->subtype==MYSELF_ST){
+                                       if (parse_uri(get_from(msg)->uri.s, get_from(msg)->uri.len,
+                                                                       &uri) < 0){
+                                               LOG(L_ERR, "ERROR: eval_elem: bad uri in From:\n");
+                                               goto error;
+                                       }
+                                       ret=check_self_op(e->op, &uri.host,
+                                                                               uri.port_no?uri.port_no:SIP_PORT);
+                               }else{
+                                       ret=comp_strstr(&get_from(msg)->uri,
+                                                       e->r.param, e->op, e->subtype);
+                               }
+                               break;
+               case TO_URI_O:
+                               if ((msg->to==0) && ((parse_headers(msg, HDR_TO, 0)==-1) ||
+                                                       (msg->to==0))){
+                                       LOG(L_ERR, "ERROR: eval_elem: bad or missing"
+                                                               " To: header\n");
+                                       goto error;
+                               }
+                               /* to content is parsed automatically */
+                               if (e->subtype==MYSELF_ST){
+                                       if (parse_uri(get_to(msg)->uri.s, get_to(msg)->uri.len,
+                                                                       &uri) < 0){
+                                               LOG(L_ERR, "ERROR: eval_elem: bad uri in To:\n");
+                                               goto error;
+                                       }
+                                       ret=check_self_op(e->op, &uri.host,
+                                                                               uri.port_no?uri.port_no:SIP_PORT);
+                               }else{
+                                       ret=comp_strstr(&get_to(msg)->uri,
+                                                                               e->r.param, e->op, e->subtype);
+                               }
+                               break;
                case SRCIP_O:
                                ret=comp_ip(&msg->rcv.src_ip, e->r.param, e->op, e->subtype);
                                break;
index 144cafb..3c2f709 100644 (file)
@@ -146,6 +146,12 @@ void print_expr(struct expr* exp)
                        case URI_O:
                                DBG("uri");
                                break;
+                       case FROM_URI_O:
+                               DBG("from_uri");
+                               break;
+                       case TO_URI_O:
+                               DBG("to_uri");
+                               break;
                        case SRCIP_O:
                                DBG("srcip");
                                break;
index aceddf1..b3dec0d 100644 (file)
@@ -55,7 +55,7 @@
 enum { EXP_T=1, ELEM_T };
 enum { AND_OP=1, OR_OP, NOT_OP };
 enum { EQUAL_OP=10, MATCH_OP, GT_OP, LT_OP, GTE_OP, LTE_OP, DIFF_OP, NO_OP };
-enum { METHOD_O=1, URI_O, SRCIP_O, SRCPORT_O,
+enum { METHOD_O=1, URI_O, FROM_URI_O, TO_URI_O, SRCIP_O, SRCPORT_O,
           DSTIP_O, DSTPORT_O, PROTO_O, AF_O, MSGLEN_O, DEFAULT_O, ACTION_O,
           NUMBER_O};