
#if !defined(AFX_BORFRRAS_H__3A595C86_7D79_4878_89E8_EB262E70CE6C__INCLUDED_)
#define AFX_BORFRRAS_H__3A595C86_7D79_4878_89E8_EB262E70CE6C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// Project resources.
#include "resource.h"

// The message table resource for event viewer messages.
#include "borfevm.h"

using namespace std;


// The service name that will be registered with the Service Control Manager.
#define BORF_KNOB_SERVICE_NAME  L"borfrras"

// The device type that we know about.
#define BORF_KNOB_RRAS_MODEM  L"MODEM"

// The main polling interval in milliseconds.
#define BORF_KNOB_POLLING_INTERVAL  60000

// The percentage of modem ports that must be used before the system is considered busy.
#define BORF_KNOB_TIME_BUSY_THRESHOLD  0.50

// The time limit for regular dial-up users in seconds.  One hour.
#define BORF_KNOB_TIME_LIMIT  3600

// The starting hour of the overnight no-borf period.  Midnight.
#define BORF_KNOB_TIME_OFF  0

// The ending hour of the overnight no-borf period.  9am.
#define BORF_KNOB_TIME_ON   9

// Apply time rules to servers in this group.
#define BORF_KNOB_TIME_SERVER_GROUP   L"Borf Time Servers"

// Put borf'd users into this group.
#define BORF_KNOB_TIME_LOCKOUT_GROUP  L"Borf Time Lockout"

// The maximum number of allowed dial-up connections.
#define BORF_KNOB_DUPLICATE_LIMIT  1

// Check for duplicate logons on servers in this group.
#define BORF_KNOB_DUPLICATE_SERVER_GROUP   L"Borf Duplicate Servers"

// Put borf'd users into this group.
#define BORF_KNOB_DUPLICATE_LOCKOUT_GROUP  L"Borf Duplicate Lockout"


typedef CMap< CString, LPCTSTR, DWORD, DWORD& > CMapStringToDword;


typedef enum _BORF_RUNNING
{
	BORF_RUNNING_STOPPED = 0,
	BORF_RUNNING_CONSOLE,
	BORF_RUNNING_SERVICE

} BORF_RUNNING;


typedef struct _BORF_CONNECTION
{
	RAS_SERVER_HANDLE  hServer;
	RAS_CONNECTION_0*  pConnection0;
	RAS_CONNECTION_1*  pConnection1;
	RAS_CONNECTION_2*  pConnection2;

} BORF_CONNECTION, *PBORF_CONNECTION;


typedef struct _BORF_OPTIONS
{
	CString  sDomainName;
	DWORD    dwPollingInterval;
	DOUBLE   dTimeBusyThreshold;
	DWORD    dwTimeLimit;
	DWORD    dwTimeOff;
	DWORD    dwTimeOn;
	CString  sTimeServerGroup;
	CString  sTimeLockoutGroup;
	DWORD    dwDuplicateLimit;
	CString  sDuplicateServerGroup;
	CString  sDuplicateLockoutGroup;

} BORF_OPTIONS, *PBORF_OPTIONS;


class CListBorfConnection : public CList< BORF_CONNECTION, BORF_CONNECTION& >
{
	public:

		~CListBorfConnection()
		{
			// Default destructor.
			this->RemoveAll();
		}

		CListBorfConnection()
		{
			// Default constructor. Do nothing.
		}

		CListBorfConnection( const CListBorfConnection& MyCopy )
		{
			// Copy constructor.
			POSITION MyCopyPosition = MyCopy.GetHeadPosition();
			while( MyCopyPosition )	{ this->AddTail( MyCopy.GetNext( MyCopyPosition ) ); }
		}
};


class CListMprServerHandle : public CList< MPR_SERVER_HANDLE, MPR_SERVER_HANDLE >
{
	public:

		~CListMprServerHandle()
		{
			// Default destructor.
			this->RemoveAll();
		}

		CListMprServerHandle()
		{
			// Default constructor. Do nothing.
		}

		CListMprServerHandle( const CListMprServerHandle& MyCopy )
		{
			// Copy constructor.
			POSITION MyCopyPosition = MyCopy.GetHeadPosition();
			while( MyCopyPosition )	{ this->AddTail( MyCopy.GetNext( MyCopyPosition ) ); }
		}
};



// *** PROTOTYPES ***

HRESULT BorfADsMembers( const CString& sADsPath, CStringList& borfRetVal );
HRESULT BorfADsAddNameToGroup( LPCTSTR wszADsName, LPCTSTR wszADsGroup );
HRESULT BorfStripWinntPath( CString& sADsPath );
HRESULT BorfStripWinntPathList( CStringList& sADsPathList );

void WINAPI BorfServiceControlHandler( DWORD dwOpcode );
void WINAPI BorfServiceMain( DWORD argc, LPTSTR *argv );
HRESULT BorfServiceInstall( void );
HRESULT BorfServiceUninstall( void );
HRESULT BorfServiceCheck( void );

HRESULT BorfConnectionEnumerate( const CListMprServerHandle& oMprServerHandleList, CListBorfConnection& oConnectionList );
HRESULT BorfConnectionFree( CListBorfConnection& oConnectionList );
HRESULT BorfConnectionDisconnect( BORF_CONNECTION& borfConnection );
HRESULT BorfServerConnect( const CStringList& oServerNameList, CListMprServerHandle& oServerHandleList );
HRESULT BorfServerDisconnect( CListMprServerHandle& oServerHandleList );
HRESULT BorfDisconnectDuplicate( CListBorfConnection& oConnectionList );
HRESULT BorfDisconnectTime( CListBorfConnection oConnectionList, DWORD dwCount );
HRESULT BorfServerIsBusy( const CListMprServerHandle& oServerHandleList, DWORD& dwBusyCount );

void BorfEvent( WORD wType, DWORD dwIdm, DWORD dwVoid, LPVOID lpVoid, LPCTSTR lpwszList, ... );
void BorfApiWarning( DWORD dwError, LPCTSTR lpwszSource );
int BorfMain( void );

#endif // !defined(AFX_BORFRRAS_H__3A595C86_7D79_4878_89E8_EB262E70CE6C__INCLUDED_)

// eof