DEFINITION MODULE Hosts;

        (********************************************************)
        (*                                                      *)
        (*          Checks on host names and addresses          *)
        (*                                                      *)
        (*  Programmer:         P. Moylan                       *)
        (*  Started:            9 May 1998                      *)
        (*  Last edited:        23 September 2025               *)
        (*  Status:             OK                              *)
        (*                                                      *)
        (********************************************************)

FROM Names IMPORT
    (* type *)  HostName, DomainName;

FROM Watchdog IMPORT
    (* type *)  WatchdogID;

FROM TransLog IMPORT
    (* type *)  TransactionLogID;

PROCEDURE OnBlacklist (IPAddress: CARDINAL;  ID: TransactionLogID;
                            watchID: WatchdogID;
                            VAR (*OUT*) message: ARRAY OF CHAR): BOOLEAN;

    (* Returns TRUE if IPAddress is on one of the realtime blacklists   *)
    (* for which we have blacklist checking enabled.  In this case      *)
    (* message is set to a suitable error response to the client.  We   *)
    (* signal on watchdog before checking each list, because the checks *)
    (* do involve time delays.                                          *)

PROCEDURE CheckHost (IPAddress: CARDINAL;
                     VAR (*OUT*) IsBanned, OnWhitelist, MayRelay: BOOLEAN);

    (* Looks up our internal list of hosts, and returns results: *)
    (*     IsBanned:   this host is on our blacklist, we will    *)
    (*                 refuse any connection from it.            *)
    (*     OnWhitelist: this host is whitelisted                 *)
    (*     MayRelay:   this host is one from whom we will        *)
    (*                 accept mail to be relayed.                *)

PROCEDURE BannedHost (VAR (*IN*) name: HostName;  LogID: TransactionLogID;
                                    watchID: WatchdogID): BOOLEAN;

    (* Returns TRUE if name matches a name in the "banned" list.  This  *)
    (* is different from the CheckHost check because we are now         *)
    (* checking the name rather than the address.                       *)

PROCEDURE AcceptableRelayDestination (VAR (*IN*) name: HostName): BOOLEAN;

    (* Returns TRUE if name matches a name in the "acceptable relay     *)
    (* destinations" list.                                              *)

PROCEDURE NoChunkingHost (VAR (*IN*) name: HostName): BOOLEAN;

    (* Returns TRUE if name matches a name in the "nochunking" list.    *)

PROCEDURE RefreshHostLists;

    (* This procedure is to be called whenever there is a chance that   *)
    (* the INI data might have been updated.  Discards the existing     *)
    (* version of all host lists, and builds new copies.  Also checks   *)
    (* for changes in the Relay blacklist specifications.               *)

END Hosts.

