Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2023 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * Author: Eden Abitbol <eden.abitbol@savoirfairelinux.com> |
| 5 | * Author: Mohamed Chibani <mohamed.chibani@savoirfairelinux.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include "igd.h" |
Adrien Béraud | 25c30c4 | 2023-07-05 13:46:54 -0400 | [diff] [blame] | 25 | #include "upnp/mapping.h" |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 26 | #include "ip_utils.h" |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 27 | |
| 28 | #include <map> |
| 29 | #include <string> |
| 30 | #include <chrono> |
| 31 | #include <functional> |
| 32 | #include <condition_variable> |
| 33 | #include <list> |
| 34 | |
Adrien Béraud | 1ae60aa | 2023-07-07 09:55:09 -0400 | [diff] [blame] | 35 | namespace dhtnet { |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 36 | namespace upnp { |
| 37 | |
| 38 | // UPnP device descriptions. |
| 39 | constexpr static const char* UPNP_ROOT_DEVICE = "upnp:rootdevice"; |
| 40 | constexpr static const char* UPNP_IGD_DEVICE |
| 41 | = "urn:schemas-upnp-org:device:InternetGatewayDevice:1"; |
| 42 | constexpr static const char* UPNP_WAN_DEVICE = "urn:schemas-upnp-org:device:WANDevice:1"; |
| 43 | constexpr static const char* UPNP_WANCON_DEVICE |
| 44 | = "urn:schemas-upnp-org:device:WANConnectionDevice:1"; |
| 45 | constexpr static const char* UPNP_WANIP_SERVICE = "urn:schemas-upnp-org:service:WANIPConnection:1"; |
| 46 | constexpr static const char* UPNP_WANPPP_SERVICE |
| 47 | = "urn:schemas-upnp-org:service:WANPPPConnection:1"; |
| 48 | |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 49 | |
| 50 | // Pure virtual interface class that UPnPContext uses to call protocol functions. |
| 51 | class UPnPProtocol : public std::enable_shared_from_this<UPnPProtocol>//, protected UpnpThreadUtil |
| 52 | { |
| 53 | public: |
| 54 | enum class UpnpError : int { INVALID_ERR = -1, ERROR_OK, CONFLICT_IN_MAPPING }; |
| 55 | |
| 56 | UPnPProtocol() {}; |
| 57 | virtual ~UPnPProtocol() {}; |
| 58 | |
| 59 | // Get protocol type. |
| 60 | virtual NatProtocolType getProtocol() const = 0; |
| 61 | |
| 62 | // Get protocol type as string. |
| 63 | virtual char const* getProtocolName() const = 0; |
| 64 | |
| 65 | // Clear all known IGDs. |
| 66 | virtual void clearIgds() = 0; |
| 67 | |
| 68 | // Search for IGD. |
| 69 | virtual void searchForIgd() = 0; |
| 70 | |
| 71 | // Get the IGD instance. |
| 72 | virtual std::list<std::shared_ptr<IGD>> getIgdList() const = 0; |
| 73 | |
| 74 | // Return true if it has at least one valid IGD. |
| 75 | virtual bool isReady() const = 0; |
| 76 | |
| 77 | // Get the list of already allocated mappings if any. |
| 78 | virtual std::map<Mapping::key_t, Mapping> getMappingsListByDescr(const std::shared_ptr<IGD>&, |
| 79 | const std::string&) const |
| 80 | { |
| 81 | return {}; |
| 82 | } |
| 83 | |
| 84 | // Sends a request to add a mapping. |
| 85 | virtual void requestMappingAdd(const Mapping& map) = 0; |
| 86 | |
| 87 | // Renew an allocated mapping. |
| 88 | virtual void requestMappingRenew(const Mapping& mapping) = 0; |
| 89 | |
| 90 | // Sends a request to remove a mapping. |
| 91 | virtual void requestMappingRemove(const Mapping& igdMapping) = 0; |
| 92 | |
| 93 | // Set the user callbacks. |
| 94 | virtual void setObserver(UpnpMappingObserver* obs) = 0; |
| 95 | |
| 96 | // Get the current host (local) address |
| 97 | virtual const IpAddr getHostAddress() const = 0; |
| 98 | |
| 99 | // Terminate |
| 100 | virtual void terminate() = 0; |
| 101 | }; |
| 102 | |
| 103 | } // namespace upnp |
| 104 | } // namespace jami |