Browse Source

websocket: use signature macro instead of offsetting inside server hdr define

- pass rcv info structure by address
- remove function name from logs

(cherry picked from commit c0e687d820f9bbf2b6b1ef6892e5b34c30f25a63)
(cherry picked from commit 3a288421dbbffca9952200533668a653d6a4c170)
Daniel-Constantin Mierla 5 years ago
parent
commit
6ee76b6f4a

+ 2 - 2
src/modules/websocket/websocket.c

@@ -210,8 +210,8 @@ static int mod_init(void)
 	}
 
 	if(ws_ping_application_data.len < 1 || ws_ping_application_data.len > 125) {
-		ws_ping_application_data.s = DEFAULT_PING_APPLICATION_DATA + 8;
-		ws_ping_application_data.len = DEFAULT_PING_APPLICATION_DATA_LEN - 8;
+		ws_ping_application_data.s = DEFAULT_PING_APPLICATION_DATA;
+		ws_ping_application_data.len = DEFAULT_PING_APPLICATION_DATA_LEN;
 	}
 
 	if(ws_keepalive_mechanism != KEEPALIVE_MECHANISM_NONE) {

+ 6 - 6
src/modules/websocket/ws_conn.c

@@ -184,14 +184,14 @@ void wsconn_destroy(void)
 	}
 }
 
-int wsconn_add(struct receive_info rcv, unsigned int sub_protocol)
+int wsconn_add(struct receive_info *rcv, unsigned int sub_protocol)
 {
 	int cur_cons, max_cons;
-	int id = rcv.proto_reserved1;
+	int id = rcv->proto_reserved1;
 	int id_hash = tcp_id_hash(id);
 	ws_connection_t *wsc;
 
-	LM_DBG("wsconn_add id [%d]\n", id);
+	LM_DBG("connection id [%d]\n", id);
 
 	/* Allocate and fill in new WebSocket connection */
 	wsc = shm_malloc(sizeof(ws_connection_t) + BUF_SIZE + 1);
@@ -203,13 +203,13 @@ int wsconn_add(struct receive_info rcv, unsigned int sub_protocol)
 	wsc->id = id;
 	wsc->id_hash = id_hash;
 	wsc->state = WS_S_OPEN;
-	wsc->rcv = rcv;
+	wsc->rcv = *rcv;
 	wsc->sub_protocol = sub_protocol;
 	wsc->run_event = 0;
 	wsc->frag_buf.s = ((char *)wsc) + sizeof(ws_connection_t);
 	atomic_set(&wsc->refcnt, 0);
 
-	LM_DBG("wsconn_add new wsc => [%p], ref => [%d]\n", wsc,
+	LM_DBG("new wsc => [%p], ref => [%d]\n", wsc,
 			atomic_get(&wsc->refcnt));
 
 	WSCONN_LOCK;
@@ -229,7 +229,7 @@ int wsconn_add(struct receive_info rcv, unsigned int sub_protocol)
 
 	WSCONN_UNLOCK;
 
-	LM_DBG("wsconn_add added to conn_table wsc => [%p], ref => [%d]\n", wsc,
+	LM_DBG("added to conn_table wsc => [%p], ref => [%d]\n", wsc,
 			atomic_get(&wsc->refcnt));
 
 	/* Update connection statistics */

+ 1 - 1
src/modules/websocket/ws_conn.h

@@ -95,7 +95,7 @@ extern stat_var *ws_msrp_max_concurrent_connections;
 
 int wsconn_init(void);
 void wsconn_destroy(void);
-int wsconn_add(struct receive_info rcv, unsigned int sub_protocol);
+int wsconn_add(struct receive_info *rcv, unsigned int sub_protocol);
 int wsconn_rm(ws_connection_t *wsc, ws_conn_eventroute_t run_event_route);
 int wsconn_update(ws_connection_t *wsc);
 void wsconn_close_now(ws_connection_t *wsc);

+ 2 - 2
src/modules/websocket/ws_frame.h

@@ -48,8 +48,8 @@ extern int ws_keepalive_mechanism;
 #define DEFAULT_KEEPALIVE_TIMEOUT 180 /* seconds */
 
 extern str ws_ping_application_data;
-#define DEFAULT_PING_APPLICATION_DATA SERVER_HDR
-#define DEFAULT_PING_APPLICATION_DATA_LEN SERVER_HDR_LEN
+#define DEFAULT_PING_APPLICATION_DATA SRVAPP_SIGNATURE
+#define DEFAULT_PING_APPLICATION_DATA_LEN SRVAPP_SIGNATURE_LEN
 
 extern stat_var *ws_failed_connections;
 extern stat_var *ws_local_closed_connections;

+ 1 - 1
src/modules/websocket/ws_handshake.c

@@ -310,7 +310,7 @@ int ws_handle_handshake(struct sip_msg *msg)
 			(unsigned char *)reply_key.s, base64_enc_len(SHA_DIGEST_LENGTH));
 
 	/* Add the connection to the WebSocket connection table */
-	wsconn_add(msg->rcv, sub_protocol);
+	wsconn_add(&msg->rcv, sub_protocol);
 
 	/* Make sure Kamailio core sends future messages on this connection
 	   directly to this module */