IWMSIPList::Add

banner art

Previous Next

IWMSIPList::Add

The Add method adds an IWMSIPEntry interface to the IWMSIPList collection.

Syntax

  HRESULT Add(
  BSTR  szAddr,
  BSTR  szMask,
  IWMSIpEntry**  pNewEntry
);

Parameters

szAddr

[in] BSTR containing an IP address in decimal notation.

szMask

[in] BSTR containing a mask used to determine whether the first parameter specifies a single IP address or a range of IP addresses. A value of 255.255.255.255 indicates that the first parameter represents a single IP address.

pNewEntry

[out] Pointer to a pointer to the newly added IWMSIPEntry object. This method calls AddRef internally. To avoid memory leaks, you must call Release when you are finished using the interface.

Return Values

If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.

Return code Number Description
E_INVALIDARG 0x80070057 The szAddr parameter or the szMask parameter is NULL.

Remarks

When the address, which is specified by the IWMSIPEntry::put_Address method, refers to a valid IPv6 address the mask must be set to a single numeric value representing the IPv6 prefix length. For example, if the IP address is 3FFE:5000::1, the mask might be set to 127. When the address refers to a valid IPv4 address, the mask must be set using decimal notation. The server treats the mask as a 32-bit value. Each bit in the mask is compared to the corresponding bit in the IP address. When the bit value in the mask is 1, the corresponding bit in the IP address is included in the list. When the bit value in the mask is 0, all values are included. For example if the IP address in the list is 134.123.123.20 and the mask is 255.255.255.0 (that is, the bit fields are 11111111 11111111 11111111 00000000), all IP addresses from 134.123.123.0 to 134.123.123.255 are included in the list. For more information, see the IWMSIPEntry::put_Mask method.

Example Code

#include <windows.h>
#include <atlbase.h>    // Includes CComBSTR and CComVariant.

// To access system plug-in interfaces, the
// entire type library must be imported as shown.
#import "WMSServerTypeLib.dll" no_namespace named_guids \
                               raw_interfaces_only

// Declare variables and interfaces.
IWMSServer      *pServer;
IWMSPlugins     *pPlugins;
IWMSPlugin      *pPlugin;
IDispatch       *pDispatch;
IWMSIPAdmin     *pIPAdmin;
IWMSIPList      *pIPList;
IWMSIPEntry     *pIPEntry;

HRESULT         hr;
CComVariant     varIndex;
CComBSTR        bstrIP;
CComBSTR        bstrMask;

// Initialize the COM library and retrieve a pointer
// to an IWMSServer interface.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer,
                      NULL,
                      CLSCTX_ALL,
                      IID_IWMSServer,
                      (void **)&pServer);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to an IWMSPlugins interface
// containing event handler plug-ins.
hr = pServer->get_EventHandlers(&pPlugins);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to the IWMSPlugin interface
// of the plug-in to be configured.
varIndex = "WMS IP Address Authorization";
hr = pPlugins->get_Item(varIndex, &pPlugin);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to the custom interface
// of the plug-in.
hr = pPlugin->get_CustomInterface(&pDispatch);
if (FAILED(hr)) goto EXIT;

// Query the specific administration interface
// for the plug-in.
hr = pDispatch->QueryInterface(IID_IWMSIPAdmin,
                              (void **)&pIPAdmin);
if (FAILED(hr)) goto EXIT;

// Retrieve the list of banned IP addresses.
hr = pIPAdmin->get_DisallowIP(&pIPList);
if (FAILED(hr)) goto EXIT;

// Add an IP to the list of banned addresses.
// Setting the mask in this case bans all IP addresses
// in the range of 128.117.93.0 to 128.117.93.255.
bstrIP = "128.117.93.5";
bstrMask = "255.255.255.0";
hr = pIPList->Add(bstrIP, bstrMask, &pIPEntry);
if (FAILED(hr)) goto EXIT;

EXIT:

Requirements

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003 family, Windows Server 2008 family.

See Also

Previous Next