mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralgw.git
synced 2025-11-07 14:17:55 +00:00
48 lines
1.5 KiB
C++
48 lines
1.5 KiB
C++
//
|
|
// Created by stephane bourque on 2021-09-16.
|
|
//
|
|
|
|
#include "RESTAPI_TelemetryWebSocket.h"
|
|
#include "Poco/Net/WebSocket.h"
|
|
#include "Poco/Net/NetException.h"
|
|
#include "TelemetryStream.h"
|
|
|
|
namespace OpenWifi {
|
|
|
|
void RESTAPI_TelemetryWebSocket::DoGet() {
|
|
// try and upgrade this session to websocket...
|
|
if (Request->find("Upgrade") != Request->end() &&
|
|
Poco::icompare((*Request)["Upgrade"], "websocket") == 0) {
|
|
try {
|
|
Poco::URI U(Request->getURI());
|
|
std::string UUID, SerialNumber;
|
|
auto Parameters = U.getQueryParameters();
|
|
for (const auto &i : Parameters) {
|
|
if (i.first == "serialNumber") {
|
|
SerialNumber = i.second;
|
|
} else if(i.first=="uuid") {
|
|
UUID = i.second;
|
|
}
|
|
}
|
|
auto WS = Poco::SharedPtr<Poco::Net::WebSocket>( new Poco::Net::WebSocket(*Request, *Response));
|
|
new TelemetryClient(UUID, SerialNumber, WS, TelemetryStream()->NextReactor(), Logger_);
|
|
} catch (const Poco::Net::WebSocketException &E) {
|
|
Logger_.log(E);
|
|
switch (E.code()) {
|
|
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
|
|
Response->set("Sec-WebSocket-Version", Poco::Net::WebSocket::WEBSOCKET_VERSION);
|
|
// fallthrough
|
|
case Poco::Net::WebSocket::WS_ERR_NO_HANDSHAKE:
|
|
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_VERSION:
|
|
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_KEY:
|
|
Response->setStatusAndReason(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
|
|
Response->setContentLength(0);
|
|
Response->send();
|
|
break;
|
|
}
|
|
} catch (const Poco::Exception &E) {
|
|
Logger_.log(E);
|
|
}
|
|
}
|
|
}
|
|
} |