{"schema":"libjg2-1",
"vpath":"/git/",
"avatar":"/git/avatar/",
"alang":"",
"gen_ut":1750391997,
"reponame":"libwebsockets",
"desc":"libwebsockets lightweight C networking library",
"owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets",
"f":3,
"items": [
{"schema":"libjg2-1",
"cid":"13b22f899cbfee0bd669c7ce093d2256",
"commit": {"type":"commit",
"time": 1512099456,
"time_ofs": 480,
"oid_tree": { "oid": "09d7303863b408ee13487943b062d721d1dacef1", "alias": []},
"oid":{ "oid": "91a821c7938413e16f51938e0a0847bcea865881", "alias": []},
"msg": "esp32: align with esp-idf changes",
"sig_commit": { "git_time": { "time": 1512099456, "offset": 480 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },
"sig_author": { "git_time": { "time": 1511492099, "offset": 480 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }},
"body": "esp32: align with esp-idf changes\n\nLWIP_SOCKET_OFFSET is now nonzero, which I handled a while back.\n\nBut the C api support for it is broken in esp-idf.\n\nselect() takes unmodified fds, but FD_SET / FD_ISSET etc must have the\noffset subtracted on their args.\n\nWith this we are working on current HEAD esp-idf."
,
"diff": "diff --git a/component.mk b/component.mk\nindex 9afdeb6..9b5235e 100644\n--- a/component.mk\n+++ b/component.mk\n@@ -19,12 +19,12 @@ endif\n build:\n \tcd $(COMPONENT_BUILD_DIR) ; \u005c\n \techo \u0022doing lws cmake\u0022 ; \u005c\n-\tcmake $(COMPONENT_PATH) -DLWS_C_FLAGS\u003d\u0022$(CFLAGS) -DNDEBUG\u003d1\u0022 \u005c\n+\tcmake $(COMPONENT_PATH) -DLWS_C_FLAGS\u003d\u0022$(CFLAGS) \u0022 \u005c\n \t\t-DIDF_PATH\u003d$(IDF_PATH) \u005c\n \t\t-DCROSS_PATH\u003d$(CROSS_PATH) \u005c\n \t\t-DBUILD_DIR_BASE\u003d$(BUILD_DIR_BASE) \u005c\n \t\t-DCMAKE_TOOLCHAIN_FILE\u003d$(COMPONENT_PATH)/contrib/cross-esp32.cmake \u005c\n-\t\t-DCMAKE_BUILD_TYPE\u003dRELEASE \u005c\n+\t\t-DCMAKE_BUILD_TYPE\u003dDEBUG \u005c\n \t\t-DLWS_MBEDTLS_INCLUDE_DIRS\u003d\u0022${IDF_PATH}/components/openssl/include;${IDF_PATH}/components/mbedtls/include;${IDF_PATH}/components/mbedtls/port/include\u0022 \u005c\n \t\t-DLWS_WITH_STATS\u003d0 \u005c\n \t\t-DLWS_WITH_HTTP2\u003d1 \u005c\ndiff --git a/lib/alloc.c b/lib/alloc.c\nindex 2060aac..a7baca9 100644\n--- a/lib/alloc.c\n+++ b/lib/alloc.c\n@@ -51,7 +51,7 @@ void lws_set_allocator(void *(*cb)(void *ptr, size_t size, const char *reason))\n static void *_realloc(void *ptr, size_t size, const char *reason)\n {\n \tif (size) {\n-#if defined(LWS_PLAT_ESP32)\n+#if defined(LWS_WITH_ESP32)\n \t\tlwsl_notice(\u0022%s: size %lu: %s\u005cn\u0022, __func__,\n \t\t\t (unsigned long)size, reason);\n #else\ndiff --git a/lib/handshake.c b/lib/handshake.c\nindex a2f8933..e5a024b 100644\n--- a/lib/handshake.c\n+++ b/lib/handshake.c\n@@ -63,7 +63,7 @@ LWS_VISIBLE int\n lws_read(struct lws *wsi, unsigned char *buf, lws_filepos_t len)\n {\n \tunsigned char *last_char, *oldbuf \u003d buf;\n-\tlws_filepos_t body_chunk_len, inlen \u003d len;\n+\tlws_filepos_t body_chunk_len;\n \tsize_t n;\n \n \tswitch (wsi-\u003estate) {\n@@ -105,7 +105,7 @@ lws_read(struct lws *wsi, unsigned char *buf, lws_filepos_t len)\n \t\t\tbuf +\u003d body_chunk_len;\n \t\t\tlen -\u003d body_chunk_len;\n \t\t}\n-\t\tlwsl_debug(\u0022%s: used up block of %d\u005cn\u0022, __func__, (int)inlen);\n+\t\tlwsl_debug(\u0022%s: used up block\u005cn\u0022, __func__);\n \t\tbreak;\n #endif\n \n@@ -271,7 +271,7 @@ postbody_completion:\n \t\tbreak;\n \tdefault:\n \t\tlwsl_err(\u0022%s: Unhandled state %d\u005cn\u0022, __func__, wsi-\u003estate);\n-\t\tbreak;\n+\t\tgoto bail;\n \t}\n \n read_ok:\ndiff --git a/lib/http2/hpack.c b/lib/http2/hpack.c\nindex 70aff4a..f7fe9d3 100644\n--- a/lib/http2/hpack.c\n+++ b/lib/http2/hpack.c\n@@ -594,12 +594,17 @@ lws_hpack_dynamic_size(struct lws *wsi, int size)\n \tdyn \u003d \u0026nwsi-\u003eh2.h2n-\u003ehpack_dyn_table;\n \tlwsl_info(\u0022%s: from %d to %d, lim %d\u005cn\u0022, __func__,\n \t\t (int)dyn-\u003enum_entries, size,\n-\t\t nwsi-\u003eh2.h2n-\u003eset.s[H2SET_HEADER_TABLE_SIZE]);\n+\t\t nwsi-\u003evhost-\u003eset.s[H2SET_HEADER_TABLE_SIZE]);\n \n-\tif (size \u003e (int)nwsi-\u003eh2.h2n-\u003eset.s[H2SET_HEADER_TABLE_SIZE]) {\n+\tif (size \u003e (int)nwsi-\u003evhost-\u003eset.s[H2SET_HEADER_TABLE_SIZE]) {\n+\t\tlwsl_notice(\u0022rejecting hpack dyn size %u\u005cn\u0022, size);\n+#if defined(LWS_WITH_ESP32)\n+\t\tsize \u003d nwsi-\u003evhost-\u003eset.s[H2SET_HEADER_TABLE_SIZE];\n+#else\n \t\tlws_h2_goaway(nwsi, H2_ERR_COMPRESSION_ERROR,\n \t\t\t\u0022Asked for header table bigger than we told\u0022);\n \t\tgoto bail;\n+#endif\n \t}\n \n \tdyn-\u003evirtual_payload_max \u003d size;\n@@ -615,6 +620,8 @@ lws_hpack_dynamic_size(struct lws *wsi, int size)\n \tif (dyn-\u003enum_entries \u003c min)\n \t\tmin \u003d dyn-\u003enum_entries;\n \n+\t// lwsl_notice(\u0022dte requested size %d\u005cn\u0022, size);\n+\n \tdte \u003d lws_zalloc(sizeof(*dte) * (size + 1), \u0022dynamic table entries\u0022);\n \tif (!dte)\n \t\tgoto bail;\ndiff --git a/lib/http2/http2.c b/lib/http2/http2.c\nindex e69bb0d..cdbf502 100644\n--- a/lib/http2/http2.c\n+++ b/lib/http2/http2.c\n@@ -540,7 +540,7 @@ int lws_h2_do_pps_send(struct lws *wsi)\n \tcase LWS_H2_PPS_MY_SETTINGS:\n \t\t/*\n \t\t * if any of our settings varies from h2 \u0022default defaults\u0022\n-\t\t * then we must inform the perr\n+\t\t * then we must inform the peer\n \t\t */\n \t\tfor (n \u003d 1; n \u003c H2SET_COUNT; n++)\n \t\t\tif (h2n-\u003eset.s[n] !\u003d lws_h2_defaults.s[n]) {\n@@ -691,7 +691,7 @@ bail:\n \n /*\n * The frame header part has just completely arrived.\n- * Perform actions for frame completion.\n+ * Perform actions for header completion.\n */\n static int\n lws_h2_parse_frame_header(struct lws *wsi)\n@@ -1488,6 +1488,8 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen,\n \t\t\th2n-\u003einside +\u003d n;\n \t\t\th2n-\u003ecount +\u003d n - 1;\n \n+\t\t\tlwsl_notice(\u0022%s: count %d len %d\u005cn\u0022, __func__, (int)h2n-\u003ecount, (int)h2n-\u003elength);\n+\n \t\t\tbreak;\n \n \t\tcase LWS_H2_FRAME_TYPE_PRIORITY:\ndiff --git a/lib/libwebsockets.c b/lib/libwebsockets.c\nindex 90120ee..b1c3ff3 100644\n--- a/lib/libwebsockets.c\n+++ b/lib/libwebsockets.c\n@@ -741,7 +741,6 @@ just_kill_connection:\n \n \tif (wsi-\u003eprotocol \u0026\u0026 !wsi-\u003etold_user_closed \u0026\u0026 wsi-\u003eprotocol-\u003ecallback \u0026\u0026\n \t wsi-\u003emode !\u003d LWSCM_RAW \u0026\u0026 (wsi-\u003estate_pre_close \u0026 _LSF_CCB)) {\n-\t\tlwsl_debug(\u0022calling back CLOSED %d %d\u005cn\u0022, wsi-\u003emode, wsi-\u003estate);\n \t\twsi-\u003eprotocol-\u003ecallback(wsi, LWS_CALLBACK_CLOSED,\n \t\t\t\t\twsi-\u003euser_space, NULL, 0);\n \t} else if (wsi-\u003emode \u003d\u003d LWSCM_HTTP_SERVING_ACCEPTED) {\ndiff --git a/lib/libwebsockets.h b/lib/libwebsockets.h\nindex a695b66..f8d5705 100644\n--- a/lib/libwebsockets.h\n+++ b/lib/libwebsockets.h\n@@ -658,6 +658,8 @@ struct lws_esp32 {\n \tvoid *scan_consumer_arg;\n \tstruct lws_group_member *first;\n \tint extant_group_members;\n+\n+\tvolatile char button_is_down;\n };\n \n struct lws_esp32_image {\ndiff --git a/lib/plat/lws-plat-esp32.c b/lib/plat/lws-plat-esp32.c\nindex efc1291..4344ebd 100644\n--- a/lib/plat/lws-plat-esp32.c\n+++ b/lib/plat/lws-plat-esp32.c\n@@ -1,5 +1,5 @@\n /*\n- * libwebsockets - small server side websockets and web server implementation\n+ * libwebsockets - lib/plat/lws-plat-esp32.c\n *\n * Copyright (C) 2010-2017 Andy Green \u003candy@warmcat.com\u003e\n *\n@@ -24,6 +24,11 @@\n #include \u003cesp_attr.h\u003e\n #include \u003cesp_system.h\u003e\n \n+#include \u0022apps/sntp/sntp.h\u0022\n+\n+#include \u003clwip/sockets.h\u003e\n+#include \u003cesp_task_wdt.h\u003e\n+\n int\n lws_plat_socket_offset(void)\n {\n@@ -72,18 +77,20 @@ lws_send_pipe_choked(struct lws *wsi)\n #if defined(LWS_WITH_HTTP2)\n \twsi_eff \u003d lws_get_network_wsi(wsi);\n #endif\n+\tint n;\n \n \t/* treat the fact we got a truncated send pending as if we're choked */\n \tif (wsi_eff-\u003etrunc_len)\n \t\treturn 1;\n \n \tFD_ZERO(\u0026writefds);\n-\tFD_SET(wsi_eff-\u003edesc.sockfd, \u0026writefds);\n+\tFD_SET(wsi_eff-\u003edesc.sockfd - LWIP_SOCKET_OFFSET, \u0026writefds);\n \n-\tif (select(wsi_eff-\u003edesc.sockfd + 1, NULL, \u0026writefds, NULL, \u0026tv) \u003c 1)\n-\t\treturn 1;\n+\tn \u003d select(wsi_eff-\u003edesc.sockfd + 1, NULL, \u0026writefds, NULL, \u0026tv);\n+\tif (n \u003c 0)\n+\t\treturn 1; /* choked */\n \n-\treturn 0;\n+\treturn !n; /* n \u003d 0 \u003d not writable \u003d choked */\n }\n \n LWS_VISIBLE int\n@@ -93,7 +100,7 @@ lws_poll_listen_fd(struct lws_pollfd *fd)\n \tstruct timeval tv \u003d { 0, 0 };\n \n \tFD_ZERO(\u0026readfds);\n-\tFD_SET(fd-\u003efd, \u0026readfds);\n+\tFD_SET(fd-\u003efd - LWIP_SOCKET_OFFSET, \u0026readfds);\n \n \treturn select(fd-\u003efd + 1, \u0026readfds, NULL, NULL, \u0026tv);\n }\n@@ -139,16 +146,16 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)\n \t\tgoto faked_service;\n \n \tif (!context-\u003eservice_tid_detected) {\n-\t\tstruct lws _lws;\n+\t\tstruct lws *_lws \u003d lws_zalloc(sizeof(*_lws), \u0022tid probe\u0022);\n \n-\t\tmemset(\u0026_lws, 0, sizeof(_lws));\n-\t\t_lws.context \u003d context;\n+\t\t_lws-\u003econtext \u003d context;\n \n \t\tcontext-\u003eservice_tid_detected \u003d\n \t\t\tcontext-\u003evhost_list-\u003eprotocols[0].callback(\n-\t\t\t\u0026_lws, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);\n+\t\t\t_lws, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);\n \t\tcontext-\u003eservice_tid \u003d context-\u003eservice_tid_detected;\n \t\tcontext-\u003eservice_tid_detected \u003d 1;\n+\t\tlws_free(_lws);\n \t}\n \n \t/*\n@@ -178,24 +185,35 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)\n \t\t\tif (pt-\u003efds[n].fd \u003e\u003d max_fd)\n \t\t\t\tmax_fd \u003d pt-\u003efds[n].fd;\n \t\t\tif (pt-\u003efds[n].events \u0026 LWS_POLLIN)\n-\t\t\t\tFD_SET(pt-\u003efds[n].fd, \u0026readfds);\n+\t\t\t\tFD_SET(pt-\u003efds[n].fd - LWIP_SOCKET_OFFSET, \u0026readfds);\n \t\t\tif (pt-\u003efds[n].events \u0026 LWS_POLLOUT)\n-\t\t\t\tFD_SET(pt-\u003efds[n].fd, \u0026writefds);\n-\t\t\tFD_SET(pt-\u003efds[n].fd, \u0026errfds);\n+\t\t\t\tFD_SET(pt-\u003efds[n].fd - LWIP_SOCKET_OFFSET, \u0026writefds);\n+\t\t\tFD_SET(pt-\u003efds[n].fd - LWIP_SOCKET_OFFSET, \u0026errfds);\n \t\t}\n \n \t\tn \u003d select(max_fd + 1, \u0026readfds, \u0026writefds, \u0026errfds, ptv);\n-\t\tfor (n \u003d 0; n \u003c pt-\u003efds_count; n++) {\n-\t\t\tif (FD_ISSET(pt-\u003efds[n].fd, \u0026readfds))\n-\t\t\t\tpt-\u003efds[n].revents |\u003d LWS_POLLIN;\n-\t\t\tif (FD_ISSET(pt-\u003efds[n].fd, \u0026writefds))\n-\t\t\t\tpt-\u003efds[n].revents |\u003d LWS_POLLOUT;\n-\t\t\tif (FD_ISSET(pt-\u003efds[n].fd, \u0026errfds))\n-\t\t\t\tpt-\u003efds[n].revents |\u003d LWS_POLLHUP;\n+\t\tn \u003d 0;\n+\t\tfor (m \u003d 0; m \u003c pt-\u003efds_count; m++) {\n+\t\t\tc \u003d 0;\n+\t\t\tif (FD_ISSET(pt-\u003efds[m].fd - LWIP_SOCKET_OFFSET, \u0026readfds)) {\n+\t\t\t\tpt-\u003efds[m].revents |\u003d LWS_POLLIN;\n+\t\t\t\tc \u003d 1;\n+\t\t\t}\n+\t\t\tif (FD_ISSET(pt-\u003efds[m].fd - LWIP_SOCKET_OFFSET, \u0026writefds)) {\n+\t\t\t\tpt-\u003efds[m].revents |\u003d LWS_POLLOUT;\n+\t\t\t\tc \u003d 1;\n+\t\t\t}\n+\t\t\tif (FD_ISSET(pt-\u003efds[m].fd - LWIP_SOCKET_OFFSET, \u0026errfds)) {\n+\t\t\t\t// lwsl_notice(\u0022errfds %d\u005cn\u0022, pt-\u003efds[m].fd);\n+\t\t\t\tpt-\u003efds[m].revents |\u003d LWS_POLLHUP;\n+\t\t\t\tc \u003d 1;\n+\t\t\t}\n+\n+\t\t\tif (c)\n+\t\t\t\tn++;\n \t\t}\n \t}\n \n-\n #ifdef LWS_OPENSSL_SUPPORT\n \tif (!pt-\u003erx_draining_ext_list \u0026\u0026\n \t !lws_ssl_anybody_has_buffered_read_tsi(context, tsi) \u0026\u0026 !n) {\n@@ -245,7 +263,12 @@ lws_plat_check_connection_error(struct lws *wsi)\n LWS_VISIBLE int\n lws_plat_service(struct lws_context *context, int timeout_ms)\n {\n-\treturn _lws_plat_service_tsi(context, timeout_ms, 0);\n+\tint n \u003d _lws_plat_service_tsi(context, timeout_ms, 0);\n+\n+\tlws_service_fd_tsi(context, NULL, 0);\n+\tesp_task_wdt_reset();\n+\n+\treturn n;\n }\n \n LWS_VISIBLE int\n@@ -627,41 +650,46 @@ struct lws_esp32 lws_esp32 \u003d {\n */\n \n enum lws_gapss {\n-\tLWS_GAPSS_INITIAL,\t/* just started up, init and move to LWS_GAPSS_SCAN */\n+\tLWS_GAPSS_INITIAL,\t/* just started up, init and move to\n+\t\t\t\t * LWS_GAPSS_SCAN */\n \tLWS_GAPSS_SCAN,\t\t/*\n-\t\t\t\t * Unconnected, scanning: AP known in one of the config\n-\t\t\t\t * slots -\u003e configure it, start timeout + LWS_GAPSS_STAT,\n-\t\t\t\t * if no AP already up in same group with lower MAC,\n-\t\t\t\t * after a random period start up our AP (LWS_GAPSS_AP)\n+\t\t\t\t * Unconnected, scanning: AP known in one of the\n+\t\t\t\t * config slots -\u003e configure it, start timeout +\n+\t\t\t\t * LWS_GAPSS_STAT, if no AP already up in same\n+\t\t\t\t * group with lower MAC, after a random period\n+\t\t\t\t * start up our AP (LWS_GAPSS_AP)\n \t\t\t\t */\n \tLWS_GAPSS_AP,\t\t/*\n-\t\t\t\t * Trying to be the group AP... periodically do a scan\n-\t\t\t\t * LWS_GAPSS_AP_SCAN, faster and then slower\n+\t\t\t\t * Trying to be the group AP... periodically do\n+\t\t\t\t * a scan LWS_GAPSS_AP_SCAN, faster and then\n+\t\t\t\t * slower\n \t\t\t\t */\n \tLWS_GAPSS_AP_SCAN,\t/*\n-\t\t\t\t * doing a scan while trying to be the group AP... if\n-\t\t\t\t * we see a lower MAC being the AP for the same group\n-\t\t\t\t * AP, abandon being an AP and join that AP as a\n-\t\t\t\t * station\n+\t\t\t\t * doing a scan while trying to be the group\n+\t\t\t\t * AP... if we see a lower MAC being the AP for\n+\t\t\t\t * the same group AP, abandon being an AP and\n+\t\t\t\t * join that AP as a station\n \t\t\t\t */\n \tLWS_GAPSS_STAT_GRP_AP,\t/*\n-\t\t\t\t * We have decided to join another group member who is\n-\t\t\t\t * being the AP, as its MAC is lower than ours. This\n-\t\t\t\t * is a stable state, but we still do periodic scans\n-\t\t\t\t * (LWS_GAPSS_STAT_GRP_AP_SCAN) and will always prefer\n-\t\t\t\t * an AP configured in a slot.\n+\t\t\t\t * We have decided to join another group member\n+\t\t\t\t * who is being the AP, as its MAC is lower than\n+\t\t\t\t * ours. This is a stable state, but we still\n+\t\t\t\t * do periodic scans LWS_GAPSS_STAT_GRP_AP_SCAN\n+\t\t\t\t * and will always prefer an AP configured in a\n+\t\t\t\t * slot.\n \t\t\t\t */\n \tLWS_GAPSS_STAT_GRP_AP_SCAN,\n \t\t\t\t/*\n-\t\t\t\t * We have joined a group member who is doing the AP\n-\t\t\t\t * job... we want to check every now and then if a\n-\t\t\t\t * configured AP has appeared that we should better\n-\t\t\t\t * use instead. Otherwise stay in LWS_GAPSS_STAT_GRP_AP\n+\t\t\t\t * We have joined a group member who is doing\n+\t\t\t\t * the AP job... we want to check every now and\n+\t\t\t\t * then if a configured AP has appeared that we\n+\t\t\t\t * should better use instead. Otherwise stay in\n+\t\t\t\t * LWS_GAPSS_STAT_GRP_AP\n \t\t\t\t */\n \tLWS_GAPSS_STAT,\t\t/*\n-\t\t\t\t * trying to connect to another non-group AP. If we\n-\t\t\t\t * don't get an IP within a timeout and retries,\n-\t\t\t\t * blacklist it and go back \n+\t\t\t\t * trying to connect to another non-group AP.\n+\t\t\t\t * If we don't get an IP within a timeout and\n+\t\t\t\t * retries, blacklist it and go back\n \t\t\t\t */\n \tLWS_GAPSS_STAT_HAPPY,\n };\n@@ -684,7 +712,6 @@ static TimerHandle_t leds_timer, scan_timer, debounce_timer\n #endif\n ;\n static enum lws_gapss gapss \u003d LWS_GAPSS_INITIAL;\n-static char bdown;\n \n #define GPIO_SW 14\n \n@@ -932,19 +959,20 @@ lws_esp32_button(int down)\n void IRAM_ATTR\n gpio_irq(void *arg)\n {\n-\tbdown ^\u003d 1;\n \tgpio_set_intr_type(GPIO_SW, GPIO_INTR_DISABLE);\n \txTimerStart(debounce_timer, 0);\n-\n-\tlws_esp32_button(bdown);\n }\n \n static void lws_esp32_debounce_timer_cb(TimerHandle_t th)\n {\n-\tif (bdown)\n+\tif (lws_esp32.button_is_down)\n \t\tgpio_set_intr_type(GPIO_SW, GPIO_INTR_POSEDGE);\n \telse\n \t\tgpio_set_intr_type(GPIO_SW, GPIO_INTR_NEGEDGE);\n+\n+\tlws_esp32.button_is_down \u003d gpio_get_level(GPIO_SW);\n+\n+\tlws_esp32_button(lws_esp32.button_is_down);\n }\n \n \n@@ -978,7 +1006,7 @@ end_scan()\n \tint n, m;\n \n \tcount_ap_records \u003d ARRAY_SIZE(ap_records);\n-\tif (esp_wifi_scan_get_ap_records(\u0026count_ap_records, ap_records) !\u003d ESP_OK) {\n+\tif (esp_wifi_scan_get_ap_records(\u0026count_ap_records, ap_records)) {\n \t\tlwsl_err(\u0022%s: failed\u005cn\u0022, __func__);\n \t\treturn;\n \t}\n@@ -1005,13 +1033,15 @@ end_scan()\n \t\tif (!lws_esp32.ssid[(n + try_slot + 1) \u0026 3][0])\n \t\t\tcontinue;\n \n-\t\tlwsl_notice(\u0022looking for %s\u005cn\u0022, lws_esp32.ssid[(n + try_slot + 1) \u0026 3]);\n+\t\tlwsl_notice(\u0022looking for %s\u005cn\u0022,\n+\t\t\t lws_esp32.ssid[(n + try_slot + 1) \u0026 3]);\n \n \t\t/* this ssid appears in scan results? */\n \n \t\tfor (m \u003d 0; m \u003c count_ap_records; m++) {\n \t\t\t// lwsl_notice(\u0022 %s\u005cn\u0022, ap_records[m].ssid);\n-\t\t\tif (strcmp((char *)ap_records[m].ssid, lws_esp32.ssid[(n + try_slot + 1) \u0026 3]) \u003d\u003d 0)\n+\t\t\tif (!strcmp((char *)ap_records[m].ssid,\n+\t\t\t\t lws_esp32.ssid[(n + try_slot + 1) \u0026 3]))\n \t\t\t\tgoto hit;\n \t\t}\n \n@@ -1027,10 +1057,13 @@ hit:\n \t\t\t\tsizeof(lws_esp32.active_ssid) - 1);\n \t\tlws_esp32.active_ssid[sizeof(lws_esp32.active_ssid) - 1] \u003d '\u005c0';\n \n-\t\tstrncpy((char *)sta_config.sta.ssid, lws_esp32.ssid[m], sizeof(sta_config.sta.ssid) - 1);\n-\t\tstrncpy((char *)sta_config.sta.password, lws_esp32.password[m], sizeof(sta_config.sta.password) - 1);\n+\t\tstrncpy((char *)sta_config.sta.ssid, lws_esp32.ssid[m],\n+\t\t\tsizeof(sta_config.sta.ssid) - 1);\n+\t\tstrncpy((char *)sta_config.sta.password, lws_esp32.password[m],\n+\t\t\tsizeof(sta_config.sta.password) - 1);\n \n-\t\ttcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, (const char *)\u0026config.ap.ssid[7]);\n+\t\ttcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA,\n+\t\t\t\t\t (const char *)\u0026config.ap.ssid[7]);\n \t\tlws_gapss_to(LWS_GAPSS_STAT);\n \n \t\tesp_wifi_set_config(WIFI_IF_STA, \u0026sta_config);\n@@ -1043,7 +1076,8 @@ hit:\n \n passthru:\n \tif (lws_esp32.scan_consumer)\n-\t\tlws_esp32.scan_consumer(count_ap_records, ap_records, lws_esp32.scan_consumer_arg);\n+\t\tlws_esp32.scan_consumer(count_ap_records, ap_records,\n+\t\t\t\t\tlws_esp32.scan_consumer_arg);\n \n }\n \n@@ -1120,6 +1154,8 @@ esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event)\n \t\t/* fallthru */\n \tcase SYSTEM_EVENT_STA_DISCONNECTED:\n \t\tlwsl_notice(\u0022SYSTEM_EVENT_STA_DISCONNECTED\u005cn\u0022);\n+\t\tif (sntp_enabled())\n+\t\t\tsntp_stop();\n \t\tlws_esp32.conn_ap \u003d 0;\n \t\tlws_esp32.inet \u003d 0;\n \t\tlws_esp32.sta_ip[0] \u003d '\u005c0';\n@@ -1203,7 +1239,8 @@ esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event)\n \t\t\t}\n \n \t\t\tif (!mem) {\n-\t\t\t\tstruct lws_group_member *mem \u003d lws_malloc(sizeof(*mem), \u0022group\u0022);\n+\t\t\t\tstruct lws_group_member *mem \u003d\n+\t\t\t\t\t lws_malloc(sizeof(*mem), \u0022group\u0022);\n \t\t\t\tif (mem) {\n \t\t\t\t\tmem-\u003elast_seen \u003d ~(uint64_t)0;\n \t\t\t\t\tstrcpy(mem-\u003emodel, lws_esp32.model);\n@@ -1211,27 +1248,35 @@ esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event)\n \t\t\t\t\tstrcpy(mem-\u003ehost, lws_esp32.hostname);\n \t\t\t\t\tstrcpy(mem-\u003emac, lws_esp32.mac);\n \t\t\t\t\tmem-\u003eflags \u003d LWS_GROUP_FLAG_SELF;\n-\t\t\t\t\tlws_get_iframe_size(\u0026mem-\u003ewidth, \u0026mem-\u003eheight);\n-\t\t\t\t\tmemcpy(\u0026mem-\u003eaddr, \u0026event-\u003eevent_info.got_ip.ip_info.ip,\n-\t\t\t\t\t\t\tsizeof(mem-\u003eaddr));\n-\t\t\t\t\tmemcpy(\u0026mem-\u003eaddrv6, \u0026event-\u003eevent_info.got_ip6.ip6_info.ip,\n-\t\t\t\t\t\t\tsizeof(mem-\u003eaddrv6));\n+\t\t\t\t\tlws_get_iframe_size(\u0026mem-\u003ewidth,\n+\t\t\t\t\t\t\t \u0026mem-\u003eheight);\n+\t\t\t\t\tmemcpy(\u0026mem-\u003eaddr,\n+\t\t\t\t\t \u0026event-\u003eevent_info.got_ip.ip_info.ip,\n+\t\t\t\t\t sizeof(mem-\u003eaddr));\n+\t\t\t\t\tmemcpy(\u0026mem-\u003eaddrv6,\n+\t\t\t\t\t \u0026event-\u003eevent_info.got_ip6.ip6_info.ip,\n+\t\t\t\t\t sizeof(mem-\u003eaddrv6));\n \t\t\t\t\tmem-\u003enext \u003d lws_esp32.first;\n \t\t\t\t\tlws_esp32.first \u003d mem;\n \t\t\t\t\tlws_esp32.extant_group_members++;\n \n-\t\t\t\t\tlws_group_member_event_call(LWS_SYSTEM_GROUP_MEMBER_ADD, mem);\n+\t\t\t\t\tlws_group_member_event_call(\n+\t\t\t\t\t LWS_SYSTEM_GROUP_MEMBER_ADD, mem);\n \t\t\t\t}\n \t\t\t} else { /* update our IP */\n-\t\t\t\t\tmemcpy(\u0026mem-\u003eaddr, \u0026event-\u003eevent_info.got_ip.ip_info.ip,\n-\t\t\t\t\t\t\tsizeof(mem-\u003eaddr));\n-\t\t\t\t\tmemcpy(\u0026mem-\u003eaddrv6, \u0026event-\u003eevent_info.got_ip6.ip6_info.ip,\n-\t\t\t\t\t\t\tsizeof(mem-\u003eaddrv6));\n-\t\t\t\t\tlws_group_member_event_call(LWS_SYSTEM_GROUP_MEMBER_CHANGE, mem);\n+\t\t\t\tmemcpy(\u0026mem-\u003eaddr,\n+\t\t\t\t \u0026event-\u003eevent_info.got_ip.ip_info.ip,\n+\t\t\t\t sizeof(mem-\u003eaddr));\n+\t\t\t\tmemcpy(\u0026mem-\u003eaddrv6,\n+\t\t\t\t \u0026event-\u003eevent_info.got_ip6.ip6_info.ip,\n+\t\t\t\t sizeof(mem-\u003eaddrv6));\n+\t\t\t\tlws_group_member_event_call(\n+\t\t\t\t\t LWS_SYSTEM_GROUP_MEMBER_CHANGE, mem);\n \t\t\t}\n \n \n-\t\t\tif (mdns_service_txt_set(lws_esp32.mdns, \u0022_lwsgrmem\u0022, \u0022_tcp\u0022, ARRAY_SIZE(txta),\n+\t\t\tif (mdns_service_txt_set(lws_esp32.mdns, \u0022_lwsgrmem\u0022,\n+\t\t\t\t\t\t \u0022_tcp\u0022, ARRAY_SIZE(txta),\n \t\t\t\t\t\t (const char **)txta))\n \t\t\t\tlwsl_notice(\u0022txt set failed\u005cn\u0022);\n \t\t} else\n@@ -1242,6 +1287,11 @@ esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event)\n #endif\n \n \t\tlwsl_notice(\u0022 --- Got IP %s\u005cn\u0022, lws_esp32.sta_ip);\n+\t\tif (!sntp_enabled()) {\n+\t\t\tsntp_setoperatingmode(SNTP_OPMODE_POLL);\n+\t\t\tsntp_setservername(0, \u0022pool.ntp.org\u0022);\n+\t\t\tsntp_init();\n+\t\t}\n \t\tbreak;\n \n \tcase SYSTEM_EVENT_SCAN_DONE:\n@@ -1258,7 +1308,7 @@ esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event)\n \n static lws_fop_fd_t IRAM_ATTR\n esp32_lws_fops_open(const struct lws_plat_file_ops *fops, const char *filename,\n- const char *vfs_path, lws_fop_flags_t *flags)\n+ const char *vfs_path, lws_fop_flags_t *flags)\n {\n \tstruct esp32_file *f \u003d malloc(sizeof(*f));\n \tlws_fop_fd_t fop_fd;\n@@ -1359,9 +1409,11 @@ lws_esp32_wlan_nvs_get(int retry)\n \n \tesp_efuse_mac_get_default(mac);\n \tmac[5] |\u003d 1; /* match the AP MAC */\n-\tsnprintf(lws_esp32.serial, sizeof(lws_esp32.serial) - 1, \u0022%02X%02X%02X\u0022, mac[3], mac[4], mac[5]);\n-\tsnprintf(lws_esp32.mac, sizeof(lws_esp32.mac) - 1, \u0022%02X%02X%02X%02X%02X%02X\u0022, mac[0],\n-\t\t\tmac[1], mac[2], mac[3], mac[4], mac[5]);\n+\tsnprintf(lws_esp32.serial, sizeof(lws_esp32.serial) - 1,\n+\t\t \u0022%02X%02X%02X\u0022, mac[3], mac[4], mac[5]);\n+\tsnprintf(lws_esp32.mac, sizeof(lws_esp32.mac) - 1,\n+\t\t \u0022%02X%02X%02X%02X%02X%02X\u0022, mac[0], mac[1], mac[2], mac[3],\n+\t\t mac[4], mac[5]);\n \n \tESP_ERROR_CHECK(nvs_open(\u0022lws-station\u0022, NVS_READWRITE, \u0026nvh));\n \n@@ -1489,7 +1541,8 @@ lws_esp32_wlan_start_ap(void)\n \tesp_wifi_scan_start(\u0026scan_config, false);\n \n \tif (sta_config.sta.ssid[0]) {\n-\t\ttcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, (const char *)\u0026config.ap.ssid[7]);\n+\t\ttcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA,\n+\t\t\t\t\t (const char *)\u0026config.ap.ssid[7]);\n \t\tesp_wifi_set_auto_connect(1);\n \t\tESP_ERROR_CHECK( esp_wifi_connect());\n \t\tESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, \u0026sta_config));\n@@ -1510,7 +1563,8 @@ lws_esp32_wlan_start_station(void)\n \n \tESP_ERROR_CHECK( esp_wifi_start());\n \n-\ttcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, (const char *)\u0026config.ap.ssid[7]);\n+\ttcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA,\n+\t\t\t\t (const char *)\u0026config.ap.ssid[7]);\n \tesp_wifi_set_auto_connect(1);\n \t//ESP_ERROR_CHECK( esp_wifi_connect());\n \n@@ -1520,7 +1574,8 @@ lws_esp32_wlan_start_station(void)\n const esp_partition_t *\n lws_esp_ota_get_boot_partition(void)\n {\n-\tconst esp_partition_t *part \u003d esp_ota_get_boot_partition(), *factory_part, *ota;\n+\tconst esp_partition_t *part \u003d esp_ota_get_boot_partition(),\n+\t\t\t *factory_part, *ota;\n \tesp_image_header_t eih, ota_eih;\n \tuint32_t *p_force_factory_magic \u003d (uint32_t *)LWS_MAGIC_REBOOT_TYPE_ADS;\n \n@@ -1535,7 +1590,7 @@ lws_esp_ota_get_boot_partition(void)\n \tif (eih.spi_mode \u003d\u003d 0xff ||\n \t *p_force_factory_magic \u003d\u003d LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY ||\n \t *p_force_factory_magic \u003d\u003d LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON\n-\t ) {\n+\t) {\n \t\t/*\n \t\t * we believed we were going to boot OTA, but we fell\n \t\t * back to FACTORY in the bootloader when we saw it\n@@ -1557,18 +1612,22 @@ lws_esp_ota_get_boot_partition(void)\n \t\t\t * it means we were just written and need to copy\n \t\t\t * ourselves into the FACTORY slot.\n \t\t\t */\n-\t\t\tlwsl_notice(\u0022Copying FACTORY update into place 0x%x len 0x%x\u005cn\u0022,\n-\t\t\t\t factory_part-\u003eaddress, factory_part-\u003esize);\n-\t\t\tesp_task_wdt_feed();\n-\t\t\tif (spi_flash_erase_range(factory_part-\u003eaddress, factory_part-\u003esize) !\u003d ESP_OK) {\n+\t\t\tlwsl_notice(\u0022Copying FACTORY update into place \u0022\n+\t\t\t\t \u00220x%x len 0x%x\u005cn\u0022, factory_part-\u003eaddress,\n+\t\t\t\t factory_part-\u003esize);\n+\t\t\tesp_task_wdt_reset();\n+\t\t\tif (spi_flash_erase_range(factory_part-\u003eaddress,\n+\t\t\t\t\t\t factory_part-\u003esize)) {\n \t \t lwsl_err(\u0022spi: Failed to erase\u005cn\u0022);\n \t \t goto retry;\n \t \t}\n \n \t\t\tfor (n \u003d 0; n \u003c factory_part-\u003esize; n +\u003d sizeof(buf)) {\n-\t\t\t\tesp_task_wdt_feed();\n-\t\t\t\tspi_flash_read(part-\u003eaddress + n , buf, sizeof(buf));\n-\t \tif (spi_flash_write(factory_part-\u003eaddress + n, buf, sizeof(buf)) !\u003d ESP_OK) {\n+\t\t\t\tesp_task_wdt_reset();\n+\t\t\t\tspi_flash_read(part-\u003eaddress + n , buf,\n+\t\t\t\t\t sizeof(buf));\n+\t\t\t\tif (spi_flash_write(factory_part-\u003eaddress + n,\n+\t\t\t\t\t\t buf, sizeof(buf))) {\n \t \t lwsl_err(\u0022spi: Failed to write\u005cn\u0022);\n \t \t goto retry;\n \t \t}\n@@ -1578,8 +1637,8 @@ lws_esp_ota_get_boot_partition(void)\n \t\t\tspi_flash_erase_range(ota-\u003eaddress, 4096);\n \n \t\t\t/*\n-\t\t\t * with no viable OTA image, we will come back up in factory\n-\t\t\t * where the user can reload the OTA image\n+\t\t\t * with no viable OTA image, we will come back up in\n+\t\t\t * factory where the user can reload the OTA image\n \t\t\t */\n \t\t\tlwsl_notice(\u0022 FACTORY copy successful, rebooting\u005cn\u0022);\n retry:\n@@ -1613,10 +1672,7 @@ lws_esp32_set_creation_defaults(struct lws_context_creation_info *info)\n \tinfo-\u003etimeout_secs \u003d 30;\n \tinfo-\u003esimultaneous_ssl_restriction \u003d 4;\n \tinfo-\u003eoptions \u003d LWS_SERVER_OPTION_EXPLICIT_VHOSTS |\n-\t\t LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;\n-\n-//\tinfo-\u003essl_cert_filepath \u003d \u0022default-cert.pem\u0022;\n-//\tinfo-\u003essl_private_key_filepath \u003d \u0022default-key.pem\u0022;\n+\t\t LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;\n }\n \n int\n@@ -1630,8 +1686,10 @@ lws_esp32_get_image_info(const esp_partition_t *part, struct lws_esp32_image *i,\n \tspi_flash_read(part-\u003eaddress , \u0026eih, sizeof(eih));\n \thdr \u003d part-\u003eaddress + sizeof(eih);\n \n-\tif (eih.magic !\u003d ESP_IMAGE_HEADER_MAGIC)\n+\tif (eih.magic !\u003d ESP_IMAGE_HEADER_MAGIC) {\n+\t\tlwsl_notice(\u0022%s: bad image header magic\u005cn\u0022, __func__);\n \t\treturn 1;\n+\t}\n \n \teis.data_len \u003d 0;\n \twhile (eih.segment_count-- \u0026\u0026 eis.data_len !\u003d 0xffffffff) {\n@@ -1810,7 +1868,8 @@ lws_esp32_init(struct lws_context_creation_info *info, struct lws_vhost **pvh)\n \t\n \tlws_esp32_romfs \u003d (romfs_t)i.romfs;\n \tif (!romfs_mount_check(lws_esp32_romfs)) {\n-\t\tlwsl_err(\u0022Failed to mount ROMFS at %p 0x%x\u005cn\u0022, lws_esp32_romfs, i.romfs);\n+\t\tlwsl_err(\u0022mount error on ROMFS at %p 0x%x\u005cn\u0022, lws_esp32_romfs,\n+\t\t\t i.romfs);\n \t\treturn NULL;\n \t}\n \ndiff --git a/lib/pollfd.c b/lib/pollfd.c\nindex 25c9482..8f44d1e 100644\n--- a/lib/pollfd.c\n+++ b/lib/pollfd.c\n@@ -127,7 +127,7 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)\n \n \tpfd \u003d \u0026pt-\u003efds[wsi-\u003eposition_in_fds_table];\n \tpa-\u003efd \u003d wsi-\u003edesc.sockfd;\n-\tlwsl_debug(\u0022%s: fd %d old events %d\u005cn\u0022, __func__, pa-\u003efd, pfd-\u003eevents);\n+\tlwsl_debug(\u0022%s: wsi %p: fd %d events %d -\u003e %d\u005cn\u0022, __func__, wsi, pa-\u003efd, pfd-\u003eevents, (pfd-\u003eevents \u0026 ~_and) | _or);\n \tpa-\u003eprev_events \u003d pfd-\u003eevents;\n \tpa-\u003eevents \u003d pfd-\u003eevents \u003d (pfd-\u003eevents \u0026 ~_and) | _or;\n \ndiff --git a/lib/service.c b/lib/service.c\nindex 7a0196c..cd13aa1 100644\n--- a/lib/service.c\n+++ b/lib/service.c\n@@ -1029,7 +1029,6 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,\n #endif\n \n \t\tlws_plat_service_periodic(context);\n-\n \t\tlws_check_deferred_free(context, 0);\n \n #if defined(LWS_WITH_PEER_LIMITS)\n@@ -1060,7 +1059,7 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,\n \t\t\t/* we have to take copies, because he may be deleted */\n \t\t\twsi1 \u003d wsi-\u003etimeout_list;\n \t\t\ttmp_fd \u003d wsi-\u003edesc.sockfd;\n-\t\t\tif (lws_service_timeout_check(wsi, (unsigned int)now)) {\n+\t\t\tif (lws_service_timeout_check(wsi, now)) {\n \t\t\t\t/* he did time out... */\n \t\t\t\tif (tmp_fd \u003d\u003d our_fd)\n \t\t\t\t\t/* it was the guy we came to service! */\n@@ -1082,8 +1081,9 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,\n \t\t\tconst unsigned char *c;\n \n \t\t\tif (!ah-\u003ein_use || !ah-\u003ewsi || !ah-\u003eassigned ||\n-\t\t\t (ah-\u003ewsi-\u003evhost \u0026\u0026 now - ah-\u003eassigned \u003c\n-\t\t\t ah-\u003ewsi-\u003evhost-\u003etimeout_secs_ah_idle + 60)) {\n+\t\t\t (ah-\u003ewsi-\u003evhost \u0026\u0026\n+\t\t\t lws_compare_time_t(context, now, ah-\u003eassigned) \u003c\n+\t\t\t ah-\u003ewsi-\u003evhost-\u003etimeout_secs_ah_idle + 360)) {\n \t\t\t\tah \u003d ah-\u003enext;\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -1174,7 +1174,9 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,\n \t\t\t\t\t !wsi-\u003esocket_is_permanently_unusable \u0026\u0026\n \t\t\t\t\t !wsi-\u003ews-\u003esend_check_ping \u0026\u0026\n \t\t\t\t\t wsi-\u003ews-\u003etime_next_ping_check \u0026\u0026\n-\t\t\t\t\t wsi-\u003ews-\u003etime_next_ping_check \u003c now) {\n+\t\t\t\t\t lws_compare_time_t(context, now,\n+\t\t\t\t\t\twsi-\u003ews-\u003etime_next_ping_check) \u003e\n+\t\t\t\t\t context-\u003ews_ping_pong_interval) {\n \n \t\t\t\t\t\tlwsl_info(\u0022req pp on wsi %p\u005cn\u0022,\n \t\t\t\t\t\t\t wsi);\n@@ -1184,9 +1186,7 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,\n \t\t\t\t\t\t\tcontext-\u003etimeout_secs);\n \t\t\t\t\t\tlws_callback_on_writable(wsi);\n \t\t\t\t\t\twsi-\u003ews-\u003etime_next_ping_check \u003d\n-\t\t\t\t\t\t\tnow +\n-\t\t\t\t\t\t\twsi-\u003econtext-\u003e\n-\t\t\t\t\t\t\t ws_ping_pong_interval;\n+\t\t\t\t\t\t\tnow;\n \t\t\t\t\t}\n \t\t\t\t\twsi \u003d wsi-\u003esame_vh_protocol_next;\n \t\t\t\t}\n@@ -1195,14 +1195,15 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,\n \t\t}\n \t}\n \n+#ifdef LWS_OPENSSL_SUPPORT\n \t/*\n \t * check the remaining cert lifetime daily\n \t */\n-\tif (context-\u003elast_cert_check_s \u003c now - (24 * 60 * 60)) {\n+\tn \u003d lws_compare_time_t(context, now, context-\u003elast_cert_check_s);\n+\tif ((!context-\u003elast_cert_check_s || n \u003e (24 * 60 * 60)) \u0026\u0026\n+\t !lws_tls_check_all_cert_lifetimes(context))\n \t\tcontext-\u003elast_cert_check_s \u003d now;\n-\n-\t\tlws_tls_check_all_cert_lifetimes(context);\n-\t}\n+#endif\n \n \t/* the socket we came to service timed out, nothing to do */\n \tif (timed_out)\n@@ -1214,7 +1215,6 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,\n \n \t/* no, here to service a socket descriptor */\n \twsi \u003d wsi_from_fd(context, pollfd-\u003efd);\n-\n \tif (!wsi)\n \t\t/* not lws connection ... leave revents alone and return */\n \t\treturn 0;\n@@ -1639,9 +1639,6 @@ drain:\n \t\tif (wsi-\u003eah) {\n \t\t\tlwsl_debug(\u0022%s: %p: detaching\u005cn\u0022, __func__, wsi);\n \t\t\tlws_header_table_force_to_detachable_state(wsi);\n-\t\t\t/* we can run the normal ah detach flow despite\n-\t\t\t * being in ws union mode, since all union members\n-\t\t\t * start with hdr */\n \t\t\tlws_header_table_detach(wsi, 0);\n \t\t}\n \ndiff --git a/lib/tls/mbedtls/ssl.c b/lib/tls/mbedtls/ssl.c\nindex f46eaba..57d75c1 100644\n--- a/lib/tls/mbedtls/ssl.c\n+++ b/lib/tls/mbedtls/ssl.c\n@@ -191,7 +191,6 @@ lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len)\n \n \t\tif (m \u003d\u003d SSL_ERROR_WANT_WRITE || SSL_want_write(wsi-\u003essl)) {\n \t\t\tlws_set_blocking_send(wsi);\n-\n \t\t\tlwsl_notice(\u0022%s: want write\u005cn\u0022, __func__);\n \n \t\t\treturn LWS_SSL_CAPABLE_MORE_SERVICE;\ndiff --git a/plugins/protocol_esp32_lws_ota.c b/plugins/protocol_esp32_lws_ota.c\nindex d3e8808..cfb5748 100644\n--- a/plugins/protocol_esp32_lws_ota.c\n+++ b/plugins/protocol_esp32_lws_ota.c\n@@ -192,8 +192,8 @@ callback_esplws_ota(struct lws *wsi, enum lws_callback_reasons reason,\n \n \tcase LWS_CALLBACK_HTTP_BODY:\n \t\t/* create the POST argument parser if not already existing */\n-\t\t//lwsl_notice(\u0022LWS_CALLBACK_HTTP_BODY (ota) %d %d %p\u005cn\u0022, (int)pss-\u003efile_length, (int)len, pss-\u003espa);\n-\t\tlws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, 5);\n+\t\t// lwsl_notice(\u0022LWS_CALLBACK_HTTP_BODY (ota) %d %d %p\u005cn\u0022, (int)pss-\u003efile_length, (int)len, pss-\u003espa);\n+\t\tlws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, 30);\n \t\tif (!pss-\u003espa) {\n \t\t\tpss-\u003espa \u003d lws_spa_create(wsi, ota_param_names,\n \t\t\t\t\tARRAY_SIZE(ota_param_names), 4096,\ndiff --git a/plugins/protocol_esp32_lws_scan.c b/plugins/protocol_esp32_lws_scan.c\nindex 019172c..0030700 100644\n--- a/plugins/protocol_esp32_lws_scan.c\n+++ b/plugins/protocol_esp32_lws_scan.c\n@@ -69,8 +69,10 @@ struct per_vhost_data__esplws_scan {\n \tlong file_length;\n \tlong content_length;\n \n+\tint cert_remaining_days;\n+\n \tstruct lws *cwsi;\n-\tchar json[1024];\n+\tchar json[2048];\n \tint json_len;\n \n \tuint16_t count_ap_records;\n@@ -249,7 +251,7 @@ scan_finished(uint16_t count, wifi_ap_record_t *recs, void *v)\n esp_wifi_connect();\n }\n \n-static const char *ssl_names[] \u003d { \u0022ssl-pub.pem\u0022, \u0022ssl-pri.pem\u0022 };\n+static const char *ssl_names[] \u003d { \u0022ap-cert.pem\u0022, \u0022ap-key.pem\u0022 };\n \n static int\n file_upload_cb(void *data, const char *name, const char *filename,\n@@ -292,6 +294,7 @@ file_upload_cb(void *data, const char *name, const char *filename,\n \t\tn \u003d 0;\n \t\tif (!strcmp(name, \u0022pri\u0022))\n \t\t\tn \u003d 1;\n+\t\tlwsl_notice(\u0022writing %s\u005cn\u0022, ssl_names[n]);\n \t\tn \u003d nvs_set_blob(pss-\u003envh, ssl_names[n], pss-\u003ebuffer, pss-\u003efile_length);\n \t\tif (n \u003d\u003d ESP_OK)\n \t\t\tnvs_commit(pss-\u003envh);\n@@ -316,6 +319,9 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,\n \t\t\t\t\tlws_get_protocol(wsi));\n \tunsigned char *start \u003d pss-\u003ebuffer + LWS_PRE - 1, *p \u003d start,\n \t\t *end \u003d pss-\u003ebuffer + sizeof(pss-\u003ebuffer) - 1;\n+\tunion lws_tls_cert_info_results ir;\n+\tchar subject[64];\n+\tconst char *pp;\n \twifi_ap_record_t *r;\n \tint n, m;\n \tnvs_handle nvh;\n@@ -362,7 +368,6 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,\n \t\tbreak;\n \n \tcase LWS_CALLBACK_SERVER_WRITEABLE:\n-\n \t\tif (vhd-\u003eautonomous_update_sampled) {\n \t\t\tp +\u003d snprintf((char *)p, end - p,\n \t\t\t\t \u0022 {\u005cn \u005c\u0022auton\u005c\u0022:\u005c\u00221\u005c\u0022,\u005cn \u005c\u0022pos\u005c\u0022: \u005c\u0022%ld\u005c\u0022,\u005cn\u0022\n@@ -381,11 +386,15 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,\n \t\t\tchar img_factory[384], img_ota[384], group[16], role[16];\n \t\t\tint grt;\n \n+\t\tcase SCAN_STATE_NONE:\n+\n+\t\t\t/* fallthru */\n+\n \t\tcase SCAN_STATE_INITIAL:\n \n \t\t\tgettimeofday(\u0026t, NULL);\n-\t\t\tif (t.tv_sec - pss-\u003elast_send.tv_sec \u003c 10)\n-\t\t\t\treturn 0;\n+\t\t//\tif (t.tv_sec - pss-\u003elast_send.tv_sec \u003c 10)\n+\t\t//\t\treturn 0;\n \n \t\t\tpss-\u003elast_send \u003d t;\n \n@@ -394,9 +403,9 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t\tn \u003d 0;\n-\t\t\tif (nvs_get_blob(nvh, \u0022ssl-pub.pem\u0022, NULL, \u0026s) \u003d\u003d ESP_OK)\n+\t\t\tif (nvs_get_blob(nvh, \u0022ap-cert.pem\u0022, NULL, \u0026s) \u003d\u003d ESP_OK)\n \t\t\t\tn \u003d 1;\n-\t\t\tif (nvs_get_blob(nvh, \u0022ssl-pri.pem\u0022, NULL, \u0026s) \u003d\u003d ESP_OK)\n+\t\t\tif (nvs_get_blob(nvh, \u0022ap-key.pem\u0022, NULL, \u0026s) \u003d\u003d ESP_OK)\n \t\t\t\tn |\u003d 2;\n \t\t\ts \u003d sizeof(group) - 1;\n \t\t\tgroup[0] \u003d '\u005c0';\n@@ -406,6 +415,26 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,\n \n \t\t\tnvs_close(nvh);\n \n+\t\t\tir.ns.name[0] \u003d '\u005c0';\n+\t\t\tsubject[0] \u003d '\u005c0';\n+\n+\t\t\tif (t.tv_sec \u003e 1464083026 \u0026\u0026\n+\t\t\t !lws_tls_vhost_cert_info(vhd-\u003evhost,\n+\t\t\t\t LWS_TLS_CERT_INFO_VALIDITY_TO, \u0026ir, 0)) {\n+\t\t\t\tvhd-\u003ecert_remaining_days \u003d\n+\t\t\t\t\t (ir.time - t.tv_sec) / (24 * 3600);\n+\t\t\t\tir.ns.name[0] \u003d '\u005c0';\n+\t\t\t\tlws_tls_vhost_cert_info(vhd-\u003evhost,\n+\t\t\t\t\tLWS_TLS_CERT_INFO_COMMON_NAME, \u0026ir,\n+\t\t\t\t\t\tsizeof(ir.ns.name));\n+\t\t\t\tstrncpy(subject, ir.ns.name, sizeof(subject) - 1);\n+\n+\t\t\t\tir.ns.name[0] \u003d '\u005c0';\n+\t\t\t\tlws_tls_vhost_cert_info(vhd-\u003evhost,\n+\t\t\t\t\tLWS_TLS_CERT_INFO_ISSUER_NAME, \u0026ir,\n+\t\t\t\t\t\tsizeof(ir.ns.name));\n+\t\t\t}\n+\n \t\t\t/*\n \t\t\t * this value in the JSON is just\n \t\t\t * used for UI indication. Each conditional feature confirms\n@@ -418,7 +447,7 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,\n \t\t\tstrcpy(img_factory, \u0022 { \u005c\u0022date\u005c\u0022: \u005c\u0022Empty\u005c\u0022 }\u0022);\n \t\t\tstrcpy(img_ota, \u0022 { \u005c\u0022date\u005c\u0022: \u005c\u0022Empty\u005c\u0022 }\u0022);\n \n-\t\t\tif (grt !\u003d LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) {\n+\t//\t\tif (grt !\u003d LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) {\n \t\t\t\tlws_esp32_get_image_info(esp_partition_find_first(ESP_PARTITION_TYPE_APP,\n \t\t\t\t\tESP_PARTITION_SUBTYPE_APP_FACTORY, NULL), \u0026i,\n \t\t\t\t\timg_factory, sizeof(img_factory) - 1);\n@@ -432,7 +461,7 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,\n \t\t\t\timg_ota[sizeof(img_ota) - 1] \u003d '\u005c0';\n \t\t\t\tif (img_ota[0] \u003d\u003d 0xff || strlen(img_ota) \u003c 8)\n \t\t\t\t\tstrcpy(img_ota, \u0022 { \u005c\u0022date\u005c\u0022: \u005c\u0022Empty\u005c\u0022 }\u0022);\n-\t\t\t}\n+\t//\t\t}\n \n \t\t\tp +\u003d snprintf((char *)p, end - p,\n \t\t\t\t \u0022{ \u005c\u0022model\u005c\u0022:\u005c\u0022%s\u005c\u0022,\u005cn\u0022\n@@ -448,6 +477,11 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,\n \t\t\t\t \u0022 \u005c\u0022conn_ip\u005c\u0022:\u005c\u0022%s\u005c\u0022,\u005cn\u0022\n \t\t\t\t \u0022 \u005c\u0022conn_mask\u005c\u0022:\u005c\u0022%s\u005c\u0022,\u005cn\u0022\n \t\t\t\t \u0022 \u005c\u0022conn_gw\u005c\u0022:\u005c\u0022%s\u005c\u0022,\u005cn\u0022\n+\t\t\t\t \u0022 \u005c\u0022certdays\u005c\u0022:\u005c\u0022%d\u005c\u0022,\u005cn\u0022\n+\t\t\t\t \u0022 \u005c\u0022unixtime\u005c\u0022:\u005c\u0022%llu\u005c\u0022,\u005cn\u0022\n+\t\t\t\t \u0022 \u005c\u0022certissuer\u005c\u0022:\u005c\u0022%s\u005c\u0022,\u005cn\u0022\n+\t\t\t\t \u0022 \u005c\u0022certsubject\u005c\u0022:\u005c\u0022%s\u005c\u0022,\u005cn\u0022\n+\t\t\t\t \u0022 \u005c\u0022button\u005c\u0022:\u005c\u0022%d\u005c\u0022,\u005cn\u0022\n \t\t\t\t \u0022 \u005c\u0022group\u005c\u0022:\u005c\u0022%s\u005c\u0022,\u005cn\u0022\n \t\t\t\t \u0022 \u005c\u0022role\u005c\u0022:\u005c\u0022%s\u005c\u0022,\u005cn\u0022,\n \t\t\t\t lws_esp32.model,\n@@ -462,6 +496,10 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,\n \t\t\t\t lws_esp32.sta_ip,\n \t\t\t\t lws_esp32.sta_mask,\n \t\t\t\t lws_esp32.sta_gw,\n+\t\t\t\t vhd-\u003ecert_remaining_days,\n+\t\t\t\t (unsigned long long)t.tv_sec,\n+\t\t\t\t ir.ns.name, subject,\n+\t\t\t\t ((volatile struct lws_esp32 *)(\u0026lws_esp32))-\u003ebutton_is_down,\n \t\t\t\t group, role);\n \t\t\tp +\u003d snprintf((char *)p, end - p,\n \t\t\t\t \u0022 \u005c\u0022img_factory\u005c\u0022: %s,\u005cn\u0022\n@@ -573,7 +611,6 @@ scan_state_final:\n \t\t\treturn 0;\n \t\t}\n issue:\n-//\t\tlwsl_notice(\u0022issue: %d (%d)\u005cn\u0022, p - start, n);\n \t\tm \u003d lws_write(wsi, (unsigned char *)start, p - start, n);\n \t\tif (m \u003c 0) {\n \t\t\tlwsl_err(\u0022ERROR %d writing to di socket\u005cn\u0022, m);\n@@ -755,7 +792,6 @@ auton:\n \n \tcase LWS_CALLBACK_HTTP_BODY:\n \t\t/* create the POST argument parser if not already existing */\n-\t\tlwsl_notice(\u0022LWS_CALLBACK_HTTP_BODY (scan)\u005cn\u0022);\n \t\tif (!pss-\u003espa) {\n \t\t\tpss-\u003espa \u003d lws_spa_create(wsi, param_names,\n \t\t\t\t\tARRAY_SIZE(param_names), 1024,\n@@ -804,10 +840,13 @@ auton:\n \t\t}\n \t\tnvs_close(nvh);\n \n+\t\tpp \u003d lws_spa_get_string(pss-\u003espa, EPN_SERIAL);\n+\t\tif (!pp)\n+\t\t\tpp \u003d \u0022unknown\u0022;\n \t\tpss-\u003eresult_len \u003d snprintf(pss-\u003eresult + LWS_PRE, sizeof(pss-\u003eresult) - LWS_PRE - 1,\n \t\t\t\t\u0022\u003chtml\u003eRebooting after storing certs...\u003cbr\u003econnect to AP '\u003cb\u003econfig-%s-%s\u003c/b\u003e' and continue here: \u0022\n \t\t\t\t\u0022\u003ca href\u003d\u005c\u0022https://192.168.4.1\u005c\u0022\u003ehttps://192.168.4.1\u003c/a\u003e\u003c/html\u003e\u0022,\n-\t\t\t\tlws_esp32.model, lws_spa_get_string(pss-\u003espa, EPN_SERIAL));\n+\t\t\t\tlws_esp32.model, pp);\n \n \t\tif (lws_add_http_header_status(wsi, HTTP_STATUS_OK, \u0026p, end))\n \t\t\tgoto bail;\n@@ -830,6 +869,8 @@ auton:\n \tcase LWS_CALLBACK_HTTP_WRITEABLE:\n \t\tlwsl_debug(\u0022LWS_CALLBACK_HTTP_WRITEABLE: sending %d\u005cn\u0022,\n \t\t\t pss-\u003eresult_len);\n+\t\tif (!pss-\u003eresult_len)\n+\t\t\tbreak;\n \t\tn \u003d lws_write(wsi, (unsigned char *)pss-\u003eresult + LWS_PRE,\n \t\t\t pss-\u003eresult_len, LWS_WRITE_HTTP);\n \t\tif (n \u003c 0)\n","s":{"c":1750391997,"u": 13703}}
],"g": 16675,"chitpc": 0,"ehitpc": 0,"indexed":0
,
"ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}