' ########################################################################################
' Microsoft Windows
' File: NspAPI.inc
' Contents: Name Space Provider API prototypes and manifests
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_NspAPI_PBI)
#DEFINE PBX_NspAPI_PBI
%EQUATE `NSPAPI_INC = 1
#INCLUDE ONCE "Legacy/Platform/WinSock2.inc"
'#ifndef _tagBLOB_DEFINED
'#define _tagBLOB_DEFINED
'#define _BLOB_DEFINED
'#define _LPBLOB_DEFINED
'typedef struct _BLOB {
' ULONG cbSize ;
'#ifdef MIDL_PASS
' [size_is(cbSize)] BYTE *pBlobData;
'#else // MIDL_PASS
' BYTE *pBlobData ;
'#endif // MIDL_PASS
'} BLOB, *LPBLOB ;
'#endif
'#ifndef GUID_DEFINED
'#define GUID_DEFINED
'typedef struct _GUID
'{
' unsigned long Data1;
' unsigned short Data2;
' unsigned short Data3;
' unsigned char Data4[8];
'} GUID;
'#endif /* GUID_DEFINED */
'#ifndef __LPGUID_DEFINED__
'#define __LPGUID_DEFINED__
'typedef GUID *LPGUID;
'#endif
'//
'// Service categories
'//
%EQUATE `SERVICE_RESOURCE = &H00000001
%EQUATE `SERVICE_SERVICE = &H00000002
%EQUATE `SERVICE_LOCAL = &H00000004
'//
'// Operation used when calling SetService()
'//
%EQUATE `SERVICE_REGISTER = &H00000001
%EQUATE `SERVICE_DEREGISTER = &H00000002
%EQUATE `SERVICE_FLUSH = &H00000003
%EQUATE `SERVICE_ADD_TYPE = &H00000004
%EQUATE `SERVICE_DELETE_TYPE = &H00000005
'//
'// Flags that affect the operations above
'//
%EQUATE `SERVICE_FLAG_DEFER = &H00000001
%EQUATE `SERVICE_FLAG_HARD = &H00000002
'//
'// Used as input to GetService() for setting the dwProps parameter
'//
%EQUATE `PROP_COMMENT = &H00000001
%EQUATE `PROP_LOCALE = &H00000002
%EQUATE `PROP_DISPLAY_HINT = &H00000004
%EQUATE `PROP_VERSION = &H00000008
%EQUATE `PROP_START_TIME = &H00000010
%EQUATE `PROP_MACHINE = &H00000020
%EQUATE `PROP_ADDRESSES = &H00000100
%EQUATE `PROP_SD = &H00000200
%EQUATE `PROP_ALL = &H80000000
'//
'// Flags that describe attributes of Service Addresses
'//
%EQUATE `SERVICE_ADDRESS_FLAG_RPC_CN = &H00000001
%EQUATE `SERVICE_ADDRESS_FLAG_RPC_DG = &H00000002
%EQUATE `SERVICE_ADDRESS_FLAG_RPC_NB = &H00000004
'//
'// Name Spaces
'//
%EQUATE `NS_DEFAULT = 0
%EQUATE `NS_SAP = 1
%EQUATE `NS_NDS = 2
%EQUATE `NS_PEER_BROWSE = 3
%EQUATE `NS_TCPIP_LOCAL = 10
%EQUATE `NS_TCPIP_HOSTS = 11
%EQUATE `NS_DNS = 12
%EQUATE `NS_NETBT = 13
%EQUATE `NS_WINS = 14
%EQUATE `NS_NBP = 20
%EQUATE `NS_MS = 30
%EQUATE `NS_STDA = 31
%EQUATE `NS_NTDS = 32
%EQUATE `NS_X500 = 40
%EQUATE `NS_NIS = 41
%EQUATE `NS_VNS = 50
'//
'// Name space attributes.
'//
%EQUATE `NSTYPE_HIERARCHICAL = &H00000001
%EQUATE `NSTYPE_DYNAMIC = &H00000002
%EQUATE `NSTYPE_ENUMERABLE = &H00000004
%EQUATE `NSTYPE_WORKGROUP = &H00000008
'//
'// Transport attributes.
'//
%EQUATE `XP_CONNECTIONLESS = &H00000001
%EQUATE `XP_GUARANTEED_DELIVERY = &H00000002
%EQUATE `XP_GUARANTEED_ORDER = &H00000004
%EQUATE `XP_MESSAGE_ORIENTED = &H00000008
%EQUATE `XP_PSEUDO_STREAM = &H00000010
%EQUATE `XP_GRACEFUL_CLOSE = &H00000020
%EQUATE `XP_EXPEDITED_DATA = &H00000040
%EQUATE `XP_CONNECT_DATA = &H00000080
%EQUATE `XP_DISCONNECT_DATA = &H00000100
%EQUATE `XP_SUPPORTS_BROADCAST = &H00000200
%EQUATE `XP_SUPPORTS_MULTICAST = &H00000400
%EQUATE `XP_BANDWIDTH_ALLOCATION = &H00000800
%EQUATE `XP_FRAGMENTATION = &H00001000
%EQUATE `XP_ENCRYPTS = &H00002000
'//
'// Resolution flags for GetAddressByName().
'//
%EQUATE `RES_SOFT_SEARCH = &H00000001
%EQUATE `RES_FIND_MULTIPLE = &H00000002
%EQUATE `RES_SERVICE = &H00000004
'//
'// Well known value names for Service Types
'//
$SERVICE_TYPE_VALUE_SAPIDA = "SapId"
$$SERVICE_TYPE_VALUE_SAPIDW = "SapId"$$
#IF %DEF(%UNICODE)
 MACRO SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDW
#ELSE
 MACRO SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDA
#ENDIF
$SERVICE_TYPE_VALUE_CONNA = "ConnectionOriented"
$$SERVICE_TYPE_VALUE_CONNW = "ConnectionOriented"$$
#IF %DEF(%UNICODE)
 MACRO SERVICE_TYPE_VALUE_CONN = SERVICE_TYPE_VALUE_CONNW
#ELSE
 MACRO SERVICE_TYPE_VALUE_CONN = SERVICE_TYPE_VALUE_CONNA
#ENDIF
$SERVICE_TYPE_VALUE_TCPPORTA = "TcpPort"
$$SERVICE_TYPE_VALUE_TCPPORTW = "TcpPort"$$
#IF %DEF(%UNICODE)
 MACRO SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTW
#ELSE
 MACRO SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTA
#ENDIF
$SERVICE_TYPE_VALUE_UDPPORTA = "UdpPort"
$$SERVICE_TYPE_VALUE_UDPPORTW = "UdpPort"$$
#IF %DEF(%UNICODE)
 MACRO SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTW
#ELSE
 MACRO SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTA
#ENDIF
'//
'// status flags returned by SetService
'//
%EQUATE `SET_SERVICE_PARTIAL_SUCCESS = &H00000001
'//
'// Name Space Information
'//
' // Size = 12 bytes
TYPE NS_INFOA DWORD
 dwNameSpace AS DWORD
 dwNameSpaceFlags AS DWORD
 lpNameSpace AS ASCIIZ PTR
END TYPE
'//
'// Name Space Information
'//
' // Size = 12 bytes
TYPE NS_INFOW DWORD
 dwNameSpace AS DWORD
 dwNameSpaceFlags AS DWORD
 lpNameSpace AS WSTRINGZ PTR
END TYPE
#IF %DEF(%UNICODE)
 MACRO NS_INFO = NS_INFOW
#ELSE
 MACRO NS_INFO = NS_INFOA
#ENDIF
'//
'// Service Type Values. The structures are used to define named Service
'// Type specific values. This structure is self relative and has no pointers.
'//
' // Size = 20 bytes
TYPE SERVICE_TYPE_VALUE DWORD
 dwNameSpace AS DWORD
 dwValueType AS DWORD
 dwValueSize AS DWORD
 dwValueNameOffset AS DWORD
 dwValueOffset AS DWORD
END TYPE
'//
'// An absolute version of above. This structure does contain pointers.
'//
' // Size = 20 bytes
TYPE SERVICE_TYPE_VALUE_ABSA DWORD
 dwNameSpace AS DWORD
 dwValueType AS DWORD
 dwValueSize AS DWORD
 lpValueName AS ASCIIZ PTR
 lpValue AS DWORD
END TYPE
'//
'// An absolute version of above. This structure does contain pointers.
'//
' // Size = 20 bytes
TYPE SERVICE_TYPE_VALUE_ABSW DWORD
 dwNameSpace AS DWORD
 dwValueType AS DWORD
 dwValueSize AS DWORD
 lpValueName AS WSTRINGZ PTR
 lpValue AS DWORD
END TYPE
#IF %DEF(%UNICODE)
 MACRO SERVICE_TYPE_VALUE_ABS = SERVICE_TYPE_VALUE_ABSW
#ELSE
 MACRO SERVICE_TYPE_VALUE_ABS = SERVICE_TYPE_VALUE_ABSA
#ENDIF
'//
'// Service Type Information. Contains the name of the Service Type and
'// and an array of SERVICE_NS_TYPE_VALUE structures. This structure is self
'// relative and has no pointers in it.
'//
' // Size = 28 bytes
TYPE SERVICE_TYPE_INFO DWORD
 dwTypeNameOffset AS DWORD
 dwValueCount AS DWORD
 Values(0) AS SERVICE_TYPE_VALUE ' SERVICE_TYPE_VALUE[1]
END TYPE
' // Size = 28 bytes
TYPE SERVICE_TYPE_INFO_ABSA DWORD
 lpTypeName AS ASCIIZ PTR
 dwValueCount AS DWORD
 Values(0) AS SERVICE_TYPE_VALUE_ABSA ' SERVICE_TYPE_VALUE_ABSA[1]
END TYPE
' // Size = 28 bytes
TYPE SERVICE_TYPE_INFO_ABSW DWORD
 lpTypeName AS WSTRINGZ PTR
 dwValueCount AS DWORD
 Values(0) AS SERVICE_TYPE_VALUE_ABSW ' SERVICE_TYPE_VALUE_ABSW[1]
END TYPE
#IF %DEF(%UNICODE)
 MACRO SERVICE_TYPE_INFO_ABS = SERVICE_TYPE_INFO_ABSW
#ELSE
 MACRO SERVICE_TYPE_INFO_ABS = SERVICE_TYPE_INFO_ABSA
#ENDIF
'//
'// A Single Address definition.
'//
' // Size = 24 bytes
TYPE SERVICE_ADDRESS DWORD
 dwAddressType AS DWORD
 dwAddressFlags AS DWORD
 dwAddressLength AS DWORD
 dwPrincipalLength AS DWORD
 lpAddress AS BYTE PTR ' BYTE *
 lpPrincipal AS BYTE PTR ' BYTE *
END TYPE
'//
'// Addresses used by the service. Contains array of SERVICE_ADDRESS.
'//
' // Size = 28 bytes
TYPE SERVICE_ADDRESSES DWORD
 dwAddressCount AS DWORD
 Addresses(0) AS SERVICE_ADDRESS ' SERVICE_ADDRESS[1]
END TYPE
'//
'// Service Information.
'//
' // Size = 44 bytes
TYPE SERVICE_INFOA DWORD
 lpServiceType AS GUID PTR
 lpServiceName AS ASCIIZ PTR
 lpComment AS ASCIIZ PTR
 lpLocale AS ASCIIZ PTR
 dwDisplayHint AS DWORD
 dwVersion AS DWORD
 dwTime AS DWORD
 lpMachineName AS ASCIIZ PTR
 lpServiceAddress AS SERVICE_ADDRESSES PTR ' LPSERVICE_ADDRESSES
 ServiceSpecificInfo AS BLOB
END TYPE
'//
'// Service Information.
'//
' // Size = 44 bytes
TYPE SERVICE_INFOW DWORD
 lpServiceType AS GUID PTR
 lpServiceName AS WSTRINGZ PTR
 lpComment AS WSTRINGZ PTR
 lpLocale AS WSTRINGZ PTR
 dwDisplayHint AS DWORD
 dwVersion AS DWORD
 dwTime AS DWORD
 lpMachineName AS WSTRINGZ PTR
 lpServiceAddress AS SERVICE_ADDRESSES PTR ' LPSERVICE_ADDRESSES
 ServiceSpecificInfo AS BLOB
END TYPE
#IF %DEF(%UNICODE)
 MACRO SERVICE_INFO = SERVICE_INFOW
#ELSE
 MACRO SERVICE_INFO = SERVICE_INFOA
#ENDIF
'//
'// Name Space & Service Information
'//
' // Size = 48 bytes
TYPE NS_SERVICE_INFOA DWORD
 dwNameSpace AS DWORD
 ServiceInfo AS SERVICE_INFOA
END TYPE
'//
'// Name Space & Service Information
'//
' // Size = 48 bytes
TYPE NS_SERVICE_INFOW DWORD
 dwNameSpace AS DWORD
 ServiceInfo AS SERVICE_INFOW
END TYPE
#IF %DEF(%UNICODE)
 MACRO NS_SERVICE_INFO = NS_SERVICE_INFOW
#ELSE
 MACRO NS_SERVICE_INFO = NS_SERVICE_INFOA
#ENDIF
'#IF NOT %DEF(%CSADDR_DEFINED)
' %CSADDR_DEFINED = 1
''/*
'' * SockAddr Information
'' */
'' // Size = 8 bytes
'TYPE SOCKET_ADDRESS DWORD
' lpSocaddr AS SOCKADDR PTR
' iSockaddrLength AS LONG ' INT iSockaddrLength
'END TYPE
''/*
'' * CSAddr Information
'' */
'' // Size = 24 bytes
'TYPE CSADDR_INFO DWORD
' LocalAddr AS SOCKET_ADDRESS ' SOCKET_ADDRESS
' RemoteAddr AS SOCKET_ADDRESS ' SOCKET_ADDRESS
' iSocketType AS LONG ' INT
' iProtocol AS LONG ' INT
'END TYPE
'#ENDIF ' /* __CSADDR_DEFINED__ */
'//
'// Protocol Information
'//
' // Size = 32 bytes
TYPE PROTOCOL_INFOA DWORD
 dwServiceFlags AS DWORD
 iAddressFamily AS LONG ' INT
 iMaxSockAddr AS LONG ' INT
 iMinSockAddr AS LONG ' INT
 iSocketType AS LONG ' INT
 iProtocol AS LONG ' INT
 dwMessageSize AS DWORD
 lpProtocol AS ASCIIZ PTR
END TYPE
'//
'// Protocol Information
'//
' // Size = 32 bytes
TYPE PROTOCOL_INFOW DWORD
 dwServiceFlags AS DWORD
 iAddressFamily AS LONG ' INT
 iMaxSockAddr AS LONG ' INT
 iMinSockAddr AS LONG ' INT
 iSocketType AS LONG ' INT
 iProtocol AS LONG ' INT
 dwMessageSize AS DWORD
 lpProtocol AS WSTRINGZ PTR
END TYPE
#IF %DEF(%UNICODE)
 MACRO PROTOCOL_INFO = PROTOCOL_INFOW
#ELSE
 MACRO PROTOCOL_INFO = PROTOCOL_INFOA
#ENDIF
'//
'// NETRESOURCE2 Structure
'//
' // Size = 64 bytes
TYPE NETRESOURCE2A DWORD
 dwScope AS DWORD
 dwType AS DWORD
 dwUsage AS DWORD
 dwDisplayType AS DWORD
 lpLocalName AS ASCIIZ PTR
 lpRemoteName AS ASCIIZ PTR
 lpComment AS ASCIIZ PTR
 ns_info AS NS_INFO ' NS_INFO
 ServiceType AS GUID ' GUID
 dwProtocols AS DWORD
 lpiProtocols AS LONG PTR
END TYPE
'//
'// NETRESOURCE2 Structure
'//
' // Size = 64 bytes
TYPE NETRESOURCE2W DWORD
 dwScope AS DWORD
 dwType AS DWORD
 dwUsage AS DWORD
 dwDisplayType AS DWORD
 lpLocalName AS WSTRINGZ PTR
 lpRemoteName AS WSTRINGZ PTR
 lpComment AS WSTRINGZ PTR
 ns_info AS NS_INFO ' NS_INFO
 ServiceType AS GUID ' GUID
 dwProtocols AS DWORD
 lpiProtocols AS LONG PTR
END TYPE
#IF %DEF(%UNICODE)
 MACRO NETRESOURCE2 = NETRESOURCE2W
#ELSE
 MACRO NETRESOURCE2 = NETRESOURCE2A
#ENDIF
'typedef DWORD (* LPFN_NSPAPI) (VOID ) ;
'//
'// Structures for using the service routines asynchronously.
'//
'typedef
'(*LPSERVICE_CALLBACK_PROC) (
' );
'SUB SERVICE_CALLBACK_PROC (BYVAL lParam AS LONG, BYVAL hAsyncTaskHandle AS DWORD)
' // Size = 12 bytes
TYPE SERVICE_ASYNC_INFO DWORD
 lpServiceCallbackProc AS DWORD ' LPSERVICE_CALLBACK_PROC
 lParam AS LONG
 hAsyncTaskHandle AS DWORD
END TYPE
'//
'// Public NSP API prototypes.
'//
DECLARE FUNCTION EnumProtocolsA LIB "mswsock.dll" ALIAS "EnumProtocolsA" ( BYVAL lpiProtocols AS QUAD , BYREF lpProtocolBuffer AS ANY , BYREF lpdwBufferLength AS QUAD ) AS LONG ' INT
'//
'// Public NSP API prototypes.
'//
DECLARE FUNCTION EnumProtocolsW LIB "mswsock.dll" ALIAS "EnumProtocolsW" ( BYVAL lpiProtocols AS QUAD , BYREF lpProtocolBuffer AS ANY , BYREF lpdwBufferLength AS QUAD ) AS LONG ' INT
#IF %DEF(%UNICODE)
 MACRO EnumProtocols = EnumProtocolsW
#ELSE
 MACRO EnumProtocols = EnumProtocolsA
#ENDIF
DECLARE FUNCTION GetAddressByNameA LIB "mswsock.dll" ALIAS "GetAddressByNameA" ( BYVAL dwNameSpace AS QUAD , BYREF lpServiceType AS GUID , BYREF lpServiceName AS ASCIIZ , BYVAL lpiProtocols AS QUAD , BYVAL dwResolution AS QUAD , BYREF lpServiceAsyncInfo AS SERVICE_ASYNC_INFO , BYREF lpCsaddrBuffer AS ANY , BYREF lpdwBufferLength AS QUAD , BYVAL lpAliasBuffer AS QUAD , BYREF lpdwAliasBufferLength AS QUAD ) AS LONG ' INT
DECLARE FUNCTION GetAddressByNameW LIB "mswsock.dll" ALIAS "GetAddressByNameW" ( BYVAL dwNameSpace AS QUAD , BYREF lpServiceType AS GUID , BYREF lpServiceName AS WSTRINGZ , BYVAL lpiProtocols AS QUAD , BYVAL dwResolution AS QUAD , BYREF lpServiceAsyncInfo AS SERVICE_ASYNC_INFO , BYREF lpCsaddrBuffer AS ANY , BYREF lpdwBufferLength AS QUAD , BYREF lpAliasBuffer AS WSTRINGZ , BYREF lpdwAliasBufferLength AS QUAD ) AS LONG ' INT
#IF %DEF(%UNICODE)
 MACRO GetAddressByName = GetAddressByNameW
#ELSE
 MACRO GetAddressByName = GetAddressByNameA
#ENDIF
DECLARE FUNCTION GetTypeByNameA LIB "mswsock.dll" ALIAS "GetTypeByNameA" ( BYREF lpServiceName AS ASCIIZ , BYREF lpServiceType AS GUID ) AS LONG ' INT
DECLARE FUNCTION GetTypeByNameW LIB "mswsock.dll" ALIAS "GetTypeByNameW" ( BYREF lpServiceName AS WSTRINGZ , BYREF lpServiceType AS GUID ) AS LONG ' INT
#IF %DEF(%UNICODE)
 MACRO GetTypeByName = GetTypeByNameW
#ELSE
 MACRO GetTypeByName = GetTypeByNameA
#ENDIF
DECLARE FUNCTION GetNameByTypeA LIB "mswsock.dll" ALIAS "GetNameByTypeA" ( BYREF lpServiceType AS GUID , BYREF lpServiceName AS ASCIIZ , BYVAL dwNameLength AS QUAD ) AS LONG ' INT
DECLARE FUNCTION GetNameByTypeW LIB "mswsock.dll" ALIAS "GetNameByTypeW" ( BYREF lpServiceType AS GUID , BYREF lpServiceName AS WSTRINGZ , BYVAL dwNameLength AS QUAD ) AS LONG ' INT
#IF %DEF(%UNICODE)
 MACRO GetNameByType = GetNameByTypeW
#ELSE
 MACRO GetNameByType = GetNameByTypeA
#ENDIF
DECLARE FUNCTION SetServiceA LIB "mswsock.dll" ALIAS "SetServiceA" ( BYVAL dwNameSpace AS QUAD , BYVAL dwOperation AS QUAD , BYVAL dwFlags AS QUAD , BYREF lpServiceInfo AS SERVICE_INFOA , BYVAL lpServiceAsyncInfo AS SERVICE_ASYNC_INFO , BYREF lpdwStatusFlags AS QUAD ) AS LONG ' INT
DECLARE FUNCTION SetServiceW LIB "mswsock.dll" ALIAS "SetServiceW" ( BYVAL dwNameSpace AS QUAD , BYVAL dwOperation AS QUAD , BYVAL dwFlags AS QUAD , BYREF lpServiceInfo AS SERVICE_INFOW , BYVAL lpServiceAsyncInfo AS SERVICE_ASYNC_INFO , BYREF lpdwStatusFlags AS QUAD ) AS LONG ' INT
#IF %DEF(%UNICODE)
 MACRO SetService = SetServiceW
#ELSE
 MACRO SetService = SetServiceA
#ENDIF
DECLARE FUNCTION GetServiceA LIB "mswsock.dll" ALIAS "GetServiceA" ( BYVAL dwNameSpace AS QUAD , BYREF lpGuid AS GUID , BYREF lpServiceName AS ASCIIZ , BYVAL dwProperties AS QUAD , BYREF lpBuffer AS ANY , BYREF lpdwBufferSize AS QUAD , BYREF lpServiceAsyncInfo AS SERVICE_ASYNC_INFO ) AS LONG ' INT
DECLARE FUNCTION GetServiceW LIB "mswsock.dll" ALIAS "GetServiceW" ( BYVAL dwNameSpace AS QUAD , BYREF lpGuid AS GUID , BYREF lpServiceName AS WSTRINGZ , BYVAL dwProperties AS QUAD , BYREF lpBuffer AS ANY , BYREF lpdwBufferSize AS QUAD , BYREF lpServiceAsyncInfo AS SERVICE_ASYNC_INFO ) AS LONG ' INT
#IF %DEF(%UNICODE)
 MACRO GetService = GetServiceW
#ELSE
 MACRO GetService = GetServiceA
#ENDIF
#ENDIF
