[PATCH 6/7] hnetcfg: Implement static_ports_Remove().
Paul Gofman
pgofman at codeweavers.com
Wed Feb 2 02:32:58 CST 2022
Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
dlls/hnetcfg/port.c | 47 ++++++++++++++++++++++++++++++++++---
dlls/hnetcfg/tests/policy.c | 2 +-
2 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/dlls/hnetcfg/port.c b/dlls/hnetcfg/port.c
index 8c80b02babc..88816b7ee34 100644
--- a/dlls/hnetcfg/port.c
+++ b/dlls/hnetcfg/port.c
@@ -515,7 +515,8 @@ enum port_mapping_parameter
PM_ENABLED,
PM_DESC,
PM_LEASE_DURATION,
- PM_LAST
+ PM_LAST,
+ PM_REMOVE_PORT_LAST = PM_INTERNAL,
};
static struct xml_value_desc port_mapping_template[] =
@@ -602,6 +603,41 @@ static void update_mapping_list(void)
}
}
+static BOOL remove_port_mapping( LONG port, BSTR protocol )
+{
+ struct xml_value_desc mapping_desc[PM_REMOVE_PORT_LAST];
+ DWORD status = 0;
+ BSTR error_str;
+ WCHAR portW[6];
+ BOOL ret;
+
+ AcquireSRWLockExclusive( &upnp_gateway_connection_lock );
+ memcpy( mapping_desc, port_mapping_template, sizeof(mapping_desc) );
+ swprintf( portW, ARRAY_SIZE(portW), L"%u", port );
+ mapping_desc[PM_EXTERNAL_IP].value = SysAllocString( L"" );
+ mapping_desc[PM_EXTERNAL].value = SysAllocString( portW );
+ mapping_desc[PM_PROTOCOL].value = protocol;
+
+ ret = request_service( L"DeletePortMapping", mapping_desc, PM_REMOVE_PORT_LAST,
+ NULL, 0, &status, &error_str );
+ if (ret && status != HTTP_STATUS_OK)
+ {
+ WARN( "status %u, server returned error %s.\n", status, debugstr_w(error_str) );
+ SysFreeString( error_str );
+ ret = FALSE;
+ }
+ else if (!ret)
+ {
+ WARN( "Request failed.\n" );
+ }
+ update_mapping_list();
+ ReleaseSRWLockExclusive( &upnp_gateway_connection_lock );
+
+ SysFreeString( mapping_desc[PM_EXTERNAL_IP].value );
+ SysFreeString( mapping_desc[PM_EXTERNAL].value );
+ return ret;
+}
+
static BOOL init_gateway_connection(void)
{
static const char upnp_search_request[] =
@@ -1402,9 +1438,14 @@ static HRESULT WINAPI static_ports_Remove(
LONG port,
BSTR protocol )
{
- FIXME( "iface %p, port %d, protocol %s stub.\n", iface, port, debugstr_w(protocol) );
+ TRACE( "iface %p, port %d, protocol %s.\n", iface, port, debugstr_w(protocol) );
- return E_NOTIMPL;
+ if (!is_valid_protocol( protocol )) return E_INVALIDARG;
+ if (port < 0 || port > 65535) return E_INVALIDARG;
+
+ if (!remove_port_mapping( port, protocol )) return E_FAIL;
+
+ return S_OK;
}
static HRESULT WINAPI static_ports_Add(
diff --git a/dlls/hnetcfg/tests/policy.c b/dlls/hnetcfg/tests/policy.c
index ffe3442dcd0..f9178f9b07b 100644
--- a/dlls/hnetcfg/tests/policy.c
+++ b/dlls/hnetcfg/tests/policy.c
@@ -280,7 +280,7 @@ static void test_static_port_mapping_collection( IStaticPortMappingCollection *p
hr = IStaticPortMappingCollection_Remove(ports, 12345, (BSTR)L"UDP");
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IStaticPortMappingCollection_Remove(ports, 12345, (BSTR)L"UDP");
- todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+ ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
IEnumVARIANT_Release(enum_ports);
}
--
2.34.1
More information about the wine-devel
mailing list