[sr-dev] git:pd/websocket: core: added support for WS keyword for use in conditionals with proto and snd_proto

Peter Dunkley peter.dunkley at crocodile-rcs.com
Thu Jun 28 18:58:47 CEST 2012


Module: sip-router
Branch: pd/websocket
Commit: 8c6f700b4213552789fa97c4edf0ff4bb4b61f90
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8c6f700b4213552789fa97c4edf0ff4bb4b61f90

Author: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Date:   Thu Jun 28 17:57:44 2012 +0100

core: added support for WS keyword for use in conditionals with proto and snd_proto

---

 cfg.lex        |    2 ++
 cfg.y          |    9 +++++++--
 ip_addr.h      |    2 +-
 route.c        |    9 +++++++++
 route_struct.h |    3 ++-
 5 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/cfg.lex b/cfg.lex
index a626c8c..b1a0f29 100644
--- 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
--- 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;
diff --git a/ip_addr.h b/ip_addr.h
index dbf6e85..3e23633 100644
--- 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
--- 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;
diff --git a/route_struct.h b/route_struct.h
index b176b9c..9e9b5cb 100644
--- a/route_struct.h
+++ b/route_struct.h
@@ -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;




More information about the sr-dev mailing list