Skip to content

Commit edbc9c1

Browse files
committed
Update Readme and SSLClient.
1 parent 54964aa commit edbc9c1

File tree

6 files changed

+124
-19
lines changed

6 files changed

+124
-19
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,11 +946,13 @@ param **`pageSize`** (integer) The maximum number of files to return per page.
946946

947947
param **`orderBy`** (string) A comma-separated list of sort keys.
948948

949-
Note: Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'name_natural', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and 'viewedByMeTime'.
949+
Note: Valid keys are `createdTime`, `folder`, `modifiedByMeTime`, `modifiedTime`, `name`, `name_natural`, `quotaBytesUsed`, `recency`, `sharedWithMeTime`, `starred`, and `viewedByMeTime`.
950950

951-
Each key sorts ascending by default, but may be reversed with the 'desc' modifier.
951+
Each key sorts ascending by default, but may be reversed with the `desc` modifier.
952952

953-
Example usage: ?orderBy=folder,modifiedTime desc,name.
953+
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.
954+
955+
Please consult [Google Drive API doc](https://developers.google.com/drive/api/reference/rest/v3/files/list) for the more detail.
954956

955957
param **`pageToken`** (string) The token for continuing a previous list request on the next page.
956958

src/client/SSLClient/ESP_SSLClient.h

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
*
3-
* The ESP SSL Client Class, ESP_SSLClient.h v2.1.3
3+
* The ESP SSL Client Class, ESP_SSLClient.h v2.1.5
44
*
5-
* Created August 13, 2023
5+
* Created August 22, 2023
66
*
77
* The MIT License (MIT)
88
* Copyright (c) 2023 K. Suwatchai (Mobizt)
@@ -38,13 +38,42 @@
3838
#if defined(USE_EMBED_SSL_ENGINE) || defined(USE_LIB_SSL_ENGINE)
3939
#include "client/BSSL_TCP_Client.h"
4040
class ESP_SSLClient : public BSSL_TCP_Client
41+
{
42+
public:
43+
ESP_SSLClient(){};
44+
~ESP_SSLClient(){};
45+
};
46+
47+
class ESP_SSLClient2 : public BSSL_TCP_Client
48+
{
49+
public:
50+
ESP_SSLClient2(Client &client, bool enableSSL = true) : _base_client(client)
51+
{
52+
setClient(&_base_client, enableSSL);
53+
};
54+
~ESP_SSLClient2(){};
55+
56+
private:
57+
Client &_base_client;
58+
};
59+
4160
#else
4261
class ESP_SSLClient
43-
#endif
4462
{
4563
public:
4664
ESP_SSLClient(){};
4765
~ESP_SSLClient(){};
4866
};
4967

50-
#endif
68+
class ESP_SSLClient2
69+
{
70+
public:
71+
ESP_SSLClient2(Client &client, bool enableSSL = true) : _base_client(client){};
72+
~ESP_SSLClient2(){};
73+
74+
private:
75+
Client &_base_client;
76+
};
77+
#endif
78+
79+
#endif

src/client/SSLClient/client/BSSL_SSL_Client.cpp

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* BSSL_SSL_Client library v1.0.9 for Arduino devices.
2+
* BSSL_SSL_Client library v1.0.10 for Arduino devices.
33
*
4-
* Created August 13, 2003
4+
* Created August 22, 2003
55
*
66
* This work contains codes based on WiFiClientSecure from Earle F. Philhower and SSLClient from OSU OPEnS Lab.
77
*
@@ -194,6 +194,16 @@ uint8_t BSSL_SSL_Client::connected()
194194
return c_con && br_con;
195195
}
196196

197+
void BSSL_SSL_Client::validate(const char *host, uint16_t port)
198+
{
199+
mConnectionValidate(host, IPAddress(), port);
200+
}
201+
202+
void BSSL_SSL_Client::validate(IPAddress ip, uint16_t port)
203+
{
204+
mConnectionValidate(nullptr, ip, port);
205+
}
206+
197207
int BSSL_SSL_Client::available()
198208
{
199209
if (!mIsClientInitialized(false))
@@ -425,9 +435,14 @@ int BSSL_SSL_Client::connectSSL(IPAddress ip, uint16_t port)
425435
if (!mIsClientInitialized(true))
426436
return 0;
427437

438+
validate(ip, port);
439+
428440
if (!_basic_client->connected() && !mConnectBasicClient(nullptr, ip, port))
429441
return 0;
430442

443+
_ip = ip;
444+
_port = port;
445+
431446
return mConnectSSL(nullptr);
432447
}
433448

@@ -437,9 +452,14 @@ int BSSL_SSL_Client::connectSSL(const char *host, uint16_t port)
437452
if (!mIsClientInitialized(true))
438453
return 0;
439454

455+
validate(host, port);
456+
440457
if (!_basic_client->connected() && !mConnectBasicClient(host, IPAddress(), port))
441458
return 0;
442459

460+
_host = host;
461+
_port = port;
462+
443463
return mConnectSSL(host);
444464
}
445465

@@ -1374,7 +1394,8 @@ int BSSL_SSL_Client::mIsClientInitialized(bool notify)
13741394

13751395
int BSSL_SSL_Client::mConnectBasicClient(const char *host, IPAddress ip, uint16_t port)
13761396
{
1377-
if (!mIsClientInitialized(true))
1397+
1398+
if (!mConnectionValidate(host, ip, port))
13781399
return 0;
13791400

13801401
if (!(host ? _basic_client->connect(host, port) : _basic_client->connect(ip, port)))
@@ -1570,6 +1591,22 @@ int BSSL_SSL_Client::mConnectSSL(const char *host)
15701591
return 1;
15711592
}
15721593

1594+
bool BSSL_SSL_Client::mConnectionValidate(const char *host, IPAddress ip, uint16_t port)
1595+
{
1596+
if (!mIsClientInitialized(true))
1597+
return false;
1598+
1599+
if (_basic_client && _basic_client->connected() &&
1600+
host
1601+
? (strcasecmp(host, _host.c_str()) != 0 || port != _port)
1602+
: (ip != _ip || port != _port))
1603+
{
1604+
_basic_client->stop();
1605+
}
1606+
1607+
return true;
1608+
}
1609+
15731610
int BSSL_SSL_Client::mRunUntil(const unsigned target, unsigned long timeout)
15741611
{
15751612
unsigned lastState = 0;

src/client/SSLClient/client/BSSL_SSL_Client.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* BSSL_SSL_Client library v1.0.9 for Arduino devices.
2+
* BSSL_SSL_Client library v1.0.10 for Arduino devices.
33
*
4-
* Created August 13, 2003
4+
* Created August 22, 2003
55
*
66
* This work contains codes based on WiFiClientSecure from Earle F. Philhower and SSLClient from OSU OPEnS Lab.
77
*
@@ -98,6 +98,10 @@ class BSSL_SSL_Client : public Client
9898

9999
uint8_t connected() override;
100100

101+
void validate(const char* host, uint16_t port);
102+
103+
void validate(IPAddress ip, uint16_t port);
104+
101105
int available() override;
102106

103107
int read() override;
@@ -124,6 +128,8 @@ class BSSL_SSL_Client : public Client
124128

125129
int connectSSL(const char *host, uint16_t port);
126130

131+
132+
127133
void stop() override;
128134

129135
void setTimeout(unsigned int timeoutMs);
@@ -234,6 +240,8 @@ class BSSL_SSL_Client : public Client
234240

235241
int mConnectSSL(const char *host = nullptr);
236242

243+
bool mConnectionValidate(const char *host, IPAddress ip, uint16_t port);
244+
237245
int mRunUntil(const unsigned target, unsigned long timeout = 0);
238246

239247
unsigned mUpdateEngine();
@@ -333,6 +341,9 @@ class BSSL_SSL_Client : public Client
333341
unsigned long _timeout = 15000;
334342
unsigned long _handshake_timeout = 60000;
335343
bool _isSSLEnabled = false;
344+
String _host;
345+
uint16_t _port;
346+
IPAddress _ip;
336347
};
337348

338349
#endif

src/client/SSLClient/client/BSSL_TCP_Client.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* BSSL_TCP_Client v2.0.10 for Arduino devices.
2+
* BSSL_TCP_Client v2.0.11 for Arduino devices.
33
*
4-
* Created August 13, 2023
4+
* Created August 22, 2023
55
*
66
* The MIT License (MIT)
77
* Copyright (c) 2023 K. Suwatchai (Mobizt)
@@ -134,6 +134,16 @@ uint8_t BSSL_TCP_Client::connected()
134134
return _ssl_client.connected();
135135
}
136136

137+
void BSSL_TCP_Client::validate(const char *host, uint16_t port)
138+
{
139+
_ssl_client.validate(host, port);
140+
}
141+
142+
void BSSL_TCP_Client::validate(IPAddress ip, uint16_t port)
143+
{
144+
_ssl_client.validate(ip, port);
145+
}
146+
137147
int BSSL_TCP_Client::available()
138148
{
139149
return _ssl_client.available();

src/client/SSLClient/client/BSSL_TCP_Client.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* BSSL_TCP_Client v2.0.10 for Arduino devices.
2+
* BSSL_TCP_Client v2.0.11 for Arduino devices.
33
*
4-
* Created August 13, 2023
4+
* Created August 22, 2023
55
*
66
* The MIT License (MIT)
77
* Copyright (c) 2023 K. Suwatchai (Mobizt)
@@ -103,7 +103,7 @@ class BSSL_TCP_Client : public Client
103103
/**
104104
* Connect to server.
105105
* @param ip The server IP to connect.
106-
* @param port The server port to connecte.
106+
* @param port The server port to connect.
107107
* @param timeout The connection time out in miiliseconds.
108108
* @return 1 for success or 0 for error.
109109
*/
@@ -112,15 +112,15 @@ class BSSL_TCP_Client : public Client
112112
/**
113113
* Connect to server.
114114
* @param host The server host name.
115-
* @param port The server port to connecte.
115+
* @param port The server port to connect.
116116
* @return 1 for success or 0 for error.
117117
*/
118118
int connect(const char *host, uint16_t port) override;
119119

120120
/**
121121
* Connect to server.
122122
* @param host The server host name.
123-
* @param port The server port to connecte.
123+
* @param port The server port to connect.
124124
* @param timeout The connection time out in miiliseconds.
125125
* @return 1 for success or 0 for error.
126126
*/
@@ -132,6 +132,22 @@ class BSSL_TCP_Client : public Client
132132
*/
133133
uint8_t connected() override;
134134

135+
/**
136+
* Validate the last Client connection with these host and port.
137+
* @param host The server host name.
138+
* @param port The server port to connect.
139+
* The Client connection will be closed when the provided host or port is not match with that of last connection.
140+
*/
141+
void validate(const char *host, uint16_t port);
142+
143+
/**
144+
* Validate the last Client connection with these IP and port.
145+
* @param ip The server IP to connect.
146+
* @param port The server port to connect.
147+
* The Client connection will be closed when the provided IP or port is not match with that of last connection.
148+
*/
149+
void validate(IPAddress ip, uint16_t port);
150+
135151
/**
136152
* Get available data size to read.
137153
* @return The avaiable data size.

0 commit comments

Comments
 (0)