diff --git a/README.md b/README.md index 00bca45..71740cd 100644 --- a/README.md +++ b/README.md @@ -946,11 +946,13 @@ param **`pageSize`** (integer) The maximum number of files to return per page. param **`orderBy`** (string) A comma-separated list of sort keys. -Note: Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'name_natural', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and 'viewedByMeTime'. +Note: Valid keys are `createdTime`, `folder`, `modifiedByMeTime`, `modifiedTime`, `name`, `name_natural`, `quotaBytesUsed`, `recency`, `sharedWithMeTime`, `starred`, and `viewedByMeTime`. -Each key sorts ascending by default, but may be reversed with the 'desc' modifier. +Each key sorts ascending by default, but may be reversed with the `desc` modifier. -Example usage: ?orderBy=folder,modifiedTime desc,name. +Example usage: `folder,modifiedTime%20desc,name` which the white space need to be replaceed with `%20` as this parameter is used as the URI parameter of Google Drive API request endpoint. + +Please consult [Google Drive API doc](https://developers.google.com/drive/api/reference/rest/v3/files/list) for the more detail. param **`pageToken`** (string) The token for continuing a previous list request on the next page. diff --git a/src/client/SSLClient/ESP_SSLClient.h b/src/client/SSLClient/ESP_SSLClient.h index 3678750..966bd95 100644 --- a/src/client/SSLClient/ESP_SSLClient.h +++ b/src/client/SSLClient/ESP_SSLClient.h @@ -1,8 +1,8 @@ /** * - * The ESP SSL Client Class, ESP_SSLClient.h v2.1.3 + * The ESP SSL Client Class, ESP_SSLClient.h v2.1.5 * - * Created August 13, 2023 + * Created August 22, 2023 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt) @@ -38,13 +38,42 @@ #if defined(USE_EMBED_SSL_ENGINE) || defined(USE_LIB_SSL_ENGINE) #include "client/BSSL_TCP_Client.h" class ESP_SSLClient : public BSSL_TCP_Client +{ +public: + ESP_SSLClient(){}; + ~ESP_SSLClient(){}; +}; + +class ESP_SSLClient2 : public BSSL_TCP_Client +{ +public: + ESP_SSLClient2(Client &client, bool enableSSL = true) : _base_client(client) + { + setClient(&_base_client, enableSSL); + }; + ~ESP_SSLClient2(){}; + +private: + Client &_base_client; +}; + #else class ESP_SSLClient -#endif { public: ESP_SSLClient(){}; ~ESP_SSLClient(){}; }; -#endif \ No newline at end of file +class ESP_SSLClient2 +{ +public: + ESP_SSLClient2(Client &client, bool enableSSL = true) : _base_client(client){}; + ~ESP_SSLClient2(){}; + +private: + Client &_base_client; +}; +#endif + +#endif diff --git a/src/client/SSLClient/client/BSSL_SSL_Client.cpp b/src/client/SSLClient/client/BSSL_SSL_Client.cpp index 4023b64..e6e55c0 100644 --- a/src/client/SSLClient/client/BSSL_SSL_Client.cpp +++ b/src/client/SSLClient/client/BSSL_SSL_Client.cpp @@ -1,7 +1,7 @@ /** - * BSSL_SSL_Client library v1.0.9 for Arduino devices. + * BSSL_SSL_Client library v1.0.10 for Arduino devices. * - * Created August 13, 2003 + * Created August 22, 2003 * * This work contains codes based on WiFiClientSecure from Earle F. Philhower and SSLClient from OSU OPEnS Lab. * @@ -194,6 +194,16 @@ uint8_t BSSL_SSL_Client::connected() return c_con && br_con; } +void BSSL_SSL_Client::validate(const char *host, uint16_t port) +{ + mConnectionValidate(host, IPAddress(), port); +} + +void BSSL_SSL_Client::validate(IPAddress ip, uint16_t port) +{ + mConnectionValidate(nullptr, ip, port); +} + int BSSL_SSL_Client::available() { if (!mIsClientInitialized(false)) @@ -425,9 +435,14 @@ int BSSL_SSL_Client::connectSSL(IPAddress ip, uint16_t port) if (!mIsClientInitialized(true)) return 0; + validate(ip, port); + if (!_basic_client->connected() && !mConnectBasicClient(nullptr, ip, port)) return 0; + _ip = ip; + _port = port; + return mConnectSSL(nullptr); } @@ -437,9 +452,14 @@ int BSSL_SSL_Client::connectSSL(const char *host, uint16_t port) if (!mIsClientInitialized(true)) return 0; + validate(host, port); + if (!_basic_client->connected() && !mConnectBasicClient(host, IPAddress(), port)) return 0; + _host = host; + _port = port; + return mConnectSSL(host); } @@ -1374,7 +1394,8 @@ int BSSL_SSL_Client::mIsClientInitialized(bool notify) int BSSL_SSL_Client::mConnectBasicClient(const char *host, IPAddress ip, uint16_t port) { - if (!mIsClientInitialized(true)) + + if (!mConnectionValidate(host, ip, port)) return 0; if (!(host ? _basic_client->connect(host, port) : _basic_client->connect(ip, port))) @@ -1570,6 +1591,22 @@ int BSSL_SSL_Client::mConnectSSL(const char *host) return 1; } +bool BSSL_SSL_Client::mConnectionValidate(const char *host, IPAddress ip, uint16_t port) +{ + if (!mIsClientInitialized(true)) + return false; + + if (_basic_client && _basic_client->connected() && + host + ? (strcasecmp(host, _host.c_str()) != 0 || port != _port) + : (ip != _ip || port != _port)) + { + _basic_client->stop(); + } + + return true; +} + int BSSL_SSL_Client::mRunUntil(const unsigned target, unsigned long timeout) { unsigned lastState = 0; diff --git a/src/client/SSLClient/client/BSSL_SSL_Client.h b/src/client/SSLClient/client/BSSL_SSL_Client.h index 6a78f0d..e3ea523 100644 --- a/src/client/SSLClient/client/BSSL_SSL_Client.h +++ b/src/client/SSLClient/client/BSSL_SSL_Client.h @@ -1,7 +1,7 @@ /** - * BSSL_SSL_Client library v1.0.9 for Arduino devices. + * BSSL_SSL_Client library v1.0.10 for Arduino devices. * - * Created August 13, 2003 + * Created August 22, 2003 * * This work contains codes based on WiFiClientSecure from Earle F. Philhower and SSLClient from OSU OPEnS Lab. * @@ -98,6 +98,10 @@ class BSSL_SSL_Client : public Client uint8_t connected() override; + void validate(const char* host, uint16_t port); + + void validate(IPAddress ip, uint16_t port); + int available() override; int read() override; @@ -124,6 +128,8 @@ class BSSL_SSL_Client : public Client int connectSSL(const char *host, uint16_t port); + + void stop() override; void setTimeout(unsigned int timeoutMs); @@ -234,6 +240,8 @@ class BSSL_SSL_Client : public Client int mConnectSSL(const char *host = nullptr); + bool mConnectionValidate(const char *host, IPAddress ip, uint16_t port); + int mRunUntil(const unsigned target, unsigned long timeout = 0); unsigned mUpdateEngine(); @@ -333,6 +341,9 @@ class BSSL_SSL_Client : public Client unsigned long _timeout = 15000; unsigned long _handshake_timeout = 60000; bool _isSSLEnabled = false; + String _host; + uint16_t _port; + IPAddress _ip; }; #endif diff --git a/src/client/SSLClient/client/BSSL_TCP_Client.cpp b/src/client/SSLClient/client/BSSL_TCP_Client.cpp index 3e26cb0..604bfea 100644 --- a/src/client/SSLClient/client/BSSL_TCP_Client.cpp +++ b/src/client/SSLClient/client/BSSL_TCP_Client.cpp @@ -1,7 +1,7 @@ /** - * BSSL_TCP_Client v2.0.10 for Arduino devices. + * BSSL_TCP_Client v2.0.11 for Arduino devices. * - * Created August 13, 2023 + * Created August 22, 2023 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt) @@ -134,6 +134,16 @@ uint8_t BSSL_TCP_Client::connected() return _ssl_client.connected(); } +void BSSL_TCP_Client::validate(const char *host, uint16_t port) +{ + _ssl_client.validate(host, port); +} + +void BSSL_TCP_Client::validate(IPAddress ip, uint16_t port) +{ + _ssl_client.validate(ip, port); +} + int BSSL_TCP_Client::available() { return _ssl_client.available(); diff --git a/src/client/SSLClient/client/BSSL_TCP_Client.h b/src/client/SSLClient/client/BSSL_TCP_Client.h index cd2ab05..49dd02c 100644 --- a/src/client/SSLClient/client/BSSL_TCP_Client.h +++ b/src/client/SSLClient/client/BSSL_TCP_Client.h @@ -1,7 +1,7 @@ /** - * BSSL_TCP_Client v2.0.10 for Arduino devices. + * BSSL_TCP_Client v2.0.11 for Arduino devices. * - * Created August 13, 2023 + * Created August 22, 2023 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt) @@ -103,7 +103,7 @@ class BSSL_TCP_Client : public Client /** * Connect to server. * @param ip The server IP to connect. - * @param port The server port to connecte. + * @param port The server port to connect. * @param timeout The connection time out in miiliseconds. * @return 1 for success or 0 for error. */ @@ -112,7 +112,7 @@ class BSSL_TCP_Client : public Client /** * Connect to server. * @param host The server host name. - * @param port The server port to connecte. + * @param port The server port to connect. * @return 1 for success or 0 for error. */ int connect(const char *host, uint16_t port) override; @@ -120,7 +120,7 @@ class BSSL_TCP_Client : public Client /** * Connect to server. * @param host The server host name. - * @param port The server port to connecte. + * @param port The server port to connect. * @param timeout The connection time out in miiliseconds. * @return 1 for success or 0 for error. */ @@ -132,6 +132,22 @@ class BSSL_TCP_Client : public Client */ uint8_t connected() override; + /** + * Validate the last Client connection with these host and port. + * @param host The server host name. + * @param port The server port to connect. + * The Client connection will be closed when the provided host or port is not match with that of last connection. + */ + void validate(const char *host, uint16_t port); + + /** + * Validate the last Client connection with these IP and port. + * @param ip The server IP to connect. + * @param port The server port to connect. + * The Client connection will be closed when the provided IP or port is not match with that of last connection. + */ + void validate(IPAddress ip, uint16_t port); + /** * Get available data size to read. * @return The avaiable data size.