implement the majority of REST API support (this commit breaks RCON and any RCON-based tools [like dvmcmd]) (NOTE: not *all* RCON commands are implemented as REST API yet);
parent
069adffd7c
commit
529d5c1e83
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,230 @@
|
||||
/**
|
||||
* Digital Voice Modem - Host Software
|
||||
* GPLv2 Open Source. Use is subject to license terms.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* @package DVM / Host Software
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2023 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 "Defines.h"
|
||||
#include "network/UDPSocket.h"
|
||||
#include "network/rest/RequestDispatcher.h"
|
||||
#include "network/rest/http/HTTPServer.h"
|
||||
#include "lookups/RadioIdLookup.h"
|
||||
#include "lookups/TalkgroupIdLookup.h"
|
||||
#include "Thread.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <random>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Constants
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#define DVM_REST_RAND_MAX 0xfffffffffffffffe
|
||||
|
||||
#define PUT_AUTHENTICATE "/auth"
|
||||
|
||||
#define GET_VERSION "/version"
|
||||
#define GET_STATUS "/status"
|
||||
#define GET_VOICE_CH "/voice-ch"
|
||||
|
||||
#define PUT_MDM_MODE "/mdm/mode"
|
||||
#define MODE_OPT_IDLE "idle"
|
||||
#define MODE_OPT_LCKOUT "lockout"
|
||||
#define MODE_OPT_FDMR "dmr"
|
||||
#define MODE_OPT_FP25 "p25"
|
||||
#define MODE_OPT_FNXDN "nxdn"
|
||||
|
||||
#define PUT_MDM_KILL "/mdm/kill"
|
||||
|
||||
#define PUT_PERMIT_TG "/permit-tg"
|
||||
#define PUT_GRANT_TG "/grant-tg"
|
||||
#define GET_RELEASE_GRNTS "/release-grants"
|
||||
#define GET_RELEASE_AFFS "/release-affs"
|
||||
|
||||
#define GET_RID_WHITELIST "/rid-whitelist/(\\d+)"
|
||||
#define GET_RID_BLACKLIST "/rid-blacklist/(\\d+)"
|
||||
|
||||
#define GET_DMR_BEACON "/dmr/beacon"
|
||||
#define GET_DMR_DEBUG "/dmr/debug/(\\d+)/(\\d+)"
|
||||
#define GET_DMR_DUMP_CSBK "/dmr/dump-csbk/(\\d+)"
|
||||
#define PUT_DMR_RID "/dmr/rid"
|
||||
#define GET_DMR_CC_DEDICATED "/dmr/cc-enable/(\\d+)"
|
||||
#define GET_DMR_CC_BCAST "/dmr/cc-broadcast/(\\d+)"
|
||||
|
||||
#define GET_P25_CC "/p25/cc"
|
||||
//#define GET_P25_CC_FALLBACK "/p25/cc-fallback/(\\d+)"
|
||||
#define GET_P25_DEBUG "/p25/debug/(\\d+)/(\\d+)"
|
||||
#define GET_P25_DUMP_TSBK "/p25/dump-tsbk/(\\d+)"
|
||||
#define PUT_P25_RID "/p25/rid"
|
||||
#define GET_P25_CC_DEDICATED "/p25/cc-enable/(\\d+)"
|
||||
#define GET_P25_CC_BCAST "/p25/cc-broadcast/(\\d+)"
|
||||
|
||||
#define GET_NXDN_DEBUG "/nxdn/debug/(\\d+)/(\\d+)"
|
||||
#define GET_NXDN_DUMP_RCCH "/nxdn/dump-rcch/(\\d+)"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Class Prototypes
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class HOST_SW_API Host;
|
||||
namespace dmr { class HOST_SW_API Control; }
|
||||
namespace p25 { class HOST_SW_API Control; }
|
||||
namespace nxdn { class HOST_SW_API Control; }
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 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, Host* 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::TalkgroupIdLookup* tidLookup);
|
||||
/// <summary>Sets the instances of the digital radio protocols.</summary>
|
||||
void setProtocols(dmr::Control* dmr, p25::Control* p25, nxdn::Control* nxdn);
|
||||
|
||||
/// <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::HTTPRequest, network::rest::http::HTTPReply> RESTDispatcherType;
|
||||
typedef network::rest::http::HTTPRequest HTTPRequest;
|
||||
typedef network::rest::http::HTTPReply HTTPReply;
|
||||
RESTDispatcherType m_dispatcher;
|
||||
network::rest::http::HTTPServer<RESTDispatcherType> m_restServer;
|
||||
|
||||
std::mt19937 m_random;
|
||||
|
||||
uint8_t m_p25MFId;
|
||||
|
||||
std::string m_password;
|
||||
uint8_t* m_passwordHash;
|
||||
bool m_debug;
|
||||
|
||||
Host* m_host;
|
||||
dmr::Control* m_dmr;
|
||||
p25::Control* m_p25;
|
||||
nxdn::Control* m_nxdn;
|
||||
|
||||
::lookups::RadioIdLookup* m_ridLookup;
|
||||
::lookups::TalkgroupIdLookup* 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 HTTPRequest& request, HTTPReply& reply);
|
||||
|
||||
/// <summary></summary>
|
||||
void restAPI_PutAuth(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
|
||||
/// <summary></summary>
|
||||
void restAPI_GetVersion(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetStatus(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetVoiceCh(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
|
||||
/// <summary></summary>
|
||||
void restAPI_PutModemMode(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_PutModemKill(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
|
||||
/// <summary></summary>
|
||||
void restAPI_PutPermitTG(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_PutGrantTG(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetReleaseGrants(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetReleaseAffs(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
|
||||
/// <summary></summary>
|
||||
void restAPI_GetRIDWhitelist(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetRIDBlacklist(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
|
||||
/*
|
||||
** Digital Mobile Radio
|
||||
*/
|
||||
|
||||
/// <summary></summary>
|
||||
void restAPI_GetDMRBeacon(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetDMRDebug(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetDMRDumpCSBK(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_PutDMRRID(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetDMRCCEnable(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetDMRCCBroadcast(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
|
||||
/*
|
||||
** Project 25
|
||||
*/
|
||||
|
||||
/// <summary></summary>
|
||||
void restAPI_GetP25CC(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetP25Debug(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetP25DumpTSBK(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_PutP25RID(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetP25CCEnable(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetP25CCBroadcast(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
|
||||
/*
|
||||
** Next Generation Digital Narrowband
|
||||
*/
|
||||
|
||||
/// <summary></summary>
|
||||
void restAPI_GetNXDNDebug(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
/// <summary></summary>
|
||||
void restAPI_GetNXDNDumpRCCH(const HTTPRequest& request, HTTPReply& reply, const network::rest::RequestMatch& match);
|
||||
};
|
||||
|
||||
#endif // __REST_API_H__
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,214 +0,0 @@
|
||||
/**
|
||||
* Digital Voice Modem - Host Software
|
||||
* GPLv2 Open Source. Use is subject to license terms.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* @package DVM / Host Software
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost)
|
||||
// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0)
|
||||
//
|
||||
/*
|
||||
* Copyright (C) 2019 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2019-2023 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(__REMOTE_CONTROL_H__)
|
||||
#define __REMOTE_CONTROL_H__
|
||||
|
||||
#include "Defines.h"
|
||||
#include "network/UDPSocket.h"
|
||||
#include "network/rest/RequestDispatcher.h"
|
||||
#include "network/rest/http/HTTPServer.h"
|
||||
#include "lookups/RadioIdLookup.h"
|
||||
#include "lookups/TalkgroupIdLookup.h"
|
||||
#include "Thread.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Constants
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#define RCD_GET_VERSION "version"
|
||||
#define RCD_GET_HELP "help"
|
||||
#define RCD_GET_STATUS "status"
|
||||
#define RCD_GET_VOICE_CH "voice-ch"
|
||||
|
||||
#define RCD_MODE "mdm-mode"
|
||||
#define RCD_MODE_OPT_IDLE "idle"
|
||||
#define RCD_MODE_OPT_LCKOUT "lockout"
|
||||
#define RCD_MODE_OPT_FDMR "dmr"
|
||||
#define RCD_MODE_OPT_FP25 "p25"
|
||||
#define RCD_MODE_OPT_FNXDN "nxdn"
|
||||
|
||||
#define RCD_KILL "mdm-kill"
|
||||
#define RCD_FORCE_KILL "mdm-force-kill"
|
||||
|
||||
#define RCD_PERMIT_TG "permit-tg"
|
||||
#define RCD_GRANT_TG "grant-tg"
|
||||
|
||||
#define RCD_RID_WLIST "rid-whitelist"
|
||||
#define RCD_RID_BLIST "rid-blacklist"
|
||||
|
||||
#define RCD_DMR_BEACON "dmr-beacon"
|
||||
#define RCD_P25_CC "p25-cc"
|
||||
#define RCD_P25_CC_FALLBACK "p25-cc-fallback"
|
||||
|
||||
#define RCD_DMR_RID_PAGE "dmr-rid-page"
|
||||
#define RCD_DMR_RID_CHECK "dmr-rid-check"
|
||||
#define RCD_DMR_RID_INHIBIT "dmr-rid-inhibit"
|
||||
#define RCD_DMR_RID_UNINHIBIT "dmr-rid-uninhibit"
|
||||
|
||||
#define RCD_P25_SET_MFID "p25-set-mfid"
|
||||
#define RCD_P25_RID_PAGE "p25-rid-page"
|
||||
#define RCD_P25_RID_CHECK "p25-rid-check"
|
||||
#define RCD_P25_RID_INHIBIT "p25-rid-inhibit"
|
||||
#define RCD_P25_RID_UNINHIBIT "p25-rid-uninhibit"
|
||||
#define RCD_P25_RID_GAQ "p25-rid-gaq"
|
||||
#define RCD_P25_RID_UREG "p25-rid-ureg"
|
||||
|
||||
#define RCD_P25_RELEASE_GRANTS "p25-rel-grnts"
|
||||
#define RCD_P25_RELEASE_AFFS "p25-rel-affs"
|
||||
|
||||
#define RCD_DMR_CC_DEDICATED "dmr-cc-dedicated"
|
||||
#define RCD_DMR_CC_BCAST "dmr-cc-bcast"
|
||||
|
||||
#define RCD_P25_CC_DEDICATED "p25-cc-dedicated"
|
||||
#define RCD_P25_CC_BCAST "p25-cc-bcast"
|
||||
|
||||
#define RCD_DMR_DEBUG "dmr-debug"
|
||||
#define RCD_DMR_DUMP_CSBK "dmr-dump-csbk"
|
||||
#define RCD_P25_DEBUG "p25-debug"
|
||||
#define RCD_P25_DUMP_TSBK "p25-dump-tsbk"
|
||||
#define RCD_NXDN_DEBUG "nxdn-debug"
|
||||
#define RCD_NXDN_DUMP_RCCH "nxdn-dump-rcch"
|
||||
|
||||
#define RCD_DMRD_MDM_INJ "debug-dmrd-mdm-inj"
|
||||
#define RCD_P25D_MDM_INJ "debug-p25d-mdm-inj"
|
||||
#define RCD_NXDD_MDM_INJ "debug-nxdd-mdm-inj"
|
||||
|
||||
#define RCD_PING "ping"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Class Prototypes
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class HOST_SW_API Host;
|
||||
namespace dmr { class HOST_SW_API Control; }
|
||||
namespace p25 { class HOST_SW_API Control; }
|
||||
namespace nxdn { class HOST_SW_API Control; }
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Class Declaration
|
||||
// Implements the remote control networking logic.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class HOST_SW_API RemoteControl : private Thread {
|
||||
public:
|
||||
/// <summary>Initializes a new instance of the RemoteControl class.</summary>
|
||||
RemoteControl(const std::string& address, uint16_t port, const std::string& password, Host* host, bool debug);
|
||||
/// <summary>Finalizes a instance of the RemoteControl class.</summary>
|
||||
~RemoteControl();
|
||||
|
||||
/// <summary>Sets the instances of the Radio ID and Talkgroup ID lookup tables.</summary>
|
||||
void setLookups(::lookups::RadioIdLookup* ridLookup, ::lookups::TalkgroupIdLookup* tidLookup);
|
||||
/// <summary>Sets the instances of the digital radio protocols.</summary>
|
||||
void setProtocols(dmr::Control* dmr, p25::Control* p25, nxdn::Control* nxdn);
|
||||
|
||||
/// <summary>Process remote network command data.</summary>
|
||||
void process(Host* host, dmr::Control* dmr, p25::Control* p25, nxdn::Control* nxdn);
|
||||
|
||||
/// <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::HTTPRequest, network::rest::http::HTTPReply> RESTDispatcherType;
|
||||
RESTDispatcherType m_dispatcher;
|
||||
network::rest::http::HTTPServer<RESTDispatcherType> m_restServer;
|
||||
|
||||
network::UDPSocket m_socket;
|
||||
uint8_t m_p25MFId;
|
||||
|
||||
std::string m_password;
|
||||
uint8_t* m_passwordHash;
|
||||
bool m_debug;
|
||||
|
||||
Host* m_host;
|
||||
dmr::Control* m_dmr;
|
||||
p25::Control* m_p25;
|
||||
nxdn::Control* m_nxdn;
|
||||
|
||||
::lookups::RadioIdLookup* m_ridLookup;
|
||||
::lookups::TalkgroupIdLookup* m_tidLookup;
|
||||
|
||||
/// <summary>Helper to initialize REST API endpoints.</summary>
|
||||
void initializeEndpoints();
|
||||
|
||||
/// <summary></summary>
|
||||
virtual void entry();
|
||||
|
||||
/// <summary>Helper to send response to client.</summary>
|
||||
void writeResponse(std::string reply, sockaddr_storage address, uint32_t addrLen);
|
||||
|
||||
/// <summary>Helper to print the remote control help.</summary>
|
||||
std::string displayHelp();
|
||||
|
||||
/// <summary></summary>
|
||||
std::string rcdGetStatus(Host* host, dmr::Control* dmr, p25::Control* p25, nxdn::Control* nxdn);
|
||||
/// <summary></summary>
|
||||
std::string rcdGetVoiceCh(Host* host, dmr::Control* dmr, p25::Control* p25, nxdn::Control* nxdn);
|
||||
/// <summary></summary>
|
||||
std::string rcdMode(std::vector<std::string> args, Host* host, dmr::Control* dmr, p25::Control* p25, nxdn::Control* nxdn);
|
||||
|
||||
/// <summary></summary>
|
||||
std::string rcdPermitTG(std::vector<std::string> args, Host* host, dmr::Control* dmr, p25::Control* p25, nxdn::Control* nxdn);
|
||||
/// <summary></summary>
|
||||
std::string rcdGrantTG(std::vector<std::string> args, Host* host, dmr::Control* dmr, p25::Control* p25, nxdn::Control* nxdn);
|
||||
|
||||
/// <summary></summary>
|
||||
std::string rcdDMRModemInj(std::vector<std::string> args, Host* host, dmr::Control* dmr);
|
||||
/// <summary></summary>
|
||||
std::string rcdP25ModemInj(std::vector<std::string> args, Host* host, p25::Control* p25);
|
||||
/// <summary></summary>
|
||||
std::string rcdNXDNModemInj(std::vector<std::string> args, Host* host, nxdn::Control* nxdn);
|
||||
|
||||
/// <summary></summary>
|
||||
std::string getArgString(std::vector<std::string> args, uint32_t n) const;
|
||||
|
||||
/// <summary></summary>
|
||||
__forceinline uint64_t getArgUInt64(std::vector<std::string> args, uint32_t n) const { return (uint64_t)::atol(getArgString(args, n).c_str()); }
|
||||
/// <summary></summary>
|
||||
__forceinline uint32_t getArgUInt32(std::vector<std::string> args, uint32_t n) const { return (uint32_t)::atoi(getArgString(args, n).c_str()); }
|
||||
/// <summary></summary>
|
||||
__forceinline int32_t getArgInt32(std::vector<std::string> args, uint32_t n) const { return ::atoi(getArgString(args, n).c_str()); }
|
||||
/// <summary></summary>
|
||||
__forceinline uint16_t getArgUInt16(std::vector<std::string> args, uint32_t n) const { return (uint16_t)::atoi(getArgString(args, n).c_str()); }
|
||||
/// <summary></summary>
|
||||
__forceinline int16_t getArgInt16(std::vector<std::string> args, uint32_t n) const { return (int16_t)::atoi(getArgString(args, n).c_str()); }
|
||||
/// <summary></summary>
|
||||
__forceinline uint8_t getArgUInt8(std::vector<std::string> args, uint32_t n) const { return (uint8_t)::atoi(getArgString(args, n).c_str()); }
|
||||
/// <summary></summary>
|
||||
__forceinline int8_t getArgInt8(std::vector<std::string> args, uint32_t n) const { return (int8_t)::atoi(getArgString(args, n).c_str()); }
|
||||
};
|
||||
|
||||
#endif // __REMOTE_CONTROL_H__
|
||||
@ -1,71 +0,0 @@
|
||||
/**
|
||||
* Digital Voice Modem - Host Software
|
||||
* GPLv2 Open Source. Use is subject to license terms.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* @package DVM / Host Software
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Based on code from the CRUD project. (https://github.com/venediktov/CRUD)
|
||||
// Licensed under the BPL-1.0 License (https://opensource.org/license/bsl1-0-html)
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2003-2013 Christopher M. Kohlhoff
|
||||
* Copyright (C) 2023 by Bryan Biedenkapp N2PLL
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person or organization
|
||||
* obtaining a copy of the software and accompanying documentation covered by
|
||||
* this license (the “Software”) to use, reproduce, display, distribute, execute,
|
||||
* and transmit the Software, and to prepare derivative works of the Software, and
|
||||
* to permit third-parties to whom the Software is furnished to do so, all subject
|
||||
* to the following:
|
||||
*
|
||||
* The copyright notices in the Software and this entire statement, including the
|
||||
* above license grant, this restriction and the following disclaimer, must be included
|
||||
* in all copies of the Software, in whole or in part, and all derivative works of the
|
||||
* Software, unless such copies or derivative works are solely in the form of
|
||||
* machine-executable object code generated by a source language processor.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
|
||||
* DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#if !defined(__REST_HTTP__HTTP_HEADER_H__)
|
||||
#define __REST_HTTP__HTTP_HEADER_H__
|
||||
|
||||
#include "Defines.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace network
|
||||
{
|
||||
namespace rest
|
||||
{
|
||||
namespace http
|
||||
{
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Structure Declaration
|
||||
// This class implements a model for an HTTP header.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct HTTPHeader
|
||||
{
|
||||
std::string name;
|
||||
std::string value;
|
||||
|
||||
/// <summary>Initializes a new instance of the HTTPHeader struct.</summary>
|
||||
HTTPHeader() { /* stub */ }
|
||||
/// <summary>Initializes a new instance of the HTTPHeader struct.</summary>
|
||||
HTTPHeader(const std::string& name, const std::string& value) : name(name), value(value) { /* stub */ }
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
} // namespace rest
|
||||
} // namespace network
|
||||
|
||||
#endif // __REST_HTTP__HTTP_HEADER_H__
|
||||
@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Digital Voice Modem - Host Software
|
||||
* GPLv2 Open Source. Use is subject to license terms.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* @package DVM / Host Software
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Based on code from the CRUD project. (https://github.com/venediktov/CRUD)
|
||||
// Licensed under the BPL-1.0 License (https://opensource.org/license/bsl1-0-html)
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2003-2013 Christopher M. Kohlhoff
|
||||
* Copyright (C) 2023 by Bryan Biedenkapp N2PLL
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person or organization
|
||||
* obtaining a copy of the software and accompanying documentation covered by
|
||||
* this license (the “Software”) to use, reproduce, display, distribute, execute,
|
||||
* and transmit the Software, and to prepare derivative works of the Software, and
|
||||
* to permit third-parties to whom the Software is furnished to do so, all subject
|
||||
* to the following:
|
||||
*
|
||||
* The copyright notices in the Software and this entire statement, including the
|
||||
* above license grant, this restriction and the following disclaimer, must be included
|
||||
* in all copies of the Software, in whole or in part, and all derivative works of the
|
||||
* Software, unless such copies or derivative works are solely in the form of
|
||||
* machine-executable object code generated by a source language processor.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
|
||||
* DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#if !defined(__REST_HTTP__HTTP_HEADERS_H__)
|
||||
#define __REST_HTTP__HTTP_HEADERS_H__
|
||||
|
||||
#include "Defines.h"
|
||||
#include "Log.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace network
|
||||
{
|
||||
namespace rest
|
||||
{
|
||||
namespace http
|
||||
{
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Class Prototypes
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct HTTPReply;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Structure Declaration
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct HTTPHeaders
|
||||
{
|
||||
struct Header
|
||||
{
|
||||
std::string name;
|
||||
std::string value;
|
||||
|
||||
Header() : name{}, value{} { /* stub */}
|
||||
Header(std::string n, std::string v) : name{n}, value{v} { /* stub */ }
|
||||
};
|
||||
|
||||
/// <summary>Gets the list of HTTP headers.</summary>
|
||||
std::vector<Header> headers() const { return m_headers; }
|
||||
/// <summary>Returns true if the headers are empty.</summary>
|
||||
bool empty() const { return m_headers.empty(); }
|
||||
/// <summary>Returns the number of headers.</summary>
|
||||
std::size_t size() const { return m_headers.size(); }
|
||||
/// <summary>Clears the list of HTTP headers.</summary>
|
||||
void clearHeaders() { m_headers = std::vector<Header>(); }
|
||||
/// <summary>Helper to add a HTTP header.</summary>
|
||||
void add(const std::string& name, const std::string& value)
|
||||
{
|
||||
//::LogDebug(LOG_REST, "HTTPHeaders::add(), header = %s, value = %s", name.c_str(), value.c_str());
|
||||
for (auto& header : m_headers) {
|
||||
if (::strtolower(header.name) == ::strtolower(name)) {
|
||||
header.value = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_headers.push_back(Header(name, value));
|
||||
//for (auto header : m_headers)
|
||||
// ::LogDebug(LOG_REST, "HTTPHeaders::add() m_headers.header = %s, m_headers.value = %s", header.name.c_str(), header.value.c_str());
|
||||
}
|
||||
/// <summary>Helper to add a HTTP header.</summary>
|
||||
void remove(const std::string headerName)
|
||||
{
|
||||
auto header = std::find_if(m_headers.begin(), m_headers.end(), [&](const Header& h) {
|
||||
return ::strtolower(h.name) == ::strtolower(headerName);
|
||||
});
|
||||
|
||||
if (header != m_headers.end()) {
|
||||
m_headers.erase(header);
|
||||
}
|
||||
}
|
||||
/// <summary>Helper to find the named HTTP header.</summary>
|
||||
std::string find(const std::string headerName) const
|
||||
{
|
||||
auto header = std::find_if(m_headers.begin(), m_headers.end(), [&](const Header& h) {
|
||||
return ::strtolower(h.name) == ::strtolower(headerName);
|
||||
});
|
||||
|
||||
if (header != m_headers.end()) {
|
||||
return header->value;
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
friend struct HTTPReply;
|
||||
std::vector<Header> m_headers;
|
||||
};
|
||||
} // namespace http
|
||||
} // namespace rest
|
||||
} // namespace network
|
||||
|
||||
#endif // __REST_HTTP__HTTP_HEADERS_H__
|
||||
Loading…
Reference in new issue