Skip to content

Commit

Permalink
Add handler for WiFi events from service (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
manup committed Mar 18, 2018
1 parent 7f44aad commit 1ef38c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions de_web_plugin_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ class DeRestPluginPrivate : public QObject
int configureWifi(const ApiRequest &req, ApiResponse &rsp);
int restoreWifiConfig(const ApiRequest &req, ApiResponse &rsp);
int putWifiScanResult(const ApiRequest &req, ApiResponse &rsp);
int putWifiUpdated(const ApiRequest &req, ApiResponse &rsp);

void configToMap(const ApiRequest &req, QVariantMap &map);
void basicConfigToMap(QVariantMap &map);
Expand Down
19 changes: 19 additions & 0 deletions rest_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ int DeRestPluginPrivate::handleConfigurationApi(const ApiRequest &req, ApiRespon
{
return putWifiScanResult(req, rsp);
}
// PUT /api/<apikey>/config/wifi/updated
else if ((req.path.size() == 5) && (req.hdr.method() == "PUT") && (req.path[2] == "config") && (req.path[3] == "wifi") && (req.path[4] == "updated"))
{
return putWifiUpdated(req, rsp);
}
// PUT, PATCH /api/<apikey>/config
else if ((req.path.size() == 3) && (req.hdr.method() == "PUT" || req.hdr.method() == "PATCH") && (req.path[2] == "config"))
{
Expand Down Expand Up @@ -2392,15 +2397,29 @@ int DeRestPluginPrivate::putWifiScanResult(const ApiRequest &req, ApiResponse &r
return REQ_READY_SEND;
}

/*! PUT /api/config/wifi/updated (wifi service notifications)
\return REQ_READY_SEND
REQ_NOT_HANDLED
*/
int DeRestPluginPrivate::putWifiUpdated(const ApiRequest &req, ApiResponse &rsp)
{
QHostAddress localHost(QHostAddress::LocalHost);
rsp.httpStatus = HttpStatusForbidden;

if (req.sock->peerAddress() != localHost)
{
rsp.list.append(errorToMap(ERR_UNAUTHORIZED_USER, req.path.join("/"), "unauthorized user"));
return REQ_READY_SEND;
}

rsp.httpStatus = HttpStatusOk;

if (!req.content.isEmpty())
{
DBG_Printf(DBG_HTTP, "wifi: %s\n", qPrintable(req.content));
// TODO forward events
}
return REQ_READY_SEND;
}

/*! POST /api/<apikey>/config/wifiscan
Expand Down

0 comments on commit 1ef38c5

Please sign in to comment.