Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
Fix unhandle exception error in smtp
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Aug 9, 2019
1 parent 5f47a98 commit d0875a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
22 changes: 10 additions & 12 deletions src/HTTPClientESP32Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ HTTPClientESP32Ex::~HTTPClientESP32Ex()
bool HTTPClientESP32Ex::http_begin(const char *host, uint16_t port, const char *uri, const char *CAcert)
{
http_transportTraits.reset(nullptr);
memset(_host, 0, sizeof _host);
strcpy(_host, host);

_host = host;
_port = port;
memset(_uri, 0, sizeof _uri);
strcpy(_uri, uri);
_uri = uri;
http_transportTraits = TransportTraitsPtr(new TLSTraits(CAcert));
return true;
}
Expand Down Expand Up @@ -153,13 +152,13 @@ bool HTTPClientESP32Ex::http_connect(void)

_tcp = http_transportTraits->create();

if (!http_transportTraits->verify(*_tcp, _host, false, _debugCallback))
if (!http_transportTraits->verify(*_tcp, _host.c_str(), false, _debugCallback))
{
_tcp->stop();
return false;
}

if (!_tcp->connect(_host, _port))
if (!_tcp->connect(_host.c_str(), _port))
return false;

return http_connected();
Expand All @@ -178,22 +177,21 @@ bool HTTPClientESP32Ex::http_connect(bool starttls)
return false;

_tcp = http_transportTraits->create();


if (!http_transportTraits->verify(*_tcp, _host, starttls, _debugCallback))
if (!http_transportTraits->verify(*_tcp, _host.c_str(), starttls, _debugCallback))
{
_tcp->stop();
return false;
}


if (!_tcp->connect(_host, _port))
if (!_tcp->connect(_host.c_str(), _port))
return false;

return http_connected();
}

void HTTPClientESP32Ex::setDebugCallback(DebugMsgCallback cb){
_debugCallback = std::move(cb);
void HTTPClientESP32Ex::setDebugCallback(DebugMsgCallback cb)
{
_debugCallback = std::move(cb);
}
#endif
48 changes: 24 additions & 24 deletions src/HTTPClientESP32Ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@

class HTTPClientESP32Ex : public HTTPClient
{
public:
HTTPClientESP32Ex();
~HTTPClientESP32Ex();
public:
HTTPClientESP32Ex();
~HTTPClientESP32Ex();

/**
/**
* Initialization of new http connection.
* \param host - Host name without protocols.
* \param port - Server's port.
Expand All @@ -54,50 +54,50 @@ class HTTPClientESP32Ex : public HTTPClient
* \return True as default.
* If no certificate string provided, use (const char*)NULL to CAcert param
*/
bool http_begin(const char *host, uint16_t port, const char *uri, const char *CAcert);
bool http_begin(const char *host, uint16_t port, const char *uri, const char *CAcert);

/**
/**
* Check the http connection status.
* \return True if connected.
*/
bool http_connected();
bool http_connected();

/**
/**
* Establish http connection if header provided and send it, send payload if provided.
* \param header - The header string (constant chars array).
* \param payload - The payload string (constant chars array), optional.
* \return http status code, Return zero if new http connection and header and/or payload sent
* with no error or no header and payload provided. If obly payload provided, no new http connection was established.
*/
int http_sendRequest(const char *header, const char *payload);
int http_sendRequest(const char *header, const char *payload);

/**
/**
* Send extra header without making new http connection (if http_sendRequest has been called)
* \param header - The header string (constant chars array).
* \return True if header sending success.
* Need to call http_sendRequest with header first.
*/
bool http_sendHeader(const char *header);
bool http_sendHeader(const char *header);

/**
/**
* Get the WiFi client pointer.
* \return WiFi client pointer.
*/
WiFiClient *http_getStreamPtr(void);
WiFiClient *http_getStreamPtr(void);

uint16_t tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
bool http_connect(void);
bool http_connect(bool starttls);
void setDebugCallback(DebugMsgCallback cb);
uint16_t tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
bool http_connect(void);
bool http_connect(bool starttls);
void setDebugCallback(DebugMsgCallback cb);

protected:
TransportTraitsPtr http_transportTraits;
std::unique_ptr<WiFiClient> _tcp;
DebugMsgCallback _debugCallback = NULL;
protected:
TransportTraitsPtr http_transportTraits;
std::unique_ptr<WiFiClient> _tcp;
DebugMsgCallback _debugCallback = NULL;

char _host[200];
char _uri[200];
uint16_t _port = 0;
std::string _host = "";
std::string _uri = "";
uint16_t _port = 0;
};

#endif /* HTTPClientESP32Ex_H_ */

0 comments on commit d0875a3

Please sign in to comment.