You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.3 KiB

  1. From f7c171ffbe2d7677af4974a235ed3ccb7b3ba8c8 Mon Sep 17 00:00:00 2001
  2. From: Shuanglei Tao <tsl0922@gmail.com>
  3. Date: Tue, 28 Jul 2020 22:55:01 +0800
  4. Subject: [PATCH 2/7] protocol: fix request path for h2
  5. ---
  6. src/protocol.c | 12 +++++++-----
  7. src/server.h | 1 +
  8. 2 files changed, 8 insertions(+), 5 deletions(-)
  9. diff --git a/src/protocol.c b/src/protocol.c
  10. index fa96b6b..1be0a4e 100644
  11. --- a/src/protocol.c
  12. +++ b/src/protocol.c
  13. @@ -236,8 +236,12 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,
  14. lwsl_warn("refuse to serve WS client due to the --max-clients option.\n");
  15. return 1;
  16. }
  17. - if (lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_GET_URI) <= 0 ||
  18. - strcmp(buf, endpoints.ws) != 0) {
  19. +
  20. + n = lws_hdr_copy(wsi, pss->path, sizeof(pss->path), WSI_TOKEN_GET_URI);
  21. +#if defined(LWS_ROLE_H2)
  22. + if (n <= 0) n = lws_hdr_copy(wsi, pss->path, sizeof(pss->path), WSI_TOKEN_HTTP_COLON_PATH);
  23. +#endif
  24. + if (strncmp(pss->path, endpoints.ws, n) != 0) {
  25. lwsl_warn("refuse to serve WS client for illegal ws path: %s\n", buf);
  26. return 1;
  27. }
  28. @@ -276,8 +280,6 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,
  29. LIST_INSERT_HEAD(&server->procs, proc, entry);
  30. server->client_count++;
  31. - lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_GET_URI);
  32. -
  33. #if LWS_LIBRARY_VERSION_NUMBER >= 2004000
  34. lws_get_peer_simple(lws_get_network_wsi(wsi), pss->address, sizeof(pss->address));
  35. #else
  36. @@ -285,7 +287,7 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,
  37. lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), name, sizeof(name), pss->address,
  38. sizeof(pss->address));
  39. #endif
  40. - lwsl_notice("WS %s - %s, clients: %d\n", buf, pss->address, server->client_count);
  41. + lwsl_notice("WS %s - %s, clients: %d\n", pss->path, pss->address, server->client_count);
  42. break;
  43. case LWS_CALLBACK_SERVER_WRITEABLE:
  44. diff --git a/src/server.h b/src/server.h
  45. index 116d9b9..167ea8b 100644
  46. --- a/src/server.h
  47. +++ b/src/server.h
  48. @@ -57,6 +57,7 @@ struct pss_tty {
  49. int initial_cmd_index;
  50. bool authenticated;
  51. char address[50];
  52. + char path[20];
  53. struct lws *wsi;
  54. char *buffer;
  55. --
  56. 2.20.1