Skip to content

Commit

Permalink
add lws port
Browse files Browse the repository at this point in the history
  • Loading branch information
glmfe committed Jan 27, 2025
1 parent 24e3bab commit 5330c90
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 145 deletions.
22 changes: 7 additions & 15 deletions components/libwebsockets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,16 @@ set(LWS_PLAT_FREERTOS ON)
option(LWS_WITH_MBEDTLS "Build for FreeRTOS" ON)
set(LWS_WITH_MBEDTLS ON)

# set(lws_port_target_includes "libwebsockets/lib/core" "libwebsockets/include")

set(WRAP_FUNCTIONS mbedtls_ssl_handshake_step
lws_adopt_descriptor_vhost)

#set(lws_port_target_sources "${COMPONENT_DIR}/port/port.c")
# target_sources(websockets PRIVATE "${COMPONENT_DIR}/port/port.c")

# # Add port files to mbedtls targets


# idf_component_register()
# set(WRAP_FUNCTIONS
# vsnprintf)

# foreach(wrap ${WRAP_FUNCTIONS})
# target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=${wrap}")
# endforeach()
foreach(wrap ${WRAP_FUNCTIONS})
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=${wrap}")
endforeach()

target_link_libraries(${COMPONENT_LIB} INTERFACE websockets)

target_sources(${COMPONENT_LIB} INTERFACE "port/lws_port.c")


add_subdirectory(libwebsockets)
17 changes: 2 additions & 15 deletions components/libwebsockets/examples/server-echo/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(SRC_FILES) # Initialize SRC_FILES as an empty list
set(SRC_FILES "lws-server-echo.c") # Initialize SRC_FILES as an empty list
set(INCLUDE_DIRS ".") # Define include directories
set(EMBED_FILES) # Initialize EMBED_FILES as an empty list

Expand All @@ -7,19 +7,6 @@ list(APPEND EMBED_FILES
"certs/ca_cert.pem"
"certs/server_key.pem")

list(APPEND SRC_FILES
"lws-server-echo.c"
"lws_test_pt.c")

idf_component_register(SRCS ${SRC_FILES}
idf_component_register(SRCS "${SRC_FILES}"
INCLUDE_DIRS "${INCLUDE_DIRS}"
EMBED_TXTFILES "${EMBED_FILES}")

set(WRAP_FUNCTIONS vsnprintf)


foreach(wrap ${WRAP_FUNCTIONS})
target_link_libraries(${COMPONENT_LIB} PUBLIC "-Wl,--wrap=${wrap}")
endforeach()

target_sources(${COMPONENT_LIB} PUBLIC "lws_test_pt.c")
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,9 @@ static const struct lws_protocol_vhost_options pvo = {
"lws-minimal-server-echo", /* protocol name we belong to on this vhost */
"" /* ignored */
};
volatile int tst = 0;
void testt()
{
tst++;
}
// extern int __real_vsnprintf (char *__restrict __s, size_t __maxlen,__const char *__restrict __format, __gnuc_va_list __arg) __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
// extern int __wrap_vsnprintf(char *__restrict __s, size_t __maxlen, const char *__restrict __format, __gnuc_va_list __arg) __THROW __attribute__ ((__format__ (__printf__, 3, 0)));

// extern int __real_testt();

// int __wrap_vsnprintf (char *__restrict __s, size_t __maxlen, const char *__restrict __format, __gnuc_va_list __arg)
// {
// while(1);
// return 0;
// }


// void __wrap_testt()
// {
// while(1);
// }

int app_main(int argc, const char **argv)
{
testt();
ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
Expand Down
51 changes: 0 additions & 51 deletions components/libwebsockets/examples/server-echo/main/lws_test_pt.c

This file was deleted.

47 changes: 47 additions & 0 deletions components/libwebsockets/port/lws_port.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
TODO
*/
#include "stdio.h"
#include <libwebsockets.h>

extern int __real_mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl);
extern int __wrap_mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl);

int __wrap_mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl )
{
int ret = 0;

while (ssl->MBEDTLS_PRIVATE(state) != MBEDTLS_SSL_HANDSHAKE_OVER) {
ret = __real_mbedtls_ssl_handshake_step(ssl);

if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE)
{
continue;
}

if (ret != 0)
break;
}

return ret;
}

extern struct lws * __real_lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, lws_sock_file_fd_type fd, const char *vh_prot_name, struct lws *parent);
extern struct lws * __wrap_lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, lws_sock_file_fd_type fd, const char *vh_prot_name, struct lws *parent);

struct lws * __wrap_lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, lws_sock_file_fd_type fd, const char *vh_prot_name, struct lws *parent)
{
lws_adopt_desc_t info;
char nullstr[] = "(null)";
memset(&info, 0, sizeof(info));

info.vh = vh;
info.type = type;
info.fd = fd;
info.vh_prot_name = vh_prot_name;
info.parent = parent;
info.fi_wsi_name = nullstr;

return lws_adopt_descriptor_vhost_via_info(&info);
}

42 changes: 0 additions & 42 deletions components/libwebsockets/port/lws_test_pt.c

This file was deleted.

0 comments on commit 5330c90

Please sign in to comment.