Browse code

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

Peter Dunkley authored on 28/06/2012 16:57:44
Showing 5 changed files
... ...
@@ -525,6 +525,7 @@ UDP			"udp"|"UDP"
525 525
 TCP			"tcp"|"TCP"
526 526
 TLS			"tls"|"TLS"
527 527
 SCTP		"sctp"|"SCTP"
528
+WS		"ws"|"WS"
528 529
 INET		"inet"|"INET"
529 530
 INET6		"inet6"|"INET6"
530 531
 SSLv23			"sslv23"|"SSLv23"|"SSLV23"
... ...
@@ -1163,6 +1164,7 @@ IMPORTFILE      "import_file"
1163 1163
 <INITIAL>{UDP}			{ count(); return UDP; }
1164 1164
 <INITIAL>{TLS}			{ count(); return TLS; }
1165 1165
 <INITIAL>{SCTP}			{ count(); return SCTP; }
1166
+<INITIAL>{WS}			{ count(); return WS; }
1166 1167
 <INITIAL>{INET}			{ count(); yylval.intval=AF_INET;
1167 1168
 							yy_number_str=yytext; return NUMBER; }
1168 1169
 <INITIAL>{INET6}		{ count();
... ...
@@ -391,6 +391,7 @@ extern char *finame;
391 391
 %token TCP
392 392
 %token TLS
393 393
 %token SCTP
394
+%token WS
394 395
 
395 396
 /* config vars. */
396 397
 %token DEBUG_V
... ...
@@ -2203,16 +2204,20 @@ exp_elem:
2203 2203
 	| eint_op error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
2204 2204
 	| PROTO equalop proto %prec EQUAL_T
2205 2205
 		{ $$=mk_elem($2, PROTO_O, 0, NUMBER_ST, (void*)$3 ); }
2206
+	| PROTO equalop WS %prec EQUAL_T
2207
+		{ $$=mk_elem($2, PROTO_O, 0, WEBSOCKET_ST, (void *)PROTO_WS ); }
2206 2208
 	| PROTO equalop rval_expr %prec EQUAL_T
2207 2209
 		{ $$=mk_elem($2, PROTO_O, 0, RVE_ST, $3 ); }
2208 2210
 	| PROTO equalop error
2209
-		{ $$=0; yyerror("protocol expected (udp, tcp, tls or sctp)"); }
2211
+		{ $$=0; yyerror("protocol expected (udp, tcp, tls, sctp, or ws)"); }
2210 2212
 	| SNDPROTO equalop proto %prec EQUAL_T
2211 2213
 		{ $$=mk_elem($2, SNDPROTO_O, 0, NUMBER_ST, (void*)$3 ); }
2214
+	| SNDPROTO equalop WS %prec EQUAL_T
2215
+		{ $$=mk_elem($2, SNDPROTO_O, 0, WEBSOCKET_ST, (void *)PROTO_WS ); }
2212 2216
 	| SNDPROTO equalop rval_expr %prec EQUAL_T
2213 2217
 		{ $$=mk_elem($2, SNDPROTO_O, 0, RVE_ST, $3 ); }
2214 2218
 	| SNDPROTO equalop error
2215
-		{ $$=0; yyerror("protocol expected (udp, tcp, tls or sctp)"); }
2219
+		{ $$=0; yyerror("protocol expected (udp, tcp, tls, sctp, ws)"); }
2216 2220
 	| eip_op strop ipnet %prec EQUAL_T { $$=mk_elem($2, $1, 0, NET_ST, $3); }
2217 2221
 	| eip_op strop rval_expr %prec EQUAL_T {
2218 2222
 			s_tmp.s=0;
... ...
@@ -52,7 +52,7 @@
52 52
 
53 53
 #include "dprint.h"
54 54
 
55
-enum sip_protos { PROTO_NONE, PROTO_UDP, PROTO_TCP, PROTO_TLS, PROTO_SCTP, PROTO_OTHER };
55
+enum sip_protos { PROTO_NONE, PROTO_UDP, PROTO_TCP, PROTO_TLS, PROTO_SCTP, PROTO_OTHER, PROTO_WS /* Deliberately after PROTO_(OTHER|LAST) */ };
56 56
 #define PROTO_LAST PROTO_OTHER
57 57
 
58 58
 #ifdef USE_COMP
... ...
@@ -1231,6 +1231,7 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r,
1231 1231
 	pv_value_t pval;
1232 1232
 	avp_t* avp;
1233 1233
 	int right;
1234
+	struct tcp_connection *con;
1234 1235
 
1235 1236
 	if (unlikely(op==NO_OP)) return !(!left);
1236 1237
 	switch(rtype){
... ...
@@ -1260,6 +1261,14 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r,
1260 1260
 				return (op == DIFF_OP); /* not found or invalid type */
1261 1261
 			}
1262 1262
 			break;
1263
+		case WEBSOCKET_ST:
1264
+			if ((con = tcpconn_get(msg->rcv.proto_reserved1, 0, 0, 0, 0)) != NULL) {
1265
+				if (con->flags & F_CONN_WS)
1266
+					left = PROTO_WS;
1267
+			}
1268
+			right = r->numval;
1269
+			break;
1270
+
1263 1271
 		default:
1264 1272
 			LOG(L_CRIT, "BUG: comp_num: Invalid right operand (%d)\n", rtype);
1265 1273
 			return E_BUG;
... ...
@@ -136,7 +136,8 @@ enum _operand_subtype{
136 136
 		STRING_RVE_ST /* RVE converted to a string (fparam hack) */,
137 137
 		RVE_FREE_FIXUP_ST /* (str)RVE fixed up by a reversable fixup */,
138 138
 		FPARAM_DYN_ST /* temporary only (fparam hack) */,
139
-		CFG_GROUP_ST
139
+		CFG_GROUP_ST,
140
+		WEBSOCKET_ST
140 141
 };
141 142
 
142 143
 typedef enum _expr_l_type expr_l_type;