' ########################################################################################
' Microsoft Windows
' File: DavClnt.inc
' Contents: DAV specific functions that are exposed to the user.
' 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_davclnt_PBI)
#DEFINE PBX_davclnt_PBI
%EQUATE `DAVCLNT_INC = 1
'#define OPAQUE_HANDLE DWORD
'// Certificates or other Auth types will be sent through this structure
' // Size = 12 bytes
TYPE DAV_CALLBACK_AUTH_BLOB DWORD
 pBuffer AS DWORD
 ulSize AS DWORD ' ULONG // Size of AuthBlob,
 ulType AS DWORD ' ULONG // Type of Cred sent in ppBuffer. Currently the only value it supports is 1 for PCCERT_CONTEXT.
END TYPE
'// Username and password will be sent through this structure
' // Size = 16 bytes
TYPE DAV_CALLBACK_AUTH_UNP DWORD
 pszUserName AS WSTRINGZ PTR ' LPWSTR // UserName . Memory to be allocated by the callback
 ulUserNameLength AS DWORD ' ULONG // Length in WCHAR(Doesnt include terminating NULL)
 pszPassword AS WSTRINGZ PTR ' LPWSTR // Password . Memory to be allocated by the callback
 ulPasswordLength AS DWORD ' ULONG // Length in WCHAR(Doesnt include terminating NULL)
END TYPE
' // Size = 36 bytes
TYPE DAV_CALLBACK_CRED DWORD
 AuthBlob AS DAV_CALLBACK_AUTH_BLOB
 UNPBlob AS DAV_CALLBACK_AUTH_UNP
 bAuthBlobValid AS LONG ' BOOL // Indicates if AuthBlob contents is valid. If false UNPBlob is valid
 bSave AS LONG ' BOOL // Indicates the value of bsave flag. True indicates that the creds were written to credman false indicates that creds were not written to credman
END TYPE
%EQUATE `DAV_AUTHN_SCHEME_BASIC = &H00000001
%EQUATE `DAV_AUTHN_SCHEME_NTLM = &H00000002
%EQUATE `DAV_AUTHN_SCHEME_PASSPORT = &H00000004
%EQUATE `DAV_AUTHN_SCHEME_DIGEST = &H00000008
%EQUATE `DAV_AUTHN_SCHEME_NEGOTIATE = &H00000010
%EQUATE `DAV_AUTHN_SCHEME_CERT = &H00010000
%EQUATE `DAV_AUTHN_SCHEME_FBA = &H00100000
' enum AUTHNEXTSTEP
%EQUATE `DefaultBehavior = 0 ' // Try the default behaviour. Dont use callback
%EQUATE `RetryRequest = 1 ' // Retry the connection with the newly gathered creds
%EQUATE `CancelRequest = 2 ' // Cancel connection
'// Function signature for the callback to delete the memory allocated by the creds
'typedef DWORD (*PFNDAVAUTHCALLBACK_FREECRED)(__in PVOID pbuffer);
'// Function signature for the Callback that will harvest the credentials
'typedef DWORD (*PFNDAVAUTHCALLBACK)(
');
'FUNCTION DAVAUTHCALLBACK ( ' BYREF lpwzServerName AS WSTRINGZ
' , BYREF lpwzRemoteName AS WSTRINGZ
' , BYVAL dwAuthScheme AS DWORD
' , BYVAL dwFlags AS DWORD
' , BYREF pCallbackCred AS DAV_CALLBACK_CRED
' , BYREF NextStep AS LONG
' , BYREF pFreeCred AS DWORD
' ) AS DWORD
DECLARE FUNCTION DavAddConnection LIB "netapi32.dll" ALIAS "DavAddConnection" ( BYREF ConnectionHandle AS DWORD
 , BYREF RemoteName AS WSTRINGZ
 , BYREF UserName AS WSTRINGZ
 , BYREF Password AS WSTRINGZ
 , BYVAL ClientCert AS BYTE PTR
 , BYVAL CertSize AS DWORD
 ) AS DWORD
DECLARE FUNCTION DavDeleteConnection LIB "netapi32.dll" ALIAS "DavDeleteConnection" ( BYVAL ConnectionHandle AS DWORD
 ) AS DWORD
DECLARE FUNCTION DavGetUNCFromHTTPPath LIB "netapi32.dll" ALIAS "DavGetUNCFromHTTPPath" ( BYREF HttpPath AS WSTRINGZ
 , BYVAL UncPath AS DWORD
 , BYREF lpSize AS DWORD
 ) AS DWORD
DECLARE FUNCTION DavGetHTTPFromUNCPath LIB "netapi32.dll" ALIAS "DavGetHTTPFromUNCPath" ( BYREF UncPath AS WSTRINGZ
 , BYVAL HttpPath AS DWORD
 , BYREF lpSize AS DWORD
 ) AS DWORD
DECLARE FUNCTION DavGetTheLockOwnerOfTheFile LIB "davclnt.dll" ALIAS "DavGetTheLockOwnerOfTheFile" ( BYREF FileName AS WSTRINGZ
 , BYVAL LockOwnerName AS DWORD
 , BYREF LockOwnerNameLengthInBytes AS DWORD
 ) AS DWORD
DECLARE FUNCTION DavGetExtendedError LIB "netapi32.dll" ALIAS "DavGetExtendedError" ( BYVAL hFile AS DWORD
 , BYREF ExtError AS DWORD
 , BYVAL ExtErrorString AS DWORD
 , BYREF cChSize AS DWORD
 ) AS DWORD
DECLARE FUNCTION DavFlushFile LIB "netapi32.dll" ALIAS "DavFlushFile" ( BYVAL hFile AS DWORD
 ) AS DWORD
DECLARE FUNCTION DavInvalidateCache LIB "davclnt.dll" ALIAS "DavInvalidateCache" ( BYREF URLName AS WSTRINGZ
 ) AS DWORD
DECLARE FUNCTION DavCancelConnectionsToServer LIB "davclnt.dll" ALIAS "DavCancelConnectionsToServer" ( BYREF URLName AS WSTRINGZ
 , BYVAL fForce AS LONG
 ) AS DWORD
DECLARE FUNCTION DavRegisterAuthCallback LIB "davclnt.dll" ALIAS "DavRegisterAuthCallback" ( BYVAL pCallBack AS DWORD
 , BYVAL Version AS DWORD
 ) AS DWORD ' OPAQUE_HANDLE
DECLARE SUB DavUnregisterAuthCallback LIB "davclnt.dll" ALIAS "DavUnregisterAuthCallback" ( BYVAL hCallback AS QUAD )
#ENDIF
