You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
4.4 KiB
119 lines
4.4 KiB
/**
|
|
* Digital Voice Modem - Conference FNE Software
|
|
* GPLv2 Open Source. Use is subject to license terms.
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
*
|
|
* @package DVM / Conference FNE Software
|
|
*
|
|
*/
|
|
/*
|
|
* Copyright (C) 2024 by Bryan Biedenkapp N2PLL
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
#if !defined(__REST_API_H__)
|
|
#define __REST_API_H__
|
|
|
|
#include "fne/Defines.h"
|
|
#include "common/network/UDPSocket.h"
|
|
#include "common/network/rest/RequestDispatcher.h"
|
|
#include "common/network/rest/http/HTTPServer.h"
|
|
#include "common/lookups/RadioIdLookup.h"
|
|
#include "common/lookups/TalkgroupRulesLookup.h"
|
|
#include "common/Thread.h"
|
|
#include "fne/network/RESTDefines.h"
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
#include <random>
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Class Prototypes
|
|
// ---------------------------------------------------------------------------
|
|
|
|
class HOST_SW_API HostFNE;
|
|
namespace network { class HOST_SW_API FNENetwork; }
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Class Declaration
|
|
// Implements the REST API server logic.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
class HOST_SW_API RESTAPI : private Thread {
|
|
public:
|
|
/// <summary>Initializes a new instance of the RESTAPI class.</summary>
|
|
RESTAPI(const std::string& address, uint16_t port, const std::string& password, HostFNE* host, bool debug);
|
|
/// <summary>Finalizes a instance of the RESTAPI class.</summary>
|
|
~RESTAPI();
|
|
|
|
/// <summary>Sets the instances of the Radio ID and Talkgroup ID lookup tables.</summary>
|
|
void setLookups(::lookups::RadioIdLookup* ridLookup, ::lookups::TalkgroupRulesLookup* tidLookup);
|
|
/// <summary>Sets the instance of the FNE network.</summary>
|
|
void setNetwork(::network::FNENetwork* network);
|
|
|
|
/// <summary>Opens connection to the network.</summary>
|
|
bool open();
|
|
|
|
/// <summary>Closes connection to the network.</summary>
|
|
void close();
|
|
|
|
private:
|
|
typedef network::rest::RequestDispatcher<network::rest::http::HTTPPayload, network::rest::http::HTTPPayload> RESTDispatcherType;
|
|
typedef network::rest::http::HTTPPayload HTTPPayload;
|
|
RESTDispatcherType m_dispatcher;
|
|
network::rest::http::HTTPServer<RESTDispatcherType> m_restServer;
|
|
|
|
std::mt19937 m_random;
|
|
|
|
std::string m_password;
|
|
uint8_t* m_passwordHash;
|
|
bool m_debug;
|
|
|
|
HostFNE* m_host;
|
|
network::FNENetwork *m_network;
|
|
|
|
::lookups::RadioIdLookup* m_ridLookup;
|
|
::lookups::TalkgroupRulesLookup* m_tidLookup;
|
|
|
|
typedef std::unordered_map<std::string, uint64_t>::value_type AuthTokenValueType;
|
|
std::unordered_map<std::string, uint64_t> m_authTokens;
|
|
|
|
/// <summary></summary>
|
|
virtual void entry();
|
|
|
|
/// <summary>Helper to initialize REST API endpoints.</summary>
|
|
void initializeEndpoints();
|
|
|
|
/// <summary></summary>
|
|
void invalidateHostToken(const std::string host);
|
|
/// <summary></summary>
|
|
bool validateAuth(const HTTPPayload& request, HTTPPayload& reply);
|
|
|
|
/// <summary></summary>
|
|
void restAPI_PutAuth(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match);
|
|
|
|
/// <summary></summary>
|
|
void restAPI_GetVersion(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match);
|
|
/// <summary></summary>
|
|
void restAPI_GetStatus(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match);
|
|
/// <summary></summary>
|
|
void restAPI_GetPeerList(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match);
|
|
|
|
/// <summary></summary>
|
|
void restAPI_GetForceUpdate(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match);
|
|
};
|
|
|
|
#endif // __REST_API_H__
|