/** * 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 #include #include // --------------------------------------------------------------------------- // 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: /// Initializes a new instance of the RESTAPI class. RESTAPI(const std::string& address, uint16_t port, const std::string& password, HostFNE* host, bool debug); /// Finalizes a instance of the RESTAPI class. ~RESTAPI(); /// Sets the instances of the Radio ID and Talkgroup ID lookup tables. void setLookups(::lookups::RadioIdLookup* ridLookup, ::lookups::TalkgroupRulesLookup* tidLookup); /// Sets the instance of the FNE network. void setNetwork(::network::FNENetwork* network); /// Opens connection to the network. bool open(); /// Closes connection to the network. void close(); private: typedef network::rest::RequestDispatcher RESTDispatcherType; typedef network::rest::http::HTTPPayload HTTPPayload; RESTDispatcherType m_dispatcher; network::rest::http::HTTPServer 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::value_type AuthTokenValueType; std::unordered_map m_authTokens; /// virtual void entry(); /// Helper to initialize REST API endpoints. void initializeEndpoints(); /// void invalidateHostToken(const std::string host); /// bool validateAuth(const HTTPPayload& request, HTTPPayload& reply); /// void restAPI_PutAuth(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); /// void restAPI_GetVersion(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); /// void restAPI_GetStatus(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); /// void restAPI_GetPeerList(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); /// void restAPI_GetForceUpdate(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); }; #endif // __REST_API_H__