Skip to content

Commit

Permalink
remove most of todos
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavrax committed Jun 24, 2024
1 parent 7e846ad commit 55a743a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,11 @@ else()

endif()

# TODO: Check if CPP is supported on ESP32
# TODO: C++ support for ESP32 platform
if (WITH_CPP AND ESP_PLATFORM)
message(FATAL_ERROR "C++ support is not available for ESP32 platform!")
endif()

if (WITH_CPP AND NOT ESP_PLATFORM)
# TODO: Tests
# fntest/pubnub_fntest_medium.cpp
Expand Down
3 changes: 2 additions & 1 deletion freertos/pbpal_freertos_blocking_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#include "pbpal.h"

#include "pubnub_internal.h"
#include "pubnub_log.h"

#include <fcntl.h>


int pbpal_set_blocking_io(pubnub_t *pb)
{
// TODO: WHATAHELL?
PUBNUB_LOG_WARNING("pbpal_set_blocking_io() - Unsupported\n");
return -1;
}
3 changes: 2 additions & 1 deletion freertos/pbpal_resolv_and_connect_freertos_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum pbpal_resolv_n_connect_result pbpal_resolv_and_connect(pubnub_t *pb)
PUBNUB_ASSERT_OPT((pb->state == PBS_READY) || (pb->state == PBS_WAIT_DNS_SEND) || (pb->state == PBS_WAIT_DNS_RCV));

addr.sin_port = htons(HTTP_PORT);
// TODO: how to do this on ESP?

#if ESP_PLATFORM
PUBNUB_LOG_TRACE("pbpal_resolv_and_connect: gethostbyname(%s)\n",
PUBNUB_ORIGIN_SETTABLE ? pb->origin : PUBNUB_ORIGIN);
Expand All @@ -45,6 +45,7 @@ enum pbpal_resolv_n_connect_result pbpal_resolv_and_connect(pubnub_t *pb)
return pbpal_resolv_failed_processing;
}
#endif

pb->pal.socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (pb->pal.socket == SOCKET_INVALID) {
return pbpal_connect_resource_failure;
Expand Down
1 change: 0 additions & 1 deletion freertos/pubnub_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
#define PUBNUB_USE_AUTO_HEARTBEAT 1
#endif


#ifndef PUBNUB_USE_SSL
/** If true (!=0), will enable SSL/TLS support. If false (==0), will
disable SSL/TLS support. If not defined, will enable SSL/TLS
Expand Down
3 changes: 0 additions & 3 deletions mbedtls/pbpal_connect_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ static const char* get_origin(pubnub_t* pb)

#define PUBNUB_PORT "443"

// TODO: https://github.com/espressif/esp-idf/blob/v5.2.1/examples/protocols/https_mbedtls/main/https_mbedtls_example_main.c
// reference for mbedtls usage
enum pbpal_tls_result pbpal_start_tls(pubnub_t* pb)
{
struct pubnub_pal* pal = &pb->pal;
Expand All @@ -107,7 +105,6 @@ enum pbpal_tls_result pbpal_start_tls(pubnub_t* pb)

alloc_setup(pb);

// TODO: Think about pubnub_config.h and where or which to use
PUBNUB_ASSERT(SOCKET_INVALID != pb->pal.socket);
PUBNUB_LOG_TRACE("pbpal_start_tls(pb=%p) socket=%d\n", pb, pb->pal.socket);

Expand Down
16 changes: 16 additions & 0 deletions mbedtls/pbpal_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,18 @@ int pbpal_send_status(pubnub_t* pb)
return 0;
}

PUBNUB_LOG_TRACE("STATE = %d\n", pb->sock_state);
PUBNUB_LOG_TRACE("is sending %d\n", pb->sock_state == STATE_SENDING_DATA);
PUBNUB_ASSERT(pb->sock_state == STATE_SENDING_DATA);

PUBNUB_LOG_TRACE("check for null");
if (NULL == pb->pal.ssl) {
PUBNUB_LOG_ERROR("pbpal_send_status(pb=%p) called with NULL SSL context\n", pb);
return -1;
}
PUBNUB_LOG_TRACE("not a null");

PUBNUB_LOG_TRACE("will write...");
if (0 >= (result = mbedtls_ssl_write(pb->pal.ssl, pb->ptr, pb->len))) {
result = pbpal_handle_socket_condition(result, pb, __FILE__, __LINE__);
} else {
Expand All @@ -143,12 +148,14 @@ int pbpal_send_status(pubnub_t* pb)
pb->len -= result;
result = (0 == pb->len) ? 0 : +1;
}
PUBNUB_LOG_TRACE("written");

if (0 >= result) {
pb->sock_state = STATE_NONE;
pb->unreadlen = 0;
pb->ptr = (uint8_t*)pb->core.http_buf;
}
PUBNUB_LOG_TRACE("sent");

return result;
}
Expand Down Expand Up @@ -338,27 +345,36 @@ int pbpal_close(pubnub_t* pb)

if (pb->pal.ssl != NULL) {
mbedtls_ssl_close_notify(pb->pal.ssl);
PUBNUB_LOG_TRACE("pb=%p: SSL session closed\n", pb);
mbedtls_ssl_session_reset(pb->pal.ssl);
PUBNUB_LOG_TRACE("pb=%p: SSL reset\n", pb);
mbedtls_ssl_free(pb->pal.ssl);
pb->pal.ssl = NULL;
PUBNUB_LOG_TRACE("pb=%p: SSL context freed\n", pb);

mbedtls_ssl_config_free(pb->pal.ssl_config);
pb->pal.ssl_config = NULL;
PUBNUB_LOG_TRACE("pb=%p: SSL config freed\n", pb);

mbedtls_net_free(pb->pal.server_fd);
pb->pal.server_fd = NULL;
PUBNUB_LOG_TRACE("pb=%p: server_fd freed\n", pb);

mbedtls_net_free(pb->pal.net);
pb->pal.net = NULL;
PUBNUB_LOG_TRACE("pb=%p: net freed\n", pb);

mbedtls_x509_crt_free(pb->pal.ca_certificates);
pb->pal.ca_certificates = NULL;
PUBNUB_LOG_TRACE("pb=%p: ca_certificates freed\n", pb);

mbedtls_entropy_free(pb->pal.entropy);
pb->pal.entropy = NULL;
PUBNUB_LOG_TRACE("pb=%p: entropy freed\n", pb);

mbedtls_ctr_drbg_free(pb->pal.ctr_drbg);
pb->pal.ctr_drbg = NULL;
PUBNUB_LOG_TRACE("pb=%p: ctr_drbg freed\n", pb);
}

PUBNUB_LOG_TRACE("pb=%p: pbpal_close() returning 0\n", pb);
Expand Down
2 changes: 0 additions & 2 deletions mbedtls/pubnub_pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ struct pubnub_pal {
mbedtls_entropy_context* entropy;
mbedtls_ctr_drbg_context* ctr_drbg;
pbmsref_t connection_timer;

//TODO: is this socket needed?
int socket;
};

Expand Down

0 comments on commit 55a743a

Please sign in to comment.