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

SocketWrapper - copyable networking clients#768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
pennam merged 1 commit intoarduino:mainfromJAndrassy:copyable_clients
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletionslibraries/Ethernet/src/EthernetClient.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,11 +21,11 @@
#defineethernetclient_h

#include"Ethernet.h"
#include"MbedClient.h"
#include"AClient.h"

namespacearduino {

classEthernetClient :publicMbedClient {
classEthernetClient :publicAClient {
NetworkInterface *getNetwork() {
return Ethernet.getNetwork();
}
Expand Down
4 changes: 2 additions & 2 deletionslibraries/Ethernet/src/EthernetSSLClient.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,13 @@
#defineETHERNETSSLCLIENT_H

#include"EthernetClient.h"
#include"MbedSSLClient.h"
#include"AClient.h"

externconstchar CA_CERTIFICATES[];

namespacearduino {

classEthernetSSLClient :publicarduino::MbedSSLClient {
classEthernetSSLClient :publicarduino::ASslClient {
NetworkInterface *getNetwork() {
return Ethernet.getNetwork();
}
Expand Down
2 changes: 1 addition & 1 deletionlibraries/GSM/src/GSMClient.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,6 @@

#include"GSMClient.h"

arduino::GSMClient::GSMClient():MbedClient(100) {
arduino::GSMClient::GSMClient():AClient(100) {

}
4 changes: 2 additions & 2 deletionslibraries/GSM/src/GSMClient.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,11 +21,11 @@
#definegsmclient_h

#include"GSM.h"
#include"MbedClient.h"
#include"AClient.h"

namespacearduino {

classGSMClient :publicMbedClient {
classGSMClient :publicAClient {
public:
GSMClient();

Expand Down
2 changes: 1 addition & 1 deletionlibraries/GSM/src/GSMSSLClient.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,6 @@

#include"GSMSSLClient.h"

arduino::GSMSSLClient::GSMSSLClient():MbedSSLClient(100) {
arduino::GSMSSLClient::GSMSSLClient():ASslClient(100) {

}
4 changes: 2 additions & 2 deletionslibraries/GSM/src/GSMSSLClient.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,13 @@
#defineGSMSSLCLIENT_H

#include"GSM.h"
#include"MbedSSLClient.h"
#include"AClient.h"

externconstchar CA_CERTIFICATES[];

namespacearduino {

classGSMSSLClient :publicarduino::MbedSSLClient {
classGSMSSLClient :publicarduino::ASslClient {
public:
GSMSSLClient();

Expand Down
18 changes: 15 additions & 3 deletionslibraries/SE05X/src/WiFiSSLSE050Client.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,13 +19,25 @@

#include"WiFiSSLSE050Client.h"

arduino::WiFiSSLSE050Client::WiFiSSLSE050Client() {
onBeforeConnect(mbed::callback(this, &WiFiSSLSE050Client::setRootCAClientCertKey));
arduino::MbedSSLSE050Client::MbedSSLSE050Client() {
onBeforeConnect(mbed::callback(this, &MbedSSLSE050Client::setRootCAClientCertKey));
};

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

_keySlot = KeySlot;
_client_cert_len = certLen;
_client_cert = cert;
}

voidWiFiSSLSE050Client::setEccSlot(int KeySlot,const byte cert[],int certLen) {
if (!client) {
newMbedClient();
}
static_cast<MbedSSLSE050Client*>(client.get())->setEccSlot(KeySlot, cert, certLen);
}

voidWiFiSSLSE050Client::newMbedClient() {
client.reset(newMbedSSLSE050Client());
client->setNetwork(getNetwork());
}
24 changes: 18 additions & 6 deletionslibraries/SE05X/src/WiFiSSLSE050Client.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,18 +23,17 @@

#include"SE05X.h"
#include"WiFiSSLClient.h"
#include"MbedSSLClient.h"

externconstchar CA_CERTIFICATES[];

namespacearduino {

classWiFiSSLSE050Client :publicarduino::WiFiSSLClient {
classMbedSSLSE050Client :publicarduino::MbedSSLClient {

public:
WiFiSSLSE050Client();
virtual~WiFiSSLSE050Client() {
stop();
}
MbedSSLSE050Client();

voidsetEccSlot(int KeySlot,const byte cert[],int certLen);

private:
Expand All@@ -57,14 +56,27 @@ class WiFiSSLSE050Client : public arduino::WiFiSSLClient {
return0;
}

if( NSAPI_ERROR_OK != ((TLSSocket*)sock)->set_client_cert_key((void*)_client_cert, (size_t)_client_cert_len, &_keyObject, SE05X.getDeviceCtx())) {
if( NSAPI_ERROR_OK != ((TLSSocket*)sock)->set_client_cert_key((void*)_client_cert,
(size_t)_client_cert_len,
&_keyObject,
SE05X.getDeviceCtx())) {
return0;
}

return1;
}
};

classWiFiSSLSE050Client :publicarduino::WiFiSSLClient {

public:

voidsetEccSlot(int KeySlot,const byte cert[],int certLen);

protected:
virtualvoidnewMbedClient();
};

}

#endif/* WIFISSLSE050CLIENT_H*/
149 changes: 149 additions & 0 deletionslibraries/SocketWrapper/src/AClient.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@

#include"AClient.h"
#include"MbedSSLClient.h"

AClient::AClient(unsignedlong timeout) {
setSocketTimeout(timeout);
}

voidarduino::AClient::newMbedClient() {
client.reset(newMbedClient());
client->setNetwork(getNetwork());
}

arduino::AClient::operatorbool() {
return client && *client;
}

voidarduino::AClient::setSocket(Socket *sock) {
if (!client) {
newMbedClient();
}
client->setSocket(sock);
}

voidarduino::AClient::setSocketTimeout(unsignedlong timeout) {
if (!client) {
newMbedClient();
}
client->setSocketTimeout(timeout);
}

intarduino::AClient::connect(IPAddress ip,uint16_t port) {
if (!client) {
newMbedClient();
}
return client->connect(ip, port);
}

intarduino::AClient::connect(constchar *host,uint16_t port) {
if (!client) {
newMbedClient();
}
return client->connect(host, port);
}

intarduino::AClient::connectSSL(IPAddress ip,uint16_t port) {
if (!client) {
newMbedClient();
}
return client->connectSSL(ip, port);
}

intarduino::AClient::connectSSL(constchar *host,uint16_t port,bool disableSNI) {
if (!client) {
newMbedClient();
}
return client->connectSSL(host, port, disableSNI);
}

voidarduino::AClient::stop() {
if (!client)
return;
client->stop();
}

uint8_tarduino::AClient::connected() {
if (!client)
returnfalse;
return client->connected();
}

uint8_tarduino::AClient::status() {
if (!client)
returnfalse;
return client->status();
}

IPAddressarduino::AClient::remoteIP() {
if (!client)
return INADDR_NONE;
return client->remoteIP();
}

uint16_tarduino::AClient::remotePort() {
if (!client)
return0;
return client->remotePort();
}

size_tarduino::AClient::write(uint8_t b) {
if (!client)
return0;
return client->write(b);
}

size_tarduino::AClient::write(constuint8_t *buf,size_t size) {
if (!client)
return0;
return client->write(buf, size);
}

voidarduino::AClient::flush() {
if (!client)
return;
client->flush();
}

intarduino::AClient::available() {
if (!client)
return0;
return client->available();
}

intarduino::AClient::read() {
if (!client)
return -1;
return client->read();
}

intarduino::AClient::read(uint8_t *buf,size_t size) {
if (!client)
return0;
return client->read(buf, size);
}

intarduino::AClient::peek() {
if (!client)
return -1;
return client->peek();
}

voidarduino::ASslClient::newMbedClient() {
client.reset(newMbedSSLClient());
client->setNetwork(getNetwork());
}

voidarduino::ASslClient::disableSNI(bool statusSNI) {
if (!client) {
newMbedClient();
}
static_cast<MbedSSLClient*>(client.get())->disableSNI(statusSNI);
}

voidarduino::ASslClient::appendCustomCACert(constchar* ca_cert) {
if (!client) {
newMbedClient();
}
static_cast<MbedSSLClient*>(client.get())->appendCustomCACert(ca_cert);
}
85 changes: 85 additions & 0 deletionslibraries/SocketWrapper/src/AClient.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
/*
AClient.h - Copyable Client implementation for Mbed Core
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef MBEDACLIENT_H
#defineMBEDACLIENT_H

#include<Arduino.h>
#include"MbedClient.h"

namespacearduino {

classAClient :publicClient {
public:

AClient() {}
AClient(unsignedlong timeout);

virtualintconnect(IPAddress ip,uint16_t port);
virtualintconnect(constchar *host,uint16_t port);
intconnectSSL(IPAddress ip,uint16_t port);
intconnectSSL(constchar* host,uint16_t port,bool disableSNI =false);
virtualvoidstop();

virtualexplicitoperatorbool();
virtualuint8_tconnected();
uint8_tstatus();

IPAddressremoteIP();
uint16_tremotePort();

virtualsize_twrite(uint8_t);
virtualsize_twrite(constuint8_t *buf,size_t size);
virtualvoidflush();

virtualintavailable();
virtualintread();
virtualintread(uint8_t *buf,size_t size);
virtualintpeek();

using Print::write;

voidsetSocketTimeout(unsignedlong timeout);

protected:
friendclassEthernetServer;
friendclassWiFiServer;

std::shared_ptr<MbedClient> client;
virtual NetworkInterface*getNetwork() = 0;
virtualvoidnewMbedClient();
voidsetSocket(Socket* sock);

};

classASslClient :publicAClient {
public:

ASslClient() {}
ASslClient(unsignedlong timeout) : AClient(timeout) {}

voiddisableSNI(bool statusSNI);

voidappendCustomCACert(constchar* ca_cert);

protected:
virtualvoidnewMbedClient();
};

}
#endif
Loading

[8]ページ先頭

©2009-2025 Movatter.jp