//+-------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (c) Microsoft Corporation. All rights reserved.
//
//  Component: WSDAPI - Microsoft Web Services for Devices API
// 
//  File: wsdbase.idl
//
//  Abstract: Base interface definitions and typedefs for WSDAPI
//
//--------------------------------------------------------------------------

import "objidl.idl";
import "wincrypt.idl";


//
// Forward definitions
//
interface IWSDAddress;
interface IWSDMessageParameters;
interface IWSDUdpAddress;
interface IWSDUdpMessageParameters;
interface IWSDHttpAddress;
interface IWSDHttpMessageParameters;

cpp_quote("#if (WINVER >= _WIN32_WINNT_WIN7)")

//
// WSD_CONFIG_PARAM - used to pass config options into WSDAPI
// The type of pConfigData for each config param type is noted
// in the comment after each param.
//
typedef enum
{
    WSD_CONFIG_MAX_INBOUND_MESSAGE_SIZE = 1,        // DWORD
    WSD_CONFIG_MAX_OUTBOUND_MESSAGE_SIZE = 2,       // DWORD
    WSD_SECURITY_SSL_CERT_FOR_CLIENT_AUTH = 3,      // PCCERT_CONTEXT
    WSD_SECURITY_SSL_SERVER_CERT_VALIDATION = 4,    // PWSD_SECURITY_CERT_VALIDATION
    WSD_SECURITY_SSL_CLIENT_CERT_VALIDATION = 5,    // PWSD_SECURITY_CERT_VALIDATION
    WSD_SECURITY_SSL_NEGOTIATE_CLIENT_CERT = 6,     // [no type]
    WSD_SECURITY_COMPACTSIG_SIGNING_CERT = 7,       // PCCERT_CONTEXT
    WSD_SECURITY_COMPACTSIG_VALIDATION = 8,         // PWSD_SECURITY_SIGNATURE_VALIDATION
    WSD_CONFIG_HOSTING_ADDRESSES = 9,               // PWSD_CONFIG_ADDRESSES
    WSD_CONFIG_DEVICE_ADDRESSES = 10                // PWSD_CONFIG_ADDRESSES
} WSD_CONFIG_PARAM_TYPE;

typedef struct _WSD_CONFIG_PARAM
{
    WSD_CONFIG_PARAM_TYPE   configParamType;
    PVOID                   pConfigData;
    DWORD                   dwConfigDataSize;
} WSD_CONFIG_PARAM, *PWSD_CONFIG_PARAM;

//
// WSD_SECURITY_CERT_VALIDATION - used to pass certificate
// validation rules into WSDAPI. WSD_CONFIG_PARAM.pConfigData
// should point to this structure when configParamType is 
// WSD_SECURITY_SSL_SERVER_CERT_VALIDATION or
// WSD_SECURITY_SSL_CLIENT_CERT_VALIDATION
//
typedef struct _WSD_SECURITY_CERT_VALIDATION
{
    PCCERT_CONTEXT* certMatchArray;
    DWORD dwCertMatchArrayCount;
    HCERTSTORE hCertMatchStore;
    HCERTSTORE hCertIssuerStore;
    DWORD dwCertCheckOptions;
} WSD_SECURITY_CERT_VALIDATION, *PWSD_SECURITY_CERT_VALIDATION;

//
// WSD_SECURITY_SIGNATURE_VALIDATION - used to pass compact signature
// validation rules into WSDAPI. WSD_CONFIG_PARAM.pConfigData
// should point to this structure when configParamType is 
// WSD_SECURITY_COMPACTSIG_VALIDATION
//
typedef struct _WSD_SECURITY_SIGNATURE_VALIDATION
{
    PCCERT_CONTEXT* signingCertArray;
    DWORD dwSigningCertArrayCount;
    HCERTSTORE hSigningCertStore;
    DWORD dwFlags;
} WSD_SECURITY_SIGNATURE_VALIDATION, *PWSD_SECURITY_SIGNATURE_VALIDATION;

//
// Flags to control SSL certificate security check 
//
cpp_quote("#define WSDAPI_SSL_CERT_APPLY_DEFAULT_CHECKS     0x0")
cpp_quote("#define WSDAPI_SSL_CERT_IGNORE_REVOCATION        0x1")
cpp_quote("#define WSDAPI_SSL_CERT_IGNORE_EXPIRY            0x2")
cpp_quote("#define WSDAPI_SSL_CERT_IGNORE_WRONG_USAGE       0x4")
cpp_quote("#define WSDAPI_SSL_CERT_IGNORE_UNKNOWN_CA        0x8")
cpp_quote("#define WSDAPI_SSL_CERT_IGNORE_INVALID_CN        0x10")


//
// Flags to control compact signature verification
//
cpp_quote("#define WSDAPI_COMPACTSIG_ACCEPT_ALL_MESSAGES    0x1")


//
// WSD_CONFIG_ADDRESSES - used to pass hosting addresses for devicehost
// creation as well as the device address for device proxy creation.
// WSD_CONFIG_PARAM.pConfigData should point to this  structure 
// when configParamType is WSD_CONFIG_HOSTING_ADDRESSES
// or WSD_CONFIG_DEVICE_ADDRESSES.
//
typedef struct _WSD_CONFIG_ADDRESSES
{
    IWSDAddress** addresses;
    DWORD dwAddressCount;
} WSD_CONFIG_ADDRESSES, *PWSD_CONFIG_ADDRESSES;


cpp_quote("#endif")

//
//
// Address family definitions
//
cpp_quote("#define WSDAPI_ADDRESSFAMILY_IPV4 1")
cpp_quote("#define WSDAPI_ADDRESSFAMILY_IPV6 2")

//+-------------------------------------------------------------------------
//  IWSDAddress Interface
//  Description: Generic Transport Address
//--------------------------------------------------------------------------
[
    object,
    uuid(b9574c6c-12a6-4f74-93a1-3318ff605759),
    local
]
interface IWSDAddress : IUnknown
{
midl_pragma warning( disable:2495 )
    HRESULT Serialize(
        [out, size_is(cchLength), annotation("__out_ecount(cchLength)")] LPWSTR pszBuffer,
        [in] DWORD cchLength,
        [in] BOOL fSafe);
midl_pragma warning( default:2495 )

    HRESULT Deserialize(
        [in, annotation("__in")] LPCWSTR pszBuffer);
}

//+-------------------------------------------------------------------------
//  IWSDTransportAddress Interface
//  Description: IP-based Transport Address
//--------------------------------------------------------------------------
[
    object,
    uuid(70d23498-4ee6-4340-a3df-d845d2235467),
    local
]
interface IWSDTransportAddress : IWSDAddress
{
    HRESULT GetPort(
        [out, annotation("__out")] WORD* pwPort);

    HRESULT SetPort(
        [in] WORD wPort);

    HRESULT GetTransportAddress(
        [out, annotation("__deref_out")] LPCWSTR* ppszAddress); // Note: Do not deallocate ppszAddress
    
    HRESULT GetTransportAddressEx(
        [in] BOOL fSafe,
        [out, annotation("__deref_out")] LPCWSTR* ppszAddress); // Note: Do not deallocate ppszAddress
    
    HRESULT SetTransportAddress(
        [in, annotation("__in_opt")] LPCWSTR pszAddress);
}

//+-------------------------------------------------------------------------
//  IWSDMessageParameters Interface
//  Description: Specific transmission with a remote device
//--------------------------------------------------------------------------
[
    object,
    uuid(1fafe8a2-e6fc-4b80-b6cf-b7d45c416d7c)
]
interface IWSDMessageParameters : IUnknown
{
    HRESULT GetLocalAddress(
        [out] IWSDAddress** ppAddress);

    HRESULT SetLocalAddress(
        [in] IWSDAddress* pAddress);

    HRESULT GetRemoteAddress(
        [out] IWSDAddress** ppAddress);
    
    HRESULT SetRemoteAddress(
        [in] IWSDAddress* pAddress);

    HRESULT GetLowerParameters(
        [out] IWSDMessageParameters** ppTxParams);
} 

////////////////////////////////////////////////////////////////////////////
//
// Soap-over-Udp specific definitions
//
////////////////////////////////////////////////////////////////////////////

//
// Helper for creating UDP message parameters
//
cpp_quote("HRESULT WINAPI")
cpp_quote("WSDCreateUdpMessageParameters(")
cpp_quote("    IWSDUdpMessageParameters** ppTxParams);")

//
// Retransmit parameters
//
typedef struct _WSDUdpRetransmitParams
{
    ULONG ulSendDelay;
    ULONG ulRepeat;
    ULONG ulRepeatMinDelay;
    ULONG ulRepeatMaxDelay;
    ULONG ulRepeatUpperDelay;
} WSDUdpRetransmitParams;

//+-------------------------------------------------------------------------
//  IWSDUdpMessageParameters Interface
//  Description: UDP specific retransmission information for this message
//--------------------------------------------------------------------------
[
    object,
    uuid(9934149f-8f0c-447b-aa0b-73124b0ca7f0)
]
interface IWSDUdpMessageParameters : IWSDMessageParameters
{
    HRESULT SetRetransmitParams(
        [in] const WSDUdpRetransmitParams* pParams);

    HRESULT GetRetransmitParams(
        [out] WSDUdpRetransmitParams* pParams);

}

//
// Helper for creating UDP address
//
cpp_quote("HRESULT WINAPI")
cpp_quote("WSDCreateUdpAddress(")
cpp_quote("    __deref_out IWSDUdpAddress** ppAddress);")

//
// Forward declare SOCKADDR_STORAGE so MIDL wont choke
//
#ifndef SOCKADDR_STORAGE
cpp_quote("#if 1")
cpp_quote("// Forward declaration to avoid winsock2.h inclusion")
cpp_quote("#ifndef __CSADDR_DEFINED__")
cpp_quote("struct SOCKADDR_STORAGE;")
cpp_quote("#endif // __CSADDR_DEFINED__")
cpp_quote("#else  // 1")
cpp_quote("// Bogus definition used to make MIDL compiler happy")
typedef void SOCKADDR_STORAGE;
cpp_quote("#endif // 1")
#endif

typedef enum _WSDUdpMessageType
{
    ONE_WAY,
    TWO_WAY,
} WSDUdpMessageType;
    
//+-------------------------------------------------------------------------
//  IWSDUdpAddress Interface
//  Description: UDP Address Interface
//--------------------------------------------------------------------------
[
    object,
    uuid(74d6124a-a441-4f78-a1eb-97a8d1996893),
    local
]
interface IWSDUdpAddress : IWSDTransportAddress
{
    HRESULT SetSockaddr(
        [in] const SOCKADDR_STORAGE* pSockAddr);

    HRESULT GetSockaddr(
        [out, annotation("__out")] SOCKADDR_STORAGE* pSockAddr);
    
    HRESULT SetExclusive(
        [in] BOOL fExclusive);

    HRESULT GetExclusive(); 

    HRESULT SetMessageType(
        [in] WSDUdpMessageType messageType);

    HRESULT GetMessageType(
        [out, annotation("__out")] WSDUdpMessageType* pMessageType);
 
    HRESULT SetTTL(
        [in] DWORD dwTTL);

    HRESULT GetTTL(
        [out, annotation("__out")] DWORD* pdwTTL);
    
    HRESULT SetAlias(
        [in] const GUID* pAlias);

    HRESULT GetAlias(
        [out, annotation("__out")] GUID* pAlias);
}

////////////////////////////////////////////////////////////////////////////
//
// Soap-over-HTTP specific definitions
//
////////////////////////////////////////////////////////////////////////////

//
// Helper for creating http message parameters
//
cpp_quote("HRESULT WINAPI")
cpp_quote("WSDCreateHttpMessageParameters(")
cpp_quote("    __deref_out IWSDHttpMessageParameters** ppTxParams);")

//+-------------------------------------------------------------------------
//  IWSDHttpMessageParameters Interface
//  Description: HTTP message parameters
//--------------------------------------------------------------------------  
[
    object,
    uuid(540bd122-5c83-4dec-b396-ea62a2697fdf),
    local
]
interface IWSDHttpMessageParameters : IWSDMessageParameters
{
    HRESULT SetInboundHttpHeaders(
        [in, annotation("__in_opt")] LPCWSTR pszHeaders);

    HRESULT GetInboundHttpHeaders(
        [out, annotation("__deref_out")] LPCWSTR* ppszHeaders); // Note: Do not deallocate ppszHeaders

    HRESULT SetOutboundHttpHeaders(
        [in, annotation("__in_opt")] LPCWSTR pszHeaders);

    HRESULT GetOutboundHttpHeaders(
        [out, annotation("__deref_out")] LPCWSTR* ppszHeaders); // Note: Do not deallocate ppszHeaders

    HRESULT SetID(
        [in, annotation("__in_opt")] LPCWSTR pszId);

    HRESULT GetID(
        [out, annotation("__deref_out")] LPCWSTR* ppszId); // Note: Do not deallocate ppszId

    HRESULT SetContext(
        [in] IUnknown* pContext);

    HRESULT GetContext(
        [out, annotation("__deref_out")] IUnknown** ppContext);
    
    HRESULT Clear();
}


//
// Helper for creating HTTP address objects
//
cpp_quote("HRESULT WINAPI")
cpp_quote("WSDCreateHttpAddress(")
cpp_quote("    __deref_out IWSDHttpAddress** ppAdress);")

//+-------------------------------------------------------------------------
//  IWSDHttpAddress Interface
//  Description: HTTP address interface
//--------------------------------------------------------------------------
[
    object,
    uuid(d09ac7bd-2a3e-4b85-8605-2737ff3e4ea0),
    local
]
interface IWSDHttpAddress : IWSDTransportAddress
{
    HRESULT GetSecure(); 

    HRESULT SetSecure(
        [in] BOOL fSecure);

    HRESULT GetPath(
        [out, annotation("__deref_out")] LPCWSTR* ppszPath); // Note: Do not deallocate ppszAddress

    HRESULT SetPath(
        [in, annotation("__in")] LPCWSTR pszPath);
}


cpp_quote("#if (WINVER >= _WIN32_WINNT_WIN7)")

//+-------------------------------------------------------------------------
//  IWSDSSLClientCertificate Interface
//  Description: Interface to retrive SSL client certificate
//--------------------------------------------------------------------------  
[
    object,
    uuid(de105e87-a0da-418e-98ad-27b9eed87bdc),
    local
]
interface IWSDSSLClientCertificate : IUnknown
{
        
    HRESULT GetClientCertificate(
        [in, out, annotation("__deref_out")] PCCERT_CONTEXT* ppCertContext); // Should be freed using CertFreeCertificateContext 


    HRESULT GetMappedAccessToken(
        [in, out, annotation("__out")] HANDLE* phToken); // should be freed using CloseHandle
}


//+-----------------------------------------------------------------------------------
//  IWSDSignatureProperty Interface
//  Description: Interface to retrieve the compact signature properties present in the
//  message and the signature trust status based on user specified validation params
//------------------------------------------------------------------------------------
[
    object,
    uuid(03ce20aa-71c4-45e2-b32e-3766c61c790f),
    helpstring("IWSDSignatureProperty Interface"),
    pointer_default(unique),
    restricted,
    local
]
interface IWSDSignatureProperty : IUnknown
{
    HRESULT IsMessageSigned(
        [out, annotation("__out")] BOOL* pbSigned);
        
    HRESULT IsMessageSignatureTrusted(
        [out, annotation("__out")] BOOL* pbSignatureTrusted);
        
    HRESULT GetKeyInfo(
        [out, size_is(*pdwKeyInfoSize), annotation("__out_bcount_part_opt(*pdwKeyInfoSize, *pdwKeyInfoSize)")] BYTE* pbKeyInfo, 
        [in, out, annotation("__inout")] DWORD* pdwKeyInfoSize);
        
    HRESULT GetSignature(
        [out, size_is(*pdwSignatureSize), annotation("__out_bcount_part_opt(*pdwSignatureSize, *pdwSignatureSize)")] BYTE* pbSignature, 
        [in, out, annotation("__inout")] DWORD* pdwSignatureSize);
        
    HRESULT GetSignedInfoHash(
        [out, size_is(*pdwHashSize), annotation("__out_bcount_part_opt(*pdwHashSize, *pdwHashSize)")] BYTE* pbSignedInfoHash, 
        [in, out, annotation("__inout")] DWORD* pdwHashSize);
}

cpp_quote("#endif")

