diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-08-07 09:31:24 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-08-07 09:31:24 +0200 |
commit | 57c9f371bc42e35e87e1e9c18b3c6fb09cf41672 (patch) | |
tree | af3a4dfb07861bad2fa53afad5c1f16054256314 /src/plugins/relay | |
parent | 4fa278c2c30d15cbf3dcb8ca36653f2d6cd46cc5 (diff) | |
download | weechat-57c9f371bc42e35e87e1e9c18b3c6fb09cf41672.zip |
relay: use enum type for websocket status in client
Diffstat (limited to 'src/plugins/relay')
-rw-r--r-- | src/plugins/relay/relay-client.c | 24 | ||||
-rw-r--r-- | src/plugins/relay/relay-client.h | 14 |
2 files changed, 25 insertions, 13 deletions
diff --git a/src/plugins/relay/relay-client.c b/src/plugins/relay/relay-client.c index 61cf49b1d..711c26d27 100644 --- a/src/plugins/relay/relay-client.c +++ b/src/plugins/relay/relay-client.c @@ -365,7 +365,7 @@ relay_client_recv_text (struct t_relay_client *client, const char *data) lines[i][length - 1] = '\0'; /* if websocket is initializing */ - if (client->websocket == 1) + if (client->websocket == RELAY_CLIENT_WEBSOCKET_INITIALIZING) { if (lines[i][0]) { @@ -392,7 +392,7 @@ relay_client_recv_text (struct t_relay_client *client, const char *data) handshake, strlen (handshake), NULL); free (handshake); - client->websocket = 2; + client->websocket = RELAY_CLIENT_WEBSOCKET_READY; } } else @@ -524,7 +524,7 @@ relay_client_recv_text_buffer (struct t_relay_client *client, * in case of websocket, we can receive PING from client: * trace this PING in raw buffer and answer with a PONG */ - if (client->websocket == 2) + if (client->websocket == RELAY_CLIENT_WEBSOCKET_READY) { msg_type = (unsigned char)buffer[index]; if (msg_type == RELAY_CLIENT_MSG_PING) @@ -623,7 +623,7 @@ relay_client_recv_cb (const void *pointer, void *data, int fd) * (we will check later with "http_headers" if web socket is * valid or not) */ - client->websocket = 1; + client->websocket = RELAY_CLIENT_WEBSOCKET_INITIALIZING; client->http_headers = weechat_hashtable_new ( 32, WEECHAT_HASHTABLE_STRING, @@ -634,7 +634,7 @@ relay_client_recv_cb (const void *pointer, void *data, int fd) client->bytes_recv += num_read; - if (client->websocket == 2) + if (client->websocket == RELAY_CLIENT_WEBSOCKET_READY) { /* websocket used, decode message */ rc = relay_websocket_decode_frame ((unsigned char *)buffer, @@ -672,7 +672,7 @@ relay_client_recv_cb (const void *pointer, void *data, int fd) length_buffer = decoded_length; } - if ((client->websocket == 1) + if ((client->websocket == RELAY_CLIENT_WEBSOCKET_INITIALIZING) || (client->recv_data_type == RELAY_CLIENT_DATA_TEXT)) { /* websocket initializing or text data for this client */ @@ -1056,7 +1056,7 @@ relay_client_send (struct t_relay_client *client, raw_msg[1] = data; raw_size[1] = data_size; raw_flags[1] |= RELAY_RAW_FLAG_BINARY; - if ((client->websocket == 1) + if ((client->websocket == RELAY_CLIENT_WEBSOCKET_INITIALIZING) || (client->send_data_type == RELAY_CLIENT_DATA_TEXT)) { raw_size[1]--; @@ -1075,13 +1075,13 @@ relay_client_send (struct t_relay_client *client, if ((msg_type == RELAY_CLIENT_MSG_PING) || (msg_type == RELAY_CLIENT_MSG_PONG) || (msg_type == RELAY_CLIENT_MSG_CLOSE) - || ((client->websocket != 1) + || ((client->websocket != RELAY_CLIENT_WEBSOCKET_INITIALIZING) && (client->send_data_type == RELAY_CLIENT_DATA_BINARY))) { /* * set binary flag if we send binary to client - * (except if websocket == 1, which means that websocket is - * initializing, and then we are sending HTTP data, as text) + * (except if websocket is initializing and then we are sending + * HTTP data, as text) */ raw_flags[0] |= RELAY_RAW_FLAG_BINARY; } @@ -1093,7 +1093,7 @@ relay_client_send (struct t_relay_client *client, } /* if websocket is initialized, encode data in a websocket frame */ - if (client->websocket == 2) + if (client->websocket == RELAY_CLIENT_WEBSOCKET_READY) { switch (msg_type) { @@ -1306,7 +1306,7 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server) new_client->ssl = server->ssl; new_client->hook_timer_handshake = NULL; new_client->gnutls_handshake_ok = 0; - new_client->websocket = 0; + new_client->websocket = RELAY_CLIENT_WEBSOCKET_NOT_USED; new_client->http_headers = NULL; new_client->address = strdup ((address && address[0]) ? address : "local"); diff --git a/src/plugins/relay/relay-client.h b/src/plugins/relay/relay-client.h index 67e2b92a4..cd94b8b3f 100644 --- a/src/plugins/relay/relay-client.h +++ b/src/plugins/relay/relay-client.h @@ -49,6 +49,18 @@ enum t_relay_client_data_type RELAY_NUM_CLIENT_DATA_TYPES, }; +/* websocket status */ + +enum t_relay_client_websocket_status +{ + /* 0=not a ws, 1=init ws, 2=ws ready */ + RELAY_CLIENT_WEBSOCKET_NOT_USED = 0, /* no webseocket or not yet init. */ + RELAY_CLIENT_WEBSOCKET_INITIALIZING, /* websocket used, initializing */ + RELAY_CLIENT_WEBSOCKET_READY, /* websocket used, ready */ + /* number of websocket status */ + RELAY_NUM_CLIENT_WEBSOCKET_STATUS, +}; + /* type of message exchanged with the client (used for websockets) */ enum t_relay_client_msg_type @@ -93,7 +105,7 @@ struct t_relay_client gnutls_session_t gnutls_sess; /* gnutls session (only if SSL used) */ struct t_hook *hook_timer_handshake; /* timer for doing gnutls handshake*/ int gnutls_handshake_ok; /* 1 if handshake was done and OK */ - int websocket; /* 0=not a ws, 1=init ws, 2=ws ready */ + enum t_relay_client_websocket_status websocket; /* websocket status */ struct t_hashtable *http_headers; /* HTTP headers for websocket */ char *address; /* string with IP address */ char *real_ip; /* real IP (X-Real-IP HTTP header) */ |