mirror of
https://bitbucket.org/King_DuckZ/keepupnpup.git
synced 2024-11-07 21:29:00 +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"]
|
||||
path = lib/miniupnp
|
||||
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}
|
||||
PRIVATE lib/miniupnp/miniupnpc
|
||||
PRIVATE lib/better-enums
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
|
|
1
lib/better-enums
Submodule
1
lib/better-enums
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 37d8f987ca939af846a2d29a8f8198f9bf3ac4b7
|
21
src/main.cpp
21
src/main.cpp
|
@ -2,6 +2,7 @@
|
|||
#include "miniupnpc.h"
|
||||
#include "upnpcommands.h"
|
||||
#include "upnperrors.h"
|
||||
#include "enum.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
@ -14,13 +15,13 @@
|
|||
# define KUU_VERBOSE
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
enum Protocol {
|
||||
ProtocolUDP,
|
||||
ProtocolTCP,
|
||||
ProtocolOther
|
||||
};
|
||||
BETTER_ENUM (Protocol, uint8_t,
|
||||
UDP,
|
||||
TCP,
|
||||
Other
|
||||
);
|
||||
|
||||
namespace {
|
||||
class UPNPUrlsResource {
|
||||
public:
|
||||
enum IGDReply {
|
||||
|
@ -56,7 +57,8 @@ namespace {
|
|||
{
|
||||
std::array<char, 64> externaladdr;
|
||||
const auto r = UPNP_GetExternalIPAddress(m_urls.controlURL, m_data.first.servicetype, externaladdr.data());
|
||||
m_externaladdr = externaladdr.data();
|
||||
if (UPNPCOMMAND_SUCCESS != r)
|
||||
m_externaladdr = externaladdr.data();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,6 +84,8 @@ namespace {
|
|||
};
|
||||
|
||||
struct Redirection {
|
||||
Redirection() : protocol(Protocol::Other) {}
|
||||
|
||||
std::string internal_client;
|
||||
std::string remote_host;
|
||||
std::string desc;
|
||||
|
@ -162,7 +166,8 @@ namespace {
|
|||
|
||||
if (not r) {
|
||||
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.remote_host = rHost;
|
||||
redir.desc = desc;
|
||||
|
|
Loading…
Reference in a new issue