]> prime8.dev >> repos - ttyd.git/commitdiff
src: fallback to lws_get_peer_addresses on old libwebsockets
authorShuanglei Tao <tsl0922@gmail.com>
Tue, 3 Sep 2019 14:29:27 +0000 (22:29 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Tue, 3 Sep 2019 14:29:27 +0000 (22:29 +0800)
src/http.c
src/protocol.c
src/server.h

index f0b86663cc2995eb1a90ffc2256d8d8f8c71ba60..747965e2bb032b84ba394e22ef59d283aa343c1b 100644 (file)
@@ -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);
 }
 
index 1b373b1d0cbb73b99f8ba281610254e4e7f59f75..933e1eba7f52b5b20cca88d1921c3a07dba37a37 100644 (file)
@@ -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;
index a8eb20c3093b875e42de3f088e1736e5e1cbd125..34938397be763fc864793c97b3de4b019782e757 100644 (file)
@@ -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;