mirror of
https://github.com/tsl0922/ttyd.git
synced 2025-12-23 20:24:20 +01:00
src: fallback to lws_get_peer_addresses on old libwebsockets
This commit is contained in:
@@ -64,13 +64,12 @@ check_auth(struct lws *wsi, struct pss_http *pss) {
|
|||||||
void access_log(struct lws *wsi, const char *path) {
|
void access_log(struct lws *wsi, const char *path) {
|
||||||
char rip[50];
|
char rip[50];
|
||||||
|
|
||||||
#if LWS_LIBRARY_VERSION_MAJOR >=2 && LWS_LIBRARY_VERSION_MINOR >=4
|
#if LWS_LIBRARY_VERSION_MAJOR > 2 || (LWS_LIBRARY_VERSION_MAJOR ==2 && LWS_LIBRARY_VERSION_MINOR >=4)
|
||||||
struct lws *n_wsi = lws_get_network_wsi(wsi);
|
lws_get_peer_simple(lws_get_network_wsi(wsi), rip, sizeof(rip));
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
lws_get_peer_simple(wsi, rip, sizeof(rip));
|
|
||||||
lwsl_notice("HTTP %s - %s\n", path, rip);
|
lwsl_notice("HTTP %s - %s\n", path, rip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -282,9 +282,6 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason,
|
|||||||
|
|
||||||
pthread_mutex_init(&client->mutex, NULL);
|
pthread_mutex_init(&client->mutex, NULL);
|
||||||
pthread_cond_init(&client->cond, 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);
|
pthread_mutex_lock(&server->mutex);
|
||||||
LIST_INSERT_HEAD(&server->clients, client, list);
|
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);
|
pthread_mutex_unlock(&server->mutex);
|
||||||
|
|
||||||
lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_GET_URI);
|
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;
|
break;
|
||||||
|
|
||||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||||
@@ -411,7 +415,7 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason,
|
|||||||
|
|
||||||
case LWS_CALLBACK_CLOSED:
|
case LWS_CALLBACK_CLOSED:
|
||||||
tty_client_destroy(client);
|
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) {
|
if (server->once && server->client_count == 0) {
|
||||||
lwsl_notice("exiting due to the --once option.\n");
|
lwsl_notice("exiting due to the --once option.\n");
|
||||||
force_exit = true;
|
force_exit = true;
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ struct tty_client {
|
|||||||
bool initialized;
|
bool initialized;
|
||||||
int initial_cmd_index;
|
int initial_cmd_index;
|
||||||
bool authenticated;
|
bool authenticated;
|
||||||
char hostname[100];
|
|
||||||
char address[50];
|
char address[50];
|
||||||
char **args;
|
char **args;
|
||||||
int argc;
|
int argc;
|
||||||
|
|||||||
Reference in New Issue
Block a user