|
| 1 | + |
| 2 | +#include "AClient.h" |
| 3 | +#include "MbedSSLClient.h" |
| 4 | + |
| 5 | +AClient::AClient(unsigned long timeout) { |
| 6 | + setSocketTimeout(timeout); |
| 7 | +} |
| 8 | + |
| 9 | +void arduino::AClient::newMbedClient() { |
| 10 | + client.reset(new MbedClient()); |
| 11 | + client->setNetwork(getNetwork()); |
| 12 | +} |
| 13 | + |
| 14 | +arduino::AClient::operator bool() { |
| 15 | + return client && *client; |
| 16 | +} |
| 17 | + |
| 18 | +void arduino::AClient::setSocket(Socket *sock) { |
| 19 | + if (!client) { |
| 20 | + newMbedClient(); |
| 21 | + } |
| 22 | + client->setSocket(sock); |
| 23 | +} |
| 24 | + |
| 25 | +void arduino::AClient::setSocketTimeout(unsigned long timeout) { |
| 26 | + if (!client) { |
| 27 | + newMbedClient(); |
| 28 | + } |
| 29 | + client->setSocketTimeout(timeout); |
| 30 | +} |
| 31 | + |
| 32 | +int arduino::AClient::connect(IPAddress ip, uint16_t port) { |
| 33 | + if (!client) { |
| 34 | + newMbedClient(); |
| 35 | + } |
| 36 | + return client->connect(ip, port); |
| 37 | +} |
| 38 | + |
| 39 | +int arduino::AClient::connect(const char *host, uint16_t port) { |
| 40 | + if (!client) { |
| 41 | + newMbedClient(); |
| 42 | + } |
| 43 | + return client->connect(host, port); |
| 44 | +} |
| 45 | + |
| 46 | +int arduino::AClient::connectSSL(IPAddress ip, uint16_t port) { |
| 47 | + if (!client) { |
| 48 | + newMbedClient(); |
| 49 | + } |
| 50 | + return client->connectSSL(ip, port); |
| 51 | +} |
| 52 | + |
| 53 | +int arduino::AClient::connectSSL(const char *host, uint16_t port, bool disableSNI) { |
| 54 | + if (!client) { |
| 55 | + newMbedClient(); |
| 56 | + } |
| 57 | + return client->connectSSL(host, port, disableSNI); |
| 58 | +} |
| 59 | + |
| 60 | +void arduino::AClient::stop() { |
| 61 | + if (!client) |
| 62 | + return; |
| 63 | + client->stop(); |
| 64 | +} |
| 65 | + |
| 66 | +uint8_t arduino::AClient::connected() { |
| 67 | + if (!client) |
| 68 | + return false; |
| 69 | + return client->connected(); |
| 70 | +} |
| 71 | + |
| 72 | +uint8_t arduino::AClient::status() { |
| 73 | + if (!client) |
| 74 | + return false; |
| 75 | + return client->status(); |
| 76 | +} |
| 77 | + |
| 78 | +IPAddress arduino::AClient::remoteIP() { |
| 79 | + if (!client) |
| 80 | + return INADDR_NONE; |
| 81 | + return client->remoteIP(); |
| 82 | +} |
| 83 | + |
| 84 | +uint16_t arduino::AClient::remotePort() { |
| 85 | + if (!client) |
| 86 | + return 0; |
| 87 | + return client->remotePort(); |
| 88 | +} |
| 89 | + |
| 90 | +size_t arduino::AClient::write(uint8_t b) { |
| 91 | + if (!client) |
| 92 | + return 0; |
| 93 | + return client->write(b); |
| 94 | +} |
| 95 | + |
| 96 | +size_t arduino::AClient::write(const uint8_t *buf, size_t size) { |
| 97 | + if (!client) |
| 98 | + return 0; |
| 99 | + return client->write(buf, size); |
| 100 | +} |
| 101 | + |
| 102 | +void arduino::AClient::flush() { |
| 103 | + if (!client) |
| 104 | + return; |
| 105 | + client->flush(); |
| 106 | +} |
| 107 | + |
| 108 | +int arduino::AClient::available() { |
| 109 | + if (!client) |
| 110 | + return 0; |
| 111 | + return client->available(); |
| 112 | +} |
| 113 | + |
| 114 | +int arduino::AClient::read() { |
| 115 | + if (!client) |
| 116 | + return -1; |
| 117 | + return client->read(); |
| 118 | +} |
| 119 | + |
| 120 | +int arduino::AClient::read(uint8_t *buf, size_t size) { |
| 121 | + if (!client) |
| 122 | + return 0; |
| 123 | + return client->read(buf, size); |
| 124 | +} |
| 125 | + |
| 126 | +int arduino::AClient::peek() { |
| 127 | + if (!client) |
| 128 | + return -1; |
| 129 | + return client->peek(); |
| 130 | +} |
| 131 | + |
| 132 | +void arduino::ASslClient::newMbedClient() { |
| 133 | + client.reset(new MbedSSLClient()); |
| 134 | + client->setNetwork(getNetwork()); |
| 135 | +} |
| 136 | + |
| 137 | +void arduino::ASslClient::disableSNI(bool statusSNI) { |
| 138 | + if (!client) { |
| 139 | + newMbedClient(); |
| 140 | + } |
| 141 | + static_cast<MbedSSLClient*>(client.get())->disableSNI(statusSNI); |
| 142 | +} |
| 143 | + |
| 144 | +void arduino::ASslClient::appendCustomCACert(const char* ca_cert) { |
| 145 | + if (!client) { |
| 146 | + newMbedClient(); |
| 147 | + } |
| 148 | + static_cast<MbedSSLClient*>(client.get())->appendCustomCACert(ca_cert); |
| 149 | +} |
0 commit comments