DEFINITION MODULE HostLists;

        (********************************************************)
        (*                                                      *)
        (*           Lists of host names and addresses          *)
        (*                                                      *)
        (*  Programmer:         P. Moylan                       *)
        (*  Started:            1 September 2002                *)
        (*  Last edited:        23 September 2025               *)
        (*  Status:             OK                              *)
        (*                                                      *)
        (********************************************************)

FROM Names IMPORT
    (* type *)  HostName;

FROM INIData IMPORT
    (* type *)  HINI;

TYPE HostList;          (* is private *)


PROCEDURE CreateHostList (LogName: ARRAY OF CHAR;  local: BOOLEAN): HostList;

    (* Creates an empty list. *)

PROCEDURE RefreshLocalList (hini: HINI;  VAR (*INOUT*) list: HostList);

    (* Discards the existing contents of the list, then reloads it      *)
    (* from INI file data.  We assume that the caller has opened the    *)
    (* INI file.                                                        *)

PROCEDURE RefreshHostList (VAR (*IN*) app, key: ARRAY OF CHAR;
                           VAR (*INOUT*) list: HostList;
                           ExpandNumeric: BOOLEAN);

    (* Discards the existing contents of the list, then reloads it      *)
    (* from INI file data.                                              *)

PROCEDURE RefreshHostList2 (VAR (*IN*) app, key: ARRAY OF CHAR;
                            VAR (*INOUT*) list: HostList;
                            InitialAddresses: ARRAY OF CARDINAL;
                            ExpandNumeric: BOOLEAN);

    (* Like RefreshHostList, but uses the IP addresses from a given     *)
    (* array to preload the list before adding the INI file data.       *)
    (* A zero address terminates the InitialAddresses array.            *)

PROCEDURE DestroyHostList (VAR (*INOUT*) list: HostList);

    (* Empties the list, then discards it. *)

PROCEDURE FindAllAddresses (list: HostList;
                             VAR (*OUT*) address: ARRAY OF CARDINAL);

    (* Sets address to contain all the numeric addresses in list.  The  *)
    (* terminator is a zero address.                                    *)

PROCEDURE MatchHostName (list: HostList;  VAR (*IN*) name: HostName): BOOLEAN;

    (* Returns TRUE if name matches a name in the list, either as a     *)
    (* text string or as a numeric x.x.x.x name.                        *)

PROCEDURE MatchAnAddress (list: HostList;  IPAddress: CARDINAL): BOOLEAN;

    (* Returns TRUE if either the address IPAddress, or the hostname    *)
    (* obtained by rDNS lookup is in the list.  In the second case we   *)
    (* look up only the primary name, i.e. we don't bother with things  *)
    (* like aliases.  IPAddress is in network byte order.               *)

END HostLists.

