Own fork of MbedSmartRest
Dependents: MbedSmartRestMain MbedSmartRestMain
Fork of MbedSmartRest by
Diff: MbedClient.cpp
- Revision:
- 2:45a6e44a4fb4
- Parent:
- 1:9a11a331e340
- Child:
- 6:cd7ba1ddb664
--- a/MbedClient.cpp Mon Jul 07 16:14:51 2014 +0200 +++ b/MbedClient.cpp Mon Jul 07 17:08:02 2014 +0200 @@ -32,9 +32,16 @@ #include "b64.h" #include "mbed.h" -MbedClient::MbedClient(const char* host, uint16_t port, const char* username, const char* password) - : _host(host), _port(port), _username(username), _password(password), _filter(_source), _source(_sock), _sink(_sock), _sock() +MbedClient::MbedClient(const char* host, uint16_t port) : + _host(host), + _port(port), + _filter(_source), + _source(_sock), + _sink(_sock), + _sock() { + _username = NULL; + _password = NULL; _state = MBED_STATE_INIT; } @@ -42,6 +49,16 @@ { } +uint8_t MbedClient::setAuthorization(const char* username, const char* password) +{ + if (_state != MBED_STATE_INIT) + return CLIENT_INTERNAL_ERROR; + + _username = username; + _password = password; + return CLIENT_OK; +} + uint8_t MbedClient::beginRequest() { if (_state != MBED_STATE_INIT) @@ -58,7 +75,8 @@ (!send("\r\n"))) return CLIENT_CONNECTION_ERROR; - if ((strlen(_username) > 0) && (strlen(_password) > 0)) { + if ((_username != NULL) && (strlen(_username) > 0) && + (_password != NULL) && (strlen(_password) > 0)) { if (!sendBasicAuth()) return CLIENT_CONNECTION_ERROR; }