mirror of
https://bitbucket.org/King_DuckZ/keepupnpup.git
synced 2025-01-19 21:36:36 +00:00
Import better-enums
This commit is contained in:
parent
74c8be9309
commit
8694d16149
4 changed files with 18 additions and 8 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +1,6 @@
|
||||||
[submodule "lib/miniupnp"]
|
[submodule "lib/miniupnp"]
|
||||||
path = lib/miniupnp
|
path = lib/miniupnp
|
||||||
url = https://github.com/miniupnp/miniupnp.git
|
url = https://github.com/miniupnp/miniupnp.git
|
||||||
|
[submodule "lib/better-enums"]
|
||||||
|
path = lib/better-enums
|
||||||
|
url = https://github.com/aantron/better-enums
|
||||||
|
|
|
@ -21,6 +21,7 @@ add_executable(${PROJECT_NAME}
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${PROJECT_NAME}
|
||||||
PRIVATE lib/miniupnp/miniupnpc
|
PRIVATE lib/miniupnp/miniupnpc
|
||||||
|
PRIVATE lib/better-enums
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
|
1
lib/better-enums
Submodule
1
lib/better-enums
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 37d8f987ca939af846a2d29a8f8198f9bf3ac4b7
|
19
src/main.cpp
19
src/main.cpp
|
@ -2,6 +2,7 @@
|
||||||
#include "miniupnpc.h"
|
#include "miniupnpc.h"
|
||||||
#include "upnpcommands.h"
|
#include "upnpcommands.h"
|
||||||
#include "upnperrors.h"
|
#include "upnperrors.h"
|
||||||
|
#include "enum.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -14,13 +15,13 @@
|
||||||
# define KUU_VERBOSE
|
# define KUU_VERBOSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
BETTER_ENUM (Protocol, uint8_t,
|
||||||
enum Protocol {
|
UDP,
|
||||||
ProtocolUDP,
|
TCP,
|
||||||
ProtocolTCP,
|
Other
|
||||||
ProtocolOther
|
);
|
||||||
};
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
class UPNPUrlsResource {
|
class UPNPUrlsResource {
|
||||||
public:
|
public:
|
||||||
enum IGDReply {
|
enum IGDReply {
|
||||||
|
@ -56,6 +57,7 @@ namespace {
|
||||||
{
|
{
|
||||||
std::array<char, 64> externaladdr;
|
std::array<char, 64> externaladdr;
|
||||||
const auto r = UPNP_GetExternalIPAddress(m_urls.controlURL, m_data.first.servicetype, externaladdr.data());
|
const auto r = UPNP_GetExternalIPAddress(m_urls.controlURL, m_data.first.servicetype, externaladdr.data());
|
||||||
|
if (UPNPCOMMAND_SUCCESS != r)
|
||||||
m_externaladdr = externaladdr.data();
|
m_externaladdr = externaladdr.data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,6 +84,8 @@ namespace {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Redirection {
|
struct Redirection {
|
||||||
|
Redirection() : protocol(Protocol::Other) {}
|
||||||
|
|
||||||
std::string internal_client;
|
std::string internal_client;
|
||||||
std::string remote_host;
|
std::string remote_host;
|
||||||
std::string desc;
|
std::string desc;
|
||||||
|
@ -162,7 +166,8 @@ namespace {
|
||||||
|
|
||||||
if (not r) {
|
if (not r) {
|
||||||
Redirection redir;
|
Redirection redir;
|
||||||
redir.protocol = (std::string(protocol) == "TCP" ? ProtocolTCP : (std::string(protocol) == "UDP" ? ProtocolUDP : ProtocolOther));
|
better_enums::optional<Protocol> proto = Protocol::_from_string_nothrow(protocol);
|
||||||
|
redir.protocol = (proto ? *proto : +Protocol::Other);
|
||||||
redir.internal_client = intClient;
|
redir.internal_client = intClient;
|
||||||
redir.remote_host = rHost;
|
redir.remote_host = rHost;
|
||||||
redir.desc = desc;
|
redir.desc = desc;
|
||||||
|
|
Loading…
Add table
Reference in a new issue