blob: ce891e178e9c88d09edaaae322e4e8629c103159 [file] [log] [blame]
Adrien Béraud612b55b2023-05-29 10:42:04 -04001/*
2 * Copyright (C) 2004-2023 Savoir-faire Linux Inc.
3 *
Adrien Béraudcb753622023-07-17 22:32:49 -04004 * This program is free software: you can redistribute it and/or modify
Adrien Béraud612b55b2023-05-29 10:42:04 -04005 * it under the terms of the GNU General Public License as published by
Adrien Béraudcb753622023-07-17 22:32:49 -04006 * the Free Software Foundation, either version 3 of the License, or
Adrien Béraud612b55b2023-05-29 10:42:04 -04007 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Adrien Béraudcb753622023-07-17 22:32:49 -040011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Adrien Béraud612b55b2023-05-29 10:42:04 -040012 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
Adrien Béraudcb753622023-07-17 22:32:49 -040015 * along with this program. If not, see <https://www.gnu.org/licenses/>.
Adrien Béraud612b55b2023-05-29 10:42:04 -040016 */
Adrien Béraud612b55b2023-05-29 10:42:04 -040017#pragma once
18
19#include "igd.h"
Adrien Béraud25c30c42023-07-05 13:46:54 -040020#include "upnp/mapping.h"
Adrien Béraud612b55b2023-05-29 10:42:04 -040021#include "ip_utils.h"
Adrien Béraud612b55b2023-05-29 10:42:04 -040022
23#include <map>
24#include <string>
25#include <chrono>
26#include <functional>
27#include <condition_variable>
28#include <list>
29
Adrien Béraud1ae60aa2023-07-07 09:55:09 -040030namespace dhtnet {
Adrien Béraud612b55b2023-05-29 10:42:04 -040031namespace upnp {
32
33// UPnP device descriptions.
34constexpr static const char* UPNP_ROOT_DEVICE = "upnp:rootdevice";
35constexpr static const char* UPNP_IGD_DEVICE
36 = "urn:schemas-upnp-org:device:InternetGatewayDevice:1";
37constexpr static const char* UPNP_WAN_DEVICE = "urn:schemas-upnp-org:device:WANDevice:1";
38constexpr static const char* UPNP_WANCON_DEVICE
39 = "urn:schemas-upnp-org:device:WANConnectionDevice:1";
40constexpr static const char* UPNP_WANIP_SERVICE = "urn:schemas-upnp-org:service:WANIPConnection:1";
41constexpr static const char* UPNP_WANPPP_SERVICE
42 = "urn:schemas-upnp-org:service:WANPPPConnection:1";
43
Adrien Béraud612b55b2023-05-29 10:42:04 -040044
45// Pure virtual interface class that UPnPContext uses to call protocol functions.
46class UPnPProtocol : public std::enable_shared_from_this<UPnPProtocol>//, protected UpnpThreadUtil
47{
48public:
49 enum class UpnpError : int { INVALID_ERR = -1, ERROR_OK, CONFLICT_IN_MAPPING };
50
51 UPnPProtocol() {};
52 virtual ~UPnPProtocol() {};
53
54 // Get protocol type.
55 virtual NatProtocolType getProtocol() const = 0;
56
57 // Get protocol type as string.
58 virtual char const* getProtocolName() const = 0;
59
60 // Clear all known IGDs.
61 virtual void clearIgds() = 0;
62
63 // Search for IGD.
64 virtual void searchForIgd() = 0;
65
66 // Get the IGD instance.
67 virtual std::list<std::shared_ptr<IGD>> getIgdList() const = 0;
68
69 // Return true if it has at least one valid IGD.
70 virtual bool isReady() const = 0;
71
72 // Get the list of already allocated mappings if any.
73 virtual std::map<Mapping::key_t, Mapping> getMappingsListByDescr(const std::shared_ptr<IGD>&,
74 const std::string&) const
75 {
76 return {};
77 }
78
79 // Sends a request to add a mapping.
80 virtual void requestMappingAdd(const Mapping& map) = 0;
81
82 // Renew an allocated mapping.
83 virtual void requestMappingRenew(const Mapping& mapping) = 0;
84
85 // Sends a request to remove a mapping.
86 virtual void requestMappingRemove(const Mapping& igdMapping) = 0;
87
88 // Set the user callbacks.
89 virtual void setObserver(UpnpMappingObserver* obs) = 0;
90
91 // Get the current host (local) address
92 virtual const IpAddr getHostAddress() const = 0;
93
94 // Terminate
95 virtual void terminate() = 0;
96};
97
98} // namespace upnp
Sébastien Blin464bdff2023-07-19 08:02:53 -040099} // namespace dhtnet