Skip to content

Commit

Permalink
Exposed the remote port and ip for the connections. (#1370)
Browse files Browse the repository at this point in the history
Closes: #1367
  • Loading branch information
slaff authored May 2, 2018
1 parent 963669d commit 34fdcff
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Sming/SmingCore/Network/Http/HttpConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class HttpConnection : protected TcpClient {
*/
HttpResponse* getResponse();

using TcpConnection::getRemoteIp;
using TcpConnection::getRemotePort;

using TcpClient::close;

#ifdef ENABLE_SSL
Expand Down
3 changes: 3 additions & 0 deletions Sming/SmingCore/Network/Http/HttpServerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class HttpServerConnection: public TcpClient

using TcpClient::send;

using TcpConnection::getRemoteIp;
using TcpConnection::getRemotePort;

protected:
virtual err_t onReceive(pbuf *buf);
virtual void onReadyToSendData(TcpConnectionEvent sourceEvent);
Expand Down
2 changes: 2 additions & 0 deletions Sming/Wiring/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class IPAddress : public Printable
operator uint32_t() { return *((uint32_t*)_address); };
operator ip_addr() { ip_addr ret; ret.addr = *((uint32_t*)_address); return ret; };
operator ip_addr*() { return (ip_addr*)_address; };

operator char*() { return (char *)toString().c_str(); }
#if LWIP_VERSION_MAJOR == 2
operator ip_addr_t*() { return (ip_addr_t*)_address; };
#endif
Expand Down
1 change: 1 addition & 0 deletions samples/Basic_WebClient/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void displayCipher(SSL *ssl)

int onDownload(HttpConnection& connection, bool success)
{
debugf("RemoteIP: %s", (char *)connection.getRemoteIp());
debugf("Got response code: %d", connection.getResponseCode());
debugf("Success: %d", success);
if(connection.getRequest()->method != HTTP_HEAD) {
Expand Down
10 changes: 9 additions & 1 deletion samples/HttpServer_ConfigNetwork/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ void onIndex(HttpRequest &request, HttpResponse &response)
response.sendTemplate(tmpl); // will be automatically deleted
}

void onIpConfig(HttpRequest &request, HttpResponse &response)
int onIpConfig(HttpServerConnection& connection, HttpRequest &request, HttpResponse &response)
{
if (request.method == HTTP_POST)
{
debugf("Request coming from IP: %s", (char *)connection.getRemoteIp());
// If desired you can also limit the access based on remote IP. Example below:
// if(!(IPAddress("192.168.4.23") == connection.getRemoteIp())) {
// return 1; // error
// }

AppSettings.dhcp = request.getPostParameter("dhcp") == "1";
AppSettings.ip = request.getPostParameter("ip");
AppSettings.netmask = request.getPostParameter("netmask");
Expand Down Expand Up @@ -51,6 +57,8 @@ void onIpConfig(HttpRequest &request, HttpResponse &response)
}

response.sendTemplate(tmpl); // will be automatically deleted

return 0;
}

void onFile(HttpRequest &request, HttpResponse &response)
Expand Down

0 comments on commit 34fdcff

Please sign in to comment.