Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork218
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
+296 −56
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletionslibraries/Ethernet/src/EthernetClient.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionslibraries/Ethernet/src/EthernetSSLClient.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionlibraries/GSM/src/GSMClient.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,6 +19,6 @@ | ||
| #include"GSMClient.h" | ||
| arduino::GSMClient::GSMClient():AClient(100) { | ||
| } | ||
4 changes: 2 additions & 2 deletionslibraries/GSM/src/GSMClient.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionlibraries/GSM/src/GSMSSLClient.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,6 +19,6 @@ | ||
| #include"GSMSSLClient.h" | ||
| arduino::GSMSSLClient::GSMSSLClient():ASslClient(100) { | ||
| } | ||
4 changes: 2 additions & 2 deletionslibraries/GSM/src/GSMSSLClient.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
18 changes: 15 additions & 3 deletionslibraries/SE05X/src/WiFiSSLSE050Client.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
24 changes: 18 additions & 6 deletionslibraries/SE05X/src/WiFiSSLSE050Client.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,18 +23,17 @@ | ||
| #include"SE05X.h" | ||
| #include"WiFiSSLClient.h" | ||
| #include"MbedSSLClient.h" | ||
| externconstchar CA_CERTIFICATES[]; | ||
| namespacearduino { | ||
| classMbedSSLSE050Client :publicarduino::MbedSSLClient { | ||
| public: | ||
| MbedSSLSE050Client(); | ||
| voidsetEccSlot(int KeySlot,const byte cert[],int certLen); | ||
| private: | ||
| @@ -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())) { | ||
| return0; | ||
| } | ||
| return1; | ||
| } | ||
| }; | ||
| classWiFiSSLSE050Client :publicarduino::WiFiSSLClient { | ||
| public: | ||
| voidsetEccSlot(int KeySlot,const byte cert[],int certLen); | ||
JAndrassy marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| protected: | ||
| virtualvoidnewMbedClient(); | ||
| }; | ||
| } | ||
| #endif/* WIFISSLSE050CLIENT_H*/ | ||
149 changes: 149 additions & 0 deletionslibraries/SocketWrapper/src/AClient.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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 |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.