(* Copyright (C)2020-2023, Philip Munts dba Munts Technologies.                *)
(*                                                                             *)
(* Redistribution and use in source and binary forms, with or without          *)
(* modification, are permitted provided that the following conditions are met: *)
(*                                                                             *)
(* * Redistributions of source code must retain the above copyright notice,    *)
(*   this list of conditions and the following disclaimer.                     *)
(*                                                                             *)
(* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" *)
(* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE   *)
(* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  *)
(* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE   *)
(* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR         *)
(* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF        *)
(* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS    *)
(* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN     *)
(* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)     *)
(* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  *)
(* POSSIBILITY OF SUCH DAMAGE.                                                 *)

DEFINITION MODULE FOR "C" syslog;

  EXPORT UNQUALIFIED
    LOG_PID,
    LOG_CONS,
    LOG_ODELAY,
    LOG_NDELAY,
    LOG_NOWAIT,
    LOG_PERROR,
    LOG_KERN,
    LOG_USER,
    LOG_MAIL,
    LOG_DAEMON,
    LOG_AUTH,
    LOG_SYSLOG,
    LOG_LPR,
    LOG_NEWS,
    LOG_UUCP,
    LOG_CRON,
    LOG_AUTHPRIV,
    LOG_FTP,
    LOG_LOCAL0,
    LOG_LOCAL1,
    LOG_LOCAL2,
    LOG_LOCAL3,
    LOG_LOCAL4,
    LOG_LOCAL5,
    LOG_LOCAL6,
    LOG_LOCAL7,

    LOG_EMERG,
    LOG_ALERT,
    LOG_CRIT,
    LOG_ERR,
    LOG_WARNING,
    LOG_NOTICE,
    LOG_INFO,
    LOG_DEBUG,

    LINUX_openlog,
    LINUX_syslog,
    LINUX_closelog,

    Open,
    WriteString,
    Close;

  CONST
   (* syslog option constants (extracted from syslog.h) *)

    LOG_PID      = 0001H; (* log the pid with each message *)
    LOG_CONS     = 0002H; (* log on the console if errors in sending *)
    LOG_ODELAY   = 0004H; (* delay open until first syslog() (default) *)
    LOG_NDELAY   = 0008H; (* don't delay open *)
    LOG_NOWAIT   = 0010H; (* don't wait for console forks: DEPRECATED *)
    LOG_PERROR   = 0020H; (* log to stderr as well *)

   (* syslog facility constants (extracted from syslog.h) *)

    LOG_KERN     = 0000H;
    LOG_USER     = 0008H;
    LOG_MAIL     = 0010H;
    LOG_DAEMON   = 0018H;
    LOG_AUTH     = 0020H;
    LOG_SYSLOG   = 0028H;
    LOG_LPR      = 0030H;
    LOG_NEWS     = 0038H;
    LOG_UUCP     = 0040H;
    LOG_CRON     = 0048H;
    LOG_AUTHPRIV = 0050H;
    LOG_FTP      = 0058H;
    LOG_LOCAL0   = 0080H;
    LOG_LOCAL1   = 0088H;
    LOG_LOCAL2   = 0090H;
    LOG_LOCAL3   = 0098H;
    LOG_LOCAL4   = 00A0H;
    LOG_LOCAL5   = 00A8H;
    LOG_LOCAL6   = 00B0H;
    LOG_LOCAL7   = 00B8H;

   (* syslog priority constants (extracted from syslog.h) *)

    LOG_EMERG    = 0;     (* system is unusable *)
    LOG_ALERT    = 1;     (* action must be taken immediately *)
    LOG_CRIT     = 2;     (* critical conditions *)
    LOG_ERR      = 3;     (* error conditions *)
    LOG_WARNING  = 4;     (* warning conditions *)
    LOG_NOTICE   = 5;     (* normal but significant condition *)
    LOG_INFO     = 6;     (* informational *)
    LOG_DEBUG    = 7;     (* debug-level messages *)

  PROCEDURE LINUX_openlog
   (ident        : ARRAY OF CHAR;
    options      : CARDINAL;
    facility     : CARDINAL;
    VAR error    : CARDINAL);

  PROCEDURE LINUX_syslog
   (priority     : CARDINAL;
    message      : ARRAY OF CHAR;
    VAR error    : CARDINAL);

  PROCEDURE LINUX_closelog
   (VAR error    : CARDINAL);

  PROCEDURE LINUX_poll
   (numfiles     : CARDINAL;
    VAR files    : ARRAY OF INTEGER;
    VAR events   : ARRAY OF CARDINAL;
    VAR results  : ARRAY OF CARDINAL;
    timeout      : INTEGER;
    VAR error    : CARDINAL);

  (* Define some useful procedure synonyms *)

  CONST
    Open        = LINUX_openlog;
    WriteString = LINUX_syslog;
    Close       = LINUX_closelog;

END syslog.
