Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit57cabb9

Browse files
committed
SocketWrapper - copyable networking clients
1 parent29b84df commit57cabb9

File tree

14 files changed

+296
-56
lines changed

14 files changed

+296
-56
lines changed

‎libraries/Ethernet/src/EthernetClient.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#defineethernetclient_h
2222

2323
#include"Ethernet.h"
24-
#include"MbedClient.h"
24+
#include"AClient.h"
2525

2626
namespacearduino {
2727

28-
classEthernetClient :publicMbedClient {
28+
classEthernetClient :publicAClient {
2929
NetworkInterface *getNetwork() {
3030
return Ethernet.getNetwork();
3131
}

‎libraries/Ethernet/src/EthernetSSLClient.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
#defineETHERNETSSLCLIENT_H
2222

2323
#include"EthernetClient.h"
24-
#include"MbedSSLClient.h"
24+
#include"AClient.h"
2525

2626
externconstchar CA_CERTIFICATES[];
2727

2828
namespacearduino {
2929

30-
classEthernetSSLClient :publicarduino::MbedSSLClient {
30+
classEthernetSSLClient :publicarduino::ASslClient {
3131
NetworkInterface *getNetwork() {
3232
return Ethernet.getNetwork();
3333
}

‎libraries/GSM/src/GSMClient.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919

2020
#include"GSMClient.h"
2121

22-
arduino::GSMClient::GSMClient():MbedClient(100) {
22+
arduino::GSMClient::GSMClient():AClient(100) {
2323

2424
}

‎libraries/GSM/src/GSMClient.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#definegsmclient_h
2222

2323
#include"GSM.h"
24-
#include"MbedClient.h"
24+
#include"AClient.h"
2525

2626
namespacearduino {
2727

28-
classGSMClient :publicMbedClient {
28+
classGSMClient :publicAClient {
2929
public:
3030
GSMClient();
3131

‎libraries/GSM/src/GSMSSLClient.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919

2020
#include"GSMSSLClient.h"
2121

22-
arduino::GSMSSLClient::GSMSSLClient():MbedSSLClient(100) {
22+
arduino::GSMSSLClient::GSMSSLClient():ASslClient(100) {
2323

2424
}

‎libraries/GSM/src/GSMSSLClient.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
#defineGSMSSLCLIENT_H
2222

2323
#include"GSM.h"
24-
#include"MbedSSLClient.h"
24+
#include"AClient.h"
2525

2626
externconstchar CA_CERTIFICATES[];
2727

2828
namespacearduino {
2929

30-
classGSMSSLClient :publicarduino::MbedSSLClient {
30+
classGSMSSLClient :publicarduino::ASslClient {
3131
public:
3232
GSMSSLClient();
3333

‎libraries/SE05X/src/WiFiSSLSE050Client.cpp‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@
1919

2020
#include"WiFiSSLSE050Client.h"
2121

22-
arduino::WiFiSSLSE050Client::WiFiSSLSE050Client() {
23-
onBeforeConnect(mbed::callback(this, &WiFiSSLSE050Client::setRootCAClientCertKey));
22+
arduino::MbedSSLSE050Client::MbedSSLSE050Client() {
23+
onBeforeConnect(mbed::callback(this, &MbedSSLSE050Client::setRootCAClientCertKey));
2424
};
2525

26-
voidarduino::WiFiSSLSE050Client::setEccSlot(int KeySlot,const byte cert[],int certLen) {
26+
voidarduino::MbedSSLSE050Client::setEccSlot(int KeySlot,const byte cert[],int certLen) {
2727

2828
_keySlot = KeySlot;
2929
_client_cert_len = certLen;
3030
_client_cert = cert;
3131
}
32+
33+
voidWiFiSSLSE050Client::setEccSlot(int KeySlot,const byte cert[],int certLen) {
34+
if (!client) {
35+
newMbedClient();
36+
}
37+
static_cast<MbedSSLSE050Client*>(client.get())->setEccSlot(KeySlot, cert, certLen);
38+
}
39+
40+
voidWiFiSSLSE050Client::newMbedClient() {
41+
client.reset(newMbedSSLSE050Client());
42+
client->setNetwork(getNetwork());
43+
}

‎libraries/SE05X/src/WiFiSSLSE050Client.h‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@
2323

2424
#include"SE05X.h"
2525
#include"WiFiSSLClient.h"
26+
#include"MbedSSLClient.h"
2627

2728
externconstchar CA_CERTIFICATES[];
2829

2930
namespacearduino {
3031

31-
classWiFiSSLSE050Client :publicarduino::WiFiSSLClient {
32+
classMbedSSLSE050Client :publicarduino::MbedSSLClient {
3233

3334
public:
34-
WiFiSSLSE050Client();
35-
virtual~WiFiSSLSE050Client() {
36-
stop();
37-
}
35+
MbedSSLSE050Client();
36+
3837
voidsetEccSlot(int KeySlot,const byte cert[],int certLen);
3938

4039
private:
@@ -57,14 +56,27 @@ class WiFiSSLSE050Client : public arduino::WiFiSSLClient {
5756
return0;
5857
}
5958

60-
if( NSAPI_ERROR_OK != ((TLSSocket*)sock)->set_client_cert_key((void*)_client_cert, (size_t)_client_cert_len, &_keyObject, SE05X.getDeviceCtx())) {
59+
if( NSAPI_ERROR_OK != ((TLSSocket*)sock)->set_client_cert_key((void*)_client_cert,
60+
(size_t)_client_cert_len,
61+
&_keyObject,
62+
SE05X.getDeviceCtx())) {
6163
return0;
6264
}
6365

6466
return1;
6567
}
6668
};
6769

70+
classWiFiSSLSE050Client :publicarduino::WiFiSSLClient {
71+
72+
public:
73+
74+
voidsetEccSlot(int KeySlot,const byte cert[],int certLen);
75+
76+
protected:
77+
virtualvoidnewMbedClient();
78+
};
79+
6880
}
6981

7082
#endif/* WIFISSLSE050CLIENT_H*/
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
2+
#include"AClient.h"
3+
#include"MbedSSLClient.h"
4+
5+
AClient::AClient(unsignedlong timeout) {
6+
setSocketTimeout(timeout);
7+
}
8+
9+
voidarduino::AClient::newMbedClient() {
10+
client.reset(newMbedClient());
11+
client->setNetwork(getNetwork());
12+
}
13+
14+
arduino::AClient::operatorbool() {
15+
return client && *client;
16+
}
17+
18+
voidarduino::AClient::setSocket(Socket *sock) {
19+
if (!client) {
20+
newMbedClient();
21+
}
22+
client->setSocket(sock);
23+
}
24+
25+
voidarduino::AClient::setSocketTimeout(unsignedlong timeout) {
26+
if (!client) {
27+
newMbedClient();
28+
}
29+
client->setSocketTimeout(timeout);
30+
}
31+
32+
intarduino::AClient::connect(IPAddress ip,uint16_t port) {
33+
if (!client) {
34+
newMbedClient();
35+
}
36+
return client->connect(ip, port);
37+
}
38+
39+
intarduino::AClient::connect(constchar *host,uint16_t port) {
40+
if (!client) {
41+
newMbedClient();
42+
}
43+
return client->connect(host, port);
44+
}
45+
46+
intarduino::AClient::connectSSL(IPAddress ip,uint16_t port) {
47+
if (!client) {
48+
newMbedClient();
49+
}
50+
return client->connectSSL(ip, port);
51+
}
52+
53+
intarduino::AClient::connectSSL(constchar *host,uint16_t port,bool disableSNI) {
54+
if (!client) {
55+
newMbedClient();
56+
}
57+
return client->connectSSL(host, port, disableSNI);
58+
}
59+
60+
voidarduino::AClient::stop() {
61+
if (!client)
62+
return;
63+
client->stop();
64+
}
65+
66+
uint8_tarduino::AClient::connected() {
67+
if (!client)
68+
returnfalse;
69+
return client->connected();
70+
}
71+
72+
uint8_tarduino::AClient::status() {
73+
if (!client)
74+
returnfalse;
75+
return client->status();
76+
}
77+
78+
IPAddressarduino::AClient::remoteIP() {
79+
if (!client)
80+
return INADDR_NONE;
81+
return client->remoteIP();
82+
}
83+
84+
uint16_tarduino::AClient::remotePort() {
85+
if (!client)
86+
return0;
87+
return client->remotePort();
88+
}
89+
90+
size_tarduino::AClient::write(uint8_t b) {
91+
if (!client)
92+
return0;
93+
return client->write(b);
94+
}
95+
96+
size_tarduino::AClient::write(constuint8_t *buf,size_t size) {
97+
if (!client)
98+
return0;
99+
return client->write(buf, size);
100+
}
101+
102+
voidarduino::AClient::flush() {
103+
if (!client)
104+
return;
105+
client->flush();
106+
}
107+
108+
intarduino::AClient::available() {
109+
if (!client)
110+
return0;
111+
return client->available();
112+
}
113+
114+
intarduino::AClient::read() {
115+
if (!client)
116+
return -1;
117+
return client->read();
118+
}
119+
120+
intarduino::AClient::read(uint8_t *buf,size_t size) {
121+
if (!client)
122+
return0;
123+
return client->read(buf, size);
124+
}
125+
126+
intarduino::AClient::peek() {
127+
if (!client)
128+
return -1;
129+
return client->peek();
130+
}
131+
132+
voidarduino::ASslClient::newMbedClient() {
133+
client.reset(newMbedSSLClient());
134+
client->setNetwork(getNetwork());
135+
}
136+
137+
voidarduino::ASslClient::disableSNI(bool statusSNI) {
138+
if (!client) {
139+
newMbedClient();
140+
}
141+
static_cast<MbedSSLClient*>(client.get())->disableSNI(statusSNI);
142+
}
143+
144+
voidarduino::ASslClient::appendCustomCACert(constchar* ca_cert) {
145+
if (!client) {
146+
newMbedClient();
147+
}
148+
static_cast<MbedSSLClient*>(client.get())->appendCustomCACert(ca_cert);
149+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
AClient.h - Copyable Client implementation for Mbed Core
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef MBEDACLIENT_H
20+
#defineMBEDACLIENT_H
21+
22+
#include<Arduino.h>
23+
#include"MbedClient.h"
24+
25+
namespacearduino {
26+
27+
classAClient :publicClient {
28+
public:
29+
30+
AClient() {}
31+
AClient(unsignedlong timeout);
32+
33+
virtualintconnect(IPAddress ip,uint16_t port);
34+
virtualintconnect(constchar *host,uint16_t port);
35+
intconnectSSL(IPAddress ip,uint16_t port);
36+
intconnectSSL(constchar* host,uint16_t port,bool disableSNI =false);
37+
virtualvoidstop();
38+
39+
virtualexplicitoperatorbool();
40+
virtualuint8_tconnected();
41+
uint8_tstatus();
42+
43+
IPAddressremoteIP();
44+
uint16_tremotePort();
45+
46+
virtualsize_twrite(uint8_t);
47+
virtualsize_twrite(constuint8_t *buf,size_t size);
48+
virtualvoidflush();
49+
50+
virtualintavailable();
51+
virtualintread();
52+
virtualintread(uint8_t *buf,size_t size);
53+
virtualintpeek();
54+
55+
using Print::write;
56+
57+
voidsetSocketTimeout(unsignedlong timeout);
58+
59+
protected:
60+
friendclassEthernetServer;
61+
friendclassWiFiServer;
62+
63+
std::shared_ptr<MbedClient> client;
64+
virtual NetworkInterface*getNetwork() = 0;
65+
virtualvoidnewMbedClient();
66+
voidsetSocket(Socket* sock);
67+
68+
};
69+
70+
classASslClient :publicAClient {
71+
public:
72+
73+
ASslClient() {}
74+
ASslClient(unsignedlong timeout) : AClient(timeout) {}
75+
76+
voiddisableSNI(bool statusSNI);
77+
78+
voidappendCustomCACert(constchar* ca_cert);
79+
80+
protected:
81+
virtualvoidnewMbedClient();
82+
};
83+
84+
}
85+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp