From: Shuanglei Tao Date: Tue, 3 Sep 2019 14:29:27 +0000 (+0800) Subject: src: fallback to lws_get_peer_addresses on old libwebsockets X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=671427b15078e626e9d99efaaba87163cc453c75;p=ttyd.git src: fallback to lws_get_peer_addresses on old libwebsockets --- diff --git a/src/http.c b/src/http.c index f0b8666..747965e 100644 --- a/src/http.c +++ b/src/http.c @@ -64,13 +64,12 @@ check_auth(struct lws *wsi, struct pss_http *pss) { void access_log(struct lws *wsi, const char *path) { char rip[50]; -#if LWS_LIBRARY_VERSION_MAJOR >=2 && LWS_LIBRARY_VERSION_MINOR >=4 - struct lws *n_wsi = lws_get_network_wsi(wsi); +#if LWS_LIBRARY_VERSION_MAJOR > 2 || (LWS_LIBRARY_VERSION_MAJOR ==2 && LWS_LIBRARY_VERSION_MINOR >=4) + lws_get_peer_simple(lws_get_network_wsi(wsi), rip, sizeof(rip)); #else - struct lws *n_wsi = wsi; + char name[100]; + lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), name, sizeof(name), rip, sizeof(rip)); #endif - - lws_get_peer_simple(wsi, rip, sizeof(rip)); lwsl_notice("HTTP %s - %s\n", path, rip); } diff --git a/src/protocol.c b/src/protocol.c index 1b373b1..933e1eb 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -282,9 +282,6 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason, pthread_mutex_init(&client->mutex, NULL); pthread_cond_init(&client->cond, NULL); - lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), - client->hostname, sizeof(client->hostname), - client->address, sizeof(client->address)); pthread_mutex_lock(&server->mutex); LIST_INSERT_HEAD(&server->clients, client, list); @@ -292,7 +289,14 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason, pthread_mutex_unlock(&server->mutex); lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_GET_URI); - lwsl_notice("WS %s - %s (%s), clients: %d\n", buf, client->address, client->hostname, server->client_count); + +#if LWS_LIBRARY_VERSION_MAJOR > 2 || (LWS_LIBRARY_VERSION_MAJOR ==2 && LWS_LIBRARY_VERSION_MINOR >=4) + lws_get_peer_simple(lws_get_network_wsi(wsi), client->address, sizeof(client->address)); +#else + char name[100]; + lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), name, sizeof(name), client->address, sizeof(client->address)); +#endif + lwsl_notice("WS %s - %s, clients: %d\n", buf, client->address, server->client_count); break; case LWS_CALLBACK_SERVER_WRITEABLE: @@ -411,7 +415,7 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason, case LWS_CALLBACK_CLOSED: tty_client_destroy(client); - lwsl_notice("WS closed from %s (%s), clients: %d\n", client->address, client->hostname, server->client_count); + lwsl_notice("WS closed from %s, clients: %d\n", client->address, server->client_count); if (server->once && server->client_count == 0) { lwsl_notice("exiting due to the --once option.\n"); force_exit = true; diff --git a/src/server.h b/src/server.h index a8eb20c..3493839 100644 --- a/src/server.h +++ b/src/server.h @@ -31,7 +31,6 @@ struct tty_client { bool initialized; int initial_cmd_index; bool authenticated; - char hostname[100]; char address[50]; char **args; int argc;