[sr-dev] git:master:c0e687d8: websocket: use signature macro instead of offsetting inside server hdr define

Daniel-Constantin Mierla miconda at gmail.com
Sat May 16 15:23:28 CEST 2020


Module: kamailio
Branch: master
Commit: c0e687d820f9bbf2b6b1ef6892e5b34c30f25a63
URL: https://github.com/kamailio/kamailio/commit/c0e687d820f9bbf2b6b1ef6892e5b34c30f25a63

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-05-16T15:21:43+02:00

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

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

---

Modified: src/modules/websocket/websocket.c
Modified: src/modules/websocket/ws_conn.c
Modified: src/modules/websocket/ws_conn.h
Modified: src/modules/websocket/ws_frame.h
Modified: src/modules/websocket/ws_handshake.c

---

Diff:  https://github.com/kamailio/kamailio/commit/c0e687d820f9bbf2b6b1ef6892e5b34c30f25a63.diff
Patch: https://github.com/kamailio/kamailio/commit/c0e687d820f9bbf2b6b1ef6892e5b34c30f25a63.patch

---

diff --git a/src/modules/websocket/websocket.c b/src/modules/websocket/websocket.c
index 87cf4e3a5f..5cef5d6b1a 100644
--- a/src/modules/websocket/websocket.c
+++ b/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) {
diff --git a/src/modules/websocket/ws_conn.c b/src/modules/websocket/ws_conn.c
index a4442ae0d8..8570afa086 100644
--- a/src/modules/websocket/ws_conn.c
+++ b/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 */
diff --git a/src/modules/websocket/ws_conn.h b/src/modules/websocket/ws_conn.h
index 9319238e4d..f8aa93543c 100644
--- a/src/modules/websocket/ws_conn.h
+++ b/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);
diff --git a/src/modules/websocket/ws_frame.h b/src/modules/websocket/ws_frame.h
index d0f8d84ed0..51a62e04c8 100644
--- a/src/modules/websocket/ws_frame.h
+++ b/src/modules/websocket/ws_frame.h
@@ -49,8 +49,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;
diff --git a/src/modules/websocket/ws_handshake.c b/src/modules/websocket/ws_handshake.c
index 58e6077bb5..878c483f2a 100644
--- a/src/modules/websocket/ws_handshake.c
+++ b/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 */




More information about the sr-dev mailing list