core: added support for WS keyword for use in conditionals with proto and snd_proto
authorPeter Dunkley <peter.dunkley@crocodile-rcs.com>
Thu, 28 Jun 2012 16:57:44 +0000 (17:57 +0100)
committerPeter Dunkley <peter.dunkley@crocodile-rcs.com>
Thu, 28 Jun 2012 16:57:44 +0000 (17:57 +0100)
cfg.lex
cfg.y
ip_addr.h
route.c
route_struct.h

diff --git a/cfg.lex b/cfg.lex
index a626c8c..b1a0f29 100644 (file)
--- a/cfg.lex
+++ b/cfg.lex
@@ -525,6 +525,7 @@ UDP                 "udp"|"UDP"
 TCP                    "tcp"|"TCP"
 TLS                    "tls"|"TLS"
 SCTP           "sctp"|"SCTP"
+WS             "ws"|"WS"
 INET           "inet"|"INET"
 INET6          "inet6"|"INET6"
 SSLv23                 "sslv23"|"SSLv23"|"SSLV23"
@@ -1163,6 +1164,7 @@ IMPORTFILE      "import_file"
 <INITIAL>{UDP}                 { count(); return UDP; }
 <INITIAL>{TLS}                 { count(); return TLS; }
 <INITIAL>{SCTP}                        { count(); return SCTP; }
+<INITIAL>{WS}                  { count(); return WS; }
 <INITIAL>{INET}                        { count(); yylval.intval=AF_INET;
                                                        yy_number_str=yytext; return NUMBER; }
 <INITIAL>{INET6}               { count();
diff --git a/cfg.y b/cfg.y
index cdd03fc..8fdccdc 100644 (file)
--- a/cfg.y
+++ b/cfg.y
@@ -391,6 +391,7 @@ extern char *finame;
 %token TCP
 %token TLS
 %token SCTP
+%token WS
 
 /* config vars. */
 %token DEBUG_V
@@ -2203,16 +2204,20 @@ exp_elem:
        | eint_op error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
        | PROTO equalop proto %prec EQUAL_T
                { $$=mk_elem($2, PROTO_O, 0, NUMBER_ST, (void*)$3 ); }
+       | PROTO equalop WS %prec EQUAL_T
+               { $$=mk_elem($2, PROTO_O, 0, WEBSOCKET_ST, (void *)PROTO_WS ); }
        | PROTO equalop rval_expr %prec EQUAL_T
                { $$=mk_elem($2, PROTO_O, 0, RVE_ST, $3 ); }
        | PROTO equalop error
-               { $$=0; yyerror("protocol expected (udp, tcp, tls or sctp)"); }
+               { $$=0; yyerror("protocol expected (udp, tcp, tls, sctp, or ws)"); }
        | SNDPROTO equalop proto %prec EQUAL_T
                { $$=mk_elem($2, SNDPROTO_O, 0, NUMBER_ST, (void*)$3 ); }
+       | SNDPROTO equalop WS %prec EQUAL_T
+               { $$=mk_elem($2, SNDPROTO_O, 0, WEBSOCKET_ST, (void *)PROTO_WS ); }
        | SNDPROTO equalop rval_expr %prec EQUAL_T
                { $$=mk_elem($2, SNDPROTO_O, 0, RVE_ST, $3 ); }
        | SNDPROTO equalop error
-               { $$=0; yyerror("protocol expected (udp, tcp, tls or sctp)"); }
+               { $$=0; yyerror("protocol expected (udp, tcp, tls, sctp, ws)"); }
        | eip_op strop ipnet %prec EQUAL_T { $$=mk_elem($2, $1, 0, NET_ST, $3); }
        | eip_op strop rval_expr %prec EQUAL_T {
                        s_tmp.s=0;
index dbf6e85..3e23633 100644 (file)
--- a/ip_addr.h
+++ b/ip_addr.h
@@ -52,7 +52,7 @@
 
 #include "dprint.h"
 
-enum sip_protos { PROTO_NONE, PROTO_UDP, PROTO_TCP, PROTO_TLS, PROTO_SCTP, PROTO_OTHER };
+enum sip_protos { PROTO_NONE, PROTO_UDP, PROTO_TCP, PROTO_TLS, PROTO_SCTP, PROTO_OTHER, PROTO_WS /* Deliberately after PROTO_(OTHER|LAST) */ };
 #define PROTO_LAST PROTO_OTHER
 
 #ifdef USE_COMP
diff --git a/route.c b/route.c
index 7990cfd..ca357d3 100644 (file)
--- a/route.c
+++ b/route.c
@@ -1231,6 +1231,7 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r,
        pv_value_t pval;
        avp_t* avp;
        int right;
+       struct tcp_connection *con;
 
        if (unlikely(op==NO_OP)) return !(!left);
        switch(rtype){
@@ -1260,6 +1261,14 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r,
                                return (op == DIFF_OP); /* not found or invalid type */
                        }
                        break;
+               case WEBSOCKET_ST:
+                       if ((con = tcpconn_get(msg->rcv.proto_reserved1, 0, 0, 0, 0)) != NULL) {
+                               if (con->flags & F_CONN_WS)
+                                       left = PROTO_WS;
+                       }
+                       right = r->numval;
+                       break;
+
                default:
                        LOG(L_CRIT, "BUG: comp_num: Invalid right operand (%d)\n", rtype);
                        return E_BUG;
index b176b9c..9e9b5cb 100644 (file)
@@ -136,7 +136,8 @@ enum _operand_subtype{
                STRING_RVE_ST /* RVE converted to a string (fparam hack) */,
                RVE_FREE_FIXUP_ST /* (str)RVE fixed up by a reversable fixup */,
                FPARAM_DYN_ST /* temporary only (fparam hack) */,
-               CFG_GROUP_ST
+               CFG_GROUP_ST,
+               WEBSOCKET_ST
 };
 
 typedef enum _expr_l_type expr_l_type;