/*****************************************************************************/
/*
                                Service.h

Function prototypes for service configuration module.

*/
/*****************************************************************************/

#ifndef SERVICE_H_LOADED
#define SERVICE_H_LOADED 1

#include "wasd.h"

#define SERVICE_ERROR_REPORT_PATH_CODES_MAX 16

/**************/
/* structures */
/**************/

/*
   Store these structures naturally-aligned on AXP.
   Uses a bit more storage but makes access as efficient as possible.
*/

#pragma member_alignment __save
#pragma member_alignment

/* for code backward compatibility */
#define RequestScheme SchemeType
#define RequestSchemeNamePtr SchemeNamePtr

typedef struct ServiceStruct SERVICE_STRUCT;

struct ServiceStruct
{
   LIST_ENTRY  ListEntry;

   BOOL  AdminService,
         ConnectService,
         GenericService,
         Http2Enabled,
         LogFileError,
         LogFileOpen,
         LogFormatCommon,
         LogFormatCommonServer,
         LogFormatCombined,
         LogFormatProblem,
         LogFormatStamp,
         LogTimeoutEvents,
         LocalAuthRequired,
         NoLog,
         ProxyAffinity,
         ProxyAuthRequired,
         ProxyChainAuthRequired,
         ProxyFileCacheEnabled,
         ProxyService,
         RawSocket,
         SSLclientEnabled,
         ServiceErrorReportPath,
         SharedSocket;

   int  AcceptQueued,
        AdminPort,
        ConnectCount,
        ErrorReportPathLength,
        ErrorReportPathCodesCount,
        ListenBacklog,
        LogDayNumber,
        LogFileNameLength,
        LogHourNumber,
        LogMonthNumber,
        LogYearNumber,
        ProxyChainHostNameLength,
        ProxyChainPort,
        ProxyReworkMax,
        ProxyTunnel,
        ReadErrorCount,
        ReferenceCount,
        SchemeType,
        ServerBindStatus,
        ServerHostNameLength,
        ServerHostPortLength,
        ServerPort,
        ShareSSH,
        WriteErrorCount;

   int  ErrorReportPathCodes [SERVICE_ERROR_REPORT_PATH_CODES_MAX];

   int64  BytesRawRx64,
          BytesRawTx64;

   char  *LogFormatPtr,
         *ErrorReportPathCodesPtr,
         *SchemeNamePtr;

   char  BgDevName [64],
         BindIpAddressString [TCPIP_ADDRESS_STRING_MAX+1],
         BodyTag [256],
         ErrorReportPath [128],
         LogFileName [256],
         LogFormat [128],
         LogHostName [64],
         NonSslRedirect [TCPIP_HOSTNAME_MAX+1+8],
         ProxyBindIpAddressString [TCPIP_ADDRESS_STRING_MAX+1],
         ProxyChainCred [63+1],
         ProxyChainHostName [TCPIP_HOSTNAME_MAX+1],
         ProxyChainHostPort [TCPIP_HOSTNAME_MAX+1+8],
         ProxyChainIpAddressString [TCPIP_ADDRESS_STRING_MAX+1],
         ProxyChainPortString [16],
         ServerHostName [TCPIP_HOSTNAME_MAX+1],
         ServerHostPort [TCPIP_HOSTNAME_MAX+1+8],
         ServerIpAddressString [TCPIP_ADDRESS_STRING_MAX+1],
         ServerPortString [16];

   /* we'll have to cast these when we need them */
   void  *SSLclientPtr,
         *SSLserverPtr;

   IPADDRESS  BindIpAddress,
              MultiHomeIpAddress,
              ProxyBindIpAddress,
              ProxyChainIpAddress,
              ServerIpAddress;

   IO_SB  ServerIOsb;

   struct dsc$descriptor  LogFileNameDsc;
   
   struct FAB  LogFileFab;
   struct RAB  LogFileRab;

   unsigned short  ServerChannel;

   SOCKADDRESS  ServerSocketName;
};

typedef struct ServiceMetaStruct SERVICE_META;

struct ServiceMetaStruct
{
   LIST_HEAD  ServiceList;

   BOOL  ServiceLooksValid;

   /* used during configuration load */
   LIST_HEAD  *ServiceListPtr;
   SERVICE_STRUCT  ConfigService;
   int  ServiceLineNumber;
   char  ServiceLine [128];

   /* only used when reporting or changing configuration */
   void  *RequestPtr;
};

#pragma member_alignment __restore

/***********************/
/* function prototypes */
/***********************/

BOOL ServiceChange (REQUEST_STRUCT*, char*);
int ServiceConfigFromString (META_CONFIG**);
int ServiceConfigLoad (META_CONFIG**);
ServiceConfigUnload (META_CONFIG*);
ServiceConfigPostProcess (META_CONFIG*);
BOOL ServiceConfigLoadCallback (META_CONFIG*);
int ServiceControl (char*, char*);
BOOL ServiceFindVirtual (REQUEST_STRUCT*);
BOOL ServiceIsConfigured (char*);
int ServiceReferenceCount (SERVICE_STRUCT*, int);
ServiceConfigRevise (REQUEST_STRUCT*, BOOL);
ServiceConfigReviseNow (REQUEST_STRUCT*, META_CONFIG*);
int ServiceParse (char*, int*, char*, int, int*, BOOL*);
ServiceReport (REQUEST_STRUCT*, BOOL);
ServiceReportNow (REQUEST_STRUCT*, META_CONFIG*);
// int ServiceReportConfigFromString (REQUEST_STRUCT*, CONFIG_STRUCT*);

#endif /* SERVICE_H_LOADED */

/*****************************************************************************/
